2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "MsgCppTypes.h"
19 #include "MsgGconfWrapper.h"
20 #include "MsgException.h"
21 #include "MsgUtilFile.h"
22 #include "SmsPluginStorage.h"
23 #include "SmsPluginTransport.h"
24 #include "SmsPluginEventHandler.h"
25 #include "SmsPluginWapPushHandler.h"
30 #include <drm_client.h>
33 static unsigned short wapPushPortList[] = {0x0b84, 0x0b85, 0x23F0, 0x23F1, 0x23F2, 0x23F3, 0xC34F};
36 const SMS_PUSH_APP_INFO_S pushDefaultApplication[] =
38 {(char*)"text/vnd.wap.si", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SI},
39 {(char*)"application/vnd.wap.sic", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SIC},
40 {(char*)"text/vnd.wap.sl", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SL},
41 {(char*)"application/vnd.wap.slc", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SLC},
42 {(char*)"text/vnd.wap.co", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_CO},
43 {(char*)"application/vnd.wap.coc", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_COC},
45 {(char*)"application/vnd.wap.mms-message", (char*)"X-Wap-Application-Id: x-wap-application:mms.ua\r\n", SMS_WAP_APPLICATION_MMS_UA},
47 {(char*)"application/vnd.wap.sia", (char*)"X-Wap-Application-Id: x-wap-application:push.sia\r\n", SMS_WAP_APPLICATION_PUSH_SIA},
49 {(char*)"application/vnd.syncml.dm+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.dm\r\n", SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP},
50 {(char*)"application/vnd.syncml.dm+xml", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.dm\r\n", SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML},
51 {(char*)"application/vnd.syncml.notification", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.dm\r\n", SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION},
52 {(char*)"application/vnd.syncml.ds.notification", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.ds\r\n", SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION},
53 {(char*)"application/vnd.syncml+wbxml", (char*)"X-Wap-Application-Id:x-wap-application:push.syncml", SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML},
55 {(char*)"application/vnd.wap.locc+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:loc.ua\r\n", SMS_WAP_APPLICATION_LOC_UA_WBXML},
56 {(char*)"application/vnd.wap.loc+xml", (char*)"X-Wap-Application-Id: x-wap-application:loc.ua\r\n", SMS_WAP_APPLICATION_LOC_UA_XML},
58 {(char*)"application/vnd.oma.dd+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_XML},
59 {(char*)"application/vnd.oma.drm.message", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_MESSAGE},
60 {(char*)"application/vnd.oma.drm.content", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_CONETENT},
61 {(char*)"application/vnd.oma.drm.rights+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML},
62 {(char*)"application/vnd.oma.drm.rights+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML},
63 {(char*)"application/vnd.oma.drm.ro+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_V2_RO_XML},
64 {(char*)"application/vnd.oma.drm.roap-pdu+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML},
65 {(char*)"application/vnd.oma.drm.roap-trigger+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML},
66 {(char*)"application/vnd.oma.drm.roap-trigger+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML},
68 {(char*)"text/vnd.wap.connectivity-xml", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML},
69 {(char*)"application/vnd.wap.connectivity-wbxml", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML},
71 {(char*)"application/x-wap-prov.browser-settings", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS},
72 {(char*)"application/x-wap-prov.browser-bookmarks", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS},
73 {(char*)"application/x-wap-prov.syncset+xml", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_SYNCSET_WBXML},
74 {(char*)"application/x-wap-prov.syncset+wbxml", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_SYNCSET_XML},
75 {(char*)"text/vnd.wap.emn+xml", (char*)"X-Wap-Application-Id: x-wap-application:emn.ua\r\n", SMS_WAP_APPLICATION_PUSH_EMAIL_XML},
76 {(char*)"application/vnd.wap.emn+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:emn.ua\r\n", SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML},
77 {(char*)"application/vnd.wv.csp.cir", (char*)"X-Wap-Application-Id: x-wap-application:wv.ua\r\n", SMS_WAP_APPLICATION_PUSH_IMPS_CIR},
78 {(char*)"application/vnd.omaloc-supl-init", (char*)"X-Wap-Application-Id: x-oma-application:ulp.ua\r\n", SMS_WAP_APPLICATION_LBS},
83 char gWapCodeBufferLeft[WSP_CODE_BUFFER_LEFT_LEN_MAX];
84 char gWapCodeBufferRight[WSP_CODE_BUFFER_RIGHT_LEN_MAX];
86 const unsigned long wspUintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00200000, 0x10000000 };
88 const unsigned char wspHeaderFieldCount = 0x43;
89 const unsigned char wspContentsTypeCount = 0x34;
90 const unsigned long wspLanguageCount = 0x11a;
91 const unsigned char wspSecurityTypeCount = 0x04;
94 static const SMS_WSP_CONTENTS_TYPE_S wspExtendedContentsType[] = {
95 { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
96 { (char*)"application/vnd.wap.connectivity-wbxml", 0x36 },
97 { (char*)"application/pkcs7-mime", 0x37 },
98 { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
99 { (char*)"application/vnd.wap.signed-certificate", 0x39 },
100 { (char*)"application/vnd.wap.cert-response", 0x3A },
101 { (char*)"application/xhtml+xml", 0x3B },
102 { (char*)"application/wml+xml", 0x3C },
103 { (char*)"text/css", 0x3D },
105 { (char*)"application/vnd.wap.mms-message", 0x3E },
107 { (char*)"application/vnd.wap.rollover-certificate", 0x3F },
108 { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
109 { (char*)"application/vnd.wap.loc+xml", 0x41 },
110 { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
111 { (char*)"application/vnd.syncml.dm+xml", 0x43 },
112 { (char*)"application/vnd.syncml.notification", 0x44 },
113 { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
114 { (char*)"application/vnd.wv.csp.cir", 0x46 },
116 { (char*)"application/vnd.oma.dd+xml", 0x47},
117 { (char*)"application/vnd.oma.drm.message", 0x48 },
118 { (char*)"application/vnd.oma.drm.content", 0x49 },
119 { (char*)"application/vnd.oma.drm.rights+xml", 0x4A },
120 { (char*)"application/vnd.oma.drm.rights+wbxml", 0x4B },
121 { (char*)"application/vnd.syncml.ds.notification", 0x4E},
122 { (char*)"application/mikey", 0x52},
127 const char* wspHeaderFieldName[] = {
128 (char*)"Accept", /* 0x00 */
129 (char*)"Accept-Charset",
130 (char*)"Accept-Encoding",
131 (char*)"Accept-Language",
132 (char*)"Accept-Ranges",
133 (char*)"Age", /* 0x05 */
135 (char*)"Authorization",
136 (char*)"Cache-Control",
138 (char*)"Content-Base", /* 0x0a */
139 (char*)"Content-Encoding",
140 (char*)"Content-Language",
141 (char*)"Content-Length",
142 (char*)"Content-Location",
143 (char*)"Content-MD5",
144 (char*)"Content-Range", /* 0x10 */
145 (char*)"Content-Type",
149 (char*)"From", /* 0x15 */
151 (char*)"If-Modified-Since",
153 (char*)"If-None-Match",
154 (char*)"If-Range", /* 0x1a */
155 (char*)"If-Unmodified-Since",
157 (char*)"Last-Modified",
158 (char*)"Max-Forwards",
160 (char*)"Proxy-Authenticate", /* 0x20 */
161 (char*)"Proxy-Authorization",
165 (char*)"Retry-After", /* 0x25 */
167 (char*)"Transfer-Encodig",
170 (char*)"Vary", /* 0x2a */
173 (char*)"Www-Authenticate",
174 (char*)"Content-Disposition",
175 (char*)"X-Wap-Application-Id",
176 (char*)"X-Wap-Content-URI", /* 0x30 */
177 (char*)"X-Wap-Iinitiator-URI",
178 (char*)"Accept-Application", /* Back */
179 (char*)"Bearer-Indication",
181 (char*)"Profile", /* 0x35 */
182 (char*)"Profile-Diff",
183 (char*)"Profile-Warning", /* end of WAP 1.2 */
186 (char*)"Trailer", /* 0x3a */
187 (char*)"Accept-Charset", /* Back */
188 (char*)"Accept-Encoding", /* Back */
189 (char*)"Cache-Control", /* back */
190 (char*)"Content-Range",
192 (char*)"Content-ID", /* 0x40 */
195 (char*)"Encoding-Version"
199 const SMS_WSP_CHARSET_S wspCharset[] = {
200 { (char*)"big5", 0x07ea },
201 { (char*)"iso-10646-ucs-2", 0x03e8 },
202 { (char*)"iso-8859-1", 0x04 },
203 { (char*)"iso-8859-2", 0x05 },
204 { (char*)"iso-8859-3", 0x06 },
205 { (char*)"iso-8859-4", 0x07 },
206 { (char*)"iso-8859-5", 0x08 },
207 { (char*)"iso-8859-6", 0x09 },
208 { (char*)"iso-8859-7", 0x0a },
209 { (char*)"iso-8859-8", 0x0b },
210 { (char*)"iso-8859-9", 0x0c },
211 { (char*)"shift-JIS", 0x11 },
212 { (char*)"us-ascii", 0x03 },
213 { (char*)"utf-8", 0x6a },
214 { (char*)"none", 0x26 },
215 { (char*)"", 0xffff }
220 const char* wspEncodeMethod[] = {
227 const SMS_WSP_CONTENTS_TYPE_S wspContentsType[] = {
228 { (char*)"*/*", 0x00 },
229 { (char*)"text/*", 0x01 },
230 { (char*)"text/html", 0x02 },
231 { (char*)"text/plain", 0x03 },
232 { (char*)"text/x-hdml", 0x04 },
233 { (char*)"text/x-ttml", 0x05 },
234 { (char*)"text/x-vCalendar", 0x06 },
235 { (char*)"text/x-vCard", 0x07 },
236 { (char*)"text/vnd.wap.wml", 0x08 },
237 { (char*)"text/vnd.wap.wmlscript", 0x09 },
238 { (char*)"text/vnd.wap.wta-event", 0x0a },
239 { (char*)"multipart/*", 0x0b },
240 { (char*)"multipart/mixed", 0x0c },
241 { (char*)"multipart/form-data", 0x0d },
242 { (char*)"multipart/byteranges", 0x0e },
243 { (char*)"multipart/alternative", 0x0f },
244 { (char*)"application/*", 0x10 },
245 { (char*)"application/java-vm", 0x11 },
246 { (char*)"application/x-www-form-urlencoded", 0x12 },
247 { (char*)"application/x-hdmlc", 0x13 },
248 { (char*)"application/vnd.wap.wmlc", 0x14 },
249 { (char*)"application/vnd.wap.wmlscriptc", 0x15 },
250 { (char*)"application/vnd.wap.wta-eventc", 0x16 },
251 { (char*)"application/vnd.wap.uaprof", 0x17 },
252 { (char*)"application/vnd.wap.wtls-ca-certificate", 0x18 },
253 { (char*)"application/vnd.wap.wtls-user-certificate", 0x19 },
254 { (char*)"application/x-x509-ca-cert", 0x1a },
255 { (char*)"application/x-x509-user-cert", 0x1b },
256 { (char*)"image/*", 0x1c },
257 { (char*)"image/gif", 0x1d },
258 { (char*)"image/jpeg", 0x1e },
259 { (char*)"image/tiff", 0x1f },
260 { (char*)"image/png", 0x20 },
261 { (char*)"image/vnd.wap.wbmp", 0x21 },
262 { (char*)"application/vnd.wap.multipart.*", 0x22 },
263 { (char*)"application/vnd.wap.multipart.mixed", 0x23 },
264 { (char*)"application/vnd.wap.multipart.form-data", 0x24 },
265 { (char*)"application/vnd.wap.multipart.byteranges", 0x25 },
266 { (char*)"application/vnd.wap.multipart.alternative", 0x26 },
267 { (char*)"application/xml", 0x27 },
268 { (char*)"text/xml", 0x28 },
269 { (char*)"application/vnd.wap.wbxml", 0x29 },
270 { (char*)"application/x-x968-cross-cert", 0x2a },
271 { (char*)"application/x-x968-ca-cert", 0x2b },
272 { (char*)"application/x-x968-user-cert", 0x2c },
273 { (char*)"text/vnd.wap.si", 0x2d },
274 { (char*)"application/vnd.wap.sic", 0x2e },
275 { (char*)"text/vnd.wap.sl", 0x2f },
276 { (char*)"application/vnd.wap.slc", 0x30 },
277 { (char*)"text/vnd.wap.co", 0x31 },
278 { (char*)"application/vnd.wap.coc", 0x32 },
279 { (char*)"application/vnd.wap.multipart.related", 0x33 },
280 { (char*)"application/vnd.wap.sia", 0x34 },
282 { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
283 { (char*)"application/vnd.connectivity-wbxml", 0x36 },
284 { (char*)"application/pkcs7-mime", 0x37 },
285 { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
286 { (char*)"application/vnd.wap.signed-certificate", 0x39 },
287 { (char*)"application/vnd.wap.cert-response", 0x3A },
288 { (char*)"application/xhtml+xml", 0x3B },
289 { (char*)"application/wml+xml", 0x3C },
290 { (char*)"text/css", 0x3D },
292 { (char*)"application/vnd.wap.mms-message", 0x3E },
294 { (char*)"application/vnd.wap.rollover-certificate", 0x3F },
295 { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
296 { (char*)"application/vnd.wap.loc+xml", 0x41 },
297 { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
298 { (char*)"application/vnd.syncml.dm+xml", 0x43 },
299 { (char*)"application/vnd.syncml.notification", 0x44 },
300 { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
301 { (char*)"application/vnd.wv.csp.cir", 0x46 }
304 static const SMS_WAP_UNREGISTER_CONTENTS_TYPE_S wspUnregisterContentsType[]= {
305 { (char*)"application/vnd.wap.emn+wbxml", 0x30A},
306 { (char*)"application/vnd.omaloc-supl-init", 0x312},
307 { (char*)"application/vnd.oma.drm.roap-trigger+wbxml", 0x316}
310 const unsigned long wspUnregisteredContentsTypeCount = sizeof(wspUnregisterContentsType)/sizeof(SMS_WAP_UNREGISTER_CONTENTS_TYPE_S);
312 const SMS_WSP_LANGUAGE_S wspLanguage[] = {
313 { (char*)"English", 0x19 },
314 { (char*)"en", 0x19 },
315 { (char*)"Korean", 0x3d },
316 { (char*)"*", 0x00 },
317 { (char*)"Afar", 0x01 },
318 { (char*)"aa", 0x01 },
319 { (char*)"Abkhazian", 0x02 },
320 { (char*)"ab", 0x02 },
321 { (char*)"Afrikaans", 0x03 },
322 { (char*)"af", 0x03 },
323 { (char*)"Amharic", 0x04 },
324 { (char*)"am", 0x04 },
325 { (char*)"Arabic", 0x05 },
326 { (char*)"ar", 0x05 },
327 { (char*)"Assamese", 0x06 },
328 { (char*)"as", 0x06 },
329 { (char*)"Aymara", 0x07 },
330 { (char*)"ay", 0x07 },
331 { (char*)"Azerbaijani", 0x08 },
332 { (char*)"az", 0x08 },
333 { (char*)"Bashkir", 0x09 },
334 { (char*)"ba", 0x09 },
335 { (char*)"Byelorussian", 0x0a },
336 { (char*)"be", 0x0a },
337 { (char*)"Bulgarian", 0x0b },
338 { (char*)"bg", 0x0b },
339 { (char*)"Bihari", 0x0c },
340 { (char*)"bh", 0x0c },
341 { (char*)"Bislama", 0x0d },
342 { (char*)"bi", 0x0f },
343 { (char*)"Bengali", 0x0e },
344 { (char*)"Bangla", 0x0e },
345 { (char*)"bn", 0x0e },
346 { (char*)"Tibetan", 0x0f },
347 { (char*)"bo", 0x0f },
348 { (char*)"Breton", 0x10 },
349 { (char*)"br", 0x10 },
350 { (char*)"Catalan", 0x11 },
351 { (char*)"ca", 0x11 },
352 { (char*)"Corsican", 0x12 },
353 { (char*)"co", 0x12 },
354 { (char*)"Czech", 0x13 },
355 { (char*)"cs", 0x13 },
356 { (char*)"Welsh", 0x14 },
357 { (char*)"cy", 0x14 },
358 { (char*)"Denish", 0x15 },
359 { (char*)"da", 0x15 },
360 { (char*)"German", 0x16 },
361 { (char*)"de", 0x16 },
362 { (char*)"Bhutani", 0x17 },
363 { (char*)"dz", 0x17 },
364 { (char*)"Greek", 0x18 },
365 { (char*)"el", 0x18 },
366 { (char*)"Esperanto", 0x81 },
367 { (char*)"eo", 0x1a },
368 { (char*)"Spanish", 0x1b },
369 { (char*)"es", 0x1b },
370 { (char*)"Estonian", 0x1c },
371 { (char*)"et", 0x1c },
372 { (char*)"Basque", 0x1d },
373 { (char*)"eu", 0x1d },
374 { (char*)"Persian", 0x1e },
375 { (char*)"fa", 0x1e },
376 { (char*)"Finnish", 0x1f },
377 { (char*)"fi", 0x1f },
378 { (char*)"Fiji", 0x20 },
379 { (char*)"fj", 0x20 },
380 { (char*)"Faeroese", 0x82 },
381 { (char*)"fo", 0x82 },
382 { (char*)"French", 0x22 },
383 { (char*)"fr", 0x22 },
384 { (char*)"Frisian", 0x83 },
385 { (char*)"fy", 0x83 },
386 { (char*)"Irish", 0x24 },
387 { (char*)"ga", 0x24 },
388 { (char*)"Scots Gaelic", 0x25 },
389 { (char*)"gd", 0x25 },
390 { (char*)"Galician", 0x26 },
391 { (char*)"gl", 0x26 },
392 { (char*)"Guarani", 0x27 },
393 { (char*)"gn", 0x27 },
394 { (char*)"Gujarati", 0x28 },
395 { (char*)"gu", 0x28 },
396 { (char*)"Hausa", 0x29 },
397 { (char*)"ha", 0x29 },
398 { (char*)"Hebrew", 0x2a },
399 { (char*)"he", 0x2a },
400 { (char*)"Hindi", 0x2b },
401 { (char*)"hi", 0x2b },
402 { (char*)"Croatian", 0x2c },
403 { (char*)"hr", 0x2c },
404 { (char*)"Hungarian", 0x2d },
405 { (char*)"hu", 0x2d },
406 { (char*)"Armenian", 0x2e },
407 { (char*)"hy", 0x2e },
408 { (char*)"Interlingua", 0x84 },
409 { (char*)"ia", 0x84 },
410 { (char*)"Indonesian", 0x30 },
411 { (char*)"id", 0x30 },
412 { (char*)"Interlingue", 0x86 },
413 { (char*)"ie", 0x86 },
414 { (char*)"Maori", 0x47 },
415 { (char*)"mi", 0x47 },
416 { (char*)"Macedonian", 0x48 },
417 { (char*)"mk", 0x48 },
418 { (char*)"Malayalam", 0x49 },
419 { (char*)"ml", 0x49 },
420 { (char*)"Mongolian", 0x4a },
421 { (char*)"mn", 0x4a },
422 { (char*)"Moldavian", 0x4b },
423 { (char*)"mo", 0x4d },
424 { (char*)"Marathi", 0x4c },
425 { (char*)"mr", 0x4c },
426 { (char*)"Malay", 0x4d },
427 { (char*)"ms", 0x4d },
428 { (char*)"Maltese", 0x4e },
429 { (char*)"mt", 0x4e },
430 { (char*)"Burmese", 0x4f },
431 { (char*)"my", 0x4f },
432 { (char*)"Nauru", 0x50 },
433 { (char*)"na", 0x50 },
434 { (char*)"Nepali", 0x51 },
435 { (char*)"ne", 0x51 },
436 { (char*)"Dutch", 0x52 },
437 { (char*)"nl", 0x52 },
438 { (char*)"Norwegian", 0x53 },
439 { (char*)"no", 0x53 },
440 { (char*)"Occitan", 0x54 },
441 { (char*)"oc", 0x54 },
442 { (char*)"(Afan) Oromo", 0x55 },
443 { (char*)"(Afan)Oromo", 0x55 },
444 { (char*)"om", 0x55 },
445 { (char*)"Oriya", 0x56 },
446 { (char*)"or", 0x56 },
447 { (char*)"Punjabi", 0x57 },
448 { (char*)"pa", 0x57 },
449 { (char*)"Polish", 0x58 },
450 { (char*)"po", 0x58 },
451 { (char*)"Pashto", 0x59 },
452 { (char*)"Pushto", 0x59 },
453 { (char*)"ps", 0x59 },
454 { (char*)"Portugurse", 0x5a },
455 { (char*)"pt", 0x5a },
456 { (char*)"Quechua", 0x5b },
457 { (char*)"qu", 0x5b },
458 { (char*)"Rhaeto-Romance", 0x8c },
459 { (char*)"rm", 0x8c },
460 { (char*)"Kirundi", 0x5d },
461 { (char*)"rn", 0x5d },
462 { (char*)"Romanian", 0x5e },
463 { (char*)"ro", 0x5e },
464 { (char*)"Russian", 0x5f },
465 { (char*)"ru", 0x5f },
466 { (char*)"Kinyarwanda", 0x60 },
467 { (char*)"rw", 0x60 },
468 { (char*)"Sanskrit", 0x61 },
469 { (char*)"sa", 0x61 },
470 { (char*)"Sindhi", 0x62 },
471 { (char*)"sd", 0x62 },
472 { (char*)"Sangho", 0x63 },
473 { (char*)"sg", 0x63 },
474 { (char*)"Serbo-Croatian", 0x64 },
475 { (char*)"sh", 0x64 },
476 { (char*)"Sinhalese", 0x65 },
477 { (char*)"si", 0x65 },
478 { (char*)"Slovak", 0x66 },
479 { (char*)"sk", 0x66 },
480 { (char*)"Slovenian", 0x67 },
481 { (char*)"sl", 0x67 },
482 { (char*)"Samoan", 0x68 },
483 { (char*)"sm", 0x68 },
484 { (char*)"Shona", 0x69 },
485 { (char*)"sn", 0x69 },
486 { (char*)"Somali", 0x6a },
487 { (char*)"so", 0x6a },
488 { (char*)"Albanian", 0x6b },
489 { (char*)"sq", 0x6b },
490 { (char*)"Serbian", 0x6c },
491 { (char*)"sr", 0x6c },
492 { (char*)"Siswati", 0x6d },
493 { (char*)"ss", 0x6d },
494 { (char*)"Sesotho", 0x6e },
495 { (char*)"st", 0x6e },
496 { (char*)"Sundanese", 0x6f },
497 { (char*)"su", 0x6f },
498 { (char*)"Swedish", 0x70 },
499 { (char*)"sv", 0x70 },
500 { (char*)"Swahili", 0x71 },
501 { (char*)"sw", 0x71 },
502 { (char*)"Tamil", 0x72 },
503 { (char*)"ta", 0x72 },
504 { (char*)"Telugu", 0x73 },
505 { (char*)"te", 0x73 },
506 { (char*)"Tajik", 0x74 },
507 { (char*)"tg", 0x74 },
508 { (char*)"Thai", 0x75 },
509 { (char*)"th", 0x75 },
510 { (char*)"Tigrinya", 0x76 },
511 { (char*)"ti", 0x76 },
512 { (char*)"Turkmen", 0x77 },
513 { (char*)"tk", 0x77 },
514 { (char*)"Inupiak", 0x87 },
515 { (char*)"ik", 0x87 },
516 { (char*)"Icelandic", 0x33 },
517 { (char*)"is", 0x33 },
518 { (char*)"Italian", 0x34 },
519 { (char*)"it", 0x34 },
520 { (char*)"Inuktitut", 0x89 },
521 { (char*)"iu", 0x89 },
522 { (char*)"Japanese", 0x36 },
523 { (char*)"ja", 0x36 },
524 { (char*)"Javanese", 0x37 },
525 { (char*)"jw", 0x37 },
526 { (char*)"Georgian", 0x38 },
527 { (char*)"ka", 0x38 },
528 { (char*)"Kazakh", 0x39 },
529 { (char*)"kk", 0x39 },
530 { (char*)"Gerrnlandic", 0x8a },
531 { (char*)"kl", 0x8a },
532 { (char*)"Cambodian", 0x3b },
533 { (char*)"km", 0x3b },
534 { (char*)"Kannada", 0x3c },
535 { (char*)"kn", 0x3c },
536 { (char*)"Kashmiri", 0x3e },
537 { (char*)"ks", 0x3e },
538 { (char*)"Kurdish", 0x3f },
539 { (char*)"ku", 0x3f },
540 { (char*)"Kirghiz", 0x40 },
541 { (char*)"ky", 0x40 },
542 { (char*)"Latin", 0x8b },
543 { (char*)"la", 0x8b },
544 { (char*)"Lingala", 0x42 },
545 { (char*)"ln", 0x42 },
546 { (char*)"Laothian", 0x43 },
547 { (char*)"lo", 0x43 },
548 { (char*)"Lithuanian", 0x44 },
549 { (char*)"lt", 0x44 },
550 { (char*)"Lavian", 0x45 },
551 { (char*)"Lettish", 0x45 },
552 { (char*)"lv", 0x45 },
553 { (char*)"Malagasy", 0x46 },
554 { (char*)"mg", 0x46 },
555 { (char*)"Tagalog", 0x78 },
556 { (char*)"tl", 0x78 },
557 { (char*)"Setswana", 0x79 },
558 { (char*)"tn", 0x79 },
559 { (char*)"Tonga", 0x7a },
560 { (char*)"to", 0x7a },
561 { (char*)"Turkish", 0x7b },
562 { (char*)"tr", 0x7b },
563 { (char*)"Tsonga", 0x7c },
564 { (char*)"ts", 0x7c },
565 { (char*)"Tatar", 0x7d },
566 { (char*)"tt", 0x7d },
567 { (char*)"Twi", 0x7e },
568 { (char*)"tw", 0x7e },
569 { (char*)"Uighur", 0x7f },
570 { (char*)"ug", 0x7f },
571 { (char*)"Ukrainian", 0x1a },
572 { (char*)"uk", 0x1a },
573 { (char*)"Urdu", 0x21 },
574 { (char*)"ur", 0x21 },
575 { (char*)"Uzbek", 0x23 },
576 { (char*)"uz", 0x23 },
577 { (char*)"Vietnamese", 0x2f },
578 { (char*)"vi", 0x2f },
579 { (char*)"Volapuk", 0x85 },
580 { (char*)"vo", 0x85 },
581 { (char*)"Wolof", 0x31 },
582 { (char*)"wo" , 0x31 },
583 { (char*)"Xhosa", 0x32 },
584 { (char*)"xh", 0x32 },
585 { (char*)"Yiddish", 0x88 },
586 { (char*)"yi", 0x88 },
587 { (char*)"Yoruba", 0x35 },
588 { (char*)"yo", 0x35 },
589 { (char*)"Zhuang", 0x3a },
590 { (char*)"z", 0x3a },
591 { (char*)"Chinese", 0x41 },
592 { (char*)"ch", 0x41 },
593 { (char*)"Zulu", 0x5c },
594 { (char*)"zu", 0x5c },
595 { (char*)"Ko", 0x3d }
599 const SMS_WSP_HEADER_PARAMETER_S wspHeaderApplId[] = {
600 { (char*)"x-wap-application:*", 0x00 },
601 { (char*)"x-wap-application:push.sia", 0x01},
602 { (char*)"x-wap-application:wml.ua", 0x02 },
603 { (char*)"x-wap-application:wta.ua", 0x03 },
604 { (char*)"x-wap-application:mms.ua", 0x04 },
605 { (char*)"x-wap-application:push.syncml", 0x05 },
606 { (char*)"x-wap-application:loc.ua", 0x06 },
607 { (char*)"x-wap-application:syncml.dm", 0x07 },
608 { (char*)"x-wap-application:drm.ua", 0x08 },
609 { (char*)"x-wap-application:emn.ua", 0x09 },
610 { (char*)"x-oma-application:ulp.ua ", 0x10 },
611 { (char*)"x-oma-docomo:open.ctl", 0x9055 },
612 { (char*)"x-oma-docomo:xmd.mail.ua", 0x905C },
613 { (char*)"x-oma-docomo:xmd.storage.ua", 0x905F },
614 { (char*)"x-oma-docomo:xmd.lcsapp.ua", 0x9060 },
615 { (char*)"x-oma-docomo:xmd.info.ua", 0x9061 },
616 { (char*)"x-oma-docomo:xmd.agent.ua", 0x9062 },
617 { (char*)"x-oma-docomo:xmd.sab.ua", 0x9063 },
618 { (char*)"x-oma-docomo:xmd.am.ua", 0x9064 },
619 { (char*)"x-oma-docomo:xmd.emdm.ua", 0x906B },
620 { (char*)"x-oma-docomo:xmd.lac.ua", 0x906C },
621 { (char*)"x-oma-docomo:xmd.osv.ua", 0x906D },
622 { (char*)"x-oma-docomo:xmd.dcs.ua", 0x906E },
623 { (char*)"x-oma-docomo:xmd.wipe.ua", 0x906F },
624 { (char*)"x-oma-docomo:xmd.vdapp.ua ", 0x9070 },
628 const char* wspCacheControl[] = {
634 (char*)"Only-if-cached",
637 (char*)"No-transform",
638 (char*)"Must-revalidate",
639 (char*)"Proxy-revalidate"
642 const SMS_WSP_METHOD_TYPE_S wspMethodType[] = {
643 { (char*)"GET", 0x40 },
644 { (char*)"OPTIONS", 0x41 },
645 { (char*)"HEAD", 0x42 },
646 { (char*)"DELETE", 0x43 },
647 { (char*)"TRACE", 0x44 },
648 { (char*)"POST", 0x60 },
649 { (char*)"PUT", 0x61 }
653 const SMS_WSP_SECURITY_TYPE_S wspSecurityType[] = {
654 {(char*)"NETWPIN", 0x00},
655 {(char*)"USERPIN", 0x01},
656 {(char*)"USERNETWPIN", 0x02},
657 {(char*)"USERPINMAC", 0x03}
662 const char* wspWeek[] = {
673 const char* wspWeekDay[] = {
683 const char* wspMonth[] = {
700 /*==================================================================================================
701 IMPLEMENTATION OF SmsPluginWapPushHandler - Member Functions
702 ==================================================================================================*/
703 SmsPluginWapPushHandler* SmsPluginWapPushHandler::pInstance = NULL;
706 SmsPluginWapPushHandler::SmsPluginWapPushHandler()
708 memset(&tmpAddress, 0x00, sizeof(tmpAddress));
709 memset(&tmpTimeStamp, 0x00, sizeof(tmpTimeStamp));
713 SmsPluginWapPushHandler::~SmsPluginWapPushHandler()
718 SmsPluginWapPushHandler* SmsPluginWapPushHandler::instance()
721 pInstance = new SmsPluginWapPushHandler();
727 bool SmsPluginWapPushHandler::IsWapPushMsg(SMS_USERDATA_S *pUserData)
731 if (pUserData == NULL) {
732 MSG_DEBUG("pUserData is NULL");
736 int PortCount = sizeof(wapPushPortList) / sizeof(wapPushPortList[0]);
738 MSG_DEBUG("Port Count [%d]", PortCount);
740 for (int i = 0; i < pUserData->headerCnt; i++) {
741 if (pUserData->header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
742 /** Have to check something??? */
743 } else if (pUserData->header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
744 for (int j = 0; j < PortCount; j++) {
745 if (pUserData->header[i].udh.appPort16bit.destPort == wapPushPortList[j]) {
746 MSG_DEBUG("Wap Push Msg : [%04x]", wapPushPortList[j]);
759 SMS_WAP_APP_CODE_T SmsPluginWapPushHandler::getAppCode(const char *pPushHeader)
761 int appCount = sizeof(pushDefaultApplication)/sizeof(pushDefaultApplication[0]) - 1;
763 unsigned char *header = NULL;
764 SMS_WAP_APP_CODE_T appCode = SMS_WAP_APPLICATION_DEFAULT;
766 MSG_DEBUG("Application Count [%d]", appCount);
768 for (int i = 0; i < appCount; i++) {
769 header = (unsigned char*)strcasestr(pPushHeader, pushDefaultApplication[i].pContentType);
771 if (header != NULL) {
772 appCode = pushDefaultApplication[i].appCode;
777 if (appCode == SMS_WAP_APPLICATION_DEFAULT) {
778 MSG_DEBUG("Application Type is not supported");
780 MSG_DEBUG("Find Application [%d]", appCode);
788 void SmsPluginWapPushHandler::copyDeliverData(SMS_DELIVER_S *pDeliver)
790 tmpAddress.ton = pDeliver->originAddress.ton;
791 tmpAddress.npi = pDeliver->originAddress.npi;
793 strncpy(tmpAddress.address, pDeliver->originAddress.address, MAX_ADDRESS_LEN);
795 MSG_SEC_DEBUG("Address [%s]", tmpAddress.address);
797 tmpTimeStamp.format = pDeliver->timeStamp.format;
799 if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
800 tmpTimeStamp.time.absolute.year = pDeliver->timeStamp.time.absolute.year;
801 tmpTimeStamp.time.absolute.month = pDeliver->timeStamp.time.absolute.month;
802 tmpTimeStamp.time.absolute.day = pDeliver->timeStamp.time.absolute.day;
803 tmpTimeStamp.time.absolute.hour = pDeliver->timeStamp.time.absolute.hour;
804 tmpTimeStamp.time.absolute.minute = pDeliver->timeStamp.time.absolute.minute;
805 tmpTimeStamp.time.absolute.second = pDeliver->timeStamp.time.absolute.second;
806 tmpTimeStamp.time.absolute.timeZone = pDeliver->timeStamp.time.absolute.timeZone;
811 void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize, int simIndex, time_t sent_time)
815 #ifdef MSG_FW_FOR_DEBUG
816 MSG_DEBUG("DataSize [%d]", DataSize);
818 MSG_DEBUG("[pUserData]");
819 for (int i = 0; i < DataSize; i++) {
820 printf("[%02x]", pUserData[i]);
825 unsigned char* pPDUTypeData = (unsigned char*)pUserData;
826 unsigned long PDUTypeDataLen = DataSize;
828 char* pPushHeader = NULL;
829 unique_ptr<char*, void(*)(char**)> pushHeaderBuf(&pPushHeader, unique_ptr_deleter);
830 unsigned long pushHeaderLen = 0;
832 char* pPushBody = NULL;
833 unique_ptr<char*, void(*)(char**)> PushBodyBuf(&pPushBody, unique_ptr_deleter);
834 unsigned long pushBodyLen = 0;
836 unsigned long iPDU = 1;
838 char* pWspHeader = NULL;
839 unique_ptr<char*, void(*)(char**)> WspHeaderBuf(&pWspHeader, unique_ptr_deleter);
840 unsigned long wspHeaderLen = 0;
842 char* pWspBody = NULL;
843 unique_ptr<char*, void(*)(char**)> WspBodyBuf(&pWspBody, unique_ptr_deleter);
844 unsigned long wspBodyLen = 0;
849 pushHeaderLen = wspRetriveUintvarDecode(pPDUTypeData, &iPDU);
851 MSG_DEBUG("PDUTypeDataLen [%d]", PDUTypeDataLen);
852 MSG_DEBUG("pushHeaderLen [%d]", pushHeaderLen);
853 MSG_DEBUG("iPDU [%d]", iPDU);
855 wspHeaderLen = pushHeaderLen + iPDU;
857 MSG_DEBUG("wspBodyLen [%d]", wspBodyLen);
859 if (wspHeaderLen > 0) {
860 pWspHeader = new char[wspHeaderLen];
862 if (pWspHeader == NULL) {
863 MSG_DEBUG("pWspHeader Memory Allocation Failed");
866 memcpy(pWspHeader, pPDUTypeData, wspHeaderLen);
870 #ifdef MSG_FW_FOR_DEBUG
871 MSG_DEBUG("wspHeaderLen [%d]", wspHeaderLen);
873 MSG_DEBUG("[pWspHeader]");
874 for (int i = 0; i < wspHeaderLen; i++) {
875 printf("[%02x]", pWspHeader[i]);
880 /** return if it is below case error */
881 if (PDUTypeDataLen < wspHeaderLen) {
882 MSG_DEBUG("PDUTypeDataLen < wspHeaderLen !!!");
886 /** Finding wspBody Information */
887 wspBodyLen = PDUTypeDataLen - wspHeaderLen;
889 if (wspBodyLen > 0) {
890 pWspBody = new char[wspBodyLen];
892 if (pWspBody == NULL) {
893 MSG_DEBUG("pWspBody Memory Allocation Failed");
896 memcpy(pWspBody, pPDUTypeData + wspHeaderLen, wspBodyLen);
902 wspDecodeHeader(pPDUTypeData + iPDU, pushHeaderLen, PDUTypeDataLen - (iPDU + pushHeaderLen), TRUE, &pPushHeader);
904 iPDU = iPDU + pushHeaderLen;
906 pushBodyLen = PDUTypeDataLen - iPDU ;
908 if (pushBodyLen > 0) {
909 pPushBody = new char[pushBodyLen];
911 if (pPushBody == NULL) {
912 MSG_DEBUG("pPushBody Memory Allocation Failed");
915 memcpy(pPushBody, pPDUTypeData+ iPDU, pushBodyLen);
922 handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen, simIndex, sent_time);
928 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
932 if (pPushBody == NULL) {
933 MSG_DEBUG("pPushBody is NULL");
937 SMS_WAP_APP_CODE_T appCode = getAppCode(pPushHeader);
939 /** check Push message receive setting */
940 bool bPushRecv = false;
942 if (MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv) != MSG_SUCCESS)
943 MSG_INFO("MsgSettingGetBool() is failed");
945 if ((bPushRecv == false) && (appCode != SMS_WAP_APPLICATION_MMS_UA)) {
946 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
951 case SMS_WAP_APPLICATION_MMS_UA:
952 MSG_DEBUG("Received MMS Notification");
953 handleMMSNotification(pPushBody, PushBodyLen);
956 case SMS_WAP_APPLICATION_PUSH_SI:
957 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
958 handleSIMessage(pPushBody, PushBodyLen, true);
961 case SMS_WAP_APPLICATION_PUSH_SIC:
962 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
963 handleSIMessage(pPushBody, PushBodyLen, false);
966 case SMS_WAP_APPLICATION_PUSH_SL:
967 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
968 handleSLMessage(pPushBody, PushBodyLen, true);
971 case SMS_WAP_APPLICATION_PUSH_SLC:
972 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
973 handleSLMessage(pPushBody, PushBodyLen, false);
976 case SMS_WAP_APPLICATION_PUSH_CO:
977 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
978 handleCOMessage(pPushBody, PushBodyLen, true);
981 case SMS_WAP_APPLICATION_PUSH_COC:
982 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
983 handleCOMessage(pPushBody, PushBodyLen, false);
986 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
987 MSG_DEBUG("Received DM BOOTSTRAP");
988 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
991 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
992 MSG_DEBUG("Received DM BOOTSTRAP");
993 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
996 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
997 MSG_DEBUG("Received Provisioning");
998 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1001 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1002 MSG_DEBUG("Received Provisioning");
1003 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1006 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1007 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1008 MSG_DEBUG("Received Provisioning");
1009 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1012 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1013 MSG_DEBUG("Received DM Notification");
1014 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1017 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1018 MSG_DEBUG("Received DS Notification");
1019 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1022 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1023 MSG_DEBUG("Received DS Notification");
1024 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1027 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
1028 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
1029 MSG_DEBUG("Received DRM UA");
1031 if (pPushBody != NULL)
1032 handleDrmVer1(pPushBody, PushBodyLen);
1036 case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
1037 case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
1038 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
1039 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
1040 MSG_DEBUG("Received DRM V2");
1044 case SMS_WAP_APPLICATION_PUSH_EMAIL:
1045 case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
1046 case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
1047 MSG_DEBUG("Received Email");
1051 case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1052 MSG_DEBUG("Received IMPS CIR");
1053 /* TODO: IMPS CIR */
1056 case SMS_WAP_APPLICATION_LBS :
1057 MSG_DEBUG("Received LBS related message");
1058 SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1062 case SMS_WAP_APPLICATION_PUSH_SIA :
1063 MSG_DEBUG("Received SIA");
1068 MSG_DEBUG("Unknown Application [%d]", appCode);
1076 static void launchProcessByAppcode(int appcode)
1079 GError *error = NULL;
1080 GDBusConnection *connection_agent = NULL;
1081 GDBusProxy *dbus_proxy_agent = NULL;
1082 GDBusConnection *connection_service = NULL;
1083 GDBusProxy *dbus_proxy_service = NULL;
1084 GVariant *result_agent = NULL;
1085 GVariant *result_service = NULL;
1088 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1089 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1090 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1091 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1092 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1093 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1094 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION: {
1095 connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1097 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1101 dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_NONE,
1102 NULL, "org.tizen.omadmagent", "/org/tizen/omadmagent",
1103 "org.tizen.omadmagent", NULL, &error);
1105 MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
1109 result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1111 MSG_DEBUG("invoking agent proxy call failed: %s\n", error->message);
1115 connection_service = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1117 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1121 dbus_proxy_service = g_dbus_proxy_new_sync(connection_service, G_DBUS_PROXY_FLAGS_NONE, NULL,
1122 "org.tizen.omadmservice", "/org/tizen/omadmservice",
1123 "org.tizen.omadmservice", NULL, &error);
1125 MSG_DEBUG("Connecting to service proxy failed: %s\n", error->message);
1129 result_service = g_dbus_proxy_call_sync(dbus_proxy_service, "wakeup", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1131 MSG_DEBUG("invoking service proxy call failed: %s\n", error->message);
1138 cv.timedwait(mx.pMsgMutex(), 2);
1144 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1145 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML: {
1146 connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1148 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1152 dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_NONE, NULL,
1153 "org.tizen.omadsagent", "/org/tizen/omadsagent",
1154 "org.tizen.omadsagent", NULL, &error);
1156 MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
1160 result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL,
1161 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1163 MSG_DEBUG("invoking service error: %s\n", error->message);
1174 g_error_free(error);
1178 if (connection_agent) {
1179 g_object_unref(connection_agent);
1180 connection_agent = NULL;
1183 if (dbus_proxy_agent) {
1184 g_object_unref(dbus_proxy_agent);
1185 dbus_proxy_agent = NULL;
1189 g_object_unref(result_service);
1190 result_service = NULL;
1193 if (connection_service) {
1194 g_object_unref(connection_service);
1195 connection_service = NULL;
1198 if (dbus_proxy_service) {
1199 g_object_unref(dbus_proxy_service);
1200 dbus_proxy_service = NULL;
1203 if (result_service) {
1204 g_object_unref(result_service);
1205 result_service = NULL;
1212 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen, int simIndex, time_t sent_time)
1216 if (pPushBody == NULL) {
1217 MSG_DEBUG("pPushBody is NULL");
1221 msg_error_t err = MSG_SUCCESS;
1222 int pushEvt_cnt = 0;
1223 char app_id[MAX_WAPPUSH_ID_LEN] = {0, };
1224 char content_type[MAX_WAPPUSH_CONTENT_TYPE_LEN] = {0, };
1225 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
1227 err = storageHandler->getRegisteredPushEvent(pPushHeader, &pushEvt_cnt, app_id, sizeof(app_id), content_type, sizeof(content_type));
1228 MSG_DEBUG("pushEvt_cnt: %d", pushEvt_cnt);
1229 if (err != MSG_SUCCESS) {
1230 MSG_DEBUG("Fail to get registered push event");
1234 for (int i = 0; i < pushEvt_cnt; ++i) {
1235 /* check Push message receive setting */
1236 bool bPushRecv = false;
1238 if (MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv) != MSG_SUCCESS)
1239 MSG_INFO("MsgSettingGetBool() is failed");
1241 storageHandler->getnthPushEvent(i, &appcode);
1242 MSG_DEBUG("pushEvt_cnt: %d, appcode: %d", pushEvt_cnt, appcode);
1243 if ((bPushRecv == false) && (IsWapPushMsgInWhiteList(appcode) == false)) {
1244 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
1248 #ifdef FEATURE_MMS_DISABLE
1249 if (appcode == SMS_WAP_APPLICATION_MMS_UA) {
1250 MSG_DEBUG("Drop MMS Notification for DOCOMO");
1255 launchProcessByAppcode(appcode);
1258 case SMS_WAP_APPLICATION_MMS_UA:
1259 MSG_DEBUG("Received MMS Notification");
1260 handleMMSNotification(pPushBody, PushBodyLen, simIndex, sent_time);
1263 case SMS_WAP_APPLICATION_PUSH_SI:
1264 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
1265 handleSIMessage(pPushBody, PushBodyLen, true, simIndex);
1268 case SMS_WAP_APPLICATION_PUSH_SIC:
1269 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
1270 handleSIMessage(pPushBody, PushBodyLen, false, simIndex);
1273 case SMS_WAP_APPLICATION_PUSH_SL:
1274 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
1275 handleSLMessage(pPushBody, PushBodyLen, true, simIndex);
1278 case SMS_WAP_APPLICATION_PUSH_SLC:
1279 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
1280 handleSLMessage(pPushBody, PushBodyLen, false, simIndex);
1283 case SMS_WAP_APPLICATION_PUSH_CO:
1284 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
1285 handleCOMessage(pPushBody, PushBodyLen, true, simIndex);
1288 case SMS_WAP_APPLICATION_PUSH_COC:
1289 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
1290 handleCOMessage(pPushBody, PushBodyLen, false, simIndex);
1293 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1294 MSG_DEBUG("Received DM BOOTSTRAP");
1295 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1298 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1299 MSG_DEBUG("Received DM BOOTSTRAP");
1300 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1303 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1304 MSG_DEBUG("Received Provisioning");
1305 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1308 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1309 MSG_DEBUG("Received Provisioning");
1310 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1313 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1314 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1315 MSG_DEBUG("Received Provisioning");
1316 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1319 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1320 MSG_DEBUG("Received DM Notification");
1321 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1324 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1325 MSG_DEBUG("Received DS Notification");
1326 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1329 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1330 MSG_DEBUG("Received DS Notification");
1331 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1334 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
1335 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
1336 MSG_DEBUG("Received DRM UA");
1338 if (pPushBody != NULL)
1339 handleDrmVer1(pPushBody, PushBodyLen);
1343 case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
1344 case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
1345 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
1346 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
1347 MSG_DEBUG("Received DRM V2");
1351 case SMS_WAP_APPLICATION_PUSH_EMAIL:
1352 case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
1353 case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
1354 MSG_DEBUG("Received Email");
1359 case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1360 MSG_DEBUG("Received IMPS CIR");
1361 /* TODO: IMPS CIR */
1364 case SMS_WAP_APPLICATION_LBS:
1365 MSG_DEBUG("Received LBS related message");
1366 SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1370 case SMS_WAP_APPLICATION_PUSH_SIA:
1371 MSG_DEBUG("Received SIA");
1376 SmsPluginEventHandler::instance()->handlePushMsgIncoming(pPushHeader, pPushBody, PushBodyLen, app_id, content_type);
1380 storageHandler->releasePushEvent();
1386 bool SmsPluginWapPushHandler::IsWapPushMsgInWhiteList(int appCode)
1390 bool isAllowed = false;
1393 case SMS_WAP_APPLICATION_MMS_UA:
1394 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1395 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1396 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1397 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1398 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1399 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1400 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1401 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1402 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1403 MSG_INFO("appcode[%d] is allowed even if push receive option is disabled.", appCode);
1407 MSG_DEBUG("appcode[%d] is not allowed when push receive option is disabled.", appCode);
1414 void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen, int simIndex, time_t sent_time)
1418 #ifdef MSG_FW_FOR_DEBUG
1419 printf("\n\n[handleMMSNotification] Push Body.\n");
1421 for (int i = 0; i < PushBodyLen; i++) {
1422 printf(" [%02x]", pPushBody[i]);
1427 /** Make MSG_MESSAGE_INFO_S */
1428 MSG_MESSAGE_INFO_S msgInfo;
1429 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1431 msgInfo.addressList = NULL;
1432 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1434 createMsgInfo(&msgInfo);
1436 /** Convert Type values */
1437 msgInfo.msgType.mainType = MSG_MMS_TYPE;
1438 msgInfo.msgType.subType = MSG_NOTIFICATIONIND_MMS;
1439 msgInfo.msgType.classType = MSG_CLASS_NONE;
1440 msgInfo.storageId = MSG_STORAGE_PHONE;
1441 msgInfo.dataSize = PushBodyLen;
1442 msgInfo.sim_idx = simIndex;
1445 msgInfo.displayTime = sent_time;
1447 if (msgInfo.dataSize > MAX_MSG_TEXT_LEN) {
1448 msgInfo.bTextSms = false;
1450 /** Save Message Data into File */
1451 char fileName[MSG_FILENAME_LEN_MAX+1];
1452 memset(fileName, 0x00, sizeof(fileName));
1454 if (MsgCreateFileName(fileName) == false)
1455 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1457 if (MsgWriteIpcFile(fileName, pPushBody, msgInfo.dataSize) == false)
1458 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1460 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1462 msgInfo.bTextSms = true;
1464 memcpy(msgInfo.msgText, pPushBody, msgInfo.dataSize);
1465 msgInfo.msgText[msgInfo.dataSize] = '\0';
1468 msg_error_t err = MSG_SUCCESS;
1470 /** Add MMS Noti Msg into DB */
1471 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1473 if (err == MSG_SUCCESS) {
1475 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1477 if (err != MSG_SUCCESS) {
1478 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1481 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1487 void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1491 MSG_PUSH_MESSAGE_S pushMsg = {};
1493 xmlDocPtr xmlDoc = NULL;
1494 xmlNodePtr topNode = NULL;
1495 xmlNodePtr indNode = NULL;
1497 xmlChar* tmpXmlChar = NULL;
1499 if (pPushBody == NULL) {
1500 MSG_DEBUG("pPushBody is NULL");
1504 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1506 if (xmlDoc == NULL) {
1507 MSG_DEBUG("xmlDoc is NULL");
1511 topNode = xmlDocGetRootElement(xmlDoc);
1513 if (topNode == NULL) {
1514 MSG_DEBUG("topNode is NULL");
1519 indNode = topNode->xmlChildrenNode;
1521 while (indNode != NULL) {
1522 if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
1523 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1527 indNode = indNode->next;
1530 if (indNode == NULL) {
1531 MSG_DEBUG("indNode is NULL.");
1535 /** temporary set to max. */
1536 pushMsg.expires = 0xFFFFFFFF;
1538 /** setting received time */
1539 time_t t = time(NULL);
1540 time_t utfTime = time(&t);
1542 pushMsg.received = (unsigned long)utfTime;
1544 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1546 if (tmpXmlChar == NULL) {
1547 MSG_DEBUG("href is NULL.");
1551 if (tmpXmlChar != NULL)
1552 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1554 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
1556 if (tmpXmlChar != NULL)
1557 strncpy(pushMsg.id, (char*)tmpXmlChar, MAX_WAPPUSH_ID_LEN-1);
1559 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CREATED_TAG);
1561 if (tmpXmlChar != NULL)
1562 pushMsg.created = convertXmlCharToSec((char*)tmpXmlChar);
1564 if (pushMsg.created == 0)
1565 pushMsg.created = pushMsg.received;
1567 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_EXPIRES_TAG);
1569 if (tmpXmlChar != NULL)
1570 pushMsg.expires = convertXmlCharToSec((char*)tmpXmlChar);
1572 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1574 pushMsg.action = convertSIActionStrToEnum((char*)tmpXmlChar);
1576 tmpXmlChar = xmlNodeListGetString(xmlDoc, indNode->xmlChildrenNode, 1);
1578 if (tmpXmlChar == NULL) {
1579 MSG_DEBUG("contents is NULL.");
1583 strncpy(pushMsg.contents, (char*)tmpXmlChar, MAX_WAPPUSH_CONTENTS_LEN-1);
1585 /** Write push Msg to file */
1586 char fileName[MSG_FILENAME_LEN_MAX+1];
1587 memset(fileName, 0x00, sizeof(fileName));
1589 if (MsgCreateFileName(fileName) == false) {
1591 xmlFree(tmpXmlChar);
1592 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1595 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false) {
1597 xmlFree(tmpXmlChar);
1598 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1601 /** Pack Message Info Structure */
1602 MSG_MESSAGE_INFO_S msgInfo;
1603 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1605 msgInfo.addressList = NULL;
1606 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1608 createMsgInfo(&msgInfo);
1610 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1612 /** Convert Type values */
1613 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1614 msgInfo.msgType.subType = MSG_WAP_SI_SMS;
1616 msgInfo.dataSize = sizeof(pushMsg);
1617 msgInfo.sim_idx = simIndex;
1618 getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
1621 xmlFree(tmpXmlChar);
1623 msg_error_t err = MSG_SUCCESS;
1625 /** Add WAP Push Msg into DB */
1626 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1628 if (err == MSG_SUCCESS) {
1630 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1632 if (err != MSG_SUCCESS)
1633 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1635 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1644 void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1648 MSG_PUSH_MESSAGE_S pushMsg = {};
1650 xmlDocPtr xmlDoc = NULL;
1651 xmlNodePtr topNode = NULL;
1652 xmlNodePtr indNode = NULL;
1654 xmlChar* tmpXmlChar = NULL;
1656 msg_error_t err = MSG_SUCCESS;
1658 if (pPushBody == NULL) {
1659 MSG_DEBUG("pPushBody is NULL \n");
1663 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1665 if (xmlDoc == NULL) {
1666 MSG_DEBUG("xmlDoc is NULL \n");
1670 topNode = xmlDocGetRootElement(xmlDoc);
1672 if (topNode == NULL) {
1673 MSG_DEBUG("Empty Document.");
1677 MSG_SEC_DEBUG("Not an empty Document and topNode->name = %s \n", topNode->name);
1682 while (indNode != NULL) {
1683 if (!xmlStrcmp(indNode->name, (const xmlChar*)"sl")) {
1684 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1688 indNode = indNode->next;
1691 /** setting received time setting */
1692 time_t t = time(NULL);
1693 time_t utfTime = time(&t);
1695 pushMsg.received = (unsigned long)utfTime;
1697 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1699 if (tmpXmlChar == NULL) {
1700 MSG_DEBUG("href is NULL.");
1704 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1706 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1707 pushMsg.action = convertSLActionStrToEnum((char*)tmpXmlChar);
1709 /** Setting other parameters in default values */
1710 pushMsg.created = pushMsg.received;
1711 /** temporary set to MAX value. */
1712 pushMsg.expires = 0xFFFFFFFF;
1714 MSG_DEBUG("check pushMsg data");
1715 MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
1716 MSG_DEBUG("pushMsg.received : [%d]", pushMsg.received);
1717 MSG_DEBUG("pushMsg.created : [%d]", pushMsg.created);
1718 MSG_DEBUG("pushMsg.expires : [%d]", pushMsg.expires);
1719 MSG_SEC_DEBUG("pushMsg.id : [%s]", pushMsg.id);
1720 MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
1721 MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
1723 /** Write push Msg to file */
1724 char fileName[MSG_FILENAME_LEN_MAX+1];
1725 memset(fileName, 0x00, sizeof(fileName));
1727 if (MsgCreateFileName(fileName) == false)
1728 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1730 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false)
1731 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1733 /** Pack Message Info Structure */
1734 MSG_MESSAGE_INFO_S msgInfo;
1735 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1737 msgInfo.addressList = NULL;
1738 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1740 createMsgInfo(&msgInfo);
1742 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1744 /** Convert Type values */
1745 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1746 msgInfo.msgType.subType = MSG_WAP_SL_SMS;
1748 /** Update Msg Text */
1749 strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
1751 msgInfo.dataSize = sizeof(pushMsg);
1752 msgInfo.sim_idx = simIndex;
1753 getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
1755 MSG_DEBUG("dataSize : %d", msgInfo.dataSize);
1757 /** Add WAP Push Msg into DB */
1758 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1760 if (err == MSG_SUCCESS) {
1761 /** Callback to MSG FW */
1762 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1764 if (err != MSG_SUCCESS)
1765 MSG_DEBUG("callbackMsgIncoming is failed, err=[%d]", err);
1767 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1771 xmlFree(tmpXmlChar);
1778 void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1780 MSG_PUSH_CACHEOP_S cacheOp;
1782 xmlDocPtr xmlDoc = NULL;
1783 xmlNodePtr topNode = NULL;
1784 xmlNodePtr indNode = NULL;
1786 memset(&cacheOp, 0x00, sizeof(cacheOp));
1788 MSG_DEBUG("Enter handleCOMessage");
1790 if (pPushBody == NULL) {
1791 MSG_DEBUG("pPushBody is NULL \n");
1795 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1797 if (xmlDoc == NULL) {
1798 MSG_DEBUG("xmlDoc is NULL \n");
1802 topNode = xmlDocGetRootElement(xmlDoc);
1803 if (topNode == NULL) {
1804 MSG_DEBUG("Warning:Empty Document\n");
1809 indNode = topNode->xmlChildrenNode;
1812 while (indNode != NULL) {
1813 xmlChar* tmpUrl = NULL;
1814 if (!xmlStrcmp(indNode->name, (const xmlChar*)SMS_PUSH_XML_INVAL_OBJ)) {
1815 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1817 tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1819 if (tmpUrl != NULL) {
1820 strncpy(cacheOp.invalObjectUrl[cacheOp.invalObjectCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1822 MSG_DEBUG("%dth invalObjectUrl is <%s>\n", cacheOp.invalObjectCnt, cacheOp.invalObjectUrl[cacheOp.invalObjectCnt-1]);
1824 MSG_DEBUG("NO href value from the xmlDoc\n");
1826 } else if (!xmlStrcmp(indNode->name, (const xmlChar*)SMS_PUSH_XML_INVAL_SVC)) {
1827 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1828 tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1830 if (tmpUrl != NULL) {
1831 strncpy(cacheOp.invalServiceUrl[cacheOp.invalServiceCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1832 MSG_DEBUG("%dth invalServiceUrl is <%s>\n", cacheOp.invalServiceCnt, cacheOp.invalServiceUrl[cacheOp.invalServiceCnt-1]);
1834 MSG_DEBUG("NO href value from the xmlDoc\n");
1841 indNode = indNode->next;
1844 /** Write push Msg to file */
1845 char fileName[MSG_FILENAME_LEN_MAX+1];
1846 memset(fileName, 0x00, sizeof(fileName));
1848 if (MsgCreateFileName(fileName) == false) {
1850 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1853 if (MsgWriteIpcFile(fileName, (char*)(&cacheOp), sizeof(cacheOp)) == false) {
1855 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1858 /** Pack Message Info Structure */
1859 MSG_MESSAGE_INFO_S msgInfo;
1860 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1862 msgInfo.addressList = NULL;
1863 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1865 createMsgInfo(&msgInfo);
1867 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1869 /** Convert Type values */
1870 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1871 msgInfo.msgType.subType = MSG_WAP_CO_SMS;
1873 msgInfo.dataSize = sizeof(cacheOp);
1874 msgInfo.sim_idx = simIndex;
1876 msg_error_t err = MSG_SUCCESS;
1878 /** Add WAP Push Msg into DB */
1879 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1881 if (err == MSG_SUCCESS) {
1883 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1885 if (err != MSG_SUCCESS)
1886 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1888 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1897 void SmsPluginWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
1900 int drmRt = DRM_RETURN_SUCCESS;
1902 unique_ptr<char*, void(*)(char**)> buf(&cid, unique_ptr_deleter);
1904 MSG_DEBUG("Received DRM RIGHTS OBJECT Type WAP Push Message.");
1905 drm_request_type_e request_type = DRM_REQUEST_TYPE_REGISTER_LICENSE;
1906 drm_register_lic_info_s lic_req_info;
1907 drm_register_lic_resp_s lic_resp_info;
1909 bzero(&lic_req_info, sizeof(drm_register_lic_info_s));
1910 bzero(&lic_resp_info, sizeof(drm_register_lic_resp_s));
1911 bzero(lic_req_info.lic_data, sizeof(lic_req_info.lic_data));
1913 memcpy(lic_req_info.lic_data, pPushBody, PushBodyLen);
1915 lic_req_info.lic_version = DRM_OMA_DRMV1_RIGHTS;
1916 lic_req_info.roap_init_src = DRM_ROAP_INIT_FROM_WAPPUSH;
1917 lic_req_info.operation_callback.callback = NULL;
1919 drmRt = drm_process_request(request_type, &lic_req_info, &lic_resp_info);
1920 if (drmRt == DRM_RETURN_SUCCESS) {
1921 MSG_DEBUG("DRM successfully registed to drm-service.");
1923 MSG_DEBUG("Fail to regist DRM to drm-service.");
1930 void SmsPluginWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
1932 /** Convert class Type values */
1933 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
1935 /** set folder id (temporary) */
1936 pMsgInfo->folderId = MSG_INBOX_ID;
1938 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
1939 pMsgInfo->bRead = false;
1940 pMsgInfo->bProtected = false;
1941 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
1942 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
1944 time_t rawtime = time(NULL);
1946 /*** Comment below lines to save local UTC time..... (it could be used later.)
1948 if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
1950 MSG_DEBUG("year : %d", tmpTimeStamp.time.absolute.year);
1951 MSG_DEBUG("month : %d", tmpTimeStamp.time.absolute.month);
1952 MSG_DEBUG("day : %d", tmpTimeStamp.time.absolute.day);
1953 MSG_DEBUG("hour : %d", tmpTimeStamp.time.absolute.hour);
1954 MSG_DEBUG("minute : %d", tmpTimeStamp.time.absolute.minute);
1955 MSG_DEBUG("second : %d", tmpTimeStamp.time.absolute.second);
1956 MSG_DEBUG("timezone : %d", tmpTimeStamp.time.absolute.timeZone);
1958 char displayTime[32];
1962 memset(&timeinfo, 0x00, sizeof(tm));
1964 timeinfo.tm_year = (tmpTimeStamp.time.absolute.year + 100);
1965 timeinfo.tm_mon = (tmpTimeStamp.time.absolute.month - 1);
1966 timeinfo.tm_mday = tmpTimeStamp.time.absolute.day;
1967 timeinfo.tm_hour = tmpTimeStamp.time.absolute.hour;
1968 timeinfo.tm_min = tmpTimeStamp.time.absolute.minute;
1969 timeinfo.tm_sec = tmpTimeStamp.time.absolute.second;
1970 timeinfo.tm_isdst = 0;
1972 rawtime = mktime(&timeinfo);
1974 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
1975 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
1976 MSG_DEBUG("timezone [%d]", timezone);
1977 MSG_DEBUG("daylight [%d]", daylight);
1979 memset(displayTime, 0x00, sizeof(displayTime));
1980 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
1981 MSG_DEBUG("displayTime [%s]", displayTime);
1983 rawtime -= (tmpTimeStamp.time.absolute.timeZone * (3600/4));
1985 timeTM = localtime(&rawtime);
1986 memset(displayTime, 0x00, sizeof(displayTime));
1987 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1988 MSG_DEBUG("displayTime [%s]", displayTime);
1990 rawtime -= timezone;
1992 timeTM = localtime(&rawtime);
1993 memset(displayTime, 0x00, sizeof(displayTime));
1994 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1995 MSG_DEBUG("displayTime [%s]", displayTime);
2000 pMsgInfo->displayTime = rawtime;
2002 /** Convert Address values */
2003 pMsgInfo->nAddressCnt = 1;
2005 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
2006 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
2008 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
2009 strncpy(pMsgInfo->addressList[0].addressVal, tmpAddress.address, MAX_ADDRESS_VAL_LEN);
2011 pMsgInfo->msgPort.valid = false;
2012 pMsgInfo->msgPort.dstPort = 0;
2013 pMsgInfo->msgPort.srcPort = 0;
2016 void SmsPluginWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText)
2018 if (pPushBody == NULL) {
2019 MSG_DEBUG("pPushBody is NULL");
2025 *pXmlDoc = xmlParseMemory(pPushBody, AcStrlen(pPushBody));
2027 WB_UTINY* xmldata = NULL;
2028 WBXMLConvWBXML2XML *conv = NULL;
2029 WBXMLError ret = WBXML_OK;
2031 ret = wbxml_conv_wbxml2xml_create(&conv);
2032 if (ret != WBXML_OK)
2035 ret = wbxml_conv_wbxml2xml_run(conv, (WB_UTINY*)pPushBody, (WB_ULONG)PushBodyLen, &xmldata, NULL);
2037 wbxml_conv_wbxml2xml_destroy(conv);
2039 if (ret != WBXML_OK ||xmldata == NULL) {
2040 MSG_DEBUG("xmldata is NULL. Error code is [%d].\n", ret);
2044 MSG_DEBUG("xmldata : \n%s\n", xmldata);
2046 *pXmlDoc = xmlParseMemory((char*)xmldata, AcStrlen((char*)xmldata));
2050 unsigned long SmsPluginWapPushHandler::convertXmlCharToSec(char* pDate)
2052 struct tm timeStruct;
2053 time_t nTimeInSec = 0;
2055 int i = 0, index = 0;
2057 memset(tmpBuf, 0x00, sizeof(tmpBuf));
2058 memset(&timeStruct, 0x00, sizeof(struct tm));
2061 if (AcStrlen(pDate) < 20)
2064 MSG_DEBUG("pDate [%s]", pDate);
2067 for (i = 0; i < 4; i++) {
2068 tmpBuf[i] = pDate[index++];
2072 timeStruct.tm_year = (atoi(tmpBuf)-1900);
2075 for (i = 0; i < 2; i++) {
2076 tmpBuf[i] = pDate[index++];
2080 timeStruct.tm_mon = (atoi(tmpBuf) - 1);
2083 for (i = 0; i < 2; i++) {
2084 tmpBuf[i] = pDate[index++];
2088 timeStruct.tm_mday = atoi(tmpBuf);
2091 for (i = 0; i < 2; i++) {
2092 tmpBuf[i] = pDate[index++];
2096 timeStruct.tm_hour = atoi(tmpBuf);
2099 for (i = 0; i < 2; i++) {
2100 tmpBuf[i] = pDate[index++];
2104 timeStruct.tm_min = atoi(tmpBuf);
2107 for (i = 0; i < 2; i++) {
2108 tmpBuf[i] = pDate[index++];
2112 timeStruct.tm_sec = atoi(tmpBuf);
2114 nTimeInSec = mktime(&timeStruct);
2119 msg_push_action_t SmsPluginWapPushHandler::convertSIActionStrToEnum(char* pAction)
2123 if (pAction == NULL) {
2124 MSG_DEBUG("pAction is NULL. Setting to default action type.");
2125 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2128 /** compare with signal-none. */
2129 comp = g_strcmp0("signal-none", pAction);
2131 return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
2133 /** compare with signal-low. */
2134 comp = g_strcmp0("signal-low", pAction);
2136 return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
2138 /** compare with signal-medium. */
2139 comp = g_strcmp0("signal-medium", pAction);
2141 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2143 /** compare with signal-high. */
2144 comp = g_strcmp0("signal-high", pAction);
2146 return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
2148 /** compare with delete. */
2149 comp = g_strcmp0("delete", pAction);
2151 return MSG_PUSH_SI_ACTION_DELETE;
2153 /** signal-medium is default action value. */
2154 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2157 msg_push_action_t SmsPluginWapPushHandler::convertSLActionStrToEnum(char* pAction)
2161 if (pAction == NULL) {
2162 MSG_DEBUG("MSG_DEBUG is NULL. Setting to default action type.\n");
2163 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2166 /** compare pSrcStr with execute-low. */
2167 comp = g_strcmp0("execute-low", pAction);
2169 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2171 /** compare pSrcStr with execute-high. */
2172 comp = g_strcmp0("execute-high", pAction);
2174 return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
2176 /** compare pSrcStr with cache. */
2177 comp = g_strcmp0("cache", pAction);
2179 return MSG_PUSH_SL_ACTION_CACHE;
2181 /** default SL action value is execute-low. */
2182 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2186 unsigned long SmsPluginWapPushHandler::wspRetriveUintvarDecode(unsigned char* sourceData, unsigned long* currentPointer)
2188 unsigned long i = 0;
2189 unsigned long decodedValue;
2191 while (sourceData[*currentPointer + i] >= 0x80)
2194 decodedValue = wspDecodeUintvar(i + 1, sourceData + *currentPointer);
2195 *currentPointer = *currentPointer + i + 1;
2196 MSG_DEBUG("wspRetriveUintvarDecode: decodedValue=%d .\n", decodedValue);
2197 return decodedValue;
2201 unsigned long SmsPluginWapPushHandler::wspDecodeUintvar(unsigned long length, unsigned char* userVar)
2204 unsigned long decodedUintvar = 0;
2207 for (i = 0 ; i < length; i++) {
2208 decodedUintvar = decodedUintvar + (wspUintvarDecodeTable[i] * (userVar[length-(i+1)] & 0x7f));
2211 return decodedUintvar;
2215 void SmsPluginWapPushHandler::wspDecodeHeader(unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader)
2217 unsigned long iField = 0;
2218 bool continueField = FALSE;
2219 unsigned long currentLength;
2221 char* encodedHeader = NULL;
2222 unique_ptr<char*, void(*)(char**)> encodedHeaderbuf(&encodedHeader, unique_ptr_deleter);
2224 char* outTemper = NULL;
2226 char* temper = NULL;
2227 unique_ptr<char*, void(*)(char**)> temperbuf(&temper, unique_ptr_deleter);
2229 unsigned char track;
2230 unsigned long iEncodedHeader = 0;
2231 unsigned char fieldCode = 0xff;
2233 /* outTemper is Decoded Headers.
2234 temper is Single Decoded Header.
2236 if (NULL == (outTemper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ])) {
2237 MSG_DEBUG("outTemper Memory allocation is failed.\n");
2240 memset(outTemper, 0, (WSP_STANDARD_STR_LEN_MAX * 5));
2241 currentLength = WSP_STANDARD_STR_LEN_MAX;
2243 MSG_DEBUG("wspDecodeHeader: Message header decoding started.\n");
2249 MSG_DEBUG("wspDecodeHeader: RAW data \n");
2250 for (loop = 0 ; loop < (int)encodedHeaderLen; loop++) {
2252 szTempBuf[0] = 0x00;
2253 snprintf(szTempBuf, sizeof(szTempBuf), "%2X ", sEncodedHeader[loop]);
2255 if (AcStrlen(szBuf) + 7 < 64) {
2256 strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2258 strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2259 MSG_DEBUG("[%s]", szBuf);
2261 strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2264 strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2265 MSG_DEBUG("[%s]", szBuf);
2266 MSG_DEBUG("fContentType=%d \n", fContentType);
2267 /* operation for content-type */
2268 /* makes psuedo- content-type fieldcode */
2269 /* content - type is processed with header. But it's come without field code. So existence of fContentType can decide adding content type header field code whether ContentType + general header is or not. */
2272 encodedHeader = new char[ encodedHeaderLen + 1 ];
2273 if (encodedHeader == NULL) {
2274 MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2277 encodedHeader[0] = 0x91;
2278 memcpy(encodedHeader + 1, sEncodedHeader, (size_t)encodedHeaderLen);
2280 encodedHeader = new char[ encodedHeaderLen ];
2281 if (encodedHeader == NULL) {
2282 MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2286 memcpy(encodedHeader, sEncodedHeader, (size_t)encodedHeaderLen);
2289 /* Is it reacehd end of header? */
2290 while (iEncodedHeader < encodedHeaderLen) {
2291 /* Get memory for single header */
2292 if (temper == NULL) {
2293 temper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ];
2295 if (temper == NULL) {
2296 MSG_DEBUG("temper Memory allocation is failed.\n");
2299 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2301 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2304 /* this section presents header code page shifting procedure
2305 This part can be implemented by future request.
2308 track = encodedHeader[iEncodedHeader];
2310 if (track == 0x00) {
2311 MSG_DEBUG("WspLDecodeHeader: fieldcode is 0 \n");
2312 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2315 } else if ((track > 0) && (track < 0x20)) {
2317 } else if ((track < 0x7f) && (track > 0x1f)) { /* In this case, first byte is normal string. So it's considered to unknown header. */
2318 unsigned char* fieldName = (unsigned char*)gWapCodeBufferLeft;
2319 unsigned char* fieldValue = (unsigned char*)gWapCodeBufferRight;
2321 strncpy((char*)fieldName, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_LEFT_LEN_MAX-1);
2322 fieldName[WSP_CODE_BUFFER_LEFT_LEN_MAX-1] = '\0';
2323 iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldName) + 1;
2324 strncpy((char*)fieldValue, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_RIGHT_LEN_MAX-1);
2325 fieldValue[WSP_CODE_BUFFER_RIGHT_LEN_MAX-1] = '\0';
2326 iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldValue) + 1;
2328 strncat((char*)temper, (char*)fieldName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2329 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2330 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2331 /* this means 'don't process anymore.' */
2334 } else if (track > 0x7f) {
2335 /* In case of first byte is field code, else case is error. */
2337 /*if ((track & 0x7f) <= wspHeaderFieldCount) { */
2338 unsigned long fieldValueLen = encodedHeader[iEncodedHeader + 1];
2339 unsigned char fieldValue[1275];
2340 fieldCode = track & 0x7f;
2342 if ((fieldValueLen == 0) || (fieldValueLen == 0x80))
2344 dprint(DNET_WAP,DNET_DBG_HIGH, "%X %X %X %X %X %X\n" , fieldCode, encodedHeader[iEncodedHeader + 1], encodedHeader[iEncodedHeader + 2],encodedHeader[iEncodedHeader + 3],encodedHeader[iEncodedHeader + 4], encodedHeader[iEncodedHeader + 5]);
2347 memset(fieldValue, 0, 1275);
2348 /* add field name */
2349 /* This continueField flag show whether previous field code and current field code are same or not. If it's same, there are some sequential display effect by omitting field name addition process. The reason why it should be do that can be found in encoding example of spec. */
2350 if (!continueField) {
2351 strncat((char*)temper, (char*)wspHeaderFieldName[fieldCode], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2352 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2353 continueField = FALSE;
2356 /* field value is string */
2357 /* In this case, it just copy field value. */
2358 if ((fieldValueLen > LENGTH_QUOTE) && (fieldValueLen < 0x80)) {
2359 /* string field value should be NULL terminated */
2360 strncat((char*)temper, (char*)(encodedHeader + iEncodedHeader + 1), (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2361 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2363 iEncodedHeader = iEncodedHeader + AcStrlen((char*)encodedHeader + iEncodedHeader + 1) + 2;
2366 /* first field value is length */
2367 /* If first byte of field value is length value, allocate field value by the length.
2368 In field value, data is
2369 1D 03 8F 24 24 - Then 8F 24 24 is field value.
2370 1D 1F 33.... - Then allocate 33H for FieldValue.
2372 1D 'Hi man!' Like 00, if string is come, then process without calculating field value.
2373 1D 8F 24 24 - In this case, original data is wrong.
2374 If accept-charset: ISO-10646-ucs-2;Q=0.7 is
2377 03 - field value length
2378 03 E8 47 - field value
2379 it's decoded by above value.
2381 if (fieldValueLen < 0x20) {
2382 if (fieldValueLen == LENGTH_QUOTE) {
2383 /* field length is encoded in UINTVAR */
2384 unsigned long uintvarLen = 0;
2385 fieldValueLen = wspRetriveUintvarDecode((unsigned char*) encodedHeader + iEncodedHeader + 2, &uintvarLen);
2386 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2 + uintvarLen, (size_t)fieldValueLen);
2387 iEncodedHeader = iEncodedHeader + fieldValueLen + uintvarLen + 2;
2390 if (fieldValueLen == 1) {
2391 /* field value is one byte integer over 0x80 */
2392 /** make it two byte integer */
2393 fieldValue[0] = 0x00;
2394 memcpy(fieldValue + 1, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2396 iEncodedHeader = iEncodedHeader + 1 + 2;
2398 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2399 fieldValue[fieldValueLen] = 0;
2400 iEncodedHeader = iEncodedHeader + fieldValueLen + 2;
2401 if ((fieldValueLen == 0) || (fieldValueLen == 0x80)) {
2402 MSG_DEBUG("%X \n", encodedHeader[iEncodedHeader]);
2407 /* field value is single encoded */
2408 if (fieldValueLen > 0x7f) {
2409 fieldValue[0] = encodedHeader[iEncodedHeader + 1];
2411 iEncodedHeader = iEncodedHeader + 2;
2413 /* processing normal pre-defined field decoding */
2415 MSG_DEBUG("WspLDecodeHeader: FieldCode %X\n", fieldCode);
2416 MSG_DEBUG("WspLDecodeHeader: fieldSize %d\n", fieldValueLen);
2418 if ((fieldCode > wspHeaderFieldCount) && (fieldCode != 0xff)) {
2419 MSG_DEBUG("WspLDecodeHeader: unknown fieldcode %X \n", track);
2420 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2425 switch (fieldCode) {
2426 /* accept charset */
2427 /* It's normal way of field process. */
2429 unsigned long i = 0;
2432 /* Case of length of charset greater than 1 are two thigins.
2433 1. code length of charset is greater than 1.
2434 2. It include parameter.
2437 if (1 != fieldValueLen) {
2438 code = wspHeaderDecodeInteger(fieldValue);
2439 /* Calculate iField. */
2440 if (fieldValue[0] < 0x80)
2441 iField = fieldValue[0];
2445 while (wspCharset[i].charsetCode != code)
2447 strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2448 /* If parameter exist */
2449 if (iField < fieldValueLen) {
2451 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2452 wspHeaderDecodeQValue(fieldValueLen - iField, fieldValue + iField, ¶m);
2453 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2456 code = fieldValue[0] & 0x7f;
2458 while ((wspCharset[i].charsetCode != code) && (wspCharset[i].charsetCode != 0xffff )) i++;
2459 strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2465 /* Like below routine, Same decoding routine process together. */
2466 /* Accept-encoding */
2468 /* content-encoding */
2472 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2473 if (integerValue > 2) {
2474 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(2).\n");
2477 strncat((char*)temper, (char*)wspEncodeMethod[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2480 /* contents type decoder */
2485 unsigned long contentsTypeCode;
2486 unsigned long i = 0;
2487 /* encoded content type length body */
2488 unsigned long tempLen;
2489 MSG_DEBUG("fieldValueLen: %d", fieldValueLen);
2491 /* Like HTTP result state 304, it's for processing without Content type. This part doesn't defined. */
2492 if (0 == fieldValueLen) {
2493 strncat((char*)temper, (char*)"None" , (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2496 /* 01 AE --> 00 AE --> AE*/
2497 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2498 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2499 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2502 if ((fieldValue[0] < 0x20) || (fieldValue[0] >= 0x80)) {
2503 if (fieldValue[0] >= 0x80) {
2505 } else if (fieldValueLen == 2 && fieldValue[0] == 0x03 && fieldValue[1] == 0x0A) { /** 06 05 02 03 0A AF 89 */
2506 fieldValue[3] = fieldValue[2];
2507 fieldValue[2] = fieldValue[1];
2508 fieldValue[1] = fieldValue[0];
2509 fieldValue[0] = 0x02;
2512 MSG_DEBUG("WspLDecodeHeader:For CPE problem\r\n");
2514 tempLen = fieldValue[0]; /** 06 06 03 02 03 16 AF 88 */
2518 char* szExtendedContent;
2520 contentsTypeCode = fieldValue[0] & 0x7f;
2521 while ((wspContentsType[i].contentsTypeCode != contentsTypeCode) && (i < wspContentsTypeCount)) i++;
2523 /* If specified content type doesn't exist */
2524 if (i < wspContentsTypeCount)
2525 strncat((char*)temper, (char*)wspContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2527 szExtendedContent = wspExtendedDecodeType((char)contentsTypeCode);
2529 if (szExtendedContent != NULL) {
2530 MSG_DEBUG("WspLDecodeHeader: Tele2 server problem \n ");
2531 strncat((char*)temper, (char*)szExtendedContent, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2534 contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
2536 while ((i < wspUnregisteredContentsTypeCount) && (wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode)) i++;
2538 /** If there is a Content-Type assigned, */
2539 if (i < wspUnregisteredContentsTypeCount)
2540 strncat((char*)temper, (char*)wspUnregisterContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2545 tempLen = AcStrlen((char*)fieldValue) + 1;
2547 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2548 MSG_DEBUG("WspLDecodeHeader: Attention, Decoding Check of Content-Type\n ", tempLen);
2551 /* If there is a parameter */
2552 if (tempLen < fieldValueLen) {
2554 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2555 wspHeaderDecodeParameter(fieldValue + tempLen, fieldValueLen - tempLen, ¶m);
2556 if (param != NULL) {
2557 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2558 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2565 /* content-language */
2567 /* accept-language */
2569 unsigned long i = 0;
2571 unsigned long tempLen;
2572 if ((fieldValue[0] < 0x20) || (fieldValue[0] > 0x80)) {
2573 if (fieldValue[0] > 0x80)
2576 tempLen = fieldValue[0];
2578 tempLen = AcStrlen((char*)fieldValue) + 1;
2582 code = wspHeaderDecodeInteger(fieldValue);
2583 while (wspLanguage[i].languageCode != code) {
2585 if (i == wspLanguageCount)
2589 if (i < wspLanguageCount) {
2590 strncat((char*)temper, (char*)wspLanguage[i].languageName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2593 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2596 if (tempLen < fieldValueLen) {
2598 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2599 wspHeaderDecodeQValue(fieldValueLen - tempLen, fieldValue + tempLen, ¶m);
2600 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2608 /* content-length */
2612 /* Bearer-indication */
2616 unsigned char temp[16];
2618 if ((fieldValueLen == 2) && (fieldValue[0] > 0x7f))
2619 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[1]);
2622 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2623 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2626 /* X-Wap-Application-Id */
2628 unsigned char temp[64];
2631 if (track == 0xaf) { /* WAP short-integer-encoded */
2632 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2633 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen);
2635 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2637 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2638 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2639 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2642 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2645 MSG_DEBUG("integerValue = [%02x]", integerValue);
2647 int count = sizeof(wspHeaderApplId)/sizeof(SMS_WSP_HEADER_PARAMETER_S);
2648 for (int i = 0; i < count ; ++i) {
2649 if ((unsigned int)integerValue == wspHeaderApplId[i].parameterCode) {
2650 snprintf((char*)temp, 64, "%s", wspHeaderApplId[i].parameterToken);
2651 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2657 /* Accept-Application */
2659 if (0x80 == fieldValue[0]) {
2660 strncat((char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2662 unsigned char temp[16];
2664 if ((fieldValueLen == 2) && (fieldValue[0] == 1))
2665 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[0]);
2668 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2669 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2677 /* if-unmodified-since */
2681 /* if-modified-since */
2687 char* decodedString = NULL;
2688 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2689 wspHeaderDecodeDateValue(fieldValueLen, fieldValue, &decodedString);
2690 strncat((char*)temper, (char*)decodedString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2696 if (fieldValue[0] == 0x80)
2697 strncat((char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2701 if (fieldValue[0] == 0x80)
2702 strncat((char*)temper, "None", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2703 if (fieldValue[0] == 0x81)
2704 strncat((char*)temper, "Bytes", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2708 unsigned char temp[1275];
2709 memcpy(temp, fieldValue, (size_t)fieldValueLen);
2710 temp[fieldValueLen] = 0;
2711 wspHeaderCopyDecodedString(temp, ¤tLength, &temper);
2717 /* proxy - authorization */
2719 if (fieldValue[0] == 0x80) {
2720 char* addString = NULL;
2721 unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2722 wspHeaderDecodeAuth(fieldValueLen, fieldValue, &addString);
2723 strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2725 iField = AcStrlen((char*)fieldValue) + 1;
2727 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2728 if (iField < fieldValueLen) {
2730 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2731 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, ¶m);
2732 if (param != NULL) {
2733 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2734 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2744 /* Proxy-authenticate */
2746 if (0 == fieldValueLen)
2748 if (fieldValue[0] == 0x80) {
2749 char* addString = NULL;
2750 unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2751 wspHeaderDecodeChallenge(fieldValueLen, fieldValue, &addString);
2752 strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2754 unsigned char authScheme[WSP_STANDARD_STR_LEN_MAX + 1];
2755 unsigned char realmValue[WSP_STANDARD_STR_LEN_MAX];
2756 unsigned char addedString[WSP_STANDARD_STR_LEN_MAX];
2758 strncpy((char*)authScheme, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX -1);
2759 iField = AcStrlen((char*)authScheme) + 1;
2760 strncpy((char*)realmValue, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2761 iField = iField + AcStrlen((char*)realmValue) + 1;
2762 snprintf((char*)addedString, sizeof(addedString), "%s %s", authScheme, realmValue);
2763 wspHeaderCopyDecodedString(addedString, ¤tLength, &temper);
2765 if (iField < fieldValueLen) {
2767 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2768 wspHeaderDecodeParameter(fieldValue + iField, fieldValueLen - iField, ¶m);
2769 if (param != NULL) {
2770 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2771 wspHeaderCopyDecodedString((unsigned char*)param, ¤tLength, &temper);
2777 /* content -range */
2779 unsigned long first, len, last;
2781 unsigned char temp[16];
2784 strncat((char*)temper, " bytes ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2786 first = wspRetriveUintvarDecode(fieldValue, &iField);
2787 len = wspRetriveUintvarDecode(fieldValue, &iField);
2788 /* Originally range of HTTP include entity length. But WSP omit it. Finally to calculate this, it should be get content length from export. If this field is included without content length, then it can get wrong result. This content length can be get by calculating PDU length.
2790 last = first + contentsLength - 1;
2792 snprintf((char*)temp, sizeof(temp), "%u-%u/%u", (unsigned int)first, (unsigned int)last, (unsigned int)len);
2793 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2799 char* cacheString = NULL;
2800 unique_ptr<char*, void(*)(char**)> cacheStringbuf(&cacheString, unique_ptr_deleter);
2802 wspHeaderDecodeCacheControl(fieldValue, fieldValueLen, &cacheString);
2803 strncat((char*)temper, (char*)cacheString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2809 if (fieldValue[0] == 0x80) {
2810 strncat((char*)temper, (char*)wspCacheControl[0], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2812 if (1 < fieldValueLen) {
2814 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2815 wspHeaderDecodeParameter(fieldValue, fieldValueLen, ¶m);
2817 if (param != NULL) {
2818 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2819 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2829 unsigned long i = 0;
2830 while (wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen) != wspMethodType[i].methodCode) i++;
2831 strncat((char*)temper, (char*)wspMethodType[i].methodName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2836 strncat((char*)temper, "bytes=", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2837 if (fieldValue[0] == 0x80) {
2838 unsigned char temp[16];
2839 unsigned long first, last;
2842 first = wspRetriveUintvarDecode(fieldValue, &iField);
2843 last = wspRetriveUintvarDecode(fieldValue, &iField);
2845 snprintf((char*)temp, sizeof(temp), "%u-%u", (unsigned int)first, (unsigned int)last);
2846 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2848 if (fieldValue[0] == 0x81) {
2849 unsigned char temp[16];
2850 unsigned long suffix;
2852 suffix = wspRetriveUintvarDecode(fieldValue, &iField);
2854 snprintf((char*)temp, sizeof(temp), "-%u", (unsigned int)suffix);
2859 if (fieldValue[0] == 0x80) {
2861 unique_ptr<char*, void(*)(char**)> tempbuf(&temp, unique_ptr_deleter);
2863 wspHeaderDecodeDateValue(fieldValueLen - 1, fieldValue + 1, &temp);
2864 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2867 if (fieldValue[0] == 0x81) {
2868 unsigned char temp[16];
2870 snprintf((char*)temp, 16, "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2871 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2874 /* transfer-encoding */
2876 /* No other cases allowed */
2877 if (fieldValue[0] == 0x80)
2878 strncat((char*)temper, "chunked", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2883 int integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2884 if (integerValue > wspHeaderFieldCount) {
2885 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x%x).\n", wspHeaderFieldCount);
2888 strncat((char*)temper, (char*)wspHeaderFieldName[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2893 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2895 if (fieldValue[0] < 0x20)
2896 iField = fieldValue[0];
2900 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, iField));
2901 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2902 if (iField < fieldValueLen) {
2903 unsigned char agent[WSP_STANDARD_STR_LEN_MAX];
2904 unsigned char text[WSP_STANDARD_STR_LEN_MAX];
2905 strncpy((char*)agent, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2906 iField = iField + AcStrlen((char*)agent) + 1;
2907 strncpy((char*)text, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2908 snprintf((char*)temp, sizeof(temp), " %s %s", agent, text);
2909 wspHeaderCopyDecodedString(temp, ¤tLength, &temper);
2913 /* content-disposition */
2915 if (fieldValue[0] == 0x80)
2916 strncat((char*)temper, "form-data", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2918 if (fieldValue[0] == 0x81)
2919 strncat((char*)temper, "attachment", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2921 if (1 < fieldValueLen) {
2923 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2924 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, ¶m);
2926 if (param != NULL) {
2927 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2928 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2934 temper[AcStrlen((char*)temper) + fieldValueLen] = '\0';
2935 memcpy(temper, fieldValue, (size_t)fieldValueLen);
2937 /* Profile-Warning */
2939 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2941 snprintf((char*)temp, sizeof(temp), "%lX", wspHeaderDecodeInteger(fieldValue));
2943 temp[1] = (unsigned char)0x30;
2945 if (fieldValueLen > 1) {
2946 /* copy warn-target - URI */
2947 strncat((char*)temp, (char*)(fieldValue + 1), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2948 if (fieldValueLen > (AcStrlen((char*)(fieldValue + 1)) + 1)) {
2949 /* copy warn-date */
2950 char* decodedString = NULL;
2951 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2952 wspHeaderDecodeDateValue(fieldValueLen - (AcStrlen((char*)(fieldValue + 1)) + 2), fieldValue + AcStrlen((char*)(fieldValue + 1)) + 1, &decodedString);
2953 strncat((char*)temp, (char*)decodedString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2956 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2965 /* It deosn't finished decoding yet. */
2966 if ((iEncodedHeader < encodedHeaderLen) && (fieldCode != 0xff)) {
2967 /* In here, iEncodedHeader already point next field code to be decoded. */
2968 /* If this code is same, then set continueField else add CRLF. */
2969 if (fieldCode == (encodedHeader[iEncodedHeader] & 0x7f)) {
2970 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2971 continueField = TRUE;
2973 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2974 continueField = FALSE;
2977 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2980 /* add single header to total headers */
2981 strncat((char*)outTemper, (char*)temper, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)outTemper)-1);
2982 MSG_DEBUG("WspLDecodeHeader: Single Header : %s\r\n", temper);
2986 MSG_DEBUG("WspLDecodeHeader: Header decoding ended.\n");
2988 *pHeader = outTemper;
2994 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeInteger(unsigned char* data)
2996 /* we only can handle max 32bit integer */
3000 unsigned long integer;
3001 unsigned char seg[4];
3004 returner.integer = 0;
3006 if (data[0] < 0x80) {
3007 unsigned long IntLen = 0;
3009 IntLen = (data[0] > 0x04) ? 0x04:data[0];
3011 MSG_DEBUG("WspLHeaderDecodeInteger: input %d , length %d\n", data[0], IntLen);
3013 for (i = 0; i < IntLen; i++)
3014 returner.seg[IntLen-(i+1)] = data[i+1];
3016 return returner.integer;
3019 return data[0] & 0x7f;
3023 void SmsPluginWapPushHandler::wspHeaderDecodeQValue(unsigned long length, unsigned char* data, char** pDecodedString)
3025 unsigned short qBase = 0;
3028 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3029 if (*pDecodedString == NULL) {
3030 MSG_DEBUG("WspLHeaderDecodeQValue:MemAlloc failed\n");
3034 memcpy(&qBase, data, (size_t)length);
3035 qValue = (float)qBase;
3037 qValue = qValue - 100;
3038 qValue = qValue / 1000;
3039 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.3f", qValue);
3041 /* qValue variable is divided by 100. And it's multiplied by 100.
3042 It's to resolve problem of changed 0.01 of qValue. */
3043 unsigned long qValueTemp;
3044 qValue = qValue - 1;
3045 qValue = qValue / 100;
3046 qValueTemp = (unsigned long)(qValue * 100);
3047 if (0 == (qValueTemp % 10))
3048 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.1f", qValue);
3050 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.2f", qValue);
3056 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length)
3061 unsigned long integer;
3062 unsigned short seg[4];
3065 returner.integer = 0;
3068 return data[0] & 0x7f;
3070 returner.integer = 0;
3072 for (i = 0 ; i < length; i++) {
3073 returner.integer = returner.integer + (data[i] * (0x1 << ((length - (i + 1)) * 8)));
3074 MSG_DEBUG("WspLHeaderDecodeIntegerByLength: %d \n", returner.integer);
3077 return returner.integer;
3081 char* SmsPluginWapPushHandler::wspExtendedDecodeType(char contentType)
3085 while (wspExtendedContentsType[i].contentsTypeCode != contentType) {
3086 if (wspExtendedContentsType[i].contentsTypeCode == 0xff)
3091 return (char*)wspExtendedContentsType[i].contentsTypeName;
3095 void SmsPluginWapPushHandler::wspHeaderDecodeParameter(unsigned char* data, unsigned long length, char** pParam)
3097 char* param = *pParam;
3099 unsigned long SecurityTypeCode;
3100 unsigned long i = 0;
3102 if (data[0] < 0x80) {
3103 /* unknown parameter type */
3104 param = new char[WSP_STANDARD_STR_LEN_MAX];
3106 if (param == NULL) {
3107 MSG_DEBUG("WspLHeaderDecodeParameter:MemAlloc failed\n");
3111 strncpy((char*)param, (char*)data, WSP_STANDARD_STR_LEN_MAX - 1);
3113 if (NO_VALUE == data[AcStrlen((char*)param) + 1]) {
3118 strncat((char*)param, "=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3119 strncat((char*)param, (char*)(data + strlen((char*)param)), WSP_STANDARD_STR_LEN_MAX-strlen((char*)param)-1);
3126 switch (data[0] & 0x7f) {
3128 wspHeaderDecodeQValue(length - 1, data + 1, ¶m);
3131 wspHeaderDecodeCharset(length - 1 , data + 1, ¶m);
3134 wspHeaderDecodeVersion(length - 1, data + 1, ¶m);
3138 /* param = (unsigned char *)malloc((size_t)WSP_STANDARD_STR_LEN_MAX); */
3139 param = new char[WSP_STANDARD_STR_LEN_MAX];
3140 if (param == NULL) {
3141 MSG_DEBUG("WspLHeaderDecodeParameter: 0x03 MemAlloc failed\n");
3144 snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Type=%i", (int)wspHeaderDecodeInteger(data + 1));
3148 param = new char[WSP_STANDARD_STR_LEN_MAX];
3150 if (param == NULL) {
3151 MSG_DEBUG("WspLHeaderDecodeParameter:0x08 MemAlloc failed\n");
3154 snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Padding=%i", (int)wspHeaderDecodeInteger(data + 1));
3158 param = new char[WSP_STANDARD_STR_LEN_MAX];
3160 if (param == NULL) {
3161 MSG_DEBUG("WspLHeaderDecodeParameter:0x05 MemAlloc failed\n");
3164 strncpy((char*)param, "Name=", WSP_STANDARD_STR_LEN_MAX-1);
3165 memcpy(param + 5, data + 1, length - 1);
3166 param[5 + length - 1] = '\0';
3170 param = new char[WSP_STANDARD_STR_LEN_MAX];
3172 if (param == NULL) {
3173 MSG_DEBUG("WspLHeaderDecodeParameter:0x06 MemAlloc failed\n");
3176 strncpy((char*)param, "Filename=", WSP_STANDARD_STR_LEN_MAX-1);
3177 memcpy(param + 9, (char*)(data + 1), (size_t)(length - 1));
3178 param[9 + length - 1] = '\0';
3185 /*OMA Provisioning*/
3187 param = new char[WSP_STANDARD_STR_LEN_MAX];
3189 if (param == NULL) {
3190 MSG_DEBUG("WspLHeaderDecodeParameter:0x11 MemAlloc failed\n");
3193 strncpy((char*)param, "SEC=", WSP_STANDARD_STR_LEN_MAX-1);
3194 SecurityTypeCode = data[1] & 0x7f;
3195 while ((i < wspSecurityTypeCount) && (wspSecurityType[i].SecurityTypeCode != SecurityTypeCode)) i++;
3197 if (i < wspSecurityTypeCount) {
3198 strncat((char*)param, (char*)wspSecurityType[i].SecurityTypeName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3201 if (0x12 == (data[2] & 0x7f)) {
3202 strncat((char*)param, "; MAC=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3203 memcpy(param+AcStrlen((char*)param), (char*)(data+3), (size_t)length-3);
3218 void SmsPluginWapPushHandler::wspHeaderDecodeCharset(unsigned long length, unsigned char* data, char**pDecodedString)
3222 param = new char[WSP_STANDARD_STR_LEN_MAX];
3224 if (param == NULL) {
3225 MSG_DEBUG("WspLHeaderDecodeCharset:MemAlloc failed\n");
3226 *pDecodedString = NULL;
3230 strncpy((char*)param, "charset=", WSP_STANDARD_STR_LEN_MAX-1);
3232 if (data[0] > 0x80) {
3233 unsigned long code = wspHeaderDecodeInteger(data);
3234 unsigned long i = 0;
3235 while (wspCharset[i].charsetCode != code) {
3236 if (wspCharset[i].charsetCode == 0xffff) {
3237 *pDecodedString = param;
3242 strncat((char*)param, (char*)wspCharset[i].charsetName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3244 unsigned long lastLen = AcStrlen((char*)param);
3245 if (length + lastLen < WSP_STANDARD_STR_LEN_MAX - 1) {
3246 memcpy((char*)(param + lastLen), data, (size_t)length);
3247 param[length + lastLen] = '\0';
3249 memcpy((char*)(param + lastLen), data, WSP_STANDARD_STR_LEN_MAX - lastLen - 1);
3250 param[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3254 *pDecodedString = param;
3260 void SmsPluginWapPushHandler::wspHeaderDecodeVersion(unsigned long length, unsigned char* data, char** pDecodedString)
3262 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3264 if (*pDecodedString == NULL) {
3265 MSG_DEBUG("WspLHeaderDecodeVersion:MemAlloc failed\n");
3270 /* untyped version */
3271 memcpy(*pDecodedString, data, (size_t)length);
3274 unsigned char majorVer = ((data[0] & 0x7f) >> 4);
3275 unsigned char minorVer = data[0] & 0x0f;
3276 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "level=%u.%u", majorVer, minorVer);
3283 void SmsPluginWapPushHandler::wspHeaderDecodeDateValue(unsigned long length, unsigned char* data, char** pDecodedString)
3288 MSG_DEBUG("WspLHeaderDecodeDateValue: \n");
3290 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3292 if (*pDecodedString == NULL) {
3293 MSG_DEBUG("WspLHeaderDecodeDateValue:MemAlloc failed\n");
3297 lTime = wspHeaderDecodeIntegerByLength(data, length);
3299 (struct tm*)gmtime_r((const time_t*)&lTime, &pTMData);
3301 /* check date value validity */
3302 if ((pTMData.tm_wday > 6) || (pTMData.tm_mon > 11) || (pTMData.tm_mday > 31)) {
3303 MSG_DEBUG("WspLHeaderDecodeDateValue: Date decode fail %d, %d, %d \n", pTMData.tm_wday, pTMData.tm_mon, pTMData.tm_mday);
3304 strncpy((char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
3308 #ifdef MSG_FW_FOR_DEBUG
3309 /** Date type selection */
3310 switch (wspMachineStatus.dateType) {
3311 /* UNIX asciitime function */
3312 case UNIX_DATE_TYPE:
3313 snprintf((char*)decodedString, sizeof(decodedString), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData.tm_wday], wspMonth[pTMData.tm_mon],
3314 pTMData.tm_mday, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec, pTMData.tm_year + 1900);
3316 case RFC1123_DATE_TYPE:
3317 snprintf((char*)decodedString, sizeof(decodedString), "%s, %u %s %u %u:%u:%u GMT", wspWeek[pTMData.tm_wday], pTMData.tm_mday,
3318 wspMonth[pTMData.tm_mon], pTMData.tm_year + 1900, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec);
3320 case RFC850_DATE_TYPE:
3321 /* Have some Y2K Problems */
3322 /* In RFC 850, date is represented like 11-May-99. So Y2K problem always can be occured. So remainer (year divided by 100) is used. */
3323 snprintf((char*)decodedString, sizeof(decodedString), "%s, %2u-%s-%2u %u:%u:%u GMT", wspWeekDay[pTMData.tm_wday], pTMData.tm_mday,
3324 wspMonth[pTMData.tm_mon], pTMData.tm_year % CENTURY, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec);
3329 /**UNIX_DATE_TYPE : */
3330 snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData.tm_wday], wspMonth[pTMData.tm_mon],
3331 pTMData.tm_mday, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec, pTMData.tm_year + 1900);
3336 void SmsPluginWapPushHandler::wspHeaderCopyDecodedString(unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper)
3338 unsigned long elementLen = AcStrlen((char*)szDecodedString);
3339 char* temper2 = NULL;
3342 *currentLen = *currentLen + elementLen + 2;
3344 if (*currentLen > AcStrlen((char*)* pTemper) + 2) {
3345 temper2 = new char[(*currentLen + 1)];
3347 if (temper2 == NULL) {
3348 MSG_DEBUG("WspLHeaderCopyDecodedString:MemAlloc failed\n");
3351 strncpy((char*)temper2, (char*)* pTemper, *currentLen);
3353 strncpy((char*)temper2, (char*)szDecodedString, *currentLen);
3362 void SmsPluginWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3364 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3365 unsigned char passWd[WSP_STANDARD_STR_LEN_MAX];
3366 unsigned long iField = 0;
3369 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX * 2];
3371 if (*pDecodedString == NULL) {
3372 MSG_DEBUG("WspLHeaderDecodeAuth:MemAlloc failed\n");
3376 /* skip 'basic' code */
3378 memset(authStr, 0x00, sizeof(authStr));
3379 snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
3380 sscanf((char*)(fieldValue + iField), authStr, userId);
3381 iField = iField + AcStrlen((char*)userId) + 1;
3382 memset(authStr, 0x00, sizeof(authStr));
3383 snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(passWd));
3384 sscanf((char*)(fieldValue + iField), authStr, passWd);
3385 iField = iField + AcStrlen((char*)userId) + 1;
3386 snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX*2), "basic %s/%s", userId, passWd);
3392 void SmsPluginWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3394 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3395 unsigned long iField = 0;
3398 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3400 if (*pDecodedString == NULL) {
3401 MSG_DEBUG("WspLHeaderDecodeChallenge:MemAlloc failed\n");
3405 /* skip 'basic' code */
3407 memset(authStr, 0x00, sizeof(authStr));
3408 snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
3409 sscanf((char*)(fieldValue + iField), authStr, userId);
3410 iField = iField + AcStrlen((char*)userId) + 1;
3412 snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "basic realm=\"%s\"", userId);
3418 void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString)
3420 unsigned char paramString[WSP_STANDARD_STR_LEN_MAX];
3421 unsigned char cacheCode;
3423 *pCacheString = new char[WSP_STANDARD_STR_LEN_MAX];
3424 if (*pCacheString == NULL) {
3425 MSG_DEBUG("WspLHeaderDecodeCacheControl:MemAlloc failed\n");
3429 if (1 == fieldValueLen) {
3430 /* only one directive */
3431 if (fieldValue[0] > 0x8b) {
3432 return; /* It's error detection. can be omitted. */
3434 strncpy((char*)*pCacheString, (char*)wspCacheControl[fieldValue[0] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3438 if (fieldValue[0] > 0x7f) {
3439 /* directive that has parameter */
3440 cacheCode = fieldValue[0] & 0x7f;
3441 switch (cacheCode) {
3447 if (fieldValue[1] > 0x7f) {
3448 /* well known field name */
3449 strncpy((char*)paramString, (char*)wspHeaderFieldName[fieldValue[1] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3450 paramString[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3452 /* unknown field name */
3453 strncpy((char*)paramString, (char*)fieldValue + 1 , WSP_STANDARD_STR_LEN_MAX-1);
3463 snprintf((char*)paramString, sizeof(paramString), "%u", (unsigned int)wspHeaderDecodeInteger(fieldValue + 1));
3469 snprintf((char*)*pCacheString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString);
3471 /* cache extentions */
3472 /* In case of come directive of doesn't specified string style */
3474 unsigned long stringLen;
3476 strncpy((char*)*pCacheString, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX-1);
3477 stringLen = AcStrlen((char*)*pCacheString);
3479 if (stringLen + 1 < fieldValueLen) {
3480 if (fieldValue[stringLen+ 1] > 0x7f) {
3481 int untyped = (int)wspHeaderDecodeIntegerByLength(fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1));
3483 snprintf(szString, sizeof(szString), "%d", untyped);
3484 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3485 strncat((char*)*pCacheString, (char*)szString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3487 if (fieldValue[fieldValueLen] == 0) {
3488 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3489 strncat((char*)*pCacheString, (char*)fieldValue + stringLen + 1 , WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3498 void SmsPluginWapPushHandler::getDisplayName(MSG_SUB_TYPE_T subType, char* displayName)
3500 if (subType == MSG_WAP_SL_SMS || subType == MSG_WAP_SI_SMS)
3501 snprintf(displayName, MAX_ADDRESS_VAL_LEN + 1, "Push message");