]> granicus.if.org Git - curl/commitdiff
smb: Moved the URL decoding into a separate function
authorSteve Holme <steve_holme@hotmail.com>
Sat, 6 Dec 2014 21:02:06 +0000 (21:02 +0000)
committerSteve Holme <steve_holme@hotmail.com>
Sat, 6 Dec 2014 21:02:06 +0000 (21:02 +0000)
lib/smb.c

index b75b1b333e2caaff168e6494de6c41eae0e4eac7..fa9e43fcac10ba05d7c2b1680e9f45affeacfe76 100644 (file)
--- a/lib/smb.c
+++ b/lib/smb.c
@@ -57,6 +57,7 @@ static CURLcode smb_done(struct connectdata *conn, CURLcode status,
 static CURLcode smb_disconnect(struct connectdata *conn, bool dead);
 static int smb_getsock(struct connectdata *conn, curl_socket_t *socks,
                        int numsocks);
+static CURLcode smb_parse_url_path(struct connectdata *conn);
 
 /*
  * SMB handler interface
@@ -176,10 +177,7 @@ struct smb_request {
 
 static CURLcode smb_setup(struct connectdata *conn)
 {
-  CURLcode result = CURLE_OK;
   struct smb_request *req;
-  char *slash;
-  char *path;
 
   /* Initialize the request state */
   conn->data->req.protop = req = calloc(1, sizeof(struct smb_request));
@@ -189,40 +187,8 @@ static CURLcode smb_setup(struct connectdata *conn)
   req->state = SMB_REQUESTING;
   req->result = CURLE_OK;
 
-  /* URL decode the path */
-  result = Curl_urldecode(conn->data, conn->data->state.path, 0, &path, NULL,
-                          TRUE);
-  if(result)
-    return result;
-
-  /* Parse the share and path */
-  req->share = strdup((*path == '/' || *path == '\\') ? path + 1 : path);
-  if(!req->share) {
-    Curl_safefree(path);
-
-    return CURLE_OUT_OF_MEMORY;
-  }
-
-  slash = strchr(req->share, '/');
-  if(!slash)
-    slash = strchr(req->share, '\\');
-
-  if(!slash) {
-    Curl_safefree(path);
-
-    return CURLE_URL_MALFORMAT;
-  }
-
-  *slash++ = 0;
-  req->path = slash;
-  for(; *slash; slash++) {
-    if(*slash == '/')
-      *slash = '\\';
-  }
-
-  Curl_safefree(path);
-
-  return CURLE_OK;
+  /* Parse the URL path */
+  return smb_parse_url_path(conn);
 }
 
 static CURLcode smb_connect(struct connectdata *conn, bool *done)
@@ -883,4 +849,50 @@ static int smb_getsock(struct connectdata *conn, curl_socket_t *socks,
   return GETSOCK_READSOCK(0);
 }
 
+static CURLcode smb_parse_url_path(struct connectdata *conn)
+{
+  CURLcode result = CURLE_OK;
+  struct SessionHandle *data = conn->data;
+  struct smb_request *req = data->req.protop;
+  char *path;
+  char *slash;
+
+  /* URL decode the path */
+  result = Curl_urldecode(data, data->state.path, 0, &path, NULL, TRUE);
+  if(result)
+    return result;
+
+  /* Parse the path for the share */
+  req->share = strdup((*path == '/' || *path == '\\') ? path + 1 : path);
+  if(!req->share) {
+    Curl_safefree(path);
+
+    return CURLE_OUT_OF_MEMORY;
+  }
+
+  slash = strchr(req->share, '/');
+  if(!slash)
+    slash = strchr(req->share, '\\');
+
+  /* The share must be present */
+  if(!slash) {
+    Curl_safefree(path);
+
+    return CURLE_URL_MALFORMAT;
+  }
+
+  /* Parse the path for the file path converting any forward slashes into
+     backslashes */
+  *slash++ = 0;
+  req->path = slash;
+  for(; *slash; slash++) {
+    if(*slash == '/')
+      *slash = '\\';
+  }
+
+  Curl_safefree(path);
+
+  return CURLE_OK;
+}
+
 #endif /* CURL_DISABLE_SMB && USE_NTLM && USE_WINDOWS_SSPI */