diff options
| author | Daniel Stenberg <daniel@haxx.se> | 2012-03-08 23:31:38 +0100 | 
|---|---|---|
| committer | Daniel Stenberg <daniel@haxx.se> | 2012-03-08 23:31:38 +0100 | 
| commit | 41b02378342322aa8e264260057502f4d7493239 (patch) | |
| tree | 2c36f9555820464145d4153d00f24834c6df62e4 | |
| parent | cabd010dd46ae4d37d91e20e1127cb00e67ec0a7 (diff) | |
CONNECT: made generically not per-protocol
Curl_protocol_connect() now does the tunneling through the HTTP proxy if
requested instead of letting each protocol specific connection function
do it.
| -rw-r--r-- | lib/ftp.c | 27 | ||||
| -rw-r--r-- | lib/http.c | 19 | ||||
| -rw-r--r-- | lib/imap.c | 29 | ||||
| -rw-r--r-- | lib/openldap.c | 27 | ||||
| -rw-r--r-- | lib/pop3.c | 27 | ||||
| -rw-r--r-- | lib/smtp.c | 27 | ||||
| -rw-r--r-- | lib/ssh.c | 28 | ||||
| -rw-r--r-- | lib/url.c | 41 | 
8 files changed, 39 insertions, 186 deletions
| @@ -3197,33 +3197,6 @@ static CURLcode ftp_connect(struct connectdata *conn,    pp->endofresp = ftp_endofresp;    pp->conn = conn; -  if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { -    /* for FTP over HTTP proxy */ -    struct HTTP http_proxy; -    struct FTP *ftp_save; - -    /* BLOCKING */ -    /* We want "seamless" FTP operations through HTTP proxy tunnel */ - -    /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member -     * conn->proto.http; we want FTP through HTTP and we have to change the -     * member temporarily for connecting to the HTTP proxy. After -     * Curl_proxyCONNECT we have to set back the member to the original struct -     * FTP pointer -     */ -    ftp_save = data->state.proto.ftp; -    memset(&http_proxy, 0, sizeof(http_proxy)); -    data->state.proto.http = &http_proxy; - -    result = Curl_proxyCONNECT(conn, FIRSTSOCKET, -                               conn->host.name, conn->remote_port); - -    data->state.proto.ftp = ftp_save; - -    if(CURLE_OK != result) -      return result; -  } -    if(conn->handler->flags & PROTOPT_SSL) {      /* BLOCKING */      result = Curl_ssl_connect(conn, FIRSTSOCKET); diff --git a/lib/http.c b/lib/http.c index fe1c7fd88..374de7d21 100644 --- a/lib/http.c +++ b/lib/http.c @@ -5,7 +5,7 @@   *                            | (__| |_| |  _ <| |___   *                             \___|\___/|_| \_\_____|   * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.   *   * This software is licensed as described in the file COPYING, which   * you should have received as part of this distribution. The terms @@ -1309,27 +1309,10 @@ CURLcode Curl_http_connect(struct connectdata *conn, bool *done)       function to make the re-use checks properly be able to check this bit. */    conn->bits.close = FALSE; -#ifndef CURL_DISABLE_PROXY -  /* If we are not using a proxy and we want a secure connection, perform SSL -   * initialization & connection now.  If using a proxy with https, then we -   * must tell the proxy to CONNECT to the host we want to talk to.  Only -   * after the connect has occurred, can we start talking SSL -   */ -  if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { - -    /* either SSL over proxy, or explicitly asked for */ -    result = Curl_proxyCONNECT(conn, FIRSTSOCKET, -                               conn->host.name, -                               conn->remote_port); -    if(CURLE_OK != result) -      return result; -  } -    if(conn->bits.tunnel_connecting) {      /* nothing else to do except wait right now - we're not done here. */      return CURLE_OK;    } -#endif /* CURL_DISABLE_PROXY */    if(conn->given->flags & PROTOPT_SSL) {      /* perform SSL initialization */ diff --git a/lib/imap.c b/lib/imap.c index c6701417d..6551190ee 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -5,7 +5,7 @@   *                            | (__| |_| |  _ <| |___   *                             \___|\___/|_| \_\_____|   * - * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.   *   * This software is licensed as described in the file COPYING, which   * you should have received as part of this distribution. The terms @@ -721,33 +721,6 @@ static CURLcode imap_connect(struct connectdata *conn,    pp->endofresp = imap_endofresp;    pp->conn = conn; -  if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { -    /* for IMAP over HTTP proxy */ -    struct HTTP http_proxy; -    struct FTP *imap_save; - -    /* BLOCKING */ -    /* We want "seamless" IMAP operations through HTTP proxy tunnel */ - -    /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member -     * conn->proto.http; we want IMAP through HTTP and we have to change the -     * member temporarily for connecting to the HTTP proxy. After -     * Curl_proxyCONNECT we have to set back the member to the original struct -     * IMAP pointer -     */ -    imap_save = data->state.proto.imap; -    memset(&http_proxy, 0, sizeof(http_proxy)); -    data->state.proto.http = &http_proxy; - -    result = Curl_proxyCONNECT(conn, FIRSTSOCKET, -                               conn->host.name, conn->remote_port); - -    data->state.proto.imap = imap_save; - -    if(CURLE_OK != result) -      return result; -  } -    if((conn->handler->flags & PROTOPT_SSL) &&       data->state.used_interface != Curl_if_multi) {      /* BLOCKING */ diff --git a/lib/openldap.c b/lib/openldap.c index a26ff2e15..3a6c7e341 100644 --- a/lib/openldap.c +++ b/lib/openldap.c @@ -208,33 +208,6 @@ static CURLcode ldap_connect(struct connectdata *conn, bool *done)    ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto); -  if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { -    /* for LDAP over HTTP proxy */ -    struct HTTP http_proxy; -    ldapconninfo *li_save; -    CURLcode result; - -    /* BLOCKING */ -    /* We want "seamless" LDAP operations through HTTP proxy tunnel */ - -    /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member -     * conn->proto.http; we want LDAP through HTTP and we have to change the -     * member temporarily for connecting to the HTTP proxy. After -     * Curl_proxyCONNECT we have to set back the member to the original struct -     * LDAP pointer -     */ -    li_save = data->state.proto.generic; -    memset(&http_proxy, 0, sizeof(http_proxy)); -    data->state.proto.http = &http_proxy; -    result = Curl_proxyCONNECT(conn, FIRSTSOCKET, -                               conn->host.name, conn->remote_port); - -    data->state.proto.generic = li_save; - -    if(CURLE_OK != result) -      return result; -  } -  #ifdef USE_SSL    if(conn->handler->flags & PROTOPT_SSL) {      CURLcode res; diff --git a/lib/pop3.c b/lib/pop3.c index b9201e474..4009a1fd7 100644 --- a/lib/pop3.c +++ b/lib/pop3.c @@ -670,33 +670,6 @@ static CURLcode pop3_connect(struct connectdata *conn,    pp->endofresp = pop3_endofresp;    pp->conn = conn; -  if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { -    /* for POP3 over HTTP proxy */ -    struct HTTP http_proxy; -    struct FTP *pop3_save; - -    /* BLOCKING */ -    /* We want "seamless" POP3 operations through HTTP proxy tunnel */ - -    /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member -     * conn->proto.http; we want POP3 through HTTP and we have to change the -     * member temporarily for connecting to the HTTP proxy. After -     * Curl_proxyCONNECT we have to set back the member to the original struct -     * POP3 pointer -     */ -    pop3_save = data->state.proto.pop3; -    memset(&http_proxy, 0, sizeof(http_proxy)); -    data->state.proto.http = &http_proxy; - -    result = Curl_proxyCONNECT(conn, FIRSTSOCKET, -                               conn->host.name, conn->remote_port); - -    data->state.proto.pop3 = pop3_save; - -    if(CURLE_OK != result) -      return result; -  } -    if(conn->handler->flags & PROTOPT_SSL) {      /* BLOCKING */      result = Curl_ssl_connect(conn, FIRSTSOCKET); diff --git a/lib/smtp.c b/lib/smtp.c index 381e3e240..05a685949 100644 --- a/lib/smtp.c +++ b/lib/smtp.c @@ -1294,33 +1294,6 @@ static CURLcode smtp_connect(struct connectdata *conn,    pp->endofresp = smtp_endofresp;    pp->conn = conn; -  if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { -    /* for SMTP over HTTP proxy */ -    struct HTTP http_proxy; -    struct FTP *smtp_save; - -    /* BLOCKING */ -    /* We want "seamless" SMTP operations through HTTP proxy tunnel */ - -    /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member -     * conn->proto.http; we want SMTP through HTTP and we have to change the -     * member temporarily for connecting to the HTTP proxy. After -     * Curl_proxyCONNECT we have to set back the member to the original struct -     * SMTP pointer -     */ -    smtp_save = data->state.proto.smtp; -    memset(&http_proxy, 0, sizeof(http_proxy)); -    data->state.proto.http = &http_proxy; - -    result = Curl_proxyCONNECT(conn, FIRSTSOCKET, -                               conn->host.name, conn->remote_port); - -    data->state.proto.smtp = smtp_save; - -    if(CURLE_OK != result) -      return result; -  } -    if((conn->handler->protocol & CURLPROTO_SMTPS) &&        data->state.used_interface != Curl_if_multi) {      /* SMTPS is simply smtp with SSL for the control channel */ @@ -90,7 +90,6 @@  #include "multiif.h"  #include "select.h"  #include "warnless.h" -#include "http_proxy.h"  #define _MPRINTF_REPLACE /* use our functions only */  #include <curl/mprintf.h> @@ -2660,33 +2659,6 @@ static CURLcode ssh_connect(struct connectdata *conn, bool *done)       sessionhandle, deal with it */    Curl_reset_reqproto(conn); -  if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { -    /* for SSH over HTTP proxy */ -    struct HTTP http_proxy; -    struct SSHPROTO *ssh_save; - -    /* BLOCKING */ -    /* We want "seamless" SSH operations through HTTP proxy tunnel */ - -    /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member -     * conn->proto.http; we want SSH through HTTP and we have to change the -     * member temporarily for connecting to the HTTP proxy. After -     * Curl_proxyCONNECT we have to set back the member to the original struct -     * SSH pointer -     */ -    ssh_save = data->state.proto.ssh; -    memset(&http_proxy, 0, sizeof(http_proxy)); -    data->state.proto.http = &http_proxy; - -    result = Curl_proxyCONNECT(conn, FIRSTSOCKET, -                               conn->host.name, conn->remote_port); - -    data->state.proto.ssh = ssh_save; - -    if(CURLE_OK != result) -      return result; -  } -    result = ssh_init(conn);    if(result)      return result; @@ -124,6 +124,7 @@ int curl_win32_idn_to_ascii(const char *in, char **out);  #include "socks.h"  #include "curl_rtmp.h"  #include "gopher.h" +#include "http_proxy.h"  #define _MPRINTF_REPLACE /* use our functions only */  #include <curl/mprintf.h> @@ -3385,13 +3386,45 @@ CURLcode Curl_protocol_connect(struct connectdata *conn,    Curl_verboseconnect(conn);    if(!conn->bits.protoconnstart) { + +    /* Set start time here for timeout purposes in the connect procedure, it +       is later set again for the progress meter purpose */ +    conn->now = Curl_tvnow(); + +    if(conn->bits.tunnel_proxy && conn->bits.httpproxy) { +#ifndef CURL_DISABLE_PROXY +      /* for [protocol] tunneled through HTTP proxy */ +      struct HTTP http_proxy; +      void *prot_save; + +      /* BLOCKING */ +      /* We want "seamless" operations through HTTP proxy tunnel */ + +      /* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the +       * member conn->proto.http; we want [protocol] through HTTP and we have +       * to change the member temporarily for connecting to the HTTP +       * proxy. After Curl_proxyCONNECT we have to set back the member to the +       * original pointer +       */ +      prot_save = data->state.proto.generic; +      memset(&http_proxy, 0, sizeof(http_proxy)); +      data->state.proto.http = &http_proxy; + +      result = Curl_proxyCONNECT(conn, FIRSTSOCKET, +                                 conn->host.name, conn->remote_port); + +      data->state.proto.generic = prot_save; + +      if(CURLE_OK != result) +        return result; +#else +      return CURLE_NOT_BUILT_IN; +#endif +    } +      if(conn->handler->connect_it) {        /* is there a protocol-specific connect() procedure? */ -      /* Set start time here for timeout purposes in the connect procedure, it -         is later set again for the progress meter purpose */ -      conn->now = Curl_tvnow(); -        /* Call the protocol-specific connect function */        result = conn->handler->connect_it(conn, protocol_done);      } | 
