summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNick White <hg@njw.me.uk>2011-07-17 15:48:24 +0100
committerNick White <hg@njw.me.uk>2011-07-17 15:48:24 +0100
commit6ca2e52598ec57d7e54a46315daf1e7018b8333f (patch)
tree18213edc8baff4f12c307f83e41685ffae333e6d /util.c
parente4b78cbf607d90331d20ca3feec12c2b40f10251 (diff)
Add ip setting and improve robustness of http
Diffstat (limited to 'util.c')
-rw-r--r--util.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/util.c b/util.c
index 2cb7c99..68d1d72 100644
--- a/util.c
+++ b/util.c
@@ -33,7 +33,7 @@ static int dial(char *host, char *port) {
return srv;
}
-int get(char *host, char *path, char **buf) {
+int get(char *host, char *path, char *extrahdr, char **buf) {
size_t l, res;
int fd, i, p;
char h[1024] = "\0";
@@ -43,13 +43,13 @@ int get(char *host, char *path, char **buf) {
srv = fdopen(fd, "r+");
fprintf(srv, "GET %s HTTP/1.0\r\nUser-Agent: getgbook-"VERSION \
- " (not mozilla)\r\nHost: %s\r\n\r\n", path, host);
+ " (not mozilla)\r\n%sHost: %s\r\n\r\n", path, extrahdr, host);
fflush(srv);
while(h[0] != '\r') {
fgets(h, 1024, srv);
if(sscanf(h, "HTTP/%d.%d %d", &i, &i, &p) == 3 && p != 200)
- return 1;
+ return 0;
}
*buf = malloc(sizeof(char *) * 4096);
@@ -60,12 +60,12 @@ int get(char *host, char *path, char **buf) {
return l;
}
-int gettofile(char *url, char *savepath) {
+int gettofile(char *host, char *url, char *extrahdr, char *savepath) {
char *buf = 0;
FILE *f;
size_t i, l;
- if(!(l = get("books.google.com", url, &buf))) {
+ if(!(l = get(host, url, extrahdr, &buf))) {
fprintf(stderr, "Could not download %s\n", url);
return 1;
}