2 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "MsgCppTypes.h"
19 #include "MsgGconfWrapper.h"
20 #include "MsgException.h"
21 #include "MsgUtilFile.h"
22 #include "SmsCdmaPluginStorage.h"
23 #include "SmsCdmaPluginTransport.h"
24 #include "SmsCdmaPluginEventHandler.h"
25 #include "SmsCdmaPluginWapPushHandler.h"
30 #include <drm_client.h>
33 static unsigned short wapPushPortList[] = {0x0b84, 0x0b85, 0x23F0, 0x23F1, 0x23F2, 0x23F3, 0xC34F};
35 char gWapCodeBufferLeft[WSP_CODE_BUFFER_LEFT_LEN_MAX];
36 char gWapCodeBufferRight[WSP_CODE_BUFFER_RIGHT_LEN_MAX];
38 const unsigned long wspUintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00200000, 0x10000000};
40 const unsigned char wspHeaderFieldCount = 0x43;
41 const unsigned char wspContentsTypeCount = 0x34;
42 const unsigned long wspLanguageCount = 0x11a;
43 const unsigned char wspSecurityTypeCount = 0x04;
46 static const SMS_WSP_CONTENTS_TYPE_S wspExtendedContentsType[] = {
47 { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
48 { (char*)"application/vnd.wap.connectivity-wbxml", 0x36 },
49 { (char*)"application/pkcs7-mime", 0x37 },
50 { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
51 { (char*)"application/vnd.wap.signed-certificate", 0x39 },
52 { (char*)"application/vnd.wap.cert-response", 0x3A },
53 { (char*)"application/xhtml+xml", 0x3B },
54 { (char*)"application/wml+xml", 0x3C },
55 { (char*)"text/css", 0x3D },
57 { (char*)"application/vnd.wap.mms-message", 0x3E },
59 { (char*)"application/vnd.wap.rollover-certificate", 0x3F },
60 { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
61 { (char*)"application/vnd.wap.loc+xml", 0x41 },
62 { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
63 { (char*)"application/vnd.syncml.dm+xml", 0x43 },
64 { (char*)"application/vnd.syncml.notification", 0x44 },
65 { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
66 { (char*)"application/vnd.wv.csp.cir", 0x46 },
68 { (char*)"application/vnd.oma.dd+xml", 0x47},
69 { (char*)"application/vnd.oma.drm.message", 0x48 },
70 { (char*)"application/vnd.oma.drm.content", 0x49 },
71 { (char*)"application/vnd.oma.drm.rights+xml", 0x4A },
72 { (char*)"application/vnd.oma.drm.rights+wbxml", 0x4B },
73 { (char*)"application/vnd.syncml.ds.notification", 0x4E},
74 { (char*)"application/mikey", 0x52},
79 const char* wspHeaderFieldName[] = {
80 (char*)"Accept", /* 0x00 */
81 (char*)"Accept-Charset",
82 (char*)"Accept-Encoding",
83 (char*)"Accept-Language",
84 (char*)"Accept-Ranges",
85 (char*)"Age", /* 0x05 */
87 (char*)"Authorization",
88 (char*)"Cache-Control",
90 (char*)"Content-Base", /* 0x0a */
91 (char*)"Content-Encoding",
92 (char*)"Content-Language",
93 (char*)"Content-Length",
94 (char*)"Content-Location",
96 (char*)"Content-Range", /* 0x10 */
97 (char*)"Content-Type",
101 (char*)"From", /* 0x15 */
103 (char*)"If-Modified-Since",
105 (char*)"If-None-Match",
106 (char*)"If-Range", /* 0x1a */
107 (char*)"If-Unmodified-Since",
109 (char*)"Last-Modified",
110 (char*)"Max-Forwards",
112 (char*)"Proxy-Authenticate", /* 0x20 */
113 (char*)"Proxy-Authorization",
117 (char*)"Retry-After", /* 0x25 */
119 (char*)"Transfer-Encodig",
122 (char*)"Vary", /* 0x2a */
125 (char*)"Www-Authenticate",
126 (char*)"Content-Disposition",
127 (char*)"X-Wap-Application-Id",
128 (char*)"X-Wap-Content-URI", /* 0x30 */
129 (char*)"X-Wap-Iinitiator-URI",
130 (char*)"Accept-Application", /* Back */
131 (char*)"Bearer-Indication",
133 (char*)"Profile", /* 0x35 */
134 (char*)"Profile-Diff",
135 (char*)"Profile-Warning", /* end of WAP 1.2 */
138 (char*)"Trailer", /* 0x3a */
139 (char*)"Accept-Charset", /* Back */
140 (char*)"Accept-Encoding", /* Back */
141 (char*)"Cache-Control", /* back */
142 (char*)"Content-Range",
144 (char*)"Content-ID", /*x40 */
147 (char*)"Encoding-Version"
151 const SMS_WSP_CHARSET_S wspCharset[] = {
152 { (char*)"big5", 0x07ea },
153 { (char*)"iso-10646-ucs-2", 0x03e8 },
154 { (char*)"iso-8859-1", 0x04 },
155 { (char*)"iso-8859-2", 0x05 },
156 { (char*)"iso-8859-3", 0x06 },
157 { (char*)"iso-8859-4", 0x07 },
158 { (char*)"iso-8859-5", 0x08 },
159 { (char*)"iso-8859-6", 0x09 },
160 { (char*)"iso-8859-7", 0x0a },
161 { (char*)"iso-8859-8", 0x0b },
162 { (char*)"iso-8859-9", 0x0c },
163 { (char*)"shift-JIS", 0x11 },
164 { (char*)"us-ascii", 0x03 },
165 { (char*)"utf-8", 0x6a },
166 { (char*)"none", 0x26 },
167 { (char*)"", 0xffff }
171 const char* wspEncodeMethod[] = {
178 const SMS_WSP_CONTENTS_TYPE_S wspContentsType[] = {
179 { (char*)"*/*", 0x00 },
180 { (char*)"text/*", 0x01 },
181 { (char*)"text/html", 0x02 },
182 { (char*)"text/plain", 0x03 },
183 { (char*)"text/x-hdml", 0x04 },
184 { (char*)"text/x-ttml", 0x05 },
185 { (char*)"text/x-vCalendar", 0x06 },
186 { (char*)"text/x-vCard", 0x07 },
187 { (char*)"text/vnd.wap.wml", 0x08 },
188 { (char*)"text/vnd.wap.wmlscript", 0x09 },
189 { (char*)"text/vnd.wap.wta-event", 0x0a },
190 { (char*)"multipart/*", 0x0b },
191 { (char*)"multipart/mixed", 0x0c },
192 { (char*)"multipart/form-data", 0x0d },
193 { (char*)"multipart/byteranges", 0x0e },
194 { (char*)"multipart/alternative", 0x0f },
195 { (char*)"application/*", 0x10 },
196 { (char*)"application/java-vm", 0x11 },
197 { (char*)"application/x-www-form-urlencoded", 0x12 },
198 { (char*)"application/x-hdmlc", 0x13 },
199 { (char*)"application/vnd.wap.wmlc", 0x14 },
200 { (char*)"application/vnd.wap.wmlscriptc", 0x15 },
201 { (char*)"application/vnd.wap.wta-eventc", 0x16 },
202 { (char*)"application/vnd.wap.uaprof", 0x17 },
203 { (char*)"application/vnd.wap.wtls-ca-certificate", 0x18 },
204 { (char*)"application/vnd.wap.wtls-user-certificate", 0x19 },
205 { (char*)"application/x-x509-ca-cert", 0x1a },
206 { (char*)"application/x-x509-user-cert", 0x1b },
207 { (char*)"image/*", 0x1c },
208 { (char*)"image/gif", 0x1d },
209 { (char*)"image/jpeg", 0x1e },
210 { (char*)"image/tiff", 0x1f },
211 { (char*)"image/png", 0x20 },
212 { (char*)"image/vnd.wap.wbmp", 0x21 },
213 { (char*)"application/vnd.wap.multipart.*", 0x22 },
214 { (char*)"application/vnd.wap.multipart.mixed", 0x23 },
215 { (char*)"application/vnd.wap.multipart.form-data", 0x24 },
216 { (char*)"application/vnd.wap.multipart.byteranges", 0x25 },
217 { (char*)"application/vnd.wap.multipart.alternative", 0x26 },
218 { (char*)"application/xml", 0x27 },
219 { (char*)"text/xml", 0x28 },
220 { (char*)"application/vnd.wap.wbxml", 0x29 },
221 { (char*)"application/x-x968-cross-cert", 0x2a },
222 { (char*)"application/x-x968-ca-cert", 0x2b },
223 { (char*)"application/x-x968-user-cert", 0x2c },
224 { (char*)"text/vnd.wap.si", 0x2d },
225 { (char*)"application/vnd.wap.sic", 0x2e },
226 { (char*)"text/vnd.wap.sl", 0x2f },
227 { (char*)"application/vnd.wap.slc", 0x30 },
228 { (char*)"text/vnd.wap.co", 0x31 },
229 { (char*)"application/vnd.wap.coc", 0x32 },
230 { (char*)"application/vnd.wap.multipart.related", 0x33 },
231 { (char*)"application/vnd.wap.sia", 0x34 },
233 { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
234 { (char*)"application/vnd.connectivity-wbxml", 0x36 },
235 { (char*)"application/pkcs7-mime", 0x37 },
236 { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
237 { (char*)"application/vnd.wap.signed-certificate", 0x39 },
238 { (char*)"application/vnd.wap.cert-response", 0x3A },
239 { (char*)"application/xhtml+xml", 0x3B },
240 { (char*)"application/wml+xml", 0x3C },
241 { (char*)"text/css", 0x3D },
243 { (char*)"application/vnd.wap.mms-message", 0x3E },
245 { (char*)"application/vnd.wap.rollover-certificate", 0x3F },
246 { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
247 { (char*)"application/vnd.wap.loc+xml", 0x41 },
248 { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
249 { (char*)"application/vnd.syncml.dm+xml", 0x43 },
250 { (char*)"application/vnd.syncml.notification", 0x44 },
251 { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
252 { (char*)"application/vnd.wv.csp.cir", 0x46 }
256 static const SMS_WAP_UNREGISTER_CONTENTS_TYPE_S wspUnregisterContentsType[]= {
257 { (char*)"application/vnd.wap.emn+wbxml", 0x30A},
258 { (char*)"application/vnd.omaloc-supl-init", 0x312},
259 { (char*)"application/vnd.oma.drm.roap-trigger+wbxml", 0x316}
263 const unsigned long wspUnregisteredContentsTypeCount = sizeof(wspUnregisterContentsType)/sizeof(SMS_WAP_UNREGISTER_CONTENTS_TYPE_S);
266 const SMS_WSP_LANGUAGE_S wspLanguage[] = {
267 { (char*)"English", 0x19 },
268 { (char*)"en", 0x19 },
269 { (char*)"Korean", 0x3d },
270 { (char*)"*", 0x00 },
271 { (char*)"Afar", 0x01 },
272 { (char*)"aa", 0x01 },
273 { (char*)"Abkhazian", 0x02 },
274 { (char*)"ab", 0x02 },
275 { (char*)"Afrikaans", 0x03 },
276 { (char*)"af", 0x03 },
277 { (char*)"Amharic", 0x04 },
278 { (char*)"am", 0x04 },
279 { (char*)"Arabic", 0x05 },
280 { (char*)"ar", 0x05 },
281 { (char*)"Assamese", 0x06 },
282 { (char*)"as", 0x06 },
283 { (char*)"Aymara", 0x07 },
284 { (char*)"ay", 0x07 },
285 { (char*)"Azerbaijani", 0x08 },
286 { (char*)"az", 0x08 },
287 { (char*)"Bashkir", 0x09 },
288 { (char*)"ba", 0x09 },
289 { (char*)"Byelorussian", 0x0a },
290 { (char*)"be", 0x0a },
291 { (char*)"Bulgarian", 0x0b },
292 { (char*)"bg", 0x0b },
293 { (char*)"Bihari", 0x0c },
294 { (char*)"bh", 0x0c },
295 { (char*)"Bislama", 0x0d },
296 { (char*)"bi", 0x0f },
297 { (char*)"Bengali", 0x0e },
298 { (char*)"Bangla", 0x0e },
299 { (char*)"bn", 0x0e },
300 { (char*)"Tibetan", 0x0f },
301 { (char*)"bo", 0x0f },
302 { (char*)"Breton", 0x10 },
303 { (char*)"br", 0x10 },
304 { (char*)"Catalan", 0x11 },
305 { (char*)"ca", 0x11 },
306 { (char*)"Corsican", 0x12 },
307 { (char*)"co", 0x12 },
308 { (char*)"Czech", 0x13 },
309 { (char*)"cs", 0x13 },
310 { (char*)"Welsh", 0x14 },
311 { (char*)"cy", 0x14 },
312 { (char*)"Denish", 0x15 },
313 { (char*)"da", 0x15 },
314 { (char*)"German", 0x16 },
315 { (char*)"de", 0x16 },
316 { (char*)"Bhutani", 0x17 },
317 { (char*)"dz", 0x17 },
318 { (char*)"Greek", 0x18 },
319 { (char*)"el", 0x18 },
320 { (char*)"Esperanto", 0x81 },
321 { (char*)"eo", 0x1a },
322 { (char*)"Spanish", 0x1b },
323 { (char*)"es", 0x1b },
324 { (char*)"Estonian", 0x1c },
325 { (char*)"et", 0x1c },
326 { (char*)"Basque", 0x1d },
327 { (char*)"eu", 0x1d },
328 { (char*)"Persian", 0x1e },
329 { (char*)"fa", 0x1e },
330 { (char*)"Finnish", 0x1f },
331 { (char*)"fi", 0x1f },
332 { (char*)"Fiji", 0x20 },
333 { (char*)"fj", 0x20 },
334 { (char*)"Faeroese", 0x82 },
335 { (char*)"fo", 0x82 },
336 { (char*)"French", 0x22 },
337 { (char*)"fr", 0x22 },
338 { (char*)"Frisian", 0x83 },
339 { (char*)"fy", 0x83 },
340 { (char*)"Irish", 0x24 },
341 { (char*)"ga", 0x24 },
342 { (char*)"Scots Gaelic", 0x25 },
343 { (char*)"gd", 0x25 },
344 { (char*)"Galician", 0x26 },
345 { (char*)"gl", 0x26 },
346 { (char*)"Guarani", 0x27 },
347 { (char*)"gn", 0x27 },
348 { (char*)"Gujarati", 0x28 },
349 { (char*)"gu", 0x28 },
350 { (char*)"Hausa", 0x29 },
351 { (char*)"ha", 0x29 },
352 { (char*)"Hebrew", 0x2a },
353 { (char*)"he", 0x2a },
354 { (char*)"Hindi", 0x2b },
355 { (char*)"hi", 0x2b },
356 { (char*)"Croatian", 0x2c },
357 { (char*)"hr", 0x2c },
358 { (char*)"Hungarian", 0x2d },
359 { (char*)"hu", 0x2d },
360 { (char*)"Armenian", 0x2e },
361 { (char*)"hy", 0x2e },
362 { (char*)"Interlingua", 0x84 },
363 { (char*)"ia", 0x84 },
364 { (char*)"Indonesian", 0x30 },
365 { (char*)"id", 0x30 },
366 { (char*)"Interlingue", 0x86 },
367 { (char*)"ie", 0x86 },
368 { (char*)"Maori", 0x47 },
369 { (char*)"mi", 0x47 },
370 { (char*)"Macedonian", 0x48 },
371 { (char*)"mk", 0x48 },
372 { (char*)"Malayalam", 0x49 },
373 { (char*)"ml", 0x49 },
374 { (char*)"Mongolian", 0x4a },
375 { (char*)"mn", 0x4a },
376 { (char*)"Moldavian", 0x4b },
377 { (char*)"mo", 0x4d },
378 { (char*)"Marathi", 0x4c },
379 { (char*)"mr", 0x4c },
380 { (char*)"Malay", 0x4d },
381 { (char*)"ms", 0x4d },
382 { (char*)"Maltese", 0x4e },
383 { (char*)"mt", 0x4e },
384 { (char*)"Burmese", 0x4f },
385 { (char*)"my", 0x4f },
386 { (char*)"Nauru", 0x50 },
387 { (char*)"na", 0x50 },
388 { (char*)"Nepali", 0x51 },
389 { (char*)"ne", 0x51 },
390 { (char*)"Dutch", 0x52 },
391 { (char*)"nl", 0x52 },
392 { (char*)"Norwegian", 0x53 },
393 { (char*)"no", 0x53 },
394 { (char*)"Occitan", 0x54 },
395 { (char*)"oc", 0x54 },
396 { (char*)"(Afan) Oromo", 0x55 },
397 { (char*)"(Afan)Oromo", 0x55 },
398 { (char*)"om", 0x55 },
399 { (char*)"Oriya", 0x56 },
400 { (char*)"or", 0x56 },
401 { (char*)"Punjabi", 0x57 },
402 { (char*)"pa", 0x57 },
403 { (char*)"Polish", 0x58 },
404 { (char*)"po", 0x58 },
405 { (char*)"Pashto", 0x59 },
406 { (char*)"Pushto", 0x59 },
407 { (char*)"ps", 0x59 },
408 { (char*)"Portugurse", 0x5a },
409 { (char*)"pt", 0x5a },
410 { (char*)"Quechua", 0x5b },
411 { (char*)"qu", 0x5b },
412 { (char*)"Rhaeto-Romance", 0x8c },
413 { (char*)"rm", 0x8c },
414 { (char*)"Kirundi", 0x5d },
415 { (char*)"rn", 0x5d },
416 { (char*)"Romanian", 0x5e },
417 { (char*)"ro", 0x5e },
418 { (char*)"Russian", 0x5f },
419 { (char*)"ru", 0x5f },
420 { (char*)"Kinyarwanda", 0x60 },
421 { (char*)"rw", 0x60 },
422 { (char*)"Sanskrit", 0x61 },
423 { (char*)"sa", 0x61 },
424 { (char*)"Sindhi", 0x62 },
425 { (char*)"sd", 0x62 },
426 { (char*)"Sangho", 0x63 },
427 { (char*)"sg", 0x63 },
428 { (char*)"Serbo-Croatian", 0x64 },
429 { (char*)"sh", 0x64 },
430 { (char*)"Sinhalese", 0x65 },
431 { (char*)"si", 0x65 },
432 { (char*)"Slovak", 0x66 },
433 { (char*)"sk", 0x66 },
434 { (char*)"Slovenian", 0x67 },
435 { (char*)"sl", 0x67 },
436 { (char*)"Samoan", 0x68 },
437 { (char*)"sm", 0x68 },
438 { (char*)"Shona", 0x69 },
439 { (char*)"sn", 0x69 },
440 { (char*)"Somali", 0x6a },
441 { (char*)"so", 0x6a },
442 { (char*)"Albanian", 0x6b },
443 { (char*)"sq", 0x6b },
444 { (char*)"Serbian", 0x6c },
445 { (char*)"sr", 0x6c },
446 { (char*)"Siswati", 0x6d },
447 { (char*)"ss", 0x6d },
448 { (char*)"Sesotho", 0x6e },
449 { (char*)"st", 0x6e },
450 { (char*)"Sundanese", 0x6f },
451 { (char*)"su", 0x6f },
452 { (char*)"Swedish", 0x70 },
453 { (char*)"sv", 0x70 },
454 { (char*)"Swahili", 0x71 },
455 { (char*)"sw", 0x71 },
456 { (char*)"Tamil", 0x72 },
457 { (char*)"ta", 0x72 },
458 { (char*)"Telugu", 0x73 },
459 { (char*)"te", 0x73 },
460 { (char*)"Tajik", 0x74 },
461 { (char*)"tg", 0x74 },
462 { (char*)"Thai", 0x75 },
463 { (char*)"th", 0x75 },
464 { (char*)"Tigrinya", 0x76 },
465 { (char*)"ti", 0x76 },
466 { (char*)"Turkmen", 0x77 },
467 { (char*)"tk", 0x77 },
468 { (char*)"Inupiak", 0x87 },
469 { (char*)"ik", 0x87 },
470 { (char*)"Icelandic", 0x33 },
471 { (char*)"is", 0x33 },
472 { (char*)"Italian", 0x34 },
473 { (char*)"it", 0x34 },
474 { (char*)"Inuktitut", 0x89 },
475 { (char*)"iu", 0x89 },
476 { (char*)"Japanese", 0x36 },
477 { (char*)"ja", 0x36 },
478 { (char*)"Javanese", 0x37 },
479 { (char*)"jw", 0x37 },
480 { (char*)"Georgian", 0x38 },
481 { (char*)"ka", 0x38 },
482 { (char*)"Kazakh", 0x39 },
483 { (char*)"kk", 0x39 },
484 { (char*)"Gerrnlandic", 0x8a },
485 { (char*)"kl", 0x8a },
486 { (char*)"Cambodian", 0x3b },
487 { (char*)"km", 0x3b },
488 { (char*)"Kannada", 0x3c },
489 { (char*)"kn", 0x3c },
490 { (char*)"Kashmiri", 0x3e },
491 { (char*)"ks", 0x3e },
492 { (char*)"Kurdish", 0x3f },
493 { (char*)"ku", 0x3f },
494 { (char*)"Kirghiz", 0x40 },
495 { (char*)"ky", 0x40 },
496 { (char*)"Latin", 0x8b },
497 { (char*)"la", 0x8b },
498 { (char*)"Lingala", 0x42 },
499 { (char*)"ln", 0x42 },
500 { (char*)"Laothian", 0x43 },
501 { (char*)"lo", 0x43 },
502 { (char*)"Lithuanian", 0x44 },
503 { (char*)"lt", 0x44 },
504 { (char*)"Lavian", 0x45 },
505 { (char*)"Lettish", 0x45 },
506 { (char*)"lv", 0x45 },
507 { (char*)"Malagasy", 0x46 },
508 { (char*)"mg", 0x46 },
509 { (char*)"Tagalog", 0x78 },
510 { (char*)"tl", 0x78 },
511 { (char*)"Setswana", 0x79 },
512 { (char*)"tn", 0x79 },
513 { (char*)"Tonga", 0x7a },
514 { (char*)"to", 0x7a },
515 { (char*)"Turkish", 0x7b },
516 { (char*)"tr", 0x7b },
517 { (char*)"Tsonga", 0x7c },
518 { (char*)"ts", 0x7c },
519 { (char*)"Tatar", 0x7d },
520 { (char*)"tt", 0x7d },
521 { (char*)"Twi", 0x7e },
522 { (char*)"tw", 0x7e },
523 { (char*)"Uighur", 0x7f },
524 { (char*)"ug", 0x7f },
525 { (char*)"Ukrainian", 0x1a },
526 { (char*)"uk", 0x1a },
527 { (char*)"Urdu", 0x21 },
528 { (char*)"ur", 0x21 },
529 { (char*)"Uzbek", 0x23 },
530 { (char*)"uz", 0x23 },
531 { (char*)"Vietnamese", 0x2f },
532 { (char*)"vi", 0x2f },
533 { (char*)"Volapuk", 0x85 },
534 { (char*)"vo", 0x85 },
535 { (char*)"Wolof", 0x31 },
536 { (char*)"wo" , 0x31 },
537 { (char*)"Xhosa", 0x32 },
538 { (char*)"xh", 0x32 },
539 { (char*)"Yiddish", 0x88 },
540 { (char*)"yi", 0x88 },
541 { (char*)"Yoruba", 0x35 },
542 { (char*)"yo", 0x35 },
543 { (char*)"Zhuang", 0x3a },
544 { (char*)"z", 0x3a },
545 { (char*)"Chinese", 0x41 },
546 { (char*)"ch", 0x41 },
547 { (char*)"Zulu", 0x5c },
548 { (char*)"zu", 0x5c },
549 { (char*)"Ko", 0x3d }
553 const SMS_WSP_HEADER_PARAMETER_S wspHeaderApplId[] = {
554 { (char*)"x-wap-application:*", 0x00 },
555 { (char*)"x-wap-application:push.sia", 0x01},
556 { (char*)"x-wap-application:wml.ua", 0x02 },
557 { (char*)"x-wap-application:wta.ua", 0x03 },
558 { (char*)"x-wap-application:mms.ua", 0x04 },
559 { (char*)"x-wap-application:push.syncml", 0x05 },
560 { (char*)"x-wap-application:loc.ua", 0x06 },
561 { (char*)"x-wap-application:syncml.dm", 0x07 },
562 { (char*)"x-wap-application:drm.ua", 0x08 },
563 { (char*)"x-wap-application:emn.ua", 0x09 },
564 { (char*)"x-oma-application:ulp.ua ", 0x90 },
565 { (char*)"x-oma-docomo:open.ctl", 0x9055 },
566 { (char*)"x-oma-docomo:xmd.mail.ua", 0x905C },
567 { (char*)"x-oma-docomo:xmd.storage.ua", 0x905F },
568 { (char*)"x-oma-docomo:xmd.lcsapp.ua", 0x9060 },
569 { (char*)"x-oma-docomo:xmd.info.ua", 0x9061 },
570 { (char*)"x-oma-docomo:xmd.agent.ua", 0x9062 },
571 { (char*)"x-oma-docomo:xmd.sab.ua", 0x9063 },
572 { (char*)"x-oma-docomo:xmd.am.ua", 0x9064 },
573 { (char*)"x-oma-docomo:xmd.emdm.ua", 0x906B },
574 { (char*)"x-oma-docomo:xmd.lac.ua", 0x906C },
575 { (char*)"x-oma-docomo:xmd.osv.ua", 0x906D },
576 { (char*)"x-oma-docomo:xmd.dcs.ua", 0x906E },
577 { (char*)"x-oma-docomo:xmd.wipe.ua", 0x906F },
578 { (char*)"x-oma-docomo:xmd.vdapp.ua ", 0x9070 },
582 const char* wspCacheControl[] = {
588 (char*)"Only-if-cached",
591 (char*)"No-transform",
592 (char*)"Must-revalidate",
593 (char*)"Proxy-revalidate"
596 const SMS_WSP_METHOD_TYPE_S wspMethodType[] = {
597 { (char*)"GET", 0x40 },
598 { (char*)"OPTIONS", 0x41 },
599 { (char*)"HEAD", 0x42 },
600 { (char*)"DELETE", 0x43 },
601 { (char*)"TRACE", 0x44 },
602 { (char*)"POST", 0x60 },
603 { (char*)"PUT", 0x61 }
607 const SMS_WSP_SECURITY_TYPE_S wspSecurityType[] = {
608 {(char*)"NETWPIN", 0x00},
609 {(char*)"USERPIN", 0x01},
610 {(char*)"USERNETWPIN", 0x02},
611 {(char*)"USERPINMAC", 0x03}
616 const char* wspWeek[] = {
627 const char* wspWeekDay[] = {
637 const char* wspMonth[] = {
654 /*==================================================================================================
655 IMPLEMENTATION OF SmsPluginWapPushHandler - Member Functions
656 ==================================================================================================*/
657 SmsPluginWapPushHandler* SmsPluginWapPushHandler::pInstance = NULL;
660 SmsPluginWapPushHandler::SmsPluginWapPushHandler()
662 memset(&tmpAddress, 0x00, sizeof(tmpAddress));
666 SmsPluginWapPushHandler::~SmsPluginWapPushHandler()
671 SmsPluginWapPushHandler* SmsPluginWapPushHandler::instance()
674 pInstance = new SmsPluginWapPushHandler();
680 bool SmsPluginWapPushHandler::IsWapPushMsg(unsigned short dstport)
684 int PortCount = sizeof(wapPushPortList)/sizeof(wapPushPortList[0]);
686 MSG_DEBUG("Port Count [%d]", PortCount);
688 for (int i = 0; i < PortCount; i++) {
689 if (dstport == wapPushPortList[i]) {
690 MSG_DEBUG("Wap Push Msg : [%04x]", wapPushPortList[i]);
701 sms_wap_app_code_t SmsPluginWapPushHandler::getAppCode(const char *pPushHeader)
703 int appCount = sizeof(pushDefaultApplication)/sizeof(pushDefaultApplication[0]) - 1;
705 unsigned char *header = NULL;
706 SMS_WAP_APP_CODE_T appCode = SMS_WAP_APPLICATION_DEFAULT;
708 MSG_DEBUG("Application Count [%d]", appCount);
710 for (int i = 0; i < appCount; i++) {
711 header = (unsigned char*)strcasestr(pPushHeader, pushDefaultApplication[i].pContentType);
713 if (header != NULL) {
714 appCode = pushDefaultApplication[i].appCode;
719 if (appCode == SMS_WAP_APPLICATION_DEFAULT) {
720 MSG_DEBUG("Application Type is not supported");
722 MSG_DEBUG("Find Application [%d]", appCode);
730 void SmsPluginWapPushHandler::copyDeliverData(sms_trans_addr_s *pAddr)
732 memcpy(&tmpAddress, pAddr, sizeof(tmpAddress));
734 MSG_SEC_DEBUG("Address [%s]", tmpAddress.szData);
737 tmpTimeStamp.format = pDeliver->timeStamp.format;
739 if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
740 tmpTimeStamp.time.absolute.year = pDeliver->timeStamp.time.absolute.year;
741 tmpTimeStamp.time.absolute.month = pDeliver->timeStamp.time.absolute.month;
742 tmpTimeStamp.time.absolute.day = pDeliver->timeStamp.time.absolute.day;
743 tmpTimeStamp.time.absolute.hour = pDeliver->timeStamp.time.absolute.hour;
744 tmpTimeStamp.time.absolute.minute = pDeliver->timeStamp.time.absolute.minute;
745 tmpTimeStamp.time.absolute.second = pDeliver->timeStamp.time.absolute.second;
746 tmpTimeStamp.time.absolute.timeZone = pDeliver->timeStamp.time.absolute.timeZone;
752 void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize)
756 #ifdef MSG_FW_FOR_DEBUG
757 MSG_DEBUG("DataSize [%d]", DataSize);
759 MSG_DEBUG("[pUserData]");
760 for (int i = 0; i < DataSize; i++) {
761 printf("[%02x]", pUserData[i]);
766 unsigned char* pPDUTypeData = (unsigned char*)pUserData;
767 unsigned long PDUTypeDataLen = DataSize;
769 char* pPushHeader = NULL;
770 unique_ptr<char*, void(*)(char**)> pushHeaderBuf(&pPushHeader, unique_ptr_deleter);
771 unsigned long pushHeaderLen = 0;
773 char* pPushBody = NULL;
774 unique_ptr<char*, void(*)(char**)> PushBodyBuf(&pPushBody, unique_ptr_deleter);
775 unsigned long pushBodyLen = 0;
777 unsigned long iPDU = 1;
779 char* pWspHeader = NULL;
780 unique_ptr<char*, void(*)(char**)> WspHeaderBuf(&pWspHeader, unique_ptr_deleter);
781 unsigned long wspHeaderLen = 0;
783 char* pWspBody = NULL;
784 unique_ptr<char*, void(*)(char**)> WspBodyBuf(&pWspBody, unique_ptr_deleter);
785 unsigned long wspBodyLen = 0;
790 pushHeaderLen = wspRetriveUintvarDecode(pPDUTypeData, &iPDU);
792 MSG_DEBUG("PDUTypeDataLen [%d]", PDUTypeDataLen);
793 MSG_DEBUG("pushHeaderLen [%d]", pushHeaderLen);
794 MSG_DEBUG("iPDU [%d]", iPDU);
796 wspHeaderLen = pushHeaderLen + iPDU;
798 MSG_DEBUG("wspBodyLen [%d]", wspBodyLen);
800 if (wspHeaderLen > 0) {
801 pWspHeader = new char[wspHeaderLen];
803 if (pWspHeader == NULL) {
804 MSG_DEBUG("pWspHeader Memory Allocation Failed");
807 memcpy(pWspHeader, pPDUTypeData, wspHeaderLen);
811 #ifdef MSG_FW_FOR_DEBUG
812 MSG_DEBUG("wspHeaderLen [%d]", wspHeaderLen);
814 MSG_DEBUG("[pWspHeader]");
815 for (int i = 0; i < wspHeaderLen; i++) {
816 printf("[%02x]", pWspHeader[i]);
821 /* return if it is below case error */
822 if (PDUTypeDataLen < wspHeaderLen) {
823 MSG_DEBUG("PDUTypeDataLen < wspHeaderLen !!!");
827 /* Finding wspBody Information */
828 wspBodyLen = PDUTypeDataLen - wspHeaderLen;
830 if (wspBodyLen > 0) {
831 pWspBody = new char[wspBodyLen];
833 if (pWspBody == NULL) {
834 MSG_DEBUG("pWspBody Memory Allocation Failed");
837 memcpy(pWspBody, pPDUTypeData + wspHeaderLen, wspBodyLen);
843 wspDecodeHeader(pPDUTypeData + iPDU, pushHeaderLen, PDUTypeDataLen - (iPDU + pushHeaderLen), TRUE, &pPushHeader);
845 iPDU = iPDU + pushHeaderLen;
847 pushBodyLen = PDUTypeDataLen - iPDU ;
849 if (pushBodyLen > 0) {
850 pPushBody = new char[pushBodyLen];
852 if (pPushBody == NULL) {
853 MSG_DEBUG("pPushBody Memory Allocation Failed");
856 memcpy(pPushBody, pPDUTypeData+ iPDU, pushBodyLen);
863 handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen);
869 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
873 if (pPushBody == NULL) {
874 MSG_DEBUG("pPushBody is NULL");
878 SMS_WAP_APP_CODE_T appCode = getAppCode(pPushHeader);
880 /* check Push message receive setting */
881 bool bPushRecv = false;
883 if (MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv) != MSG_SUCCESS)
884 MSG_INFO("MsgSettingGetBool() is failed");
886 if ((bPushRecv == false) && (appCode != SMS_WAP_APPLICATION_MMS_UA)) {
887 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
892 case SMS_WAP_APPLICATION_MMS_UA:
893 MSG_DEBUG("Received MMS Notification");
894 handleMMSNotification(pPushBody, PushBodyLen);
896 case SMS_WAP_APPLICATION_PUSH_SI:
897 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
898 handleSIMessage(pPushBody, PushBodyLen, true);
900 case SMS_WAP_APPLICATION_PUSH_SIC:
901 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
902 handleSIMessage(pPushBody, PushBodyLen, false);
904 case SMS_WAP_APPLICATION_PUSH_SL:
905 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
906 handleSLMessage(pPushBody, PushBodyLen, true);
908 case SMS_WAP_APPLICATION_PUSH_SLC:
909 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
910 handleSLMessage(pPushBody, PushBodyLen, false);
912 case SMS_WAP_APPLICATION_PUSH_CO:
913 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
914 handleCOMessage(pPushBody, PushBodyLen, true);
916 case SMS_WAP_APPLICATION_PUSH_COC:
917 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
918 handleCOMessage(pPushBody, PushBodyLen, false);
920 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
921 MSG_DEBUG("Received DM BOOTSTRAP");
922 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
924 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
925 MSG_DEBUG("Received DM BOOTSTRAP");
926 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
928 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
929 MSG_DEBUG("Received Provisioning");
930 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
932 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
933 MSG_DEBUG("Received Provisioning");
934 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
936 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
937 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
938 MSG_DEBUG("Received Provisioning");
939 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
941 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
942 MSG_DEBUG("Received DM Notification");
943 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
945 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
946 MSG_DEBUG("Received DS Notification");
947 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
949 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
950 MSG_DEBUG("Received DS Notification");
951 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
953 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
954 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
955 MSG_DEBUG("Received DRM UA");
956 if (pPushBody != NULL)
957 handleDrmVer1(pPushBody, PushBodyLen);
959 case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
960 case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
961 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
962 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
963 MSG_DEBUG("Received DRM V2");
966 case SMS_WAP_APPLICATION_PUSH_EMAIL:
967 case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
968 case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
969 MSG_DEBUG("Received Email");
972 case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
973 MSG_DEBUG("Received IMPS CIR");
976 case SMS_WAP_APPLICATION_LBS:
977 MSG_DEBUG("Received LBS related message");
978 SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
981 case SMS_WAP_APPLICATION_PUSH_SIA:
982 MSG_DEBUG("Received SIA");
986 MSG_DEBUG("Unknown Application [%d]", appCode);
994 static void launchProcessByAppcode(int appcode)
997 GError *error = NULL;
998 GDBusConnection *connection_agent = NULL;
999 GDBusProxy *dbus_proxy_agent = NULL;
1000 GDBusConnection *connection_service = NULL;
1001 GDBusProxy *dbus_proxy_service = NULL;
1002 GVariant *result_agent = NULL;
1003 GVariant *result_service = NULL;
1006 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1007 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1008 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1009 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1010 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1011 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1012 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION: {
1013 connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1015 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1018 dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_NONE,
1019 NULL, "org.tizen.omadmagent", "/org/tizen/omadmagent",
1020 "org.tizen.omadmagent", NULL, &error);
1022 MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
1025 result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1027 MSG_DEBUG("invoking agent proxy call failed: %s\n", error->message);
1030 connection_service = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1032 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1035 dbus_proxy_service = g_dbus_proxy_new_sync(connection_service, G_DBUS_PROXY_FLAGS_NONE, NULL,
1036 "org.tizen.omadmservice", "/org/tizen/omadmservice",
1037 "org.tizen.omadmservice", NULL, &error);
1039 MSG_DEBUG("Connecting to service proxy failed: %s\n", error->message);
1042 result_service = g_dbus_proxy_call_sync(dbus_proxy_service, "wakeup", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1044 MSG_DEBUG("invoking service proxy call failed: %s\n", error->message);
1050 cv.timedwait(mx.pMutex(), 2);
1055 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1056 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML: {
1057 connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1059 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1063 dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_NONE, NULL,
1064 "org.tizen.omadsagent", "/org/tizen/omadsagent",
1065 "org.tizen.omadsagent", NULL, &error);
1067 MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
1070 result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL,
1071 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1073 MSG_DEBUG("invoking service error: %s\n", error->message);
1084 g_error_free(error);
1088 if (connection_agent) {
1089 g_object_unref(connection_agent);
1090 connection_agent = NULL;
1093 if (dbus_proxy_agent) {
1094 g_object_unref(dbus_proxy_agent);
1095 dbus_proxy_agent = NULL;
1099 g_object_unref(result_service);
1100 result_service = NULL;
1103 if (connection_service) {
1104 g_object_unref(connection_service);
1105 connection_service = NULL;
1108 if (dbus_proxy_service) {
1109 g_object_unref(dbus_proxy_service);
1110 dbus_proxy_service = NULL;
1113 if (result_service) {
1114 g_object_unref(result_service);
1115 result_service = NULL;
1122 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
1126 if (pPushBody == NULL) {
1127 MSG_DEBUG("pPushBody is NULL");
1131 msg_error_t err = MSG_SUCCESS;
1132 int pushEvt_cnt = 0;
1133 char app_id[MAX_WAPPUSH_ID_LEN] = {0, };
1134 char content_type[MAX_WAPPUSH_CONTENT_TYPE_LEN] = {0, };
1135 SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
1137 err = storageHandler->getRegisteredPushEvent(pPushHeader, &pushEvt_cnt, app_id, sizeof(app_id), content_type, sizeof(content_type));
1138 MSG_DEBUG("pushEvt_cnt: %d", pushEvt_cnt);
1139 if (err != MSG_SUCCESS) {
1140 MSG_DEBUG("Fail to get registered push event");
1144 for (int i = 0; i < pushEvt_cnt; ++i) {
1145 /* check Push message receive setting */
1146 bool bPushRecv = false;
1148 if (MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv) != MSG_SUCCESS)
1149 MSG_INFO("MsgSettingGetBool() is failed");
1151 storageHandler->getnthPushEvent(i, &appcode);
1152 MSG_DEBUG("pushEvt_cnt: %d, appcode: %d", pushEvt_cnt, appcode);
1153 if ((bPushRecv == false) && (appcode != SMS_WAP_APPLICATION_MMS_UA)) {
1154 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
1158 #ifdef FEATURE_MMS_DISABLE
1159 if (appcode == SMS_WAP_APPLICATION_MMS_UA) {
1160 MSG_DEBUG("Drop MMS Notification for DOCOMO");
1165 launchProcessByAppcode(appcode);
1168 case SMS_WAP_APPLICATION_MMS_UA:
1169 MSG_DEBUG("Received MMS Notification");
1170 handleMMSNotification(pPushBody, PushBodyLen);
1172 case SMS_WAP_APPLICATION_PUSH_SI:
1173 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
1174 /* handleSIMessage(pPushBody, PushBodyLen, true); */
1176 case SMS_WAP_APPLICATION_PUSH_SIC:
1177 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
1178 /* handleSIMessage(pPushBody, PushBodyLen, false); */
1180 case SMS_WAP_APPLICATION_PUSH_SL:
1181 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
1182 /* handleSLMessage(pPushBody, PushBodyLen, true); */
1184 case SMS_WAP_APPLICATION_PUSH_SLC:
1185 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
1186 /* handleSLMessage(pPushBody, PushBodyLen, false); */
1188 case SMS_WAP_APPLICATION_PUSH_CO:
1189 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
1190 /* handleCOMessage(pPushBody, PushBodyLen, true); */
1192 case SMS_WAP_APPLICATION_PUSH_COC:
1193 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
1194 /* handleCOMessage(pPushBody, PushBodyLen, false); */
1196 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1197 MSG_DEBUG("Received DM BOOTSTRAP");
1198 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1200 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1201 MSG_DEBUG("Received DM BOOTSTRAP");
1202 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1204 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1205 MSG_DEBUG("Received Provisioning");
1206 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1208 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1209 MSG_DEBUG("Received Provisioning");
1210 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1212 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1213 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1214 MSG_DEBUG("Received Provisioning");
1215 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1217 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1218 MSG_DEBUG("Received DM Notification");
1219 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1221 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1222 MSG_DEBUG("Received DS Notification");
1223 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1225 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1226 MSG_DEBUG("Received DS Notification");
1227 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1229 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
1230 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
1231 MSG_DEBUG("Received DRM UA");
1232 if (pPushBody != NULL)
1233 handleDrmVer1(pPushBody, PushBodyLen);
1235 case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
1236 case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
1237 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
1238 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
1239 MSG_DEBUG("Received DRM V2");
1242 case SMS_WAP_APPLICATION_PUSH_EMAIL:
1243 case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
1244 case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
1245 MSG_DEBUG("Received Email");
1248 case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1249 MSG_DEBUG("Received IMPS CIR");
1250 /* TODO: IMPS CIR */
1252 case SMS_WAP_APPLICATION_LBS:
1253 MSG_DEBUG("Received LBS related message");
1254 SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1257 case SMS_WAP_APPLICATION_PUSH_SIA:
1258 MSG_DEBUG("Received SIA");
1262 SmsPluginEventHandler::instance()->handlePushMsgIncoming(pPushHeader, pPushBody, PushBodyLen, app_id, content_type);
1266 storageHandler->releasePushEvent();
1272 void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen)
1276 #ifdef MSG_FW_FOR_DEBUG
1277 printf("\n\n[handleMMSNotification] Push Body.\n");
1279 for (int i = 0; i < PushBodyLen; i++) {
1280 printf(" [%02x]", pPushBody[i]);
1285 /* Make MSG_MESSAGE_INFO_S */
1286 MSG_MESSAGE_INFO_S msgInfo;
1287 memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1289 msgInfo.addressList = NULL;
1290 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1292 createMsgInfo(&msgInfo);
1294 /* Convert Type values */
1295 msgInfo.msgType.mainType = MSG_MMS_TYPE;
1296 msgInfo.msgType.subType = MSG_NOTIFICATIONIND_MMS;
1297 msgInfo.msgType.classType = MSG_CLASS_NONE;
1298 msgInfo.storageId = MSG_STORAGE_PHONE;
1299 msgInfo.dataSize = PushBodyLen;
1301 if (msgInfo.dataSize > MAX_MSG_TEXT_LEN) {
1302 msgInfo.bTextSms = false;
1304 /* Save Message Data into File */
1305 char fileName[MSG_FILENAME_LEN_MAX+1];
1306 memset(fileName, 0x00, sizeof(fileName));
1308 if (MsgCreateFileName(fileName) == false) {
1309 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1312 if (MsgWriteIpcFile(fileName, pPushBody, msgInfo.dataSize) == false) {
1313 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1316 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1318 msgInfo.bTextSms = true;
1320 memcpy(msgInfo.msgText, pPushBody, msgInfo.dataSize);
1321 msgInfo.msgText[msgInfo.dataSize] = '\0';
1324 msg_error_t err = MSG_SUCCESS;
1326 /* Add MMS Noti Msg into DB */
1327 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1329 if (err == MSG_SUCCESS) {
1331 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1333 if (err != MSG_SUCCESS)
1334 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1337 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1344 void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText)
1348 MSG_PUSH_MESSAGE_S pushMsg = {};
1350 xmlDocPtr xmlDoc = NULL;
1351 xmlNodePtr topNode = NULL;
1352 xmlNodePtr indNode = NULL;
1354 xmlChar* tmpXmlChar = NULL;
1356 if (pPushBody == NULL) {
1357 MSG_DEBUG("pPushBody is NULL");
1361 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1363 if (xmlDoc == NULL) {
1364 MSG_DEBUG("xmlDoc is NULL");
1368 topNode = xmlDocGetRootElement(xmlDoc);
1370 if (topNode == NULL) {
1371 MSG_DEBUG("topNode is NULL");
1376 indNode = topNode->xmlChildrenNode;
1378 while (indNode != NULL) {
1379 if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
1380 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1384 indNode = indNode->next;
1387 if (indNode == NULL) {
1388 MSG_DEBUG("indNode is NULL.");
1392 /* temporary set to max. */
1393 pushMsg.expires = 0xFFFFFFFF;
1395 /* setting received time */
1396 time_t t = time(NULL);
1397 time_t utfTime = time(&t);
1399 pushMsg.received = (unsigned long)utfTime;
1401 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1403 if (tmpXmlChar == NULL) {
1404 MSG_DEBUG("href is NULL.");
1408 if (tmpXmlChar != NULL)
1409 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1411 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
1413 if (tmpXmlChar != NULL)
1414 strncpy(pushMsg.id, (char*)tmpXmlChar, MAX_WAPPUSH_ID_LEN-1);
1416 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CREATED_TAG);
1418 if (tmpXmlChar != NULL)
1419 pushMsg.created = convertXmlCharToSec((char*)tmpXmlChar);
1421 if (pushMsg.created == 0)
1422 pushMsg.created = pushMsg.received;
1424 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_EXPIRES_TAG);
1426 if (tmpXmlChar != NULL)
1427 pushMsg.expires = convertXmlCharToSec((char*)tmpXmlChar);
1429 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1431 pushMsg.action = convertSIActionStrToEnum((char*)tmpXmlChar);
1433 tmpXmlChar = xmlNodeListGetString(xmlDoc, indNode->xmlChildrenNode, 1);
1435 if (tmpXmlChar == NULL) {
1436 MSG_DEBUG("contents is NULL.");
1440 strncpy(pushMsg.contents, (char*)tmpXmlChar, MAX_WAPPUSH_CONTENTS_LEN-1);
1442 /* Write push Msg to file */
1443 char fileName[MSG_FILENAME_LEN_MAX+1];
1444 memset(fileName, 0x00, sizeof(fileName));
1446 if (MsgCreateFileName(fileName) == false) {
1448 xmlFree(tmpXmlChar);
1449 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1452 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false) {
1454 xmlFree(tmpXmlChar);
1455 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1458 /* Pack Message Info Structure */
1459 MSG_MESSAGE_INFO_S msgInfo;
1460 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1462 msgInfo.addressList = NULL;
1463 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1465 createMsgInfo(&msgInfo);
1467 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1469 /* Convert Type values */
1470 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1471 msgInfo.msgType.subType = MSG_WAP_SI_SMS;
1473 msgInfo.dataSize = sizeof(pushMsg);
1476 xmlFree(tmpXmlChar);
1478 msg_error_t err = MSG_SUCCESS;
1480 /* Add WAP Push Msg into DB */
1481 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1483 if (err == MSG_SUCCESS) {
1485 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1487 if (err != MSG_SUCCESS) {
1488 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1491 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1500 void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText)
1504 MSG_PUSH_MESSAGE_S pushMsg = {};
1506 xmlDocPtr xmlDoc = NULL;
1507 xmlNodePtr topNode = NULL;
1508 xmlNodePtr indNode = NULL;
1510 xmlChar* tmpXmlChar = NULL;
1512 msg_error_t err = MSG_SUCCESS;
1514 if (pPushBody == NULL) {
1515 MSG_DEBUG("pPushBody is NULL \n");
1519 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1521 if (xmlDoc == NULL) {
1522 MSG_DEBUG("xmlDoc is NULL \n");
1526 topNode = xmlDocGetRootElement(xmlDoc);
1528 if (topNode == NULL) {
1529 MSG_DEBUG("Empty Document.");
1533 MSG_SEC_DEBUG("Not an empty Document and topNode->name = %s \n", topNode->name);
1538 while (indNode != NULL) {
1539 if (!xmlStrcmp(indNode->name, (const xmlChar*) "sl")) {
1540 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1544 indNode = indNode->next;
1547 /* setting received time setting */
1548 time_t t = time(NULL);
1549 time_t utfTime = time(&t);
1551 pushMsg.received = (unsigned long)utfTime;
1553 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1555 if (tmpXmlChar == NULL) {
1556 MSG_DEBUG("href is NULL.");
1560 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1562 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1563 pushMsg.action = convertSLActionStrToEnum((char*)tmpXmlChar);
1565 /* Setting other parameters in default values */
1566 pushMsg.created = pushMsg.received;
1567 /* temporary set to MAX value. */
1568 pushMsg.expires = 0xFFFFFFFF;
1570 MSG_DEBUG("check pushMsg data");
1571 MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
1572 MSG_DEBUG("pushMsg.received : [%d]", pushMsg.received);
1573 MSG_DEBUG("pushMsg.created : [%d]", pushMsg.created);
1574 MSG_DEBUG("pushMsg.expires : [%d]", pushMsg.expires);
1575 MSG_SEC_DEBUG("pushMsg.id : [%s]", pushMsg.id);
1576 MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
1577 MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
1579 /* Write push Msg to file */
1580 char fileName[MSG_FILENAME_LEN_MAX+1];
1581 memset(fileName, 0x00, sizeof(fileName));
1583 if (MsgCreateFileName(fileName) == false)
1584 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1586 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false)
1587 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1589 /* Pack Message Info Structure */
1590 MSG_MESSAGE_INFO_S msgInfo;
1591 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1593 msgInfo.addressList = NULL;
1594 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1596 createMsgInfo(&msgInfo);
1598 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1600 /* Convert Type values */
1601 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1602 msgInfo.msgType.subType = MSG_WAP_SL_SMS;
1604 /* Update Msg Text */
1605 strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
1607 msgInfo.dataSize = sizeof(pushMsg);
1609 MSG_DEBUG("dataSize : %d", msgInfo.dataSize);
1611 /* Add WAP Push Msg into DB */
1612 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1614 if (err == MSG_SUCCESS) {
1615 /* Callback to MSG FW */
1616 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1618 if (err != MSG_SUCCESS)
1619 MSG_DEBUG("callbackMsgIncoming is failed, err=[%d]", err);
1621 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1625 xmlFree(tmpXmlChar);
1633 void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText)
1635 MSG_PUSH_CACHEOP_S cacheOp;
1637 xmlDocPtr xmlDoc = NULL;
1638 xmlNodePtr topNode = NULL;
1639 xmlNodePtr indNode = NULL;
1641 memset(&cacheOp, 0x00, sizeof(cacheOp));
1643 MSG_DEBUG("Enter handleCOMessage");
1645 if (pPushBody == NULL) {
1646 MSG_DEBUG("pPushBody is NULL \n");
1650 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1652 if (xmlDoc == NULL) {
1653 MSG_DEBUG("xmlDoc is NULL \n");
1657 topNode = xmlDocGetRootElement(xmlDoc);
1658 if (topNode == NULL) {
1659 MSG_DEBUG("Warning:Empty Document\n");
1664 indNode = topNode->xmlChildrenNode;
1666 while (indNode != NULL) {
1667 xmlChar* tmpUrl = NULL;
1668 if (!xmlStrcmp(indNode->name, (const xmlChar*) SMS_PUSH_XML_INVAL_OBJ)) {
1669 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1671 tmpUrl = xmlGetProp(indNode, (xmlChar*) SMS_PUSH_XML_CO_URI);
1673 if (tmpUrl != NULL) {
1674 strncpy(cacheOp.invalObjectUrl[cacheOp.invalObjectCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1676 MSG_DEBUG("%dth invalObjectUrl is <%s>\n", cacheOp.invalObjectCnt, cacheOp.invalObjectUrl[cacheOp.invalObjectCnt-1]);
1678 MSG_DEBUG("NO href value from the xmlDoc\n");
1680 } else if (!xmlStrcmp(indNode->name, (const xmlChar*) SMS_PUSH_XML_INVAL_SVC)) {
1681 MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1682 tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1684 if (tmpUrl != NULL) {
1685 strncpy(cacheOp.invalServiceUrl[cacheOp.invalServiceCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1686 MSG_DEBUG("%dth invalServiceUrl is <%s>\n", cacheOp.invalServiceCnt, cacheOp.invalServiceUrl[cacheOp.invalServiceCnt-1]);
1688 MSG_DEBUG("NO href value from the xmlDoc\n");
1695 indNode = indNode->next;
1698 /* Write push Msg to file */
1699 char fileName[MSG_FILENAME_LEN_MAX+1];
1700 memset(fileName, 0x00, sizeof(fileName));
1702 if (MsgCreateFileName(fileName) == false) {
1704 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1707 if (MsgWriteIpcFile(fileName, (char*)(&cacheOp), sizeof(cacheOp)) == false) {
1709 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1712 /* Pack Message Info Structure */
1713 MSG_MESSAGE_INFO_S msgInfo;
1714 memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1716 msgInfo.addressList = NULL;
1717 unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1719 createMsgInfo(&msgInfo);
1721 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1723 /* Convert Type values */
1724 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1725 msgInfo.msgType.subType = MSG_WAP_CO_SMS;
1727 msgInfo.dataSize = sizeof(cacheOp);
1729 msg_error_t err = MSG_SUCCESS;
1731 /* Add WAP Push Msg into DB */
1732 err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1734 if (err == MSG_SUCCESS) {
1736 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1738 if (err != MSG_SUCCESS) {
1739 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1742 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1751 void SmsPluginWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
1754 int drmRt = DRM_RETURN_SUCCESS;
1756 unique_ptr<char*, void(*)(char**)> buf(&cid, unique_ptr_deleter);
1758 MSG_DEBUG("Received DRM RIGHTS OBJECT Type WAP Push Message.");
1759 drm_request_type_e request_type = DRM_REQUEST_TYPE_REGISTER_LICENSE;
1760 drm_register_lic_info_s lic_req_info;
1761 drm_register_lic_resp_s lic_resp_info;
1763 bzero(&lic_req_info, sizeof(drm_register_lic_info_s));
1764 bzero(&lic_resp_info, sizeof(drm_register_lic_resp_s));
1765 bzero(lic_req_info.lic_data, sizeof(lic_req_info.lic_data));
1767 memcpy(lic_req_info.lic_data, pPushBody, PushBodyLen);
1769 lic_req_info.lic_version = DRM_OMA_DRMV1_RIGHTS;
1770 lic_req_info.roap_init_src = DRM_ROAP_INIT_FROM_WAPPUSH;
1771 lic_req_info.operation_callback.callback = NULL;
1773 drmRt = drm_process_request(request_type, &lic_req_info, &lic_resp_info);
1774 if (drmRt == DRM_RETURN_SUCCESS) {
1775 MSG_DEBUG("DRM successfully registed to drm-service.");
1777 MSG_DEBUG("Fail to regist DRM to drm-service.");
1784 void SmsPluginWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
1786 /* Convert class Type values */
1787 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
1789 /* set folder id (temporary) */
1790 pMsgInfo->folderId = MSG_INBOX_ID;
1792 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
1793 pMsgInfo->bRead = false;
1794 pMsgInfo->bProtected = false;
1795 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
1796 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
1798 time_t rawtime = time(NULL);
1799 /* Comment below lines to save local UTC time..... (it could be used later.) */
1801 if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
1803 MSG_DEBUG("year : %d", tmpTimeStamp.time.absolute.year);
1804 MSG_DEBUG("month : %d", tmpTimeStamp.time.absolute.month);
1805 MSG_DEBUG("day : %d", tmpTimeStamp.time.absolute.day);
1806 MSG_DEBUG("hour : %d", tmpTimeStamp.time.absolute.hour);
1807 MSG_DEBUG("minute : %d", tmpTimeStamp.time.absolute.minute);
1808 MSG_DEBUG("second : %d", tmpTimeStamp.time.absolute.second);
1809 MSG_DEBUG("timezone : %d", tmpTimeStamp.time.absolute.timeZone);
1811 char displayTime[32];
1815 memset(&timeinfo, 0x00, sizeof(tm));
1817 timeinfo.tm_year = (tmpTimeStamp.time.absolute.year + 100);
1818 timeinfo.tm_mon = (tmpTimeStamp.time.absolute.month - 1);
1819 timeinfo.tm_mday = tmpTimeStamp.time.absolute.day;
1820 timeinfo.tm_hour = tmpTimeStamp.time.absolute.hour;
1821 timeinfo.tm_min = tmpTimeStamp.time.absolute.minute;
1822 timeinfo.tm_sec = tmpTimeStamp.time.absolute.second;
1823 timeinfo.tm_isdst = 0;
1825 rawtime = mktime(&timeinfo);
1827 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
1828 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
1829 MSG_DEBUG("timezone [%d]", timezone);
1830 MSG_DEBUG("daylight [%d]", daylight);
1832 memset(displayTime, 0x00, sizeof(displayTime));
1833 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
1834 MSG_DEBUG("displayTime [%s]", displayTime);
1836 rawtime -= (tmpTimeStamp.time.absolute.timeZone * (3600/4));
1838 timeTM = localtime(&rawtime);
1839 memset(displayTime, 0x00, sizeof(displayTime));
1840 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1841 MSG_DEBUG("displayTime [%s]", displayTime);
1843 rawtime -= timezone;
1845 timeTM = localtime(&rawtime);
1846 memset(displayTime, 0x00, sizeof(displayTime));
1847 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1848 MSG_DEBUG("displayTime [%s]", displayTime);
1852 pMsgInfo->displayTime = rawtime;
1854 /* Convert Address values */
1855 pMsgInfo->nAddressCnt = 1;
1857 pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
1858 memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
1860 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
1861 strncpy(pMsgInfo->addressList[0].addressVal, tmpAddress.szData, MAX_ADDRESS_VAL_LEN);
1863 pMsgInfo->msgPort.valid = false;
1864 pMsgInfo->msgPort.dstPort = 0;
1865 pMsgInfo->msgPort.srcPort = 0;
1869 void SmsPluginWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText)
1871 if (pPushBody == NULL) {
1872 MSG_DEBUG("pPushBody is NULL");
1877 *pXmlDoc = xmlParseMemory(pPushBody, AcStrlen(pPushBody));
1879 WB_UTINY* xmldata = NULL;
1880 WBXMLConvWBXML2XML *conv = NULL;
1881 WBXMLError ret = WBXML_OK;
1883 ret = wbxml_conv_wbxml2xml_create(&conv);
1884 if (ret != WBXML_OK)
1887 ret = wbxml_conv_wbxml2xml_run(conv, (WB_UTINY*)pPushBody, (WB_ULONG)PushBodyLen, &xmldata, NULL);
1889 wbxml_conv_wbxml2xml_destroy(conv);
1891 if (ret != WBXML_OK ||xmldata == NULL) {
1892 MSG_DEBUG("xmldata is NULL. Error code is [%d].\n", ret);
1896 MSG_DEBUG("xmldata : \n%s\n", xmldata);
1898 *pXmlDoc = xmlParseMemory((char*)xmldata, AcStrlen((char*)xmldata));
1903 unsigned long SmsPluginWapPushHandler::convertXmlCharToSec(char* pDate)
1905 struct tm timeStruct;
1906 time_t nTimeInSec = 0;
1908 int i = 0, index = 0;
1910 memset(tmpBuf, 0x00, sizeof(tmpBuf));
1911 memset(&timeStruct, 0x00, sizeof(struct tm));
1914 if (AcStrlen(pDate) < 20)
1917 MSG_DEBUG("pDate [%s]", pDate);
1920 for (i = 0; i < 4; i++) {
1921 tmpBuf[i] = pDate[index++];
1925 timeStruct.tm_year = (atoi(tmpBuf)-1900);
1928 for (i = 0; i < 2; i++) {
1929 tmpBuf[i] = pDate[index++];
1933 timeStruct.tm_mon = (atoi(tmpBuf) - 1);
1936 for (i = 0; i < 2; i++) {
1937 tmpBuf[i] = pDate[index++];
1941 timeStruct.tm_mday = atoi(tmpBuf);
1944 for (i = 0; i < 2; i++) {
1945 tmpBuf[i] = pDate[index++];
1949 timeStruct.tm_hour = atoi(tmpBuf);
1952 for (i = 0; i < 2; i++) {
1953 tmpBuf[i] = pDate[index++];
1957 timeStruct.tm_min = atoi(tmpBuf);
1960 for (i = 0; i < 2; i++) {
1961 tmpBuf[i] = pDate[index++];
1965 timeStruct.tm_sec = atoi(tmpBuf);
1967 nTimeInSec = mktime(&timeStruct);
1973 msg_push_action_t SmsPluginWapPushHandler::convertSIActionStrToEnum(char* pAction)
1977 if (pAction == NULL) {
1978 MSG_DEBUG("pAction is NULL. Setting to default action type.");
1979 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
1982 /* compare with signal-none. */
1983 comp = g_strcmp0("signal-none", pAction);
1985 return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
1987 /* compare with signal-low. */
1988 comp = g_strcmp0("signal-low", pAction);
1990 return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
1992 /* compare with signal-medium. */
1993 comp = g_strcmp0("signal-medium", pAction);
1995 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
1997 /* compare with signal-high. */
1998 comp = g_strcmp0("signal-high", pAction);
2000 return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
2002 /* compare with delete. */
2003 comp = g_strcmp0("delete", pAction);
2005 return MSG_PUSH_SI_ACTION_DELETE;
2007 /* signal-medium is default action value. */
2008 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2012 msg_push_action_t SmsPluginWapPushHandler::convertSLActionStrToEnum(char* pAction)
2016 if (pAction == NULL) {
2017 MSG_DEBUG("MSG_DEBUG is NULL. Setting to default action type.\n");
2018 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2021 /* compare pSrcStr with execute-low. */
2022 comp = g_strcmp0("execute-low", pAction);
2024 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2026 /* compare pSrcStr with execute-high. */
2027 comp = g_strcmp0("execute-high", pAction);
2029 return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
2031 /* compare pSrcStr with cache. */
2032 comp = g_strcmp0("cache", pAction);
2034 return MSG_PUSH_SL_ACTION_CACHE;
2036 /* default SL action value is execute-low. */
2037 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2041 unsigned long SmsPluginWapPushHandler::wspRetriveUintvarDecode(unsigned char* sourceData, unsigned long* currentPointer)
2043 unsigned long i = 0;
2044 unsigned long decodedValue;
2046 while (sourceData[*currentPointer +i] >= 0x80) i++;
2048 decodedValue = wspDecodeUintvar(i+1, sourceData + *currentPointer);
2049 *currentPointer = *currentPointer + i + 1;
2050 MSG_DEBUG("wspRetriveUintvarDecode: decodedValue=%d .\n", decodedValue);
2051 return decodedValue;
2055 unsigned long SmsPluginWapPushHandler::wspDecodeUintvar(unsigned long length, unsigned char* userVar)
2058 unsigned long decodedUintvar = 0;
2061 for (i = 0 ; i < length; i++) {
2062 decodedUintvar = decodedUintvar + (wspUintvarDecodeTable[i] * (userVar[length-(i+1)] & 0x7f));
2065 return decodedUintvar;
2069 void SmsPluginWapPushHandler::wspDecodeHeader(unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader)
2071 unsigned long iField;
2072 bool continueField = FALSE;
2073 unsigned long currentLength;
2075 char* encodedHeader = NULL;
2076 unique_ptr<char*, void(*)(char**)> encodedHeaderbuf(&encodedHeader, unique_ptr_deleter);
2078 char* outTemper = NULL;
2080 char* temper = NULL;
2081 unique_ptr<char*, void(*)(char**)> temperbuf(&temper, unique_ptr_deleter);
2083 unsigned char track;
2084 unsigned long iEncodedHeader = 0;
2085 unsigned char fieldCode = 0xff;
2087 /* outTemper is Decoded Headers.
2088 temper is Single Decoded Header.
2090 if (NULL == (outTemper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ])) {
2091 MSG_DEBUG("outTemper Memory allocation is failed.\n");
2094 memset(outTemper, 0, (WSP_STANDARD_STR_LEN_MAX * 5));
2095 currentLength = WSP_STANDARD_STR_LEN_MAX;
2097 MSG_DEBUG("wspDecodeHeader: Message header decoding started.\n");
2103 MSG_DEBUG("wspDecodeHeader: RAW data \n");
2104 for (loop = 0 ; loop < (int)encodedHeaderLen; loop++) {
2106 szTempBuf[0] = 0x00;
2107 snprintf(szTempBuf, sizeof(szTempBuf), "%2X ", sEncodedHeader[loop]);
2109 if (AcStrlen(szBuf) + 7 < 64) {
2110 strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2112 strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2113 MSG_DEBUG("[%s]", szBuf);
2115 strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2118 strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2119 MSG_DEBUG("[%s]", szBuf);
2120 MSG_DEBUG("fContentType=%d \n", fContentType);
2121 /* operation for content-type */
2122 /* makes psuedo- content-type fieldcode */
2123 /* 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. */
2126 encodedHeader = new char[ encodedHeaderLen + 1 ];
2127 if (encodedHeader == NULL) {
2128 MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2131 encodedHeader[0] = 0x91;
2132 memcpy(encodedHeader + 1, sEncodedHeader, (size_t)encodedHeaderLen);
2134 encodedHeader = new char[ encodedHeaderLen ];
2135 if (encodedHeader == NULL) {
2136 MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2140 memcpy(encodedHeader, sEncodedHeader, (size_t)encodedHeaderLen);
2143 /* Is it reacehd end of header? */
2144 while (iEncodedHeader < encodedHeaderLen) {
2145 /* Get memory for single header */
2146 if (temper == NULL) {
2147 temper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ];
2149 if (temper == NULL) {
2150 MSG_DEBUG("temper Memory allocation is failed.\n");
2153 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2155 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2159 /* this section presents header code page shifting procedure
2160 This part can be implemented by future request.
2163 track = encodedHeader[iEncodedHeader];
2165 if (track == 0x00) {
2166 MSG_DEBUG("WspLDecodeHeader: fieldcode is 0 \n");
2167 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2170 } else if ((track > 0) && (track < 0x20)) {
2172 } else if ((track < 0x7f) && (track > 0x1f)) { /* In this case, first byte is normal string. So it's considered to unknown header. */
2173 unsigned char* fieldName = (unsigned char*)gWapCodeBufferLeft;
2174 unsigned char* fieldValue = (unsigned char*)gWapCodeBufferRight;
2176 strncpy((char*)fieldName, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_LEFT_LEN_MAX-1);
2177 fieldName[WSP_CODE_BUFFER_LEFT_LEN_MAX-1] = '\0';
2178 iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldName) + 1;
2179 strncpy((char*)fieldValue, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_RIGHT_LEN_MAX-1);
2180 fieldValue[WSP_CODE_BUFFER_RIGHT_LEN_MAX-1] = '\0';
2181 iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldValue) + 1;
2183 strncat((char*)temper, (char*)fieldName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2184 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2185 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2186 /* this means 'don't process anymore.' */
2189 } else if (track > 0x7f) {
2190 /* In case of first byte is field code, else case is error. */
2191 /*if ((track & 0x7f) <= wspHeaderFieldCount) { */
2192 unsigned long fieldValueLen = encodedHeader[iEncodedHeader + 1];
2193 unsigned char fieldValue[1275];
2194 fieldCode = track & 0x7f;
2196 if ((fieldValueLen == 0) || (fieldValueLen == 0x80)) {
2197 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]);
2200 memset(fieldValue, 0, 1275);
2202 /* add field name */
2203 /* 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. */
2204 if (!continueField) {
2205 strncat((char*)temper, (char*)wspHeaderFieldName[fieldCode], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2206 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2207 continueField = FALSE;
2210 /* field value is string */
2211 /* In this case, it just copy field value. */
2212 if ((fieldValueLen > LENGTH_QUOTE) && (fieldValueLen < 0x80)) {
2213 /* string field value should be NULL terminated */
2214 strncat((char*)temper, (char*)(encodedHeader + iEncodedHeader + 1), (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2215 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2217 iEncodedHeader = iEncodedHeader + AcStrlen((char*)encodedHeader + iEncodedHeader + 1) + 2;
2220 /* first field value is length */
2221 /* If first byte of field value is length value, allocate field value by the length.
2222 In field value, data is
2223 1D 03 8F 24 24 - Then 8F 24 24 is field value.
2224 1D 1F 33.... - Then allocate 33H for FieldValue.
2226 1D 'Hi man!' Like 00, if string is come, then process without calculating field value.
2227 1D 8F 24 24 - In this case, original data is wrong.
2228 If accept-charset: ISO-10646-ucs-2;Q=0.7 is
2231 03 - field value length
2232 03 E8 47 - field value
2233 it's decoded by above value.
2235 if (fieldValueLen < 0x20) {
2236 if (fieldValueLen == LENGTH_QUOTE) {
2237 /* field length is encoded in UINTVAR */
2238 unsigned long uintvarLen = 0;
2239 fieldValueLen = wspRetriveUintvarDecode((unsigned char*) encodedHeader + iEncodedHeader + 2, &uintvarLen);
2240 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2 + uintvarLen, (size_t)fieldValueLen);
2241 iEncodedHeader = iEncodedHeader + fieldValueLen + uintvarLen + 2;
2244 if (fieldValueLen == 1) {
2245 /* field value is one byte integer over 0x80 */
2246 /* make it two byte integer */
2247 fieldValue[0] = 0x00;
2248 memcpy(fieldValue + 1, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2250 iEncodedHeader = iEncodedHeader + 1 + 2;
2252 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2253 fieldValue[fieldValueLen] = 0;
2254 iEncodedHeader = iEncodedHeader + fieldValueLen + 2;
2255 if ((fieldValueLen == 0) || (fieldValueLen == 0x80)) {
2256 MSG_DEBUG("%X \n", encodedHeader[iEncodedHeader]);
2262 /* field value is single encoded */
2263 if (fieldValueLen > 0x7f) {
2264 fieldValue[0] = encodedHeader[iEncodedHeader + 1];
2266 iEncodedHeader = iEncodedHeader + 2;
2268 /* processing normal pre-defined field decoding */
2270 MSG_DEBUG("WspLDecodeHeader: FieldCode %X\n", fieldCode);
2271 MSG_DEBUG("WspLDecodeHeader: fieldSize %d\n", fieldValueLen);
2273 if ((fieldCode > wspHeaderFieldCount) && (fieldCode != 0xff)) {
2274 MSG_DEBUG("WspLDecodeHeader: unknown fieldcode %X \n", track);
2275 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2280 switch (fieldCode) {
2281 /* accept charset */
2282 /* It's normal way of field process. */
2284 unsigned long i = 0;
2287 /* Case of length of charset greater than 1 are two thigins.
2288 1. code length of charset is greater than 1.
2289 2. It include parameter.
2292 if (1 != fieldValueLen) {
2293 code = wspHeaderDecodeInteger(fieldValue);
2294 /* Calculate iField. */
2295 if (fieldValue[0] < 0x80)
2296 iField = fieldValue[0];
2300 while (wspCharset[i].charsetCode != code)
2302 strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2303 /* If parameter exist */
2304 if (iField < fieldValueLen) {
2306 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2307 wspHeaderDecodeQValue(fieldValueLen - iField, fieldValue + iField, ¶m);
2308 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2311 code = fieldValue[0] & 0x7f;
2313 while ((wspCharset[i].charsetCode != code) && (wspCharset[i].charsetCode != 0xffff)) i++;
2314 strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2320 /* Like below routine, Same decoding routine process together. */
2321 /* Accept-encoding */
2323 /* content-encoding */
2327 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2328 if (integerValue > 2) {
2329 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(2).\n");
2332 strncat((char*)temper, (char*)wspEncodeMethod[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2335 /* contents type decoder */
2340 unsigned long contentsTypeCode;
2341 unsigned long i = 0;
2342 /* encoded content type length body */
2343 unsigned long tempLen;
2344 MSG_DEBUG("fieldValueLen: %d", fieldValueLen);
2346 /* Like HTTP result state 304, it's for processing without Content type. This part doesn't defined. */
2347 if (0 == fieldValueLen) {
2348 strncat((char*)temper, (char*)"None" , (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2351 /* 01 AE --> 00 AE --> AE*/
2352 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2353 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2354 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2357 if ((fieldValue[0] < 0x20) || (fieldValue[0] >= 0x80)) {
2358 if (fieldValue[0] >= 0x80) {
2360 } else if (fieldValueLen == 2 && fieldValue[0] == 0x03 && fieldValue[1] == 0x0A) { /* 06 05 02 03 0A AF 89 */
2361 fieldValue[3] = fieldValue[2];
2362 fieldValue[2] = fieldValue[1];
2363 fieldValue[1] = fieldValue[0];
2364 fieldValue[0] = 0x02;
2367 MSG_DEBUG("WspLDecodeHeader:For CPE problem\r\n");
2369 tempLen = fieldValue[0]; /* 06 06 03 02 03 16 AF 88 */
2373 char* szExtendedContent;
2375 contentsTypeCode = fieldValue[0] & 0x7f;
2376 while ((wspContentsType[i].contentsTypeCode != contentsTypeCode) && (i < wspContentsTypeCount)) i++;
2378 /* If specified content type doesn't exist */
2379 if (i < wspContentsTypeCount)
2380 strncat((char*)temper, (char*)wspContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2382 szExtendedContent = wspExtendedDecodeType((char)contentsTypeCode);
2384 if (szExtendedContent != NULL) {
2385 MSG_DEBUG("WspLDecodeHeader: Tele2 server problem \n ");
2386 strncat((char*)temper, (char*)szExtendedContent, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2389 contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
2391 while ((i < wspUnregisteredContentsTypeCount) && (wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode))
2394 /* If there is a Content-Type assigned, */
2395 if (i < wspUnregisteredContentsTypeCount)
2396 strncat((char*)temper, (char*)wspUnregisterContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2401 tempLen = AcStrlen((char*)fieldValue) + 1;
2403 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2404 MSG_DEBUG("WspLDecodeHeader: Attention, Decoding Check of Content-Type\n ", tempLen);
2407 /* If there is a parameter */
2408 if (tempLen < fieldValueLen) {
2410 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2411 wspHeaderDecodeParameter(fieldValue + tempLen, fieldValueLen - tempLen, ¶m);
2412 if (param != NULL) {
2413 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2414 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2421 /* content-language */
2423 /* accept-language */
2425 unsigned long i = 0;
2427 unsigned long tempLen;
2428 if ((fieldValue[0] < 0x20) || (fieldValue[0] > 0x80)) {
2429 if (fieldValue[0] > 0x80)
2432 tempLen = fieldValue[0];
2434 tempLen = AcStrlen((char*)fieldValue) + 1;
2438 code = wspHeaderDecodeInteger(fieldValue);
2439 while (wspLanguage[i].languageCode != code) {
2441 if (i == wspLanguageCount)
2445 if (i < wspLanguageCount) {
2446 strncat((char*)temper, (char*)wspLanguage[i].languageName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2449 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2452 if (tempLen < fieldValueLen) {
2454 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2455 wspHeaderDecodeQValue(fieldValueLen - tempLen, fieldValue + tempLen, ¶m);
2456 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2464 /* content-length */
2468 /* Bearer-indication */
2472 unsigned char temp[16];
2474 if ((fieldValueLen == 2) && (fieldValue[0] > 0x7f))
2475 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[1]);
2478 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2479 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2482 /* X-Wap-Application-Id */
2484 unsigned char temp[64];
2487 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2488 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2489 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2493 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2495 int count = sizeof(wspHeaderApplId)/sizeof(SMS_WSP_HEADER_PARAMETER_S);
2496 for (int i = 0; i < count ; ++i) {
2497 if ((unsigned int)integerValue == wspHeaderApplId[i].parameterCode) {
2498 snprintf((char*)temp, 64, "%s", wspHeaderApplId[i].parameterToken);
2499 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2505 /* Accept-Application */
2507 if (0x80 == fieldValue[0]) {
2508 strncat((char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2510 unsigned char temp[16];
2512 if ((fieldValueLen == 2) && (fieldValue[0] == 1))
2513 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[0]);
2516 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2517 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2525 /* if-unmodified-since */
2529 /* if-modified-since */
2535 char* decodedString = NULL;
2536 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2537 wspHeaderDecodeDateValue(fieldValueLen, fieldValue, &decodedString);
2538 strncat((char*)temper, (char*)decodedString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2544 if (fieldValue[0] == 0x80)
2545 strncat((char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2549 if (fieldValue[0] == 0x80)
2550 strncat((char*)temper, "None", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2551 if (fieldValue[0] == 0x81)
2552 strncat((char*)temper, "Bytes", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2556 unsigned char temp[1275];
2557 memcpy(temp, fieldValue, (size_t)fieldValueLen);
2558 temp[fieldValueLen] = 0;
2559 wspHeaderCopyDecodedString(temp, ¤tLength, &temper);
2565 /* proxy - authorization */
2567 if (fieldValue[0] == 0x80) {
2568 char* addString = NULL;
2569 unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2570 wspHeaderDecodeAuth(fieldValueLen, fieldValue, &addString);
2571 strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2573 iField = AcStrlen((char*)fieldValue) + 1;
2575 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2576 if (iField < fieldValueLen) {
2578 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2579 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, ¶m);
2580 if (param != NULL) {
2581 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2582 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2591 /* Proxy-authenticate */
2593 if (0 == fieldValueLen)
2595 if (fieldValue[0] == 0x80) {
2596 char* addString = NULL;
2597 unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2598 wspHeaderDecodeChallenge(fieldValueLen, fieldValue, &addString);
2599 strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2601 unsigned char authScheme[WSP_STANDARD_STR_LEN_MAX + 1];
2602 unsigned char realmValue[WSP_STANDARD_STR_LEN_MAX];
2603 unsigned char addedString[WSP_STANDARD_STR_LEN_MAX];
2605 strncpy((char*)authScheme, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX -1);
2606 iField = AcStrlen((char*)authScheme) + 1;
2607 strncpy((char*)realmValue, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2608 iField = iField + AcStrlen((char*)realmValue) + 1;
2609 snprintf((char*)addedString, sizeof(addedString), "%s %s", authScheme, realmValue);
2610 wspHeaderCopyDecodedString(addedString, ¤tLength, &temper);
2612 if (iField < fieldValueLen) {
2614 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2615 wspHeaderDecodeParameter(fieldValue + iField, fieldValueLen - iField, ¶m);
2616 if (param != NULL) {
2617 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2618 wspHeaderCopyDecodedString((unsigned char*)param, ¤tLength, &temper);
2624 /* content -range */
2626 unsigned long first, len, last;
2628 unsigned char temp[16];
2631 strncat((char*)temper, " bytes ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2633 first = wspRetriveUintvarDecode(fieldValue, &iField);
2634 len = wspRetriveUintvarDecode(fieldValue, &iField);
2635 /* 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. */
2636 last = first + contentsLength - 1;
2638 snprintf((char*)temp, sizeof(temp), "%u-%u/%u", (unsigned int)first, (unsigned int)last, (unsigned int)len);
2639 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2645 char* cacheString = NULL;
2646 unique_ptr<char*, void(*)(char**)> cacheStringbuf(&cacheString, unique_ptr_deleter);
2648 wspHeaderDecodeCacheControl(fieldValue, fieldValueLen, &cacheString);
2649 strncat((char*)temper, (char*)cacheString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2655 if (fieldValue[0] == 0x80) {
2656 strncat((char*)temper, (char*)wspCacheControl[0], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2658 if (1 < fieldValueLen) {
2660 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2661 wspHeaderDecodeParameter(fieldValue, fieldValueLen, ¶m);
2663 if (param != NULL) {
2664 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2665 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2675 unsigned long i = 0;
2676 while (wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen) != wspMethodType[i].methodCode) i++;
2677 strncat((char*)temper, (char*)wspMethodType[i].methodName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2682 strncat((char*)temper, "bytes=", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2683 if (fieldValue[0] == 0x80) {
2684 unsigned char temp[16];
2685 unsigned long first, last;
2688 first = wspRetriveUintvarDecode(fieldValue, &iField);
2689 last = wspRetriveUintvarDecode(fieldValue, &iField);
2691 snprintf((char*)temp, sizeof(temp), "%u-%u", (unsigned int)first, (unsigned int)last);
2692 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2694 if (fieldValue[0] == 0x81) {
2695 unsigned char temp[16];
2696 unsigned long suffix;
2698 suffix = wspRetriveUintvarDecode(fieldValue, &iField);
2700 snprintf((char*)temp, sizeof(temp), "-%u", (unsigned int)suffix);
2705 if (fieldValue[0] == 0x80) {
2707 unique_ptr<char*, void(*)(char**)> tempbuf(&temp, unique_ptr_deleter);
2709 wspHeaderDecodeDateValue(fieldValueLen - 1, fieldValue + 1, &temp);
2710 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2713 if (fieldValue[0] == 0x81) {
2714 unsigned char temp[16];
2716 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2717 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2720 /* transfer-encoding */
2722 /* No other cases allowed */
2723 if (fieldValue[0] == 0x80)
2724 strncat((char*)temper, "chunked", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2729 int integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2730 if (integerValue > wspHeaderFieldCount) {
2731 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x%x).\n", wspHeaderFieldCount);
2734 strncat((char*)temper, (char*)wspHeaderFieldName[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2739 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2741 if (fieldValue[0] < 0x20)
2742 iField = fieldValue[0];
2746 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, iField));
2747 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2748 if (iField < fieldValueLen) {
2749 unsigned char agent[WSP_STANDARD_STR_LEN_MAX];
2750 unsigned char text[WSP_STANDARD_STR_LEN_MAX];
2751 strncpy((char*)agent, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2752 iField = iField + AcStrlen((char*)agent) + 1;
2753 strncpy((char*)text, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2754 snprintf((char*)temp, sizeof(temp), " %s %s", agent, text);
2755 wspHeaderCopyDecodedString(temp, ¤tLength, &temper);
2759 /* content-disposition */
2761 if (fieldValue[0] == 0x80)
2762 strncat((char*)temper, "form-data", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2764 if (fieldValue[0] == 0x81)
2765 strncat((char*)temper, "attachment", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2767 if (1 < fieldValueLen) {
2769 unique_ptr<char*, void(*)(char**)> parambuf(¶m, unique_ptr_deleter);
2770 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, ¶m);
2772 if (param != NULL) {
2773 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2774 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2780 temper[AcStrlen((char*)temper) + fieldValueLen] = '\0';
2781 memcpy(temper, fieldValue, (size_t)fieldValueLen);
2783 /* Profile-Warning */
2785 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2787 snprintf((char*)temp, sizeof(temp), "%lX", wspHeaderDecodeInteger(fieldValue));
2789 temp[1] = (unsigned char)0x30;
2791 if (fieldValueLen > 1) {
2792 /* copy warn-target - URI */
2793 strncat((char*)temp, (char*)(fieldValue + 1), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2794 if (fieldValueLen > (AcStrlen((char*)(fieldValue + 1)) + 1)) {
2795 /* copy warn-date */
2796 char* decodedString = NULL;
2797 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2798 wspHeaderDecodeDateValue(fieldValueLen - (AcStrlen((char*)(fieldValue + 1)) + 2), fieldValue + AcStrlen((char*)(fieldValue + 1)) + 1, &decodedString);
2799 strncat((char*)temp, (char*)decodedString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2802 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2811 /* It deosn't finished decoding yet. */
2812 if ((iEncodedHeader < encodedHeaderLen) && (fieldCode != 0xff)) {
2813 /* In here, iEncodedHeader already point next field code to be decoded. */
2814 /* If this code is same, then set continueField else add CRLF. */
2815 if (fieldCode == (encodedHeader[iEncodedHeader] & 0x7f)) {
2816 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2817 continueField = TRUE;
2819 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2820 continueField = FALSE;
2823 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2826 /* add single header to total headers */
2827 strncat((char*)outTemper, (char*)temper, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)outTemper)-1);
2828 MSG_DEBUG("WspLDecodeHeader: Single Header : %s\r\n", temper);
2832 MSG_DEBUG("WspLDecodeHeader: Header decoding ended.\n");
2834 *pHeader = outTemper;
2840 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeInteger(unsigned char* data)
2842 /* we only can handle max 32bit integer */
2846 unsigned long integer;
2847 unsigned char seg[4];
2850 returner.integer = 0;
2852 if (data[0] < 0x80) {
2853 unsigned long IntLen = 0;
2855 IntLen = (data[0] > 0x04) ? 0x04:data[0];
2857 MSG_DEBUG("WspLHeaderDecodeInteger: input %d , length %d\n", data[0], IntLen);
2859 for (i = 0; i < IntLen; i++)
2860 returner.seg[IntLen-(i+1)] = data[i+1];
2862 return returner.integer;
2865 return data[0] & 0x7f;
2869 void SmsPluginWapPushHandler::wspHeaderDecodeQValue(unsigned long length, unsigned char* data, char** pDecodedString)
2871 unsigned short qBase = 0;
2874 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2875 if (*pDecodedString == NULL) {
2876 MSG_DEBUG("WspLHeaderDecodeQValue:MemAlloc failed\n");
2880 memcpy(&qBase, data, (size_t)length);
2881 qValue = (float)qBase;
2883 qValue = qValue - 100;
2884 qValue = qValue / 1000;
2885 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.3f", qValue);
2887 /* qValue variable is divided by 100. And it's multiplied by 100.
2888 It's to resolve problem of changed 0.01 of qValue. */
2889 unsigned long qValueTemp;
2890 qValue = qValue - 1;
2891 qValue = qValue / 100;
2892 qValueTemp = (unsigned long)(qValue * 100);
2893 if (0 == (qValueTemp % 10))
2894 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.1f", qValue);
2896 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.2f", qValue);
2902 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length)
2907 unsigned long integer;
2908 unsigned short seg[4];
2911 returner.integer = 0;
2914 return data[0] & 0x7f;
2916 returner.integer = 0;
2918 for (i = 0 ; i < length; i++) {
2919 returner.integer = returner.integer + (data[i] * (0x1 << ((length - (i + 1)) * 8)));
2920 MSG_DEBUG("WspLHeaderDecodeIntegerByLength: %d \n", returner.integer);
2923 return returner.integer;
2927 char* SmsPluginWapPushHandler::wspExtendedDecodeType(char contentType)
2931 while (wspExtendedContentsType[i].contentsTypeCode != contentType) {
2932 if (wspExtendedContentsType[i].contentsTypeCode == 0xff)
2937 return (char*)wspExtendedContentsType[i].contentsTypeName;
2941 void SmsPluginWapPushHandler::wspHeaderDecodeParameter(unsigned char* data, unsigned long length, char** pParam)
2943 char* param = *pParam;
2945 unsigned long SecurityTypeCode;
2946 unsigned long i = 0;
2948 if (data[0] < 0x80) {
2949 /* unknown parameter type */
2950 param = new char[WSP_STANDARD_STR_LEN_MAX];
2952 if (param == NULL) {
2953 MSG_DEBUG("WspLHeaderDecodeParameter:MemAlloc failed\n");
2957 strncpy((char*)param, (char*)data, WSP_STANDARD_STR_LEN_MAX - 1);
2959 if (NO_VALUE == data[AcStrlen((char*)param) + 1]) {
2964 strncat((char*)param, "=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
2965 strncat((char*)param, (char*)(data + AcStrlen((char*)param)), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
2972 switch (data[0] & 0x7f) {
2974 wspHeaderDecodeQValue(length - 1, data + 1, ¶m);
2977 wspHeaderDecodeCharset(length - 1 , data + 1, ¶m);
2980 wspHeaderDecodeVersion(length - 1, data + 1, ¶m);
2984 /* param = (unsigned char *)malloc((size_t)WSP_STANDARD_STR_LEN_MAX); */
2985 param = new char[WSP_STANDARD_STR_LEN_MAX];
2986 if (param == NULL) {
2987 MSG_DEBUG("WspLHeaderDecodeParameter: 0x03 MemAlloc failed\n");
2990 snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Type=%i", (int)wspHeaderDecodeInteger(data + 1));
2994 param = new char[WSP_STANDARD_STR_LEN_MAX];
2996 if (param == NULL) {
2997 MSG_DEBUG("WspLHeaderDecodeParameter:0x08 MemAlloc failed\n");
3000 snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Padding=%i", (int)wspHeaderDecodeInteger(data + 1));
3004 param = new char[WSP_STANDARD_STR_LEN_MAX];
3006 if (param == NULL) {
3007 MSG_DEBUG("WspLHeaderDecodeParameter:0x05 MemAlloc failed\n");
3010 strncpy((char*)param, "Name=", WSP_STANDARD_STR_LEN_MAX-1);
3011 memcpy(param + 5, data + 1, length - 1);
3012 param[5 + length - 1] = '\0';
3016 param = new char[WSP_STANDARD_STR_LEN_MAX];
3018 if (param == NULL) {
3019 MSG_DEBUG("WspLHeaderDecodeParameter:0x06 MemAlloc failed\n");
3022 strncpy((char*)param, "Filename=", WSP_STANDARD_STR_LEN_MAX-1);
3023 memcpy(param + 9, (char*)(data + 1), (size_t)(length - 1));
3024 param[9 + length - 1] = '\0';
3031 /*OMA Provisioning*/
3033 param = new char[WSP_STANDARD_STR_LEN_MAX];
3035 if (param == NULL) {
3036 MSG_DEBUG("WspLHeaderDecodeParameter:0x11 MemAlloc failed\n");
3039 strncpy((char*)param, "SEC=", WSP_STANDARD_STR_LEN_MAX-1);
3040 SecurityTypeCode = data[1] & 0x7f;
3041 while ((i < wspSecurityTypeCount) && (wspSecurityType[i].SecurityTypeCode != SecurityTypeCode))
3044 if (i < wspSecurityTypeCount) {
3045 strncat((char*)param, (char*)wspSecurityType[i].SecurityTypeName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3048 if (0x12 == (data[2] & 0x7f)) {
3049 strncat((char*)param, "; MAC=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3050 memcpy(param+AcStrlen((char*)param), (char*)(data+3), (size_t)length-3);
3065 void SmsPluginWapPushHandler::wspHeaderDecodeCharset(unsigned long length, unsigned char* data, char**pDecodedString)
3067 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3069 if (*pDecodedString == NULL) {
3070 MSG_DEBUG("WspLHeaderDecodeCharset:MemAlloc failed\n");
3074 strncpy((char*)*pDecodedString, "charset=", WSP_STANDARD_STR_LEN_MAX-1);
3076 if (data[0] > 0x80) {
3077 unsigned long code = wspHeaderDecodeInteger(data);
3078 unsigned long i = 0;
3079 while (wspCharset[i].charsetCode != code) {
3080 if (wspCharset[i].charsetCode == 0xffff) {
3085 strncat((char*)*pDecodedString, (char*)wspCharset[i].charsetName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pDecodedString)-1);
3087 unsigned long lastLen = AcStrlen((char*)*pDecodedString);
3088 memcpy((char*)(*pDecodedString + lastLen), data, (size_t)length);
3089 *pDecodedString[length + lastLen] = '\0';
3096 void SmsPluginWapPushHandler::wspHeaderDecodeVersion(unsigned long length, unsigned char* data, char** pDecodedString)
3098 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3100 if (*pDecodedString == NULL) {
3101 MSG_DEBUG("WspLHeaderDecodeVersion:MemAlloc failed\n");
3106 /* untyped version */
3107 memcpy(*pDecodedString, data, (size_t)length);
3110 unsigned char majorVer = ((data[0] & 0x7f) >> 4);
3111 unsigned char minorVer = data[0] & 0x0f;
3112 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "level=%u.%u", majorVer, minorVer);
3119 void SmsPluginWapPushHandler::wspHeaderDecodeDateValue(unsigned long length, unsigned char* data, char** pDecodedString)
3124 MSG_DEBUG("WspLHeaderDecodeDateValue: \n");
3126 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3128 if (*pDecodedString == NULL) {
3129 MSG_DEBUG("WspLHeaderDecodeDateValue:MemAlloc failed\n");
3133 lTime = wspHeaderDecodeIntegerByLength(data, length);
3135 pTMData = (struct tm*)gmtime((const time_t*)&lTime);
3137 if (pTMData == NULL) {
3138 MSG_DEBUG("WspLHeaderDecodeDateValue: Date decode fail \n");
3139 strncpy((char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
3143 /* check date value validity */
3144 if ((pTMData->tm_wday > 6) || (pTMData->tm_mon > 11) || (pTMData->tm_mday > 31)) {
3145 MSG_DEBUG("WspLHeaderDecodeDateValue: Date decode fail %d, %d, %d \n", pTMData->tm_wday, pTMData->tm_mon, pTMData->tm_mday);
3146 strncpy((char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
3150 #ifdef MSG_FW_FOR_DEBUG
3151 /* Date type selection */
3152 switch (wspMachineStatus.dateType) {
3153 /* UNIX asciitime function */
3154 case UNIX_DATE_TYPE:
3155 snprintf((char*)decodedString, sizeof(decodedString), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData->tm_wday], wspMonth[pTMData->tm_mon],
3156 pTMData->tm_mday, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec, pTMData->tm_year + 1900);
3158 case RFC1123_DATE_TYPE:
3159 snprintf((char*)decodedString, sizeof(decodedString), "%s, %u %s %u %u:%u:%u GMT", wspWeek[pTMData->tm_wday], pTMData->tm_mday,
3160 wspMonth[pTMData->tm_mon], pTMData->tm_year + 1900, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec);
3162 case RFC850_DATE_TYPE:
3163 /* Have some Y2K Problems */
3164 /* 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. */
3165 snprintf((char*)decodedString, sizeof(decodedString), "%s, %2u-%s-%2u %u:%u:%u GMT", wspWeekDay[pTMData->tm_wday], pTMData->tm_mday,
3166 wspMonth[pTMData->tm_mon], pTMData->tm_year % CENTURY, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec);
3170 /*UNIX_DATE_TYPE : */
3171 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],
3172 pTMData->tm_mday, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec, pTMData->tm_year + 1900);
3178 void SmsPluginWapPushHandler::wspHeaderCopyDecodedString(unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper)
3180 unsigned long elementLen = AcStrlen((char*)szDecodedString);
3181 char* temper2 = NULL;
3184 *currentLen = *currentLen + elementLen + 2;
3186 if (*currentLen > AcStrlen((char*)* pTemper) + 2) {
3187 temper2 = new char[(*currentLen + 1)];
3189 if (temper2 == NULL) {
3190 MSG_DEBUG("WspLHeaderCopyDecodedString:MemAlloc failed\n");
3193 strncpy((char*)temper2, (char*)* pTemper, *currentLen);
3195 strncpy((char*)temper2, (char*)szDecodedString, *currentLen);
3204 void SmsPluginWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3206 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3207 unsigned char passWd[WSP_STANDARD_STR_LEN_MAX];
3208 unsigned long iField = 0;
3211 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX * 2];
3213 if (*pDecodedString == NULL) {
3214 MSG_DEBUG("WspLHeaderDecodeAuth:MemAlloc failed\n");
3218 /* skip 'basic' code */
3220 memset(authStr, 0x00, sizeof(authStr));
3221 snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
3222 sscanf((char*)(fieldValue + iField), authStr, userId);
3223 iField = iField + AcStrlen((char*)userId) + 1;
3224 memset(authStr, 0x00, sizeof(authStr));
3225 snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(passWd));
3226 sscanf((char*)(fieldValue + iField), authStr, passWd);
3227 iField = iField + AcStrlen((char*)userId) + 1;
3228 snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX*2), "basic %s/%s", userId, passWd);
3234 void SmsPluginWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3236 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3237 unsigned long iField = 0;
3240 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3242 if (*pDecodedString == NULL) {
3243 MSG_DEBUG("WspLHeaderDecodeChallenge:MemAlloc failed\n");
3247 /* skip 'basic' code */
3249 memset(authStr, 0x00, sizeof(authStr));
3250 snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
3251 sscanf((char*)(fieldValue + iField), authStr, userId);
3252 iField = iField + AcStrlen((char*)userId) + 1;
3254 snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "basic realm=\"%s\"", userId);
3260 void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString)
3262 unsigned char paramString[WSP_STANDARD_STR_LEN_MAX];
3263 unsigned char cacheCode;
3265 *pCacheString = new char[WSP_STANDARD_STR_LEN_MAX];
3266 if (*pCacheString == NULL) {
3267 MSG_DEBUG("WspLHeaderDecodeCacheControl:MemAlloc failed\n");
3271 if (1 == fieldValueLen) {
3272 /* only one directive */
3273 if (fieldValue[0] > 0x8b) {
3274 return; /* It's error detection. can be omitted. */
3276 strncpy((char*)*pCacheString, (char*)wspCacheControl[fieldValue[0] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3280 if (fieldValue[0] > 0x7f) {
3281 /* directive that has parameter */
3282 cacheCode = fieldValue[0] & 0x7f;
3283 switch (cacheCode) {
3289 if (fieldValue[1] > 0x7f) {
3290 /* well known field name */
3291 strncpy((char*)paramString, (char*)wspHeaderFieldName[fieldValue[1] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3292 paramString[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3294 /* unknown field name */
3295 strncpy((char*)paramString, (char*)fieldValue + 1 , WSP_STANDARD_STR_LEN_MAX-1);
3305 snprintf((char*)paramString, sizeof(paramString), "%u", (unsigned int)wspHeaderDecodeInteger(fieldValue + 1));
3310 snprintf((char*)*pCacheString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString);
3312 /* cache extentions */
3313 /* In case of come directive of doesn't specified string style */
3315 unsigned long stringLen;
3317 strncpy((char*)*pCacheString, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX-1);
3318 stringLen = AcStrlen((char*)*pCacheString);
3320 if (stringLen + 1 < fieldValueLen) {
3321 if (fieldValue[stringLen+ 1] > 0x7f) {
3322 int untyped = (int)wspHeaderDecodeIntegerByLength(fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1));
3324 snprintf(szString, sizeof(szString), "%d", untyped);
3325 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3326 strncat((char*)*pCacheString, (char*)szString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3328 if (fieldValue[fieldValueLen] == 0) {
3329 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3330 strncat((char*)*pCacheString, (char*)fieldValue + stringLen + 1 , WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);