[asterisk-commits] dvossel: branch group/aoc r251686 - in /team/group/aoc: include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Mar 10 15:09:35 CST 2010
Author: dvossel
Date: Wed Mar 10 15:09:32 2010
New Revision: 251686
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=251686
Log:
update to AOCMessage manager action
Modified:
team/group/aoc/include/asterisk/aoc.h
team/group/aoc/main/aoc.c
team/group/aoc/main/manager.c
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=251686&r1=251685&r2=251686
==============================================================================
--- team/group/aoc/include/asterisk/aoc.h (original)
+++ team/group/aoc/include/asterisk/aoc.h Wed Mar 10 15:09:32 2010
@@ -46,7 +46,7 @@
AOC_BILLING_CALL_FWD_BUSY,
AOC_BILLING_CALL_FWD_NO_REPLY,
AOC_BILLING_CALL_DEFLECTION,
- AOC_BILLING_CALL_TRANSFER,
+ AOC_BILLING_CALL_TRANSFER, /* must remain last enum */
};
enum ast_aoc_type {
@@ -106,6 +106,9 @@
/* \brief free an ast_aoc_decoded object */
void *ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded);
+/* \brief free an ast_aoc_encoded object */
+void *ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded);
+
/* \brief decodes an encoded aoc payload.
*
* \param ast_aoc_encoded, the encoded payload to decode.
Modified: team/group/aoc/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/main/aoc.c?view=diff&rev=251686&r1=251685&r2=251686
==============================================================================
--- team/group/aoc/main/aoc.c (original)
+++ team/group/aoc/main/aoc.c Wed Mar 10 15:09:32 2010
@@ -153,6 +153,12 @@
return NULL;
}
+void *ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
+{
+ ast_free(encoded);
+ return NULL;
+}
+
static int aoc_parse_ie(struct ast_aoc_decoded *decoded, unsigned char *data, unsigned int datalen)
{
int ie;
@@ -517,7 +523,12 @@
int ast_aoc_set_billing_id(struct ast_aoc_decoded *decoded, const enum ast_aoc_billing_id id)
{
+ if ((id > AOC_BILLING_CALL_TRANSFER) || (id < AOC_BILLING_NA)) {
+ return -1;
+ }
+
decoded->billing_id = id;
+
return 0;
}
@@ -528,6 +539,9 @@
int ast_aoc_set_association_id(struct ast_aoc_decoded *decoded, const int id)
{
+ if (decoded->msg_type != AOC_E) {
+ return -1;
+ }
decoded->charging_association_id = id;
return 0;
}
@@ -539,13 +553,11 @@
int ast_aoc_set_association_number(struct ast_aoc_decoded *decoded, const char *num)
{
- if (ast_strlen_zero(num)) {
- return -1;
- }
-
- ast_copy_string(decoded->charging_association_number,
- num,
- sizeof(decoded->charging_association_number));
+ if ((decoded->msg_type != AOC_E) || ast_strlen_zero(num)) {
+ return -1;
+ }
+
+ ast_copy_string(decoded->charging_association_number, num, sizeof(decoded->charging_association_number));
return 0;
}
@@ -579,5 +591,3 @@
ast_free(encoded);
return res;
}
-
-
Modified: team/group/aoc/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/main/manager.c?view=diff&rev=251686&r1=251685&r2=251686
==============================================================================
--- team/group/aoc/main/manager.c (original)
+++ team/group/aoc/main/manager.c Wed Mar 10 15:09:32 2010
@@ -3373,21 +3373,47 @@
return NULL;
}
+static int aocmessage_get_unit_entry(const struct message *m, struct ast_aoc_unit_entry *entry, unsigned int entry_num)
+{
+ const char *unitamount;
+ const char *unittype;
+ struct ast_str *str = ast_str_alloca(32);
+
+ memset(entry, 0, sizeof(*entry));
+
+ ast_str_set(&str, 0, "UnitAmount(%u)", entry_num);
+ unitamount = astman_get_header(m, ast_str_buffer(str));
+
+ ast_str_set(&str, 0, "UnitType(%u)", entry_num);
+ unittype = astman_get_header(m, ast_str_buffer(str));
+
+ /* unit amount is required, so we can't have a type without a amount */
+ if (ast_strlen_zero(unitamount) || (sscanf(unitamount, "%30u", &entry->amount) != 1)) {
+ return -1;
+ }
+
+ if (!ast_strlen_zero(unittype)) {
+ sscanf(unittype, "%30u", &entry->type);
+ }
+
+
+ return 0;
+}
static int action_aocmessage(struct mansession *s, const struct message *m)
{
const char *channel = astman_get_header(m, "Channel");
const char *msgtype = astman_get_header(m, "MsgType");
const char *chargetype = astman_get_header(m, "ChargeType");
-// const char *currencyname = astman_get_header(m, "CurrencyName");
+ const char *currencyname = astman_get_header(m, "CurrencyName");
const char *currencyamount = astman_get_header(m, "CurrencyAmount");
const char *mult = astman_get_header(m, "CurrencyMultiplier");
const char *totaltype = astman_get_header(m, "TotalType");
const char *aocebillingid = astman_get_header(m, "AOCEBillingId");
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");
+ 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;
@@ -3395,8 +3421,11 @@
enum ast_aoc_total_type _totaltype = AOC_TOTAL;
enum ast_aoc_billing_id _billingid = AOC_BILLING_NA;
unsigned int _currencyamount = 0;
-// int _association_id;
+ int _association_id = 0;
struct ast_channel *chan;
+
+ 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");
@@ -3435,12 +3464,13 @@
if (_chargetype == AOC_CHARGE_CURRENCY) {
- if (!ast_strlen_zero(currencyamount) && (sscanf(currencyamount, "%30u", &_currencyamount) != 1)) {
- astman_send_error(s, m, "Invalid CurrencyAmount");
+ if (ast_strlen_zero(currencyamount) || (sscanf(currencyamount, "%30u", &_currencyamount) != 1)) {
+ astman_send_error(s, m, "Invalid CurrencyAmount, CurrencyAmount is a required when ChargeType is Currency");
}
if (ast_strlen_zero(mult)) {
- /* if mult is zero len, ignore this is optional */
+ astman_send_error(s, m, "ChargeMultiplier unspecified, ChargeMultiplier is required when ChargeType is Currency.");
+ return 0;
} else if (!strcasecmp(mult, "onethousandth")) {
_mult = AOC_MULT_ONETHOUSANDTH;
} else if (!strcasecmp(mult, "onehundredth")) {
@@ -3459,11 +3489,7 @@
astman_send_error(s, m, "Invalid ChargeMultiplier");
return 0;
}
-
- } else if (_chargetype == AOC_CHARGE_UNIT) {
- /*TODO handle the unit stuffs */
- }
-
+ }
if (_msgtype == AOC_D) {
if (!ast_strlen_zero(totaltype) && !strcasecmp(totaltype, "subtotal")) {
@@ -3505,9 +3531,50 @@
astman_send_error(s, m, "Invalid AOCEBillingId");
return 0;
}
- }
-
-//charging association crap
+
+ if (!ast_strlen_zero(association_id) || (sscanf(association_id, "%30d", &_association_id) != 1)) {
+ astman_send_error(s, m, "Invalid ChargingAssociationId");
+ }
+
+ }
+
+ /* 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;
+ }
+
+ if (_chargetype == AOC_CHARGE_CURRENCY) {
+ ast_aoc_set_currency_info(decoded, _currencyamount, _mult, ast_strlen_zero(currencyname) ? NULL : currencyname);
+ } else {
+ struct ast_aoc_unit_entry entry;
+ int i;
+
+ /* multiple unit entries are possible, lets get them all */
+ for (i = 0; i < 32; i++) {
+ if (aocmessage_get_unit_entry(m, &entry, i)) {
+ break; /* that's the end then */
+ }
+
+ ast_aoc_add_unit_entry(decoded, entry.amount, entry.type);
+ }
+
+ if (!i) {
+ astman_send_error(s, m, "Invalid Unit entry, UnitAmount(0) is required.");
+ ast_aoc_destroy_decoded(decoded);
+ return 0;
+ }
+
+ }
+
+ ast_aoc_set_association_number(decoded, association_num);
+ ast_aoc_set_association_id(decoded, _association_id);
+ ast_aoc_set_billing_id(decoded, _billingid);
+ ast_aoc_set_total_type(decoded, _totaltype);
+
+
+ ast_aoc_destroy_decoded(decoded);
+ ast_aoc_destroy_encoded(encoded);
return 0;
}
More information about the asterisk-commits
mailing list