~ubuntu-branches/ubuntu/edgy/curl/edgy

« back to all changes in this revision

Viewing changes to lib/http.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-06-29 15:04:24 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060629150424-pn00qumt9sml8p4m
Tags: 7.15.4-1ubuntu1
Synchronize to Debian. Only change left: Removal of stunnel and
libdb4.2-dev build dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2006, 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
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: http.c,v 1.275 2005/10/20 20:07:33 bagder Exp $
 
21
 * $Id: http.c,v 1.282 2006-05-05 22:14:40 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
37
37
#include <sys/stat.h>
38
38
#endif
39
39
 
40
 
#include <errno.h>
41
 
 
42
40
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
43
41
#include <time.h>
44
42
#include <io.h>
97
95
#include "select.h"
98
96
#include "parsedate.h" /* for the week day and month names */
99
97
#include "strtoofft.h"
 
98
#include "multiif.h"
100
99
 
101
100
#define _MPRINTF_REPLACE /* use our functions only */
102
101
#include <curl/mprintf.h>
845
844
static
846
845
CURLcode add_buffer_send(send_buffer *in,
847
846
                         struct connectdata *conn,
848
 
                         long *bytes_written) /* add the number of sent
 
847
                         long *bytes_written, /* add the number of sent
849
848
                                                 bytes to this counter */
 
849
                         int socketindex)
850
850
{
851
851
  ssize_t amount;
852
852
  CURLcode res;
854
854
  size_t size;
855
855
  struct HTTP *http = conn->proto.http;
856
856
  size_t sendsize;
857
 
  curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
 
857
  curl_socket_t sockfd;
 
858
 
 
859
  curlassert(socketindex <= SECONDARYSOCKET);
 
860
 
 
861
  sockfd = conn->sock[socketindex];
858
862
 
859
863
  /* The looping below is required since we use non-blocking sockets, but due
860
864
     to the circumstances we will just loop and try again and again etc */
1166
1170
        if(CURLE_OK == result)
1167
1171
          /* Now send off the request */
1168
1172
          result = add_buffer_send(req_buffer, conn,
1169
 
                                   &data->info.request_size);
 
1173
                                   &data->info.request_size, sockindex);
1170
1174
      }
1171
1175
      if(result)
1172
1176
        failf(data, "Failed sending CONNECT to proxy");
1356
1360
   * after the connect has occured, can we start talking SSL
1357
1361
   */
1358
1362
 
1359
 
  if(conn->bits.tunnel_proxy) {
 
1363
  if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
1360
1364
 
1361
1365
    /* either SSL over proxy, or explicitly asked for */
1362
1366
    result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
1366
1370
      return result;
1367
1371
  }
1368
1372
 
1369
 
  if(conn->protocol & PROT_HTTPS) {
1370
 
    /* perform SSL initialization for this socket */
1371
 
    result = Curl_ssl_connect(conn, FIRSTSOCKET);
1372
 
    if(result)
1373
 
      return result;
1374
 
  }
1375
 
 
1376
1373
  if(!data->state.this_is_a_follow) {
1377
1374
    /* this is not a followed location, get the original host name */
1378
1375
    if (data->state.first_host)
1382
1379
    data->state.first_host = strdup(conn->host.name);
1383
1380
  }
1384
1381
 
1385
 
  *done = TRUE;
1386
 
 
1387
 
  return CURLE_OK;
1388
 
}
 
1382
  if(conn->protocol & PROT_HTTPS) {
 
1383
    /* perform SSL initialization */
 
1384
    if(data->state.used_interface == Curl_if_multi) {
 
1385
      result = Curl_https_connecting(conn, done);
 
1386
      if(result)
 
1387
        return result;
 
1388
    }
 
1389
    else {
 
1390
      /* BLOCKING */
 
1391
      result = Curl_ssl_connect(conn, FIRSTSOCKET);
 
1392
      if(result)
 
1393
        return result;
 
1394
      *done = TRUE;
 
1395
    }
 
1396
  }
 
1397
  else {
 
1398
    *done = TRUE;
 
1399
  }
 
1400
 
 
1401
  return CURLE_OK;
 
1402
}
 
1403
 
 
1404
CURLcode Curl_https_connecting(struct connectdata *conn, bool *done)
 
1405
{
 
1406
  CURLcode result;
 
1407
  curlassert(conn->protocol & PROT_HTTPS);
 
1408
 
 
1409
  /* perform SSL initialization for this socket */
 
1410
  result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, done);
 
1411
  if(result)
 
1412
    return result;
 
1413
 
 
1414
  return CURLE_OK;
 
1415
}
 
1416
 
 
1417
#ifdef USE_SSLEAY
 
1418
/* This function is OpenSSL-specific. It should be made to query the generic
 
1419
   SSL layer instead. */
 
1420
int Curl_https_getsock(struct connectdata *conn,
 
1421
                       curl_socket_t *socks,
 
1422
                       int numsocks)
 
1423
{
 
1424
  if (conn->protocol & PROT_HTTPS) {
 
1425
    struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET];
 
1426
 
 
1427
    if(!numsocks)
 
1428
      return GETSOCK_BLANK;
 
1429
 
 
1430
    if (connssl->connecting_state == ssl_connect_2_writing) {
 
1431
      /* write mode */
 
1432
      socks[0] = conn->sock[FIRSTSOCKET];
 
1433
      return GETSOCK_WRITESOCK(0);
 
1434
    }
 
1435
    else if (connssl->connecting_state == ssl_connect_2_reading) {
 
1436
      /* read mode */
 
1437
      socks[0] = conn->sock[FIRSTSOCKET];
 
1438
      return GETSOCK_READSOCK(0);
 
1439
    }
 
1440
  }
 
1441
  return CURLE_OK;
 
1442
}
 
1443
#else
 
1444
#ifdef USE_GNUTLS
 
1445
int Curl_https_getsock(struct connectdata *conn,
 
1446
                       curl_socket_t *socks,
 
1447
                       int numsocks)
 
1448
{
 
1449
  (void)conn;
 
1450
  (void)socks;
 
1451
  (void)numsocks;
 
1452
  return GETSOCK_BLANK;
 
1453
}
 
1454
#endif
 
1455
#endif
1389
1456
 
1390
1457
/*
1391
1458
 * Curl_http_done() gets called from Curl_done() after a single HTTP request
2032
2099
          return result;
2033
2100
 
2034
2101
        result = add_buffer_send(req_buffer, conn,
2035
 
                                 &data->info.request_size);
 
2102
                                 &data->info.request_size, FIRSTSOCKET);
2036
2103
        if(result)
2037
2104
          failf(data, "Failed sending POST request");
2038
2105
        else
2097
2164
 
2098
2165
      /* fire away the whole request to the server */
2099
2166
      result = add_buffer_send(req_buffer, conn,
2100
 
                               &data->info.request_size);
 
2167
                               &data->info.request_size, FIRSTSOCKET);
2101
2168
      if(result)
2102
2169
        failf(data, "Failed sending POST request");
2103
2170
      else
2141
2208
 
2142
2209
      /* this sends the buffer and frees all the buffer resources */
2143
2210
      result = add_buffer_send(req_buffer, conn,
2144
 
                               &data->info.request_size);
 
2211
                               &data->info.request_size, FIRSTSOCKET);
2145
2212
      if(result)
2146
2213
        failf(data, "Failed sending PUT request");
2147
2214
      else
2263
2330
      }
2264
2331
      /* issue the request */
2265
2332
      result = add_buffer_send(req_buffer, conn,
2266
 
                               &data->info.request_size);
 
2333
                               &data->info.request_size, FIRSTSOCKET);
2267
2334
 
2268
2335
      if(result)
2269
2336
        failf(data, "Failed sending HTTP POST request");
2280
2347
 
2281
2348
      /* issue the request */
2282
2349
      result = add_buffer_send(req_buffer, conn,
2283
 
                               &data->info.request_size);
 
2350
                               &data->info.request_size, FIRSTSOCKET);
2284
2351
 
2285
2352
      if(result)
2286
2353
        failf(data, "Failed sending HTTP request");