[asterisk-commits] murf: branch murf/newcdr r62094 - in /team/murf/newcdr: cel/ configs/ funcs/ ...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Apr 26 21:09:44 MST 2007


Author: murf
Date: Thu Apr 26 23:09:43 2007
New Revision: 62094

URL: http://svn.digium.com/view/asterisk?view=rev&rev=62094
Log:
Hmmm. Hit me while I was going over the cdr struct, that most of these fields are copies of what's in the channel. So I got rid of them. UserField? Could be a simple channel var. Put a channel ptr in the cel struct. Now down really to event time and type.

Added:
    team/murf/newcdr/funcs/func_cel.c   (with props)
Modified:
    team/murf/newcdr/cel/cel_custom.c
    team/murf/newcdr/configs/cel_custom.conf.sample
    team/murf/newcdr/include/asterisk/cel.h
    team/murf/newcdr/main/cel.c

Modified: team/murf/newcdr/cel/cel_custom.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_custom.c?view=diff&rev=62094&r1=62093&r2=62094
==============================================================================
--- team/murf/newcdr/cel/cel_custom.c (original)
+++ team/murf/newcdr/cel/cel_custom.c Thu Apr 26 23:09:43 2007
@@ -118,9 +118,7 @@
 	memset(buf, 0 , sizeof(buf));
 	/* Quite possibly the first use of a static struct ast_channel, we need it so the var funcs will work */
 	/* fix this code */
-	memset(&dummy, 0, sizeof(dummy));
-	dummy.cdr = cel;
-	pbx_substitute_variables_helper(&dummy, format, buf, sizeof(buf) - 1);
+	pbx_substitute_variables_helper(cel->chan, format, buf, sizeof(buf) - 1);
 
 	/* because of the absolutely unconditional need for the
 	   highest reliability possible in writing billing records,

Modified: team/murf/newcdr/configs/cel_custom.conf.sample
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/configs/cel_custom.conf.sample?view=diff&rev=62094&r1=62093&r2=62094
==============================================================================
--- team/murf/newcdr/configs/cel_custom.conf.sample (original)
+++ team/murf/newcdr/configs/cel_custom.conf.sample Thu Apr 26 23:09:43 2007
@@ -6,5 +6,5 @@
 ; 
 ;
 ;[mappings]
-;Master.csv => "${CEL(eventtype)}","${CEL(eventname)}","${CEL(eventtime)}","${CEL(clid)}","${CEL(src)}","${CEL(exten)}","${CEL(context)}","${CEL(channel)}","${CEL(app)}","${CEL(appdata)}","${CEL(disposition)}","${CEL(amaflags)}","${CEL(accountcode)}","${CEL(uniqueid)}","${CEL(userfield)}"
+;Master.csv => "${CEL(eventtype)}","${CEL(eventname)}","${CEL(eventtime)}","${CEL(clid)}","${CEL(clidnum)}","${CEL(exten)}","${CEL(context)}","${CEL(channel)}","${CEL(app)}","${CEL(appdata)}","${CEL(amaflags)}","${CEL(accountcode)}","${CEL(uniqueid)}"
 

Added: team/murf/newcdr/funcs/func_cel.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/funcs/func_cel.c?view=auto&rev=62094
==============================================================================
--- team/murf/newcdr/funcs/func_cel.c (added)
+++ team/murf/newcdr/funcs/func_cel.c Thu Apr 26 23:09:43 2007
@@ -1,0 +1,160 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Portions Copyright (C) 2005, Anthony Minessale II
+ *
+ * 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  Call Detail Record related dialplan functions
+ *
+ * \author Steve Murphy, using basis from:
+ * \author Anthony Minessale II 
+ *
+ * \ingroup functions
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/logger.h"
+#include "asterisk/utils.h"
+#include "asterisk/app.h"
+#include "asterisk/cel.h"
+
+enum {
+	OPT_RECURSIVE = (1 << 0),
+	OPT_UNPARSED = (1 << 1),
+	OPT_LAST = (1 << 2),
+} cel_option_flags;
+
+AST_APP_OPTIONS(cel_func_options, {
+	AST_APP_OPTION('u', OPT_UNPARSED),
+});
+
+static int cel_read(struct ast_channel *chan, const char *cmd, char *parse,
+		    char *buf, size_t len)
+{
+	char *ret;
+	struct ast_flags flags = { 0 };
+	struct ast_cel *cel = chan ? chan->cel : NULL;
+	AST_DECLARE_APP_ARGS(args,
+			     AST_APP_ARG(variable);
+			     AST_APP_ARG(options);
+	);
+
+	if (ast_strlen_zero(parse))
+		return -1;
+
+	if (!cel)
+		return -1;
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (!ast_strlen_zero(args.options))
+		ast_app_parse_options(cel_func_options, &flags, NULL, args.options);
+
+	ast_cel_getvar(cel, args.variable, &ret, buf, len,
+			   ast_test_flag(&flags, OPT_UNPARSED));
+
+	return 0;
+}
+
+static int cel_write(struct ast_channel *chan, const char *cmd, char *parse,
+		     const char *value)
+{
+	struct ast_flags flags = { 0 };
+	AST_DECLARE_APP_ARGS(args,
+			     AST_APP_ARG(variable);
+			     AST_APP_ARG(options);
+	);
+
+	if (ast_strlen_zero(parse) || !value || !chan)
+		return -1;
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (!ast_strlen_zero(args.options))
+		ast_app_parse_options(cel_func_options, &flags, NULL, args.options);
+
+	if (!strcasecmp(args.variable, "accountcode"))
+		ast_cel_setaccount(chan, value);
+	else if (!strcasecmp(args.variable, "amaflags"))
+		ast_cel_setamaflags(chan, value);
+	else
+		ast_cel_setvar(chan->cel, args.variable, value, ast_test_flag(&flags, OPT_RECURSIVE));
+		/* No need to worry about the u flag, as all fields for which setting
+		 * 'u' would do anything are marked as readonly. */
+
+	return 0;
+}
+
+static struct ast_custom_function cel_function = {
+	.name = "CEL",
+	.synopsis = "Gets or sets a CEL variable",
+	.syntax = "CEL(<name>[|options])",
+	.read = cel_read,
+	.write = cel_write,
+	.desc =
+"Options:\n"
+"  'u' retrieves the raw, unprocessed value\n"
+"  For example, 'eventtime', will be retrieved as epoch\n"
+"  values, when the 'u' option is passed, but formatted as YYYY-MM-DD HH:MM:SS\n"
+"  otherwise.  Similarly, disposition and amaflags will return their raw\n"
+"  integral values.\n"
+"  For the most part, these are channel fields; in some cases, info specific\n"
+"   to the Channel Event will be stored into the channel variables for the possible\n"
+"   use of the various CEL backends. These are not readable, or modifiable except by\n"
+"     eventtime = epoch value (raw) of the time the event occurred.\n"
+"     eventtype = an ascii string representing the type of event\n"
+"     usereventname = if eventtype = USER_EVENT, then this field\n"
+"                     contains the designated name of the event\n"
+"  Here is a list of all the available channel field names:\n"
+"    clid          appdata\n"
+"    clidnum       amaflags\n"
+"    exten         accountcode\n"
+"    context       uniqueid\n"
+"    channel       app\n"
+"  All of the above variables are read-only, except for accountcode,\n"
+"  and amaflags. You may, however,  supply\n"
+"  a name not on the above list, and create your own\n"
+"  variable, whose value can be changed with this function,\n"
+"  and this variable will be stored on the channel.\n"
+"    raw values for amaflags:\n"
+"       1 = OMIT\n"
+"       2 = BILLING\n"
+"       3 = DOCUMENTATION\n",
+};
+
+static int unload_module(void)
+{
+	return ast_custom_function_unregister(&cel_function);
+}
+
+static int load_module(void)
+{
+	return ast_custom_function_register(&cel_function);
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "CEL dialplan function");

Propchange: team/murf/newcdr/funcs/func_cel.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/newcdr/funcs/func_cel.c
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/newcdr/funcs/func_cel.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/murf/newcdr/include/asterisk/cel.h
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/include/asterisk/cel.h?view=diff&rev=62094&r1=62093&r2=62094
==============================================================================
--- team/murf/newcdr/include/asterisk/cel.h (original)
+++ team/murf/newcdr/include/asterisk/cel.h Thu Apr 26 23:09:43 2007
@@ -36,6 +36,7 @@
 /* Include channel.h after relevant declarations it will need */
 #include "asterisk/channel.h"
 #include "asterisk/utils.h"
+#include "asterisk/event.h"
 
 enum ast_cel_eventtype {
 	/*! channel birth */
@@ -70,46 +71,22 @@
 	
 /*! Responsible for call detail data */
 struct ast_cel {
+	/*! the channel involved */
+	struct ast_channel *chan;
 	/*! At what time did this event occur? */
 	struct timeval eventtime;
 	/*! wha' happened? */
 	enum ast_cel_eventtype eventtype;
 	/*! Which userEvent? */
 	char usereventname[AST_MAX_EXTENSION];
-	/*! Caller*ID with text */
-	char clid[AST_MAX_EXTENSION];
-	/*! Caller*ID number */
-	char clidnum[AST_MAX_EXTENSION];		
-	/*! Extension */
-	char exten[AST_MAX_EXTENSION];		
-	/*! Context */
-	char context[AST_MAX_EXTENSION];	
-	/*! Channel name */
-	char channel[AST_MAX_EXTENSION];
-
-	/*! Application if appropriate */
-	char app[AST_MAX_EXTENSION];	
-	/*! Last application data/args */
-	char appdata[AST_MAX_EXTENSION];	
-	
-	/*! What flags to use */
-	long int amaflags;				
-	/*! What account number to use */
-	char accountcode[AST_MAX_ACCOUNT_CODE];			
-	/* Unique Channel Identifier */
-	char uniqueid[32];
-	/* User field */
-	char userfield[AST_MAX_USER_FIELD];
-
-	/* A linked list for variables */
-	struct varshead varshead;
+	/* we got rid of userfield in favor of just plain vars */
 };
 
 /*! \brief Return TRUE if CDR subsystem is enabled */
 int check_cel_enabled(void);
 
-/*! \brief Allocate a CDR record 
- * Returns a malloc'd ast_cdr structure, returns NULL on error (malloc failure)
+/*! \brief Allocate a CEL record 
+ * Returns a malloc'd ast_cel structure, returns NULL on error (malloc failure)
  */
 struct ast_cdr *ast_cel_alloc(void);
 

Modified: team/murf/newcdr/main/cel.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/main/cel.c?view=diff&rev=62094&r1=62093&r2=62094
==============================================================================
--- team/murf/newcdr/main/cel.c (original)
+++ team/murf/newcdr/main/cel.c Thu Apr 26 23:09:43 2007
@@ -168,10 +168,102 @@
 	return "Unknown";
 }
 
-void ast_cel_destroy(struct ast_cel *cel)
-{
-	ast_cdr_free_vars(cdr, 0);
-}
+int ast_cel_setaccount(struct ast_channel *chan, const char *account)
+{
+
+	ast_string_field_set(chan, accountcode, account);
+	return 0;
+}
+
+int ast_cel_setamaflags(struct ast_channel *chan, const char *flag)
+{
+	int newflag = ast_cel_amaflags2int(flag);
+	chan->amaflags = newflag;
+	return 0;
+}
+
+int ast_cel_amaflags2int(const char *flag)
+{
+	if (!strcasecmp(flag, "default"))
+		return 0;
+	if (!strcasecmp(flag, "omit"))
+		return AST_CDR_OMIT;
+	if (!strcasecmp(flag, "billing"))
+		return AST_CDR_BILLING;
+	if (!strcasecmp(flag, "documentation"))
+		return AST_CDR_DOCUMENTATION;
+	return -1;
+}
+
+static const char *ast_cel_getvar_internal(struct ast_channel *chan, const char *name) 
+{
+	struct ast_var_t *variables;
+	struct varshead *headp = &chan->varshead;
+	
+	if (ast_strlen_zero(name))
+		return NULL;
+
+	AST_LIST_TRAVERSE(headp, variables, entries) {
+		if (!strcasecmp(name, ast_var_name(variables)))
+			return ast_var_value(variables);
+	}
+	
+	return NULL;
+}
+
+/*! CDR channel variable retrieval */
+void ast_cel_getvar(struct ast_channel *chan, const char *name, char **ret, char *workspace, int workspacelen, int raw) 
+{
+	const char *fmt = "%Y-%m-%d %T";
+	const char *varbuf;
+
+	if (!chan)  /* don't die if the cdr is null */
+		return;
+
+	*ret = NULL;
+
+	if (!strcasecmp(name, "clid"))
+		ast_copy_string(workspace, chan->cid->cid_name, workspacelen);
+	else if (!strcasecmp(name, "clidnum"))
+		ast_copy_string(workspace, chan->cid->cid_num, workspacelen);
+	else if (!strcasecmp(name, "clidani"))
+		ast_copy_string(workspace, chan->cid->cid_ani, workspacelen);
+	else if (!strcasecmp(name, "clidrdnis"))
+		ast_copy_string(workspace, chan->cid->cid_rdnis, workspacelen);
+	else if (!strcasecmp(name, "exten"))
+		ast_copy_string(workspace, chan->exten, workspacelen);
+	else if (!strcasecmp(name, "context"))
+		ast_copy_string(workspace, chan->context, workspacelen);
+	else if (!strcasecmp(name, "channel"))
+		ast_copy_string(workspace, chan->name, workspacelen);
+	else if (!strcasecmp(name, "app"))
+		ast_copy_string(workspace, chan->appl, workspacelen);
+	else if (!strcasecmp(name, "appdata"))
+		ast_copy_string(workspace, chan->data, workspacelen);
+	} else if (!strcasecmp(name, "amaflags")) {
+		if (raw) {
+			snprintf(workspace, workspacelen, "%ld", chan->amaflags);
+		} else {
+			ast_copy_string(workspace, ast_cel_flags2str(chan->amaflags), workspacelen);
+		}
+	} else if (!strcasecmp(name, "accountcode"))
+		ast_copy_string(workspace, chan->accountcode, workspacelen);
+	else if (!strcasecmp(name, "uniqueid"))
+		ast_copy_string(workspace, chan->uniqueid, workspacelen);
+	else if ((varbuf = ast_cel_getvar_internal(chan, name)))
+		ast_copy_string(workspace, varbuf, workspacelen);
+	else
+		workspace[0] = '\0';
+
+	if (!ast_strlen_zero(workspace))
+		*ret = workspace;
+}
+
+/* readonly channel variables */
+static	const char *cel_readonly_vars[] = { "clid", "clidnum", "exten", "context", "channel",
+											"app", "appdata", "eventtype", "eventname", "usereventname",
+											"uniqueid",
+											NULL };
 
 /*! Frees the cel struct */
 void ast_cel_destroy(struct ast_cel *cel)
@@ -179,3 +271,4 @@
 	ast_cel_free_vars(cel, 0);
 	free(cel);
 }
+



More information about the asterisk-commits mailing list