diff options
author | Nick White <git@njw.me.uk> | 2012-07-10 23:09:23 +0100 |
---|---|---|
committer | Nick White <git@njw.me.uk> | 2012-07-10 23:09:23 +0100 |
commit | 80afa0fb239cdc9b593cd61f322b2b916921d68d (patch) | |
tree | ec0f447cf55f9f2e44b34390fca3aa155005f304 /util.c | |
parent | 94ec3569e3c42693045ee33c36152526cdf46f78 (diff) |
Make HTTP interface more regular
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -114,6 +114,21 @@ int get(char *host, char *path, char *sendcookie, char *savecookie, char **body) return request(host, h, savecookie, body); } +int post(char *host, char *path, char *sendcookie, char *savecookie, char *data, char **body) { + char h[BUFSIZ] = ""; + char c[COOKIEMAX] = ""; + + if(sendcookie && sendcookie[0]) + snprintf(c, COOKIEMAX, "\r\nCookie: %s", sendcookie); + snprintf(h, BUFSIZ, "POST %s HTTP/1.0\r\nUser-Agent: getxbook-"VERSION \ + " (not mozilla)\r\nContent-Length: %d\r\n" \ + "Content-Type: application/x-www-form-urlencoded\r\n" \ + "Host: %s%s\r\n\r\n%s\r\n", + path, (int)strlen(data), host, c, data); + + return request(host, h, savecookie, body); +} + int gettofile(char *host, char *url, char *sendcookie, char *savecookie, char *savepath) { char *buf = 0; FILE *f; @@ -140,18 +155,6 @@ int gettofile(char *host, char *url, char *sendcookie, char *savecookie, char *s return 0; } -int post(char *host, char *path, char *data, char **body) { - char h[BUFSIZ] = ""; - - snprintf(h, BUFSIZ, "POST %s HTTP/1.0\r\nUser-Agent: getxbook-"VERSION \ - " (not mozilla)\r\nContent-Length: %d\r\n" \ - "Content-Type: application/x-www-form-urlencoded\r\n" \ - "Host: %s\r\n\r\n%s\r\n", - path, (int)strlen(data), host, data); - - return request(host, h, NULL, body); -} - int renameifjpg(char *path) { FILE *f; char *newpath, *c; |