[asterisk-commits] dvossel: branch dvossel/generic_aoc r257741 - in /team/dvossel/generic_aoc: c...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Apr 16 17:11:11 CDT 2010
Author: dvossel
Date: Fri Apr 16 17:11:08 2010
New Revision: 257741
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=257741
Log:
fixes aoc charging association generic representation
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/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=257741&r1=257740&r2=257741
==============================================================================
--- team/dvossel/generic_aoc/channels/sig_pri.c (original)
+++ team/dvossel/generic_aoc/channels/sig_pri.c Fri Apr 16 17:11:08 2010
@@ -2700,19 +2700,25 @@
static void sig_pri_aoc_e_from_ast(struct sig_pri_chan *pvt, struct ast_aoc_decoded *decoded)
{
struct pri_subcmd_aoc_e *aoc_e = &pvt->aoc_e;
+ const struct ast_aoc_charging_association *ca = ast_aoc_get_association_info(decoded);
memset(aoc_e, 0, sizeof(*aoc_e));
pvt->holding_aoce = 1;
- if (ast_aoc_get_association_id(decoded)) {
- aoc_e->associated.charge.id = ast_aoc_get_association_id(decoded);
+
+ switch (ca->charging_type) {
+ case AST_AOC_CHARGING_ASSOCIATION_NUMBER:
+ ast_copy_string(aoc_e->associated.charge.number.str, ca->charge.number.number, sizeof(aoc_e->associated.charge.number.str));
+ aoc_e->associated.charge.number.plan = ca->charge.number.plan;
+ aoc_e->associated.charging_type = PRI_AOC_E_CHARGING_ASSOCIATION_NUMBER;
+ break;
+ case AST_AOC_CHARGING_ASSOCIATION_ID:
+ aoc_e->associated.charge.id = ca->charge.id;
aoc_e->associated.charging_type = PRI_AOC_E_CHARGING_ASSOCIATION_ID;
- } else if (!ast_strlen_zero(ast_aoc_get_association_number(decoded))) {
- ast_copy_string(aoc_e->associated.charge.number.str, ast_aoc_get_association_number(decoded), sizeof(aoc_e->associated.charge.number.str));
- aoc_e->associated.charge.number.plan = ast_aoc_get_association_plan(decoded);
- aoc_e->associated.charging_type = PRI_AOC_E_CHARGING_ASSOCIATION_NUMBER;
- } else {
- aoc_e->associated.charging_type = PRI_AOC_E_CHARGING_ASSOCIATION_NOT_AVAILABLE;
+ break;
+ case AST_AOC_CHARGING_ASSOCIATION_NA:
+ default:
+ break;
}
switch (ast_aoc_get_billing_id(decoded)) {
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=257741&r1=257740&r2=257741
==============================================================================
--- team/dvossel/generic_aoc/include/asterisk/aoc.h (original)
+++ team/dvossel/generic_aoc/include/asterisk/aoc.h Fri Apr 16 17:11:08 2010
@@ -180,6 +180,24 @@
unsigned int type; /* 1 - 16 by ETSI standard */
};
+enum AST_AOC_CHARGING_ASSOCIATION {
+ AST_AOC_CHARGING_ASSOCIATION_NA,
+ AST_AOC_CHARGING_ASSOCIATION_NUMBER,
+ AST_AOC_CHARGING_ASSOCIATION_ID,
+};
+struct ast_aoc_charging_association_number {
+ uint8_t plan;
+ char number[32];
+}__attribute__ ((packed));
+struct ast_aoc_charging_association {
+ union {
+ int32_t id;
+ struct ast_aoc_charging_association_number number;
+ } charge;
+ /*! \see enum AST_AOC_CHARGING_ASSOCIATION */
+ uint8_t charging_type;
+}__attribute__ ((packed));
+
/*! \brief AOC Payload Header. Holds all the encoded AOC data to pass on the wire */
struct ast_aoc_encoded;
@@ -512,13 +530,8 @@
/*! \brief get the billing id for AOC-D and AOC-E messages*/
enum ast_aoc_billing_id ast_aoc_get_billing_id(struct ast_aoc_decoded *decoded);
-/*! \brief get the charging association id for AOC-E messages*/
-int ast_aoc_get_association_id(struct ast_aoc_decoded *decoded);
-
-unsigned short ast_aoc_get_association_plan(struct ast_aoc_decoded *decoded);
-
-/*! \brief get the charging association number for AOC-E messages*/
-const char *ast_aoc_get_association_number(struct ast_aoc_decoded *decoded);
+/*! \brief get the charging association info for AOC-E messages*/
+const struct ast_aoc_charging_association *ast_aoc_get_association_info(struct ast_aoc_decoded *decoded);
/*! \brief get whether or not the AST_AOC_REQUEST message as a termination request.
* \since 1.8
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=257741&r1=257740&r2=257741
==============================================================================
--- team/dvossel/generic_aoc/main/aoc.c (original)
+++ team/dvossel/generic_aoc/main/aoc.c Fri Apr 16 17:11:08 2010
@@ -86,9 +86,7 @@
enum ast_aoc_billing_id billing_id;
/* Charging Association information */
- int charging_association_id;
- uint8_t charging_association_plan;
- char charging_association_number[32];
+ struct ast_aoc_charging_association charging_association;
/* AOC-S charge information */
int aoc_s_count;
@@ -133,9 +131,7 @@
}__attribute__ ((packed));
struct aoc_ie_charging_association {
- int32_t charge_id;
- char charge_number[32];
- uint8_t charge_plan;
+ struct ast_aoc_charging_association ca;
}__attribute__ ((packed));
struct aoc_ie_charging_rate {
@@ -280,11 +276,11 @@
break;
case AOC_IE_CHARGING_ASSOCIATION:
if (len == sizeof(struct aoc_ie_charging_association)) {
- struct aoc_ie_charging_association ie;
- memcpy(&ie, data + 2, len);
- decoded->charging_association_id = ntohl(ie.charge_id);
- decoded->charging_association_plan = ie.charge_plan;
- memcpy(decoded->charging_association_number, ie.charge_number, sizeof(decoded->charging_association_number));
+ memcpy(&decoded->charging_association, data + 2, sizeof(decoded->charging_association));
+ /* everything in the charging_association struct is a single byte except for the id */
+ if (decoded->charging_association.charging_type == AST_AOC_CHARGING_ASSOCIATION_ID) {
+ decoded->charging_association.charge.id = ntohl(decoded->charging_association.charge.id);
+ }
} else {
ast_log(LOG_WARNING, "Recieved invalid charging association ie\n");
}
@@ -484,13 +480,17 @@
aoc_append_ie(ied, AOC_IE_BILLING, (const void *) &ie, sizeof(ie));
}
- if (decoded->charging_association_id ||
- !ast_strlen_zero(decoded->charging_association_number)) {
- struct aoc_ie_charging_association ie = { 0 };
- ie.charge_id = htonl(decoded->charging_association_id);
- ie.charge_plan = decoded->charging_association_plan; /* only one byte */
- if (!ast_strlen_zero(decoded->charging_association_number)) {
- ast_copy_string(ie.charge_number, decoded->charging_association_number, sizeof(ie.charge_number));
+ if (decoded->charging_association.charging_type != AST_AOC_CHARGING_ASSOCIATION_NA) {
+ struct aoc_ie_charging_association ie;
+ memset(&ie, 0, sizeof(ie));
+ ie.ca.charging_type = decoded->charging_association.charging_type; /* only one byte */
+ if (decoded->charging_association.charging_type == AST_AOC_CHARGING_ASSOCIATION_NUMBER) {
+ ie.ca.charge.number.plan = decoded->charging_association.charge.number.plan; /* only one byte */
+ ast_copy_string(ie.ca.charge.number.number,
+ decoded->charging_association.charge.number.number,
+ sizeof(ie.ca.charge.number.number));
+ } else if (decoded->charging_association.charging_type == AST_AOC_CHARGING_ASSOCIATION_ID) {
+ ie.ca.charge.id = htonl(decoded->charging_association.charge.id);
}
aoc_append_ie(ied, AOC_IE_CHARGING_ASSOCIATION, (const void *) &ie, sizeof(ie));
}
@@ -901,13 +901,15 @@
if (decoded->msg_type != AST_AOC_E) {
return -1;
}
- decoded->charging_association_id = id;
+ memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
+ decoded->charging_association.charging_type = AST_AOC_CHARGING_ASSOCIATION_ID;
+ decoded->charging_association.charge.id = id;
return 0;
}
-int ast_aoc_get_association_id(struct ast_aoc_decoded *decoded)
-{
- return decoded->charging_association_id;
+const struct ast_aoc_charging_association *ast_aoc_get_association_info(struct ast_aoc_decoded *decoded)
+{
+ return &decoded->charging_association;
}
int ast_aoc_set_association_number(struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
@@ -915,23 +917,13 @@
if ((decoded->msg_type != AST_AOC_E) || ast_strlen_zero(num)) {
return -1;
}
-
- decoded->charging_association_plan = plan;
- ast_copy_string(decoded->charging_association_number, num, sizeof(decoded->charging_association_number));
+ memset(&decoded->charging_association, 0, sizeof(decoded->charging_association));
+ decoded->charging_association.charging_type = AST_AOC_CHARGING_ASSOCIATION_NUMBER;
+ decoded->charging_association.charge.number.plan = plan;
+ ast_copy_string(decoded->charging_association.charge.number.number, num, sizeof(decoded->charging_association.charge.number.number));
return 0;
}
-
-const char *ast_aoc_get_association_number(struct ast_aoc_decoded *decoded)
-{
- return decoded->charging_association_number;
-}
-
-unsigned short ast_aoc_get_association_plan(struct ast_aoc_decoded *decoded)
-{
- return decoded->charging_association_plan;
-}
-
int ast_aoc_set_termination_request(struct ast_aoc_decoded *decoded)
{
@@ -1423,14 +1415,21 @@
}
charge_str = "ChargingAssociation";
- if (!ast_strlen_zero(decoded->charging_association_number)) {
+
+ switch (decoded->charging_association.charging_type) {
+ case AST_AOC_CHARGING_ASSOCIATION_NUMBER:
snprintf(prefix, sizeof(prefix), "%s/Number", charge_str);
ast_str_append(msg, 0, "%s: %s\r\n", prefix,
- decoded->charging_association_number);
+ decoded->charging_association.charge.number.number);
ast_str_append(msg, 0, "%s/Plan: %d\r\n", prefix,
- decoded->charging_association_plan);
- } else if (decoded->charging_association_id) {
- ast_str_append(msg, 0, "%s/ID: %d\r\n", charge_str, decoded->charging_association_id);
+ decoded->charging_association.charge.number.plan);
+ break;
+ case AST_AOC_CHARGING_ASSOCIATION_ID:
+ ast_str_append(msg, 0, "%s/ID: %d\r\n", charge_str, decoded->charging_association.charge.id);
+ break;
+ case AST_AOC_CHARGING_ASSOCIATION_NA:
+ default:
+ break;
}
charge_str = aoc_charge_type_str(decoded->charge_type);
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=257741&r1=257740&r2=257741
==============================================================================
--- team/dvossel/generic_aoc/tests/test_aoc.c (original)
+++ team/dvossel/generic_aoc/tests/test_aoc.c Fri Apr 16 17:11:08 2010
@@ -193,7 +193,7 @@
decoded = ast_aoc_destroy_decoded(decoded);
ast_str_reset(msg);
- /* ---- TEST 3, AOC-E event generation */
+ /* ---- TEST 3, AOC-E event generation with various charging association information*/
if (!(decoded = ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_UNIT, 0))) {
ast_test_status_update(test, "failed to create AOC-E message for event generation.\n");
@@ -209,8 +209,8 @@
res = AST_TEST_FAIL;
goto cleanup_aoc_event_test;
}
+
if (ast_aoc_decoded2str(decoded, &msg)) {
-
ast_test_status_update(test, "failed to generate AOC-E msg string.\n");
res = AST_TEST_FAIL;
goto cleanup_aoc_event_test;
@@ -227,10 +227,74 @@
"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");
- res = AST_TEST_FAIL;
- goto cleanup_aoc_event_test;
- }
+ ast_test_status_update(test, "AOC-E msg event did not match expected results, with no charging association info\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_event_test;
+ }
+
+ /* add AOC-E charging association number info */
+ if (ast_aoc_set_association_number(decoded, "555-555-5555", 16)) {
+ ast_test_status_update(test, "failed to set the charging association number info correctly, 3\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_event_test;
+ }
+
+ ast_str_reset(msg);
+ if (ast_aoc_decoded2str(decoded, &msg)) {
+ ast_test_status_update(test, "failed to generate AOC-E msg string.\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_event_test;
+ }
+
+ if (strncmp(ast_str_buffer(msg),
+ "AOC-E\r\n"
+ "ChargingAssociation/Number: 555-555-5555\r\n"
+ "ChargingAssociation/Number/Plan: 16\r\n"
+ "Type: Units\r\n"
+ "BillingID: NotAvailable\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: 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, with charging association number\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_event_test;
+ }
+
+ /* add AOC-E charging association id info */
+ if (ast_aoc_set_association_id(decoded, 2222)) {
+ ast_test_status_update(test, "failed to set the charging association number info correctly, 3\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_event_test;
+ }
+
+ ast_str_reset(msg);
+ if (ast_aoc_decoded2str(decoded, &msg)) {
+ ast_test_status_update(test, "failed to generate AOC-E msg string.\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_event_test;
+ }
+
+ if (strncmp(ast_str_buffer(msg),
+ "AOC-E\r\n"
+ "ChargingAssociation/ID: 2222\r\n"
+ "Type: Units\r\n"
+ "BillingID: NotAvailable\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: 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 with charging association id.\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_event_test;
+ }
+
cleanup_aoc_event_test:
@@ -357,17 +421,33 @@
goto cleanup_aoc_test;
}
- /* Add charging association information */
- if ((ast_aoc_set_association_id(decoded, 1234)) ||
- (ast_aoc_get_association_id(decoded) != 1234) ||
- (ast_aoc_set_association_number(decoded, "5-555-555-555-555-5555", 2)) ||
- (ast_aoc_get_association_plan(decoded) != 2) ||
- (strcmp(ast_aoc_get_association_number(decoded), "5-555-555-555-555-5555"))) {
-
- ast_test_status_update(test, "TEST 2, could not set charging association info correctly\n");
- res = AST_TEST_FAIL;
- goto cleanup_aoc_test;
-
+
+ /* Test charging association information */
+ {
+ const struct ast_aoc_charging_association *ca;
+ if ((ast_aoc_set_association_id(decoded, 1234)) ||
+ (!(ca = ast_aoc_get_association_info(decoded)))) {
+ ast_test_status_update(test, "TEST 2, could not set charging association id info correctly\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_test;
+ }
+
+ if ((ca->charging_type != AST_AOC_CHARGING_ASSOCIATION_ID) || (ca->charge.id != 1234)) {
+ ast_test_status_update(test, "TEST 2, could not get charging association id info correctly, 2\n");
+ }
+
+ if ((ast_aoc_set_association_number(decoded, "1234", 16)) ||
+ (!(ca = ast_aoc_get_association_info(decoded)))) {
+ ast_test_status_update(test, "TEST 2, could not set charging association number info correctly, 3\n");
+ res = AST_TEST_FAIL;
+ goto cleanup_aoc_test;
+ }
+
+ if ((ca->charging_type != AST_AOC_CHARGING_ASSOCIATION_NUMBER) ||
+ (ca->charge.number.plan != 16) ||
+ (strcmp(ca->charge.number.number, "1234"))) {
+ ast_test_status_update(test, "TEST 2, could not get charging association number info correctly\n");
+ }
}
/* Test every billing id possiblity */
More information about the asterisk-commits
mailing list