libtools
http.h
Go to the documentation of this file.
1 
20 #ifndef __TOOLS_HTTP_H
21 #define __TOOLS_HTTP_H
22 
23 #include <stddef.h>
24 
31 /*------------------------------------------------------------------------*/
32 
34 typedef enum http_method {
44 
45 /*------------------------------------------------------------------------*/
46 
48 typedef enum http_status {
60 
61 /*------------------------------------------------------------------------*/
62 
64 typedef enum http_header_type {
68 
70 typedef struct http_header {
72  char *name;
73 
76 
78  union {
80  char *s;
81 
83  int i;
84  } val;
86 
92 #define HTTP_HEADER_STRING(n, v) \
93  { .type = HTTP_HEADER_STRING, .name = (n), .val.s = (v), }
94 
100 #define HTTP_HEADER_INT(n, v) \
101  { .type = HTTP_HEADER_INT, .name = (n), .val.i = (v), }
102 
103 /*------------------------------------------------------------------------*/
104 
110 #define HTTP_ERROR(x) ((x) != HTTP_SUCCESS)
111 
112 /*------------------------------------------------------------------------*/
113 
123 typedef int (*http_request_cb_t)(http_method_t m, const char *path, const char *ver, void *priv);
124 
134 typedef int (*http_reply_cb_t)(const char *ver, int code, const char *msg, void *priv);
135 
144 typedef int (*http_header_cb_t)(const char *name, const char *value, void *priv);
145 
146 /*------------------------------------------------------------------------*/
147 
161 http_status_t http_request_send(int sockfd, http_method_t method, const char *path, const char *ver, http_header_t hdr[], size_t count);
162 
172 http_status_t http_request_recv(int sockfd, http_request_cb_t request_cb, http_header_cb_t header_cb, void *priv);
173 
186 http_status_t http_reply_send(int sockfd, const char *ver, int code, const char *desc, http_header_t hdr[], size_t count);
187 
198 http_status_t http_reply_recv(int sockfd, http_reply_cb_t reply_cb, http_header_cb_t header_cb, void *priv);
199 
202 #endif /* __TOOLS_HTTP_H */
Definition: http.h:40
Definition: http.h:38
Definition: http.h:54
int(* http_header_cb_t)(const char *name, const char *value, void *priv)
pointer to a callback function to process header
Definition: http.h:144
http_status_t http_reply_recv(int sockfd, http_reply_cb_t reply_cb, http_header_cb_t header_cb, void *priv)
read HTTP reply from socket and parse it
Definition: http.h:51
http_status_t http_request_send(int sockfd, http_method_t method, const char *path, const char *ver, http_header_t hdr[], size_t count)
send HTTP request by socket
char * name
name of header
Definition: http.h:72
Definition: http.h:41
http_header_type_t type
type of header
Definition: http.h:75
int(* http_reply_cb_t)(const char *ver, int code, const char *msg, void *priv)
pointer to a callback function to process reply
Definition: http.h:134
Definition: http.h:50
http_status_t http_reply_send(int sockfd, const char *ver, int code, const char *desc, http_header_t hdr[], size_t count)
send HTTP reply to socket
Definition: http.h:53
int i
value is a integer
Definition: http.h:83
Definition: http.h:39
int(* http_request_cb_t)(http_method_t m, const char *path, const char *ver, void *priv)
pointer to a callback function to process request
Definition: http.h:123
enum http_status http_status_t
HTTP status code.
Definition: http.h:42
struct http_header http_header_t
HTTP header type.
char * s
value is a string
Definition: http.h:80
enum http_method http_method_t
HTTP methods, see rfc2616.
http_header_type
HTTP header values type.
Definition: http.h:64
#define HTTP_HEADER_STRING(n, v)
define HTTP header name with string value
Definition: http.h:92
Definition: http.h:58
#define HTTP_HEADER_INT(n, v)
define HTTP header name with integer value
Definition: http.h:100
http_method
HTTP methods, see rfc2616.
Definition: http.h:34
enum http_header_type http_header_type_t
HTTP header values type.
Definition: http.h:37
Definition: http.h:52
union http_header::@0 val
header value
Definition: http.h:56
http_status
HTTP status code.
Definition: http.h:48
Definition: http.h:55
Definition: http.h:35
Definition: http.h:49
Definition: http.h:36
HTTP header type.
Definition: http.h:70
Definition: http.h:57
http_status_t http_request_recv(int sockfd, http_request_cb_t request_cb, http_header_cb_t header_cb, void *priv)
read HTTP request from socket and parse it