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.
20 #include <drm_client.h>
24 #include "MsgCppTypes.h"
25 #include "MsgGconfWrapper.h"
26 #include "MsgException.h"
27 #include "MsgUtilFile.h"
28 #include "Sms3gppTransport.h"
29 #include "Sms3gppEventHandler.h"
30 #include "Sms3gppWapPushHandler.h"
31 #include "SmsPluginStorage.h"
34 static unsigned short wapPushPortList[] = { 0x0b84, 0x0b85, 0x23F0, 0x23F1, 0x23F2, 0x23F3, 0xC34F };
36 static char gWapCodeBufferLeft[WSP_CODE_BUFFER_LEFT_LEN_MAX];
37 static char gWapCodeBufferRight[WSP_CODE_BUFFER_RIGHT_LEN_MAX];
39 static const unsigned long wspUintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00200000, 0x10000000};
41 static const unsigned char wspHeaderFieldCount = 0x43;
42 static const unsigned char wspContentsTypeCount = 0x34;
43 static const unsigned long wspLanguageCount = 0x11a;
44 static const unsigned char wspSecurityTypeCount = 0x04;
47 static const SMS_3GPP_WSP_CONTENTS_TYPE_S wspExtendedContentsType[] = {
48 { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
49 { (char*)"application/vnd.wap.connectivity-wbxml", 0x36 },
50 { (char*)"application/pkcs7-mime", 0x37 },
51 { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
52 { (char*)"application/vnd.wap.signed-certificate", 0x39 },
53 { (char*)"application/vnd.wap.cert-response", 0x3A },
54 { (char*)"application/xhtml+xml", 0x3B },
55 { (char*)"application/wml+xml", 0x3C },
56 { (char*)"text/css", 0x3D },
58 { (char*)"application/vnd.wap.mms-message", 0x3E },
60 { (char*)"application/vnd.wap.rollover-certificate", 0x3F },
61 { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
62 { (char*)"application/vnd.wap.loc+xml", 0x41 },
63 { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
64 { (char*)"application/vnd.syncml.dm+xml", 0x43 },
65 { (char*)"application/vnd.syncml.notification", 0x44 },
66 { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
67 { (char*)"application/vnd.wv.csp.cir", 0x46 },
69 { (char*)"application/vnd.oma.dd+xml", 0x47},
70 { (char*)"application/vnd.oma.drm.message", 0x48 },
71 { (char*)"application/vnd.oma.drm.content", 0x49 },
72 { (char*)"application/vnd.oma.drm.rights+xml", 0x4A },
73 { (char*)"application/vnd.oma.drm.rights+wbxml", 0x4B },
74 { (char*)"application/vnd.syncml.ds.notification", 0x4E},
75 { (char*)"application/mikey", 0x52},
80 static const char* wspHeaderFieldName[] = {
81 (char*)"Accept", /* 0x00 */
82 (char*)"Accept-Charset",
83 (char*)"Accept-Encoding",
84 (char*)"Accept-Language",
85 (char*)"Accept-Ranges",
86 (char*)"Age", /* 0x05 */
88 (char*)"Authorization",
89 (char*)"Cache-Control",
91 (char*)"Content-Base", /* 0x0a */
92 (char*)"Content-Encoding",
93 (char*)"Content-Language",
94 (char*)"Content-Length",
95 (char*)"Content-Location",
97 (char*)"Content-Range", /* 0x10 */
98 (char*)"Content-Type",
102 (char*)"From", /* 0x15 */
104 (char*)"If-Modified-Since",
106 (char*)"If-None-Match",
107 (char*)"If-Range", /* 0x1a */
108 (char*)"If-Unmodified-Since",
110 (char*)"Last-Modified",
111 (char*)"Max-Forwards",
113 (char*)"Proxy-Authenticate", /* 0x20 */
114 (char*)"Proxy-Authorization",
118 (char*)"Retry-After", /* 0x25 */
120 (char*)"Transfer-Encodig",
123 (char*)"Vary", /* 0x2a */
126 (char*)"Www-Authenticate",
127 (char*)"Content-Disposition",
128 (char*)"X-Wap-Application-Id",
129 (char*)"X-Wap-Content-URI", /* 0x30 */
130 (char*)"X-Wap-Iinitiator-URI",
131 (char*)"Accept-Application", /* Back */
132 (char*)"Bearer-Indication",
134 (char*)"Profile", /* 0x35 */
135 (char*)"Profile-Diff",
136 (char*)"Profile-Warning", /* end of WAP 1.2 */
139 (char*)"Trailer", /* 0x3a */
140 (char*)"Accept-Charset", /* Back */
141 (char*)"Accept-Encoding", /* Back */
142 (char*)"Cache-Control", /* back */
143 (char*)"Content-Range",
145 (char*)"Content-ID", /* 0x40 */
148 (char*)"Encoding-Version"
152 static const SMS_3GPP_WSP_CHARSET_S wspCharset[] = {
153 { (char*)"big5", 0x07ea },
154 { (char*)"iso-10646-ucs-2", 0x03e8 },
155 { (char*)"iso-8859-1", 0x04 },
156 { (char*)"iso-8859-2", 0x05 },
157 { (char*)"iso-8859-3", 0x06 },
158 { (char*)"iso-8859-4", 0x07 },
159 { (char*)"iso-8859-5", 0x08 },
160 { (char*)"iso-8859-6", 0x09 },
161 { (char*)"iso-8859-7", 0x0a },
162 { (char*)"iso-8859-8", 0x0b },
163 { (char*)"iso-8859-9", 0x0c },
164 { (char*)"shift-JIS", 0x11 },
165 { (char*)"us-ascii", 0x03 },
166 { (char*)"utf-8", 0x6a },
167 { (char*)"none", 0x26 },
168 { (char*)"", 0xffff }
172 static const char* wspEncodeMethod[] = {
179 static const SMS_3GPP_WSP_CONTENTS_TYPE_S wspContentsType[] = {
180 { (char*)"*/*", 0x00 },
181 { (char*)"text/*", 0x01 },
182 { (char*)"text/html", 0x02 },
183 { (char*)"text/plain", 0x03 },
184 { (char*)"text/x-hdml", 0x04 },
185 { (char*)"text/x-ttml", 0x05 },
186 { (char*)"text/x-vCalendar", 0x06 },
187 { (char*)"text/x-vCard", 0x07 },
188 { (char*)"text/vnd.wap.wml", 0x08 },
189 { (char*)"text/vnd.wap.wmlscript", 0x09 },
190 { (char*)"text/vnd.wap.wta-event", 0x0a },
191 { (char*)"multipart/*", 0x0b },
192 { (char*)"multipart/mixed", 0x0c },
193 { (char*)"multipart/form-data", 0x0d },
194 { (char*)"multipart/byteranges", 0x0e },
195 { (char*)"multipart/alternative", 0x0f },
196 { (char*)"application/*", 0x10 },
197 { (char*)"application/java-vm", 0x11 },
198 { (char*)"application/x-www-form-urlencoded", 0x12 },
199 { (char*)"application/x-hdmlc", 0x13 },
200 { (char*)"application/vnd.wap.wmlc", 0x14 },
201 { (char*)"application/vnd.wap.wmlscriptc", 0x15 },
202 { (char*)"application/vnd.wap.wta-eventc", 0x16 },
203 { (char*)"application/vnd.wap.uaprof", 0x17 },
204 { (char*)"application/vnd.wap.wtls-ca-certificate", 0x18 },
205 { (char*)"application/vnd.wap.wtls-user-certificate", 0x19 },
206 { (char*)"application/x-x509-ca-cert", 0x1a },
207 { (char*)"application/x-x509-user-cert", 0x1b },
208 { (char*)"image/*", 0x1c },
209 { (char*)"image/gif", 0x1d },
210 { (char*)"image/jpeg", 0x1e },
211 { (char*)"image/tiff", 0x1f },
212 { (char*)"image/png", 0x20 },
213 { (char*)"image/vnd.wap.wbmp", 0x21 },
214 { (char*)"application/vnd.wap.multipart.*", 0x22 },
215 { (char*)"application/vnd.wap.multipart.mixed", 0x23 },
216 { (char*)"application/vnd.wap.multipart.form-data", 0x24 },
217 { (char*)"application/vnd.wap.multipart.byteranges", 0x25 },
218 { (char*)"application/vnd.wap.multipart.alternative", 0x26 },
219 { (char*)"application/xml", 0x27 },
220 { (char*)"text/xml", 0x28 },
221 { (char*)"application/vnd.wap.wbxml", 0x29 },
222 { (char*)"application/x-x968-cross-cert", 0x2a },
223 { (char*)"application/x-x968-ca-cert", 0x2b },
224 { (char*)"application/x-x968-user-cert", 0x2c },
225 { (char*)"text/vnd.wap.si", 0x2d },
226 { (char*)"application/vnd.wap.sic", 0x2e },
227 { (char*)"text/vnd.wap.sl", 0x2f },
228 { (char*)"application/vnd.wap.slc", 0x30 },
229 { (char*)"text/vnd.wap.co", 0x31 },
230 { (char*)"application/vnd.wap.coc", 0x32 },
231 { (char*)"application/vnd.wap.multipart.related", 0x33 },
232 { (char*)"application/vnd.wap.sia", 0x34 },
234 { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
235 { (char*)"application/vnd.connectivity-wbxml", 0x36 },
236 { (char*)"application/pkcs7-mime", 0x37 },
237 { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
238 { (char*)"application/vnd.wap.signed-certificate", 0x39 },
239 { (char*)"application/vnd.wap.cert-response", 0x3A },
240 { (char*)"application/xhtml+xml", 0x3B },
241 { (char*)"application/wml+xml", 0x3C },
242 { (char*)"text/css", 0x3D },
244 { (char*)"application/vnd.wap.mms-message", 0x3E },
246 { (char*)"application/vnd.wap.rollover-certificate", 0x3F },
247 { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
248 { (char*)"application/vnd.wap.loc+xml", 0x41 },
249 { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
250 { (char*)"application/vnd.syncml.dm+xml", 0x43 },
251 { (char*)"application/vnd.syncml.notification", 0x44 },
252 { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
253 { (char*)"application/vnd.wv.csp.cir", 0x46 }
257 static const SMS_3GPP_WAP_UNREGISTER_CONTENTS_TYPE_S wspUnregisterContentsType[]= {
258 { (char*)"application/vnd.wap.emn+wbxml", 0x30A},
259 { (char*)"application/vnd.omaloc-supl-init", 0x312},
260 { (char*)"application/vnd.oma.drm.roap-trigger+wbxml", 0x316}
264 static const unsigned long wspUnregisteredContentsTypeCount = sizeof(wspUnregisterContentsType)/sizeof(SMS_3GPP_WAP_UNREGISTER_CONTENTS_TYPE_S);
267 static const SMS_3GPP_WSP_LANGUAGE_S wspLanguage[] = {
268 { (char*)"English", 0x19 },
269 { (char*)"en", 0x19 },
270 { (char*)"Korean", 0x3d },
271 { (char*)"*", 0x00 },
272 { (char*)"Afar", 0x01 },
273 { (char*)"aa", 0x01 },
274 { (char*)"Abkhazian", 0x02 },
275 { (char*)"ab", 0x02 },
276 { (char*)"Afrikaans", 0x03 },
277 { (char*)"af", 0x03 },
278 { (char*)"Amharic", 0x04 },
279 { (char*)"am", 0x04 },
280 { (char*)"Arabic", 0x05 },
281 { (char*)"ar", 0x05 },
282 { (char*)"Assamese", 0x06 },
283 { (char*)"as", 0x06 },
284 { (char*)"Aymara", 0x07 },
285 { (char*)"ay", 0x07 },
286 { (char*)"Azerbaijani", 0x08 },
287 { (char*)"az", 0x08 },
288 { (char*)"Bashkir", 0x09 },
289 { (char*)"ba", 0x09 },
290 { (char*)"Byelorussian", 0x0a },
291 { (char*)"be", 0x0a },
292 { (char*)"Bulgarian", 0x0b },
293 { (char*)"bg", 0x0b },
294 { (char*)"Bihari", 0x0c },
295 { (char*)"bh", 0x0c },
296 { (char*)"Bislama", 0x0d },
297 { (char*)"bi", 0x0f },
298 { (char*)"Bengali", 0x0e },
299 { (char*)"Bangla", 0x0e },
300 { (char*)"bn", 0x0e },
301 { (char*)"Tibetan", 0x0f },
302 { (char*)"bo", 0x0f },
303 { (char*)"Breton", 0x10 },
304 { (char*)"br", 0x10 },
305 { (char*)"Catalan", 0x11 },
306 { (char*)"ca", 0x11 },
307 { (char*)"Corsican", 0x12 },
308 { (char*)"co", 0x12 },
309 { (char*)"Czech", 0x13 },
310 { (char*)"cs", 0x13 },
311 { (char*)"Welsh", 0x14 },
312 { (char*)"cy", 0x14 },
313 { (char*)"Denish", 0x15 },
314 { (char*)"da", 0x15 },
315 { (char*)"German", 0x16 },
316 { (char*)"de", 0x16 },
317 { (char*)"Bhutani", 0x17 },
318 { (char*)"dz", 0x17 },
319 { (char*)"Greek", 0x18 },
320 { (char*)"el", 0x18 },
321 { (char*)"Esperanto", 0x81 },
322 { (char*)"eo", 0x1a },
323 { (char*)"Spanish", 0x1b },
324 { (char*)"es", 0x1b },
325 { (char*)"Estonian", 0x1c },
326 { (char*)"et", 0x1c },
327 { (char*)"Basque", 0x1d },
328 { (char*)"eu", 0x1d },
329 { (char*)"Persian", 0x1e },
330 { (char*)"fa", 0x1e },
331 { (char*)"Finnish", 0x1f },
332 { (char*)"fi", 0x1f },
333 { (char*)"Fiji", 0x20 },
334 { (char*)"fj", 0x20 },
335 { (char*)"Faeroese", 0x82 },
336 { (char*)"fo", 0x82 },
337 { (char*)"French", 0x22 },
338 { (char*)"fr", 0x22 },
339 { (char*)"Frisian", 0x83 },
340 { (char*)"fy", 0x83 },
341 { (char*)"Irish", 0x24 },
342 { (char*)"ga", 0x24 },
343 { (char*)"Scots Gaelic", 0x25 },
344 { (char*)"gd", 0x25 },
345 { (char*)"Galician", 0x26 },
346 { (char*)"gl", 0x26 },
347 { (char*)"Guarani", 0x27 },
348 { (char*)"gn", 0x27 },
349 { (char*)"Gujarati", 0x28 },
350 { (char*)"gu", 0x28 },
351 { (char*)"Hausa", 0x29 },
352 { (char*)"ha", 0x29 },
353 { (char*)"Hebrew", 0x2a },
354 { (char*)"he", 0x2a },
355 { (char*)"Hindi", 0x2b },
356 { (char*)"hi", 0x2b },
357 { (char*)"Croatian", 0x2c },
358 { (char*)"hr", 0x2c },
359 { (char*)"Hungarian", 0x2d },
360 { (char*)"hu", 0x2d },
361 { (char*)"Armenian", 0x2e },
362 { (char*)"hy", 0x2e },
363 { (char*)"Interlingua", 0x84 },
364 { (char*)"ia", 0x84 },
365 { (char*)"Indonesian", 0x30 },
366 { (char*)"id", 0x30 },
367 { (char*)"Interlingue", 0x86 },
368 { (char*)"ie", 0x86 },
369 { (char*)"Maori", 0x47 },
370 { (char*)"mi", 0x47 },
371 { (char*)"Macedonian", 0x48 },
372 { (char*)"mk", 0x48 },
373 { (char*)"Malayalam", 0x49 },
374 { (char*)"ml", 0x49 },
375 { (char*)"Mongolian", 0x4a },
376 { (char*)"mn", 0x4a },
377 { (char*)"Moldavian", 0x4b },
378 { (char*)"mo", 0x4d },
379 { (char*)"Marathi", 0x4c },
380 { (char*)"mr", 0x4c },
381 { (char*)"Malay", 0x4d },
382 { (char*)"ms", 0x4d },
383 { (char*)"Maltese", 0x4e },
384 { (char*)"mt", 0x4e },
385 { (char*)"Burmese", 0x4f },
386 { (char*)"my", 0x4f },
387 { (char*)"Nauru", 0x50 },
388 { (char*)"na", 0x50 },
389 { (char*)"Nepali", 0x51 },
390 { (char*)"ne", 0x51 },
391 { (char*)"Dutch", 0x52 },
392 { (char*)"nl", 0x52 },
393 { (char*)"Norwegian", 0x53 },
394 { (char*)"no", 0x53 },
395 { (char*)"Occitan", 0x54 },
396 { (char*)"oc", 0x54 },
397 { (char*)"(Afan) Oromo", 0x55 },
398 { (char*)"(Afan)Oromo", 0x55 },
399 { (char*)"om", 0x55 },
400 { (char*)"Oriya", 0x56 },
401 { (char*)"or", 0x56 },
402 { (char*)"Punjabi", 0x57 },
403 { (char*)"pa", 0x57 },
404 { (char*)"Polish", 0x58 },
405 { (char*)"po", 0x58 },
406 { (char*)"Pashto", 0x59 },
407 { (char*)"Pushto", 0x59 },
408 { (char*)"ps", 0x59 },
409 { (char*)"Portugurse", 0x5a },
410 { (char*)"pt", 0x5a },
411 { (char*)"Quechua", 0x5b },
412 { (char*)"qu", 0x5b },
413 { (char*)"Rhaeto-Romance", 0x8c },
414 { (char*)"rm", 0x8c },
415 { (char*)"Kirundi", 0x5d },
416 { (char*)"rn", 0x5d },
417 { (char*)"Romanian", 0x5e },
418 { (char*)"ro", 0x5e },
419 { (char*)"Russian", 0x5f },
420 { (char*)"ru", 0x5f },
421 { (char*)"Kinyarwanda", 0x60 },
422 { (char*)"rw", 0x60 },
423 { (char*)"Sanskrit", 0x61 },
424 { (char*)"sa", 0x61 },
425 { (char*)"Sindhi", 0x62 },
426 { (char*)"sd", 0x62 },
427 { (char*)"Sangho", 0x63 },
428 { (char*)"sg", 0x63 },
429 { (char*)"Serbo-Croatian", 0x64 },
430 { (char*)"sh", 0x64 },
431 { (char*)"Sinhalese", 0x65 },
432 { (char*)"si", 0x65 },
433 { (char*)"Slovak", 0x66 },
434 { (char*)"sk", 0x66 },
435 { (char*)"Slovenian", 0x67 },
436 { (char*)"sl", 0x67 },
437 { (char*)"Samoan", 0x68 },
438 { (char*)"sm", 0x68 },
439 { (char*)"Shona", 0x69 },
440 { (char*)"sn", 0x69 },
441 { (char*)"Somali", 0x6a },
442 { (char*)"so", 0x6a },
443 { (char*)"Albanian", 0x6b },
444 { (char*)"sq", 0x6b },
445 { (char*)"Serbian", 0x6c },
446 { (char*)"sr", 0x6c },
447 { (char*)"Siswati", 0x6d },
448 { (char*)"ss", 0x6d },
449 { (char*)"Sesotho", 0x6e },
450 { (char*)"st", 0x6e },
451 { (char*)"Sundanese", 0x6f },
452 { (char*)"su", 0x6f },
453 { (char*)"Swedish", 0x70 },
454 { (char*)"sv", 0x70 },
455 { (char*)"Swahili", 0x71 },
456 { (char*)"sw", 0x71 },
457 { (char*)"Tamil", 0x72 },
458 { (char*)"ta", 0x72 },
459 { (char*)"Telugu", 0x73 },
460 { (char*)"te", 0x73 },
461 { (char*)"Tajik", 0x74 },
462 { (char*)"tg", 0x74 },
463 { (char*)"Thai", 0x75 },
464 { (char*)"th", 0x75 },
465 { (char*)"Tigrinya", 0x76 },
466 { (char*)"ti", 0x76 },
467 { (char*)"Turkmen", 0x77 },
468 { (char*)"tk", 0x77 },
469 { (char*)"Inupiak", 0x87 },
470 { (char*)"ik", 0x87 },
471 { (char*)"Icelandic", 0x33 },
472 { (char*)"is", 0x33 },
473 { (char*)"Italian", 0x34 },
474 { (char*)"it", 0x34 },
475 { (char*)"Inuktitut", 0x89 },
476 { (char*)"iu", 0x89 },
477 { (char*)"Japanese", 0x36 },
478 { (char*)"ja", 0x36 },
479 { (char*)"Javanese", 0x37 },
480 { (char*)"jw", 0x37 },
481 { (char*)"Georgian", 0x38 },
482 { (char*)"ka", 0x38 },
483 { (char*)"Kazakh", 0x39 },
484 { (char*)"kk", 0x39 },
485 { (char*)"Gerrnlandic", 0x8a },
486 { (char*)"kl", 0x8a },
487 { (char*)"Cambodian", 0x3b },
488 { (char*)"km", 0x3b },
489 { (char*)"Kannada", 0x3c },
490 { (char*)"kn", 0x3c },
491 { (char*)"Kashmiri", 0x3e },
492 { (char*)"ks", 0x3e },
493 { (char*)"Kurdish", 0x3f },
494 { (char*)"ku", 0x3f },
495 { (char*)"Kirghiz", 0x40 },
496 { (char*)"ky", 0x40 },
497 { (char*)"Latin", 0x8b },
498 { (char*)"la", 0x8b },
499 { (char*)"Lingala", 0x42 },
500 { (char*)"ln", 0x42 },
501 { (char*)"Laothian", 0x43 },
502 { (char*)"lo", 0x43 },
503 { (char*)"Lithuanian", 0x44 },
504 { (char*)"lt", 0x44 },
505 { (char*)"Lavian", 0x45 },
506 { (char*)"Lettish", 0x45 },
507 { (char*)"lv", 0x45 },
508 { (char*)"Malagasy", 0x46 },
509 { (char*)"mg", 0x46 },
510 { (char*)"Tagalog", 0x78 },
511 { (char*)"tl", 0x78 },
512 { (char*)"Setswana", 0x79 },
513 { (char*)"tn", 0x79 },
514 { (char*)"Tonga", 0x7a },
515 { (char*)"to", 0x7a },
516 { (char*)"Turkish", 0x7b },
517 { (char*)"tr", 0x7b },
518 { (char*)"Tsonga", 0x7c },
519 { (char*)"ts", 0x7c },
520 { (char*)"Tatar", 0x7d },
521 { (char*)"tt", 0x7d },
522 { (char*)"Twi", 0x7e },
523 { (char*)"tw", 0x7e },
524 { (char*)"Uighur", 0x7f },
525 { (char*)"ug", 0x7f },
526 { (char*)"Ukrainian", 0x1a },
527 { (char*)"uk", 0x1a },
528 { (char*)"Urdu", 0x21 },
529 { (char*)"ur", 0x21 },
530 { (char*)"Uzbek", 0x23 },
531 { (char*)"uz", 0x23 },
532 { (char*)"Vietnamese", 0x2f },
533 { (char*)"vi", 0x2f },
534 { (char*)"Volapuk", 0x85 },
535 { (char*)"vo", 0x85 },
536 { (char*)"Wolof", 0x31 },
537 { (char*)"wo" , 0x31 },
538 { (char*)"Xhosa", 0x32 },
539 { (char*)"xh", 0x32 },
540 { (char*)"Yiddish", 0x88 },
541 { (char*)"yi", 0x88 },
542 { (char*)"Yoruba", 0x35 },
543 { (char*)"yo", 0x35 },
544 { (char*)"Zhuang", 0x3a },
545 { (char*)"z", 0x3a },
546 { (char*)"Chinese", 0x41 },
547 { (char*)"ch", 0x41 },
548 { (char*)"Zulu", 0x5c },
549 { (char*)"zu", 0x5c },
550 { (char*)"Ko", 0x3d }
554 static const SMS_3GPP_WSP_HEADER_PARAMETER_S wspHeaderApplId[] = {
555 { (char*)"x-wap-application:*", 0x00 },
556 { (char*)"x-wap-application:push.sia", 0x01},
557 { (char*)"x-wap-application:wml.ua", 0x02 },
558 { (char*)"x-wap-application:wta.ua", 0x03 },
559 { (char*)"x-wap-application:mms.ua", 0x04 },
560 { (char*)"x-wap-application:push.syncml", 0x05 },
561 { (char*)"x-wap-application:loc.ua", 0x06 },
562 { (char*)"x-wap-application:syncml.dm", 0x07 },
563 { (char*)"x-wap-application:drm.ua", 0x08 },
564 { (char*)"x-wap-application:emn.ua", 0x09 },
565 { (char*)"x-oma-application:ulp.ua ", 0x10 },
566 { (char*)"x-oma-docomo:open.ctl", 0x9055 },
567 { (char*)"x-oma-docomo:xmd.mail.ua", 0x905C },
568 { (char*)"x-oma-docomo:xmd.storage.ua", 0x905F },
569 { (char*)"x-oma-docomo:xmd.lcsapp.ua", 0x9060 },
570 { (char*)"x-oma-docomo:xmd.info.ua", 0x9061 },
571 { (char*)"x-oma-docomo:xmd.agent.ua", 0x9062 },
572 { (char*)"x-oma-docomo:xmd.sab.ua", 0x9063 },
573 { (char*)"x-oma-docomo:xmd.am.ua", 0x9064 },
574 { (char*)"x-oma-docomo:xmd.emdm.ua", 0x906B },
575 { (char*)"x-oma-docomo:xmd.lac.ua", 0x906C },
576 { (char*)"x-oma-docomo:xmd.osv.ua", 0x906D },
577 { (char*)"x-oma-docomo:xmd.dcs.ua", 0x906E },
578 { (char*)"x-oma-docomo:xmd.wipe.ua", 0x906F },
579 { (char*)"x-oma-docomo:xmd.vdapp.ua ", 0x9070 },
583 static const char* wspCacheControl[] = {
589 (char*)"Only-if-cached",
592 (char*)"No-transform",
593 (char*)"Must-revalidate",
594 (char*)"Proxy-revalidate"
598 static const SMS_3GPP_WSP_METHOD_TYPE_S wspMethodType[] = {
599 { (char*)"GET", 0x40 },
600 { (char*)"OPTIONS", 0x41 },
601 { (char*)"HEAD", 0x42 },
602 { (char*)"DELETE", 0x43 },
603 { (char*)"TRACE", 0x44 },
604 { (char*)"POST", 0x60 },
605 { (char*)"PUT", 0x61 }
609 static const SMS_3GPP_WSP_SECURITY_TYPE_S wspSecurityType[] = {
610 {(char*)"NETWPIN", 0x00},
611 {(char*)"USERPIN", 0x01},
612 {(char*)"USERNETWPIN", 0x02},
613 {(char*)"USERPINMAC", 0x03}
617 static const char* wspWeek[] = {
628 #ifdef MSG_FW_FOR_DEBUG
629 static const char* wspWeekDay[] = {
641 static const char* wspMonth[] = {
656 /*==================================================================================================
657 IMPLEMENTATION OF Sms3gppWapPushHandler - Member Functions
658 ==================================================================================================*/
659 Sms3gppWapPushHandler* Sms3gppWapPushHandler::pInstance = NULL;
662 Sms3gppWapPushHandler::Sms3gppWapPushHandler()
664 memset(&tmpAddress, 0x00, sizeof(tmpAddress));
665 memset(&tmpTimeStamp, 0x00, sizeof(tmpTimeStamp));
669 Sms3gppWapPushHandler::~Sms3gppWapPushHandler()
674 Sms3gppWapPushHandler* Sms3gppWapPushHandler::instance()
677 pInstance = new Sms3gppWapPushHandler();
683 bool Sms3gppWapPushHandler::IsWapPushMsg(SMS_3GPP_USERDATA_S *pUserData)
687 if (pUserData == NULL) {
688 MSG_DEBUG("pUserData is NULL");
692 int PortCount = sizeof(wapPushPortList) / sizeof(wapPushPortList[0]);
694 MSG_DEBUG("Port Count [%d]", PortCount);
696 for (int i = 0; i < pUserData->headerCnt; i++) {
697 if (pUserData->header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
698 /** Have to check something??? */
699 } else if (pUserData->header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
700 for (int j = 0; j < PortCount; j++) {
701 if (pUserData->header[i].udh.appPort16bit.destPort == wapPushPortList[j]) {
702 MSG_DEBUG("Wap Push Msg : [%04x]", wapPushPortList[j]);
715 SMS_WAP_APP_CODE_T Sms3gppWapPushHandler::getAppCode(const char *pPushHeader)
717 int appCount = sizeof(pushDefaultApplication)/sizeof(pushDefaultApplication[0]) - 1;
719 unsigned char *header = NULL;
720 SMS_WAP_APP_CODE_T appCode = SMS_WAP_APPLICATION_DEFAULT;
722 MSG_DEBUG("Application Count [%d]", appCount);
724 for (int i = 0; i < appCount; i++) {
725 header = (unsigned char*)strcasestr(pPushHeader, pushDefaultApplication[i].pContentType);
727 if (header != NULL) {
728 appCode = pushDefaultApplication[i].appCode;
733 if (appCode == SMS_WAP_APPLICATION_DEFAULT) {
734 MSG_DEBUG("Application Type is not supported");
736 MSG_DEBUG("Find Application [%d]", appCode);
744 void Sms3gppWapPushHandler::copyDeliverData(SMS_3GPP_DELIVER_S *pDeliver)
746 tmpAddress.ton = pDeliver->originAddress.ton;
747 tmpAddress.npi = pDeliver->originAddress.npi;
749 strncpy(tmpAddress.address, pDeliver->originAddress.address, MAX_ADDRESS_LEN);
751 MSG_SEC_DEBUG("Address [%s]", tmpAddress.address);
753 tmpTimeStamp.format = pDeliver->timeStamp.format;
755 if (tmpTimeStamp.format == SMS_3GPP_TIME_ABSOLUTE) {
756 tmpTimeStamp.time.absolute.year = pDeliver->timeStamp.time.absolute.year;
757 tmpTimeStamp.time.absolute.month = pDeliver->timeStamp.time.absolute.month;
758 tmpTimeStamp.time.absolute.day = pDeliver->timeStamp.time.absolute.day;
759 tmpTimeStamp.time.absolute.hour = pDeliver->timeStamp.time.absolute.hour;
760 tmpTimeStamp.time.absolute.minute = pDeliver->timeStamp.time.absolute.minute;
761 tmpTimeStamp.time.absolute.second = pDeliver->timeStamp.time.absolute.second;
762 tmpTimeStamp.time.absolute.timeZone = pDeliver->timeStamp.time.absolute.timeZone;
767 void Sms3gppWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize, int simIndex, time_t sent_time)
771 #ifdef MSG_FW_FOR_DEBUG
772 MSG_DEBUG("DataSize [%d]", DataSize);
774 MSG_DEBUG("[pUserData]");
775 for (int i = 0; i < DataSize; i++) {
776 printf("[%02x]", pUserData[i]);
781 unsigned char* pPDUTypeData = (unsigned char*)pUserData;
782 unsigned long PDUTypeDataLen = DataSize;
784 char* pPushHeader = NULL;
785 unique_ptr<char*, void(*)(char**)> pushHeaderBuf(&pPushHeader, unique_ptr_deleter);
786 unsigned long pushHeaderLen = 0;
788 char* pPushBody = NULL;
789 unique_ptr<char*, void(*)(char**)> PushBodyBuf(&pPushBody, unique_ptr_deleter);
790 unsigned long pushBodyLen = 0;
792 unsigned long iPDU = 1;
794 char* pWspHeader = NULL;
795 unique_ptr<char*, void(*)(char**)> WspHeaderBuf(&pWspHeader, unique_ptr_deleter);
796 unsigned long wspHeaderLen = 0;
798 char* pWspBody = NULL;
799 unique_ptr<char*, void(*)(char**)> WspBodyBuf(&pWspBody, unique_ptr_deleter);
800 unsigned long wspBodyLen = 0;
805 pushHeaderLen = wspRetriveUintvarDecode(pPDUTypeData, &iPDU);
807 MSG_DEBUG("PDUTypeDataLen [%lu]", PDUTypeDataLen);
808 MSG_DEBUG("pushHeaderLen [%lu]", pushHeaderLen);
809 MSG_DEBUG("iPDU [%lu]", iPDU);
811 wspHeaderLen = pushHeaderLen + iPDU;
813 MSG_DEBUG("wspBodyLen [%lu]", wspBodyLen);
815 if (wspHeaderLen > 0) {
816 pWspHeader = new char[wspHeaderLen];
818 if (pWspHeader == NULL) {
819 MSG_DEBUG("pWspHeader Memory Allocation Failed");
822 memcpy(pWspHeader, pPDUTypeData, wspHeaderLen);
826 #ifdef MSG_FW_FOR_DEBUG
827 MSG_DEBUG("wspHeaderLen [%d]", wspHeaderLen);
829 MSG_DEBUG("[pWspHeader]");
830 for (int i = 0; i < wspHeaderLen; i++) {
831 printf("[%02x]", pWspHeader[i]);
836 /* return if it is below case error */
837 if (PDUTypeDataLen < wspHeaderLen) {
838 MSG_DEBUG("PDUTypeDataLen < wspHeaderLen !!!");
842 /* Finding wspBody Information */
843 wspBodyLen = PDUTypeDataLen - wspHeaderLen;
845 if (wspBodyLen > 0) {
846 pWspBody = new char[wspBodyLen];
848 if (pWspBody == NULL) {
849 MSG_DEBUG("pWspBody Memory Allocation Failed");
852 memcpy(pWspBody, pPDUTypeData + wspHeaderLen, wspBodyLen);
858 wspDecodeHeader(pPDUTypeData + iPDU, pushHeaderLen, PDUTypeDataLen - (iPDU + pushHeaderLen), TRUE, &pPushHeader);
860 iPDU = iPDU + pushHeaderLen;
862 pushBodyLen = PDUTypeDataLen - iPDU ;
864 if (pushBodyLen > 0) {
865 pPushBody = new char[pushBodyLen];
867 if (pPushBody == NULL) {
868 MSG_DEBUG("pPushBody Memory Allocation Failed");
871 memcpy(pPushBody, pPDUTypeData+ iPDU, pushBodyLen);
878 handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen, simIndex, sent_time);
884 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
888 if (pPushBody == NULL) {
889 MSG_DEBUG("pPushBody is NULL");
893 SMS_WAP_APP_CODE_T appCode = getAppCode(pPushHeader);
895 /** check Push message receive setting */
896 bool bPushRecv = false;
898 if (MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv) != MSG_SUCCESS)
899 MSG_INFO("MsgSettingGetBool() is failed");
901 if ((bPushRecv == false) && (appCode != SMS_WAP_APPLICATION_MMS_UA)) {
902 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
907 case SMS_WAP_APPLICATION_MMS_UA:
908 MSG_DEBUG("Received MMS Notification");
909 handleMMSNotification(pPushBody, PushBodyLen);
912 case SMS_WAP_APPLICATION_PUSH_SI:
913 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
914 handleSIMessage(pPushBody, PushBodyLen, true);
917 case SMS_WAP_APPLICATION_PUSH_SIC:
918 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
919 handleSIMessage(pPushBody, PushBodyLen, false);
922 case SMS_WAP_APPLICATION_PUSH_SL:
923 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
924 handleSLMessage(pPushBody, PushBodyLen, true);
927 case SMS_WAP_APPLICATION_PUSH_SLC:
928 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
929 handleSLMessage(pPushBody, PushBodyLen, false);
932 case SMS_WAP_APPLICATION_PUSH_CO:
933 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
934 handleCOMessage(pPushBody, PushBodyLen, true);
937 case SMS_WAP_APPLICATION_PUSH_COC:
938 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
939 handleCOMessage(pPushBody, PushBodyLen, false);
942 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
943 MSG_DEBUG("Received DM BOOTSTRAP");
944 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
947 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
948 MSG_DEBUG("Received DM BOOTSTRAP");
949 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
952 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
953 MSG_DEBUG("Received Provisioning");
954 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
957 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
958 MSG_DEBUG("Received Provisioning");
959 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
962 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
963 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
964 MSG_DEBUG("Received Provisioning");
965 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
968 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
969 MSG_DEBUG("Received DM Notification");
970 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
973 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
974 MSG_DEBUG("Received DS Notification");
975 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
978 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
979 MSG_DEBUG("Received DS Notification");
980 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
983 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
984 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
985 MSG_DEBUG("Received DRM UA");
987 if (pPushBody != NULL)
988 handleDrmVer1(pPushBody, PushBodyLen);
992 case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
993 case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
994 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
995 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
996 MSG_DEBUG("Received DRM V2");
1000 case SMS_WAP_APPLICATION_PUSH_EMAIL:
1001 case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
1002 case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
1003 MSG_DEBUG("Received Email");
1007 case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1008 MSG_DEBUG("Received IMPS CIR");
1009 /* TODO: IMPS CIR */
1012 case SMS_WAP_APPLICATION_LBS :
1013 MSG_DEBUG("Received LBS related message");
1014 SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1018 case SMS_WAP_APPLICATION_PUSH_SIA :
1019 MSG_DEBUG("Received SIA");
1024 MSG_DEBUG("Unknown Application [%d]", appCode);
1032 static void launchProcessByAppcode(int appcode)
1035 GError *error = NULL;
1036 GDBusConnection *connection_agent = NULL;
1037 GDBusProxy *dbus_proxy_agent = NULL;
1038 GDBusConnection *connection_service = NULL;
1039 GDBusProxy *dbus_proxy_service = NULL;
1040 GVariant *result_agent = NULL;
1041 GVariant *result_service = NULL;
1044 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1045 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1046 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1047 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1048 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1049 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1050 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION: {
1051 connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1053 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1057 dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
1058 NULL, "org.tizen.omadmagent", "/org/tizen/omadmagent",
1059 "org.tizen.omadmagent", NULL, &error);
1061 MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
1065 result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1067 MSG_DEBUG("invoking agent proxy call failed: %s\n", error->message);
1071 connection_service = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1073 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1077 dbus_proxy_service = g_dbus_proxy_new_sync(connection_service, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
1078 "org.tizen.omadmservice", "/org/tizen/omadmservice",
1079 "org.tizen.omadmservice", NULL, &error);
1081 MSG_DEBUG("Connecting to service proxy failed: %s\n", error->message);
1085 result_service = g_dbus_proxy_call_sync(dbus_proxy_service, "wakeup", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1087 MSG_DEBUG("invoking service proxy call failed: %s\n", error->message);
1094 cv.timedwait(mx.pMsgMutex(), 2);
1099 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1100 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML: {
1101 connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1103 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1107 dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
1108 "org.tizen.omadsagent", "/org/tizen/omadsagent",
1109 "org.tizen.omadsagent", NULL, &error);
1111 MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
1115 result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL,
1116 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1118 MSG_DEBUG("invoking service error: %s\n", error->message);
1129 g_error_free(error);
1133 if (connection_agent) {
1134 g_object_unref(connection_agent);
1135 connection_agent = NULL;
1138 if (dbus_proxy_agent) {
1139 g_object_unref(dbus_proxy_agent);
1140 dbus_proxy_agent = NULL;
1144 g_object_unref(result_service);
1145 result_service = NULL;
1148 if (connection_service) {
1149 g_object_unref(connection_service);
1150 connection_service = NULL;
1153 if (dbus_proxy_service) {
1154 g_object_unref(dbus_proxy_service);
1155 dbus_proxy_service = NULL;
1158 if (result_service) {
1159 g_object_unref(result_service);
1160 result_service = NULL;
1167 void Sms3gppWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen, int simIndex, time_t sent_time)
1171 MSG_ERR_RET_M(pPushHeader == NULL, "pPushHeader is NULL!");
1172 MSG_ERR_RET_M(pPushBody == NULL, "pPushBody is NULL!");
1174 msg_error_t err = MSG_SUCCESS;
1175 int pushEvt_cnt = 0;
1176 char app_id[MAX_WAPPUSH_ID_LEN] = {0, };
1177 char content_type[MAX_WAPPUSH_CONTENT_TYPE_LEN] = {0, };
1178 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
1180 err = storageHandler->getRegisteredPushEvent(pPushHeader, &pushEvt_cnt, app_id, sizeof(app_id), content_type, sizeof(content_type));
1181 MSG_DEBUG("pushEvt_cnt: %d", pushEvt_cnt);
1182 if (err != MSG_SUCCESS) {
1183 MSG_DEBUG("Fail to get registered push event");
1187 for (int i = 0; i < pushEvt_cnt; ++i) {
1188 /* check Push message receive setting */
1189 bool bPushRecv = false;
1191 if (MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv) != MSG_SUCCESS)
1192 MSG_INFO("MsgSettingGetBool() is failed");
1194 storageHandler->getnthPushEvent(i, &appcode);
1195 MSG_DEBUG("pushEvt_cnt: %d, appcode: %d", pushEvt_cnt, appcode);
1196 if ((bPushRecv == false) && (IsWapPushMsgInWhiteList(appcode) == false)) {
1197 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
1201 #ifdef FEATURE_MMS_DISABLE
1202 if (appcode == SMS_WAP_APPLICATION_MMS_UA) {
1203 MSG_DEBUG("Drop MMS Notification for DOCOMO");
1208 launchProcessByAppcode(appcode);
1211 case SMS_WAP_APPLICATION_MMS_UA:
1212 MSG_DEBUG("Received MMS Notification");
1213 handleMMSNotification(pPushBody, PushBodyLen, simIndex, sent_time);
1215 case SMS_WAP_APPLICATION_PUSH_SI:
1216 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
1217 handleSIMessage(pPushBody, PushBodyLen, true, simIndex);
1219 case SMS_WAP_APPLICATION_PUSH_SIC:
1220 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
1221 handleSIMessage(pPushBody, PushBodyLen, false, simIndex);
1223 case SMS_WAP_APPLICATION_PUSH_SL:
1224 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
1225 handleSLMessage(pPushBody, PushBodyLen, true, simIndex);
1227 case SMS_WAP_APPLICATION_PUSH_SLC:
1228 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
1229 handleSLMessage(pPushBody, PushBodyLen, false, simIndex);
1231 case SMS_WAP_APPLICATION_PUSH_CO:
1232 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
1233 handleCOMessage(pPushBody, PushBodyLen, true, simIndex);
1235 case SMS_WAP_APPLICATION_PUSH_COC:
1236 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
1237 handleCOMessage(pPushBody, PushBodyLen, false, simIndex);
1239 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1240 MSG_DEBUG("Received DM BOOTSTRAP");
1241 Sms3gppEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1243 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1244 MSG_DEBUG("Received DM BOOTSTRAP");
1245 Sms3gppEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1247 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1248 MSG_DEBUG("Received Provisioning");
1249 Sms3gppEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1251 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1252 MSG_DEBUG("Received Provisioning");
1253 Sms3gppEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1255 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1256 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1257 MSG_DEBUG("Received Provisioning");
1258 Sms3gppEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1260 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1261 MSG_DEBUG("Received DM Notification");
1262 Sms3gppEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1264 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1265 MSG_DEBUG("Received DS Notification");
1266 Sms3gppEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1268 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1269 MSG_DEBUG("Received DS Notification");
1270 Sms3gppEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1272 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
1273 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
1274 MSG_DEBUG("Received DRM UA");
1275 if (pPushBody != NULL)
1276 handleDrmVer1(pPushBody, PushBodyLen);
1279 case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
1280 case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
1281 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
1282 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
1283 MSG_DEBUG("Received DRM V2");
1286 case SMS_WAP_APPLICATION_PUSH_EMAIL:
1287 case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
1288 case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
1289 MSG_DEBUG("Received Email");
1292 case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1293 MSG_DEBUG("Received IMPS CIR");
1294 /* TODO: IMPS CIR */
1296 case SMS_WAP_APPLICATION_LBS:
1297 MSG_DEBUG("Received LBS related message");
1298 Sms3gppEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1301 case SMS_WAP_APPLICATION_PUSH_SIA:
1302 MSG_DEBUG("Received SIA");
1306 Sms3gppEventHandler::instance()->handlePushMsgIncoming(pPushHeader, pPushBody, PushBodyLen, app_id, content_type);
1310 storageHandler->releasePushEvent();
1316 bool Sms3gppWapPushHandler::IsWapPushMsgInWhiteList(int appCode)
1320 bool isAllowed = false;
1323 case SMS_WAP_APPLICATION_MMS_UA:
1324 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1325 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1326 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1327 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1328 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1329 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1330 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1331 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1332 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1333 MSG_INFO("appcode[%d] is allowed even if push receive option is disabled.", appCode);
1337 MSG_DEBUG("appcode[%d] is not allowed when push receive option is disabled.", appCode);
1345 void Sms3gppWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen, int simIndex, time_t sent_time)
1349 #ifdef MSG_FW_FOR_DEBUG
1350 printf("\n\n[handleMMSNotification] Push Body.\n");
1352 for (int i = 0; i < PushBodyLen; i++) {
1353 printf(" [%02x]", pPushBody[i]);
1358 /* Make MSG_MESSAGE_INFO_S */
1359 MSG_MESSAGE_INFO_S msgInfo;
1360 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1362 msgInfo.addressList = NULL;
1363 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1365 createMsgInfo(&msgInfo);
1367 /* Convert Type values */
1368 msgInfo.msgType.mainType = MSG_MMS_TYPE;
1369 msgInfo.msgType.subType = MSG_NOTIFICATIONIND_MMS;
1370 msgInfo.msgType.classType = MSG_CLASS_NONE;
1371 msgInfo.storageId = MSG_STORAGE_PHONE;
1372 msgInfo.dataSize = PushBodyLen;
1373 msgInfo.sim_idx = simIndex;
1376 msgInfo.displayTime = sent_time;
1378 if (msgInfo.dataSize > MAX_MSG_TEXT_LEN) {
1379 msgInfo.bTextSms = false;
1381 /* Save Message Data into File */
1382 char fileName[MSG_FILENAME_LEN_MAX+1];
1383 memset(fileName, 0x00, sizeof(fileName));
1385 if (MsgCreateFileName(fileName) == false)
1386 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1388 if (MsgWriteIpcFile(fileName, pPushBody, msgInfo.dataSize) == false)
1389 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1391 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1393 msgInfo.bTextSms = true;
1395 memcpy(msgInfo.msgText, pPushBody, msgInfo.dataSize);
1396 msgInfo.msgText[msgInfo.dataSize] = '\0';
1399 msg_error_t err = MSG_SUCCESS;
1401 /* Add MMS Noti Msg into DB */
1402 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1404 if (err == MSG_SUCCESS) {
1406 err = Sms3gppEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1407 if (err != MSG_SUCCESS) {
1408 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1411 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1418 void XmlFree(xmlChar* tmpXml)
1420 if (tmpXml != NULL) {
1426 void Sms3gppWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1430 MSG_PUSH_MESSAGE_S pushMsg = {};
1432 xmlDocPtr xmlDoc = NULL;
1433 xmlNodePtr topNode = NULL;
1434 xmlNodePtr indNode = NULL;
1436 xmlChar* tmpXmlChar = NULL;
1438 if (pPushBody == NULL) {
1439 MSG_DEBUG("pPushBody is NULL");
1443 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1445 if (xmlDoc == NULL) {
1446 MSG_DEBUG("xmlDoc is NULL");
1450 topNode = xmlDocGetRootElement(xmlDoc);
1452 if (topNode == NULL) {
1453 MSG_DEBUG("topNode is NULL");
1458 indNode = topNode->xmlChildrenNode;
1460 while (indNode != NULL) {
1461 if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
1462 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1466 indNode = indNode->next;
1469 if (indNode == NULL) {
1470 MSG_DEBUG("indNode is NULL.");
1474 /** temporary set to max. */
1475 pushMsg.expires = 0xFFFFFFFF;
1477 /** setting received time */
1478 time_t t = time(NULL);
1479 time_t utfTime = time(&t);
1481 pushMsg.received = (unsigned long)utfTime;
1483 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1485 if (tmpXmlChar == NULL) {
1486 MSG_DEBUG("href is NULL.");
1490 if (tmpXmlChar != NULL)
1491 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1493 XmlFree(tmpXmlChar);
1495 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
1497 if (tmpXmlChar != NULL)
1498 strncpy(pushMsg.id, (char*)tmpXmlChar, MAX_WAPPUSH_ID_LEN-1);
1500 XmlFree(tmpXmlChar);
1502 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CREATED_TAG);
1504 if (tmpXmlChar != NULL)
1505 pushMsg.created = convertXmlCharToSec((char*)tmpXmlChar);
1507 if (pushMsg.created == 0)
1508 pushMsg.created = pushMsg.received;
1510 XmlFree(tmpXmlChar);
1512 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_EXPIRES_TAG);
1514 if (tmpXmlChar != NULL)
1515 pushMsg.expires = convertXmlCharToSec((char*)tmpXmlChar);
1517 XmlFree(tmpXmlChar);
1519 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1521 pushMsg.action = convertSIActionStrToEnum((char*)tmpXmlChar);
1523 XmlFree(tmpXmlChar);
1525 tmpXmlChar = xmlNodeListGetString(xmlDoc, indNode->xmlChildrenNode, 1);
1527 if (tmpXmlChar == NULL) {
1528 MSG_DEBUG("contents is NULL.");
1532 strncpy(pushMsg.contents, (char*)tmpXmlChar, MAX_WAPPUSH_CONTENTS_LEN-1);
1534 /** Write push Msg to file */
1535 char fileName[MSG_FILENAME_LEN_MAX+1];
1536 memset(fileName, 0x00, sizeof(fileName));
1538 if (MsgCreateFileName(fileName) == false) {
1540 xmlFree(tmpXmlChar);
1541 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1544 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false) {
1546 xmlFree(tmpXmlChar);
1547 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1550 /* Pack Message Info Structure */
1551 MSG_MESSAGE_INFO_S msgInfo;
1552 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1554 msgInfo.addressList = NULL;
1555 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1557 createMsgInfo(&msgInfo);
1559 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1561 /* Convert Type values */
1562 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1563 msgInfo.msgType.subType = MSG_WAP_SI_SMS;
1564 msgInfo.sim_idx = simIndex;
1566 msgInfo.dataSize = sizeof(pushMsg);
1567 getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
1569 xmlFree(tmpXmlChar);
1571 msg_error_t err = MSG_SUCCESS;
1573 /* Add WAP Push Msg into DB */
1574 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1575 if (err == MSG_SUCCESS) {
1577 err = Sms3gppEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1578 if (err != MSG_SUCCESS)
1579 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1581 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1590 void Sms3gppWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1594 MSG_PUSH_MESSAGE_S pushMsg = {};
1596 xmlDocPtr xmlDoc = NULL;
1597 xmlNodePtr topNode = NULL;
1598 xmlNodePtr indNode = NULL;
1600 xmlChar* tmpXmlChar = NULL;
1602 msg_error_t err = MSG_SUCCESS;
1604 if (pPushBody == NULL) {
1605 MSG_DEBUG("pPushBody is NULL \n");
1609 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1611 if (xmlDoc == NULL) {
1612 MSG_DEBUG("xmlDoc is NULL \n");
1616 topNode = xmlDocGetRootElement(xmlDoc);
1618 if (topNode == NULL) {
1619 MSG_DEBUG("Empty Document.");
1623 MSG_SEC_DEBUG("Not an empty Document and topNode->name = %s \n", topNode->name);
1628 while (indNode != NULL) {
1629 if (!xmlStrcmp(indNode->name, (const xmlChar*)"sl")) {
1630 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1634 indNode = indNode->next;
1637 /* setting received time setting */
1638 time_t t = time(NULL);
1639 time_t utfTime = time(&t);
1641 pushMsg.received = (unsigned long)utfTime;
1643 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1645 if (tmpXmlChar == NULL) {
1646 MSG_DEBUG("href is NULL.");
1650 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1652 XmlFree(tmpXmlChar);
1654 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1655 pushMsg.action = convertSLActionStrToEnum((char*)tmpXmlChar);
1657 /* Setting other parameters in default values */
1658 pushMsg.created = pushMsg.received;
1659 /* temporary set to MAX value. */
1660 pushMsg.expires = 0xFFFFFFFF;
1662 MSG_DEBUG("check pushMsg data");
1663 MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
1664 MSG_DEBUG("pushMsg.received : [%lu]", pushMsg.received);
1665 MSG_DEBUG("pushMsg.created : [%lu]", pushMsg.created);
1666 MSG_DEBUG("pushMsg.expires : [%lu]", pushMsg.expires);
1667 MSG_SEC_DEBUG("pushMsg.id : [%s]", pushMsg.id);
1668 MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
1669 MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
1671 /* Write push Msg to file */
1672 char fileName[MSG_FILENAME_LEN_MAX+1];
1673 memset(fileName, 0x00, sizeof(fileName));
1675 if (MsgCreateFileName(fileName) == false)
1676 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1678 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false)
1679 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1681 /* Pack Message Info Structure */
1682 MSG_MESSAGE_INFO_S msgInfo;
1683 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1685 msgInfo.addressList = NULL;
1686 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1688 createMsgInfo(&msgInfo);
1690 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1692 /* Convert Type values */
1693 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1694 msgInfo.msgType.subType = MSG_WAP_SL_SMS;
1695 msgInfo.sim_idx = simIndex;
1697 /* Update Msg Text */
1698 strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
1700 msgInfo.dataSize = sizeof(pushMsg);
1701 getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
1702 MSG_DEBUG("dataSize : %zu", msgInfo.dataSize);
1704 /** Add WAP Push Msg into DB */
1705 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1706 if (err == MSG_SUCCESS) {
1707 /* Callback to MSG FW */
1708 err = Sms3gppEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1710 if (err != MSG_SUCCESS)
1711 MSG_DEBUG("callbackMsgIncoming is failed, err=[%d]", err);
1713 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1717 xmlFree(tmpXmlChar);
1724 void Sms3gppWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1726 MSG_PUSH_CACHEOP_S cacheOp;
1728 xmlDocPtr xmlDoc = NULL;
1729 xmlNodePtr topNode = NULL;
1730 xmlNodePtr indNode = NULL;
1732 memset(&cacheOp, 0x00, sizeof(cacheOp));
1734 MSG_DEBUG("Enter handleCOMessage");
1736 if (pPushBody == NULL) {
1737 MSG_DEBUG("pPushBody is NULL \n");
1741 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1743 if (xmlDoc == NULL) {
1744 MSG_DEBUG("xmlDoc is NULL \n");
1748 topNode = xmlDocGetRootElement(xmlDoc);
1749 if (topNode == NULL) {
1750 MSG_DEBUG("Warning:Empty Document\n");
1755 indNode = topNode->xmlChildrenNode;
1757 while (indNode != NULL) {
1758 xmlChar* tmpUrl = NULL;
1759 if (!xmlStrcmp(indNode->name, (const xmlChar*)SMS_PUSH_XML_INVAL_OBJ)) {
1760 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1762 tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1764 if (tmpUrl != NULL) {
1765 strncpy(cacheOp.invalObjectUrl[cacheOp.invalObjectCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1767 MSG_DEBUG("%dth invalObjectUrl is <%s>\n", cacheOp.invalObjectCnt, cacheOp.invalObjectUrl[cacheOp.invalObjectCnt-1]);
1769 MSG_DEBUG("NO href value from the xmlDoc\n");
1771 } else if (!xmlStrcmp(indNode->name, (const xmlChar*)SMS_PUSH_XML_INVAL_SVC)) {
1772 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1773 tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1775 if (tmpUrl != NULL) {
1776 strncpy(cacheOp.invalServiceUrl[cacheOp.invalServiceCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1777 MSG_DEBUG("%dth invalServiceUrl is <%s>\n", cacheOp.invalServiceCnt, cacheOp.invalServiceUrl[cacheOp.invalServiceCnt-1]);
1779 MSG_DEBUG("NO href value from the xmlDoc\n");
1786 indNode = indNode->next;
1789 /* Write push Msg to file */
1790 char fileName[MSG_FILENAME_LEN_MAX+1];
1791 memset(fileName, 0x00, sizeof(fileName));
1793 if (MsgCreateFileName(fileName) == false) {
1795 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1798 if (MsgWriteIpcFile(fileName, (char*)(&cacheOp), sizeof(cacheOp)) == false) {
1800 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1803 /* Pack Message Info Structure */
1804 MSG_MESSAGE_INFO_S msgInfo;
1805 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1807 msgInfo.addressList = NULL;
1808 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1810 createMsgInfo(&msgInfo);
1812 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1814 /* Convert Type values */
1815 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1816 msgInfo.msgType.subType = MSG_WAP_CO_SMS;
1817 msgInfo.sim_idx = simIndex;
1819 msgInfo.dataSize = sizeof(cacheOp);
1821 msg_error_t err = MSG_SUCCESS;
1823 /* Add WAP Push Msg into DB */
1824 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1825 if (err == MSG_SUCCESS) {
1827 err = Sms3gppEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1828 if (err != MSG_SUCCESS)
1829 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1831 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1840 void Sms3gppWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
1843 int drmRt = DRM_RETURN_SUCCESS;
1845 unique_ptr<char*, void(*)(char**)> buf(&cid, unique_ptr_deleter);
1847 MSG_DEBUG("Received DRM RIGHTS OBJECT Type WAP Push Message.");
1848 drm_request_type_e request_type = DRM_REQUEST_TYPE_REGISTER_LICENSE;
1849 drm_register_lic_info_s lic_req_info;
1850 drm_register_lic_resp_s lic_resp_info;
1852 bzero(&lic_req_info, sizeof(drm_register_lic_info_s));
1853 bzero(&lic_resp_info, sizeof(drm_register_lic_resp_s));
1854 bzero(lic_req_info.lic_data, sizeof(lic_req_info.lic_data));
1856 memcpy(lic_req_info.lic_data, pPushBody, PushBodyLen);
1858 lic_req_info.lic_version = DRM_OMA_DRMV1_RIGHTS;
1859 lic_req_info.roap_init_src = DRM_ROAP_INIT_FROM_WAPPUSH;
1860 lic_req_info.operation_callback.callback = NULL;
1862 drmRt = drm_process_request(request_type, &lic_req_info, &lic_resp_info);
1863 if (drmRt == DRM_RETURN_SUCCESS) {
1864 MSG_DEBUG("DRM successfully registed to drm-service.");
1866 MSG_DEBUG("Fail to regist DRM to drm-service.");
1873 void Sms3gppWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
1875 /* Convert class Type values */
1876 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
1878 /* set folder id (temporary) */
1879 pMsgInfo->folderId = MSG_INBOX_ID;
1881 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
1882 pMsgInfo->bRead = false;
1883 pMsgInfo->bProtected = false;
1884 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
1885 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
1887 time_t rawtime = time(NULL);
1888 /* Comment below lines to save local UTC time..... (it could be used later.) */
1890 if (tmpTimeStamp.format == SMS_3GPP_TIME_ABSOLUTE) {
1892 MSG_DEBUG("year : %d", tmpTimeStamp.time.absolute.year);
1893 MSG_DEBUG("month : %d", tmpTimeStamp.time.absolute.month);
1894 MSG_DEBUG("day : %d", tmpTimeStamp.time.absolute.day);
1895 MSG_DEBUG("hour : %d", tmpTimeStamp.time.absolute.hour);
1896 MSG_DEBUG("minute : %d", tmpTimeStamp.time.absolute.minute);
1897 MSG_DEBUG("second : %d", tmpTimeStamp.time.absolute.second);
1898 MSG_DEBUG("timezone : %d", tmpTimeStamp.time.absolute.timeZone);
1900 char displayTime[32];
1904 memset(&timeinfo, 0x00, sizeof(tm));
1906 timeinfo.tm_year = (tmpTimeStamp.time.absolute.year + 100);
1907 timeinfo.tm_mon = (tmpTimeStamp.time.absolute.month - 1);
1908 timeinfo.tm_mday = tmpTimeStamp.time.absolute.day;
1909 timeinfo.tm_hour = tmpTimeStamp.time.absolute.hour;
1910 timeinfo.tm_min = tmpTimeStamp.time.absolute.minute;
1911 timeinfo.tm_sec = tmpTimeStamp.time.absolute.second;
1912 timeinfo.tm_isdst = 0;
1914 rawtime = mktime(&timeinfo);
1916 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
1917 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
1918 MSG_DEBUG("timezone [%d]", timezone);
1919 MSG_DEBUG("daylight [%d]", daylight);
1921 memset(displayTime, 0x00, sizeof(displayTime));
1922 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
1923 MSG_DEBUG("displayTime [%s]", displayTime);
1925 rawtime -= (tmpTimeStamp.time.absolute.timeZone * (3600/4));
1927 timeTM = localtime(&rawtime);
1928 memset(displayTime, 0x00, sizeof(displayTime));
1929 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1930 MSG_DEBUG("displayTime [%s]", displayTime);
1932 rawtime -= timezone;
1934 timeTM = localtime(&rawtime);
1935 memset(displayTime, 0x00, sizeof(displayTime));
1936 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1937 MSG_DEBUG("displayTime [%s]", displayTime);
1941 pMsgInfo->displayTime = rawtime;
1943 /* Convert Address values */
1944 pMsgInfo->nAddressCnt = 1;
1946 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
1947 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1949 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
1950 strncpy(pMsgInfo->addressList[0].addressVal, tmpAddress.address, MAX_ADDRESS_VAL_LEN);
1952 pMsgInfo->msgPort.valid = false;
1953 pMsgInfo->msgPort.dstPort = 0;
1954 pMsgInfo->msgPort.srcPort = 0;
1957 void Sms3gppWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText)
1959 if (pPushBody == NULL) {
1960 MSG_DEBUG("pPushBody is NULL");
1965 *pXmlDoc = xmlParseMemory(pPushBody, AcStrlen(pPushBody));
1967 WB_UTINY* xmldata = NULL;
1968 WBXMLConvWBXML2XML *conv = NULL;
1969 WBXMLError ret = WBXML_OK;
1971 ret = wbxml_conv_wbxml2xml_create(&conv);
1972 if (ret != WBXML_OK)
1975 ret = wbxml_conv_wbxml2xml_run(conv, (WB_UTINY*)pPushBody, (WB_ULONG)PushBodyLen, &xmldata, NULL);
1977 wbxml_conv_wbxml2xml_destroy(conv);
1979 if (ret != WBXML_OK ||xmldata == NULL) {
1980 MSG_DEBUG("xmldata is NULL. Error code is [%d].\n", ret);
1984 MSG_DEBUG("xmldata : \n%s\n", xmldata);
1986 *pXmlDoc = xmlParseMemory((char*)xmldata, AcStrlen((char*)xmldata));
1990 unsigned long Sms3gppWapPushHandler::convertXmlCharToSec(char* pDate)
1992 struct tm timeStruct;
1993 time_t nTimeInSec = 0;
1998 memset(tmpBuf, 0x00, sizeof(tmpBuf));
1999 memset(&timeStruct, 0x00, sizeof(struct tm));
2002 if (AcStrlen(pDate) < 20)
2005 MSG_DEBUG("pDate [%s]", pDate);
2008 for (i = 0; i < 4; i++) {
2009 tmpBuf[i] = pDate[index++];
2013 timeStruct.tm_year = (atoi(tmpBuf)-1900);
2016 for (i = 0; i < 2; i++) {
2017 tmpBuf[i] = pDate[index++];
2021 timeStruct.tm_mon = (atoi(tmpBuf) - 1);
2024 for (i = 0; i < 2; i++) {
2025 tmpBuf[i] = pDate[index++];
2029 timeStruct.tm_mday = atoi(tmpBuf);
2032 for (i = 0; i < 2; i++) {
2033 tmpBuf[i] = pDate[index++];
2037 timeStruct.tm_hour = atoi(tmpBuf);
2040 for (i = 0; i < 2; i++) {
2041 tmpBuf[i] = pDate[index++];
2045 timeStruct.tm_min = atoi(tmpBuf);
2048 for (i = 0; i < 2; i++) {
2049 tmpBuf[i] = pDate[index++];
2053 timeStruct.tm_sec = atoi(tmpBuf);
2055 nTimeInSec = mktime(&timeStruct);
2061 msg_push_action_t Sms3gppWapPushHandler::convertSIActionStrToEnum(char* pAction)
2065 if (pAction == NULL) {
2066 MSG_DEBUG("pAction is NULL. Setting to default action type.");
2067 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2070 /* compare with signal-none. */
2071 comp = g_strcmp0("signal-none", pAction);
2073 return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
2075 /* compare with signal-low. */
2076 comp = g_strcmp0("signal-low", pAction);
2078 return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
2080 /* compare with signal-medium. */
2081 comp = g_strcmp0("signal-medium", pAction);
2083 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2085 /* compare with signal-high. */
2086 comp = g_strcmp0("signal-high", pAction);
2088 return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
2090 /* compare with delete. */
2091 comp = g_strcmp0("delete", pAction);
2093 return MSG_PUSH_SI_ACTION_DELETE;
2095 /* signal-medium is default action value. */
2096 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2100 msg_push_action_t Sms3gppWapPushHandler::convertSLActionStrToEnum(char* pAction)
2104 if (pAction == NULL) {
2105 MSG_DEBUG("MSG_DEBUG is NULL. Setting to default action type.\n");
2106 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2109 /* compare pSrcStr with execute-low. */
2110 comp = g_strcmp0("execute-low", pAction);
2112 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2114 /* compare pSrcStr with execute-high. */
2115 comp = g_strcmp0("execute-high", pAction);
2117 return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
2119 /* compare pSrcStr with cache. */
2120 comp = g_strcmp0("cache", pAction);
2122 return MSG_PUSH_SL_ACTION_CACHE;
2124 /* default SL action value is execute-low. */
2125 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2129 unsigned long Sms3gppWapPushHandler::wspRetriveUintvarDecode(unsigned char* sourceData, unsigned long* currentPointer)
2131 unsigned long i = 0;
2132 unsigned long decodedValue;
2134 while (sourceData[*currentPointer + i] >= 0x80)
2137 decodedValue = wspDecodeUintvar(i + 1, sourceData + *currentPointer);
2138 *currentPointer = *currentPointer + i + 1;
2139 MSG_DEBUG("wspRetriveUintvarDecode: decodedValue=%lu .\n", decodedValue);
2140 return decodedValue;
2144 unsigned long Sms3gppWapPushHandler::wspDecodeUintvar(unsigned long length, unsigned char* userVar)
2147 unsigned long decodedUintvar = 0;
2149 for (i = 0 ; i < length; i++) {
2150 decodedUintvar = decodedUintvar + (wspUintvarDecodeTable[i] * (userVar[length-(i+1)] & 0x7f));
2153 return decodedUintvar;
2157 void Sms3gppWapPushHandler::wspDecodeHeader(unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader)
2159 unsigned long iField = 0;
2160 bool continueField = FALSE;
2161 unsigned long currentLength;
2163 char* encodedHeader = NULL;
2164 unique_ptr<char*, void(*)(char**)> encodedHeaderbuf(&encodedHeader, unique_ptr_deleter);
2166 char* outTemper = NULL;
2168 char* temper = NULL;
2169 unique_ptr<char*, void(*)(char**)> temperbuf(&temper, unique_ptr_deleter);
2171 unsigned char track;
2172 unsigned long iEncodedHeader = 0;
2173 unsigned char fieldCode = 0xff;
2175 /* outTemper is Decoded Headers.
2176 temper is Single Decoded Header.
2178 if (NULL == (outTemper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ])) {
2179 MSG_DEBUG("outTemper Memory allocation is failed.\n");
2182 memset(outTemper, 0, (WSP_STANDARD_STR_LEN_MAX * 5));
2183 currentLength = WSP_STANDARD_STR_LEN_MAX;
2185 MSG_DEBUG("wspDecodeHeader: Message header decoding started.\n");
2191 MSG_DEBUG("wspDecodeHeader: RAW data \n");
2192 for (loop = 0 ; loop < (int)encodedHeaderLen; loop++) {
2194 szTempBuf[0] = 0x00;
2195 snprintf(szTempBuf, sizeof(szTempBuf), "%2X ", sEncodedHeader[loop]);
2197 if (AcStrlen(szBuf) + 7 < 64) {
2198 strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2200 strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2201 MSG_DEBUG("[%s]", szBuf);
2203 strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2206 strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2207 MSG_DEBUG("[%s]", szBuf);
2208 MSG_DEBUG("fContentType=%d \n", fContentType);
2209 /* operation for content-type */
2210 /* makes psuedo- content-type fieldcode */
2211 /* 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. */
2214 encodedHeader = new char[ encodedHeaderLen + 1 ];
2215 if (encodedHeader == NULL) {
2216 MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2219 encodedHeader[0] = 0x91;
2220 memcpy(encodedHeader + 1, sEncodedHeader, (size_t)encodedHeaderLen);
2222 encodedHeader = new char[ encodedHeaderLen ];
2223 if (encodedHeader == NULL) {
2224 MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2228 memcpy(encodedHeader, sEncodedHeader, (size_t)encodedHeaderLen);
2231 /* Is it reacehd end of header? */
2232 while (iEncodedHeader < encodedHeaderLen) {
2233 /* Get memory for single header */
2234 if (temper == NULL) {
2235 temper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ];
2237 if (temper == NULL) {
2238 MSG_DEBUG("temper Memory allocation is failed.\n");
2241 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2243 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2246 /* this section presents header code page shifting procedure
2247 This part can be implemented by future request.
2250 track = encodedHeader[iEncodedHeader];
2252 if (track == 0x00) {
2253 MSG_DEBUG("WspLDecodeHeader: fieldcode is 0 \n");
2254 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2257 } else if ((track > 0) && (track < 0x20)) {
2259 } else if ((track < 0x7f) && (track > 0x1f)) { /* In this case, first byte is normal string. So it's considered to unknown header. */
2260 unsigned char* fieldName = (unsigned char*)gWapCodeBufferLeft;
2261 unsigned char* fieldValue = (unsigned char*)gWapCodeBufferRight;
2263 strncpy((char*)fieldName, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_LEFT_LEN_MAX-1);
2264 fieldName[WSP_CODE_BUFFER_LEFT_LEN_MAX-1] = '\0';
2265 iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldName) + 1;
2266 strncpy((char*)fieldValue, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_RIGHT_LEN_MAX-1);
2267 fieldValue[WSP_CODE_BUFFER_RIGHT_LEN_MAX-1] = '\0';
2268 iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldValue) + 1;
2270 strncat((char*)temper, (char*)fieldName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2271 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2272 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2273 /* this means 'don't process anymore.' */
2276 } else if (track > 0x7f) {
2277 /* In case of first byte is field code, else case is error. */
2278 /*if ((track & 0x7f) <= wspHeaderFieldCount) { */
2279 unsigned long fieldValueLen = encodedHeader[iEncodedHeader + 1];
2280 unsigned char fieldValue[1275];
2281 fieldCode = track & 0x7f;
2283 if ((fieldValueLen == 0) || (fieldValueLen == 0x80)) {
2284 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]);
2287 memset(fieldValue, 0, 1275);
2289 /* add field name */
2290 /* 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. */
2291 if (!continueField) {
2292 strncat((char*)temper, (char*)wspHeaderFieldName[fieldCode], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2293 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2294 continueField = FALSE;
2297 /* field value is string */
2298 /* In this case, it just copy field value. */
2299 if ((fieldValueLen > LENGTH_QUOTE) && (fieldValueLen < 0x80)) {
2300 /* string field value should be NULL terminated */
2301 strncat((char*)temper, (char*)(encodedHeader + iEncodedHeader + 1), (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2302 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2304 iEncodedHeader = iEncodedHeader + AcStrlen((char*)encodedHeader + iEncodedHeader + 1) + 2;
2308 /* first field value is length */
2309 /* If first byte of field value is length value, allocate field value by the length.
2310 In field value, data is
2311 1D 03 8F 24 24 - Then 8F 24 24 is field value.
2312 1D 1F 33.... - Then allocate 33H for FieldValue.
2314 1D 'Hi man!' Like 00, if string is come, then process without calculating field value.
2315 1D 8F 24 24 - In this case, original data is wrong.
2316 If accept-charset: ISO-10646-ucs-2;Q=0.7 is
2319 03 - field value length
2320 03 E8 47 - field value
2321 it's decoded by above value.
2323 if (fieldValueLen < 0x20) {
2324 if (fieldValueLen == LENGTH_QUOTE) {
2325 /* field length is encoded in UINTVAR */
2326 unsigned long uintvarLen = 0;
2327 fieldValueLen = wspRetriveUintvarDecode((unsigned char*) encodedHeader + iEncodedHeader + 2, &uintvarLen);
2328 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2 + uintvarLen, (size_t)fieldValueLen);
2329 iEncodedHeader = iEncodedHeader + fieldValueLen + uintvarLen + 2;
2331 if (fieldValueLen == 1) {
2332 /* field value is one byte integer over 0x80 */
2333 /** make it two byte integer */
2334 fieldValue[0] = 0x00;
2335 memcpy(fieldValue + 1, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2337 iEncodedHeader = iEncodedHeader + 1 + 2;
2339 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2340 fieldValue[fieldValueLen] = 0;
2341 iEncodedHeader = iEncodedHeader + fieldValueLen + 2;
2342 if ((fieldValueLen == 0) || (fieldValueLen == 0x80)) {
2343 MSG_DEBUG("%X \n", encodedHeader[iEncodedHeader]);
2349 /* field value is single encoded */
2350 if (fieldValueLen > 0x7f) {
2351 fieldValue[0] = encodedHeader[iEncodedHeader + 1];
2353 iEncodedHeader = iEncodedHeader + 2;
2355 /* processing normal pre-defined field decoding */
2357 MSG_DEBUG("WspLDecodeHeader: FieldCode %X\n", fieldCode);
2358 MSG_DEBUG("WspLDecodeHeader: fieldSize %lu\n", fieldValueLen);
2360 if ((fieldCode > wspHeaderFieldCount) && (fieldCode != 0xff)) {
2361 MSG_DEBUG("WspLDecodeHeader: unknown fieldcode %X \n", track);
2362 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2366 switch (fieldCode) {
2367 /* accept charset */
2368 /* It's normal way of field process. */
2370 unsigned long i = 0;
2373 /* Case of length of charset greater than 1 are two thigins.
2374 1. code length of charset is greater than 1.
2375 2. It include parameter.
2378 if (1 != fieldValueLen) {
2379 code = wspHeaderDecodeInteger(fieldValue);
2380 /* Calculate iField. */
2381 if (fieldValue[0] < 0x80)
2382 iField = fieldValue[0];
2386 while (wspCharset[i].charsetCode != code)
2388 strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2389 /* If parameter exist */
2390 if (iField < fieldValueLen) {
2392 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2393 wspHeaderDecodeQValue(fieldValueLen - iField, fieldValue + iField, ¶m);
2394 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2397 code = fieldValue[0] & 0x7f;
2399 while ((wspCharset[i].charsetCode != code) && (wspCharset[i].charsetCode != 0xffff )) i++;
2400 strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2406 /* Like below routine, Same decoding routine process together. */
2407 /* Accept-encoding */
2409 /* content-encoding */
2413 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2414 if (integerValue > 2) {
2415 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(2).\n");
2418 strncat((char*)temper, (char*)wspEncodeMethod[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2421 /* contents type decoder */
2426 unsigned long contentsTypeCode;
2427 unsigned long i = 0;
2428 /* encoded content type length body */
2429 unsigned long tempLen;
2430 MSG_DEBUG("fieldValueLen: %lu", fieldValueLen);
2432 /* Like HTTP result state 304, it's for processing without Content type. This part doesn't defined. */
2433 if (0 == fieldValueLen) {
2434 strncat((char*)temper, (char*)"None" , (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2437 /* 01 AE --> 00 AE --> AE*/
2438 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2439 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2440 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2443 if ((fieldValue[0] < 0x20) || (fieldValue[0] >= 0x80)) {
2444 if (fieldValue[0] >= 0x80) {
2446 } else if (fieldValueLen == 2 && fieldValue[0] == 0x03 && fieldValue[1] == 0x0A) { /** 06 05 02 03 0A AF 89 */
2447 fieldValue[3] = fieldValue[2];
2448 fieldValue[2] = fieldValue[1];
2449 fieldValue[1] = fieldValue[0];
2450 fieldValue[0] = 0x02;
2453 MSG_DEBUG("WspLDecodeHeader:For CPE problem\r\n");
2455 tempLen = fieldValue[0]; /** 06 06 03 02 03 16 AF 88 */
2459 char* szExtendedContent;
2461 contentsTypeCode = fieldValue[0] & 0x7f;
2462 while ((wspContentsType[i].contentsTypeCode != contentsTypeCode) && (i < wspContentsTypeCount)) i++;
2464 /* If specified content type doesn't exist */
2465 if (i < wspContentsTypeCount)
2466 strncat((char*)temper, (char*)wspContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2468 szExtendedContent = wspExtendedDecodeType((char)contentsTypeCode);
2470 if (szExtendedContent != NULL) {
2471 MSG_DEBUG("WspLDecodeHeader: Tele2 server problem \n ");
2472 strncat((char*)temper, (char*)szExtendedContent, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2475 contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
2477 while ((i < wspUnregisteredContentsTypeCount) && (wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode)) i++;
2479 /** If there is a Content-Type assigned, */
2480 if (i < wspUnregisteredContentsTypeCount)
2481 strncat((char*)temper, (char*)wspUnregisterContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2486 tempLen = AcStrlen((char*)fieldValue) + 1;
2488 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2489 MSG_DEBUG("WspLDecodeHeader: Attention, Decoding Check of Content-Type %lu\n ", tempLen);
2492 /* If there is a parameter */
2493 if (tempLen < fieldValueLen) {
2495 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2496 wspHeaderDecodeParameter(fieldValue + tempLen, fieldValueLen - tempLen, ¶m);
2497 if (param != NULL) {
2498 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2499 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2506 /* content-language */
2508 /* accept-language */
2510 unsigned long i = 0;
2512 unsigned long tempLen;
2513 if ((fieldValue[0] < 0x20) || (fieldValue[0] > 0x80)) {
2514 if (fieldValue[0] > 0x80)
2517 tempLen = fieldValue[0];
2519 tempLen = AcStrlen((char*)fieldValue) + 1;
2523 code = wspHeaderDecodeInteger(fieldValue);
2524 while (wspLanguage[i].languageCode != code) {
2526 if (i == wspLanguageCount)
2530 if (i < wspLanguageCount) {
2531 strncat((char*)temper, (char*)wspLanguage[i].languageName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2534 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2537 if (tempLen < fieldValueLen) {
2539 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2540 wspHeaderDecodeQValue(fieldValueLen - tempLen, fieldValue + tempLen, ¶m);
2541 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2549 /* content-length */
2553 /* Bearer-indication */
2557 unsigned char temp[16];
2559 if ((fieldValueLen == 2) && (fieldValue[0] > 0x7f))
2560 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[1]);
2563 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2564 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2567 /* X-Wap-Application-Id */
2569 unsigned char temp[64];
2572 if (track == 0xaf) { /* WAP short-integer-encoded */
2573 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2574 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen);
2576 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2578 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2579 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2580 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2583 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2586 MSG_DEBUG("integerValue = [%02x]", integerValue);
2588 int count = sizeof(wspHeaderApplId)/sizeof(SMS_3GPP_WSP_HEADER_PARAMETER_S);
2589 for (int i = 0; i < count ; ++i) {
2590 if ((unsigned int)integerValue == wspHeaderApplId[i].parameterCode) {
2591 snprintf((char*)temp, 64, "%s", wspHeaderApplId[i].parameterToken);
2592 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2598 /* Accept-Application */
2600 if (0x80 == fieldValue[0]) {
2601 strncat((char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2603 unsigned char temp[16];
2605 if ((fieldValueLen == 2) && (fieldValue[0] == 1))
2606 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[0]);
2609 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2610 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2618 /* if-unmodified-since */
2622 /* if-modified-since */
2628 char* decodedString = NULL;
2629 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2630 wspHeaderDecodeDateValue(fieldValueLen, fieldValue, &decodedString);
2631 strncat((char*)temper, (char*)decodedString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2637 if (fieldValue[0] == 0x80)
2638 strncat((char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2642 if (fieldValue[0] == 0x80)
2643 strncat((char*)temper, "None", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2644 if (fieldValue[0] == 0x81)
2645 strncat((char*)temper, "Bytes", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2649 unsigned char temp[1275];
2650 memcpy(temp, fieldValue, (size_t)fieldValueLen);
2651 temp[fieldValueLen] = 0;
2652 wspHeaderCopyDecodedString(temp, ¤tLength, &temper);
2658 /* proxy - authorization */
2660 if (fieldValue[0] == 0x80) {
2661 char* addString = NULL;
2662 unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2663 wspHeaderDecodeAuth(fieldValueLen, fieldValue, &addString);
2664 strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2666 iField = AcStrlen((char*)fieldValue) + 1;
2668 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2669 if (iField < fieldValueLen) {
2671 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2672 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, ¶m);
2673 if (param != NULL) {
2674 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2675 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2685 /* Proxy-authenticate */
2687 if (0 == fieldValueLen)
2689 if (fieldValue[0] == 0x80) {
2690 char* addString = NULL;
2691 unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2692 wspHeaderDecodeChallenge(fieldValueLen, fieldValue, &addString);
2693 strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2695 unsigned char authScheme[WSP_STANDARD_STR_LEN_MAX + 1];
2696 unsigned char realmValue[WSP_STANDARD_STR_LEN_MAX];
2697 unsigned char addedString[WSP_STANDARD_STR_LEN_MAX];
2699 strncpy((char*)authScheme, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX -1);
2700 iField = AcStrlen((char*)authScheme) + 1;
2701 strncpy((char*)realmValue, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2702 iField = iField + AcStrlen((char*)realmValue) + 1;
2703 int wrn = snprintf((char*)addedString, sizeof(addedString), "%s %s", authScheme, realmValue);
2705 MSG_DEBUG("snprintf was failed");
2706 wspHeaderCopyDecodedString(addedString, ¤tLength, &temper);
2708 if (iField < fieldValueLen) {
2710 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2711 wspHeaderDecodeParameter(fieldValue + iField, fieldValueLen - iField, ¶m);
2712 if (param != NULL) {
2713 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2714 wspHeaderCopyDecodedString((unsigned char*)param, ¤tLength, &temper);
2720 /* content -range */
2722 unsigned long first, len, last;
2724 unsigned char temp[16];
2727 strncat((char*)temper, " bytes ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2729 first = wspRetriveUintvarDecode(fieldValue, &iField);
2730 len = wspRetriveUintvarDecode(fieldValue, &iField);
2731 /* 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.
2733 last = first + contentsLength - 1;
2735 snprintf((char*)temp, sizeof(temp), "%u-%u/%u", (unsigned int)first, (unsigned int)last, (unsigned int)len);
2736 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2742 char* cacheString = NULL;
2743 unique_ptr<char*, void(*)(char**)> cacheStringbuf(&cacheString, unique_ptr_deleter);
2745 wspHeaderDecodeCacheControl(fieldValue, fieldValueLen, &cacheString);
2746 strncat((char*)temper, (char*)cacheString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2752 if (fieldValue[0] == 0x80) {
2753 strncat((char*)temper, (char*)wspCacheControl[0], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2755 if (1 < fieldValueLen) {
2757 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2758 wspHeaderDecodeParameter(fieldValue, fieldValueLen, ¶m);
2760 if (param != NULL) {
2761 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2762 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2772 unsigned long i = 0;
2773 while (wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen) != wspMethodType[i].methodCode) i++;
2774 strncat((char*)temper, (char*)wspMethodType[i].methodName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2779 strncat((char*)temper, "bytes=", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2780 if (fieldValue[0] == 0x80) {
2781 unsigned char temp[16];
2782 unsigned long first, last;
2785 first = wspRetriveUintvarDecode(fieldValue, &iField);
2786 last = wspRetriveUintvarDecode(fieldValue, &iField);
2788 snprintf((char*)temp, sizeof(temp), "%u-%u", (unsigned int)first, (unsigned int)last);
2789 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2791 if (fieldValue[0] == 0x81) {
2792 unsigned char temp[16];
2793 unsigned long suffix;
2795 suffix = wspRetriveUintvarDecode(fieldValue, &iField);
2797 snprintf((char*)temp, sizeof(temp), "-%u", (unsigned int)suffix);
2802 if (fieldValue[0] == 0x80) {
2804 unique_ptr<char*, void(*)(char**)> tempbuf(&temp, unique_ptr_deleter);
2806 wspHeaderDecodeDateValue(fieldValueLen - 1, fieldValue + 1, &temp);
2807 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2810 if (fieldValue[0] == 0x81) {
2811 unsigned char temp[16];
2813 snprintf((char*)temp, 16, "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2814 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2817 /* transfer-encoding */
2819 /* No other cases allowed */
2820 if (fieldValue[0] == 0x80)
2821 strncat((char*)temper, "chunked", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2826 int integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2827 if (integerValue > wspHeaderFieldCount) {
2828 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x%x).\n", wspHeaderFieldCount);
2831 strncat((char*)temper, (char*)wspHeaderFieldName[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2836 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2838 if (fieldValue[0] < 0x20)
2839 iField = fieldValue[0];
2843 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, iField));
2844 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2845 if (iField < fieldValueLen) {
2846 unsigned char agent[WSP_STANDARD_STR_LEN_MAX];
2847 unsigned char text[WSP_STANDARD_STR_LEN_MAX];
2848 strncpy((char*)agent, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2849 iField = iField + AcStrlen((char*)agent) + 1;
2850 strncpy((char*)text, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2851 int wrn = snprintf((char*)temp, sizeof(temp), " %s %s", agent, text);
2853 MSG_DEBUG("snprintf was failed");
2854 wspHeaderCopyDecodedString(temp, ¤tLength, &temper);
2858 /* content-disposition */
2860 if (fieldValue[0] == 0x80)
2861 strncat((char*)temper, "form-data", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2863 if (fieldValue[0] == 0x81)
2864 strncat((char*)temper, "attachment", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2866 if (1 < fieldValueLen) {
2868 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2869 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, ¶m);
2871 if (param != NULL) {
2872 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2873 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2879 temper[AcStrlen((char*)temper) + fieldValueLen] = '\0';
2880 memcpy(temper, fieldValue, (size_t)fieldValueLen);
2882 /* Profile-Warning */
2884 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2886 snprintf((char*)temp, sizeof(temp), "%lX", wspHeaderDecodeInteger(fieldValue));
2888 temp[1] = (unsigned char)0x30;
2890 if (fieldValueLen > 1) {
2891 /* copy warn-target - URI */
2892 strncat((char*)temp, (char*)(fieldValue + 1), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2893 if (fieldValueLen > (AcStrlen((char*)(fieldValue + 1)) + 1)) {
2894 /* copy warn-date */
2895 char* decodedString = NULL;
2896 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2897 wspHeaderDecodeDateValue(fieldValueLen - (AcStrlen((char*)(fieldValue + 1)) + 2), fieldValue + AcStrlen((char*)(fieldValue + 1)) + 1, &decodedString);
2898 strncat((char*)temp, (char*)decodedString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2901 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2910 /* It deosn't finished decoding yet. */
2911 if ((iEncodedHeader < encodedHeaderLen) && (fieldCode != 0xff)) {
2912 /* In here, iEncodedHeader already point next field code to be decoded. */
2913 /* If this code is same, then set continueField else add CRLF. */
2914 if (fieldCode == (encodedHeader[iEncodedHeader] & 0x7f)) {
2915 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2916 continueField = TRUE;
2918 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2919 continueField = FALSE;
2922 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2925 /* add single header to total headers */
2926 strncat((char*)outTemper, (char*)temper, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)outTemper)-1);
2927 MSG_DEBUG("WspLDecodeHeader: Single Header : %s\r\n", temper);
2930 MSG_DEBUG("WspLDecodeHeader: Header decoding ended.\n");
2932 *pHeader = outTemper;
2938 unsigned long Sms3gppWapPushHandler::wspHeaderDecodeInteger(unsigned char* data)
2940 /* we only can handle max 32bit integer */
2944 unsigned long integer;
2945 unsigned char seg[4];
2948 returner.integer = 0;
2950 if (data[0] < 0x80) {
2951 unsigned long IntLen = 0;
2953 IntLen = (data[0] > 0x04) ? 0x04:data[0];
2955 MSG_DEBUG("WspLHeaderDecodeInteger: input %d , length %lu\n", data[0], IntLen);
2957 for (i = 0; i < IntLen; i++)
2958 returner.seg[IntLen-(i+1)] = data[i+1];
2960 return returner.integer;
2963 return data[0] & 0x7f;
2967 void Sms3gppWapPushHandler::wspHeaderDecodeQValue(unsigned long length, unsigned char* data, char** pDecodedString)
2969 unsigned short qBase = 0;
2972 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2973 if (*pDecodedString == NULL) {
2974 MSG_DEBUG("WspLHeaderDecodeQValue:MemAlloc failed\n");
2978 memcpy(&qBase, data, (size_t)length);
2979 qValue = (float)qBase;
2981 qValue = qValue - 100;
2982 qValue = qValue / 1000;
2983 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.3f", qValue);
2985 /* qValue variable is divided by 100. And it's multiplied by 100.
2986 It's to resolve problem of changed 0.01 of qValue. */
2987 unsigned long qValueTemp;
2988 qValue = qValue - 1;
2989 qValue = qValue / 100;
2990 qValueTemp = (unsigned long)(qValue * 100);
2991 if (0 == (qValueTemp % 10))
2992 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.1f", qValue);
2994 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.2f", qValue);
3000 unsigned long Sms3gppWapPushHandler::wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length)
3005 unsigned long integer;
3006 unsigned short seg[4];
3009 returner.integer = 0;
3012 return data[0] & 0x7f;
3014 returner.integer = 0;
3016 for (i = 0 ; i < length; i++) {
3017 returner.integer = returner.integer + (data[i] * (0x1 << ((length - (i + 1)) * 8)));
3018 MSG_DEBUG("WspLHeaderDecodeIntegerByLength: %lu \n", returner.integer);
3021 return returner.integer;
3025 char* Sms3gppWapPushHandler::wspExtendedDecodeType(char contentType)
3029 while (wspExtendedContentsType[i].contentsTypeCode != contentType) {
3030 if (wspExtendedContentsType[i].contentsTypeCode == 0xff)
3035 return (char*)wspExtendedContentsType[i].contentsTypeName;
3039 void Sms3gppWapPushHandler::wspHeaderDecodeParameter(unsigned char* data, unsigned long length, char** pParam)
3041 char* param = *pParam;
3043 unsigned long SecurityTypeCode;
3044 unsigned long i = 0;
3046 if (data[0] < 0x80) {
3047 /* unknown parameter type */
3048 param = new char[WSP_STANDARD_STR_LEN_MAX];
3050 if (param == NULL) {
3051 MSG_DEBUG("WspLHeaderDecodeParameter:MemAlloc failed\n");
3055 strncpy((char*)param, (char*)data, WSP_STANDARD_STR_LEN_MAX - 1);
3057 if (NO_VALUE == data[AcStrlen((char*)param) + 1]) {
3062 strncat((char*)param, "=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3063 strncat((char*)param, (char*)(data + strlen((char*)param)), WSP_STANDARD_STR_LEN_MAX-strlen((char*)param)-1);
3070 switch (data[0] & 0x7f) {
3072 wspHeaderDecodeQValue(length - 1, data + 1, ¶m);
3075 wspHeaderDecodeCharset(length - 1 , data + 1, ¶m);
3078 wspHeaderDecodeVersion(length - 1, data + 1, ¶m);
3082 /* param = (unsigned char *)malloc((size_t)WSP_STANDARD_STR_LEN_MAX); */
3083 param = new char[WSP_STANDARD_STR_LEN_MAX];
3084 if (param == NULL) {
3085 MSG_DEBUG("WspLHeaderDecodeParameter: 0x03 MemAlloc failed\n");
3088 snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Type=%i", (int)wspHeaderDecodeInteger(data + 1));
3092 param = new char[WSP_STANDARD_STR_LEN_MAX];
3094 if (param == NULL) {
3095 MSG_DEBUG("WspLHeaderDecodeParameter:0x08 MemAlloc failed\n");
3098 snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Padding=%i", (int)wspHeaderDecodeInteger(data + 1));
3102 param = new char[WSP_STANDARD_STR_LEN_MAX];
3104 if (param == NULL) {
3105 MSG_DEBUG("WspLHeaderDecodeParameter:0x05 MemAlloc failed\n");
3108 strncpy((char*)param, "Name=", WSP_STANDARD_STR_LEN_MAX-1);
3109 memcpy(param + 5, data + 1, length - 1);
3110 param[5 + length - 1] = '\0';
3114 param = new char[WSP_STANDARD_STR_LEN_MAX];
3116 if (param == NULL) {
3117 MSG_DEBUG("WspLHeaderDecodeParameter:0x06 MemAlloc failed\n");
3120 strncpy((char*)param, "Filename=", WSP_STANDARD_STR_LEN_MAX-1);
3121 memcpy(param + 9, (char*)(data + 1), (size_t)(length - 1));
3122 param[9 + length - 1] = '\0';
3129 /*OMA Provisioning*/
3131 param = new char[WSP_STANDARD_STR_LEN_MAX];
3133 if (param == NULL) {
3134 MSG_DEBUG("WspLHeaderDecodeParameter:0x11 MemAlloc failed\n");
3137 strncpy((char*)param, "SEC=", WSP_STANDARD_STR_LEN_MAX-1);
3138 SecurityTypeCode = data[1] & 0x7f;
3139 while ((i < wspSecurityTypeCount) && (wspSecurityType[i].SecurityTypeCode != SecurityTypeCode)) i++;
3141 if (i < wspSecurityTypeCount) {
3142 strncat((char*)param, (char*)wspSecurityType[i].SecurityTypeName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3145 if (0x12 == (data[2] & 0x7f)) {
3146 strncat((char*)param, "; MAC=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3147 memcpy(param+AcStrlen((char*)param), (char*)(data+3), (size_t)length-3);
3161 void Sms3gppWapPushHandler::wspHeaderDecodeCharset(unsigned long length, unsigned char* data, char**pDecodedString)
3165 param = new char[WSP_STANDARD_STR_LEN_MAX];
3166 if (param == NULL) {
3167 MSG_DEBUG("WspLHeaderDecodeCharset:MemAlloc failed\n");
3168 *pDecodedString = NULL;
3172 strncpy((char*)param, "charset=", WSP_STANDARD_STR_LEN_MAX-1);
3174 if (data[0] > 0x80) {
3175 unsigned long code = wspHeaderDecodeInteger(data);
3176 unsigned long i = 0;
3177 while (wspCharset[i].charsetCode != code) {
3178 if (wspCharset[i].charsetCode == 0xffff) {
3179 *pDecodedString = param;
3184 strncat((char*)param, (char*)wspCharset[i].charsetName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3186 unsigned long lastLen = AcStrlen((char*)param);
3187 if (length + lastLen < WSP_STANDARD_STR_LEN_MAX - 1) {
3188 memcpy((char*)(param + lastLen), data, (size_t)length);
3189 param[length + lastLen] = '\0';
3191 memcpy((char*)(param + lastLen), data, WSP_STANDARD_STR_LEN_MAX - lastLen - 1);
3192 param[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3196 *pDecodedString = param;
3201 void Sms3gppWapPushHandler::wspHeaderDecodeVersion(unsigned long length, unsigned char* data, char** pDecodedString)
3203 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3205 if (*pDecodedString == NULL) {
3206 MSG_DEBUG("WspLHeaderDecodeVersion:MemAlloc failed\n");
3211 /* untyped version */
3212 memcpy(*pDecodedString, data, (size_t)length);
3215 unsigned char majorVer = ((data[0] & 0x7f) >> 4);
3216 unsigned char minorVer = data[0] & 0x0f;
3217 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "level=%u.%u", majorVer, minorVer);
3224 void Sms3gppWapPushHandler::wspHeaderDecodeDateValue(unsigned long length, unsigned char* data, char** pDecodedString)
3229 MSG_DEBUG("WspLHeaderDecodeDateValue: \n");
3231 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3233 if (*pDecodedString == NULL) {
3234 MSG_DEBUG("WspLHeaderDecodeDateValue:MemAlloc failed\n");
3238 lTime = wspHeaderDecodeIntegerByLength(data, length);
3240 (struct tm*)gmtime_r((const time_t*)&lTime, &pTMData);
3242 /* check date value validity */
3243 if ((pTMData.tm_wday > 6) || (pTMData.tm_mon > 11) || (pTMData.tm_mday > 31)) {
3244 MSG_DEBUG("WspLHeaderDecodeDateValue: Date decode fail %d, %d, %d \n", pTMData.tm_wday, pTMData.tm_mon, pTMData.tm_mday);
3245 strncpy((char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
3249 #ifdef MSG_FW_FOR_DEBUG
3250 /** Date type selection */
3251 switch (wspMachineStatus.dateType) {
3252 /* UNIX asciitime function */
3253 case UNIX_DATE_TYPE:
3254 snprintf((char*)decodedString, sizeof(decodedString), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData.tm_wday], wspMonth[pTMData.tm_mon],
3255 pTMData.tm_mday, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec, pTMData.tm_year + 1900);
3257 case RFC1123_DATE_TYPE:
3258 snprintf((char*)decodedString, sizeof(decodedString), "%s, %u %s %u %u:%u:%u GMT", wspWeek[pTMData.tm_wday], pTMData.tm_mday,
3259 wspMonth[pTMData.tm_mon], pTMData.tm_year + 1900, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec);
3261 case RFC850_DATE_TYPE:
3262 /* Have some Y2K Problems */
3263 /* 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. */
3264 snprintf((char*)decodedString, sizeof(decodedString), "%s, %2u-%s-%2u %u:%u:%u GMT", wspWeekDay[pTMData.tm_wday], pTMData.tm_mday,
3265 wspMonth[pTMData.tm_mon], pTMData.tm_year % CENTURY, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec);
3270 /**UNIX_DATE_TYPE : */
3271 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],
3272 pTMData.tm_mday, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec, pTMData.tm_year + 1900);
3277 void Sms3gppWapPushHandler::wspHeaderCopyDecodedString(unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper)
3279 unsigned long elementLen = AcStrlen((char*)szDecodedString);
3280 char* temper2 = NULL;
3283 *currentLen = *currentLen + elementLen + 2;
3285 if (*currentLen > AcStrlen((char*)* pTemper) + 2) {
3286 temper2 = new char[(*currentLen + 1)];
3288 if (temper2 == NULL) {
3289 MSG_DEBUG("WspLHeaderCopyDecodedString:MemAlloc failed\n");
3292 strncpy((char*)temper2, (char*)* pTemper, *currentLen);
3294 strncpy((char*)temper2, (char*)szDecodedString, *currentLen);
3303 void Sms3gppWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3305 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3306 unsigned char passWd[WSP_STANDARD_STR_LEN_MAX];
3307 unsigned long iField = 0;
3310 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX * 2];
3312 if (*pDecodedString == NULL) {
3313 MSG_DEBUG("WspLHeaderDecodeAuth:MemAlloc failed\n");
3317 /* skip 'basic' code */
3319 memset(authStr, 0x00, sizeof(authStr));
3320 snprintf(authStr, sizeof(authStr), "%%%zus", sizeof(userId));
3321 sscanf((char*)(fieldValue + iField), authStr, userId);
3322 iField = iField + AcStrlen((char*)userId) + 1;
3323 memset(authStr, 0x00, sizeof(authStr));
3324 snprintf(authStr, sizeof(authStr), "%%%zus", sizeof(passWd));
3325 sscanf((char*)(fieldValue + iField), authStr, passWd);
3326 iField = iField + AcStrlen((char*)userId) + 1;
3327 int wrn = snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX*2), "basic %s/%s", userId, passWd);
3329 MSG_DEBUG("snprintf was failed\n");
3335 void Sms3gppWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3337 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3338 unsigned long iField = 0;
3341 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3343 if (*pDecodedString == NULL) {
3344 MSG_DEBUG("WspLHeaderDecodeChallenge:MemAlloc failed\n");
3348 /* skip 'basic' code */
3350 memset(authStr, 0x00, sizeof(authStr));
3351 snprintf(authStr, sizeof(authStr), "%%%zus", sizeof(userId));
3352 sscanf((char*)(fieldValue + iField), authStr, userId);
3353 iField = iField + AcStrlen((char*)userId) + 1;
3355 int wrn = snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "basic realm=\"%s\"", userId);
3357 MSG_DEBUG("snprintf was failed\n");
3363 void Sms3gppWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString)
3365 unsigned char paramString[WSP_STANDARD_STR_LEN_MAX];
3366 unsigned char cacheCode;
3369 *pCacheString = new char[WSP_STANDARD_STR_LEN_MAX];
3370 if (*pCacheString == NULL) {
3371 MSG_DEBUG("WspLHeaderDecodeCacheControl:MemAlloc failed\n");
3375 if (1 == fieldValueLen) {
3376 /* only one directive */
3377 if (fieldValue[0] > 0x8b) {
3378 return; /* It's error detection. can be omitted. */
3380 strncpy((char*)*pCacheString, (char*)wspCacheControl[fieldValue[0] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3384 if (fieldValue[0] > 0x7f) {
3385 /* directive that has parameter */
3386 cacheCode = fieldValue[0] & 0x7f;
3387 switch (cacheCode) {
3393 if (fieldValue[1] > 0x7f) {
3394 /* well known field name */
3395 strncpy((char*)paramString, (char*)wspHeaderFieldName[fieldValue[1] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3396 paramString[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3398 /* unknown field name */
3399 strncpy((char*)paramString, (char*)fieldValue + 1 , WSP_STANDARD_STR_LEN_MAX-1);
3409 snprintf((char*)paramString, sizeof(paramString), "%u", (unsigned int)wspHeaderDecodeInteger(fieldValue + 1));
3415 wrn = snprintf((char*)*pCacheString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString);
3417 MSG_DEBUG("snprintf was failed");
3419 /* cache extentions */
3420 /* In case of come directive of doesn't specified string style */
3422 unsigned long stringLen;
3424 strncpy((char*)*pCacheString, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX-1);
3425 stringLen = AcStrlen((char*)*pCacheString);
3427 if (stringLen + 1 < fieldValueLen) {
3428 if (fieldValue[stringLen+ 1] > 0x7f) {
3429 int untyped = (int)wspHeaderDecodeIntegerByLength(fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1));
3431 snprintf(szString, sizeof(szString), "%d", untyped);
3432 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3433 strncat((char*)*pCacheString, (char*)szString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3435 if (fieldValue[fieldValueLen] == 0) {
3436 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3437 strncat((char*)*pCacheString, (char*)fieldValue + stringLen + 1 , WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3446 void Sms3gppWapPushHandler::getDisplayName(MSG_SUB_TYPE_T subType, char* displayName)
3448 if (subType == MSG_WAP_SL_SMS || subType == MSG_WAP_SI_SMS)
3449 snprintf(displayName, MAX_ADDRESS_VAL_LEN + 1, "Push message");