httpread.h
Go to the documentation of this file.
00001 /*
00002  * httpread - Manage reading file(s) from HTTP/TCP socket
00003  * Author: Ted Merrill
00004  * Copyright 2008 Atheros Communications
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  *
00010  * Alternatively, this software may be distributed under the terms of BSD
00011  * license.
00012  *
00013  * See README and COPYING for more details.
00014  */
00015 
00016 #ifndef HTTPREAD_H
00017 #define HTTPREAD_H
00018 
00019 /* event types (passed to callback) */
00020 enum httpread_event {
00021         HTTPREAD_EVENT_FILE_READY = 1,        /* including reply ready */
00022         HTTPREAD_EVENT_TIMEOUT = 2,
00023         HTTPREAD_EVENT_ERROR = 3      /* misc. error, esp malloc error */
00024 };
00025 
00026 
00027 /* header type detected
00028  * available to callback via call to httpread_reply_code_get()
00029  */
00030 enum httpread_hdr_type {
00031         HTTPREAD_HDR_TYPE_UNKNOWN = 0,      /* none of the following */
00032         HTTPREAD_HDR_TYPE_REPLY = 1,        /* hdr begins w/ HTTP/ */
00033         HTTPREAD_HDR_TYPE_GET = 2,          /* hdr begins with GET<sp> */
00034         HTTPREAD_HDR_TYPE_HEAD = 3,         /* hdr begins with HEAD<sp> */
00035         HTTPREAD_HDR_TYPE_POST = 4,         /* hdr begins with POST<sp> */
00036         HTTPREAD_HDR_TYPE_PUT = 5,          /* hdr begins with ... */
00037         HTTPREAD_HDR_TYPE_DELETE = 6,       /* hdr begins with ... */
00038         HTTPREAD_HDR_TYPE_TRACE = 7,        /* hdr begins with ... */
00039         HTTPREAD_HDR_TYPE_CONNECT = 8,      /* hdr begins with ... */
00040         HTTPREAD_HDR_TYPE_NOTIFY = 9,       /* hdr begins with ... */
00041         HTTPREAD_HDR_TYPE_M_SEARCH = 10,    /* hdr begins with ... */
00042         HTTPREAD_HDR_TYPE_M_POST = 11,      /* hdr begins with ... */
00043         HTTPREAD_HDR_TYPE_SUBSCRIBE = 12,   /* hdr begins with ... */
00044         HTTPREAD_HDR_TYPE_UNSUBSCRIBE = 13, /* hdr begins with ... */
00045 
00046         HTTPREAD_N_HDR_TYPES    /* keep last */
00047 };
00048 
00049 
00050 /* control instance -- opaque struct declaration
00051  */
00052 struct httpread;
00053 
00054 
00055 /* httpread_destroy -- if h is non-NULL, clean up
00056  * This must eventually be called by the application following
00057  * call of the application's callback and may be called
00058  * earlier if desired.
00059  */
00060 void httpread_destroy(struct httpread *h);
00061 
00062 /* httpread_create -- start a new reading session making use of eloop.
00063  * The new instance will use the socket descriptor for reading (until
00064  * it gets a file and not after) but will not close the socket, even
00065  * when the instance is destroyed (the application must do that).
00066  * Return NULL on error.
00067  *
00068  * Provided that httpread_create successfully returns a handle,
00069  * the callback fnc is called to handle httpread_event events.
00070  * The caller should do destroy on any errors or unknown events.
00071  *
00072  * Pass max_bytes == 0 to not read body at all (required for e.g.
00073  * reply to HEAD request).
00074  */
00075 struct httpread * httpread_create(
00076         int sd,         /* descriptor of TCP socket to read from */
00077         void (*cb)(struct httpread *handle, void *cookie,
00078                     enum httpread_event e),  /* call on event */
00079         void *cookie,    /* pass to callback */
00080         int max_bytes,          /* maximum file size else abort it */
00081         int timeout_seconds     /* 0; or total duration timeout period */
00082         );
00083 
00084 /* httpread_hdr_type_get -- When file is ready, returns header type.
00085  */
00086 enum httpread_hdr_type httpread_hdr_type_get(struct httpread *h);
00087 
00088 
00089 /* httpread_uri_get -- When file is ready, uri_get returns (translated) URI
00090  * or possibly NULL (which would be an error).
00091  */
00092 char *httpread_uri_get(struct httpread *h);
00093 
00094 /* httpread_reply_code_get -- When reply is ready, returns reply code */
00095 int httpread_reply_code_get(struct httpread *h);
00096 
00097 
00098 /* httpread_length_get -- When file is ready, returns file length. */
00099 int httpread_length_get(struct httpread *h);
00100 
00101 /* httpread_data_get -- When file is ready, returns file content
00102  * with null byte appened.
00103  * Might return NULL in some error condition.
00104  */
00105 void * httpread_data_get(struct httpread *h);
00106 
00107 /* httpread_hdr_get -- When file is ready, returns header content
00108  * with null byte appended.
00109  * Might return NULL in some error condition.
00110  */
00111 char * httpread_hdr_get(struct httpread *h);
00112 
00113 /* httpread_hdr_line_get -- When file is ready, returns pointer
00114  * to line within header content matching the given tag
00115  * (after the tag itself and any spaces/tabs).
00116  *
00117  * The tag should end with a colon for reliable matching.
00118  *
00119  * If not found, returns NULL;
00120  */
00121 char * httpread_hdr_line_get(struct httpread *h, const char *tag);
00122 
00123 #endif /* HTTPREAD_H */


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:33:20