summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2012-07-10 23:09:23 +0100
committerNick White <git@njw.me.uk>2012-07-10 23:09:23 +0100
commit80afa0fb239cdc9b593cd61f322b2b916921d68d (patch)
treeec0f447cf55f9f2e44b34390fca3aa155005f304
parent94ec3569e3c42693045ee33c36152526cdf46f78 (diff)
Make HTTP interface more regular
-rw-r--r--getabook.c2
-rw-r--r--util.c27
-rw-r--r--util.h4
3 files changed, 18 insertions, 15 deletions
diff --git a/getabook.c b/getabook.c
index 0ad6944..d923029 100644
--- a/getabook.c
+++ b/getabook.c
@@ -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);
diff --git a/util.c b/util.c
index 54a0a64..4130188 100644
--- a/util.c
+++ b/util.c
@@ -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;
diff --git a/util.h b/util.h
index af05560..35bbd74 100644
--- a/util.h
+++ b/util.h
@@ -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);