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