3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
5 * This file is part of msg-service.
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 * Sangkoo Kim <sangkoo.kim@samsung.com>
9 * Seunghwan Lee <sh.cat.lee@samsung.com>
10 * SoonMin Jung <sm0415.jung@samsung.com>
11 * Jae-Young Lee <jy4710.lee@samsung.com>
12 * KeeBum Kim <keebum.kim@samsung.com>
14 * PROPRIETARY/CONFIDENTIAL
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
32 #include "MsgCppTypes.h"
33 #include "MsgGconfWrapper.h"
34 #include "MsgException.h"
35 #include "MsgUtilFile.h"
36 #include "SmsPluginStorage.h"
37 #include "SmsPluginTransport.h"
38 #include "SmsPluginEventHandler.h"
39 #include "SmsPluginWapPushHandler.h"
42 #include "drm-service.h"
44 static unsigned short wapPushPortList [] = {0x0b84, 0x0b85, 0x23F0, 0x23F1, 0x23F2, 0x23F3, 0xC34F};
46 const SMS_PUSH_APP_INFO_S pushDefaultApplication [] =
48 {(char*)"text/vnd.wap.si", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SI},
49 {(char*)"application/vnd.wap.sic", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SIC},
50 {(char*)"text/vnd.wap.sl", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SL},
51 {(char*)"application/vnd.wap.slc", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SLC},
52 {(char*)"text/vnd.wap.co", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_CO},
53 {(char*)"application/vnd.wap.coc", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_COC},
55 {(char*)"application/vnd.wap.mms-message", (char*)"X-Wap-Application-Id: x-wap-application:mms.ua\r\n", SMS_WAP_APPLICATION_MMS_UA},
57 {(char*)"application/vnd.wap.sia", (char*)"X-Wap-Application-Id: x-wap-application:push.sia\r\n", SMS_WAP_APPLICATION_PUSH_SIA},
59 {(char*)"application/vnd.syncml.dm+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.dm\r\n", SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP},
60 {(char*)"application/vnd.syncml.dm+xml", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.dm\r\n", SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML},
61 {(char*)"application/vnd.syncml.notification", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.dm\r\n", SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION},
62 {(char*)"application/vnd.syncml.ds.notification", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.ds\r\n", SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION},
63 {(char*)"application/vnd.syncml+wbxml", (char*)"X-Wap-Application-Id:x-wap-application:push.syncml", SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML},
65 {(char*)"application/vnd.wap.locc+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:loc.ua\r\n", SMS_WAP_APPLICATION_LOC_UA_WBXML},
66 {(char*)"application/vnd.wap.loc+xml", (char*)"X-Wap-Application-Id: x-wap-application:loc.ua\r\n", SMS_WAP_APPLICATION_LOC_UA_XML},
68 {(char*)"application/vnd.oma.dd+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_XML},
69 {(char*)"application/vnd.oma.drm.message", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_MESSAGE},
70 {(char*)"application/vnd.oma.drm.content", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_CONETENT},
71 {(char*)"application/vnd.oma.drm.rights+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML},
72 {(char*)"application/vnd.oma.drm.rights+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML},
73 {(char*)"application/vnd.oma.drm.ro+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_V2_RO_XML},
74 {(char*)"application/vnd.oma.drm.roap-pdu+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML},
75 {(char*)"application/vnd.oma.drm.roap-trigger+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML},
76 {(char*)"application/vnd.oma.drm.roap-trigger+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML},
78 {(char*)"text/vnd.wap.emn+xml", (char*)"X-Wap-Application-Id: x-wap-application:emn.ua\r\n", SMS_WAP_APPLICATION_PUSH_EMAIL_XML},
79 {(char*)"application/vnd.wap.emn+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:emn.ua\r\n", SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML},
80 {(char*)"application/vnd.wv.csp.cir", (char*)"X-Wap-Application-Id: x-wap-application:wv.ua\r\n", SMS_WAP_APPLICATION_PUSH_IMPS_CIR},
81 {(char*)"application/vnd.omaloc-supl-init", (char*)"X-Wap-Application-Id: x-oma-application:ulp.ua\r\n", SMS_WAP_APPLICATION_LBS},
86 char gWapCodeBufferLeft[WSP_CODE_BUFFER_LEFT_LEN_MAX];
87 char gWapCodeBufferRight[WSP_CODE_BUFFER_RIGHT_LEN_MAX];
89 const unsigned long wspUintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00200000, 0x10000000};
91 const unsigned char wspHeaderFieldCount = 0x43;
92 const unsigned char wspContentsTypeCount = 0x34;
93 const unsigned long wspLanguageCount = 0x11a;
94 const unsigned char wspSecurityTypeCount = 0x04;
97 static const SMS_WSP_CONTENTS_TYPE_S wspExtendedContentsType[] =
99 { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
100 { (char*)"application/vnd.wap.connectivity-wbxml", 0x36 },
101 { (char*)"application/pkcs7-mime", 0x37 },
102 { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
103 { (char*)"application/vnd.wap.signed-certificate", 0x39 },
104 { (char*)"application/vnd.wap.cert-response", 0x3A },
105 { (char*)"application/xhtml+xml", 0x3B },
106 { (char*)"application/wml+xml", 0x3C },
107 { (char*)"text/css", 0x3D },
109 { (char*)"application/vnd.wap.mms-message", 0x3E },
111 { (char*)"application/vnd.wap.rollover-certificate", 0x3F },
112 { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
113 { (char*)"application/vnd.wap.loc+xml", 0x41 },
114 { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
115 { (char*)"application/vnd.syncml.dm+xml", 0x43 },
116 { (char*)"application/vnd.syncml.notification", 0x44 },
117 { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
118 { (char*)"application/vnd.wv.csp.cir", 0x46 },
120 { (char*)"application/vnd.oma.dd+xml", 0x47},
121 { (char*)"application/vnd.oma.drm.message", 0x48 },
122 { (char*)"application/vnd.oma.drm.content", 0x49 },
123 { (char*)"application/vnd.oma.drm.rights+xml", 0x4A },
124 { (char*)"application/vnd.oma.drm.rights+wbxml", 0x4B },
125 { (char*)"application/vnd.syncml.ds.notification", 0x4E},
126 { (char*)"application/mikey", 0x52},
131 const char* wspHeaderFieldName[] =
133 (char*)"Accept", //0x00
134 (char*)"Accept-Charset",
135 (char*)"Accept-Encoding",
136 (char*)"Accept-Language",
137 (char*)"Accept-Ranges",
140 (char*)"Authorization",
141 (char*)"Cache-Control",
143 (char*)"Content-Base", //0x0a
144 (char*)"Content-Encoding",
145 (char*)"Content-Language",
146 (char*)"Content-Length",
147 (char*)"Content-Location",
148 (char*)"Content-MD5",
149 (char*)"Content-Range", //0x10
150 (char*)"Content-Type",
154 (char*)"From", //0x15
156 (char*)"If-Modified-Since",
158 (char*)"If-None-Match",
159 (char*)"If-Range", //0x1a
160 (char*)"If-Unmodified-Since",
162 (char*)"Last-Modified",
163 (char*)"Max-Forwards",
165 (char*)"Proxy-Authenticate", //0x20
166 (char*)"Proxy-Authorization",
170 (char*)"Retry-After", //0x25
172 (char*)"Transfer-Encodig",
175 (char*)"Vary", //0x2a
178 (char*)"Www-Authenticate",
179 (char*)"Content-Disposition",
180 (char*)"X-Wap-Application-Id",
181 (char*)"X-Wap-Content-URI", //0x30
182 (char*)"X-Wap-Iinitiator-URI",
183 (char*)"Accept-Application", // Back
184 (char*)"Bearer-Indication",
186 (char*)"Profile", //0x35
187 (char*)"Profile-Diff",
188 (char*)"Profile-Warning", // end of WAP 1.2
191 (char*)"Trailer", //0x3a
192 (char*)"Accept-Charset", //Back
193 (char*)"Accept-Encoding", // Back
194 (char*)"Cache-Control", // back
195 (char*)"Content-Range",
197 (char*)"Content-ID", //x40
200 (char*)"Encoding-Version"
204 const SMS_WSP_CHARSET_S wspCharset[] =
206 { (char*)"big5", 0x07ea },
207 { (char*)"iso-10646-ucs-2", 0x03e8 },
208 { (char*)"iso-8859-1", 0x04 },
209 { (char*)"iso-8859-2", 0x05 },
210 { (char*)"iso-8859-3", 0x06 },
211 { (char*)"iso-8859-4", 0x07 },
212 { (char*)"iso-8859-5", 0x08 },
213 { (char*)"iso-8859-6", 0x09 },
214 { (char*)"iso-8859-7", 0x0a },
215 { (char*)"iso-8859-8", 0x0b },
216 { (char*)"iso-8859-9", 0x0c },
217 { (char*)"shift-JIS", 0x11 },
218 { (char*)"us-ascii", 0x03 },
219 { (char*)"utf-8", 0x6a },
220 { (char*)"none", 0x26 },
221 { (char*)"", 0xffff }
226 const char* wspEncodeMethod[] =
234 const SMS_WSP_CONTENTS_TYPE_S wspContentsType[] =
236 { (char*)"*/*", 0x00 },
237 { (char*)"text/*", 0x01 },
238 { (char*)"text/html", 0x02 },
239 { (char*)"text/plain", 0x03 },
240 { (char*)"text/x-hdml", 0x04 },
241 { (char*)"text/x-ttml", 0x05 },
242 { (char*)"text/x-vCalendar", 0x06 },
243 { (char*)"text/x-vCard", 0x07 },
244 { (char*)"text/vnd.wap.wml", 0x08 },
245 { (char*)"text/vnd.wap.wmlscript", 0x09 },
246 { (char*)"text/vnd.wap.wta-event", 0x0a },
247 { (char*)"multipart/*", 0x0b },
248 { (char*)"multipart/mixed", 0x0c },
249 { (char*)"multipart/form-data", 0x0d },
250 { (char*)"multipart/byteranges", 0x0e },
251 { (char*)"multipart/alternative", 0x0f },
252 { (char*)"application/*", 0x10 },
253 { (char*)"application/java-vm", 0x11 },
254 { (char*)"application/x-www-form-urlencoded", 0x12 },
255 { (char*)"application/x-hdmlc", 0x13 },
256 { (char*)"application/vnd.wap.wmlc", 0x14 },
257 { (char*)"application/vnd.wap.wmlscriptc", 0x15 },
258 { (char*)"application/vnd.wap.wta-eventc", 0x16 },
259 { (char*)"application/vnd.wap.uaprof", 0x17 },
260 { (char*)"application/vnd.wap.wtls-ca-certificate", 0x18 },
261 { (char*)"application/vnd.wap.wtls-user-certificate", 0x19 },
262 { (char*)"application/x-x509-ca-cert", 0x1a },
263 { (char*)"application/x-x509-user-cert", 0x1b },
264 { (char*)"image/*", 0x1c },
265 { (char*)"image/gif", 0x1d },
266 { (char*)"image/jpeg", 0x1e },
267 { (char*)"image/tiff", 0x1f },
268 { (char*)"image/png", 0x20 },
269 { (char*)"image/vnd.wap.wbmp", 0x21 },
270 { (char*)"application/vnd.wap.multipart.*", 0x22 },
271 { (char*)"application/vnd.wap.multipart.mixed", 0x23 },
272 { (char*)"application/vnd.wap.multipart.form-data", 0x24 },
273 { (char*)"application/vnd.wap.multipart.byteranges", 0x25 },
274 { (char*)"application/vnd.wap.multipart.alternative", 0x26 },
275 { (char*)"application/xml", 0x27 },
276 { (char*)"text/xml",0x28 },
277 { (char*)"application/vnd.wap.wbxml", 0x29 },
278 { (char*)"application/x-x968-cross-cert", 0x2a },
279 { (char*)"application/x-x968-ca-cert", 0x2b },
280 { (char*)"application/x-x968-user-cert", 0x2c },
281 { (char*)"text/vnd.wap.si", 0x2d },
282 { (char*)"application/vnd.wap.sic", 0x2e },
283 { (char*)"text/vnd.wap.sl", 0x2f },
284 { (char*)"application/vnd.wap.slc", 0x30 },
285 { (char*)"text/vnd.wap.co", 0x31 },
286 { (char*)"application/vnd.wap.coc", 0x32 },
287 { (char*)"application/vnd.wap.multipart.related", 0x33 },
288 { (char*)"application/vnd.wap.sia", 0x34 },
290 { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
291 { (char*)"application/vnd.connectivity-wbxml", 0x36 },
292 { (char*)"application/pkcs7-mime", 0x37 },
293 { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
294 { (char*)"application/vnd.wap.signed-certificate", 0x39 },
295 { (char*)"application/vnd.wap.cert-response", 0x3A },
296 { (char*)"application/xhtml+xml", 0x3B },
297 { (char*)"application/wml+xml", 0x3C },
298 { (char*)"text/css", 0x3D },
300 { (char*)"application/vnd.wap.mms-message", 0x3E },
302 { (char*)"application/vnd.wap.rollover-certificate", 0x3F },
303 { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
304 { (char*)"application/vnd.wap.loc+xml", 0x41 },
305 { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
306 { (char*)"application/vnd.syncml.dm+xml", 0x43 },
307 { (char*)"application/vnd.syncml.notification", 0x44 },
308 { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
309 { (char*)"application/vnd.wv.csp.cir", 0x46 }
312 static const SMS_WAP_UNREGISTER_CONTENTS_TYPE_S wspUnregisterContentsType[]=
314 { (char*)"application/vnd.wap.emn+wbxml", 0x30A},
315 { (char*)"application/vnd.omaloc-supl-init", 0x312},
316 { (char*)"application/vnd.oma.drm.roap-trigger+wbxml", 0x316}
319 const unsigned long wspUnregisteredContentsTypeCount = sizeof(wspUnregisterContentsType)/sizeof(SMS_WAP_UNREGISTER_CONTENTS_TYPE_S);
321 const SMS_WSP_LANGUAGE_S wspLanguage[] =
323 { (char*)"English", 0x19 },
324 { (char*)"en", 0x19 },
325 { (char*)"Korean", 0x3d },
326 { (char*)"*", 0x00 },
327 { (char*)"Afar", 0x01 },
328 { (char*)"aa", 0x01 },
329 { (char*)"Abkhazian", 0x02 },
330 { (char*)"ab", 0x02 },
331 { (char*)"Afrikaans", 0x03 },
332 { (char*)"af", 0x03 },
333 { (char*)"Amharic", 0x04 },
334 { (char*)"am", 0x04 },
335 { (char*)"Arabic", 0x05 },
336 { (char*)"ar", 0x05 },
337 { (char*)"Assamese", 0x06 },
338 { (char*)"as", 0x06 },
339 { (char*)"Aymara", 0x07 },
340 { (char*)"ay", 0x07 },
341 { (char*)"Azerbaijani", 0x08 },
342 { (char*)"az", 0x08 },
343 { (char*)"Bashkir", 0x09 },
344 { (char*)"ba", 0x09 },
345 { (char*)"Byelorussian", 0x0a },
346 { (char*)"be", 0x0a },
347 { (char*)"Bulgarian", 0x0b },
348 { (char*)"bg", 0x0b },
349 { (char*)"Bihari", 0x0c },
350 { (char*)"bh", 0x0c },
351 { (char*)"Bislama", 0x0d },
352 { (char*)"bi", 0x0f },
353 { (char*)"Bengali", 0x0e },
354 { (char*)"Bangla", 0x0e },
355 { (char*)"bn", 0x0e },
356 { (char*)"Tibetan", 0x0f },
357 { (char*)"bo", 0x0f },
358 { (char*)"Breton", 0x10 },
359 { (char*)"br", 0x10 },
360 { (char*)"Catalan", 0x11 },
361 { (char*)"ca", 0x11 },
362 { (char*)"Corsican", 0x12 },
363 { (char*)"co", 0x12 },
364 { (char*)"Czech", 0x13 },
365 { (char*)"cs", 0x13 },
366 { (char*)"Welsh", 0x14 },
367 { (char*)"cy", 0x14 },
368 { (char*)"Denish", 0x15 },
369 { (char*)"da", 0x15 },
370 { (char*)"German", 0x16 },
371 { (char*)"de", 0x16 },
372 { (char*)"Bhutani", 0x17 },
373 { (char*)"dz", 0x17 },
374 { (char*)"Greek", 0x18 },
375 { (char*)"el", 0x18 },
376 { (char*)"Esperanto", 0x81 },
377 { (char*)"eo", 0x1a },
378 { (char*)"Spanish", 0x1b },
379 { (char*)"es", 0x1b },
380 { (char*)"Estonian", 0x1c },
381 { (char*)"et", 0x1c },
382 { (char*)"Basque", 0x1d },
383 { (char*)"eu", 0x1d },
384 { (char*)"Persian", 0x1e },
385 { (char*)"fa", 0x1e },
386 { (char*)"Finnish", 0x1f },
387 { (char*)"fi", 0x1f },
388 { (char*)"Fiji", 0x20 },
389 { (char*)"fj", 0x20 },
390 { (char*)"Faeroese", 0x82 },
391 { (char*)"fo", 0x82 },
392 { (char*)"French", 0x22 },
393 { (char*)"fr", 0x22 },
394 { (char*)"Frisian", 0x83 },
395 { (char*)"fy", 0x83 },
396 { (char*)"Irish", 0x24 },
397 { (char*)"ga", 0x24 },
398 { (char*)"Scots Gaelic", 0x25 },
399 { (char*)"gd", 0x25 },
400 { (char*)"Galician", 0x26 },
401 { (char*)"gl", 0x26 },
402 { (char*)"Guarani", 0x27 },
403 { (char*)"gn", 0x27 },
404 { (char*)"Gujarati", 0x28 },
405 { (char*)"gu", 0x28 },
406 { (char*)"Hausa", 0x29 },
407 { (char*)"ha", 0x29 },
408 { (char*)"Hebrew", 0x2a },
409 { (char*)"he", 0x2a },
410 { (char*)"Hindi", 0x2b },
411 { (char*)"hi", 0x2b },
412 { (char*)"Croatian", 0x2c },
413 { (char*)"hr", 0x2c },
414 { (char*)"Hungarian", 0x2d },
415 { (char*)"hu", 0x2d },
416 { (char*)"Armenian", 0x2e },
417 { (char*)"hy", 0x2e },
418 { (char*)"Interlingua", 0x84 },
419 { (char*)"ia", 0x84 },
420 { (char*)"Indonesian", 0x30 },
421 { (char*)"id", 0x30 },
422 { (char*)"Interlingue", 0x86 },
423 { (char*)"ie", 0x86 },
424 { (char*)"Maori", 0x47 },
425 { (char*)"mi", 0x47 },
426 { (char*)"Macedonian", 0x48 },
427 { (char*)"mk", 0x48 },
428 { (char*)"Malayalam", 0x49 },
429 { (char*)"ml", 0x49 },
430 { (char*)"Mongolian", 0x4a },
431 { (char*)"mn", 0x4a },
432 { (char*)"Moldavian", 0x4b },
433 { (char*)"mo", 0x4d },
434 { (char*)"Marathi", 0x4c },
435 { (char*)"mr", 0x4c },
436 { (char*)"Malay", 0x4d },
437 { (char*)"ms", 0x4d },
438 { (char*)"Maltese", 0x4e },
439 { (char*)"mt", 0x4e },
440 { (char*)"Burmese", 0x4f },
441 { (char*)"my", 0x4f },
442 { (char*)"Nauru", 0x50 },
443 { (char*)"na", 0x50 },
444 { (char*)"Nepali", 0x51 },
445 { (char*)"ne", 0x51 },
446 { (char*)"Dutch", 0x52 },
447 { (char*)"nl", 0x52 },
448 { (char*)"Norwegian", 0x53 },
449 { (char*)"no", 0x53 },
450 { (char*)"Occitan", 0x54 },
451 { (char*)"oc", 0x54 },
452 { (char*)"(Afan) Oromo", 0x55 },
453 { (char*)"(Afan)Oromo", 0x55 },
454 { (char*)"om", 0x55 },
455 { (char*)"Oriya", 0x56 },
456 { (char*)"or", 0x56 },
457 { (char*)"Punjabi", 0x57 },
458 { (char*)"pa", 0x57 },
459 { (char*)"Polish", 0x58 },
460 { (char*)"po", 0x58 },
461 { (char*)"Pashto", 0x59 },
462 { (char*)"Pushto", 0x59 },
463 { (char*)"ps", 0x59 },
464 { (char*)"Portugurse", 0x5a },
465 { (char*)"pt", 0x5a },
466 { (char*)"Quechua", 0x5b },
467 { (char*)"qu", 0x5b },
468 { (char*)"Rhaeto-Romance", 0x8c },
469 { (char*)"rm", 0x8c },
470 { (char*)"Kirundi", 0x5d },
471 { (char*)"rn", 0x5d },
472 { (char*)"Romanian", 0x5e },
473 { (char*)"ro", 0x5e },
474 { (char*)"Russian", 0x5f },
475 { (char*)"ru", 0x5f },
476 { (char*)"Kinyarwanda", 0x60 },
477 { (char*)"rw", 0x60 },
478 { (char*)"Sanskrit", 0x61 },
479 { (char*)"sa", 0x61 },
480 { (char*)"Sindhi", 0x62 },
481 { (char*)"sd", 0x62 },
482 { (char*)"Sangho", 0x63 },
483 { (char*)"sg", 0x63 },
484 { (char*)"Serbo-Croatian", 0x64 },
485 { (char*)"sh", 0x64 },
486 { (char*)"Sinhalese", 0x65 },
487 { (char*)"si", 0x65 },
488 { (char*)"Slovak", 0x66 },
489 { (char*)"sk", 0x66 },
490 { (char*)"Slovenian", 0x67 },
491 { (char*)"sl", 0x67 },
492 { (char*)"Samoan", 0x68 },
493 { (char*)"sm", 0x68 },
494 { (char*)"Shona", 0x69 },
495 { (char*)"sn", 0x69 },
496 { (char*)"Somali", 0x6a },
497 { (char*)"so", 0x6a },
498 { (char*)"Albanian", 0x6b },
499 { (char*)"sq", 0x6b },
500 { (char*)"Serbian", 0x6c },
501 { (char*)"sr", 0x6c },
502 { (char*)"Siswati", 0x6d },
503 { (char*)"ss", 0x6d },
504 { (char*)"Sesotho", 0x6e },
505 { (char*)"st", 0x6e },
506 { (char*)"Sundanese", 0x6f },
507 { (char*)"su", 0x6f },
508 { (char*)"Swedish", 0x70 },
509 { (char*)"sv", 0x70 },
510 { (char*)"Swahili", 0x71 },
511 { (char*)"sw", 0x71 },
512 { (char*)"Tamil", 0x72 },
513 { (char*)"ta", 0x72 },
514 { (char*)"Telugu", 0x73 },
515 { (char*)"te", 0x73 },
516 { (char*)"Tajik", 0x74 },
517 { (char*)"tg", 0x74 },
518 { (char*)"Thai", 0x75 },
519 { (char*)"th", 0x75 },
520 { (char*)"Tigrinya", 0x76 },
521 { (char*)"ti", 0x76 },
522 { (char*)"Turkmen", 0x77 },
523 { (char*)"tk", 0x77 },
524 { (char*)"Inupiak", 0x87 },
525 { (char*)"ik", 0x87 },
526 { (char*)"Icelandic", 0x33 },
527 { (char*)"is", 0x33 },
528 { (char*)"Italian", 0x34 },
529 { (char*)"it", 0x34 },
530 { (char*)"Inuktitut", 0x89 },
531 { (char*)"iu", 0x89 },
532 { (char*)"Japanese", 0x36 },
533 { (char*)"ja", 0x36 },
534 { (char*)"Javanese", 0x37 },
535 { (char*)"jw", 0x37 },
536 { (char*)"Georgian", 0x38 },
537 { (char*)"ka", 0x38 },
538 { (char*)"Kazakh", 0x39 },
539 { (char*)"kk", 0x39 },
540 { (char*)"Gerrnlandic", 0x8a },
541 { (char*)"kl", 0x8a },
542 { (char*)"Cambodian", 0x3b },
543 { (char*)"km", 0x3b },
544 { (char*)"Kannada", 0x3c },
545 { (char*)"kn", 0x3c },
546 { (char*)"Kashmiri", 0x3e },
547 { (char*)"ks", 0x3e },
548 { (char*)"Kurdish", 0x3f },
549 { (char*)"ku", 0x3f },
550 { (char*)"Kirghiz", 0x40 },
551 { (char*)"ky", 0x40 },
552 { (char*)"Latin", 0x8b },
553 { (char*)"la", 0x8b },
554 { (char*)"Lingala", 0x42 },
555 { (char*)"ln", 0x42 },
556 { (char*)"Laothian", 0x43 },
557 { (char*)"lo", 0x43 },
558 { (char*)"Lithuanian", 0x44 },
559 { (char*)"lt", 0x44 },
560 { (char*)"Lavian", 0x45 },
561 { (char*)"Lettish", 0x45 },
562 { (char*)"lv", 0x45 },
563 { (char*)"Malagasy", 0x46 },
564 { (char*)"mg", 0x46 },
565 { (char*)"Tagalog", 0x78 },
566 { (char*)"tl", 0x78 },
567 { (char*)"Setswana", 0x79 },
568 { (char*)"tn", 0x79 },
569 { (char*)"Tonga", 0x7a },
570 { (char*)"to", 0x7a },
571 { (char*)"Turkish", 0x7b },
572 { (char*)"tr", 0x7b },
573 { (char*)"Tsonga", 0x7c },
574 { (char*)"ts", 0x7c },
575 { (char*)"Tatar", 0x7d },
576 { (char*)"tt", 0x7d },
577 { (char*)"Twi", 0x7e },
578 { (char*)"tw", 0x7e },
579 { (char*)"Uighur", 0x7f },
580 { (char*)"ug", 0x7f },
581 { (char*)"Ukrainian", 0x1a },
582 { (char*)"uk", 0x1a },
583 { (char*)"Urdu", 0x21 },
584 { (char*)"ur", 0x21 },
585 { (char*)"Uzbek", 0x23 },
586 { (char*)"uz", 0x23 },
587 { (char*)"Vietnamese", 0x2f },
588 { (char*)"vi", 0x2f },
589 { (char*)"Volapuk", 0x85 },
590 { (char*)"vo", 0x85 },
591 { (char*)"Wolof", 0x31 },
592 { (char*)"wo" , 0x31 },
593 { (char*)"Xhosa", 0x32 },
594 { (char*)"xh", 0x32 },
595 { (char*)"Yiddish", 0x88 },
596 { (char*)"yi", 0x88 },
597 { (char*)"Yoruba", 0x35 },
598 { (char*)"yo", 0x35 },
599 { (char*)"Zhuang", 0x3a },
600 { (char*)"z", 0x3a },
601 { (char*)"Chinese", 0x41 },
602 { (char*)"ch", 0x41 },
603 { (char*)"Zulu", 0x5c },
604 { (char*)"zu", 0x5c },
605 { (char*)"Ko", 0x3d }
609 const SMS_WSP_HEADER_PARAMETER_S wspHeaderApplId[] =
611 { (char*)"x-wap-application:*", 0x00 },
612 { (char*)"x-wap-application:push.sia", 0x01},
613 { (char*)"x-wap-application:wml.ua", 0x02 },
614 { (char*)"x-wap-application:wta.ua", 0x03 },
615 { (char*)"x-wap-application:mms.ua", 0x04 },
616 { (char*)"x-wap-application:push.syncml", 0x05 },
617 { (char*)"x-wap-application:loc.ua", 0x06 },
618 { (char*)"x-wap-application:syncml.dm", 0x07 },
619 { (char*)"x-wap-application:drm.ua", 0x08 },
620 { (char*)"x-wap-application:emn.ua", 0x09 }
624 const char* wspCacheControl[] =
631 (char*)"Only-if-cached",
634 (char*)"No-transform",
635 (char*)"Must-revalidate",
636 (char*)"Proxy-revalidate"
639 const SMS_WSP_METHOD_TYPE_S wspMethodType[] =
641 { (char*)"GET", 0x40 },
642 { (char*)"OPTIONS", 0x41 },
643 { (char*)"HEAD", 0x42 },
644 { (char*)"DELETE", 0x43 },
645 { (char*)"TRACE", 0x44 },
646 { (char*)"POST", 0x60 },
647 { (char*)"PUT", 0x61 }
651 const SMS_WSP_SECURITY_TYPE_S wspSecurityType[] =
653 {(char*)"NETWPIN",0x00},
654 {(char*)"USERPIN",0x01},
655 {(char*)"USERNETWPIN",0x02},
656 {(char*)"USERPINMAC",0x03}
661 const char* wspWeek[] =
673 const char* wspWeekDay[] =
684 const char* wspMonth[] =
702 /*==================================================================================================
703 IMPLEMENTATION OF SmsPluginWapPushHandler - Member Functions
704 ==================================================================================================*/
705 SmsPluginWapPushHandler* SmsPluginWapPushHandler::pInstance = NULL;
708 SmsPluginWapPushHandler::SmsPluginWapPushHandler()
710 memset(&tmpAddress, 0x00, sizeof(tmpAddress));
714 SmsPluginWapPushHandler::~SmsPluginWapPushHandler()
720 SmsPluginWapPushHandler* SmsPluginWapPushHandler::instance()
723 pInstance = new SmsPluginWapPushHandler();
729 bool SmsPluginWapPushHandler::IsWapPushMsg(SMS_USERDATA_S *pUserData)
733 if (pUserData == NULL) {
734 MSG_DEBUG("pUserData is NULL");
738 int PortCount = sizeof(wapPushPortList)/sizeof(wapPushPortList[0]);
740 MSG_DEBUG("Port Count [%d]", PortCount);
742 for (int i = 0; i < pUserData->headerCnt; i++) {
743 if (pUserData->header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
744 /** Have to check something??? */
745 } else if (pUserData->header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
747 for (int j = 0; j < PortCount; j++) {
748 if (pUserData->header[i].udh.appPort16bit.destPort == wapPushPortList[j]) {
749 MSG_DEBUG("Wap Push Msg : [%04x]", wapPushPortList[j]);
762 SMS_WAP_APP_CODE_T SmsPluginWapPushHandler::getAppCode(const char *pPushHeader)
764 int appCount = sizeof(pushDefaultApplication)/sizeof(pushDefaultApplication[0]) - 1;
766 unsigned char *header = NULL;
767 SMS_WAP_APP_CODE_T appCode = SMS_WAP_APPLICATION_DEFAULT;
769 MSG_DEBUG("Application Count [%d]", appCount);
771 for (int i = 0; i < appCount; i++) {
773 header = (unsigned char*)strcasestr(pPushHeader, pushDefaultApplication[i].pContentType);
775 if (header != NULL) {
776 appCode = pushDefaultApplication[i].appCode;
781 if (appCode == SMS_WAP_APPLICATION_DEFAULT) {
782 MSG_DEBUG("Application Type is not supported");
784 MSG_DEBUG("Find Application [%d]", appCode);
791 void SmsPluginWapPushHandler::copyDeliverData(SMS_DELIVER_S *pDeliver)
793 tmpAddress.ton = pDeliver->originAddress.ton;
794 tmpAddress.npi = pDeliver->originAddress.npi;
796 strncpy(tmpAddress.address, pDeliver->originAddress.address, MAX_ADDRESS_LEN);
798 MSG_DEBUG("Address [%s]", tmpAddress.address);
800 tmpTimeStamp.format = pDeliver->timeStamp.format;
802 if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
803 tmpTimeStamp.time.absolute.year = pDeliver->timeStamp.time.absolute.year;
804 tmpTimeStamp.time.absolute.month = pDeliver->timeStamp.time.absolute.month;
805 tmpTimeStamp.time.absolute.day = pDeliver->timeStamp.time.absolute.day;
806 tmpTimeStamp.time.absolute.hour = pDeliver->timeStamp.time.absolute.hour;
807 tmpTimeStamp.time.absolute.minute = pDeliver->timeStamp.time.absolute.minute;
808 tmpTimeStamp.time.absolute.second = pDeliver->timeStamp.time.absolute.second;
809 tmpTimeStamp.time.absolute.timeZone = pDeliver->timeStamp.time.absolute.timeZone;
814 void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize)
818 unsigned char* pPDUTypeData = (unsigned char*)pUserData;
819 unsigned long PDUTypeDataLen = DataSize;
821 char* pPushHeader = NULL;
822 AutoPtr<char> pushHeaderBuf(&pPushHeader);
823 unsigned long pushHeaderLen = 0;
825 char* pPushBody = NULL;
826 AutoPtr<char> PushBodyBuf(&pPushBody);
827 unsigned long pushBodyLen = 0;
829 unsigned long iPDU = 1;
831 char* pWspHeader = NULL;
832 AutoPtr<char> WspHeaderBuf(&pWspHeader);
833 unsigned long wspHeaderLen = 0;
835 char* pWspBody = NULL;
836 AutoPtr<char> WspBodyBuf(&pWspBody);
837 unsigned long wspBodyLen = 0;
842 pushHeaderLen = wspRetriveUintvarDecode( pPDUTypeData, &iPDU );
844 MSG_DEBUG("PDUTypeDataLen [%d]", PDUTypeDataLen);
845 MSG_DEBUG("pushHeaderLen [%d]", pushHeaderLen);
846 MSG_DEBUG("iPDU [%d]", iPDU);
848 wspHeaderLen = pushHeaderLen + iPDU;
850 MSG_DEBUG("wspBodyLen [%d]", wspBodyLen);
852 if (wspHeaderLen > 0) {
854 pWspHeader = new char[wspHeaderLen];
856 if (pWspHeader == NULL) {
857 MSG_DEBUG("pWspHeader Memory Allocation Failed");
860 memcpy(pWspHeader, pPDUTypeData, wspHeaderLen);
864 /** return if it is below case error */
865 if (PDUTypeDataLen < wspHeaderLen) {
866 MSG_DEBUG("PDUTypeDataLen < wspHeaderLen !!!");
870 /** Finding wspBody Information */
871 wspBodyLen = PDUTypeDataLen - wspHeaderLen;
873 if (wspBodyLen > 0) {
875 pWspBody = new char[wspBodyLen];
877 if (pWspBody == NULL) {
878 MSG_DEBUG("pWspBody Memory Allocation Failed");
881 memcpy(pWspBody, pPDUTypeData + wspHeaderLen, wspBodyLen);
887 wspDecodeHeader(pPDUTypeData + iPDU, pushHeaderLen, PDUTypeDataLen - (iPDU + pushHeaderLen), TRUE, &pPushHeader);
889 iPDU = iPDU + pushHeaderLen;
891 pushBodyLen = PDUTypeDataLen - iPDU ;
893 if (pushBodyLen > 0) {
894 pPushBody = new char[pushBodyLen];
896 if (pPushBody == NULL) {
897 MSG_DEBUG("pPushBody Memory Allocation Failed");
900 memcpy(pPushBody, pPDUTypeData+ iPDU, pushBodyLen);
907 handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen);
913 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
917 if (pPushBody == NULL) {
918 MSG_DEBUG("pPushBody is NULL");
922 SMS_WAP_APP_CODE_T appCode = getAppCode(pPushHeader);
924 /** check Push message receive setting */
925 bool bPushRecv = false;
927 MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv);
929 if ((bPushRecv == false) && (appCode != SMS_WAP_APPLICATION_MMS_UA)) {
930 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
935 case SMS_WAP_APPLICATION_MMS_UA:
936 MSG_DEBUG("Received MMS Notification");
938 handleMMSNotification(pPushBody, PushBodyLen);
941 case SMS_WAP_APPLICATION_PUSH_SI:
942 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
943 handleSIMessage(pPushBody, PushBodyLen, true);
946 case SMS_WAP_APPLICATION_PUSH_SIC:
947 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
948 handleSIMessage(pPushBody, PushBodyLen, false);
951 case SMS_WAP_APPLICATION_PUSH_SL:
952 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
953 handleSLMessage(pPushBody, PushBodyLen, true);
956 case SMS_WAP_APPLICATION_PUSH_SLC:
957 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
958 handleSLMessage(pPushBody, PushBodyLen, false);
961 case SMS_WAP_APPLICATION_PUSH_CO:
962 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
963 handleCOMessage(pPushBody, PushBodyLen, true);
966 case SMS_WAP_APPLICATION_PUSH_COC:
967 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
968 handleCOMessage(pPushBody, PushBodyLen, false);
971 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
972 MSG_DEBUG("Received DM BOOTSTRAP");
973 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
976 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
977 MSG_DEBUG("Received DM BOOTSTRAP");
978 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
981 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
982 MSG_DEBUG("Received Provisioning");
983 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
986 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
987 MSG_DEBUG("Received Provisioning");
988 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
991 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
992 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
993 MSG_DEBUG("Received Provisioning");
994 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
997 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
998 MSG_DEBUG("Received DM Notification");
999 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1002 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1003 MSG_DEBUG("Received DS Notification");
1004 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1007 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1008 MSG_DEBUG("Received DS Notification");
1009 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1012 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
1013 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
1014 MSG_DEBUG("Received DRM UA");
1016 if (pPushBody != NULL)
1017 handleDrmVer1(pPushBody, PushBodyLen);
1021 case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
1022 case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
1023 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
1024 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
1025 MSG_DEBUG("Received DRM V2");
1029 case SMS_WAP_APPLICATION_PUSH_EMAIL:
1030 case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
1031 case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
1032 MSG_DEBUG("Received Email");
1036 case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1037 MSG_DEBUG("Received IMPS CIR");
1041 case SMS_WAP_APPLICATION_LBS :
1042 MSG_DEBUG("Received LBS related message");
1043 SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1047 case SMS_WAP_APPLICATION_PUSH_SIA :
1048 MSG_DEBUG("Received SIA");
1053 MSG_DEBUG("Unknown Application [%d]", appCode);
1061 void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen)
1065 /** Make MSG_MESSAGE_INFO_S */
1066 MSG_MESSAGE_INFO_S msgInfo;
1068 createMsgInfo(&msgInfo);
1070 /** Convert Type values */
1071 msgInfo.msgType.mainType = MSG_MMS_TYPE;
1072 msgInfo.msgType.subType = MSG_NOTIFICATIONIND_MMS;
1074 msgInfo.dataSize = PushBodyLen;
1076 if (msgInfo.dataSize > MAX_MSG_TEXT_LEN) {
1077 msgInfo.bTextSms = false;
1079 /** Save Message Data into File */
1080 char fileName[MAX_COMMON_INFO_SIZE+1];
1081 memset(fileName, 0x00, sizeof(fileName));
1083 if (MsgCreateFileName(fileName) == false)
1084 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1086 if (MsgWriteIpcFile(fileName, pPushBody, msgInfo.dataSize) == false)
1087 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1089 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1091 msgInfo.bTextSms = true;
1093 memcpy(msgInfo.msgText, pPushBody, msgInfo.dataSize);
1094 msgInfo.msgText[msgInfo.dataSize] = '\0';
1097 MSG_ERROR_T err = MSG_SUCCESS;
1099 /** Add MMS Noti Msg into DB */
1100 err = SmsPluginStorage::instance()->addMessage(&msgInfo);
1102 if (err == MSG_SUCCESS) {
1104 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1106 if (err != MSG_SUCCESS) {
1107 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1110 MSG_DEBUG("addMessage() Error !! [%d]", err);
1116 void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText)
1120 MSG_PUSH_MESSAGE_S pushMsg = {};
1122 xmlDocPtr xmlDoc = NULL;
1123 xmlNodePtr topNode = NULL;
1124 xmlNodePtr indNode = NULL;
1126 xmlChar* tmpXmlChar = NULL;
1128 if (pPushBody == NULL) {
1129 MSG_DEBUG("pPushBody is NULL");
1133 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1135 if (xmlDoc == NULL) {
1136 MSG_DEBUG("xmlDoc is NULL");
1140 topNode = xmlDocGetRootElement(xmlDoc);
1142 if (xmlDoc == NULL) {
1143 MSG_DEBUG("Empty Document");
1148 indNode = topNode->xmlChildrenNode;
1150 while (indNode != NULL) {
1151 if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
1152 MSG_DEBUG("indNode->name = %s\n", indNode->name);
1156 indNode = indNode->next;
1159 if (indNode == NULL) {
1160 MSG_DEBUG("indNode is NULL.");
1164 /** temporary set to max. */
1165 pushMsg.expires = 0xFFFFFFFF;
1167 /** setting received time */
1168 time_t t = time(NULL);
1169 time_t utfTime = time(&t);
1171 pushMsg.received = (unsigned long)utfTime;
1173 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1175 if (tmpXmlChar == NULL) {
1176 MSG_DEBUG("href is NULL.");
1180 if (tmpXmlChar != NULL)
1181 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1183 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
1185 if (tmpXmlChar != NULL)
1186 strncpy(pushMsg.id, (char*)tmpXmlChar, MAX_WAPPUSH_ID_LEN-1);
1188 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CREATED_TAG);
1190 if (tmpXmlChar != NULL)
1191 pushMsg.created = convertXmlCharToSec((char*)tmpXmlChar);
1193 if (pushMsg.created == 0)
1194 pushMsg.created = pushMsg.received;
1196 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_EXPIRES_TAG);
1198 if (tmpXmlChar != NULL)
1199 pushMsg.expires = convertXmlCharToSec((char*)tmpXmlChar);
1201 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1203 pushMsg.action = convertSIActionStrToEnum((char*)tmpXmlChar);
1205 tmpXmlChar = xmlNodeListGetString(xmlDoc, indNode->xmlChildrenNode, 1);
1207 if (tmpXmlChar == NULL) {
1208 MSG_DEBUG("contents is NULL.");
1212 strncpy(pushMsg.contents, (char*)tmpXmlChar, MAX_WAPPUSH_CONTENTS_LEN-1);
1214 /** Write push Msg to file */
1215 char fileName[MAX_COMMON_INFO_SIZE+1];
1216 memset(fileName, 0x00, sizeof(fileName));
1218 if (MsgCreateFileName(fileName) == false) {
1220 xmlFree(tmpXmlChar);
1221 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1224 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false) {
1226 xmlFree(tmpXmlChar);
1227 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1230 /** Pack Message Info Structure */
1231 MSG_MESSAGE_INFO_S msgInfo;
1233 createMsgInfo(&msgInfo);
1235 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1237 /** Convert Type values */
1238 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1239 msgInfo.msgType.subType = MSG_WAP_SI_SMS;
1241 msgInfo.dataSize = sizeof(pushMsg);
1244 xmlFree(tmpXmlChar);
1246 MSG_ERROR_T err = MSG_SUCCESS;
1248 /** Add WAP Push Msg into DB */
1249 err = SmsPluginStorage::instance()->addMessage(&msgInfo);
1251 if (err == MSG_SUCCESS) {
1253 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1255 if (err != MSG_SUCCESS){
1256 MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1259 MSG_DEBUG("addMessage() Error !! [%d]", err);
1268 void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText)
1272 MSG_PUSH_MESSAGE_S pushMsg = {};
1274 xmlDocPtr xmlDoc = NULL;
1275 xmlNodePtr topNode = NULL;
1276 xmlNodePtr indNode = NULL;
1278 xmlChar* tmpXmlChar = NULL;
1280 if (pPushBody == NULL) {
1281 MSG_DEBUG("pPushBody is NULL \n" );
1285 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1287 if (xmlDoc == NULL) {
1288 MSG_DEBUG("xmlDoc is NULL \n" );
1292 topNode = xmlDocGetRootElement(xmlDoc);
1294 if (topNode == NULL) {
1295 MSG_DEBUG("Empty Document." );
1299 MSG_DEBUG("Not an empty Document and topNode->name = %s \n",topNode->name );
1304 while (indNode != NULL) {
1305 if (!xmlStrcmp(indNode->name, (const xmlChar*) "sl")) {
1306 MSG_DEBUG("indNode->name = %s\n",indNode->name);
1310 indNode = indNode->next;
1313 /** setting received time setting */
1314 time_t t = time(NULL);
1315 time_t utfTime = time(&t);
1317 pushMsg.received = (unsigned long)utfTime;
1319 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1321 if (tmpXmlChar == NULL) {
1322 MSG_DEBUG("href is NULL.");
1326 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1328 tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1329 pushMsg.action = convertSLActionStrToEnum((char*)tmpXmlChar);
1331 /** Setting other parameters in default values */
1332 pushMsg.created = pushMsg.received;
1333 /** temporary set to MAX value. */
1334 pushMsg.expires = 0xFFFFFFFF;
1336 MSG_DEBUG("check pushMsg data");
1337 MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
1338 MSG_DEBUG("pushMsg.received : [%d]", pushMsg.received);
1339 MSG_DEBUG("pushMsg.created : [%d]", pushMsg.created);
1340 MSG_DEBUG("pushMsg.expires : [%d]", pushMsg.expires);
1341 MSG_DEBUG("pushMsg.id : [%s]", pushMsg.id);
1342 MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
1343 MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
1345 /** Write push Msg to file */
1346 char fileName[MAX_COMMON_INFO_SIZE+1];
1347 memset(fileName, 0x00, sizeof(fileName));
1349 if (MsgCreateFileName(fileName) == false)
1350 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1352 if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false)
1353 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1355 /** Pack Message Info Structure */
1356 MSG_MESSAGE_INFO_S msgInfo;
1358 createMsgInfo(&msgInfo);
1360 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1362 /** Convert Type values */
1363 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1364 msgInfo.msgType.subType = MSG_WAP_SL_SMS;
1366 /** Update Msg Text */
1367 strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
1369 msgInfo.dataSize = sizeof(pushMsg);
1371 MSG_DEBUG("dataSize : %d", msgInfo.dataSize);
1373 /** Callback to MSG FW */
1374 SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1377 xmlFree(tmpXmlChar);
1384 void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText)
1386 MSG_PUSH_CACHEOP_S cacheOp;
1388 xmlDocPtr xmlDoc = NULL;
1389 xmlNodePtr topNode = NULL;
1390 xmlNodePtr indNode = NULL;
1392 memset(&cacheOp, 0x00, sizeof(cacheOp));
1394 MSG_DEBUG("Enter handleCOMessage");
1396 if (pPushBody == NULL) {
1397 MSG_DEBUG("pPushBody is NULL \n" );
1401 getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1403 if (xmlDoc == NULL) {
1404 MSG_DEBUG("xmlDoc is NULL \n" );
1408 topNode = xmlDocGetRootElement(xmlDoc);
1409 if (topNode == NULL) {
1410 MSG_DEBUG("Warning:Empty Document\n" );
1415 indNode = topNode->xmlChildrenNode;
1418 while(indNode != NULL) {
1420 xmlChar* tmpUrl = NULL;
1421 if (!xmlStrcmp(indNode->name, (const xmlChar*) SMS_PUSH_XML_INVAL_OBJ)) {
1422 MSG_DEBUG("indNode->name = %s\n", indNode->name);
1424 tmpUrl = xmlGetProp(indNode, (xmlChar*) SMS_PUSH_XML_CO_URI);
1426 if (tmpUrl != NULL) {
1427 strncpy(cacheOp.invalObjectUrl[cacheOp.invalObjectCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1429 MSG_DEBUG("%dth invalObjectUrl is <%s>\n", cacheOp.invalObjectCnt, cacheOp.invalObjectUrl[cacheOp.invalObjectCnt-1]);
1431 MSG_DEBUG("NO href value from the xmlDoc\n");
1433 } else if (!xmlStrcmp(indNode->name, (const xmlChar*) SMS_PUSH_XML_INVAL_SVC)) {
1434 MSG_DEBUG("indNode->name = %s\n",indNode->name);
1435 tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1437 if (tmpUrl != NULL) {
1438 strncpy(cacheOp.invalServiceUrl[cacheOp.invalServiceCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1439 MSG_DEBUG("%dth invalServiceUrl is <%s>\n", cacheOp.invalServiceCnt, cacheOp.invalServiceUrl[cacheOp.invalServiceCnt-1]);
1441 MSG_DEBUG("NO href value from the xmlDoc\n");
1448 indNode = indNode->next;
1451 /** Write push Msg to file */
1452 char fileName[MAX_COMMON_INFO_SIZE+1];
1453 memset(fileName, 0x00, sizeof(fileName));
1455 if (MsgCreateFileName(fileName) == false) {
1457 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1460 if (MsgWriteIpcFile(fileName, (char*)(&cacheOp), sizeof(cacheOp)) == false) {
1462 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1465 /** Pack Message Info Structure */
1466 MSG_MESSAGE_INFO_S msgInfo;
1468 createMsgInfo(&msgInfo);
1470 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1472 /** Convert Type values */
1473 msgInfo.msgType.mainType = MSG_SMS_TYPE;
1474 msgInfo.msgType.subType = MSG_WAP_CO_SMS;
1476 msgInfo.dataSize = sizeof(cacheOp);
1478 MSG_ERROR_T err = MSG_SUCCESS;
1480 /** Add WAP Push Msg into DB */
1481 err = SmsPluginStorage::instance()->addMessage(&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("addMessage() Error !! [%d]", err);
1500 void SmsPluginWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
1502 DRM_RESULT drmRt = DRM_RESULT_SUCCESS;
1504 AutoPtr<char> buf(&cid);
1506 MSG_DEBUG("Received DRM RIGHTS OBJECT Type WAP Push Message.");
1508 drmRt = drm_svc_register_ro( (unsigned char*)pPushBody, (unsigned int)PushBodyLen,
1509 DRM_OMA_DRMV1_RIGHTS, (unsigned char**)&cid,
1511 DRM_ROAP_INIT_FROM_WAPPUSH,
1514 if (drmRt == DRM_RESULT_SUCCESS) {
1515 MSG_DEBUG("DRM successfully registed to drm-service.");
1518 MSG_DEBUG("Fail to regist DRM to drm-service.");
1524 void SmsPluginWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
1526 /** Convert class Type values */
1527 pMsgInfo->msgType.classType = MSG_CLASS_NONE;
1529 /** set folder id (temporary) */
1530 pMsgInfo->folderId = MSG_INBOX_ID;
1532 pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
1533 pMsgInfo->bRead = false;
1534 pMsgInfo->bProtected = false;
1535 pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
1536 pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
1539 time_t rawtime = time(NULL);
1541 pMsgInfo->displayTime = rawtime;
1543 /** Convert Address values */
1544 pMsgInfo->nAddressCnt = 1;
1545 pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
1546 strncpy(pMsgInfo->addressList[0].addressVal, tmpAddress.address, MAX_ADDRESS_VAL_LEN);
1548 pMsgInfo->msgPort.valid = false;
1549 pMsgInfo->msgPort.dstPort = 0;
1550 pMsgInfo->msgPort.srcPort = 0;
1554 void SmsPluginWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText)
1556 if (pPushBody == NULL) {
1557 MSG_DEBUG("pPushBody is NULL");
1563 *pXmlDoc = xmlParseMemory(pPushBody, strlen(pPushBody));
1565 WB_UTINY* xmldata = NULL;
1566 WBXMLConvWBXML2XML *conv = NULL;
1567 WBXMLError ret = WBXML_OK;
1569 ret = wbxml_conv_wbxml2xml_create(&conv);
1570 if (ret != WBXML_OK)
1573 ret = wbxml_conv_wbxml2xml_run(conv, (WB_UTINY*)pPushBody, (WB_ULONG)PushBodyLen, &xmldata, NULL);
1575 wbxml_conv_wbxml2xml_destroy(conv);
1577 if (ret != WBXML_OK ||xmldata == NULL) {
1578 MSG_DEBUG("xmldata is NULL. Error code is [%d].\n", ret);
1582 MSG_DEBUG("xmldata : \n%s\n", xmldata);
1584 *pXmlDoc = xmlParseMemory((char*)xmldata, strlen((char*)xmldata));
1589 unsigned long SmsPluginWapPushHandler::convertXmlCharToSec(char* pDate)
1591 struct tm timeStruct;
1592 time_t nTimeInSec = 0;
1594 int i = 0, index = 0;
1596 memset(tmpBuf, 0x00, sizeof(tmpBuf));
1597 memset(&timeStruct, 0x00, sizeof(&timeStruct));
1600 if (strlen(pDate)<20)
1603 MSG_DEBUG("pDate [%s]", pDate);
1606 for (i = 0; i < 4; i++) {
1607 tmpBuf[i] = pDate[index++];
1611 timeStruct.tm_year = (atoi( tmpBuf)-1900);
1614 for (i = 0; i < 2; i++) {
1615 tmpBuf[i] = pDate[index++];
1619 timeStruct.tm_mon = (atoi( tmpBuf) - 1);
1622 for (i = 0; i < 2; i++) {
1623 tmpBuf[i] = pDate[index++];
1627 timeStruct.tm_mday = atoi( tmpBuf);
1630 for (i = 0; i < 2; i++) {
1631 tmpBuf[i] = pDate[index++];
1635 timeStruct.tm_hour = atoi( tmpBuf);
1638 for (i = 0; i < 2; i++) {
1639 tmpBuf[i] = pDate[index++];
1643 timeStruct.tm_min = atoi( tmpBuf);
1646 for (i = 0; i < 2; i++) {
1647 tmpBuf[i] = pDate[index++];
1651 timeStruct.tm_sec = atoi( tmpBuf);
1653 nTimeInSec = mktime(&timeStruct);
1658 MSG_PUSH_ACTION_T SmsPluginWapPushHandler::convertSIActionStrToEnum(char* pAction)
1662 if (pAction == NULL) {
1663 MSG_DEBUG("pAction is NULL. Setting to default action type.");
1664 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
1667 /** compare with signal-none. */
1668 comp = strcmp( "signal-none", pAction );
1670 return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
1672 /** compare with signal-low. */
1673 comp = strcmp( "signal-low", pAction );
1675 return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
1677 /** compare with signal-medium. */
1678 comp = strcmp( "signal-medium", pAction );
1680 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
1682 /** compare with signal-high. */
1683 comp = strcmp( "signal-high", pAction );
1685 return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
1687 /** compare with delete. */
1688 comp = strcmp( "delete", pAction );
1690 return MSG_PUSH_SI_ACTION_DELETE;
1692 /** signal-medium is default action value. */
1693 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
1697 MSG_PUSH_ACTION_T SmsPluginWapPushHandler::convertSLActionStrToEnum(char* pAction)
1701 if (pAction == NULL) {
1702 MSG_DEBUG( "MSG_DEBUG is NULL. Setting to default action type.\n" );
1703 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
1706 /** compare pSrcStr with execute-low. */
1707 comp = strcmp( "execute-low", pAction );
1709 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
1711 /** compare pSrcStr with execute-high. */
1712 comp = strcmp( "execute-high", pAction );
1714 return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
1716 /** compare pSrcStr with cache. */
1717 comp = strcmp( "cache", pAction );
1719 return MSG_PUSH_SL_ACTION_CACHE;
1721 /** default SL action value is execute-low. */
1722 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
1727 unsigned long SmsPluginWapPushHandler::wspRetriveUintvarDecode( unsigned char* sourceData, unsigned long* currentPointer )
1729 unsigned long i = 0;
1730 unsigned long decodedValue;
1732 while (sourceData[*currentPointer +i] >= 0x80) i++;
1734 decodedValue = wspDecodeUintvar( i+1, sourceData + *currentPointer );
1735 *currentPointer = *currentPointer + i + 1;
1736 MSG_DEBUG("wspRetriveUintvarDecode: decodedValue=%d .\n",decodedValue );
1737 return decodedValue;
1741 unsigned long SmsPluginWapPushHandler::wspDecodeUintvar(unsigned long length, unsigned char* userVar )
1744 unsigned long decodedUintvar = 0;
1747 for (i = 0 ; i < length; i++) {
1748 decodedUintvar = decodedUintvar + ( wspUintvarDecodeTable[i] * (userVar[length-(i+1)] & 0x7f ));
1751 return decodedUintvar;
1755 void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader)
1757 unsigned long iField;
1758 bool continueField = FALSE;
1759 unsigned long currentLength;
1761 char* encodedHeader = NULL;
1762 AutoPtr<char> encodedHeaderbuf(&encodedHeader);
1764 char* outTemper = NULL;
1766 char* temper = NULL;
1767 AutoPtr<char> temperbuf(&temper);
1769 unsigned char track;
1770 unsigned long iEncodedHeader = 0;
1771 unsigned char fieldCode = 0xff;
1773 /* outTemper is Decoded Headers.
1774 temper is Single Decoded Header.
1776 if (NULL == ( outTemper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ])) {
1777 MSG_DEBUG("outTemper Memory allocation is failed.\n" );
1780 memset(outTemper, 0, (WSP_STANDARD_STR_LEN_MAX * 5));
1781 currentLength = WSP_STANDARD_STR_LEN_MAX;
1783 MSG_DEBUG("wspDecodeHeader: Message header decoding started.\n" );
1789 MSG_DEBUG("wspDecodeHeader: RAW data \n" );
1790 for (loop = 0 ; loop<(int)encodedHeaderLen; loop++) {
1792 szTempBuf[0] = 0x00;
1793 sprintf( szTempBuf, "%2X ", sEncodedHeader[loop] );
1795 if (AcStrlen( szBuf ) + 7 < 64) {
1796 strncat( szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1 );
1798 strncat( szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1 );
1799 MSG_DEBUG("[%s]", szBuf);
1801 strncat( szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1 );
1804 strncat( szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1 );
1805 MSG_DEBUG("[%s]", szBuf);
1806 MSG_DEBUG("fContentType=%d \n",fContentType );
1807 /* operation for content-type */
1808 /* makes psuedo- content-type fieldcode */
1809 /* 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. */
1812 encodedHeader = new char[ encodedHeaderLen + 1 ];
1813 if (encodedHeader == NULL) {
1814 MSG_DEBUG("encodedHeader Memory allocation is failed.\n" );
1817 encodedHeader[0] = 0x91;
1818 memcpy( encodedHeader + 1, sEncodedHeader, (size_t)encodedHeaderLen );
1820 encodedHeader = new char[ encodedHeaderLen ];
1821 if (encodedHeader == NULL) {
1822 MSG_DEBUG("encodedHeader Memory allocation is failed.\n" );
1826 memcpy( encodedHeader, sEncodedHeader, (size_t)encodedHeaderLen );
1829 /* Is it reacehd end of header? */
1830 while (iEncodedHeader < encodedHeaderLen) {
1831 /* Get memory for single header */
1832 temper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ];
1833 if (temper == NULL) {
1834 MSG_DEBUG("temper Memory allocation is failed.\n" );
1838 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
1840 /* this section presents header code page shifting procedure
1841 This part can be implemented by future request.
1842 if (track == 0x 7f )
1844 track = encodedHeader[iEncodedHeader];
1846 if (track == 0x00) {
1847 MSG_DEBUG("WspLDecodeHeader: fieldcode is 0 \n" );
1848 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
1851 } else if (( track > 0 ) && ( track < 0x20 )) {
1853 } else if (( track < 0x7f ) && ( track > 0x1f )) { /* In this case, first byte is normal string. So it's considered to unknown header. */
1854 unsigned char* fieldName = (unsigned char*)gWapCodeBufferLeft;
1855 unsigned char* fieldValue = (unsigned char*)gWapCodeBufferRight;
1857 strncpy( (char*)fieldName, (char*)(encodedHeader + iEncodedHeader ),WSP_CODE_BUFFER_LEFT_LEN_MAX-1);
1858 fieldName[WSP_CODE_BUFFER_LEFT_LEN_MAX-1] = '\0';
1859 iEncodedHeader = iEncodedHeader + AcStrlen( (char*)fieldName ) + 1;
1860 strncpy( (char*)fieldValue, (char*)(encodedHeader + iEncodedHeader ), WSP_CODE_BUFFER_RIGHT_LEN_MAX-1);
1861 fieldValue[WSP_CODE_BUFFER_RIGHT_LEN_MAX-1] = '\0';
1862 iEncodedHeader = iEncodedHeader + AcStrlen( (char*)fieldValue ) + 1;
1864 strncat((char*)temper, (char*)fieldName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
1865 strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
1866 strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
1867 /* this means 'don't process anymore.' */
1870 } else if (track > 0x7f) {
1871 /* In case of first byte is field code, else case is error. */
1873 /*if (( track & 0x7f ) <= wspHeaderFieldCount ) */
1876 unsigned long fieldValueLen = encodedHeader[iEncodedHeader + 1];
1877 unsigned char fieldValue[1275];
1878 fieldCode = track & 0x7f;
1880 if (( fieldValueLen == 0 ) || ( fieldValueLen == 0x80 ))
1882 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] );
1885 memset(fieldValue, 0, 1275);
1887 /* add field name */
1888 /* 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. */
1889 if (!continueField) {
1890 strncat( (char*)temper, (char*)wspHeaderFieldName[fieldCode], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
1891 strncat( (char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
1892 continueField = FALSE;
1895 /* field value is string */
1896 /* In this case, it just copy field value. */
1897 if (( fieldValueLen > LENGTH_QUOTE ) && ( fieldValueLen < 0x80 )) {
1899 /* string field value should be NULL terminated */
1900 strncat( (char*)temper, (char*)(encodedHeader + iEncodedHeader + 1 ), (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
1901 strncat( (char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
1903 iEncodedHeader = iEncodedHeader + AcStrlen( (char*)encodedHeader + iEncodedHeader + 1 ) + 2;
1906 /* first field value is length */
1907 /* If first byte of field value is length value, allocate field value by the length.
1908 In field value, data is
1909 1D 03 8F 24 24 - Then 8F 24 24 is field value.
1910 1D 1F 33.... - Then allocate 33H for FieldValue.
1912 1D 'Hi man!' Like 00, if string is come, then process without calculating field value.
1913 1D 8F 24 24 - In this case, original data is wrong.
1914 If accept-charset: ISO-10646-ucs-2;Q=0.7 is
1917 03 - field value length
1918 03 E8 47 - field value
1919 it's decoded by above value.
1921 if (fieldValueLen < 0x20) {
1923 if (fieldValueLen == LENGTH_QUOTE) {
1925 /* field length is encoded in UINTVAR */
1926 unsigned long uintvarLen = 0;
1927 fieldValueLen = wspRetriveUintvarDecode((unsigned char*) encodedHeader + iEncodedHeader + 2, &uintvarLen );
1928 memcpy( fieldValue, encodedHeader + iEncodedHeader + 2 + uintvarLen, (size_t)fieldValueLen );
1929 iEncodedHeader = iEncodedHeader + fieldValueLen + uintvarLen + 2;
1933 if (fieldValueLen == 1) {
1934 /* field value is one byte integer over 0x80 */
1935 /** make it two byte integer */
1936 fieldValue[0] = 0x00;
1937 memcpy( fieldValue + 1, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
1939 iEncodedHeader = iEncodedHeader + 1 + 2;
1941 memcpy( fieldValue, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen );
1942 fieldValue[fieldValueLen] = 0;
1943 iEncodedHeader = iEncodedHeader + fieldValueLen + 2;
1944 if (( fieldValueLen == 0 ) || ( fieldValueLen == 0x80 )) {
1945 MSG_DEBUG("%X \n", encodedHeader[iEncodedHeader] );
1950 /* field value is single encoded */
1951 if (fieldValueLen > 0x7f) {
1952 fieldValue[0] = encodedHeader[iEncodedHeader + 1];
1954 iEncodedHeader = iEncodedHeader + 2;
1956 /* processing normal pre-defined field decoding */
1958 MSG_DEBUG("WspLDecodeHeader: FieldCode %X\n", fieldCode );
1959 MSG_DEBUG("WspLDecodeHeader: fieldSize %d\n", fieldValueLen );
1961 if (( fieldCode > wspHeaderFieldCount ) && ( fieldCode != 0xff )) {
1962 MSG_DEBUG("WspLDecodeHeader: unknown fieldcode %X \n", track );
1963 strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
1968 switch ( fieldCode )
1970 /* accept charset */
1971 /* It's normal way of field process. */
1974 unsigned long i = 0;
1977 /* Case of length of charset greater than 1 are two thigins.
1978 1. code length of charset is greater than 1.
1979 2. It include parameter.
1982 if (1 != fieldValueLen) {
1983 code = wspHeaderDecodeInteger( fieldValue );
1984 /* Calculate iField. */
1985 if (fieldValue[0] < 0x80 )
1986 iField = fieldValue[0];
1990 while ( wspCharset[i].charsetCode != code )
1992 strncat( (char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
1993 /* If parameter exist */
1994 if (iField < fieldValueLen) {
1996 AutoPtr<char> parambuf(¶m);
1997 wspHeaderDecodeQValue( fieldValueLen - iField, fieldValue + iField, ¶m);
1998 strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2001 code = fieldValue[0] & 0x7f;
2003 while (( wspCharset[i].charsetCode != code ) && ( wspCharset[i].charsetCode != 0xffff )) i++;
2004 strncat( (char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2011 /* Like below routine, Same decoding routine process together. */
2012 /* Accept-encoding */
2014 /* content-encoding */
2019 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen );
2020 if (integerValue > 2) {
2021 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(2).\n");
2024 strncat( (char*)temper, (char*)wspEncodeMethod[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2027 /* contents type decoder */
2033 unsigned long contentsTypeCode;
2034 unsigned long i = 0;
2035 /* encoded content type length body */
2036 unsigned long tempLen;
2038 /* Like HTTP result state 304, it's for processing without Content type. This part doesn't defined. */
2039 if (0 == fieldValueLen) {
2040 strncat( (char*)temper, (char*)"None" , (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2043 /* 01 AE --> 00 AE --> AE*/
2044 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2045 memcpy( fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1 );
2046 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n" );
2049 if ((fieldValue[0] < 0x20 ) || (fieldValue[0] > 0x80 )) {
2050 if (fieldValue[0] > 0x80) {
2052 } else if (fieldValueLen == 2 && fieldValue[0] == 0x03 && fieldValue[1] == 0x0A) { /** 06 05 02 03 0A AF 89 */
2053 fieldValue[3] = fieldValue[2];
2054 fieldValue[2] = fieldValue[1];
2055 fieldValue[1] = fieldValue[0];
2056 fieldValue[0] = 0x02;
2059 MSG_DEBUG("WspLDecodeHeader:For CPE problem\r\n" );
2061 tempLen = fieldValue[0]; /** 06 06 03 02 03 16 AF 88 */
2066 char* szExtendedContent;
2068 contentsTypeCode = fieldValue[0] & 0x7f;
2069 while (( wspContentsType[i].contentsTypeCode != contentsTypeCode ) && ( i < wspContentsTypeCount )) i++;
2071 /* If specified content type doesn't exist */
2072 if (i < wspContentsTypeCount)
2073 strncat( (char*)temper, (char*)wspContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2075 szExtendedContent = wspExtendedDecodeType( (char)contentsTypeCode );
2077 if (szExtendedContent != NULL) {
2078 MSG_DEBUG("WspLDecodeHeader: Tele2 server problem \n " );
2079 strncat( (char*)temper, (char*)szExtendedContent, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2082 contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
2084 while ((wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode) && (i < wspUnregisteredContentsTypeCount)) i++;
2086 /** If there is a Content-Type assigned, */
2087 if (i < wspUnregisteredContentsTypeCount)
2088 strncat ((char*)temper, (char*)wspUnregisterContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2093 tempLen = AcStrlen( (char*)fieldValue ) + 1;
2095 strncat ((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2096 MSG_DEBUG("WspLDecodeHeader: Attention, Decoding Check of Content-Type\n ", tempLen);
2099 /* If there is a parameter */
2100 if (tempLen < fieldValueLen) {
2102 AutoPtr<char> parambuf(¶m);
2103 wspHeaderDecodeParameter( fieldValue + tempLen, fieldValueLen - tempLen, ¶m);
2104 if (param != NULL) {
2105 strncat( (char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2106 strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2113 /* content-language */
2115 /* accept-language */
2118 unsigned long i = 0;
2120 unsigned long tempLen;
2121 if ((fieldValue[0] < 0x20 ) || (fieldValue[0] > 0x80 )) {
2122 if (fieldValue[0] > 0x80 )
2125 tempLen = fieldValue[0];
2127 tempLen = AcStrlen( (char*)fieldValue ) + 1;
2132 code = wspHeaderDecodeInteger( fieldValue );
2133 while ( wspLanguage[i].languageCode != code) {
2135 if (i == wspLanguageCount)
2139 if (i < wspLanguageCount) {
2140 strncat( (char*)temper, (char*)wspLanguage[i].languageName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2143 strncat( (char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2146 if (tempLen < fieldValueLen) {
2148 AutoPtr<char> parambuf(¶m);
2149 wspHeaderDecodeQValue( fieldValueLen - tempLen, fieldValue + tempLen, ¶m );
2150 strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2158 /* content-length */
2162 /* Bearer-indication */
2168 unsigned char temp[16];
2170 if (( fieldValueLen == 2 ) && ( fieldValue[0] > 0x7f ))
2171 AcSprintf( (char*)temp, "%u", (unsigned int)fieldValue[1]);
2174 sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue, fieldValueLen ));
2175 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2178 /* X-Wap-Application-Id */
2181 unsigned char temp[64];
2184 if (fieldValueLen == 2 && fieldValue[0] == 0) {
2185 memcpy( fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1 );
2186 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n" );
2190 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2192 if (integerValue > 0x0A) {
2193 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x0A).\n");
2197 snprintf((char*)temp, 64, "%s", wspHeaderApplId[integerValue].parameterToken);
2198 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1);
2201 /* Accept-Application */
2203 if (0x80 == fieldValue[0]) {
2204 strncat( (char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
2207 unsigned char temp[16];
2209 if (( fieldValueLen == 2 ) && ( fieldValue[0] == 1 ))
2210 AcSprintf( (char*)temp, "%u", (unsigned int)fieldValue[0]);
2213 sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue, fieldValueLen ));
2214 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1);
2222 /* if-unmodified-since */
2226 /* if-modified-since */
2233 char* decodedString = NULL;
2234 AutoPtr<char> decodedStringbuf(&decodedString);
2235 wspHeaderDecodeDateValue( fieldValueLen, fieldValue, &decodedString);
2236 strncat( (char*)temper, (char*)decodedString, (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
2242 if (fieldValue[0] == 0x80 )
2243 strncat( (char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
2247 if (fieldValue[0] == 0x80 )
2248 strncat( (char*)temper, "None", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
2249 if (fieldValue[0] == 0x81 )
2250 strncat( (char*)temper, "Bytes", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
2255 unsigned char temp[1275];
2256 memcpy( temp, fieldValue, (size_t)fieldValueLen );
2257 temp[fieldValueLen] = 0;
2258 wspHeaderCopyDecodedString( temp, ¤tLength, &temper );
2264 /* proxy - authorization */
2266 if (fieldValue[0] == 0x80) {
2267 char* addString = NULL;
2268 AutoPtr<char> addStringbuf(&addString);
2269 wspHeaderDecodeAuth(fieldValueLen, fieldValue, &addString );
2270 strncat( (char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2272 iField = AcStrlen( (char*)fieldValue) + 1;
2274 strncat( (char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2275 if (iField < fieldValueLen) {
2277 AutoPtr<char> parambuf(¶m);
2278 wspHeaderDecodeParameter( fieldValue + 1, fieldValueLen - 1, ¶m );
2279 if (param != NULL) {
2280 strncat( (char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2281 strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2291 /* Proxy-authenticate */
2293 if (0 == fieldValueLen )
2295 if (fieldValue[0] == 0x80) {
2296 char* addString = NULL;
2297 AutoPtr<char> addStringbuf(&addString);
2298 wspHeaderDecodeChallenge(fieldValueLen, fieldValue, &addString );
2299 strncat( (char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2301 unsigned char authScheme[WSP_STANDARD_STR_LEN_MAX + 1];
2302 unsigned char realmValue[WSP_STANDARD_STR_LEN_MAX];
2303 unsigned char addedString[WSP_STANDARD_STR_LEN_MAX];
2305 strncpy( (char*)authScheme, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX -1);
2306 iField = AcStrlen( (char*)authScheme ) + 1;
2307 strncpy( (char*)realmValue, (char*)(fieldValue + iField ), WSP_STANDARD_STR_LEN_MAX-1);
2308 iField = iField + AcStrlen( (char*)realmValue ) + 1;
2309 sprintf( (char*)addedString, "%s %s", authScheme, realmValue );
2310 wspHeaderCopyDecodedString( addedString, ¤tLength, &temper );
2312 if (iField < fieldValueLen) {
2314 AutoPtr<char> parambuf(¶m);
2315 wspHeaderDecodeParameter( fieldValue + iField, fieldValueLen - iField, ¶m );
2316 if (param != NULL) {
2317 strncat( (char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2318 wspHeaderCopyDecodedString( (unsigned char*)param, ¤tLength, &temper );
2324 /* content -range */
2327 unsigned long first, len, last;
2329 unsigned char temp[16];
2332 strncat( (char*)temper," bytes ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2334 first = wspRetriveUintvarDecode( fieldValue, &iField );
2335 len = wspRetriveUintvarDecode( fieldValue, &iField );
2336 /* 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.
2338 last = first + contentsLength - 1;
2340 sprintf( (char*)temp, "%u-%u/%u", (unsigned int)first, (unsigned int)last, (unsigned int)len );
2341 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2348 char* cacheString = NULL;
2349 AutoPtr<char> cacheStringbuf(&cacheString);
2351 wspHeaderDecodeCacheControl( fieldValue, fieldValueLen, &cacheString );
2352 strncat( (char*)temper, (char*)cacheString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2358 if (fieldValue[0] == 0x80) {
2359 strncat( (char*)temper, (char*)wspCacheControl[0], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2361 if (1 < fieldValueLen) {
2363 AutoPtr<char> parambuf(¶m);
2364 wspHeaderDecodeParameter( fieldValue, fieldValueLen, ¶m );
2366 if (param != NULL) {
2367 strncat( (char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2368 strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2379 unsigned long i = 0;
2380 while ( wspHeaderDecodeIntegerByLength( fieldValue, fieldValueLen ) != wspMethodType[i].methodCode ) i++;
2381 strncat( (char*)temper, (char*)wspMethodType[i].methodName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2386 strncat( (char*)temper, "bytes=", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2387 if (fieldValue[0] == 0x80) {
2388 unsigned char temp[16];
2389 unsigned long first, last;
2392 first = wspRetriveUintvarDecode( fieldValue, &iField );
2393 last = wspRetriveUintvarDecode( fieldValue, &iField );
2395 sprintf( (char*)temp, "%u-%u", (unsigned int)first, (unsigned int)last );
2396 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2398 if (fieldValue[0] == 0x81) {
2399 unsigned char temp[16];
2400 unsigned long suffix;
2402 suffix = wspRetriveUintvarDecode( fieldValue, &iField );
2404 sprintf( (char*)temp, "-%u", (unsigned int)suffix );
2410 if (fieldValue[0] == 0x80) {
2412 AutoPtr<char> tempbuf(&temp);
2414 wspHeaderDecodeDateValue( fieldValueLen - 1, fieldValue + 1, &temp );
2415 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2418 if (fieldValue[0] == 0x81) {
2419 unsigned char temp[16];
2421 sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue,fieldValueLen ));
2422 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2425 /* transfer-encoding */
2427 /* No other cases allowed */
2428 if (fieldValue[0] == 0x80 )
2429 strncat( (char*)temper, "chunked", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2435 int integerValue = wspHeaderDecodeIntegerByLength(fieldValue,fieldValueLen );
2436 if (integerValue > wspHeaderFieldCount) {
2437 MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x%x).\n",wspHeaderFieldCount);
2440 strncat( (char*)temper, (char*)wspHeaderFieldName[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2447 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2449 if (fieldValue[0] < 0x20 )
2450 iField = fieldValue[0];
2453 sprintf( (char*)temp, "%u", (unsigned int)wspHeaderDecodeIntegerByLength( fieldValue, iField ));
2454 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2455 if (iField < fieldValueLen) {
2456 unsigned char agent[WSP_STANDARD_STR_LEN_MAX];
2457 unsigned char text[WSP_STANDARD_STR_LEN_MAX];
2458 strncpy( (char*)agent, (char*)(fieldValue + iField ),WSP_STANDARD_STR_LEN_MAX-1);
2459 iField = iField + AcStrlen((char*)agent ) + 1;
2460 strncpy((char*)text, (char*)(fieldValue + iField ),WSP_STANDARD_STR_LEN_MAX-1);
2462 sprintf( (char*)temp, " %s %s", agent, text );
2463 wspHeaderCopyDecodedString( temp, ¤tLength, &temper );
2467 /* content-disposition */
2469 if (fieldValue[0] == 0x80 )
2470 strncat( (char*)temper, "form-data", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2472 if (fieldValue[0] == 0x81 )
2473 strncat( (char*)temper, "attachment", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2475 if (1 < fieldValueLen) {
2477 AutoPtr<char> parambuf(¶m);
2478 wspHeaderDecodeParameter( fieldValue + 1, fieldValueLen - 1, ¶m );
2480 if (param != NULL) {
2481 strncat( (char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2482 strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2488 temper[AcStrlen((char*)temper) + fieldValueLen] = '\0';
2489 memcpy( temper, fieldValue, (size_t)fieldValueLen );
2491 /* Profile-Warning */
2494 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2496 sprintf( (char*)temp, "%lX", wspHeaderDecodeInteger(fieldValue ));
2498 temp[1] = (unsigned char)0x30;
2500 if (fieldValueLen > 1) {
2501 /* copy warn-target - URI */
2502 strncat( (char*)temp, (char*)(fieldValue + 1), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1 );
2503 if (fieldValueLen > ( AcStrlen( (char*)(fieldValue + 1)) + 1 )) {
2504 /* copy warn-date */
2505 char* decodedString = NULL;
2506 AutoPtr<char> decodedStringbuf(&decodedString);
2507 wspHeaderDecodeDateValue( fieldValueLen - ( AcStrlen( (char*)(fieldValue + 1)) + 2 ), fieldValue + AcStrlen( (char*)(fieldValue + 1)) + 1, &decodedString );
2508 strncat( (char*)temp, (char*)decodedString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1 );
2511 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2522 /* It deosn't finished decoding yet. */
2523 if (( iEncodedHeader < encodedHeaderLen ) && ( fieldCode != 0xff )) {
2524 /* In here, iEncodedHeader already point next field code to be decoded. */
2525 /* If this code is same, then set continueField else add CRLF. */
2526 if (fieldCode == (encodedHeader[iEncodedHeader] & 0x7f )) {
2527 strncat( (char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2528 continueField = TRUE;
2530 strncat( (char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2531 continueField = FALSE;
2534 strncat( (char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2537 /* add single header to total headers */
2538 strncat( (char*)outTemper, (char*)temper, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)outTemper)-1 );
2539 MSG_DEBUG("WspLDecodeHeader: Single Header : %s\r\n", temper );
2544 MSG_DEBUG("WspLDecodeHeader: Header decoding ended.\n" );
2546 *pHeader = outTemper;
2553 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeInteger( unsigned char* data )
2555 /* we only can handle max 32bit integer */
2559 unsigned long integer;
2560 unsigned char seg[4];
2563 returner.integer = 0;
2565 if (data[0] < 0x80) {
2566 unsigned long IntLen = 0;
2568 IntLen = (data[0]>0x04) ? 0x04:data[0];
2570 MSG_DEBUG("WspLHeaderDecodeInteger: input %d , length %d\n", data[0], IntLen);
2572 for (i=0; i<IntLen; i++)
2573 returner.seg[IntLen-( i+1)] = data[i+1];
2575 return returner.integer;
2578 return data[0] & 0x7f;
2582 void SmsPluginWapPushHandler::wspHeaderDecodeQValue( unsigned long length, unsigned char* data, char** pDecodedString)
2584 unsigned short qBase = 0;
2587 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2588 if (*pDecodedString == NULL) {
2589 MSG_DEBUG("WspLHeaderDecodeQValue:MemAlloc failed\n");
2593 memcpy( &qBase, data, (size_t)length );
2594 qValue = (float)qBase;
2596 qValue = qValue - 100;
2597 qValue = qValue / 1000;
2598 sprintf( (char*)*pDecodedString, "; q=%.3f", qValue );
2600 /* qValue variable is divided by 100. And it's multiplied by 100.
2601 It's to resolve problem of changed 0.01 of qValue. */
2602 unsigned long qValueTemp;
2603 qValue = qValue - 1;
2604 qValue = qValue / 100;
2605 qValueTemp = (unsigned long)(qValue * 100);
2606 if (0 == (qValueTemp % 10 ))
2607 sprintf( (char*)*pDecodedString, "; q=%.1f", qValue );
2609 sprintf( (char*)*pDecodedString, "; q=%.2f", qValue );
2615 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length )
2620 unsigned long integer;
2621 unsigned short seg[4];
2624 returner.integer = 0;
2627 return data[0] & 0x7f;
2629 returner.integer = 0;
2631 for (i = 0 ; i < length; i++) {
2632 returner.integer = returner.integer + ( data[i] * (0x1 << ( ( length - ( i + 1)) * 8 )));
2633 MSG_DEBUG("WspLHeaderDecodeIntegerByLength: %d \n", returner.integer );
2636 return returner.integer;
2640 char* SmsPluginWapPushHandler::wspExtendedDecodeType(char contentType )
2644 while ( wspExtendedContentsType[i].contentsTypeCode != contentType) {
2645 if (wspExtendedContentsType[i].contentsTypeCode == 0xff)
2650 return (char*)wspExtendedContentsType[i].contentsTypeName;
2654 void SmsPluginWapPushHandler::wspHeaderDecodeParameter( unsigned char* data, unsigned long length, char** pParam)
2656 char* param = *pParam;
2658 unsigned long SecurityTypeCode;
2659 unsigned long i = 0;
2661 if (data[0] < 0x80) {
2662 /* unknown parameter type */
2663 param = new char[WSP_STANDARD_STR_LEN_MAX];
2665 if (param == NULL) {
2666 MSG_DEBUG("WspLHeaderDecodeParameter:MemAlloc failed\n" );
2670 strncpy( (char*)param, (char*)data, WSP_STANDARD_STR_LEN_MAX - 1);
2672 if (NO_VALUE == data[AcStrlen( (char*)param ) + 1]) {
2677 strncat( (char*)param, "=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1 );
2678 strncat( (char*)param, (char*)(data + AcStrlen( (char*)param )), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
2685 switch ( data[0] & 0x7f )
2688 wspHeaderDecodeQValue( length - 1, data + 1, ¶m);
2691 wspHeaderDecodeCharset( length - 1 , data + 1, ¶m);
2694 wspHeaderDecodeVersion( length - 1, data + 1, ¶m);
2698 param = new char[WSP_STANDARD_STR_LEN_MAX];
2699 if (param == NULL) {
2700 MSG_DEBUG("WspLHeaderDecodeParameter: 0x03 MemAlloc failed\n");
2703 sprintf( (char*)param, "Type=%i", (int)wspHeaderDecodeInteger( data + 1 ));
2707 param = new char[WSP_STANDARD_STR_LEN_MAX];
2709 if (param == NULL) {
2710 MSG_DEBUG("WspLHeaderDecodeParameter:0x08 MemAlloc failed\n");
2713 sprintf( (char*)param, "Padding=%i", (int)wspHeaderDecodeInteger( data + 1 ));
2717 param = new char[WSP_STANDARD_STR_LEN_MAX];
2719 if (param == NULL) {
2720 MSG_DEBUG("WspLHeaderDecodeParameter:0x05 MemAlloc failed\n");
2723 strncpy( (char*)param, "Name=", WSP_STANDARD_STR_LEN_MAX-1);
2724 memcpy( param + 5, data + 1, length - 1 );
2725 param[5 + length - 1] = '\0';
2729 param = new char[WSP_STANDARD_STR_LEN_MAX];
2731 if (param == NULL) {
2732 MSG_DEBUG("WspLHeaderDecodeParameter:0x06 MemAlloc failed\n");
2735 strncpy( (char*)param, "Filename=", WSP_STANDARD_STR_LEN_MAX-1);
2736 memcpy( param + 9, (char*)(data + 1), (size_t)(length - 1) );
2737 param[9 + length - 1] = '\0';
2744 /*OMA Provisioning*/
2746 param = new char[WSP_STANDARD_STR_LEN_MAX];
2748 if (param == NULL) {
2749 MSG_DEBUG("WspLHeaderDecodeParameter:0x11 MemAlloc failed\n");
2752 strncpy((char*)param, "SEC=", WSP_STANDARD_STR_LEN_MAX-1);
2753 SecurityTypeCode = data[1] & 0x7f;
2754 while (( i < wspSecurityTypeCount ) && ( wspSecurityType[i].SecurityTypeCode != SecurityTypeCode )) i++;
2756 if (i < wspSecurityTypeCount) {
2757 strncat( (char*)param, (char*)wspSecurityType[i].SecurityTypeName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
2760 if (0x12 == (data[2] & 0x7f)) {
2761 strncat( (char*)param, "; MAC=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1 );
2762 memcpy(param+AcStrlen( (char*)param),(char*)(data+3),(size_t)length-3 );
2777 void SmsPluginWapPushHandler::wspHeaderDecodeCharset( unsigned long length, unsigned char* data, char**pDecodedString)
2780 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2782 if (*pDecodedString == NULL) {
2783 MSG_DEBUG("WspLHeaderDecodeCharset:MemAlloc failed\n");
2787 strncpy( (char*)*pDecodedString, "charset=", WSP_STANDARD_STR_LEN_MAX-1);
2789 if (data[0] > 0x80) {
2790 unsigned long code = wspHeaderDecodeInteger(data );
2791 unsigned long i = 0;
2792 while (wspCharset[i].charsetCode != code) {
2793 if (wspCharset[i].charsetCode == 0xffff) {
2798 strncat( (char*)*pDecodedString, (char*)wspCharset[i].charsetName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pDecodedString)-1 );
2800 unsigned long lastLen = AcStrlen((char*)*pDecodedString);
2801 memcpy( (char*)(*pDecodedString + lastLen), data, (size_t)length );
2802 *pDecodedString[length + lastLen] = '\0';
2810 void SmsPluginWapPushHandler::wspHeaderDecodeVersion( unsigned long length, unsigned char* data, char** pDecodedString )
2812 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2814 if (*pDecodedString == NULL) {
2815 MSG_DEBUG("WspLHeaderDecodeVersion:MemAlloc failed\n");
2820 /* untyped version */
2821 memcpy( *pDecodedString, data, (size_t)length );
2824 unsigned char majorVer = ((data[0] & 0x7f ) >> 4 );
2825 unsigned char minorVer = data[0] & 0x0f;
2826 sprintf( (char*)*pDecodedString, "level=%u.%u", majorVer, minorVer );
2833 void SmsPluginWapPushHandler::wspHeaderDecodeDateValue( unsigned long length, unsigned char* data, char** pDecodedString )
2838 MSG_DEBUG("WspLHeaderDecodeDateValue: \n" );
2840 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2842 if (*pDecodedString == NULL) {
2843 MSG_DEBUG( "WspLHeaderDecodeDateValue:MemAlloc failed\n");
2847 lTime = wspHeaderDecodeIntegerByLength(data, length);
2849 pTMData = (struct tm*)gmtime((const time_t* )&lTime);
2851 if (pTMData == NULL) {
2852 MSG_DEBUG( "WspLHeaderDecodeDateValue: Date decode fail \n" );
2853 strncpy( (char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
2857 /* check date value validity */
2859 if (( pTMData->tm_wday > 6 ) || (pTMData->tm_mon > 12 ) || (pTMData->tm_mday > 31 ))
2861 MSG_DEBUG( "WspLHeaderDecodeDateValue: Date decode fail %d, %d, %d \n", pTMData->tm_wday, pTMData->tm_mon, pTMData->tm_mday );
2862 strncpy( (char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
2867 /**UNIX_DATE_TYPE : */
2868 sprintf( (char*)*pDecodedString, "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData->tm_wday], wspMonth[pTMData->tm_mon],
2869 pTMData->tm_mday, pTMData->tm_hour, pTMData->tm_min, pTMData->tm_sec, pTMData->tm_year + 1900 );
2875 void SmsPluginWapPushHandler::wspHeaderCopyDecodedString( unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper )
2877 unsigned long elementLen = AcStrlen( (char*)szDecodedString );
2878 char* temper2 = NULL;
2881 *currentLen = *currentLen + elementLen + 2;
2883 if ( *currentLen > AcStrlen( (char*)* pTemper ) + 2) {
2884 temper2 = new char[(*currentLen + 1 )];
2886 if (temper2 == NULL) {
2887 MSG_DEBUG( "WspLHeaderCopyDecodedString:MemAlloc failed\n");
2890 strncpy( (char*)temper2, (char*)* pTemper, *currentLen);
2892 strncpy( (char*)temper2, (char*)szDecodedString, *currentLen);
2901 void SmsPluginWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString )
2903 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
2904 unsigned char passWd[WSP_STANDARD_STR_LEN_MAX];
2905 unsigned long iField = 0;
2907 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX * 2];
2909 if (*pDecodedString == NULL) {
2910 MSG_DEBUG("WspLHeaderDecodeAuth:MemAlloc failed\n" );
2914 /* skip 'basic' code */
2916 sscanf((char*)(fieldValue + iField), "%s", userId );
2917 iField = iField + AcStrlen( (char*)userId ) + 1;
2918 sscanf( (char*)(fieldValue + iField), "%s", passWd );
2919 iField = iField + AcStrlen( (char*)userId ) + 1;
2920 sprintf( (char*)*pDecodedString, "basic %s/%s", userId, passWd );
2926 void SmsPluginWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString )
2928 unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
2929 unsigned long iField = 0;
2931 *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2933 if (*pDecodedString == NULL) {
2934 MSG_DEBUG( "WspLHeaderDecodeChallenge:MemAlloc failed\n");
2938 /* skip 'basic' code */
2940 sscanf( (char*)(fieldValue + iField), "%s", userId );
2941 iField = iField + AcStrlen( (char*)userId ) + 1;
2943 sprintf( (char*)*pDecodedString, "basic realm=\"%s\"", userId );
2949 void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString)
2951 unsigned char paramString[WSP_STANDARD_STR_LEN_MAX];
2952 unsigned char cacheCode;
2954 *pCacheString = new char[WSP_STANDARD_STR_LEN_MAX];
2955 if (*pCacheString == NULL) {
2956 MSG_DEBUG( "WspLHeaderDecodeCacheControl:MemAlloc failed\n");
2960 if (1 == fieldValueLen) {
2961 /* only one directive */
2962 if (fieldValue[0] > 0x8b) {
2963 return; /* It's error detection. can be omitted. */
2965 strncpy( (char*)*pCacheString, (char*)wspCacheControl[fieldValue[0] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
2969 if (fieldValue[0] > 0x7f) {
2970 /* directive that has parameter */
2971 cacheCode = fieldValue[0] & 0x7f;
2972 switch ( cacheCode )
2979 if (fieldValue[1] > 0x7f) {
2980 /* well known field name */
2981 strncpy( (char*)paramString, (char*)wspHeaderFieldName[fieldValue[1] & 0x7f],WSP_STANDARD_STR_LEN_MAX-1 );
2982 paramString[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
2984 /* unknown field name */
2985 strncpy( (char*)paramString, (char*)fieldValue + 1 , WSP_STANDARD_STR_LEN_MAX-1);
2995 sprintf( (char*)paramString, "%u", (unsigned int)wspHeaderDecodeInteger( fieldValue + 1));
3002 sprintf((char*)*pCacheString, "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString );
3004 /* cache extentions */
3005 /* In case of come directive of doesn't specified string style */
3007 unsigned long stringLen;
3009 strncpy( (char*)*pCacheString, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX-1);
3010 stringLen = AcStrlen((char*)*pCacheString );
3012 if (stringLen + 1 < fieldValueLen) {
3014 if (fieldValue[stringLen+ 1] > 0x7f) {
3015 int untyped = (int)wspHeaderDecodeIntegerByLength( fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1 ));
3017 sprintf( szString, "%d", untyped );
3018 strncat( (char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1 );
3019 strncat( (char*)*pCacheString, (char*)szString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1 );
3021 if (fieldValue[fieldValueLen] == 0) {
3022 strncat( (char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1 );
3023 strncat( (char*)*pCacheString, (char*)fieldValue + stringLen + 1 , WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);