[asterisk-commits] dlee: branch dlee/ari-url-shuffle r391591 - in /team/dlee/ari-url-shuffle: in...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jun 12 20:40:12 CDT 2013
Author: dlee
Date: Wed Jun 12 20:40:10 2013
New Revision: 391591
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391591
Log:
Attach a WebSocket server to each WebSocket endpoint
Modified:
team/dlee/ari-url-shuffle/include/asterisk/stasis_http.h
team/dlee/ari-url-shuffle/res/res_stasis_http_events.c
team/dlee/ari-url-shuffle/rest-api-templates/asterisk_processor.py
team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_http_resource.c.mustache
team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py
Modified: team/dlee/ari-url-shuffle/include/asterisk/stasis_http.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/include/asterisk/stasis_http.h?view=diff&rev=391591&r1=391590&r2=391591
==============================================================================
--- team/dlee/ari-url-shuffle/include/asterisk/stasis_http.h (original)
+++ team/dlee/ari-url-shuffle/include/asterisk/stasis_http.h Wed Jun 12 20:40:10 2013
@@ -53,13 +53,17 @@
struct stasis_rest_handlers {
/*! Path segement to handle */
const char *path_segment;
- /*! If true (non-zero), path_segment is a wildcard, and will match all values.
+ /*! If true (non-zero), path_segment is a wildcard, and will match all
+ * values.
*
- * Value of the segement will be passed into the \a path_vars parameter of the callback.
+ * Value of the segement will be passed into the \a path_vars parameter
+ * of the callback.
*/
int is_wildcard;
/*! Callbacks for all handled HTTP methods. */
stasis_rest_callback callbacks[AST_HTTP_MAX_METHOD];
+ /*! WebSocket server for handling WebSocket upgrades. */
+ struct ast_websocket_server *ws_server;
/*! Number of children in the children array */
size_t num_children;
/*! Handlers for sub-paths */
Modified: team/dlee/ari-url-shuffle/res/res_stasis_http_events.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/res/res_stasis_http_events.c?view=diff&rev=391591&r1=391590&r2=391591
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_events.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_events.c Wed Jun 12 20:40:10 2013
@@ -80,6 +80,10 @@
static int load_module(void)
{
+ events.ws_server = ast_websocket_server_create();
+ if (!events.ws_server) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
stasis_app_ref();
return stasis_http_add_handler(&events);
}
@@ -87,6 +91,8 @@
static int unload_module(void)
{
stasis_http_remove_handler(&events);
+ ao2_cleanup(events.ws_server);
+ events.ws_server = NULL;
stasis_app_unref();
return 0;
}
Modified: team/dlee/ari-url-shuffle/rest-api-templates/asterisk_processor.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/rest-api-templates/asterisk_processor.py?view=diff&rev=391591&r1=391590&r2=391591
==============================================================================
--- team/dlee/ari-url-shuffle/rest-api-templates/asterisk_processor.py (original)
+++ team/dlee/ari-url-shuffle/rest-api-templates/asterisk_processor.py Wed Jun 12 20:40:10 2013
@@ -144,6 +144,7 @@
segment = resource_api.root_path.get_child(api.path.split('/'))
for operation in api.operations:
segment.operations.append(operation)
+ api.full_name = segment.full_name
resource_api.api_declaration.has_events = False
for model in resource_api.api_declaration.models:
if model.id == "Event":
Modified: team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_http_resource.c.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_http_resource.c.mustache?view=diff&rev=391591&r1=391590&r2=391591
==============================================================================
--- team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_http_resource.c.mustache (original)
+++ team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_http_resource.c.mustache Wed Jun 12 20:40:10 2013
@@ -100,6 +100,16 @@
static int load_module(void)
{
+{{#apis}}
+{{#operations}}
+{{#is_websocket}}
+ {{full_name}}.ws_server = ast_websocket_server_create();
+ if (!{{full_name}}.ws_server) {
+ return AST_MODULE_LOAD_FAILURE;
+ }
+{{/is_websocket}}
+{{/operations}}
+{{/apis}}
stasis_app_ref();
return stasis_http_add_handler(&{{root_full_name}});
}
@@ -107,6 +117,14 @@
static int unload_module(void)
{
stasis_http_remove_handler(&{{root_full_name}});
+{{#apis}}
+{{#operations}}
+{{#is_websocket}}
+ ao2_cleanup({{full_name}}.ws_server);
+ {{full_name}}.ws_server = NULL;
+{{/is_websocket}}
+{{/operations}}
+{{/apis}}
stasis_app_unref();
return 0;
}
Modified: team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py?view=diff&rev=391591&r1=391590&r2=391591
==============================================================================
--- team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py (original)
+++ team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py Wed Jun 12 20:40:10 2013
@@ -218,6 +218,13 @@
self.http_method = op_json.get('httpMethod')
self.nickname = op_json.get('nickname')
self.response_class = op_json.get('responseClass')
+ self.is_websocket = op_json.get('upgrade') == 'websocket'
+ self.is_req = not self.is_websocket
+
+ if self.is_websocket and self.http_method != 'GET':
+ raise ValueError(
+ "upgrade: websocket is only valid on GET operations")
+
params_json = op_json.get('parameters') or []
self.parameters = [
Parameter().load(j, processor, context) for j in params_json]
More information about the asterisk-commits
mailing list