Commit | Line | Data |
---|---|---|
33733396 FT |
1 | /* |
2 | ashd - A Sane HTTP Daemon | |
3 | Copyright (C) 2008 Fredrik Tolf <fredrik@dolda2000.com> | |
4 | ||
5 | This program is free software: you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation, either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #include <stdlib.h> | |
20 | #include <string.h> | |
21 | ||
22 | #ifdef HAVE_CONFIG_H | |
23 | #include <config.h> | |
24 | #endif | |
25 | #include <utils.h> | |
26 | #include <req.h> | |
27 | ||
28 | struct htreq *mkreq(char *method, char *url, char *ver) | |
29 | { | |
30 | struct htreq *req; | |
31 | ||
32 | omalloc(req); | |
33 | req->method = sstrdup(method); | |
34 | req->url = sstrdup(url); | |
35 | req->ver = sstrdup(ver); | |
36 | req->restbuf = sstrdup(url); | |
37 | req->rest = req->restbuf; | |
38 | return(req); | |
39 | } | |
40 | ||
41 | void freereq(struct htreq *req) | |
42 | { | |
43 | int i; | |
44 | ||
45 | free(req->method); | |
46 | free(req->url); | |
47 | free(req->ver); | |
48 | free(req->restbuf); | |
49 | if(req->headers) { | |
50 | for(i = 0; i < req->noheaders; i++) { | |
51 | free(req->headers[i][0]); | |
52 | free(req->headers[i][1]); | |
53 | free(req->headers[i]); | |
54 | } | |
55 | free(req->headers); | |
56 | } | |
57 | free(req); | |
58 | } | |
59 | ||
66987955 FT |
60 | char *getheader(struct htreq *req, char *name) |
61 | { | |
62 | int i; | |
63 | ||
64 | for(i = 0; i < req->noheaders; i++) { | |
65 | if(!strcasecmp(req->headers[i][0], name)) | |
66 | return(req->headers[i][1]); | |
67 | } | |
68 | return(NULL); | |
69 | } | |
70 | ||
33733396 FT |
71 | void reqpreheader(struct htreq *req, char *name, char *val) |
72 | { | |
73 | req->headers = srealloc(req->headers, sizeof(*req->headers) * (req->noheaders + 1)); | |
74 | memmove(req->headers + 1, req->headers, sizeof(*req->headers) * req->noheaders); | |
75 | req->noheaders++; | |
76 | req->headers[0] = smalloc(sizeof(*req->headers[0]) * 2); | |
77 | req->headers[0][0] = sstrdup(name); | |
78 | req->headers[0][1] = sstrdup(val); | |
79 | } | |
80 | ||
81 | void reqappheader(struct htreq *req, char *name, char *val) | |
82 | { | |
83 | int i; | |
84 | ||
85 | i = req->noheaders++; | |
86 | req->headers = srealloc(req->headers, sizeof(*req->headers) * req->noheaders); | |
87 | req->headers[i] = smalloc(sizeof(*req->headers[i]) * 2); | |
88 | req->headers[i][0] = sstrdup(name); | |
89 | req->headers[i][1] = sstrdup(val); | |
90 | } |