Repository navigation
Expand file tree
/
Copy pathprocess.c
More file actions
81 lines (71 loc) · 1.93 KB
/
Copy pathprocess.c
File metadata and controls
81 lines (71 loc) · 1.93 KB
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
/* process.c
*
* This file is part of httpd.
*
* 02/17/1996 Michael Temari <Michael@TemWare.Com>
* 07/07/1996 Initial Relase Michael Temari <Michael@TemWare.Com>
* 12/29/2002 Michael Temari <Michael@TemWare.Com>
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "config.h"
#include "http.h"
#include "utility.h"
int processrequest(rq, rp)
struct http_request *rq;
struct http_reply *rp;
{
/* clear out http_reply */
memset(rp, 0, sizeof(*rp));
rp->status = HTTP_STATUS_OK;
strcpy(rp->statusmsg, "OK");
rp->modtime = (time_t) -1;
rp->urlaccess = -1;
rp->size = 0;
rp->fd = -1;
rp->ofd = -1;
rp->pid = 0;
/* Simple requests can only be a GET */
if(rq->type == HTTP_REQUEST_TYPE_SIMPLE && rq->method != HTTP_METHOD_GET) {
rp->status = HTTP_STATUS_BAD_REQUEST;
strcpy(rp->statusmsg, "Bad request");
return(0);
}
/* I don't know this method */
if(rq->method == HTTP_METHOD_UNKNOWN) {
rp->status = HTTP_STATUS_NOT_IMPLEMENTED;
strcpy(rp->statusmsg, "Method not implemented");
return(0);
}
/* Check for access and real location of url */
if(police(rq, rp))
return(-1);
/* We're done if there was an error accessing the url */
if(rp->status != HTTP_STATUS_OK)
return(0);
/* Check to see if we have a newer version for them */
if(rq->method == HTTP_METHOD_GET)
if(rq->ifmodsince != (time_t) -1)
if(rq->ifmodsince < time((time_t *)NULL))
if(rp->modtime != (time_t) -1 && rp->modtime <= rq->ifmodsince) {
rp->status = HTTP_STATUS_NOT_MODIFIED;
strcpy(rp->statusmsg, "Not modified");
close(rp->fd);
rp->fd = -1;
return(0);
}
rp->status = HTTP_STATUS_OK;
strcpy(rp->statusmsg, "OK");
if(rp->size != 0)
rp->keepopen = rq->keepopen;
return(0);
}