wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
httpread.h
Go to the documentation of this file.
1 
6 #ifndef HTTPREAD_H
7 #define HTTPREAD_H
8 
9 /* event types (passed to callback) */
10 enum httpread_event {
11  HTTPREAD_EVENT_FILE_READY = 1, /* including reply ready */
12  HTTPREAD_EVENT_TIMEOUT = 2,
13  HTTPREAD_EVENT_ERROR = 3 /* misc. error, esp malloc error */
14 };
15 
16 
17 /* header type detected
18  * available to callback via call to httpread_reply_code_get()
19  */
20 enum httpread_hdr_type {
21  HTTPREAD_HDR_TYPE_UNKNOWN = 0, /* none of the following */
22  HTTPREAD_HDR_TYPE_REPLY = 1, /* hdr begins w/ HTTP/ */
23  HTTPREAD_HDR_TYPE_GET = 2, /* hdr begins with GET<sp> */
24  HTTPREAD_HDR_TYPE_HEAD = 3, /* hdr begins with HEAD<sp> */
25  HTTPREAD_HDR_TYPE_POST = 4, /* hdr begins with POST<sp> */
26  HTTPREAD_HDR_TYPE_PUT = 5, /* hdr begins with ... */
27  HTTPREAD_HDR_TYPE_DELETE = 6, /* hdr begins with ... */
28  HTTPREAD_HDR_TYPE_TRACE = 7, /* hdr begins with ... */
29  HTTPREAD_HDR_TYPE_CONNECT = 8, /* hdr begins with ... */
30  HTTPREAD_HDR_TYPE_NOTIFY = 9, /* hdr begins with ... */
31  HTTPREAD_HDR_TYPE_M_SEARCH = 10, /* hdr begins with ... */
32  HTTPREAD_HDR_TYPE_M_POST = 11, /* hdr begins with ... */
33  HTTPREAD_HDR_TYPE_SUBSCRIBE = 12, /* hdr begins with ... */
34  HTTPREAD_HDR_TYPE_UNSUBSCRIBE = 13, /* hdr begins with ... */
35 
36  HTTPREAD_N_HDR_TYPES /* keep last */
37 };
38 
39 
40 /* control instance -- opaque struct declaration
41  */
42 struct httpread;
43 
44 
45 /* httpread_destroy -- if h is non-NULL, clean up
46  * This must eventually be called by the application following
47  * call of the application's callback and may be called
48  * earlier if desired.
49  */
50 void httpread_destroy(struct httpread *h);
51 
52 /* httpread_create -- start a new reading session making use of eloop.
53  * The new instance will use the socket descriptor for reading (until
54  * it gets a file and not after) but will not close the socket, even
55  * when the instance is destroyed (the application must do that).
56  * Return NULL on error.
57  *
58  * Provided that httpread_create successfully returns a handle,
59  * the callback fnc is called to handle httpread_event events.
60  * The caller should do destroy on any errors or unknown events.
61  *
62  * Pass max_bytes == 0 to not read body at all (required for e.g.
63  * reply to HEAD request).
64  */
65 struct httpread * httpread_create(
66  int sd, /* descriptor of TCP socket to read from */
67  void (*cb)(struct httpread *handle, void *cookie,
68  enum httpread_event e), /* call on event */
69  void *cookie, /* pass to callback */
70  int max_bytes, /* maximum file size else abort it */
71  int timeout_seconds /* 0; or total duration timeout period */
72  );
73 
74 /* httpread_hdr_type_get -- When file is ready, returns header type.
75  */
76 enum httpread_hdr_type httpread_hdr_type_get(struct httpread *h);
77 
78 
79 /* httpread_uri_get -- When file is ready, uri_get returns (translated) URI
80  * or possibly NULL (which would be an error).
81  */
82 char *httpread_uri_get(struct httpread *h);
83 
84 /* httpread_reply_code_get -- When reply is ready, returns reply code */
85 int httpread_reply_code_get(struct httpread *h);
86 
87 
88 /* httpread_length_get -- When file is ready, returns file length. */
89 int httpread_length_get(struct httpread *h);
90 
91 /* httpread_data_get -- When file is ready, returns file content
92  * with null byte appened.
93  * Might return NULL in some error condition.
94  */
95 void * httpread_data_get(struct httpread *h);
96 
97 /* httpread_hdr_get -- When file is ready, returns header content
98  * with null byte appended.
99  * Might return NULL in some error condition.
100  */
101 char * httpread_hdr_get(struct httpread *h);
102 
103 /* httpread_hdr_line_get -- When file is ready, returns pointer
104  * to line within header content matching the given tag
105  * (after the tag itself and any spaces/tabs).
106  *
107  * The tag should end with a colon for reliable matching.
108  *
109  * If not found, returns NULL;
110  */
111 char * httpread_hdr_line_get(struct httpread *h, const char *tag);
112 
113 #endif /* HTTPREAD_H */
Definition: httpread.c:46