freeswitch: bump to 1.10.10
[feed/telephony.git] / net / freeswitch / patches / 490-build-properly-fix-time_t-issues.patch
1 From 80492dcd5a6a859cf4bfc7d22ba594c64e94e3fd Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?=C3=89rico=20Nogueira?= <erico.erc@gmail.com>
3 Date: Wed, 27 Oct 2021 20:38:28 -0300
4 Subject: [PATCH] [build] properly fix time_t issues
5
6 aa71d87528643fd1b3897a64ecec8c11e92b5b55 tried fixing the issue by
7 adding yet another case to the TIME_T_FMT definition, but hardcoding
8 values as hinted at by internal variables or by platform is not future
9 proof or allows for improvements.
10
11 The most portable fix for time_t handling is to always cast it to
12 (long long) for printing and use "lld" for formatting.
13 ---
14 src/include/switch_platform.h | 20 +++-----------------
15 src/mod/applications/mod_httapi/mod_httapi.c | 2 +-
16 src/mod/endpoints/mod_sofia/sofia_presence.c | 3 ++-
17 src/switch_channel.c | 20 ++++++++++----------
18 src/switch_ivr_originate.c | 2 +-
19 5 files changed, 17 insertions(+), 30 deletions(-)
20
21 --- a/src/include/switch_platform.h
22 +++ b/src/include/switch_platform.h
23 @@ -245,10 +245,6 @@ typedef intptr_t switch_ssize_t;
24 #define SWITCH_INT64_T_FMT "lld"
25 #define SWITCH_UINT64_T_FMT "llu"
26
27 -#ifndef TIME_T_FMT
28 -#define TIME_T_FMT SWITCH_INT64_T_FMT
29 -#endif
30 -
31 #else
32 #ifndef SWITCH_SSIZE_T_FMT
33 #define SWITCH_SSIZE_T_FMT (sizeof (switch_ssize_t) == sizeof (long) ? "ld" : sizeof (switch_ssize_t) == sizeof (int) ? "d" : "lld")
34 @@ -266,25 +262,15 @@ typedef intptr_t switch_ssize_t;
35 #define SWITCH_UINT64_T_FMT (sizeof (long) == 8 ? "lu" : "llu")
36 #endif
37
38 -#ifndef TIME_T_FMT
39 -#if defined(__FreeBSD__) && SIZEOF_VOIDP == 4
40 -#define TIME_T_FMT "d"
41 -#else
42 -#if __USE_TIME_BITS64
43 -#define TIME_T_FMT SWITCH_INT64_T_FMT
44 -#else
45 -#define TIME_T_FMT "ld"
46 -#endif
47 -#endif
48 -#endif
49 -
50 -
51 #if UINTPTR_MAX == 0xffffffffffffffff
52 #define FS_64BIT 1
53 #endif
54
55 #endif
56
57 +#define TIME_T_FMT "lld"
58 +#define TIME_T_CAST(x) ((long long)(x))
59 +
60 #if defined(__sun__) && (defined(__x86_64) || defined(__arch64__))
61 #define SWITCH_TIME_T_FMT SWITCH_SIZE_T_FMT
62 #else
63 --- a/src/mod/applications/mod_httapi/mod_httapi.c
64 +++ b/src/mod/applications/mod_httapi/mod_httapi.c
65 @@ -2742,7 +2742,7 @@ static switch_status_t write_meta_file(h
66
67 switch_snprintf(write_data, sizeof(write_data),
68 "%" TIME_T_FMT ":%s",
69 - switch_epoch_time_now(NULL) + ttl,
70 + TIME_T_CAST(switch_epoch_time_now(NULL) + ttl),
71 data);
72
73
74 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c
75 +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c
76 @@ -4198,7 +4198,8 @@ void sofia_presence_handle_sip_i_subscri
77 sql = switch_mprintf("insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname,expires,rcd,profile_name) "
78 "values ('%q','%q','%q','seized','%q',%"TIME_T_FMT",%ld,'%q')",
79 to_user, to_host, switch_str_nil(p), mod_sofia_globals.hostname,
80 - switch_epoch_time_now(NULL) + exp_delta, (long)now, profile->name);
81 + TIME_T_CAST(switch_epoch_time_now(NULL) + exp_delta), (long)now,
82 + profile->name);
83
84 if (mod_sofia_globals.debug_sla > 1) {
85 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEIZE SQL %s\n", sql);
86 --- a/src/switch_channel.c
87 +++ b/src/switch_channel.c
88 @@ -4662,39 +4662,39 @@ SWITCH_DECLARE(switch_status_t) switch_c
89
90 tt_created = (time_t) (caller_profile->times->created / 1000000);
91 mtt_created = (time_t) (caller_profile->times->created / 1000);
92 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_created);
93 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_created));
94 switch_channel_set_variable(channel, "start_epoch", tmp);
95 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
96 switch_channel_set_variable(channel, "start_uepoch", tmp);
97
98 tt_prof_created = (time_t) (caller_profile->times->profile_created / 1000000);
99 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_prof_created);
100 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_prof_created));
101 switch_channel_set_variable(channel, "profile_start_epoch", tmp);
102 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->profile_created);
103 switch_channel_set_variable(channel, "profile_start_uepoch", tmp);
104
105 tt_answered = (time_t) (caller_profile->times->answered / 1000000);
106 mtt_answered = (time_t) (caller_profile->times->answered / 1000);
107 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_answered);
108 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_answered));
109 switch_channel_set_variable(channel, "answer_epoch", tmp);
110 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
111 switch_channel_set_variable(channel, "answer_uepoch", tmp);
112
113 tt_bridged = (time_t) (caller_profile->times->bridged / 1000000);
114 mtt_bridged = (time_t) (caller_profile->times->bridged / 1000);
115 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_bridged);
116 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_bridged));
117 switch_channel_set_variable(channel, "bridge_epoch", tmp);
118 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->bridged);
119 switch_channel_set_variable(channel, "bridge_uepoch", tmp);
120
121 tt_last_hold = (time_t) (caller_profile->times->last_hold / 1000000);
122 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_last_hold);
123 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_last_hold));
124 switch_channel_set_variable(channel, "last_hold_epoch", tmp);
125 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->last_hold);
126 switch_channel_set_variable(channel, "last_hold_uepoch", tmp);
127
128 tt_hold_accum = (time_t) (caller_profile->times->hold_accum / 1000000);
129 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_hold_accum);
130 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_hold_accum));
131 switch_channel_set_variable(channel, "hold_accum_seconds", tmp);
132 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hold_accum);
133 switch_channel_set_variable(channel, "hold_accum_usec", tmp);
134 @@ -4702,28 +4702,28 @@ SWITCH_DECLARE(switch_status_t) switch_c
135 switch_channel_set_variable(channel, "hold_accum_ms", tmp);
136
137 tt_resurrected = (time_t) (caller_profile->times->resurrected / 1000000);
138 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_resurrected);
139 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_resurrected));
140 switch_channel_set_variable(channel, "resurrect_epoch", tmp);
141 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->resurrected);
142 switch_channel_set_variable(channel, "resurrect_uepoch", tmp);
143
144 tt_progress = (time_t) (caller_profile->times->progress / 1000000);
145 mtt_progress = (time_t) (caller_profile->times->progress / 1000);
146 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress);
147 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_progress));
148 switch_channel_set_variable(channel, "progress_epoch", tmp);
149 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress);
150 switch_channel_set_variable(channel, "progress_uepoch", tmp);
151
152 tt_progress_media = (time_t) (caller_profile->times->progress_media / 1000000);
153 mtt_progress_media = (time_t) (caller_profile->times->progress_media / 1000);
154 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_progress_media);
155 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_progress_media));
156 switch_channel_set_variable(channel, "progress_media_epoch", tmp);
157 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->progress_media);
158 switch_channel_set_variable(channel, "progress_media_uepoch", tmp);
159
160 tt_hungup = (time_t) (caller_profile->times->hungup / 1000000);
161 mtt_hungup = (time_t) (caller_profile->times->hungup / 1000);
162 - switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_hungup);
163 + switch_snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, TIME_T_CAST(tt_hungup));
164 switch_channel_set_variable(channel, "end_epoch", tmp);
165 switch_snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
166 switch_channel_set_variable(channel, "end_uepoch", tmp);
167 --- a/src/switch_ivr_originate.c
168 +++ b/src/switch_ivr_originate.c
169 @@ -800,7 +800,7 @@ static uint8_t check_channel_status(orig
170 time_t elapsed = switch_epoch_time_now(NULL) - start;
171 oglobals->originate_status[i].per_channel_progress_timelimit_sec = elapsed + extend_timeout;
172 oglobals->originate_status[i].per_channel_timelimit_sec = elapsed + extend_timeout;
173 - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "elapsed %" TIME_T_FMT ", timelimit extended to %u\n", elapsed, oglobals->originate_status[i].per_channel_timelimit_sec);
174 + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "elapsed %" TIME_T_FMT ", timelimit extended to %u\n", TIME_T_CAST(elapsed), oglobals->originate_status[i].per_channel_timelimit_sec);
175 } else if (oglobals->cancel_timeout || cancel_timeout) {
176 /* cancel timeout for this leg only */
177 oglobals->originate_status[i].per_channel_progress_timelimit_sec = 0;