[asterisk-commits] russell: branch group/newcdr r202146 - in /team/group/newcdr: cel/ include/as...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jun 20 09:43:51 CDT 2009
Author: russell
Date: Sat Jun 20 09:43:47 2009
New Revision: 202146
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202146
Log:
rework handling of strings <-> enum
Modified:
team/group/newcdr/cel/cel_manager.c
team/group/newcdr/cel/cel_radius.c
team/group/newcdr/cel/cel_tds.c
team/group/newcdr/include/asterisk/cel.h
team/group/newcdr/main/cel.c
Modified: team/group/newcdr/cel/cel_manager.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_manager.c?view=diff&rev=202146&r1=202145&r2=202146
==============================================================================
--- team/group/newcdr/cel/cel_manager.c (original)
+++ team/group/newcdr/cel/cel_manager.c Sat Jun 20 09:43:47 2009
@@ -174,7 +174,7 @@
record.caller_id_name, record.caller_id_ani, record.caller_id_rdnis,
record.caller_id_dnid, record.extension, record.context, record.channel_name,
record.application_name, record.application_data, start_time,
- ast_cel_flags2str(record.amaflag), record.unique_id, record.linked_id,
+ ast_cel_get_ama_flag_name(record.amaflag), record.unique_id, record.linked_id,
record.user_field, record.peer);
}
Modified: team/group/newcdr/cel/cel_radius.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_radius.c?view=diff&rev=202146&r1=202145&r2=202146
==============================================================================
--- team/group/newcdr/cel/cel_radius.c (original)
+++ team/group/newcdr/cel/cel_radius.c Sat Jun 20 09:43:47 2009
@@ -156,7 +156,7 @@
return -1;
}
/* AMA Flags */
- amaflags = ast_strdupa(ast_cel_flags2str(record->amaflag));
+ amaflags = ast_strdupa(ast_cel_get_ama_flag_name(record->amaflag));
if (!rc_avpair_add(rh, send, PW_AST_AMA_FLAGS, amaflags, strlen(amaflags), VENDOR_CODE)) {
return -1;
}
Modified: team/group/newcdr/cel/cel_tds.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_tds.c?view=diff&rev=202146&r1=202145&r2=202146
==============================================================================
--- team/group/newcdr/cel/cel_tds.c (original)
+++ team/group/newcdr/cel/cel_tds.c Sat Jun 20 09:43:47 2009
@@ -203,7 +203,7 @@
")",
settings->table, accountcode_ai, clidnum_ai, clid_ai, cidani_ai, cidrdnis_ai,
ciddnid_ai, exten_ai, context_ai, channel_ai, app_ai, appdata_ai, start,
- record.event_name, ast_cel_flags2str(record.amaflag), uniqueid_ai, linkedid_ai,
+ record.event_name, ast_cel_get_ama_flag_name(record.amaflag), uniqueid_ai, linkedid_ai,
userfield_ai, peer_ai);
if (erc == FAIL) {
Modified: team/group/newcdr/include/asterisk/cel.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/include/asterisk/cel.h?view=diff&rev=202146&r1=202145&r2=202146
==============================================================================
--- team/group/newcdr/include/asterisk/cel.h (original)
+++ team/group/newcdr/include/asterisk/cel.h Sat Jun 20 09:43:47 2009
@@ -32,9 +32,11 @@
/*! AMA Flags */
enum ast_cel_ama_flag {
- AST_CEL_OMIT,
- AST_CEL_BILLING,
- AST_CEL_DOCUMENTATION,
+ AST_CEL_AMA_FLAG_OMIT,
+ AST_CEL_AMA_FLAG_BILLING,
+ AST_CEL_AMA_FLAG_DOCUMENTATION,
+ /*! \brief Must be final entry */
+ AST_CEL_AMA_FLAG_TOTAL,
};
/*!
@@ -145,7 +147,7 @@
*
* \return the string representation of the flag
*/
-const char *ast_cel_flags2str(enum ast_cel_ama_flag flag);
+const char *ast_cel_get_ama_flag_name(enum ast_cel_ama_flag flag);
/*!
* \brief Check and potentially retire a Linked ID
Modified: team/group/newcdr/main/cel.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/cel.c?view=diff&rev=202146&r1=202145&r2=202146
==============================================================================
--- team/group/newcdr/main/cel.c (original)
+++ team/group/newcdr/main/cel.c Sat Jun 20 09:43:47 2009
@@ -52,6 +52,12 @@
*/
static int64_t eventset;
+/*!
+ * \brief Maximum possible CEL event IDs
+ * \note This limit is currently imposed by the eventset definition
+ */
+#define CEL_MAX_EVENT_IDS 64
+
/*! \brief Track no events by default. */
static const int64_t CEL_DEFAULT_EVENTS = 0;
@@ -60,6 +66,41 @@
static struct ao2_container *appset;
static char cel_dateformat[256];
+
+static const char *cel_event_types[CEL_MAX_EVENT_IDS] = {
+ [0] = "ALL",
+ [AST_CEL_CHANNEL_START] = "CHAN_START",
+ [AST_CEL_CHANNEL_END] = "CHAN_END",
+ [AST_CEL_ANSWER] = "ANSWER",
+ [AST_CEL_HANGUP] = "HANGUP",
+ [AST_CEL_APP_START] = "APP_START",
+ [AST_CEL_APP_END] = "APP_END",
+ [AST_CEL_BRIDGE_START] = "BRIDGE_START",
+ [AST_CEL_BRIDGE_END] = "BRIDGE_END",
+ [AST_CEL_BRIDGE_UPDATE] = "BRIDGE_UPDATE",
+ [AST_CEL_CONF_START] = "CONF_START",
+ [AST_CEL_CONF_END] = "CONF_END",
+ [AST_CEL_PARK_START] = "PARK_START",
+ [AST_CEL_PARK_END] = "PARK_END",
+ [AST_CEL_TRANSFER] = "TRANSFER",
+ [AST_CEL_USER_DEFINED] = "USER_DEFINED",
+ [AST_CEL_CONF_ENTER] = "CONF_ENTER",
+ [AST_CEL_CONF_EXIT] = "CONF_EXIT",
+ [AST_CEL_BLINDTRANSFER] = "BLINDTRANSFER",
+ [AST_CEL_ATTENDEDTRANSFER] = "ATTENDEDTRANSFER",
+ [AST_CEL_PICKUP] = "PICKUP",
+ [AST_CEL_FORWARD] = "FORWARD",
+ [AST_CEL_3WAY_START] = "3WAY_START",
+ [AST_CEL_3WAY_END] = "3WAY_END",
+ [AST_CEL_HOOKFLASH] = "HOOKFLASH",
+ [AST_CEL_LINKEDID_END] = "LINKEDID_END",
+};
+
+static const char *cel_ama_flags[AST_CEL_AMA_FLAG_TOTAL] = {
+ [AST_CEL_AMA_FLAG_OMIT] = "OMIT",
+ [AST_CEL_AMA_FLAG_BILLING] = "BILLING",
+ [AST_CEL_AMA_FLAG_DOCUMENTATION] = "DOCUMENTATION",
+};
unsigned int ast_cel_check_enabled(void)
{
@@ -129,61 +170,19 @@
enum ast_cel_event_type ast_cel_str_to_event_type(const char *name)
{
- if (!strcasecmp(name, "ALL")) {
- return 0;
- } else if (!strcasecmp(name, "CHAN_START")) {
- return AST_CEL_CHANNEL_START;
- } else if (!strcasecmp(name, "CHAN_END")) {
- return AST_CEL_CHANNEL_END;
- } else if (!strcasecmp(name, "ANSWER")) {
- return AST_CEL_ANSWER;
- } else if (!strcasecmp(name, "HANGUP")) {
- return AST_CEL_HANGUP;
- } else if (!strcasecmp(name, "APP_START")) {
- return AST_CEL_APP_START;
- } else if (!strcasecmp(name, "APP_END")) {
- return AST_CEL_APP_END;
- } else if (!strcasecmp(name, "BRIDGE_START")) {
- return AST_CEL_BRIDGE_START;
- } else if (!strcasecmp(name, "BRIDGE_END")) {
- return AST_CEL_BRIDGE_END;
- } else if (!strcasecmp(name, "BRIDGE_UPDATE")) {
- return AST_CEL_BRIDGE_UPDATE;
- } else if (!strcasecmp(name, "CONF_START")) {
- return AST_CEL_CONF_START;
- } else if (!strcasecmp(name, "CONF_END")) {
- return AST_CEL_CONF_END;
- } else if (!strcasecmp(name, "PARK_START")) {
- return AST_CEL_PARK_START;
- } else if (!strcasecmp(name, "PARK_END")) {
- return AST_CEL_PARK_END;
- } else if (!strcasecmp(name, "TRANSFER")) {
- return AST_CEL_TRANSFER;
- } else if (!strcasecmp(name, "USER_DEFINED")) {
- return AST_CEL_USER_DEFINED;
- } else if (!strcasecmp(name, "CONF_ENTER")) {
- return AST_CEL_CONF_ENTER;
- } else if (!strcasecmp(name, "CONF_EXIT")) {
- return AST_CEL_CONF_EXIT;
- } else if (!strcasecmp(name, "BLINDTRANSFER")) {
- return AST_CEL_BLINDTRANSFER;
- } else if (!strcasecmp(name, "ATTENDEDTRANSFER")) {
- return AST_CEL_ATTENDEDTRANSFER;
- } else if (!strcasecmp(name, "PICKUP")) {
- return AST_CEL_PICKUP;
- } else if (!strcasecmp(name, "FORWARD")) {
- return AST_CEL_FORWARD;
- } else if (!strcasecmp(name, "3WAY_START")) {
- return AST_CEL_3WAY_START;
- } else if (!strcasecmp(name, "3WAY_END")) {
- return AST_CEL_3WAY_END;
- } else if (!strcasecmp(name, "HOOKFLASH")) {
- return AST_CEL_HOOKFLASH;
- } else if (!strcasecmp(name, "LINKEDID_END")) {
- return AST_CEL_LINKEDID_END;
- } else {
- return -1;
- }
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_LEN(cel_event_types); i++) {
+ if (!cel_event_types[i]) {
+ continue;
+ }
+
+ if (!strcasecmp(name, cel_event_types[i])) {
+ return i;
+ }
+ }
+
+ return -1;
}
static int ast_cel_track_event(enum ast_cel_event_type et)
@@ -308,52 +307,12 @@
const char *ast_cel_get_type_name(enum ast_cel_event_type type)
{
-#define EV(e) case e: return # e
-
- switch (type) {
- EV(AST_CEL_CHANNEL_START);
- EV(AST_CEL_CHANNEL_END);
- EV(AST_CEL_HANGUP);
- EV(AST_CEL_ANSWER);
- EV(AST_CEL_APP_START);
- EV(AST_CEL_APP_END);
- EV(AST_CEL_BRIDGE_START);
- EV(AST_CEL_BRIDGE_UPDATE);
- EV(AST_CEL_BRIDGE_END);
- EV(AST_CEL_CONF_START);
- EV(AST_CEL_CONF_END);
- EV(AST_CEL_PARK_START);
- EV(AST_CEL_PARK_END);
- EV(AST_CEL_TRANSFER);
- EV(AST_CEL_CONF_ENTER);
- EV(AST_CEL_CONF_EXIT);
- EV(AST_CEL_USER_DEFINED);
- EV(AST_CEL_BLINDTRANSFER);
- EV(AST_CEL_ATTENDEDTRANSFER);
- EV(AST_CEL_PICKUP);
- EV(AST_CEL_FORWARD);
- EV(AST_CEL_3WAY_START);
- EV(AST_CEL_3WAY_END);
- EV(AST_CEL_HOOKFLASH);
- EV(AST_CEL_LINKEDID_END);
- }
-
-#undef EV
-
- return "Unknown";
-}
-
-const char *ast_cel_flags2str(enum ast_cel_ama_flag flag)
-{
- switch (flag) {
- case AST_CEL_OMIT:
- return "OMIT";
- case AST_CEL_BILLING:
- return "BILLING";
- case AST_CEL_DOCUMENTATION:
- return "DOCUMENTATION";
- }
- return "Unknown";
+ return S_OR(cel_event_types[type], "Unknown");
+}
+
+const char *ast_cel_get_ama_flag_name(enum ast_cel_ama_flag flag)
+{
+ return S_OR(cel_ama_flags[flag], "Unknown");
}
/* called whenever a channel is destroyed or a linkedid is changed to
More information about the asterisk-commits
mailing list