[asterisk-commits] russell: branch group/newcdr r202108 - in /team/group/newcdr: cel/ include/as...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jun 20 08:58:09 CDT 2009


Author: russell
Date: Sat Jun 20 08:58:05 2009
New Revision: 202108

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202108
Log:
Do struct version check for ast_cel_event_record, and remove need for a malloc

Modified:
    team/group/newcdr/cel/cel_adaptive_odbc.c
    team/group/newcdr/cel/cel_manager.c
    team/group/newcdr/cel/cel_pgsql.c
    team/group/newcdr/cel/cel_radius.c
    team/group/newcdr/cel/cel_tds.c
    team/group/newcdr/include/asterisk/cel.h
    team/group/newcdr/main/cel.c

Modified: team/group/newcdr/cel/cel_adaptive_odbc.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_adaptive_odbc.c?view=diff&rev=202108&r1=202107&r2=202108
==============================================================================
--- team/group/newcdr/cel/cel_adaptive_odbc.c (original)
+++ team/group/newcdr/cel/cel_adaptive_odbc.c Sat Jun 20 08:58:05 2009
@@ -352,15 +352,19 @@
 	char colbuf[1024], *colptr;
 	SQLHSTMT stmt = NULL;
 	SQLLEN rows = 0;
-	struct ast_cel_event_record *record = ast_cel_fill_record(event);
-
-	if (!sql || !sql2 || !record) {
+	struct ast_cel_event_record record = {
+		.version = AST_CEL_EVENT_RECORD_VERSION,
+	};
+
+	if (ast_cel_fill_record(event, &record)) {
+		return;
+	}
+
+	if (!sql || !sql2) {
 		if (sql)
 			ast_free(sql);
 		if (sql2)
 			ast_free(sql2);
-		if (record)
-			ast_free(record);
 		return;
 	}
 
@@ -368,7 +372,6 @@
 		ast_log(LOG_ERROR, "Unable to lock table list.  Insert CEL(s) failed.\n");
 		ast_free(sql);
 		ast_free(sql2);
-		ast_free(record);
 		return;
 	}
 
@@ -393,48 +396,48 @@
 			if (entry->staticvalue) {
 				colptr = ast_strdupa(entry->staticvalue);
 			} else if (datefield) {
-				struct timeval date_tv = record->event_time;
+				struct timeval date_tv = record.event_time;
 				struct ast_tm tm = { 0, };
 				ast_localtime(&date_tv, &tm, tableptr->usegmtime ? "UTC" : NULL);
 				ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S", &tm);
 				colptr = colbuf;
 			} else {
 				if (strcmp(entry->celname, "userdeftype") == 0) {
-					strncpy(colbuf, record->user_defined_name, sizeof(colbuf));
+					strncpy(colbuf, record.user_defined_name, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "cid_name") == 0) {
-					strncpy(colbuf, record->caller_id_name, sizeof(colbuf));
+					strncpy(colbuf, record.caller_id_name, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "cid_num") == 0) {
-					strncpy(colbuf, record->caller_id_num, sizeof(colbuf));
+					strncpy(colbuf, record.caller_id_num, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "cid_ani") == 0) {
-					strncpy(colbuf, record->caller_id_ani, sizeof(colbuf));
+					strncpy(colbuf, record.caller_id_ani, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "cid_rdnis") == 0) {
-					strncpy(colbuf, record->caller_id_rdnis, sizeof(colbuf));
+					strncpy(colbuf, record.caller_id_rdnis, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "cid_dnid") == 0) {
-					strncpy(colbuf, record->caller_id_dnid, sizeof(colbuf));
+					strncpy(colbuf, record.caller_id_dnid, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "exten") == 0) {
-					strncpy(colbuf, record->extension, sizeof(colbuf));
+					strncpy(colbuf, record.extension, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "context") == 0) {
-					strncpy(colbuf, record->context, sizeof(colbuf));
+					strncpy(colbuf, record.context, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "channame") == 0) {
-					strncpy(colbuf, record->channel_name, sizeof(colbuf));
+					strncpy(colbuf, record.channel_name, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "appname") == 0) {
-					strncpy(colbuf, record->application_name, sizeof(colbuf));
+					strncpy(colbuf, record.application_name, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "appdata") == 0) {
-					strncpy(colbuf, record->application_data, sizeof(colbuf));
+					strncpy(colbuf, record.application_data, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "accountcode") == 0) {
-					strncpy(colbuf, record->account_code, sizeof(colbuf));
+					strncpy(colbuf, record.account_code, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "peeraccount") == 0) {
-					strncpy(colbuf, record->peer_account, sizeof(colbuf));
+					strncpy(colbuf, record.peer_account, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "uniqueid") == 0) {
-					strncpy(colbuf, record->unique_id, sizeof(colbuf));
+					strncpy(colbuf, record.unique_id, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "linkedid") == 0) {
-					strncpy(colbuf, record->linked_id, sizeof(colbuf));
+					strncpy(colbuf, record.linked_id, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "userfield") == 0) {
-					strncpy(colbuf, record->user_field, sizeof(colbuf));
+					strncpy(colbuf, record.user_field, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "peer") == 0) {
-					strncpy(colbuf, record->peer, sizeof(colbuf));
+					strncpy(colbuf, record.peer, sizeof(colbuf));
 				} else if (strcmp(entry->celname, "amaflags") == 0) {
-					snprintf(colbuf, sizeof(colbuf), "%d", record->amaflag);
+					snprintf(colbuf, sizeof(colbuf), "%d", record.amaflag);
 				} else {
 					colbuf[0] = 0;
 				}
@@ -471,7 +474,7 @@
 					 * form (but only when we're dealing with a character-based field).
 					 */
 					if (strcasecmp(entry->name, "eventtype") == 0) {
-						snprintf(colbuf, sizeof(colbuf), "%s", record->event_name);
+						snprintf(colbuf, sizeof(colbuf), "%s", record.event_name);
 					}
 
 					/* Truncate too-long fields */
@@ -566,7 +569,7 @@
 					{
 						int integer = 0;
 						if (strcasecmp(entry->name, "eventtype") == 0) {
-							integer = (int) record->event_type;
+							integer = (int) record.event_type;
 						} else if (sscanf(colptr, "%d", &integer) != 1) {
 							ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
 							continue;
@@ -581,7 +584,7 @@
 					{
 						long long integer = 0;
 						if (strcasecmp(entry->name, "eventtype") == 0) {
-							integer = (long long) record->event_type;
+							integer = (long long) record.event_type;
 						} else if (sscanf(colptr, "%lld", &integer) != 1) {
 							ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
 							continue;
@@ -596,7 +599,7 @@
 					{
 						short integer = 0;
 						if (strcasecmp(entry->name, "eventtype") == 0) {
-							integer = (short) record->event_type;
+							integer = (short) record.event_type;
 						} else if (sscanf(colptr, "%hd", &integer) != 1) {
 							ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
 							continue;
@@ -611,7 +614,7 @@
 					{
 						char integer = 0;
 						if (strcasecmp(entry->name, "eventtype") == 0) {
-							integer = (char) record->event_type;
+							integer = (char) record.event_type;
 						} else if (sscanf(colptr, "%hhd", &integer) != 1) {
 							ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
 							continue;
@@ -626,7 +629,7 @@
 					{
 						char integer = 0;
 						if (strcasecmp(entry->name, "eventtype") == 0) {
-							integer = (char) record->event_type;
+							integer = (char) record.event_type;
 						} else if (sscanf(colptr, "%hhd", &integer) != 1) {
 							ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name);
 							continue;
@@ -644,7 +647,7 @@
 					{
 						double number = 0.0;
 						if (strcasecmp(entry->name, "eventtype") == 0) {
-							number = (double)record->event_type;
+							number = (double)record.event_type;
 						} else if (sscanf(colptr, "%lf", &number) != 1) {
 							ast_log(LOG_WARNING, "CEL variable %s is not an numeric type.\n", entry->name);
 							continue;
@@ -661,7 +664,7 @@
 					{
 						double number = 0.0;
 						if (strcasecmp(entry->name, "eventtype") == 0) {
-							number = (double)record->event_type;
+							number = (double) record.event_type;
 						} else if (sscanf(colptr, "%lf", &number) != 1) {
 							ast_log(LOG_WARNING, "CEL variable %s is not an numeric type.\n", entry->name);
 							continue;
@@ -711,8 +714,6 @@
 
 	ast_free(sql);
 	ast_free(sql2);
-	ast_free(record);
-	return;
 }
 
 static int unload_module(void)

Modified: team/group/newcdr/cel/cel_manager.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_manager.c?view=diff&rev=202108&r1=202107&r2=202108
==============================================================================
--- team/group/newcdr/cel/cel_manager.c (original)
+++ team/group/newcdr/cel/cel_manager.c Sat Jun 20 08:58:05 2009
@@ -138,18 +138,19 @@
 {
 	struct ast_tm timeresult;
 	char start_time[80] = "";
-	struct ast_cel_event_record *record = ast_cel_fill_record(event);
-
-	if (!enablecel || !record) {
-		if (record) {
-			ast_free(record);
-		}
+	struct ast_cel_event_record record = {
+		.version = AST_CEL_EVENT_RECORD_VERSION,
+	};
+
+	if (ast_cel_fill_record(event, &record)) {
 		return;
 	}
 
-	ast_log(LOG_NOTICE, "Logging event to manager interface\n");
-
-	ast_localtime(&record->event_time, &timeresult, NULL);
+	if (!enablecel) {
+		return;
+	}
+
+	ast_localtime(&record.event_time, &timeresult, NULL);
 	ast_strftime(start_time, sizeof(start_time), DATE_FORMAT, &timeresult);
 
 	manager_event(EVENT_FLAG_CALL, "CEL",
@@ -171,16 +172,12 @@
 	    "LinkedID: %s\r\n"
 	    "Userfield: %s\r\n"
 	    "Peer: %s\r\n",
-		record->event_name, record->account_code, record->caller_id_num,
-		record->caller_id_name, record->caller_id_ani, record->caller_id_rdnis,
-		record->caller_id_dnid, record->extension, record->context, record->channel_name,
-		record->application_name, record->application_data, start_time,
-		ast_cel_flags2str(record->amaflag), record->unique_id, record->linked_id,
-		record->user_field, record->peer);
-
-	ast_free(record);
-
-	return;
+		record.event_name, record.account_code, record.caller_id_num,
+		record.caller_id_name, record.caller_id_ani, record.caller_id_rdnis,
+		record.caller_id_dnid, record.extension, record.context, record.channel_name,
+		record.application_name, record.application_data, start_time,
+		ast_cel_flags2str(record.amaflag), record.unique_id, record.linked_id,
+		record.user_field, record.peer);
 }
 
 static int unload_module(void)

Modified: team/group/newcdr/cel/cel_pgsql.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_pgsql.c?view=diff&rev=202108&r1=202107&r2=202108
==============================================================================
--- team/group/newcdr/cel/cel_pgsql.c (original)
+++ team/group/newcdr/cel/cel_pgsql.c Sat Jun 20 08:58:05 2009
@@ -118,11 +118,17 @@
 	struct ast_tm tm;
 	char timestr[128];
 	char *pgerror;
-	struct ast_cel_event_record *record = ast_cel_fill_record(event);
+	struct ast_cel_event_record record = {
+		.version = AST_CEL_EVENT_RECORD_VERSION,
+	};
+
+	if (ast_cel_fill_record(event, &record)) {
+		return;
+	}
 
 	ast_mutex_lock(&pgsql_lock);
 
-	ast_localtime(&record->event_time, &tm, NULL);
+	ast_localtime(&record.event_time, &tm, NULL);
 	ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
 
 	if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
@@ -167,17 +173,17 @@
 			if (strcmp(cur->name, "eventtime") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
 					LENGTHEN_BUF2(13);
-					ast_str_append(&sql2, 0, "%s%ld", SEP, record->event_time.tv_sec);
+					ast_str_append(&sql2, 0, "%s%ld", SEP, record.event_time.tv_sec);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
 					LENGTHEN_BUF2(31);
 					ast_str_append(&sql2, 0, "%s%f",
 						SEP,
-						(double) record->event_time.tv_sec +
-						(double) record->event_time.tv_usec / 1000000.0);
+						(double) record.event_time.tv_sec +
+						(double) record.event_time.tv_usec / 1000000.0);
 				} else {
 					/* char, hopefully */
 					LENGTHEN_BUF2(31);
-					ast_localtime(&record->event_time, &tm, NULL);
+					ast_localtime(&record.event_time, &tm, NULL);
 					ast_strftime(buf, sizeof(buf), DATE_FORMAT, &tm);
 					ast_str_append(&sql2, 0, "%s'%s'", SEP, buf);
 				}
@@ -185,61 +191,61 @@
 				if (cur->type[0] == 'i') {
 					/* Get integer, no need to escape anything */
 					LENGTHEN_BUF2(5);
-					ast_str_append(&sql2, 0, "%s%d", SEP, (int) record->event_type);
+					ast_str_append(&sql2, 0, "%s%d", SEP, (int) record.event_type);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
 					LENGTHEN_BUF2(31);
-					ast_str_append(&sql2, 0, "%s%f", SEP, (double) record->event_type);
+					ast_str_append(&sql2, 0, "%s%f", SEP, (double) record.event_type);
 				} else {
 					/* Char field, probably */
-					LENGTHEN_BUF2(strlen(record->event_name) + 1);
-					ast_str_append(&sql2, 0, "%s'%s'", SEP, record->event_name);
+					LENGTHEN_BUF2(strlen(record.event_name) + 1);
+					ast_str_append(&sql2, 0, "%s'%s'", SEP, record.event_name);
 				}
 			} else if (strcmp(cur->name, "amaflags") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
 					/* Integer, no need to escape anything */
 					LENGTHEN_BUF2(13);
-					ast_str_append(&sql2, 0, "%s%d", SEP, record->amaflag);
+					ast_str_append(&sql2, 0, "%s%d", SEP, record.amaflag);
 				} else {
 					/* Although this is a char field, there are no special characters in the values for these fields */
 					LENGTHEN_BUF2(31);
-					ast_str_append(&sql2, 0, "%s'%d'", SEP, record->amaflag);
+					ast_str_append(&sql2, 0, "%s'%d'", SEP, record.amaflag);
 				}
 			} else {
 				/* Arbitrary field, could be anything */
 				if (strcmp(cur->name, "userdeftype") == 0) {
-					value = record->user_defined_name;
+					value = record.user_defined_name;
 				} else if (strcmp(cur->name, "cid_name") == 0) {
-					value = record->caller_id_name;
+					value = record.caller_id_name;
 				} else if (strcmp(cur->name, "cid_num") == 0) {
-					value = record->caller_id_num;
+					value = record.caller_id_num;
 				} else if (strcmp(cur->name, "cid_ani") == 0) {
-					value = record->caller_id_ani;
+					value = record.caller_id_ani;
 				} else if (strcmp(cur->name, "cid_rdnis") == 0) {
-					value = record->caller_id_rdnis;
+					value = record.caller_id_rdnis;
 				} else if (strcmp(cur->name, "cid_dnid") == 0) {
-					value = record->caller_id_dnid;
+					value = record.caller_id_dnid;
 				} else if (strcmp(cur->name, "exten") == 0) {
-					value = record->extension;
+					value = record.extension;
 				} else if (strcmp(cur->name, "context") == 0) {
-					value = record->context;
+					value = record.context;
 				} else if (strcmp(cur->name, "channame") == 0) {
-					value = record->channel_name;
+					value = record.channel_name;
 				} else if (strcmp(cur->name, "appname") == 0) {
-					value = record->application_name;
+					value = record.application_name;
 				} else if (strcmp(cur->name, "appdata") == 0) {
-					value = record->application_data;
+					value = record.application_data;
 				} else if (strcmp(cur->name, "accountcode") == 0) {
-					value = record->account_code;
+					value = record.account_code;
 				} else if (strcmp(cur->name, "peeraccount") == 0) {
-					value = record->peer_account;
+					value = record.peer_account;
 				} else if (strcmp(cur->name, "uniqueid") == 0) {
-					value = record->unique_id;
+					value = record.unique_id;
 				} else if (strcmp(cur->name, "linkedid") == 0) {
-					value = record->linked_id;
+					value = record.linked_id;
 				} else if (strcmp(cur->name, "userfield") == 0) {
-					value = record->user_field;
+					value = record.user_field;
 				} else if (strcmp(cur->name, "peer") == 0) {
-					value = record->peer;
+					value = record.peer;
 				} else {
 					value = "";
 				}
@@ -328,7 +334,7 @@
 			ast_free(sql2);
 			return;
 		}
-        ast_mutex_unlock(&pgsql_lock);
+		ast_mutex_unlock(&pgsql_lock);
 	}
 }
 

Modified: team/group/newcdr/cel/cel_radius.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_radius.c?view=diff&rev=202108&r1=202107&r2=202108
==============================================================================
--- team/group/newcdr/cel/cel_radius.c (original)
+++ team/group/newcdr/cel/cel_radius.c Sat Jun 20 08:58:05 2009
@@ -184,13 +184,15 @@
 {
 	int result = ERROR_RC;
 	VALUE_PAIR *send = NULL;
-	struct ast_cel_event_record *record = ast_cel_fill_record(event);
-
-	if (!record) {
+	struct ast_cel_event_record record = {
+		.version = AST_CEL_EVENT_RECORD_VERSION,
+	};
+
+	if (ast_cel_fill_record(event, &record)) {
 		return;
 	}
 
-	if (build_radius_record(&send, record)) {
+	if (build_radius_record(&send, &record)) {
 		if (option_debug) {
 			ast_log(LOG_DEBUG, "Unable to create RADIUS record. CEL not recorded!\n");
 		}
@@ -206,7 +208,6 @@
 	if (send) {
 		rc_avpair_free(send);
 	}
-	ast_free(record);
 }
 
 static int unload_module(void)

Modified: team/group/newcdr/cel/cel_tds.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/cel/cel_tds.c?view=diff&rev=202108&r1=202107&r2=202108
==============================================================================
--- team/group/newcdr/cel/cel_tds.c (original)
+++ team/group/newcdr/cel/cel_tds.c Sat Jun 20 08:58:05 2009
@@ -117,31 +117,33 @@
 	char *accountcode_ai, *clidnum_ai, *exten_ai, *context_ai, *clid_ai, *channel_ai, *app_ai, *appdata_ai, *uniqueid_ai, *linkedid_ai, *cidani_ai, *cidrdnis_ai, *ciddnid_ai, *peer_ai, *userfield_ai;
 	RETCODE erc;
 	int attempt = 1;
-	struct ast_cel_event_record *record = ast_cel_fill_record(event);
-
-	if (!record) {
+	struct ast_cel_event_record record = {
+		.version = AST_CEL_EVENT_RECORD_VERSION,
+	};
+
+	if (ast_cel_fill_record(event, &record)) {
 		return;
 	}
 
 	ast_mutex_lock(&tds_lock);
 
-	accountcode_ai = anti_injection(record->account_code, 20);
-	clidnum_ai     = anti_injection(record->caller_id_num, 80);
-	clid_ai        = anti_injection(record->caller_id_name, 80);
-	cidani_ai      = anti_injection(record->caller_id_ani, 80);
-	cidrdnis_ai    = anti_injection(record->caller_id_rdnis, 80);
-	ciddnid_ai     = anti_injection(record->caller_id_dnid, 80);
-	exten_ai       = anti_injection(record->extension, 80);
-	context_ai     = anti_injection(record->context, 80);
-	channel_ai     = anti_injection(record->channel_name, 80);
-	app_ai         = anti_injection(record->application_name, 80);
-	appdata_ai     = anti_injection(record->application_data, 80);
-	uniqueid_ai    = anti_injection(record->unique_id, 32);
-	linkedid_ai    = anti_injection(record->linked_id, 32);
-	userfield_ai   = anti_injection(record->user_field, 32);
-	peer_ai        = anti_injection(record->peer, 32);
-
-	get_date(start, sizeof(start), record->event_time);
+	accountcode_ai = anti_injection(record.account_code, 20);
+	clidnum_ai     = anti_injection(record.caller_id_num, 80);
+	clid_ai        = anti_injection(record.caller_id_name, 80);
+	cidani_ai      = anti_injection(record.caller_id_ani, 80);
+	cidrdnis_ai    = anti_injection(record.caller_id_rdnis, 80);
+	ciddnid_ai     = anti_injection(record.caller_id_dnid, 80);
+	exten_ai       = anti_injection(record.extension, 80);
+	context_ai     = anti_injection(record.context, 80);
+	channel_ai     = anti_injection(record.channel_name, 80);
+	app_ai         = anti_injection(record.application_name, 80);
+	appdata_ai     = anti_injection(record.application_data, 80);
+	uniqueid_ai    = anti_injection(record.unique_id, 32);
+	linkedid_ai    = anti_injection(record.linked_id, 32);
+	userfield_ai   = anti_injection(record.user_field, 32);
+	peer_ai        = anti_injection(record.peer, 32);
+
+	get_date(start, sizeof(start), record.event_time);
 
 retry:
 	/* Ensure that we are connected */
@@ -201,7 +203,7 @@
 		")",
 		settings->table, accountcode_ai, clidnum_ai, clid_ai, cidani_ai, cidrdnis_ai,
 		ciddnid_ai, exten_ai, context_ai, channel_ai, app_ai, appdata_ai, start,
-		record->event_name, ast_cel_flags2str(record->amaflag), uniqueid_ai, linkedid_ai,
+		record.event_name, ast_cel_flags2str(record.amaflag), uniqueid_ai, linkedid_ai,
 		userfield_ai, peer_ai);
 
 	if (erc == FAIL) {
@@ -251,8 +253,6 @@
 	free(userfield_ai);
 	free(peer_ai);
 
-	free(record);
-
 	return;
 }
 

Modified: team/group/newcdr/include/asterisk/cel.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/include/asterisk/cel.h?view=diff&rev=202108&r1=202107&r2=202108
==============================================================================
--- team/group/newcdr/include/asterisk/cel.h (original)
+++ team/group/newcdr/include/asterisk/cel.h Sat Jun 20 08:58:05 2009
@@ -169,9 +169,19 @@
 		char *userdefevname, const char *extra,
 		const struct ast_channel *peer2);
 
-#define AST_CEL_RECORD_VERSION 1
-
+/*!
+ * \brief Helper struct for getting the fields out of a CEL event
+ */
 struct ast_cel_event_record {
+	/*!
+	 * \brief struct ABI version
+	 * \note This \b must be incremented when the struct changes.
+	 */
+	#define AST_CEL_EVENT_RECORD_VERSION 1
+	/*!
+	 * \brief struct ABI version
+	 * \note This \b must stay as the first member.
+	 */
 	uint32_t version;
 	enum ast_cel_event_type event_type;
 	struct timeval event_time;
@@ -196,7 +206,16 @@
 	const char *peer;
 };
 
-struct ast_cel_event_record *ast_cel_fill_record(const struct ast_event *event);
+/*!
+ * \brief Fill in an ast_cel_event_record from a CEL event
+ *
+ * \param[in] event the CEL event
+ * \param[out] r the ast_cel_event_record to fill in
+ *
+ * \retval 0 success
+ * \retval non-zero failure
+ */
+int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/group/newcdr/main/cel.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/cel.c?view=diff&rev=202108&r1=202107&r2=202108
==============================================================================
--- team/group/newcdr/main/cel.c (original)
+++ team/group/newcdr/main/cel.c Sat Jun 20 08:58:05 2009
@@ -572,15 +572,14 @@
 	}
 }
 
-struct ast_cel_event_record *ast_cel_fill_record(const struct ast_event *e)
-{
-	struct ast_cel_event_record *r = ast_calloc(1, sizeof(*r));
-
-	if (!r)
-		return NULL;
-
-	/* Update this if the struct layout changes */
-	r->version = AST_CEL_RECORD_VERSION;
+int ast_cel_fill_record(const struct ast_event *e, struct ast_cel_event_record *r)
+{
+	if (r->version != AST_CEL_EVENT_RECORD_VERSION) {
+		ast_log(LOG_ERROR, "Module ABI mismatch for ast_cel_event_record.  "
+				"Please ensure all modules were compiled for "
+				"this version of Asterisk.\n");
+		return -1;
+	}
 
 	r->event_type = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TYPE);
 
@@ -594,25 +593,25 @@
 		r->event_name = ast_cel_get_type_name(r->event_type);
 	}
 
-	r->caller_id_name   = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNAME);
-	r->caller_id_num    = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNUM);
-	r->caller_id_ani    = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDANI);
-	r->caller_id_rdnis  = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDRDNIS);
-	r->caller_id_dnid   = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDDNID);
-	r->extension        = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTEN);
-	r->context          = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CONTEXT);
-	r->channel_name     = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CHANNAME);
-	r->application_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPNAME);
-	r->application_data = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPDATA);
-	r->account_code     = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE);
-	r->peer_account     = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE);
-	r->unique_id        = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_UNIQUEID);
-	r->linked_id        = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_LINKEDID);
+	r->caller_id_name   = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNAME), "");
+	r->caller_id_num    = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNUM), "");
+	r->caller_id_ani    = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDANI), "");
+	r->caller_id_rdnis  = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDRDNIS), "");
+	r->caller_id_dnid   = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDDNID), "");
+	r->extension        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTEN), "");
+	r->context          = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CONTEXT), "");
+	r->channel_name     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CHANNAME), "");
+	r->application_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPNAME), "");
+	r->application_data = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPDATA), "");
+	r->account_code     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), "");
+	r->peer_account     = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), "");
+	r->unique_id        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_UNIQUEID), "");
+	r->linked_id        = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_LINKEDID), "");
 	r->amaflag          = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_AMAFLAGS);
-	r->user_field       = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USERFIELD);
-	r->peer             = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_PEER);
-
-	return r;
+	r->user_field       = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USERFIELD), "");
+	r->peer             = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_PEER), "");
+
+	return 0;
 }
 
 static int app_hash(const void *obj, const int flags)




More information about the asterisk-commits mailing list