aboutsummaryrefslogtreecommitdiffstats
path: root/cdr
diff options
context:
space:
mode:
authormogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-02 21:04:04 +0000
committermogorman <mogorman@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-02 21:04:04 +0000
commit4f4909d208c16bc7c17a130b79f638a9892503c9 (patch)
tree8873da8fe1c0e9b44b0372cd803f681f546f9e26 /cdr
parent0bdc8c8d9bbbad77b0b4e6b4e852a48c497eff48 (diff)
cdr_csv logging parameters in cdr.conf
usegmtime, log date/time in GMT loguniqueid log uniqueid loguserfield log user field patch provided by bug 5015 git-svn-id: http://svn.digium.com/svn/asterisk/trunk@11586 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cdr')
-rw-r--r--cdr/cdr_csv.c78
1 files changed, 70 insertions, 8 deletions
diff --git a/cdr/cdr_csv.c b/cdr/cdr_csv.c
index 7145262c0..ab48ca6d5 100644
--- a/cdr/cdr_csv.c
+++ b/cdr/cdr_csv.c
@@ -41,6 +41,7 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#include "asterisk/config.h"
#include "asterisk/channel.h"
#include "asterisk/cdr.h"
#include "asterisk/module.h"
@@ -52,6 +53,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define DATE_FORMAT "%Y-%m-%d %T"
+static int usegmtime = 0;
+static int loguniqueid = 0;
+static int loguserfield = 0;
+static char *config = "cdr.conf";
+
/* #define CSV_LOGUNIQUEID 1 */
/* #define CSV_LOGUSERFIELD 1 */
@@ -89,6 +95,58 @@ static char *name = "csv";
static FILE *mf = NULL;
+
+static int load_config(void)
+{
+ struct ast_config *cfg;
+ struct ast_variable *var;
+ char *tmp;
+
+ usegmtime = 0;
+ loguniqueid = 0;
+ loguserfield = 0;
+
+ cfg = ast_config_load(config);
+
+ if (!cfg) {
+ ast_log(LOG_WARNING, "unable to load config: %s\n", config);
+ return -1;
+ }
+
+ var = ast_variable_browse(cfg, "csv");
+ if (!var) {
+ ast_config_destroy(cfg);
+ return -1;
+ }
+
+ tmp = ast_variable_retrieve(cfg, "csv", "usegmtime");
+ if (tmp) {
+ usegmtime = ast_true(tmp);
+ if (usegmtime) {
+ ast_log(LOG_DEBUG, "logging time in GMT\n");
+ }
+ }
+
+ tmp = ast_variable_retrieve(cfg, "csv", "loguniqueid");
+ if (tmp) {
+ loguniqueid = ast_true(tmp);
+ if (loguniqueid) {
+ ast_log(LOG_DEBUG, "logging CDR field UNIQUEID\n");
+ }
+ }
+
+ tmp = ast_variable_retrieve(cfg, "csv", "loguserfield");
+ if (tmp) {
+ loguserfield = ast_true(tmp);
+ if (loguserfield) {
+ ast_log(LOG_DEBUG, "logging CDR user-defined field\n");
+ }
+ }
+
+ ast_config_destroy(cfg);
+ return 0;
+}
+
static int append_string(char *buf, char *s, size_t bufsize)
{
int pos = strlen(buf);
@@ -140,7 +198,11 @@ static int append_date(char *buf, struct timeval tv, size_t bufsize)
strncat(buf, ",", bufsize - strlen(buf) - 1);
return 0;
}
- localtime_r(&t,&tm);
+ if (usegmtime) {
+ gmtime_r(&t,&tm);
+ } else {
+ localtime_r(&t,&tm);
+ }
strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
return append_string(buf, tmp, bufsize);
}
@@ -181,15 +243,12 @@ static int build_csv_record(char *buf, size_t bufsize, struct ast_cdr *cdr)
append_string(buf, ast_cdr_disp2str(cdr->disposition), bufsize);
/* AMA Flags */
append_string(buf, ast_cdr_flags2str(cdr->amaflags), bufsize);
-
-#ifdef CSV_LOGUNIQUEID
/* Unique ID */
- append_string(buf, cdr->uniqueid, bufsize);
-#endif
-#ifdef CSV_LOGUSERFIELD
+ if (loguniqueid)
+ append_string(buf, cdr->uniqueid, bufsize);
/* append the user field */
- append_string(buf, cdr->userfield,bufsize);
-#endif
+ if(loguserfield)
+ append_string(buf, cdr->userfield,bufsize);
/* If we hit the end of our buffer, log an error */
if (strlen(buf) < bufsize - 5) {
/* Trim off trailing comma */
@@ -268,6 +327,8 @@ int unload_module(void)
int load_module(void)
{
int res;
+
+ load_config();
res = ast_cdr_register(name, desc, csv_log);
if (res) {
@@ -280,6 +341,7 @@ int load_module(void)
int reload(void)
{
+ load_config();
return 0;
}