Revert "Update to 7.40.1"
[platform/upstream/curl.git] / src / tool_operate.c
index 35a0dd3..fd2fd6d 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -202,7 +202,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
   CURL *curl = config->easy;
   char *httpgetfields = NULL;
 
-  CURLcode result = CURLE_OK;
+  CURLcode res = CURLE_OK;
   unsigned long li;
 
   /* Save the values of noprogress and isatty to restore them later on */
@@ -226,7 +226,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
   /* Check we have a url */
   if(!config->url_list || !config->url_list->url) {
     helpf(global->errors, "no URL specified!\n");
-    result = CURLE_FAILED_INIT;
+    res = CURLE_FAILED_INIT;
     goto quit_curl;
   }
 
@@ -249,7 +249,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
       if(!config->cacert) {
         curl_free(env);
         helpf(global->errors, "out of memory\n");
-        result = CURLE_OUT_OF_MEMORY;
+        res = CURLE_OUT_OF_MEMORY;
         goto quit_curl;
       }
     }
@@ -260,7 +260,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
         if(!config->capath) {
           curl_free(env);
           helpf(global->errors, "out of memory\n");
-          result = CURLE_OUT_OF_MEMORY;
+          res = CURLE_OUT_OF_MEMORY;
           goto quit_curl;
         }
       }
@@ -271,7 +271,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
           if(!config->cacert) {
             curl_free(env);
             helpf(global->errors, "out of memory\n");
-            result = CURLE_OUT_OF_MEMORY;
+            res = CURLE_OUT_OF_MEMORY;
             goto quit_curl;
           }
         }
@@ -282,8 +282,8 @@ static CURLcode operate_do(struct GlobalConfig *global,
       curl_free(env);
 #ifdef WIN32
     else {
-      result = FindWin32CACert(config, "curl-ca-bundle.crt");
-      if(result)
+      res = FindWin32CACert(config, "curl-ca-bundle.crt");
+      if(res)
         goto quit_curl;
     }
 #endif
@@ -296,19 +296,19 @@ static CURLcode operate_do(struct GlobalConfig *global,
       Curl_safefree(config->postfields);
       if(!httpgetfields) {
         helpf(global->errors, "out of memory\n");
-        result = CURLE_OUT_OF_MEMORY;
+        res = CURLE_OUT_OF_MEMORY;
         goto quit_curl;
       }
       if(SetHTTPrequest(config,
                         (config->no_body?HTTPREQ_HEAD:HTTPREQ_GET),
                         &config->httpreq)) {
-        result = CURLE_FAILED_INIT;
+        res = CURLE_FAILED_INIT;
         goto quit_curl;
       }
     }
     else {
       if(SetHTTPrequest(config, HTTPREQ_SIMPLEPOST, &config->httpreq)) {
-        result = CURLE_FAILED_INIT;
+        res = CURLE_FAILED_INIT;
         goto quit_curl;
       }
     }
@@ -321,7 +321,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
       FILE *newfile = fopen(config->headerfile, "wb");
       if(!newfile) {
         warnf(config, "Failed to open %s\n", config->headerfile);
-        result = CURLE_WRITE_ERROR;
+        res = CURLE_WRITE_ERROR;
         goto quit_curl;
       }
       else {
@@ -389,7 +389,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
       outfiles = strdup(urlnode->outfile);
       if(!outfiles) {
         helpf(global->errors, "out of memory\n");
-        result = CURLE_OUT_OF_MEMORY;
+        res = CURLE_OUT_OF_MEMORY;
         break;
       }
     }
@@ -398,9 +398,9 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
     if(!config->globoff && infiles) {
       /* Unless explicitly shut off */
-      result = glob_url(&inglob, infiles, &infilenum,
-                        global->showerror?global->errors:NULL);
-      if(result) {
+      res = (CURLcode) glob_url(&inglob, infiles, &infilenum,
+                     global->showerror?global->errors:NULL);
+      if(res) {
         Curl_safefree(outfiles);
         break;
       }
@@ -423,15 +423,15 @@ static CURLcode operate_do(struct GlobalConfig *global,
         Curl_nop_stmt;
       else {
         if(inglob) {
-          result = glob_next_url(&uploadfile, inglob);
-          if(result == CURLE_OUT_OF_MEMORY)
+          res = (CURLcode) glob_next_url(&uploadfile, inglob);
+          if(res == CURLE_OUT_OF_MEMORY)
             helpf(global->errors, "out of memory\n");
         }
         else if(!up) {
           uploadfile = strdup(infiles);
           if(!uploadfile) {
             helpf(global->errors, "out of memory\n");
-            result = CURLE_OUT_OF_MEMORY;
+            res = CURLE_OUT_OF_MEMORY;
           }
         }
         else
@@ -449,9 +449,9 @@ static CURLcode operate_do(struct GlobalConfig *global,
       if(!config->globoff) {
         /* Unless explicitly shut off, we expand '{...}' and '[...]'
            expressions and return total number of URLs in pattern set */
-        result = glob_url(&urls, urlnode->url, &urlnum,
-                          global->showerror?global->errors:NULL);
-        if(result) {
+        res = (CURLcode) glob_url(&urls, urlnode->url, &urlnum,
+                       global->showerror?global->errors:NULL);
+        if(res) {
           Curl_safefree(uploadfile);
           break;
         }
@@ -493,25 +493,25 @@ static CURLcode operate_do(struct GlobalConfig *global,
              filename. */
           outfile = strdup(mlfile->filename);
           if(!outfile) {
-            result = CURLE_OUT_OF_MEMORY;
+            res = CURLE_OUT_OF_MEMORY;
             goto show_error;
           }
           this_url = strdup(mlres->url);
           if(!this_url) {
-            result = CURLE_OUT_OF_MEMORY;
+            res = CURLE_OUT_OF_MEMORY;
             goto show_error;
           }
         }
         else {
           if(urls) {
-            result = glob_next_url(&this_url, urls);
-            if(result)
+            res = (CURLcode) glob_next_url(&this_url, urls);
+            if(res)
               goto show_error;
           }
           else if(!li) {
             this_url = strdup(urlnode->url);
             if(!this_url) {
-              result = CURLE_OUT_OF_MEMORY;
+              res = CURLE_OUT_OF_MEMORY;
               goto show_error;
             }
           }
@@ -523,7 +523,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
           if(outfiles) {
             outfile = strdup(outfiles);
             if(!outfile) {
-              result = CURLE_OUT_OF_MEMORY;
+              res = CURLE_OUT_OF_MEMORY;
               goto show_error;
             }
           }
@@ -540,12 +540,12 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
           if(!outfile) {
             /* extract the file name from the URL */
-            result = get_url_file_name(&outfile, this_url);
-            if(result)
+            res = get_url_file_name(&outfile, this_url);
+            if(res)
               goto show_error;
-            if(!*outfile && !config->content_disposition) {
+            if((!outfile || !*outfile) && !config->content_disposition) {
               helpf(global->errors, "Remote file name has no length!\n");
-              result = CURLE_WRITE_ERROR;
+              res = CURLE_WRITE_ERROR;
               goto quit_urls;
             }
 #if defined(MSDOS) || defined(WIN32)
@@ -553,7 +553,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
                bad characters in the file name before using it */
             outfile = sanitize_dos_name(outfile);
             if(!outfile) {
-              result = CURLE_OUT_OF_MEMORY;
+              res = CURLE_OUT_OF_MEMORY;
               goto show_error;
             }
 #endif /* MSDOS || WIN32 */
@@ -561,9 +561,9 @@ static CURLcode operate_do(struct GlobalConfig *global,
           else if(urls) {
             /* fill '#1' ... '#9' terms from URL pattern */
             char *storefile = outfile;
-            result = glob_match_url(&outfile, storefile, urls);
+            res = (CURLcode) glob_match_url(&outfile, storefile, urls);
             Curl_safefree(storefile);
-            if(result) {
+            if(res) {
               /* bad globbing */
               warnf(config, "bad output glob!\n");
               goto quit_urls;
@@ -574,11 +574,11 @@ static CURLcode operate_do(struct GlobalConfig *global,
              file output call */
 
           if(config->create_dirs || metalink) {
-            result = create_dir_hierarchy(outfile, global->errors);
+            res = create_dir_hierarchy(outfile, global->errors);
             /* create_dir_hierarchy shows error upon CURLE_WRITE_ERROR */
-            if(result == CURLE_WRITE_ERROR)
+            if(res == CURLE_WRITE_ERROR)
               goto quit_urls;
-            if(result) {
+            if(res) {
               goto show_error;
             }
           }
@@ -614,7 +614,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
 #endif
             if(!file) {
               helpf(global->errors, "Can't open '%s'!\n", outfile);
-              result = CURLE_WRITE_ERROR;
+              res = CURLE_WRITE_ERROR;
               goto quit_urls;
             }
             outs.fopened = TRUE;
@@ -636,7 +636,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
           this_url = add_file_name_to_url(curl, this_url, uploadfile);
           if(!this_url) {
-            result = CURLE_OUT_OF_MEMORY;
+            res = CURLE_OUT_OF_MEMORY;
             goto show_error;
           }
           /* VMS Note:
@@ -680,7 +680,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
               close(infd);
               infd = STDIN_FILENO;
             }
-            result = CURLE_READ_ERROR;
+            res = CURLE_READ_ERROR;
             goto quit_urls;
           }
           infdopen = TRUE;
@@ -780,7 +780,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
             urlbuffer = aprintf("%s/?%s", this_url, httpgetfields);
 
           if(!urlbuffer) {
-            result = CURLE_OUT_OF_MEMORY;
+            res = CURLE_OUT_OF_MEMORY;
             goto show_error;
           }
 
@@ -1025,9 +1025,6 @@ static CURLcode operate_do(struct GlobalConfig *global,
         if(config->crlfile)
           my_setopt_str(curl, CURLOPT_CRLFILE, config->crlfile);
 
-        if(config->pinnedpubkey)
-          my_setopt_str(curl, CURLOPT_PINNEDPUBLICKEY, config->pinnedpubkey);
-
         if(curlinfo->features & CURL_VERSION_SSL) {
           if(config->insecure_ok) {
             my_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
@@ -1038,30 +1035,27 @@ static CURLcode operate_do(struct GlobalConfig *global,
             /* libcurl default is strict verifyhost -> 2L   */
             /* my_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L); */
           }
-
-          if(config->verifystatus)
-            my_setopt(curl, CURLOPT_SSL_VERIFYSTATUS, 1L);
         }
 
         if(built_in_protos & (CURLPROTO_SCP|CURLPROTO_SFTP)) {
           if(!config->insecure_ok) {
             char *home;
             char *file;
-            result = CURLE_OUT_OF_MEMORY;
+            res = CURLE_OUT_OF_MEMORY;
             home = homedir();
             if(home) {
               file = aprintf("%s/%sssh/known_hosts", home, DOT_CHAR);
               if(file) {
                 /* new in curl 7.19.6 */
-                result = res_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, file);
+                res = res_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, file);
                 curl_free(file);
-                if(result == CURLE_UNKNOWN_OPTION)
+                if(res == CURLE_UNKNOWN_OPTION)
                   /* libssh2 version older than 1.1.1 */
-                  result = CURLE_OK;
+                  res = CURLE_OK;
               }
               Curl_safefree(home);
             }
-            if(result)
+            if(res)
               goto show_error;
           }
         }
@@ -1158,8 +1152,8 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
         /* new in curl 7.9.3 */
         if(config->engine) {
-          result = res_setopt_str(curl, CURLOPT_SSLENGINE, config->engine);
-          if(result)
+          res = res_setopt_str(curl, CURLOPT_SSLENGINE, config->engine);
+          if(res)
             goto show_error;
           my_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L);
         }
@@ -1334,11 +1328,6 @@ static CURLcode operate_do(struct GlobalConfig *global,
           my_setopt(curl, CURLOPT_SSL_ENABLE_ALPN, 0L);
         }
 
-        /* new in 7.40.0 */
-        if(config->unix_socket_path)
-          my_setopt_str(curl, CURLOPT_UNIX_SOCKET_PATH,
-                        config->unix_socket_path);
-
         /* initialize retry vars for loop below */
         retry_sleep_default = (config->retry_delay) ?
           config->retry_delay*1000L : RETRY_SLEEP_DEFAULT; /* ms */
@@ -1348,8 +1337,8 @@ static CURLcode operate_do(struct GlobalConfig *global,
         retrystart = tvnow();
 
 #ifndef CURL_DISABLE_LIBCURL_OPTION
-        result = easysrc_perform();
-        if(result) {
+        res = easysrc_perform();
+        if(res) {
           goto show_error;
         }
 #endif
@@ -1362,7 +1351,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
               metalink_parser_context_delete(outs.metalink_parser);
             outs.metalink_parser = metalink_parser_context_new();
             if(outs.metalink_parser == NULL) {
-              result = CURLE_OUT_OF_MEMORY;
+              res = CURLE_OUT_OF_MEMORY;
               goto show_error;
             }
             fprintf(config->global->errors,
@@ -1376,10 +1365,10 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
 #ifdef CURLDEBUG
           if(config->test_event_based)
-            result = curl_easy_perform_ev(curl);
+            res = curl_easy_perform_ev(curl);
           else
 #endif
-          result = curl_easy_perform(curl);
+          res = curl_easy_perform(curl);
 
           if(outs.is_cd_filename && outs.stream && !global->mute &&
              outs.filename)
@@ -1399,15 +1388,15 @@ static CURLcode operate_do(struct GlobalConfig *global,
               RETRY_LAST /* not used */
             } retry = RETRY_NO;
             long response;
-            if((CURLE_OPERATION_TIMEDOUT == result) ||
-               (CURLE_COULDNT_RESOLVE_HOST == result) ||
-               (CURLE_COULDNT_RESOLVE_PROXY == result) ||
-               (CURLE_FTP_ACCEPT_TIMEOUT == result))
+            if((CURLE_OPERATION_TIMEDOUT == res) ||
+               (CURLE_COULDNT_RESOLVE_HOST == res) ||
+               (CURLE_COULDNT_RESOLVE_PROXY == res) ||
+               (CURLE_FTP_ACCEPT_TIMEOUT == res))
               /* retry timeout always */
               retry = RETRY_TIMEOUT;
-            else if((CURLE_OK == result) ||
+            else if((CURLE_OK == res) ||
                     (config->failonerror &&
-                     (CURLE_HTTP_RETURNED_ERROR == result))) {
+                     (CURLE_HTTP_RETURNED_ERROR == res))) {
               /* If it returned OK. _or_ failonerror was enabled and it
                  returned due to such an error, check for HTTP transient
                  errors to retry on. */
@@ -1438,7 +1427,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
                 }
               }
             } /* if CURLE_OK */
-            else if(result) {
+            else if(res) {
               curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
 
               if(response/100 == 4)
@@ -1482,7 +1471,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
                   if(!global->mute)
                     fprintf(global->errors,
                             "failed to truncate, exiting\n");
-                  result = CURLE_WRITE_ERROR;
+                  res = CURLE_WRITE_ERROR;
                   goto quit_urls;
                 }
                 /* now seek to the end of the file, the position where we
@@ -1505,7 +1494,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
                not. Basically, we want to try the next resource if
                download was not successful. */
             long response;
-            if(CURLE_OK == result) {
+            if(CURLE_OK == res) {
               /* TODO We want to try next resource when download was
                  not successful. How to know that? */
               char *effective_url = NULL;
@@ -1529,7 +1518,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
                       "Metalink: fetching (%s) from (%s) FAILED (%s)\n",
                       mlfile->filename, this_url,
                       (errorbuffer[0]) ?
-                      errorbuffer : curl_easy_strerror(result));
+                      errorbuffer : curl_easy_strerror((CURLcode)res));
             }
           }
           if(metalink && !metalink_next_res)
@@ -1570,10 +1559,10 @@ static CURLcode operate_do(struct GlobalConfig *global,
         }
         else
 #endif
-        if(result && global->showerror) {
-          fprintf(global->errors, "curl: (%d) %s\n", result, (errorbuffer[0]) ?
-                  errorbuffer : curl_easy_strerror(result));
-          if(result == CURLE_SSL_CACERT)
+        if(res && global->showerror) {
+          fprintf(global->errors, "curl: (%d) %s\n", res, (errorbuffer[0]) ?
+                  errorbuffer : curl_easy_strerror((CURLcode)res));
+          if(res == CURLE_SSL_CACERT)
             fprintf(global->errors, "%s%s",
                     CURL_CA_CERT_ERRORMSG1, CURL_CA_CERT_ERRORMSG2);
         }
@@ -1594,7 +1583,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
         quit_urls:
 
         /* Set file extended attributes */
-        if(!result && config->xattr && outs.fopened && outs.stream) {
+        if(!res && config->xattr && outs.fopened && outs.stream) {
           int rc = fwrite_xattr(curl, fileno(outs.stream));
           if(rc)
             warnf(config, "Error setting extended attributes: %s\n",
@@ -1604,24 +1593,24 @@ static CURLcode operate_do(struct GlobalConfig *global,
         /* Close the file */
         if(outs.fopened && outs.stream) {
           int rc = fclose(outs.stream);
-          if(!result && rc) {
+          if(!res && rc) {
             /* something went wrong in the writing process */
-            result = CURLE_WRITE_ERROR;
-            fprintf(global->errors, "(%d) Failed writing body\n", result);
+            res = CURLE_WRITE_ERROR;
+            fprintf(global->errors, "(%d) Failed writing body\n", res);
           }
         }
         else if(!outs.s_isreg && outs.stream) {
           /* Dump standard stream buffered data */
           int rc = fflush(outs.stream);
-          if(!result && rc) {
+          if(!res && rc) {
             /* something went wrong in the writing process */
-            result = CURLE_WRITE_ERROR;
-            fprintf(global->errors, "(%d) Failed writing body\n", result);
+            res = CURLE_WRITE_ERROR;
+            fprintf(global->errors, "(%d) Failed writing body\n", res);
           }
         }
 
 #ifdef __AMIGA__
-        if(!result && outs.s_isreg && outs.filename) {
+        if(!res && outs.s_isreg && outs.filename) {
           /* Set the url (up to 80 chars) as comment for the file */
           if(strlen(url) > 78)
             url[79] = '\0';
@@ -1631,7 +1620,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
 #ifdef HAVE_UTIME
         /* File time can only be set _after_ the file has been closed */
-        if(!result && config->remote_time && outs.s_isreg && outs.filename) {
+        if(!res && config->remote_time && outs.s_isreg && outs.filename) {
           /* Ask libcurl if we got a remote file time */
           long filetime = -1;
           curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
@@ -1645,7 +1634,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
 #endif
 
 #ifdef USE_METALINK
-        if(!metalink && config->use_metalink && result == CURLE_OK) {
+        if(!metalink && config->use_metalink && res == CURLE_OK) {
           int rv = parse_metalink(config, &outs, this_url);
           if(rv == 0)
             fprintf(config->global->errors, "Metalink: parsing (%s) OK\n",
@@ -1654,7 +1643,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
             fprintf(config->global->errors, "Metalink: parsing (%s) FAILED\n",
                     this_url);
         }
-        else if(metalink && result == CURLE_OK && !metalink_next_res) {
+        else if(metalink && res == CURLE_OK && !metalink_next_res) {
           int rv = metalink_check_hash(global, mlfile, outs.filename);
           if(rv == 0) {
             metalink_next_res = 1;
@@ -1682,7 +1671,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
         if(metalink) {
           /* Should exit if error is fatal. */
-          if(is_fatal_error(result)) {
+          if(is_fatal_error(res)) {
             break;
           }
           if(!metalink_next_res)
@@ -1697,10 +1686,10 @@ static CURLcode operate_do(struct GlobalConfig *global,
         else
         if(urlnum > 1) {
           /* when url globbing, exit loop upon critical error */
-          if(is_fatal_error(result))
+          if(is_fatal_error(res))
             break;
         }
-        else if(result)
+        else if(res)
           /* when not url globbing, exit loop upon any error */
           break;
 
@@ -1718,10 +1707,10 @@ static CURLcode operate_do(struct GlobalConfig *global,
 
       if(infilenum > 1) {
         /* when file globbing, exit loop upon critical error */
-        if(is_fatal_error(result))
+        if(is_fatal_error(res))
           break;
       }
-      else if(result)
+      else if(res)
         /* when not file globbing, exit loop upon any error */
         break;
 
@@ -1747,7 +1736,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
     /*
     ** Bail out upon critical errors
     */
-    if(is_fatal_error(result))
+    if(is_fatal_error(res))
       goto quit_curl;
 
   } /* for-loop through all URLs */
@@ -1780,7 +1769,7 @@ static CURLcode operate_do(struct GlobalConfig *global,
   /* Release metalink related resources here */
   clean_metalink(config);
 
-  return result;
+  return res;
 }
 
 CURLcode operate(struct GlobalConfig *config, int argc, argv_item_t argv[])
@@ -1856,9 +1845,6 @@ CURLcode operate(struct GlobalConfig *config, int argc, argv_item_t argv[])
         /* Cleanup the libcurl source output */
         easysrc_cleanup();
 
-        /* set current back to first so that isn't NULL */
-        config->current = config->first;
-
         /* Dump the libcurl code if previously enabled */
         dumpeasysrc(config);
 #endif