File: add-partial-time64-support.patch

package info (click to toggle)
kannel 1.4.5-22
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,284 kB
  • sloc: ansic: 105,659; sh: 32,211; xml: 20,360; php: 1,103; perl: 711; makefile: 583; yacc: 548; awk: 133; python: 122; javascript: 27; pascal: 3
file content (238 lines) | stat: -rw-r--r-- 8,056 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
From: Guillem Jover <gjover@sipwise.com>
Date: Tue, 8 Oct 2024 16:10:51 +0000
Subject: Add partial time64 support on 32-bit arches

This fixes the code to handle time_t correctly on 32-bit and 64-bit
architectures, including 32-bit architectures with 64-bit time_t.

This does not implement full support for time64, as that might require
modifying the protocol to encode time 64-bit fields, which the protocol
currently seems to encode in 32-bit fields. It's not clear whether the
current encoding is part of the protocols used or just an internal
serialization used by the code.
---
 gw/bb_store_redis.c |  9 +++++++++
 gw/msg-decl.h       |  7 ++++---
 gw/msg.c            | 33 +++++++++++++++++++++++++++++++++
 gw/msg.h            |  1 +
 gw/smsc/smsc_smpp.c |  2 +-
 gw/smsc/smsc_soap.c |  4 ++--
 6 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/gw/bb_store_redis.c b/gw/bb_store_redis.c
index caba8f0..bb30c74 100644
--- a/gw/bb_store_redis.c
+++ b/gw/bb_store_redis.c
@@ -115,6 +115,7 @@ static Dict *hash_msg_pack(Msg *msg)
     h = dict_create(32, octstr_destroy_item);
 
 #define INTEGER(name) dict_put(h, octstr_imm(#name), octstr_format("%ld", p->name));
+#define TIME(name) dict_put(h, octstr_imm(#name), octstr_format("%lld", (long long)p->name));
 #define OCTSTR(name) dict_put(h, octstr_imm(#name), octstr_duplicate(p->name));
 #define UUID(name) { \
         char id[UUID_STR_LEN + 1]; \
@@ -149,6 +150,9 @@ static Msg *hash_msg_unpack(Dict *hash)
 #define INTEGER(name) \
     if ((os = dict_get(hash, octstr_imm(#name))) != NULL) \
         p->name = atol(octstr_get_cstr(os));
+#define TIME(name) \
+    if ((os = dict_get(hash, octstr_imm(#name))) != NULL) \
+        p->name = atoll(octstr_get_cstr(os));
 #define OCTSTR(name) p->name = octstr_duplicate(dict_get(hash, octstr_imm(#name)));
 #define UUID(name) \
     if ((os = dict_get(hash, octstr_imm(#name))) != NULL) \
@@ -269,6 +273,11 @@ static void store_redis_add_msg(Octstr *id, Msg *msg)
         gwlist_produce(b, octstr_imm(#name)); \
         gwlist_produce(b, octstr_format("%ld", p->name)); \
     }
+#define TIME(name) \
+    if (p->name != MSG_PARAM_UNDEFINED) { \
+        gwlist_produce(b, octstr_imm(#name)); \
+        gwlist_produce(b, octstr_format("%lld", (long long)p->name)); \
+    }
 #define OCTSTR(name) \
     if (p->name != NULL) { \
         gwlist_produce(b, octstr_imm(#name)); \
diff --git a/gw/msg-decl.h b/gw/msg-decl.h
index 1fad7a7..e0f1cc6 100644
--- a/gw/msg-decl.h
+++ b/gw/msg-decl.h
@@ -83,7 +83,7 @@ MSG(sms,
         OCTSTR(receiver)
         OCTSTR(udhdata)
         OCTSTR(msgdata)
-        INTEGER(time)
+        TIME(time)
         OCTSTR(smsc_id)
         OCTSTR(smsc_number)
         OCTSTR(foreign_id)
@@ -109,14 +109,14 @@ MSG(sms,
         VOID(split_parts)
         INTEGER(priority)
         INTEGER(resend_try)
-        INTEGER(resend_time)
+        TIME(resend_time)
         OCTSTR(meta_data)
     })
 
 MSG(ack,
     {
         INTEGER(nack)
-        INTEGER(time)
+        TIME(time)
         UUID(id)
     })
     
@@ -131,6 +131,7 @@ MSG(wdp_datagram,
 
 #undef MSG
 #undef INTEGER
+#undef TIME
 #undef OCTSTR
 #undef UUID
 #undef VOID
diff --git a/gw/msg.c b/gw/msg.c
index f1ba589..430a8fb 100644
--- a/gw/msg.c
+++ b/gw/msg.c
@@ -76,10 +76,12 @@
  */
 
 static void append_integer(Octstr *os, long i);
+static void append_time(Octstr *os, time_t t);
 static void append_string(Octstr *os, Octstr *field);
 static void append_uuid(Octstr *os, uuid_t id);
 
 static int parse_integer(long *i, Octstr *packed, int *off);
+static int parse_time(time_t *t, Octstr *packed, int *off);
 static int parse_string(Octstr **os, Octstr *packed, int *off);
 static int parse_uuid(uuid_t id, Octstr *packed, int *off);
 
@@ -99,6 +101,7 @@ Msg *msg_create_real(enum msg_type type, const char *file, long line,
 
     msg->type = type;
 #define INTEGER(name) p->name = MSG_PARAM_UNDEFINED;
+#define TIME(name) INTEGER(name)
 #define OCTSTR(name) p->name = NULL;
 #define UUID(name) uuid_generate(p->name);
 #define VOID(name) p->name = NULL;
@@ -115,6 +118,7 @@ Msg *msg_duplicate(Msg *msg)
     new = msg_create(msg->type);
 
 #define INTEGER(name) p->name = q->name;
+#define TIME(name) INTEGER(name)
 #define OCTSTR(name) \
     if (q->name == NULL) p->name = NULL; \
     else p->name = octstr_duplicate(q->name);
@@ -135,6 +139,7 @@ void msg_destroy(Msg *msg)
         return;
 
 #define INTEGER(name) p->name = 0;
+#define TIME(name) INTEGER(name)
 #define OCTSTR(name) octstr_destroy(p->name);
 #define UUID(name) uuid_clear(p->name);
 #define VOID(name)
@@ -157,6 +162,8 @@ void msg_dump(Msg *msg, int level)
     debug("gw.msg", 0, "%*s type: %s", level, "", type_as_str(msg));
 #define INTEGER(name) \
     debug("gw.msg", 0, "%*s %s.%s: %ld", level, "", t, #name, (long) p->name);
+#define TIME(name) \
+    debug("gw.msg", 0, "%*s %s.%s: %lld", level, "", t, #name, (long long) p->name);
 #define OCTSTR(name) \
     debug("gw.msg", 0, "%*s %s.%s:", level, "", t, #name); \
     octstr_dump(p->name, level + 1);
@@ -186,6 +193,7 @@ Octstr *msg_pack(Msg *msg)
     append_integer(os, msg->type);
 
 #define INTEGER(name) append_integer(os, p->name);
+#define TIME(name) append_time(os, p->name);
 #define OCTSTR(name) append_string(os, p->name);
 #define UUID(name) append_uuid(os, p->name);
 #define VOID(name)
@@ -221,6 +229,8 @@ Msg *msg_unpack_real(Octstr *os, const char *file, long line, const char *func)
 
 #define INTEGER(name) \
     if (parse_integer(&(p->name), os, &off) == -1) goto error;
+#define TIME(name) \
+    if (parse_time(&(p->name), os, &off) == -1) goto error;
 #define OCTSTR(name) \
     if (parse_string(&(p->name), os, &off) == -1) goto error;
 #define UUID(name) \
@@ -272,6 +282,14 @@ static void append_integer(Octstr *os, long i)
     octstr_append_data(os, (char *)buf, 4);
 }
 
+static void append_time(Octstr *os, time_t t)
+{
+    unsigned char buf[4];
+
+    encode_network_long(buf, t);
+    octstr_append_data(os, (char *)buf, 4);
+}
+
 static void append_string(Octstr *os, Octstr *field)
 {
     if (field == NULL)
@@ -307,6 +325,21 @@ static int parse_integer(long *i, Octstr *packed, int *off)
     return 0;
 }
 
+static int parse_time(time_t *t, Octstr *packed, int *off)
+{
+    unsigned char buf[4];
+
+    gw_assert(*off >= 0);
+    if (*off + 4 > octstr_len(packed)) {
+        error(0, "Packet too short while unpacking Msg.");
+        return -1;
+    }
+
+    octstr_get_many_chars((char *)buf, packed, *off, 4);
+    *t = decode_network_long(buf);
+    *off += 4;
+    return 0;
+}
 
 static int parse_string(Octstr **os, Octstr *packed, int *off)
 {
diff --git a/gw/msg.h b/gw/msg.h
index 4263a36..b472c0e 100644
--- a/gw/msg.h
+++ b/gw/msg.h
@@ -80,6 +80,7 @@ typedef struct {
 	enum msg_type type;
 
 	#define INTEGER(name) long name;
+	#define TIME(name) time_t name;
 	#define OCTSTR(name) Octstr *name;
 	#define UUID(name) uuid_t name;
 	#define VOID(name) void *name;
diff --git a/gw/smsc/smsc_smpp.c b/gw/smsc/smsc_smpp.c
index 5c5097e..1b15db0 100644
--- a/gw/smsc/smsc_smpp.c
+++ b/gw/smsc/smsc_smpp.c
@@ -1170,7 +1170,7 @@ static SMPP_PDU *msg_to_pdu(SMPP *smpp, Msg *msg)
 }
 
 
-static int send_enquire_link(SMPP *smpp, Connection *conn, long *last_sent)
+static int send_enquire_link(SMPP *smpp, Connection *conn, time_t *last_sent)
 {
     SMPP_PDU *pdu;
     Octstr *os;
diff --git a/gw/smsc/smsc_soap.c b/gw/smsc/smsc_soap.c
index fb02d87..bc44fad 100644
--- a/gw/smsc/smsc_soap.c
+++ b/gw/smsc/smsc_soap.c
@@ -2052,9 +2052,9 @@ static Octstr* soap_convert_token(Msg* msg, Octstr* name, PrivData* privdata)
                 sprintf(buf,"%ld", p->fieldname); \
                 return octstr_create(buf); \
         }
-#define INT64(fieldname) \
+#define TIME(fieldname) \
         if (!octstr_str_compare(name, #fieldname)) { \
-                sprintf(buf,"%lld", p->fieldname); \
+                sprintf(buf,"%lld", (long long)p->fieldname); \
                 return octstr_create(buf); \
         }
 #define OCTSTR(fieldname) \