~ubuntu-branches/ubuntu/gutsy/curl/gutsy-updates

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-08-01 12:22:30 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070801122230-uaarmp6lo65py9t6
Tags: 7.16.4-1ubuntu1
* Merge with Debian.
  - Drop debian/patches/gnutls-verifications, applied upstream.
  - Remove all stuff which should be reverted according to 7.16.2-6ubuntu4.
  - Remaining change: drop stunnel build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: main.c,v 1.412 2007-04-04 20:27:47 danf Exp $
 
21
 * $Id: main.c,v 1.422 2007-07-01 22:01:19 bagder Exp $
22
22
 ***************************************************************************/
23
23
#include "setup.h"
24
24
 
47
47
 
48
48
#define CURLseparator   "--_curl_--"
49
49
 
 
50
#ifdef NETWARE
50
51
#ifdef __NOVELL_LIBC__
51
52
#include <screen.h>
 
53
#else
 
54
#include <nwconio.h>
 
55
#define mkdir mkdir_510
 
56
#endif
52
57
#endif
53
58
 
54
59
#include "version.h"
406
411
  bool list_engines;
407
412
  bool crlf;
408
413
  char *customrequest;
409
 
  char *krb4level;
 
414
  char *krblevel;
410
415
  char *trace_dump; /* file to dump the network trace to, or NULL */
411
416
  FILE *trace_stream;
412
417
  bool trace_fopened;
501
506
        while(!ISSPACE(ptr[cut]) && cut) {
502
507
          cut--;
503
508
        }
 
509
        if(0 == cut)
 
510
          /* not a single cutting position was found, just cut it at the
 
511
             max text width then! */
 
512
          cut = WARN_TEXTWIDTH-1;
504
513
 
505
514
        fwrite(ptr, cut + 1, 1, config->errors);
506
515
        fputs("\n", config->errors);
643
652
    "    --ftp-ssl       Try SSL/TLS for ftp transfer (F)",
644
653
    "    --ftp-ssl-control Require SSL/TLS for ftp login, clear for transfer (F)",
645
654
    "    --ftp-ssl-reqd  Require SSL/TLS for ftp transfer (F)",
646
 
    "    --ftp-ssl-ccc   Send CCC after authenticating. (F)",
 
655
    "    --ftp-ssl-ccc   Send CCC after authenticating (F)",
647
656
    "    --ftp-ssl-ccc-mode [active/passive] Set CCC mode (F)",
648
657
    " -F/--form <name=content> Specify HTTP multipart POST data (H)",
649
658
    "    --form-string <name=string> Specify HTTP multipart POST data (H)",
656
665
    " -I/--head          Show document info only",
657
666
    " -j/--junk-session-cookies Ignore session cookies read from file (H)",
658
667
    "    --interface <interface> Specify network interface/address to use",
659
 
    "    --krb4 <level>  Enable krb4 with specified security level (F)",
 
668
    "    --krb <level>   Enable kerberos with specified security level (F)",
660
669
    " -k/--insecure      Allow connections to SSL sites without certs (H)",
661
670
    " -K/--config        Specify which config file to read",
662
671
    "    --libcurl <file> Dump libcurl equivalent code of this command line",
684
693
    "    --proxy-ntlm    Use NTLM authentication on the proxy (H)",
685
694
    " -P/--ftp-port <address> Use PORT with address instead of PASV (F)",
686
695
    " -q                 If used as the first parameter disables .curlrc",
687
 
    " -Q/--quote <cmd>   Send command(s) to server before file transfer (F)",
 
696
    " -Q/--quote <cmd>   Send command(s) to server before file transfer (F/SFTP)",
688
697
    " -r/--range <range> Retrieve a byte range from a HTTP/1.1 or FTP server",
689
698
    "    --random-file <file> File for reading random data from (SSL)",
690
699
    "    --raw           Pass HTTP \"raw\", without any transfer decoding (H)",
702
711
    "    --trace-ascii <file> Like --trace but without the hex output",
703
712
    "    --trace-time    Add time stamps to trace/verbose output",
704
713
    " -T/--upload-file <file> Transfer <file> to remote site",
705
 
    "    --url <URL>     Spet URL to work with",
 
714
    "    --url <URL>     Set URL to work with",
706
715
    " -u/--user <user[:password]> Set server user and password",
707
716
    " -U/--proxy-user <user[:password]> Set proxy user and password",
708
717
    " -v/--verbose       Make the operation more talkative",
727
736
  };
728
737
  for(i=0; helptext[i]; i++) {
729
738
    puts(helptext[i]);
730
 
#ifdef __NOVELL_LIBC__
 
739
#ifdef NETWARE
731
740
    if (i && ((i % 23) == 0))
732
741
      pressanykey();
733
742
#endif
1467
1476
    {"*u", "crlf",        FALSE},
1468
1477
    {"*v", "stderr",      TRUE},
1469
1478
    {"*w", "interface",   TRUE},
1470
 
    {"*x", "krb4",        TRUE},
 
1479
    {"*x", "krb" ,        TRUE},
 
1480
    {"*x", "krb4" ,       TRUE}, /* this is the previous name */
1471
1481
    {"*y", "max-filesize", TRUE},
1472
1482
    {"*z", "disable-eprt", FALSE},
1473
1483
    {"$a", "ftp-ssl",    FALSE},
1800
1810
        /* interface */
1801
1811
        GetStr(&config->iface, nextarg);
1802
1812
        break;
1803
 
      case 'x': /* --krb4 */
1804
 
        /* krb4 level string */
1805
 
        if(curlinfo->features & CURL_VERSION_KERBEROS4)
1806
 
          GetStr(&config->krb4level, nextarg);
 
1813
      case 'x': /* --krb */
 
1814
        /* kerberos level string */
 
1815
        if(curlinfo->features & (CURL_VERSION_KERBEROS4 | CURL_VERSION_GSSNEGOTIATE))
 
1816
          GetStr(&config->krblevel, nextarg);
1807
1817
        else
1808
1818
          return PARAM_LIBCURL_DOESNT_SUPPORT;
1809
1819
        break;
2350
2360
         (and won't actually be range by definition). The man page previously
2351
2361
         claimed that to be a good way, why this code is added to work-around
2352
2362
         it. */
2353
 
      if(!strchr(nextarg, '-')) {
 
2363
      if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
2354
2364
        char buffer[32];
2355
2365
        curl_off_t off;
2356
2366
        warnf(config,
2360
2370
        snprintf(buffer, sizeof(buffer), "%Od-", off);
2361
2371
        GetStr(&config->range, buffer);
2362
2372
      }
2363
 
      else
 
2373
      {
 
2374
        /* byte range requested */
 
2375
        char* tmp_range;
 
2376
        tmp_range=nextarg;
 
2377
        while(*tmp_range != '\0') {
 
2378
          if(!ISDIGIT(*tmp_range)&&*tmp_range!='-'&&*tmp_range!=',') {
 
2379
            warnf(config,"Invalid character is found in given range. "
 
2380
                  "A specified range MUST have only digits in "
 
2381
                  "\'start\'-\'stop\'. The server's response to this "
 
2382
                  "request is uncertain.\n");
 
2383
            break;
 
2384
          }
 
2385
          tmp_range++;
 
2386
        }
2364
2387
        /* byte range requested */
2365
2388
        GetStr(&config->range, nextarg);
2366
 
 
 
2389
      }
2367
2390
      break;
2368
2391
    case 'R':
2369
2392
      /* use remote file's time */
2371
2394
      break;
2372
2395
    case 's':
2373
2396
      /* don't show progress meter, don't show errors : */
2374
 
      config->conf |= (CONF_MUTE|CONF_NOPROGRESS);
 
2397
      config->conf ^= (CONF_MUTE|CONF_NOPROGRESS);
2375
2398
      config->showerror ^= TRUE; /* toggle off */
2376
2399
      break;
2377
2400
    case 'S':
3238
3261
    free(config->cookie);
3239
3262
  if(config->cookiefile)
3240
3263
    free(config->cookiefile);
3241
 
  if(config->krb4level)
3242
 
    free(config->krb4level);
 
3264
  if(config->krblevel)
 
3265
    free(config->krblevel);
3243
3266
  if(config->headerfile)
3244
3267
    free(config->headerfile);
3245
3268
  if(config->ftpport)
3337
3360
  return FALSE; /* non-HTTP upload, probably no output should be expected */
3338
3361
}
3339
3362
 
3340
 
#define my_setopt(x,y,z) _my_setopt(x, #y, y, z)
 
3363
#define my_setopt(x,y,z) _my_setopt(x, config, #y, y, z)
3341
3364
 
3342
3365
static struct curl_slist *easycode;
3343
3366
 
3344
 
CURLcode _my_setopt(CURL *curl, const char *name, CURLoption tag, ...);
 
3367
CURLcode _my_setopt(CURL *curl, struct Configurable *config, const char *name,
 
3368
                    CURLoption tag, ...);
3345
3369
 
3346
 
CURLcode _my_setopt(CURL *curl, const char *name, CURLoption tag, ...)
 
3370
CURLcode _my_setopt(CURL *curl, struct Configurable *config, const char *name,
 
3371
                    CURLoption tag, ...)
3347
3372
{
3348
3373
  va_list arg;
3349
3374
  CURLcode ret;
3392
3417
    ret = curl_easy_setopt(curl, tag, oval);
3393
3418
  }
3394
3419
 
3395
 
  bufp = curl_maprintf("%scurl_easy_setopt(hnd, %s, %s);%s",
3396
 
                       remark?"/* ":"", name, value,
3397
 
                       remark?" [REMARK] */":"");
3398
 
 
3399
 
  if (!curl_slist_append(easycode, bufp))
3400
 
    ret = CURLE_OUT_OF_MEMORY;
3401
 
  curl_free(bufp);
 
3420
  if(config->libcurl) {
 
3421
    /* we only use this for real if --libcurl was used */
 
3422
 
 
3423
    bufp = curl_maprintf("%scurl_easy_setopt(hnd, %s, %s);%s",
 
3424
                         remark?"/* ":"", name, value,
 
3425
                         remark?" [REMARK] */":"");
 
3426
 
 
3427
    if (!bufp || !curl_slist_append(easycode, bufp))
 
3428
      ret = CURLE_OUT_OF_MEMORY;
 
3429
    if (bufp)
 
3430
      curl_free(bufp);
 
3431
  }
3402
3432
  va_end(arg);
3403
3433
 
3404
3434
  return ret;
3469
3499
}
3470
3500
 
3471
3501
static int
3472
 
operate(struct Configurable *config, int argc, char *argv[])
 
3502
operate(struct Configurable *config, int argc, argv_item_t argv[])
3473
3503
{
3474
3504
  char errorbuffer[CURL_ERROR_SIZE];
3475
3505
  char useragent[128]; /* buah, we don't want a larger default user agent */
3481
3511
  struct OutStruct heads;
3482
3512
  struct InStruct input;
3483
3513
 
3484
 
  char *url = NULL;
3485
 
 
3486
3514
  URLGlob *urls=NULL;
3487
3515
  URLGlob *inglob=NULL;
3488
3516
  int urlnum;
3489
3517
  int infilenum;
3490
 
  char *outfiles;
3491
 
  char *infiles; /* might a glob pattern */
3492
3518
  char *uploadfile=NULL; /* a single file, never a glob */
3493
3519
 
3494
 
  int separator = 0;
3495
 
 
3496
3520
  FILE *infd = stdin;
3497
3521
  bool infdfopen;
3498
3522
  FILE *headerfilep = NULL;
3499
 
  char *urlbuffer=NULL;
3500
3523
  curl_off_t uploadfilesize; /* -1 means unknown */
3501
3524
  bool stillflags=TRUE;
3502
3525
 
3507
3530
  CURL *curl;
3508
3531
  int res = 0;
3509
3532
  int i;
3510
 
  int up; /* upload file counter within a single upload glob */
3511
3533
  long retry_sleep_default;
3512
 
  long retry_numretries;
3513
3534
  long retry_sleep;
3514
 
  long response;
3515
 
  struct timeval retrystart;
3516
3535
 
3517
3536
  char *env;
3518
3537
#ifdef CURLDEBUG
3738
3757
 
3739
3758
  /* loop through the list of given URLs */
3740
3759
  while(urlnode) {
 
3760
    int up; /* upload file counter within a single upload glob */
3741
3761
    char *dourl;
 
3762
    char *url;
 
3763
    char *infiles; /* might be a glob pattern */
 
3764
    char *outfiles=NULL;
3742
3765
 
3743
3766
    /* get the full URL (it might be NULL) */
3744
3767
    dourl=urlnode->url;
3763
3786
    outs.bytes = 0; /* nothing written yet */
3764
3787
 
3765
3788
    /* save outfile pattern before expansion */
3766
 
    outfiles = urlnode->outfile?strdup(urlnode->outfile):NULL;
 
3789
    if (urlnode->outfile) {
 
3790
      outfiles = strdup(urlnode->outfile);
 
3791
      if (!outfiles) {
 
3792
        clean_getout(config);
 
3793
        break;
 
3794
      }
 
3795
    } 
3767
3796
 
3768
3797
    infiles = urlnode->infile;
3769
3798
 
3788
3817
           glob_next_url(inglob):
3789
3818
           (!up?strdup(infiles):NULL));
3790
3819
        up++) {
 
3820
      int separator = 0;
 
3821
      long retry_numretries;
3791
3822
      uploadfilesize=-1;
3792
3823
 
3793
3824
      if(!config->globoff) {
3811
3842
          (url = urls?glob_next_url(urls):(i?NULL:strdup(url)));
3812
3843
          i++) {
3813
3844
        char *outfile;
 
3845
        struct timeval retrystart;
3814
3846
        outfile = outfiles?strdup(outfiles):NULL;
3815
3847
 
3816
3848
        if((urlnode->flags&GETOUT_USEREMOTE) ||
3939
3971
            filep = curl_easy_escape(curl, filep, 0 /* use strlen */);
3940
3972
 
3941
3973
            if(filep) {
3942
 
 
3943
 
              urlbuffer=(char *)malloc(strlen(url) + strlen(filep) + 3);
 
3974
              char *urlbuffer=(char *)malloc(strlen(url) + strlen(filep) + 3);
3944
3975
              if(!urlbuffer) {
3945
3976
                helpf("out of memory\n");
3946
3977
                return CURLE_OUT_OF_MEMORY;
4005
4036
            printf("%s%s\n", CURLseparator, url);
4006
4037
        }
4007
4038
        if (httpgetfields) {
 
4039
          char *urlbuffer;
4008
4040
          /* Find out whether the url contains a file name */
4009
4041
          const char *pc =strstr(url, "://");
4010
4042
          char sep='?';
4190
4222
        /* three new ones in libcurl 7.3: */
4191
4223
        my_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, config->proxytunnel);
4192
4224
        my_setopt(curl, CURLOPT_INTERFACE, config->iface);
4193
 
        my_setopt(curl, CURLOPT_KRB4LEVEL, config->krb4level);
 
4225
        my_setopt(curl, CURLOPT_KRBLEVEL, config->krblevel);
4194
4226
 
4195
4227
        progressbarinit(&progressbar, config);
4196
4228
        if((config->progressmode == CURL_PROGRESS_BAR) &&
4353
4385
              RETRY_FTP,
4354
4386
              RETRY_LAST /* not used */
4355
4387
            } retry = RETRY_NO;
 
4388
            long response;
4356
4389
            if(CURLE_OPERATION_TIMEDOUT == res)
4357
4390
              /* retry timeout always */
4358
4391
              retry = RETRY_TIMEOUT;
4579
4612
 
4580
4613
  /* cleanup the curl handle! */
4581
4614
  curl_easy_cleanup(curl);
4582
 
  curl_slist_append(easycode, "curl_easy_cleanup(hnd);");
 
4615
  if (easycode)
 
4616
    curl_slist_append(easycode, "curl_easy_cleanup(hnd);");
4583
4617
 
4584
4618
  if(config->headerfile && !headerfilep && heads.stream)
4585
4619
    fclose(heads.stream);