diff options
Diffstat (limited to 'lib/getinfo.c')
-rw-r--r-- | lib/getinfo.c | 100 |
1 files changed, 60 insertions, 40 deletions
diff --git a/lib/getinfo.c b/lib/getinfo.c index 910f520e..d4b01bf2 100644 --- a/lib/getinfo.c +++ b/lib/getinfo.c @@ -9,7 +9,7 @@ * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms - * are also available at http://curl.haxx.se/docs/copyright.html. + * are also available at https://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is @@ -113,7 +113,7 @@ static CURLcode getinfo_char(struct SessionHandle *data, CURLINFO info, break; default: - return CURLE_BAD_FUNCTION_ARGUMENT; + return CURLE_UNKNOWN_OPTION; } return CURLE_OK; @@ -200,7 +200,7 @@ static CURLcode getinfo_long(struct SessionHandle *data, CURLINFO info, break; default: - return CURLE_BAD_FUNCTION_ARGUMENT; + return CURLE_UNKNOWN_OPTION; } return CURLE_OK; @@ -253,7 +253,7 @@ static CURLcode getinfo_double(struct SessionHandle *data, CURLINFO info, break; default: - return CURLE_BAD_FUNCTION_ARGUMENT; + return CURLE_UNKNOWN_OPTION; } return CURLE_OK; @@ -281,54 +281,69 @@ static CURLcode getinfo_slist(struct SessionHandle *data, CURLINFO info, *param_slistp = ptr.to_slist; break; case CURLINFO_TLS_SESSION: + case CURLINFO_TLS_SSL_PTR: { struct curl_tlssessioninfo **tsip = (struct curl_tlssessioninfo **) param_slistp; struct curl_tlssessioninfo *tsi = &data->tsi; struct connectdata *conn = data->easy_conn; - unsigned int sockindex = 0; - void *internals = NULL; *tsip = tsi; - tsi->backend = CURLSSLBACKEND_NONE; + tsi->backend = Curl_ssl_backend(); tsi->internals = NULL; - if(!conn) - break; - - /* Find the active ("in use") SSL connection, if any */ - while((sockindex < sizeof(conn->ssl) / sizeof(conn->ssl[0])) && - (!conn->ssl[sockindex].use)) - sockindex++; - - if(sockindex == sizeof(conn->ssl) / sizeof(conn->ssl[0])) - break; /* no SSL session found */ - - /* Return the TLS session information from the relevant backend */ -#ifdef USE_OPENSSL - internals = conn->ssl[sockindex].ctx; -#endif -#ifdef USE_GNUTLS - internals = conn->ssl[sockindex].session; + if(conn && tsi->backend != CURLSSLBACKEND_NONE) { + unsigned int i; + for(i = 0; i < (sizeof(conn->ssl) / sizeof(conn->ssl[0])); ++i) { + if(conn->ssl[i].use) { +#if defined(USE_AXTLS) + tsi->internals = (void *)conn->ssl[i].ssl; +#elif defined(USE_CYASSL) + tsi->internals = (void *)conn->ssl[i].handle; +#elif defined(USE_DARWINSSL) + tsi->internals = (void *)conn->ssl[i].ssl_ctx; +#elif defined(USE_GNUTLS) + tsi->internals = (void *)conn->ssl[i].session; +#elif defined(USE_GSKIT) + tsi->internals = (void *)conn->ssl[i].handle; +#elif defined(USE_MBEDTLS) + tsi->internals = (void *)&conn->ssl[i].ssl; +#elif defined(USE_NSS) + tsi->internals = (void *)conn->ssl[i].handle; +#elif defined(USE_OPENSSL) + /* Legacy: CURLINFO_TLS_SESSION must return an SSL_CTX pointer. */ + tsi->internals = ((info == CURLINFO_TLS_SESSION) ? + (void *)conn->ssl[i].ctx : + (void *)conn->ssl[i].handle); +#elif defined(USE_POLARSSL) + tsi->internals = (void *)&conn->ssl[i].ssl; +#elif defined(USE_SCHANNEL) + tsi->internals = (void *)&conn->ssl[i].ctxt->ctxt_handle; +#elif defined(USE_SSL) +#error "SSL backend specific information missing for CURLINFO_TLS_SSL_PTR" #endif -#ifdef USE_NSS - internals = conn->ssl[sockindex].handle; -#endif -#ifdef USE_GSKIT - internals = conn->ssl[sockindex].handle; -#endif - if(internals) { - tsi->backend = Curl_ssl_backend(); - tsi->internals = internals; + break; + } + } } - /* NOTE: For other SSL backends, it is not immediately clear what data - to return from 'struct ssl_connect_data'; thus, for now we keep the - backend as CURLSSLBACKEND_NONE in those cases, which should be - interpreted as "not supported" */ } break; default: - return CURLE_BAD_FUNCTION_ARGUMENT; + return CURLE_UNKNOWN_OPTION; + } + + return CURLE_OK; +} + +static CURLcode getinfo_socket(struct SessionHandle *data, CURLINFO info, + curl_socket_t *param_socketp) +{ + switch(info) { + case CURLINFO_ACTIVESOCKET: + *param_socketp = Curl_getconnectinfo(data, NULL); + break; + default: + return CURLE_UNKNOWN_OPTION; } return CURLE_OK; @@ -341,9 +356,9 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) double *param_doublep = NULL; char **param_charp = NULL; struct curl_slist **param_slistp = NULL; + curl_socket_t *param_socketp = NULL; int type; - /* default return code is to error out! */ - CURLcode result = CURLE_BAD_FUNCTION_ARGUMENT; + CURLcode result = CURLE_UNKNOWN_OPTION; if(!data) return result; @@ -372,6 +387,11 @@ CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...) if(param_slistp) result = getinfo_slist(data, info, param_slistp); break; + case CURLINFO_SOCKET: + param_socketp = va_arg(arg, curl_socket_t *); + if(param_socketp) + result = getinfo_socket(data, info, param_socketp); + break; default: break; } |