[asterisk-commits] dvossel: branch dvossel/generic_aoc r257488 - in /team/dvossel/generic_aoc: c...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Apr 15 15:29:18 CDT 2010
Author: dvossel
Date: Thu Apr 15 15:29:15 2010
New Revision: 257488
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=257488
Log:
handles non-present AOC unit amount or type correctly
Modified:
team/dvossel/generic_aoc/channels/sig_pri.c
team/dvossel/generic_aoc/include/asterisk/aoc.h
team/dvossel/generic_aoc/main/aoc.c
team/dvossel/generic_aoc/main/manager.c
team/dvossel/generic_aoc/tests/test_aoc.c
Modified: team/dvossel/generic_aoc/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/generic_aoc/channels/sig_pri.c?view=diff&rev=257488&r1=257487&r2=257488
==============================================================================
--- team/dvossel/generic_aoc/channels/sig_pri.c (original)
+++ team/dvossel/generic_aoc/channels/sig_pri.c Thu Apr 15 15:29:15 2010
@@ -2347,10 +2347,12 @@
{
int i;
for (i = 0; i < aoc_d->recorded.unit.num_items; ++i) {
- if (aoc_d->recorded.unit.item[i].number >= 0) {
- ast_aoc_add_unit_entry(decoded, aoc_d->recorded.unit.item[i].number,
- (aoc_d->recorded.unit.item[i].type < 0) ? 0 : aoc_d->recorded.unit.item[i].type);
- }
+ /* if type or number are negative, then they are not present */
+ ast_aoc_add_unit_entry(decoded,
+ (aoc_d->recorded.unit.item[i].number >= 0 ? 1 : 0),
+ aoc_d->recorded.unit.item[i].number,
+ (aoc_d->recorded.unit.item[i].type >= 0 ? 1 : 0),
+ aoc_d->recorded.unit.item[i].type);
}
}
}
@@ -2466,10 +2468,12 @@
{
int i;
for (i = 0; i < aoc_e->recorded.unit.num_items; ++i) {
- if (aoc_e->recorded.unit.item[i].number >= 0) {
- ast_aoc_add_unit_entry(decoded, aoc_e->recorded.unit.item[i].number,
- (aoc_e->recorded.unit.item[i].type < 0) ? 0 : aoc_e->recorded.unit.item[i].type);
- }
+ /* if type or number are negative, then they are not present */
+ ast_aoc_add_unit_entry(decoded,
+ (aoc_e->recorded.unit.item[i].number >= 0 ? 1 : 0),
+ aoc_e->recorded.unit.item[i].number,
+ (aoc_e->recorded.unit.item[i].type >= 0 ? 1 : 0),
+ aoc_e->recorded.unit.item[i].type);
}
}
}
@@ -2640,8 +2644,16 @@
aoc_d.charge = PRI_AOC_DE_CHARGE_UNITS;
for (i = 0; i < ast_aoc_get_unit_count(decoded); i++) {
if ((entry = ast_aoc_get_unit_info(decoded, i)) && i < ARRAY_LEN(aoc_d.recorded.unit.item)) {
- aoc_d.recorded.unit.item[i].number = entry->amount;
- aoc_d.recorded.unit.item[i].type = entry->type;
+ if (entry->valid_amount) {
+ aoc_d.recorded.unit.item[i].number = entry->amount;
+ } else {
+ aoc_d.recorded.unit.item[i].number = -1;
+ }
+ if (entry->valid_type) {
+ aoc_d.recorded.unit.item[i].type = entry->type;
+ } else {
+ aoc_d.recorded.unit.item[i].type = -1;
+ }
aoc_d.recorded.unit.num_items++;
} else {
break;
@@ -2740,8 +2752,16 @@
aoc_e->charge = PRI_AOC_DE_CHARGE_UNITS;
for (i = 0; i < ast_aoc_get_unit_count(decoded); i++) {
if ((entry = ast_aoc_get_unit_info(decoded, i)) && i < ARRAY_LEN(aoc_e->recorded.unit.item)) {
- aoc_e->recorded.unit.item[i].number = entry->amount;
- aoc_e->recorded.unit.item[i].type = entry->type;
+ if (entry->valid_amount) {
+ aoc_e->recorded.unit.item[i].number = entry->amount;
+ } else {
+ aoc_e->recorded.unit.item[i].number = -1;
+ }
+ if (entry->valid_type) {
+ aoc_e->recorded.unit.item[i].type = entry->type;
+ } else {
+ aoc_e->recorded.unit.item[i].type = -1;
+ }
aoc_e->recorded.unit.num_items++;
}
}
Modified: team/dvossel/generic_aoc/include/asterisk/aoc.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/generic_aoc/include/asterisk/aoc.h?view=diff&rev=257488&r1=257487&r2=257488
==============================================================================
--- team/dvossel/generic_aoc/include/asterisk/aoc.h (original)
+++ team/dvossel/generic_aoc/include/asterisk/aoc.h Thu Apr 15 15:29:15 2010
@@ -176,7 +176,9 @@
};
struct ast_aoc_unit_entry {
+ char valid_amount;
unsigned int amount;
+ char valid_type;
unsigned int type; /* 1 - 16 by ETSI standard */
};
@@ -258,13 +260,21 @@
/*! \brief Adds a unit entry into the list of units
*
* \param ast_aoc_decoded struct to set values on
+ * \param amount_is_present, set this if the number of units is
+ * actually present.
* \param number of units
+ * \param type_is_present, set this if the type value is present
* \param unit type
*
+ * \note If neither the amount nor the type is present, the entry will
+ * not be added.
+ *
* \retval 0 success
*/
int ast_aoc_add_unit_entry(struct ast_aoc_decoded *decoded,
+ const unsigned int amount_is_present,
const unsigned int amount,
+ const unsigned int type_is_present,
const unsigned int type);
/*! \brief set the billing id for a AOC-D or AST_AOC_E message
Modified: team/dvossel/generic_aoc/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/generic_aoc/main/aoc.c?view=diff&rev=257488&r1=257487&r2=257488
==============================================================================
--- team/dvossel/generic_aoc/main/aoc.c (original)
+++ team/dvossel/generic_aoc/main/aoc.c Thu Apr 15 15:29:15 2010
@@ -114,7 +114,9 @@
#define AOC_IE_UNIT 2
struct aoc_ie_unit {
+ uint8_t valid_amount;
uint32_t amount;
+ uint8_t valid_type;
uint8_t type;
};
@@ -136,6 +138,8 @@
};
#define AOC_IE_TERMINATION_REQUEST 6
+/* termination request has no data associated with it.
+ * the ie is either present or it is not */
struct ast_aoc_decoded *ast_aoc_create(const enum ast_aoc_type msg_type,
const enum ast_aoc_charge_type charge_type,
@@ -259,7 +263,7 @@
if (len == sizeof(struct aoc_ie_unit)) {
struct aoc_ie_unit ie;
memcpy(&ie, data + 2, len);
- ast_aoc_add_unit_entry(decoded, ntohl(ie.amount), ie.type);
+ ast_aoc_add_unit_entry(decoded, ie.valid_amount, ntohl(ie.amount), ie.valid_type, ie.type);
} else {
ast_log(LOG_WARNING, "Recieved invalid unit ie\n");
}
@@ -465,7 +469,9 @@
struct aoc_ie_unit ie = { 0 };
int i;
for (i = 0; i < decoded->unit_count; i++) {
+ ie.valid_amount = decoded->unit_list[i].valid_amount; /* only one byte */
ie.amount = htonl(decoded->unit_list[i].amount);
+ ie.valid_type = decoded->unit_list[i].valid_type; /* only one byte */
ie.type = decoded->unit_list[i].type; /* only one byte */
aoc_append_ie(ied, AOC_IE_UNIT, (const void *) &ie, sizeof(ie));
}
@@ -827,7 +833,9 @@
}
int ast_aoc_add_unit_entry(struct ast_aoc_decoded *decoded,
+ const unsigned int amount_is_present,
const unsigned int amount,
+ const unsigned int type_is_present,
const unsigned int type)
{
if ((decoded->msg_type == AST_AOC_REQUEST) ||
@@ -835,8 +843,23 @@
return -1;
}
- decoded->unit_list[decoded->unit_count].amount = amount;
- decoded->unit_list[decoded->unit_count].type = type;
+ if (!amount_is_present && !type_is_present) {
+ return -1;
+ }
+
+ decoded->unit_list[decoded->unit_count].valid_amount = amount_is_present;
+ if (amount_is_present) {
+ decoded->unit_list[decoded->unit_count].amount = amount;
+ } else {
+ decoded->unit_list[decoded->unit_count].amount = 0;
+ }
+
+ decoded->unit_list[decoded->unit_count].valid_type = type_is_present;
+ if (type_is_present) {
+ decoded->unit_list[decoded->unit_count].type = type;
+ } else {
+ decoded->unit_list[decoded->unit_count].type = 0;
+ }
decoded->unit_count++;
return 0;
@@ -1372,10 +1395,14 @@
decoded->unit_count);
for (idx = 0; idx < decoded->unit_count; ++idx) {
snprintf(prefix, sizeof(prefix), "%s/Item(%d)", charge_str, idx);
- ast_str_append(msg, 0, "%s/NumberOf: %u\r\n", prefix,
- decoded->unit_list[idx].amount);
- ast_str_append(msg, 0, "%s/TypeOf: %d\r\n", prefix,
- decoded->unit_list[idx].type);
+ if (decoded->unit_list[idx].valid_amount) {
+ ast_str_append(msg, 0, "%s/NumberOf: %u\r\n", prefix,
+ decoded->unit_list[idx].amount);
+ }
+ if (decoded->unit_list[idx].valid_type) {
+ ast_str_append(msg, 0, "%s/TypeOf: %d\r\n", prefix,
+ decoded->unit_list[idx].type);
+ }
}
break;
default:
@@ -1429,10 +1456,14 @@
decoded->unit_count);
for (idx = 0; idx < decoded->unit_count; ++idx) {
snprintf(prefix, sizeof(prefix), "%s/Item(%d)", charge_str, idx);
- ast_str_append(msg, 0, "%s/NumberOf: %u\r\n", prefix,
- decoded->unit_list[idx].amount);
- ast_str_append(msg, 0, "%s/TypeOf: %d\r\n", prefix,
- decoded->unit_list[idx].type);
+ if (decoded->unit_list[idx].valid_amount) {
+ ast_str_append(msg, 0, "%s/NumberOf: %u\r\n", prefix,
+ decoded->unit_list[idx].amount);
+ }
+ if (decoded->unit_list[idx].valid_type) {
+ ast_str_append(msg, 0, "%s/TypeOf: %d\r\n", prefix,
+ decoded->unit_list[idx].type);
+ }
}
break;
default:
Modified: team/dvossel/generic_aoc/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/generic_aoc/main/manager.c?view=diff&rev=257488&r1=257487&r2=257488
==============================================================================
--- team/dvossel/generic_aoc/main/manager.c (original)
+++ team/dvossel/generic_aoc/main/manager.c Thu Apr 15 15:29:15 2010
@@ -3522,15 +3522,17 @@
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);
- }
-
+ entry->valid_amount = 0;
+ } else {
+ entry->valid_amount = 1;
+ }
+
+ if (ast_strlen_zero(unittype) || sscanf(unittype, "%30u", &entry->type) != 1) {
+ entry->valid_type = 0;
+ } else {
+ entry->valid_type = 1;
+ }
return 0;
}
@@ -3716,7 +3718,7 @@
break; /* that's the end then */
}
- ast_aoc_add_unit_entry(decoded, entry.amount, entry.type);
+ ast_aoc_add_unit_entry(decoded, entry.valid_amount, entry.amount, entry.valid_type, entry.type);
}
/* at least one unit entry is required */
Modified: team/dvossel/generic_aoc/tests/test_aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/generic_aoc/tests/test_aoc.c?view=diff&rev=257488&r1=257487&r2=257488
==============================================================================
--- team/dvossel/generic_aoc/tests/test_aoc.c (original)
+++ team/dvossel/generic_aoc/tests/test_aoc.c Thu Apr 15 15:29:15 2010
@@ -200,10 +200,10 @@
res = AST_TEST_FAIL;
goto cleanup_aoc_event_test;
}
- if ((ast_aoc_add_unit_entry(decoded, 111, 1)) ||
- (ast_aoc_add_unit_entry(decoded, 2222, 2)) ||
- (ast_aoc_add_unit_entry(decoded, 3333, 3)) ||
- (ast_aoc_add_unit_entry(decoded, 44444, 4))) {
+ if ((ast_aoc_add_unit_entry(decoded, 1, 111, 1, 1)) ||
+ (!ast_aoc_add_unit_entry(decoded, 0, 2222, 0, 2)) || /* we expect this to fail, and it should not be added to entry list */
+ (ast_aoc_add_unit_entry(decoded, 1, 3333, 0, 3)) ||
+ (ast_aoc_add_unit_entry(decoded, 0, 44444, 1, 4))) {
ast_test_status_update(test, "failed to set unit info for AOC-E message\n");
res = AST_TEST_FAIL;
@@ -220,18 +220,14 @@
"AOC-E\r\n"
"Type: Units\r\n"
"BillingID: NotAvailable\r\n"
- "Units/NumberItems: 4\r\n"
+ "Units/NumberItems: 3\r\n"
"Units/Item(0)/NumberOf: 111\r\n"
"Units/Item(0)/TypeOf: 1\r\n"
- "Units/Item(1)/NumberOf: 2222\r\n"
- "Units/Item(1)/TypeOf: 2\r\n"
- "Units/Item(2)/NumberOf: 3333\r\n"
- "Units/Item(2)/TypeOf: 3\r\n"
- "Units/Item(3)/NumberOf: 44444\r\n"
- "Units/Item(3)/TypeOf: 4\r\n",
+ "Units/Item(1)/NumberOf: 3333\r\n"
+ "Units/Item(2)/TypeOf: 4\r\n",
strlen(ast_str_buffer(msg)))) {
- ast_test_status_update(test, "AOC-E msg event did not match expected results\n");
+ ast_test_status_update(test, "AOC-E msg event did not match expected results.\n");
res = AST_TEST_FAIL;
goto cleanup_aoc_event_test;
}
@@ -328,10 +324,10 @@
}
/* Set unit information, verify results*/
- if ((ast_aoc_add_unit_entry(decoded, 1, 2)) ||
- (ast_aoc_add_unit_entry(decoded, 2, 3)) ||
- (ast_aoc_add_unit_entry(decoded, 3, 4)) ||
- (ast_aoc_add_unit_entry(decoded, 4, 5))) {
+ if ((ast_aoc_add_unit_entry(decoded, 1, 1, 1, 2)) ||
+ (!ast_aoc_add_unit_entry(decoded, 0, 123, 0, 123)) || /* this entry should fail since either number nor type are present */
+ (ast_aoc_add_unit_entry(decoded, 0, 2, 1, 3)) ||
+ (ast_aoc_add_unit_entry(decoded, 1, 3, 0, 4))) {
ast_test_status_update(test, "Test 2: failed to set unit info\n");
res = AST_TEST_FAIL;
@@ -339,13 +335,13 @@
}
/* verify unit list is correct */
- if (ast_aoc_get_unit_count(decoded) == 4) {
+ if (ast_aoc_get_unit_count(decoded) == 3) {
int i;
const struct ast_aoc_unit_entry *unit;
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 3; i++) {
if (!(unit = ast_aoc_get_unit_info(decoded, i)) ||
- (unit->amount != (i+1)) ||
- (unit->type != (i+2))) {
+ ((unit->valid_amount) && (unit->amount != (i+1))) ||
+ ((unit->valid_type) && (unit->type != (i+2)))) {
ast_test_status_update(test, "TEST 2, invalid unit entry result, got %d,%d, expected %d,%d\n",
unit->amount,
unit->type,
More information about the asterisk-commits
mailing list