working on https server
This commit is contained in:
parent
d08bc700c9
commit
83a5182941
@ -233,7 +233,7 @@ to see the man page.
|
||||
|
||||
Po-sheng Lin <personlin118@gmail.com>
|
||||
|
||||
Peter Dunkley <peter.dunkley@crocodilertc.net>
|
||||
Peter Dunkley <peter.dunkley@acision.com>
|
||||
|
||||
Mutsutoshi Yoshimoto <mutsutoshi.yoshimoto@mixi.co.jp>
|
||||
|
||||
|
||||
@ -941,7 +941,7 @@ https://groups.google.com/forum/?fromgroups=#!forum/turn-server-project-rfc5766-
|
||||
|
||||
Po-sheng Lin <personlin118@gmail.com>
|
||||
|
||||
Peter Dunkley <peter.dunkley@crocodilertc.net>
|
||||
Peter Dunkley <peter.dunkley@acision.com>
|
||||
|
||||
Mutsutoshi Yoshimoto <mutsutoshi.yoshimoto@mixi.co.jp>
|
||||
|
||||
|
||||
@ -329,7 +329,7 @@ SEE ALSO
|
||||
|
||||
Po-sheng Lin <personlin118@gmail.com>
|
||||
|
||||
Peter Dunkley <peter.dunkley@crocodilertc.net>
|
||||
Peter Dunkley <peter.dunkley@acision.com>
|
||||
|
||||
Mutsutoshi Yoshimoto <mutsutoshi.yoshimoto@mixi.co.jp>
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
#include "ns_ioalib_impl.h"
|
||||
|
||||
void write_http_echo(ioa_socket_handle s)
|
||||
static void write_http_echo(ioa_socket_handle s)
|
||||
{
|
||||
if(s && !ioa_socket_tobeclosed(s)) {
|
||||
SOCKET_APP_TYPE sat = get_ioa_socket_app_type(s);
|
||||
@ -51,8 +51,6 @@ void write_http_echo(ioa_socket_handle s)
|
||||
}
|
||||
}
|
||||
|
||||
void handle_https(ioa_socket_handle s, ioa_network_buffer_handle nbh) {
|
||||
//TODO
|
||||
UNUSED_ARG(nbh);
|
||||
void handle_http(ioa_socket_handle s) {
|
||||
write_http_echo(s);
|
||||
}
|
||||
|
||||
@ -1649,6 +1649,7 @@ static void setup_relay_server(struct relay_server *rs, ioa_engine_handle e, int
|
||||
&turn_params.secure_stun, turn_params.shatype, &turn_params.mobility,
|
||||
turn_params.server_relay,
|
||||
send_turn_session_info,
|
||||
send_https_socket,
|
||||
allocate_bps,
|
||||
turn_params.oauth, turn_params.oauth_server_name);
|
||||
|
||||
|
||||
@ -1218,15 +1218,38 @@ static void cliserver_input_handler(struct evconnlistener *l, evutil_socket_t fd
|
||||
void setup_cli_thread(void)
|
||||
{
|
||||
cliserver.event_base = turn_event_base_new();
|
||||
super_memory_t* sm = new_super_memory_region();
|
||||
cliserver.e = create_ioa_engine(sm, cliserver.event_base, turn_params.listener.tp, turn_params.relay_ifname, turn_params.relays_number, turn_params.relay_addrs,
|
||||
turn_params.default_relays, turn_params.verbose
|
||||
#if !defined(TURN_NO_HIREDIS)
|
||||
,turn_params.redis_statsdb
|
||||
#endif
|
||||
);
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,"IO method (cli thread): %s\n",event_base_get_method(cliserver.event_base));
|
||||
|
||||
struct bufferevent *pair[2];
|
||||
{
|
||||
struct bufferevent *pair[2];
|
||||
|
||||
bufferevent_pair_new(cliserver.event_base, TURN_BUFFEREVENTS_OPTIONS, pair);
|
||||
cliserver.in_buf = pair[0];
|
||||
cliserver.out_buf = pair[1];
|
||||
bufferevent_setcb(cliserver.in_buf, cli_server_receive_message, NULL, NULL, &cliserver);
|
||||
bufferevent_enable(cliserver.in_buf, EV_READ);
|
||||
bufferevent_pair_new(cliserver.event_base, TURN_BUFFEREVENTS_OPTIONS, pair);
|
||||
|
||||
cliserver.in_buf = pair[0];
|
||||
cliserver.out_buf = pair[1];
|
||||
|
||||
bufferevent_setcb(cliserver.in_buf, cli_server_receive_message, NULL, NULL, &cliserver);
|
||||
bufferevent_enable(cliserver.in_buf, EV_READ);
|
||||
}
|
||||
|
||||
{
|
||||
struct bufferevent *pair[2];
|
||||
|
||||
bufferevent_pair_new(cliserver.event_base, TURN_BUFFEREVENTS_OPTIONS, pair);
|
||||
|
||||
cliserver.https_in_buf = pair[0];
|
||||
cliserver.https_out_buf = pair[1];
|
||||
|
||||
bufferevent_setcb(cliserver.https_in_buf, https_cli_server_receive_message, NULL, NULL, &cliserver);
|
||||
bufferevent_enable(cliserver.https_in_buf, EV_READ);
|
||||
}
|
||||
|
||||
if(!cli_addr_set) {
|
||||
if(make_ioa_addr((const u08bits*)CLI_DEFAULT_IP,0,&cli_addr)<0) {
|
||||
@ -1330,4 +1353,73 @@ int send_turn_session_info(struct turn_session_info* tsi)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/////////// HTTPS /////////////
|
||||
|
||||
static void write_https_echo(ioa_socket_handle s)
|
||||
{
|
||||
if(s && !ioa_socket_tobeclosed(s)) {
|
||||
SOCKET_APP_TYPE sat = get_ioa_socket_app_type(s);
|
||||
if(sat == HTTPS_CLIENT_SOCKET) {
|
||||
ioa_network_buffer_handle nbh_http = ioa_network_buffer_allocate(s->e);
|
||||
size_t len_http = ioa_network_buffer_get_size(nbh_http);
|
||||
u08bits *data = ioa_network_buffer_data(nbh_http);
|
||||
char data_http[1025];
|
||||
char content_http[1025];
|
||||
const char* title = "HTTPS TURN Server";
|
||||
snprintf(content_http,sizeof(content_http)-1,"<!DOCTYPE html>\r\n<html>\r\n <head>\r\n <title>%s</title>\r\n </head>\r\n <body>\r\n %s\r\n </body>\r\n</html>\r\n",title,title);
|
||||
snprintf(data_http,sizeof(data_http)-1,"HTTP/1.1 200 OK\r\nServer: %s\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: %d\r\n\r\n%s",TURN_SOFTWARE,(int)strlen(content_http),content_http);
|
||||
len_http = strlen(data_http);
|
||||
ns_bcopy(data_http,data,len_http);
|
||||
ioa_network_buffer_set_size(nbh_http,len_http);
|
||||
send_data_from_ioa_socket_nbh(s, NULL, nbh_http, TTL_IGNORE, TOS_IGNORE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_https(ioa_socket_handle s, ioa_network_buffer_handle nbh) {
|
||||
//TODO
|
||||
UNUSED_ARG(nbh);
|
||||
write_https_echo(s);
|
||||
}
|
||||
|
||||
static void https_input_handler(ioa_socket_handle s, int event_type, ioa_net_data *data, void *arg, int can_resume) {
|
||||
|
||||
UNUSED_ARG(arg);
|
||||
UNUSED_ARG(s);
|
||||
UNUSED_ARG(event_type);
|
||||
UNUSED_ARG(can_resume);
|
||||
|
||||
handle_https(s,data->nbh);
|
||||
|
||||
ioa_network_buffer_delete(cliserver.e, data->nbh);
|
||||
data->nbh = NULL;
|
||||
}
|
||||
|
||||
void https_cli_server_receive_message(struct bufferevent *bev, void *ptr)
|
||||
{
|
||||
UNUSED_ARG(ptr);
|
||||
|
||||
ioa_socket_handle s= NULL;
|
||||
int n = 0;
|
||||
struct evbuffer *input = bufferevent_get_input(bev);
|
||||
|
||||
while ((n = evbuffer_remove(input, &s, sizeof(s))) > 0) {
|
||||
if (n != sizeof(s)) {
|
||||
fprintf(stderr,"%s: Weird HTTPS CLI buffer error: size=%d\n",__FUNCTION__,n);
|
||||
continue;
|
||||
}
|
||||
|
||||
register_callback_on_ioa_socket(cliserver.e, s, IOA_EV_READ, https_input_handler, NULL, 0);
|
||||
|
||||
handle_https(s,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void send_https_socket(ioa_socket_handle s) {
|
||||
struct evbuffer *output = bufferevent_get_output(cliserver.https_out_buf);
|
||||
if(output) {
|
||||
evbuffer_add(output,&s,sizeof(s));
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
@ -54,10 +54,13 @@ extern "C" {
|
||||
struct cli_server {
|
||||
evutil_socket_t listen_fd;
|
||||
struct event_base* event_base;
|
||||
ioa_engine_handle e;
|
||||
int verbose;
|
||||
struct evconnlistener *l;
|
||||
struct bufferevent *in_buf;
|
||||
struct bufferevent *out_buf;
|
||||
struct bufferevent *https_in_buf;
|
||||
struct bufferevent *https_out_buf;
|
||||
ur_map *sessions;
|
||||
pthread_t thr;
|
||||
};
|
||||
@ -86,8 +89,10 @@ extern int cli_max_output_sessions;
|
||||
void setup_cli_thread(void);
|
||||
|
||||
void cli_server_receive_message(struct bufferevent *bev, void *ptr);
|
||||
void https_cli_server_receive_message(struct bufferevent *bev, void *ptr);
|
||||
|
||||
int send_turn_session_info(struct turn_session_info* tsi);
|
||||
void send_https_socket(ioa_socket_handle s);
|
||||
|
||||
////////////////////////////////////////////
|
||||
|
||||
|
||||
@ -278,8 +278,7 @@ int get_default_protocol_port(const char* scheme, size_t slen);
|
||||
|
||||
///////////// HTTP ////////////////////
|
||||
|
||||
void write_http_echo(ioa_socket_handle s);
|
||||
void handle_https(ioa_socket_handle s, ioa_network_buffer_handle nbh);
|
||||
void handle_http(ioa_socket_handle s);
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
|
||||
@ -4442,12 +4442,11 @@ static int read_client_connection(turn_turnserver *server,
|
||||
if(sat == HTTP_CLIENT_SOCKET) {
|
||||
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: HTTP connection input: %s\n", __FUNCTION__, (char*)ioa_network_buffer_data(in_buffer->nbh));
|
||||
write_http_echo(ss->client_socket);
|
||||
handle_http(ss->client_socket);
|
||||
|
||||
} else if(sat == HTTPS_CLIENT_SOCKET) {
|
||||
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: HTTPS connection input: %s\n", __FUNCTION__, (char*)ioa_network_buffer_data(in_buffer->nbh));
|
||||
handle_https(ss->client_socket,in_buffer->nbh);
|
||||
//???
|
||||
|
||||
} else if (stun_is_channel_message_str(ioa_network_buffer_data(in_buffer->nbh),
|
||||
&blen,
|
||||
@ -4542,11 +4541,16 @@ static int read_client_connection(turn_turnserver *server,
|
||||
proto = "HTTPS";
|
||||
set_ioa_socket_app_type(ss->client_socket,HTTPS_CLIENT_SOCKET);
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: %s (%s %s) request: %s\n", __FUNCTION__, proto, get_ioa_socket_cipher(ss->client_socket), get_ioa_socket_ssl_method(ss->client_socket), (char*)ioa_network_buffer_data(in_buffer->nbh));
|
||||
handle_https(ss->client_socket,in_buffer->nbh);
|
||||
if(server->send_https_socket) {
|
||||
ioa_socket_handle new_s = detach_ioa_socket(ss->client_socket);
|
||||
if(new_s) {
|
||||
server->send_https_socket(new_s);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set_ioa_socket_app_type(ss->client_socket,HTTP_CLIENT_SOCKET);
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "%s: %s request: %s\n", __FUNCTION__, proto, (char*)ioa_network_buffer_data(in_buffer->nbh));
|
||||
write_http_echo(ss->client_socket);
|
||||
handle_http(ss->client_socket);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -4802,6 +4806,7 @@ void init_turn_server(turn_turnserver* server,
|
||||
send_socket_to_relay_cb send_socket_to_relay,
|
||||
vintp secure_stun, SHATYPE shatype, vintp mobility, int server_relay,
|
||||
send_turn_session_info_cb send_turn_session_info,
|
||||
send_https_socket_cb send_https_socket,
|
||||
allocate_bps_cb allocate_bps_func,
|
||||
int oauth, const char* oauth_server_name) {
|
||||
|
||||
@ -4827,6 +4832,7 @@ void init_turn_server(turn_turnserver* server,
|
||||
server->mobility = mobility;
|
||||
server->server_relay = server_relay;
|
||||
server->send_turn_session_info = send_turn_session_info;
|
||||
server->send_https_socket = send_https_socket;
|
||||
server->oauth = oauth;
|
||||
if(oauth)
|
||||
server->oauth_server_name = oauth_server_name;
|
||||
|
||||
@ -96,6 +96,7 @@ typedef int (*check_new_allocation_quota_cb)(u08bits *username, int oauth, u08bi
|
||||
typedef void (*release_allocation_quota_cb)(u08bits *username, int oauth, u08bits *realm);
|
||||
typedef int (*send_socket_to_relay_cb)(turnserver_id id, u64bits cid, stun_tid *tid, ioa_socket_handle s, int message_integrity, MESSAGE_TO_RELAY_TYPE rmt, ioa_net_data *nd, int can_resume);
|
||||
typedef int (*send_turn_session_info_cb)(struct turn_session_info *tsi);
|
||||
typedef void (*send_https_socket_cb)(ioa_socket_handle s);
|
||||
|
||||
typedef band_limit_t (*allocate_bps_cb)(band_limit_t bps, int positive);
|
||||
|
||||
@ -131,6 +132,7 @@ struct _turn_turnserver {
|
||||
vintp no_loopback_peers;
|
||||
vintp no_multicast_peers;
|
||||
send_turn_session_info_cb send_turn_session_info;
|
||||
send_https_socket_cb send_https_socket;
|
||||
|
||||
/* RFC 6062 ==>> */
|
||||
vintp no_udp_relay;
|
||||
@ -199,6 +201,7 @@ void init_turn_server(turn_turnserver* server,
|
||||
vintp mobility,
|
||||
int server_relay,
|
||||
send_turn_session_info_cb send_turn_session_info,
|
||||
send_https_socket_cb send_https_socket,
|
||||
allocate_bps_cb allocate_bps_func,
|
||||
int oauth,
|
||||
const char* oauth_server_name);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user