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 | |
parent | 94ec3569e3c42693045ee33c36152526cdf46f78 (diff) |
Make HTTP interface more regular
-rw-r--r-- | getabook.c | 2 | ||||
-rw-r--r-- | util.c | 27 | ||||
-rw-r--r-- | util.h | 4 |
3 files changed, 18 insertions, 15 deletions
@@ -114,7 +114,7 @@ int getpageurls(int pagenum) { strncpy(url, "/gp/search-inside/service-data", URLMAX); snprintf(query, URLMAX, "method=goToPage&asin=%s&page=%d", bookid, pagenum); - if(!post("www.amazon.com", url, query, &buf)) + if(!post("www.amazon.com", url, NULL, NULL, query, &buf)) return 1; fillurls(buf); @@ -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; @@ -1,7 +1,7 @@ /* See COPYING file for copyright and license details. */ #define COOKIEMAX 1024 int dial(char *host, char *port); -int get(char *host, char *path, char *sendcookie, char *savecookie, char **buf); +int get(char *host, char *path, char *sendcookie, char *savecookie, char **body); +int post(char *host, char *path, char *sendcookie, char *savecookie, char *data, char **body); int gettofile(char *host, char *url, char *sendcookie, char *savecookie, char *savepath); -int post(char *host, char *path, char *data, char **buf); int renameifjpg(char *path); |