From 35d3ec45c8ce52e34709448a49d491f9d1ef7ba0 Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Sat, 10 Dec 2016 14:34:29 +0100 Subject: [PATCH] Moved set_websocket_handler to own file --- Makefile | 1 + src/httplib_set_websocket_handler.c | 43 +++++++++++++++++++++++++++++ src/libhttp.c | 9 +----- 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 src/httplib_set_websocket_handler.c diff --git a/Makefile b/Makefile index 4136dca4..4840e04e 100644 --- a/Makefile +++ b/Makefile @@ -78,6 +78,7 @@ LIB_SOURCES = src/libhttp.c \ src/httplib_set_sock_timeout.c \ src/httplib_set_tcp_nodelay.c \ src/httplib_set_uid_option.c \ + src/httplib_set_websocket_handler.c \ src/httplib_ssl_error.c \ src/httplib_ssl_get_client_cert_info.c \ src/httplib_ssl_get_protocol.c \ diff --git a/src/httplib_set_websocket_handler.c b/src/httplib_set_websocket_handler.c new file mode 100644 index 00000000..b9f89c50 --- /dev/null +++ b/src/httplib_set_websocket_handler.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016 Lammert Bies + * Copyright (c) 2013-2016 the Civetweb developers + * Copyright (c) 2004-2013 Sergey Lyubka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + + +#include "libhttp-private.h" + + + +/* + * void mg_set_websocket_handler(); + * + * the function mg_set_websocket_handler() sets callback functions for the + * processing of events from a websocket. + */ + +void mg_set_websocket_handler( struct mg_context *ctx, const char *uri, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata ) { + + int is_delete_request = (connect_handler == NULL) && (ready_handler == NULL) && (data_handler == NULL) && (close_handler == NULL); + XX_httplib_set_handler_type(ctx, uri, WEBSOCKET_HANDLER, is_delete_request, NULL, connect_handler, ready_handler, data_handler, close_handler, NULL, cbdata); + +} /* mg_set_websocket_handler */ diff --git a/src/libhttp.c b/src/libhttp.c index e9e34382..9075c4dc 100644 --- a/src/libhttp.c +++ b/src/libhttp.c @@ -7428,12 +7428,5 @@ void XX_httplib_set_handler_type( struct mg_context *ctx, const char *uri, int h void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata) { XX_httplib_set_handler_type(ctx, uri, REQUEST_HANDLER, handler == NULL, handler, NULL, NULL, NULL, NULL, NULL, cbdata); -} - -void mg_set_websocket_handler( struct mg_context *ctx, const char *uri, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata ) { - - int is_delete_request = (connect_handler == NULL) && (ready_handler == NULL) && (data_handler == NULL) && (close_handler == NULL); - XX_httplib_set_handler_type(ctx, uri, WEBSOCKET_HANDLER, is_delete_request, NULL, connect_handler, ready_handler, data_handler, close_handler, NULL, cbdata); - -} /* mg_set_websocket_handler */ +} /* mg_set_request_handler */