wok-next rev 19232
httpfs-fuse: add status 301 supprot
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Jun 25 11:48:21 2016 +0200 (2016-06-25) |
parents | 140b8603135c |
children | ff90a1630a13 |
files | httpfs-fuse/receipt httpfs-fuse/stuff/httpfs.u |
line diff
1.1 --- a/httpfs-fuse/receipt Fri Jun 24 19:59:40 2016 +0100 1.2 +++ b/httpfs-fuse/receipt Sat Jun 25 11:48:21 2016 +0200 1.3 @@ -18,9 +18,8 @@ 1.4 # Rules to configure and make the package. 1.5 compile_rules() 1.6 { 1.7 - cd $src 1.8 - mkdir -p $DESTDIR/usr/bin \ 1.9 - $DESTDIR/usr/share/boot 1.10 + patch -p0 < $stuff/httpfs.u 1.11 + mkdir -p $DESTDIR/usr/bin $DESTDIR/usr/share/boot 1.12 . ./make_httpfs && cp -a httpfs $DESTDIR/usr/bin && 1.13 cp -a static_uclibc/httpfs $DESTDIR/usr/share/boot/httpfs-static 1.14 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/httpfs-fuse/stuff/httpfs.u Sat Jun 25 11:48:21 2016 +0200 2.3 @@ -0,0 +1,75 @@ 2.4 +--- httpfs.c 2.5 ++++ httpfs.c 2.6 +@@ -313,6 +313,7 @@ 2.7 + struct timeval timeout; 2.8 + int bytes, status; 2.9 + 2.10 ++moved: 2.11 + #ifdef USE_SSL 2.12 + if (protocol == PROTO_HTTPS) { 2.13 + /* Make SSL connection. */ 2.14 +@@ -371,6 +372,27 @@ 2.15 + #endif 2.16 + 2.17 + (void) sscanf(buf, "HTTP/1.1 %d ", &status); 2.18 ++ if (status == 301 || status == 302) { 2.19 ++ static int movedcnt = 0; 2.20 ++ b = strstr(buf,"Location:"); 2.21 ++ if (b != NULL && ++movedcnt < 5) { 2.22 ++ char *eol = strchr(b, '\r'); 2.23 ++ b = strstr(b,"http"); 2.24 ++ if (eol == NULL || b == NULL) 2.25 ++ goto notmoved; 2.26 ++ *eol = 0; 2.27 ++ fprintf(stderr, "%s: HEAD (read) Status %d moved to %s\n", 2.28 ++ argv0, status, b); 2.29 ++ protocol = parseURL(b, host, &file_name, &port); 2.30 ++ if (protocol == -1) 2.31 ++ goto notmoved; 2.32 ++ close(sockfd); 2.33 ++ sockfd = open_client_socket(host, port); 2.34 ++ if (sockfd >= 0) 2.35 ++ goto moved; 2.36 ++ } 2.37 ++ } 2.38 ++notmoved: 2.39 + if (status != 200) { 2.40 + fprintf(stderr, "%s: HEAD (read) failed with Status %d\n", argv0, status); 2.41 + return -1; 2.42 +@@ -892,6 +914,7 @@ 2.43 + struct stat mpstat; 2.44 + int sr; 2.45 + char* ri; 2.46 ++ char* s; 2.47 + char* fusev[4]; 2.48 + 2.49 + argv0 = argv[0]; 2.50 +@@ -911,6 +934,14 @@ 2.51 + if (sockfd < 0) 2.52 + return 1; 2.53 + 2.54 ++ s = httpfs_path; 2.55 ++ ri = rindex(file_name, '/'); 2.56 ++ if (ri == (char *) 0) { 2.57 ++ ri = file_name; 2.58 ++ *s++ = '/'; 2.59 ++ } 2.60 ++ strcpy(s, ri); 2.61 ++ 2.62 + if (getSize() != 0) 2.63 + return 1; 2.64 + 2.65 +@@ -930,13 +961,6 @@ 2.66 + return 1; 2.67 + } 2.68 + 2.69 +- ri = rindex(file_name, '/'); 2.70 +- if (ri == (char *) 0) { 2.71 +- httpfs_path[0] = '/'; 2.72 +- strcpy(&httpfs_path[1], file_name); 2.73 +- } else 2.74 +- strcpy(httpfs_path, ri); 2.75 +- 2.76 + fusev[0] = argv0; 2.77 + fusev[1] = "-o"; 2.78 + fusev[2] = "nonempty";