Commit 47592fea authored by Pekka Pessi's avatar Pekka Pessi

Added vtables for transports.

API: tport_is_public().

darcs-hash:20060324014001-3e792-bccf257536ae0777433441f198b298510e746884.gz
parent 12b8a29a
......@@ -120,13 +120,6 @@ enum {
};
typedef enum tport_pri_type_e tport_pri_type_t;
enum {
tp_pri_is_local = 0,
tp_pri_is_stun,
tp_pri_is_http_connect,
} tport_primary_type_e;
/* AI extension flags - these must not overlap with existing AI flags. */
/** Message is to be sent/received compressed */
......@@ -252,6 +245,9 @@ TPORT_DLL int tport_is_master(tport_t const *self);
/** Return true if transport is primary. */
TPORT_DLL int tport_is_primary(tport_t const *self);
/** Return nonzero if transport is public. */
TPORT_DLL int tport_is_public(tport_t const *self);
/** Return true if transport is secondary. */
TPORT_DLL int tport_is_secondary(tport_t const *self);
......
......@@ -77,8 +77,21 @@ TPORT_DLL extern tag_typedef_t tptag_server;
TPORT_DLL extern tag_typedef_t tptag_server_ref;
#define TPTAG_SERVER_REF(x) tptag_server_ref, tag_bool_vr(&(x))
/** Define how the public transport connects to Internet.
*
* @sa TPTAG_PUBLIC(), tport_is_public().
*/
enum tport_via {
tport_type_local = 0,
tport_type_client = 1,
tport_type_stun = 2,
tport_type_upnp = 3,
tport_type_connect = 4,
tport_type_socks = 5,
} tport_pri_type_t;
TPORT_DLL extern tag_typedef_t tptag_public;
/** Bind public sockets (default false, enable with TPTAG_PUBLIC(1), TPTAG_PUBLIC(2) etc). */
/** Use a transport reaching to public Internet. */
#define TPTAG_PUBLIC(x) tptag_public, tag_int_v((x))
TPORT_DLL extern tag_typedef_t tptag_public_ref;
......
......@@ -35,6 +35,8 @@
#include "config.h"
#undef HAVE_TLS
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
......@@ -465,6 +467,7 @@ static int init_test(tp_test_t *tt)
#endif
tp_name_t const *tpn;
tport_t *tp;
int idle;
BEGIN();
......@@ -540,6 +543,10 @@ static int init_test(tp_test_t *tt)
TAG_END()),
0);
TEST(tport_get_params(tt->tt_srv_tports,
TPTAG_IDLE_REF(idle),
TAG_END()), 1);
for (tp = tport_primaries(tt->tt_srv_tports); tp; tp = tport_next(tp))
TEST_S(tport_name(tp)->tpn_ident, "server");
......
This diff is collapsed.
......@@ -61,7 +61,7 @@
char const tls_version[] = OPENSSL_VERSION_TEXT;
enum { tls_master, tls_client, tls_slave };
enum { tls_master, tls_slave };
struct tls_s {
SSL_CTX *ctx;
......@@ -98,21 +98,6 @@ tls_t *tls_create(int type)
return tls;
}
static
tls_t *tls_clone(tls_t *tls)
{
tls_t *tls_new = tls_create(tls_slave);
if (tls_new) {
tls_new->ctx = tls->ctx;
tls_new->bio_err = tls->bio_err;
if (!(tls_new->read_buffer = malloc(tls_buffer_size)))
free(tls_new), tls_new = NULL;
}
return tls_new;
}
static
void tls_set_default(tls_issues_t *i)
{
......@@ -381,10 +366,17 @@ int tls_accept(tls_t *tls)
}
#endif
tls_t *tls_init_slave(tls_t *master, int sock)
tls_t *tls_clone(tls_t *master, int sock, int accept)
{
tls_t *tls = tls_clone(master);
tls_t *tls = tls_create(tls_slave);
if (tls) {
tls->ctx = master->ctx;
tls->bio_err = master->bio_err;
if (!(tls->read_buffer = malloc(tls_buffer_size)))
free(tls), tls = NULL;
}
if (!tls)
return tls;
......@@ -394,7 +386,7 @@ tls_t *tls_init_slave(tls_t *master, int sock)
tls->con = SSL_new(tls->ctx);
if (tls->con == NULL) {
BIO_printf(tls->bio_err, "tls_init_slave: SSL_new failed\n");
BIO_printf(tls->bio_err, "tls_clone: SSL_new failed\n");
ERR_print_errors(tls->bio_err);
tls_free(tls);
errno = EIO;
......@@ -402,7 +394,10 @@ tls_t *tls_init_slave(tls_t *master, int sock)
}
SSL_set_bio(tls->con, tls->bio_con, tls->bio_con);
SSL_set_accept_state(tls->con);
if (accept)
SSL_set_accept_state(tls->con);
else
SSL_set_connect_state(tls->con);
SSL_set_mode(tls->con, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
tls_read(tls); /* XXX - works only with non-blocking sockets */
......@@ -410,32 +405,16 @@ tls_t *tls_init_slave(tls_t *master, int sock)
return tls;
}
tls_t *tls_init_slave(tls_t *master, int sock)
{
int accept;
return tls_clone(master, sock, accept = 1);
}
tls_t *tls_init_client(tls_t *master, int sock)
{
tls_t *tls = tls_clone(master);
if (!tls)
return tls;
tls->bio_con = BIO_new_socket(sock, BIO_NOCLOSE);
tls->con = SSL_new(tls->ctx);
if (tls->con == NULL || tls->bio_con == NULL) {
BIO_printf(tls->bio_err, "tls_init_client: SSL_new failed\n");
ERR_print_errors(tls->bio_err);
tls_free(tls);
errno = EIO;
return NULL;
}
SSL_set_bio(tls->con, tls->bio_con, tls->bio_con);
SSL_set_connect_state(tls->con);
SSL_set_mode(tls->con, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
tls_read(tls); /* XXX - works only with non-blocking sockets */
return tls;
int accept;
return tls_clone(master, sock, accept = 0);
}
static char *tls_strdup(char const *s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment