update tizen source
[framework/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginWapPushHandler.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
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>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
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.
21 *
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.
28 *
29 */
30
31 #include "MsgDebug.h"
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"
40
41
42 #include "drm-service.h"
43
44 static unsigned short wapPushPortList [] = {0x0b84, 0x0b85, 0x23F0, 0x23F1, 0x23F2, 0x23F3, 0xC34F};
45
46 const SMS_PUSH_APP_INFO_S pushDefaultApplication [] =
47 {
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},
54
55         {(char*)"application/vnd.wap.mms-message", (char*)"X-Wap-Application-Id: x-wap-application:mms.ua\r\n", SMS_WAP_APPLICATION_MMS_UA},
56
57         {(char*)"application/vnd.wap.sia", (char*)"X-Wap-Application-Id: x-wap-application:push.sia\r\n", SMS_WAP_APPLICATION_PUSH_SIA},
58
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},
64
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},
67
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},
77
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},
82         {NULL, NULL}
83 };
84
85
86 char gWapCodeBufferLeft[WSP_CODE_BUFFER_LEFT_LEN_MAX];
87 char gWapCodeBufferRight[WSP_CODE_BUFFER_RIGHT_LEN_MAX];
88
89 const unsigned long wspUintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00200000, 0x10000000};
90
91 const unsigned char wspHeaderFieldCount  = 0x43;
92 const unsigned char wspContentsTypeCount = 0x34;
93 const unsigned long wspLanguageCount    = 0x11a;
94 const unsigned char wspSecurityTypeCount = 0x04;
95
96
97 static const SMS_WSP_CONTENTS_TYPE_S wspExtendedContentsType[] =
98 {
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 },
108
109         { (char*)"application/vnd.wap.mms-message", 0x3E },
110
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 },
119
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},
127         { (char*)"", 0xff }
128 };
129
130
131 const char* wspHeaderFieldName[] =
132 {
133         (char*)"Accept",  //0x00
134         (char*)"Accept-Charset",
135         (char*)"Accept-Encoding",
136         (char*)"Accept-Language",
137         (char*)"Accept-Ranges",
138         (char*)"Age", //0x05
139         (char*)"Allow",
140         (char*)"Authorization",
141         (char*)"Cache-Control",
142         (char*)"Connection",
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",
151         (char*)"Date",
152         (char*)"ETag",
153         (char*)"Expires",
154         (char*)"From", //0x15
155         (char*)"Host",
156         (char*)"If-Modified-Since",
157         (char*)"If-Match",
158         (char*)"If-None-Match",
159         (char*)"If-Range", //0x1a
160         (char*)"If-Unmodified-Since",
161         (char*)"Location",
162         (char*)"Last-Modified",
163         (char*)"Max-Forwards",
164         (char*)"Pragma",
165         (char*)"Proxy-Authenticate", //0x20
166         (char*)"Proxy-Authorization",
167         (char*)"Public",
168         (char*)"Range",
169         (char*)"Referer",
170         (char*)"Retry-After", //0x25
171         (char*)"Server",
172         (char*)"Transfer-Encodig",
173         (char*)"Upgrade",
174         (char*)"User-Agent",
175         (char*)"Vary", //0x2a
176         (char*)"Via",
177         (char*)"Warning",
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",
185         (char*)"Push-Flag",
186         (char*)"Profile", //0x35
187         (char*)"Profile-Diff",
188         (char*)"Profile-Warning", // end of WAP 1.2
189         (char*)"Expect",
190         (char*)"Te",
191         (char*)"Trailer", //0x3a
192         (char*)"Accept-Charset", //Back
193         (char*)"Accept-Encoding", // Back
194         (char*)"Cache-Control", // back
195         (char*)"Content-Range",
196         (char*)"X-Wap-Tod",
197         (char*)"Content-ID", //x40
198         (char*)"Set-Cookie",
199         (char*)"Cookie",
200         (char*)"Encoding-Version"
201 };
202
203
204 const SMS_WSP_CHARSET_S wspCharset[] =
205 {
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 }
222 };
223
224
225
226 const char* wspEncodeMethod[] =
227 {
228         (char*)"Gzip",
229         (char*)"Compress",
230         (char*)"Deflate"
231 };
232
233
234 const SMS_WSP_CONTENTS_TYPE_S wspContentsType[] =
235 {
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 },
289
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 },
299
300         { (char*)"application/vnd.wap.mms-message", 0x3E },
301
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 }
310 };
311
312 static const SMS_WAP_UNREGISTER_CONTENTS_TYPE_S wspUnregisterContentsType[]=
313 {
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}
317 };
318
319 const unsigned long wspUnregisteredContentsTypeCount = sizeof(wspUnregisterContentsType)/sizeof(SMS_WAP_UNREGISTER_CONTENTS_TYPE_S);
320
321 const SMS_WSP_LANGUAGE_S wspLanguage[] =
322 {
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 }
606 };
607
608
609 const SMS_WSP_HEADER_PARAMETER_S wspHeaderApplId[] =
610 {
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 }
621 };
622
623
624 const char* wspCacheControl[] =
625 {
626         (char*)"No-cache",
627         (char*)"No-store",
628         (char*)"Max-age",
629         (char*)"Max-stale",
630         (char*)"Min-fresh",
631         (char*)"Only-if-cached",
632         (char*)"Public",
633         (char*)"Private",
634         (char*)"No-transform",
635         (char*)"Must-revalidate",
636         (char*)"Proxy-revalidate"
637 };
638
639 const SMS_WSP_METHOD_TYPE_S wspMethodType[] =
640 {
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 }
648 };
649
650
651 const SMS_WSP_SECURITY_TYPE_S wspSecurityType[] =
652 {
653         {(char*)"NETWPIN",0x00},
654         {(char*)"USERPIN",0x01},
655         {(char*)"USERNETWPIN",0x02},
656         {(char*)"USERPINMAC",0x03}
657 };
658
659
660
661 const char* wspWeek[] =
662 {
663         (char*)"Sun",
664         (char*)"Mon",
665         (char*)"Tue",
666         (char*)"Wed",
667         (char*)"Thu",
668         (char*)"Fri",
669         (char*)"Sat"
670 };
671
672
673 const char* wspWeekDay[] =
674 {
675         (char*)"Sunday",
676         (char*)"Monday",
677         (char*)"Tuesday",
678         (char*)"Wednesday",
679         (char*)"Thursday",
680         (char*)"Friday",
681         (char*)"Saturday"
682 };
683
684 const char* wspMonth[] =
685 {
686         (char*)"Jan",
687         (char*)"Feb",
688         (char*)"Mar",
689         (char*)"Apr",
690         (char*)"May",
691         (char*)"Jun",
692         (char*)"Jul",
693         (char*)"Aug",
694         (char*)"Sep",
695         (char*)"Oct",
696         (char*)"Nov",
697         (char*)"Dec"
698 };
699
700
701
702 /*==================================================================================================
703                                      IMPLEMENTATION OF SmsPluginWapPushHandler - Member Functions
704 ==================================================================================================*/
705 SmsPluginWapPushHandler* SmsPluginWapPushHandler::pInstance = NULL;
706
707
708 SmsPluginWapPushHandler::SmsPluginWapPushHandler()
709 {
710         memset(&tmpAddress, 0x00, sizeof(tmpAddress));
711 }
712
713
714 SmsPluginWapPushHandler::~SmsPluginWapPushHandler()
715 {
716
717 }
718
719
720 SmsPluginWapPushHandler* SmsPluginWapPushHandler::instance()
721 {
722         if (!pInstance)
723                 pInstance = new SmsPluginWapPushHandler();
724
725         return pInstance;
726 }
727
728
729 bool SmsPluginWapPushHandler::IsWapPushMsg(SMS_USERDATA_S *pUserData)
730 {
731         MSG_BEGIN();
732
733         if (pUserData == NULL) {
734                 MSG_DEBUG("pUserData is NULL");
735                 return false;
736         }
737
738         int PortCount = sizeof(wapPushPortList)/sizeof(wapPushPortList[0]);
739
740         MSG_DEBUG("Port Count [%d]", PortCount);
741
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) {
746
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]);
750                                         return true;
751                                 }
752                         }
753                 }
754         }
755
756         MSG_END();
757
758         return false;
759 }
760
761
762 SMS_WAP_APP_CODE_T SmsPluginWapPushHandler::getAppCode(const char *pPushHeader)
763 {
764         int appCount = sizeof(pushDefaultApplication)/sizeof(pushDefaultApplication[0]) - 1;
765
766         unsigned char *header = NULL;
767         SMS_WAP_APP_CODE_T      appCode = SMS_WAP_APPLICATION_DEFAULT;
768
769         MSG_DEBUG("Application Count [%d]", appCount);
770
771         for (int i = 0; i < appCount; i++) {
772
773                 header = (unsigned char*)strcasestr(pPushHeader, pushDefaultApplication[i].pContentType);
774
775                 if (header != NULL) {
776                         appCode = pushDefaultApplication[i].appCode;
777                         break;
778                 }
779         }
780
781         if (appCode == SMS_WAP_APPLICATION_DEFAULT) {
782                 MSG_DEBUG("Application Type is not supported");
783         } else {
784                 MSG_DEBUG("Find Application [%d]", appCode);
785         }
786
787         return appCode;
788 }
789
790
791 void SmsPluginWapPushHandler::copyDeliverData(SMS_DELIVER_S *pDeliver)
792 {
793         tmpAddress.ton = pDeliver->originAddress.ton;
794         tmpAddress.npi = pDeliver->originAddress.npi;
795
796         strncpy(tmpAddress.address, pDeliver->originAddress.address, MAX_ADDRESS_LEN);
797
798         MSG_DEBUG("Address [%s]", tmpAddress.address);
799
800         tmpTimeStamp.format = pDeliver->timeStamp.format;
801
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;
810         }
811 }
812
813
814 void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize)
815 {
816         MSG_BEGIN();
817
818         unsigned char* pPDUTypeData = (unsigned char*)pUserData;
819         unsigned long PDUTypeDataLen = DataSize;
820
821         char* pPushHeader = NULL;
822         AutoPtr<char> pushHeaderBuf(&pPushHeader);
823         unsigned long pushHeaderLen = 0;
824
825         char* pPushBody = NULL;
826         AutoPtr<char> PushBodyBuf(&pPushBody);
827         unsigned long pushBodyLen = 0;
828
829         unsigned long iPDU = 1;
830
831         char* pWspHeader = NULL;
832         AutoPtr<char> WspHeaderBuf(&pWspHeader);
833         unsigned long   wspHeaderLen = 0;
834
835         char* pWspBody = NULL;
836         AutoPtr<char> WspBodyBuf(&pWspBody);
837         unsigned long wspBodyLen = 0;
838
839         /** pass PDU type */
840         iPDU++;
841
842         pushHeaderLen = wspRetriveUintvarDecode( pPDUTypeData, &iPDU );
843
844         MSG_DEBUG("PDUTypeDataLen [%d]", PDUTypeDataLen);
845         MSG_DEBUG("pushHeaderLen [%d]", pushHeaderLen);
846         MSG_DEBUG("iPDU [%d]", iPDU);
847
848         wspHeaderLen = pushHeaderLen + iPDU;
849
850         MSG_DEBUG("wspBodyLen [%d]", wspBodyLen);
851
852         if (wspHeaderLen > 0) {
853
854                 pWspHeader = new char[wspHeaderLen];
855
856                 if (pWspHeader == NULL) {
857                         MSG_DEBUG("pWspHeader Memory Allocation Failed");
858                         return;
859                 } else {
860                         memcpy(pWspHeader, pPDUTypeData, wspHeaderLen);
861                 }
862         }
863
864         /** return if it is below case error */
865         if (PDUTypeDataLen < wspHeaderLen) {
866                 MSG_DEBUG("PDUTypeDataLen < wspHeaderLen !!!");
867                 return;
868         }
869
870         /** Finding wspBody Information */
871         wspBodyLen = PDUTypeDataLen - wspHeaderLen;
872
873         if (wspBodyLen > 0) {
874
875                 pWspBody = new char[wspBodyLen];
876
877                 if (pWspBody == NULL) {
878                         MSG_DEBUG("pWspBody Memory Allocation Failed");
879                         return;
880                 } else {
881                         memcpy(pWspBody, pPDUTypeData + wspHeaderLen, wspBodyLen);
882                 }
883         } else {
884                 pWspBody = NULL;
885         }
886
887         wspDecodeHeader(pPDUTypeData + iPDU, pushHeaderLen, PDUTypeDataLen - (iPDU + pushHeaderLen), TRUE, &pPushHeader);
888
889         iPDU = iPDU + pushHeaderLen;
890
891         pushBodyLen = PDUTypeDataLen - iPDU ;
892
893         if (pushBodyLen > 0) {
894                 pPushBody = new char[pushBodyLen];
895
896                 if (pPushBody == NULL)  {
897                         MSG_DEBUG("pPushBody Memory Allocation Failed");
898                         return;
899                 } else {
900                         memcpy(pPushBody, pPDUTypeData+ iPDU, pushBodyLen);
901                 }
902         } else {
903                 pPushBody = NULL;
904                 return;
905         }
906
907         handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen);
908
909         MSG_END();
910 }
911
912
913 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
914 {
915         MSG_BEGIN();
916
917         if (pPushBody == NULL) {
918                 MSG_DEBUG("pPushBody is NULL");
919                 return;
920         }
921
922         SMS_WAP_APP_CODE_T      appCode = getAppCode(pPushHeader);
923
924         /**  check Push message receive setting */
925         bool bPushRecv = false;
926
927         MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv);
928
929         if ((bPushRecv == false) && (appCode != SMS_WAP_APPLICATION_MMS_UA)) {
930                 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
931                 return;
932         }
933
934         switch (appCode) {
935         case SMS_WAP_APPLICATION_MMS_UA:
936                 MSG_DEBUG("Received MMS Notification");
937
938                 handleMMSNotification(pPushBody, PushBodyLen);
939                 break;
940
941         case SMS_WAP_APPLICATION_PUSH_SI:
942                 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
943                 handleSIMessage(pPushBody, PushBodyLen, true);
944                 break;
945
946         case SMS_WAP_APPLICATION_PUSH_SIC:
947                 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
948                 handleSIMessage(pPushBody, PushBodyLen, false);
949                 break;
950
951         case SMS_WAP_APPLICATION_PUSH_SL:
952                 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
953                 handleSLMessage(pPushBody, PushBodyLen, true);
954                 break;
955
956         case SMS_WAP_APPLICATION_PUSH_SLC:
957                 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
958                 handleSLMessage(pPushBody, PushBodyLen, false);
959                 break;
960
961         case SMS_WAP_APPLICATION_PUSH_CO:
962                 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
963                 handleCOMessage(pPushBody, PushBodyLen, true);
964                 break;
965
966         case SMS_WAP_APPLICATION_PUSH_COC:
967                 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
968                 handleCOMessage(pPushBody, PushBodyLen, false);
969                 break;
970
971         case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
972                 MSG_DEBUG("Received DM BOOTSTRAP");
973                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
974                 break;
975
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);
979                 break;
980
981         case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
982                 MSG_DEBUG("Received Provisioning");
983                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
984                 break;
985
986         case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
987                 MSG_DEBUG("Received Provisioning");
988                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
989                 break;
990
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);
995                 break;
996
997         case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
998                 MSG_DEBUG("Received DM Notification");
999                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1000                 break;
1001
1002         case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1003                 MSG_DEBUG("Received DS Notification");
1004                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1005                 break;
1006
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);
1010                 break;
1011
1012         case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
1013         case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
1014                 MSG_DEBUG("Received DRM UA");
1015
1016                 if (pPushBody != NULL)
1017                         handleDrmVer1(pPushBody, PushBodyLen);
1018
1019                 break;
1020
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");
1026                 // TODO: DRM V2
1027                 break;
1028
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");
1033                 // TODO: Email
1034                 break;
1035
1036         case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1037                 MSG_DEBUG("Received IMPS CIR");
1038                 // TODO: IMPS CIR
1039                 break;
1040
1041         case SMS_WAP_APPLICATION_LBS :
1042                 MSG_DEBUG("Received LBS related message");
1043                 SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1044                 // TODO: LBS
1045                 break;
1046
1047         case SMS_WAP_APPLICATION_PUSH_SIA :
1048                 MSG_DEBUG("Received SIA");
1049                 // TODO: SIA
1050                 break;
1051
1052         default:
1053                 MSG_DEBUG("Unknown Application [%d]", appCode);
1054                 break;
1055         }
1056
1057         MSG_END();
1058 }
1059
1060
1061 void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen)
1062 {
1063         MSG_BEGIN();
1064
1065         /** Make MSG_MESSAGE_INFO_S */
1066         MSG_MESSAGE_INFO_S msgInfo;
1067
1068         createMsgInfo(&msgInfo);
1069
1070         /** Convert Type values */
1071         msgInfo.msgType.mainType = MSG_MMS_TYPE;
1072         msgInfo.msgType.subType = MSG_NOTIFICATIONIND_MMS;
1073
1074         msgInfo.dataSize = PushBodyLen;
1075
1076         if (msgInfo.dataSize > MAX_MSG_TEXT_LEN) {
1077                 msgInfo.bTextSms = false;
1078
1079                 /** Save Message Data into File */
1080                 char fileName[MAX_COMMON_INFO_SIZE+1];
1081                 memset(fileName, 0x00, sizeof(fileName));
1082
1083                 if (MsgCreateFileName(fileName) == false)
1084                         THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1085
1086                 if (MsgWriteIpcFile(fileName, pPushBody, msgInfo.dataSize) == false)
1087                         THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1088
1089                 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1090         } else {
1091                 msgInfo.bTextSms = true;
1092
1093                 memcpy(msgInfo.msgText, pPushBody, msgInfo.dataSize);
1094                 msgInfo.msgText[msgInfo.dataSize] = '\0';
1095         }
1096
1097         MSG_ERROR_T err = MSG_SUCCESS;
1098
1099         /** Add MMS Noti Msg into DB */
1100         err = SmsPluginStorage::instance()->addMessage(&msgInfo);
1101
1102         if (err == MSG_SUCCESS) {
1103                 /**  Callback */
1104                 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1105
1106                 if (err != MSG_SUCCESS) {
1107                         MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1108                 }
1109         } else {
1110                 MSG_DEBUG("addMessage() Error !! [%d]", err);
1111         }
1112
1113         MSG_END();
1114 }
1115
1116 void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText)
1117 {
1118         MSG_BEGIN();
1119
1120         MSG_PUSH_MESSAGE_S pushMsg = {};
1121
1122         xmlDocPtr       xmlDoc = NULL;
1123         xmlNodePtr      topNode = NULL;
1124         xmlNodePtr      indNode = NULL;
1125
1126         xmlChar*                tmpXmlChar = NULL;
1127
1128         if (pPushBody == NULL) {
1129                 MSG_DEBUG("pPushBody is NULL");
1130                 return;
1131         }
1132
1133         getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1134
1135         if (xmlDoc == NULL) {
1136                 MSG_DEBUG("xmlDoc is NULL");
1137                 return;
1138         }
1139
1140         topNode = xmlDocGetRootElement(xmlDoc);
1141
1142         if (xmlDoc == NULL) {
1143                 MSG_DEBUG("Empty Document");
1144                 xmlFreeDoc(xmlDoc);
1145                 return;
1146         }
1147
1148         indNode = topNode->xmlChildrenNode;
1149
1150         while (indNode != NULL) {
1151                 if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
1152                         MSG_DEBUG("indNode->name = %s\n", indNode->name);
1153                         break;
1154                 }
1155
1156                 indNode = indNode->next;
1157         }
1158
1159         if (indNode == NULL) {
1160                 MSG_DEBUG("indNode is NULL.");
1161                 return;
1162         }
1163
1164         /**  temporary set to max. */
1165         pushMsg.expires = 0xFFFFFFFF;
1166
1167         /** setting received time */
1168         time_t  t               =       time(NULL);
1169         time_t  utfTime =       time(&t);
1170
1171         pushMsg.received = (unsigned long)utfTime;
1172
1173         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1174
1175         if (tmpXmlChar == NULL) {
1176                 MSG_DEBUG("href is NULL.");
1177                 return;
1178         }
1179
1180         if (tmpXmlChar != NULL)
1181                 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1182
1183         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
1184
1185         if (tmpXmlChar != NULL)
1186                 strncpy(pushMsg.id, (char*)tmpXmlChar, MAX_WAPPUSH_ID_LEN-1);
1187
1188         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CREATED_TAG);
1189
1190         if (tmpXmlChar != NULL)
1191                 pushMsg.created = convertXmlCharToSec((char*)tmpXmlChar);
1192
1193         if (pushMsg.created == 0)
1194                 pushMsg.created = pushMsg.received;
1195
1196         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_EXPIRES_TAG);
1197
1198         if (tmpXmlChar != NULL)
1199                 pushMsg.expires = convertXmlCharToSec((char*)tmpXmlChar);
1200
1201         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1202
1203         pushMsg.action = convertSIActionStrToEnum((char*)tmpXmlChar);
1204
1205         tmpXmlChar = xmlNodeListGetString(xmlDoc, indNode->xmlChildrenNode, 1);
1206
1207         if (tmpXmlChar == NULL) {
1208                 MSG_DEBUG("contents is NULL.");
1209                 return;
1210         }
1211
1212         strncpy(pushMsg.contents, (char*)tmpXmlChar, MAX_WAPPUSH_CONTENTS_LEN-1);
1213
1214         /** Write push Msg to file */
1215         char fileName[MAX_COMMON_INFO_SIZE+1];
1216         memset(fileName, 0x00, sizeof(fileName));
1217
1218         if (MsgCreateFileName(fileName) == false) {
1219                 xmlFree(xmlDoc);
1220                 xmlFree(tmpXmlChar);
1221                 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1222         }
1223
1224         if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false) {
1225                 xmlFree(xmlDoc);
1226                 xmlFree(tmpXmlChar);
1227                 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1228         }
1229
1230         /**  Pack Message Info Structure */
1231         MSG_MESSAGE_INFO_S msgInfo;
1232
1233         createMsgInfo(&msgInfo);
1234
1235         strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1236
1237         /**  Convert Type values */
1238         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1239         msgInfo.msgType.subType = MSG_WAP_SI_SMS;
1240
1241         msgInfo.dataSize = sizeof(pushMsg);
1242
1243         xmlFree(xmlDoc);
1244         xmlFree(tmpXmlChar);
1245
1246         MSG_ERROR_T err = MSG_SUCCESS;
1247
1248         /** Add WAP Push Msg into DB */
1249         err = SmsPluginStorage::instance()->addMessage(&msgInfo);
1250
1251         if (err == MSG_SUCCESS) {
1252                 /** Callback */
1253                 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1254
1255                 if (err != MSG_SUCCESS){
1256                         MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1257                 }
1258         } else {
1259                 MSG_DEBUG("addMessage() Error !! [%d]", err);
1260         }
1261
1262         MSG_END();
1263
1264         return;
1265 }
1266
1267
1268 void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText)
1269 {
1270         MSG_BEGIN();
1271
1272         MSG_PUSH_MESSAGE_S pushMsg = {};
1273
1274         xmlDocPtr       xmlDoc = NULL;
1275         xmlNodePtr      topNode = NULL;
1276         xmlNodePtr      indNode = NULL;
1277
1278         xmlChar*                tmpXmlChar = NULL;
1279
1280         if (pPushBody == NULL) {
1281                 MSG_DEBUG("pPushBody is NULL \n" );
1282                 return;
1283         }
1284
1285         getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1286
1287         if (xmlDoc == NULL) {
1288                 MSG_DEBUG("xmlDoc is NULL \n" );
1289                 return;
1290         }
1291
1292         topNode = xmlDocGetRootElement(xmlDoc);
1293
1294         if (topNode == NULL) {
1295                 MSG_DEBUG("Empty Document." );
1296                 xmlFreeDoc(xmlDoc);
1297                 return;
1298         } else {
1299                 MSG_DEBUG("Not an empty Document and topNode->name = %s \n",topNode->name );
1300         }
1301
1302         indNode = topNode;
1303
1304         while (indNode != NULL) {
1305                 if (!xmlStrcmp(indNode->name, (const xmlChar*) "sl")) {
1306                         MSG_DEBUG("indNode->name = %s\n",indNode->name);
1307                         break;
1308                 }
1309
1310                 indNode = indNode->next;
1311         }
1312
1313         /**  setting received time setting */
1314         time_t  t               =       time(NULL);
1315         time_t  utfTime =       time(&t);
1316
1317         pushMsg.received = (unsigned long)utfTime;
1318
1319         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1320
1321         if (tmpXmlChar == NULL) {
1322                 MSG_DEBUG("href is NULL.");
1323                 return;
1324         }
1325
1326         strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1327
1328         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1329         pushMsg.action = convertSLActionStrToEnum((char*)tmpXmlChar);
1330
1331         /** Setting other parameters in default values */
1332         pushMsg.created = pushMsg.received;
1333         /** temporary set to MAX value. */
1334         pushMsg.expires = 0xFFFFFFFF;
1335
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);
1344
1345         /** Write push Msg to file */
1346         char fileName[MAX_COMMON_INFO_SIZE+1];
1347         memset(fileName, 0x00, sizeof(fileName));
1348
1349         if (MsgCreateFileName(fileName) == false)
1350                 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1351
1352         if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false)
1353                 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1354
1355         /** Pack Message Info Structure */
1356         MSG_MESSAGE_INFO_S msgInfo;
1357
1358         createMsgInfo(&msgInfo);
1359
1360         strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1361
1362         /** Convert Type values */
1363         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1364         msgInfo.msgType.subType = MSG_WAP_SL_SMS;
1365
1366         /**  Update Msg Text */
1367         strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
1368
1369         msgInfo.dataSize = sizeof(pushMsg);
1370
1371         MSG_DEBUG("dataSize : %d", msgInfo.dataSize);
1372
1373         /** Callback to MSG FW */
1374         SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1375
1376         xmlFree(xmlDoc);
1377         xmlFree(tmpXmlChar);
1378
1379         MSG_END();
1380
1381         return;
1382 }
1383
1384 void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText)
1385 {
1386         MSG_PUSH_CACHEOP_S cacheOp;
1387
1388         xmlDocPtr       xmlDoc = NULL;
1389         xmlNodePtr      topNode = NULL;
1390         xmlNodePtr      indNode = NULL;
1391
1392         memset(&cacheOp, 0x00, sizeof(cacheOp));
1393
1394         MSG_DEBUG("Enter handleCOMessage");
1395
1396         if (pPushBody == NULL) {
1397                 MSG_DEBUG("pPushBody is NULL \n" );
1398                 return;
1399         }
1400
1401         getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1402
1403         if (xmlDoc == NULL) {
1404                 MSG_DEBUG("xmlDoc is NULL \n" );
1405                 return;
1406         }
1407
1408         topNode = xmlDocGetRootElement(xmlDoc);
1409         if (topNode == NULL) {
1410                 MSG_DEBUG("Warning:Empty Document\n" );
1411                 xmlFreeDoc(xmlDoc);
1412                 return;
1413         }
1414
1415         indNode = topNode->xmlChildrenNode;
1416
1417
1418         while(indNode != NULL) {
1419
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);
1423
1424                         tmpUrl = xmlGetProp(indNode, (xmlChar*) SMS_PUSH_XML_CO_URI);
1425
1426                         if (tmpUrl != NULL) {
1427                                 strncpy(cacheOp.invalObjectUrl[cacheOp.invalObjectCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1428
1429                                 MSG_DEBUG("%dth invalObjectUrl is <%s>\n", cacheOp.invalObjectCnt, cacheOp.invalObjectUrl[cacheOp.invalObjectCnt-1]);
1430                         } else {
1431                                 MSG_DEBUG("NO href value from the xmlDoc\n");
1432                         }
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);
1436
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]);
1440                         } else {
1441                                 MSG_DEBUG("NO href value from the xmlDoc\n");
1442                         }
1443                 }
1444
1445                 if (tmpUrl != NULL)
1446                         xmlFree(tmpUrl);
1447
1448                 indNode = indNode->next;
1449         }
1450
1451         /**  Write push Msg to file */
1452         char fileName[MAX_COMMON_INFO_SIZE+1];
1453         memset(fileName, 0x00, sizeof(fileName));
1454
1455         if (MsgCreateFileName(fileName) == false) {
1456                 xmlFree(xmlDoc);
1457                 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1458         }
1459
1460         if (MsgWriteIpcFile(fileName, (char*)(&cacheOp), sizeof(cacheOp)) == false) {
1461                 xmlFree(xmlDoc);
1462                 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1463         }
1464
1465         /**  Pack Message Info Structure */
1466         MSG_MESSAGE_INFO_S msgInfo;
1467
1468         createMsgInfo(&msgInfo);
1469
1470         strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1471
1472         /**  Convert Type values */
1473         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1474         msgInfo.msgType.subType = MSG_WAP_CO_SMS;
1475
1476         msgInfo.dataSize = sizeof(cacheOp);
1477
1478         MSG_ERROR_T err = MSG_SUCCESS;
1479
1480         /** Add WAP Push Msg into DB */
1481         err = SmsPluginStorage::instance()->addMessage(&msgInfo);
1482
1483         if (err == MSG_SUCCESS) {
1484                 /** Callback */
1485                 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1486
1487                 if (err != MSG_SUCCESS) {
1488                         MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1489                 }
1490         } else {
1491                 MSG_DEBUG("addMessage() Error !! [%d]", err);
1492         }
1493
1494         xmlFree(xmlDoc);
1495
1496         return;
1497 }
1498
1499
1500 void SmsPluginWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
1501 {
1502         DRM_RESULT drmRt = DRM_RESULT_SUCCESS;
1503         char* cid = NULL;
1504         AutoPtr<char> buf(&cid);
1505
1506         MSG_DEBUG("Received DRM RIGHTS OBJECT Type WAP Push Message.");
1507
1508         drmRt = drm_svc_register_ro( (unsigned char*)pPushBody, (unsigned int)PushBodyLen,
1509                                                                         DRM_OMA_DRMV1_RIGHTS, (unsigned char**)&cid,
1510                                                                         NULL,
1511                                                                         DRM_ROAP_INIT_FROM_WAPPUSH,
1512                                                                         NULL);
1513
1514         if (drmRt == DRM_RESULT_SUCCESS) {
1515                 MSG_DEBUG("DRM successfully registed to drm-service.");
1516                 return;
1517         } else {
1518                 MSG_DEBUG("Fail to regist DRM to drm-service.");
1519                 return;
1520         }
1521 }
1522
1523
1524 void SmsPluginWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
1525 {
1526         /** Convert class Type values */
1527         pMsgInfo->msgType.classType = MSG_CLASS_NONE;
1528
1529         /**  set folder id (temporary) */
1530         pMsgInfo->folderId = MSG_INBOX_ID;
1531
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;
1537
1538
1539         time_t rawtime = time(NULL);
1540
1541         pMsgInfo->displayTime = rawtime;
1542
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);
1547
1548         pMsgInfo->msgPort.valid = false;
1549         pMsgInfo->msgPort.dstPort = 0;
1550         pMsgInfo->msgPort.srcPort = 0;
1551
1552 }
1553
1554 void SmsPluginWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText)
1555 {
1556         if (pPushBody == NULL) {
1557                 MSG_DEBUG("pPushBody is NULL");
1558                 return;
1559         }
1560
1561
1562         if (isText) {
1563                 *pXmlDoc = xmlParseMemory(pPushBody, strlen(pPushBody));
1564         } else {
1565                 WB_UTINY*       xmldata = NULL;
1566                 WBXMLConvWBXML2XML *conv = NULL;
1567                 WBXMLError ret = WBXML_OK;
1568
1569                 ret = wbxml_conv_wbxml2xml_create(&conv);
1570                 if (ret != WBXML_OK)
1571                         return;
1572
1573                 ret = wbxml_conv_wbxml2xml_run(conv, (WB_UTINY*)pPushBody, (WB_ULONG)PushBodyLen, &xmldata, NULL);
1574
1575                 wbxml_conv_wbxml2xml_destroy(conv);
1576
1577                 if (ret != WBXML_OK ||xmldata == NULL) {
1578                         MSG_DEBUG("xmldata is NULL. Error code is [%d].\n", ret);
1579                         return;
1580                 }
1581
1582                 MSG_DEBUG("xmldata : \n%s\n", xmldata);
1583
1584                 *pXmlDoc = xmlParseMemory((char*)xmldata, strlen((char*)xmldata));
1585         }
1586
1587 }
1588
1589 unsigned long SmsPluginWapPushHandler::convertXmlCharToSec(char* pDate)
1590 {
1591         struct tm       timeStruct;
1592         time_t          nTimeInSec = 0;
1593         char                    tmpBuf[10];
1594         int                     i = 0, index = 0;
1595
1596         memset(tmpBuf, 0x00, sizeof(tmpBuf));
1597         memset(&timeStruct, 0x00, sizeof(&timeStruct));
1598
1599         /** check pDate */
1600         if (strlen(pDate)<20)
1601                 return 0;
1602
1603         MSG_DEBUG("pDate [%s]", pDate);
1604
1605         /** Year */
1606         for (i = 0; i < 4; i++) {
1607                 tmpBuf[i] = pDate[index++];
1608         }
1609         tmpBuf[i] = '\0';
1610         index++;
1611         timeStruct.tm_year = (atoi( tmpBuf)-1900);
1612
1613         /**  Month */
1614         for (i = 0; i < 2; i++) {
1615                 tmpBuf[i] = pDate[index++];
1616         }
1617         tmpBuf[i] = '\0';
1618         index++;
1619         timeStruct.tm_mon = (atoi( tmpBuf) - 1);
1620
1621         /** Date */
1622         for (i = 0; i < 2; i++) {
1623                 tmpBuf[i] = pDate[index++];
1624         }
1625         tmpBuf[i] = '\0';
1626         index++;
1627         timeStruct.tm_mday = atoi( tmpBuf);
1628
1629         /** Hours */
1630         for (i = 0; i < 2; i++) {
1631                 tmpBuf[i] = pDate[index++];
1632         }
1633         tmpBuf[i] = '\0';
1634         index++;
1635         timeStruct.tm_hour = atoi( tmpBuf);
1636
1637         /** Minites */
1638         for (i = 0; i < 2; i++) {
1639                 tmpBuf[i] = pDate[index++];
1640         }
1641         tmpBuf[i] = '\0';
1642         index++;
1643         timeStruct.tm_min = atoi( tmpBuf);
1644
1645         /** Seconds */
1646         for (i = 0; i < 2; i++) {
1647                 tmpBuf[i] = pDate[index++];
1648         }
1649         tmpBuf[i] = '\0';
1650         index++;
1651         timeStruct.tm_sec = atoi( tmpBuf);
1652
1653         nTimeInSec = mktime(&timeStruct);
1654
1655         return nTimeInSec;
1656 }
1657
1658 MSG_PUSH_ACTION_T SmsPluginWapPushHandler::convertSIActionStrToEnum(char* pAction)
1659 {
1660         int comp = 0;
1661
1662         if (pAction == NULL) {
1663                 MSG_DEBUG("pAction is NULL. Setting to default action type.");
1664                 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
1665         }
1666
1667         /** compare  with signal-none. */
1668         comp = strcmp( "signal-none", pAction );
1669         if (comp == 0)
1670                 return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
1671
1672         /** compare  with signal-low. */
1673         comp = strcmp( "signal-low", pAction );
1674         if (comp == 0)
1675                 return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
1676
1677         /**  compare  with signal-medium. */
1678         comp = strcmp( "signal-medium", pAction );
1679         if (comp == 0)
1680                 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
1681
1682         /**  compare  with signal-high. */
1683         comp = strcmp( "signal-high", pAction );
1684         if (comp == 0)
1685                 return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
1686
1687         /**  compare  with delete. */
1688         comp = strcmp( "delete", pAction );
1689         if (comp == 0)
1690                 return MSG_PUSH_SI_ACTION_DELETE;
1691
1692         /**  signal-medium is default action value. */
1693         return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
1694
1695 }
1696
1697 MSG_PUSH_ACTION_T SmsPluginWapPushHandler::convertSLActionStrToEnum(char* pAction)
1698 {
1699         int comp = 0;
1700
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;
1704         }
1705
1706         /**  compare pSrcStr with execute-low. */
1707         comp = strcmp( "execute-low", pAction );
1708         if (comp == 0)
1709                 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
1710
1711         /**  compare pSrcStr with execute-high. */
1712         comp = strcmp( "execute-high", pAction );
1713         if (comp == 0)
1714                 return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
1715
1716         /** compare pSrcStr with cache. */
1717         comp = strcmp( "cache", pAction );
1718         if (comp == 0)
1719                 return MSG_PUSH_SL_ACTION_CACHE;
1720
1721         /** default SL action value is execute-low. */
1722         return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
1723
1724 }
1725
1726
1727 unsigned long SmsPluginWapPushHandler::wspRetriveUintvarDecode( unsigned char* sourceData, unsigned long* currentPointer )
1728 {
1729         unsigned long i = 0;
1730         unsigned long decodedValue;
1731
1732         while (sourceData[*currentPointer +i] >= 0x80) i++;
1733
1734         decodedValue = wspDecodeUintvar( i+1, sourceData + *currentPointer );
1735         *currentPointer = *currentPointer + i + 1;
1736         MSG_DEBUG("wspRetriveUintvarDecode: decodedValue=%d .\n",decodedValue );
1737         return decodedValue;
1738 }
1739
1740
1741 unsigned long SmsPluginWapPushHandler::wspDecodeUintvar(unsigned long length, unsigned char* userVar )
1742 {
1743         unsigned long i;
1744         unsigned long decodedUintvar = 0;
1745
1746
1747         for (i = 0 ; i < length; i++) {
1748                 decodedUintvar = decodedUintvar +  ( wspUintvarDecodeTable[i] * (userVar[length-(i+1)] & 0x7f ));
1749         }
1750
1751         return decodedUintvar;
1752 }
1753
1754
1755 void SmsPluginWapPushHandler::wspDecodeHeader( unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader)
1756 {
1757         unsigned long iField;
1758         bool   continueField = FALSE;
1759         unsigned long currentLength;
1760
1761         char* encodedHeader = NULL;
1762         AutoPtr<char> encodedHeaderbuf(&encodedHeader);
1763
1764         char* outTemper = NULL;
1765
1766         char* temper = NULL;
1767         AutoPtr<char> temperbuf(&temper);
1768
1769         unsigned char track;
1770         unsigned long iEncodedHeader = 0;
1771         unsigned char fieldCode = 0xff;
1772
1773         /* outTemper is Decoded Headers.
1774             temper is Single Decoded Header.
1775         */
1776         if (NULL == ( outTemper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ])) {
1777                 MSG_DEBUG("outTemper Memory allocation is failed.\n" );
1778                 return;
1779         }
1780         memset(outTemper, 0, (WSP_STANDARD_STR_LEN_MAX * 5));
1781         currentLength = WSP_STANDARD_STR_LEN_MAX;
1782
1783         MSG_DEBUG("wspDecodeHeader: Message header decoding started.\n" );
1784
1785         int loop;
1786         char szBuf[64];
1787
1788         szBuf[0] = 0x00;
1789         MSG_DEBUG("wspDecodeHeader: RAW data \n" );
1790         for (loop = 0 ; loop<(int)encodedHeaderLen; loop++) {
1791                 char szTempBuf[5];
1792                 szTempBuf[0] = 0x00;
1793                 sprintf( szTempBuf, "%2X ", sEncodedHeader[loop] );
1794
1795                 if (AcStrlen( szBuf ) + 7 < 64) {
1796                         strncat( szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1 );
1797                 } else {
1798                         strncat( szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1 );
1799                         MSG_DEBUG("[%s]", szBuf);
1800                         szBuf[0] = 0x00;
1801                         strncat( szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1 );
1802                 }
1803         }
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. */
1810
1811         if (fContentType) {
1812                 encodedHeader = new char[ encodedHeaderLen + 1 ];
1813                 if (encodedHeader == NULL)      {
1814                         MSG_DEBUG("encodedHeader Memory allocation is failed.\n" );
1815                         return;
1816                 }
1817                 encodedHeader[0] = 0x91;
1818                 memcpy( encodedHeader + 1, sEncodedHeader, (size_t)encodedHeaderLen );
1819         } else {
1820                 encodedHeader = new char[ encodedHeaderLen ];
1821                 if (encodedHeader == NULL)      {
1822                         MSG_DEBUG("encodedHeader Memory allocation is failed.\n" );
1823                         return;
1824                 }
1825
1826                 memcpy( encodedHeader, sEncodedHeader, (size_t)encodedHeaderLen );
1827         }
1828
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" );
1835                         return;
1836                 }
1837
1838                 memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
1839
1840                 /* this section presents header code page shifting procedure
1841                    This part can be implemented by future request.
1842                 if (track == 0x 7f )
1843                 */
1844                 track = encodedHeader[iEncodedHeader];
1845
1846                 if (track == 0x00) {
1847                         MSG_DEBUG("WspLDecodeHeader: fieldcode  is 0 \n" );
1848                         strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
1849                         fieldCode = 0xff;
1850                         iEncodedHeader++;
1851                 } else if (( track > 0 ) && ( track < 0x20 )) {
1852                         iEncodedHeader++;
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;
1856
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;
1863
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.' */
1868                         fieldCode = 0xff;
1869
1870                 } else if (track > 0x7f) {
1871                         /* In case of first byte is field code, else case is error. */
1872
1873                         /*if (( track & 0x7f ) <= wspHeaderFieldCount ) */
1874                         {
1875
1876                                 unsigned long  fieldValueLen = encodedHeader[iEncodedHeader + 1];
1877                                 unsigned char fieldValue[1275];
1878                                 fieldCode = track & 0x7f;
1879                                 /*
1880                                 if (( fieldValueLen == 0 ) || ( fieldValueLen == 0x80 ))
1881                                 {
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] );
1883                                 }
1884                                 */
1885                                 memset(fieldValue, 0, 1275);
1886                                 {
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;
1893                                         }
1894
1895                                         /* field value is string */
1896                                         /* In this case, it just copy field value. */
1897                                         if (( fieldValueLen > LENGTH_QUOTE ) && ( fieldValueLen < 0x80 )) {
1898
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 );
1902
1903                                                 iEncodedHeader = iEncodedHeader + AcStrlen( (char*)encodedHeader + iEncodedHeader + 1 ) + 2;
1904                                                 fieldCode = 0xff;
1905                                         }
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.
1911                                         1D 8F - Then 8F
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
1915                                         01 03 03 E8 47
1916                                         01 - field code
1917                                         03 - field value length
1918                                         03 E8 47 - field value
1919                                         it's decoded by above value.
1920                                         */
1921                                         if (fieldValueLen < 0x20) {
1922
1923                                                 if (fieldValueLen  == LENGTH_QUOTE) {
1924
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;
1930
1931                                                 } else {
1932
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);
1938                                                                 fieldValueLen = 2;
1939                                                                 iEncodedHeader = iEncodedHeader + 1 + 2;
1940                                                         } else {
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] );
1946                                                                 }
1947                                                         }
1948                                                 }
1949                                         }
1950                                         /* field value is single encoded */
1951                                         if (fieldValueLen > 0x7f) {
1952                                                 fieldValue[0] = encodedHeader[iEncodedHeader + 1];
1953                                                 fieldValueLen = 1;
1954                                                 iEncodedHeader = iEncodedHeader + 2;
1955                                         }
1956                                         /* processing normal pre-defined field decoding */
1957
1958                                         MSG_DEBUG("WspLDecodeHeader: FieldCode %X\n", fieldCode );
1959                                         MSG_DEBUG("WspLDecodeHeader: fieldSize %d\n", fieldValueLen );
1960
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);
1964                                                 fieldCode = 0xff;
1965                                         }
1966
1967
1968                                         switch ( fieldCode )
1969                                         {
1970                                                 /* accept charset */
1971                                                 /* It's normal way of field process. */
1972                                                 case 0x01 :
1973                                                         {
1974                                                                 unsigned long  i = 0;
1975                                                                 unsigned long  code;
1976
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.
1980                                                                 3. Or both of two
1981                                                                 */
1982                                                                 if (1 != fieldValueLen) {
1983                                                                         code = wspHeaderDecodeInteger( fieldValue );
1984                                                                         /* Calculate iField. */
1985                                                                         if (fieldValue[0] < 0x80 )
1986                                                                                 iField = fieldValue[0];
1987                                                                         else
1988                                                                                 iField = 1;
1989
1990                                                                         while ( wspCharset[i].charsetCode != code )
1991                                                                                 i++;
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) {
1995                                                                                 char* param = NULL;
1996                                                                                 AutoPtr<char> parambuf(&param);
1997                                                                                 wspHeaderDecodeQValue( fieldValueLen - iField, fieldValue + iField, &param);
1998                                                                                 strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
1999                                                                         }
2000                                                                 } else {
2001                                                                         code = fieldValue[0] & 0x7f;
2002
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 );
2005                                                                 }
2006
2007                                                         }
2008                                                         break;
2009
2010                                                 /* type encoding */
2011                                                 /* Like below routine, Same decoding routine process together. */
2012                                                 /* Accept-encoding */
2013                                                 case 0x02 :
2014                                                 /* content-encoding */
2015                                                 case 0x0b :
2016                                                         {
2017                                                                 int integerValue;
2018
2019                                                                 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen );
2020                                                                 if (integerValue > 2) {
2021                                                                         MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(2).\n");
2022                                                                         break;
2023                                                                 }
2024                                                                 strncat( (char*)temper, (char*)wspEncodeMethod[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2025                                                         }
2026                                                         break;
2027                                                 /* contents type decoder */
2028                                                 /* accept */
2029                                                 case 0x00 :
2030                                                 /* content-type */
2031                                                 case 0x11 :
2032                                                         {
2033                                                                 unsigned long  contentsTypeCode;
2034                                                                 unsigned long  i = 0;
2035                                                                 /* encoded content type length body */
2036                                                                 unsigned long  tempLen;
2037
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);
2041                                                                         break;
2042                                                                 }
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" );
2047                                                                 }
2048
2049                                                                 if ((fieldValue[0] < 0x20 ) || (fieldValue[0] > 0x80 )) {
2050                                                                         if (fieldValue[0] > 0x80) {
2051                                                                                 tempLen = 1;
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;
2057                                                                                 tempLen = 2;
2058                                                                                 fieldValueLen = 3;
2059                                                                                 MSG_DEBUG("WspLDecodeHeader:For CPE problem\r\n" );
2060                                                                         } else {
2061                                                                                 tempLen = fieldValue[0]; /** 06 06 03 02 03 16 AF 88 */
2062                                                                         }
2063
2064                                                                         if (tempLen == 1) {
2065
2066                                                                                 char* szExtendedContent;
2067
2068                                                                                 contentsTypeCode = fieldValue[0] & 0x7f;
2069                                                                                 while (( wspContentsType[i].contentsTypeCode != contentsTypeCode ) && ( i < wspContentsTypeCount )) i++;
2070
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 );
2074
2075                                                                                 szExtendedContent =  wspExtendedDecodeType( (char)contentsTypeCode );
2076
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 );
2080                                                                                 }
2081                                                                         } else {
2082                                                                                 contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
2083
2084                                                                                 while ((wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode) && (i < wspUnregisteredContentsTypeCount)) i++;
2085
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);
2089
2090                                                                                 tempLen +=1;
2091                                                                         }
2092                                                                 } else {
2093                                                                         tempLen = AcStrlen( (char*)fieldValue ) + 1;
2094
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);
2097                                                                 }
2098
2099                                                                 /* If there is a parameter */
2100                                                                 if (tempLen < fieldValueLen) {
2101                                                                         char* param = NULL;
2102                                                                         AutoPtr<char> parambuf(&param);
2103                                                                         wspHeaderDecodeParameter( fieldValue + tempLen, fieldValueLen - tempLen, &param);
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 );
2107                                                                         }
2108                                                                 }
2109                                                         }
2110                                                         break;
2111
2112                                                 /* language */
2113                                                 /* content-language */
2114                                                 case 0x0c :
2115                                                 /* accept-language */
2116                                                 case 0x03 :
2117                                                         {
2118                                                                 unsigned long i = 0;
2119                                                                 unsigned long code;
2120                                                                 unsigned long tempLen;
2121                                                                 if ((fieldValue[0] < 0x20 ) || (fieldValue[0] > 0x80 )) {
2122                                                                         if (fieldValue[0] > 0x80 )
2123                                                                                 tempLen = 1;
2124                                                                         else
2125                                                                                 tempLen = fieldValue[0];
2126                                                                 } else {
2127                                                                         tempLen = AcStrlen( (char*)fieldValue ) + 1;
2128                                                                 }
2129
2130                                                                 if (tempLen == 1) {
2131
2132                                                                         code = wspHeaderDecodeInteger( fieldValue );
2133                                                                         while ( wspLanguage[i].languageCode != code) {
2134                                                                                 i++;
2135                                                                                 if (i == wspLanguageCount)
2136                                                                                         break;
2137                                                                         }
2138
2139                                                                         if (i < wspLanguageCount) {
2140                                                                                 strncat( (char*)temper, (char*)wspLanguage[i].languageName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2141                                                                         }
2142                                                                 } else {
2143                                                                         strncat( (char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2144                                                                 }
2145
2146                                                                 if (tempLen < fieldValueLen) {
2147                                                                         char* param = NULL;
2148                                                                         AutoPtr<char> parambuf(&param);
2149                                                                         wspHeaderDecodeQValue(  fieldValueLen - tempLen, fieldValue + tempLen, &param );
2150                                                                         strncat( (char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2151                                                                 }
2152                                                         }
2153                                                         break;
2154
2155                                                 /* integer */
2156                                                 /* Max-forwards */
2157                                                 case 0x1e :
2158                                                 /* content-length */
2159                                                 case 0x0d :
2160                                                 /* age */
2161                                                 case 0x05 :
2162                                                 /* Bearer-indication */
2163                                                 case 0x33 :
2164                                                 /* Push-Flag */
2165                                                 case 0x34 :
2166                                                         {
2167
2168                                                                 unsigned char temp[16];
2169                                                                 /*
2170                                                                 if (( fieldValueLen == 2 ) && ( fieldValue[0] > 0x7f ))
2171                                                                         AcSprintf( (char*)temp, "%u", (unsigned int)fieldValue[1]);
2172                                                                 else
2173                                                                 */
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 );
2176                                                         }
2177                                                         break;
2178                                                 /* X-Wap-Application-Id */
2179                                                 case 0x2f :
2180                                                         {
2181                                                                 unsigned char temp[64];
2182                                                                 int         integerValue;
2183
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" );
2187                                                                         fieldValueLen = 1;
2188                                                                 }
2189
2190                                                                 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2191
2192                                                                 if (integerValue > 0x0A) {
2193                                                                         MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x0A).\n");
2194                                                                         break;
2195                                                                 }
2196
2197                                                                 snprintf((char*)temp, 64, "%s", wspHeaderApplId[integerValue].parameterToken);
2198                                                                 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1);
2199                                                         }
2200                                                         break;
2201                                                 /* Accept-Application */
2202                                                 case 0x32 :
2203                                                         if (0x80 == fieldValue[0]) {
2204                                                                 strncat( (char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
2205                                                         } else {
2206
2207                                                                 unsigned char temp[16];
2208                                                                 /*
2209                                 if (( fieldValueLen == 2 ) && ( fieldValue[0] == 1 ))
2210                                         AcSprintf( (char*)temp, "%u", (unsigned int)fieldValue[0]);
2211                                 else
2212                                                                 */
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);
2215                                                         }
2216                                                         break;
2217
2218
2219                                                 /* date */
2220                                                 /* last-modified */
2221                                                 case 0x1d :
2222                                                 /* if-unmodified-since */
2223                                                 case 0x1b :
2224                                                 /* if-range */
2225                                                 case 0x1a :
2226                                                 /* if-modified-since */
2227                                                 case 0x17 :
2228                                                 /* expires */
2229                                                 case 0x14 :
2230                                                 /* date */
2231                                                 case 0x12 :
2232                                                         {
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 );
2237                                                         }
2238                                                         break;
2239
2240                                                 /* connection */
2241                                                 case 0x09 :
2242                                                         if (fieldValue[0] == 0x80 )
2243                                                                 strncat( (char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-strlen(temper)-1 );
2244                                                         break;
2245                                                 /* accept-ranges */
2246                                                 case 0x04 :
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 );
2251                                                         break;
2252                                                 /* content-md5 */
2253                                                 case 0x0f :
2254                                                         {
2255                                                                 unsigned char temp[1275];
2256                                                                 memcpy( temp, fieldValue, (size_t)fieldValueLen );
2257                                                                 temp[fieldValueLen] = 0;
2258                                                                 wspHeaderCopyDecodedString( temp, &currentLength, &temper );
2259                                                         }
2260                                                         break;
2261                                                 /* Credential */
2262                                                 /* authorization */
2263                                                 case 0x07 :
2264                                                 /* proxy - authorization */
2265                                                 case 0x21 :
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 );
2271                                                         } else {
2272                                                                 iField = AcStrlen( (char*)fieldValue) + 1;
2273
2274                                                                 strncat( (char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2275                                                                 if (iField < fieldValueLen) {
2276                                                                         char* param = NULL;
2277                                                                         AutoPtr<char> parambuf(&param);
2278                                                                         wspHeaderDecodeParameter( fieldValue + 1, fieldValueLen - 1, &param );
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 );
2282                                                                         }
2283                                                                 }
2284                                                         }
2285                                                         break;
2286
2287
2288                                                 /* Challenge */
2289                                                 /* www - auth */
2290                                                 case 0x2d :
2291                                                 /* Proxy-authenticate */
2292                                                 case 0x20 :
2293                                                         if (0 == fieldValueLen )
2294                                                                 break;
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 );
2300                                                         } else {
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];
2304
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, &currentLength, &temper );
2311
2312                                                                 if (iField < fieldValueLen) {
2313                                                                         char* param = NULL;
2314                                                                         AutoPtr<char> parambuf(&param);
2315                                                                         wspHeaderDecodeParameter( fieldValue + iField, fieldValueLen - iField, &param );
2316                                                                         if (param != NULL) {
2317                                                                                 strncat( (char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2318                                                                                 wspHeaderCopyDecodedString( (unsigned char*)param, &currentLength, &temper );
2319                                                                         }
2320                                                                 }
2321                                                         }
2322                                                         break;
2323
2324                                                 /* content -range */
2325                                                 case 0x10 :
2326                                                         {
2327                                                                 unsigned long  first, len, last;
2328
2329                                                                 unsigned char  temp[16];
2330                                                                 iField = 0;
2331
2332                                                                 strncat( (char*)temper," bytes ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2333
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.
2337                                                                 */
2338                                                                 last = first + contentsLength - 1;
2339
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 );
2342                                                         }
2343                                                         break;
2344
2345                                                 /* cache-control */
2346                                                 case 0x08 :
2347                                                         {
2348                                                                 char* cacheString = NULL;
2349                                                                 AutoPtr<char> cacheStringbuf(&cacheString);
2350
2351                                                                 wspHeaderDecodeCacheControl( fieldValue, fieldValueLen, &cacheString );
2352                                                                 strncat( (char*)temper, (char*)cacheString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2353                                                         }
2354                                                         break;
2355
2356                                                 /* pragma */
2357                                                 case 0x1f :
2358                                                         if (fieldValue[0] == 0x80) {
2359                                                                 strncat( (char*)temper, (char*)wspCacheControl[0], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2360                                                         } else {
2361                                                                 if (1 < fieldValueLen) {
2362                                                                         char* param = NULL;
2363                                                                         AutoPtr<char> parambuf(&param);
2364                                                                         wspHeaderDecodeParameter( fieldValue, fieldValueLen, &param );
2365
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 );
2369                                                                         }
2370                                                                 }
2371                                                         }
2372
2373                                                         break;
2374                                                 /* public */
2375                                                 case 0x22 :
2376                                                 /* allow */
2377                                                 case 0x06 :
2378                                                         {
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 );
2382                                                         }
2383                                                         break;
2384                                                 /* range */
2385                                                 case 0x23 :
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;
2390                                                                 iField = 0;
2391
2392                                                                 first = wspRetriveUintvarDecode( fieldValue, &iField );
2393                                                                 last = wspRetriveUintvarDecode( fieldValue, &iField );
2394
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 );
2397                                                         }
2398                                                         if (fieldValue[0] == 0x81) {
2399                                                                 unsigned char temp[16];
2400                                                                 unsigned long  suffix;
2401
2402                                                                 suffix = wspRetriveUintvarDecode( fieldValue, &iField );
2403
2404                                                                 sprintf( (char*)temp, "-%u", (unsigned int)suffix );
2405
2406                                                         }
2407                                                         break;
2408                                                 /* retry-after */
2409                                                 case 0x25 :
2410                                                         if (fieldValue[0] == 0x80) {
2411                                                                 char* temp = NULL;
2412                                                                 AutoPtr<char> tempbuf(&temp);
2413
2414                                                                 wspHeaderDecodeDateValue( fieldValueLen - 1, fieldValue + 1, &temp );
2415                                                                 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2416                                                         }
2417
2418                                                         if (fieldValue[0] == 0x81) {
2419                                                                 unsigned char temp[16];
2420
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 );
2423                                                         }
2424                                                         break;
2425                                                 /* transfer-encoding */
2426                                                 case 0x27 :
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 );
2430
2431                                                         break;
2432                                                 /* vary */
2433                                                 case 0x2a :
2434                                                         {
2435                                                                 int integerValue = wspHeaderDecodeIntegerByLength(fieldValue,fieldValueLen );
2436                                                                 if (integerValue > wspHeaderFieldCount) {
2437                                                                         MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x%x).\n",wspHeaderFieldCount);
2438                                                                         break;
2439                                                                 }
2440                                                                 strncat( (char*)temper, (char*)wspHeaderFieldName[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2441                                                         }
2442                                                         break;
2443                                                 /* warning */
2444                                                 case 0x2c :
2445                                                         {
2446
2447                                                                 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2448
2449                                                                 if (fieldValue[0] < 0x20 )
2450                                                                         iField = fieldValue[0];
2451                                                                 else
2452                                                                         iField = 1;
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);
2461
2462                                                                         sprintf( (char*)temp, " %s %s", agent, text );
2463                                                                         wspHeaderCopyDecodedString( temp, &currentLength, &temper );
2464                                                                 }
2465                                                         }
2466                                                         break;
2467                                                 /* content-disposition */
2468                                                 case 0x2e :
2469                                                         if (fieldValue[0] == 0x80 )
2470                                                                 strncat( (char*)temper, "form-data", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2471
2472                                                         if (fieldValue[0] == 0x81 )
2473                                                                 strncat( (char*)temper, "attachment", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2474
2475                                                         if (1 < fieldValueLen) {
2476                                                                 char* param = NULL;
2477                                                                 AutoPtr<char> parambuf(&param);
2478                                                                 wspHeaderDecodeParameter( fieldValue + 1, fieldValueLen - 1, &param );
2479
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 );
2483                                                                 }
2484                                                         }
2485                                                         break;
2486                                                 /* Profile-diff */
2487                                                 case 0x36 :
2488                                                         temper[AcStrlen((char*)temper) + fieldValueLen] = '\0';
2489                                                         memcpy( temper, fieldValue, (size_t)fieldValueLen );
2490                                                         break;
2491                                                 /* Profile-Warning */
2492                                                 case 0x37 :
2493                                                         {
2494                                                                 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2495
2496                                                                 sprintf( (char*)temp, "%lX", wspHeaderDecodeInteger(fieldValue ));
2497                                                                 temp[2] = temp[1];
2498                                                                 temp[1] = (unsigned char)0x30;
2499                                                                 temp[3] = '\0';
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 );
2509                                                                         }
2510                                                                 }
2511                                                                 strncat( (char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2512                                                         }
2513                                                         break;
2514
2515                                                 default :
2516                                                         break;
2517                                         }
2518
2519                                 }
2520                         }
2521                 }
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;
2529                         } else {
2530                                 strncat( (char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2531                                 continueField = FALSE;
2532                         }
2533                 } else {
2534                         strncat( (char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1 );
2535                 }
2536
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 );
2540
2541         }
2542
2543
2544         MSG_DEBUG("WspLDecodeHeader: Header decoding ended.\n" );
2545
2546         *pHeader = outTemper;
2547
2548         return;
2549
2550 }
2551
2552
2553 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeInteger( unsigned char* data )
2554 {
2555         /* we only can handle max 32bit integer */
2556         unsigned long i;
2557
2558         union {
2559                 unsigned long integer;
2560                 unsigned char seg[4];
2561         } returner;
2562
2563         returner.integer = 0;
2564
2565         if (data[0] < 0x80) {
2566                 unsigned long IntLen = 0;
2567
2568                 IntLen = (data[0]>0x04) ? 0x04:data[0];
2569
2570                 MSG_DEBUG("WspLHeaderDecodeInteger: input %d , length %d\n", data[0], IntLen);
2571
2572                 for (i=0; i<IntLen; i++)
2573                         returner.seg[IntLen-( i+1)] = data[i+1];
2574
2575                 return returner.integer;
2576         }
2577
2578         return data[0] & 0x7f;
2579 }
2580
2581
2582 void SmsPluginWapPushHandler::wspHeaderDecodeQValue( unsigned long length, unsigned char* data, char** pDecodedString)
2583 {
2584         unsigned short qBase = 0;
2585         float  qValue;
2586
2587         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2588         if (*pDecodedString == NULL) {
2589                 MSG_DEBUG("WspLHeaderDecodeQValue:MemAlloc failed\n");
2590                 return;
2591         }
2592
2593         memcpy( &qBase, data, (size_t)length );
2594         qValue = (float)qBase;
2595         if (qValue > 100) {
2596                 qValue = qValue - 100;
2597                 qValue = qValue / 1000;
2598                 sprintf( (char*)*pDecodedString, "; q=%.3f", qValue );
2599         } else {
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 );
2608                 else
2609                         sprintf( (char*)*pDecodedString, "; q=%.2f", qValue );
2610         }
2611         return;
2612 }
2613
2614
2615 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length )
2616 {
2617         unsigned long i;
2618
2619         union {
2620                 unsigned long integer;
2621                 unsigned short  seg[4];
2622         } returner;
2623
2624         returner.integer = 0;
2625
2626         if (length == 1 )
2627                 return data[0] & 0x7f;
2628
2629         returner.integer = 0;
2630
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 );
2634         }
2635
2636         return returner.integer;
2637 }
2638
2639
2640 char* SmsPluginWapPushHandler::wspExtendedDecodeType(char contentType  )
2641 {
2642         int i = 0;
2643
2644         while ( wspExtendedContentsType[i].contentsTypeCode != contentType) {
2645                 if (wspExtendedContentsType[i].contentsTypeCode == 0xff)
2646                         return NULL;
2647                 i++;
2648         }
2649
2650         return (char*)wspExtendedContentsType[i].contentsTypeName;
2651 }
2652
2653
2654 void SmsPluginWapPushHandler::wspHeaderDecodeParameter( unsigned char* data, unsigned long length, char** pParam)
2655 {
2656         char* param = *pParam;
2657
2658         unsigned long SecurityTypeCode;
2659         unsigned long  i = 0;
2660
2661         if (data[0] < 0x80) {
2662                 /* unknown parameter type */
2663                 param = new char[WSP_STANDARD_STR_LEN_MAX];
2664
2665                 if (param == NULL) {
2666                         MSG_DEBUG("WspLHeaderDecodeParameter:MemAlloc failed\n" );
2667                         return;
2668                 }
2669
2670                 strncpy( (char*)param, (char*)data, WSP_STANDARD_STR_LEN_MAX - 1);
2671
2672                 if (NO_VALUE == data[AcStrlen( (char*)param ) + 1]) {
2673                         *pParam = param;
2674                         return;
2675                 }
2676
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);
2679
2680                 *pParam = param;
2681
2682                 return;
2683         }
2684
2685         switch ( data[0] & 0x7f )
2686         {
2687                 case 0x00 :
2688                         wspHeaderDecodeQValue(  length - 1, data + 1, &param);
2689                         break;
2690                 case 0x01 :
2691                         wspHeaderDecodeCharset( length - 1 , data + 1, &param);
2692                         break;
2693                 case 0x02 :
2694                         wspHeaderDecodeVersion( length - 1, data + 1, &param);
2695                         break;
2696                         /* integer */
2697                 case 0x03 :
2698                         param = new char[WSP_STANDARD_STR_LEN_MAX];
2699                         if (param == NULL) {
2700                                 MSG_DEBUG("WspLHeaderDecodeParameter: 0x03 MemAlloc failed\n");
2701                                 return;
2702                         } else {
2703                                 sprintf( (char*)param, "Type=%i", (int)wspHeaderDecodeInteger( data + 1 ));
2704                         }
2705                         break;
2706                 case 0x08 :
2707                         param = new char[WSP_STANDARD_STR_LEN_MAX];
2708
2709                         if (param == NULL) {
2710                                 MSG_DEBUG("WspLHeaderDecodeParameter:0x08 MemAlloc failed\n");
2711                                 return;
2712                         } else {
2713                                 sprintf( (char*)param, "Padding=%i", (int)wspHeaderDecodeInteger( data + 1 ));
2714                         }
2715                         break;
2716                 case 0x05 :
2717                         param = new char[WSP_STANDARD_STR_LEN_MAX];
2718
2719                         if (param == NULL) {
2720                                 MSG_DEBUG("WspLHeaderDecodeParameter:0x05 MemAlloc failed\n");
2721                                 return;
2722                         } else {
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';
2726                         }
2727                         break;
2728                 case 0x06 :
2729                         param = new char[WSP_STANDARD_STR_LEN_MAX];
2730
2731                         if (param == NULL) {
2732                                 MSG_DEBUG("WspLHeaderDecodeParameter:0x06 MemAlloc failed\n");
2733                                 return;
2734                         } else {
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';
2738                         }
2739                         break;
2740                 case 0x07 :
2741                         param = NULL;
2742                         /* TBI */
2743                         break;
2744                         /*OMA Provisioning*/
2745                 case 0x11 :
2746                         param = new char[WSP_STANDARD_STR_LEN_MAX];
2747
2748                         if (param == NULL) {
2749                                 MSG_DEBUG("WspLHeaderDecodeParameter:0x11 MemAlloc failed\n");
2750                                 return;
2751                         } else {
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++;
2755
2756                                 if (i < wspSecurityTypeCount) {
2757                                         strncat( (char*)param, (char*)wspSecurityType[i].SecurityTypeName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
2758                                 }
2759
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 );
2763                                 }
2764                         }
2765                         break;
2766
2767                 default :
2768                         param = NULL;
2769                         break;
2770         }
2771
2772         *pParam = param;
2773         return;
2774 }
2775
2776
2777 void SmsPluginWapPushHandler::wspHeaderDecodeCharset( unsigned long length, unsigned char* data, char**pDecodedString)
2778 {
2779
2780         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2781
2782         if (*pDecodedString == NULL) {
2783                 MSG_DEBUG("WspLHeaderDecodeCharset:MemAlloc failed\n");
2784                 return;
2785         }
2786
2787         strncpy( (char*)*pDecodedString, "charset=", WSP_STANDARD_STR_LEN_MAX-1);
2788
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) {
2794                                 return;
2795                         }
2796                         i++;
2797                 }
2798                 strncat( (char*)*pDecodedString, (char*)wspCharset[i].charsetName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pDecodedString)-1 );
2799         } else {
2800                 unsigned long  lastLen = AcStrlen((char*)*pDecodedString);
2801                 memcpy( (char*)(*pDecodedString + lastLen), data, (size_t)length );
2802                 *pDecodedString[length + lastLen] = '\0';
2803         }
2804
2805         return;
2806 }
2807
2808
2809
2810 void SmsPluginWapPushHandler::wspHeaderDecodeVersion( unsigned long length, unsigned char* data, char** pDecodedString )
2811 {
2812         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2813
2814         if (*pDecodedString == NULL) {
2815                 MSG_DEBUG("WspLHeaderDecodeVersion:MemAlloc failed\n");
2816                 return;
2817         }
2818
2819         if (length > 1) {
2820                 /* untyped version */
2821                 memcpy( *pDecodedString, data, (size_t)length );
2822         } else {
2823                 /* typed version */
2824                 unsigned char majorVer  = ((data[0] & 0x7f ) >> 4 );
2825                 unsigned char minorVer = data[0] & 0x0f;
2826                 sprintf( (char*)*pDecodedString, "level=%u.%u", majorVer, minorVer );
2827         }
2828
2829         return;
2830 }
2831
2832
2833 void SmsPluginWapPushHandler::wspHeaderDecodeDateValue( unsigned long length, unsigned char* data, char** pDecodedString )
2834 {
2835         time_t  lTime;
2836         struct  tm* pTMData;
2837
2838         MSG_DEBUG("WspLHeaderDecodeDateValue:   \n" );
2839
2840         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2841
2842         if (*pDecodedString == NULL) {
2843                 MSG_DEBUG( "WspLHeaderDecodeDateValue:MemAlloc failed\n");
2844                 return;
2845         }
2846
2847         lTime = wspHeaderDecodeIntegerByLength(data, length);
2848
2849         pTMData = (struct tm*)gmtime((const time_t* )&lTime);
2850
2851         if (pTMData == NULL) {
2852                 MSG_DEBUG( "WspLHeaderDecodeDateValue: Date decode fail \n" );
2853                 strncpy( (char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
2854                 return;
2855         }
2856
2857         /* check date value validity */
2858         {
2859                 if (( pTMData->tm_wday > 6 ) || (pTMData->tm_mon > 12 ) || (pTMData->tm_mday >  31 ))
2860                 {
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);
2863                         return;
2864                 }
2865         }
2866
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 );
2870
2871         return;
2872
2873 }
2874
2875 void SmsPluginWapPushHandler::wspHeaderCopyDecodedString( unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper )
2876 {
2877         unsigned long elementLen = AcStrlen( (char*)szDecodedString );
2878         char* temper2 = NULL;
2879
2880         /**  // CR+LF */
2881         *currentLen = *currentLen + elementLen + 2;
2882
2883         if ( *currentLen > AcStrlen( (char*)* pTemper ) + 2) {
2884                 temper2 = new char[(*currentLen + 1 )];
2885
2886                 if (temper2 == NULL) {
2887                         MSG_DEBUG( "WspLHeaderCopyDecodedString:MemAlloc failed\n");
2888                         return;
2889                 }
2890                 strncpy( (char*)temper2, (char*)* pTemper, *currentLen);
2891                 delete[] *pTemper;
2892                 strncpy( (char*)temper2, (char*)szDecodedString, *currentLen);
2893         }
2894
2895         *pTemper = temper2;
2896
2897         return;
2898 }
2899
2900
2901 void SmsPluginWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString )
2902 {
2903         unsigned char  userId[WSP_STANDARD_STR_LEN_MAX];
2904         unsigned char  passWd[WSP_STANDARD_STR_LEN_MAX];
2905         unsigned long iField = 0;
2906
2907         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX * 2];
2908
2909         if (*pDecodedString == NULL) {
2910                 MSG_DEBUG("WspLHeaderDecodeAuth:MemAlloc failed\n" );
2911                 return;
2912         }
2913
2914         /* skip 'basic' code */
2915         iField++;
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 );
2921
2922         return;
2923 }
2924
2925
2926 void SmsPluginWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString )
2927 {
2928         unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
2929         unsigned long iField = 0;
2930
2931         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
2932
2933         if (*pDecodedString == NULL) {
2934                 MSG_DEBUG( "WspLHeaderDecodeChallenge:MemAlloc failed\n");
2935                 return;
2936         }
2937
2938         /* skip 'basic' code */
2939         iField++;
2940         sscanf( (char*)(fieldValue + iField), "%s", userId );
2941         iField = iField + AcStrlen( (char*)userId ) + 1;
2942
2943         sprintf( (char*)*pDecodedString, "basic realm=\"%s\"", userId );
2944
2945         return;
2946 }
2947
2948
2949 void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString)
2950 {
2951         unsigned char  paramString[WSP_STANDARD_STR_LEN_MAX];
2952         unsigned char  cacheCode;
2953
2954         *pCacheString = new char[WSP_STANDARD_STR_LEN_MAX];
2955         if (*pCacheString == NULL) {
2956                 MSG_DEBUG( "WspLHeaderDecodeCacheControl:MemAlloc failed\n");
2957                 return;
2958         }
2959
2960         if (1 == fieldValueLen) {
2961                 /* only one directive */
2962                 if (fieldValue[0] > 0x8b) {
2963                         return; /* It's error detection. can be omitted. */
2964                 }
2965                 strncpy( (char*)*pCacheString, (char*)wspCacheControl[fieldValue[0] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
2966                 return;
2967         }
2968
2969         if (fieldValue[0] > 0x7f) {
2970                 /* directive that has parameter */
2971                 cacheCode = fieldValue[0] & 0x7f;
2972                 switch ( cacheCode )
2973                 {
2974                                 /* field name */
2975                                 /* no-cache */
2976                         case 0x00 :
2977                                 /* private */
2978                         case 0x07 :
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';
2983                                 } else {
2984                                         /* unknown field name */
2985                                         strncpy( (char*)paramString, (char*)fieldValue + 1 , WSP_STANDARD_STR_LEN_MAX-1);
2986                                 }
2987                                 break;
2988                                 /* secound */
2989                                 /* max-age */
2990                         case 0x02 :
2991                                 /* max- stale */
2992                         case 0x03 :
2993                                 /* min-fresh */
2994                         case 0x04 :
2995                                 sprintf( (char*)paramString, "%u", (unsigned int)wspHeaderDecodeInteger( fieldValue + 1));
2996                                 break;
2997
2998                         default :
2999                                 break;
3000
3001                 }
3002                 sprintf((char*)*pCacheString, "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString );
3003         } else {
3004                 /* cache extentions */
3005                 /* In case of come directive of doesn't specified string style */
3006
3007                 unsigned long stringLen;
3008                 char szString[32];
3009                 strncpy( (char*)*pCacheString, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX-1);
3010                 stringLen = AcStrlen((char*)*pCacheString );
3011
3012                 if (stringLen + 1 < fieldValueLen) {
3013
3014                         if (fieldValue[stringLen+ 1] > 0x7f) {
3015                                 int untyped = (int)wspHeaderDecodeIntegerByLength( fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1 ));
3016
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 );
3020                         } else {
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);
3024                                 }
3025                         }
3026                 }
3027         }
3028
3029         return;
3030 }