]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
make url_convert_hex not have to xstrdup the buffer
authorwessels <>
Wed, 10 Apr 1996 09:53:59 +0000 (09:53 +0000)
committerwessels <>
Wed, 10 Apr 1996 09:53:59 +0000 (09:53 +0000)
src/gopher.cc
src/url.cc

index b39f10b02bab54533bdb68c1cbe4d9015ea74324..72f7e05802314b33d3dc7662223a89db6eaf7496 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gopher.cc,v 1.21 1996/04/09 23:28:33 wessels Exp $ */
+/* $Id: gopher.cc,v 1.22 1996/04/10 03:53:59 wessels Exp $ */
 
 /*
  * DEBUG: Section 10          gopher: GOPHER
@@ -188,19 +188,18 @@ int gopher_url_parser(url, host, port, type_id, request)
      char *type_id;
      char *request;
 {
-    static char atypebuf[MAX_URL];
+    static char proto[MAX_URL];
     static char hostbuf[MAX_URL];
-    char *tmp = NULL;
     int t;
 
-    atypebuf[0] = hostbuf[0] = '\0';
+    proto[0] = hostbuf[0] = '\0';
     host[0] = request[0] = '\0';
     (*port) = 0;
     (*type_id) = 0;
 
-    t = sscanf(url, "%[a-zA-Z]://%[^/]/%c%s", atypebuf, hostbuf,
+    t = sscanf(url, "%[a-zA-Z]://%[^/]/%c%s", proto, hostbuf,
        type_id, request);
-    if ((t < 2) || strcasecmp(atypebuf, "gopher")) {
+    if ((t < 2) || strcasecmp(proto, "gopher")) {
        return -1;
     } else if (t == 2) {
        (*type_id) = GOPHER_DIRECTORY;
@@ -209,9 +208,7 @@ int gopher_url_parser(url, host, port, type_id, request)
        request[0] = '\0';
     } else {
        /* convert %xx to char */
-       tmp = url_convert_hex(request);
-       strncpy(request, tmp, MAX_URL);
-       safe_free(tmp);
+       (void) url_convert_hex(request, 0);
     }
 
     host[0] = '\0';
index 60b8f0fa9419e588499d3c8360943b2acb3f5624..98dd5e575d49dd8d2dc1e7f5783dacf5f8b2ad6e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: url.cc,v 1.6 1996/04/04 01:30:53 wessels Exp $ */
+/* $Id: url.cc,v 1.7 1996/04/10 03:54:00 wessels Exp $ */
 
 /* 
  * DEBUG: Section 23          url
@@ -14,31 +14,29 @@ static char hex[17] = "0123456789abcdef";
 /* convert %xx in url string to a character 
  * Allocate a new string and return a pointer to converted string */
 
-char *url_convert_hex(org_url)
+char *url_convert_hex(org_url, allocate)
      char *org_url;
+    int allocate;
 {
-    int i;
-    char temp[MAX_URL], hexstr[MAX_URL];
-    static char *url;
-
-    url = (char *) xcalloc(1, MAX_URL);
-    strncpy(url, org_url, MAX_URL);
-
-    i = 0;
-    while (i < (int) (strlen(url) - 2)) {
-       if (url[i] == '%') {
-           /* found %xx, convert it to char */
-           strncpy(temp, url, i);
-           strncpy(hexstr, url + i + 1, 2);
-           hexstr[2] = '\0';
-           temp[i] = (char) ((int) strtol(hexstr, (char **) NULL, 16));
-           temp[i + 1] = '\0';
-           strncat(temp, url + i + 3, MAX_URL);
-           strcpy(url, temp);
+    static char *code = "00";
+    char *url = NULL;
+    char *s = NULL;
+    char *t = NULL;
+
+    url = allocate ? (char *) xstrdup(org_url) : org_url;
+
+    for (s=t=url; *(s+2); s++) {
+        if (*s == '%') {
+               *code = *++s;
+               *(code+1) = *++s;
+               *t++ = (char) strtol(code, NULL, 16);
+        } else {
+               *t++ = *s;
        }
-       i++;
     }
-
+    do {
+       *t++ = *s;
+    } while (*s++);
     return url;
 }