-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_server.h
121 lines (99 loc) · 3.22 KB
/
http_server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* ivykis, an event handling library
* Copyright (C) 2002, 2003 Lennert Buytenhek
* Dedicated to Marija Kulikova.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __IV_HTTP_SERVER_H
#define __IV_HTTP_SERVER_H
#include <iv.h>
#include <iv_list.h>
struct http_request;
struct http_request_interest;
int http_register_interest(struct http_request_interest *);
void http_unregister_interest(struct http_request_interest *);
int http_dequeue_request(struct http_request_interest *,
struct http_request **);
char *http_request_get_uri_param(struct http_request *, char *);
char *http_request_get_header_param(struct http_request *, char *);
int http_request_get_peername(struct http_request *, struct sockaddr *,
socklen_t *);
void http_request_set_status_code(struct http_request *, int);
void http_request_set_content_length(struct http_request *, int);
void http_request_set_content_type(struct http_request *, char *);
void http_request_set_server(struct http_request *, char *);
int http_request_start_reply(struct http_request *);
int http_request_write(struct http_request *, char *, size_t);
int http_request_end_reply(struct http_request *);
int http_request_steal_socket(struct http_request *, int);
void http_request_finish_request(struct http_request *);
/* internals *****************************************************************/
struct http_tuple
{
char *key;
char *value;
struct iv_list_head list;
};
struct http_request_interest
{
char *ip;
char *port;
char *method;
char *host;
char *uri;
void *cookie;
void (*handler)(void *);
struct iv_list_head list;
struct http_listening_socket *sock;
struct iv_list_head reqs;
};
#define IV_HTTP_REPLY_CONTENT_LENGTH 0
#define IV_HTTP_REPLY_CHUNKED 1
#define IV_HTTP_REPLY_CONNECTION_CLOSE 2
#define MAXREQBUF 4096
#define IV_HTTP_VERSION_0_9 9
#define IV_HTTP_VERSION_1_0 10
#define IV_HTTP_VERSION_1_1 11
struct http_request
{
/* Parsed fields. */
char *method;
char *uri;
struct iv_list_head uri_params;
char *_version;
struct iv_list_head header_params;
/* Determined fields. */
char *host;
int reply_mode;
int http_version;
int connection_close;
int accept_chunked;
/* Reply fields. */
int status_code;
int content_length;
int content_sent;
char *content_type;
char *server;
/* Internal state. */
struct iv_list_head list;
struct http_connection *conn;
char buf[MAXREQBUF];
int parse_ptr;
int read_ptr;
int end_ptr;
int done;
};
#endif