Get the openssl code ready for C++ management.
The strings aren't managed yet.
This commit is contained in:
+18
-21
@@ -64,28 +64,28 @@
|
||||
#define CERT_STATUS_BAD 3
|
||||
#define CERT_STATUS_USER_ACCEPTED 4
|
||||
|
||||
typedef struct {
|
||||
struct Server_t {
|
||||
char *hostname;
|
||||
int port;
|
||||
int cert_status;
|
||||
} Server_t;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct FdMapEntry_t{
|
||||
int fd;
|
||||
int connkey;
|
||||
} FdMapEntry_t;
|
||||
};
|
||||
|
||||
/*
|
||||
* Data type for TLS connection information
|
||||
*/
|
||||
typedef struct {
|
||||
struct Conn_t {
|
||||
int fd;
|
||||
DilloUrl *url;
|
||||
SSL *ssl;
|
||||
bool connecting;
|
||||
bool in_connect;
|
||||
bool do_shutdown;
|
||||
} Conn_t;
|
||||
};
|
||||
|
||||
/* List of active TLS connections */
|
||||
static Klist_t *conn_list = NULL;
|
||||
@@ -112,7 +112,7 @@ static int Tls_fd_map_cmp(const void *v1, const void *v2)
|
||||
|
||||
static void Tls_fd_map_add_entry(int fd, int connkey)
|
||||
{
|
||||
FdMapEntry_t *e = dNew0(FdMapEntry_t, 1);
|
||||
FdMapEntry_t *e = std::make_unique< FdMapEntry_t >().release();
|
||||
e->fd = fd;
|
||||
e->connkey = connkey;
|
||||
|
||||
@@ -130,12 +130,12 @@ static void Tls_fd_map_add_entry(int fd, int connkey)
|
||||
*/
|
||||
static void Tls_fd_map_remove_entry(int fd)
|
||||
{
|
||||
void *data = dList_find_custom(fd_map, INT2VOIDP(fd), Tls_fd_map_cmp);
|
||||
std::unique_ptr< FdMapEntry_t > data { reinterpret_cast< FdMapEntry_t * >( dList_find_custom(fd_map, INT2VOIDP(fd), Tls_fd_map_cmp) ) };
|
||||
|
||||
//MSG("REMOVE ENTRY %d\n", fd);
|
||||
if (data) {
|
||||
dList_remove_fast(fd_map, data);
|
||||
dFree(data);
|
||||
dList_remove_fast(fd_map, data.get());
|
||||
data.reset();
|
||||
} else {
|
||||
MSG("TLS FD ENTRY NOT FOUND FOR %d\n", fd);
|
||||
}
|
||||
@@ -166,7 +166,7 @@ static int Tls_conn_new(int fd, const DilloUrl *url, SSL *ssl)
|
||||
{
|
||||
int key;
|
||||
|
||||
Conn_t *conn = dNew0(Conn_t, 1);
|
||||
Conn_t *conn = std::make_unique< Conn_t >().release();
|
||||
conn->fd = fd;
|
||||
conn->url = a_Url_dup(url).release();
|
||||
conn->ssl = ssl;
|
||||
@@ -415,7 +415,7 @@ int a_Tls_openssl_connect_ready(const DilloUrl *url)
|
||||
if (s->cert_status == CERT_STATUS_NONE)
|
||||
s->cert_status = CERT_STATUS_RECEIVING;
|
||||
} else {
|
||||
s = dNew(Server_t, 1);
|
||||
s = std::make_unique< Server_t >().release();
|
||||
|
||||
s->hostname = dStrdup(URL_HOST(url));
|
||||
s->port = URL_PORT(url);
|
||||
@@ -1074,9 +1074,11 @@ void a_Tls_openssl_reset_server_state(const DilloUrl *url)
|
||||
*/
|
||||
static void Tls_close_by_key(int connkey)
|
||||
{
|
||||
Conn_t *c;
|
||||
std::unique_ptr< Conn_t > c;
|
||||
|
||||
if ((c = reinterpret_cast< Conn_t * >( a_Klist_get_data(conn_list, connkey) ))) {
|
||||
c.reset( reinterpret_cast< Conn_t * >( a_Klist_get_data(conn_list, connkey) ));
|
||||
|
||||
if( c ){
|
||||
a_Tls_openssl_reset_server_state(c->url);
|
||||
if (c->connecting) {
|
||||
a_IOwatch_remove_fd(c->fd, -1);
|
||||
@@ -1095,7 +1097,6 @@ static void Tls_close_by_key(int connkey)
|
||||
delete c->url;
|
||||
Tls_fd_map_remove_entry(c->fd);
|
||||
a_Klist_remove(conn_list, connkey);
|
||||
dFree(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1371,13 +1372,11 @@ void a_Tls_openssl_close_by_fd(int fd)
|
||||
static void Tls_servers_freeall(void)
|
||||
{
|
||||
if (servers) {
|
||||
Server_t *s;
|
||||
int i, n = dList_length(servers);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
s = (Server_t *) dList_nth_data(servers, i);
|
||||
std::unique_ptr< Server_t > s { reinterpret_cast< Server_t * >( dList_nth_data(servers, i) ) };
|
||||
dFree(s->hostname);
|
||||
dFree(s);
|
||||
}
|
||||
dList_free(servers);
|
||||
}
|
||||
@@ -1386,12 +1385,10 @@ static void Tls_servers_freeall(void)
|
||||
static void Tls_fd_map_remove_all(void)
|
||||
{
|
||||
if (fd_map) {
|
||||
FdMapEntry_t *fme;
|
||||
int i, n = dList_length(fd_map);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
fme = (FdMapEntry_t *) dList_nth_data(fd_map, i);
|
||||
dFree(fme);
|
||||
std::unique_ptr< FdMapEntry_t >fme{ reinterpret_cast<FdMapEntry_t *>( dList_nth_data(fd_map, i) ) };
|
||||
}
|
||||
dList_free(fd_map);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user