[svn-commits] dlee: branch dlee/ari-event-remodel2 r392362 - in /team/dlee/ari-event-remode...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 20 15:19:05 CDT 2013


Author: dlee
Date: Thu Jun 20 15:19:03 2013
New Revision: 392362

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392362
Log:
Format websocket according to config; thin down channel to match AMI

Modified:
    team/dlee/ari-event-remodel2/include/asterisk/stasis_http.h
    team/dlee/ari-event-remodel2/main/stasis_channels.c
    team/dlee/ari-event-remodel2/res/res_stasis_http.c
    team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
    team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h
    team/dlee/ari-event-remodel2/res/stasis_http/ari_websockets.c
    team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json

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=392362&r1=392361&r2=392362
==============================================================================
--- team/dlee/ari-event-remodel2/include/asterisk/stasis_http.h (original)
+++ team/dlee/ari-event-remodel2/include/asterisk/stasis_http.h Thu Jun 20 15:19:03 2013
@@ -32,6 +32,12 @@
 #include "asterisk/http.h"
 #include "asterisk/json.h"
 #include "asterisk/http_websocket.h"
+
+/*!
+ * \brief Configured encoding format for JSON output.
+ * \return JSON output encoding (compact, pretty, etc.)
+ */
+enum ast_json_encoding_format stasis_http_json_format(void);
 
 struct stasis_http_response;
 

Modified: team/dlee/ari-event-remodel2/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/main/stasis_channels.c?view=diff&rev=392362&r1=392361&r2=392362
==============================================================================
--- team/dlee/ari-event-remodel2/main/stasis_channels.c (original)
+++ team/dlee/ari-event-remodel2/main/stasis_channels.c Thu Jun 20 15:19:03 2013
@@ -614,25 +614,25 @@
 		return NULL;
 	}
 
-	json_chan = ast_json_pack("{ s: s, s: s, s: s, s: s, s: s, s: s, s: s,"
-				  "  s: s, s: s, s: s, s: s, s: o, s: o, s: o,"
-				  "  s: o"
-				  "}",
-				  "name", snapshot->name,
-				  "state", ast_state2str(snapshot->state),
-				  "accountcode", snapshot->accountcode,
-				  "peeraccount", snapshot->peeraccount,
-				  "userfield", snapshot->userfield,
-				  "uniqueid", snapshot->uniqueid,
-				  "linkedid", snapshot->linkedid,
-				  "parkinglot", snapshot->parkinglot,
-				  "hangupsource", snapshot->hangupsource,
-				  "appl", snapshot->appl,
-				  "data", snapshot->data,
-				  "dialplan", ast_json_dialplan_cep(snapshot->context, snapshot->exten, snapshot->priority),
-				  "caller", ast_json_name_number(snapshot->caller_name, snapshot->caller_number),
-				  "connected", ast_json_name_number(snapshot->connected_name, snapshot->connected_number),
-				  "creationtime", ast_json_timeval(snapshot->creationtime, NULL));
+	json_chan = ast_json_pack(
+		/* Broken up into groups of three for readability */
+		"{ s: s, s: s, s: s,"
+		"  s: o, s: o, s: s,"
+		"  s: o, s: o }",
+		/* First line */
+		"id", snapshot->uniqueid,
+		"name", snapshot->name,
+		"state", ast_state2str(snapshot->state),
+		/* Second line */
+		"caller", ast_json_name_number(
+			snapshot->caller_name, snapshot->caller_number),
+		"connected", ast_json_name_number(
+			snapshot->connected_name, snapshot->connected_number),
+		"accountcode", snapshot->accountcode,
+		/* Third line */
+		"dialplan", ast_json_dialplan_cep(
+			snapshot->context, snapshot->exten, snapshot->priority),
+		"creationtime", ast_json_timeval(snapshot->creationtime, NULL));
 
 	return ast_json_ref(json_chan);
 }

Modified: team/dlee/ari-event-remodel2/res/res_stasis_http.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/res_stasis_http.c?view=diff&rev=392362&r1=392361&r2=392362
==============================================================================
--- team/dlee/ari-event-remodel2/res/res_stasis_http.c (original)
+++ team/dlee/ari-event-remodel2/res/res_stasis_http.c Thu Jun 20 15:19:03 2013
@@ -780,6 +780,11 @@
 	 */
 }
 
+enum ast_json_encoding_format stasis_http_json_format(void)
+{
+	RAII_VAR(struct conf *, cfg, ao2_global_obj_ref(confs), ao2_cleanup);
+	return cfg->global->format;
+}
 
 /*!
  * \internal
@@ -802,7 +807,6 @@
 				struct ast_variable *get_params,
 				struct ast_variable *headers)
 {
-	RAII_VAR(struct conf *, cfg, ao2_global_obj_ref(confs), ao2_cleanup);
 	RAII_VAR(struct ast_str *, response_headers, ast_str_create(40), ast_free);
 	RAII_VAR(struct ast_str *, response_body, ast_str_create(256), ast_free);
 	struct stasis_http_response response = {};
@@ -856,7 +860,7 @@
 	if (response.message && !ast_json_is_null(response.message)) {
 		ast_str_append(&response_headers, 0,
 			       "Content-type: application/json\r\n");
-		if (ast_json_dump_str_format(response.message, &response_body, cfg->global->format) != 0) {
+		if (ast_json_dump_str_format(response.message, &response_body, stasis_http_json_format()) != 0) {
 			/* Error encoding response */
 			response.response_code = 500;
 			response.response_text = "Internal Server Error";

Modified: team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c?view=diff&rev=392362&r1=392361&r2=392362
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c Thu Jun 20 15:19:03 2013
@@ -167,20 +167,13 @@
 	int res = 1;
 	struct ast_json_iter *iter;
 	int has_accountcode = 0;
-	int has_appl = 0;
 	int has_caller = 0;
 	int has_connected = 0;
 	int has_creationtime = 0;
-	int has_data = 0;
 	int has_dialplan = 0;
-	int has_hangupsource = 0;
-	int has_linkedid = 0;
+	int has_id = 0;
 	int has_name = 0;
-	int has_parkinglot = 0;
-	int has_peeraccount = 0;
 	int has_state = 0;
-	int has_uniqueid = 0;
-	int has_userfield = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
 		if (strcmp("accountcode", ast_json_object_iter_key(iter)) == 0) {
@@ -190,16 +183,6 @@
 				ast_json_object_iter_value(iter));
 			if (!prop_res) {
 				ast_log(LOG_ERROR, "ARI Channel field accountcode failed validation\n");
-				res = 0;
-			}
-		} else
-		if (strcmp("appl", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_appl = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI Channel field appl failed validation\n");
 				res = 0;
 			}
 		} else
@@ -233,16 +216,6 @@
 				res = 0;
 			}
 		} else
-		if (strcmp("data", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_data = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI Channel field data failed validation\n");
-				res = 0;
-			}
-		} else
 		if (strcmp("dialplan", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_dialplan = 1;
@@ -253,23 +226,13 @@
 				res = 0;
 			}
 		} else
-		if (strcmp("hangupsource", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_hangupsource = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI Channel field hangupsource failed validation\n");
-				res = 0;
-			}
-		} else
-		if (strcmp("linkedid", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_linkedid = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI Channel field linkedid failed validation\n");
+		if (strcmp("id", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_id = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI Channel field id failed validation\n");
 				res = 0;
 			}
 		} else
@@ -283,26 +246,6 @@
 				res = 0;
 			}
 		} else
-		if (strcmp("parkinglot", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_parkinglot = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI Channel field parkinglot failed validation\n");
-				res = 0;
-			}
-		} else
-		if (strcmp("peeraccount", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_peeraccount = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI Channel field peeraccount failed validation\n");
-				res = 0;
-			}
-		} else
 		if (strcmp("state", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_state = 1;
@@ -310,26 +253,6 @@
 				ast_json_object_iter_value(iter));
 			if (!prop_res) {
 				ast_log(LOG_ERROR, "ARI Channel field state failed validation\n");
-				res = 0;
-			}
-		} else
-		if (strcmp("uniqueid", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_uniqueid = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI Channel field uniqueid failed validation\n");
-				res = 0;
-			}
-		} else
-		if (strcmp("userfield", ast_json_object_iter_key(iter)) == 0) {
-			int prop_res;
-			has_userfield = 1;
-			prop_res = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_res) {
-				ast_log(LOG_ERROR, "ARI Channel field userfield failed validation\n");
 				res = 0;
 			}
 		} else
@@ -345,10 +268,6 @@
 		ast_log(LOG_ERROR, "ARI Channel missing required field accountcode\n");
 		res = 0;
 	}
-	if (!has_appl) {
-		ast_log(LOG_ERROR, "ARI Channel missing required field appl\n");
-		res = 0;
-	}
 	if (!has_caller) {
 		ast_log(LOG_ERROR, "ARI Channel missing required field caller\n");
 		res = 0;
@@ -361,44 +280,20 @@
 		ast_log(LOG_ERROR, "ARI Channel missing required field creationtime\n");
 		res = 0;
 	}
-	if (!has_data) {
-		ast_log(LOG_ERROR, "ARI Channel missing required field data\n");
-		res = 0;
-	}
 	if (!has_dialplan) {
 		ast_log(LOG_ERROR, "ARI Channel missing required field dialplan\n");
 		res = 0;
 	}
-	if (!has_hangupsource) {
-		ast_log(LOG_ERROR, "ARI Channel missing required field hangupsource\n");
-		res = 0;
-	}
-	if (!has_linkedid) {
-		ast_log(LOG_ERROR, "ARI Channel missing required field linkedid\n");
+	if (!has_id) {
+		ast_log(LOG_ERROR, "ARI Channel missing required field id\n");
 		res = 0;
 	}
 	if (!has_name) {
 		ast_log(LOG_ERROR, "ARI Channel missing required field name\n");
 		res = 0;
 	}
-	if (!has_parkinglot) {
-		ast_log(LOG_ERROR, "ARI Channel missing required field parkinglot\n");
-		res = 0;
-	}
-	if (!has_peeraccount) {
-		ast_log(LOG_ERROR, "ARI Channel missing required field peeraccount\n");
-		res = 0;
-	}
 	if (!has_state) {
 		ast_log(LOG_ERROR, "ARI Channel missing required field state\n");
-		res = 0;
-	}
-	if (!has_uniqueid) {
-		ast_log(LOG_ERROR, "ARI Channel missing required field uniqueid\n");
-		res = 0;
-	}
-	if (!has_userfield) {
-		ast_log(LOG_ERROR, "ARI Channel missing required field userfield\n");
 		res = 0;
 	}
 

Modified: team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h?view=diff&rev=392362&r1=392361&r2=392362
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h Thu Jun 20 15:19:03 2013
@@ -490,20 +490,13 @@
  * - number: string (required)
  * Channel
  * - accountcode: string (required)
- * - appl: string (required)
  * - caller: CallerID (required)
  * - connected: CallerID (required)
  * - creationtime: Date (required)
- * - data: string (required)
  * - dialplan: DialplanCEP (required)
- * - hangupsource: string (required)
- * - linkedid: string (required)
+ * - id: string (required)
  * - name: string (required)
- * - parkinglot: string (required)
- * - peeraccount: string (required)
  * - state: string (required)
- * - uniqueid: string (required)
- * - userfield: string (required)
  * Dialed
  * DialplanCEP
  * - context: string (required)

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=392362&r1=392361&r2=392362
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_websockets.c (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_websockets.c Thu Jun 20 15:19:03 2013
@@ -114,7 +114,9 @@
 int ari_websocket_session_write(struct ari_websocket_session *session,
 	struct ast_json *message)
 {
-	RAII_VAR(char *, str, ast_json_dump_string(message), ast_free);
+	RAII_VAR(char *, str, NULL, ast_free);
+
+	str = ast_json_dump_string_format(message, stasis_http_json_format());
 
 	if (str == NULL) {
 		ast_log(LOG_ERROR, "Failed to encode JSON object\n");

Modified: team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json?view=diff&rev=392362&r1=392361&r2=392362
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json (original)
+++ team/dlee/ari-event-remodel2/rest-api/api-docs/channels.json Thu Jun 20 15:19:03 2013
@@ -631,10 +631,10 @@
 			"id": "Channel",
 			"description": "A specific communication connection between Asterisk and an Endpoint.",
 			"properties": {
-				"uniqueid": {
+				"id": {
 					"required": true,
 					"type": "string",
-					"description": "Unique identifier of the channel"
+					"description": "Unique identifier of the channel.\n\nThis is the same as the Uniqueid field in AMI."
 				},
 				"name": {
 					"required": true,
@@ -643,54 +643,40 @@
 				},
 				"state": {
 					"required": true,
+					"type": "string",
+					"allowableValues": {
+						"valueType": "LIST",
+						"values": [
+							"Down",
+							"Rsrved",
+							"OffHook",
+							"Dialing",
+							"Ring",
+							"Ringing",
+							"Up",
+							"Busy",
+							"Dialing Offhook",
+							"Pre-ring",
+							"Unknown"
+						]
+					}
+				},
+				"caller": {
+					"required": true,
+					"type": "CallerID"
+				},
+				"connected": {
+					"required": true,
+					"type": "CallerID"
+				},
+				"accountcode": {
+					"required": true,
 					"type": "string"
-				},
-				"accountcode": {
-					"required": true,
-					"type": "string"
-				},
-				"peeraccount": {
-					"required": true,
-					"type": "string"
-				},
-				"userfield": {
-					"required": true,
-					"type": "string"
-				},
-				"linkedid": {
-					"required": true,
-					"type": "string"
-				},
-				"parkinglot": {
-					"required": true,
-					"type": "string"
-				},
-				"hangupsource": {
-					"required": true,
-					"type": "string"
-				},
-				"appl": {
-					"required": true,
-					"type": "string",
-					"description": "Currently executing dialplan application"
-				},
-				"data": {
-					"required": true,
-					"type": "string",
-					"description": "Arguments passed to appl"
 				},
 				"dialplan": {
 					"required": true,
 					"type": "DialplanCEP",
 					"description": "Current location in the dialplan"
-				},
-				"caller": {
-					"required": true,
-					"type": "CallerID"
-				},
-				"connected": {
-					"required": true,
-					"type": "CallerID"
 				},
 				"creationtime": {
 					"required": true,




More information about the svn-commits mailing list