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

« back to all changes in this revision

Viewing changes to lib/transfer.c

  • Committer: Bazaar Package Importer
  • Author(s): Ramakrishnan Muthukrishnan
  • Date: 2011-02-28 19:35:36 UTC
  • mto: (3.6.1 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20110228193536-p3a9jawxxofcsz7o
Tags: upstream-7.21.4
ImportĀ upstreamĀ versionĀ 7.21.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
355
355
#endif
356
356
}
357
357
 
 
358
/*
 
359
 * Check to see if CURLOPT_TIMECONDITION was met by comparing the time of the
 
360
 * remote document with the time provided by CURLOPT_TIMEVAL
 
361
 */
 
362
bool Curl_meets_timecondition(struct SessionHandle *data, long timeofdoc)
 
363
{
 
364
  if((timeofdoc == 0) || (data->set.timevalue == 0))
 
365
    return TRUE;
 
366
 
 
367
  switch(data->set.timecondition) {
 
368
  case CURL_TIMECOND_IFMODSINCE:
 
369
  default:
 
370
    if(timeofdoc <= data->set.timevalue) {
 
371
      infof(data,
 
372
            "The requested document is not new enough\n");
 
373
      data->info.timecond = TRUE;
 
374
      return FALSE;
 
375
    }
 
376
    break;
 
377
  case CURL_TIMECOND_IFUNMODSINCE:
 
378
    if(timeofdoc >= data->set.timevalue) {
 
379
      infof(data,
 
380
            "The requested document is not old enough\n");
 
381
      data->info.timecond = TRUE;
 
382
      return FALSE;
 
383
    }
 
384
    break;
 
385
  }
 
386
 
 
387
  return TRUE;
 
388
}
358
389
 
359
390
/*
360
391
 * Go ahead and do a read if we have a readable socket or if
518
549
               requested. This seems to be what chapter 13.3.4 of
519
550
               RFC 2616 defines to be the correct action for a
520
551
               HTTP/1.1 client */
521
 
            if((k->timeofdoc > 0) && (data->set.timevalue > 0)) {
522
 
              switch(data->set.timecondition) {
523
 
              case CURL_TIMECOND_IFMODSINCE:
524
 
              default:
525
 
                if(k->timeofdoc < data->set.timevalue) {
526
 
                  infof(data,
527
 
                        "The requested document is not new enough\n");
528
 
                  *done = TRUE;
529
 
                  data->info.timecond = TRUE;
530
 
                  return CURLE_OK;
531
 
                }
532
 
                break;
533
 
              case CURL_TIMECOND_IFUNMODSINCE:
534
 
                if(k->timeofdoc > data->set.timevalue) {
535
 
                  infof(data,
536
 
                        "The requested document is not old enough\n");
537
 
                  *done = TRUE;
538
 
                  data->info.timecond = TRUE;
539
 
                  return CURLE_OK;
540
 
                }
541
 
                break;
542
 
              } /* switch */
543
 
            } /* two valid time strings */
 
552
 
 
553
            if(!Curl_meets_timecondition(data, k->timeofdoc)) {
 
554
              *done = TRUE;
 
555
              return CURLE_OK;
 
556
            }
544
557
          } /* we have a time condition */
545
558
 
546
559
        } /* this is HTTP */
1064
1077
    return result;
1065
1078
 
1066
1079
  if(k->keepon) {
1067
 
    if(0 > Curl_timeleft(conn, &k->now, FALSE)) {
 
1080
    if(0 > Curl_timeleft(data, &k->now, FALSE)) {
1068
1081
      if(k->size != -1) {
1069
1082
        failf(data, "Operation timed out after %ld milliseconds with %"
1070
1083
              FORMAT_OFF_T " out of %" FORMAT_OFF_T " bytes received",
1347
1360
         to work with, skip the timeout */
1348
1361
      timeout_ms = 0;
1349
1362
    else {
1350
 
      totmp = Curl_timeleft(conn, &k->now, FALSE);
 
1363
      totmp = Curl_timeleft(data, &k->now, FALSE);
1351
1364
      if(totmp < 0)
1352
1365
        return CURLE_OPERATION_TIMEDOUT;
1353
1366
      else if(!totmp)
1382
1395
  return CURLE_OK;
1383
1396
}
1384
1397
 
1385
 
static void loadhostpairs(struct SessionHandle *data)
 
1398
static CURLcode loadhostpairs(struct SessionHandle *data)
1386
1399
{
1387
1400
  struct curl_slist *hostp;
1388
1401
  char hostname[256];
1393
1406
    if(!hostp->data)
1394
1407
      continue;
1395
1408
    if(hostp->data[0] == '-') {
1396
 
      /* mark an entry for removal */
 
1409
      /* TODO: mark an entry for removal */
1397
1410
    }
1398
1411
    else if(3 == sscanf(hostp->data, "%255[^:]:%d:%255s", hostname, &port,
1399
1412
                        address)) {
1416
1429
 
1417
1430
      if(data->share)
1418
1431
        Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
 
1432
 
 
1433
      if(!dns)
 
1434
        return CURLE_OUT_OF_MEMORY;
1419
1435
    }
1420
1436
  }
1421
1437
  data->change.resolve = NULL; /* dealt with now */
 
1438
 
 
1439
  return CURLE_OK;
1422
1440
}
1423
1441
 
1424
1442
 
1460
1478
 
1461
1479
  /* If there is a list of host pairs to deal with */
1462
1480
  if(data->change.resolve)
1463
 
    loadhostpairs(data);
 
1481
    res = loadhostpairs(data);
1464
1482
 
1465
 
 /* Allow data->set.use_port to set which port to use. This needs to be
1466
 
  * disabled for example when we follow Location: headers to URLs using
1467
 
  * different ports! */
1468
 
  data->state.allow_port = TRUE;
 
1483
  if(!res) {
 
1484
    /* Allow data->set.use_port to set which port to use. This needs to be
 
1485
     * disabled for example when we follow Location: headers to URLs using
 
1486
     * different ports! */
 
1487
    data->state.allow_port = TRUE;
1469
1488
 
1470
1489
#if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(HAVE_MSG_NOSIGNAL)
1471
 
  /*************************************************************
1472
 
   * Tell signal handler to ignore SIGPIPE
1473
 
   *************************************************************/
1474
 
  if(!data->set.no_signal)
1475
 
    data->state.prev_signal = signal(SIGPIPE, SIG_IGN);
 
1490
    /*************************************************************
 
1491
     * Tell signal handler to ignore SIGPIPE
 
1492
     *************************************************************/
 
1493
    if(!data->set.no_signal)
 
1494
      data->state.prev_signal = signal(SIGPIPE, SIG_IGN);
1476
1495
#endif
1477
1496
 
1478
 
  Curl_initinfo(data); /* reset session-specific information "variables" */
1479
 
  Curl_pgrsStartNow(data);
1480
 
 
1481
 
  if(data->set.timeout)
1482
 
    Curl_expire(data, data->set.timeout);
1483
 
 
1484
 
  if(data->set.connecttimeout)
1485
 
    Curl_expire(data, data->set.connecttimeout);
1486
 
 
1487
 
  return CURLE_OK;
 
1497
    Curl_initinfo(data); /* reset session-specific information "variables" */
 
1498
    Curl_pgrsStartNow(data);
 
1499
 
 
1500
    if(data->set.timeout)
 
1501
      Curl_expire(data, data->set.timeout);
 
1502
 
 
1503
    if(data->set.connecttimeout)
 
1504
      Curl_expire(data, data->set.connecttimeout);
 
1505
  }
 
1506
 
 
1507
  return res;
1488
1508
}
1489
1509
 
1490
1510
/*