[svn-commits] murf: branch murf/newcdr r62217 - in /team/murf/newcdr: cel/ funcs/ include/a...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Apr 27 11:20:35 MST 2007


Author: murf
Date: Fri Apr 27 13:20:35 2007
New Revision: 62217

URL: http://svn.digium.com/view/asterisk?view=rev&rev=62217
Log:
Phase I almost complete-- have some code to add to flesh out the event restrictions in the config file, then the next phase (actually generate the events) can be done; at least, the backends are all roughed in now

Modified:
    team/murf/newcdr/cel/cel_csv.c
    team/murf/newcdr/cel/cel_custom.c
    team/murf/newcdr/cel/cel_manager.c
    team/murf/newcdr/cel/cel_odbc.c
    team/murf/newcdr/cel/cel_pgsql.c
    team/murf/newcdr/cel/cel_radius.c
    team/murf/newcdr/cel/cel_sqlite.c
    team/murf/newcdr/cel/cel_sqlite3_custom.c
    team/murf/newcdr/cel/cel_tds.c
    team/murf/newcdr/funcs/func_cel.c
    team/murf/newcdr/include/asterisk/cel.h
    team/murf/newcdr/include/asterisk/event.h
    team/murf/newcdr/main/Makefile
    team/murf/newcdr/main/cdr.c
    team/murf/newcdr/main/cel.c
    team/murf/newcdr/main/event.c

Modified: team/murf/newcdr/cel/cel_csv.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_csv.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_csv.c (original)
+++ team/murf/newcdr/cel/cel_csv.c Fri Apr 27 13:20:35 2007
@@ -273,6 +273,7 @@
 	struct ast_cel *cel;
 	
 	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
+	cel_set_backend_channel_vars(cel);
 	snprintf(csvmaster, sizeof(csvmaster),"%s/%s/%s", ast_config_AST_LOG_DIR, CSV_LOG_DIR, CSV_MASTER);
 #if 0
 	printf("[CDR] %s ('%s' -> '%s') Dur: %ds Bill: %ds Disp: %s Flags: %s Account: [%s]\n", cel->channel, cel->src, cel->dst, cel->duration, cel->billsec, ast_cel_disp2str(cel->disposition), ast_cel_flags2str(cel->amaflags), cel->accountcode);

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=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_custom.c (original)
+++ team/murf/newcdr/cel/cel_custom.c Fri Apr 27 13:20:35 2007
@@ -115,6 +115,7 @@
 		return 0;
 
 	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
+	cel_set_backend_channel_vars(cel);
 	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 */

Modified: team/murf/newcdr/cel/cel_manager.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_manager.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_manager.c (original)
+++ team/murf/newcdr/cel/cel_manager.c Fri Apr 27 13:20:35 2007
@@ -100,6 +100,7 @@
 		return 0;
 
 	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
+	cel_set_backend_channel_vars(cel);
 	t = cel->start.tv_sec;
 	localtime_r(&t, &timeresult);
 	strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);

Modified: team/murf/newcdr/cel/cel_odbc.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_odbc.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_odbc.c (original)
+++ team/murf/newcdr/cel/cel_odbc.c Fri Apr 27 13:20:35 2007
@@ -100,6 +100,7 @@
 	struct ast_cel *cel = 0;
 
 	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
+	cel_set_backend_channel_vars(cel);
 	if (usegmtime) 
 		gmtime_r(&cel->start.tv_sec,&tm);
 	else

Modified: team/murf/newcdr/cel/cel_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_pgsql.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_pgsql.c (original)
+++ team/murf/newcdr/cel/cel_pgsql.c Fri Apr 27 13:20:35 2007
@@ -83,6 +83,7 @@
 	struct ast_cel *cel = 0;
 	
 	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
+	cel_set_backend_channel_vars(cel);
 	ast_mutex_lock(&pgsql_lock);
 
 	localtime_r(&cel->start.tv_sec,&tm);

Modified: team/murf/newcdr/cel/cel_radius.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_radius.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_radius.c (original)
+++ team/murf/newcdr/cel/cel_radius.c Fri Apr 27 13:20:35 2007
@@ -220,6 +220,7 @@
 	struct ast_cel *cel = 0;
 	
 	cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
+	cel_set_backend_channel_vars(cel);
 
 	if (build_radius_record(&send, cel)) {
 		if (option_debug)

Modified: team/murf/newcdr/cel/cel_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_sqlite.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_sqlite.c (original)
+++ team/murf/newcdr/cel/cel_sqlite.c Fri Apr 27 13:20:35 2007
@@ -106,6 +106,7 @@
 	int count;
 	struct ast_cel *cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
 
+	cel_set_backend_channel_vars(cel);
 	ast_mutex_lock(&sqlite_lock);
 
 	t = cel->start.tv_sec;

Modified: team/murf/newcdr/cel/cel_sqlite3_custom.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_sqlite3_custom.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_sqlite3_custom.c (original)
+++ team/murf/newcdr/cel/cel_sqlite3_custom.c Fri Apr 27 13:20:35 2007
@@ -163,6 +163,7 @@
 	{ /* Make it obvious that only sql_cmd should be used outside of this block */
 		char *sql_tmp_cmd;
 		char sql_insert_cmd[2048] = "";
+		cel_set_backend_channel_vars(cel);
 		sql_tmp_cmd = sqlite3_mprintf("INSERT INTO %q (%q) VALUES (%q)", table, columns, values);
 		dummy.cel = cel;
 		pbx_substitute_variables_helper(&dummy, sql_tmp_cmd, sql_insert_cmd, sizeof(sql_insert_cmd) - 1);

Modified: team/murf/newcdr/cel/cel_tds.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/cel/cel_tds.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/cel/cel_tds.c (original)
+++ team/murf/newcdr/cel/cel_tds.c Fri Apr 27 13:20:35 2007
@@ -120,6 +120,7 @@
 #endif
 	struct ast_cel *cel = ast_event_get_ie_raw(event, AST_EVENT_IE_CELPTR);
 
+	cel_set_backend_channel_vars(cel);
 	ast_mutex_lock(&tds_lock);
 
 	memset(sqlcmd, 0, 2048);

Modified: team/murf/newcdr/funcs/func_cel.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/funcs/func_cel.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/funcs/func_cel.c (original)
+++ team/murf/newcdr/funcs/func_cel.c Fri Apr 27 13:20:35 2007
@@ -58,7 +58,6 @@
 {
 	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);
@@ -67,7 +66,7 @@
 	if (ast_strlen_zero(parse))
 		return -1;
 
-	if (!cel)
+	if (!chan)
 		return -1;
 
 	AST_STANDARD_APP_ARGS(args, parse);
@@ -75,7 +74,7 @@
 	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_cel_getvar(chan, args.variable, &ret, buf, len,
 			   ast_test_flag(&flags, OPT_UNPARSED));
 
 	return 0;
@@ -103,7 +102,7 @@
 	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));
+		ast_cel_setvar(chan, args.variable, value);
 		/* No need to worry about the u flag, as all fields for which setting
 		 * 'u' would do anything are marked as readonly. */
 
@@ -112,7 +111,7 @@
 
 static struct ast_custom_function cel_function = {
 	.name = "CEL",
-	.synopsis = "Gets or sets a CEL variable",
+	.synopsis = "Gets or sets a CEL related channel variable or field",
 	.syntax = "CEL(<name>[|options])",
 	.read = cel_read,
 	.write = cel_write,

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=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/include/asterisk/cel.h (original)
+++ team/murf/newcdr/include/asterisk/cel.h Fri Apr 27 13:20:35 2007
@@ -26,9 +26,9 @@
 #include <sys/time.h>
 
 /*! AMA Flags */
-#define AST_CDR_OMIT				(1)
-#define AST_CDR_BILLING				(2)
-#define AST_CDR_DOCUMENTATION			(3)
+#define AST_CEL_OMIT				(1)
+#define AST_CEL_BILLING				(2)
+#define AST_CEL_DOCUMENTATION			(3)
 
 #define AST_MAX_USER_FIELD			256
 #define AST_MAX_ACCOUNT_CODE			20
@@ -88,12 +88,40 @@
 /*! \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);
+struct ast_cel *ast_cel_alloc(void);
+
+char *ast_cel_eventtype2str(enum ast_cel_eventtype eventtype);
+
+/*! Converts AMA flag to printable string */
+char *ast_cel_flags2str(int flag);
+
+
+int ast_cel_setaccount(struct ast_channel *chan, const char *account);
+
+int ast_cel_setamaflags(struct ast_channel *chan, const char *flag);
+
+int ast_cel_amaflags2int(const char *flag);
+
+/*! CEL channel variable retrieval */
+void ast_cel_getvar(struct ast_channel *chan, const char *name, char **ret, char *workspace, int workspacelen, int raw) ;
+
+/*! Set a CEL channel variable 
+	\note You can't set the CEL variables that are managed by the PBX
+*/
+int ast_cel_setvar(struct ast_channel *chan, const char *name, const char *value);
+
+
+void cel_set_backend_channel_vars(struct ast_cel *cel);
+
+/*! Frees the cel struct */
+void ast_cel_destroy(struct ast_cel *cel);
+
+void ast_cel_report_event(struct ast_channel *chan, enum ast_cel_eventtype);
 
 
 extern int cel_default_amaflags;
-
 extern char cel_default_accountcode[AST_MAX_ACCOUNT_CODE];
+int ast_cel_engine_init(void);
 
 
 #endif /* _ASTERISK_CDR_H */

Modified: team/murf/newcdr/include/asterisk/event.h
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/include/asterisk/event.h?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/include/asterisk/event.h (original)
+++ team/murf/newcdr/include/asterisk/event.h Fri Apr 27 13:20:35 2007
@@ -75,7 +75,7 @@
  * pointer to the peer.
  */
 struct ast_event_sub *ast_event_subscribe(enum ast_event_type event_type, 
-	ast_event_cb_t cb, void *userdata, ...);
+										  ast_event_cb_t cb, char *description, void *userdata, ...);
 
 /*!
  * \brief Un-subscribe from events
@@ -86,6 +86,30 @@
  * \return Nothing
  */
 void ast_event_unsubscribe(struct ast_event_sub *event_sub);
+
+/*!
+ * \brief Traverse subscribers
+ *
+ * \param et -- the event type.
+ * \param curr -- the current subscriber in the list; NULL means to return the first.
+ * 
+ * \return a ptr to the next subscriber
+ */
+
+struct ast_event_sub *ast_event_next_subscriber(enum ast_event_type et, struct ast_event_sub *curr);
+
+/*!
+ * \brief Get the subscriber description
+ *
+ * \param curr -- the subscriber who's description is sought.
+ * 
+ * \return a string
+ */
+
+char *ast_event_subscriber_get_description(struct ast_event_sub *curr);
+
+void ast_event_lock_subscribers(enum ast_event_type et);
+void ast_event_unlock_subscribers(enum ast_event_type et);
 
 /*!
  * \brief Check if subscribers exist
@@ -385,4 +409,7 @@
  */
 enum ast_event_type ast_event_get_type(const struct ast_event *event);
 
+void ast_event_init(void);
+
+
 #endif /* AST_EVENT_H */

Modified: team/murf/newcdr/main/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/main/Makefile?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/main/Makefile (original)
+++ team/murf/newcdr/main/Makefile Fri Apr 27 13:20:35 2007
@@ -20,7 +20,7 @@
 OBJS=	io.o sched.o logger.o frame.o loader.o config.o channel.o \
 	translate.o file.o pbx.o cli.o md5.o term.o \
 	ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
-	cdr.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
+	cdr.o cel.o event.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
 	dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
 	astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
 	utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \

Modified: team/murf/newcdr/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/main/cdr.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/main/cdr.c (original)
+++ team/murf/newcdr/main/cdr.c Fri Apr 27 13:20:35 2007
@@ -298,9 +298,6 @@
 	struct varshead *headp;
 	int x;
 	
-	if (!cdr)  /* don't die if the cdr is null */
-		return -1;
-	
 	for (x = 0; cdr_readonly_vars[x]; x++) {
 		if (!strcasecmp(name, cdr_readonly_vars[x])) {
 			ast_log(LOG_ERROR, "Attempt to set the '%s' read-only variable!.\n", name);

Modified: team/murf/newcdr/main/cel.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/main/cel.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/main/cel.c (original)
+++ team/murf/newcdr/main/cel.c Fri Apr 27 13:20:35 2007
@@ -72,6 +72,33 @@
 	return x;
 }
 
+static int handle_cli_status(int fd, int argc, char *argv[])
+{
+	struct ast_event_sub *sub = 0;
+	
+	if (argc > 2)
+		return RESULT_SHOWUSAGE;
+
+	ast_cli(fd, "CEL logging: %s\n", cel_enabled ? "enabled" : "disabled");
+	
+	if (cel_enabled) {
+		ast_event_lock_subscribers(AST_EVENT_CEL);
+		while ((sub=ast_event_next_subscriber(AST_EVENT_CEL, sub))) {
+			ast_cli(fd, "CEL registered backend: %s\n", ast_event_subscriber_get_description(sub));
+		}
+		ast_event_unlock_subscribers(AST_EVENT_CEL);
+	}
+
+	return 0;
+}
+
+static struct ast_cli_entry cli_status = {
+	{ "cel", "status", NULL },
+	handle_cli_status, "Display the CEL status",
+	"Usage: cel status\n"
+	"	Displays the Channel Event Logging system status.\n"
+};
+
 
 static int do_reload(void)
 {
@@ -85,11 +112,11 @@
 
 	if ((config = ast_config_load("cel.conf"))) {
 		if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
-			enabled = ast_true(enabled_value);
-		}
-	}
-
-	if (enabled) {
+			cel_enabled = ast_true(enabled_value);
+		}
+	}
+
+	if (cel_enabled) {
 		ast_log(LOG_NOTICE, "CEL logging enabled.\n");
 	} else {
 		ast_log(LOG_NOTICE, "CEL logging disabled.\n");
@@ -98,25 +125,6 @@
 	ast_config_destroy(config);
 
 	return res;
-}
-
-static int handle_cli_status(int fd, int argc, char *argv[])
-{
-	int cnt=0;
-
-	if (argc > 2)
-		return RESULT_SHOWUSAGE;
-
-	ast_cli(fd, "CEL logging: %s\n", enabled ? "enabled" : "disabled");
-	if (enabled) {
-		AST_LIST_LOCK(&be_list);
-		AST_LIST_TRAVERSE(&be_list, beitem, list) {
-			ast_cli(fd, "CEL registered backend: %s\n", beitem->name);
-		}
-		AST_LIST_UNLOCK(&be_list);
-	}
-
-	return 0;
 }
 
 char *ast_cel_eventtype2str(enum ast_cel_eventtype eventtype)
@@ -152,6 +160,7 @@
 	case CEL_USER_DEFINED:
 		return "EV_USER_DEF";
 	}
+	return "";
 }
 
 /*! Converts AMA flag to printable string */
@@ -179,6 +188,53 @@
 {
 	int newflag = ast_cel_amaflags2int(flag);
 	chan->amaflags = newflag;
+	return 0;
+}
+
+/* readonly channel variables */
+static	const char *cel_readonly_vars[] = { "clid", "clidnum", "clidani", "clidrdnis", "exten", "context", "channel",
+											"app", "appdata", "eventtype", "eventname",
+											"uniqueid",
+											NULL };
+
+
+/*! Set a CEL channel variable 
+	\note You can't set the CEL variables that are managed by the PBX
+*/
+int ast_cel_setvar(struct ast_channel *chan, const char *name, const char *value) 
+{
+	struct ast_var_t *newvariable;
+	struct varshead *headp;
+	int x;
+	
+	for (x = 0; cel_readonly_vars[x]; x++) {
+		if (!strcasecmp(name, cel_readonly_vars[x])) {
+			ast_log(LOG_ERROR, "Attempt to set the '%s' read-only variable!.\n", name);
+			return -1;
+		}
+	}
+
+	if (!chan) {
+		ast_log(LOG_ERROR, "Attempt to set a variable on a NULL Channel.\n");
+		return -1;
+	}
+
+	headp = &chan->varshead;
+	AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
+		if (!strcasecmp(ast_var_name(newvariable), name)) {
+			/* there is already such a variable, delete it */
+			AST_LIST_REMOVE_CURRENT(headp, entries);
+			ast_var_delete(newvariable);
+			break;
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+
+	if (value) {
+		newvariable = ast_var_assign(name, value);
+		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
+	}
+
 	return 0;
 }
 
@@ -195,6 +251,20 @@
 	return -1;
 }
 
+static void cel_get_tv(struct timeval tv, const char *fmt, char *buf, int bufsize)
+{
+	if (fmt == NULL) {	/* raw mode */
+		snprintf(buf, bufsize, "%ld.%06ld", (long)tv.tv_sec, (long)tv.tv_usec);
+	} else {  
+		time_t t = tv.tv_sec;
+		if (t) {
+			struct tm tm;
+			localtime_r(&t, &tm);
+			strftime(buf, bufsize, fmt, &tm);
+		}
+	}
+}
+
 static const char *ast_cel_getvar_internal(struct ast_channel *chan, const char *name) 
 {
 	struct ast_var_t *variables;
@@ -211,7 +281,7 @@
 	return NULL;
 }
 
-/*! CDR channel variable retrieval */
+/*! CEL 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";
@@ -223,13 +293,13 @@
 	*ret = NULL;
 
 	if (!strcasecmp(name, "clid"))
-		ast_copy_string(workspace, chan->cid->cid_name, workspacelen);
+		ast_copy_string(workspace, chan->cid.cid_name, workspacelen);
 	else if (!strcasecmp(name, "clidnum"))
-		ast_copy_string(workspace, chan->cid->cid_num, workspacelen);
+		ast_copy_string(workspace, chan->cid.cid_num, workspacelen);
 	else if (!strcasecmp(name, "clidani"))
-		ast_copy_string(workspace, chan->cid->cid_ani, workspacelen);
+		ast_copy_string(workspace, chan->cid.cid_ani, workspacelen);
 	else if (!strcasecmp(name, "clidrdnis"))
-		ast_copy_string(workspace, chan->cid->cid_rdnis, workspacelen);
+		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"))
@@ -240,9 +310,28 @@
 		ast_copy_string(workspace, chan->appl, workspacelen);
 	else if (!strcasecmp(name, "appdata"))
 		ast_copy_string(workspace, chan->data, workspacelen);
+	else if (!strcasecmp(name, "eventtime")) { /* only available to the backends, and needs special handling via raw */
+		struct ast_var_t *variables;
+		struct varshead *headp = &chan->varshead;
+		const char *t2=0;
+		struct timeval tv2;
+		
+		AST_LIST_TRAVERSE(headp, variables, entries) {
+			if (!strcasecmp(name, ast_var_name(variables))) {
+				t2 = ast_var_value(variables);
+				break;
+			}
+		}
+		if (raw)
+			ast_copy_string(workspace, t2 ? t2 : "",  workspacelen);
+		else {
+			tv2.tv_sec = atoi(t2);
+			cel_get_tv(tv2, fmt, workspace, workspacelen);
+		}
+		
 	} else if (!strcasecmp(name, "amaflags")) {
 		if (raw) {
-			snprintf(workspace, workspacelen, "%ld", chan->amaflags);
+			snprintf(workspace, workspacelen, "%d", chan->amaflags);
 		} else {
 			ast_copy_string(workspace, ast_cel_flags2str(chan->amaflags), workspacelen);
 		}
@@ -259,16 +348,82 @@
 		*ret = workspace;
 }
 
-/* readonly channel variables */
-static	const char *cel_readonly_vars[] = { "clid", "clidnum", "exten", "context", "channel",
-											"app", "appdata", "eventtype", "eventname", "usereventname",
-											"uniqueid",
-											NULL };
+void cel_set_backend_channel_vars(struct ast_cel *cel)
+{
+	/* set the eventtime, eventtype fields */
+
+	struct ast_var_t *newvariable;
+	struct varshead *headp;
+	char timebuf[30];
+
+	/* first, remove existing vars of those names */
+	headp = &cel->chan->varshead;
+	AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
+		if (!strcasecmp(ast_var_name(newvariable), "eventtime")) {
+			/* there is already such a variable, delete it */
+			AST_LIST_REMOVE_CURRENT(headp, entries);
+			ast_var_delete(newvariable);
+			continue;
+		}
+		if (!strcasecmp(ast_var_name(newvariable), "eventtype")) {
+			/* there is already such a variable, delete it */
+			AST_LIST_REMOVE_CURRENT(headp, entries);
+			ast_var_delete(newvariable);
+			continue;
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+	
+	/* next, insert them */
+	if (cel->eventtype == CEL_USER_DEFINED)
+		newvariable = ast_var_assign("eventtype", cel->usereventname);
+	else
+		newvariable = ast_var_assign("eventtype", ast_cel_eventtype2str(cel->eventtype));
+	AST_LIST_INSERT_HEAD(headp, newvariable, entries);
+	
+	snprintf(timebuf, sizeof(timebuf), "%ld", cel->eventtime.tv_sec);
+	newvariable = ast_var_assign("eventtime", timebuf);
+	AST_LIST_INSERT_HEAD(headp, newvariable, entries);
+}
+
 
 /*! Frees the cel struct */
 void ast_cel_destroy(struct ast_cel *cel)
 {
-	ast_cel_free_vars(cel, 0);
 	free(cel);
 }
 
+void ast_cel_report_event(struct ast_channel *chan, enum ast_cel_eventtype eventtype)
+{
+	struct ast_cel *cel = ast_cel_alloc();
+	struct ast_event *ev;
+	
+	if (!cel)
+		return;
+	
+	cel->chan = chan;
+	cel->eventtype = eventtype;
+	cel->usereventname[0] = 0;
+	cel->eventtime = ast_tvnow();
+	
+	/* now, report this event */
+	ev = ast_event_new(AST_EVENT_CEL, 
+					   AST_EVENT_IE_CELPTR, AST_EVENT_IE_PLTYPE_PTR, cel,
+					   AST_EVENT_IE_END);
+	if (!ev) {
+		free(cel);
+		return;
+	}
+	ast_event_queue(ev); /* a lot of stuff happens here */
+}
+
+int ast_cel_engine_init(void)
+{
+	int res;
+
+	ast_cli_register(&cli_status);
+
+	res = do_reload();
+
+	return res;
+}

Modified: team/murf/newcdr/main/event.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/main/event.c?view=diff&rev=62217&r1=62216&r2=62217
==============================================================================
--- team/murf/newcdr/main/event.c (original)
+++ team/murf/newcdr/main/event.c Fri Apr 27 13:20:35 2007
@@ -88,6 +88,7 @@
 struct ast_event_sub {
 	enum ast_event_type type;
 	ast_event_cb_t cb;
+	char description[20];
 	void *userdata;
 	uint32_t uniqueid;
 	AST_LIST_HEAD_NOLOCK(, ast_event_ie_val) ie_vals;
@@ -225,6 +226,9 @@
 			case AST_EVENT_IE_PLTYPE_STR:
 				ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
 				break;
+			case AST_EVENT_IE_PLTYPE_PTR:
+				ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.str, sizeof(ie_val->payload.str));
+				break;
 			}
 			if (!event)
 				break;
@@ -241,7 +245,7 @@
 }
 
 struct ast_event_sub *ast_event_subscribe(enum ast_event_type type, ast_event_cb_t cb, 
-	void *userdata, ...)
+										  char *description, void *userdata, ...)
 {
 	va_list ap;
 	enum ast_event_ie_type ie_type;
@@ -255,7 +259,8 @@
 
 	if (!(sub = ast_calloc(1, sizeof(*sub))))
 		return NULL;
-
+	ast_copy_string(sub->description, description, sizeof(sub->description));
+	
 	va_start(ap, userdata);
 	for (ie_type = va_arg(ap, enum ast_event_type);
 		ie_type != AST_EVENT_IE_END;
@@ -304,6 +309,9 @@
 			case AST_EVENT_IE_PLTYPE_STR:
 				ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
 				break;
+			case AST_EVENT_IE_PLTYPE_PTR:
+				ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.str, sizeof(ie_val->payload.str));
+				break;
 			}
 			if (!event)
 				break;
@@ -329,6 +337,33 @@
 
 	free(sub);
 }
+
+struct ast_event_sub *ast_event_next_subscriber(enum ast_event_type et, struct ast_event_sub *curr)
+{
+	if (curr)
+		return AST_RWLIST_NEXT(curr, entry);
+	else
+		return AST_RWLIST_FIRST(&ast_event_subs[et]);
+}
+
+char *ast_event_subscriber_get_description(struct ast_event_sub *curr)
+{
+	if (curr)
+		return curr->description;
+	return 0;
+}
+
+void ast_event_lock_subscribers(enum ast_event_type et)
+{
+	AST_RWLIST_RDLOCK(&ast_event_subs[et]);
+
+}
+
+void ast_event_unlock_subscribers(enum ast_event_type et)
+{
+	AST_RWLIST_UNLOCK(&ast_event_subs[et]);
+}
+
 
 void ast_event_unsubscribe(struct ast_event_sub *sub)
 {



More information about the svn-commits mailing list