Add to git.
[rws.git] / rws_request.c
1 /* Shared object scripts.
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: rws_request.c,v 1.5 2002/12/01 14:58:02 rich Exp $
19  */
20
21 #include "config.h"
22
23 #include "cfg.h"
24 #include "rws_request.h"
25
26 struct rws_request
27 {
28   http_request http_request;
29   io_handle io;
30   const char *host_header;
31   const char *canonical_path;
32   const char *file_path;
33
34   /* These are used for retrieving configuration information.
35    * XXX These are also a huge hack which will be removed when we
36    * have a decent configuration object type in c2lib.
37    */
38   void *host;
39   void *alias;
40   const char * (*cfg_get_string) (void *, void *, const char *, const char *);
41   int (*cfg_get_int) (void *, void *, const char *, int);
42   int (*cfg_get_bool) (void *, void *, const char *, int);
43 };
44
45 rws_request
46 new_rws_request (pool pool, http_request http_request, io_handle io,
47                  const char *host_header, const char *canonical_path,
48                  const char *file_path, void *host, void *alias,
49                  const char * (*cfg_get_string)
50                  (void *, void *, const char *, const char *),
51                  int (*cfg_get_int) (void *, void *, const char *, int),
52                  int (*cfg_get_bool) (void *, void *, const char *, int))
53 {
54   rws_request p = pmalloc (pool, sizeof *p);
55
56   p->http_request = http_request;
57   p->io = io;
58   p->host_header = host_header;
59   p->canonical_path = canonical_path;
60   p->file_path = file_path;
61   p->host = host;
62   p->alias = alias;
63   p->cfg_get_string = cfg_get_string;
64   p->cfg_get_int = cfg_get_int;
65   p->cfg_get_bool = cfg_get_bool;
66
67   return p;
68 }
69
70 http_request
71 rws_request_http_request (rws_request p)
72 {
73   return p->http_request;
74 }
75
76 io_handle
77 rws_request_io (rws_request p)
78 {
79   return p->io;
80 }
81
82 const char *
83 rws_request_host_header (rws_request p)
84 {
85   return p->host_header;
86 }
87
88 const char *
89 rws_request_canonical_path (rws_request p)
90 {
91   return p->canonical_path;
92 }
93
94 const char *
95 rws_request_file_path (rws_request p)
96 {
97   return p->file_path;
98 }
99
100 const char *
101 rws_request_cfg_get_string (rws_request p,
102                             const char *key, const char *default_value)
103 {
104   return p->cfg_get_string (p->host, p->alias, key, default_value);
105 }
106
107 int
108 rws_request_cfg_get_int (rws_request p,
109                          const char *key, int default_value)
110 {
111   return p->cfg_get_int (p->host, p->alias, key, default_value);
112 }
113
114 int
115 rws_request_cfg_get_bool (rws_request p,
116                           const char *key, int default_value)
117 {
118   return p->cfg_get_bool (p->host, p->alias, key, default_value);
119 }