mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
T. Bharath's comments about SSL cleanup incorporated, and the two new
curl_global_* functions
This commit is contained in:
parent
a9d0a85842
commit
d300cf4d84
16
lib/easy.c
16
lib/easy.c
@ -73,16 +73,30 @@
|
|||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include "transfer.h"
|
#include "transfer.h"
|
||||||
#include <curl/types.h>
|
#include "ssluse.h"
|
||||||
|
|
||||||
#define _MPRINTF_REPLACE /* use our functions only */
|
#define _MPRINTF_REPLACE /* use our functions only */
|
||||||
#include <curl/mprintf.h>
|
#include <curl/mprintf.h>
|
||||||
|
|
||||||
|
CURLcode curl_global_init(void)
|
||||||
|
{
|
||||||
|
Curl_SSL_init();
|
||||||
|
return CURLE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void curl_global_cleanup(void)
|
||||||
|
{
|
||||||
|
Curl_SSL_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
CURL *curl_easy_init(void)
|
CURL *curl_easy_init(void)
|
||||||
{
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
struct UrlData *data;
|
struct UrlData *data;
|
||||||
|
|
||||||
|
/* Make sure we inited the global SSL stuff */
|
||||||
|
Curl_SSL_init();
|
||||||
|
|
||||||
/* We use curl_open() with undefined URL so far */
|
/* We use curl_open() with undefined URL so far */
|
||||||
res = Curl_open((CURL **)&data, NULL);
|
res = Curl_open((CURL **)&data, NULL);
|
||||||
if(res != CURLE_OK)
|
if(res != CURLE_OK)
|
||||||
|
40
lib/ssluse.c
40
lib/ssluse.c
@ -235,6 +235,40 @@ int cert_verify_callback(int ok, X509_STORE_CTX *ctx)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Global init */
|
||||||
|
void Curl_SSL_init(void)
|
||||||
|
{
|
||||||
|
#ifdef USE_SSLEAY
|
||||||
|
static int only_once=0;
|
||||||
|
|
||||||
|
/* make sure this is only done once */
|
||||||
|
if(0 != only_once)
|
||||||
|
return;
|
||||||
|
|
||||||
|
only_once++; /* never again */
|
||||||
|
|
||||||
|
/* Lets get nice error messages */
|
||||||
|
SSL_load_error_strings();
|
||||||
|
|
||||||
|
/* Setup all the global SSL stuff */
|
||||||
|
SSLeay_add_ssl_algorithms();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Global cleanup */
|
||||||
|
void Curl_SSL_cleanup(void)
|
||||||
|
{
|
||||||
|
#ifdef USE_SSLEAY
|
||||||
|
/* Free the SSL error strings */
|
||||||
|
ERR_free_strings();
|
||||||
|
|
||||||
|
/* EVP_cleanup() removes all ciphers and digests from the
|
||||||
|
table. */
|
||||||
|
EVP_cleanup();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ====================================================== */
|
/* ====================================================== */
|
||||||
CURLcode
|
CURLcode
|
||||||
Curl_SSLConnect(struct connectdata *conn)
|
Curl_SSLConnect(struct connectdata *conn)
|
||||||
@ -250,15 +284,9 @@ Curl_SSLConnect(struct connectdata *conn)
|
|||||||
/* mark this is being ssl enabled from here on out. */
|
/* mark this is being ssl enabled from here on out. */
|
||||||
conn->ssl.use = TRUE;
|
conn->ssl.use = TRUE;
|
||||||
|
|
||||||
/* Lets get nice error messages */
|
|
||||||
SSL_load_error_strings();
|
|
||||||
|
|
||||||
/* Make funny stuff to get random input */
|
/* Make funny stuff to get random input */
|
||||||
random_the_seed(conn);
|
random_the_seed(conn);
|
||||||
|
|
||||||
/* Setup all the global SSL stuff */
|
|
||||||
SSLeay_add_ssl_algorithms();
|
|
||||||
|
|
||||||
switch(data->ssl.version) {
|
switch(data->ssl.version) {
|
||||||
default:
|
default:
|
||||||
req_method = SSLv23_client_method();
|
req_method = SSLv23_client_method();
|
||||||
|
@ -24,4 +24,8 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
#include "urldata.h"
|
#include "urldata.h"
|
||||||
CURLcode Curl_SSLConnect(struct connectdata *conn);
|
CURLcode Curl_SSLConnect(struct connectdata *conn);
|
||||||
|
/* Global SSL init */
|
||||||
|
void Curl_SSL_init(void);
|
||||||
|
/* Global SSL cleanup */
|
||||||
|
void Curl_SSL_cleanup(void);
|
||||||
#endif
|
#endif
|
||||||
|
11
lib/url.c
11
lib/url.c
@ -833,6 +833,17 @@ CURLcode Curl_disconnect(struct connectdata *conn)
|
|||||||
|
|
||||||
#ifdef USE_SSLEAY
|
#ifdef USE_SSLEAY
|
||||||
if (conn->ssl.use) {
|
if (conn->ssl.use) {
|
||||||
|
/*
|
||||||
|
ERR_remove_state() frees the error queue associated with
|
||||||
|
thread pid. If pid == 0, the current thread will have its
|
||||||
|
error queue removed.
|
||||||
|
|
||||||
|
Since error queue data structures are allocated
|
||||||
|
automatically for new threads, they must be freed when
|
||||||
|
threads are terminated in oder to avoid memory leaks.
|
||||||
|
*/
|
||||||
|
ERR_remove_state(0);
|
||||||
|
|
||||||
if(conn->ssl.handle) {
|
if(conn->ssl.handle) {
|
||||||
(void)SSL_shutdown(conn->ssl.handle);
|
(void)SSL_shutdown(conn->ssl.handle);
|
||||||
SSL_set_connect_state(conn->ssl.handle);
|
SSL_set_connect_state(conn->ssl.handle);
|
||||||
|
Loading…
Reference in New Issue
Block a user