mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-19 19:20:35 +00:00
Allow setting static values in CDRs
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@157006 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -59,6 +59,7 @@ struct columns {
|
|||||||
char *name;
|
char *name;
|
||||||
char *cdrname;
|
char *cdrname;
|
||||||
char *filtervalue;
|
char *filtervalue;
|
||||||
|
char *staticvalue;
|
||||||
SQLSMALLINT type;
|
SQLSMALLINT type;
|
||||||
SQLINTEGER size;
|
SQLINTEGER size;
|
||||||
SQLSMALLINT decimals;
|
SQLSMALLINT decimals;
|
||||||
@@ -187,7 +188,7 @@ static int load_config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while ((res = SQLFetch(stmt)) != SQL_NO_DATA && res != SQL_ERROR) {
|
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);
|
SQLGetData(stmt, 4, SQL_C_CHAR, columnname, sizeof(columnname), &sqlptr);
|
||||||
|
|
||||||
@@ -203,10 +204,19 @@ static int load_config(void)
|
|||||||
cdrvar = ast_strip(alias);
|
cdrvar = ast_strip(alias);
|
||||||
ast_verb(3, "Found alias %s for column %s in %s@%s\n", cdrvar, columnname, tableptr->table, tableptr->connection);
|
ast_verb(3, "Found alias %s for column %s in %s@%s\n", cdrvar, columnname, tableptr->table, tableptr->connection);
|
||||||
break;
|
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) {
|
if (!entry) {
|
||||||
ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s' on connection '%s'\n", columnname, table, connection);
|
ast_log(LOG_ERROR, "Out of memory creating entry for column '%s' in table '%s' on connection '%s'\n", columnname, table, connection);
|
||||||
res = -1;
|
res = -1;
|
||||||
@@ -218,8 +228,14 @@ static int load_config(void)
|
|||||||
if (!ast_strlen_zero(cdrvar)) {
|
if (!ast_strlen_zero(cdrvar)) {
|
||||||
entry->cdrname = entry->name + strlen(columnname) + 1;
|
entry->cdrname = entry->name + strlen(columnname) + 1;
|
||||||
strcpy(entry->cdrname, cdrvar);
|
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);
|
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, 5, SQL_C_SHORT, &entry->type, sizeof(entry->type), NULL);
|
||||||
SQLGetData(stmt, 7, SQL_C_LONG, &entry->size, sizeof(entry->size), NULL);
|
SQLGetData(stmt, 7, SQL_C_LONG, &entry->size, sizeof(entry->size), NULL);
|
||||||
@@ -372,11 +388,14 @@ static int odbc_log(struct ast_cdr *cdr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we have a similarly named variable */
|
/* 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 timeval date_tv = (datefield == 1) ? cdr->start : (datefield == 2) ? cdr->answer : cdr->end;
|
||||||
struct ast_tm tm = { 0, };
|
struct ast_tm tm = { 0, };
|
||||||
ast_localtime(&date_tv, &tm, "UTC");
|
ast_localtime(&date_tv, &tm, "UTC");
|
||||||
ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S", &tm);
|
ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S", &tm);
|
||||||
|
colptr = colbuf;
|
||||||
} else {
|
} else {
|
||||||
ast_cdr_getvar(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), 0, datefield ? 0 : 1);
|
ast_cdr_getvar(cdr, entry->cdrname, &colptr, colbuf, sizeof(colbuf), 0, datefield ? 0 : 1);
|
||||||
}
|
}
|
||||||
@@ -410,16 +429,18 @@ static int odbc_log(struct ast_cdr *cdr)
|
|||||||
/* For these two field names, get the rendered form, instead of the raw
|
/* 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).
|
* 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);
|
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);
|
ast_cdr_getvar(cdr, entry->name, &colptr, colbuf, sizeof(colbuf), 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Truncate too-long fields */
|
/* Truncate too-long fields */
|
||||||
if (entry->type != SQL_GUID) {
|
if (entry->type != SQL_GUID) {
|
||||||
if (strlen(colptr) > entry->octetlen)
|
if (strlen(colptr) > entry->octetlen) {
|
||||||
colptr[entry->octetlen] = '\0';
|
colptr[entry->octetlen] = '\0';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ast_str_append(&sql, 0, "%s,", entry->name);
|
ast_str_append(&sql, 0, "%s,", entry->name);
|
||||||
LENGTHEN_BUF2(strlen(colptr));
|
LENGTHEN_BUF2(strlen(colptr));
|
||||||
@@ -451,8 +472,9 @@ static int odbc_log(struct ast_cdr *cdr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (year > 0 && year < 100)
|
if (year > 0 && year < 100) {
|
||||||
year += 2000;
|
year += 2000;
|
||||||
|
}
|
||||||
|
|
||||||
ast_str_append(&sql, 0, "%s,", entry->name);
|
ast_str_append(&sql, 0, "%s,", entry->name);
|
||||||
LENGTHEN_BUF2(17);
|
LENGTHEN_BUF2(17);
|
||||||
@@ -492,8 +514,9 @@ static int odbc_log(struct ast_cdr *cdr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (year > 0 && year < 100)
|
if (year > 0 && year < 100) {
|
||||||
year += 2000;
|
year += 2000;
|
||||||
|
}
|
||||||
|
|
||||||
ast_str_append(&sql, 0, "%s,", entry->name);
|
ast_str_append(&sql, 0, "%s,", entry->name);
|
||||||
LENGTHEN_BUF2(26);
|
LENGTHEN_BUF2(26);
|
||||||
@@ -624,10 +647,12 @@ early_release:
|
|||||||
AST_RWLIST_UNLOCK(&odbc_tables);
|
AST_RWLIST_UNLOCK(&odbc_tables);
|
||||||
|
|
||||||
/* Next time, just allocate buffers that are that big to start with. */
|
/* Next time, just allocate buffers that are that big to start with. */
|
||||||
if (sql->used > maxsize)
|
if (sql->used > maxsize) {
|
||||||
maxsize = sql->used;
|
maxsize = sql->used;
|
||||||
if (sql2->used > maxsize2)
|
}
|
||||||
|
if (sql2->used > maxsize2) {
|
||||||
maxsize2 = sql2->used;
|
maxsize2 = sql2->used;
|
||||||
|
}
|
||||||
|
|
||||||
ast_free(sql);
|
ast_free(sql);
|
||||||
ast_free(sql2);
|
ast_free(sql2);
|
||||||
|
@@ -37,6 +37,11 @@
|
|||||||
; Any filter specified MUST match exactly or the CDR will be discarded
|
; Any filter specified MUST match exactly or the CDR will be discarded
|
||||||
;filter accountcode => somename
|
;filter accountcode => somename
|
||||||
;filter src => 123
|
;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:
|
; On Wednesday 10 September 2008 21:11:16 Tilghman Lesher wrote:
|
||||||
|
Reference in New Issue
Block a user