Back to index

avfs  1.0.1
Classes | Defines | Functions | Variables
http_utils.h File Reference
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#include "neon_defs.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  http_status

Defines

#define HTTP_QUOTES   "\"'"
#define HTTP_WHITESPACE   " \r\n\t"
#define HTTP_FREE(x)   do { if ((x) != NULL) free((x)); (x) = NULL; } while (0)
#define HTTP_PORT   80
#define min(a, b)   ((a)<(b)?(a):(b))
#define DEBUG   if (0) neon_debug
#define DEBUG_SOCKET   (1<<0)
#define DEBUG_HTTP   (1<<1)
#define DEBUG_XML   (1<<2)
#define DEBUG_HTTPAUTH   (1<<3)
#define DEBUG_HTTPPLAIN   (1<<4)
#define DEBUG_LOCKS   (1<<5)
#define DEBUG_XMLPARSE   (1<<6)
#define DEBUG_HTTPBODY   (1<<7)
#define DEBUG_HTTPBASIC   (1<<8)
#define DEBUG_FLUSH   (1<<30)

Functions

BEGIN_NEON_DECLS const char * neon_version_string (void)
int neon_version_minimum (int major, int minor)
time_t http_dateparse (const char *date)
void neon_debug_init (FILE *stream, int mask)
void neon_debug (int ch, const char *,...)
int http_parse_statusline (const char *status_line, http_status *s)

Variables

int neon_debug_mask

Class Documentation

struct http_status

Definition at line 92 of file http_utils.h.

Class Members
int code
int klass
int major_version
int minor_version
const char * reason_phrase

Define Documentation

#define DEBUG   if (0) neon_debug

Definition at line 66 of file http_utils.h.

#define DEBUG_FLUSH   (1<<30)

Definition at line 80 of file http_utils.h.

#define DEBUG_HTTP   (1<<1)

Definition at line 72 of file http_utils.h.

#define DEBUG_HTTPAUTH   (1<<3)

Definition at line 74 of file http_utils.h.

#define DEBUG_HTTPBASIC   (1<<8)

Definition at line 79 of file http_utils.h.

#define DEBUG_HTTPBODY   (1<<7)

Definition at line 78 of file http_utils.h.

#define DEBUG_HTTPPLAIN   (1<<4)

Definition at line 75 of file http_utils.h.

#define DEBUG_LOCKS   (1<<5)

Definition at line 76 of file http_utils.h.

#define DEBUG_SOCKET   (1<<0)

Definition at line 71 of file http_utils.h.

#define DEBUG_XML   (1<<2)

Definition at line 73 of file http_utils.h.

#define DEBUG_XMLPARSE   (1<<6)

Definition at line 77 of file http_utils.h.

#define HTTP_FREE (   x)    do { if ((x) != NULL) free((x)); (x) = NULL; } while (0)

Definition at line 50 of file http_utils.h.

#define HTTP_PORT   80

Definition at line 53 of file http_utils.h.

#define HTTP_QUOTES   "\"'"

Definition at line 46 of file http_utils.h.

#define HTTP_WHITESPACE   " \r\n\t"

Definition at line 47 of file http_utils.h.

#define min (   a,
 
)    ((a)<(b)?(a):(b))

Definition at line 60 of file http_utils.h.


Function Documentation

time_t http_dateparse ( const char *  date)

Definition at line 100 of file http_utils.c.

                                        {
    time_t tmp;
    tmp = rfc1123_parse(date);
    if (tmp == -1) {
        tmp = rfc1036_parse(date);
       if (tmp == -1)
           tmp = asctime_parse(date);
    }
    return tmp;
}
int http_parse_statusline ( const char *  status_line,
http_status s 
)

Definition at line 111 of file http_utils.c.

                                                                    {
    const char *part;
    int major, minor, status_code, klass;
    /* Check they're speaking the right language */
    if (strncmp(status_line, "HTTP/", 5) != 0) {
       return -1;
    }
    /* And find out which dialect of this peculiar language
     * they can talk... */
    major = 0;
    minor = 0; 
    /* Note, we're good children, and accept leading zero's on the
     * version numbers */
    for (part = status_line + 5; *part != '\0' && isdigit(*part); part++) {
       major = major*10 + (*part-'0');
    }
    if (*part != '.') { 
       return -1;
    }
    for (part++ ; *part != '\0' && isdigit(*part); part++) {
       minor = minor*10 + (*part-'0');
    }
    if (*part != ' ') {
       return -1;
    }
    /* Skip any spaces */
    for (; *part == ' ' ; part++) /* noop */;
    /* Now for the Status-Code. part now points at the first Y in
     * "HTTP/x.x YYY". We want value of YYY... could use atoi, but
     * probably quicker this way. */
    if (!isdigit(part[0]) || !isdigit(part[1]) || !isdigit(part[2])) {
       return -1;
    }
    status_code = 100*(part[0]-'0') + 10*(part[1]-'0') + (part[2]-'0');
    klass = part[0]-'0';
    /* Skip whitespace between status-code and reason-phrase */
    for (part+=3; *part == ' ' || *part == '\t'; part++) /* noop */;
    if (*part == '\0') {
       return -1;
    }
    /* Fill in the results */
    st->major_version = major;
    st->minor_version = minor;
    st->reason_phrase = part;
    st->code = status_code;
    st->klass = klass;
    return 0;
}
void neon_debug ( int  ch,
const char *  ,
  ... 
)

Definition at line 49 of file http_utils.c.

{
    va_list params;
    if ((ch&neon_debug_mask) != ch) return;
    fflush(stdout);
    va_start(params, template);
    vfprintf(neon_debug_stream, template, params);
    va_end(params);
    if ((ch&DEBUG_FLUSH) == DEBUG_FLUSH) {
       fflush(neon_debug_stream);
    }
}
void neon_debug_init ( FILE *  stream,
int  mask 
)

Definition at line 43 of file http_utils.c.

{
    neon_debug_stream = stream;
    neon_debug_mask = mask;
}
int neon_version_minimum ( int  major,
int  minor 
)

Definition at line 92 of file http_utils.c.

{
    return 
       (NEON_VERSION_MAJOR < major) || 
       (NEON_VERSION_MINOR < minor);
}

Definition at line 87 of file http_utils.c.

{
    return version_string;
}

Variable Documentation

Definition at line 40 of file http_utils.c.