1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

added error handling on authentication failure

This commit is contained in:
Falk Werner 2020-03-01 11:06:09 +01:00
parent af2343c67a
commit f79b9c998a
2 changed files with 27 additions and 16 deletions

View File

@ -73,7 +73,8 @@ wfp_impl_client_protocol_on_authenticate_finished(
json_t const * WF_UNUSED_PARAM(error)) json_t const * WF_UNUSED_PARAM(error))
{ {
struct wfp_client_protocol * protocol = user_data; struct wfp_client_protocol * protocol = user_data;
if (NULL == protocol->wsi) { return; }
if (NULL != result) if (NULL != result)
{ {
protocol->is_connected = true; protocol->is_connected = true;
@ -81,9 +82,9 @@ wfp_impl_client_protocol_on_authenticate_finished(
} }
else else
{ {
// ToDo: handle error protocol->is_shutdown_requested = true;
} lws_callback_on_writable(protocol->wsi);
}
} }
static void wfp_impl_client_protocol_add_filesystem( static void wfp_impl_client_protocol_add_filesystem(
@ -105,6 +106,7 @@ static int wfp_impl_client_protocol_callback(
void * in, void * in,
size_t len) size_t len)
{ {
int result = 0;
struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); struct lws_protocols const * ws_protocol = lws_get_protocol(wsi);
struct wfp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL; struct wfp_client_protocol * protocol = (NULL != ws_protocol) ? ws_protocol->user: NULL;
@ -123,7 +125,8 @@ static int wfp_impl_client_protocol_callback(
break; break;
case LWS_CALLBACK_CLIENT_CLOSED: case LWS_CALLBACK_CLIENT_CLOSED:
protocol->is_connected = false; protocol->is_connected = false;
protocol->provider.disconnected(protocol->user_data); protocol->provider.disconnected(protocol->user_data);
protocol->wsi = NULL;
break; break;
case LWS_CALLBACK_CLIENT_RECEIVE: case LWS_CALLBACK_CLIENT_RECEIVE:
wfp_impl_client_protocol_process(protocol, in, len); wfp_impl_client_protocol_process(protocol, in, len);
@ -131,26 +134,32 @@ static int wfp_impl_client_protocol_callback(
case LWS_CALLBACK_SERVER_WRITEABLE: case LWS_CALLBACK_SERVER_WRITEABLE:
// fall-through // fall-through
case LWS_CALLBACK_CLIENT_WRITEABLE: case LWS_CALLBACK_CLIENT_WRITEABLE:
if ((wsi == protocol->wsi) && (!wf_slist_empty(&protocol->messages))) if (wsi == protocol->wsi)
{ {
struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages); if (protocol->is_shutdown_requested)
struct wf_message * message = wf_container_of(item, struct wf_message, item);
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
wf_message_dispose(message);
if (!wf_slist_empty(&protocol->messages))
{ {
lws_callback_on_writable(wsi); result = 1;
} }
} else if (!wf_slist_empty(&protocol->messages))
{
struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages);
struct wf_message * message = wf_container_of(item, struct wf_message, item);
lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT);
wf_message_dispose(message);
if (!wf_slist_empty(&protocol->messages))
{
lws_callback_on_writable(wsi);
}
}
}
break; break;
default: default:
break; break;
} }
} }
return 0; return result;
} }
static bool wfp_impl_client_protocol_send( static bool wfp_impl_client_protocol_send(
@ -177,6 +186,7 @@ void wfp_impl_client_protocol_init(
void * user_data) void * user_data)
{ {
protocol->is_connected = false; protocol->is_connected = false;
protocol->is_shutdown_requested = false;
wf_slist_init(&protocol->messages); wf_slist_init(&protocol->messages);
protocol->wsi = NULL; protocol->wsi = NULL;

View File

@ -20,6 +20,7 @@ struct wf_timer_manager;
struct wfp_client_protocol struct wfp_client_protocol
{ {
bool is_connected; bool is_connected;
bool is_shutdown_requested;
struct wfp_request request; struct wfp_request request;
struct wfp_provider provider; struct wfp_provider provider;
void * user_data; void * user_data;