~ubuntu-branches/ubuntu/saucy/curl/saucy-201307251546

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Ramakrishnan Muthukrishnan
  • Date: 2010-10-18 11:13:17 UTC
  • mto: (3.6.1 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: james.westby@ubuntu.com-20101018111317-9rkas34ecwtq0upn
Tags: upstream-7.21.2
ImportĀ upstreamĀ versionĀ 7.21.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
#define DEFAULT_MAXREDIRS  50L
149
149
 
150
150
#if defined(O_BINARY) && defined(HAVE_SETMODE)
151
 
  #ifdef __HIGHC__
152
 
    #define SET_BINMODE(file) _setmode(file,O_BINARY)
153
 
  #else
154
 
    #define SET_BINMODE(file) setmode(fileno(file),O_BINARY)
155
 
  #endif
156
 
#else
157
 
  #define SET_BINMODE(file)   ((void)0)
 
151
#ifdef __HIGHC__
 
152
#define SET_BINMODE(file) _setmode(file,O_BINARY)
 
153
#else
 
154
#define SET_BINMODE(file) setmode(fileno(file),O_BINARY)
 
155
#endif
 
156
#else
 
157
#define SET_BINMODE(file)   ((void)0)
158
158
#endif
159
159
 
160
160
#ifndef O_BINARY
331
331
  input_ptr = output_ptr = buffer;
332
332
  in_bytes = out_bytes = length;
333
333
  rc = iconv(outbound_cd, &input_ptr,  &in_bytes,
334
 
                          &output_ptr, &out_bytes);
335
 
  if ((rc == -1) || (in_bytes != 0)) {
 
334
             &output_ptr, &out_bytes);
 
335
  if((rc == -1) || (in_bytes != 0)) {
336
336
    return CURLE_CONV_FAILED;
337
337
  }
338
338
 
364
364
  input_ptr = output_ptr = buffer;
365
365
  in_bytes = out_bytes = length;
366
366
  rc = iconv(inbound_cd, &input_ptr,  &in_bytes,
367
 
                         &output_ptr, &out_bytes);
368
 
  if ((rc == -1) || (in_bytes != 0)) {
 
367
             &output_ptr, &out_bytes);
 
368
  if((rc == -1) || (in_bytes != 0)) {
369
369
    return CURLE_CONV_FAILED;
370
370
  }
371
371
 
383
383
  case CURLINFO_SSL_DATA_IN:
384
384
  case CURLINFO_SSL_DATA_OUT:
385
385
    /* data, treat as ASCII */
386
 
    if ((this_char >= 0x20) && (this_char < 0x7f)) {
 
386
    if((this_char >= 0x20) && (this_char < 0x7f)) {
387
387
      /* printable ASCII hex value: convert to host encoding */
388
388
      convert_from_network(&this_char, 1);
389
389
    }
394
394
    /* fall through to default */
395
395
  default:
396
396
    /* treat as host encoding */
397
 
    if (ISPRINT(this_char)
398
 
        &&  (this_char != '\t')
399
 
        &&  (this_char != '\r')
400
 
        &&  (this_char != '\n')) {
 
397
    if(ISPRINT(this_char)
 
398
       &&  (this_char != '\t')
 
399
       &&  (this_char != '\r')
 
400
       &&  (this_char != '\n')) {
401
401
      /* printable characters excluding tabs and line end characters */
402
402
      return this_char;
403
403
    }
411
411
#ifdef WIN32
412
412
 
413
413
#ifdef __BORLANDC__
414
 
   /* 64-bit lseek-like function unavailable */
 
414
/* 64-bit lseek-like function unavailable */
415
415
#  define _lseeki64(hnd,ofs,whence) lseek(hnd,ofs,whence)
416
416
#endif
417
417
 
418
418
#ifdef __POCC__
419
 
#  if (__POCC__ < 450)
420
 
     /* 64-bit lseek-like function unavailable */
 
419
#  if(__POCC__ < 450)
 
420
/* 64-bit lseek-like function unavailable */
421
421
#    define _lseeki64(hnd,ofs,whence) _lseek(hnd,ofs,whence)
422
422
#  else
423
423
#    define _lseeki64(hnd,ofs,whence) _lseek64(hnd,ofs,whence)
432
432
 * Truncate a file handle at a 64-bit position 'where'.
433
433
 */
434
434
 
435
 
static int ftruncate64 (int fd, curl_off_t where)
 
435
static int ftruncate64(int fd, curl_off_t where)
436
436
{
437
437
  if(_lseeki64(fd, where, SEEK_SET) < 0)
438
438
    return -1;
912
912
  for(i=0; helptext[i]; i++) {
913
913
    puts(helptext[i]);
914
914
#ifdef PRINT_LINES_PAUSE
915
 
    if (i && ((i % PRINT_LINES_PAUSE) == 0))
 
915
    if(i && ((i % PRINT_LINES_PAUSE) == 0))
916
916
      pressanykey();
917
917
#endif
918
918
  }
986
986
 
987
987
/* Structure for storing the information needed to build a multiple files
988
988
 * section
989
 
*/
 
989
 */
990
990
struct multi_files {
991
991
  struct curl_forms   form;
992
992
  struct multi_files *next;
995
995
/* Add a new list entry possibly with a type_name
996
996
 */
997
997
static struct multi_files *
998
 
AddMultiFiles (const char *file_name,
999
 
               const char *type_name,
1000
 
               const char *show_filename,
1001
 
               struct multi_files **multi_start,
1002
 
               struct multi_files **multi_current)
 
998
AddMultiFiles(const char *file_name,
 
999
              const char *type_name,
 
1000
              const char *show_filename,
 
1001
              struct multi_files **multi_start,
 
1002
              struct multi_files **multi_current)
1003
1003
{
1004
1004
  struct multi_files *multi;
1005
1005
  struct multi_files *multi_type = NULL;
1006
1006
  struct multi_files *multi_name = NULL;
1007
1007
  multi = malloc(sizeof(struct multi_files));
1008
 
  if (multi) {
 
1008
  if(multi) {
1009
1009
    memset(multi, 0, sizeof(struct multi_files));
1010
1010
    multi->form.option = CURLFORM_FILE;
1011
1011
    multi->form.value = file_name;
1013
1013
  else
1014
1014
    return NULL;
1015
1015
 
1016
 
  if (!*multi_start)
 
1016
  if(!*multi_start)
1017
1017
    *multi_start = multi;
1018
1018
 
1019
 
  if (type_name) {
 
1019
  if(type_name) {
1020
1020
    multi_type = malloc(sizeof(struct multi_files));
1021
 
    if (multi_type) {
 
1021
    if(multi_type) {
1022
1022
      memset(multi_type, 0, sizeof(struct multi_files));
1023
1023
      multi_type->form.option = CURLFORM_CONTENTTYPE;
1024
1024
      multi_type->form.value = type_name;
1027
1027
      multi = multi_type;
1028
1028
    }
1029
1029
    else {
1030
 
      free (multi);
 
1030
      free(multi);
1031
1031
      return NULL;
1032
1032
    }
1033
1033
  }
1034
 
  if (show_filename) {
 
1034
  if(show_filename) {
1035
1035
    multi_name = malloc(sizeof(struct multi_files));
1036
 
    if (multi_name) {
 
1036
    if(multi_name) {
1037
1037
      memset(multi_name, 0, sizeof(struct multi_files));
1038
1038
      multi_name->form.option = CURLFORM_FILENAME;
1039
1039
      multi_name->form.value = show_filename;
1042
1042
      multi = multi_name;
1043
1043
    }
1044
1044
    else {
1045
 
      free (multi);
 
1045
      free(multi);
1046
1046
      return NULL;
1047
1047
    }
1048
1048
  }
1049
1049
 
1050
 
  if (*multi_current)
 
1050
  if(*multi_current)
1051
1051
    (*multi_current)->next = multi;
1052
1052
 
1053
1053
  *multi_current = multi;
1057
1057
 
1058
1058
/* Free the items of the list.
1059
1059
 */
1060
 
static void FreeMultiInfo (struct multi_files *multi_start)
 
1060
static void FreeMultiInfo(struct multi_files *multi_start)
1061
1061
{
1062
1062
  struct multi_files *multi;
1063
 
  while (multi_start) {
 
1063
  while(multi_start) {
1064
1064
    multi = multi_start;
1065
1065
    multi_start = multi_start->next;
1066
 
    free (multi);
 
1066
    free(multi);
1067
1067
  }
1068
1068
}
1069
1069
 
1070
1070
/* Print list of OpenSSL engines supported.
1071
1071
 */
1072
 
static void list_engines (const struct curl_slist *engines)
 
1072
static void list_engines(const struct curl_slist *engines)
1073
1073
{
1074
 
  puts ("Build-time engines:");
1075
 
  if (!engines) {
1076
 
    puts ("  <none>");
 
1074
  puts("Build-time engines:");
 
1075
  if(!engines) {
 
1076
    puts("  <none>");
1077
1077
    return;
1078
1078
  }
1079
 
  for ( ; engines; engines = engines->next)
1080
 
    printf ("  %s\n", engines->data);
 
1079
  for( ; engines; engines = engines->next)
 
1080
    printf("  %s\n", engines->data);
1081
1081
}
1082
1082
 
1083
1083
/***************************************************************************
1190
1190
            while(ISSPACE(*ptr))
1191
1191
              ptr++;
1192
1192
 
1193
 
            if(curlx_strnequal("type=", ptr, 5)) {
 
1193
            if(checkprefix("type=", ptr)) {
1194
1194
              /* set type pointer */
1195
1195
              type = &ptr[5];
1196
1196
 
1199
1199
                             major, minor)) {
1200
1200
                warnf(config, "Illegally formatted content-type field!\n");
1201
1201
                free(contents);
1202
 
                FreeMultiInfo (multi_start);
 
1202
                FreeMultiInfo(multi_start);
1203
1203
                return 2; /* illegal content-type syntax! */
1204
1204
              }
 
1205
 
1205
1206
              /* now point beyond the content-type specifier */
1206
1207
              sep = (char *)type + strlen(major)+strlen(minor)+1;
1207
1208
 
 
1209
              /* there's a semicolon following - we check if it is a filename
 
1210
                 specified and if not we simply assume that it is text that
 
1211
                 the user wants included in the type and include that too up
 
1212
                 to the next zero or semicolon. */
 
1213
              if((*sep==';') && !checkprefix(";filename=", sep)) {
 
1214
                sep2 = strchr(sep+1, ';');
 
1215
                if(sep2)
 
1216
                  sep = sep2;
 
1217
                else
 
1218
                  sep = sep+strlen(sep); /* point to end of string */
 
1219
              }
 
1220
 
1208
1221
              if(*sep) {
1209
1222
                *sep=0; /* zero terminate type string */
1210
1223
 
1213
1226
              else
1214
1227
                ptr = NULL; /* end */
1215
1228
            }
1216
 
            else if(curlx_strnequal("filename=", ptr, 9)) {
 
1229
            else if(checkprefix("filename=", ptr)) {
1217
1230
              filename = &ptr[9];
1218
1231
              ptr=strchr(filename, FORM_TYPE_SEPARATOR);
1219
1232
              if(!ptr) {
1244
1257
        }
1245
1258
        /* if type == NULL curl_formadd takes care of the problem */
1246
1259
 
1247
 
        if (!AddMultiFiles (contp, type, filename, &multi_start,
1248
 
                            &multi_current)) {
 
1260
        if(!AddMultiFiles(contp, type, filename, &multi_start,
 
1261
                          &multi_current)) {
1249
1262
          warnf(config, "Error building form post!\n");
1250
1263
          free(contents);
1251
 
          FreeMultiInfo (multi_start);
 
1264
          FreeMultiInfo(multi_start);
1252
1265
          return 3;
1253
1266
        }
1254
1267
        contp = sep; /* move the contents pointer to after the separator */
1256
1269
      } while(sep && *sep); /* loop if there's another file name */
1257
1270
 
1258
1271
      /* now we add the multiple files section */
1259
 
      if (multi_start) {
 
1272
      if(multi_start) {
1260
1273
        struct curl_forms *forms = NULL;
1261
1274
        struct multi_files *ptr = multi_start;
1262
1275
        unsigned int i, count = 0;
1263
 
        while (ptr) {
 
1276
        while(ptr) {
1264
1277
          ptr = ptr->next;
1265
1278
          ++count;
1266
1279
        }
1267
1280
        forms = malloc((count+1)*sizeof(struct curl_forms));
1268
 
        if (!forms)
 
1281
        if(!forms)
1269
1282
        {
1270
1283
          fprintf(config->errors, "Error building form post!\n");
1271
1284
          free(contents);
1272
 
          FreeMultiInfo (multi_start);
 
1285
          FreeMultiInfo(multi_start);
1273
1286
          return 4;
1274
1287
        }
1275
 
        for (i = 0, ptr = multi_start; i < count; ++i, ptr = ptr->next)
 
1288
        for(i = 0, ptr = multi_start; i < count; ++i, ptr = ptr->next)
1276
1289
        {
1277
1290
          forms[i].option = ptr->form.option;
1278
1291
          forms[i].value = ptr->form.value;
1279
1292
        }
1280
1293
        forms[count].option = CURLFORM_END;
1281
 
        FreeMultiInfo (multi_start);
1282
 
        if (curl_formadd(httppost, last_post,
1283
 
                         CURLFORM_COPYNAME, name,
1284
 
                         CURLFORM_ARRAY, forms, CURLFORM_END) != 0) {
 
1294
        FreeMultiInfo(multi_start);
 
1295
        if(curl_formadd(httppost, last_post,
 
1296
                        CURLFORM_COPYNAME, name,
 
1297
                        CURLFORM_ARRAY, forms, CURLFORM_END) != 0) {
1285
1298
          warnf(config, "curl_formadd failed!\n");
1286
1299
          free(forms);
1287
1300
          free(contents);
1312
1325
        i++;
1313
1326
        info[i].option = CURLFORM_END;
1314
1327
 
1315
 
        if (curl_formadd(httppost, last_post,
1316
 
                         CURLFORM_ARRAY, info, CURLFORM_END ) != 0) {
 
1328
        if(curl_formadd(httppost, last_post,
 
1329
                        CURLFORM_ARRAY, info, CURLFORM_END ) != 0) {
1317
1330
          warnf(config, "curl_formadd failed, possibly the file %s is bad!\n",
1318
1331
                contp+1);
1319
1332
          free(contents);
1328
1341
        info[i].value = contp;
1329
1342
        i++;
1330
1343
        info[i].option = CURLFORM_END;
1331
 
        if (curl_formadd(httppost, last_post,
1332
 
                         CURLFORM_ARRAY, info, CURLFORM_END) != 0) {
 
1344
        if(curl_formadd(httppost, last_post,
 
1345
                        CURLFORM_ARRAY, info, CURLFORM_END) != 0) {
1333
1346
          warnf(config, "curl_formadd failed!\n");
1334
1347
          free(contents);
1335
1348
          return 7;
1468
1481
  /* now that GetStr has copied the contents of nextarg, wipe the next
1469
1482
   * argument out so that the username:password isn't displayed in the
1470
1483
   * system process list */
1471
 
  if (str) {
 
1484
  if(str) {
1472
1485
    size_t len = strlen(str);
1473
1486
    memset(str, ' ', len);
1474
1487
  }
1539
1552
    { "smtp", CURLPROTO_SMTP },
1540
1553
    { "smtps", CURLPROTO_SMTPS },
1541
1554
    { "rtsp", CURLPROTO_RTSP },
 
1555
    { "gopher", CURLPROTO_GOPHER },
1542
1556
    { NULL, 0 }
1543
1557
  };
1544
1558
 
1547
1561
 
1548
1562
  buffer = strdup(str); /* because strtok corrupts it */
1549
1563
 
1550
 
  for (token = strtok(buffer, sep);
1551
 
       token;
1552
 
       token = strtok(NULL, sep)) {
 
1564
  for(token = strtok(buffer, sep);
 
1565
      token;
 
1566
      token = strtok(NULL, sep)) {
1553
1567
    enum e_action { allow, deny, set } action = allow;
1554
1568
 
1555
1569
    struct sprotos const *pp;
1556
1570
 
1557
1571
    /* Process token modifiers */
1558
 
    while (!ISALNUM(*token)) { /* may be NULL if token is all modifiers */
 
1572
    while(!ISALNUM(*token)) { /* may be NULL if token is all modifiers */
1559
1573
      switch (*token++) {
1560
1574
      case '=':
1561
1575
        action = set;
1572
1586
      }
1573
1587
    }
1574
1588
 
1575
 
    for (pp=protos; pp->name; pp++) {
1576
 
      if (curlx_raw_equal(token, pp->name)) {
 
1589
    for(pp=protos; pp->name; pp++) {
 
1590
      if(curlx_raw_equal(token, pp->name)) {
1577
1591
        switch (action) {
1578
1592
        case deny:
1579
1593
          *val &= ~(pp->bit);
1589
1603
      }
1590
1604
    }
1591
1605
 
1592
 
    if (!(pp->name)) { /* unknown protocol */
 
1606
    if(!(pp->name)) { /* unknown protocol */
1593
1607
      /* If they have specified only this protocol, we say treat it as
1594
1608
         if no protocols are allowed */
1595
 
      if (action == set)
 
1609
      if(action == set)
1596
1610
        *val = 0;
1597
1611
      warnf(config, "unrecognized protocol '%s'\n", token);
1598
1612
    }
1611
1625
 */
1612
1626
static int str2offset(curl_off_t *val, const char *str)
1613
1627
{
1614
 
#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
 
1628
#if(CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
1615
1629
  *val = curlx_strtoofft(str, NULL, 0);
1616
1630
  if((*val == CURL_OFF_T_MAX || *val == CURL_OFF_T_MIN) && (ERRNO == ERANGE))
1617
1631
    return 1;
1618
1632
#else
1619
1633
  *val = strtol(str, NULL, 0);
1620
 
  if ((*val == LONG_MIN || *val == LONG_MAX) && ERRNO == ERANGE)
 
1634
  if((*val == LONG_MIN || *val == LONG_MAX) && ERRNO == ERANGE)
1621
1635
    return 1;
1622
1636
#endif
1623
1637
  return 0;
1641
1655
 
1642
1656
    /* build a nice-looking prompt */
1643
1657
    curlx_msnprintf(prompt, sizeof(prompt),
1644
 
                   "Enter %s password for user '%s':",
1645
 
                   kind, *userpwd);
 
1658
                    "Enter %s password for user '%s':",
 
1659
                    kind, *userpwd);
1646
1660
 
1647
1661
    /* get password */
1648
1662
    getpass_r(prompt, passwd, sizeof(passwd));
1707
1721
  int keepidle = (int)config->alivetime;
1708
1722
#endif
1709
1723
 
1710
 
  switch (purpose) {
 
1724
  switch(purpose) {
1711
1725
  case CURLSOCKTYPE_IPCXN:
1712
1726
    if(setsockopt(curlfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&onoff,
1713
1727
                  sizeof(onoff)) < 0) {
1717
1731
      return 0;
1718
1732
    }
1719
1733
    else {
1720
 
      if (config->alivetime) {
 
1734
      if(config->alivetime) {
1721
1735
#ifdef TCP_KEEPIDLE
1722
1736
        if(setsockopt(curlfd, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&keepidle,
1723
1737
                      sizeof(keepidle)) < 0) {
1769
1783
  /* single-letter,
1770
1784
     long-name,
1771
1785
     boolean whether it takes an additional argument
1772
 
     */
 
1786
  */
1773
1787
  static const struct LongShort aliases[]= {
1774
1788
    /* all these ones, starting with "*" or "$" as a short-option have *no*
1775
1789
       short option to mention. */
2065
2079
        config->tracetype = TRACE_ASCII;
2066
2080
        break;
2067
2081
      case 'i': /* --limit-rate */
2068
 
        {
2069
 
          /* We support G, M, K too */
2070
 
          char *unit;
2071
 
          curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
2072
 
 
2073
 
          if(!*unit)
2074
 
            unit=(char *)"b";
2075
 
          else if(strlen(unit) > 1)
2076
 
            unit=(char *)"w"; /* unsupported */
2077
 
 
2078
 
          switch(*unit) {
2079
 
          case 'G':
2080
 
          case 'g':
2081
 
            value *= 1024*1024*1024;
2082
 
            break;
2083
 
          case 'M':
2084
 
          case 'm':
2085
 
            value *= 1024*1024;
2086
 
            break;
2087
 
          case 'K':
2088
 
          case 'k':
2089
 
            value *= 1024;
2090
 
            break;
2091
 
          case 'b':
2092
 
          case 'B':
2093
 
            /* for plain bytes, leave as-is */
2094
 
            break;
2095
 
          default:
2096
 
            warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
2097
 
            return PARAM_BAD_USE;
2098
 
          }
2099
 
          config->recvpersecond = value;
2100
 
          config->sendpersecond = value;
 
2082
      {
 
2083
        /* We support G, M, K too */
 
2084
        char *unit;
 
2085
        curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
 
2086
 
 
2087
        if(!*unit)
 
2088
          unit=(char *)"b";
 
2089
        else if(strlen(unit) > 1)
 
2090
          unit=(char *)"w"; /* unsupported */
 
2091
 
 
2092
        switch(*unit) {
 
2093
        case 'G':
 
2094
        case 'g':
 
2095
          value *= 1024*1024*1024;
 
2096
          break;
 
2097
        case 'M':
 
2098
        case 'm':
 
2099
          value *= 1024*1024;
 
2100
          break;
 
2101
        case 'K':
 
2102
        case 'k':
 
2103
          value *= 1024;
 
2104
          break;
 
2105
        case 'b':
 
2106
        case 'B':
 
2107
          /* for plain bytes, leave as-is */
 
2108
          break;
 
2109
        default:
 
2110
          warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
 
2111
          return PARAM_BAD_USE;
2101
2112
        }
2102
 
        break;
 
2113
        config->recvpersecond = value;
 
2114
        config->sendpersecond = value;
 
2115
      }
 
2116
      break;
2103
2117
 
2104
2118
      case 'j': /* --compressed */
2105
2119
        config->encoding = toggle;
2192
2206
        }
2193
2207
        else
2194
2208
          config->errors = stdout;
2195
 
      break;
 
2209
        break;
2196
2210
      case 'w': /* --interface */
2197
2211
        /* interface */
2198
2212
        GetStr(&config->iface, nextarg);
2217
2231
        break;
2218
2232
 
2219
2233
      default: /* the URL! */
2220
 
        {
2221
 
          struct getout *url;
2222
 
          if(config->url_get || (config->url_get=config->url_list)) {
2223
 
            /* there's a node here, if it already is filled-in continue to find
2224
 
               an "empty" node */
2225
 
            while(config->url_get && (config->url_get->flags&GETOUT_URL))
2226
 
              config->url_get = config->url_get->next;
2227
 
          }
2228
 
 
2229
 
          /* now there might or might not be an available node to fill in! */
2230
 
 
2231
 
          if(config->url_get)
2232
 
            /* existing node */
2233
 
            url = config->url_get;
2234
 
          else
2235
 
            /* there was no free node, create one! */
2236
 
            url=new_getout(config);
2237
 
 
2238
 
          if(url) {
2239
 
            /* fill in the URL */
2240
 
            GetStr(&url->url, nextarg);
2241
 
            url->flags |= GETOUT_URL;
2242
 
          }
2243
 
        }
 
2234
      {
 
2235
        struct getout *url;
 
2236
        if(config->url_get || (config->url_get=config->url_list)) {
 
2237
          /* there's a node here, if it already is filled-in continue to find
 
2238
             an "empty" node */
 
2239
          while(config->url_get && (config->url_get->flags&GETOUT_URL))
 
2240
            config->url_get = config->url_get->next;
 
2241
        }
 
2242
 
 
2243
        /* now there might or might not be an available node to fill in! */
 
2244
 
 
2245
        if(config->url_get)
 
2246
          /* existing node */
 
2247
          url = config->url_get;
 
2248
        else
 
2249
          /* there was no free node, create one! */
 
2250
          url=new_getout(config);
 
2251
 
 
2252
        if(url) {
 
2253
          /* fill in the URL */
 
2254
          GetStr(&url->url, nextarg);
 
2255
          url->flags |= GETOUT_URL;
 
2256
        }
 
2257
      }
2244
2258
      }
2245
2259
      break;
2246
2260
    case '$': /* more options without a short option */
2348
2362
      case 'y': /* --ftp-ssl-ccc */
2349
2363
        config->ftp_ssl_ccc = toggle;
2350
2364
        if(!config->ftp_ssl_ccc_mode)
2351
 
            config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
 
2365
          config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
2352
2366
        break;
2353
2367
      case 'j': /* --ftp-ssl-ccc-mode */
2354
2368
        config->ftp_ssl_ccc = TRUE;
2490
2504
      break;
2491
2505
    case 'd':
2492
2506
      /* postfield data */
2493
 
      {
2494
 
        char *postdata=NULL;
2495
 
        FILE *file;
2496
 
 
2497
 
        if(subletter == 'e') { /* --data-urlencode*/
2498
 
          /* [name]=[content], we encode the content part only
2499
 
           * [name]@[file name]
2500
 
           *
2501
 
           * Case 2: we first load the file using that name and then encode
2502
 
           * the content.
2503
 
           */
2504
 
          const char *p = strchr(nextarg, '=');
2505
 
          size_t size = 0;
2506
 
          size_t nlen;
2507
 
          char is_file;
2508
 
          if(!p)
2509
 
            /* there was no '=' letter, check for a '@' instead */
2510
 
            p = strchr(nextarg, '@');
2511
 
          if (p) {
2512
 
            nlen = p - nextarg; /* length of the name part */
2513
 
            is_file = *p++; /* pass the separator */
2514
 
          }
2515
 
          else {
2516
 
            /* neither @ nor =, so no name and it isn't a file */
2517
 
            nlen = is_file = 0;
2518
 
            p = nextarg;
2519
 
          }
2520
 
          if('@' == is_file) {
2521
 
            /* a '@' letter, it means that a file name or - (stdin) follows */
2522
 
 
2523
 
            if(curlx_strequal("-", p)) {
2524
 
              file = stdin;
2525
 
              SET_BINMODE(stdin);
2526
 
            }
2527
 
            else {
2528
 
              file = fopen(p, "rb");
2529
 
              if(!file)
2530
 
                warnf(config,
2531
 
                      "Couldn't read data from file \"%s\", this makes "
2532
 
                      "an empty POST.\n", nextarg);
2533
 
            }
2534
 
 
2535
 
            err = file2memory(&postdata, &size, file);
2536
 
 
2537
 
            if(file && (file != stdin))
2538
 
              fclose(file);
2539
 
            if(err)
2540
 
              return err;
2541
 
          }
2542
 
          else {
2543
 
            GetStr(&postdata, p);
2544
 
            size = strlen(postdata);
2545
 
          }
2546
 
 
2547
 
          if(!postdata) {
2548
 
            /* no data from the file, point to a zero byte string to make this
2549
 
               get sent as a POST anyway */
2550
 
            postdata=strdup("");
2551
 
          }
2552
 
          else {
2553
 
            char *enc = curl_easy_escape(config->easy, postdata, (int)size);
2554
 
            free(postdata); /* no matter if it worked or not */
2555
 
            if(enc) {
2556
 
              /* now make a string with the name from above and append the
2557
 
                 encoded string */
2558
 
              size_t outlen = nlen + strlen(enc) + 2;
2559
 
              char *n = malloc(outlen);
2560
 
              if(!n) {
2561
 
                curl_free(enc);
2562
 
                return PARAM_NO_MEM;
2563
 
              }
2564
 
              if (nlen > 0) /* only append '=' if we have a name */
2565
 
                snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
2566
 
              else
2567
 
                strcpy(n, enc);
2568
 
              curl_free(enc);
2569
 
              postdata = n;
2570
 
            }
2571
 
            else
2572
 
              return PARAM_NO_MEM;
2573
 
          }
2574
 
        }
2575
 
        else if('@' == *nextarg) {
2576
 
          size_t size = 0;
2577
 
          /* the data begins with a '@' letter, it means that a file name
2578
 
             or - (stdin) follows */
2579
 
          nextarg++; /* pass the @ */
2580
 
 
2581
 
          if(curlx_strequal("-", nextarg)) {
 
2507
    {
 
2508
      char *postdata=NULL;
 
2509
      FILE *file;
 
2510
 
 
2511
      if(subletter == 'e') { /* --data-urlencode*/
 
2512
        /* [name]=[content], we encode the content part only
 
2513
         * [name]@[file name]
 
2514
         *
 
2515
         * Case 2: we first load the file using that name and then encode
 
2516
         * the content.
 
2517
         */
 
2518
        const char *p = strchr(nextarg, '=');
 
2519
        size_t size = 0;
 
2520
        size_t nlen;
 
2521
        char is_file;
 
2522
        if(!p)
 
2523
          /* there was no '=' letter, check for a '@' instead */
 
2524
          p = strchr(nextarg, '@');
 
2525
        if(p) {
 
2526
          nlen = p - nextarg; /* length of the name part */
 
2527
          is_file = *p++; /* pass the separator */
 
2528
        }
 
2529
        else {
 
2530
          /* neither @ nor =, so no name and it isn't a file */
 
2531
          nlen = is_file = 0;
 
2532
          p = nextarg;
 
2533
        }
 
2534
        if('@' == is_file) {
 
2535
          /* a '@' letter, it means that a file name or - (stdin) follows */
 
2536
 
 
2537
          if(curlx_strequal("-", p)) {
2582
2538
            file = stdin;
2583
 
            if(subletter == 'b') /* forced data-binary */
2584
 
              SET_BINMODE(stdin);
 
2539
            SET_BINMODE(stdin);
2585
2540
          }
2586
2541
          else {
2587
 
            file = fopen(nextarg, "rb");
 
2542
            file = fopen(p, "rb");
2588
2543
            if(!file)
2589
 
              warnf(config, "Couldn't read data from file \"%s\", this makes "
 
2544
              warnf(config,
 
2545
                    "Couldn't read data from file \"%s\", this makes "
2590
2546
                    "an empty POST.\n", nextarg);
2591
2547
          }
2592
2548
 
2593
 
          if(subletter == 'b') {
2594
 
            /* forced binary */
2595
 
            err = file2memory(&postdata, &size, file);
2596
 
            config->postfieldsize = (curl_off_t)size;
2597
 
          }
2598
 
          else
2599
 
            err = file2string(&postdata, file);
 
2549
          err = file2memory(&postdata, &size, file);
2600
2550
 
2601
2551
          if(file && (file != stdin))
2602
2552
            fclose(file);
2603
2553
          if(err)
2604
2554
            return err;
 
2555
        }
 
2556
        else {
 
2557
          GetStr(&postdata, p);
 
2558
          size = strlen(postdata);
 
2559
        }
2605
2560
 
2606
 
          if(!postdata) {
2607
 
            /* no data from the file, point to a zero byte string to make this
2608
 
               get sent as a POST anyway */
2609
 
            postdata=strdup("");
 
2561
        if(!postdata) {
 
2562
          /* no data from the file, point to a zero byte string to make this
 
2563
             get sent as a POST anyway */
 
2564
          postdata=strdup("");
 
2565
        }
 
2566
        else {
 
2567
          char *enc = curl_easy_escape(config->easy, postdata, (int)size);
 
2568
          free(postdata); /* no matter if it worked or not */
 
2569
          if(enc) {
 
2570
            /* now make a string with the name from above and append the
 
2571
               encoded string */
 
2572
            size_t outlen = nlen + strlen(enc) + 2;
 
2573
            char *n = malloc(outlen);
 
2574
            if(!n) {
 
2575
              curl_free(enc);
 
2576
              return PARAM_NO_MEM;
 
2577
            }
 
2578
            if(nlen > 0) /* only append '=' if we have a name */
 
2579
              snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
 
2580
            else
 
2581
              strcpy(n, enc);
 
2582
            curl_free(enc);
 
2583
            postdata = n;
2610
2584
          }
2611
 
        }
2612
 
        else {
2613
 
          GetStr(&postdata, nextarg);
2614
 
        }
2615
 
 
2616
 
#ifdef CURL_DOES_CONVERSIONS
2617
 
        if(subletter != 'b') { /* NOT forced binary, convert to ASCII */
2618
 
          convert_to_network(postdata, strlen(postdata));
2619
 
        }
2620
 
#endif
2621
 
 
2622
 
        if(config->postfields) {
2623
 
          /* we already have a string, we append this one
2624
 
             with a separating &-letter */
2625
 
          char *oldpost=config->postfields;
2626
 
          size_t newlen = strlen(oldpost) + strlen(postdata) + 2;
2627
 
          config->postfields=malloc(newlen);
2628
 
          if(!config->postfields) {
2629
 
            free(postdata);
 
2585
          else
2630
2586
            return PARAM_NO_MEM;
2631
 
          }
2632
 
          /* use ASCII value 0x26 for '&' to accommodate non-ASCII platforms */
2633
 
          snprintf(config->postfields, newlen, "%s\x26%s", oldpost, postdata);
2634
 
          free(oldpost);
 
2587
        }
 
2588
      }
 
2589
      else if('@' == *nextarg) {
 
2590
        size_t size = 0;
 
2591
        /* the data begins with a '@' letter, it means that a file name
 
2592
           or - (stdin) follows */
 
2593
        nextarg++; /* pass the @ */
 
2594
 
 
2595
        if(curlx_strequal("-", nextarg)) {
 
2596
          file = stdin;
 
2597
          if(subletter == 'b') /* forced data-binary */
 
2598
            SET_BINMODE(stdin);
 
2599
        }
 
2600
        else {
 
2601
          file = fopen(nextarg, "rb");
 
2602
          if(!file)
 
2603
            warnf(config, "Couldn't read data from file \"%s\", this makes "
 
2604
                  "an empty POST.\n", nextarg);
 
2605
        }
 
2606
 
 
2607
        if(subletter == 'b') {
 
2608
          /* forced binary */
 
2609
          err = file2memory(&postdata, &size, file);
 
2610
          config->postfieldsize = (curl_off_t)size;
 
2611
        }
 
2612
        else
 
2613
          err = file2string(&postdata, file);
 
2614
 
 
2615
        if(file && (file != stdin))
 
2616
          fclose(file);
 
2617
        if(err)
 
2618
          return err;
 
2619
 
 
2620
        if(!postdata) {
 
2621
          /* no data from the file, point to a zero byte string to make this
 
2622
             get sent as a POST anyway */
 
2623
          postdata=strdup("");
 
2624
        }
 
2625
      }
 
2626
      else {
 
2627
        GetStr(&postdata, nextarg);
 
2628
      }
 
2629
 
 
2630
#ifdef CURL_DOES_CONVERSIONS
 
2631
      if(subletter != 'b') { /* NOT forced binary, convert to ASCII */
 
2632
        convert_to_network(postdata, strlen(postdata));
 
2633
      }
 
2634
#endif
 
2635
 
 
2636
      if(config->postfields) {
 
2637
        /* we already have a string, we append this one
 
2638
           with a separating &-letter */
 
2639
        char *oldpost=config->postfields;
 
2640
        size_t newlen = strlen(oldpost) + strlen(postdata) + 2;
 
2641
        config->postfields=malloc(newlen);
 
2642
        if(!config->postfields) {
2635
2643
          free(postdata);
 
2644
          return PARAM_NO_MEM;
2636
2645
        }
2637
 
        else
2638
 
          config->postfields=postdata;
 
2646
        /* use ASCII value 0x26 for '&' to accommodate non-ASCII platforms */
 
2647
        snprintf(config->postfields, newlen, "%s\x26%s", oldpost, postdata);
 
2648
        free(oldpost);
 
2649
        free(postdata);
2639
2650
      }
2640
 
      /*
2641
 
        We can't set the request type here, as this data might be used in
2642
 
        a simple GET if -G is used. Already or soon.
 
2651
      else
 
2652
        config->postfields=postdata;
 
2653
    }
 
2654
    /*
 
2655
      We can't set the request type here, as this data might be used in
 
2656
      a simple GET if -G is used. Already or soon.
2643
2657
 
2644
 
        if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq))
2645
 
          return PARAM_BAD_USE;
2646
 
      */
2647
 
      break;
 
2658
      if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq))
 
2659
      return PARAM_BAD_USE;
 
2660
    */
 
2661
    break;
2648
2662
    case 'D':
2649
2663
      /* dump-header to given file name */
2650
2664
      GetStr(&config->headerfile, nextarg);
2651
2665
      break;
2652
2666
    case 'e':
2653
 
      {
2654
 
        char *ptr = strstr(nextarg, ";auto");
2655
 
        if(ptr) {
2656
 
          /* Automatic referer requested, this may be combined with a
2657
 
             set initial one */
2658
 
          config->autoreferer = TRUE;
2659
 
          *ptr = 0; /* zero terminate here */
2660
 
        }
2661
 
        else
2662
 
          config->autoreferer = FALSE;
2663
 
        GetStr(&config->referer, nextarg);
 
2667
    {
 
2668
      char *ptr = strstr(nextarg, ";auto");
 
2669
      if(ptr) {
 
2670
        /* Automatic referer requested, this may be combined with a
 
2671
           set initial one */
 
2672
        config->autoreferer = TRUE;
 
2673
        *ptr = 0; /* zero terminate here */
2664
2674
      }
2665
 
      break;
 
2675
      else
 
2676
        config->autoreferer = FALSE;
 
2677
      GetStr(&config->referer, nextarg);
 
2678
    }
 
2679
    break;
2666
2680
    case 'E':
2667
2681
      switch(subletter) {
2668
2682
      case 'a': /* CA info PEM file */
2684
2698
        break;
2685
2699
      case 'f': /* crypto engine */
2686
2700
        GetStr(&config->engine, nextarg);
2687
 
        if (config->engine && curlx_raw_equal(config->engine,"list"))
2688
 
           config->list_engines = TRUE;
 
2701
        if(config->engine && curlx_raw_equal(config->engine,"list"))
 
2702
          config->list_engines = TRUE;
2689
2703
        break;
2690
2704
      case 'g': /* CA info PEM file */
2691
2705
        /* CA cert directory */
2696
2710
        break;
2697
2711
      case 'i': /* --hostpubmd5 md5 of the host public key */
2698
2712
        GetStr(&config->hostpubmd5, nextarg);
2699
 
        if (!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
2700
 
           return PARAM_BAD_USE;
 
2713
        if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
 
2714
          return PARAM_BAD_USE;
2701
2715
        break;
2702
2716
      case 'j': /* CRL info PEM file */
2703
2717
        /* CRL file */
2704
2718
        GetStr(&config->crlfile, nextarg);
2705
2719
        break;
2706
2720
      default: /* certificate file */
2707
 
        {
2708
 
          char *ptr = strchr(nextarg, ':');
2709
 
          /* Since we live in a world of weirdness and confusion, the win32
2710
 
             dudes can use : when using drive letters and thus
2711
 
             c:\file:password needs to work. In order not to break
2712
 
             compatibility, we still use : as separator, but we try to detect
2713
 
             when it is used for a file name! On windows. */
 
2721
      {
 
2722
        char *ptr = strchr(nextarg, ':');
 
2723
        /* Since we live in a world of weirdness and confusion, the win32
 
2724
           dudes can use : when using drive letters and thus
 
2725
           c:\file:password needs to work. In order not to break
 
2726
           compatibility, we still use : as separator, but we try to detect
 
2727
           when it is used for a file name! On windows. */
2714
2728
#ifdef WIN32
2715
 
          if(ptr &&
2716
 
             (ptr == &nextarg[1]) &&
2717
 
             (nextarg[2] == '\\' || nextarg[2] == '/') &&
2718
 
             (ISALPHA(nextarg[0])) )
2719
 
             /* colon in the second column, followed by a backslash, and the
2720
 
                first character is an alphabetic letter:
 
2729
        if(ptr &&
 
2730
           (ptr == &nextarg[1]) &&
 
2731
           (nextarg[2] == '\\' || nextarg[2] == '/') &&
 
2732
           (ISALPHA(nextarg[0])) )
 
2733
          /* colon in the second column, followed by a backslash, and the
 
2734
             first character is an alphabetic letter:
2721
2735
 
2722
 
                this is a drive letter colon */
2723
 
            ptr = strchr(&nextarg[3], ':'); /* find the next one instead */
 
2736
             this is a drive letter colon */
 
2737
          ptr = strchr(&nextarg[3], ':'); /* find the next one instead */
2724
2738
#endif
2725
 
          if(ptr) {
2726
 
            /* we have a password too */
2727
 
            *ptr=0;
2728
 
            ptr++;
2729
 
            GetStr(&config->key_passwd, ptr);
2730
 
          }
2731
 
          GetStr(&config->cert, nextarg);
2732
 
          cleanarg(nextarg);
 
2739
        if(ptr) {
 
2740
          /* we have a password too */
 
2741
          *ptr=0;
 
2742
          ptr++;
 
2743
          GetStr(&config->key_passwd, ptr);
2733
2744
        }
 
2745
        GetStr(&config->cert, nextarg);
 
2746
        cleanarg(nextarg);
 
2747
      }
2734
2748
      }
2735
2749
      break;
2736
2750
    case 'f':
2789
2803
        return PARAM_BAD_USE;
2790
2804
      break;
2791
2805
    case 'J': /* --remote-header-name */
2792
 
      if (config->include_headers) {
 
2806
      if(config->include_headers) {
2793
2807
        warnf(config,
2794
2808
              "--include and --remote-header-name cannot be combined.\n");
2795
2809
        return PARAM_BAD_USE;
2860
2874
        config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
2861
2875
        break;
2862
2876
      }
2863
 
    /* fall-through! */
 
2877
      /* fall-through! */
2864
2878
    case 'o': /* --output */
2865
2879
      /* output file */
2866
 
      {
2867
 
        struct getout *url;
2868
 
        if(config->url_out || (config->url_out=config->url_list)) {
2869
 
          /* there's a node here, if it already is filled-in continue to find
2870
 
             an "empty" node */
2871
 
          while(config->url_out && (config->url_out->flags&GETOUT_OUTFILE))
2872
 
            config->url_out = config->url_out->next;
 
2880
    {
 
2881
      struct getout *url;
 
2882
      if(config->url_out || (config->url_out=config->url_list)) {
 
2883
        /* there's a node here, if it already is filled-in continue to find
 
2884
           an "empty" node */
 
2885
        while(config->url_out && (config->url_out->flags&GETOUT_OUTFILE))
 
2886
          config->url_out = config->url_out->next;
 
2887
      }
 
2888
 
 
2889
      /* now there might or might not be an available node to fill in! */
 
2890
 
 
2891
      if(config->url_out)
 
2892
        /* existing node */
 
2893
        url = config->url_out;
 
2894
      else
 
2895
        /* there was no free node, create one! */
 
2896
        url=new_getout(config);
 
2897
 
 
2898
      if(url) {
 
2899
        /* fill in the outfile */
 
2900
        if('o' == letter) {
 
2901
          GetStr(&url->outfile, nextarg);
 
2902
          url->flags &= ~GETOUT_USEREMOTE; /* switch off */
2873
2903
        }
2874
 
 
2875
 
        /* now there might or might not be an available node to fill in! */
2876
 
 
2877
 
        if(config->url_out)
2878
 
          /* existing node */
2879
 
          url = config->url_out;
2880
 
        else
2881
 
          /* there was no free node, create one! */
2882
 
          url=new_getout(config);
2883
 
 
2884
 
        if(url) {
2885
 
          /* fill in the outfile */
2886
 
          if('o' == letter) {
2887
 
            GetStr(&url->outfile, nextarg);
 
2904
        else {
 
2905
          url->outfile=NULL; /* leave it */
 
2906
          if(toggle)
 
2907
            url->flags |= GETOUT_USEREMOTE;  /* switch on */
 
2908
          else
2888
2909
            url->flags &= ~GETOUT_USEREMOTE; /* switch off */
2889
 
          }
2890
 
          else {
2891
 
            url->outfile=NULL; /* leave it */
2892
 
            if(toggle)
2893
 
              url->flags |= GETOUT_USEREMOTE;  /* switch on */
2894
 
            else
2895
 
              url->flags &= ~GETOUT_USEREMOTE; /* switch off */
2896
 
          }
2897
 
          url->flags |= GETOUT_OUTFILE;
2898
2910
        }
 
2911
        url->flags |= GETOUT_OUTFILE;
2899
2912
      }
2900
 
      break;
 
2913
    }
 
2914
    break;
2901
2915
    case 'P':
2902
2916
      /* This makes the FTP sessions use PORT instead of PASV */
2903
2917
      /* use <eth0> or <192.168.10.10> style addresses. Anything except
2904
2918
         this will make us try to get the "default" address.
2905
2919
         NOTE: this is a changed behaviour since the released 4.1!
2906
 
         */
 
2920
      */
2907
2921
      GetStr(&config->ftpport, nextarg);
2908
2922
      break;
2909
2923
    case 'p':
2991
3005
      break;
2992
3006
    case 'T':
2993
3007
      /* we are uploading */
2994
 
      {
2995
 
        struct getout *url;
2996
 
        if(config->url_out || (config->url_out=config->url_list)) {
2997
 
          /* there's a node here, if it already is filled-in continue to find
2998
 
             an "empty" node */
2999
 
          while(config->url_out && (config->url_out->flags&GETOUT_UPLOAD))
3000
 
            config->url_out = config->url_out->next;
3001
 
        }
3002
 
 
3003
 
        /* now there might or might not be an available node to fill in! */
3004
 
 
3005
 
        if(config->url_out)
3006
 
          /* existing node */
3007
 
          url = config->url_out;
3008
 
        else
3009
 
          /* there was no free node, create one! */
3010
 
          url=new_getout(config);
3011
 
 
3012
 
        if(url) {
3013
 
          url->flags |= GETOUT_UPLOAD; /* mark -T used */
3014
 
          if(!*nextarg)
3015
 
            url->flags |= GETOUT_NOUPLOAD;
3016
 
          else {
3017
 
            /* "-" equals stdin, but keep the string around for now */
3018
 
            GetStr(&url->infile, nextarg);
3019
 
          }
3020
 
        }
3021
 
      }
3022
 
      break;
 
3008
    {
 
3009
      struct getout *url;
 
3010
      if(config->url_out || (config->url_out=config->url_list)) {
 
3011
        /* there's a node here, if it already is filled-in continue to find
 
3012
           an "empty" node */
 
3013
        while(config->url_out && (config->url_out->flags&GETOUT_UPLOAD))
 
3014
          config->url_out = config->url_out->next;
 
3015
      }
 
3016
 
 
3017
      /* now there might or might not be an available node to fill in! */
 
3018
 
 
3019
      if(config->url_out)
 
3020
        /* existing node */
 
3021
        url = config->url_out;
 
3022
      else
 
3023
        /* there was no free node, create one! */
 
3024
        url=new_getout(config);
 
3025
 
 
3026
      if(url) {
 
3027
        url->flags |= GETOUT_UPLOAD; /* mark -T used */
 
3028
        if(!*nextarg)
 
3029
          url->flags |= GETOUT_NOUPLOAD;
 
3030
        else {
 
3031
          /* "-" equals stdin, but keep the string around for now */
 
3032
          GetStr(&url->infile, nextarg);
 
3033
        }
 
3034
      }
 
3035
    }
 
3036
    break;
3023
3037
    case 'u':
3024
3038
      /* user:password  */
3025
3039
      GetStr(&config->userpwd, nextarg);
3054
3068
        break;
3055
3069
 
3056
3070
      printf(CURL_ID "%s\n", curl_version());
3057
 
      if (curlinfo->protocols) {
 
3071
      if(curlinfo->protocols) {
3058
3072
        printf("Protocols: ");
3059
 
        for (proto=curlinfo->protocols; *proto; ++proto) {
 
3073
        for(proto=curlinfo->protocols; *proto; ++proto) {
3060
3074
          printf("%s ", *proto);
3061
3075
        }
3062
3076
        puts(""); /* newline */
3260
3274
         * directory as our executable
3261
3275
         */
3262
3276
        file = fopen(filebuffer, "r");
3263
 
        if (file != NULL) {
 
3277
        if(file != NULL) {
3264
3278
          fclose(file);
3265
3279
          filename = filebuffer;
3266
3280
        }
3270
3284
           * We assume that we are using the ASCII version here.
3271
3285
           */
3272
3286
          int n = GetModuleFileName(0, filebuffer, sizeof(filebuffer));
3273
 
          if (n > 0 && n < (int)sizeof(filebuffer)) {
 
3287
          if(n > 0 && n < (int)sizeof(filebuffer)) {
3274
3288
            /* We got a valid filename - get the directory part */
3275
3289
            char *lastdirchar = strrchr(filebuffer, '\\');
3276
 
            if (lastdirchar) {
 
3290
            if(lastdirchar) {
3277
3291
              size_t remaining;
3278
3292
              *lastdirchar = 0;
3279
3293
              /* If we have enough space, build the RC filename */
3280
3294
              remaining = sizeof(filebuffer) - strlen(filebuffer);
3281
 
              if (strlen(CURLRC) < remaining - 1) {
 
3295
              if(strlen(CURLRC) < remaining - 1) {
3282
3296
                snprintf(lastdirchar, remaining,
3283
3297
                         "%s%s", DIR_CHAR, CURLRC);
3284
3298
                /* Don't bother checking if it exists - we do
3297
3311
    }
3298
3312
 
3299
3313
# else /* __AMIGA__ */
3300
 
  /* On AmigaOS all the config files are into env:
3301
 
   */
3302
 
  filename = "ENV:" CURLRC;
 
3314
    /* On AmigaOS all the config files are into env:
 
3315
     */
 
3316
    filename = "ENV:" CURLRC;
3303
3317
 
3304
3318
#endif
3305
3319
  }
3319
3333
 
3320
3334
#define ISSEP(x) (((x)=='=') || ((x) == ':'))
3321
3335
 
3322
 
    while (NULL != (aline = my_get_line(file))) {
 
3336
    while(NULL != (aline = my_get_line(file))) {
3323
3337
      lineno++;
3324
3338
      line = aline;
3325
3339
      alloced_param=FALSE;
3361
3375
        /* quoted parameter, do the quote dance */
3362
3376
        line++;
3363
3377
        param=malloc(strlen(line)+1); /* parameter */
3364
 
        if (!param) {
 
3378
        if(!param) {
3365
3379
          /* out of memory */
3366
3380
          free(aline);
3367
3381
          rc = 1;
3377
3391
        *line=0; /* zero terminate */
3378
3392
      }
3379
3393
 
3380
 
      if (param && !*param) {
 
3394
      if(param && !*param) {
3381
3395
        /* do this so getparameter can check for required parameters.
3382
3396
           Otherwise it always thinks there's a parameter. */
3383
 
        if (alloced_param)
 
3397
        if(alloced_param)
3384
3398
          free(param);
3385
3399
        param = NULL;
3386
3400
      }
3390
3404
#endif
3391
3405
      res = getparameter(option, param, &usedarg, config);
3392
3406
 
3393
 
      if (param && *param && !usedarg)
 
3407
      if(param && *param && !usedarg)
3394
3408
        /* we passed in a parameter that wasn't used! */
3395
3409
        res = PARAM_GOT_EXTRA_PARAMETER;
3396
3410
 
3465
3479
 
3466
3480
  if(!out->stream) {
3467
3481
    out->bytes = 0; /* nothing written yet */
3468
 
    if (!out->filename) {
 
3482
    if(!out->filename) {
3469
3483
      warnf(config, "Remote filename has no length!\n");
3470
3484
      return err_rc; /* Failure */
3471
3485
    }
3472
3486
 
3473
 
    if (config->content_disposition) {
 
3487
    if(config->content_disposition) {
3474
3488
      /* don't overwrite existing files */
3475
3489
      FILE* f = fopen(out->filename, "r");
3476
 
      if (f) {
 
3490
      if(f) {
3477
3491
        fclose(f);
3478
3492
        warnf(config, "Refusing to overwrite %s: %s\n", out->filename,
3479
3493
              strerror(EEXIST));
3527
3541
{
3528
3542
  struct InStruct *in=(struct InStruct *)stream;
3529
3543
 
3530
 
#if (CURL_SIZEOF_CURL_OFF_T > SIZEOF_OFF_T) && !defined(USE_WIN32_LARGE_FILES)
 
3544
#if(CURL_SIZEOF_CURL_OFF_T > SIZEOF_OFF_T) && !defined(USE_WIN32_LARGE_FILES)
3531
3545
  /* The offset check following here is only interesting if curl_off_t is
3532
3546
     larger than off_t and we are not using the WIN32 large file support
3533
3547
     macros that provide the support to do 64bit seeks correctly */
3625
3639
  if(total < 1) {
3626
3640
    curl_off_t prevblock = bar->prev / 1024;
3627
3641
    curl_off_t thisblock = point / 1024;
3628
 
    while ( thisblock > prevblock ) {
 
3642
    while( thisblock > prevblock ) {
3629
3643
      fprintf( bar->out, "#" );
3630
3644
      prevblock++;
3631
3645
    }
3635
3649
    percent = frac * 100.0f;
3636
3650
    barwidth = bar->width - 7;
3637
3651
    num = (int) (((double)barwidth) * frac);
3638
 
    for ( i = 0; i < num; i++ ) {
 
3652
    for( i = 0; i < num; i++ ) {
3639
3653
      line[i] = '#';
3640
3654
    }
3641
3655
    line[i] = '\0';
3664
3678
  /* pass this through to progress function so
3665
3679
   * it can display progress towards total file
3666
3680
   * not just the part that's left. (21-may-03, dbyron) */
3667
 
  if (config->use_resume)
 
3681
  if(config->use_resume)
3668
3682
    bar->initial_size = config->resume_from;
3669
3683
 
3670
3684
/* TODO: get terminal width through ansi escapes or something similar.
3671
 
         try to update width when xterm is resized... - 19990617 larsa */
 
3685
   try to update width when xterm is resized... - 19990617 larsa */
3672
3686
#ifndef __EMX__
3673
3687
  /* 20000318 mgs
3674
3688
   * OS/2 users most likely won't have this env var set, and besides that
3675
3689
   * we're using our own way to determine screen width */
3676
3690
  colp = curlx_getenv("COLUMNS");
3677
 
  if (colp != NULL) {
 
3691
  if(colp != NULL) {
3678
3692
    bar->width = atoi(colp);
3679
3693
    curl_free(colp);
3680
3694
  }
3726
3740
 
3727
3741
    for(c = 0; (c < width) && (i+c < size); c++) {
3728
3742
      /* check for 0D0A; if found, skip past and start a new line of output */
3729
 
      if ((tracetype == TRACE_ASCII) &&
3730
 
          (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
 
3743
      if((tracetype == TRACE_ASCII) &&
 
3744
         (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
3731
3745
        i+=(c+2-width);
3732
3746
        break;
3733
3747
      }
3734
3748
#ifdef CURL_DOES_CONVERSIONS
3735
3749
      /* repeat the 0D0A check above but use the host encoding for CRLF */
3736
 
      if ((tracetype == TRACE_ASCII) &&
3737
 
          (i+c+1 < size) && ptr[i+c]=='\r' && ptr[i+c+1]=='\n') {
 
3750
      if((tracetype == TRACE_ASCII) &&
 
3751
         (i+c+1 < size) && ptr[i+c]=='\r' && ptr[i+c+1]=='\n') {
3738
3752
        i+=(c+2-width);
3739
3753
        break;
3740
3754
      }
3746
3760
              (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:UNPRINTABLE_CHAR);
3747
3761
#endif /* CURL_DOES_CONVERSIONS */
3748
3762
      /* check again for 0D0A, to avoid an extra \n if it's at width */
3749
 
      if ((tracetype == TRACE_ASCII) &&
3750
 
          (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
 
3763
      if((tracetype == TRACE_ASCII) &&
 
3764
         (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
3751
3765
        i+=(c+3-width);
3752
3766
        break;
3753
3767
      }
3966
3980
    free(config->writeout);
3967
3981
  if(config->httppost)
3968
3982
    curl_formfree(config->httppost);
3969
 
  if (config->cert)
 
3983
  if(config->cert)
3970
3984
    free(config->cert);
3971
3985
  if(config->cacert)
3972
3986
    free(config->cacert);
3973
 
  if (config->cert_type)
 
3987
  if(config->cert_type)
3974
3988
    free(config->cert_type);
3975
3989
  if(config->capath)
3976
3990
    free(config->capath);
3988
4002
    free(config->socksproxy);
3989
4003
  if(config->libcurl)
3990
4004
    free(config->libcurl);
3991
 
  if (config->key_passwd)
 
4005
  if(config->key_passwd)
3992
4006
    free(config->key_passwd);
3993
 
  if (config->key)
 
4007
  if(config->key)
3994
4008
    free(config->key);
3995
 
  if (config->key_type)
 
4009
  if(config->key_type)
3996
4010
    free(config->key_type);
3997
 
  if (config->pubkey)
 
4011
  if(config->pubkey)
3998
4012
    free(config->pubkey);
3999
 
  if (config->referer)
 
4013
  if(config->referer)
4000
4014
    free(config->referer);
4001
 
  if (config->hostpubmd5)
 
4015
  if(config->hostpubmd5)
4002
4016
    free(config->hostpubmd5);
4003
4017
  if(config->mail_from)
4004
4018
    free(config->mail_from);
4038
4052
    DWORD buflen;
4039
4053
    char *ptr = NULL;
4040
4054
    char *retval = malloc(sizeof (TCHAR) * (MAX_PATH + 1));
4041
 
    if (!retval)
 
4055
    if(!retval)
4042
4056
      return;
4043
4057
    retval[0] = '\0';
4044
4058
    buflen = SearchPathA(NULL, bundle_file, NULL, MAX_PATH+2, retval, &ptr);
4045
 
    if (buflen > 0) {
 
4059
    if(buflen > 0) {
4046
4060
      GetStr(&config->cacert, retval);
4047
4061
    }
4048
4062
    free(retval);
4098
4112
    unsigned char *ptr = (unsigned char *)pval;
4099
4113
 
4100
4114
    /* function pointers are never printable */
4101
 
    if (tag >= CURLOPTTYPE_FUNCTIONPOINT) {
4102
 
      if (pval) {
 
4115
    if(tag >= CURLOPTTYPE_FUNCTIONPOINT) {
 
4116
      if(pval) {
4103
4117
        strcpy(value, "functionpointer"); /* 'value' fits 256 bytes */
4104
4118
        remark = TRUE;
4105
4119
      }
4137
4151
    else
4138
4152
      bufp = curlx_maprintf("curl_easy_setopt(hnd, %s, %s);", name, value);
4139
4153
 
4140
 
    if (!bufp)
 
4154
    if(!bufp)
4141
4155
      ret = CURLE_OUT_OF_MEMORY;
4142
4156
    else {
4143
4157
      struct curl_slist *list =
4148
4162
      else
4149
4163
        easycode = list;
4150
4164
    }
4151
 
    if (bufp)
 
4165
    if(bufp)
4152
4166
      curl_free(bufp);
4153
4167
  }
4154
4168
  va_end(arg);
4332
4346
 
4333
4347
  /* simple implementation of strndup() */
4334
4348
  copy = malloc(len+1);
4335
 
  if (!copy)
 
4349
  if(!copy)
4336
4350
    return NULL;
4337
4351
  strncpy(copy, ptr, len);
4338
4352
  copy[len] = 0;
4339
4353
 
4340
4354
  p = copy;
4341
 
  if (*p == '\'' || *p == '"') {
 
4355
  if(*p == '\'' || *p == '"') {
4342
4356
    /* store the starting quote */
4343
4357
    quote = *p;
4344
4358
    p++;
4346
4360
 
4347
4361
  /* if the filename contains a path, only use filename portion */
4348
4362
  q = strrchr(copy, '/');
 
4363
  if(q) {
 
4364
    p=q+1;
 
4365
    if(!*p) {
 
4366
      free(copy);
 
4367
      return NULL;
 
4368
    }
 
4369
  }
 
4370
 
 
4371
  /* If the filename contains a backslash, only use filename portion. The idea
 
4372
     is that even systems that don't handle backslashes as path separators
 
4373
     probably want the path removed for convenience. */
 
4374
  q = strrchr(p, '\\');
4349
4375
  if (q) {
4350
 
    p=q+1;
 
4376
    p = q+1;
4351
4377
    if (!*p) {
4352
4378
      free(copy);
4353
4379
      return NULL;
4358
4384
    /* if the file name started with a quote, then scan for the end quote and
4359
4385
       stop there */
4360
4386
    q = strrchr(p, quote);
4361
 
    if (q)
 
4387
    if(q)
4362
4388
      *q = 0;
4363
4389
  }
4364
4390
  else
4375
4401
      *q  = 0;
4376
4402
  }
4377
4403
 
4378
 
  if (copy!=p)
 
4404
  if(copy!=p)
4379
4405
    memmove(copy, p, strlen(p)+1);
4380
4406
 
4381
4407
  return copy;
4390
4416
  const char* end = (char*)ptr + cb;
4391
4417
  size_t len;
4392
4418
 
4393
 
  if (cb > 20 && curlx_strnequal(str, "Content-disposition:", 20)) {
 
4419
  if(cb > 20 && checkprefix("Content-disposition:", str)) {
4394
4420
    char *p = (char*)str + 20;
4395
4421
 
4396
4422
    /* look for the 'filename=' parameter
4399
4425
      char *filename;
4400
4426
      char *semi;
4401
4427
 
4402
 
      while (*p && (p < end) && !ISALPHA(*p))
 
4428
      while(*p && (p < end) && !ISALPHA(*p))
4403
4429
        p++;
4404
 
      if (p > end-9)
 
4430
      if(p > end-9)
4405
4431
        break;
4406
4432
 
4407
 
      if (memcmp(p, "filename=", 9)) {
 
4433
      if(memcmp(p, "filename=", 9)) {
4408
4434
        /* no match, find next parameter */
4409
 
        while ((p < end) && (*p != ';'))
 
4435
        while((p < end) && (*p != ';'))
4410
4436
          p++;
4411
4437
        continue;
4412
4438
      }
4418
4444
      */
4419
4445
      len = semi ? (semi - p) : (ssize_t)cb - (p - str);
4420
4446
      filename = parse_filename(p, len);
4421
 
      if (filename) {
 
4447
      if(filename) {
4422
4448
        outs->filename = filename;
4423
4449
        break;
4424
4450
      }
4487
4513
  /* Initialize curl library - do not call any libcurl functions before.
4488
4514
     Note that the CURLDEBUG magic above is an exception, but then that's not
4489
4515
     part of the official public API.
4490
 
   */
4491
 
  if (main_init() != CURLE_OK) {
 
4516
  */
 
4517
  if(main_init() != CURLE_OK) {
4492
4518
    helpf(config->errors, "error initializing curl library\n");
4493
4519
    return CURLE_FAILED_INIT;
4494
4520
  }
4543
4569
    parseconfig(NULL, config); /* ignore possible failure */
4544
4570
  }
4545
4571
 
4546
 
  if ((argc < 2)  && !config->url_list) {
 
4572
  if((argc < 2)  && !config->url_list) {
4547
4573
    helpf(config->errors, NULL);
4548
4574
    return CURLE_FAILED_INIT;
4549
4575
  }
4550
4576
 
4551
4577
  /* Parse options */
4552
 
  for (i = 1; i < argc; i++) {
 
4578
  for(i = 1; i < argc; i++) {
4553
4579
    if(stillflags &&
4554
4580
       ('-' == argv[i][0])) {
4555
4581
      char *nextarg;
4617
4643
   * We support the environment variable thing for non-Windows platforms
4618
4644
   * too. Just for the sake of it.
4619
4645
   */
4620
 
  if (!config->cacert &&
4621
 
      !config->capath &&
4622
 
      !config->insecure_ok) {
 
4646
  if(!config->cacert &&
 
4647
     !config->capath &&
 
4648
     !config->insecure_ok) {
4623
4649
    env = curlx_getenv("CURL_CA_BUNDLE");
4624
4650
    if(env)
4625
4651
      GetStr(&config->cacert, env);
4642
4668
#endif
4643
4669
  }
4644
4670
 
4645
 
  if (config->postfields) {
4646
 
    if (config->use_httpget) {
 
4671
  if(config->postfields) {
 
4672
    if(config->use_httpget) {
4647
4673
      /* Use the postfields data for a http get */
4648
4674
      httpgetfields = strdup(config->postfields);
4649
4675
      free(config->postfields);
4669
4695
    goto quit_curl;
4670
4696
  }
4671
4697
 
4672
 
  if (config->list_engines) {
 
4698
  if(config->list_engines) {
4673
4699
    struct curl_slist *engines = NULL;
4674
4700
 
4675
4701
    curl_easy_getinfo(curl, CURLINFO_SSL_ENGINES, &engines);
4725
4751
    outs.bytes = 0; /* nothing written yet */
4726
4752
 
4727
4753
    /* save outfile pattern before expansion */
4728
 
    if (urlnode->outfile) {
 
4754
    if(urlnode->outfile) {
4729
4755
      outfiles = strdup(urlnode->outfile);
4730
 
      if (!outfiles) {
 
4756
      if(!outfiles) {
4731
4757
        clean_getout(config);
4732
4758
        break;
4733
4759
      }
4779
4805
          (url = urls?glob_next_url(urls):(i?NULL:strdup(url)));
4780
4806
          i++) {
4781
4807
        /* NOTE: In the condition expression in the for() statement above, the
4782
 
           'url' variable is only ever strdup()ed if (i == 0) and thus never
 
4808
           'url' variable is only ever strdup()ed if(i == 0) and thus never
4783
4809
           when this loops later on. Further down in this function we call
4784
4810
           free(url) and then the code loops. Static code parsers may thus get
4785
4811
           tricked into believing that we have a potential access-after-free
4810
4836
            }
4811
4837
#if defined(MSDOS) || defined(WIN32)
4812
4838
            /* For DOS and WIN32, we do some major replacing of
4813
 
             bad characters in the file name before using it */
 
4839
               bad characters in the file name before using it */
4814
4840
            outfile = sanitize_dos_name(outfile);
4815
4841
            if(!outfile) {
4816
4842
              res = CURLE_OUT_OF_MEMORY;
4863
4889
            outs.init = config->resume_from;
4864
4890
            /* open file for output: */
4865
4891
            outs.stream=(FILE *) fopen(outfile, config->resume_from?"ab":"wb");
4866
 
            if (!outs.stream) {
 
4892
            if(!outs.stream) {
4867
4893
              helpf(config->errors, "Can't open '%s'!\n", outfile);
4868
4894
              free(url);
4869
4895
              res = CURLE_WRITE_ERROR;
4904
4930
           */
4905
4931
 
4906
4932
          infd= open(uploadfile, O_RDONLY | O_BINARY);
4907
 
          if ((infd == -1) || fstat(infd, &fileinfo)) {
 
4933
          if((infd == -1) || fstat(infd, &fileinfo)) {
4908
4934
            helpf(config->errors, "Can't open '%s'!\n", uploadfile);
4909
4935
            if(infd != -1)
4910
4936
              close(infd);
4925
4951
            goto quit_urls;
4926
4952
          }
4927
4953
          infdopen=TRUE;
4928
 
          uploadfilesize=fileinfo.st_size;
 
4954
 
 
4955
          /* we ignore file size for char/block devices, sockets, etc. */
 
4956
          if(S_ISREG(fileinfo.st_mode))
 
4957
            uploadfilesize=fileinfo.st_size;
4929
4958
 
4930
4959
        }
4931
4960
        else if(uploadfile && stdin_upload(uploadfile)) {
4956
4985
 
4957
4986
          SET_BINMODE(stdin);
4958
4987
          infd = STDIN_FILENO;
4959
 
          if (curlx_strequal(uploadfile, ".")) {
4960
 
            if (curlx_nonblock((curl_socket_t)infd, TRUE) < 0)
 
4988
          if(curlx_strequal(uploadfile, ".")) {
 
4989
            if(curlx_nonblock((curl_socket_t)infd, TRUE) < 0)
4961
4990
              warnf(config,
4962
4991
                    "fcntl failed on fd=%d: %s\n", infd, strerror(errno));
4963
4992
          }
4972
5001
             meter */
4973
5002
          config->noprogress = config->isatty = TRUE;
4974
5003
 
4975
 
        if (urlnum > 1 && !(config->mute)) {
 
5004
        if(urlnum > 1 && !(config->mute)) {
4976
5005
          fprintf(config->errors, "\n[%d/%d]: %s --> %s\n",
4977
5006
                  i+1, urlnum, url, outfile ? outfile : "<stdout>");
4978
 
          if (separator)
 
5007
          if(separator)
4979
5008
            printf("%s%s\n", CURLseparator, url);
4980
5009
        }
4981
 
        if (httpgetfields) {
 
5010
        if(httpgetfields) {
4982
5011
          char *urlbuffer;
4983
5012
          /* Find out whether the url contains a file name */
4984
5013
          const char *pc =strstr(url, "://");
5020
5049
            res = CURLE_OUT_OF_MEMORY;
5021
5050
            goto quit_urls;
5022
5051
          }
5023
 
          if (pc)
 
5052
          if(pc)
5024
5053
            sprintf(urlbuffer, "%s%c%s", url, sep, httpgetfields);
5025
5054
          else
5026
5055
            /* Append  / before the ? to create a well-formed url
5054
5083
        input.config = config;
5055
5084
        my_setopt(curl, CURLOPT_READDATA, &input);
5056
5085
        /* what call to read */
5057
 
        if ((outfile && !curlx_strequal("-", outfile)) ||
5058
 
            !curlx_strnequal(url, "telnet:", 7))
 
5086
        if((outfile && !curlx_strequal("-", outfile)) ||
 
5087
           !checkprefix("telnet:", url))
5059
5088
          my_setopt(curl, CURLOPT_READFUNCTION, my_fread);
5060
5089
 
5061
5090
        /* in 7.18.0, the CURLOPT_SEEKFUNCTION/DATA pair is taking over what
5088
5117
        my_setopt(curl, CURLOPT_DIRLISTONLY, config->dirlistonly);
5089
5118
        my_setopt(curl, CURLOPT_APPEND, config->ftp_append);
5090
5119
 
5091
 
        if (config->netrc_opt)
 
5120
        if(config->netrc_opt)
5092
5121
          my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
5093
 
        else if (config->netrc)
 
5122
        else if(config->netrc)
5094
5123
          my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
5095
5124
        else
5096
5125
          my_setopt(curl, CURLOPT_NETRC, CURL_NETRC_IGNORED);
5151
5180
        /* default to strict verifyhost */
5152
5181
        /* my_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2); */
5153
5182
        if(config->cacert || config->capath) {
5154
 
          if (config->cacert)
 
5183
          if(config->cacert)
5155
5184
            my_setopt_str(curl, CURLOPT_CAINFO, config->cacert);
5156
5185
 
5157
 
          if (config->capath)
 
5186
          if(config->capath)
5158
5187
            my_setopt_str(curl, CURLOPT_CAPATH, config->capath);
5159
5188
          my_setopt(curl, CURLOPT_SSL_VERIFYPEER, TRUE);
5160
5189
        }
5161
 
        if (config->crlfile)
 
5190
        if(config->crlfile)
5162
5191
          my_setopt_str(curl, CURLOPT_CRLFILE, config->crlfile);
5163
5192
        if(config->insecure_ok) {
5164
5193
          /* new stuff needed for libcurl 7.10 */
5269
5298
        res = CURLE_OK;
5270
5299
 
5271
5300
        /* new in curl ?? */
5272
 
        if (config->engine) {
 
5301
        if(config->engine) {
5273
5302
          res = my_setopt_str(curl, CURLOPT_SSLENGINE, config->engine);
5274
5303
          my_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1);
5275
5304
        }
5276
5305
 
5277
 
        if (res != CURLE_OK)
5278
 
           goto show_error;
 
5306
        if(res != CURLE_OK)
 
5307
          goto show_error;
5279
5308
 
5280
5309
        /* new in curl 7.10 */
5281
5310
        my_setopt_str(curl, CURLOPT_ENCODING,
5282
 
                  (config->encoding) ? "" : NULL);
 
5311
                      (config->encoding) ? "" : NULL);
5283
5312
 
5284
5313
        /* new in curl 7.10.7, extended in 7.19.4 but this only sets 0 or 1 */
5285
5314
        my_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
5298
5327
        /* new in curl 7.10.8 */
5299
5328
        if(config->max_filesize)
5300
5329
          my_setopt(curl, CURLOPT_MAXFILESIZE_LARGE,
5301
 
                           config->max_filesize);
 
5330
                    config->max_filesize);
5302
5331
 
5303
5332
        if(4 == config->ip_version)
5304
5333
          my_setopt(curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
5321
5350
 
5322
5351
        /* new in curl 7.16.1 */
5323
5352
        if(config->ftp_ssl_ccc)
5324
 
            my_setopt(curl, CURLOPT_FTP_SSL_CCC, config->ftp_ssl_ccc_mode);
 
5353
          my_setopt(curl, CURLOPT_FTP_SSL_CCC, config->ftp_ssl_ccc_mode);
5325
5354
 
5326
5355
        /* new in curl 7.11.1, modified in 7.15.2 */
5327
5356
        if(config->socksproxy) {
5333
5362
        /* new in curl 7.19.4 */
5334
5363
        if(config->socks5_gssapi_service)
5335
5364
          my_setopt_str(curl, CURLOPT_SOCKS5_GSSAPI_SERVICE,
5336
 
                    config->socks5_gssapi_service);
 
5365
                        config->socks5_gssapi_service);
5337
5366
 
5338
5367
        /* new in curl 7.19.4 */
5339
5368
        if(config->socks5_gssapi_nec)
5355
5384
        if(config->localport) {
5356
5385
          my_setopt(curl, CURLOPT_LOCALPORT, config->localport);
5357
5386
          my_setopt_str(curl, CURLOPT_LOCALPORTRANGE,
5358
 
                    config->localportrange);
 
5387
                        config->localportrange);
5359
5388
        }
5360
5389
 
5361
5390
        /* curl 7.15.5 */
5362
5391
        my_setopt_str(curl, CURLOPT_FTP_ALTERNATIVE_TO_USER,
5363
 
                  config->ftp_alternative_to_user);
 
5392
                      config->ftp_alternative_to_user);
5364
5393
 
5365
5394
        /* curl 7.16.0 */
5366
5395
        if(config->disable_sessionid)
5374
5403
        }
5375
5404
 
5376
5405
        /* curl 7.17.1 */
5377
 
        if (!config->nokeepalive) {
 
5406
        if(!config->nokeepalive) {
5378
5407
          my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockoptcallback);
5379
5408
          my_setopt(curl, CURLOPT_SOCKOPTDATA, config);
5380
5409
        }
5397
5426
        if(config->ftp_pret)
5398
5427
          my_setopt(curl, CURLOPT_FTP_USE_PRET, TRUE);
5399
5428
 
5400
 
        if (config->proto_present)
 
5429
        if(config->proto_present)
5401
5430
          my_setopt(curl, CURLOPT_PROTOCOLS, config->proto);
5402
 
        if (config->proto_redir_present)
 
5431
        if(config->proto_redir_present)
5403
5432
          my_setopt(curl, CURLOPT_REDIR_PROTOCOLS, config->proto_redir);
5404
5433
 
5405
 
        if ((urlnode->flags & GETOUT_USEREMOTE)
5406
 
            && config->content_disposition) {
 
5434
        if((urlnode->flags & GETOUT_USEREMOTE)
 
5435
           && config->content_disposition) {
5407
5436
          my_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
5408
5437
          my_setopt(curl, CURLOPT_HEADERDATA, &outs);
5409
5438
        }
5414
5443
 
5415
5444
        for(;;) {
5416
5445
          res = curl_easy_perform(curl);
5417
 
          if (!curl_slist_append(easycode, "ret = curl_easy_perform(hnd);")) {
 
5446
          if(!curl_slist_append(easycode, "ret = curl_easy_perform(hnd);")) {
5418
5447
            res = CURLE_OUT_OF_MEMORY;
5419
5448
            break;
5420
5449
          }
5421
5450
 
5422
 
          if (config->content_disposition && outs.stream && !config->mute)
 
5451
          if(config->content_disposition && outs.stream && !config->mute &&
 
5452
             outs.filename)
5423
5453
            printf("curl: Saved to filename '%s'\n", outs.filename);
5424
5454
 
5425
5455
          /* if retry-max-time is non-zero, make sure we haven't exceeded the
5448
5478
              char *this_url=NULL;
5449
5479
              curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &this_url);
5450
5480
              if(this_url &&
5451
 
                 curlx_strnequal(this_url, "http", 4)) {
 
5481
                 checkprefix("http", this_url)) {
5452
5482
                /* This was HTTP(S) */
5453
5483
                curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
5454
5484
 
5549
5579
        if(config->writeout)
5550
5580
          ourWriteOut(curl, config->writeout);
5551
5581
#ifdef USE_ENVIRONMENT
5552
 
        if (config->writeenv)
 
5582
        if(config->writeenv)
5553
5583
          ourWriteEnv(curl);
5554
5584
#endif
5555
5585
 
5556
 
show_error:
 
5586
        show_error:
5557
5587
 
5558
5588
#ifdef __VMS
5559
5589
        if(is_vms_shell()) {
5570
5600
                    errorbuffer[0]? errorbuffer:
5571
5601
                    curl_easy_strerror((CURLcode)res));
5572
5602
            if(CURLE_SSL_CACERT == res) {
5573
 
#define CURL_CA_CERT_ERRORMSG1 \
5574
 
"More details here: http://curl.haxx.se/docs/sslcerts.html\n\n" \
5575
 
"curl performs SSL certificate verification by default, using a \"bundle\"\n" \
5576
 
" of Certificate Authority (CA) public keys (CA certs). If the default\n" \
5577
 
" bundle file isn't adequate, you can specify an alternate file\n" \
5578
 
" using the --cacert option.\n"
 
5603
#define CURL_CA_CERT_ERRORMSG1                                          \
 
5604
              "More details here: http://curl.haxx.se/docs/sslcerts.html\n\n" \
 
5605
                "curl performs SSL certificate verification by default, using a \"bundle\"\n" \
 
5606
                " of Certificate Authority (CA) public keys (CA certs). If the default\n" \
 
5607
                " bundle file isn't adequate, you can specify an alternate file\n" \
 
5608
                " using the --cacert option.\n"
5579
5609
 
5580
 
#define CURL_CA_CERT_ERRORMSG2 \
5581
 
"If this HTTPS server uses a certificate signed by a CA represented in\n" \
5582
 
" the bundle, the certificate verification probably failed due to a\n" \
5583
 
" problem with the certificate (it might be expired, or the name might\n" \
5584
 
" not match the domain name in the URL).\n" \
5585
 
"If you'd like to turn off curl's verification of the certificate, use\n" \
5586
 
" the -k (or --insecure) option.\n"
 
5610
#define CURL_CA_CERT_ERRORMSG2                                          \
 
5611
              "If this HTTPS server uses a certificate signed by a CA represented in\n" \
 
5612
                " the bundle, the certificate verification probably failed due to a\n" \
 
5613
                " problem with the certificate (it might be expired, or the name might\n" \
 
5614
                " not match the domain name in the URL).\n"             \
 
5615
                "If you'd like to turn off curl's verification of the certificate, use\n" \
 
5616
                " the -k (or --insecure) option.\n"
5587
5617
 
5588
5618
              fprintf(config->errors, "%s%s",
5589
5619
                      CURL_CA_CERT_ERRORMSG1,
5592
5622
          }
5593
5623
        }
5594
5624
 
5595
 
        if (outfile && !curlx_strequal(outfile, "-") && outs.stream) {
 
5625
        if(outfile && !curlx_strequal(outfile, "-") && outs.stream) {
5596
5626
          int rc = fclose(outs.stream);
5597
5627
          if(!res && rc) {
5598
5628
            /* something went wrong in the writing process */
5625
5655
        SetComment( outs.filename, url);
5626
5656
#endif
5627
5657
 
5628
 
quit_urls:
 
5658
        quit_urls:
5629
5659
        if(url)
5630
5660
          free(url);
5631
5661
 
5671
5701
 
5672
5702
  } /* while-loop through all URLs */
5673
5703
 
5674
 
quit_curl:
5675
 
  if (httpgetfields)
 
5704
  quit_curl:
 
5705
  if(httpgetfields)
5676
5706
    free(httpgetfields);
5677
5707
 
5678
 
  if (config->engine)
 
5708
  if(config->engine)
5679
5709
    free(config->engine);
5680
5710
 
5681
5711
  /* cleanup the curl handle! */
5682
5712
  curl_easy_cleanup(curl);
5683
5713
  config->easy = NULL; /* cleanup now */
5684
 
  if (easycode)
 
5714
  if(easycode)
5685
5715
    curl_slist_append(easycode, "curl_easy_cleanup(hnd);");
5686
5716
 
5687
5717
  if(heads.stream && (heads.stream != stdout))
5721
5751
         fd[1] == STDIN_FILENO ||
5722
5752
         fd[1] == STDOUT_FILENO ||
5723
5753
         fd[1] == STDERR_FILENO )
5724
 
    if (pipe(fd) < 0)
 
5754
    if(pipe(fd) < 0)
5725
5755
      return;   /* Out of handles. This isn't really a big problem now, but
5726
5756
                   will be when we try to create a socket later. */
5727
5757
  close(fd[0]);
5744
5774
 
5745
5775
  res = operate(&config, argc, argv);
5746
5776
#ifdef __SYMBIAN32__
5747
 
  if (config.showerror)
 
5777
  if(config.showerror)
5748
5778
    pressanykey();
5749
5779
#endif
5750
5780
  free_config_fields(&config);
5751
5781
 
5752
5782
#ifdef __NOVELL_LIBC__
5753
 
  if (getenv("_IN_NETWARE_BASH_") == NULL)
 
5783
  if(getenv("_IN_NETWARE_BASH_") == NULL)
5754
5784
    pressanykey();
5755
5785
#endif
5756
5786
#ifdef __VMS
5767
5797
 */
5768
5798
static char *my_get_line(FILE *fp)
5769
5799
{
5770
 
   char buf[4096];
5771
 
   char *nl = NULL;
5772
 
   char *retval = NULL;
5773
 
 
5774
 
   do {
5775
 
     if (NULL == fgets(buf, sizeof(buf), fp))
5776
 
       break;
5777
 
     if (NULL == retval) {
5778
 
       retval = strdup(buf);
5779
 
       if(!retval)
5780
 
         return NULL;
5781
 
     }
5782
 
     else {
5783
 
       char *ptr;
5784
 
       ptr = realloc(retval, strlen(retval) + strlen(buf) + 1);
5785
 
       if (NULL == ptr) {
5786
 
         free(retval);
5787
 
         return NULL;
5788
 
       }
5789
 
       retval = ptr;
5790
 
       strcat(retval, buf);
5791
 
     }
5792
 
   }
5793
 
   while (NULL == (nl = strchr(retval, '\n')));
5794
 
 
5795
 
   if (NULL != nl)
5796
 
     *nl = '\0';
5797
 
 
5798
 
   return retval;
 
5800
  char buf[4096];
 
5801
  char *nl = NULL;
 
5802
  char *retval = NULL;
 
5803
 
 
5804
  do {
 
5805
    if(NULL == fgets(buf, sizeof(buf), fp))
 
5806
      break;
 
5807
    if(NULL == retval) {
 
5808
      retval = strdup(buf);
 
5809
      if(!retval)
 
5810
        return NULL;
 
5811
    }
 
5812
    else {
 
5813
      char *ptr;
 
5814
      ptr = realloc(retval, strlen(retval) + strlen(buf) + 1);
 
5815
      if(NULL == ptr) {
 
5816
        free(retval);
 
5817
        return NULL;
 
5818
      }
 
5819
      retval = ptr;
 
5820
      strcat(retval, buf);
 
5821
    }
 
5822
  }
 
5823
  while(NULL == (nl = strchr(retval, '\n')));
 
5824
 
 
5825
  if(NULL != nl)
 
5826
    *nl = '\0';
 
5827
 
 
5828
  return retval;
5799
5829
}
5800
5830
 
5801
5831
static void show_dir_errno(FILE *errors, const char *name)
5860
5890
 
5861
5891
  tempdir = strtok(outdup, DIR_CHAR);
5862
5892
 
5863
 
  while (tempdir != NULL) {
 
5893
  while(tempdir != NULL) {
5864
5894
    tempdir2 = strtok(NULL, DIR_CHAR);
5865
5895
    /* since strtok returns a token for the last word even
5866
5896
       if not ending with DIR_CHAR, we need to prune it */
5867
 
    if (tempdir2 != NULL) {
 
5897
    if(tempdir2 != NULL) {
5868
5898
      size_t dlen = strlen(dirbuildup);
5869
 
      if (dlen)
 
5899
      if(dlen)
5870
5900
        sprintf(&dirbuildup[dlen], "%s%s", DIR_CHAR, tempdir);
5871
5901
      else {
5872
 
        if (0 != strncmp(outdup, DIR_CHAR, 1))
 
5902
        if(0 != strncmp(outdup, DIR_CHAR, 1))
5873
5903
          strcpy(dirbuildup, tempdir);
5874
5904
        else
5875
5905
          sprintf(dirbuildup, "%s%s", DIR_CHAR, tempdir);
5876
5906
      }
5877
 
      if (access(dirbuildup, F_OK) == -1) {
 
5907
      if(access(dirbuildup, F_OK) == -1) {
5878
5908
        result = mkdir(dirbuildup,(mode_t)0000750);
5879
 
        if (-1 == result) {
 
5909
        if(-1 == result) {
5880
5910
          show_dir_errno(errors, dirbuildup);
5881
5911
          break; /* get out of loop */
5882
5912
        }
5927
5957
{
5928
5958
  static char dos_name[PATH_MAX];
5929
5959
  static const char illegal_chars_dos[] = ".+, ;=[]" /* illegal in DOS */
5930
 
                                       "|<>\\\":?*"; /* illegal in DOS & W95 */
 
5960
    "|<>\\\":?*"; /* illegal in DOS & W95 */
5931
5961
  static const char *illegal_chars_w95 = &illegal_chars_dos[8];
5932
5962
  int idx, dot_idx;
5933
5963
  const char *s = file_name;
5937
5967
  size_t len = sizeof (illegal_chars_dos) - 1;
5938
5968
 
5939
5969
  /* Support for Windows 9X VFAT systems, when available. */
5940
 
  if (_use_lfn (file_name)) {
 
5970
  if(_use_lfn (file_name)) {
5941
5971
    illegal_aliens = illegal_chars_w95;
5942
5972
    len -= (illegal_chars_w95 - illegal_chars_dos);
5943
5973
  }
5944
5974
 
5945
5975
  /* Get past the drive letter, if any. */
5946
 
  if (s[0] >= 'A' && s[0] <= 'z' && s[1] == ':') {
 
5976
  if(s[0] >= 'A' && s[0] <= 'z' && s[1] == ':') {
5947
5977
    *d++ = *s++;
5948
5978
    *d++ = *s++;
5949
5979
  }
5950
5980
 
5951
 
  for (idx = 0, dot_idx = -1; *s && d < dlimit; s++, d++) {
5952
 
    if (memchr (illegal_aliens, *s, len)) {
 
5981
  for(idx = 0, dot_idx = -1; *s && d < dlimit; s++, d++) {
 
5982
    if(memchr (illegal_aliens, *s, len)) {
5953
5983
      /* Dots are special: DOS doesn't allow them as the leading character,
5954
5984
         and a file name cannot have more than a single dot.  We leave the
5955
5985
         first non-leading dot alone, unless it comes too close to the
5956
5986
         beginning of the name: we want sh.lex.c to become sh_lex.c, not
5957
5987
         sh.lex-c.  */
5958
 
      if (*s == '.') {
5959
 
        if (idx == 0 && (s[1] == '/' || (s[1] == '.' && s[2] == '/'))) {
 
5988
      if(*s == '.') {
 
5989
        if(idx == 0 && (s[1] == '/' || (s[1] == '.' && s[2] == '/'))) {
5960
5990
          /* Copy "./" and "../" verbatim.  */
5961
5991
          *d++ = *s++;
5962
 
          if (*s == '.')
 
5992
          if(*s == '.')
5963
5993
            *d++ = *s++;
5964
5994
          *d = *s;
5965
5995
        }
5966
 
        else if (idx == 0)
 
5996
        else if(idx == 0)
5967
5997
          *d = '_';
5968
 
        else if (dot_idx >= 0) {
5969
 
          if (dot_idx < 5) { /* 5 is a heuristic ad-hoc'ery */
 
5998
        else if(dot_idx >= 0) {
 
5999
          if(dot_idx < 5) { /* 5 is a heuristic ad-hoc'ery */
5970
6000
            d[dot_idx - idx] = '_'; /* replace previous dot */
5971
6001
            *d = '.';
5972
6002
          }
5976
6006
        else
5977
6007
          *d = '.';
5978
6008
 
5979
 
        if (*s == '.')
 
6009
        if(*s == '.')
5980
6010
          dot_idx = idx;
5981
6011
      }
5982
 
      else if (*s == '+' && s[1] == '+') {
5983
 
        if (idx - 2 == dot_idx) { /* .c++, .h++ etc. */
 
6012
      else if(*s == '+' && s[1] == '+') {
 
6013
        if(idx - 2 == dot_idx) { /* .c++, .h++ etc. */
5984
6014
          *d++ = 'x';
5985
6015
          *d   = 'x';
5986
6016
        }
5997
6027
    }
5998
6028
    else
5999
6029
      *d = *s;
6000
 
    if (*s == '/') {
 
6030
    if(*s == '/') {
6001
6031
      idx = 0;
6002
6032
      dot_idx = -1;
6003
6033
    }
6022
6052
  strncpy(fname, file_name, PATH_MAX-1);
6023
6053
  fname[PATH_MAX-1] = 0;
6024
6054
  base = basename(fname);
6025
 
  if (((stat(base, &st_buf)) == 0) && (S_ISCHR(st_buf.st_mode))) {
 
6055
  if(((stat(base, &st_buf)) == 0) && (S_ISCHR(st_buf.st_mode))) {
6026
6056
    size_t blen = strlen (base);
6027
6057
 
6028
 
    if (strlen(fname) >= PATH_MAX-1) {
 
6058
    if(strlen(fname) >= PATH_MAX-1) {
6029
6059
      /* Make room for the '_' */
6030
6060
      blen--;
6031
6061
      base[blen] = 0;