]> granicus.if.org Git - curl/commitdiff
Remove pointless storing of the protocol as a string within the connectdata
authorDaniel Stenberg <daniel@haxx.se>
Thu, 17 Dec 2009 15:45:04 +0000 (15:45 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 17 Dec 2009 15:45:04 +0000 (15:45 +0000)
struct, and instead use the already stored string in the handler struct.

lib/ldap.c
lib/url.c
lib/urldata.h
tests/data/test523

index 0152e668cf74a3c52d3ae8c3c2b4ff24256241e3..ec9252f56e127c58276af7bd7dda3011370286a5 100644 (file)
@@ -200,7 +200,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
   }
 
   /* Get the URL scheme ( either ldap or ldaps ) */
-  if(Curl_raw_equal(conn->protostr, "LDAPS"))
+  if(conn->protocol & PROT_SSL)
     ldap_ssl = 1;
   infof(data, "LDAP local: trying to establish %s connection\n",
           ldap_ssl ? "encrypted" : "cleartext");
index 6e35b666fc2cea1ebdf2b62f9475af95b080947e..b85129a62025c3ae003d976421e70cdc34405b08 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -2752,7 +2752,7 @@ ConnectionExists(struct SessionHandle *data,
          it is a non-SSL protocol tunneled over the same http proxy name and
          port number */
 
-      if(Curl_raw_equal(needle->protostr, check->protostr) &&
+      if(Curl_raw_equal(needle->handler->scheme, check->handler->scheme) &&
          Curl_raw_equal(needle->host.name, check->host.name) &&
          (needle->remote_port == check->remote_port) ) {
         if(needle->protocol & PROT_SSL) {
@@ -3256,7 +3256,8 @@ static struct connectdata *allocate_conn(void)
 }
 
 static CURLcode findprotocol(struct SessionHandle *data,
-                             struct connectdata *conn)
+                             struct connectdata *conn,
+                             const char *protostr)
 {
   const struct Curl_handler * const *pp;
   const struct Curl_handler *p;
@@ -3265,7 +3266,7 @@ static CURLcode findprotocol(struct SessionHandle *data,
      variables based on the URL. Now that the handler may be changed later
      when the protocol specific setup function is called. */
   for (pp = protocols; (p = *pp) != NULL; pp++) {
-    if(Curl_raw_equal(p->scheme, conn->protostr)) {
+    if(Curl_raw_equal(p->scheme, protostr)) {
       /* Protocol found in table. Check if allowed */
       if(!(data->set.allowed_protocols & p->protocol))
         /* nope, get out */
@@ -3292,7 +3293,7 @@ static CURLcode findprotocol(struct SessionHandle *data,
      to anything since it is already assigned to a dummy-struct in the
      create_conn() function when the connectdata struct is allocated. */
   failf(data, "Protocol %s not supported or disabled in " LIBCURL_NAME,
-        conn->protostr);
+        protostr);
 
   return CURLE_UNSUPPORTED_PROTOCOL;
 }
@@ -3307,6 +3308,8 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
   char *tmp;
   char *path = data->state.path;
   int rc;
+  char protobuf[16];
+  const char *protop;
 
   /*************************************************************
    * Parse the URL.
@@ -3317,8 +3320,8 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
    * url ...
    ************************************************************/
   if((2 == sscanf(data->change.url, "%15[^:]:%[^\n]",
-                  conn->protostr,
-                  path)) && Curl_raw_equal(conn->protostr, "file")) {
+                  protobuf, path)) &&
+     Curl_raw_equal(protobuf, "file")) {
     if(path[0] == '/' && path[1] == '/') {
       /* Allow omitted hostname (e.g. file:/<path>).  This is not strictly
        * speaking a valid file: URL by RFC 1738, but treating file:/<path> as
@@ -3364,7 +3367,7 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
       }
     }
 
-    strcpy(conn->protostr, "file"); /* store protocol string lowercase */
+    protop = "file"; /* protocol string */
   }
   else {
     /* clear path */
@@ -3372,7 +3375,7 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
 
     if(2 > sscanf(data->change.url,
                    "%15[^\n:]://%[^\n/]%[^\n]",
-                   conn->protostr,
+                   protobuf,
                    conn->host.name, path)) {
 
       /*
@@ -3404,19 +3407,21 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
        * lib/version.c too! */
 
       if(checkprefix("FTP.", conn->host.name))
-        strcpy(conn->protostr, "ftp");
+        protop = "ftp";
       else if(checkprefix("DICT.", conn->host.name))
-        strcpy(conn->protostr, "DICT");
+        protop = "DICT";
       else if(checkprefix("LDAP.", conn->host.name))
-        strcpy(conn->protostr, "LDAP");
+        protop = "LDAP";
       else if(checkprefix("IMAP.", conn->host.name))
-        strcpy(conn->protostr, "IMAP");
+        protop = "IMAP";
       else {
-        strcpy(conn->protostr, "http");
+        protop = "http";
       }
 
       conn->protocol |= PROT_MISSING; /* not given in URL */
     }
+    else
+      protop = protobuf;
   }
 
   /* We search for '?' in the host name (but only on the right side of a
@@ -3493,12 +3498,12 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
 
   /*
    * So if the URL was A://B/C,
-   *   conn->protostr is A
+   *   protop is A
    *   conn->host.name is B
    *   data->state.path is /C
    */
 
-  return findprotocol(data, conn);
+  return findprotocol(data, conn, protop);
 }
 
 static void llist_dtor(void *user, void *element)
@@ -3685,7 +3690,7 @@ static char *detect_proxy(struct connectdata *conn)
 
   if(!check_noproxy(conn->host.name, no_proxy)) {
     /* It was not listed as without proxy */
-    char *protop = conn->protostr;
+    const char *protop = conn->handler->scheme;
     char *envp = proxy_env;
     char *prox;
 
@@ -4036,18 +4041,18 @@ static CURLcode parse_remote_port(struct SessionHandle *data,
     if(conn->bits.httpproxy) {
       /* we need to create new URL with the new port number */
       char *url;
-      bool isftp = (bool)(Curl_raw_equal("ftp", conn->protostr) ||
-                          Curl_raw_equal("ftps", conn->protostr));
+      /* FTPS connections have the FTP bit set too, so they match as well */
+      bool isftp = (bool)conn->protocol & PROT_FTP;
 
       /*
        * This synthesized URL isn't always right--suffixes like ;type=A
        * are stripped off. It would be better to work directly from the
        * original URL and simply replace the port part of it.
        */
-      url = aprintf("%s://%s%s%s:%d%s%s", conn->protostr,
-             conn->bits.ipv6_ip?"[":"", conn->host.name,
-             conn->bits.ipv6_ip?"]":"", conn->remote_port,
-             isftp?"/":"", data->state.path);
+      url = aprintf("%s://%s%s%s:%d%s%s", conn->handler->scheme,
+                    conn->bits.ipv6_ip?"[":"", conn->host.name,
+                    conn->bits.ipv6_ip?"]":"", conn->remote_port,
+                    isftp?"/":"", data->state.path);
       if(!url)
         return CURLE_OUT_OF_MEMORY;
 
@@ -4456,7 +4461,7 @@ static CURLcode create_conn(struct SessionHandle *data,
        part added so that we have a valid URL. */
     char *reurl;
 
-    reurl = aprintf("%s://%s", conn->protostr, data->change.url);
+    reurl = aprintf("%s://%s", conn->handler->scheme, data->change.url);
 
     if(!reurl) {
       Curl_safefree(proxy);
index 0d0128a321c0c287e35e2e9aded9ab846a179c66..8107a9e8fe75be700b4babeee6910fe42cf5dda4 100644 (file)
@@ -703,7 +703,6 @@ struct connectdata {
 
   unsigned int scope;    /* address scope for IPv6 */
 
-  char protostr[16];  /* store the protocol string in this buffer */
   int socktype;  /* SOCK_STREAM or SOCK_DGRAM */
 
   struct hostname host;
index 4c67cdbd89e3f8845ba5f7bb0755de9d963d0db3..6c1efbd5d82f065326a4fd5fc0d8e12c8745ef8e 100644 (file)
@@ -50,7 +50,7 @@ http://www.haxx.se:999/523 http://%HOSTIP:%HTTPPORT
 ^User-Agent:.*
 </strip>
 <protocol>
-GET http://www.haxx.se:19999/523 HTTP/1.1\r
+GET HTTP://www.haxx.se:19999/523 HTTP/1.1\r
 Authorization: Basic eHh4Onl5eQ==\r
 Host: www.haxx.se:19999\r
 Accept: */*\r