75 |
static void internal_error(int, int, char *); |
static void internal_error(int, int, char *); |
76 |
static void internal_error_ssl(ssl_connection *, int, char *); |
static void internal_error_ssl(ssl_connection *, int, char *); |
77 |
static HttpParameter parse_parameters(char *); |
static HttpParameter parse_parameters(char *); |
|
static int is_available(int); |
|
78 |
|
|
79 |
|
|
80 |
/** |
/** |
81 |
* A HTTP Processor module that can handle HTTP requests received |
* A naive quasi HTTP Processor module that can handle HTTP requests |
82 |
* from a client, and return responses based on those requests. |
* received from a client, and return responses based on those |
83 |
|
* requests. |
84 |
* |
* |
85 |
* This Processor delegates the actual handling of the request and |
* This Processor delegates the actual handling of the request and |
86 |
* reponse to so called cervlets, which must implement two methods; |
* reponse to so called cervlets, which must implement two methods; |
97 |
* The doGet/doPost routines act's on the COMMAND. See the |
* The doGet/doPost routines act's on the COMMAND. See the |
98 |
* cervlet.c code in this dir. for an example. |
* cervlet.c code in this dir. for an example. |
99 |
* |
* |
|
* 2) This design is based on the Java Servlet API Framework, and |
|
|
* to some extent; the Jakarta Catelina servlet engine by the very |
|
|
* talented Craig R. McClanahan and others. |
|
|
* |
|
|
* |
|
100 |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
101 |
* @author Christian Hopp, <chopp@iei.tu-clausthal.de> |
* @author Christian Hopp, <chopp@iei.tu-clausthal.de> |
102 |
* |
* |
111 |
|
|
112 |
/** |
/** |
113 |
* Process a HTTP request. This is done by dispatching to the service |
* Process a HTTP request. This is done by dispatching to the service |
114 |
* function. Before the dispatch, an alarm clock is setup for handling |
* function. |
|
* request timeout. |
|
115 |
* @param wrapper A Wrapper object wrapping the client socket connection |
* @param wrapper A Wrapper object wrapping the client socket connection |
116 |
*/ |
*/ |
117 |
void *http_processor(void *wrapper) { |
void *http_processor(void *wrapper) { |
118 |
|
|
119 |
RequestWrapper W= wrapper; |
RequestWrapper W= wrapper; |
120 |
|
|
121 |
if(! is_available(W->socket)) { |
if(! can_read(W->socket, REQUEST_TIMEOUT)) { |
|
|
|
122 |
internal_error(W->socket, SC_REQUEST_TIMEOUT, |
internal_error(W->socket, SC_REQUEST_TIMEOUT, |
123 |
"Time out when handling the Request"); |
"Time out when handling the Request"); |
124 |
goto shutdown; |
goto shutdown; |
|
|
|
125 |
} |
} |
126 |
do_service(W); |
do_service(W); |
127 |
|
|
1144 |
"</body></html>\r\n", |
"</body></html>\r\n", |
1145 |
SERVER_PROTOCOL, status, status_msg, date, server, |
SERVER_PROTOCOL, status, status_msg, date, server, |
1146 |
status_msg, status_msg, msg, SERVER_URL, server); |
status_msg, status_msg, msg, SERVER_URL, server); |
1147 |
sock_send(client, response, strlen(response), 0); |
sock_write(client, response, strlen(response)); |
1148 |
free(server); |
free(server); |
1149 |
free(date); |
free(date); |
1150 |
|
|
1206 |
|
|
1207 |
} |
} |
1208 |
|
|
|
|
|
|
/** |
|
|
* Check if data is available, if not, wait timeout seconds for data |
|
|
* to be present. |
|
|
* @param s A client socket |
|
|
* @return TRUE if data is available otherwise FALSE |
|
|
*/ |
|
|
static int is_available(int s) { |
|
|
|
|
|
fd_set rset; |
|
|
struct timeval tv; |
|
|
|
|
|
if(s < 0) |
|
|
return FALSE; |
|
|
|
|
|
FD_ZERO(&rset); |
|
|
FD_SET(s, &rset); |
|
|
tv.tv_sec= REQUEST_TIMEOUT; |
|
|
tv.tv_usec= 0; |
|
|
|
|
|
return (select(s+1, &rset, NULL, NULL, &tv)>0); |
|
|
|
|
|
} |
|
|
|
|