1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
5 * Copyright (C) 2001-2010, Eduardo Silva P. <edsiper@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "scheduler.h"
30 #define MK_REQUEST_DEFAULT_PAGE "<HTML><BODY><H1>%s</H1>%s<BR><HR><ADDRESS>%s</ADDRESS></BODY></HTML>"
32 /* Handle index file names: index.* */
33 #define MAX_INDEX_NAME 50
36 char indexname
[MAX_INDEX_NAME
];
37 struct indexfile
*next
;
40 #define MK_CRLF "\r\n"
41 #define MK_ENDBLOCK "\r\n\r\n"
44 mk_pointer mk_endblock
;
47 #define RH_ACCEPT "Accept:"
48 #define RH_ACCEPT_CHARSET "Accept-Charset:"
49 #define RH_ACCEPT_ENCODING "Accept-Encoding:"
50 #define RH_ACCEPT_LANGUAGE "Accept-Language:"
51 #define RH_CONNECTION "Connection:"
52 #define RH_COOKIE "Cookie:"
53 #define RH_CONTENT_LENGTH "Content-Length:"
54 #define RH_CONTENT_RANGE "Content-Range:"
55 #define RH_CONTENT_TYPE "Content-type:"
56 #define RH_IF_MODIFIED_SINCE "If-Modified-Since:"
57 #define RH_HOST "Host:"
58 #define RH_LAST_MODIFIED "Last-Modified:"
59 #define RH_LAST_MODIFIED_SINCE "Last-Modified-Since:"
60 #define RH_REFERER "Referer:"
61 #define RH_RANGE "Range:"
62 #define RH_USER_AGENT "User-Agent:"
64 mk_pointer mk_rh_accept
;
65 mk_pointer mk_rh_accept_charset
;
66 mk_pointer mk_rh_accept_encoding
;
67 mk_pointer mk_rh_accept_language
;
68 mk_pointer mk_rh_connection
;
69 mk_pointer mk_rh_cookie
;
70 mk_pointer mk_rh_content_length
;
71 mk_pointer mk_rh_content_range
;
72 mk_pointer mk_rh_content_type
;
73 mk_pointer mk_rh_if_modified_since
;
74 mk_pointer mk_rh_host
;
75 mk_pointer mk_rh_last_modified
;
76 mk_pointer mk_rh_last_modified_since
;
77 mk_pointer mk_rh_referer
;
78 mk_pointer mk_rh_range
;
79 mk_pointer mk_rh_user_agent
;
81 /* Aqui se registran temporalmente los
82 parametros de una peticion */
83 #define MAX_REQUEST_METHOD 10
84 #define MAX_REQUEST_URI 1025
85 #define MAX_REQUEST_PROTOCOL 10
86 #define MAX_SCRIPTALIAS 3
88 #define MK_REQUEST_STATUS_INCOMPLETE -1
89 #define MK_REQUEST_STATUS_COMPLETED 0
94 #define EXIT_PCONNECTION 24
98 struct client_request
*first
;
99 struct client_request
*last
;
102 struct client_request
104 int pipelined
; /* Pipelined request */
106 int counter_connections
; /* Count persistent connections */
107 int status
; /* Request status */
108 char *body
; /* Original request sent */
118 struct request
*request
; /* Parsed request */
119 struct client_request
*next
;
122 pthread_key_t request_index
;
128 int status
; /* 0: not found, 1: found = skip! */
129 struct header_toc
*next
;
132 /* Request plugin Handler, each request can be handled by
133 * several plugins, we handle list in a simple list */
137 struct handler
*next
;
144 int pipelined
; /* Pipelined request */
147 /*----First header of client request--*/
150 mk_pointer uri
; /* original request */
151 char *uri_processed
; /* processed request */
155 mk_pointer protocol_p
;
157 /* If request specify Connection: close, Monkey will
158 * close the connection after send the response, by
159 * default this var is set to VAR_OFF;
163 /*---Request headers--*/
166 mk_pointer accept_language
;
167 mk_pointer accept_encoding
;
168 mk_pointer accept_charset
;
169 mk_pointer content_type
;
170 mk_pointer connection
;
173 mk_pointer if_modified_since
;
174 mk_pointer last_modified_since
;
178 mk_pointer user_agent
;
179 /*---------------------*/
182 mk_pointer post_variables
;
183 /*-----------------*/
186 mk_pointer real_path
; /* Absolute real path */
187 char *user_uri
; /* ~user/...path */
188 mk_pointer query_string
; /* ?... */
190 char *virtual_user
; /* Virtualhost user */
191 char *script_filename
;
193 int user_home
; /* user_home request(VAR_ON/VAR_OFF) */
199 /* file descriptors */
202 struct file_info
*file_info
;
203 struct host
*host_conf
;
204 struct header_values
*headers
; /* headers response */
205 struct request
*next
;
211 /* Plugin handlers */
212 struct plugin
*handled_by
;
218 mk_pointer
*status_p
;
220 /* Length of the content to send */
223 /* Private value, real length of the file requested */
227 int pconnections_left
;
229 int transfer_encoding
;
232 time_t last_modified
;
233 mk_pointer content_type
;
237 struct request
*mk_request_parse(struct client_request
*cr
);
238 int mk_request_process(struct client_request
*cr
, struct request
*s_request
);
239 mk_pointer
mk_request_index(char *pathfile
);
242 /* Custom HTML Page for errors */
243 mk_pointer
*mk_request_set_default_page(char *title
, mk_pointer message
,
246 int mk_request_header_process(struct request
*sr
);
247 mk_pointer
mk_request_header_find(struct header_toc
*toc
, int toc_len
,
248 char *request_body
, mk_pointer header
);
250 void mk_request_error(int http_status
, struct client_request
*cr
,
253 struct request
*mk_request_alloc();
254 void mk_request_free_list(struct client_request
*cr
);
255 void mk_request_free(struct request
*sr
);
257 struct client_request
*mk_request_client_create(int socket
);
258 struct client_request
*mk_request_client_get(int socket
);
259 void mk_request_client_remove(int socket
);
261 void mk_request_init_error_msgs();
263 int mk_handler_read(int socket
, struct client_request
*cr
);
264 int mk_handler_write(int socket
, struct client_request
*cr
);
267 struct header_toc
*mk_request_header_toc_create(int len
);
268 void mk_request_header_toc_parse(struct header_toc
*toc
, int toc_len
,
269 char *data
, int len
);
271 void mk_request_ka_next(struct client_request
*cr
);