X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Freq.c;fp=lib%2Freq.c;h=47523f39bb5201262de137badec2de21ed672881;hb=337333968e3d06cf5f1fa5198eeba3121aee467a;hp=0000000000000000000000000000000000000000;hpb=f4cdf91946475f428f3861275ce9d07f2da73a93;p=ashd.git diff --git a/lib/req.c b/lib/req.c new file mode 100644 index 0000000..47523f3 --- /dev/null +++ b/lib/req.c @@ -0,0 +1,79 @@ +/* + ashd - A Sane HTTP Daemon + Copyright (C) 2008 Fredrik Tolf + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include + +#ifdef HAVE_CONFIG_H +#include +#endif +#include +#include + +struct htreq *mkreq(char *method, char *url, char *ver) +{ + struct htreq *req; + + omalloc(req); + req->method = sstrdup(method); + req->url = sstrdup(url); + req->ver = sstrdup(ver); + req->restbuf = sstrdup(url); + req->rest = req->restbuf; + return(req); +} + +void freereq(struct htreq *req) +{ + int i; + + free(req->method); + free(req->url); + free(req->ver); + free(req->restbuf); + if(req->headers) { + for(i = 0; i < req->noheaders; i++) { + free(req->headers[i][0]); + free(req->headers[i][1]); + free(req->headers[i]); + } + free(req->headers); + } + free(req); +} + +void reqpreheader(struct htreq *req, char *name, char *val) +{ + req->headers = srealloc(req->headers, sizeof(*req->headers) * (req->noheaders + 1)); + memmove(req->headers + 1, req->headers, sizeof(*req->headers) * req->noheaders); + req->noheaders++; + req->headers[0] = smalloc(sizeof(*req->headers[0]) * 2); + req->headers[0][0] = sstrdup(name); + req->headers[0][1] = sstrdup(val); +} + +void reqappheader(struct htreq *req, char *name, char *val) +{ + int i; + + i = req->noheaders++; + req->headers = srealloc(req->headers, sizeof(*req->headers) * req->noheaders); + req->headers[i] = smalloc(sizeof(*req->headers[i]) * 2); + req->headers[i][0] = sstrdup(name); + req->headers[i][1] = sstrdup(val); +}