X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Freq.c;h=db84e55531d32bb46fd131cb247185542c95148d;hb=992ce9ef8adb25fdcc47264187450a3edb287167;hp=da367a34e4f7b2857b459c5f34e5c3b7cbf3398b;hpb=41213112d34e04d3d088600c6b5eafeaab21330c;p=ashd.git diff --git a/lib/req.c b/lib/req.c index da367a3..db84e55 100644 --- a/lib/req.c +++ b/lib/req.c @@ -89,6 +89,17 @@ char *getheader(struct hthead *head, char *name) return(NULL); } +void replrest(struct hthead *head, char *rest) +{ + char *tmp; + + /* Do not free the current rest string yet, so that the new one + * can a subpart of the old one. */ + tmp = head->rest; + head->rest = sstrdup(rest); + free(tmp); +} + void headpreheader(struct hthead *head, const char *name, const char *val) { head->headers = srealloc(head->headers, sizeof(*head->headers) * (head->noheaders + 1)); @@ -110,14 +121,11 @@ void headappheader(struct hthead *head, const char *name, const char *val) head->headers[i][1] = sstrdup(val); } -int sendreq(int sock, struct hthead *req) +int sendreq(int sock, struct hthead *req, int fd) { int ret, i; - int pfds[2]; struct charbuf buf; - if(socketpair(PF_UNIX, SOCK_DGRAM, 0, pfds)) - return(-1); bufinit(buf); bufcatstr2(buf, req->method); bufcatstr2(buf, req->url); @@ -128,15 +136,12 @@ int sendreq(int sock, struct hthead *req) bufcatstr2(buf, req->headers[i][1]); } bufcatstr2(buf, ""); - ret = sendfd(sock, pfds[0], buf.b, buf.d); + ret = sendfd(sock, fd, buf.b, buf.d); buffree(buf); - close(pfds[0]); - if(ret < 0) { - close(pfds[1]); + if(ret < 0) return(-1); - } else { - return(pfds[1]); - } + else + return(0); } int recvreq(int sock, struct hthead **reqp)