|
|
|
@ -75,11 +75,14 @@ wfp_impl_client_protocol_on_add_filesystem_finished(
|
|
|
|
|
|
|
|
|
|
if (NULL != result)
|
|
|
|
|
{
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "filesystem added");
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "handshake finished");
|
|
|
|
|
protocol->is_connected = true;
|
|
|
|
|
protocol->provider.connected(protocol->user_data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "add filesystem failed");
|
|
|
|
|
protocol->is_shutdown_requested = true;
|
|
|
|
|
lws_callback_on_writable(protocol->wsi);
|
|
|
|
|
}
|
|
|
|
@ -88,13 +91,15 @@ wfp_impl_client_protocol_on_add_filesystem_finished(
|
|
|
|
|
static void wfp_impl_client_protocol_add_filesystem(
|
|
|
|
|
struct wfp_client_protocol * protocol)
|
|
|
|
|
{
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "begin add filesystem");
|
|
|
|
|
|
|
|
|
|
wfp_jsonrpc_proxy_invoke(
|
|
|
|
|
protocol->proxy,
|
|
|
|
|
&wfp_impl_client_protocol_on_add_filesystem_finished,
|
|
|
|
|
protocol,
|
|
|
|
|
"add_filesystem",
|
|
|
|
|
"s",
|
|
|
|
|
"cprovider");
|
|
|
|
|
protocol->fs_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
@ -108,10 +113,12 @@ wfp_impl_client_protocol_on_authenticate_finished(
|
|
|
|
|
|
|
|
|
|
if (NULL != result)
|
|
|
|
|
{
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "authentication finished");
|
|
|
|
|
wfp_impl_client_protocol_add_filesystem(protocol);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "authentication failed");
|
|
|
|
|
protocol->is_shutdown_requested = true;
|
|
|
|
|
lws_callback_on_writable(protocol->wsi);
|
|
|
|
|
}
|
|
|
|
@ -120,6 +127,8 @@ wfp_impl_client_protocol_on_authenticate_finished(
|
|
|
|
|
static void wfp_impl_client_protocol_authenticate(
|
|
|
|
|
struct wfp_client_protocol * protocol)
|
|
|
|
|
{
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "begin authenticate");
|
|
|
|
|
|
|
|
|
|
struct wfp_credentials credentials;
|
|
|
|
|
wfp_impl_credentials_init(&credentials);
|
|
|
|
|
|
|
|
|
@ -141,12 +150,15 @@ static void wfp_impl_client_protocol_authenticate(
|
|
|
|
|
static void wfp_impl_client_protocol_handshake(
|
|
|
|
|
struct wfp_client_protocol * protocol)
|
|
|
|
|
{
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "begin connection handshake");
|
|
|
|
|
|
|
|
|
|
if (wfp_impl_provider_is_authentication_enabled(&protocol->provider))
|
|
|
|
|
{
|
|
|
|
|
wfp_impl_client_protocol_authenticate(protocol);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "skip authentication");
|
|
|
|
|
wfp_impl_client_protocol_add_filesystem(protocol);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -169,18 +181,22 @@ static int wfp_impl_client_protocol_callback(
|
|
|
|
|
switch (reason)
|
|
|
|
|
{
|
|
|
|
|
case LWS_CALLBACK_CLIENT_ESTABLISHED:
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "connection established");
|
|
|
|
|
wfp_impl_client_protocol_handshake(protocol);
|
|
|
|
|
break;
|
|
|
|
|
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "connect error");
|
|
|
|
|
protocol->is_connected = false;
|
|
|
|
|
protocol->provider.disconnected(protocol->user_data);
|
|
|
|
|
break;
|
|
|
|
|
case LWS_CALLBACK_CLIENT_CLOSED:
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "connection closed");
|
|
|
|
|
protocol->is_connected = false;
|
|
|
|
|
protocol->provider.disconnected(protocol->user_data);
|
|
|
|
|
protocol->wsi = NULL;
|
|
|
|
|
break;
|
|
|
|
|
case LWS_CALLBACK_CLIENT_RECEIVE:
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "received: \"%.*s\"", len, in);
|
|
|
|
|
wfp_impl_client_protocol_process(protocol, in, len);
|
|
|
|
|
break;
|
|
|
|
|
case LWS_CALLBACK_SERVER_WRITEABLE:
|
|
|
|
@ -194,8 +210,10 @@ static int wfp_impl_client_protocol_callback(
|
|
|
|
|
}
|
|
|
|
|
else if (!wfp_slist_empty(&protocol->messages))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
struct wfp_slist_item * item = wfp_slist_remove_first(&protocol->messages);
|
|
|
|
|
struct wfp_message * message = wfp_container_of(item, struct wfp_message, item);
|
|
|
|
|
protocol->provider.log(protocol->user_data, 0, "send: \"%.*s\"", message->length, message->data);
|
|
|
|
|
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
|
|
|
|
|
wfp_message_dispose(message);
|
|
|
|
|
|
|
|
|
@ -229,6 +247,7 @@ static void wfp_impl_client_protocol_send(
|
|
|
|
|
void wfp_impl_client_protocol_init(
|
|
|
|
|
struct wfp_client_protocol * protocol,
|
|
|
|
|
struct wfp_provider const * provider,
|
|
|
|
|
char const * fs_name,
|
|
|
|
|
void * user_data)
|
|
|
|
|
{
|
|
|
|
|
protocol->is_connected = false;
|
|
|
|
@ -243,6 +262,7 @@ void wfp_impl_client_protocol_init(
|
|
|
|
|
protocol->timer_manager = wfp_timer_manager_create();
|
|
|
|
|
protocol->proxy = wfp_jsonrpc_proxy_create(protocol->timer_manager, WFP_DEFAULT_TIMEOUT, &wfp_impl_client_protocol_send, protocol);
|
|
|
|
|
|
|
|
|
|
protocol->fs_name = strdup(fs_name);
|
|
|
|
|
protocol->user_data = user_data;
|
|
|
|
|
wfp_impl_provider_init_from_prototype(&protocol->provider, provider);
|
|
|
|
|
}
|
|
|
|
@ -253,13 +273,14 @@ void wfp_impl_client_protocol_cleanup(
|
|
|
|
|
wfp_jsonrpc_proxy_dispose(protocol->proxy);
|
|
|
|
|
wfp_timer_manager_dispose(protocol->timer_manager);
|
|
|
|
|
wfp_message_queue_cleanup(&protocol->messages);
|
|
|
|
|
free(protocol->fs_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wfp_client_protocol * wfp_impl_client_protocol_create(
|
|
|
|
|
struct wfp_client_config const * config)
|
|
|
|
|
{
|
|
|
|
|
struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol));
|
|
|
|
|
wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data);
|
|
|
|
|
wfp_impl_client_protocol_init(protocol, &config->provider, config->fs_name, config->user_data);
|
|
|
|
|
|
|
|
|
|
return protocol;
|
|
|
|
|
}
|
|
|
|
|