Fix issue : fail to make thumbnail
[platform/core/messaging/msg-service.git] / plugin / sms_plugin / SmsPluginWapPushHandler.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16
17 #include "MsgDebug.h"
18 #include "MsgCppTypes.h"
19 #include "MsgGconfWrapper.h"
20 #include "MsgException.h"
21 #include "MsgUtilFile.h"
22 #include "SmsPluginStorage.h"
23 #include "SmsPluginTransport.h"
24 #include "SmsPluginEventHandler.h"
25 #include "SmsPluginWapPushHandler.h"
26
27 #include <glib.h>
28 #include <gio/gio.h>
29 #if MSG_DRM_SUPPORT
30 #include <drm_client.h>
31 #endif
32
33 static unsigned short wapPushPortList[] = {0x0b84, 0x0b85, 0x23F0, 0x23F1, 0x23F2, 0x23F3, 0xC34F};
34
35 #if 0
36 const SMS_PUSH_APP_INFO_S pushDefaultApplication[] =
37 {
38         {(char*)"text/vnd.wap.si", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SI},
39         {(char*)"application/vnd.wap.sic", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SIC},
40         {(char*)"text/vnd.wap.sl", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SL},
41         {(char*)"application/vnd.wap.slc", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_SLC},
42         {(char*)"text/vnd.wap.co", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_CO},
43         {(char*)"application/vnd.wap.coc", (char*)"X-Wap-Application-Id: x-wap-application:wml.ua\r\n", SMS_WAP_APPLICATION_PUSH_COC},
44
45         {(char*)"application/vnd.wap.mms-message", (char*)"X-Wap-Application-Id: x-wap-application:mms.ua\r\n", SMS_WAP_APPLICATION_MMS_UA},
46
47         {(char*)"application/vnd.wap.sia", (char*)"X-Wap-Application-Id: x-wap-application:push.sia\r\n", SMS_WAP_APPLICATION_PUSH_SIA},
48
49         {(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},
50         {(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},
51         {(char*)"application/vnd.syncml.notification", (char*)"X-Wap-Application-Id: x-wap-application:push.syncml.dm\r\n", SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION},
52         {(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},
53         {(char*)"application/vnd.syncml+wbxml", (char*)"X-Wap-Application-Id:x-wap-application:push.syncml", SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML},
54
55         {(char*)"application/vnd.wap.locc+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:loc.ua\r\n", SMS_WAP_APPLICATION_LOC_UA_WBXML},
56         {(char*)"application/vnd.wap.loc+xml", (char*)"X-Wap-Application-Id: x-wap-application:loc.ua\r\n", SMS_WAP_APPLICATION_LOC_UA_XML},
57
58         {(char*)"application/vnd.oma.dd+xml", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_XML},
59         {(char*)"application/vnd.oma.drm.message", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_MESSAGE},
60         {(char*)"application/vnd.oma.drm.content", (char*)"X-Wap-Application-Id: x-wap-application:drm.ua\r\n", SMS_WAP_APPLICATION_DRM_UA_CONETENT},
61         {(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},
62         {(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},
63         {(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},
64         {(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},
65         {(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},
66         {(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},
67
68         {(char*)"text/vnd.wap.connectivity-xml", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML},
69         {(char*)"application/vnd.wap.connectivity-wbxml", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML},
70
71         {(char*)"application/x-wap-prov.browser-settings", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS},
72         {(char*)"application/x-wap-prov.browser-bookmarks", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS},
73         {(char*)"application/x-wap-prov.syncset+xml", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_SYNCSET_WBXML},
74         {(char*)"application/x-wap-prov.syncset+wbxml", (char*)"X-Wap-Application-Id: x-wap-samsung:provisioning.ua\r\n", SMS_WAP_APPLICATION_PUSH_SYNCSET_XML},
75         {(char*)"text/vnd.wap.emn+xml", (char*)"X-Wap-Application-Id: x-wap-application:emn.ua\r\n", SMS_WAP_APPLICATION_PUSH_EMAIL_XML},
76         {(char*)"application/vnd.wap.emn+wbxml", (char*)"X-Wap-Application-Id: x-wap-application:emn.ua\r\n", SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML},
77         {(char*)"application/vnd.wv.csp.cir", (char*)"X-Wap-Application-Id: x-wap-application:wv.ua\r\n", SMS_WAP_APPLICATION_PUSH_IMPS_CIR},
78         {(char*)"application/vnd.omaloc-supl-init", (char*)"X-Wap-Application-Id: x-oma-application:ulp.ua\r\n", SMS_WAP_APPLICATION_LBS},
79         {NULL, NULL}
80 };
81 #endif
82
83 char gWapCodeBufferLeft[WSP_CODE_BUFFER_LEFT_LEN_MAX];
84 char gWapCodeBufferRight[WSP_CODE_BUFFER_RIGHT_LEN_MAX];
85
86 const unsigned long wspUintvarDecodeTable[] = { 0x00000001, 0x00000080, 0x00004000, 0x00200000, 0x10000000 };
87
88 const unsigned char wspHeaderFieldCount  = 0x43;
89 const unsigned char wspContentsTypeCount = 0x34;
90 const unsigned long wspLanguageCount    = 0x11a;
91 const unsigned char wspSecurityTypeCount = 0x04;
92
93
94 static const SMS_WSP_CONTENTS_TYPE_S wspExtendedContentsType[] = {
95         { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
96         { (char*)"application/vnd.wap.connectivity-wbxml", 0x36 },
97         { (char*)"application/pkcs7-mime",  0x37 },
98         { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
99         { (char*)"application/vnd.wap.signed-certificate", 0x39  },
100         { (char*)"application/vnd.wap.cert-response", 0x3A },
101         { (char*)"application/xhtml+xml", 0x3B },
102         { (char*)"application/wml+xml", 0x3C  },
103         { (char*)"text/css", 0x3D },
104
105         { (char*)"application/vnd.wap.mms-message", 0x3E },
106
107         { (char*)"application/vnd.wap.rollover-certificate", 0x3F  },
108         { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
109         { (char*)"application/vnd.wap.loc+xml", 0x41 },
110         { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
111         { (char*)"application/vnd.syncml.dm+xml", 0x43 },
112         { (char*)"application/vnd.syncml.notification", 0x44 },
113         { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
114         { (char*)"application/vnd.wv.csp.cir", 0x46 },
115
116         { (char*)"application/vnd.oma.dd+xml", 0x47},
117         { (char*)"application/vnd.oma.drm.message", 0x48 },
118         { (char*)"application/vnd.oma.drm.content", 0x49 },
119         { (char*)"application/vnd.oma.drm.rights+xml", 0x4A },
120         { (char*)"application/vnd.oma.drm.rights+wbxml", 0x4B },
121         { (char*)"application/vnd.syncml.ds.notification", 0x4E},
122         { (char*)"application/mikey", 0x52},
123         { (char*)"", 0xff }
124 };
125
126
127 const char* wspHeaderFieldName[] = {
128         (char*)"Accept",  /* 0x00 */
129         (char*)"Accept-Charset",
130         (char*)"Accept-Encoding",
131         (char*)"Accept-Language",
132         (char*)"Accept-Ranges",
133         (char*)"Age", /* 0x05 */
134         (char*)"Allow",
135         (char*)"Authorization",
136         (char*)"Cache-Control",
137         (char*)"Connection",
138         (char*)"Content-Base", /* 0x0a */
139         (char*)"Content-Encoding",
140         (char*)"Content-Language",
141         (char*)"Content-Length",
142         (char*)"Content-Location",
143         (char*)"Content-MD5",
144         (char*)"Content-Range", /* 0x10 */
145         (char*)"Content-Type",
146         (char*)"Date",
147         (char*)"ETag",
148         (char*)"Expires",
149         (char*)"From", /* 0x15 */
150         (char*)"Host",
151         (char*)"If-Modified-Since",
152         (char*)"If-Match",
153         (char*)"If-None-Match",
154         (char*)"If-Range", /* 0x1a */
155         (char*)"If-Unmodified-Since",
156         (char*)"Location",
157         (char*)"Last-Modified",
158         (char*)"Max-Forwards",
159         (char*)"Pragma",
160         (char*)"Proxy-Authenticate", /* 0x20 */
161         (char*)"Proxy-Authorization",
162         (char*)"Public",
163         (char*)"Range",
164         (char*)"Referer",
165         (char*)"Retry-After", /* 0x25 */
166         (char*)"Server",
167         (char*)"Transfer-Encodig",
168         (char*)"Upgrade",
169         (char*)"User-Agent",
170         (char*)"Vary", /* 0x2a */
171         (char*)"Via",
172         (char*)"Warning",
173         (char*)"Www-Authenticate",
174         (char*)"Content-Disposition",
175         (char*)"X-Wap-Application-Id",
176         (char*)"X-Wap-Content-URI", /* 0x30 */
177         (char*)"X-Wap-Iinitiator-URI",
178         (char*)"Accept-Application", /* Back */
179         (char*)"Bearer-Indication",
180         (char*)"Push-Flag",
181         (char*)"Profile", /* 0x35 */
182         (char*)"Profile-Diff",
183         (char*)"Profile-Warning", /* end of WAP 1.2 */
184         (char*)"Expect",
185         (char*)"Te",
186         (char*)"Trailer", /* 0x3a */
187         (char*)"Accept-Charset", /* Back */
188         (char*)"Accept-Encoding", /* Back */
189         (char*)"Cache-Control", /* back */
190         (char*)"Content-Range",
191         (char*)"X-Wap-Tod",
192         (char*)"Content-ID", /* 0x40 */
193         (char*)"Set-Cookie",
194         (char*)"Cookie",
195         (char*)"Encoding-Version"
196 };
197
198
199 const SMS_WSP_CHARSET_S wspCharset[] = {
200         { (char*)"big5", 0x07ea },
201         { (char*)"iso-10646-ucs-2", 0x03e8 },
202         { (char*)"iso-8859-1", 0x04 },
203         { (char*)"iso-8859-2", 0x05 },
204         { (char*)"iso-8859-3", 0x06 },
205         { (char*)"iso-8859-4", 0x07 },
206         { (char*)"iso-8859-5", 0x08 },
207         { (char*)"iso-8859-6", 0x09 },
208         { (char*)"iso-8859-7", 0x0a },
209         { (char*)"iso-8859-8", 0x0b },
210         { (char*)"iso-8859-9", 0x0c },
211         { (char*)"shift-JIS", 0x11 },
212         { (char*)"us-ascii", 0x03 },
213         { (char*)"utf-8", 0x6a },
214         { (char*)"none", 0x26 },
215         { (char*)"", 0xffff }
216 };
217
218
219
220 const char* wspEncodeMethod[] = {
221         (char*)"Gzip",
222         (char*)"Compress",
223         (char*)"Deflate"
224 };
225
226
227 const SMS_WSP_CONTENTS_TYPE_S wspContentsType[] = {
228         { (char*)"*/*", 0x00 },
229         { (char*)"text/*", 0x01 },
230         { (char*)"text/html", 0x02 },
231         { (char*)"text/plain", 0x03 },
232         { (char*)"text/x-hdml", 0x04 },
233         { (char*)"text/x-ttml", 0x05 },
234         { (char*)"text/x-vCalendar", 0x06 },
235         { (char*)"text/x-vCard", 0x07 },
236         { (char*)"text/vnd.wap.wml", 0x08 },
237         { (char*)"text/vnd.wap.wmlscript", 0x09 },
238         { (char*)"text/vnd.wap.wta-event", 0x0a },
239         { (char*)"multipart/*", 0x0b },
240         { (char*)"multipart/mixed", 0x0c },
241         { (char*)"multipart/form-data", 0x0d },
242         { (char*)"multipart/byteranges", 0x0e },
243         { (char*)"multipart/alternative", 0x0f },
244         { (char*)"application/*", 0x10 },
245         { (char*)"application/java-vm", 0x11 },
246         { (char*)"application/x-www-form-urlencoded", 0x12 },
247         { (char*)"application/x-hdmlc", 0x13 },
248         { (char*)"application/vnd.wap.wmlc", 0x14 },
249         { (char*)"application/vnd.wap.wmlscriptc", 0x15 },
250         { (char*)"application/vnd.wap.wta-eventc", 0x16 },
251         { (char*)"application/vnd.wap.uaprof", 0x17 },
252         { (char*)"application/vnd.wap.wtls-ca-certificate", 0x18 },
253         { (char*)"application/vnd.wap.wtls-user-certificate", 0x19 },
254         { (char*)"application/x-x509-ca-cert", 0x1a },
255         { (char*)"application/x-x509-user-cert", 0x1b },
256         { (char*)"image/*", 0x1c },
257         { (char*)"image/gif", 0x1d },
258         { (char*)"image/jpeg", 0x1e },
259         { (char*)"image/tiff", 0x1f },
260         { (char*)"image/png", 0x20 },
261         { (char*)"image/vnd.wap.wbmp", 0x21 },
262         { (char*)"application/vnd.wap.multipart.*", 0x22 },
263         { (char*)"application/vnd.wap.multipart.mixed", 0x23 },
264         { (char*)"application/vnd.wap.multipart.form-data", 0x24 },
265         { (char*)"application/vnd.wap.multipart.byteranges", 0x25 },
266         { (char*)"application/vnd.wap.multipart.alternative", 0x26 },
267         { (char*)"application/xml", 0x27 },
268         { (char*)"text/xml", 0x28 },
269         { (char*)"application/vnd.wap.wbxml", 0x29 },
270         { (char*)"application/x-x968-cross-cert", 0x2a },
271         { (char*)"application/x-x968-ca-cert", 0x2b },
272         { (char*)"application/x-x968-user-cert", 0x2c },
273         { (char*)"text/vnd.wap.si", 0x2d },
274         { (char*)"application/vnd.wap.sic", 0x2e },
275         { (char*)"text/vnd.wap.sl", 0x2f },
276         { (char*)"application/vnd.wap.slc", 0x30 },
277         { (char*)"text/vnd.wap.co", 0x31 },
278         { (char*)"application/vnd.wap.coc", 0x32 },
279         { (char*)"application/vnd.wap.multipart.related", 0x33 },
280         { (char*)"application/vnd.wap.sia", 0x34 },
281
282         { (char*)"text/vnd/wap/connectivity-xml", 0x35 },
283         { (char*)"application/vnd.connectivity-wbxml", 0x36 },
284         { (char*)"application/pkcs7-mime",  0x37 },
285         { (char*)"application/vnd.wap.hashed-certificate", 0x38 },
286         { (char*)"application/vnd.wap.signed-certificate", 0x39  },
287         { (char*)"application/vnd.wap.cert-response", 0x3A },
288         { (char*)"application/xhtml+xml", 0x3B },
289         { (char*)"application/wml+xml", 0x3C  },
290         { (char*)"text/css", 0x3D },
291
292         { (char*)"application/vnd.wap.mms-message", 0x3E },
293
294         { (char*)"application/vnd.wap.rollover-certificate", 0x3F  },
295         { (char*)"application/vnd.wap.locc+wbxml", 0x40 },
296         { (char*)"application/vnd.wap.loc+xml", 0x41 },
297         { (char*)"application/vnd.syncml.dm+wbxml", 0x42 },
298         { (char*)"application/vnd.syncml.dm+xml", 0x43 },
299         { (char*)"application/vnd.syncml.notification", 0x44 },
300         { (char*)"application/vnd.wap.xhtml+xml", 0x45 },
301         { (char*)"application/vnd.wv.csp.cir", 0x46 }
302 };
303
304 static const SMS_WAP_UNREGISTER_CONTENTS_TYPE_S wspUnregisterContentsType[]= {
305         { (char*)"application/vnd.wap.emn+wbxml", 0x30A},
306         { (char*)"application/vnd.omaloc-supl-init", 0x312},
307         { (char*)"application/vnd.oma.drm.roap-trigger+wbxml", 0x316}
308 };
309
310 const unsigned long wspUnregisteredContentsTypeCount = sizeof(wspUnregisterContentsType)/sizeof(SMS_WAP_UNREGISTER_CONTENTS_TYPE_S);
311
312 const SMS_WSP_LANGUAGE_S wspLanguage[] = {
313         { (char*)"English", 0x19 },
314         { (char*)"en", 0x19 },
315         { (char*)"Korean", 0x3d },
316         { (char*)"*", 0x00 },
317         { (char*)"Afar", 0x01 },
318         { (char*)"aa", 0x01 },
319         { (char*)"Abkhazian", 0x02 },
320         { (char*)"ab", 0x02 },
321         { (char*)"Afrikaans", 0x03 },
322         { (char*)"af", 0x03 },
323         { (char*)"Amharic", 0x04 },
324         { (char*)"am", 0x04 },
325         { (char*)"Arabic", 0x05 },
326         { (char*)"ar", 0x05 },
327         { (char*)"Assamese", 0x06 },
328         { (char*)"as", 0x06 },
329         { (char*)"Aymara", 0x07 },
330         { (char*)"ay", 0x07 },
331         { (char*)"Azerbaijani", 0x08 },
332         { (char*)"az", 0x08 },
333         { (char*)"Bashkir", 0x09 },
334         { (char*)"ba", 0x09 },
335         { (char*)"Byelorussian", 0x0a },
336         { (char*)"be", 0x0a },
337         { (char*)"Bulgarian", 0x0b },
338         { (char*)"bg", 0x0b },
339         { (char*)"Bihari", 0x0c },
340         { (char*)"bh", 0x0c },
341         { (char*)"Bislama", 0x0d },
342         { (char*)"bi", 0x0f },
343         { (char*)"Bengali", 0x0e },
344         { (char*)"Bangla", 0x0e },
345         { (char*)"bn", 0x0e },
346         { (char*)"Tibetan", 0x0f },
347         { (char*)"bo", 0x0f },
348         { (char*)"Breton", 0x10 },
349         { (char*)"br", 0x10 },
350         { (char*)"Catalan", 0x11 },
351         { (char*)"ca", 0x11 },
352         { (char*)"Corsican", 0x12 },
353         { (char*)"co", 0x12 },
354         { (char*)"Czech", 0x13 },
355         { (char*)"cs", 0x13 },
356         { (char*)"Welsh", 0x14 },
357         { (char*)"cy", 0x14 },
358         { (char*)"Denish", 0x15 },
359         { (char*)"da", 0x15 },
360         { (char*)"German", 0x16 },
361         { (char*)"de", 0x16 },
362         { (char*)"Bhutani", 0x17 },
363         { (char*)"dz", 0x17 },
364         { (char*)"Greek", 0x18 },
365         { (char*)"el", 0x18 },
366         { (char*)"Esperanto", 0x81 },
367         { (char*)"eo", 0x1a },
368         { (char*)"Spanish", 0x1b },
369         { (char*)"es", 0x1b },
370         { (char*)"Estonian", 0x1c },
371         { (char*)"et", 0x1c },
372         { (char*)"Basque", 0x1d },
373         { (char*)"eu", 0x1d },
374         { (char*)"Persian", 0x1e },
375         { (char*)"fa", 0x1e },
376         { (char*)"Finnish", 0x1f },
377         { (char*)"fi", 0x1f },
378         { (char*)"Fiji", 0x20 },
379         { (char*)"fj", 0x20 },
380         { (char*)"Faeroese", 0x82 },
381         { (char*)"fo", 0x82 },
382         { (char*)"French", 0x22 },
383         { (char*)"fr", 0x22 },
384         { (char*)"Frisian", 0x83 },
385         { (char*)"fy", 0x83 },
386         { (char*)"Irish", 0x24 },
387         { (char*)"ga", 0x24 },
388         { (char*)"Scots Gaelic", 0x25 },
389         { (char*)"gd", 0x25 },
390         { (char*)"Galician", 0x26 },
391         { (char*)"gl", 0x26 },
392         { (char*)"Guarani", 0x27 },
393         { (char*)"gn", 0x27 },
394         { (char*)"Gujarati", 0x28 },
395         { (char*)"gu", 0x28 },
396         { (char*)"Hausa", 0x29 },
397         { (char*)"ha", 0x29 },
398         { (char*)"Hebrew", 0x2a },
399         { (char*)"he", 0x2a },
400         { (char*)"Hindi", 0x2b },
401         { (char*)"hi", 0x2b },
402         { (char*)"Croatian", 0x2c },
403         { (char*)"hr", 0x2c },
404         { (char*)"Hungarian", 0x2d },
405         { (char*)"hu", 0x2d },
406         { (char*)"Armenian", 0x2e },
407         { (char*)"hy", 0x2e },
408         { (char*)"Interlingua", 0x84 },
409         { (char*)"ia", 0x84 },
410         { (char*)"Indonesian", 0x30 },
411         { (char*)"id", 0x30 },
412         { (char*)"Interlingue", 0x86 },
413         { (char*)"ie", 0x86 },
414         { (char*)"Maori", 0x47 },
415         { (char*)"mi", 0x47 },
416         { (char*)"Macedonian", 0x48 },
417         { (char*)"mk", 0x48 },
418         { (char*)"Malayalam", 0x49 },
419         { (char*)"ml", 0x49 },
420         { (char*)"Mongolian", 0x4a },
421         { (char*)"mn", 0x4a },
422         { (char*)"Moldavian", 0x4b },
423         { (char*)"mo", 0x4d },
424         { (char*)"Marathi", 0x4c },
425         { (char*)"mr", 0x4c },
426         { (char*)"Malay", 0x4d },
427         { (char*)"ms", 0x4d },
428         { (char*)"Maltese", 0x4e },
429         { (char*)"mt", 0x4e },
430         { (char*)"Burmese", 0x4f },
431         { (char*)"my", 0x4f },
432         { (char*)"Nauru", 0x50 },
433         { (char*)"na", 0x50 },
434         { (char*)"Nepali", 0x51 },
435         { (char*)"ne", 0x51 },
436         { (char*)"Dutch", 0x52 },
437         { (char*)"nl", 0x52 },
438         { (char*)"Norwegian", 0x53 },
439         { (char*)"no", 0x53 },
440         { (char*)"Occitan", 0x54 },
441         { (char*)"oc", 0x54 },
442         { (char*)"(Afan) Oromo", 0x55 },
443         { (char*)"(Afan)Oromo", 0x55 },
444         { (char*)"om", 0x55 },
445         { (char*)"Oriya", 0x56 },
446         { (char*)"or", 0x56 },
447         { (char*)"Punjabi", 0x57 },
448         { (char*)"pa", 0x57 },
449         { (char*)"Polish", 0x58 },
450         { (char*)"po", 0x58 },
451         { (char*)"Pashto", 0x59 },
452         { (char*)"Pushto", 0x59 },
453         { (char*)"ps", 0x59 },
454         { (char*)"Portugurse", 0x5a },
455         { (char*)"pt", 0x5a },
456         { (char*)"Quechua", 0x5b },
457         { (char*)"qu", 0x5b },
458         { (char*)"Rhaeto-Romance", 0x8c },
459         { (char*)"rm", 0x8c },
460         { (char*)"Kirundi", 0x5d },
461         { (char*)"rn", 0x5d },
462         { (char*)"Romanian", 0x5e },
463         { (char*)"ro", 0x5e },
464         { (char*)"Russian", 0x5f },
465         { (char*)"ru", 0x5f },
466         { (char*)"Kinyarwanda", 0x60 },
467         { (char*)"rw", 0x60 },
468         { (char*)"Sanskrit", 0x61 },
469         { (char*)"sa", 0x61 },
470         { (char*)"Sindhi", 0x62 },
471         { (char*)"sd", 0x62 },
472         { (char*)"Sangho", 0x63 },
473         { (char*)"sg", 0x63 },
474         { (char*)"Serbo-Croatian", 0x64 },
475         { (char*)"sh", 0x64 },
476         { (char*)"Sinhalese", 0x65 },
477         { (char*)"si", 0x65 },
478         { (char*)"Slovak", 0x66 },
479         { (char*)"sk", 0x66 },
480         { (char*)"Slovenian", 0x67 },
481         { (char*)"sl", 0x67 },
482         { (char*)"Samoan", 0x68 },
483         { (char*)"sm", 0x68 },
484         { (char*)"Shona", 0x69 },
485         { (char*)"sn", 0x69 },
486         { (char*)"Somali", 0x6a },
487         { (char*)"so", 0x6a },
488         { (char*)"Albanian", 0x6b },
489         { (char*)"sq", 0x6b },
490         { (char*)"Serbian", 0x6c },
491         { (char*)"sr", 0x6c },
492         { (char*)"Siswati", 0x6d },
493         { (char*)"ss", 0x6d },
494         { (char*)"Sesotho", 0x6e },
495         { (char*)"st", 0x6e },
496         { (char*)"Sundanese", 0x6f },
497         { (char*)"su", 0x6f },
498         { (char*)"Swedish", 0x70 },
499         { (char*)"sv", 0x70 },
500         { (char*)"Swahili", 0x71 },
501         { (char*)"sw", 0x71 },
502         { (char*)"Tamil", 0x72 },
503         { (char*)"ta", 0x72 },
504         { (char*)"Telugu", 0x73 },
505         { (char*)"te", 0x73 },
506         { (char*)"Tajik", 0x74 },
507         { (char*)"tg", 0x74 },
508         { (char*)"Thai", 0x75 },
509         { (char*)"th", 0x75 },
510         { (char*)"Tigrinya", 0x76 },
511         { (char*)"ti", 0x76 },
512         { (char*)"Turkmen", 0x77 },
513         { (char*)"tk", 0x77 },
514         { (char*)"Inupiak", 0x87 },
515         { (char*)"ik", 0x87 },
516         { (char*)"Icelandic", 0x33 },
517         { (char*)"is", 0x33 },
518         { (char*)"Italian", 0x34 },
519         { (char*)"it", 0x34 },
520         { (char*)"Inuktitut", 0x89 },
521         { (char*)"iu", 0x89 },
522         { (char*)"Japanese", 0x36 },
523         { (char*)"ja", 0x36 },
524         { (char*)"Javanese", 0x37 },
525         { (char*)"jw", 0x37 },
526         { (char*)"Georgian", 0x38 },
527         { (char*)"ka", 0x38 },
528         { (char*)"Kazakh", 0x39 },
529         { (char*)"kk", 0x39 },
530         { (char*)"Gerrnlandic", 0x8a },
531         { (char*)"kl", 0x8a },
532         { (char*)"Cambodian", 0x3b },
533         { (char*)"km", 0x3b },
534         { (char*)"Kannada", 0x3c },
535         { (char*)"kn", 0x3c },
536         { (char*)"Kashmiri", 0x3e },
537         { (char*)"ks", 0x3e },
538         { (char*)"Kurdish", 0x3f },
539         { (char*)"ku", 0x3f },
540         { (char*)"Kirghiz", 0x40 },
541         { (char*)"ky", 0x40 },
542         { (char*)"Latin", 0x8b },
543         { (char*)"la", 0x8b },
544         { (char*)"Lingala", 0x42 },
545         { (char*)"ln", 0x42 },
546         { (char*)"Laothian", 0x43 },
547         { (char*)"lo", 0x43 },
548         { (char*)"Lithuanian", 0x44 },
549         { (char*)"lt", 0x44 },
550         { (char*)"Lavian", 0x45 },
551         { (char*)"Lettish", 0x45 },
552         { (char*)"lv", 0x45 },
553         { (char*)"Malagasy", 0x46 },
554         { (char*)"mg", 0x46 },
555         { (char*)"Tagalog", 0x78 },
556         { (char*)"tl", 0x78 },
557         { (char*)"Setswana", 0x79 },
558         { (char*)"tn", 0x79 },
559         { (char*)"Tonga", 0x7a },
560         { (char*)"to", 0x7a },
561         { (char*)"Turkish", 0x7b },
562         { (char*)"tr", 0x7b },
563         { (char*)"Tsonga", 0x7c },
564         { (char*)"ts", 0x7c },
565         { (char*)"Tatar", 0x7d },
566         { (char*)"tt", 0x7d },
567         { (char*)"Twi", 0x7e },
568         { (char*)"tw", 0x7e },
569         { (char*)"Uighur", 0x7f },
570         { (char*)"ug", 0x7f },
571         { (char*)"Ukrainian", 0x1a },
572         { (char*)"uk", 0x1a },
573         { (char*)"Urdu", 0x21 },
574         { (char*)"ur", 0x21 },
575         { (char*)"Uzbek", 0x23 },
576         { (char*)"uz", 0x23 },
577         { (char*)"Vietnamese", 0x2f },
578         { (char*)"vi", 0x2f },
579         { (char*)"Volapuk", 0x85 },
580         { (char*)"vo", 0x85 },
581         { (char*)"Wolof", 0x31 },
582         { (char*)"wo" , 0x31 },
583         { (char*)"Xhosa", 0x32 },
584         { (char*)"xh", 0x32 },
585         { (char*)"Yiddish", 0x88 },
586         { (char*)"yi", 0x88 },
587         { (char*)"Yoruba", 0x35 },
588         { (char*)"yo", 0x35 },
589         { (char*)"Zhuang", 0x3a },
590         { (char*)"z", 0x3a },
591         { (char*)"Chinese", 0x41 },
592         { (char*)"ch", 0x41 },
593         { (char*)"Zulu", 0x5c },
594         { (char*)"zu", 0x5c },
595         { (char*)"Ko", 0x3d }
596 };
597
598
599 const SMS_WSP_HEADER_PARAMETER_S wspHeaderApplId[] = {
600         { (char*)"x-wap-application:*",  0x00 },
601         { (char*)"x-wap-application:push.sia",  0x01},
602         { (char*)"x-wap-application:wml.ua",  0x02 },
603         { (char*)"x-wap-application:wta.ua", 0x03 },
604         { (char*)"x-wap-application:mms.ua", 0x04 },
605         { (char*)"x-wap-application:push.syncml", 0x05 },
606         { (char*)"x-wap-application:loc.ua",  0x06 },
607         { (char*)"x-wap-application:syncml.dm", 0x07 },
608         { (char*)"x-wap-application:drm.ua", 0x08 },
609         { (char*)"x-wap-application:emn.ua", 0x09 },
610         { (char*)"x-oma-application:ulp.ua ", 0x10 },
611         { (char*)"x-oma-docomo:open.ctl", 0x9055 },
612         { (char*)"x-oma-docomo:xmd.mail.ua", 0x905C },
613         { (char*)"x-oma-docomo:xmd.storage.ua", 0x905F },
614         { (char*)"x-oma-docomo:xmd.lcsapp.ua", 0x9060 },
615         { (char*)"x-oma-docomo:xmd.info.ua", 0x9061 },
616         { (char*)"x-oma-docomo:xmd.agent.ua", 0x9062 },
617         { (char*)"x-oma-docomo:xmd.sab.ua", 0x9063 },
618         { (char*)"x-oma-docomo:xmd.am.ua", 0x9064 },
619         { (char*)"x-oma-docomo:xmd.emdm.ua", 0x906B },
620         { (char*)"x-oma-docomo:xmd.lac.ua", 0x906C },
621         { (char*)"x-oma-docomo:xmd.osv.ua", 0x906D },
622         { (char*)"x-oma-docomo:xmd.dcs.ua", 0x906E },
623         { (char*)"x-oma-docomo:xmd.wipe.ua", 0x906F },
624         { (char*)"x-oma-docomo:xmd.vdapp.ua ", 0x9070 },
625 };
626
627
628 const char* wspCacheControl[] = {
629         (char*)"No-cache",
630         (char*)"No-store",
631         (char*)"Max-age",
632         (char*)"Max-stale",
633         (char*)"Min-fresh",
634         (char*)"Only-if-cached",
635         (char*)"Public",
636         (char*)"Private",
637         (char*)"No-transform",
638         (char*)"Must-revalidate",
639         (char*)"Proxy-revalidate"
640 };
641
642 const SMS_WSP_METHOD_TYPE_S wspMethodType[] = {
643         { (char*)"GET", 0x40 },
644         { (char*)"OPTIONS", 0x41 },
645         { (char*)"HEAD", 0x42 },
646         { (char*)"DELETE", 0x43 },
647         { (char*)"TRACE", 0x44 },
648         { (char*)"POST", 0x60 },
649         { (char*)"PUT", 0x61 }
650 };
651
652
653 const SMS_WSP_SECURITY_TYPE_S wspSecurityType[] = {
654         {(char*)"NETWPIN", 0x00},
655         {(char*)"USERPIN", 0x01},
656         {(char*)"USERNETWPIN", 0x02},
657         {(char*)"USERPINMAC", 0x03}
658 };
659
660
661
662 const char* wspWeek[] = {
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         (char*)"Sunday",
675         (char*)"Monday",
676         (char*)"Tuesday",
677         (char*)"Wednesday",
678         (char*)"Thursday",
679         (char*)"Friday",
680         (char*)"Saturday"
681 };
682
683 const char* wspMonth[] = {
684         (char*)"Jan",
685         (char*)"Feb",
686         (char*)"Mar",
687         (char*)"Apr",
688         (char*)"May",
689         (char*)"Jun",
690         (char*)"Jul",
691         (char*)"Aug",
692         (char*)"Sep",
693         (char*)"Oct",
694         (char*)"Nov",
695         (char*)"Dec"
696 };
697
698
699
700 /*==================================================================================================
701                                      IMPLEMENTATION OF SmsPluginWapPushHandler - Member Functions
702 ==================================================================================================*/
703 SmsPluginWapPushHandler* SmsPluginWapPushHandler::pInstance = NULL;
704
705
706 SmsPluginWapPushHandler::SmsPluginWapPushHandler()
707 {
708         memset(&tmpAddress, 0x00, sizeof(tmpAddress));
709         memset(&tmpTimeStamp, 0x00, sizeof(tmpTimeStamp));
710 }
711
712
713 SmsPluginWapPushHandler::~SmsPluginWapPushHandler()
714 {
715 }
716
717
718 SmsPluginWapPushHandler* SmsPluginWapPushHandler::instance()
719 {
720         if (!pInstance)
721                 pInstance = new SmsPluginWapPushHandler();
722
723         return pInstance;
724 }
725
726
727 bool SmsPluginWapPushHandler::IsWapPushMsg(SMS_USERDATA_S *pUserData)
728 {
729         MSG_BEGIN();
730
731         if (pUserData == NULL) {
732                 MSG_DEBUG("pUserData is NULL");
733                 return false;
734         }
735
736         int PortCount = sizeof(wapPushPortList) / sizeof(wapPushPortList[0]);
737
738         MSG_DEBUG("Port Count [%d]", PortCount);
739
740         for (int i = 0; i < pUserData->headerCnt; i++) {
741                 if (pUserData->header[i].udhType == SMS_UDH_APP_PORT_8BIT) {
742                         /** Have to check something??? */
743                 } else if (pUserData->header[i].udhType == SMS_UDH_APP_PORT_16BIT) {
744                         for (int j = 0; j < PortCount; j++) {
745                                 if (pUserData->header[i].udh.appPort16bit.destPort == wapPushPortList[j]) {
746                                         MSG_DEBUG("Wap Push Msg : [%04x]", wapPushPortList[j]);
747                                         return true;
748                                 }
749                         }
750                 }
751         }
752
753         MSG_END();
754
755         return false;
756 }
757
758 #if 0
759 SMS_WAP_APP_CODE_T SmsPluginWapPushHandler::getAppCode(const char *pPushHeader)
760 {
761         int appCount = sizeof(pushDefaultApplication)/sizeof(pushDefaultApplication[0]) - 1;
762
763         unsigned char *header = NULL;
764         SMS_WAP_APP_CODE_T      appCode = SMS_WAP_APPLICATION_DEFAULT;
765
766         MSG_DEBUG("Application Count [%d]", appCount);
767
768         for (int i = 0; i < appCount; i++) {
769                 header = (unsigned char*)strcasestr(pPushHeader, pushDefaultApplication[i].pContentType);
770
771                 if (header != NULL) {
772                         appCode = pushDefaultApplication[i].appCode;
773                         break;
774                 }
775         }
776
777         if (appCode == SMS_WAP_APPLICATION_DEFAULT) {
778                 MSG_DEBUG("Application Type is not supported");
779         } else {
780                 MSG_DEBUG("Find Application [%d]", appCode);
781         }
782
783         return appCode;
784 }
785 #endif
786
787
788 void SmsPluginWapPushHandler::copyDeliverData(SMS_DELIVER_S *pDeliver)
789 {
790         tmpAddress.ton = pDeliver->originAddress.ton;
791         tmpAddress.npi = pDeliver->originAddress.npi;
792
793         strncpy(tmpAddress.address, pDeliver->originAddress.address, MAX_ADDRESS_LEN);
794
795         MSG_SEC_DEBUG("Address [%s]", tmpAddress.address);
796
797         tmpTimeStamp.format = pDeliver->timeStamp.format;
798
799         if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
800                 tmpTimeStamp.time.absolute.year = pDeliver->timeStamp.time.absolute.year;
801                 tmpTimeStamp.time.absolute.month = pDeliver->timeStamp.time.absolute.month;
802                 tmpTimeStamp.time.absolute.day = pDeliver->timeStamp.time.absolute.day;
803                 tmpTimeStamp.time.absolute.hour = pDeliver->timeStamp.time.absolute.hour;
804                 tmpTimeStamp.time.absolute.minute = pDeliver->timeStamp.time.absolute.minute;
805                 tmpTimeStamp.time.absolute.second = pDeliver->timeStamp.time.absolute.second;
806                 tmpTimeStamp.time.absolute.timeZone = pDeliver->timeStamp.time.absolute.timeZone;
807         }
808 }
809
810
811 void SmsPluginWapPushHandler::handleWapPushMsg(const char *pUserData, int DataSize, int simIndex, time_t sent_time)
812 {
813         MSG_BEGIN();
814
815 #ifdef MSG_FW_FOR_DEBUG
816         MSG_DEBUG("DataSize [%d]", DataSize);
817
818         MSG_DEBUG("[pUserData]");
819         for (int i = 0; i < DataSize; i++) {
820                 printf("[%02x]", pUserData[i]);
821         }
822         printf("\n\n");
823 #endif
824
825         unsigned char* pPDUTypeData = (unsigned char*)pUserData;
826         unsigned long PDUTypeDataLen = DataSize;
827
828         char* pPushHeader = NULL;
829         unique_ptr<char*, void(*)(char**)> pushHeaderBuf(&pPushHeader, unique_ptr_deleter);
830         unsigned long pushHeaderLen = 0;
831
832         char* pPushBody = NULL;
833         unique_ptr<char*, void(*)(char**)> PushBodyBuf(&pPushBody, unique_ptr_deleter);
834         unsigned long pushBodyLen = 0;
835
836         unsigned long iPDU = 1;
837
838         char* pWspHeader = NULL;
839         unique_ptr<char*, void(*)(char**)> WspHeaderBuf(&pWspHeader, unique_ptr_deleter);
840         unsigned long   wspHeaderLen = 0;
841
842         char* pWspBody = NULL;
843         unique_ptr<char*, void(*)(char**)> WspBodyBuf(&pWspBody, unique_ptr_deleter);
844         unsigned long wspBodyLen = 0;
845
846         /** pass PDU type */
847         iPDU++;
848
849         pushHeaderLen = wspRetriveUintvarDecode(pPDUTypeData, &iPDU);
850
851         MSG_DEBUG("PDUTypeDataLen [%d]", PDUTypeDataLen);
852         MSG_DEBUG("pushHeaderLen [%d]", pushHeaderLen);
853         MSG_DEBUG("iPDU [%d]", iPDU);
854
855         wspHeaderLen = pushHeaderLen + iPDU;
856
857         MSG_DEBUG("wspBodyLen [%d]", wspBodyLen);
858
859         if (wspHeaderLen > 0) {
860                 pWspHeader = new char[wspHeaderLen];
861
862                 if (pWspHeader == NULL) {
863                         MSG_DEBUG("pWspHeader Memory Allocation Failed");
864                         return;
865                 } else {
866                         memcpy(pWspHeader, pPDUTypeData, wspHeaderLen);
867                 }
868         }
869
870 #ifdef MSG_FW_FOR_DEBUG
871         MSG_DEBUG("wspHeaderLen [%d]", wspHeaderLen);
872
873         MSG_DEBUG("[pWspHeader]");
874         for (int i = 0; i < wspHeaderLen; i++) {
875                 printf("[%02x]", pWspHeader[i]);
876         }
877         printf("\n\n");
878 #endif
879
880         /** return if it is below case error */
881         if (PDUTypeDataLen < wspHeaderLen) {
882                 MSG_DEBUG("PDUTypeDataLen < wspHeaderLen !!!");
883                 return;
884         }
885
886         /** Finding wspBody Information */
887         wspBodyLen = PDUTypeDataLen - wspHeaderLen;
888
889         if (wspBodyLen > 0) {
890                 pWspBody = new char[wspBodyLen];
891
892                 if (pWspBody == NULL) {
893                         MSG_DEBUG("pWspBody Memory Allocation Failed");
894                         return;
895                 } else {
896                         memcpy(pWspBody, pPDUTypeData + wspHeaderLen, wspBodyLen);
897                 }
898         } else {
899                 pWspBody = NULL;
900         }
901
902         wspDecodeHeader(pPDUTypeData + iPDU, pushHeaderLen, PDUTypeDataLen - (iPDU + pushHeaderLen), TRUE, &pPushHeader);
903
904         iPDU = iPDU + pushHeaderLen;
905
906         pushBodyLen = PDUTypeDataLen - iPDU ;
907
908         if (pushBodyLen > 0) {
909                 pPushBody = new char[pushBodyLen];
910
911                 if (pPushBody == NULL) {
912                         MSG_DEBUG("pPushBody Memory Allocation Failed");
913                         return;
914                 } else {
915                         memcpy(pPushBody, pPDUTypeData+ iPDU, pushBodyLen);
916                 }
917         } else {
918                 pPushBody = NULL;
919                 return;
920         }
921
922         handleWapPushCallback((char *)pPushHeader, (char *)pPushBody, (int)pushBodyLen, (char *)pWspHeader, (int)wspHeaderLen, (char *)pWspBody, (int)wspBodyLen, simIndex, sent_time);
923
924         MSG_END();
925 }
926
927 #if 0
928 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen)
929 {
930         MSG_BEGIN();
931
932         if (pPushBody == NULL) {
933                 MSG_DEBUG("pPushBody is NULL");
934                 return;
935         }
936
937         SMS_WAP_APP_CODE_T      appCode = getAppCode(pPushHeader);
938
939         /**  check Push message receive setting */
940         bool bPushRecv = false;
941
942         if (MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv) != MSG_SUCCESS)
943                 MSG_INFO("MsgSettingGetBool() is failed");
944
945         if ((bPushRecv == false) && (appCode != SMS_WAP_APPLICATION_MMS_UA)) {
946                 MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
947                 return;
948         }
949
950         switch (appCode) {
951         case SMS_WAP_APPLICATION_MMS_UA:
952                 MSG_DEBUG("Received MMS Notification");
953                 handleMMSNotification(pPushBody, PushBodyLen);
954                 break;
955
956         case SMS_WAP_APPLICATION_PUSH_SI:
957                 MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
958                 handleSIMessage(pPushBody, PushBodyLen, true);
959                 break;
960
961         case SMS_WAP_APPLICATION_PUSH_SIC:
962                 MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
963                 handleSIMessage(pPushBody, PushBodyLen, false);
964                 break;
965
966         case SMS_WAP_APPLICATION_PUSH_SL:
967                 MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
968                 handleSLMessage(pPushBody, PushBodyLen, true);
969                 break;
970
971         case SMS_WAP_APPLICATION_PUSH_SLC:
972                 MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
973                 handleSLMessage(pPushBody, PushBodyLen, false);
974                 break;
975
976         case SMS_WAP_APPLICATION_PUSH_CO:
977                 MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
978                 handleCOMessage(pPushBody, PushBodyLen, true);
979                 break;
980
981         case SMS_WAP_APPLICATION_PUSH_COC:
982                 MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
983                 handleCOMessage(pPushBody, PushBodyLen, false);
984                 break;
985
986         case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
987                 MSG_DEBUG("Received DM BOOTSTRAP");
988                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
989                 break;
990
991         case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
992                 MSG_DEBUG("Received DM BOOTSTRAP");
993                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
994                 break;
995
996         case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
997                 MSG_DEBUG("Received Provisioning");
998                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
999                 break;
1000
1001         case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1002                 MSG_DEBUG("Received Provisioning");
1003                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1004                 break;
1005
1006         case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1007         case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1008                 MSG_DEBUG("Received Provisioning");
1009                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1010                 break;
1011
1012         case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1013                 MSG_DEBUG("Received DM Notification");
1014                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1015                 break;
1016
1017         case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1018                 MSG_DEBUG("Received DS Notification");
1019                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1020                 break;
1021
1022         case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1023                 MSG_DEBUG("Received DS Notification");
1024                 SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen);
1025                 break;
1026
1027         case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
1028         case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
1029                 MSG_DEBUG("Received DRM UA");
1030
1031                 if (pPushBody != NULL)
1032                         handleDrmVer1(pPushBody, PushBodyLen);
1033
1034                 break;
1035
1036         case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
1037         case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
1038         case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
1039         case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
1040                 MSG_DEBUG("Received DRM V2");
1041                 /* TODO: DRM V2 */
1042                 break;
1043
1044         case SMS_WAP_APPLICATION_PUSH_EMAIL:
1045         case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
1046         case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
1047                 MSG_DEBUG("Received Email");
1048                 /* TODO: Email */
1049                 break;
1050
1051         case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1052                 MSG_DEBUG("Received IMPS CIR");
1053                 /* TODO: IMPS CIR */
1054                 break;
1055
1056         case SMS_WAP_APPLICATION_LBS :
1057                 MSG_DEBUG("Received LBS related message");
1058                 SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1059                 /* TODO: LBS */
1060                 break;
1061
1062         case SMS_WAP_APPLICATION_PUSH_SIA :
1063                 MSG_DEBUG("Received SIA");
1064                 /* TODO: SIA */
1065                 break;
1066
1067         default:
1068                 MSG_DEBUG("Unknown Application [%d]", appCode);
1069                 break;
1070         }
1071
1072         MSG_END();
1073 }
1074 #else
1075
1076 static void launchProcessByAppcode(int appcode)
1077 {
1078         MSG_BEGIN();
1079         GError *error = NULL;
1080         GDBusConnection *connection_agent = NULL;
1081         GDBusProxy *dbus_proxy_agent = NULL;
1082         GDBusConnection *connection_service = NULL;
1083         GDBusProxy *dbus_proxy_service = NULL;
1084         GVariant *result_agent = NULL;
1085         GVariant *result_service = NULL;
1086
1087         switch (appcode) {
1088         case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1089         case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1090         case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1091         case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1092         case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1093         case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1094         case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION: {
1095                         connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1096                         if (error) {
1097                                 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1098                                 goto _DBUS_ERROR;
1099                         }
1100
1101                         dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_NONE,
1102                                                                                 NULL, "org.tizen.omadmagent", "/org/tizen/omadmagent",
1103                                                                                 "org.tizen.omadmagent", NULL, &error);
1104                         if (error) {
1105                                 MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
1106                                 goto _DBUS_ERROR;
1107                         }
1108
1109                         result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1110                         if (error) {
1111                                 MSG_DEBUG("invoking agent proxy call failed: %s\n", error->message);
1112                                 goto _DBUS_ERROR;
1113                         }
1114
1115                         connection_service = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1116                         if (error) {
1117                                 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1118                                 goto _DBUS_ERROR;
1119                         }
1120
1121                         dbus_proxy_service = g_dbus_proxy_new_sync(connection_service, G_DBUS_PROXY_FLAGS_NONE, NULL,
1122                                                                                 "org.tizen.omadmservice", "/org/tizen/omadmservice",
1123                                                                                 "org.tizen.omadmservice", NULL, &error);
1124                         if (error) {
1125                                 MSG_DEBUG("Connecting to service proxy failed: %s\n", error->message);
1126                                 goto _DBUS_ERROR;
1127                         }
1128
1129                         result_service = g_dbus_proxy_call_sync(dbus_proxy_service, "wakeup", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1130                         if (error) {
1131                                 MSG_DEBUG("invoking service proxy call failed: %s\n", error->message);
1132                                 goto _DBUS_ERROR;
1133                         }
1134
1135                         MsgMutex mx;
1136                         MsgCndVar cv;
1137                         mx.lock();
1138                         cv.timedwait(mx.pMsgMutex(), 2);
1139                         mx.unlock();
1140
1141                         MSG_END();
1142                 }
1143                 break;
1144         case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1145         case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML: {
1146                         connection_agent = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
1147                         if (error) {
1148                                 MSG_DEBUG("Connecting to system bus failed: %s\n", error->message);
1149                                 goto _DBUS_ERROR;
1150                         }
1151
1152                         dbus_proxy_agent = g_dbus_proxy_new_sync(connection_agent, G_DBUS_PROXY_FLAGS_NONE, NULL,
1153                                                                                 "org.tizen.omadsagent", "/org/tizen/omadsagent",
1154                                                                                 "org.tizen.omadsagent", NULL, &error);
1155                         if (error) {
1156                                 MSG_DEBUG("Connecting to agent proxy failed: %s\n", error->message);
1157                                 goto _DBUS_ERROR;
1158                         }
1159
1160                         result_agent = g_dbus_proxy_call_sync(dbus_proxy_agent, "Hello_Agent", NULL,
1161                                                                         G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1162                         if (error) {
1163                                 MSG_DEBUG("invoking service error: %s\n", error->message);
1164                                 goto _DBUS_ERROR;
1165                         }
1166                 }
1167                 break;
1168         default:
1169                 break;
1170         }
1171
1172 _DBUS_ERROR:
1173         if (error) {
1174                 g_error_free(error);
1175                 error = NULL;
1176         }
1177
1178         if (connection_agent) {
1179                 g_object_unref(connection_agent);
1180                 connection_agent = NULL;
1181         }
1182
1183         if (dbus_proxy_agent) {
1184                 g_object_unref(dbus_proxy_agent);
1185                 dbus_proxy_agent = NULL;
1186         }
1187
1188         if (result_agent) {
1189                 g_object_unref(result_service);
1190                 result_service = NULL;
1191         }
1192
1193         if (connection_service) {
1194                 g_object_unref(connection_service);
1195                 connection_service = NULL;
1196         }
1197
1198         if (dbus_proxy_service) {
1199                 g_object_unref(dbus_proxy_service);
1200                 dbus_proxy_service = NULL;
1201         }
1202
1203         if (result_service) {
1204                 g_object_unref(result_service);
1205                 result_service = NULL;
1206         }
1207
1208         MSG_END();
1209 }
1210
1211
1212 void SmsPluginWapPushHandler::handleWapPushCallback(char* pPushHeader, char* pPushBody, int PushBodyLen, char* pWspHeader, int WspHeaderLen, char* pWspBody, int WspBodyLen, int simIndex, time_t sent_time)
1213 {
1214         MSG_BEGIN();
1215
1216         if (pPushBody == NULL) {
1217                 MSG_DEBUG("pPushBody is NULL");
1218                 return;
1219         }
1220
1221         msg_error_t err = MSG_SUCCESS;
1222         int pushEvt_cnt = 0;
1223         char app_id[MAX_WAPPUSH_ID_LEN] = {0, };
1224         char content_type[MAX_WAPPUSH_CONTENT_TYPE_LEN] = {0, };
1225         SmsPluginStorage *storageHandler = SmsPluginStorage::instance();
1226
1227         err = storageHandler->getRegisteredPushEvent(pPushHeader, &pushEvt_cnt, app_id, sizeof(app_id), content_type, sizeof(content_type));
1228         MSG_DEBUG("pushEvt_cnt: %d", pushEvt_cnt);
1229         if (err != MSG_SUCCESS) {
1230                 MSG_DEBUG("Fail to get registered push event");
1231                 return;
1232         }
1233
1234         for (int i = 0; i < pushEvt_cnt; ++i) {
1235                 /* check Push message receive setting */
1236                 bool bPushRecv = false;
1237                 int appcode = 0;
1238                 if (MsgSettingGetBool(PUSH_RECV_OPTION, &bPushRecv) != MSG_SUCCESS)
1239                         MSG_INFO("MsgSettingGetBool() is failed");
1240
1241                 storageHandler->getnthPushEvent(i, &appcode);
1242                 MSG_DEBUG("pushEvt_cnt: %d, appcode: %d", pushEvt_cnt, appcode);
1243                 if ((bPushRecv == false) && (IsWapPushMsgInWhiteList(appcode) == false)) {
1244                         MSG_DEBUG("Push Message Receive option is OFF. Drop Push Message.");
1245                         return;
1246                 }
1247
1248 #ifdef FEATURE_MMS_DISABLE
1249                 if (appcode == SMS_WAP_APPLICATION_MMS_UA) {
1250                         MSG_DEBUG("Drop MMS Notification for DOCOMO");
1251                         return;
1252                 }
1253
1254 #endif
1255                 launchProcessByAppcode(appcode);
1256
1257                 switch (appcode) {
1258                 case SMS_WAP_APPLICATION_MMS_UA:
1259                         MSG_DEBUG("Received MMS Notification");
1260                         handleMMSNotification(pPushBody, PushBodyLen, simIndex, sent_time);
1261                         break;
1262
1263                 case SMS_WAP_APPLICATION_PUSH_SI:
1264                         MSG_DEBUG("Received WAP Push (Service Indication Textual form)");
1265                         handleSIMessage(pPushBody, PushBodyLen, true, simIndex);
1266                         break;
1267
1268                 case SMS_WAP_APPLICATION_PUSH_SIC:
1269                         MSG_DEBUG("Received WAP Push (Service Indication Tokenised form)");
1270                         handleSIMessage(pPushBody, PushBodyLen, false, simIndex);
1271                         break;
1272
1273                 case SMS_WAP_APPLICATION_PUSH_SL:
1274                         MSG_DEBUG("Received WAP Push (Service Loading Textual form)");
1275                         handleSLMessage(pPushBody, PushBodyLen, true, simIndex);
1276                         break;
1277
1278                 case SMS_WAP_APPLICATION_PUSH_SLC:
1279                         MSG_DEBUG("Received WAP Push (Service Loading Tokenised form)");
1280                         handleSLMessage(pPushBody, PushBodyLen, false, simIndex);
1281                         break;
1282
1283                 case SMS_WAP_APPLICATION_PUSH_CO:
1284                         MSG_DEBUG("Received WAP Push (Cache Operation Textual form)");
1285                         handleCOMessage(pPushBody, PushBodyLen, true, simIndex);
1286                         break;
1287
1288                 case SMS_WAP_APPLICATION_PUSH_COC:
1289                         MSG_DEBUG("Received WAP Push (Cache Operation Tokenised form)");
1290                         handleCOMessage(pPushBody, PushBodyLen, false, simIndex);
1291                         break;
1292
1293                 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1294                         MSG_DEBUG("Received DM BOOTSTRAP");
1295                         SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1296                         break;
1297
1298                 case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1299                         MSG_DEBUG("Received DM BOOTSTRAP");
1300                         SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1301                         break;
1302
1303                 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1304                         MSG_DEBUG("Received Provisioning");
1305                         SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_XML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1306                         break;
1307
1308                 case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1309                         MSG_DEBUG("Received Provisioning");
1310                         SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(CP_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1311                         break;
1312
1313                 case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1314                 case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1315                         MSG_DEBUG("Received Provisioning");
1316                         SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(OTHERS, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1317                         break;
1318
1319                 case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1320                         MSG_DEBUG("Received DM Notification");
1321                         SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DM_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1322                         break;
1323
1324                 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1325                         MSG_DEBUG("Received DS Notification");
1326                         SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_NOTIFICATION, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1327                         break;
1328
1329                 case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1330                         MSG_DEBUG("Received DS Notification");
1331                         SmsPluginEventHandler::instance()->handleSyncMLMsgIncoming(DS_WBXML, pPushBody, PushBodyLen, pWspHeader, WspHeaderLen, simIndex);
1332                         break;
1333
1334                 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_XML:
1335                 case SMS_WAP_APPLICATION_DRM_UA_RIGHTS_WBXML:
1336                         MSG_DEBUG("Received DRM UA");
1337
1338                         if (pPushBody != NULL)
1339                                 handleDrmVer1(pPushBody, PushBodyLen);
1340
1341                         break;
1342
1343                 case SMS_WAP_APPLICATION_DRM_V2_RO_XML:
1344                 case SMS_WAP_APPLICATION_DRM_V2_ROAP_PDU_XML:
1345                 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_XML:
1346                 case SMS_WAP_APPLICATION_DRM_V2_ROAP_TRIGGER_WBXML:
1347                         MSG_DEBUG("Received DRM V2");
1348                         /* TODO: DRM V2 */
1349                         break;
1350
1351                 case SMS_WAP_APPLICATION_PUSH_EMAIL:
1352                 case SMS_WAP_APPLICATION_PUSH_EMAIL_XML:
1353                 case SMS_WAP_APPLICATION_PUSH_EMAIL_WBXML:
1354                         MSG_DEBUG("Received Email");
1355                         /* TODO: Email */
1356                         break;
1357
1358
1359                 case SMS_WAP_APPLICATION_PUSH_IMPS_CIR:
1360                         MSG_DEBUG("Received IMPS CIR");
1361                         /* TODO: IMPS CIR */
1362                         break;
1363
1364                 case SMS_WAP_APPLICATION_LBS:
1365                         MSG_DEBUG("Received LBS related message");
1366                         SmsPluginEventHandler::instance()->handleLBSMsgIncoming(pPushHeader, pPushBody, PushBodyLen);
1367                         /* TODO: LBS */
1368                         break;
1369
1370                 case SMS_WAP_APPLICATION_PUSH_SIA:
1371                         MSG_DEBUG("Received SIA");
1372                         /* TODO: SIA */
1373                         break;
1374
1375                 default:
1376                         SmsPluginEventHandler::instance()->handlePushMsgIncoming(pPushHeader, pPushBody, PushBodyLen, app_id, content_type);
1377                         break;
1378                 }
1379         }
1380         storageHandler->releasePushEvent();
1381
1382         MSG_END();
1383 }
1384 #endif
1385
1386 bool SmsPluginWapPushHandler::IsWapPushMsgInWhiteList(int appCode)
1387 {
1388         MSG_BEGIN();
1389
1390         bool isAllowed = false;
1391
1392         switch (appCode) {
1393         case SMS_WAP_APPLICATION_MMS_UA:
1394         case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP:
1395         case SMS_WAP_APPLICATION_SYNCML_DM_BOOTSTRAP_XML:
1396         case SMS_WAP_APPLICATION_PUSH_PROVISIONING_XML:
1397         case SMS_WAP_APPLICATION_PUSH_PROVISIONING_WBXML:
1398         case SMS_WAP_APPLICATION_PUSH_BROWSER_SETTINGS:
1399         case SMS_WAP_APPLICATION_PUSH_BROWSER_BOOKMARKS:
1400         case SMS_WAP_APPLICATION_SYNCML_DM_NOTIFICATION:
1401         case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION:
1402         case SMS_WAP_APPLICATION_SYNCML_DS_NOTIFICATION_WBXML:
1403                 MSG_INFO("appcode[%d] is allowed even if push receive option is disabled.", appCode);
1404                 isAllowed = true;
1405                 break;
1406         default:
1407                 MSG_DEBUG("appcode[%d] is not allowed when push receive option is disabled.", appCode);
1408                 break;
1409         }
1410
1411         return isAllowed;
1412 }
1413
1414 void SmsPluginWapPushHandler::handleMMSNotification(const char *pPushBody, int PushBodyLen, int simIndex, time_t sent_time)
1415 {
1416         MSG_BEGIN();
1417
1418 #ifdef MSG_FW_FOR_DEBUG
1419         printf("\n\n[handleMMSNotification] Push Body.\n");
1420
1421         for (int i = 0; i < PushBodyLen; i++) {
1422                 printf(" [%02x]", pPushBody[i]);
1423         }
1424         printf("\n\n");
1425 #endif
1426
1427         /** Make MSG_MESSAGE_INFO_S */
1428         MSG_MESSAGE_INFO_S msgInfo;
1429         memset(&msgInfo, 0x00, sizeof(MSG_MESSAGE_INFO_S));
1430
1431         msgInfo.addressList = NULL;
1432         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1433
1434         createMsgInfo(&msgInfo);
1435
1436         /** Convert Type values */
1437         msgInfo.msgType.mainType = MSG_MMS_TYPE;
1438         msgInfo.msgType.subType = MSG_NOTIFICATIONIND_MMS;
1439         msgInfo.msgType.classType = MSG_CLASS_NONE;
1440         msgInfo.storageId = MSG_STORAGE_PHONE;
1441         msgInfo.dataSize = PushBodyLen;
1442         msgInfo.sim_idx = simIndex;
1443
1444         if (sent_time > 0)
1445                 msgInfo.displayTime = sent_time;
1446
1447         if (msgInfo.dataSize > MAX_MSG_TEXT_LEN) {
1448                 msgInfo.bTextSms = false;
1449
1450                 /** Save Message Data into File */
1451                 char fileName[MSG_FILENAME_LEN_MAX+1];
1452                 memset(fileName, 0x00, sizeof(fileName));
1453
1454                 if (MsgCreateFileName(fileName) == false)
1455                         THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1456
1457                 if (MsgWriteIpcFile(fileName, pPushBody, msgInfo.dataSize) == false)
1458                         THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1459
1460                 strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1461         } else {
1462                 msgInfo.bTextSms = true;
1463
1464                 memcpy(msgInfo.msgText, pPushBody, msgInfo.dataSize);
1465                 msgInfo.msgText[msgInfo.dataSize] = '\0';
1466         }
1467
1468         msg_error_t err = MSG_SUCCESS;
1469
1470         /** Add MMS Noti Msg into DB */
1471         err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1472
1473         if (err == MSG_SUCCESS) {
1474                 /**  Callback */
1475                 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1476
1477                 if (err != MSG_SUCCESS) {
1478                         MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1479                 }
1480         } else {
1481                 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1482         }
1483
1484         MSG_END();
1485 }
1486
1487 void SmsPluginWapPushHandler::handleSIMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1488 {
1489         MSG_BEGIN();
1490
1491         MSG_PUSH_MESSAGE_S pushMsg = {};
1492
1493         xmlDocPtr       xmlDoc = NULL;
1494         xmlNodePtr      topNode = NULL;
1495         xmlNodePtr      indNode = NULL;
1496
1497         xmlChar* tmpXmlChar = NULL;
1498
1499         if (pPushBody == NULL) {
1500                 MSG_DEBUG("pPushBody is NULL");
1501                 return;
1502         }
1503
1504         getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1505
1506         if (xmlDoc == NULL) {
1507                 MSG_DEBUG("xmlDoc is NULL");
1508                 return;
1509         }
1510
1511         topNode = xmlDocGetRootElement(xmlDoc);
1512
1513         if (topNode == NULL) {
1514                 MSG_DEBUG("topNode is NULL");
1515                 xmlFreeDoc(xmlDoc);
1516                 return;
1517         }
1518
1519         indNode = topNode->xmlChildrenNode;
1520
1521         while (indNode != NULL) {
1522                 if (!xmlStrcmp(indNode->name, (const xmlChar*) "indication")) {
1523                         MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1524                         break;
1525                 }
1526
1527                 indNode = indNode->next;
1528         }
1529
1530         if (indNode == NULL) {
1531                 MSG_DEBUG("indNode is NULL.");
1532                 return;
1533         }
1534
1535         /**  temporary set to max. */
1536         pushMsg.expires = 0xFFFFFFFF;
1537
1538         /** setting received time */
1539         time_t t = time(NULL);
1540         time_t utfTime = time(&t);
1541
1542         pushMsg.received = (unsigned long)utfTime;
1543
1544         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1545
1546         if (tmpXmlChar == NULL) {
1547                 MSG_DEBUG("href is NULL.");
1548                 return;
1549         }
1550
1551         if (tmpXmlChar != NULL)
1552                 strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1553
1554         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_SI_ID_TAG);
1555
1556         if (tmpXmlChar != NULL)
1557                 strncpy(pushMsg.id, (char*)tmpXmlChar, MAX_WAPPUSH_ID_LEN-1);
1558
1559         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CREATED_TAG);
1560
1561         if (tmpXmlChar != NULL)
1562                 pushMsg.created = convertXmlCharToSec((char*)tmpXmlChar);
1563
1564         if (pushMsg.created == 0)
1565                 pushMsg.created = pushMsg.received;
1566
1567         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_EXPIRES_TAG);
1568
1569         if (tmpXmlChar != NULL)
1570                 pushMsg.expires = convertXmlCharToSec((char*)tmpXmlChar);
1571
1572         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1573
1574         pushMsg.action = convertSIActionStrToEnum((char*)tmpXmlChar);
1575
1576         tmpXmlChar = xmlNodeListGetString(xmlDoc, indNode->xmlChildrenNode, 1);
1577
1578         if (tmpXmlChar == NULL) {
1579                 MSG_DEBUG("contents is NULL.");
1580                 return;
1581         }
1582
1583         strncpy(pushMsg.contents, (char*)tmpXmlChar, MAX_WAPPUSH_CONTENTS_LEN-1);
1584
1585         /** Write push Msg to file */
1586         char fileName[MSG_FILENAME_LEN_MAX+1];
1587         memset(fileName, 0x00, sizeof(fileName));
1588
1589         if (MsgCreateFileName(fileName) == false) {
1590                 xmlFree(xmlDoc);
1591                 xmlFree(tmpXmlChar);
1592                 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1593         }
1594
1595         if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false) {
1596                 xmlFree(xmlDoc);
1597                 xmlFree(tmpXmlChar);
1598                 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1599         }
1600
1601         /**  Pack Message Info Structure */
1602         MSG_MESSAGE_INFO_S msgInfo;
1603         memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1604
1605         msgInfo.addressList = NULL;
1606         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1607
1608         createMsgInfo(&msgInfo);
1609
1610         strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1611
1612         /**  Convert Type values */
1613         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1614         msgInfo.msgType.subType = MSG_WAP_SI_SMS;
1615
1616         msgInfo.dataSize = sizeof(pushMsg);
1617         msgInfo.sim_idx = simIndex;
1618         getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
1619
1620         xmlFree(xmlDoc);
1621         xmlFree(tmpXmlChar);
1622
1623         msg_error_t err = MSG_SUCCESS;
1624
1625         /** Add WAP Push Msg into DB */
1626         err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1627
1628         if (err == MSG_SUCCESS) {
1629                 /** Callback */
1630                 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1631
1632                 if (err != MSG_SUCCESS)
1633                         MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1634         } else {
1635                 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1636         }
1637
1638         MSG_END();
1639
1640         return;
1641 }
1642
1643
1644 void SmsPluginWapPushHandler::handleSLMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1645 {
1646         MSG_BEGIN();
1647
1648         MSG_PUSH_MESSAGE_S pushMsg = {};
1649
1650         xmlDocPtr       xmlDoc = NULL;
1651         xmlNodePtr      topNode = NULL;
1652         xmlNodePtr      indNode = NULL;
1653
1654         xmlChar*                tmpXmlChar = NULL;
1655
1656         msg_error_t err = MSG_SUCCESS;
1657
1658         if (pPushBody == NULL) {
1659                 MSG_DEBUG("pPushBody is NULL \n");
1660                 return;
1661         }
1662
1663         getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1664
1665         if (xmlDoc == NULL) {
1666                 MSG_DEBUG("xmlDoc is NULL \n");
1667                 return;
1668         }
1669
1670         topNode = xmlDocGetRootElement(xmlDoc);
1671
1672         if (topNode == NULL) {
1673                 MSG_DEBUG("Empty Document.");
1674                 xmlFreeDoc(xmlDoc);
1675                 return;
1676         } else {
1677                 MSG_SEC_DEBUG("Not an empty Document and topNode->name = %s \n", topNode->name);
1678         }
1679
1680         indNode = topNode;
1681
1682         while (indNode != NULL) {
1683                 if (!xmlStrcmp(indNode->name, (const xmlChar*)"sl")) {
1684                         MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1685                         break;
1686                 }
1687
1688                 indNode = indNode->next;
1689         }
1690
1691         /**  setting received time setting */
1692         time_t t = time(NULL);
1693         time_t utfTime = time(&t);
1694
1695         pushMsg.received = (unsigned long)utfTime;
1696
1697         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_HREF_TAG);
1698
1699         if (tmpXmlChar == NULL) {
1700                 MSG_DEBUG("href is NULL.");
1701                 return;
1702         }
1703
1704         strncpy(pushMsg.href, (char*)tmpXmlChar, MAX_WAPPUSH_HREF_LEN-1);
1705
1706         tmpXmlChar = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_ACTION_TAG);
1707         pushMsg.action = convertSLActionStrToEnum((char*)tmpXmlChar);
1708
1709         /** Setting other parameters in default values */
1710         pushMsg.created = pushMsg.received;
1711         /** temporary set to MAX value. */
1712         pushMsg.expires = 0xFFFFFFFF;
1713
1714         MSG_DEBUG("check pushMsg data");
1715         MSG_DEBUG("pushMsg.action : [%d]", pushMsg.action);
1716         MSG_DEBUG("pushMsg.received : [%d]", pushMsg.received);
1717         MSG_DEBUG("pushMsg.created : [%d]", pushMsg.created);
1718         MSG_DEBUG("pushMsg.expires : [%d]", pushMsg.expires);
1719         MSG_SEC_DEBUG("pushMsg.id : [%s]", pushMsg.id);
1720         MSG_DEBUG("pushMsg.href : [%s]", pushMsg.href);
1721         MSG_DEBUG("pushMsg.contents : [%s]", pushMsg.contents);
1722
1723         /** Write push Msg to file */
1724         char fileName[MSG_FILENAME_LEN_MAX+1];
1725         memset(fileName, 0x00, sizeof(fileName));
1726
1727         if (MsgCreateFileName(fileName) == false)
1728                 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1729
1730         if (MsgWriteIpcFile(fileName, (char*)(&pushMsg), sizeof(pushMsg)) == false)
1731                 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1732
1733         /** Pack Message Info Structure */
1734         MSG_MESSAGE_INFO_S msgInfo;
1735         memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1736
1737         msgInfo.addressList = NULL;
1738         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1739
1740         createMsgInfo(&msgInfo);
1741
1742         strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1743
1744         /** Convert Type values */
1745         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1746         msgInfo.msgType.subType = MSG_WAP_SL_SMS;
1747
1748         /**  Update Msg Text */
1749         strncpy(msgInfo.msgText, pushMsg.href, MAX_MSG_TEXT_LEN);
1750
1751         msgInfo.dataSize = sizeof(pushMsg);
1752         msgInfo.sim_idx = simIndex;
1753         getDisplayName(msgInfo.msgType.subType, msgInfo.addressList[0].addressVal);
1754
1755         MSG_DEBUG("dataSize : %d", msgInfo.dataSize);
1756
1757         /** Add WAP Push Msg into DB */
1758         err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1759
1760         if (err == MSG_SUCCESS) {
1761                 /** Callback to MSG FW */
1762                 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1763
1764                 if (err != MSG_SUCCESS)
1765                         MSG_DEBUG("callbackMsgIncoming is failed, err=[%d]", err);
1766         } else {
1767                 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1768         }
1769
1770         xmlFree(xmlDoc);
1771         xmlFree(tmpXmlChar);
1772
1773         MSG_END();
1774
1775         return;
1776 }
1777
1778 void SmsPluginWapPushHandler::handleCOMessage(char* pPushBody, int PushBodyLen, bool isText, int simIndex)
1779 {
1780         MSG_PUSH_CACHEOP_S cacheOp;
1781
1782         xmlDocPtr       xmlDoc = NULL;
1783         xmlNodePtr      topNode = NULL;
1784         xmlNodePtr      indNode = NULL;
1785
1786         memset(&cacheOp, 0x00, sizeof(cacheOp));
1787
1788         MSG_DEBUG("Enter handleCOMessage");
1789
1790         if (pPushBody == NULL) {
1791                 MSG_DEBUG("pPushBody is NULL \n");
1792                 return;
1793         }
1794
1795         getXmlDoc(pPushBody, PushBodyLen, &xmlDoc, isText);
1796
1797         if (xmlDoc == NULL) {
1798                 MSG_DEBUG("xmlDoc is NULL \n");
1799                 return;
1800         }
1801
1802         topNode = xmlDocGetRootElement(xmlDoc);
1803         if (topNode == NULL) {
1804                 MSG_DEBUG("Warning:Empty Document\n");
1805                 xmlFreeDoc(xmlDoc);
1806                 return;
1807         }
1808
1809         indNode = topNode->xmlChildrenNode;
1810
1811
1812         while (indNode != NULL) {
1813                 xmlChar* tmpUrl = NULL;
1814                 if (!xmlStrcmp(indNode->name, (const xmlChar*)SMS_PUSH_XML_INVAL_OBJ)) {
1815                         MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1816
1817                         tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1818
1819                         if (tmpUrl != NULL) {
1820                                 strncpy(cacheOp.invalObjectUrl[cacheOp.invalObjectCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1821
1822                                 MSG_DEBUG("%dth invalObjectUrl is <%s>\n", cacheOp.invalObjectCnt, cacheOp.invalObjectUrl[cacheOp.invalObjectCnt-1]);
1823                         } else {
1824                                 MSG_DEBUG("NO href value from the xmlDoc\n");
1825                         }
1826                 } else if (!xmlStrcmp(indNode->name, (const xmlChar*)SMS_PUSH_XML_INVAL_SVC)) {
1827                         MSG_SEC_DEBUG("indNode->name = %s\n", indNode->name);
1828                         tmpUrl = xmlGetProp(indNode, (xmlChar*)SMS_PUSH_XML_CO_URI);
1829
1830                         if (tmpUrl != NULL) {
1831                                 strncpy(cacheOp.invalServiceUrl[cacheOp.invalServiceCnt++], (char*)tmpUrl, MAX_PUSH_CACHEOP_MAX_URL_LEN-1);
1832                                 MSG_DEBUG("%dth invalServiceUrl is <%s>\n", cacheOp.invalServiceCnt, cacheOp.invalServiceUrl[cacheOp.invalServiceCnt-1]);
1833                         } else {
1834                                 MSG_DEBUG("NO href value from the xmlDoc\n");
1835                         }
1836                 }
1837
1838                 if (tmpUrl != NULL)
1839                         xmlFree(tmpUrl);
1840
1841                 indNode = indNode->next;
1842         }
1843
1844         /**  Write push Msg to file */
1845         char fileName[MSG_FILENAME_LEN_MAX+1];
1846         memset(fileName, 0x00, sizeof(fileName));
1847
1848         if (MsgCreateFileName(fileName) == false) {
1849                 xmlFree(xmlDoc);
1850                 THROW(MsgException::FILE_ERROR, "MsgCreateFileName error");
1851         }
1852
1853         if (MsgWriteIpcFile(fileName, (char*)(&cacheOp), sizeof(cacheOp)) == false) {
1854                 xmlFree(xmlDoc);
1855                 THROW(MsgException::FILE_ERROR, "MsgWriteIpcFile error");
1856         }
1857
1858         /**  Pack Message Info Structure */
1859         MSG_MESSAGE_INFO_S msgInfo;
1860         memset(&msgInfo, 0, sizeof(MSG_MESSAGE_INFO_S));
1861
1862         msgInfo.addressList = NULL;
1863         unique_ptr<MSG_ADDRESS_INFO_S*, void(*)(MSG_ADDRESS_INFO_S**)> addressListBuf(&msgInfo.addressList, unique_ptr_deleter);
1864
1865         createMsgInfo(&msgInfo);
1866
1867         strncpy(msgInfo.msgData, fileName, MAX_MSG_DATA_LEN);
1868
1869         /**  Convert Type values */
1870         msgInfo.msgType.mainType = MSG_SMS_TYPE;
1871         msgInfo.msgType.subType = MSG_WAP_CO_SMS;
1872
1873         msgInfo.dataSize = sizeof(cacheOp);
1874         msgInfo.sim_idx = simIndex;
1875
1876         msg_error_t err = MSG_SUCCESS;
1877
1878         /** Add WAP Push Msg into DB */
1879         err = SmsPluginStorage::instance()->checkMessage(&msgInfo);
1880
1881         if (err == MSG_SUCCESS) {
1882                 /** Callback */
1883                 err = SmsPluginEventHandler::instance()->callbackMsgIncoming(&msgInfo);
1884
1885                 if (err != MSG_SUCCESS)
1886                         MSG_DEBUG("callbackMsgIncoming() Error !! [%d]", err);
1887         } else {
1888                 MSG_DEBUG("checkMessage() Error !! [%d]", err);
1889         }
1890
1891         xmlFree(xmlDoc);
1892
1893         return;
1894 }
1895
1896
1897 void SmsPluginWapPushHandler::handleDrmVer1(char* pPushBody, int PushBodyLen)
1898 {
1899 #if MSG_DRM_SUPPORT
1900         int drmRt = DRM_RETURN_SUCCESS;
1901         char* cid = NULL;
1902         unique_ptr<char*, void(*)(char**)> buf(&cid, unique_ptr_deleter);
1903
1904         MSG_DEBUG("Received DRM RIGHTS OBJECT Type WAP Push Message.");
1905         drm_request_type_e request_type = DRM_REQUEST_TYPE_REGISTER_LICENSE;
1906         drm_register_lic_info_s lic_req_info;
1907         drm_register_lic_resp_s lic_resp_info;
1908
1909         bzero(&lic_req_info, sizeof(drm_register_lic_info_s));
1910         bzero(&lic_resp_info, sizeof(drm_register_lic_resp_s));
1911         bzero(lic_req_info.lic_data, sizeof(lic_req_info.lic_data));
1912
1913         memcpy(lic_req_info.lic_data, pPushBody, PushBodyLen);
1914
1915         lic_req_info.lic_version = DRM_OMA_DRMV1_RIGHTS;
1916         lic_req_info.roap_init_src = DRM_ROAP_INIT_FROM_WAPPUSH;
1917         lic_req_info.operation_callback.callback = NULL;
1918
1919         drmRt = drm_process_request(request_type, &lic_req_info, &lic_resp_info);
1920         if (drmRt == DRM_RETURN_SUCCESS) {
1921                 MSG_DEBUG("DRM successfully registed to drm-service.");
1922         } else {
1923                 MSG_DEBUG("Fail to regist DRM to drm-service.");
1924         }
1925 #endif
1926         return;
1927 }
1928
1929
1930 void SmsPluginWapPushHandler::createMsgInfo(MSG_MESSAGE_INFO_S* pMsgInfo)
1931 {
1932         /** Convert class Type values */
1933         pMsgInfo->msgType.classType = MSG_CLASS_NONE;
1934
1935         /**  set folder id (temporary) */
1936         pMsgInfo->folderId = MSG_INBOX_ID;
1937
1938         pMsgInfo->networkStatus = MSG_NETWORK_RECEIVED;
1939         pMsgInfo->bRead = false;
1940         pMsgInfo->bProtected = false;
1941         pMsgInfo->priority = MSG_MESSAGE_PRIORITY_NORMAL;
1942         pMsgInfo->direction = MSG_DIRECTION_TYPE_MT;
1943
1944         time_t rawtime = time(NULL);
1945
1946 /*** Comment below lines to save local UTC time..... (it could be used later.)
1947
1948         if (tmpTimeStamp.format == SMS_TIME_ABSOLUTE) {
1949
1950                 MSG_DEBUG("year : %d", tmpTimeStamp.time.absolute.year);
1951                 MSG_DEBUG("month : %d", tmpTimeStamp.time.absolute.month);
1952                 MSG_DEBUG("day : %d", tmpTimeStamp.time.absolute.day);
1953                 MSG_DEBUG("hour : %d", tmpTimeStamp.time.absolute.hour);
1954                 MSG_DEBUG("minute : %d", tmpTimeStamp.time.absolute.minute);
1955                 MSG_DEBUG("second : %d", tmpTimeStamp.time.absolute.second);
1956                 MSG_DEBUG("timezone : %d", tmpTimeStamp.time.absolute.timeZone);
1957
1958                 char displayTime[32];
1959                 struct tm * timeTM;
1960
1961                 struct tm timeinfo;
1962                 memset(&timeinfo, 0x00, sizeof(tm));
1963
1964                 timeinfo.tm_year = (tmpTimeStamp.time.absolute.year + 100);
1965                 timeinfo.tm_mon = (tmpTimeStamp.time.absolute.month - 1);
1966                 timeinfo.tm_mday = tmpTimeStamp.time.absolute.day;
1967                 timeinfo.tm_hour = tmpTimeStamp.time.absolute.hour;
1968                 timeinfo.tm_min = tmpTimeStamp.time.absolute.minute;
1969                 timeinfo.tm_sec = tmpTimeStamp.time.absolute.second;
1970                 timeinfo.tm_isdst = 0;
1971
1972                 rawtime = mktime(&timeinfo);
1973
1974                 MSG_DEBUG("tzname[0] [%s]", tzname[0]);
1975                 MSG_DEBUG("tzname[1] [%s]", tzname[1]);
1976                 MSG_DEBUG("timezone [%d]", timezone);
1977                 MSG_DEBUG("daylight [%d]", daylight);
1978
1979                 memset(displayTime, 0x00, sizeof(displayTime));
1980                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", &timeinfo);
1981                 MSG_DEBUG("displayTime [%s]", displayTime);
1982
1983                 rawtime -= (tmpTimeStamp.time.absolute.timeZone * (3600/4));
1984
1985                 timeTM = localtime(&rawtime);
1986                 memset(displayTime, 0x00, sizeof(displayTime));
1987                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1988                 MSG_DEBUG("displayTime [%s]", displayTime);
1989
1990                 rawtime -= timezone;
1991
1992                 timeTM = localtime(&rawtime);
1993                 memset(displayTime, 0x00, sizeof(displayTime));
1994                 strftime(displayTime, 32, "%Y-%02m-%02d %T %z", timeTM);
1995                 MSG_DEBUG("displayTime [%s]", displayTime);
1996         }
1997
1998 ***/
1999
2000         pMsgInfo->displayTime = rawtime;
2001
2002         /**  Convert Address values */
2003         pMsgInfo->nAddressCnt = 1;
2004
2005         pMsgInfo->addressList = (MSG_ADDRESS_INFO_S *)new char[sizeof(MSG_ADDRESS_INFO_S)];
2006         memset(pMsgInfo->addressList, 0x00, sizeof(MSG_ADDRESS_INFO_S));
2007
2008         pMsgInfo->addressList[0].addressType = MSG_ADDRESS_TYPE_PLMN;
2009         strncpy(pMsgInfo->addressList[0].addressVal, tmpAddress.address, MAX_ADDRESS_VAL_LEN);
2010
2011         pMsgInfo->msgPort.valid = false;
2012         pMsgInfo->msgPort.dstPort = 0;
2013         pMsgInfo->msgPort.srcPort = 0;
2014 }
2015
2016 void SmsPluginWapPushHandler::getXmlDoc(const char* pPushBody, const int PushBodyLen, xmlDocPtr *pXmlDoc, const bool isText)
2017 {
2018         if (pPushBody == NULL) {
2019                 MSG_DEBUG("pPushBody is NULL");
2020                 return;
2021         }
2022
2023
2024         if (isText) {
2025                 *pXmlDoc = xmlParseMemory(pPushBody, AcStrlen(pPushBody));
2026         } else {
2027                 WB_UTINY*       xmldata = NULL;
2028                 WBXMLConvWBXML2XML *conv = NULL;
2029                 WBXMLError ret = WBXML_OK;
2030
2031                 ret = wbxml_conv_wbxml2xml_create(&conv);
2032                 if (ret != WBXML_OK)
2033                         return;
2034
2035                 ret = wbxml_conv_wbxml2xml_run(conv, (WB_UTINY*)pPushBody, (WB_ULONG)PushBodyLen, &xmldata, NULL);
2036
2037                 wbxml_conv_wbxml2xml_destroy(conv);
2038
2039                 if (ret != WBXML_OK ||xmldata == NULL) {
2040                         MSG_DEBUG("xmldata is NULL. Error code is [%d].\n", ret);
2041                         return;
2042                 }
2043
2044                 MSG_DEBUG("xmldata : \n%s\n", xmldata);
2045
2046                 *pXmlDoc = xmlParseMemory((char*)xmldata, AcStrlen((char*)xmldata));
2047         }
2048 }
2049
2050 unsigned long SmsPluginWapPushHandler::convertXmlCharToSec(char* pDate)
2051 {
2052         struct tm       timeStruct;
2053         time_t          nTimeInSec = 0;
2054         char                    tmpBuf[10];
2055         int                     i = 0, index = 0;
2056
2057         memset(tmpBuf, 0x00, sizeof(tmpBuf));
2058         memset(&timeStruct, 0x00, sizeof(struct tm));
2059
2060         /** check pDate */
2061         if (AcStrlen(pDate) < 20)
2062                 return 0;
2063
2064         MSG_DEBUG("pDate [%s]", pDate);
2065
2066         /** Year */
2067         for (i = 0; i < 4; i++) {
2068                 tmpBuf[i] = pDate[index++];
2069         }
2070         tmpBuf[i] = '\0';
2071         index++;
2072         timeStruct.tm_year = (atoi(tmpBuf)-1900);
2073
2074         /**  Month */
2075         for (i = 0; i < 2; i++) {
2076                 tmpBuf[i] = pDate[index++];
2077         }
2078         tmpBuf[i] = '\0';
2079         index++;
2080         timeStruct.tm_mon = (atoi(tmpBuf) - 1);
2081
2082         /** Date */
2083         for (i = 0; i < 2; i++) {
2084                 tmpBuf[i] = pDate[index++];
2085         }
2086         tmpBuf[i] = '\0';
2087         index++;
2088         timeStruct.tm_mday = atoi(tmpBuf);
2089
2090         /** Hours */
2091         for (i = 0; i < 2; i++) {
2092                 tmpBuf[i] = pDate[index++];
2093         }
2094         tmpBuf[i] = '\0';
2095         index++;
2096         timeStruct.tm_hour = atoi(tmpBuf);
2097
2098         /** Minites */
2099         for (i = 0; i < 2; i++) {
2100                 tmpBuf[i] = pDate[index++];
2101         }
2102         tmpBuf[i] = '\0';
2103         index++;
2104         timeStruct.tm_min = atoi(tmpBuf);
2105
2106         /** Seconds */
2107         for (i = 0; i < 2; i++) {
2108                 tmpBuf[i] = pDate[index++];
2109         }
2110         tmpBuf[i] = '\0';
2111         index++;
2112         timeStruct.tm_sec = atoi(tmpBuf);
2113
2114         nTimeInSec = mktime(&timeStruct);
2115
2116         return nTimeInSec;
2117 }
2118
2119 msg_push_action_t SmsPluginWapPushHandler::convertSIActionStrToEnum(char* pAction)
2120 {
2121         int comp = 0;
2122
2123         if (pAction == NULL) {
2124                 MSG_DEBUG("pAction is NULL. Setting to default action type.");
2125                 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2126         }
2127
2128         /** compare  with signal-none. */
2129         comp = g_strcmp0("signal-none", pAction);
2130         if (comp == 0)
2131                 return MSG_PUSH_SI_ACTION_SIGNAL_NONE;
2132
2133         /** compare  with signal-low. */
2134         comp = g_strcmp0("signal-low", pAction);
2135         if (comp == 0)
2136                 return MSG_PUSH_SI_ACTION_SIGNAL_LOW;
2137
2138         /**  compare  with signal-medium. */
2139         comp = g_strcmp0("signal-medium", pAction);
2140         if (comp == 0)
2141                 return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2142
2143         /**  compare  with signal-high. */
2144         comp = g_strcmp0("signal-high", pAction);
2145         if (comp == 0)
2146                 return MSG_PUSH_SI_ACTION_SIGNAL_HIGH;
2147
2148         /**  compare  with delete. */
2149         comp = g_strcmp0("delete", pAction);
2150         if (comp == 0)
2151                 return MSG_PUSH_SI_ACTION_DELETE;
2152
2153         /**  signal-medium is default action value. */
2154         return MSG_PUSH_SI_ACTION_SIGNAL_MEDIUM;
2155 }
2156
2157 msg_push_action_t SmsPluginWapPushHandler::convertSLActionStrToEnum(char* pAction)
2158 {
2159         int comp = 0;
2160
2161         if (pAction == NULL) {
2162                 MSG_DEBUG("MSG_DEBUG is NULL. Setting to default action type.\n");
2163                 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2164         }
2165
2166         /**  compare pSrcStr with execute-low. */
2167         comp = g_strcmp0("execute-low", pAction);
2168         if (comp == 0)
2169                 return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2170
2171         /**  compare pSrcStr with execute-high. */
2172         comp = g_strcmp0("execute-high", pAction);
2173         if (comp == 0)
2174                 return MSG_PUSH_SL_ACTION_EXECUTE_HIGH;
2175
2176         /** compare pSrcStr with cache. */
2177         comp = g_strcmp0("cache", pAction);
2178         if (comp == 0)
2179                 return MSG_PUSH_SL_ACTION_CACHE;
2180
2181         /** default SL action value is execute-low. */
2182         return MSG_PUSH_SL_ACTION_EXECUTE_LOW;
2183 }
2184
2185
2186 unsigned long SmsPluginWapPushHandler::wspRetriveUintvarDecode(unsigned char* sourceData, unsigned long* currentPointer)
2187 {
2188         unsigned long i = 0;
2189         unsigned long decodedValue;
2190
2191         while (sourceData[*currentPointer + i] >= 0x80)
2192                 i++;
2193
2194         decodedValue = wspDecodeUintvar(i + 1, sourceData + *currentPointer);
2195         *currentPointer = *currentPointer + i + 1;
2196         MSG_DEBUG("wspRetriveUintvarDecode: decodedValue=%d .\n", decodedValue);
2197         return decodedValue;
2198 }
2199
2200
2201 unsigned long SmsPluginWapPushHandler::wspDecodeUintvar(unsigned long length, unsigned char* userVar)
2202 {
2203         unsigned long i;
2204         unsigned long decodedUintvar = 0;
2205
2206
2207         for (i = 0 ; i < length; i++) {
2208                 decodedUintvar = decodedUintvar +  (wspUintvarDecodeTable[i] * (userVar[length-(i+1)] & 0x7f));
2209         }
2210
2211         return decodedUintvar;
2212 }
2213
2214
2215 void SmsPluginWapPushHandler::wspDecodeHeader(unsigned char* sEncodedHeader, unsigned long encodedHeaderLen, unsigned long contentsLength, bool fContentType, char** pHeader)
2216 {
2217         unsigned long iField = 0;
2218         bool   continueField = FALSE;
2219         unsigned long currentLength;
2220
2221         char* encodedHeader = NULL;
2222         unique_ptr<char*, void(*)(char**)> encodedHeaderbuf(&encodedHeader, unique_ptr_deleter);
2223
2224         char* outTemper = NULL;
2225
2226         char* temper = NULL;
2227         unique_ptr<char*, void(*)(char**)> temperbuf(&temper, unique_ptr_deleter);
2228
2229         unsigned char track;
2230         unsigned long iEncodedHeader = 0;
2231         unsigned char fieldCode = 0xff;
2232
2233         /* outTemper is Decoded Headers.
2234             temper is Single Decoded Header.
2235         */
2236         if (NULL == (outTemper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ])) {
2237                 MSG_DEBUG("outTemper Memory allocation is failed.\n");
2238                 return;
2239         }
2240         memset(outTemper, 0, (WSP_STANDARD_STR_LEN_MAX * 5));
2241         currentLength = WSP_STANDARD_STR_LEN_MAX;
2242
2243         MSG_DEBUG("wspDecodeHeader: Message header decoding started.\n");
2244
2245         int loop;
2246         char szBuf[64];
2247
2248         szBuf[0] = 0x00;
2249         MSG_DEBUG("wspDecodeHeader: RAW data \n");
2250         for (loop = 0 ; loop < (int)encodedHeaderLen; loop++) {
2251                 char szTempBuf[5];
2252                 szTempBuf[0] = 0x00;
2253                 snprintf(szTempBuf, sizeof(szTempBuf), "%2X ", sEncodedHeader[loop]);
2254
2255                 if (AcStrlen(szBuf) + 7 < 64) {
2256                         strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2257                 } else {
2258                         strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2259                         MSG_DEBUG("[%s]", szBuf);
2260                         szBuf[0] = 0x00;
2261                         strncat(szBuf, szTempBuf, sizeof(szBuf)-AcStrlen(szBuf)-1);
2262                 }
2263         }
2264         strncat(szBuf, "\n", sizeof(szBuf)-AcStrlen(szBuf)-1);
2265         MSG_DEBUG("[%s]", szBuf);
2266         MSG_DEBUG("fContentType=%d  \n", fContentType);
2267         /* operation for content-type */
2268         /* makes psuedo- content-type fieldcode */
2269         /* 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. */
2270
2271         if (fContentType) {
2272                 encodedHeader = new char[ encodedHeaderLen + 1 ];
2273                 if (encodedHeader == NULL) {
2274                         MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2275                         return;
2276                 }
2277                 encodedHeader[0] = 0x91;
2278                 memcpy(encodedHeader + 1, sEncodedHeader, (size_t)encodedHeaderLen);
2279         } else {
2280                 encodedHeader = new char[ encodedHeaderLen ];
2281                 if (encodedHeader == NULL) {
2282                         MSG_DEBUG("encodedHeader Memory allocation is failed.\n");
2283                         return;
2284                 }
2285
2286                 memcpy(encodedHeader, sEncodedHeader, (size_t)encodedHeaderLen);
2287         }
2288
2289         /* Is it reacehd end of header? */
2290         while (iEncodedHeader < encodedHeaderLen) {
2291                 /* Get memory for single header */
2292                 if (temper == NULL) {
2293                         temper = new char[ WSP_STANDARD_STR_LEN_MAX * 5 ];
2294
2295                         if (temper == NULL) {
2296                                 MSG_DEBUG("temper Memory allocation is failed.\n");
2297                                 return;
2298                         }
2299                         memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2300                 } else {
2301                         memset(temper, 0x00, (WSP_STANDARD_STR_LEN_MAX * 5));
2302                 }
2303
2304                 /* this section presents header code page shifting procedure
2305                    This part can be implemented by future request.
2306                 if (track == 0x 7f)
2307                 */
2308                 track = encodedHeader[iEncodedHeader];
2309
2310                 if (track == 0x00) {
2311                         MSG_DEBUG("WspLDecodeHeader: fieldcode  is 0 \n");
2312                         strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2313                         fieldCode = 0xff;
2314                         iEncodedHeader++;
2315                 } else if ((track > 0) && (track < 0x20)) {
2316                         iEncodedHeader++;
2317                 } else if ((track < 0x7f) && (track > 0x1f)) { /* In this case, first byte is normal string. So it's considered to unknown header. */
2318                         unsigned char* fieldName = (unsigned char*)gWapCodeBufferLeft;
2319                         unsigned char* fieldValue = (unsigned char*)gWapCodeBufferRight;
2320
2321                         strncpy((char*)fieldName, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_LEFT_LEN_MAX-1);
2322                         fieldName[WSP_CODE_BUFFER_LEFT_LEN_MAX-1] = '\0';
2323                         iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldName) + 1;
2324                         strncpy((char*)fieldValue, (char*)(encodedHeader + iEncodedHeader), WSP_CODE_BUFFER_RIGHT_LEN_MAX-1);
2325                         fieldValue[WSP_CODE_BUFFER_RIGHT_LEN_MAX-1] = '\0';
2326                         iEncodedHeader = iEncodedHeader + AcStrlen((char*)fieldValue) + 1;
2327
2328                         strncat((char*)temper, (char*)fieldName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2329                         strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2330                         strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2331                         /* this means 'don't process anymore.' */
2332                         fieldCode = 0xff;
2333
2334                 } else if (track > 0x7f) {
2335                         /* In case of first byte is field code, else case is error. */
2336
2337                         /*if ((track & 0x7f) <= wspHeaderFieldCount) { */
2338                                 unsigned long  fieldValueLen = encodedHeader[iEncodedHeader + 1];
2339                                 unsigned char fieldValue[1275];
2340                                 fieldCode = track & 0x7f;
2341                                 /*
2342                                 if ((fieldValueLen == 0) || (fieldValueLen == 0x80))
2343                                 {
2344                                         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]);
2345                                 }
2346                                 */
2347                                 memset(fieldValue, 0, 1275);
2348                                 /* add field name */
2349                                 /* 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. */
2350                                 if (!continueField) {
2351                                         strncat((char*)temper, (char*)wspHeaderFieldName[fieldCode], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2352                                         strncat((char*)temper, ": ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2353                                         continueField = FALSE;
2354                                 }
2355
2356                                 /* field value is string */
2357                                 /* In this case, it just copy field value. */
2358                                 if ((fieldValueLen > LENGTH_QUOTE) && (fieldValueLen < 0x80)) {
2359                                         /* string field value should be NULL terminated */
2360                                         strncat((char*)temper, (char*)(encodedHeader + iEncodedHeader + 1), (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2361                                         strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2362
2363                                         iEncodedHeader = iEncodedHeader + AcStrlen((char*)encodedHeader + iEncodedHeader + 1) + 2;
2364                                         fieldCode = 0xff;
2365                                 }
2366                                 /* first field value is length */
2367                                 /* If first byte of field value is length value, allocate field value by the length.
2368                                 In field value, data is
2369                                 1D 03 8F 24 24  - Then 8F 24 24 is field value.
2370                                 1D 1F 33.... - Then  allocate 33H for FieldValue.
2371                                 1D 8F - Then 8F
2372                                 1D 'Hi man!' Like 00, if string is come, then process without calculating field value.
2373                                 1D 8F 24 24 - In this case, original data is wrong.
2374                                 If  accept-charset: ISO-10646-ucs-2;Q=0.7 is
2375                                 01 03 03 E8 47
2376                                 01 - field code
2377                                 03 - field value length
2378                                 03 E8 47 - field value
2379                                 it's decoded by above value.
2380                                 */
2381                                 if (fieldValueLen < 0x20) {
2382                                         if (fieldValueLen  == LENGTH_QUOTE) {
2383                                                 /* field length is encoded in UINTVAR */
2384                                                 unsigned long  uintvarLen = 0;
2385                                                 fieldValueLen = wspRetriveUintvarDecode((unsigned char*) encodedHeader + iEncodedHeader + 2, &uintvarLen);
2386                                                 memcpy(fieldValue, encodedHeader + iEncodedHeader + 2 + uintvarLen, (size_t)fieldValueLen);
2387                                                 iEncodedHeader = iEncodedHeader + fieldValueLen + uintvarLen + 2;
2388
2389                                         } else {
2390                                                 if (fieldValueLen == 1) {
2391                                                         /* field value is one byte integer over 0x80 */
2392                                                         /** make it two byte integer */
2393                                                         fieldValue[0] = 0x00;
2394                                                         memcpy(fieldValue + 1, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2395                                                         fieldValueLen = 2;
2396                                                         iEncodedHeader = iEncodedHeader + 1 + 2;
2397                                                 } else {
2398                                                         memcpy(fieldValue, encodedHeader + iEncodedHeader + 2, (size_t)fieldValueLen);
2399                                                         fieldValue[fieldValueLen] = 0;
2400                                                         iEncodedHeader = iEncodedHeader + fieldValueLen + 2;
2401                                                         if ((fieldValueLen == 0) || (fieldValueLen == 0x80)) {
2402                                                                 MSG_DEBUG("%X \n",  encodedHeader[iEncodedHeader]);
2403                                                         }
2404                                                 }
2405                                         }
2406                                 }
2407                                 /* field value is single encoded */
2408                                 if (fieldValueLen > 0x7f) {
2409                                         fieldValue[0] = encodedHeader[iEncodedHeader + 1];
2410                                         fieldValueLen = 1;
2411                                         iEncodedHeader = iEncodedHeader + 2;
2412                                 }
2413                                 /* processing normal pre-defined field decoding */
2414
2415                                 MSG_DEBUG("WspLDecodeHeader: FieldCode %X\n", fieldCode);
2416                                 MSG_DEBUG("WspLDecodeHeader: fieldSize %d\n", fieldValueLen);
2417
2418                                 if ((fieldCode  > wspHeaderFieldCount) && (fieldCode != 0xff)) {
2419                                         MSG_DEBUG("WspLDecodeHeader: unknown fieldcode %X \n", track);
2420                                         strncpy((char*) temper, (char*)"", (WSP_STANDARD_STR_LEN_MAX * 5)-1);
2421                                         fieldCode = 0xff;
2422                                 }
2423
2424
2425                                 switch (fieldCode) {
2426                                         /* accept charset */
2427                                         /* It's normal way of field process. */
2428                                         case 0x01: {
2429                                                 unsigned long  i = 0;
2430                                                 unsigned long  code;
2431
2432                                                 /* Case of length of charset greater than 1 are two thigins.
2433                                                 1. code length of charset is greater than 1.
2434                                                 2. It include parameter.
2435                                                 3. Or both of two
2436                                                 */
2437                                                 if (1 != fieldValueLen) {
2438                                                         code = wspHeaderDecodeInteger(fieldValue);
2439                                                         /* Calculate iField. */
2440                                                         if (fieldValue[0] < 0x80)
2441                                                                 iField = fieldValue[0];
2442                                                         else
2443                                                                 iField = 1;
2444
2445                                                         while (wspCharset[i].charsetCode != code)
2446                                                                 i++;
2447                                                         strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2448                                                         /* If parameter exist */
2449                                                         if (iField < fieldValueLen) {
2450                                                                 char* param = NULL;
2451                                                                 unique_ptr<char*, void(*)(char**)> parambuf(&param, unique_ptr_deleter);
2452                                                                 wspHeaderDecodeQValue(fieldValueLen - iField, fieldValue + iField, &param);
2453                                                                 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2454                                                         }
2455                                                 } else {
2456                                                         code = fieldValue[0] & 0x7f;
2457
2458                                                         while ((wspCharset[i].charsetCode != code) && (wspCharset[i].charsetCode != 0xffff )) i++;
2459                                                         strncat((char*)temper, (char*)wspCharset[i].charsetName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2460                                                 }
2461                                         }
2462                                         break;
2463
2464                                         /* type encoding */
2465                                         /* Like below routine, Same decoding routine process together. */
2466                                         /* Accept-encoding */
2467                                         case 0x02:
2468                                         /* content-encoding */
2469                                         case 0x0b: {
2470                                                 int integerValue;
2471
2472                                                 integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2473                                                 if (integerValue > 2) {
2474                                                         MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(2).\n");
2475                                                         break;
2476                                                 }
2477                                                 strncat((char*)temper, (char*)wspEncodeMethod[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2478                                         }
2479                                         break;
2480                                         /* contents type decoder */
2481                                         /* accept */
2482                                         case 0x00:
2483                                         /* content-type */
2484                                         case 0x11: {
2485                                                 unsigned long  contentsTypeCode;
2486                                                 unsigned long  i = 0;
2487                                                 /* encoded content type length body */
2488                                                 unsigned long  tempLen;
2489                                                 MSG_DEBUG("fieldValueLen: %d", fieldValueLen);
2490
2491                                                 /* Like HTTP result state 304, it's for processing without Content type. This part doesn't defined. */
2492                                                 if (0 == fieldValueLen) {
2493                                                         strncat((char*)temper, (char*)"None" , (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2494                                                         break;
2495                                                 }
2496                                                 /* 01 AE --> 00 AE --> AE*/
2497                                                 if (fieldValueLen == 2  &&  fieldValue[0] == 0) {
2498                                                         memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2499                                                         MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2500                                                 }
2501
2502                                                 if ((fieldValue[0] < 0x20) || (fieldValue[0] >= 0x80)) {
2503                                                         if (fieldValue[0] >= 0x80) {
2504                                                                 tempLen = 1;
2505                                                         } else if (fieldValueLen == 2 && fieldValue[0] == 0x03 && fieldValue[1] == 0x0A) { /** 06 05 02 03 0A AF 89 */
2506                                                                 fieldValue[3] = fieldValue[2];
2507                                                                 fieldValue[2] = fieldValue[1];
2508                                                                 fieldValue[1] = fieldValue[0];
2509                                                                 fieldValue[0] = 0x02;
2510                                                                 tempLen = 2;
2511                                                                 fieldValueLen = 3;
2512                                                                 MSG_DEBUG("WspLDecodeHeader:For CPE problem\r\n");
2513                                                         } else {
2514                                                                 tempLen = fieldValue[0]; /** 06 06 03 02 03 16 AF 88 */
2515                                                         }
2516
2517                                                         if (tempLen == 1) {
2518                                                                 char* szExtendedContent;
2519
2520                                                                 contentsTypeCode = fieldValue[0] & 0x7f;
2521                                                                 while ((wspContentsType[i].contentsTypeCode != contentsTypeCode) && (i < wspContentsTypeCount)) i++;
2522
2523                                                                 /* If specified content type doesn't exist */
2524                                                                 if (i < wspContentsTypeCount)
2525                                                                         strncat((char*)temper, (char*)wspContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2526
2527                                                                 szExtendedContent =  wspExtendedDecodeType((char)contentsTypeCode);
2528
2529                                                                 if (szExtendedContent != NULL) {
2530                                                                         MSG_DEBUG("WspLDecodeHeader: Tele2 server problem \n ");
2531                                                                         strncat((char*)temper, (char*)szExtendedContent, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2532                                                                 }
2533                                                         } else {
2534                                                                 contentsTypeCode = wspHeaderDecodeInteger(fieldValue);
2535
2536                                                                 while ((i < wspUnregisteredContentsTypeCount) && (wspUnregisterContentsType[i].contentsTypeCode != contentsTypeCode)) i++;
2537
2538                                                                 /** If there is a Content-Type assigned, */
2539                                                                 if (i < wspUnregisteredContentsTypeCount)
2540                                                                         strncat((char*)temper, (char*)wspUnregisterContentsType[i].contentsTypeName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2541
2542                                                                 tempLen +=1;
2543                                                         }
2544                                                 } else {
2545                                                         tempLen = AcStrlen((char*)fieldValue) + 1;
2546
2547                                                         strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2548                                                         MSG_DEBUG("WspLDecodeHeader: Attention, Decoding Check of Content-Type\n ", tempLen);
2549                                                 }
2550
2551                                                 /* If there is a parameter */
2552                                                 if (tempLen < fieldValueLen) {
2553                                                         char* param = NULL;
2554                                                         unique_ptr<char*, void(*)(char**)> parambuf(&param, unique_ptr_deleter);
2555                                                         wspHeaderDecodeParameter(fieldValue + tempLen, fieldValueLen - tempLen, &param);
2556                                                         if (param != NULL) {
2557                                                                 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2558                                                                 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2559                                                         }
2560                                                 }
2561                                         }
2562                                         break;
2563
2564                                         /* language */
2565                                         /* content-language */
2566                                         case 0x0c:
2567                                         /* accept-language */
2568                                         case 0x03: {
2569                                                 unsigned long i = 0;
2570                                                 unsigned long code;
2571                                                 unsigned long tempLen;
2572                                                 if ((fieldValue[0] < 0x20) || (fieldValue[0] > 0x80)) {
2573                                                         if (fieldValue[0] > 0x80)
2574                                                                 tempLen = 1;
2575                                                         else
2576                                                                 tempLen = fieldValue[0];
2577                                                 } else {
2578                                                         tempLen = AcStrlen((char*)fieldValue) + 1;
2579                                                 }
2580
2581                                                 if (tempLen == 1) {
2582                                                         code = wspHeaderDecodeInteger(fieldValue);
2583                                                         while (wspLanguage[i].languageCode != code) {
2584                                                                 i++;
2585                                                                 if (i == wspLanguageCount)
2586                                                                         break;
2587                                                         }
2588
2589                                                         if (i < wspLanguageCount) {
2590                                                                 strncat((char*)temper, (char*)wspLanguage[i].languageName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2591                                                         }
2592                                                 } else {
2593                                                         strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2594                                                 }
2595
2596                                                 if (tempLen < fieldValueLen) {
2597                                                         char* param = NULL;
2598                                                         unique_ptr<char*, void(*)(char**)> parambuf(&param, unique_ptr_deleter);
2599                                                         wspHeaderDecodeQValue(fieldValueLen - tempLen, fieldValue + tempLen, &param);
2600                                                         strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2601                                                 }
2602                                         }
2603                                         break;
2604
2605                                         /* integer */
2606                                         /* Max-forwards */
2607                                         case 0x1e:
2608                                         /* content-length */
2609                                         case 0x0d:
2610                                         /* age */
2611                                         case 0x05:
2612                                         /* Bearer-indication */
2613                                         case 0x33:
2614                                         /* Push-Flag */
2615                                         case 0x34: {
2616                                                 unsigned char temp[16];
2617                                                 /*
2618                                                 if ((fieldValueLen == 2) && (fieldValue[0] > 0x7f))
2619                                                         AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[1]);
2620                                                 else
2621                                                 */
2622                                                 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2623                                                 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2624                                         }
2625                                         break;
2626                                         /* X-Wap-Application-Id */
2627                                         case 0x2f: {
2628                                                 unsigned char temp[64];
2629                                                 int         integerValue;
2630
2631                                                 if (track == 0xaf) { /* WAP short-integer-encoded */
2632                                                         if (fieldValueLen == 2 &&  fieldValue[0] == 0) {
2633                                                                 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen);
2634                                                         }
2635                                                         integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2636                                                 } else {
2637                                                         if (fieldValueLen == 2 &&  fieldValue[0] == 0) {
2638                                                                 memcpy(fieldValue, encodedHeader + iEncodedHeader -1, (size_t)fieldValueLen-1);
2639                                                                 MSG_DEBUG("WspLDecodeHeader:For mmO2 problem\r\n");
2640                                                                 fieldValueLen = 1;
2641                                                         }
2642                                                         integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2643                                                 }
2644
2645                                                 MSG_DEBUG("integerValue = [%02x]", integerValue);
2646
2647                                                 int count = sizeof(wspHeaderApplId)/sizeof(SMS_WSP_HEADER_PARAMETER_S);
2648                                                 for (int i = 0; i < count ; ++i) {
2649                                                         if ((unsigned int)integerValue == wspHeaderApplId[i].parameterCode) {
2650                                                                 snprintf((char*)temp, 64, "%s", wspHeaderApplId[i].parameterToken);
2651                                                                 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2652                                                                 break;
2653                                                         }
2654                                                 }
2655                                         }
2656                                         break;
2657                                         /* Accept-Application */
2658                                         case 0x32:
2659                                                 if (0x80 == fieldValue[0]) {
2660                                                         strncat((char*)temper, "*", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2661                                                 } else {
2662                                                         unsigned char temp[16];
2663                                                         /*
2664                                                         if ((fieldValueLen == 2) && (fieldValue[0] == 1))
2665                                                                 AcSprintf((char*)temp, "%u", (unsigned int)fieldValue[0]);
2666                                                         else
2667                                                         */
2668                                                         snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2669                                                         strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2670                                                 }
2671                                                 break;
2672
2673
2674                                         /* date */
2675                                         /* last-modified */
2676                                         case 0x1d:
2677                                         /* if-unmodified-since */
2678                                         case 0x1b:
2679                                         /* if-range */
2680                                         case 0x1a:
2681                                         /* if-modified-since */
2682                                         case 0x17:
2683                                         /* expires */
2684                                         case 0x14:
2685                                         /* date */
2686                                         case 0x12: {
2687                                                 char* decodedString = NULL;
2688                                                 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2689                                                 wspHeaderDecodeDateValue(fieldValueLen, fieldValue, &decodedString);
2690                                                 strncat((char*)temper, (char*)decodedString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2691                                         }
2692                                         break;
2693
2694                                         /* connection */
2695                                         case 0x09:
2696                                                 if (fieldValue[0] == 0x80)
2697                                                         strncat((char*)temper, "Close", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2698                                                 break;
2699                                         /* accept-ranges */
2700                                         case 0x04:
2701                                                 if (fieldValue[0] == 0x80)
2702                                                         strncat((char*)temper, "None", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2703                                                 if (fieldValue[0] == 0x81)
2704                                                         strncat((char*)temper, "Bytes", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen(temper)-1);
2705                                                 break;
2706                                         /* content-md5 */
2707                                         case 0x0f: {
2708                                                 unsigned char temp[1275];
2709                                                 memcpy(temp, fieldValue, (size_t)fieldValueLen);
2710                                                 temp[fieldValueLen] = 0;
2711                                                 wspHeaderCopyDecodedString(temp, &currentLength, &temper);
2712                                         }
2713                                         break;
2714                                         /* Credential */
2715                                         /* authorization */
2716                                         case 0x07:
2717                                         /* proxy - authorization */
2718                                         case 0x21:
2719                                                 if (fieldValue[0] == 0x80) {
2720                                                         char* addString = NULL;
2721                                                         unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2722                                                         wspHeaderDecodeAuth(fieldValueLen, fieldValue, &addString);
2723                                                         strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2724                                                 } else {
2725                                                         iField = AcStrlen((char*)fieldValue) + 1;
2726
2727                                                         strncat((char*)temper, (char*)fieldValue, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2728                                                         if (iField < fieldValueLen) {
2729                                                                 char* param = NULL;
2730                                                                 unique_ptr<char*, void(*)(char**)> parambuf(&param, unique_ptr_deleter);
2731                                                                 wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, &param);
2732                                                                 if (param != NULL) {
2733                                                                         strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2734                                                                         strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2735                                                                 }
2736                                                         }
2737                                                 }
2738                                                 break;
2739
2740
2741                                         /* Challenge */
2742                                         /* www - auth */
2743                                         case 0x2d:
2744                                         /* Proxy-authenticate */
2745                                         case 0x20:
2746                                                 if (0 == fieldValueLen)
2747                                                         break;
2748                                                 if (fieldValue[0] == 0x80) {
2749                                                         char* addString = NULL;
2750                                                         unique_ptr<char*, void(*)(char**)> addStringbuf(&addString, unique_ptr_deleter);
2751                                                         wspHeaderDecodeChallenge(fieldValueLen, fieldValue, &addString);
2752                                                         strncat((char*)temper, addString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2753                                                 } else {
2754                                                         unsigned char  authScheme[WSP_STANDARD_STR_LEN_MAX + 1];
2755                                                         unsigned char  realmValue[WSP_STANDARD_STR_LEN_MAX];
2756                                                         unsigned char  addedString[WSP_STANDARD_STR_LEN_MAX];
2757
2758                                                         strncpy((char*)authScheme, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX -1);
2759                                                         iField = AcStrlen((char*)authScheme) + 1;
2760                                                         strncpy((char*)realmValue, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2761                                                         iField = iField + AcStrlen((char*)realmValue) + 1;
2762                                                         snprintf((char*)addedString, sizeof(addedString), "%s %s", authScheme, realmValue);
2763                                                         wspHeaderCopyDecodedString(addedString, &currentLength, &temper);
2764
2765                                                         if (iField < fieldValueLen) {
2766                                                                 char* param = NULL;
2767                                                                 unique_ptr<char*, void(*)(char**)> parambuf(&param, unique_ptr_deleter);
2768                                                                 wspHeaderDecodeParameter(fieldValue + iField, fieldValueLen - iField, &param);
2769                                                                 if (param != NULL) {
2770                                                                         strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2771                                                                         wspHeaderCopyDecodedString((unsigned char*)param, &currentLength, &temper);
2772                                                                 }
2773                                                         }
2774                                                 }
2775                                                 break;
2776
2777                                         /* content -range */
2778                                         case 0x10: {
2779                                                 unsigned long  first, len, last;
2780
2781                                                 unsigned char  temp[16];
2782                                                 iField = 0;
2783
2784                                                 strncat((char*)temper, " bytes ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2785
2786                                                 first = wspRetriveUintvarDecode(fieldValue, &iField);
2787                                                 len = wspRetriveUintvarDecode(fieldValue, &iField);
2788                                                 /* 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.
2789                                                 */
2790                                                 last = first + contentsLength - 1;
2791
2792                                                 snprintf((char*)temp, sizeof(temp), "%u-%u/%u", (unsigned int)first, (unsigned int)last, (unsigned int)len);
2793                                                 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2794                                         }
2795                                         break;
2796
2797                                         /* cache-control */
2798                                         case 0x08: {
2799                                                 char* cacheString = NULL;
2800                                                 unique_ptr<char*, void(*)(char**)> cacheStringbuf(&cacheString, unique_ptr_deleter);
2801
2802                                                 wspHeaderDecodeCacheControl(fieldValue, fieldValueLen, &cacheString);
2803                                                 strncat((char*)temper, (char*)cacheString, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2804                                         }
2805                                         break;
2806
2807                                         /* pragma */
2808                                         case 0x1f:
2809                                                 if (fieldValue[0] == 0x80) {
2810                                                         strncat((char*)temper, (char*)wspCacheControl[0], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2811                                                 } else {
2812                                                         if (1 < fieldValueLen) {
2813                                                                 char* param = NULL;
2814                                                                 unique_ptr<char*, void(*)(char**)> parambuf(&param, unique_ptr_deleter);
2815                                                                 wspHeaderDecodeParameter(fieldValue, fieldValueLen, &param);
2816
2817                                                                 if (param != NULL) {
2818                                                                         strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2819                                                                         strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2820                                                                 }
2821                                                         }
2822                                                 }
2823
2824                                                 break;
2825                                         /* public */
2826                                         case 0x22:
2827                                         /* allow */
2828                                         case 0x06: {
2829                                                 unsigned long  i = 0;
2830                                                 while (wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen) != wspMethodType[i].methodCode) i++;
2831                                                 strncat((char*)temper, (char*)wspMethodType[i].methodName, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2832                                         }
2833                                         break;
2834                                         /* range */
2835                                         case 0x23:
2836                                                 strncat((char*)temper, "bytes=", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2837                                                 if (fieldValue[0] == 0x80) {
2838                                                         unsigned char temp[16];
2839                                                         unsigned long  first, last;
2840                                                         iField = 0;
2841
2842                                                         first = wspRetriveUintvarDecode(fieldValue, &iField);
2843                                                         last = wspRetriveUintvarDecode(fieldValue, &iField);
2844
2845                                                         snprintf((char*)temp, sizeof(temp), "%u-%u", (unsigned int)first, (unsigned int)last);
2846                                                         strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2847                                                 }
2848                                                 if (fieldValue[0] == 0x81) {
2849                                                         unsigned char temp[16];
2850                                                         unsigned long  suffix;
2851
2852                                                         suffix = wspRetriveUintvarDecode(fieldValue, &iField);
2853
2854                                                         snprintf((char*)temp, sizeof(temp), "-%u", (unsigned int)suffix);
2855                                                 }
2856                                                 break;
2857                                         /* retry-after */
2858                                         case 0x25:
2859                                                 if (fieldValue[0] == 0x80) {
2860                                                         char* temp = NULL;
2861                                                         unique_ptr<char*, void(*)(char**)> tempbuf(&temp, unique_ptr_deleter);
2862
2863                                                         wspHeaderDecodeDateValue(fieldValueLen - 1, fieldValue + 1, &temp);
2864                                                         strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2865                                                 }
2866
2867                                                 if (fieldValue[0] == 0x81) {
2868                                                         unsigned char temp[16];
2869
2870                                                         snprintf((char*)temp, 16, "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen));
2871                                                         strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2872                                                 }
2873                                                 break;
2874                                         /* transfer-encoding */
2875                                         case 0x27:
2876                                                 /* No other cases allowed */
2877                                                 if (fieldValue[0] == 0x80)
2878                                                         strncat((char*)temper, "chunked", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2879
2880                                                 break;
2881                                         /* vary */
2882                                         case 0x2a: {
2883                                                 int integerValue = wspHeaderDecodeIntegerByLength(fieldValue, fieldValueLen);
2884                                                 if (integerValue > wspHeaderFieldCount) {
2885                                                         MSG_DEBUG("WspLDecodeHeader: integerValue is over limit(0x%x).\n", wspHeaderFieldCount);
2886                                                         break;
2887                                                 }
2888                                                 strncat((char*)temper, (char*)wspHeaderFieldName[integerValue], (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2889                                         }
2890                                         break;
2891                                         /* warning */
2892                                         case 0x2c: {
2893                                                 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2894
2895                                                 if (fieldValue[0] < 0x20)
2896                                                         iField = fieldValue[0];
2897                                                 else
2898                                                         iField = 1;
2899
2900                                                 snprintf((char*)temp, sizeof(temp), "%u", (unsigned int)wspHeaderDecodeIntegerByLength(fieldValue, iField));
2901                                                 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2902                                                 if (iField < fieldValueLen) {
2903                                                         unsigned char agent[WSP_STANDARD_STR_LEN_MAX];
2904                                                         unsigned char text[WSP_STANDARD_STR_LEN_MAX];
2905                                                         strncpy((char*)agent, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2906                                                         iField = iField + AcStrlen((char*)agent) + 1;
2907                                                         strncpy((char*)text, (char*)(fieldValue + iField), WSP_STANDARD_STR_LEN_MAX-1);
2908                                                         snprintf((char*)temp, sizeof(temp), " %s %s", agent, text);
2909                                                         wspHeaderCopyDecodedString(temp, &currentLength, &temper);
2910                                                 }
2911                                         }
2912                                         break;
2913                                         /* content-disposition */
2914                                         case 0x2e:
2915                                                 if (fieldValue[0] == 0x80)
2916                                                         strncat((char*)temper, "form-data", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2917
2918                                                 if (fieldValue[0] == 0x81)
2919                                                         strncat((char*)temper, "attachment", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2920
2921                                                 if (1 < fieldValueLen) {
2922                                                         char* param = NULL;
2923                                                         unique_ptr<char*, void(*)(char**)> parambuf(&param, unique_ptr_deleter);
2924                                                         wspHeaderDecodeParameter(fieldValue + 1, fieldValueLen - 1, &param);
2925
2926                                                         if (param != NULL) {
2927                                                                 strncat((char*)temper, "; ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2928                                                                 strncat((char*)temper, (char*)param, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2929                                                         }
2930                                                 }
2931                                                 break;
2932                                         /* Profile-diff */
2933                                         case 0x36:
2934                                                 temper[AcStrlen((char*)temper) + fieldValueLen] = '\0';
2935                                                 memcpy(temper, fieldValue, (size_t)fieldValueLen);
2936                                                 break;
2937                                         /* Profile-Warning */
2938                                         case 0x37: {
2939                                                 unsigned char temp[WSP_STANDARD_STR_LEN_MAX];
2940
2941                                                 snprintf((char*)temp, sizeof(temp), "%lX", wspHeaderDecodeInteger(fieldValue));
2942                                                 temp[2] = temp[1];
2943                                                 temp[1] = (unsigned char)0x30;
2944                                                 temp[3] = '\0';
2945                                                 if (fieldValueLen > 1) {
2946                                                         /* copy warn-target - URI */
2947                                                         strncat((char*)temp, (char*)(fieldValue + 1), WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2948                                                         if (fieldValueLen > (AcStrlen((char*)(fieldValue + 1)) + 1)) {
2949                                                                 /* copy warn-date */
2950                                                                 char* decodedString = NULL;
2951                                                                 unique_ptr<char*, void(*)(char**)> decodedStringbuf(&decodedString, unique_ptr_deleter);
2952                                                                 wspHeaderDecodeDateValue(fieldValueLen - (AcStrlen((char*)(fieldValue + 1)) + 2), fieldValue + AcStrlen((char*)(fieldValue + 1)) + 1, &decodedString);
2953                                                                 strncat((char*)temp, (char*)decodedString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)temp)-1);
2954                                                         }
2955                                                 }
2956                                                 strncat((char*)temper, (char*)temp, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2957                                         }
2958                                         break;
2959
2960                                         default:
2961                                                 break;
2962                                 }
2963                         /*}*/
2964                 }
2965                 /* It deosn't finished decoding yet. */
2966                 if ((iEncodedHeader < encodedHeaderLen) && (fieldCode != 0xff)) {
2967                         /* In here, iEncodedHeader already point next field code to be decoded. */
2968                         /* If this code is same, then set continueField else add CRLF. */
2969                         if (fieldCode == (encodedHeader[iEncodedHeader] & 0x7f)) {
2970                                 strncat((char*)temper, ", ", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2971                                 continueField = TRUE;
2972                         } else {
2973                                 strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2974                                 continueField = FALSE;
2975                         }
2976                 } else {
2977                         strncat((char*)temper, "\r\n", (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)temper)-1);
2978                 }
2979
2980                 /* add single header to total headers */
2981                 strncat((char*)outTemper, (char*)temper, (WSP_STANDARD_STR_LEN_MAX * 5)-AcStrlen((char*)outTemper)-1);
2982                 MSG_DEBUG("WspLDecodeHeader: Single Header : %s\r\n", temper);
2983         }
2984
2985
2986         MSG_DEBUG("WspLDecodeHeader: Header decoding ended.\n");
2987
2988         *pHeader = outTemper;
2989
2990         return;
2991 }
2992
2993
2994 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeInteger(unsigned char* data)
2995 {
2996         /* we only can handle max 32bit integer */
2997         unsigned long i;
2998
2999         union {
3000                 unsigned long integer;
3001                 unsigned char seg[4];
3002         } returner;
3003
3004         returner.integer = 0;
3005
3006         if (data[0] < 0x80) {
3007                 unsigned long IntLen = 0;
3008
3009                 IntLen = (data[0] > 0x04) ? 0x04:data[0];
3010
3011                 MSG_DEBUG("WspLHeaderDecodeInteger: input %d , length %d\n", data[0], IntLen);
3012
3013                 for (i = 0; i < IntLen; i++)
3014                         returner.seg[IntLen-(i+1)] = data[i+1];
3015
3016                 return returner.integer;
3017         }
3018
3019         return data[0] & 0x7f;
3020 }
3021
3022
3023 void SmsPluginWapPushHandler::wspHeaderDecodeQValue(unsigned long length, unsigned char* data, char** pDecodedString)
3024 {
3025         unsigned short qBase = 0;
3026         float  qValue;
3027
3028         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3029         if (*pDecodedString == NULL) {
3030                 MSG_DEBUG("WspLHeaderDecodeQValue:MemAlloc failed\n");
3031                 return;
3032         }
3033
3034         memcpy(&qBase, data, (size_t)length);
3035         qValue = (float)qBase;
3036         if (qValue > 100) {
3037                 qValue = qValue - 100;
3038                 qValue = qValue / 1000;
3039                 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.3f", qValue);
3040         } else {
3041                 /* qValue variable is divided by 100. And it's multiplied by 100.
3042                    It's to resolve problem of changed 0.01 of qValue. */
3043                 unsigned long qValueTemp;
3044                 qValue = qValue - 1;
3045                 qValue = qValue / 100;
3046                 qValueTemp = (unsigned long)(qValue * 100);
3047                 if (0 == (qValueTemp % 10))
3048                         snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.1f", qValue);
3049                 else
3050                         snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "; q=%.2f", qValue);
3051         }
3052         return;
3053 }
3054
3055
3056 unsigned long SmsPluginWapPushHandler::wspHeaderDecodeIntegerByLength(unsigned char* data, unsigned long length)
3057 {
3058         unsigned long i;
3059
3060         union {
3061                 unsigned long integer;
3062                 unsigned short  seg[4];
3063         } returner;
3064
3065         returner.integer = 0;
3066
3067         if (length == 1)
3068                 return data[0] & 0x7f;
3069
3070         returner.integer = 0;
3071
3072         for (i = 0 ; i < length; i++) {
3073                 returner.integer  =  returner.integer + (data[i]  *  (0x1  << ((length - (i + 1)) * 8)));
3074                 MSG_DEBUG("WspLHeaderDecodeIntegerByLength: %d \n", returner.integer);
3075         }
3076
3077         return returner.integer;
3078 }
3079
3080
3081 char* SmsPluginWapPushHandler::wspExtendedDecodeType(char contentType)
3082 {
3083         int i = 0;
3084
3085         while (wspExtendedContentsType[i].contentsTypeCode != contentType) {
3086                 if (wspExtendedContentsType[i].contentsTypeCode == 0xff)
3087                         return NULL;
3088                 i++;
3089         }
3090
3091         return (char*)wspExtendedContentsType[i].contentsTypeName;
3092 }
3093
3094
3095 void SmsPluginWapPushHandler::wspHeaderDecodeParameter(unsigned char* data, unsigned long length, char** pParam)
3096 {
3097         char* param = *pParam;
3098
3099         unsigned long SecurityTypeCode;
3100         unsigned long  i = 0;
3101
3102         if (data[0] < 0x80) {
3103                 /* unknown parameter type */
3104                 param = new char[WSP_STANDARD_STR_LEN_MAX];
3105
3106                 if (param == NULL) {
3107                         MSG_DEBUG("WspLHeaderDecodeParameter:MemAlloc failed\n");
3108                         return;
3109                 }
3110
3111                 strncpy((char*)param, (char*)data, WSP_STANDARD_STR_LEN_MAX - 1);
3112
3113                 if (NO_VALUE == data[AcStrlen((char*)param) + 1]) {
3114                         *pParam = param;
3115                         return;
3116                 }
3117
3118                 strncat((char*)param, "=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3119                 strncat((char*)param, (char*)(data + strlen((char*)param)), WSP_STANDARD_STR_LEN_MAX-strlen((char*)param)-1);
3120
3121                 *pParam = param;
3122
3123                 return;
3124         }
3125
3126         switch (data[0] & 0x7f) {
3127         case 0x00:
3128                 wspHeaderDecodeQValue(length - 1, data + 1, &param);
3129                 break;
3130         case 0x01:
3131                 wspHeaderDecodeCharset(length - 1 , data + 1, &param);
3132                 break;
3133         case 0x02:
3134                 wspHeaderDecodeVersion(length - 1, data + 1, &param);
3135                 break;
3136                 /* integer */
3137         case 0x03:
3138                 /* param = (unsigned char *)malloc((size_t)WSP_STANDARD_STR_LEN_MAX); */
3139                 param = new char[WSP_STANDARD_STR_LEN_MAX];
3140                 if (param == NULL) {
3141                         MSG_DEBUG("WspLHeaderDecodeParameter: 0x03 MemAlloc failed\n");
3142                         return;
3143                 } else {
3144                         snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Type=%i", (int)wspHeaderDecodeInteger(data + 1));
3145                 }
3146                 break;
3147         case 0x08:
3148                 param = new char[WSP_STANDARD_STR_LEN_MAX];
3149
3150                 if (param == NULL) {
3151                         MSG_DEBUG("WspLHeaderDecodeParameter:0x08 MemAlloc failed\n");
3152                         return;
3153                 } else {
3154                         snprintf((char*)param, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "Padding=%i", (int)wspHeaderDecodeInteger(data + 1));
3155                 }
3156                 break;
3157         case 0x05:
3158                 param = new char[WSP_STANDARD_STR_LEN_MAX];
3159
3160                 if (param == NULL) {
3161                         MSG_DEBUG("WspLHeaderDecodeParameter:0x05 MemAlloc failed\n");
3162                         return;
3163                 } else {
3164                         strncpy((char*)param, "Name=", WSP_STANDARD_STR_LEN_MAX-1);
3165                         memcpy(param + 5, data + 1, length - 1);
3166                         param[5 + length - 1] = '\0';
3167                 }
3168                 break;
3169         case 0x06:
3170                 param = new char[WSP_STANDARD_STR_LEN_MAX];
3171
3172                 if (param == NULL) {
3173                         MSG_DEBUG("WspLHeaderDecodeParameter:0x06 MemAlloc failed\n");
3174                         return;
3175                 } else {
3176                         strncpy((char*)param, "Filename=", WSP_STANDARD_STR_LEN_MAX-1);
3177                         memcpy(param + 9, (char*)(data + 1), (size_t)(length - 1));
3178                         param[9 + length - 1] = '\0';
3179                 }
3180                 break;
3181         case 0x07:
3182                 param = NULL;
3183                 /* TBI */
3184                 break;
3185                 /*OMA Provisioning*/
3186         case 0x11:
3187                 param = new char[WSP_STANDARD_STR_LEN_MAX];
3188
3189                 if (param == NULL) {
3190                         MSG_DEBUG("WspLHeaderDecodeParameter:0x11 MemAlloc failed\n");
3191                         return;
3192                 } else {
3193                         strncpy((char*)param, "SEC=", WSP_STANDARD_STR_LEN_MAX-1);
3194                         SecurityTypeCode = data[1] & 0x7f;
3195                         while ((i < wspSecurityTypeCount) && (wspSecurityType[i].SecurityTypeCode != SecurityTypeCode)) i++;
3196
3197                         if (i < wspSecurityTypeCount) {
3198                                 strncat((char*)param, (char*)wspSecurityType[i].SecurityTypeName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3199                         }
3200
3201                         if (0x12 == (data[2] & 0x7f)) {
3202                                 strncat((char*)param, "; MAC=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3203                                 memcpy(param+AcStrlen((char*)param), (char*)(data+3), (size_t)length-3);
3204                         }
3205                 }
3206                 break;
3207
3208         default:
3209                 param = NULL;
3210                 break;
3211         }
3212
3213         *pParam = param;
3214         return;
3215 }
3216
3217
3218 void SmsPluginWapPushHandler::wspHeaderDecodeCharset(unsigned long length, unsigned char* data, char**pDecodedString)
3219 {
3220         char* param = NULL;
3221
3222         param = new char[WSP_STANDARD_STR_LEN_MAX];
3223
3224         if (param == NULL) {
3225                 MSG_DEBUG("WspLHeaderDecodeCharset:MemAlloc failed\n");
3226                 *pDecodedString = NULL;
3227                 return;
3228         }
3229
3230         strncpy((char*)param, "charset=", WSP_STANDARD_STR_LEN_MAX-1);
3231
3232         if (data[0] > 0x80) {
3233                 unsigned long code = wspHeaderDecodeInteger(data);
3234                 unsigned long i = 0;
3235                 while (wspCharset[i].charsetCode !=  code) {
3236                         if (wspCharset[i].charsetCode == 0xffff) {
3237                                 *pDecodedString = param;
3238                                 return;
3239                         }
3240                         i++;
3241                 }
3242                 strncat((char*)param, (char*)wspCharset[i].charsetName, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)param)-1);
3243         } else {
3244                 unsigned long lastLen = AcStrlen((char*)param);
3245                 if (length + lastLen < WSP_STANDARD_STR_LEN_MAX - 1) {
3246                         memcpy((char*)(param + lastLen), data, (size_t)length);
3247                         param[length + lastLen] = '\0';
3248                 } else {
3249                         memcpy((char*)(param + lastLen), data, WSP_STANDARD_STR_LEN_MAX - lastLen - 1);
3250                         param[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3251                 }
3252         }
3253
3254         *pDecodedString = param;
3255         return;
3256 }
3257
3258
3259
3260 void SmsPluginWapPushHandler::wspHeaderDecodeVersion(unsigned long length, unsigned char* data, char** pDecodedString)
3261 {
3262         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3263
3264         if (*pDecodedString == NULL) {
3265                 MSG_DEBUG("WspLHeaderDecodeVersion:MemAlloc failed\n");
3266                 return;
3267         }
3268
3269         if (length > 1) {
3270                 /* untyped version */
3271                 memcpy(*pDecodedString, data, (size_t)length);
3272         } else {
3273                 /* typed version */
3274                 unsigned char majorVer  = ((data[0] & 0x7f) >> 4);
3275                 unsigned char minorVer = data[0] & 0x0f;
3276                 snprintf((char*)*pDecodedString, sizeof(char)*WSP_STANDARD_STR_LEN_MAX, "level=%u.%u", majorVer, minorVer);
3277         }
3278
3279         return;
3280 }
3281
3282
3283 void SmsPluginWapPushHandler::wspHeaderDecodeDateValue(unsigned long length, unsigned char* data, char** pDecodedString)
3284 {
3285         time_t  lTime;
3286         struct  tm pTMData;
3287
3288         MSG_DEBUG("WspLHeaderDecodeDateValue:   \n");
3289
3290         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3291
3292         if (*pDecodedString == NULL) {
3293                 MSG_DEBUG("WspLHeaderDecodeDateValue:MemAlloc failed\n");
3294                 return;
3295         }
3296
3297         lTime = wspHeaderDecodeIntegerByLength(data, length);
3298
3299         (struct tm*)gmtime_r((const time_t*)&lTime, &pTMData);
3300
3301         /* check date value validity */
3302         if ((pTMData.tm_wday > 6) || (pTMData.tm_mon > 11) || (pTMData.tm_mday > 31)) {
3303                 MSG_DEBUG("WspLHeaderDecodeDateValue: Date decode fail %d, %d, %d \n", pTMData.tm_wday, pTMData.tm_mon, pTMData.tm_mday);
3304                 strncpy((char*)*pDecodedString, "Decoding Failed", WSP_STANDARD_STR_LEN_MAX-1);
3305                 return;
3306         }
3307
3308 #ifdef MSG_FW_FOR_DEBUG
3309         /** Date type selection */
3310         switch (wspMachineStatus.dateType) {
3311                         /* UNIX asciitime function */
3312                 case UNIX_DATE_TYPE:
3313                         snprintf((char*)decodedString, sizeof(decodedString), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData.tm_wday], wspMonth[pTMData.tm_mon],
3314                                            pTMData.tm_mday, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec, pTMData.tm_year + 1900);
3315                         break;
3316                 case RFC1123_DATE_TYPE:
3317                         snprintf((char*)decodedString, sizeof(decodedString), "%s, %u %s %u %u:%u:%u GMT", wspWeek[pTMData.tm_wday], pTMData.tm_mday,
3318                                            wspMonth[pTMData.tm_mon], pTMData.tm_year + 1900, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec);
3319                         break;
3320                 case RFC850_DATE_TYPE:
3321                         /* Have some Y2K Problems */
3322                         /* In RFC 850, date is represented like 11-May-99. So Y2K problem always can be occured. So remainer (year divided by 100) is used.                     */
3323                         snprintf((char*)decodedString, sizeof(decodedString), "%s, %2u-%s-%2u %u:%u:%u GMT", wspWeekDay[pTMData.tm_wday], pTMData.tm_mday,
3324                                            wspMonth[pTMData.tm_mon], pTMData.tm_year % CENTURY, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec);
3325
3326                         break;
3327         }
3328 #endif
3329         /**UNIX_DATE_TYPE : */
3330         snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s %s %-2u %u:%u:%u %u GMT", wspWeek[pTMData.tm_wday], wspMonth[pTMData.tm_mon],
3331                                                                                         pTMData.tm_mday, pTMData.tm_hour, pTMData.tm_min, pTMData.tm_sec, pTMData.tm_year + 1900);
3332
3333         return;
3334 }
3335
3336 void SmsPluginWapPushHandler::wspHeaderCopyDecodedString(unsigned char* szDecodedString, unsigned long* currentLen, char** pTemper)
3337 {
3338         unsigned long elementLen = AcStrlen((char*)szDecodedString);
3339         char* temper2 = NULL;
3340
3341         /** CR+LF */
3342         *currentLen = *currentLen + elementLen + 2;
3343
3344         if (*currentLen > AcStrlen((char*)* pTemper) + 2) {
3345                 temper2 = new char[(*currentLen + 1)];
3346
3347                 if (temper2 == NULL) {
3348                         MSG_DEBUG("WspLHeaderCopyDecodedString:MemAlloc failed\n");
3349                         return;
3350                 }
3351                 strncpy((char*)temper2, (char*)* pTemper, *currentLen);
3352                 delete[] *pTemper;
3353                 strncpy((char*)temper2, (char*)szDecodedString, *currentLen);
3354         }
3355
3356         *pTemper = temper2;
3357
3358         return;
3359 }
3360
3361
3362 void SmsPluginWapPushHandler::wspHeaderDecodeAuth(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3363 {
3364         unsigned char  userId[WSP_STANDARD_STR_LEN_MAX];
3365         unsigned char  passWd[WSP_STANDARD_STR_LEN_MAX];
3366         unsigned long iField = 0;
3367         char authStr[256];
3368
3369         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX * 2];
3370
3371         if (*pDecodedString == NULL) {
3372                 MSG_DEBUG("WspLHeaderDecodeAuth:MemAlloc failed\n");
3373                 return;
3374         }
3375
3376         /* skip 'basic' code */
3377         iField++;
3378         memset(authStr, 0x00, sizeof(authStr));
3379         snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
3380         sscanf((char*)(fieldValue + iField), authStr, userId);
3381         iField = iField + AcStrlen((char*)userId) + 1;
3382         memset(authStr, 0x00, sizeof(authStr));
3383         snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(passWd));
3384         sscanf((char*)(fieldValue + iField), authStr, passWd);
3385         iField = iField + AcStrlen((char*)userId) + 1;
3386         snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX*2), "basic %s/%s", userId, passWd);
3387
3388         return;
3389 }
3390
3391
3392 void SmsPluginWapPushHandler::wspHeaderDecodeChallenge(unsigned long fieldValueLen, unsigned char* fieldValue, char** pDecodedString)
3393 {
3394         unsigned char userId[WSP_STANDARD_STR_LEN_MAX];
3395         unsigned long iField = 0;
3396         char authStr[256];
3397
3398         *pDecodedString = new char[WSP_STANDARD_STR_LEN_MAX];
3399
3400         if (*pDecodedString == NULL) {
3401                 MSG_DEBUG("WspLHeaderDecodeChallenge:MemAlloc failed\n");
3402                 return;
3403         }
3404
3405         /* skip 'basic' code */
3406         iField++;
3407         memset(authStr, 0x00, sizeof(authStr));
3408         snprintf(authStr, sizeof(authStr), "%%%ds", sizeof(userId));
3409         sscanf((char*)(fieldValue + iField), authStr, userId);
3410         iField = iField + AcStrlen((char*)userId) + 1;
3411
3412         snprintf((char*)*pDecodedString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "basic realm=\"%s\"", userId);
3413
3414         return;
3415 }
3416
3417
3418 void SmsPluginWapPushHandler::wspHeaderDecodeCacheControl(unsigned char* fieldValue, unsigned long fieldValueLen, char** pCacheString)
3419 {
3420         unsigned char  paramString[WSP_STANDARD_STR_LEN_MAX];
3421         unsigned char  cacheCode;
3422
3423         *pCacheString = new char[WSP_STANDARD_STR_LEN_MAX];
3424         if (*pCacheString == NULL) {
3425                 MSG_DEBUG("WspLHeaderDecodeCacheControl:MemAlloc failed\n");
3426                 return;
3427         }
3428
3429         if (1 == fieldValueLen) {
3430                 /* only one directive */
3431                 if (fieldValue[0] > 0x8b) {
3432                         return; /* It's error detection. can be omitted. */
3433                 }
3434                 strncpy((char*)*pCacheString, (char*)wspCacheControl[fieldValue[0] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3435                 return;
3436         }
3437
3438         if (fieldValue[0] > 0x7f) {
3439                 /* directive that has parameter */
3440                 cacheCode = fieldValue[0] & 0x7f;
3441                 switch (cacheCode) {
3442                         /* field name */
3443                         /* no-cache */
3444                 case 0x00 :
3445                         /* private */
3446                 case 0x07 :
3447                         if (fieldValue[1] > 0x7f) {
3448                                 /* well known field name */
3449                                 strncpy((char*)paramString, (char*)wspHeaderFieldName[fieldValue[1] & 0x7f], WSP_STANDARD_STR_LEN_MAX-1);
3450                                 paramString[WSP_STANDARD_STR_LEN_MAX-1] = '\0';
3451                         } else {
3452                                 /* unknown field name */
3453                                 strncpy((char*)paramString, (char*)fieldValue + 1 , WSP_STANDARD_STR_LEN_MAX-1);
3454                         }
3455                         break;
3456                         /* secound */
3457                         /* max-age */
3458                 case 0x02 :
3459                         /* max- stale */
3460                 case 0x03 :
3461                         /* min-fresh */
3462                 case 0x04 :
3463                         snprintf((char*)paramString, sizeof(paramString), "%u", (unsigned int)wspHeaderDecodeInteger(fieldValue + 1));
3464                         break;
3465
3466                 default :
3467                         break;
3468                 }
3469                 snprintf((char*)*pCacheString, (sizeof(char)*WSP_STANDARD_STR_LEN_MAX), "%s=%s", (char*)wspCacheControl[cacheCode], (char*)paramString);
3470         } else {
3471                 /* cache extentions */
3472                 /* In case of come directive of doesn't specified string style */
3473
3474                 unsigned long stringLen;
3475                 char szString[32];
3476                 strncpy((char*)*pCacheString, (char*)fieldValue, WSP_STANDARD_STR_LEN_MAX-1);
3477                 stringLen = AcStrlen((char*)*pCacheString);
3478
3479                 if (stringLen + 1 < fieldValueLen) {
3480                         if (fieldValue[stringLen+ 1] > 0x7f) {
3481                                 int untyped = (int)wspHeaderDecodeIntegerByLength(fieldValue + stringLen + 1, fieldValueLen - (stringLen + 1));
3482
3483                                 snprintf(szString, sizeof(szString), "%d", untyped);
3484                                 strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3485                                 strncat((char*)*pCacheString, (char*)szString, WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3486                         } else {
3487                                 if (fieldValue[fieldValueLen] == 0) {
3488                                         strncat((char*)*pCacheString, (char*)"=", WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3489                                         strncat((char*)*pCacheString, (char*)fieldValue + stringLen + 1 , WSP_STANDARD_STR_LEN_MAX-AcStrlen((char*)*pCacheString)-1);
3490                                 }
3491                         }
3492                 }
3493         }
3494
3495         return;
3496 }
3497
3498 void SmsPluginWapPushHandler::getDisplayName(MSG_SUB_TYPE_T subType, char* displayName)
3499 {
3500         if (subType == MSG_WAP_SL_SMS || subType == MSG_WAP_SI_SMS)
3501                 snprintf(displayName, MAX_ADDRESS_VAL_LEN + 1, "Push message");
3502         return;
3503 }