[svn-commits] murf: branch murf/cel2cdr r179218 - in /team/murf/cel2cdr: cel/ include/aster...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Feb 28 14:15:42 CST 2009


Author: murf
Date: Sat Feb 28 14:15:38 2009
New Revision: 179218

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=179218
Log:
Straighten up/ clean up things here and there

Modified:
    team/murf/cel2cdr/cel/cel_cel2cdr.c
    team/murf/cel2cdr/include/asterisk/extconf.h
    team/murf/cel2cdr/utils/Makefile
    team/murf/cel2cdr/utils/csv2ev.c

Modified: team/murf/cel2cdr/cel/cel_cel2cdr.c
URL: http://svn.digium.com/svn-view/asterisk/team/murf/cel2cdr/cel/cel_cel2cdr.c?view=diff&rev=179218&r1=179217&r2=179218
==============================================================================
--- team/murf/cel2cdr/cel/cel_cel2cdr.c (original)
+++ team/murf/cel2cdr/cel/cel_cel2cdr.c Sat Feb 28 14:15:38 2009
@@ -19,8 +19,12 @@
 /* for simple CDRs:
  */
 
+#include "asterisk.h"
+
 #include "asterisk/dlinkedlists.h"
 #include "asterisk/hashtab.h"
+#include "asterisk/event.h"
+#include "asterisk/module.h"
 
 struct event_list_member
 {
@@ -48,7 +52,7 @@
           as they are 'used up' (a CDR posted). This should
           be fast & painless 
 	*/
-	AST_DLLIST_ENTRY(event_list_member) list;
+	AST_DLLIST_HEAD(list, event_list_member) list;
 };
 
 /* this hashtab is the central theme to the CDR approach.
@@ -61,32 +65,33 @@
 
 static int table_compare_func(const void *a, const void *b)
 {
-	struct event_list *ev_a = a;
-	struct event list *ev_b = b;
-	return strcmp(ev_b->linkedid, ev_b->linkedid);
+	const struct event_list *ev_a = a;
+	const struct event_list *ev_b = b;
+	return strcmp(ev_a->linkedid, ev_b->linkedid);
 }
 
 static unsigned int table_hash_func(const void *obj)
 {
-	struct event_list *obj_a = obj;
-	ast_hashtab_hash_string(obj_a->linkedid);
+	const struct event_list *obj_a = obj;
+	return ast_hashtab_hash_string(obj_a->linkedid);
 }
 
 /* destruction is really boring stuff....
    until it doesn't work, or doesn't work right! */
 
-void destroy_event_list_member(struct event_list_member *m)
+static void destroy_event_list_member(struct event_list_member *m)
 {
 	ast_event_destroy(m->ev);
 	m->ev = NULL;
 	free(m);
 }
 
-void destroy_event_list(struct event_list *l)
+static void destroy_event_list(void *lv)
 {
+	struct event_list *l = lv;
 	struct event_list_member *m;
 	
-	AST_DLLIST_TRAVERSE_SAFE_BEGIN(&l->list, m, list) {
+	AST_DLLIST_TRAVERSE_SAFE_BEGIN(&(l->list), m, list) {
 		AST_DLLIST_REMOVE_CURRENT(list);
 		destroy_event_list_member(m);
 	}
@@ -106,30 +111,41 @@
 enum cdr_mode_type cdr_mode = CEL2CDR_MODE_SIMPLE;
 static int cel2cdr_enabled = 0;
 
-static mod_load_func()
+static int mod_load_func(void)
 {
 	/* read the config file, set all the control variables. */
 
 	/* set up the master table */
 	if (cel2cdr_enabled) {
 		if (!master_table) {
-			master_table = ast_hashtab_create(1001, table_compare_func, table_resize_func,
-											  table_newsize_func, table_hash_func, 1 /* do locking */);
+			master_table = ast_hashtab_create(1001, table_compare_func, ast_hashtab_resize_java,
+											  ast_hashtab_newsize_java, table_hash_func, 1 /* do locking */);
 		} else {
 			/* this shouldn't happen? or should I just remove all the
 			   stuff from the table and leave it initialized? */
 		}
 	}
+	return AST_MODULE_LOAD_SUCCESS;
 }
 
-static mod_unload_func()
+static int mod_unload_func(void)
 {
 	if (master_table) {
 		ast_hashtab_destroy(master_table, destroy_event_list);
 		master_table = NULL;
 	}
+	return AST_MODULE_LOAD_SUCCESS;
 }
 
+static int mod_reload_func(void)
+{
+	mod_unload_func();
+	mod_load_func();
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+
+void cel2cdr_handle_event(const struct ast_event *event, void *userdata);
 
 void cel2cdr_handle_event(const struct ast_event *event, void *userdata)
 {
@@ -142,3 +158,9 @@
 		}
 	}
 }
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "This turns CEL events into CDR structs in realtime",
+                .load = mod_load_func,
+                .unload = mod_unload_func,
+                .reload = mod_reload_func,
+               );

Modified: team/murf/cel2cdr/include/asterisk/extconf.h
URL: http://svn.digium.com/svn-view/asterisk/team/murf/cel2cdr/include/asterisk/extconf.h?view=diff&rev=179218&r1=179217&r2=179218
==============================================================================
--- team/murf/cel2cdr/include/asterisk/extconf.h (original)
+++ team/murf/cel2cdr/include/asterisk/extconf.h Sat Feb 28 14:15:38 2009
@@ -72,6 +72,10 @@
 };
 
 /* ================== above: the config world; below, the dialplan world */
+enum ast_doc_src {
+        AST_XML_DOC,            /*!< From XML documentation */
+        AST_STATIC_DOC          /*!< From application/function registration */
+};
 
 /*! \brief A registered application */
 struct ast_app {
@@ -83,7 +87,7 @@
 		AST_STRING_FIELD(arguments);    /*!< Arguments description */
 		AST_STRING_FIELD(seealso);      /*!< See also */
 	);
-	enum ast_xmldoc_src docsrc;		/*!< Where the documentation come from. */
+	enum ast_doc_src docsrc;		/*!< Where the documentation come from. */
 	AST_RWLIST_ENTRY(ast_app) list;		/*!< Next app in list */
 	void *module;			/*!< Module this app belongs to */
 	char name[0];				/*!< Name of the application */
@@ -111,6 +115,16 @@
 	char stuff[0];
 };
 /* from pbx.h */
+enum ast_extension_states {
+        AST_EXTENSION_REMOVED = -2,     /*!< Extension removed */
+        AST_EXTENSION_DEACTIVATED = -1, /*!< Extension hint removed */
+        AST_EXTENSION_NOT_INUSE = 0,    /*!< No device INUSE or BUSY  */
+        AST_EXTENSION_INUSE = 1 << 0,   /*!< One or more devices INUSE */
+        AST_EXTENSION_BUSY = 1 << 1,    /*!< All devices BUSY */
+        AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */
+        AST_EXTENSION_RINGING = 1 << 3, /*!< All devices RINGING */
+        AST_EXTENSION_ONHOLD = 1 << 4,  /*!< All devices ONHOLD */
+};
 typedef int (*ast_state_cb_type)(char *context, char* id, enum ast_extension_states state, void *data);
 struct ast_timing {
 	int hastime;				/*!< If time construct exists */
@@ -141,7 +155,7 @@
 	char stuff[0];
 };
 
-*! \brief Ignore patterns in dial plan */
+/*! \brief Ignore patterns in dial plan */
 struct ast_ignorepat {
 	const char *registrar;
 	struct ast_ignorepat *next;

Modified: team/murf/cel2cdr/utils/Makefile
URL: http://svn.digium.com/svn-view/asterisk/team/murf/cel2cdr/utils/Makefile?view=diff&rev=179218&r1=179217&r2=179218
==============================================================================
--- team/murf/cel2cdr/utils/Makefile (original)
+++ team/murf/cel2cdr/utils/Makefile Sat Feb 28 14:15:38 2009
@@ -132,6 +132,7 @@
 	$(ECHO_PREFIX) echo "   [CP] $(subst $(ASTTOPDIR)/,,$<) -> $@"
 	$(CMD_PREFIX) cp "$<" "$@"
 
+csv2ev.o: ASTCFLAGS+=-DSTANDALONE
 csv2ev.o : csv2ev.c
 
 ael_main.o: ASTCFLAGS+=-DSTANDALONE

Modified: team/murf/cel2cdr/utils/csv2ev.c
URL: http://svn.digium.com/svn-view/asterisk/team/murf/cel2cdr/utils/csv2ev.c?view=diff&rev=179218&r1=179217&r2=179218
==============================================================================
--- team/murf/cel2cdr/utils/csv2ev.c (original)
+++ team/murf/cel2cdr/utils/csv2ev.c Sat Feb 28 14:15:38 2009
@@ -23,16 +23,21 @@
  *
  * \author Steve Murphy <murf at digium.com>
  */
-
+#include "asterisk.h"
 #include "asterisk/event.h" /* which will include the event_defs.h also */
 #include "asterisk/linkedlists.h"
+#include "asterisk/stringfields.h"
+#include "asterisk/xmldoc.h"
+#define NOTYET
 #include "asterisk/extconf.h"
 #include "asterisk/cel.h"
 
 /* a simple linked list will represent what the user put in his cel_custom
    config file... basically, we need the order of each field type.
-   we can then rocket the data off to the event calls */
+   we can then rocket the data off to the event calls
 */
+
+void cel2cdr_handle_event(const struct ast_event *event, void *userdata);
 
 struct csv_list_mem
 {
@@ -42,10 +47,10 @@
 
 struct csv_list
 {
-	AST_LIST_HEAD_NOLOCK(list, csv_list_mem);
+	AST_LIST_HEAD_NOLOCK(list, csv_list_mem) list;
 };
 
-enum ast_event_ie_type csv2ev_str2eventietype(char *str)
+static enum ast_event_ie_type csv2ev_str2eventietype(char *str)
 {
 	/* hmmm, could we do a perfect hash of some sort? */
 	/* later maybe */
@@ -94,10 +99,10 @@
 }
 
 
-struct csv_list *parse_mappings(char *val)
+static struct csv_list *parse_mappings(char *val)
 {
 	struct csv_list *x = calloc(sizeof(struct csv_list),1);
-	char *beg1, *end1;
+	char *beg1;
 	
 	if (!x) {
 		printf("Couldn't allocate a csv_list struct!\n");
@@ -110,15 +115,15 @@
 		strcat(val,",\""); /* now every field is ended with the same char sequence! */
 	}
 	
-	while (beg1 = strstr(val,"\",\"")) {
+	while ((beg1 = strstr(val,"\",\""))) {
+		struct csv_list_mem *m = calloc(sizeof(struct csv_list_mem),1);
 		*beg1 = 0;
 		/* val now points to the single entry, stripped of quotes */
-		struct csv_list_mem *m = calloc(sizeof(struct csv_list_mem),1);
 		if (!m) {
 			printf("Couldn't allocate a csv_list_mem struct!\n");
 			return NULL;
 		}
-		AST_LIST_INSERT_TAIL(x, m, list);
+		AST_LIST_INSERT_TAIL(&(x->list), m, list);
 		m->type = csv2ev_str2eventietype(val);
 		val = beg1+3;
 	}
@@ -126,11 +131,12 @@
 	return x;
 }
 
-char *get_mappings(char *fname, char **fname)
-{
+static char *get_mappings(char **fname)
+{
+	struct ast_config *f;
 	/* open the cel_custom file and get the first mappings value */
 	localized_use_conf_dir();
-	struct ast_config *f = localized_config_load(fname);
+	f = localized_config_load("cel_csv.conf");
 	if (f) {
 		struct ast_category *m = localized_category_get(f, "mappings");
 		if (m) {
@@ -138,7 +144,7 @@
 			if (m->root) {
 				printf("Found '%s => %s' in mappings!\n", m->root->name, m->root->name);
 				*fname = m->root->name;
-				return m->root->val;
+				return strdup(m->root->value);
 			} else {
 				printf("Sorry, but the mappings category was empty!\n");
 				return NULL;
@@ -153,15 +159,18 @@
 	}
 }
 
+void csv2events(void);
+
 void csv2events(void)
 {
 	
 	/* load the config file, then the csv file, and generate the events */
-	struct csv_list *csvlist, *csvptr;
-	char *fname;
-	char *mappings = get_mappings("cel_custom.conf", &fname);
+	struct csv_list *csvlist;
+	struct csv_list_mem *csvptr;
+	char *fname = 0;
+	char *mappings = get_mappings(&fname);
 	if (mappings) {
-		csvlist = parse_mappings(char *val);
+		csvlist = parse_mappings(mappings);
 		if (csvlist) {
 			/* OK, we know the order of each field. Watch out for usecs.
 			   Now, let's open the log file and begin event generation */
@@ -172,18 +181,21 @@
 			snprintf(filename, 512, "/var/log/asterisk/cel-custom/%s", fname);
 			f = fopen(filename, "r");
 			if (f) {
-				while (r=fgets(buf, sizeof(buf), f)) {
+				struct ast_event *ev;
+				
+				while ((r=fgets(buf, sizeof(buf), f))) {
 					char *beg1, *val;
-					char *e_udef, *e_cid_name, *e_cid_num, *e_cid_ani, *e_cid_rdnis,
-						*e_cid_dnid, *e_exten, *e_context, *e_name, *e_appl, *e_appdata, *e_acctcode,
-						*e_peeracct, *e_uniqueid, *e_linkedid, *e_userfield, *e_extra, *e_peername;
-					unsigned int i_tvsec, i_tvusec, i_ama;
-					int i_type;
-					char *decptr;
+					char *e_udef = NULL, *e_cid_name = NULL, *e_cid_num = NULL, *e_cid_ani = NULL, *e_cid_rdnis = NULL,
+						*e_cid_dnid = NULL, *e_exten = NULL, *e_context = NULL, *e_name = NULL, *e_appl = NULL, *e_appdata = NULL, *e_acctcode = NULL,
+						*e_peeracct = NULL, *e_uniqueid = NULL, *e_linkedid = NULL, *e_userfield = NULL, *e_extra = NULL, *e_peername = NULL;
+					unsigned int i_tvsec = 0, i_tvusec = 0, i_ama = 0;
+					int i_type = 0;
+					char *decptr = NULL;
 					
 					if (buf[strlen(buf)-1] != '\n') {
-						printf("Buffer size of %d was not large enough; tossing out input\n");
-						fgets(buf, sizeof(buf), f); /* hopefully, that was all there's left! */
+						char *fgets_result;
+						printf("Buffer size of %zd was not large enough; tossing out input\n", sizeof(buf));
+						fgets_result = fgets(buf, sizeof(buf), f); /* hopefully, that was all there's left! I know this is ugly, but, I'll get back it to it someday!! XXXXXtodoXXXXX */
 						continue;
 					} else {
 						buf[strlen(buf)-1] = 0;
@@ -203,9 +215,9 @@
 					   generate the event structs, so we don't have dependencies
 					   on taskprocessors and who knows what else in the asterisk
 					   core! */
-					csvptr = AST_LIST_FIRST(csvlist);
+					csvptr = AST_LIST_FIRST(&(csvlist->list));
 					/* gather up the fields, and prepare for a the event call */
-					while (beg1 = strstr(val,"\",\"")) {
+					while ((beg1 = strstr(val,"\",\""))) {
 						*beg1 = 0;
 						/* val now points to the single entry, stripped of quotes */
 						switch(csvptr->type)
@@ -224,7 +236,7 @@
 							i_tvsec = strtol(val, NULL, 10);
 							decptr = strchr(val,'.');
 							if (decptr) {
-								i_tvusec = strlol(decptr+1, NULL, 10);
+								i_tvusec = strtol(decptr+1, NULL, 10);
 							} else {
 								i_tvusec = 0;
 							}
@@ -299,6 +311,9 @@
 							
 						case AST_EVENT_IE_CEL_EXTRA:
 							e_extra = val;
+							break;
+						default:
+							printf("what in the...? are we calling with this IE type: %d\n", csvptr->type);
 							break;
 						}
 						csvptr = AST_LIST_NEXT(csvptr,list);




More information about the svn-commits mailing list