[asterisk-commits] dlee: branch dlee/ari-event-remodel2 r392165 - in /team/dlee/ari-event-remode...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jun 18 12:20:50 CDT 2013


Author: dlee
Date: Tue Jun 18 12:20:48 2013
New Revision: 392165

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392165
Log:
WebSocket validation

Modified:
    team/dlee/ari-event-remodel2/include/asterisk/stasis_http.h
    team/dlee/ari-event-remodel2/res/res_stasis_http_events.c
    team/dlee/ari-event-remodel2/res/stasis_http/ari_websockets.c
    team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache

Modified: team/dlee/ari-event-remodel2/include/asterisk/stasis_http.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/include/asterisk/stasis_http.h?view=diff&rev=392165&r1=392164&r2=392165
==============================================================================
--- team/dlee/ari-event-remodel2/include/asterisk/stasis_http.h (original)
+++ team/dlee/ari-event-remodel2/include/asterisk/stasis_http.h Tue Jun 18 12:20:48 2013
@@ -142,11 +142,12 @@
  * \brief Create an ARI WebSocket session.
  *
  * \param ws_session Underlying WebSocket session.
+ * \param validator Function to validate outgoing messages.
  * \return New ARI WebSocket session.
  * \return \c NULL on error.
  */
 struct ari_websocket_session *ari_websocket_session_create(
-	struct ast_websocket *ws_session);
+	struct ast_websocket *ws_session, int (*validator)(struct ast_json *));
 
 /*!
  * \brief Read a message from an ARI WebSocket.

Modified: team/dlee/ari-event-remodel2/res/res_stasis_http_events.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/res_stasis_http_events.c?view=diff&rev=392165&r1=392164&r2=392165
==============================================================================
--- team/dlee/ari-event-remodel2/res/res_stasis_http_events.c (original)
+++ team/dlee/ari-event-remodel2/res/res_stasis_http_events.c Tue Jun 18 12:20:48 2013
@@ -62,7 +62,8 @@
 		} else
 		{}
 	}
-	session = ari_websocket_session_create(ws_session);
+	session = ari_websocket_session_create(ws_session,
+		ari_validate_event);
 	if (!session) {
 		ast_log(LOG_ERROR, "Failed to create ARI session\n");
 		return;

Modified: team/dlee/ari-event-remodel2/res/stasis_http/ari_websockets.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/ari_websockets.c?view=diff&rev=392165&r1=392164&r2=392165
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_websockets.c (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_websockets.c Tue Jun 18 12:20:48 2013
@@ -31,6 +31,7 @@
 
 struct ari_websocket_session {
 	struct ast_websocket *ws_session;
+	int (*validator)(struct ast_json *);
 };
 
 static void websocket_session_dtor(void *obj)
@@ -42,7 +43,7 @@
 }
 
 struct ari_websocket_session *ari_websocket_session_create(
-	struct ast_websocket *ws_session)
+	struct ast_websocket *ws_session, int (*validator)(struct ast_json *))
 {
 	RAII_VAR(struct ari_websocket_session *, session, NULL, ao2_cleanup);
 
@@ -63,6 +64,7 @@
 
 	ao2_ref(ws_session, +1);
 	session->ws_session = ws_session;
+	session->validator = validator;
 
 	ao2_ref(session, +1);
 	return session;
@@ -119,6 +121,12 @@
 		return -1;
 	}
 
+#ifdef AST_DEVMODE
+	if (!session->validator(message)) {
+		ast_log(LOG_ERROR, "Outgoing message failed validation\n");
+	}
+#endif
+
 	return ast_websocket_write(session->ws_session,
 		AST_WEBSOCKET_OPCODE_TEXT, str,	strlen(str));
 }

Modified: team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache?view=diff&rev=392165&r1=392164&r2=392165
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/res_stasis_http_resource.c.mustache Tue Jun 18 12:20:48 2013
@@ -99,7 +99,8 @@
 	struct ast_variable *path_vars = NULL;
 {{/has_path_parameters}}
 {{> param_parsing}}
-	session = ari_websocket_session_create(ws_session);
+	session = ari_websocket_session_create(ws_session,
+		ari_validate_{{snake_response_class}});
 	if (!session) {
 		ast_log(LOG_ERROR, "Failed to create ARI session\n");
 		return;




More information about the asterisk-commits mailing list