1 /*
2    HTTP utility functions
3    Copyright (C) 1999-2006, Joe Orton <joe@manyfish.co.uk>
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14 
15    You should have received a copy of the GNU Library General Public
16    License along with this library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18    MA 02111-1307, USA
19 
20 */
21 
22 #ifndef NE_UTILS_H
23 #define NE_UTILS_H
24 
25 #include <sys/types.h>
26 
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <time.h>
30 #include <sys/time.h>
31 
32 #include "ne_defs.h"
33 
34 #ifdef NEON_TRIO
35 #include <trio.h>
36 #endif
37 
38 #include "davix_logger_c.h"
39 
40 NE_BEGIN_DECLS
41 
42 /* Returns a human-readable library version string describing the
43  * version and build information; for example:
44  *    "neon 0.2.0: Library build, OpenSSL support" */
45 const char *ne_version_string(void);
46 
47 /* Returns non-zero if library version is not of major version
48  * 'major', or if minor version is not greater than or equal to
49  * 'minor'.  For neon versions with major == 0, all minor versions are
50  * presumed to be incompatible.  */
51 int ne_version_match(int major, int minor);
52 
53 
54 void ne_davix_logger(int scope, const char* msg, ...);
55 
56 void davix_get_monotonic_time(struct timespec *time_value);
57 
58 /* Feature codes: */
59 #define NE_FEATURE_SSL (1) /* SSL/TLS support */
60 #define NE_FEATURE_ZLIB (2) /* zlib compression in compress interface */
61 #define NE_FEATURE_IPV6 (3) /* IPv6 is supported in resolver */
62 #define NE_FEATURE_LFS (4) /* large file support */
63 #define NE_FEATURE_SOCKS (5) /* SOCKSv5 support */
64 #define NE_FEATURE_TS_SSL (6) /* Thread-safe SSL/TLS support */
65 #define NE_FEATURE_I18N (7) /* i18n error message support */
66 
67 /* Returns non-zero if library is built with support for the given
68  * NE_FEATURE_* feature code 'code'. */
69 int ne_has_support(int feature);
70 
71 /* Debugging macro to allow code to be optimized out if debugging is
72  * disabled at build time. */
73 #ifndef NE_DEBUGGING
74 #define NE_DEBUG if (0) ne_debug
75 #else /* DEBUGGING */
76 /* #define NE_DEBUG ne_debug */
77 /* bypasses default Neon logger and use Davix's instead */
78 #define NE_DEBUG ne_davix_logger
79 #endif
80 
81 /* DEBUGGING */
82 
83 /* Debugging masks. */
84 /* Map to DAVIX logging masks. */
85 #define NE_DBG_SOCKET (DAVIX_LOG_SOCKET ) /* raw socket */
86 #define NE_DBG_HTTP (DAVIX_LOG_HEADER ) /* HTTP request/response handling */
87 #define NE_DBG_XML (DAVIX_LOG_XML ) /* XML parser */
88 #define NE_DBG_HTTPAUTH (DAVIX_LOG_SSL ) /* HTTP authentication (hiding credentials) */
89 #define NE_DBG_HTTPPLAIN (DAVIX_LOG_SSL ) /* plaintext HTTP authentication */
90 #define NE_DBG_LOCKS (DAVIX_LOG_LOCKS ) /* WebDAV locking */
91 #define NE_DBG_XMLPARSE (DAVIX_LOG_XML ) /* low-level XML parser */
92 #define NE_DBG_HTTPBODY (DAVIX_LOG_BODY ) /* HTTP response body blocks */
93 #define NE_DBG_SSL (DAVIX_LOG_SSL ) /* SSL/TLS */
94 #define NE_DBG_CORE (DAVIX_LOG_SOCKET )
95 #define NE_DBG_FLUSH (1<<30) /* always flush debugging */
96 
97 /* Send debugging output to 'stream', for all of the given debug
98  * channels.  To disable debugging, pass 'stream' as NULL and 'mask'
99  * as 0. */
100 void ne_debug_init(FILE *stream, int mask);
101 
102 /* The current debug mask and stream set by the last call to
103  * ne_debug_init. */
104 extern int ne_debug_mask;
105 extern FILE *ne_debug_stream;
106 
107 /* Produce debug output if any of channels 'ch' is enabled for
108  * debugging. */
109 void ne_debug(int ch, const char *, ...) ne_attribute((format(printf, 2, 3)));
110 
111 /* Storing an HTTP status result */
112 typedef struct {
113     int major_version;
114     int minor_version;
115     int code; /* Status-Code value */
116     int klass; /* Class of Status-Code (1-5) */
117     char *reason_phrase;
118 } ne_status;
119 
120 /* NB: couldn't use 'class' in ne_status because it would clash with
121  * the C++ reserved word. */
122 
123 /* Parse 'status_line' using the the RFC2616 Status-Line grammar.
124  * s->reason_phrase is malloc-allocated if non-NULL, and must be
125  * free'd by the caller.  Returns 0 on success, in which case all
126  * fields of '*s' will be set; or -1 on parse error, in which case
127  * '*s' is unmodified. */
128 int ne_parse_statusline(const char *status_line, ne_status *s);
129 
130 NE_END_DECLS
131 
132 #endif /* NE_UTILS_H */
133