1 /*
2    HTTP utility functions
3    Copyright (C) 1999-2002, 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 
30 #include "ne_defs.h"
31 
32 #ifdef NEON_TRIO
33 /* no HAVE_TRIO_H check so this works from outside neon build tree. */
34 #include <trio.h>
35 #endif
36 
37 BEGIN_NEON_DECLS
38 
39 /* Returns a human-readable version string like:
40  * "neon 0.2.0: Library build, OpenSSL support"
41  */
42 const char *ne_version_string(void);
43 
44 /* Returns non-zero if library version is not of major version
45  * 'major', or if minor version is not greater than or equal to
46  * 'minor'. */
47 int ne_version_match(int major, int minor);
48 
49 /* Returns non-zero if neon has support for SSL. */
50 int ne_supports_ssl(void);
51 
52 /* Use replacement snprintf's if trio is being used. */
53 #ifdef NEON_TRIO
54 #define ne_snprintf trio_snprintf
55 #define ne_vsnprintf trio_vsnprintf
56 #else
57 #define ne_snprintf snprintf
58 #define ne_vsnprintf vsnprintf
59 #endif
60 
61 #ifndef WIN32
62 #undef min
63 #define min(a,b) ((a)<(b)?(a):(b))
64 #endif
65 
66 /* CONSIDER: mutt has a nicer way of way of doing debugging output... maybe
67  * switch to like that. */
68 
69 #ifndef NE_DEBUGGING
70 #define NE_DEBUG if (0) ne_debug
71 #else /* DEBUGGING */
72 #define NE_DEBUG ne_debug
73 #endif /* DEBUGGING */
74 
75 #define NE_DBG_SOCKET (1<<0)
76 #define NE_DBG_HTTP (1<<1)
77 #define NE_DBG_XML (1<<2)
78 #define NE_DBG_HTTPAUTH (1<<3)
79 #define NE_DBG_HTTPPLAIN (1<<4)
80 #define NE_DBG_LOCKS (1<<5)
81 #define NE_DBG_XMLPARSE (1<<6)
82 #define NE_DBG_HTTPBODY (1<<7)
83 #define NE_DBG_SSL (1<<8)
84 #define NE_DBG_FLUSH (1<<30)
85 
86 /* Send debugging output to 'stream', for all of the given debug
87  * channels.  To disable debugging, pass 'stream' as NULL and 'mask'
88  * as 0. */
89 void ne_debug_init(FILE *stream, int mask);
90 
91 /* The current debug mask and stream set by the last call to
92  * ne_debug_init. */
93 extern int ne_debug_mask;
94 extern FILE *ne_debug_stream;
95 
96 /* Produce debug output if any of channels 'ch' is enabled for
97  * debugging. */
98 void ne_debug(int ch, const char *, ...) ne_attribute((format(printf, 2, 3)));
99 
100 /* Storing an HTTP status result */
101 typedef struct {
102     int major_version;
103     int minor_version;
104     int code; /* Status-Code value */
105     int klass; /* Class of Status-Code (1-5) */
106     char *reason_phrase;
107 } ne_status;
108 
109 /* NB: couldn't use 'class' in ne_status because it would clash with
110  * the C++ reserved word. */
111 
112 /* Parser for strings which follow the Status-Line grammar from
113  * RFC2616.  s->reason_phrase is malloc-allocated if non-NULL, and
114  * must be free'd by the caller.
115  *  Returns:
116  *    0 on success, *s will be filled in.
117  *   -1 on parse error.
118  */
119 int ne_parse_statusline(const char *status_line, ne_status *s);
120 
121 END_NEON_DECLS
122 
123 #endif /* NE_UTILS_H */
124