From 03b8ee473a90a3ab6b7506bfffec27f83efed914 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 23 Feb 2019 16:20:30 +0100 Subject: [PATCH] client now connects (but still does not communicate) --- lib/wsfsp/client.c | 27 +++++++++++++++++++++++---- lib/wsfsp/client_protocol.c | 18 +++++++++++++++++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/wsfsp/client.c b/lib/wsfsp/client.c index 0a12f95..297ce72 100644 --- a/lib/wsfsp/client.c +++ b/lib/wsfsp/client.c @@ -8,7 +8,9 @@ #include "wsfsp/provider.h" #include "wsfsp/client_protocol_intern.h" +#include "wsfsp/url.h" +#define WSFSP_PROTOCOL ("fs") #define WSFSP_DISABLE_LWS_LOG 0 #define WSFSP_CLIENT_PROTOCOL_COUNT 2 #define WSFSP_CLIENT_TIMEOUT (1 * 1000) @@ -21,6 +23,7 @@ struct wsfsp_client struct lws_context_creation_info info; struct lws_protocols protocols[WSFSP_CLIENT_PROTOCOL_COUNT]; struct lws_context * context; + struct lws * wsi; }; @@ -64,10 +67,26 @@ void wsfsp_client_connect( struct wsfsp_client * client, char const * url) { - (void) client; - (void) url; - - // ToDo: implement me + struct wsfsp_url url_data; + bool const success = wsfsp_url_init(&url_data, url); + if (success) + { + struct lws_client_connect_info info; + memset(&info, 0, sizeof(struct lws_client_connect_info)); + info.context = client->context; + info.port = url_data.port; + info.address = url_data.host; + info.path = url_data.path; + info.host = info.address; + info.origin = info.address; + info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0; + info.protocol = WSFSP_PROTOCOL; + info.pwsi = &client->wsi; + + lws_client_connect_via_info(&info); + + wsfsp_url_cleanup(&url_data); + } } void wsfsp_client_disconnect( diff --git a/lib/wsfsp/client_protocol.c b/lib/wsfsp/client_protocol.c index 8265cf4..c1ea02d 100644 --- a/lib/wsfsp/client_protocol.c +++ b/lib/wsfsp/client_protocol.c @@ -10,11 +10,27 @@ static int wsfsp_client_protocol_callback( struct lws * WSFS_UNUSED_PARAM(wsi), - enum lws_callback_reasons WSFS_UNUSED_PARAM(reason), + enum lws_callback_reasons reason, void * WSFS_UNUSED_PARAM(user), void * WSFS_UNUSED_PARAM(in), size_t WSFS_UNUSED_PARAM(len)) { + + switch (reason) + { + case LWS_CALLBACK_CLIENT_ESTABLISHED: + puts("established"); + break; + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + puts("error: client could not connect"); + break; + case LWS_CALLBACK_CLIENT_CLOSED: + puts("client closed"); + break; + default: + break; + } + return 0; }