wpa_supplicant / hostapd 2.0

httpread.h

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