From 9c696e665fde0e94b6d6aac20cf40bcb35ac94e6 Mon Sep 17 00:00:00 2001 From: "David M. Lee" Date: Thu, 18 Apr 2013 17:30:28 +0000 Subject: Allow WebSocket connections on more URL's This patch adds the concept of ast_websocket_server to res_http_websocket, allowing WebSocket connections on URL's more more than /ws. The existing funcitons for managing the WebSocket subprotocols on /ws still work, so this patch should be completely backward compatible. (closes issue ASTERISK-21279) Review: https://reviewboard.asterisk.org/r/2453/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@386020 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/http_websocket.h | 54 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/asterisk/http_websocket.h b/include/asterisk/http_websocket.h index d59bc25cd..82c7ad8b6 100644 --- a/include/asterisk/http_websocket.h +++ b/include/asterisk/http_websocket.h @@ -19,6 +19,7 @@ #ifndef _ASTERISK_HTTP_WEBSOCKET_H #define _ASTERISK_HTTP_WEBSOCKET_H +#include "asterisk/http.h" #include "asterisk/optional_api.h" /*! @@ -40,7 +41,13 @@ enum ast_websocket_opcode { }; /*! - * \brief Opaque structure for WebSocket sessions + * \brief Opaque structure for WebSocket server. + * \since 12 + */ +struct ast_websocket_server; + +/*! + * \brief Opaque structure for WebSocket sessions. */ struct ast_websocket; @@ -58,7 +65,24 @@ struct ast_websocket; typedef void (*ast_websocket_callback)(struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers); /*! - * \brief Add a sub-protocol handler to the server + * \brief Creates a \ref websocket_server + * + * \retval New \ref websocket_server instance + * \retval \c NULL on error + * \since 12 + */ +struct ast_websocket_server *ast_websocket_server_create(void); + +/*! + * \brief Callback suitable for use with a \ref ast_http_uri. + * + * Set the data field of the ast_http_uri to \ref ast_websocket_server. + * \since 12 + */ +int ast_websocket_uri_cb(struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_vars, struct ast_variable *headers); + +/*! + * \brief Add a sub-protocol handler to the default /ws server * * \param name Name of the sub-protocol to register * \param callback Callback called when a new connection requesting the sub-protocol is established @@ -69,7 +93,7 @@ typedef void (*ast_websocket_callback)(struct ast_websocket *session, struct ast AST_OPTIONAL_API(int, ast_websocket_add_protocol, (const char *name, ast_websocket_callback callback), {return -1;}); /*! - * \brief Remove a sub-protocol handler from the server + * \brief Remove a sub-protocol handler from the default /ws server. * * \param name Name of the sub-protocol to unregister * \param callback Callback that was previously registered with the sub-protocol @@ -79,6 +103,30 @@ AST_OPTIONAL_API(int, ast_websocket_add_protocol, (const char *name, ast_websock */ AST_OPTIONAL_API(int, ast_websocket_remove_protocol, (const char *name, ast_websocket_callback callback), {return -1;}); +/*! + * \brief Add a sub-protocol handler to the given server. + * + * \param name Name of the sub-protocol to register + * \param callback Callback called when a new connection requesting the sub-protocol is established + * + * \retval 0 success + * \retval -1 if sub-protocol handler could not be registered + * \since 12 + */ +AST_OPTIONAL_API(int, ast_websocket_server_add_protocol, (struct ast_websocket_server *server, const char *name, ast_websocket_callback callback), {return -1;}); + +/*! + * \brief Remove a sub-protocol handler from the given server. + * + * \param name Name of the sub-protocol to unregister + * \param callback Callback that was previously registered with the sub-protocol + * + * \retval 0 success + * \retval -1 if sub-protocol was not found or if callback did not match + * \since 12 + */ +AST_OPTIONAL_API(int, ast_websocket_server_remove_protocol, (struct ast_websocket_server *server, const char *name, ast_websocket_callback callback), {return -1;}); + /*! * \brief Read a WebSocket frame and handle it * -- cgit v1.2.3