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 Sms3gppWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1422 MSG_PUSH_MESSAGE_S pushMsg = {};
1424 xmlDocPtr xmlDoc = NULL;
1425 xmlNodePtr topNode = NULL;
1426 xmlNodePtr indNode = NULL;
1428 xmlChar* tmpXmlChar = NULL;
1430 if (pPushBody == NULL) {
1431 MSG_DEBUG("pPushBody is NULL");
1435 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1437 if (xmlDoc == NULL) {
1438 MSG_DEBUG("xmlDoc is NULL");
1442 topNode = xmlDocGetRootElement(xmlDoc);
1444 if (topNode == NULL) {
1445 MSG_DEBUG("topNode is NULL");
1450 indNode = topNode->xmlChildrenNode;
1452 while (indNode != NULL) {
1453 if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
1454 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1458 indNode = indNode->next;
1461 if (indNode == NULL) {
1462 MSG_DEBUG("indNode is NULL.");
1466 /** temporary set to max. */
1467 pushMsg.expires = 0xFFFFFFFF;
1469 /** setting received time */
1470 time_t t = time(NULL);
1471 time_t utfTime = time(&t);
1473 pushMsg.received = (unsigned long)utfTime;
1475 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1477 if (tmpXmlChar == NULL) {
1478 MSG_DEBUG("href is NULL.");
1482 if (tmpXmlChar != NULL)
1483 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1485 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
1487 if (tmpXmlChar != NULL)
1488 strncpy(pushMsg.id, (char*)tmpXmlChar, MAX_WAPPUSH_ID_LEN-1);
1490 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CREATED_TAG);
1492 if (tmpXmlChar != NULL)
1493 pushMsg.created = convertXmlCharToSec((char*)tmpXmlChar);
1495 if (pushMsg.created == 0)
1496 pushMsg.created = pushMsg.received;
1498 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_EXPIRES_TAG);
1500 if (tmpXmlChar != NULL)
1501 pushMsg.expires = convertXmlCharToSec((char*)tmpXmlChar);
1503 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1505 pushMsg.action = convertSIActionStrToEnum((char*)tmpXmlChar);
1507 tmpXmlChar = xmlNodeListGetString(xmlDoc, indNode->xmlChildrenNode, 1);
1509 if (tmpXmlChar == NULL) {
1510 MSG_DEBUG("contents is NULL.");
1514 strncpy(pushMsg.contents, (char*)tmpXmlChar, MAX_WAPPUSH_CONTENTS_LEN-1);
1516 /** Write push Msg to file */
1517 char fileName[MSG_FILENAME_LEN_MAX+1];
1518 memset(fileName, 0x00, sizeof(fileName));
1520 if (MsgCreateFileName(fileName) == false) {
1522 xmlFree(tmpXmlChar);
1523 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1526 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false) {
1528 xmlFree(tmpXmlChar);
1529 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1532 /* Pack Message Info Structure */
1533 MSG_MESSAGE_INFO_S msgInfo;
1534 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1536 msgInfo.addressList = NULL;
1537 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1539 createMsgInfo(&msgInfo);
1541 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1543 /* Convert Type values */
1544 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1545 msgInfo.msgType.subType = MSG_WAP_SI_SMS;
1546 msgInfo.sim_idx = simIndex;
1548 msgInfo.dataSize = sizeof(pushMsg);
1549 getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
1551 xmlFree(tmpXmlChar);
1553 msg_error_t err = MSG_SUCCESS;
1555 /* Add WAP Push Msg into DB */
1556 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1557 if (err == MSG_SUCCESS) {
1559 err = Sms3gppEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1560 if (err != MSG_SUCCESS)
1561 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1563 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1572 void Sms3gppWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1576 MSG_PUSH_MESSAGE_S pushMsg = {};
1578 xmlDocPtr xmlDoc = NULL;
1579 xmlNodePtr topNode = NULL;
1580 xmlNodePtr indNode = NULL;
1582 xmlChar* tmpXmlChar = NULL;
1584 msg_error_t err = MSG_SUCCESS;
1586 if (pPushBody == NULL) {
1587 MSG_DEBUG("pPushBody is NULL \n");
1591 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1593 if (xmlDoc == NULL) {
1594 MSG_DEBUG("xmlDoc is NULL \n");
1598 topNode = xmlDocGetRootElement(xmlDoc);
1600 if (topNode == NULL) {
1601 MSG_DEBUG("Empty Document.");
1605 MSG_SEC_DEBUG("Not an empty Document and topNode->name = %s \n", topNode->name);
1610 while (indNode != NULL) {
1611 if (!xmlStrcmp(indNode->name, (const xmlChar*)"sl")) {
1612 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1616 indNode = indNode->next;
1619 /* setting received time setting */
1620 time_t t = time(NULL);
1621 time_t utfTime = time(&t);
1623 pushMsg.received = (unsigned long)utfTime;
1625 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1627 if (tmpXmlChar == NULL) {
1628 MSG_DEBUG("href is NULL.");
1632 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1634 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1635 pushMsg.action = convertSLActionStrToEnum((char*)tmpXmlChar);
1637 /* Setting other parameters in default values */
1638 pushMsg.created = pushMsg.received;
1639 /* temporary set to MAX value. */
1640 pushMsg.expires = 0xFFFFFFFF;
1642 MSG_DEBUG("check pushMsg data");
1643 MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
1644 MSG_DEBUG("pushMsg.received : [%lu]", pushMsg.received);
1645 MSG_DEBUG("pushMsg.created : [%lu]", pushMsg.created);
1646 MSG_DEBUG("pushMsg.expires : [%lu]", pushMsg.expires);
1647 MSG_SEC_DEBUG("pushMsg.id : [%s]", pushMsg.id);
1648 MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
1649 MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
1651 /* Write push Msg to file */
1652 char fileName[MSG_FILENAME_LEN_MAX+1];
1653 memset(fileName, 0x00, sizeof(fileName));
1655 if (MsgCreateFileName(fileName) == false)
1656 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1658 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false)
1659 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1661 /* Pack Message Info Structure */
1662 MSG_MESSAGE_INFO_S msgInfo;
1663 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1665 msgInfo.addressList = NULL;
1666 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1668 createMsgInfo(&msgInfo);
1670 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1672 /* Convert Type values */
1673 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1674 msgInfo.msgType.subType = MSG_WAP_SL_SMS;
1675 msgInfo.sim_idx = simIndex;
1677 /* Update Msg Text */
1678 strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
1680 msgInfo.dataSize = sizeof(pushMsg);
1681 getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
1682 MSG_DEBUG("dataSize : %zu", msgInfo.dataSize);
1684 /** Add WAP Push Msg into DB */
1685 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1686 if (err == MSG_SUCCESS) {
1687 /* Callback to MSG FW */
1688 err = Sms3gppEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1690 if (err != MSG_SUCCESS)
1691 MSG_DEBUG("callbackMsgIncoming is failed, err=[%d]", err);
1693 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1697 xmlFree(tmpXmlChar);
1704 void Sms3gppWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1706 MSG_PUSH_CACHEOP_S cacheOp;
1708 xmlDocPtr xmlDoc = NULL;
1709 xmlNodePtr topNode = NULL;
1710 xmlNodePtr indNode = NULL;
1712 memset(&cacheOp, 0x00, sizeof(cacheOp));
1714 MSG_DEBUG("Enter handleCOMessage");
1716 if (pPushBody == NULL) {
1717 MSG_DEBUG("pPushBody is NULL \n");
1721 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1723 if (xmlDoc == NULL) {
1724 MSG_DEBUG("xmlDoc is NULL \n");
1728 topNode = xmlDocGetRootElement(xmlDoc);
1729 if (topNode == NULL) {
1730 MSG_DEBUG("Warning:Empty Document\n");
1735 indNode = topNode->xmlChildrenNode;
1737 while (indNode != NULL) {
1738 xmlChar* tmpUrl = NULL;
1739 if (!xmlStrcmp(indNode->name, (const xmlChar*)SMS_PUSH_XML_INVAL_OBJ)) {
1740 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1742 tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1744 if (tmpUrl != NULL) {
1745 strncpy(cacheOp.invalObjectUrl[cacheOp.invalObjectCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1747 MSG_DEBUG("%dth invalObjectUrl is <%s>\n", cacheOp.invalObjectCnt, cacheOp.invalObjectUrl[cacheOp.invalObjectCnt-1]);
1749 MSG_DEBUG("NO href value from the xmlDoc\n");
1751 } else if (!xmlStrcmp(indNode->name, (const xmlChar*)SMS_PUSH_XML_INVAL_SVC)) {
1752 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1753 tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1755 if (tmpUrl != NULL) {
1756 strncpy(cacheOp.invalServiceUrl[cacheOp.invalServiceCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1757 MSG_DEBUG("%dth invalServiceUrl is <%s>\n", cacheOp.invalServiceCnt, cacheOp.invalServiceUrl[cacheOp.invalServiceCnt-1]);
1759 MSG_DEBUG("NO href value from the xmlDoc\n");
1766 indNode = indNode->next;
1769 /* Write push Msg to file */
1770 char fileName[MSG_FILENAME_LEN_MAX+1];
1771 memset(fileName, 0x00, sizeof(fileName));
1773 if (MsgCreateFileName(fileName) == false) {
1775 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1778 if (MsgWriteIpcFile(fileName, (char*)(&cacheOp), sizeof(cacheOp)) == false) {
1780 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1783 /* Pack Message Info Structure */
1784 MSG_MESSAGE_INFO_S msgInfo;
1785 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1787 msgInfo.addressList = NULL;
1788 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1790 createMsgInfo(&msgInfo);
1792 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1794 /* Convert Type values */
1795 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1796 msgInfo.msgType.subType = MSG_WAP_CO_SMS;
1797 msgInfo.sim_idx = simIndex;
1799 msgInfo.dataSize = sizeof(cacheOp);
1801 msg_error_t err = MSG_SUCCESS;
1803 /* Add WAP Push Msg into DB */
1804 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1805 if (err == MSG_SUCCESS) {
1807 err = Sms3gppEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1808 if (err != MSG_SUCCESS)
1809 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1811 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1820 void Sms3gppWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
1823 int drmRt = DRM_RETURN_SUCCESS;
1825 unique_ptr<char*, void(*)(char**)> buf(&cid, unique_ptr_deleter);
1827 MSG_DEBUG("Received DRM RIGHTS OBJECT Type WAP Push Message.");
1828 drm_request_type_e request_type = DRM_REQUEST_TYPE_REGISTER_LICENSE;
1829 drm_register_lic_info_s lic_req_info;
1830 drm_register_lic_resp_s lic_resp_info;
1832 bzero(&lic_req_info, sizeof(drm_register_lic_info_s));
1833 bzero(&lic_resp_info, sizeof(drm_register_lic_resp_s));
1834 bzero(lic_req_info.lic_data, sizeof(lic_req_info.lic_data));
1836 memcpy(lic_req_info.lic_data, pPushBody, PushBodyLen);
1838 lic_req_info.lic_version = DRM_OMA_DRMV1_RIGHTS;
1839 lic_req_info.roap_init_src = DRM_ROAP_INIT_FROM_WAPPUSH;
1840 lic_req_info.operation_callback.callback = NULL;
1842 drmRt = drm_process_request(request_type, &lic_req_info, &lic_resp_info);
1843 if (drmRt == DRM_RETURN_SUCCESS) {
1844 MSG_DEBUG("DRM successfully registed to drm-service.");
1846 MSG_DEBUG("Fail to regist DRM to drm-service.");
1853 void Sms3gppWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
1855 /* Convert class Type values */
1856 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
1858 /* set folder id (temporary) */
1859 pMsgInfo->folderId = MSG_INBOX_ID;
1861 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
1862 pMsgInfo->bRead = false;
1863 pMsgInfo->bProtected = false;
1864 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
1865 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
1867 time_t rawtime = time(NULL);
1868 /* Comment below lines to save local UTC time..... (it could be used later.) */
1870 if (tmpTimeStamp.format == SMS_3GPP_TIME_ABSOLUTE) {
1872 MSG_DEBUG("year : %d", tmpTimeStamp.time.absolute.year);
1873 MSG_DEBUG("month : %d", tmpTimeStamp.time.absolute.month);
1874 MSG_DEBUG("day : %d", tmpTimeStamp.time.absolute.day);
1875 MSG_DEBUG("hour : %d", tmpTimeStamp.time.absolute.hour);
1876 MSG_DEBUG("minute : %d", tmpTimeStamp.time.absolute.minute);
1877 MSG_DEBUG("second : %d", tmpTimeStamp.time.absolute.second);
1878 MSG_DEBUG("timezone : %d", tmpTimeStamp.time.absolute.timeZone);
1880 char displayTime[32];
1884 memset(&timeinfo, 0x00, sizeof(tm));
1886 timeinfo.tm_year = (tmpTimeStamp.time.absolute.year + 100);
1887 timeinfo.tm_mon = (tmpTimeStamp.time.absolute.month - 1);
1888 timeinfo.tm_mday = tmpTimeStamp.time.absolute.day;
1889 timeinfo.tm_hour = tmpTimeStamp.time.absolute.hour;
1890 timeinfo.tm_min = tmpTimeStamp.time.absolute.minute;
1891 timeinfo.tm_sec = tmpTimeStamp.time.absolute.second;
1892 timeinfo.tm_isdst = 0;
1894 rawtime = mktime(&timeinfo);
1896 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
1897 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
1898 MSG_DEBUG("timezone [%d]", timezone);
1899 MSG_DEBUG("daylight [%d]", daylight);
1901 memset(displayTime, 0x00, sizeof(displayTime));
1902 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
1903 MSG_DEBUG("displayTime [%s]", displayTime);
1905 rawtime -= (tmpTimeStamp.time.absolute.timeZone * (3600/4));
1907 timeTM = localtime(&rawtime);
1908 memset(displayTime, 0x00, sizeof(displayTime));
1909 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1910 MSG_DEBUG("displayTime [%s]", displayTime);
1912 rawtime -= timezone;
1914 timeTM = localtime(&rawtime);
1915 memset(displayTime, 0x00, sizeof(displayTime));
1916 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1917 MSG_DEBUG("displayTime [%s]", displayTime);
1921 pMsgInfo->displayTime = rawtime;
1923 /* Convert Address values */
1924 pMsgInfo->nAddressCnt = 1;
1926 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
1927 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1929 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
1930 strncpy(pMsgInfo->addressList[0].addressVal, tmpAddress.address, MAX_ADDRESS_VAL_LEN);
1932 pMsgInfo->msgPort.valid = false;
1933 pMsgInfo->msgPort.dstPort = 0;
1934 pMsgInfo->msgPort.srcPort = 0;
1937 void Sms3gppWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText)
1939 if (pPushBody == NULL) {
1940 MSG_DEBUG("pPushBody is NULL");
1945 *pXmlDoc = xmlParseMemory(pPushBody, AcStrlen(pPushBody));
1947 WB_UTINY* xmldata = NULL;
1948 WBXMLConvWBXML2XML *conv = NULL;
1949 WBXMLError ret = WBXML_OK;
1951 ret = wbxml_conv_wbxml2xml_create(&conv);
1952 if (ret != WBXML_OK)
1955 ret = wbxml_conv_wbxml2xml_run(conv, (WB_UTINY*)pPushBody, (WB_ULONG)PushBodyLen, &xmldata, NULL);
1957 wbxml_conv_wbxml2xml_destroy(conv);
1959 if (ret != WBXML_OK ||xmldata == NULL) {
1960 MSG_DEBUG("xmldata is NULL. Error code is [%d].\n", ret);
1964 MSG_DEBUG("xmldata : \n%s\n", xmldata);
1966 *pXmlDoc = xmlParseMemory((char*)xmldata, AcStrlen((char*)xmldata));
1970 unsigned long Sms3gppWapPushHandler::convertXmlCharToSec(char* pDate)
1972 struct tm timeStruct;
1973 time_t nTimeInSec = 0;
1978 memset(tmpBuf, 0x00, sizeof(tmpBuf));
1979 memset(&timeStruct, 0x00, sizeof(struct tm));
1982 if (AcStrlen(pDate) < 20)
1985 MSG_DEBUG("pDate [%s]", pDate);
1988 for (i = 0; i < 4; i++) {
1989 tmpBuf[i] = pDate[index++];
1993 timeStruct.tm_year = (atoi(tmpBuf)-1900);
1996 for (i = 0; i < 2; i++) {
1997 tmpBuf[i] = pDate[index++];
2001 timeStruct.tm_mon = (atoi(tmpBuf) - 1);
2004 for (i = 0; i < 2; i++) {
2005 tmpBuf[i] = pDate[index++];
2009 timeStruct.tm_mday = atoi(tmpBuf);
2012 for (i = 0; i < 2; i++) {
2013 tmpBuf[i] = pDate[index++];
2017 timeStruct.tm_hour = atoi(tmpBuf);
2020 for (i = 0; i < 2; i++) {
2021 tmpBuf[i] = pDate[index++];
2025 timeStruct.tm_min = atoi(tmpBuf);
2028 for (i = 0; i < 2; i++) {
2029 tmpBuf[i] = pDate[index++];
2033 timeStruct.tm_sec = atoi(tmpBuf);
2035 nTimeInSec = mktime(&timeStruct);
2041 msg_push_action_t Sms3gppWapPushHandler::convertSIActionStrToEnum(char* pAction)
2045 if (pAction == NULL) {
2046 MSG_DEBUG("pAction is NULL. Setting to default action type.");
2047 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2050 /* compare with signal-none. */
2051 comp = g_strcmp0("signal-none", pAction);
2053 return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
2055 /* compare with signal-low. */
2056 comp = g_strcmp0("signal-low", pAction);
2058 return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
2060 /* compare with signal-medium. */
2061 comp = g_strcmp0("signal-medium", pAction);
2063 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2065 /* compare with signal-high. */
2066 comp = g_strcmp0("signal-high", pAction);
2068 return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
2070 /* compare with delete. */
2071 comp = g_strcmp0("delete", pAction);
2073 return MSG_PUSH_SI_ACTION_DELETE;
2075 /* signal-medium is default action value. */
2076 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2080 msg_push_action_t Sms3gppWapPushHandler::convertSLActionStrToEnum(char* pAction)
2084 if (pAction == NULL) {
2085 MSG_DEBUG("MSG_DEBUG is NULL. Setting to default action type.\n");
2086 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2089 /* compare pSrcStr with execute-low. */
2090 comp = g_strcmp0("execute-low", pAction);
2092 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2094 /* compare pSrcStr with execute-high. */
2095 comp = g_strcmp0("execute-high", pAction);
2097 return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
2099 /* compare pSrcStr with cache. */
2100 comp = g_strcmp0("cache", pAction);
2102 return MSG_PUSH_SL_ACTION_CACHE;
2104 /* default SL action value is execute-low. */
2105 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2109 unsigned long Sms3gppWapPushHandler::wspRetriveUintvarDecode(unsigned char* sourceData, unsigned long* currentPointer)
2111 unsigned long i = 0;
2112 unsigned long decodedValue;
2114 while (sourceData[*currentPointer + i] >= 0x80)
2117 decodedValue = wspDecodeUintvar(i + 1, sourceData + *currentPointer);
2118 *currentPointer = *currentPointer + i + 1;
2119 MSG_DEBUG("wspRetriveUintvarDecode: decodedValue=%lu .\n", decodedValue);
2120 return decodedValue;
2124 unsigned long Sms3gppWapPushHandler::wspDecodeUintvar(unsigned long length, unsigned char* userVar)
2127 unsigned long decodedUintvar = 0;
2129 for (i = 0 ; i < length; i++) {
2130 decodedUintvar = decodedUintvar + (wspUintvarDecodeTable[i] * (userVar[length-(i+1)] & 0x7f));
2133 return decodedUintvar;
2137 void Sms3gppWapPushHandler::wspDecodeHeader(unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader)
2139 unsigned long iField = 0;
2140 bool continueField = FALSE;
2141 unsigned long currentLength;
2143 char* encodedHeader = NULL;
2144 unique_ptr<char*, void(*)(char**)> encodedHeaderbuf(&encodedHeader, unique_ptr_deleter);
2146 char* outTemper = NULL;
2148 char* temper = NULL;
2149 unique_ptr<char*, void(*)(char**)> temperbuf(&temper, unique_ptr_deleter);
2151 unsigned char track;
2152 unsigned long iEncodedHeader = 0;
2153 unsigned char fieldCode = 0xff;
2155 /* outTemper is Decoded Headers.
2156 temper is Single Decoded Header.
2158 if (NULL == (outTemper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ])) {
2159 MSG_DEBUG("outTemper Memory allocation is failed.\n");
2162 memset(outTemper, 0, (WSP_STANDARD_STR_LEN_MAX * 5));
2163 currentLength = WSP_STANDARD_STR_LEN_MAX;
2165 MSG_DEBUG("wspDecodeHeader: Message header decoding started.\n");
2171 MSG_DEBUG("wspDecodeHeader: RAW data \n");
2172 for (loop = 0 ; loop < (int)encodedHeaderLen; loop++) {
2174 szTempBuf[0] = 0x00;
2175 snprintf(szTempBuf, sizeof(szTempBuf), "%2X ", sEncodedHeader[loop]);
2177 if (AcStrlen(szBuf) + 7 < 64) {
2178 strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2180 strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2181 MSG_DEBUG("[%s]", szBuf);
2183 strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2186 strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2187 MSG_DEBUG("[%s]", szBuf);
2188 MSG_DEBUG("fContentType=%d \n", fContentType);
2189 /* operation for content-type */
2190 /* makes psuedo- content-type fieldcode */
2191 /* 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. */
2194 encodedHeader = new char[ encodedHeaderLen + 1 ];
2195 if (encodedHeader == NULL) {
2196 MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2199 encodedHeader[0] = 0x91;
2200 memcpy(encodedHeader + 1, sEncodedHeader, (size_t)encodedHeaderLen);
2202 encodedHeader = new char[ encodedHeaderLen ];
2203 if (encodedHeader == NULL) {
2204 MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2208 memcpy(encodedHeader, sEncodedHeader, (size_t)encodedHeaderLen);
2211 /* Is it reacehd end of header? */
2212 while (iEncodedHeader < encodedHeaderLen) {
2213 /* Get memory for single header */
2214 if (temper == NULL) {
2215 temper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ];
2217 if (temper == NULL) {
2218 MSG_DEBUG("temper Memory allocation is failed.\n");
2221 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2223 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2226 /* this section presents header code page shifting procedure
2227 This part can be implemented by future request.
2230 track = encodedHeader[iEncodedHeader];
2232 if (track == 0x00) {
2233 MSG_DEBUG("WspLDecodeHeader: fieldcode is 0 \n");
2234 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2237 } else if ((track > 0) && (track < 0x20)) {
2239 } else if ((track < 0x7f) && (track > 0x1f)) { /* In this case, first byte is normal string. So it's considered to unknown header. */
2240 unsigned char* fieldName = (unsigned char*)gWapCodeBufferLeft;
2241 unsigned char* fieldValue = (unsigned char*)gWapCodeBufferRight;
2243 strncpy((char*)fieldName, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_LEFT_LEN_MAX-1);
2244 fieldName[WSP_CODE_BUFFER_LEFT_LEN_MAX-1] = '\0';
2245 iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldName) + 1;
2246 strncpy((char*)fieldValue, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_RIGHT_LEN_MAX-1);
2247 fieldValue[WSP_CODE_BUFFER_RIGHT_LEN_MAX-1] = '\0';
2248 iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldValue) + 1;
2250 strncat((char*)temper, (char*)fieldName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2251 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2252 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2253 /* this means 'don't process anymore.' */
2256 } else if (track > 0x7f) {
2257 /* In case of first byte is field code, else case is error. */
2258 /*if ((track & 0x7f) <= wspHeaderFieldCount) { */
2259 unsigned long fieldValueLen = encodedHeader[iEncodedHeader + 1];
2260 unsigned char fieldValue[1275];
2261 fieldCode = track & 0x7f;
2263 if ((fieldValueLen == 0) || (fieldValueLen == 0x80)) {
2264 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]);
2267 memset(fieldValue, 0, 1275);
2269 /* add field name */
2270 /* 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. */
2271 if (!continueField) {
2272 strncat((char*)temper, (char*)wspHeaderFieldName[fieldCode], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2273 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2274 continueField = FALSE;
2277 /* field value is string */
2278 /* In this case, it just copy field value. */
2279 if ((fieldValueLen > LENGTH_QUOTE) && (fieldValueLen < 0x80)) {
2280 /* string field value should be NULL terminated */
2281 strncat((char*)temper, (char*)(encodedHeader + iEncodedHeader + 1), (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2282 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2284 iEncodedHeader = iEncodedHeader + AcStrlen((char*)encodedHeader + iEncodedHeader + 1) + 2;
2288 /* first field value is length */
2289 /* If first byte of field value is length value, allocate field value by the length.
2290 In field value, data is
2291 1D 03 8F 24 24 - Then 8F 24 24 is field value.
2292 1D 1F 33.... - Then allocate 33H for FieldValue.
2294 1D 'Hi man!' Like 00, if string is come, then process without calculating field value.
2295 1D 8F 24 24 - In this case, original data is wrong.
2296 If accept-charset: ISO-10646-ucs-2;Q=0.7 is
2299 03 - field value length
2300 03 E8 47 - field value
2301 it's decoded by above value.
2303 if (fieldValueLen < 0x20) {
2304 if (fieldValueLen == LENGTH_QUOTE) {
2305 /* field length is encoded in UINTVAR */
2306 unsigned long uintvarLen = 0;
2307 fieldValueLen = wspRetriveUintvarDecode((unsigned char*) encodedHeader + iEncodedHeader + 2, &uintvarLen);
2308 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2 + uintvarLen, (size_t)fieldValueLen);
2309 iEncodedHeader = iEncodedHeader + fieldValueLen + uintvarLen + 2;
2311 if (fieldValueLen == 1) {
2312 /* field value is one byte integer over 0x80 */
2313 /** make it two byte integer */
2314 fieldValue[0] = 0x00;
2315 memcpy(fieldValue + 1, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2317 iEncodedHeader = iEncodedHeader + 1 + 2;
2319 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2320 fieldValue[fieldValueLen] = 0;
2321 iEncodedHeader = iEncodedHeader + fieldValueLen + 2;
2322 if ((fieldValueLen == 0) || (fieldValueLen == 0x80)) {
2323 MSG_DEBUG("%X \n", encodedHeader[iEncodedHeader]);
2329 /* field value is single encoded */
2330 if (fieldValueLen > 0x7f) {
2331 fieldValue[0] = encodedHeader[iEncodedHeader + 1];
2333 iEncodedHeader = iEncodedHeader + 2;
2335 /* processing normal pre-defined field decoding */
2337 MSG_DEBUG("WspLDecodeHeader: FieldCode %X\n", fieldCode);
2338 MSG_DEBUG("WspLDecodeHeader: fieldSize %lu\n", fieldValueLen);
2340 if ((fieldCode > wspHeaderFieldCount) && (fieldCode != 0xff)) {
2341 MSG_DEBUG("WspLDecodeHeader: unknown fieldcode %X \n", track);
2342 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2346 switch (fieldCode) {
2347 /* accept charset */
2348 /* It's normal way of field process. */
2350 unsigned long i = 0;
2353 /* Case of length of charset greater than 1 are two thigins.
2354 1. code length of charset is greater than 1.
2355 2. It include parameter.
2358 if (1 != fieldValueLen) {
2359 code = wspHeaderDecodeInteger(fieldValue);
2360 /* Calculate iField. */
2361 if (fieldValue[0] < 0x80)
2362 iField = fieldValue[0];
2366 while (wspCharset[i].charsetCode != code)
2368 strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2369 /* If parameter exist */
2370 if (iField < fieldValueLen) {
2372 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2373 wspHeaderDecodeQValue(fieldValueLen - iField, fieldValue + iField, ¶m);
2374 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2377 code = fieldValue[0] & 0x7f;
2379 while ((wspCharset[i].charsetCode != code) && (wspCharset[i].charsetCode != 0xffff )) i++;
2380 strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2386 /* Like below routine, Same decoding routine process together. */
2387 /* Accept-encoding */
2389 /* content-encoding */
2393 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2394 if (integerValue > 2) {
2395 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(2).\n");
2398 strncat((char*)temper, (char*)wspEncodeMethod[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2401 /* contents type decoder */
2406 unsigned long contentsTypeCode;
2407 unsigned long i = 0;
2408 /* encoded content type length body */
2409 unsigned long tempLen;
2410 MSG_DEBUG("fieldValueLen: %lu", fieldValueLen);
2412 /* Like HTTP result state 304, it's for processing without Content type. This part doesn't defined. */
2413 if (0 == fieldValueLen) {
2414 strncat((char*)temper, (char*)"None" , (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2417 /* 01 AE --> 00 AE --> AE*/
2418 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2419 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2420 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2423 if ((fieldValue[0] < 0x20) || (fieldValue[0] >= 0x80)) {
2424 if (fieldValue[0] >= 0x80) {
2426 } else if (fieldValueLen == 2 && fieldValue[0] == 0x03 && fieldValue[1] == 0x0A) { /** 06 05 02 03 0A AF 89 */
2427 fieldValue[3] = fieldValue[2];
2428 fieldValue[2] = fieldValue[1];
2429 fieldValue[1] = fieldValue[0];
2430 fieldValue[0] = 0x02;
2433 MSG_DEBUG("WspLDecodeHeader:For CPE problem\r\n");
2435 tempLen = fieldValue[0]; /** 06 06 03 02 03 16 AF 88 */
2439 char* szExtendedContent;
2441 contentsTypeCode = fieldValue[0] & 0x7f;
2442 while ((wspContentsType[i].contentsTypeCode != contentsTypeCode) && (i < wspContentsTypeCount)) i++;
2444 /* If specified content type doesn't exist */
2445 if (i < wspContentsTypeCount)
2446 strncat((char*)temper, (char*)wspContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2448 szExtendedContent = wspExtendedDecodeType((char)contentsTypeCode);
2450 if (szExtendedContent != NULL) {
2451 MSG_DEBUG("WspLDecodeHeader: Tele2 server problem \n ");
2452 strncat((char*)temper, (char*)szExtendedContent, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2455 contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
2457 while ((i < wspUnregisteredContentsTypeCount) && (wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode)) i++;
2459 /** If there is a Content-Type assigned, */
2460 if (i < wspUnregisteredContentsTypeCount)
2461 strncat((char*)temper, (char*)wspUnregisterContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2466 tempLen = AcStrlen((char*)fieldValue) + 1;
2468 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2469 MSG_DEBUG("WspLDecodeHeader: Attention, Decoding Check of Content-Type %lu\n ", tempLen);
2472 /* If there is a parameter */
2473 if (tempLen < fieldValueLen) {
2475 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2476 wspHeaderDecodeParameter(fieldValue + tempLen, fieldValueLen - tempLen, ¶m);
2477 if (param != NULL) {
2478 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2479 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2486 /* content-language */
2488 /* accept-language */
2490 unsigned long i = 0;
2492 unsigned long tempLen;
2493 if ((fieldValue[0] < 0x20) || (fieldValue[0] > 0x80)) {
2494 if (fieldValue[0] > 0x80)
2497 tempLen = fieldValue[0];
2499 tempLen = AcStrlen((char*)fieldValue) + 1;
2503 code = wspHeaderDecodeInteger(fieldValue);
2504 while (wspLanguage[i].languageCode != code) {
2506 if (i == wspLanguageCount)
2510 if (i < wspLanguageCount) {
2511 strncat((char*)temper, (char*)wspLanguage[i].languageName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2514 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2517 if (tempLen < fieldValueLen) {
2519 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2520 wspHeaderDecodeQValue(fieldValueLen - tempLen, fieldValue + tempLen, ¶m);
2521 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2529 /* content-length */
2533 /* Bearer-indication */
2537 unsigned char temp[16];
2539 if ((fieldValueLen == 2) && (fieldValue[0] > 0x7f))
2540 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[1]);
2543 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2544 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2547 /* X-Wap-Application-Id */
2549 unsigned char temp[64];
2552 if (track == 0xaf) { /* WAP short-integer-encoded */
2553 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2554 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen);
2556 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2558 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2559 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2560 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2563 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2566 MSG_DEBUG("integerValue = [%02x]", integerValue);
2568 int count = sizeof(wspHeaderApplId)/sizeof(SMS_3GPP_WSP_HEADER_PARAMETER_S);
2569 for (int i = 0; i < count ; ++i) {
2570 if ((unsigned int)integerValue == wspHeaderApplId[i].parameterCode) {
2571 snprintf((char*)temp, 64, "%s", wspHeaderApplId[i].parameterToken);
2572 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2578 /* Accept-Application */
2580 if (0x80 == fieldValue[0]) {
2581 strncat((char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2583 unsigned char temp[16];
2585 if ((fieldValueLen == 2) && (fieldValue[0] == 1))
2586 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[0]);
2589 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2590 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2598 /* if-unmodified-since */
2602 /* if-modified-since */
2608 char* decodedString = NULL;
2609 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2610 wspHeaderDecodeDateValue(fieldValueLen, fieldValue, &decodedString);
2611 strncat((char*)temper, (char*)decodedString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2617 if (fieldValue[0] == 0x80)
2618 strncat((char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2622 if (fieldValue[0] == 0x80)
2623 strncat((char*)temper, "None", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2624 if (fieldValue[0] == 0x81)
2625 strncat((char*)temper, "Bytes", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2629 unsigned char temp[1275];
2630 memcpy(temp, fieldValue, (size_t)fieldValueLen);
2631 temp[fieldValueLen] = 0;
2632 wspHeaderCopyDecodedString(temp, ¤tLength, &temper);
2638 /* proxy - authorization */
2640 if (fieldValue[0] == 0x80) {
2641 char* addString = NULL;
2642 unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2643 wspHeaderDecodeAuth(fieldValueLen, fieldValue, &addString);
2644 strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2646 iField = AcStrlen((char*)fieldValue) + 1;
2648 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2649 if (iField < fieldValueLen) {
2651 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2652 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, ¶m);
2653 if (param != NULL) {
2654 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2655 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2665 /* Proxy-authenticate */
2667 if (0 == fieldValueLen)
2669 if (fieldValue[0] == 0x80) {
2670 char* addString = NULL;
2671 unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2672 wspHeaderDecodeChallenge(fieldValueLen, fieldValue, &addString);
2673 strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2675 unsigned char authScheme[WSP_STANDARD_STR_LEN_MAX + 1];
2676 unsigned char realmValue[WSP_STANDARD_STR_LEN_MAX];
2677 unsigned char addedString[WSP_STANDARD_STR_LEN_MAX];
2679 strncpy((char*)authScheme, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX -1);
2680 iField = AcStrlen((char*)authScheme) + 1;
2681 strncpy((char*)realmValue, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2682 iField = iField + AcStrlen((char*)realmValue) + 1;
2683 int wrn = snprintf((char*)addedString, sizeof(addedString), "%s %s", authScheme, realmValue);
2685 MSG_DEBUG("snprintf was failed");
2686 wspHeaderCopyDecodedString(addedString, ¤tLength, &temper);
2688 if (iField < fieldValueLen) {
2690 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2691 wspHeaderDecodeParameter(fieldValue + iField, fieldValueLen - iField, ¶m);
2692 if (param != NULL) {
2693 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2694 wspHeaderCopyDecodedString((unsigned char*)param, ¤tLength, &temper);
2700 /* content -range */
2702 unsigned long first, len, last;
2704 unsigned char temp[16];
2707 strncat((char*)temper, " bytes ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2709 first = wspRetriveUintvarDecode(fieldValue, &iField);
2710 len = wspRetriveUintvarDecode(fieldValue, &iField);
2711 /* 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.
2713 last = first + contentsLength - 1;
2715 snprintf((char*)temp, sizeof(temp), "%u-%u/%u", (unsigned int)first, (unsigned int)last, (unsigned int)len);
2716 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2722 char* cacheString = NULL;
2723 unique_ptr<char*, void(*)(char**)> cacheStringbuf(&cacheString, unique_ptr_deleter);
2725 wspHeaderDecodeCacheControl(fieldValue, fieldValueLen, &cacheString);
2726 strncat((char*)temper, (char*)cacheString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2732 if (fieldValue[0] == 0x80) {
2733 strncat((char*)temper, (char*)wspCacheControl[0], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2735 if (1 < fieldValueLen) {
2737 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2738 wspHeaderDecodeParameter(fieldValue, fieldValueLen, ¶m);
2740 if (param != NULL) {
2741 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2742 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2752 unsigned long i = 0;
2753 while (wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen) != wspMethodType[i].methodCode) i++;
2754 strncat((char*)temper, (char*)wspMethodType[i].methodName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2759 strncat((char*)temper, "bytes=", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2760 if (fieldValue[0] == 0x80) {
2761 unsigned char temp[16];
2762 unsigned long first, last;
2765 first = wspRetriveUintvarDecode(fieldValue, &iField);
2766 last = wspRetriveUintvarDecode(fieldValue, &iField);
2768 snprintf((char*)temp, sizeof(temp), "%u-%u", (unsigned int)first, (unsigned int)last);
2769 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2771 if (fieldValue[0] == 0x81) {
2772 unsigned char temp[16];
2773 unsigned long suffix;
2775 suffix = wspRetriveUintvarDecode(fieldValue, &iField);
2777 snprintf((char*)temp, sizeof(temp), "-%u", (unsigned int)suffix);
2782 if (fieldValue[0] == 0x80) {
2784 unique_ptr<char*, void(*)(char**)> tempbuf(&temp, unique_ptr_deleter);
2786 wspHeaderDecodeDateValue(fieldValueLen - 1, fieldValue + 1, &temp);
2787 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2790 if (fieldValue[0] == 0x81) {
2791 unsigned char temp[16];
2793 snprintf((char*)temp, 16, "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2794 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2797 /* transfer-encoding */
2799 /* No other cases allowed */
2800 if (fieldValue[0] == 0x80)
2801 strncat((char*)temper, "chunked", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2806 int integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2807 if (integerValue > wspHeaderFieldCount) {
2808 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x%x).\n", wspHeaderFieldCount);
2811 strncat((char*)temper, (char*)wspHeaderFieldName[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2816 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2818 if (fieldValue[0] < 0x20)
2819 iField = fieldValue[0];
2823 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, iField));
2824 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2825 if (iField < fieldValueLen) {
2826 unsigned char agent[WSP_STANDARD_STR_LEN_MAX];
2827 unsigned char text[WSP_STANDARD_STR_LEN_MAX];
2828 strncpy((char*)agent, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2829 iField = iField + AcStrlen((char*)agent) + 1;
2830 strncpy((char*)text, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2831 int wrn = snprintf((char*)temp, sizeof(temp), " %s %s", agent, text);
2833 MSG_DEBUG("snprintf was failed");
2834 wspHeaderCopyDecodedString(temp, ¤tLength, &temper);
2838 /* content-disposition */
2840 if (fieldValue[0] == 0x80)
2841 strncat((char*)temper, "form-data", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2843 if (fieldValue[0] == 0x81)
2844 strncat((char*)temper, "attachment", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2846 if (1 < fieldValueLen) {
2848 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2849 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, ¶m);
2851 if (param != NULL) {
2852 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2853 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2859 temper[AcStrlen((char*)temper) + fieldValueLen] = '\0';
2860 memcpy(temper, fieldValue, (size_t)fieldValueLen);
2862 /* Profile-Warning */
2864 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2866 snprintf((char*)temp, sizeof(temp), "%lX", wspHeaderDecodeInteger(fieldValue));
2868 temp[1] = (unsigned char)0x30;
2870 if (fieldValueLen > 1) {
2871 /* copy warn-target - URI */
2872 strncat((char*)temp, (char*)(fieldValue + 1), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2873 if (fieldValueLen > (AcStrlen((char*)(fieldValue + 1)) + 1)) {
2874 /* copy warn-date */
2875 char* decodedString = NULL;
2876 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2877 wspHeaderDecodeDateValue(fieldValueLen - (AcStrlen((char*)(fieldValue + 1)) + 2), fieldValue + AcStrlen((char*)(fieldValue + 1)) + 1, &decodedString);
2878 strncat((char*)temp, (char*)decodedString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2881 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2890 /* It deosn't finished decoding yet. */
2891 if ((iEncodedHeader < encodedHeaderLen) && (fieldCode != 0xff)) {
2892 /* In here, iEncodedHeader already point next field code to be decoded. */
2893 /* If this code is same, then set continueField else add CRLF. */
2894 if (fieldCode == (encodedHeader[iEncodedHeader] & 0x7f)) {
2895 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2896 continueField = TRUE;
2898 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2899 continueField = FALSE;
2902 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2905 /* add single header to total headers */
2906 strncat((char*)outTemper, (char*)temper, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)outTemper)-1);
2907 MSG_DEBUG("WspLDecodeHeader: Single Header : %s\r\n", temper);
2910 MSG_DEBUG("WspLDecodeHeader: Header decoding ended.\n");
2912 *pHeader = outTemper;
2918 unsigned long Sms3gppWapPushHandler::wspHeaderDecodeInteger(unsigned char* data)
2920 /* we only can handle max 32bit integer */
2924 unsigned long integer;
2925 unsigned char seg[4];
2928 returner.integer = 0;
2930 if (data[0] < 0x80) {
2931 unsigned long IntLen = 0;
2933 IntLen = (data[0] > 0x04) ? 0x04:data[0];
2935 MSG_DEBUG("WspLHeaderDecodeInteger: input %d , length %lu\n", data[0], IntLen);
2937 for (i = 0; i < IntLen; i++)
2938 returner.seg[IntLen-(i+1)] = data[i+1];
2940 return returner.integer;
2943 return data[0] & 0x7f;
2947 void Sms3gppWapPushHandler::wspHeaderDecodeQValue(unsigned long length, unsigned char* data, char** pDecodedString)
2949 unsigned short qBase = 0;
2952 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2953 if (*pDecodedString == NULL) {
2954 MSG_DEBUG("WspLHeaderDecodeQValue:MemAlloc failed\n");
2958 memcpy(&qBase, data, (size_t)length);
2959 qValue = (float)qBase;
2961 qValue = qValue - 100;
2962 qValue = qValue / 1000;
2963 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.3f", qValue);
2965 /* qValue variable is divided by 100. And it's multiplied by 100.
2966 It's to resolve problem of changed 0.01 of qValue. */
2967 unsigned long qValueTemp;
2968 qValue = qValue - 1;
2969 qValue = qValue / 100;
2970 qValueTemp = (unsigned long)(qValue * 100);
2971 if (0 == (qValueTemp % 10))
2972 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.1f", qValue);
2974 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.2f", qValue);
2980 unsigned long Sms3gppWapPushHandler::wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length)
2985 unsigned long integer;
2986 unsigned short seg[4];
2989 returner.integer = 0;
2992 return data[0] & 0x7f;
2994 returner.integer = 0;
2996 for (i = 0 ; i < length; i++) {
2997 returner.integer = returner.integer + (data[i] * (0x1 << ((length - (i + 1)) * 8)));
2998 MSG_DEBUG("WspLHeaderDecodeIntegerByLength: %lu \n", returner.integer);
3001 return returner.integer;
3005 char* Sms3gppWapPushHandler::wspExtendedDecodeType(char contentType)
3009 while (wspExtendedContentsType[i].contentsTypeCode != contentType) {
3010 if (wspExtendedContentsType[i].contentsTypeCode == 0xff)
3015 return (char*)wspExtendedContentsType[i].contentsTypeName;
3019 void Sms3gppWapPushHandler::wspHeaderDecodeParameter(unsigned char* data, unsigned long length, char** pParam)
3021 char* param = *pParam;
3023 unsigned long SecurityTypeCode;
3024 unsigned long i = 0;
3026 if (data[0] < 0x80) {
3027 /* unknown parameter type */
3028 param = new char[WSP_STANDARD_STR_LEN_MAX];
3030 if (param == NULL) {
3031 MSG_DEBUG("WspLHeaderDecodeParameter:MemAlloc failed\n");
3035 strncpy((char*)param, (char*)data, WSP_STANDARD_STR_LEN_MAX - 1);
3037 if (NO_VALUE == data[AcStrlen((char*)param) + 1]) {
3042 strncat((char*)param, "=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3043 strncat((char*)param, (char*)(data + strlen((char*)param)), WSP_STANDARD_STR_LEN_MAX-strlen((char*)param)-1);
3050 switch (data[0] & 0x7f) {
3052 wspHeaderDecodeQValue(length - 1, data + 1, ¶m);
3055 wspHeaderDecodeCharset(length - 1 , data + 1, ¶m);
3058 wspHeaderDecodeVersion(length - 1, data + 1, ¶m);
3062 /* param = (unsigned char *)malloc((size_t)WSP_STANDARD_STR_LEN_MAX); */
3063 param = new char[WSP_STANDARD_STR_LEN_MAX];
3064 if (param == NULL) {
3065 MSG_DEBUG("WspLHeaderDecodeParameter: 0x03 MemAlloc failed\n");
3068 snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Type=%i", (int)wspHeaderDecodeInteger(data + 1));
3072 param = new char[WSP_STANDARD_STR_LEN_MAX];
3074 if (param == NULL) {
3075 MSG_DEBUG("WspLHeaderDecodeParameter:0x08 MemAlloc failed\n");
3078 snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Padding=%i", (int)wspHeaderDecodeInteger(data + 1));
3082 param = new char[WSP_STANDARD_STR_LEN_MAX];
3084 if (param == NULL) {
3085 MSG_DEBUG("WspLHeaderDecodeParameter:0x05 MemAlloc failed\n");
3088 strncpy((char*)param, "Name=", WSP_STANDARD_STR_LEN_MAX-1);
3089 memcpy(param + 5, data + 1, length - 1);
3090 param[5 + length - 1] = '\0';
3094 param = new char[WSP_STANDARD_STR_LEN_MAX];
3096 if (param == NULL) {
3097 MSG_DEBUG("WspLHeaderDecodeParameter:0x06 MemAlloc failed\n");
3100 strncpy((char*)param, "Filename=", WSP_STANDARD_STR_LEN_MAX-1);
3101 memcpy(param + 9, (char*)(data + 1), (size_t)(length - 1));
3102 param[9 + length - 1] = '\0';
3109 /*OMA Provisioning*/
3111 param = new char[WSP_STANDARD_STR_LEN_MAX];
3113 if (param == NULL) {
3114 MSG_DEBUG("WspLHeaderDecodeParameter:0x11 MemAlloc failed\n");
3117 strncpy((char*)param, "SEC=", WSP_STANDARD_STR_LEN_MAX-1);
3118 SecurityTypeCode = data[1] & 0x7f;
3119 while ((i < wspSecurityTypeCount) && (wspSecurityType[i].SecurityTypeCode != SecurityTypeCode)) i++;
3121 if (i < wspSecurityTypeCount) {
3122 strncat((char*)param, (char*)wspSecurityType[i].SecurityTypeName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3125 if (0x12 == (data[2] & 0x7f)) {
3126 strncat((char*)param, "; MAC=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3127 memcpy(param+AcStrlen((char*)param), (char*)(data+3), (size_t)length-3);
3141 void Sms3gppWapPushHandler::wspHeaderDecodeCharset(unsigned long length, unsigned char* data, char**pDecodedString)
3145 param = new char[WSP_STANDARD_STR_LEN_MAX];
3146 if (param == NULL) {
3147 MSG_DEBUG("WspLHeaderDecodeCharset:MemAlloc failed\n");
3148 *pDecodedString = NULL;
3152 strncpy((char*)param, "charset=", WSP_STANDARD_STR_LEN_MAX-1);
3154 if (data[0] > 0x80) {
3155 unsigned long code = wspHeaderDecodeInteger(data);
3156 unsigned long i = 0;
3157 while (wspCharset[i].charsetCode != code) {
3158 if (wspCharset[i].charsetCode == 0xffff) {
3159 *pDecodedString = param;
3164 strncat((char*)param, (char*)wspCharset[i].charsetName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3166 unsigned long lastLen = AcStrlen((char*)param);
3167 if (length + lastLen < WSP_STANDARD_STR_LEN_MAX - 1) {
3168 memcpy((char*)(param + lastLen), data, (size_t)length);
3169 param[length + lastLen] = '\0';
3171 memcpy((char*)(param + lastLen), data, WSP_STANDARD_STR_LEN_MAX - lastLen - 1);
3172 param[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3176 *pDecodedString = param;
3181 void Sms3gppWapPushHandler::wspHeaderDecodeVersion(unsigned long length, unsigned char* data, char** pDecodedString)
3183 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3185 if (*pDecodedString == NULL) {
3186 MSG_DEBUG("WspLHeaderDecodeVersion:MemAlloc failed\n");
3191 /* untyped version */
3192 memcpy(*pDecodedString, data, (size_t)length);
3195 unsigned char majorVer = ((data[0] & 0x7f) >> 4);
3196 unsigned char minorVer = data[0] & 0x0f;
3197 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "level=%u.%u", majorVer, minorVer);
3204 void Sms3gppWapPushHandler::wspHeaderDecodeDateValue(unsigned long length, unsigned char* data, char** pDecodedString)
3209 MSG_DEBUG("WspLHeaderDecodeDateValue: \n");
3211 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3213 if (*pDecodedString == NULL) {
3214 MSG_DEBUG("WspLHeaderDecodeDateValue:MemAlloc failed\n");
3218 lTime = wspHeaderDecodeIntegerByLength(data, length);
3220 (struct tm*)gmtime_r((const time_t*)&lTime, &pTMData);
3222 /* check date value validity */
3223 if ((pTMData.tm_wday > 6) || (pTMData.tm_mon > 11) || (pTMData.tm_mday > 31)) {
3224 MSG_DEBUG("WspLHeaderDecodeDateValue: Date decode fail %d, %d, %d \n", pTMData.tm_wday, pTMData.tm_mon, pTMData.tm_mday);
3225 strncpy((char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
3229 #ifdef MSG_FW_FOR_DEBUG
3230 /** Date type selection */
3231 switch (wspMachineStatus.dateType) {
3232 /* UNIX asciitime function */
3233 case UNIX_DATE_TYPE:
3234 snprintf((char*)decodedString, sizeof(decodedString), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData.tm_wday], wspMonth[pTMData.tm_mon],
3235 pTMData.tm_mday, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec, pTMData.tm_year + 1900);
3237 case RFC1123_DATE_TYPE:
3238 snprintf((char*)decodedString, sizeof(decodedString), "%s, %u %s %u %u:%u:%u GMT", wspWeek[pTMData.tm_wday], pTMData.tm_mday,
3239 wspMonth[pTMData.tm_mon], pTMData.tm_year + 1900, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec);
3241 case RFC850_DATE_TYPE:
3242 /* Have some Y2K Problems */
3243 /* 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. */
3244 snprintf((char*)decodedString, sizeof(decodedString), "%s, %2u-%s-%2u %u:%u:%u GMT", wspWeekDay[pTMData.tm_wday], pTMData.tm_mday,
3245 wspMonth[pTMData.tm_mon], pTMData.tm_year % CENTURY, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec);
3250 /**UNIX_DATE_TYPE : */
3251 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],
3252 pTMData.tm_mday, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec, pTMData.tm_year + 1900);
3257 void Sms3gppWapPushHandler::wspHeaderCopyDecodedString(unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper)
3259 unsigned long elementLen = AcStrlen((char*)szDecodedString);
3260 char* temper2 = NULL;
3263 *currentLen = *currentLen + elementLen + 2;
3265 if (*currentLen > AcStrlen((char*)* pTemper) + 2) {
3266 temper2 = new char[(*currentLen + 1)];
3268 if (temper2 == NULL) {
3269 MSG_DEBUG("WspLHeaderCopyDecodedString:MemAlloc failed\n");
3272 strncpy((char*)temper2, (char*)* pTemper, *currentLen);
3274 strncpy((char*)temper2, (char*)szDecodedString, *currentLen);
3283 void Sms3gppWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3285 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3286 unsigned char passWd[WSP_STANDARD_STR_LEN_MAX];
3287 unsigned long iField = 0;
3290 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX * 2];
3292 if (*pDecodedString == NULL) {
3293 MSG_DEBUG("WspLHeaderDecodeAuth:MemAlloc failed\n");
3297 /* skip 'basic' code */
3299 memset(authStr, 0x00, sizeof(authStr));
3300 snprintf(authStr, sizeof(authStr), "%%%zus", sizeof(userId));
3301 sscanf((char*)(fieldValue + iField), authStr, userId);
3302 iField = iField + AcStrlen((char*)userId) + 1;
3303 memset(authStr, 0x00, sizeof(authStr));
3304 snprintf(authStr, sizeof(authStr), "%%%zus", sizeof(passWd));
3305 sscanf((char*)(fieldValue + iField), authStr, passWd);
3306 iField = iField + AcStrlen((char*)userId) + 1;
3307 int wrn = snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX*2), "basic %s/%s", userId, passWd);
3309 MSG_DEBUG("snprintf was failed\n");
3315 void Sms3gppWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3317 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3318 unsigned long iField = 0;
3321 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3323 if (*pDecodedString == NULL) {
3324 MSG_DEBUG("WspLHeaderDecodeChallenge:MemAlloc failed\n");
3328 /* skip 'basic' code */
3330 memset(authStr, 0x00, sizeof(authStr));
3331 snprintf(authStr, sizeof(authStr), "%%%zus", sizeof(userId));
3332 sscanf((char*)(fieldValue + iField), authStr, userId);
3333 iField = iField + AcStrlen((char*)userId) + 1;
3335 int wrn = snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "basic realm=\"%s\"", userId);
3337 MSG_DEBUG("snprintf was failed\n");
3343 void Sms3gppWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString)
3345 unsigned char paramString[WSP_STANDARD_STR_LEN_MAX];
3346 unsigned char cacheCode;
3349 *pCacheString = new char[WSP_STANDARD_STR_LEN_MAX];
3350 if (*pCacheString == NULL) {
3351 MSG_DEBUG("WspLHeaderDecodeCacheControl:MemAlloc failed\n");
3355 if (1 == fieldValueLen) {
3356 /* only one directive */
3357 if (fieldValue[0] > 0x8b) {
3358 return; /* It's error detection. can be omitted. */
3360 strncpy((char*)*pCacheString, (char*)wspCacheControl[fieldValue[0] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3364 if (fieldValue[0] > 0x7f) {
3365 /* directive that has parameter */
3366 cacheCode = fieldValue[0] & 0x7f;
3367 switch (cacheCode) {
3373 if (fieldValue[1] > 0x7f) {
3374 /* well known field name */
3375 strncpy((char*)paramString, (char*)wspHeaderFieldName[fieldValue[1] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3376 paramString[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3378 /* unknown field name */
3379 strncpy((char*)paramString, (char*)fieldValue + 1 , WSP_STANDARD_STR_LEN_MAX-1);
3389 snprintf((char*)paramString, sizeof(paramString), "%u", (unsigned int)wspHeaderDecodeInteger(fieldValue + 1));
3395 wrn = snprintf((char*)*pCacheString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString);
3397 MSG_DEBUG("snprintf was failed");
3399 /* cache extentions */
3400 /* In case of come directive of doesn't specified string style */
3402 unsigned long stringLen;
3404 strncpy((char*)*pCacheString, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX-1);
3405 stringLen = AcStrlen((char*)*pCacheString);
3407 if (stringLen + 1 < fieldValueLen) {
3408 if (fieldValue[stringLen+ 1] > 0x7f) {
3409 int untyped = (int)wspHeaderDecodeIntegerByLength(fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1));
3411 snprintf(szString, sizeof(szString), "%d", untyped);
3412 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3413 strncat((char*)*pCacheString, (char*)szString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3415 if (fieldValue[fieldValueLen] == 0) {
3416 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3417 strncat((char*)*pCacheString, (char*)fieldValue + stringLen + 1 , WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3426 void Sms3gppWapPushHandler::getDisplayName(MSG_SUB_TYPE_T subType, char* displayName)
3428 if (subType == MSG_WAP_SL_SMS || subType == MSG_WAP_SI_SMS)
3429 snprintf(displayName, MAX_ADDRESS_VAL_LEN + 1, "Push message");