[asterisk-commits] kharwell: branch kharwell/stasis_aoc_event r393352 - /team/kharwell/stasis_ao...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 1 15:09:23 CDT 2013


Author: kharwell
Date: Mon Jul  1 15:09:22 2013
New Revision: 393352

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393352
Log:
addressed review issues

Modified:
    team/kharwell/stasis_aoc_event/main/aoc.c
    team/kharwell/stasis_aoc_event/main/manager.c

Modified: team/kharwell/stasis_aoc_event/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis_aoc_event/main/aoc.c?view=diff&rev=393352&r1=393351&r2=393352
==============================================================================
--- team/kharwell/stasis_aoc_event/main/aoc.c (original)
+++ team/kharwell/stasis_aoc_event/main/aoc.c Mon Jul  1 15:09:22 2013
@@ -38,6 +38,122 @@
 #include "asterisk/manager.h"
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis_message_router.h"
+
+/*** DOCUMENTATION
+	<managerEvent language="en_US" name="AOC-S">
+		<managerEventInstance class="EVENT_FLAG_AOC">
+			<synopsis>Raised when an Advice of Charge message is sent at the beginning of a call.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="Chargeable" />
+				<parameter name="RateType">
+					<enumlist>
+						<enum name="NotAvailable" />
+						<enum name="Free" />
+						<enum name="FreeFromBeginning" />
+						<enum name="Duration" />
+						<enum name="Flag" />
+						<enum name="Volume" />
+						<enum name="SpecialCode" />
+					</enumlist>
+				</parameter>
+				<parameter name="Currency" />
+				<parameter name="Name" />
+				<parameter name="Cost" />
+				<parameter name="Multiplier">
+					<enumlist>
+						<enum name="1/1000" />
+						<enum name="1/100" />
+						<enum name="1/10" />
+						<enum name="1" />
+						<enum name="10" />
+						<enum name="100" />
+						<enum name="1000" />
+					</enumlist>
+				</parameter>
+				<parameter name="ChargingType" />
+				<parameter name="StepFunction" />
+				<parameter name="Granularity" />
+				<parameter name="Length" />
+				<parameter name="Scale" />
+				<parameter name="Unit">
+					<enumlist>
+						<enum name="Octect" />
+						<enum name="Segment" />
+						<enum name="Message" />
+					</enumlist>
+				</parameter>
+				<parameter name="SpecialCode" />
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="AOC-D">
+		<managerEventInstance class="EVENT_FLAG_AOC">
+			<synopsis>Raised when an Advice of Charge message is sent during a call.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="Charge" />
+				<parameter name="Type">
+					<enumlist>
+						<enum name="NotAvailable" />
+						<enum name="Free" />
+						<enum name="Currency" />
+						<enum name="Units" />
+					</enumlist>
+				</parameter>
+				<parameter name="BillingID">
+					<enumlist>
+						<enum name="Normal" />
+						<enum name="Reverse" />
+						<enum name="CreditCard" />
+						<enum name="CallForwardingUnconditional" />
+						<enum name="CallForwardingBusy" />
+						<enum name="CallForwardingNoReply" />
+						<enum name="CallDeflection" />
+						<enum name="CallTransfer" />
+						<enum name="NotAvailable" />
+					</enumlist>
+				</parameter>
+				<parameter name="TotalType">
+					<enumlist>
+						<enum name="SubTotal" />
+						<enum name="Total" />
+					</enumlist>
+				</parameter>
+				<parameter name="Currency" />
+				<parameter name="Name" />
+				<parameter name="Cost" />
+				<parameter name="Multiplier">
+					<enumlist>
+						<enum name="1/1000" />
+						<enum name="1/100" />
+						<enum name="1/10" />
+						<enum name="1" />
+						<enum name="10" />
+						<enum name="100" />
+						<enum name="1000" />
+					</enumlist>
+				</parameter>
+				<parameter name="Units" />
+				<parameter name="NumberOf" />
+				<parameter name="TypeOf" />
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="AOC-E">
+		<managerEventInstance class="EVENT_FLAG_AOC">
+			<synopsis>Raised when an Advice of Charge message is sent at the end of a call.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="ChargingAssociation" />
+				<parameter name="Number" />
+				<parameter name="Plan" />
+				<parameter name="ID" />
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='AOC-D']/managerEventInstance/syntax/parameter)" />
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+***/
 
 /* Encoded Payload Flags */
 #define AST_AOC_ENCODED_TYPE_REQUEST    (0 << 0)
@@ -1677,90 +1793,6 @@
 			     "Charge", charge_to_json(decoded));
 }
 
-static void json_value_str_append(struct ast_json *value, const char *key,
-				  struct ast_str **res)
-{
-	switch (ast_json_typeof(value)) {
-	case AST_JSON_STRING:
-		ast_str_append(res, 0, "%s: %s\r\n", key, ast_json_string_get(value));
-		break;
-	case AST_JSON_INTEGER:
-		ast_str_append(res, 0, "%s: %jd\r\n", key, ast_json_integer_get(value));
-		break;
-	case AST_JSON_TRUE:
-		ast_str_append(res, 0, "%s: True\r\n", key);
-		break;
-	case AST_JSON_FALSE:
-		ast_str_append(res, 0, "%s: False\r\n", key);
-		break;
-	default:
-		ast_str_append(res, 0, "%s: \r\n", key);
-		break;
-	}
-}
-
-static void json_to_ast_str(struct ast_json *obj, const char *key,
-				struct ast_str **res);
-
-static void json_array_with_key(struct ast_json *obj, const char* key,
-				size_t index, struct ast_str **res)
-{
-	struct ast_str *key_str = ast_str_alloca(64);
-	ast_str_set(&key_str, 0, "%s(%zu)", key, index);
-	json_to_ast_str(obj, ast_str_buffer(key_str), res);
-}
-
-static void json_obj_with_key(struct ast_json *obj, const char* key,
-			      const char *parent_key, struct ast_str **res)
-{
-	if (parent_key) {
-		struct ast_str *key_str = ast_str_alloca(64);
-		ast_str_set(&key_str, 0, "%s/%s", parent_key, key);
-		json_to_ast_str(obj, ast_str_buffer(key_str), res);
-		return;
-	}
-
-	json_to_ast_str(obj, key, res);
-}
-
-static void json_to_ast_str(struct ast_json *obj, const char *key,
-			    struct ast_str **res)
-{
-	struct ast_json_iter *i;
-
-	if (!obj || (!res && !(*res) && (!(*res = ast_str_create(1024))))) {
-		return;
-	}
-
-	if (ast_json_typeof(obj) != AST_JSON_OBJECT &&
-	    ast_json_typeof(obj) != AST_JSON_ARRAY) {
-		json_value_str_append(obj, key, res);
-		return;
-	}
-
-	if (ast_json_typeof(obj) == AST_JSON_ARRAY) {
-		size_t j;
-		for (j = 0; j < ast_json_array_size(obj); ++j) {
-			json_array_with_key(ast_json_array_get(obj, j),
-					    key, j, res);
-		}
-		return;
-	}
-
-	for (i = ast_json_object_iter(obj); i;
-	     i = ast_json_object_iter_next(obj, i)) {
-		json_obj_with_key(ast_json_object_iter_value(i),
-				  ast_json_object_iter_key(i), key, res);
-	}
-}
-
-static struct ast_str *json_obj_to_ast_str(struct ast_json *obj)
-{
-	struct ast_str *res = ast_str_create(1024);
-	json_to_ast_str(obj, NULL, &res);
-	return res;
-}
-
 static struct ast_manager_event_blob *aoc_to_ami(struct stasis_message *message,
 						 const char *event_name)
 {
@@ -1773,7 +1805,7 @@
 		return NULL;
 	}
 
-	if (!(aoc = json_obj_to_ast_str(obj->blob))) {
+	if (!(aoc = ast_manager_str_from_json_object(obj->blob, NULL))) {
 		return NULL;
 	}
 

Modified: team/kharwell/stasis_aoc_event/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis_aoc_event/main/manager.c?view=diff&rev=393352&r1=393351&r2=393352
==============================================================================
--- team/kharwell/stasis_aoc_event/main/manager.c (original)
+++ team/kharwell/stasis_aoc_event/main/manager.c Mon Jul  1 15:09:22 2013
@@ -1274,47 +1274,98 @@
 	return stasis_router;
 }
 
+static void manager_json_value_str_append(struct ast_json *value, const char *key,
+					  struct ast_str **res)
+{
+	switch (ast_json_typeof(value)) {
+	case AST_JSON_STRING:
+		ast_str_append(res, 0, "%s: %s\r\n", key, ast_json_string_get(value));
+		break;
+	case AST_JSON_INTEGER:
+		ast_str_append(res, 0, "%s: %jd\r\n", key, ast_json_integer_get(value));
+		break;
+	case AST_JSON_TRUE:
+		ast_str_append(res, 0, "%s: True\r\n", key);
+		break;
+	case AST_JSON_FALSE:
+		ast_str_append(res, 0, "%s: False\r\n", key);
+		break;
+	default:
+		ast_str_append(res, 0, "%s: \r\n", key);
+		break;
+	}
+}
+
+static void manager_json_to_ast_str(struct ast_json *obj, const char *key,
+				    struct ast_str **res, key_exclusion_cb exclusion_cb);
+
+static void manager_json_array_with_key(struct ast_json *obj, const char* key,
+					size_t index, struct ast_str **res,
+					key_exclusion_cb exclusion_cb)
+{
+	struct ast_str *key_str = ast_str_alloca(64);
+	ast_str_set(&key_str, 0, "%s(%zu)", key, index);
+	manager_json_to_ast_str(obj, ast_str_buffer(key_str),
+				res, exclusion_cb);
+}
+
+static void manager_json_obj_with_key(struct ast_json *obj, const char* key,
+				      const char *parent_key, struct ast_str **res,
+				      key_exclusion_cb exclusion_cb)
+{
+	if (parent_key) {
+		struct ast_str *key_str = ast_str_alloca(64);
+		ast_str_set(&key_str, 0, "%s/%s", parent_key, key);
+		manager_json_to_ast_str(obj, ast_str_buffer(key_str),
+					res, exclusion_cb);
+		return;
+	}
+
+	manager_json_to_ast_str(obj, key, res, exclusion_cb);
+}
+
+void manager_json_to_ast_str(struct ast_json *obj, const char *key,
+			     struct ast_str **res, key_exclusion_cb exclusion_cb)
+{
+	struct ast_json_iter *i;
+
+	if (!obj || (!res && !(*res) && (!(*res = ast_str_create(1024))))) {
+		return;
+	}
+
+	if (exclusion_cb && key && exclusion_cb(key)) {
+		return;
+	}
+
+	if (ast_json_typeof(obj) != AST_JSON_OBJECT &&
+	    ast_json_typeof(obj) != AST_JSON_ARRAY) {
+		manager_json_value_str_append(obj, key, res);
+		return;
+	}
+
+	if (ast_json_typeof(obj) == AST_JSON_ARRAY) {
+		size_t j;
+		for (j = 0; j < ast_json_array_size(obj); ++j) {
+			manager_json_array_with_key(ast_json_array_get(obj, j),
+						    key, j, res, exclusion_cb);
+		}
+		return;
+	}
+
+	for (i = ast_json_object_iter(obj); i;
+	     i = ast_json_object_iter_next(obj, i)) {
+		manager_json_obj_with_key(ast_json_object_iter_value(i),
+					  ast_json_object_iter_key(i),
+					  key, res, exclusion_cb);
+	}
+}
+
+
 struct ast_str *ast_manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
 {
-	struct ast_str *output_str = ast_str_create(32);
-	struct ast_json *value;
-	struct ast_json_iter *iter;
-	const char *key;
-	if (!output_str) {
-		return NULL;
-	}
-
-	for (iter = ast_json_object_iter(blob); iter; iter = ast_json_object_iter_next(blob, iter)) {
-		key = ast_json_object_iter_key(iter);
-		value = ast_json_object_iter_value(iter);
-
-		if (exclusion_cb && exclusion_cb(key)) {
-			continue;
-		}
-		switch (ast_json_typeof(value)) {
-		case AST_JSON_STRING:
-			ast_str_append(&output_str, 0, "%s: %s\r\n", key, ast_json_string_get(value));
-			break;
-		case AST_JSON_INTEGER:
-			ast_str_append(&output_str, 0, "%s: %jd\r\n", key, ast_json_integer_get(value));
-			break;
-		case AST_JSON_TRUE:
-			ast_str_append(&output_str, 0, "%s: True\r\n", key);
-			break;
-		case AST_JSON_FALSE:
-			ast_str_append(&output_str, 0, "%s: False\r\n", key);
-			break;
-		default:
-			ast_str_append(&output_str, 0, "%s: \r\n", key);
-			break;
-		}
-
-		if (!output_str) {
-			return NULL;
-		}
-	}
-
-	return output_str;
+	struct ast_str *res = ast_str_create(1024);
+	manager_json_to_ast_str(blob, NULL, &res, exclusion_cb);
+	return res;
 }
 
 static void manager_default_msg_cb(void *data, struct stasis_subscription *sub,




More information about the asterisk-commits mailing list