[asterisk-commits] dvossel: branch group/aoc r251393 - in /team/group/aoc: include/asterisk/ mai...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 8 12:52:56 CST 2010


Author: dvossel
Date: Mon Mar  8 12:52:52 2010
New Revision: 251393

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=251393
Log:
beginning of generic aoc decode and encode routines with unit test skeleton

Added:
    team/group/aoc/include/asterisk/aoc.h   (with props)
    team/group/aoc/main/aoc.c   (with props)
    team/group/aoc/tests/test_aoc.c   (with props)

Added: team/group/aoc/include/asterisk/aoc.h
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/include/asterisk/aoc.h?view=auto&rev=251393
==============================================================================
--- team/group/aoc/include/asterisk/aoc.h (added)
+++ team/group/aoc/include/asterisk/aoc.h Mon Mar  8 12:52:52 2010
@@ -1,0 +1,157 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2009-2010, Digium, Inc.
+ *
+ * David Vossel <dvossel at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Test Framework API
+ *
+ * For an overview on how to use the test API, see \ref AstUnitTestAPI
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+#ifndef _AST_AOC_H_
+#define _AST_AOC_H_
+
+/* AOC enums */
+enum ast_aoc_currency_multiplier {
+	AOC_MULT_ONETHOUSANDTH,
+	AOC_MULT_ONEHUNDREDTH,
+	AOC_MULT_ONETENTH,
+	AOC_MULT_ONE,
+	AOC_MULT_TEN,
+	AOC_MULT_HUNDRED,
+	AOC_MULT_THOUSAND,
+};
+
+enum ast_aoc_billing_id {
+	AOC_BILLING_NA,
+	AOC_BILLING_NORMAL,
+	AOC_BILLING_REVERSE_CHARGE,
+	AOC_BILLING_CREDIT_CARD,
+	AOC_BILLING_CALL_FWD_UNCONDITIONAL,
+	AOC_BILLING_CALL_FWD_NO_REPLY,
+	AOC_BILLING_CALL_DEFLECTION,
+	AOC_BILLING_CALL_TRANSFER,
+};
+
+enum ast_aoc_type {
+	/* AOC_S */  /* Reserved for AOC-S support */
+	AOC_D,
+	AOC_E,
+	AOC_REQUEST,
+};
+
+enum ast_aoc_charge_type {
+	AOC_CHARGE_NA,
+	AOC_CHARGE_FREE,
+	AOC_CHARGE_CURRENCY,
+	AOC_CHARGE_UNIT,
+};
+
+enum ast_aoc_request {
+	AOC_REQUEST_S = (1 << 0),
+	AOC_REQUEST_D = (1 << 1),
+	AOC_REQUEST_E = (1 << 2),
+};
+
+enum ast_aoc_total_type {
+	AOC_TOTAL = 0,
+	AOC_SUBTOTAL = 1,
+};
+
+/* AOC Payload Header. Holds all the encoded AOC data to pass on the wire */
+struct ast_aoc_encoded {
+	uint8_t  version;
+	uint8_t  flags;
+	uint16_t datalen;
+	unsigned char data[0];
+};
+
+
+/* Decoded AOC data */
+struct ast_aoc_decoded {
+	enum ast_aoc_type msg_type;
+	enum ast_aoc_charge_type charge_type;
+	enum ast_aoc_request request_flag;
+	enum ast_aoc_total_type total_type;
+
+	/* currency information */
+	enum ast_aoc_currency_multiplier multiplier;
+	unsigned int currency_amount;
+	char name[10+1];
+
+	/* unit information */
+	unsigned int unit_amount;
+	unsigned int unit_type; /* 1 - 16 */
+
+	/* Billing Id */
+	enum ast_aoc_billing_id billing_id;
+
+	/* Charging Association information */
+	int charging_association_id;
+	char charging_association_number[64];
+};
+
+
+/* \brief creates a ast_aoc_decode object of a specific message type */
+struct ast_aoc_decoded *ast_aoc_create(const enum ast_aoc_type msg_type);
+
+struct ast_aoc_decoded *ast_aoc_decode(struct ast_aoc_encoded *encoded);
+
+struct ast_aoc_encoded *ast_aoc_encode(struct ast_aoc_decoded *decoded);
+
+
+/* get set functions */
+enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded);
+
+int ast_aoc_set_request(struct ast_aoc_decoded *decode, const enum ast_aoc_request);
+enum ast_aoc_request ast_aoc_get_request(struct ast_aoc_decoded *decode);
+
+int ast_aoc_set_total_type(struct ast_aoc_decoded *decode, const enum ast_aoc_total_type);
+enum ast_aoc_total_type ast_aoc_get_total_type(struct ast_aoc_decoded *decode);
+
+/* currency type */
+int ast_aoc_set_currency_amount(struct ast_aoc_decoded *decode, const unsigned int amount);
+unsigned int ast_aoc_get_currency_amount(struct ast_aoc_decoded *decode);
+
+int ast_aoc_set_currency_multiplier(struct ast_aoc_decoded *decode, const enum ast_aoc_currency_multiplier multiplier);
+enum ast_aoc_currency_multiplier ast_aoc_get_currency_multiplier(struct ast_aoc_decoded *decode);
+
+int ast_aoc_set_currency_name(struct ast_aoc_decoded *decode, const char *name);
+const char *ast_aoc_get_currency_name(struct ast_aoc_decoded *decode);
+
+/* unit type */
+int ast_aoc_set_unit_amount(struct ast_aoc_decoded *decode, const unsigned int amount);
+unsigned int ast_aoc_get_unit_amount(struct ast_aoc_decoded *decode);
+
+int ast_aoc_set_unit_type(struct ast_aoc_decoded *decode, unsigned int);
+unsigned int ast_aoc_get_unit_type(struct ast_aoc_decoded *decode);
+
+/* billing id */
+int ast_aoc_set_billing_id(struct ast_aoc_decoded *decode, const enum ast_aoc_billing_id id);
+enum ast_aoc_billing_id ast_aoc_get_billing_id(struct ast_aoc_decoded *decode);
+
+/* charging association */
+int ast_aoc_set_association_id(struct ast_aoc_decoded *decode, const int id);
+int ast_aoc_get_association_id(struct ast_aoc_decoded *decode);
+
+int ast_aoc_set_association_number(struct ast_aoc_decoded *decode, const char *num);
+char *ast_aoc_get_association_number(struct ast_aoc_decoded *decode);
+
+#endif

Propchange: team/group/aoc/include/asterisk/aoc.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/aoc/include/asterisk/aoc.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/aoc/include/asterisk/aoc.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/group/aoc/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/main/aoc.c?view=auto&rev=251393
==============================================================================
--- team/group/aoc/main/aoc.c (added)
+++ team/group/aoc/main/aoc.c Mon Mar  8 12:52:52 2010
@@ -1,0 +1,138 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * David Vossel <dvossel at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief generic AOC payload generation encoding and decoding
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+#include "asterisk.h"
+#include "asterisk/aoc.h"
+#include "asterisk/utils.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
+
+#include "asterisk/_private.h"
+
+
+/* Encoded Payload Flags */
+#define AOC_ENCODED_TYPE_REQUEST (0 << 0)
+#define AOC_ENCODED_TYPE_D       (1 << 0)
+#define AOC_ENCODED_TYPE_E       (2 << 0)
+/* #define AOC_PAYLOAD_TYPE_S (3 << 0)  This is not yet supported, but reserve this for future use */
+
+#define AOC_ENCODED_REQUEST_S    (1 << 2)
+#define AOC_ENCODED_REQUEST_D    (1 << 3)
+#define AOC_ENCODED_REQUEST_E    (1 << 4)
+
+#define AOC_ENCODED_CHARGE_NA       (0 << 5) | (0 << 6)
+#define AOC_ENCODED_CHARGE_FREE     (1 << 5) | (0 << 6)
+#define AOC_ENCODED_CHARGE_CURRENCY (2 << 5) | (0 << 5)
+#define AOC_ENCODED_CHARGE_UNIT     (3 << 5)
+
+#define AOC_ENCODED_CHARGE_SUBTOTAL (1 << 7)
+#define AOC_ENCODED_CHARGE_TOTAL    (0 << 7)
+
+struct aoc_pl_ie_hdr {
+	uint8_t ie_id;
+	uint8_t datalen;
+	unsigned char data[0];
+};
+
+/* AOC Payload Information Elements */
+#define AOC_IE_CURRENCY 1
+struct aoc_ie_currency {
+	uint8_t  multiplier;
+	uint32_t amount;
+	char name[10+1];
+};
+
+#define AOC_IE_UNIT 2
+struct aoc_ie_unit {
+	uint32_t amount;
+	uint8_t  type;
+};
+
+#define AOCE_IE_BILLING 3
+struct aoce_ie_billing {
+	uint8_t aoce_billing_id;
+};
+
+#define AOCD_IE_BILLING 4
+struct aocd_ie_billing {
+	uint8_t aocd_billing_id;
+};
+
+#define AOC_IE_CHARGING_ASSOCIATION 5
+struct aoc_ie_charging_association {
+	int16_t charge_id;
+	uint8_t datalen;
+	unsigned char data[0];
+
+};
+
+
+
+struct ast_aoc_decoded *ast_aoc_create(const enum ast_aoc_type msg_type)
+{
+	struct ast_aoc_decoded *decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded));
+
+	if (!decoded) {
+		ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object \n");
+	}
+
+	return decoded;
+}
+
+struct ast_aoc_decoded *ast_aoc_decode(struct ast_aoc_encoded *encoded)
+{
+	struct ast_aoc_decoded *decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded));
+
+	if (!decoded) {
+		ast_log(LOG_WARNING, "Failed to create ast_aoc_decoded object \n");
+		return NULL;
+	}
+
+//todohere actually decode the encoded msg 
+
+	return decoded;
+
+
+}
+
+struct ast_aoc_encoded *ast_aoc_encode(struct ast_aoc_decoded *decoded)
+{
+	struct ast_aoc_encoded *encoded = ast_calloc(1, sizeof(struct ast_aoc_encoded));
+
+	if (!encoded) {
+		ast_log(LOG_WARNING, "Failed to create ast_aoc_encoded object during decode routine. \n");
+		return NULL;
+	}
+
+//todohere actually encode a msg 
+
+	return encoded;
+
+
+
+}
+
+
+

Propchange: team/group/aoc/main/aoc.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/aoc/main/aoc.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/aoc/main/aoc.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/group/aoc/tests/test_aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/tests/test_aoc.c?view=auto&rev=251393
==============================================================================
--- team/group/aoc/tests/test_aoc.c (added)
+++ team/group/aoc/tests/test_aoc.c Mon Mar  8 12:52:52 2010
@@ -1,0 +1,72 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * David Vossel <dvossel at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! 
+ * \file
+ * \brief Generic AOC encode decode tests
+ *
+ * \author David Vossel  <dvossel at digium.com>
+ * 
+ * \ingroup tests
+ */
+
+/*** MODULEINFO
+	<depend>TEST_FRAMEWORK</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/utils.h"
+#include "asterisk/module.h"
+#include "asterisk/test.h"
+
+AST_TEST_DEFINE(aoc_encode_decode_test)
+{
+	int res = AST_TEST_PASS;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "aoc_encode_decode_test";
+		info->category = "main/aoc/";
+		info->summary = "Advice of Charge encode and decode test";
+		info->description =
+			"This tests the Advice of Charge encode and decode routines.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+
+	return res;
+}
+
+static int unload_module(void)
+{
+	AST_TEST_UNREGISTER(aoc_encode_decode_test);
+	return 0;
+}
+
+static int load_module(void)
+{
+	AST_TEST_REGISTER(aoc_encode_decode_test);
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Test");

Propchange: team/group/aoc/tests/test_aoc.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/aoc/tests/test_aoc.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/aoc/tests/test_aoc.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list