]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add tz stuff to mod_say_en, other langs need similar code
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 31 Oct 2008 20:24:06 +0000 (20:24 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 31 Oct 2008 20:24:06 +0000 (20:24 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10214 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_voicemail/mod_voicemail.c
src/mod/say/mod_say_en/mod_say_en.c
src/switch_time.c

index 3036f17953dfb74658905be949ad7c5d53c2ebff..23e0a467d48a6858f0b9d6f9b0851f839f719dd3 100644 (file)
@@ -1655,7 +1655,8 @@ SWITCH_DECLARE(void) switch_core_memory_reclaim_all(void);
 SWITCH_DECLARE(void) switch_core_setrlimits(void);
 SWITCH_DECLARE(void) switch_time_sync(void);
 SWITCH_DECLARE(time_t) switch_timestamp(time_t *t);
-SWITCH_DECLARE(switch_status_t) switch_strftime_tz(const char *tz, const char *format, char *date, size_t len);
+SWITCH_DECLARE(switch_status_t) switch_strftime_tz(const char *tz, const char *format, char *date, size_t len, switch_time_t thetime);
+SWITCH_DECLARE(switch_status_t) switch_time_exp_tz_name(const char *tz, switch_time_exp_t *tm, switch_time_t thetime);
 SWITCH_DECLARE(void) switch_load_network_lists(switch_bool_t reload);
 SWITCH_DECLARE(switch_bool_t) switch_check_network_list_ip_token(const char *ip_str, const char *list_name, const char **token);
 #define switch_check_network_list_ip(_ip_str, _list_name) switch_check_network_list_ip_token(_ip_str, _list_name, NULL)
index 84afb4a2d8ba939faeeefae0e5904500e1b52411..f1ed508abe92e35aefbdbc13fe19ea390a5f2f04 100644 (file)
@@ -2763,7 +2763,7 @@ SWITCH_STANDARD_API(strftime_tz_api_function)
                }
        }
        
-       if (switch_strftime_tz(tz_name, format, date, sizeof(date)) == SWITCH_STATUS_SUCCESS) { /* The lookup of the zone may fail. */
+       if (switch_strftime_tz(tz_name, format, date, sizeof(date), 0) == SWITCH_STATUS_SUCCESS) { /* The lookup of the zone may fail. */
                stream->write_function(stream, "%s", date);
        } else {
                stream->write_function(stream, "-ERR Invalid Timezone\n");
index f02a9a70e5b57a9211bc46d66a77411e0eda84f5..0eb11ad825df06cbd7b0044ffd8162697019ae30 100644 (file)
@@ -1983,11 +1983,23 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro
 
                                }
 
-                               x_params = switch_xml_child(x_user, "params");
+                               
 
                                thepass = thehash = NULL;
                                switch_snprintf(sql, sizeof(sql), "select * from voicemail_prefs where username='%s' and domain='%s'", myid, domain_name);
                                vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
+
+                               x_params = switch_xml_child(x_user, "variables");
+                               for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
+                                       const char *var = switch_xml_attr_soft(x_param, "name");
+                                       const char *val = switch_xml_attr_soft(x_param, "value");
+
+                                       if (!strcasecmp(var, "timezone")) {
+                                               switch_channel_set_variable(channel, var, val);
+                                       }
+                               }
+
+                               x_params = switch_xml_child(x_user, "params");
                                for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
                                        const char *var = switch_xml_attr_soft(x_param, "name");
                                        const char *val = switch_xml_attr_soft(x_param, "value");
@@ -2012,6 +2024,9 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro
                                                vm_email = switch_core_session_strdup(session, val);
                                        } else if (!strcasecmp(var, "storage-dir")) {
                                                vm_storage_dir = switch_core_session_strdup(session, val);
+
+                                       } else if (!strcasecmp(var, "timezone")) {
+                                               switch_channel_set_variable(channel, var, val);
                                        } 
 
                                }
@@ -2188,6 +2203,16 @@ static switch_status_t deliver_vm(vm_profile_t *profile,
                filename = path;
        }
 
+       x_params = switch_xml_child(x_user, "variables");
+       for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
+               const char *var = switch_xml_attr_soft(x_param, "name");
+               const char *val = switch_xml_attr_soft(x_param, "value");
+               
+               if (!strcasecmp(var, "timezone")) {
+                       vm_timezone = switch_core_strdup(pool, val);
+               }
+       }
+
        x_params = switch_xml_child(x_user, "params");
 
        for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
@@ -2297,7 +2322,7 @@ static switch_status_t deliver_vm(vm_profile_t *profile,
                message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages,
                                          &total_new_urgent_messages, &total_saved_urgent_messages);
 
-               if (switch_strlen_zero(vm_timezone) || (switch_strftime_tz(vm_timezone, profile->date_fmt, date, sizeof(date)) != SWITCH_STATUS_SUCCESS)) {
+               if (switch_strlen_zero(vm_timezone) || (switch_strftime_tz(vm_timezone, profile->date_fmt, date, sizeof(date), 0) != SWITCH_STATUS_SUCCESS)) {
                        switch_time_exp_lt(&tm, switch_timestamp_now());
                        switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm);
                }
index 9932940c262e74d4acd3d65910334b0b917a7151..9906d201f0e7333a965dd8d679efbe9ad6f39ec2 100644 (file)
@@ -266,7 +266,9 @@ static switch_status_t en_say_time(switch_core_session_t *session, char *tosay,
        switch_time_t target = 0;
        switch_time_exp_t tm;
        uint8_t say_date = 0, say_time = 0;
-
+       switch_channel_t *channel = switch_core_session_get_channel(session);
+       const char *tz = switch_channel_get_variable(channel, "timezone");
+       
        if (type == SST_TIME_MEASUREMENT) {
                int64_t hours = 0;
                int64_t minutes = 0;
@@ -291,7 +293,7 @@ static switch_status_t en_say_time(switch_core_session_t *session, char *tosay,
                                }
                        }
                } else {
-                       if ((seconds = atoi(tosay)) <= 0) {
+                       if ((seconds = atol(tosay)) <= 0) {
                                seconds = (int64_t) switch_timestamp(NULL);
                        }
 
@@ -347,12 +349,22 @@ static switch_status_t en_say_time(switch_core_session_t *session, char *tosay,
                return SWITCH_STATUS_SUCCESS;
        }
 
-       if ((t = atoi(tosay)) > 0) {
+       if ((t = atol(tosay)) > 0) {
                target = switch_time_make(t, 0);
        } else {
                target = switch_timestamp_now();
        }
-       switch_time_exp_lt(&tm, target);
+       
+       if (tz) {
+               int check = atoi(tz);
+               if (check) {
+                       switch_time_exp_tz(&tm, target, check);
+               } else {
+                       switch_time_exp_tz_name(tz, &tm, target);
+               }
+       } else {
+               switch_time_exp_lt(&tm, target);
+       }
 
        switch (type) {
        case SST_CURRENT_DATE_TIME:
index 97ff8e810f0a1fffcbfe841f5f5ba473b6f4c3c0..0a9d8a34fc9c3a5fbb1bea54a0f216e15e9ceec7 100644 (file)
@@ -543,9 +543,39 @@ static void event_handler(switch_event_t *event)
 
 static void tztime(const time_t * const timep, const char *tzstring, struct tm * const tmp );
 
-SWITCH_DECLARE(switch_status_t) switch_strftime_tz(const char *tz, const char *format, char *date, size_t len)
+SWITCH_DECLARE(switch_status_t) switch_time_exp_tz_name(const char *tz, switch_time_exp_t *tm, switch_time_t thetime)
+{
+       struct tm xtm = { 0 };
+       const char *tz_name = tz;
+    const char *tzdef;
+       time_t timep;
+       
+       if (!thetime) {
+        thetime = switch_timestamp_now();
+    }
+
+       timep =  (thetime) / (int64_t) (1000000);
+
+       if (!switch_strlen_zero(tz_name)) {
+               tzdef = switch_lookup_timezone( tz_name );
+       } else {
+               /* We set the default timezone to GMT. */
+               tz_name="GMT";
+               tzdef="GMT";
+       }
+       
+       if (tzdef) { /* The lookup of the zone may fail. */
+               tztime( &timep, tzdef, &xtm );
+               tm2switchtime( &xtm, tm);
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+       return SWITCH_STATUS_FALSE;
+
+}
+
+SWITCH_DECLARE(switch_status_t) switch_strftime_tz(const char *tz, const char *format, char *date, size_t len, switch_time_t thetime)
 {
-       switch_time_t thetime;
        time_t timep;
 
        const char *tz_name = tz;
@@ -556,7 +586,9 @@ SWITCH_DECLARE(switch_status_t) switch_strftime_tz(const char *tz, const char *f
        struct tm tm = { 0 };
        switch_time_exp_t stm;
 
-       thetime = switch_timestamp_now();
+       if (!thetime) {
+               thetime = switch_timestamp_now();
+       }
 
        timep =  (thetime) / (int64_t) (1000000);