PageRenderTime 30ms CodeModel.GetById 12ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/client.h

http://github.com/nicolasff/webdis
C++ Header | 93 lines | 63 code | 26 blank | 4 comment | 0 complexity | 7878d33ae219aff96e1c64a86a6aeda2 MD5 | raw file
 1#ifndef CLIENT_H
 2#define CLIENT_H
 3
 4#include <event.h>
 5#include <arpa/inet.h>
 6#include "http_parser.h"
 7#include "websocket.h"
 8
 9struct http_header;
10struct server;
11struct cmd;
12
13typedef enum {
14	LAST_CB_NONE = 0,
15	LAST_CB_KEY = 1,
16	LAST_CB_VAL = 2} last_cb_t;
17
18typedef enum {
19	CLIENT_DISCONNECTED = -1,
20	CLIENT_OOM = -2} client_error_t;
21
22struct http_client {
23
24	int fd;
25	in_addr_t addr;
26	struct event ev;
27
28	struct worker *w;
29	struct server *s;
30
31
32	/* HTTP parsing */
33	struct http_parser parser;
34	struct http_parser_settings settings;
35	char *buffer;
36	size_t sz;
37	size_t request_sz; /* accumulated so far. */
38	last_cb_t last_cb;
39
40	/* various flags. */
41	char keep_alive;
42	char broken;
43	char is_websocket;
44	char http_version;
45	char failed_alloc;
46
47	/* HTTP data */
48	char *path;
49	size_t path_sz;
50
51	/* headers */
52	struct http_header *headers;
53	int header_count;
54
55	char *body;
56	size_t body_sz;
57
58	char *type; /* forced output content-type */
59	char *jsonp; /* jsonp wrapper */
60	char *separator; /* list separator for raw lists */
61	char *filename; /* content-disposition */
62
63	struct cmd *pub_sub;
64
65	struct ws_msg *frame; /* websocket frame */
66};
67
68struct http_client *
69http_client_new(struct worker *w, int fd, in_addr_t addr);
70
71void
72http_client_reset(struct http_client *c);
73
74void
75http_client_free(struct http_client *c);
76
77int
78http_client_read(struct http_client *c);
79
80int
81http_client_remove_data(struct http_client *c, size_t sz);
82
83int
84http_client_execute(struct http_client *c);
85
86int
87http_client_add_to_body(struct http_client *c, const char *at, size_t sz);
88
89const char *
90client_get_header(struct http_client *c, const char *key);
91
92
93#endif