Add to git.
[rws.git] / process_rq.h
1 /* Request processing thread.
2  * - by Richard W.M. Jones <rich@annexia.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  * $Id: process_rq.h,v 1.7 2002/09/02 07:50:09 rich Exp $
19  */
20
21 #ifndef PROCESS_RQ_H
22 #define PROCESS_RQ_H
23
24 #ifdef HAVE_SYS_SOCKET_H
25 #include <sys/socket.h>
26 #endif
27
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31
32 #ifdef HAVE_SYS_STAT_H
33 #include <sys/stat.h>
34 #endif
35
36 #include <pool.h>
37
38 #include <pthr_pseudothread.h>
39 #include <pthr_http.h>
40 #include <pthr_iolib.h>
41
42 /* The PROCESS_RQ type is both the pseudothread object which handles
43  * the request, and also the request information structure itself.
44  */
45
46 struct process_rq
47 {
48   pseudothread pth;             /* Pseudothread handle. */
49   pool pool;                    /* Thread pool for all allocations. */
50   int sock;                     /* Socket fd. */
51   io_handle io;                 /* IO handle. */
52   http_request http_request;    /* HTTP request object. */
53   const char *host_header;      /* Host header or "default". */
54
55   /* These are used to establish context by the cfg (configuration) code. */
56   void *host;                   /* Host object. */
57   void *alias;                  /* Alias object. */
58
59   /* The various different paths.
60    *
61    * REQUESTED_PATH is the path as requested by the user (sans query
62    * string). This path is grotty, containing ".", "..", "///", etc. Do
63    * not use it, except perhaps when displaying error messages.
64    *
65    * CANONICAL_PATH is the requested path cleaned up to remove ".", ".."
66    * etc.
67    *
68    * REWRITTEN_PATH is the path after internal rewrite rules have been
69    * applied.
70    *
71    * ALIASNAME is the alias which matches this path. REMAINDER is the
72    * remaining part of the path. Thus (in theory at least), ALIASNAME +
73    * REMAINDER == CANONICAL_PATH.
74    *
75    * ROOT is the document root corresponding to the matching alias. This
76    * corresponds to the actual path of the file on disk. FILE_PATH is
77    * the full path to the actual file on disk. Thus, ROOT + "/" + REMAINDER
78    * == FILE_PATH.
79    *
80    * Directories are always followed by a "/". If a user requests a
81    * directory which isn't followed by a "/" then the path parsing code
82    * transparently issues a 301 (Permanently Moved) browser redirect
83    * including the corrected path.
84    *
85    * Example (no internal rewrite):
86    *   REQUESTED_PATH       "/cgi-bin/../docs/dir///file.html"
87    *   CANONICAL_PATH       "/docs/dir/file.html"
88    *   REWRITTEN_PATH       "/docs/dir/file.html"
89    *   ALIASNAME            "/docs/"
90    *   REMAINDER            "dir/file.html"
91    *   ROOT                 "/home/rich/mydocs"
92    *   FILE_PATH            "/home/rich/mydocs/dir/file.html"
93    *
94    * Example (with internal rewrite):
95    *   REQUESTED_PATH       "/cgi-bin/../docs/dir///file.html"
96    *   CANONICAL_PATH       "/docs/dir/file.html"
97    *   REWRITTEN_PATH       "/newdocs/dir/file.html"
98    *   ALIASNAME            "/newdocs/"
99    *   REMAINDER            "dir/file.html"
100    *   ROOT                 "/home/rich/mynewdocs"
101    *   FILE_PATH            "/home/rich/mynewdocs/dir/file.html"
102    */
103   const char *requested_path;
104   const char *canonical_path;
105   const char *rewritten_path;
106   const char *aliasname;
107   const char *remainder;
108   const char *root;
109   const char *file_path;
110
111   struct stat statbuf;          /* Stat of file. */
112 };
113
114 typedef struct process_rq *process_rq;
115
116 extern process_rq new_process_rq (int sock);
117
118 /* Define some RFC-compliant dates to represent past and future. */
119 #define DISTANT_PAST   "Thu, 01 Dec 1994 16:00:00 GMT"
120 #define DISTANT_FUTURE "Sun, 01 Dec 2030 16:00:00 GMT"
121
122 /* Headers which are sent to defeat caches. */
123 #define NO_CACHE_HEADERS "Cache-Control", "must-revalidate", "Expires", DISTANT_PAST, "Pragma", "no-cache"
124
125 #define CRLF "\r\n"
126
127 #endif /* PROCESS_RQ_H */