Back to index

avfs  1.0.1
http_utils.h
Go to the documentation of this file.
00001 /* 
00002    HTTP utility functions
00003    Copyright (C) 1999-2001, Joe Orton <joe@light.plus.com>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009    
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00018    MA 02111-1307, USA
00019 
00020 */
00021 
00022 #ifndef HTTP_UTILS_H
00023 #define HTTP_UTILS_H
00024 
00025 #include <sys/types.h>
00026 
00027 #include <stdarg.h>
00028 #include <stdio.h>
00029 
00030 #include "neon_defs.h"
00031 
00032 BEGIN_NEON_DECLS
00033 
00034 /* Returns a user-visible version string like:
00035  * "neon 0.2.0: Standalone build, OpenSSL support"
00036  */
00037 const char *neon_version_string(void);
00038 
00039 /* Returns non-zero if the neon API compiled in is less than
00040  * major.minor. i.e.
00041  *   I am: 1.2 -  neon_version_check(1, 3) => -1
00042  *   I am: 0.10 -  neon_version_check(0, 9) => 0
00043  */
00044 int neon_version_minimum(int major, int minor);
00045 
00046 #define HTTP_QUOTES "\"'"
00047 #define HTTP_WHITESPACE " \r\n\t"
00048 
00049 /* Handy macro to free things. */
00050 #define HTTP_FREE(x) do { if ((x) != NULL) free((x)); (x) = NULL; } while (0)
00051 
00052 #ifndef HTTP_PORT
00053 #define HTTP_PORT 80
00054 #endif
00055 
00056 time_t http_dateparse(const char *date);
00057 
00058 #ifndef WIN32
00059 #undef min
00060 #define min(a,b) ((a)<(b)?(a):(b))
00061 #endif
00062 
00063 /* CONSIDER: mutt has a nicer way of way of doing debugging output... maybe
00064  * switch to like that. */
00065 #ifndef DEBUGGING
00066 #define DEBUG if (0) neon_debug
00067 #else /* DEBUGGING */
00068 #define DEBUG neon_debug
00069 #endif /* DEBUGGING */
00070 
00071 #define DEBUG_SOCKET (1<<0)
00072 #define DEBUG_HTTP (1<<1)
00073 #define DEBUG_XML (1<<2)
00074 #define DEBUG_HTTPAUTH (1<<3)
00075 #define DEBUG_HTTPPLAIN (1<<4)
00076 #define DEBUG_LOCKS (1<<5)
00077 #define DEBUG_XMLPARSE (1<<6)
00078 #define DEBUG_HTTPBODY (1<<7)
00079 #define DEBUG_HTTPBASIC (1<<8)
00080 #define DEBUG_FLUSH (1<<30)
00081 
00082 void neon_debug_init(FILE *stream, int mask);
00083 extern int neon_debug_mask;
00084 
00085 void neon_debug(int ch, const char *, ...)
00086 #ifdef __GNUC__
00087                 __attribute__ ((format (printf, 2, 3)))
00088 #endif /* __GNUC__ */
00089 ;
00090 
00091 /* Storing an HTTP status result */
00092 typedef struct {
00093     int major_version;
00094     int minor_version;
00095     int code; /* Status-Code value */
00096     /* We can't use 'class' as the member name since this crashes
00097      * with the C++ reserved keyword 'class', annoyingly.
00098      * This was '_class' previously, but that was even MORE annoying.
00099      * So know it is klass. */
00100     int klass; /* Class of Status-Code (1-5) */
00101     const char *reason_phrase;
00102 } http_status;
00103 
00104 /* Parser for strings which follow the Status-Line grammar from 
00105  * RFC2616.
00106  *  Returns:
00107  *    0 on success, *s will be filled in.
00108  *   -1 on parse error.
00109  */
00110 int http_parse_statusline(const char *status_line, http_status *s);
00111 
00112 END_NEON_DECLS
00113 
00114 #endif /* HTTP_UTILS_H */