Debian Codegraph @

deps/libneon/src/ne_utils.h

raw
1 /*
2 HTTP utility functions
3 Copyright (C) 1999-2006, Joe Orton <[email protected]>
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_HDR (DAVIX_LOG_HEADER ) /* HTTP headers */
87 #define NE_DBG_HTTP (DAVIX_LOG_HTTP ) /* HTTP request/response handling */
88 #define NE_DBG_XML (DAVIX_LOG_XML ) /* XML parser */
89 #define NE_DBG_HTTPAUTH (DAVIX_LOG_SSL ) /* HTTP authentication (hiding credentials) */
90 #define NE_DBG_HTTPPLAIN (DAVIX_LOG_SENSITIVE ) /* plaintext HTTP authentication */
91 #define NE_DBG_LOCKS (DAVIX_LOG_LOCKS ) /* WebDAV locking */
92 #define NE_DBG_XMLPARSE (DAVIX_LOG_XML ) /* low-level XML parser */
93 #define NE_DBG_HTTPBODY (DAVIX_LOG_BODY ) /* HTTP response body blocks */
94 #define NE_DBG_SSL (DAVIX_LOG_SSL ) /* SSL/TLS */
95 #define NE_DBG_CORE (DAVIX_LOG_SOCKET )
96 #define NE_DBG_FLUSH (1<<30) /* always flush debugging */
97
98 /* Send debugging output to 'stream', for all of the given debug
99 * channels. To disable debugging, pass 'stream' as NULL and 'mask'
100 * as 0. */
101 void ne_debug_init(FILE *stream, int mask);
102
103 /* The current debug mask and stream set by the last call to
104 * ne_debug_init. */
105 extern int ne_debug_mask;
106 extern FILE *ne_debug_stream;
107
108 /* Produce debug output if any of channels 'ch' is enabled for
109 * debugging. */
110 void ne_debug(int ch, const char *, ...) ne_attribute((format(printf, 2, 3)));
111
112 /* Storing an HTTP status result */
113 typedef struct {
114 int major_version;
115 int minor_version;
116 int code; /* Status-Code value */
117 int klass; /* Class of Status-Code (1-5) */
118 char *reason_phrase;
119 } ne_status;
120
121 /* NB: couldn't use 'class' in ne_status because it would clash with
122 * the C++ reserved word. */
123
124 /* Parse 'status_line' using the the RFC2616 Status-Line grammar.
125 * s->reason_phrase is malloc-allocated if non-NULL, and must be
126 * free'd by the caller. Returns 0 on success, in which case all
127 * fields of '*s' will be set; or -1 on parse error, in which case
128 * '*s' is unmodified. */
129 int ne_parse_statusline(const char *status_line, ne_status *s);
130
131 NE_END_DECLS
132
133 #endif /* NE_UTILS_H */