source: trunk/minix/commands/httpd/process.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.9 KB
Line 
1/* process.c
2 *
3 * This file is part of httpd.
4 *
5 * 02/17/1996 Michael Temari <Michael@TemWare.Com>
6 * 07/07/1996 Initial Relase Michael Temari <Michael@TemWare.Com>
7 * 12/29/2002 Michael Temari <Michael@TemWare.Com>
8 *
9 */
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <ctype.h>
13#include <stdio.h>
14#include <string.h>
15#include <stdlib.h>
16#include <time.h>
17#include <fcntl.h>
18#include <unistd.h>
19#include <errno.h>
20
21#include "config.h"
22#include "http.h"
23#include "utility.h"
24
25int processrequest(rq, rp)
26struct http_request *rq;
27struct http_reply *rp;
28{
29 /* clear out http_reply */
30 memset(rp, 0, sizeof(*rp));
31 rp->status = HTTP_STATUS_OK;
32 strcpy(rp->statusmsg, "OK");
33 rp->modtime = (time_t) -1;
34 rp->urlaccess = -1;
35 rp->size = 0;
36 rp->fd = -1;
37 rp->ofd = -1;
38 rp->pid = 0;
39
40 /* Simple requests can only be a GET */
41 if(rq->type == HTTP_REQUEST_TYPE_SIMPLE && rq->method != HTTP_METHOD_GET) {
42 rp->status = HTTP_STATUS_BAD_REQUEST;
43 strcpy(rp->statusmsg, "Bad request");
44 return(0);
45 }
46
47 /* I don't know this method */
48 if(rq->method == HTTP_METHOD_UNKNOWN) {
49 rp->status = HTTP_STATUS_NOT_IMPLEMENTED;
50 strcpy(rp->statusmsg, "Method not implemented");
51 return(0);
52 }
53
54 /* Check for access and real location of url */
55 if(police(rq, rp))
56 return(-1);
57
58 /* We're done if there was an error accessing the url */
59 if(rp->status != HTTP_STATUS_OK)
60 return(0);
61
62 /* Check to see if we have a newer version for them */
63 if(rq->method == HTTP_METHOD_GET)
64 if(rq->ifmodsince != (time_t) -1)
65 if(rq->ifmodsince < time((time_t *)NULL))
66 if(rp->modtime != (time_t) -1 && rp->modtime <= rq->ifmodsince) {
67 rp->status = HTTP_STATUS_NOT_MODIFIED;
68 strcpy(rp->statusmsg, "Not modified");
69 close(rp->fd);
70 rp->fd = -1;
71 return(0);
72 }
73
74 rp->status = HTTP_STATUS_OK;
75 strcpy(rp->statusmsg, "OK");
76
77 if(rp->size != 0)
78 rp->keepopen = rq->keepopen;
79
80 return(0);
81}
Note: See TracBrowser for help on using the repository browser.