From edcec9fa9086599d56bffe7fdb2c1f05ae7a3ad8 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sun, 2 Jun 2019 15:45:12 +0200 Subject: File backend peer query --- websocksy.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'websocksy.c') diff --git a/websocksy.c b/websocksy.c index c635ca7..7727ef0 100644 --- a/websocksy.c +++ b/websocksy.c @@ -125,12 +125,23 @@ static peer_transport client_detect_transport(char* host){ return peer_tcp_client; } +static char* client_detect_port(char* host){ + size_t u; + + for(u = 0; host[u]; u++){ + if(host[u] == ':'){ + host[u] = 0; + return strdup(host + u + 1); + } + } + + return NULL; +} + /* Establish peer connection for negotiated websocket */ int client_connect(websocket* ws){ ws->peer = config.backend.query(ws->request_path, ws->protocols, ws->protocol, ws->headers, ws->header, ws); if(!ws->peer.host){ - //TODO check port if network socket - //TODO try to extract port from host if none given //no peer provided return 1; } @@ -145,6 +156,15 @@ int client_connect(websocket* ws){ ws->peer.transport = client_detect_transport(ws->peer.host); } + if((ws->peer.transport == peer_tcp_client || ws->peer.transport == peer_udp_client) + && !ws->peer.port){ + ws->peer.port = client_detect_port(ws->peer.host); + if(!ws->peer.port){ + //no port provided + return 1; + } + } + //TODO connection establishment should be async in the future switch(ws->peer.transport){ case peer_tcp_client: @@ -172,6 +192,10 @@ int client_connect(websocket* ws){ return (ws->peer_fd == -1) ? 1 : 0; } +ws_framing core_framing(char* name){ + return plugin_framing(name); +} + /* Signal handler, attached to SIGINT */ static void signal_handler(int signum){ shutdown_requested = 1; -- cgit v1.2.3