[asterisk-commits] branch oej/test-this-branch r15105 - in
/team/oej/test-this-branch: cdr/ conf...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sun Mar 26 19:28:40 MST 2006
Author: oej
Date: Sun Mar 26 20:28:37 2006
New Revision: 15105
URL: http://svn.digium.com/view/asterisk?rev=15105&view=rev
Log:
Updates to cdr_radius
Modified:
team/oej/test-this-branch/cdr/cdr_radius.c
team/oej/test-this-branch/configs/cdr.conf.sample
Modified: team/oej/test-this-branch/cdr/cdr_radius.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/cdr/cdr_radius.c?rev=15105&r1=15104&r2=15105&view=diff
==============================================================================
--- team/oej/test-this-branch/cdr/cdr_radius.c (original)
+++ team/oej/test-this-branch/cdr/cdr_radius.c Sun Mar 26 20:28:37 2006
@@ -47,7 +47,8 @@
#include "asterisk/logger.h"
#include "asterisk/utils.h"
-#define DATE_FORMAT "%Y-%m-%d %T"
+/* ISO 8601 standard format */
+#define DATE_FORMAT "%Y-%m-%d %T %z"
#define VENDOR_CODE 22736
@@ -69,9 +70,6 @@
#define PW_AST_AMA_FLAGS 116
#define PW_AST_UNIQUE_ID 117
#define PW_AST_USER_FIELD 118
-
-/* #define RADIUS_LOGUNIQUEID 1 */
-/* #define RADIUS_LOGUSERFIELD 1 */
/*----------------------------------------------------
The values are as follows (taken from cdr_cdsv.c):
@@ -103,13 +101,18 @@
static char *desc = "RADIUS CDR Backend";
static char *name = "radius";
-static char *config = "radius.conf";
+static char *radius_config = "radius.conf";
+static char *cdr_config = "cdr.conf";
static char radiuscfg[AST_CONFIG_MAX_PATH];
AST_MUTEX_DEFINE_STATIC(rc_lock);
-static rc_handle *rh = NULL;
+static int global_usegmtime = -1; /*!< log dates and times in UTC */
+static int global_loguniqueid = -1; /*!< log unique id */
+static int global_loguserfield = -1; /*!< log user field */
+
+static rc_handle *rh = NULL;
static int build_radius_record(VALUE_PAIR **send, struct ast_cdr *cdr)
{
@@ -118,8 +121,6 @@
char buf[253];
struct tm tm;
char timestr[128];
- time_t t;
-
aux = PW_STATUS_STOP;
if (!rc_avpair_add(rh, send, PW_ACCT_STATUS_TYPE, &aux, 0, 0)) {
@@ -190,9 +191,12 @@
return -1;
}
+
/* Start Time */
- t = cdr->start.tv_sec;
- localtime_r(&t, &tm);
+ if (global_usegmtime)
+ gmtime_r(&(cdr->start.tv_sec), &tm);
+ else
+ localtime_r(&(cdr->start.tv_sec), &tm);
strftime(timestr, 128, DATE_FORMAT, &tm);
if (!rc_avpair_add(rh, send, PW_AST_START_TIME, timestr, strlen(timestr), VENDOR_CODE)) {
ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
@@ -200,8 +204,10 @@
}
/* Answer Time */
- t = cdr->answer.tv_sec;
- localtime_r(&t, &tm);
+ if (global_usegmtime)
+ gmtime_r(&(cdr->answer.tv_sec), &tm);
+ else
+ localtime_r(&(cdr->answer.tv_sec), &tm);
strftime(timestr, 128, DATE_FORMAT, &tm);
if (!rc_avpair_add(rh, send, PW_AST_ANSWER_TIME, timestr, strlen(timestr), VENDOR_CODE)) {
ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
@@ -209,8 +215,10 @@
}
/* End Time */
- t = cdr->end.tv_sec;
- localtime_r(&t, &tm);
+ if (global_usegmtime)
+ gmtime_r(&(cdr->end.tv_sec), &tm);
+ else
+ localtime_r(&(cdr->end.tv_sec), &tm);
strftime(timestr, 128, DATE_FORMAT, &tm);
if (!rc_avpair_add(rh, send, PW_AST_END_TIME, timestr, strlen(timestr), VENDOR_CODE)) {
ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
@@ -245,22 +253,24 @@
return -1;
}
-#ifdef RADIUS_LOGUNIQUEID
- /* Unique ID */
- ast_copy_string(buf, cdr->uniqueid, sizeof(buf));
- if (!rc_avpair_add(rh, send, PW_AST_UNIQUE_ID, &buf, strlen(buf), VENDOR_CODE)) {
- ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
- return -1;
- }
-#endif
-#ifdef RADIUS_LOGUSERFIELD
- /* append the user field */
- ast_copy_string(buf, cdr->userfield, sizeof(buf));
- if (!rc_avpair_add(rh, send, PW_AST_USER_FIELD, &buf, strlen(buf), VENDOR_CODE)) {
- ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
- return -1;
- }
-#endif
+ if (global_loguniqueid) {
+ /* Unique ID */
+ ast_copy_string(buf, cdr->uniqueid, sizeof(buf));
+ if (!rc_avpair_add(rh, send, PW_AST_UNIQUE_ID, &buf, strlen(buf), VENDOR_CODE)) {
+ ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
+ return -1;
+ }
+ }
+
+ if (global_loguserfield) {
+ /* append the user field */
+ ast_copy_string(buf, cdr->userfield, sizeof(buf));
+ if (!rc_avpair_add(rh, send, PW_AST_USER_FIELD, &buf, strlen(buf), VENDOR_CODE)) {
+ ast_log(LOG_WARNING, "Failed to add VALUE PAIR. RADIUS CDR not recorded!\n");
+ return -1;
+ }
+ }
+
return 1;
}
@@ -306,9 +316,9 @@
struct ast_variable *var;
char *tmp;
- cfg = ast_config_load(config);
+ cfg = ast_config_load(radius_config);
if (!cfg) {
- ast_log(LOG_WARNING,"Unable to load config for RADIUS CDR's: %s\n", config);
+ ast_log(LOG_WARNING,"Unable to load config for RADIUS CDR's: %s\n", radius_config);
return 0;
}
@@ -346,6 +356,18 @@
return -1;
}
+ cfg = ast_config_load(cdr_config);
+ if (!cfg) {
+ ast_log(LOG_WARNING,"Unable to load config for RADIUS CDR's: %s\n", cdr_config);
+ return 0;
+ }
+
+ global_usegmtime = ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime"));
+ global_loguniqueid = ast_true(ast_variable_retrieve(cfg, "radius", "loguniqueid"));
+ global_loguserfield = ast_true(ast_variable_retrieve(cfg, "radius", "loguserfield"));
+
+ ast_config_destroy(cfg);
+
res = ast_cdr_register(name, desc, radius_log);
if (res) {
ast_log(LOG_ERROR, "Unable to register RADIUS CDR handling\n");
Modified: team/oej/test-this-branch/configs/cdr.conf.sample
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/configs/cdr.conf.sample?rev=15105&r1=15104&r2=15105&view=diff
==============================================================================
--- team/oej/test-this-branch/configs/cdr.conf.sample (original)
+++ team/oej/test-this-branch/configs/cdr.conf.sample Sun Mar 26 20:28:37 2006
@@ -61,3 +61,8 @@
;loguniqueid=yes ;log uniqueid
;loguserfield=yes ;log user field
+;[radius]
+;usegmtime=yes ;log date/time in GMT
+;loguniqueid=yes ;log uniqueid
+;loguserfield=yes ;log user field
+
More information about the asterisk-commits
mailing list