kamailio: fix dep for keepalive module
[feed/telephony.git] / net / kamailio / patches / 170-core-add-support-for-time64-libcs.patch
1 From 3f224cff811e970ad8279c89fffbfd800b85bb64 Mon Sep 17 00:00:00 2001
2 From: Sebastian Kemper <sebastian_ml@gmx.net>
3 Date: Sat, 23 Oct 2021 01:23:40 +0200
4 Subject: [PATCH] core: add support for time64 libcs
5
6 libcs are implementing changes to fix the year 2038 issue on 32 bit
7 platforms (see [1]). musl libc already went ahead and implemented it,
8 starting with musl-1.2.0 (see [2]).
9
10 This commit adds the groundwork for always using the "lld" format when
11 dealing with time_t and casting the values to be formatted to (long
12 long). The aim is to be future proof and portable.
13
14 Example warning when not using TIME_T_FMT while compiling for a 32 bit
15 target using a time64 libc:
16
17 In file included from auth_identity.c:50:
18 auth_identity.c: In function 'check_date':
19 ../../core/dprint.h:316:73: warning: format '%ld' expects argument of type 'long int', but argument 11 has type 'time_t' {aka 'long long int'} [-Wformat=]
20 316 | fprintf(stderr, "%2d(%d) %s: %.*s%s%s%s" fmt, \
21 | ^~~~~~~~~~~~~~~~~~~~~~~~
22 ../../core/dprint.h:340:25: note: in expansion of macro 'LOG_FX'
23 340 | LOG_FX(facility, level, lname, prefix, _FUNC_NAME_, fmt, ## args)
24 | ^~~~~~
25 ../../core/dprint.h:346:25: note: in expansion of macro 'LOG_FL'
26 346 | LOG_FL(facility, level, NULL, prefix, fmt, ## args)
27 | ^~~~~~
28 ../../core/dprint.h:349:25: note: in expansion of macro 'LOG_FP'
29 349 | LOG_FP(DEFAULT_FACILITY, (level), LOC_INFO, fmt, ## args)
30 | ^~~~~~
31 auth_identity.c:594:17: note: in expansion of macro 'LOG'
32 594 | LOG(L_INFO, "AUTH_IDENTITY VERIFIER: Outdated date header value (%ld sec)\n", tnow - tmsg + glb_iauthval);
33 | ^~~
34
35 [1] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign
36 [2] https://musl.libc.org/time64.html
37
38 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
39
40 auth_identity: use TIME_T_FMT
41
42 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
43
44 cdp: use TIME_T_FMT
45
46 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
47
48 db_redis: use TIME_T_FMT
49
50 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
51
52 ims_charging: use TIME_T_FMT
53
54 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
55
56 ims_dialog: use TIME_T_FMT
57
58 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
59
60 ims_icscf: use TIME_T_FMT
61
62 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
63
64 ims_registrar_pcscf: use TIME_T_FMT
65
66 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
67
68 ims_registrar_scscf: use TIME_T_FMT
69
70 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
71
72 ims_usrloc_scscf: use TIME_T_FMT
73
74 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
75
76 nat_traversal: use TIME_T_FMT
77
78 The size of the time_t destination is unknown as it is depending on the
79 platform. So we "read into a known-size integer (either int or long
80 long) and then assign the value to a time_t as a second step" (quote
81 from [1]).
82
83 [1] https://stackoverflow.com/questions/4171478/how-to-read-data-into-a-time-t-variable-using-scanf
84
85 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
86
87 xhttp_pi: use TIME_T_FMT
88
89 Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
90 ---
91 src/core/dprint.h | 2 ++
92 src/modules/auth_identity/auth_identity.c | 2 +-
93 src/modules/cdp/routing.c | 4 ++--
94 src/modules/db_redis/redis_dbase.c | 2 +-
95 src/modules/ims_charging/ims_ro.c | 3 ++-
96 src/modules/ims_dialog/dlg_handlers.c | 2 +-
97 src/modules/ims_icscf/scscf_list.c | 7 ++++---
98 src/modules/ims_registrar_pcscf/notify.c | 4 ++--
99 src/modules/ims_registrar_pcscf/save.c | 5 +++--
100 src/modules/ims_registrar_scscf/registrar_notify.c | 5 +++--
101 src/modules/ims_registrar_scscf/save.c | 2 +-
102 src/modules/ims_usrloc_scscf/impurecord.c | 7 ++++---
103 src/modules/nat_traversal/nat_traversal.c | 5 ++++-
104 src/modules/xhttp_pi/xhttp_pi_fnc.c | 8 ++++----
105 14 files changed, 34 insertions(+), 24 deletions(-)
106
107 --- a/src/core/dprint.h
108 +++ b/src/core/dprint.h
109 @@ -35,6 +35,8 @@
110 #include "compiler_opt.h"
111 #include "cfg_core.h"
112
113 +#define TIME_T_FMT "lld"
114 +#define TIME_T_CAST(x) ((long long)(x))
115
116 /** dicover the function name */
117 /* C >= 99 has __func__, older gcc versions have __FUNCTION__ */
118 --- a/src/modules/auth_identity/auth_identity.c
119 +++ b/src/modules/auth_identity/auth_identity.c
120 @@ -591,7 +591,7 @@ static int check_date(struct sip_msg* ms
121 }
122
123 if (tnow > tmsg + glb_iauthval) {
124 - LOG(L_INFO, "AUTH_IDENTITY VERIFIER: Outdated date header value (%ld sec)\n", tnow - tmsg + glb_iauthval);
125 + LOG(L_INFO, "AUTH_IDENTITY VERIFIER: Outdated date header value (%" TIME_T_FMT " sec)\n", TIME_T_CAST(tnow - tmsg + glb_iauthval));
126 return -4;
127 } else
128 LOG(AUTH_DBG_LEVEL, "AUTH_IDENTITY VERIFIER: Date header value OK\n");
129 --- a/src/modules/cdp/routing.c
130 +++ b/src/modules/cdp/routing.c
131 @@ -146,10 +146,10 @@ peer* get_first_connected_route(cdp_sess
132 }
133
134 least_recent_time = peers[0]->last_selected;
135 - LM_DBG("peer [%.*s] was last used @ %ld\n", peers[0]->fqdn.len, peers[0]->fqdn.s, peers[0]->last_selected);
136 + LM_DBG("peer [%.*s] was last used @ %" TIME_T_FMT "\n", peers[0]->fqdn.len, peers[0]->fqdn.s, TIME_T_CAST(peers[0]->last_selected));
137 p = peers[0];
138 for (j = 1; j < peer_count; j++) {
139 - LM_DBG("Peer [%.*s] was last used at [%ld]\n", peers[j]->fqdn.len, peers[j]->fqdn.s, peers[j]->last_selected);
140 + LM_DBG("Peer [%.*s] was last used at [%" TIME_T_FMT "]\n", peers[j]->fqdn.len, peers[j]->fqdn.s, TIME_T_CAST(peers[j]->last_selected));
141 if (peers[j]->last_selected < least_recent_time) {
142 least_recent_time = peers[j]->last_selected;
143 p = peers[j];
144 --- a/src/modules/db_redis/redis_dbase.c
145 +++ b/src/modules/db_redis/redis_dbase.c
146 @@ -142,7 +142,7 @@ static int db_redis_val2str(const db_val
147 _str->s[_str->len] = '\0';
148 break;
149 case DB1_DATETIME:
150 - LM_DBG("converting datetime value %ld to str\n", VAL_TIME(v));
151 + LM_DBG("converting datetime value %" TIME_T_FMT " to str\n", TIME_T_CAST(VAL_TIME(v)));
152 _str->s = (char*)pkg_malloc(_str->len);
153 if (!_str->s) goto memerr;
154 localtime_r(&(VAL_TIME(v)), &_time);
155 --- a/src/modules/ims_charging/ims_ro.c
156 +++ b/src/modules/ims_charging/ims_ro.c
157 @@ -856,7 +856,8 @@ void send_ccr_stop_with_param(struct ro_
158 LM_DBG("Final used number of seconds for session is %ld\n", used);
159 }
160
161 - LM_DBG("Call started at %ld and ended at %ld and lasted %d seconds and so far we have billed for %ld seconds\n", ro_session->start_time, stop_time,
162 + LM_DBG("Call started at %" TIME_T_FMT " and ended at %" TIME_T_FMT " and lasted %d seconds and so far we have billed for %ld seconds\n",
163 + TIME_T_CAST(ro_session->start_time), TIME_T_CAST(stop_time),
164 actual_time_seconds, ro_session->billed + used);
165 if (ro_session->billed + used < actual_time_seconds) {
166 LM_DBG("Making adjustment by adding %ld seconds\n", actual_time_seconds - (ro_session->billed + used));
167 --- a/src/modules/ims_dialog/dlg_handlers.c
168 +++ b/src/modules/ims_dialog/dlg_handlers.c
169 @@ -1867,7 +1867,7 @@ void internal_print_all_dlg(struct dlg_c
170
171 LM_DBG("----------------------------");
172 LM_DBG("Dialog h_entry:h_id = [%u : %u]\n", dlg->h_entry, dlg->h_id);
173 - LM_DBG("Dialog age: %ld\n", act_time - dlg->init_ts);
174 + LM_DBG("Dialog age: %" TIME_T_FMT "\n", TIME_T_CAST(act_time - dlg->init_ts));
175 LM_DBG("Dialog call-id: %.*s\n", dlg->callid.len, dlg->callid.s);
176 LM_DBG("Dialog state: %d\n", dlg->state);
177 LM_DBG("Dialog ref counter: %d\n", dlg->ref);
178 --- a/src/modules/ims_icscf/scscf_list.c
179 +++ b/src/modules/ims_icscf/scscf_list.c
180 @@ -586,15 +586,16 @@ void ims_icscf_timer_routine() {
181 sl = l->list;
182 while (sl) {
183
184 - LM_DBG("INF: Score:[%4d] Start_time [%ld] S-CSCF: <%.*s> \n",
185 + LM_DBG("INF: Score:[%4d] Start_time [%" TIME_T_FMT "] S-CSCF: <%.*s> \n",
186 sl->score,
187 - sl->start_time,
188 + TIME_T_CAST(sl->start_time),
189 sl->scscf_name.len, sl->scscf_name.s);
190 time_t now = time(0);
191 time_t time_elapsed = now - sl->start_time;
192 if (time_elapsed > scscf_entry_expiry) {
193
194 - LM_DBG("Scscf entry expired: Time now %ld Start time %ld - elapsed %ld\n", now, sl->start_time, time_elapsed);
195 + LM_DBG("Scscf entry expired: Time now %" TIME_T_FMT " Start time %" TIME_T_FMT " - elapsed %" TIME_T_FMT "\n",
196 + TIME_T_CAST(now), TIME_T_CAST(sl->start_time), TIME_T_CAST(time_elapsed));
197 delete_list = 1; //if any of the entries in this list have expired remove the whole list!
198
199 }
200 --- a/src/modules/ims_registrar_pcscf/notify.c
201 +++ b/src/modules/ims_registrar_pcscf/notify.c
202 @@ -209,8 +209,8 @@ int process_contact(udomain_t * _d, int
203 /*TODO_LATEST - put this back */
204 } else {//state is active
205 //update this contact
206 - LM_DBG("This contact: <%.*s> is in state active and is in usrloc so just updating - old expires: %li, new expires: %i which is in %i seconds\n", contact_uri.len, contact_uri.s,
207 - pcontact->expires,
208 + LM_DBG("This contact: <%.*s> is in state active and is in usrloc so just updating - old expires: %" TIME_T_FMT ", new expires: %i which is in %i seconds\n", contact_uri.len, contact_uri.s,
209 + TIME_T_CAST(pcontact->expires),
210 expires,
211 expires - local_time_now);
212 if (ul.update_pcontact(_d, &ci, pcontact) != 0) {
213 --- a/src/modules/ims_registrar_pcscf/save.c
214 +++ b/src/modules/ims_registrar_pcscf/save.c
215 @@ -223,8 +223,9 @@ static inline int update_contacts(struct
216 }
217 //TODO_LATEST replace above
218 } else { //update contact
219 - LM_DBG("Updating contact: <%.*s>, old expires: %li, new expires: %i which is in %i seconds\n", c->uri.len, c->uri.s,
220 - pcontact->expires-local_time_now,
221 + LM_DBG("Updating contact: <%.*s>, old expires: %" TIME_T_FMT ", new expires: %i which is in %i seconds\n",
222 + c->uri.len, c->uri.s,
223 + TIME_T_CAST(pcontact->expires-local_time_now),
224 expires,
225 expires-local_time_now);
226 ci.reg_state = PCONTACT_REGISTERED;
227 --- a/src/modules/ims_registrar_scscf/registrar_notify.c
228 +++ b/src/modules/ims_registrar_scscf/registrar_notify.c
229 @@ -54,6 +54,7 @@
230 #include "../../core/parser/parse_from.h"
231 #include "../../core/parser/parse_content.h"
232 #include "../../core/parser/parse_uri.h"
233 +#include "../../core/dprint.h" /* TIME_T_FMT */
234 #include <libxml/parser.h>
235
236 #include "../../lib/ims/useful_defs.h"
237 @@ -1517,8 +1518,8 @@ void create_notifications(udomain_t* _t,
238 subscription_state.len = 0;
239 if (subscription_state.s) {
240
241 - sprintf(subscription_state.s, "%.*s%ld", subs_active.len,
242 - subs_active.s, s->expires - act_time);
243 + sprintf(subscription_state.s, "%.*s%" TIME_T_FMT, subs_active.len,
244 + subs_active.s, TIME_T_CAST(s->expires - act_time));
245 subscription_state.len = strlen(subscription_state.s);
246 }
247
248 --- a/src/modules/ims_registrar_scscf/save.c
249 +++ b/src/modules/ims_registrar_scscf/save.c
250 @@ -545,7 +545,7 @@ static inline int update_contacts_helper
251 LM_DBG("Need to update contact: <%.*s>: "
252 "q_value [%d],"
253 "sos: [%d],"
254 - "expires [%ld]\n", chi->uri.len, chi->uri.s, qvalue, sos, expires - time(NULL));
255 + "expires [%" TIME_T_FMT "]\n", chi->uri.len, chi->uri.s, qvalue, sos, TIME_T_CAST(expires - time(NULL)));
256
257 LM_DBG("packing contact information\n");
258 if ((ci = pack_ci(msg, chi, expires, 0)) == 0) {
259 --- a/src/modules/ims_usrloc_scscf/impurecord.c
260 +++ b/src/modules/ims_usrloc_scscf/impurecord.c
261 @@ -244,7 +244,7 @@ void print_impurecord(FILE* _f, impureco
262 header = 1;
263 }
264 fprintf(_f, "\t\twatcher uri: <%.*s> and presentity uri: <%.*s>\n", subscriber->watcher_uri.len, subscriber->watcher_uri.s, subscriber->presentity_uri.len, subscriber->presentity_uri.s);
265 - fprintf(_f, "\t\tExpires: %ld\n", subscriber->expires);
266 + fprintf(_f, "\t\tExpires: %" TIME_T_FMT "\n", TIME_T_CAST(subscriber->expires));
267 subscriber = subscriber->next;
268 }
269
270 @@ -405,8 +405,9 @@ static inline void process_impurecord(im
271 hascontacts = 1;
272 }
273 } else {
274 - LM_DBG("\t\tContact #%i - %.*s, Ref [%d] (expires in %ld seconds) (State: %d)\n",
275 - k, ptr->c.len, ptr->c.s, ptr->ref_count, ptr->expires - act_time, ptr->state);
276 + LM_DBG("\t\tContact #%i - %.*s, Ref [%d] (expires in %" TIME_T_FMT " seconds) (State: %d)\n",
277 + k, ptr->c.len, ptr->c.s, ptr->ref_count,
278 + TIME_T_CAST(ptr->expires - act_time), ptr->state);
279 mustdeleteimpu = 0;
280 hascontacts = 1;
281 }
282 --- a/src/modules/nat_traversal/nat_traversal.c
283 +++ b/src/modules/nat_traversal/nat_traversal.c
284 @@ -1707,6 +1707,7 @@ static void restore_keepalive_state(void
285 unsigned h;
286 str host;
287 FILE *f;
288 + long long ll_1, ll_2;
289
290 if(!keepalive_state_file)
291 return;
292 @@ -1724,7 +1725,9 @@ static void restore_keepalive_state(void
293 res = fscanf(f, STATE_FILE_HEADER); // skip header
294
295 while(true) {
296 - res = fscanf(f, "%63s %63s %ld %ld", uri, socket, &rtime, &stime);
297 + res = fscanf(f, "%63s %63s %" TIME_T_FMT " %" TIME_T_FMT, uri, socket, &ll_1, &ll_2);
298 + rtime = ll_1;
299 + stime = ll_2;
300 if(res == EOF) {
301 if(ferror(f))
302 LM_ERR("error while reading keepalive state file: %s\n",
303 --- a/src/modules/xhttp_pi/xhttp_pi_fnc.c
304 +++ b/src/modules/xhttp_pi/xhttp_pi_fnc.c
305 @@ -3186,18 +3186,18 @@ int ph_run_pi_cmd(pi_ctx_t* ctx)
306 val_str.len = max_page_len - ctx->reply.body.len;
307 if(db_time2str(values[j].val.time_val,
308 val_str.s, &val_str.len)!=0){
309 - LM_ERR("Unable to convert double [%ld]\n",
310 - values[j].val.time_val);
311 + LM_ERR("Unable to convert double [%" TIME_T_FMT "]\n",
312 + TIME_T_CAST(values[j].val.time_val));
313 goto error;
314 }
315 p += val_str.len;
316 ctx->reply.body.len += val_str.len;
317 if(link_on) XHTTP_PI_COPY_2(p,XHTTP_PI_SQUOT_GT,val_str);
318 LM_DBG(" got %.*s[%d]=>"
319 - "[%ld][%.*s]\n",
320 + "[%" TIME_T_FMT "][%.*s]\n",
321 command->q_keys[j]->len,
322 command->q_keys[j]->s, i,
323 - values[j].val.time_val,
324 + TIME_T_CAST(values[j].val.time_val),
325 val_str.len, val_str.s);
326 break;
327 default: