]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7303 #comment Added adjustment of time values reported by FS server when RADIUS...
authorSergey Safarov <s.safarov@gmail.com>
Thu, 19 Feb 2015 11:30:55 +0000 (14:30 +0300)
committerSergey Safarov <s.safarov@gmail.com>
Sat, 21 Feb 2015 07:02:11 +0000 (10:02 +0300)
src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c
src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.conf.xml

index 93927bd5eb2f4d1a4e84c56fd5e2f653b5892f19..aecbaf0c6247f2597208a5a353954678f047f904 100644 (file)
@@ -53,6 +53,7 @@ static char *my_deadtime;             /* 0 */
 static char *my_timeout;               /* 5 */
 static char *my_retries;               /* 3 */
 static char my_servers[SERVER_MAX][255];
+static const char *my_timezone="";             /* Asia/Tokyo */
 
 static rc_handle *my_radius_init(void)
 {
@@ -151,6 +152,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
        char *uuid_str;
 
        switch_time_exp_t tm;
+       switch_time_exp_t requested_tm;
        char buffer[32];
 
        char *radius_avpair_data;
@@ -186,6 +188,13 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
                goto end;
        }
 
+       /* GMT offset may change according daylight saving rules. Evaluating GMT offset each time */
+       if (zstr(my_timezone)) {
+               switch_time_exp_lt(&requested_tm, switch_micro_time_now());
+       } else {
+               switch_time_exp_tz_name(my_timezone, &requested_tm, switch_micro_time_now());
+       }
+
        /* Create the radius packet */
 
        /* Set Status Type */
@@ -314,7 +323,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
                                }
                        }
                        if (callstartdate > 0) {
-                               switch_time_exp_lt(&tm, callstartdate);
+                               switch_time_exp_tz(&tm, callstartdate, requested_tm.tm_gmtoff);
                                switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
                                                                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                                                                tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
@@ -326,7 +335,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
                        }
 
                        if (callanswerdate > 0) {
-                               switch_time_exp_lt(&tm, callanswerdate);
+                               switch_time_exp_tz(&tm, callanswerdate, requested_tm.tm_gmtoff);
                                switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
                                                                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                                                                tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
@@ -338,7 +347,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
                        }
 
                        if (calltransferdate > 0) {
-                               switch_time_exp_lt(&tm, calltransferdate);
+                               switch_time_exp_tz(&tm, calltransferdate, requested_tm.tm_gmtoff);
                                switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
                                                                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                                                                tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
@@ -350,7 +359,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session)
                        }
 
                        if (callenddate > 0) {
-                               switch_time_exp_lt(&tm, callenddate);
+                               switch_time_exp_tz(&tm, callenddate, requested_tm.tm_gmtoff);
                                switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
                                                                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                                                                tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
@@ -431,6 +440,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
        char *uuid_str;
 
        switch_time_exp_t tm;
+       switch_time_exp_t requested_tm;
+
        char buffer[32] = "";
 
        char *radius_avpair_data;
@@ -467,6 +478,13 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
                goto end;
        }
 
+       /* GMT offset may change according daylight saving rules. Evaluating GMT offset each time */
+       if (zstr(my_timezone)) {
+               switch_time_exp_lt(&requested_tm, time(NULL));
+       } else {
+               switch_time_exp_tz_name(my_timezone, &requested_tm, time(NULL));
+       }
+
        /* Create the radius packet */
 
        /* Set Status Type */
@@ -617,7 +635,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
                        }
 
                        if (callstartdate > 0) {
-                               switch_time_exp_lt(&tm, callstartdate);
+                               switch_time_exp_tz(&tm, callstartdate, requested_tm.tm_gmtoff);
                                switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
                                                                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                                                                tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
@@ -629,7 +647,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
                        }
 
                        if (callanswerdate > 0) {
-                               switch_time_exp_lt(&tm, callanswerdate);
+                               switch_time_exp_tz(&tm, callanswerdate, requested_tm.tm_gmtoff);
                                switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
                                                                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                                                                tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
@@ -641,7 +659,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
                        }
 
                        if (calltransferdate > 0) {
-                               switch_time_exp_lt(&tm, calltransferdate);
+                               switch_time_exp_tz(&tm, calltransferdate, requested_tm.tm_gmtoff);
                                switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
                                                                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                                                                tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
@@ -653,7 +671,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
                        }
 
                        if (callenddate > 0) {
-                               switch_time_exp_lt(&tm, callenddate);
+                               switch_time_exp_tz(&tm, callenddate, requested_tm.tm_gmtoff);
                                switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d",
                                                                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                                                                tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_usec, tm.tm_gmtoff / 3600, tm.tm_gmtoff % 3600);
@@ -729,6 +747,7 @@ static switch_status_t load_config(void)
 
        int num_servers = 0;
        int i = 0;
+       static char *tz_name;
 
        my_timeout = "5";
        my_retries = "3";
@@ -768,6 +787,8 @@ static switch_status_t load_config(void)
                                my_retries = strdup(val);
                        } else if (!strcmp(var, "radius_deadtime")) {
                                my_deadtime = strdup(val);
+                       } else if (!strcmp(var, "timezone")) {
+                               tz_name = strdup(val);
                        }
                }
        }
@@ -779,6 +800,15 @@ static switch_status_t load_config(void)
                return SWITCH_STATUS_TERM;
        }
 
+       if (!zstr(tz_name)) {
+               if (switch_lookup_timezone(tz_name)) {
+                       my_timezone= tz_name;
+               } else {
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find timezone %s\n, Setting timezone to GMT", tz_name);
+                       my_timezone= "GMT";
+               }
+       }
+
        /* If we made it this far, we succeeded */
        return SWITCH_STATUS_SUCCESS;
 }
index 5ecaa7f8340ba2592ad69075cc538f4438758624..fea5194b816e268069eac900aff7a57b2c8c3224 100644 (file)
                         such interval and so on. This option is no-op if there is only one
                         server in the list. Set to 0 in order to disable the feature. -->
                <param name="radius_deadtime" value="0"/>
+               <!-- Timezone name from "autoload_configs/timezones.conf.xml".
+                        All time related values will be adjusted for this timezone.
+                        If param is not provided used is local server timezone -->
+               <!-- <param name="timezone" value="Asia/Tokyo"/> -->
        </settings>
 </configuration>