[asterisk-commits] tilghman: trunk r157006 - in /trunk: cdr/ configs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 14 16:36:30 CST 2008


Author: tilghman
Date: Fri Nov 14 16:36:30 2008
New Revision: 157006

URL: http://svn.digium.com/view/asterisk?view=rev&rev=157006
Log:
Allow setting static values in CDRs

Modified:
    trunk/cdr/cdr_adaptive_odbc.c
    trunk/configs/cdr_adaptive_odbc.conf.sample

Modified: trunk/cdr/cdr_adaptive_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_adaptive_odbc.c?view=diff&rev=157006&r1=157005&r2=157006
==============================================================================
--- trunk/cdr/cdr_adaptive_odbc.c (original)
+++ trunk/cdr/cdr_adaptive_odbc.c Fri Nov 14 16:36:30 2008
@@ -59,6 +59,7 @@
 	char *name;
 	char *cdrname;
 	char *filtervalue;
+	char *staticvalue;
 	SQLSMALLINT type;
 	SQLINTEGER size;
 	SQLSMALLINT decimals;
@@ -187,7 +188,7 @@
 		}
 
 		while ((res = SQLFetch(stmt)) != SQL_NO_DATA && res != SQL_ERROR) {
-			char *cdrvar = "";
+			char *cdrvar = "", *staticvalue = "";
 
 			SQLGetData(stmt,  4, SQL_C_CHAR, columnname, sizeof(columnname), &sqlptr);
 
@@ -203,10 +204,19 @@
 					cdrvar = ast_strip(alias);
 					ast_verb(3, "Found alias %s for column %s in %s@%s\n", cdrvar, columnname, tableptr->table, tableptr->connection);
 					break;
+				} else if (strncmp(var->name, "static", 6) == 0 && strcasecmp(var->value, columnname) == 0) {
+					char *item = ast_strdupa(var->name + 6);
+					item = ast_strip(item);
+					if (item[0] == '"' && item[strlen(item) - 1] == '"') {
+						/* Remove surrounding quotes */
+						item[strlen(item) - 1] = '\0';
+						item++;
+					}
+					staticvalue = item;
 				}
 			}
 
-			entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(columnname) + 1 + strlen(cdrvar) + 1);
+			entry = ast_calloc(sizeof(char), sizeof(*entry) + strlen(columnname) + 1 + strlen(cdrvar) + 1 + strlen(staticvalue) + 1);
 			if (!entry) {
 				ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s' on connection '%s'\n", columnname, table, connection);
 				res = -1;
@@ -218,8 +228,14 @@
 			if (!ast_strlen_zero(cdrvar)) {
 				entry->cdrname = entry->name + strlen(columnname) + 1;
 				strcpy(entry->cdrname, cdrvar);
-			} else /* Point to same place as the column name */
+			} else { /* Point to same place as the column name */
 				entry->cdrname = (char *)entry + sizeof(*entry);
+			}
+
+			if (!ast_strlen_zero(staticvalue)) {
+				entry->staticvalue = entry->cdrname + strlen(entry->cdrname) + 1;
+				strcpy(entry->staticvalue, staticvalue);
+			}
 
 			SQLGetData(stmt,  5, SQL_C_SHORT, &entry->type, sizeof(entry->type), NULL);
 			SQLGetData(stmt,  7, SQL_C_LONG, &entry->size, sizeof(entry->size), NULL);
@@ -372,11 +388,14 @@
 			}
 
 			/* Check if we have a similarly named variable */
-			if (datefield && tableptr->usegmtime) {
+			if (entry->staticvalue) {
+				colptr = ast_strdupa(entry->staticvalue);
+			} else if (datefield && tableptr->usegmtime) {
 				struct timeval date_tv = (datefield == 1) ? cdr->start : (datefield == 2) ? cdr->answer : cdr->end;
 				struct ast_tm tm = { 0, };
 				ast_localtime(&date_tv, &tm, "UTC");
 				ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S", &tm);
+				colptr = colbuf;
 			} else {
 				ast_cdr_getvar(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), 0, datefield ? 0 : 1);
 			}
@@ -410,15 +429,17 @@
 					/* For these two field names, get the rendered form, instead of the raw
 					 * form (but only when we're dealing with a character-based field).
 					 */
-					if (strcasecmp(entry->name, "disposition") == 0)
+					if (strcasecmp(entry->name, "disposition") == 0) {
 						ast_cdr_getvar(cdr, entry->name, &colptr, colbuf, sizeof(colbuf), 0, 0);
-					else if (strcasecmp(entry->name, "amaflags") == 0)
+					} else if (strcasecmp(entry->name, "amaflags") == 0) {
 						ast_cdr_getvar(cdr, entry->name, &colptr, colbuf, sizeof(colbuf), 0, 0);
+					}
 
 					/* Truncate too-long fields */
 					if (entry->type != SQL_GUID) {
-						if (strlen(colptr) > entry->octetlen)
+						if (strlen(colptr) > entry->octetlen) {
 							colptr[entry->octetlen] = '\0';
+						}
 					}
 
 					ast_str_append(&sql, 0, "%s,", entry->name);
@@ -451,8 +472,9 @@
 							break;
 						}
 
-						if (year > 0 && year < 100)
+						if (year > 0 && year < 100) {
 							year += 2000;
+						}
 
 						ast_str_append(&sql, 0, "%s,", entry->name);
 						LENGTHEN_BUF2(17);
@@ -492,8 +514,9 @@
 							break;
 						}
 
-						if (year > 0 && year < 100)
+						if (year > 0 && year < 100) {
 							year += 2000;
+						}
 
 						ast_str_append(&sql, 0, "%s,", entry->name);
 						LENGTHEN_BUF2(26);
@@ -624,10 +647,12 @@
 	AST_RWLIST_UNLOCK(&odbc_tables);
 
 	/* Next time, just allocate buffers that are that big to start with. */
-	if (sql->used > maxsize)
+	if (sql->used > maxsize) {
 		maxsize = sql->used;
-	if (sql2->used > maxsize2)
+	}
+	if (sql2->used > maxsize2) {
 		maxsize2 = sql2->used;
+	}
 
 	ast_free(sql);
 	ast_free(sql2);

Modified: trunk/configs/cdr_adaptive_odbc.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/cdr_adaptive_odbc.conf.sample?view=diff&rev=157006&r1=157005&r2=157006
==============================================================================
--- trunk/configs/cdr_adaptive_odbc.conf.sample (original)
+++ trunk/configs/cdr_adaptive_odbc.conf.sample Fri Nov 14 16:36:30 2008
@@ -37,6 +37,11 @@
 ; Any filter specified MUST match exactly or the CDR will be discarded
 ;filter accountcode => somename
 ;filter src => 123
+;
+; Additionally, we now support setting static values per column.  Reason
+; for this is to allow different sections to specify different values for
+; a certain named column, presumably separated by filters.
+static "Some Special Value" => identifier_code
 
 
 ; On Wednesday 10 September 2008 21:11:16 Tilghman Lesher wrote:




More information about the asterisk-commits mailing list