[asterisk-commits] murf: branch murf/newcdr r62495 - in /team/murf/newcdr: configs/ include/aste...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue May 1 07:05:44 MST 2007


Author: murf
Date: Tue May  1 09:05:43 2007
New Revision: 62495

URL: http://svn.digium.com/view/asterisk?view=rev&rev=62495
Log:
compiles again; added code to process config info, and use it for pre-filtering events

Modified:
    team/murf/newcdr/configs/cel.conf.sample
    team/murf/newcdr/include/asterisk/cel.h
    team/murf/newcdr/main/Makefile
    team/murf/newcdr/main/cel.c

Modified: team/murf/newcdr/configs/cel.conf.sample
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/configs/cel.conf.sample?view=diff&rev=62495&r1=62494&r2=62495
==============================================================================
--- team/murf/newcdr/configs/cel.conf.sample (original)
+++ team/murf/newcdr/configs/cel.conf.sample Tue May  1 09:05:43 2007
@@ -29,19 +29,18 @@
 ;       CHAN_START  -- The time a channel was created
 ;       CHAN_END    -- The time a channel was terminated
 ;       ANSWER  -- The time a channel was answered (ie, phone taken off-hook, etc)
+;       HANGUP -- The time at which a hangup occurred.
 ;       CONF_ENTER   -- The time a channel was connected into a conference room
 ;       CONF_EXIT    -- The time a channel was removed from a conference room
 ;       APP_START    -- The time a tracked app was started
 ;       APP_END      -- the time a tracked app ended.
+;       PARK_START   -- The time a call was parked
+;       PARK_END    
 ;       USER_EVENT  ; these are triggered from the dialplan, and have a name.
 
-events= APP_START, CHAN_START, CHAN_END, CHAN_ANSWER
+events= APP_START, CHAN_START, CHAN_END, ANSWER,HANGUP
 
 
 [csv]
 usegmtime=yes ;log date/time in GMT
 loguniqueid=yes ;log uniqueid
-loguserfield=yes ;log user field
-
-
-

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=62495&r1=62494&r2=62495
==============================================================================
--- team/murf/newcdr/include/asterisk/cel.h (original)
+++ team/murf/newcdr/include/asterisk/cel.h Tue May  1 09:05:43 2007
@@ -37,6 +37,7 @@
 #include "asterisk/channel.h"
 #include "asterisk/utils.h"
 #include "asterisk/event.h"
+#include "asterisk/hashtab.h"
 
 enum ast_cel_eventtype {
 	/*! channel birth */
@@ -115,6 +116,6 @@
 extern int cel_default_amaflags;
 extern char cel_default_accountcode[AST_MAX_ACCOUNT_CODE];
 int ast_cel_engine_init(void);
-
+inline int track_event(enum ast_cel_eventtype et);
 
 #endif /* _ASTERISK_CDR_H */

Modified: team/murf/newcdr/main/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/main/Makefile?view=diff&rev=62495&r1=62494&r2=62495
==============================================================================
--- team/murf/newcdr/main/Makefile (original)
+++ team/murf/newcdr/main/Makefile Tue May  1 09:05:43 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 cel.o event.o tdd.o acl.o rtp.o udptl.o manager.o asterisk.o \
+	cdr.o cel.o hashtab.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/cel.c
URL: http://svn.digium.com/view/asterisk/team/murf/newcdr/main/cel.c?view=diff&rev=62495&r1=62494&r2=62495
==============================================================================
--- team/murf/newcdr/main/cel.c (original)
+++ team/murf/newcdr/main/cel.c Tue May  1 09:05:43 2007
@@ -34,6 +34,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <signal.h>
+#include <ctype.h>
 
 #include "asterisk/lock.h"
 #include "asterisk/channel.h"
@@ -54,6 +55,8 @@
 char cel_default_accountcode[AST_MAX_ACCOUNT_CODE];
 
 static int cel_enabled;		/*! Is the CEL subsystem enabled ? */
+static long long eventset = 0; /*! which events we want to track */
+static struct ast_hashtab *appset = 0;
 
 int check_cel_enabled()
 {
@@ -88,20 +91,191 @@
 	"	Displays the Channel Event Logging system status.\n"
 };
 
+static enum ast_cel_eventtype configevent2eventtype(char *eventname)
+{
+	if (strcasecmp(eventname,"ALL")==0)
+		return 0;
+	else if (strcasecmp(eventname,"CHAN_START")==0)
+		return CEL_CHANNEL_START;
+	else if (strcasecmp(eventname,"CHAN_END")==0)
+		return CEL_CHANNEL_END;
+	else if (strcasecmp(eventname,"ANSWER")==0)
+		return CEL_ANSWER;
+	else if (strcasecmp(eventname,"HANGUP")==0)
+		return CEL_HANGUP;
+	else if (strcasecmp(eventname,"APP_START")==0)
+		return CEL_APP_START;
+	else if (strcasecmp(eventname,"APP_END")==0)
+		return CEL_APP_END;
+	else if (strcasecmp(eventname,"BRIDGE_START")==0)
+		return CEL_BRIDGE_START;
+	else if (strcasecmp(eventname,"BRIDGE_END")==0)
+		return CEL_BRIDGE_END;
+	else if (strcasecmp(eventname,"CONF_START")==0)
+		return CEL_CONF_START;
+	else if (strcasecmp(eventname,"CONF_END")==0)
+		return CEL_CONF_END;
+	else if (strcasecmp(eventname,"PARK_START")==0)
+		return CEL_PARK_START;
+	else if (strcasecmp(eventname,"PARK_END")==0)
+		return CEL_PARK_END;
+	else if (strcasecmp(eventname,"TRANSFER")==0)
+		return CEL_TRANSFER;
+	else if (strcasecmp(eventname,"USER_DEFINED")==0)
+		return CEL_USER_DEFINED;
+	else 
+		return -1;
+}
+
+inline int track_event(enum ast_cel_eventtype et)
+{
+	return  (eventset & (1<<(int)et));
+}
+
 
 static int do_reload(void)
 {
 	struct ast_config *config;
 	const char *enabled_value;
+	const char *eventlist;
+	const char *applist;
 	int was_enabled;
 	int res=0;
 
 	was_enabled = cel_enabled;
 	cel_enabled = 1;
-
+	enum ast_cel_eventtype et;
+	if (appset) {
+		/* a pre-existing hash table == destroy it */
+		/* first, free all the entries */
+		char *str;
+		struct ast_hashtab_iter *it;
+		it = ast_hashtab_start_traversal(appset);
+		while ((str=ast_hashtab_next(it))) {
+			free(str);
+		}
+		ast_hashtab_destroy(appset);
+		appset=0;
+	}
+	
+	
 	if ((config = ast_config_load("cel.conf"))) {
 		if ((enabled_value = ast_variable_retrieve(config, "general", "enable"))) {
 			cel_enabled = ast_true(enabled_value);
+		}
+		if (cel_enabled) {
+			
+			if ((eventlist = ast_variable_retrieve(config, "general", "events"))) {
+				char *t1, *t2, *t3, *myeventlist = ast_strdup(eventlist);
+				t1 = myeventlist;
+				if (!t1 || !(*t1)) {
+					ast_log(LOG_ERROR, "no events line? Turning off CEL capability!\n");
+					cel_enabled = 0;
+				}
+				else
+				{
+					while (t1 && *t1) {
+						t2 = strchr(t1,',');
+						if (!t2) {
+							t2 = t1 + strlen(t1) - 1;
+						}
+						
+						/*push t1 to the first non-blank char */
+						while (t1 && *t1 && isspace(*t1))
+							t1++;
+						if (t2 == t1) {
+							ast_log(LOG_ERROR, "A comma with no preceeding event name? --Ignored\n");
+							t1 = t2+1;
+							continue;
+						}
+						if (!(*t1)) {
+							ast_log(LOG_ERROR, "no events to log? Turning off CEL capability!\n");
+							cel_enabled = 0;
+							break;
+						}
+						/* pull t3 (a copy of t2) to last non-blank char */
+						t3 = t2;
+						while (t3 && *t3 && isspace(*t3))
+							t3--;
+						*(t3+1) = 0;
+						/* t1 now points to null-terminated entry */
+						et = configevent2eventtype(t1);
+						if ((int)et == 0) /* all events */
+							eventset = -1; /* turn on all the bits */
+						else if ((int)et == -1)  /* unmatched event */
+							ast_log(LOG_ERROR, "Unrecognized event name %s!\n", t1);
+						else {
+							eventset |=  (1 << (int)et);
+						}
+						t1 = t2+1;
+					}
+				}
+				if (myeventlist)
+					free(myeventlist);
+			}
+			if ((applist = ast_variable_retrieve(config, "general", "apps"))) {
+				char *t1, *t2, *t3, *myapplist = ast_strdup(applist);
+				if (!track_event(CEL_APP_START) && !track_event(CEL_APP_END)) {
+					ast_log(LOG_ERROR, "An apps= config line, but not tracking APP events!\n");
+				} else {
+					t1 = myapplist;
+					int commacount = 0;
+					t2 = t1;
+					while (t2) {
+						t2 = strchr(t2,',');
+						if (t2) {
+							t2++;
+							commacount++;
+						}
+					}
+					/* form a hash table */
+					appset = ast_hashtab_create(commacount+1, ast_hashtab_compare_strings_nocase,
+												ast_hashtab_resize_none,
+												ast_hashtab_newsize_none, 
+												ast_hashtab_hash_string_nocase,1);
+					while (t1 && *t1) {
+						t2 = strchr(t1,',');
+						if (!t2) {
+							t2 = t1 + strlen(t1) - 1;
+						}
+						
+						/*push t1 to the first non-blank char */
+						while (t1 && *t1 && isspace(*t1))
+							t1++;
+						if (t2 == t1) {
+							ast_log(LOG_ERROR, "A comma with no preceeding event name? --Ignored\n");
+							t1 = t2+1;
+							continue;
+						}
+						if (!(*t1)) {
+							ast_log(LOG_ERROR, "no events to log? Turning off CEL capability!\n");
+							cel_enabled = 0;
+							break;
+						}
+						/* pull t3 (a copy of t2) to last non-blank char */
+						t3 = t2;
+						while (t3 && *t3 && isspace(*t3))
+							t3--;
+						*(t3+1) = 0;
+						/* t1 now points to null-terminated entry */
+						
+						/* while just a few apps would be OK to put in a linked list,
+						   If there are dozens, a linked list search would be really 
+						   horribly slow and therefore bad.
+						   So, let's put these in a hash table 
+						*/
+						t3 = strdup(t1);
+						if (!ast_hashtab_insert_safe(appset, t3)) {
+							ast_log(LOG_ERROR, "The %s app in the apps= line is repeated!\n", t3);
+							free(t3);
+						}
+						
+						t1 = t2+1;
+					}
+				}
+				if (myapplist)
+					free(myapplist);
+			}
 		}
 	}
 
@@ -378,21 +552,35 @@
 
 void ast_cel_report_event(const struct ast_channel *chan, enum ast_cel_eventtype eventtype, char *userdefevname)
 {
-	struct ast_event *ev;
-	time_t eventtime = time(0);
-	
-	/* now, report this event */
-	ev = ast_event_new(AST_EVENT_CEL, 
-					   AST_EVENT_IE_CHANPTR, AST_EVENT_IE_PLTYPE_PTR, chan,
-					   AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, (unsigned int)eventtime,
-					   AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtype,
-					   AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, userdefevname,
-					   AST_EVENT_IE_END);
-	if (!ev) {
-		return;
-	}
-	ast_event_queue(ev); /* a lot of stuff happens here */
-}
+	if (track_event(eventtype))
+	{
+		time_t eventtime;
+		struct ast_event *ev;
+		int trackit = 1;
+		
+		if (eventtype==CEL_APP_START || eventtype==CEL_APP_END) {
+			
+			if (!ast_hashtab_lookup(appset, chan->appl))
+				trackit = 0;
+		}
+
+		if (trackit) {
+			eventtime = time(0);
+			/* now, report this event */
+			ev = ast_event_new(AST_EVENT_CEL, 
+							   AST_EVENT_IE_CHANPTR, AST_EVENT_IE_PLTYPE_PTR, chan,
+							   AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, (unsigned int)eventtime,
+							   AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtype,
+							   AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, userdefevname,
+							   AST_EVENT_IE_END);
+			if (!ev) {
+				return;
+			}
+			ast_event_queue(ev); /* a lot of stuff happens here */
+		}
+	}
+}
+
 
 int ast_cel_engine_init(void)
 {



More information about the asterisk-commits mailing list