Skip to content
Snippets Groups Projects
main.c 61.6 KiB
Newer Older
  • Learn to ignore specific revisions
  •       /* three new ones in libcurl 7.3: */
          curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, config->proxytunnel);
          curl_easy_setopt(curl, CURLOPT_INTERFACE, config->iface);
          curl_easy_setopt(curl, CURLOPT_KRB4LEVEL, config->krb4level);
          
          if((config->progressmode == CURL_PROGRESS_BAR) &&
             !(config->conf&(CONF_NOPROGRESS|CONF_MUTE))) {
            /* we want the alternative style, then we have to implement it
               ourselves! */
    
            progressbarinit(&progressbar, config);
    
            curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, myprogress);
            curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &progressbar);
          }
    
          /* new in libcurl 7.6.2: */
          curl_easy_setopt(curl, CURLOPT_TELNETOPTIONS, config->telnet_options);
    
    
          /* new in libcurl 7.7: */
          curl_easy_setopt(curl, CURLOPT_RANDOM_FILE, config->random_file);
          curl_easy_setopt(curl, CURLOPT_EGDSOCKET, config->egd_file);
    
          curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, config->connecttimeout);
    
          
          res = curl_easy_perform(curl);
    
          if(config->writeout) {
            ourWriteOut(curl, config->writeout);
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    #ifdef	VMS
    
          if (!config->showerror)  {
            vms_show = VMSSTS_HIDE;
          }
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    #else
    
          if((res!=CURLE_OK) && config->showerror)
            fprintf(config->errors, "curl: (%d) %s\n", res, errorbuffer);
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    #endif
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    
    
          if(config->headerfile && !headerfilep && heads.stream)
            fclose(heads.stream);
    
          if(urlbuffer)
            free(urlbuffer);
          if (outfile && !strequal(outfile, "-") && outs.stream)
            fclose(outs.stream);
    
    
    #ifdef HAVE_UTIME
          /* Important that we set the time _after_ the file has been 
             closed, as is done above here */
          if(config->remote_time && outs.filename) {
            /* as libcurl if we got a time. Pretty please */
            long filetime;
            curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
            if(filetime >= 0) {
              struct utimbuf times;
              times.actime = filetime;
              times.modtime = filetime;
              utime(outs.filename, &times); /* set the time we got */
            }
          }
    #endif
    
    
          if (config->infile)
            fclose(infd);
          if(headerfilep)
            fclose(headerfilep);
          
    
          if(url)
            free(url);
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    
    
          if(outfile)
            free(outfile);
    
        if(outfiles)
          free(outfiles);
    
        if(urls)
          /* cleanup memory used for URL globbing patterns */
          glob_cleanup(urls);
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    
    
        /* empty this urlnode struct */
        if(urlnode->url)
          free(urlnode->url);
        if(urlnode->outfile)
          free(urlnode->outfile);
    
        /* move on to the next URL */
        nextnode=urlnode->next;
        free(urlnode); /* free the node */
        urlnode = nextnode;
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    
    
      } /* while-loop through all URLs */
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    
    
      if(allocuseragent)
    
        free(config->useragent);
    
      /* cleanup the curl handle! */
      curl_easy_cleanup(curl);
    
    
      if((config->errors != stderr) &&
         (config->errors != stdout))
        /* it wasn't directed to stdout or stderr so close the file! */
        fclose(config->errors);
    
    
      struct Configurable config;
    
      memset(&config, 0, sizeof(struct Configurable));
      
    
      res = operate(&config, argc, argv);
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    #ifdef	VMS
      return (vms_cond[res]|vms_show);
    #else
    
      return res;
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    #endif
    
    Daniel Stenberg's avatar
    Daniel Stenberg committed
    }
    
    
    static char *my_get_line(FILE *fp)
    {
       char buf[4096];
       char *nl = NULL;
       char *retval = NULL;
    
       do
       {
          if (NULL == fgets(buf, sizeof(buf), fp))
             break;
          if (NULL == retval)
             retval = strdup(buf);
          else
          {
             if (NULL == (retval = realloc(retval,
                                           strlen(retval) + strlen(buf) + 1)))
                break;
             strcat(retval, buf);
          }
       }
       while (NULL == (nl = strchr(retval, '\n')));
    
       if (NULL != nl)
         *nl = '\0';
    
       return retval;
    }