[asterisk-commits] russell: branch group/newcdr r202001 - /team/group/newcdr/main/cel.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 19 15:40:29 CDT 2009


Author: russell
Date: Fri Jun 19 15:40:26 2009
New Revision: 202001

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202001
Log:
be crash resistant, follow coding guidelines

Modified:
    team/group/newcdr/main/cel.c

Modified: team/group/newcdr/main/cel.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/cel.c?view=diff&rev=202001&r1=202000&r2=202001
==============================================================================
--- team/group/newcdr/main/cel.c (original)
+++ team/group/newcdr/main/cel.c Fri Jun 19 15:40:26 2009
@@ -431,16 +431,15 @@
 struct ast_channel* ast_cel_fabricate_channel_from_event(const struct ast_event *event)
 {
 	enum ast_cel_event_type event_type;
-	struct timeval eventtime = {0};
-	const char *userdefname = 0;
+	struct timeval eventtime;
+	const char *userdefname = NULL;
 	struct varshead *headp;
 	struct ast_var_t *newvariable;
 	char timebuf[30];
-
 	struct ast_channel *tchan;
-
 	const char *cid_ani, *cid_rdnis, *cid_name, *cid_num, *cid_dnid;
-	const char *exten, *context, *channame, *appname, *appdata, *accountcode, *peeraccount, *uniqueid, *linkedid, *peer, *userfield, *extra;
+	const char *exten, *context, *channame, *appname, *appdata, *accountcode,
+			*peeraccount, *uniqueid, *linkedid, *peer, *userfield, *extra;
 	unsigned int amaflag;
 
 	/* do not call ast_channel_alloc because this is not really a real channel */
@@ -482,7 +481,9 @@
 	} else {
 		newvariable = ast_var_assign("eventtype", ast_cel_get_type_name(event_type));
 	}
-	AST_LIST_INSERT_HEAD(headp, newvariable, entries);
+	if (newvariable) {
+		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
+	}
 
 	if (ast_strlen_zero(cel_dateformat)) {
 		snprintf(timebuf, sizeof(timebuf), "%ld.%06ld", eventtime.tv_sec, eventtime.tv_usec);
@@ -491,11 +492,14 @@
 		ast_localtime(&eventtime, &tm, NULL);
 		ast_strftime(timebuf, sizeof(timebuf), cel_dateformat, &tm);
 	}
-	newvariable = ast_var_assign("eventtime", timebuf);
-	AST_LIST_INSERT_HEAD(headp, newvariable, entries);
-
-	newvariable = ast_var_assign("eventextra", extra);
-	AST_LIST_INSERT_HEAD(headp, newvariable, entries);
+
+	if ((newvariable = ast_var_assign("eventtime", timebuf))) {
+		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
+	}
+
+	if ((newvariable = ast_var_assign("eventextra", extra))) {
+		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
+	}
 
 	tchan->cid.cid_name = ast_strdup(cid_name);
 	tchan->cid.cid_num = ast_strdup(cid_num);
@@ -505,12 +509,12 @@
 
 	ast_copy_string(tchan->exten, exten, sizeof(tchan->exten));
 	ast_copy_string(tchan->context, context, sizeof(tchan->context));
-	ast_string_field_set(tchan,name,channame);
-	ast_string_field_set(tchan,uniqueid,uniqueid);
-	ast_string_field_set(tchan,linkedid,linkedid);
-	ast_string_field_set(tchan,accountcode,accountcode);
-	ast_string_field_set(tchan,peeraccount,peeraccount);
-	ast_string_field_set(tchan,userfield,userfield);
+	ast_string_field_set(tchan, name, S_OR(channame, ""));
+	ast_string_field_set(tchan, uniqueid, S_OR(uniqueid, ""));
+	ast_string_field_set(tchan, linkedid, S_OR(linkedid, ""));
+	ast_string_field_set(tchan, accountcode, S_OR(accountcode, ""));
+	ast_string_field_set(tchan, peeraccount, S_OR(peeraccount, ""));
+	ast_string_field_set(tchan, userfield, S_OR(userfield, ""));
 
 	pbx_builtin_setvar_helper(tchan, "BRIDGEPEER", peer);
 




More information about the asterisk-commits mailing list