[svn-commits] dvossel: branch group/aoc r251777 - in /team/group/aoc: channels/ include/ast...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Mar 10 17:42:20 CST 2010


Author: dvossel
Date: Wed Mar 10 17:42:16 2010
New Revision: 251777

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=251777
Log:
completion of AOCMessage manager action

AOCMessage can now be used to generate an aoc message.  At the moment
when generating a message on a sip channel, a temporary log message
is displayed indicating it was received.  AOCMessage user documentation
has yet to be completed though.

Modified:
    team/group/aoc/channels/chan_sip.c
    team/group/aoc/include/asterisk/aoc.h
    team/group/aoc/main/aoc.c
    team/group/aoc/main/manager.c

Modified: team/group/aoc/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/channels/chan_sip.c?view=diff&rev=251777&r1=251776&r2=251777
==============================================================================
--- team/group/aoc/channels/chan_sip.c (original)
+++ team/group/aoc/channels/chan_sip.c Wed Mar 10 17:42:16 2010
@@ -5364,6 +5364,9 @@
 	case AST_CONTROL_REDIRECTING:
 		update_redirecting(p, data, datalen);
 		break;
+	case AST_CONTROL_AOC:
+		ast_log(LOG_NOTICE, "SIP got the AOC frame\n"); //todohere remove this, just temporary
+		break;
 	case -1:
 		res = -1;
 		break;

Modified: team/group/aoc/include/asterisk/aoc.h
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/include/asterisk/aoc.h?view=diff&rev=251777&r1=251776&r2=251777
==============================================================================
--- team/group/aoc/include/asterisk/aoc.h (original)
+++ team/group/aoc/include/asterisk/aoc.h Wed Mar 10 17:42:16 2010
@@ -122,12 +122,12 @@
 /* \brief encodes a decoded aoc structure so it can be passed on the wire
  *
  * \param ast_aoc_decoded struct to be encoded
- * \param ast_aoc_encoded struct hold encoded data
- *
- * \retval size of encoded data
- * \retval 0 failure
- */
-size_t ast_aoc_encode(struct ast_aoc_decoded *decoded, struct ast_aoc_encoded **encoded_out);
+ * \param output parameter representing size of encoded data
+ *
+ * \retval pointer to encoded data
+ * \retval NULL failure
+ */
+struct ast_aoc_encoded *ast_aoc_encode(struct ast_aoc_decoded *decoded, size_t *out_size);
 
 /* \brief Sets the type of total for a AOC-D message
  *

Modified: team/group/aoc/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/main/aoc.c?view=diff&rev=251777&r1=251776&r2=251777
==============================================================================
--- team/group/aoc/main/aoc.c (original)
+++ team/group/aoc/main/aoc.c Wed Mar 10 17:42:16 2010
@@ -344,15 +344,16 @@
 	}
 }
 
-size_t ast_aoc_encode(struct ast_aoc_decoded *decoded, struct ast_aoc_encoded **encoded_out)
+struct ast_aoc_encoded *ast_aoc_encode(struct ast_aoc_decoded *decoded, size_t *out_size)
 {
 	struct aoc_ie_data ied;
-	struct ast_aoc_encoded *encoded;
+	struct ast_aoc_encoded *encoded = NULL;
 	size_t size = 0;
 
-	if (!decoded || !encoded_out) {
-		return 0;
-	}
+	if (!decoded || !out_size) {
+		return NULL;
+	}
+	*out_size = 0;
 
 	/* create information element buffer before allocating the payload,
 	 * by doing this the exact size of the payload + the id data can be
@@ -363,7 +364,7 @@
 
 	if (!(encoded = ast_calloc(1, size))) {
 		ast_log(LOG_WARNING, "Failed to create ast_aoc_encoded object during decode routine. \n");
-		return 0;
+		return NULL;
 	}
 
 	/* -- Set ie data buffer */
@@ -421,10 +422,10 @@
 	/* --- Set Version Number --- */
 	encoded->version = AOC_ENCODE_VERSION;
 
-	/* set the output param */
-	*encoded_out = encoded;
-
-	return size;
+	/* set the output size  */
+	*out_size = size;
+
+	return encoded;
 }
 
 enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded)
@@ -571,10 +572,10 @@
 {
 	struct ast_aoc_decoded *new = NULL;
 	struct ast_aoc_encoded *encoded = NULL;
-	unsigned int size;
+	size_t size;
 	int res = 0;
 
-	if (!(size = ast_aoc_encode(decoded, &encoded))) {
+	if (!(encoded = ast_aoc_encode(decoded, &size))) {
 		return -1;
 	}
 

Modified: team/group/aoc/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/main/manager.c?view=diff&rev=251777&r1=251776&r2=251777
==============================================================================
--- team/group/aoc/main/manager.c (original)
+++ team/group/aoc/main/manager.c Wed Mar 10 17:42:16 2010
@@ -3403,6 +3403,7 @@
 static int action_aocmessage(struct mansession *s, const struct message *m)
 {
 	const char *channel = astman_get_header(m, "Channel");
+	const char *pchannel = astman_get_header(m, "PartialChannel");
 	const char *msgtype = astman_get_header(m, "MsgType");
 	const char *chargetype = astman_get_header(m, "ChargeType");
 	const char *currencyname = astman_get_header(m, "CurrencyName");
@@ -3413,7 +3414,6 @@
 	const char *aocdbillingid = astman_get_header(m, "AOCDBillingId");
 	const char *association_id= astman_get_header(m, "ChargingAssociationId");
 	const char *association_num = astman_get_header(m, "ChargingAssociationNumber");
-/*	const char *actionid = astman_get_header(m, "ActionId"); TODO XXX take care of adding action id to this*/
 
 	enum ast_aoc_type _msgtype;
 	enum ast_aoc_charge_type _chargetype;
@@ -3422,29 +3422,34 @@
 	enum ast_aoc_billing_id _billingid = AOC_BILLING_NA;
 	unsigned int _currencyamount = 0;
 	int _association_id = 0;
-	struct ast_channel *chan;
+	struct ast_channel *chan = NULL;
 
 	struct ast_aoc_decoded *decoded = NULL;
 	struct ast_aoc_encoded *encoded = NULL;
-
-	if (ast_strlen_zero(channel)) {
-		astman_send_error(s, m, "Channel not specified");
-		return 0;
-	}
-
-	if (!(chan = ast_channel_get_by_name(channel))) {
+	size_t encoded_size = 0;
+
+	if (ast_strlen_zero(channel) && ast_strlen_zero(pchannel)) {
+		astman_send_error(s, m, "Channel and PartialChannel are not specified. Specify at least one of these.");
+		goto aocmessage_cleanup;
+	}
+
+	if (!(chan = ast_channel_get_by_name(channel)) && !ast_strlen_zero(pchannel)) {
+		chan = ast_channel_get_by_name_prefix(pchannel, strlen(pchannel));
+	}
+
+	if (!chan) {
 		astman_send_error(s, m, "No such channel");
-		return 0;
+		goto aocmessage_cleanup;
 	}
 
 	if (ast_strlen_zero(msgtype) || (strcasecmp(msgtype, "d") && strcasecmp(msgtype, "e"))) {
 		astman_send_error(s, m, "Invalid MsgType");
-		return 0;
+		goto aocmessage_cleanup;
 	}
 
 	if (ast_strlen_zero(chargetype)) {
 		astman_send_error(s, m, "ChargeType not specified");
-		return 0;
+		goto aocmessage_cleanup;
 	}
 
 	_msgtype = strcasecmp(msgtype, "d") ? AOC_E : AOC_D;
@@ -3459,7 +3464,7 @@
 		_chargetype = AOC_CHARGE_UNIT;
 	} else {
 		astman_send_error(s, m, "Invalid ChargeType");
-		return 0;
+		goto aocmessage_cleanup;
 	}
 
 	if (_chargetype == AOC_CHARGE_CURRENCY) {
@@ -3470,7 +3475,7 @@
 
 		if (ast_strlen_zero(mult)) {
 			astman_send_error(s, m, "ChargeMultiplier unspecified, ChargeMultiplier is required when ChargeType is Currency.");
-			return 0;
+			goto aocmessage_cleanup;
 		} else if (!strcasecmp(mult, "onethousandth")) {
 			_mult = AOC_MULT_ONETHOUSANDTH;
 		} else if (!strcasecmp(mult, "onehundredth")) {
@@ -3487,7 +3492,7 @@
 			_mult = AOC_MULT_THOUSAND;
 		} else {
 			astman_send_error(s, m, "Invalid ChargeMultiplier");
-			return 0;
+			goto aocmessage_cleanup;
 		}
 	}
 
@@ -3496,7 +3501,7 @@
 			_totaltype = AOC_SUBTOTAL;
 		}
 
-		if (!ast_strlen_zero(aocdbillingid)) {
+		if (ast_strlen_zero(aocdbillingid)) {
 			/* ignore this is optional */
 		} else if (!strcasecmp(aocdbillingid, "Normal")) {
 			_billingid = AOC_BILLING_NORMAL;
@@ -3506,10 +3511,10 @@
 			_billingid = AOC_BILLING_CREDIT_CARD;
 		} else {
 			astman_send_error(s, m, "Invalid AOCDBillingId");
-			return 0;
+			goto aocmessage_cleanup;
 		}
 	} else {
-		if (!ast_strlen_zero(aocebillingid)) {
+		if (ast_strlen_zero(aocebillingid)) {
 			/* ignore this is optional */
 		} else if (!strcasecmp(aocebillingid, "Normal")) {
 			_billingid = AOC_BILLING_NORMAL;
@@ -3529,10 +3534,10 @@
 			_billingid = AOC_BILLING_CALL_TRANSFER;
 		} else {
 			astman_send_error(s, m, "Invalid AOCEBillingId");
-			return 0;
-		}
-
-		if (!ast_strlen_zero(association_id) || (sscanf(association_id, "%30d", &_association_id) != 1)) {
+			goto aocmessage_cleanup;
+		}
+
+		if (!ast_strlen_zero(association_id) && (sscanf(association_id, "%30d", &_association_id) != 1)) {
 			astman_send_error(s, m, "Invalid ChargingAssociationId");
 		}
 
@@ -3541,7 +3546,7 @@
 	/* create decoded object and start setting values */
 	if (!(decoded = ast_aoc_create(_msgtype, _chargetype, 0))) {
 			astman_send_error(s, m, "Message Creation Failed");
-			return 0;
+			goto aocmessage_cleanup;
 	}
 
 	if (_chargetype == AOC_CHARGE_CURRENCY) {
@@ -3559,10 +3564,10 @@
 			ast_aoc_add_unit_entry(decoded, entry.amount, entry.type);
 		}
 
+		/* at least one unit entry is required */
 		if (!i) {
-			astman_send_error(s, m, "Invalid Unit entry, UnitAmount(0) is required.");
-			ast_aoc_destroy_decoded(decoded);
-			return 0;
+			astman_send_error(s, m, "Invalid UnitAmount(0), At least one valid unit entry is required when ChargeType is set to Unit");
+			goto aocmessage_cleanup;
 		}
 
 	}
@@ -3573,9 +3578,20 @@
 	ast_aoc_set_total_type(decoded, _totaltype);
 
 
+	if ((encoded = ast_aoc_encode(decoded, &encoded_size)) && !ast_indicate_data(chan, AST_CONTROL_AOC, encoded, encoded_size)) {
+		astman_send_ack(s, m, "AOC Message successfully queued on channel");
+	} else {
+		astman_send_error(s, m, "Error encoding AOC message, could not queue onto channel");
+	}
+
+aocmessage_cleanup:
+
 	ast_aoc_destroy_decoded(decoded);
 	ast_aoc_destroy_encoded(encoded);
 
+	if (chan) {
+		chan = ast_channel_unref(chan);
+	}
 	return 0;
 }
 




More information about the svn-commits mailing list