2 ashd - A Sane HTTP Daemon
3 Copyright (C) 2008 Fredrik Tolf <fredrik@dolda2000.com>
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.
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.
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/>.
28 struct htreq *mkreq(char *method, char *url, char *ver)
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;
41 void freereq(struct htreq *req)
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]);
60 void reqpreheader(struct htreq *req, char *name, char *val)
62 req->headers = srealloc(req->headers, sizeof(*req->headers) * (req->noheaders + 1));
63 memmove(req->headers + 1, req->headers, sizeof(*req->headers) * req->noheaders);
65 req->headers[0] = smalloc(sizeof(*req->headers[0]) * 2);
66 req->headers[0][0] = sstrdup(name);
67 req->headers[0][1] = sstrdup(val);
70 void reqappheader(struct htreq *req, char *name, char *val)
75 req->headers = srealloc(req->headers, sizeof(*req->headers) * req->noheaders);
76 req->headers[i] = smalloc(sizeof(*req->headers[i]) * 2);
77 req->headers[i][0] = sstrdup(name);
78 req->headers[i][1] = sstrdup(val);