93 |
* found in the URL it's asumed to be the PATHINFO. In other words |
* found in the URL it's asumed to be the PATHINFO. In other words |
94 |
* this processor perceive an URL as: |
* this processor perceive an URL as: |
95 |
* |
* |
96 |
* /COMMAND?args/PATHINFO |
* /COMMAND?QUERYSTRING/PATHINFO |
97 |
* |
* |
98 |
* The doGet/doPost routines act's on the COMMAND. See the |
* The doGet/doPost routines act's on the COMMAND. See the |
99 |
* cervlet.c code in this dir. for an example. |
* cervlet.c code in this dir. for an example. |
135 |
/** |
/** |
136 |
* Process a HTTP request. This is done by dispatching to the service |
* Process a HTTP request. This is done by dispatching to the service |
137 |
* function. |
* function. |
138 |
* @param s A Socket_T object wrapping the client socket connection |
* @param s A Socket_T representing the client connection |
139 |
*/ |
*/ |
140 |
void *http_processor(void *s) { |
void *http_processor(void *s) { |
141 |
|
|
213 |
* actual response to the client is done in the service function, |
* actual response to the client is done in the service function, |
214 |
* which will call the private function send_response. Cervlets |
* which will call the private function send_response. Cervlets |
215 |
* should use this function (i.e. out_print) for sending a response, |
* should use this function (i.e. out_print) for sending a response, |
216 |
* and never use the HttpResponse outputstream directly. |
* and never use the HttpResponse Socket directly to send data. |
217 |
* |
* |
218 |
* Despite the above warning, IF the HttpResponse.outputstream was |
* Despite the above warning, IF the HttpResponse.socket was used |
219 |
* used directly by a cervlet THEN the cervlet MUST set the |
* directly by a cervlet THEN the cervlet MUST set the is_committed |
220 |
* is_committed flag in the HttpResponse object and is responsible for |
* flag in the HttpResponse object and is responsible for sending all |
221 |
* sending all HTTP headers and content by itself. |
* HTTP headers and content by itself. |
222 |
* @param res HttpResponse object |
* @param res HttpResponse object |
223 |
* @param m A formated string to be sent to the client |
* @param m A formated string to be sent to the client |
224 |
*/ |
*/ |
396 |
|
|
397 |
*buf=0; |
*buf=0; |
398 |
|
|
399 |
for(p= res->headers; p && ((b-buf)>RES_STRLEN); p= p->next) { |
for(p= res->headers; p; p= p->next) { |
400 |
|
|
401 |
b+= snprintf(b, STRLEN-(b-buf),"%s: %s\r\n", p->name, p->value); |
b+= snprintf(b, STRLEN-(b-buf),"%s: %s\r\n", p->name, p->value); |
402 |
|
|
519 |
|
|
520 |
if(is_authenticated(req, res)) { |
if(is_authenticated(req, res)) { |
521 |
|
|
522 |
if(!strcmp(req->method, METHOD_GET)) { |
if(IS(req->method, METHOD_GET)) { |
523 |
|
|
524 |
Impl.doGet(req, res); |
Impl.doGet(req, res); |
525 |
|
|
526 |
} |
} |
527 |
else if(!strcmp(req->method, METHOD_POST)) { |
else if(IS(req->method, METHOD_POST)) { |
528 |
|
|
529 |
Impl.doPost(req, res); |
Impl.doPost(req, res); |
530 |
|
|
587 |
Socket_T S= res->S; |
Socket_T S= res->S; |
588 |
|
|
589 |
if(!res->is_committed) { |
if(!res->is_committed) { |
590 |
|
|
591 |
char date[STRLEN]; |
char date[STRLEN]; |
592 |
char server[STRLEN]; |
char server[STRLEN]; |
593 |
char *headers= get_headers(res); |
char *headers= get_headers(res); |
671 |
|
|
672 |
/** |
/** |
673 |
* Returns a new HttpResponse object wrapping a default response. Use |
* Returns a new HttpResponse object wrapping a default response. Use |
674 |
* set_XXX methods to change the object. |
* the set_XXX methods to change the object. |
675 |
*/ |
*/ |
676 |
static HttpResponse create_HttpResponse(Socket_T S) { |
static HttpResponse create_HttpResponse(Socket_T S) { |
677 |
|
|
710 |
if(! socket_readln(S, line, sizeof(line))) |
if(! socket_readln(S, line, sizeof(line))) |
711 |
break; |
break; |
712 |
|
|
713 |
if(!strcmp(line, "\r\n") || !strcmp(line, "\n")) |
if(IS(line, "\r\n") || IS(line, "\n")) |
714 |
break; |
break; |
715 |
|
|
716 |
if( NULL != (value= strchr(line, ':'))) { |
if( NULL != (value= strchr(line, ':'))) { |
751 |
int alloc= FALSE; |
int alloc= FALSE; |
752 |
char *query_string= NULL; |
char *query_string= NULL; |
753 |
|
|
754 |
if(!strcmp(req->method, METHOD_POST)) { |
if(IS(req->method, METHOD_POST)) { |
755 |
|
|
756 |
Socket_T S= req->S; |
Socket_T S= req->S; |
757 |
|
|
772 |
|
|
773 |
} |
} |
774 |
|
|
775 |
} else if(!strcmp(req->method, METHOD_GET)) { |
} else if(IS(req->method, METHOD_GET)) { |
776 |
|
|
777 |
char *p; |
char *p; |
778 |
|
|
818 |
|
|
819 |
if(res->headers)destroy_entry(res->headers); |
if(res->headers)destroy_entry(res->headers); |
820 |
memset(res->outputbuffer, 0, res->bufsize); |
memset(res->outputbuffer, 0, res->bufsize); |
821 |
|
res->bufused= 0; |
822 |
res->headers= NULL; /* Release Pragma */ |
res->headers= NULL; /* Release Pragma */ |
823 |
|
|
824 |
} |
} |