poldek: poldek/vfile/vfff/http.c, poldek/vfile/vfreq.c - fixed uri...

mis mis at pld-linux.org
Fri Jul 6 00:16:45 CEST 2007


Author: mis                          Date: Thu Jul  5 22:16:45 2007 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- fixed uri escaping (#37)

---- Files affected:
poldek/poldek/vfile/vfff:
   http.c (1.8 -> 1.9) 
poldek/poldek/vfile:
   vfreq.c (1.8 -> 1.9) 

---- Diffs:

================================================================
Index: poldek/poldek/vfile/vfff/http.c
diff -u poldek/poldek/vfile/vfff/http.c:1.8 poldek/poldek/vfile/vfff/http.c:1.9
--- poldek/poldek/vfile/vfff/http.c:1.8	Mon Jul  2 17:57:19 2007
+++ poldek/poldek/vfile/vfff/http.c	Fri Jul  6 00:16:40 2007
@@ -121,18 +121,10 @@
 
 extern int vhttp_misc_base64(char *b64, int size, const char *bin);
 
-static char *make_req_line(char *buf, int size, const char *method, const char *uri) 
+static
+char *make_req_line(char *buf, int size, const char *method, const char *uri)
 {
-    char *escaped = NULL;
-    
-    if ((escaped = vfff_uri_escape(uri)))
-        uri = escaped;
-    
     n_snprintf(buf, size, "%s %s HTTP/1.1\r\n", method, uri);
-
-    if (escaped)
-        free(escaped);
-    
     return buf;
 }
 
@@ -970,8 +962,7 @@
         goto l_end;
     }
 
-    /* poor HTTP client doesn't supports Trasfer-Encodings */
-
+    /* poor HTTP client doesn't support Trasfer-Encodings */
     if (!status_code_ok(resp->code, resp->msg, rreq->uri) &&
         resp->code != HTTP_STATUS_BAD_RANGE)
         goto l_err_end;

================================================================
Index: poldek/poldek/vfile/vfreq.c
diff -u poldek/poldek/vfile/vfreq.c:1.8 poldek/poldek/vfile/vfreq.c:1.9
--- poldek/poldek/vfile/vfreq.c:1.8	Fri Oct  7 13:24:55 2005
+++ poldek/poldek/vfile/vfreq.c	Fri Jul  6 00:16:40 2007
@@ -41,7 +41,7 @@
 #include "vfile.h"
 #include "vfile_intern.h"
 
-
+char *vfff_uri_escape(const char *path);
 
 static int extr_port(char *host) 
 {
@@ -222,27 +222,25 @@
     return 1;
 }
 
-
-
 struct vf_request *vf_request_new(const char *url, const char *destpath)
 {
-    char               buf[PATH_MAX], tmp[PATH_MAX];
+    char               buf[PATH_MAX], tmp[PATH_MAX], *escaped_uri;
     const char         *proxy = NULL;
     char               *err_msg = _("%s: URL parse error\n");
     struct vf_request  *req, rreq, preq;
     int                len;
 
-    memset(&rreq, 0, sizeof(rreq));
+    memset(&r, 0, sizeof(r));
 
     //printf("**request new %s\n", url);
     snprintf(buf, sizeof(buf), "%s", url);
     
-    if (!vf_parse_url(buf, &rreq) || rreq.uri == NULL) {
+    if (!vf_parse_url(buf, &req) || rreq.uri == NULL) {
         vf_logerr(err_msg, CL_URL(url));
         return NULL;
     }
     
-    if ((proxy = get_proxy(&rreq))) {
+    if ((proxy = get_proxy(&r))) {
         char pbuf[PATH_MAX];
 
         snprintf(pbuf, sizeof(pbuf), "%s", proxy);
@@ -256,7 +254,7 @@
     
     if (destpath) {
         rreq.destpath = (char*)destpath;
-        if (!vf_request_open_destpath(&rreq))
+        if (!vf_request_open_destpath(&r))
             return NULL;
     }
     
@@ -273,16 +271,23 @@
     req->st_local_size = rreq.st_local_size;
     req->st_local_mtime = rreq.st_local_mtime;
     
-    len = n_snprintf(tmp, sizeof(tmp), "%s://%s/%s", rreq.proto, rreq.host,
-                     rreq.uri);
-    req->url = n_strdupl(tmp, len);
     req->proto = n_strdup(rreq.proto);
     req->host = n_strdup(rreq.host);
 
     len = n_snprintf(tmp, sizeof(tmp), "/%s", rreq.uri);
-    req->uri = n_strdupl(tmp, len);
 
+    /* escape URI if HTTP */
+    if (n_str_eq(req->proto, "http") && (escaped_uri = vfff_uri_escape(tmp)))
+        req->uri = escaped_uri;
+    else 
+        req->uri = n_strdupl(tmp, len);
+
+    len = n_snprintf(tmp, sizeof(tmp), "%s://%s/%s", rreq.proto, rreq.host,
+                     req->uri);
+    req->url = n_strdupl(tmp, len);
     req->port = rreq.port;
+
+    
     if (rreq.login)
         req->login = n_strdup(rreq.login);
 
@@ -356,7 +361,6 @@
     free(req);
 }
 
-
 #define xx_replace(p, q) n_cfree(&p); p = q; q = NULL; 
 
 struct vf_request *vf_request_redirto(struct vf_request *req, const char *url)
@@ -366,7 +370,6 @@
     tmpreq = vf_request_new(url, NULL);
     if (tmpreq == NULL)
         return NULL;
-
     
     if (*vfile_verbose > 1)
         vf_loginfo("Redirected to %s\n", PR_URL(tmpreq->url));
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/poldek/poldek/vfile/vfff/http.c?r1=1.8&r2=1.9&f=u
    http://cvs.pld-linux.org/poldek/poldek/vfile/vfreq.c?r1=1.8&r2=1.9&f=u



More information about the pld-cvs-commit mailing list