[asterisk-commits] dlee: branch dlee/ari-url-shuffle r391642 - in /team/dlee/ari-url-shuffle: re...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 13 08:29:42 CDT 2013


Author: dlee
Date: Thu Jun 13 08:29:40 2013
New Revision: 391642

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391642
Log:
Attach the subprotocol to the websocket

Modified:
    team/dlee/ari-url-shuffle/res/res_stasis_http_asterisk.c
    team/dlee/ari-url-shuffle/res/res_stasis_http_bridges.c
    team/dlee/ari-url-shuffle/res/res_stasis_http_channels.c
    team/dlee/ari-url-shuffle/res/res_stasis_http_endpoints.c
    team/dlee/ari-url-shuffle/res/res_stasis_http_events.c
    team/dlee/ari-url-shuffle/res/res_stasis_http_playback.c
    team/dlee/ari-url-shuffle/res/res_stasis_http_recordings.c
    team/dlee/ari-url-shuffle/res/res_stasis_http_sounds.c
    team/dlee/ari-url-shuffle/rest-api-templates/res_stasis_http_resource.c.mustache
    team/dlee/ari-url-shuffle/rest-api-templates/rest_handler.mustache
    team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py
    team/dlee/ari-url-shuffle/rest-api/api-docs/events.json

Modified: team/dlee/ari-url-shuffle/res/res_stasis_http_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/res/res_stasis_http_asterisk.c?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_asterisk.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_asterisk.c Thu Jun 13 08:29:40 2013
@@ -88,8 +88,10 @@
 
 static int load_module(void)
 {
+	int r = 0;
 	stasis_app_ref();
-	return stasis_http_add_handler(&asterisk);
+	r |= stasis_http_add_handler(&asterisk);
+	return r;
 }
 
 static int unload_module(void)

Modified: team/dlee/ari-url-shuffle/res/res_stasis_http_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/res/res_stasis_http_bridges.c?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_bridges.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_bridges.c Thu Jun 13 08:29:40 2013
@@ -276,8 +276,10 @@
 
 static int load_module(void)
 {
+	int r = 0;
 	stasis_app_ref();
-	return stasis_http_add_handler(&bridges);
+	r |= stasis_http_add_handler(&bridges);
+	return r;
 }
 
 static int unload_module(void)

Modified: team/dlee/ari-url-shuffle/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/res/res_stasis_http_channels.c?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_channels.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_channels.c Thu Jun 13 08:29:40 2013
@@ -510,8 +510,10 @@
 
 static int load_module(void)
 {
+	int r = 0;
 	stasis_app_ref();
-	return stasis_http_add_handler(&channels);
+	r |= stasis_http_add_handler(&channels);
+	return r;
 }
 
 static int unload_module(void)

Modified: team/dlee/ari-url-shuffle/res/res_stasis_http_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/res/res_stasis_http_endpoints.c?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_endpoints.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_endpoints.c Thu Jun 13 08:29:40 2013
@@ -139,8 +139,10 @@
 
 static int load_module(void)
 {
+	int r = 0;
 	stasis_app_ref();
-	return stasis_http_add_handler(&endpoints);
+	r |= stasis_http_add_handler(&endpoints);
+	return r;
 }
 
 static int unload_module(void)

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=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_events.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_events.c Thu Jun 13 08:29:40 2013
@@ -45,34 +45,15 @@
 #include "asterisk/stasis_app.h"
 #include "stasis_http/resource_events.h"
 
-/*!
- * \brief Parameter parsing callback for /events.
- * \param get_params GET parameters in the HTTP request.
- * \param path_vars Path variables extracted from the request.
- * \param headers HTTP headers.
- * \param[out] response Response to the HTTP request.
- */
-static void event_websocket_cb(
-    struct ast_variable *get_params, struct ast_variable *path_vars,
-    struct ast_variable *headers, struct stasis_http_response *response)
+static void event_websocket_ws_cb(struct ast_websocket *ws_session,
+	struct ast_variable *parameters, struct ast_variable *headers)
 {
-	struct ast_event_websocket_args args = {};
-	struct ast_variable *i;
-
-	for (i = get_params; i; i = i->next) {
-		if (strcmp(i->name, "app") == 0) {
-			args.app = (i->value);
-		} else
-		{}
-	}
-	stasis_http_event_websocket(headers, &args, response);
 }
 
 /*! \brief REST handler for /api-docs/events.{format} */
 static struct stasis_rest_handlers events = {
 	.path_segment = "events",
 	.callbacks = {
-		[AST_HTTP_GET] = event_websocket_cb,
 	},
 	.num_children = 0,
 	.children = {  }
@@ -80,12 +61,16 @@
 
 static int load_module(void)
 {
+	int r = 0;
 	events.ws_server = ast_websocket_server_create();
 	if (!events.ws_server) {
 		return AST_MODULE_LOAD_FAILURE;
-        }
+	}
+	r |= ast_websocket_server_add_protocol(events.ws_server,
+		"ari", event_websocket_ws_cb);
 	stasis_app_ref();
-	return stasis_http_add_handler(&events);
+	r |= stasis_http_add_handler(&events);
+	return r;
 }
 
 static int unload_module(void)

Modified: team/dlee/ari-url-shuffle/res/res_stasis_http_playback.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/res/res_stasis_http_playback.c?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_playback.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_playback.c Thu Jun 13 08:29:40 2013
@@ -149,8 +149,10 @@
 
 static int load_module(void)
 {
+	int r = 0;
 	stasis_app_ref();
-	return stasis_http_add_handler(&playback);
+	r |= stasis_http_add_handler(&playback);
+	return r;
 }
 
 static int unload_module(void)

Modified: team/dlee/ari-url-shuffle/res/res_stasis_http_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/res/res_stasis_http_recordings.c?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_recordings.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_recordings.c Thu Jun 13 08:29:40 2013
@@ -383,8 +383,10 @@
 
 static int load_module(void)
 {
+	int r = 0;
 	stasis_app_ref();
-	return stasis_http_add_handler(&recordings);
+	r |= stasis_http_add_handler(&recordings);
+	return r;
 }
 
 static int unload_module(void)

Modified: team/dlee/ari-url-shuffle/res/res_stasis_http_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/res/res_stasis_http_sounds.c?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/res/res_stasis_http_sounds.c (original)
+++ team/dlee/ari-url-shuffle/res/res_stasis_http_sounds.c Thu Jun 13 08:29:40 2013
@@ -115,8 +115,10 @@
 
 static int load_module(void)
 {
+	int r = 0;
 	stasis_app_ref();
-	return stasis_http_add_handler(&sounds);
+	r |= stasis_http_add_handler(&sounds);
+	return r;
 }
 
 static int unload_module(void)

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=391642&r1=391641&r2=391642
==============================================================================
--- 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 Thu Jun 13 08:29:40 2013
@@ -52,6 +52,7 @@
 
 {{#apis}}
 {{#operations}}
+{{#is_req}}
 /*!
  * \brief Parameter parsing callback for {{path}}.
  * \param get_params GET parameters in the HTTP request.
@@ -90,6 +91,13 @@
 {{/has_parameters}}
 	stasis_http_{{c_nickname}}(headers, &args, response);
 }
+{{/is_req}}
+{{#is_websocket}}
+static void {{c_nickname}}_ws_cb(struct ast_websocket *ws_session,
+	struct ast_variable *parameters, struct ast_variable *headers)
+{
+}
+{{/is_websocket}}
 {{/operations}}
 {{/apis}}
 
@@ -100,18 +108,22 @@
 
 static int load_module(void)
 {
+	int r = 0;
 {{#apis}}
 {{#operations}}
 {{#is_websocket}}
 	{{full_name}}.ws_server = ast_websocket_server_create();
 	if (!{{full_name}}.ws_server) {
 		return AST_MODULE_LOAD_FAILURE;
-        }
+	}
+	r |= ast_websocket_server_add_protocol({{full_name}}.ws_server,
+		"{{websocket_protocol}}", {{c_nickname}}_ws_cb);
 {{/is_websocket}}
 {{/operations}}
 {{/apis}}
 	stasis_app_ref();
-	return stasis_http_add_handler(&{{root_full_name}});
+	r |= stasis_http_add_handler(&{{root_full_name}});
+	return r;
 }
 
 static int unload_module(void)

Modified: team/dlee/ari-url-shuffle/rest-api-templates/rest_handler.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/rest-api-templates/rest_handler.mustache?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/rest-api-templates/rest_handler.mustache (original)
+++ team/dlee/ari-url-shuffle/rest-api-templates/rest_handler.mustache Thu Jun 13 08:29:40 2013
@@ -1,4 +1,4 @@
-{{! -*- C -*-
+{{!
  * Asterisk -- An open source telephony toolkit.
  *
  * Copyright (C) 2013, Digium, Inc.
@@ -30,7 +30,9 @@
 {{/is_wildcard}}
 	.callbacks = {
 {{#operations}}
+{{#is_req}}
 		[{{c_http_method}}] = {{c_nickname}}_cb,
+{{/is_req}}
 {{/operations}}
 	},
 	.num_children = {{num_children}},

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=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py (original)
+++ team/dlee/ari-url-shuffle/rest-api-templates/swagger_model.py Thu Jun 13 08:29:40 2013
@@ -221,9 +221,11 @@
         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")
+        if self.is_websocket:
+            self.websocket_protocol = op_json.get('websocketProtocol')
+            if self.http_method != 'GET':
+                raise ValueError(
+                    "upgrade: websocket is only valid on GET operations")
 
         params_json = op_json.get('parameters') or []
         self.parameters = [

Modified: team/dlee/ari-url-shuffle/rest-api/api-docs/events.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-url-shuffle/rest-api/api-docs/events.json?view=diff&rev=391642&r1=391641&r2=391642
==============================================================================
--- team/dlee/ari-url-shuffle/rest-api/api-docs/events.json (original)
+++ team/dlee/ari-url-shuffle/rest-api/api-docs/events.json Thu Jun 13 08:29:40 2013
@@ -14,6 +14,7 @@
 				{
 					"httpMethod": "GET",
 					"upgrade": "websocket",
+					"websocketProtocol": "ari",
 					"summary": "WebSocket connection for events.",
 					"nickname": "eventWebsocket",
 					"responseClass": "Event",




More information about the asterisk-commits mailing list