update tizen source
[framework/messaging/msg-service.git] / plugin / mms_plugin / MmsPluginHttp.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include "MmsPluginHttp.h"
32 #include "MmsPluginUserAgent.h"
33 #include "stdlib.h"
34 #include <time.h>
35 #include "MmsPluginConnManWrapper.h"
36
37
38
39 void httpGetHostFromUrl(char *pUrl, char *pHost)
40 {
41         int hostLen = 0;
42         int tailLen = 0;
43         char *tail = NULL;
44
45         if (strstr(pUrl, "HTTP://") == NULL) {
46                 tail = strstr(pUrl, "/");
47                 if (NULL == tail)
48                         tailLen = 0;
49                 else
50                         tailLen = strlen(tail);
51
52                 hostLen = strlen(pUrl) - tailLen;
53                 memcpy(pHost, pUrl, hostLen);
54                 pHost[hostLen] = '\0';
55         } else {
56                 tail = strstr(&pUrl[7], "/");
57                 if (NULL == tail)
58                         tailLen = 0;
59                 else
60                         tailLen = strlen(tail);
61
62                 hostLen = strlen(pUrl) - tailLen - 7;
63                 memcpy(pHost, &pUrl[7], hostLen);
64                 pHost[hostLen] = '\0';
65         }
66 }
67
68 void  HttpHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen)
69 {
70         char szBuffer[1025] = {0, };
71         char pcheader[HTTP_REQUEST_LEN] = {0, };
72
73         bool nResult = MsgMmsGetCustomHTTPHeader(MMS_HH_CONTENT_TYPE, szBuffer);
74         if (nResult) {
75                 strcat(pcheader,"Content-Type: ");
76                 strcat(pcheader, szBuffer);
77                 MSG_DEBUG("%s", pcheader);
78                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
79         }
80
81         memset(szBuffer, 0, 1025);
82         memset(pcheader, 0, HTTP_REQUEST_LEN);
83         snprintf(szBuffer, 1024, "%d", ulContentLen);
84         if (nResult) {
85                 strcat(pcheader, "Content-Length: ");
86                 strcat(pcheader, szBuffer);
87                 MSG_DEBUG("%s", pcheader);
88                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
89         }
90
91         memset(szBuffer, 0, 1025);
92         memset(pcheader, 0, HTTP_REQUEST_LEN);
93         nResult = MsgMmsGetCustomHTTPHeader(MMS_HH_HOST, szBuffer);
94         if (nResult) {
95                 strcat(pcheader, "HOST: ");
96                 strcat(pcheader, szBuffer);
97                 MSG_DEBUG("%s", pcheader);
98                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
99         }
100
101         memset(szBuffer, 0, 1025);
102         memset(pcheader, 0, HTTP_REQUEST_LEN);
103         nResult = MsgMmsGetCustomHTTPHeader(MMS_HH_ACCEPT, szBuffer);
104         if (nResult) {
105                 strcat(pcheader, "Accept: ");
106                 strcat(pcheader, szBuffer);
107                 MSG_DEBUG("%s", pcheader);
108                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
109         }
110
111         memset(szBuffer, 0, 1025);
112         memset(pcheader, 0, HTTP_REQUEST_LEN);
113         nResult = MsgMmsGetCustomHTTPHeader(MMS_HH_ACCEPT_CHARSET, szBuffer);
114         if (nResult) {
115                 strcat(pcheader, "Accept-Charset: ");
116                 strcat(pcheader, szBuffer);
117                 MSG_DEBUG("%s", pcheader);
118                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
119         }
120
121         memset(szBuffer, 0, 1025);
122         memset(pcheader, 0, HTTP_REQUEST_LEN);
123         nResult = MsgMmsGetCustomHTTPHeader(MMS_HH_ACCEPT_LANGUAGE, szBuffer);
124         if (nResult) {
125                 strcat(pcheader, "Accept-Language: ");
126                 strcat(pcheader, szBuffer);
127                 MSG_DEBUG("%s", pcheader);
128                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
129         }
130
131         memset(szBuffer, 0, 1025);
132         memset(pcheader, 0, HTTP_REQUEST_LEN);
133         nResult = MsgMmsGetCustomHTTPHeader(MMS_HH_ACCEPT_ENCODING, szBuffer);
134         if (nResult) {
135                 strcat(pcheader, "Accept-Encoding: ");
136                 strcat(pcheader, szBuffer);
137                 MSG_DEBUG("%s", pcheader);
138                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
139         }
140
141         memset(szBuffer, 0, 1025);
142         memset(pcheader, 0, HTTP_REQUEST_LEN);
143         nResult = MsgMmsGetCustomHTTPHeader(MMS_HH_USER_AGENT, szBuffer);
144         if (nResult) {
145                 strcat(pcheader, "User-Agent: ");
146                 strcat(pcheader, szBuffer);
147                 MSG_DEBUG("%s", pcheader);
148                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
149         }
150
151         memset(szBuffer, 0, 1025);
152         memset(pcheader, 0, HTTP_REQUEST_LEN);
153         nResult = MsgMmsGetCustomHTTPHeader(MMS_HH_WAP_PROFILE, szBuffer);
154         if (nResult) {
155                 strcat(pcheader, "X-wap-profile: ");
156                 strcat(pcheader, szBuffer);
157                 MSG_DEBUG("%s", pcheader);
158                 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
159         }
160 }
161
162 bool MsgMmsGetCustomHTTPHeader(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer)
163 {
164         bool result;
165
166         result = false;
167         if (szHeaderBuffer != NULL) {
168                 switch (httpHeaderItem) {
169                 case MMS_HH_CONTENT_TYPE:
170                         snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_CONTENT_TYPE);
171                         result = true;
172                         break;
173
174                 case MMS_HH_HOST:
175                         MsgMmsGetHost(szHeaderBuffer, 1024);
176                         if (strlen(szHeaderBuffer) > 0)
177                                 result = true;
178                         else
179                                 result = false;
180                         break;
181
182                 case MMS_HH_ACCEPT:
183                         snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_ACCEPT);
184                         result = true;
185                         break;
186
187                 case MMS_HH_ACCEPT_CHARSET:
188                         snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_CHARSET);
189                         result = true;
190                         break;
191
192                 case MMS_HH_ACCEPT_LANGUAGE:
193                         snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_LANGUAGE);
194                         result = true;
195                         break;
196
197                 case MMS_HH_ACCEPT_ENCODING:
198                         snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_ENCODING);
199                         result = true;
200                         break;
201
202                 case MMS_HH_USER_AGENT:
203                         {
204                                 char szUserAgent[1024 + 1] = {0,};
205
206                                 memset(szUserAgent, 0x00, (sizeof(char) * (1024 + 1) ));
207                                 snprintf(szUserAgent, 1024, "%s", MSG_MMS_HH_USER_AGENT);
208
209                                 snprintf((char *)szHeaderBuffer, 1024, "%s", szUserAgent);
210                                 result = true;
211                         }
212                         break;
213
214                 case MMS_HH_WAP_PROFILE:
215                         {
216                                 char szUAProfile[1024 + 1] = {0,};
217
218                                 memset(szUAProfile, 0x00, (sizeof(char)*(1024+1) ));
219                                 snprintf(szUAProfile, 1024, "%s", MSG_MMS_WAP_PROFILE);
220
221                                 snprintf((char *)szHeaderBuffer, 1024, "%s", szUAProfile);
222                                 result = true;
223                         }
224                         break;
225
226                 default:
227                         MSG_DEBUG("invalid param");
228                         break;
229                 }
230         }
231
232         return result;
233 }
234
235 void MsgMmsGetHost(char *szHost, int nBufferLen)
236 {
237         MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance();
238         MMS_PLUGIN_HTTP_DATA_S *httpConfigData = pHttpAgent->getHttpConfigData();
239
240         const char *prefixString = "http://";
241         const char *delim = ":/\\=@";
242
243         int prefixLength = strlen(prefixString);
244
245         char *startPtr = &httpConfigData->mmscConfig.mmscUrl[0];
246         char *movePtr = NULL;
247
248         MSG_DEBUG("startPtr(%s)", startPtr);
249
250         if (strncasecmp(startPtr, prefixString, prefixLength) == 0) {
251                 MSG_DEBUG("(%s) exist", prefixString);
252                 startPtr += prefixLength;
253                 movePtr = startPtr;
254                 movePtr = strpbrk(movePtr, delim);
255                 MSG_DEBUG("strpbrk --> movePtr(%s)", movePtr);
256                 if (movePtr == NULL) {
257                         strncpy(szHost, startPtr, nBufferLen);
258                         MSG_DEBUG("szHost(%s)", szHost);
259                 } else {
260                         int nCopyLen = movePtr - startPtr;
261                         strncpy(szHost, startPtr, nCopyLen);
262                         MSG_DEBUG("szHost(%s)", szHost);
263                 }
264         } else {
265                 MSG_DEBUG("(%s) not exist", prefixString);
266                 movePtr = startPtr;
267                 movePtr = strpbrk(movePtr, delim);
268                 MSG_DEBUG("strpbrk --> movePtr(%s)", movePtr);
269                 if (movePtr == NULL) {
270                         strncpy(szHost, startPtr, nBufferLen);
271                         MSG_DEBUG("szHost(%s)", szHost);
272                 } else {
273                         int nCopyLen = movePtr - startPtr;
274                         strncpy(szHost, startPtr, nCopyLen);
275                         MSG_DEBUG("szHost(%s)", szHost);
276                 }
277         }
278 }
279
280
281 MMS_NET_ERROR_T MmsHttpReadData(void *ptr, size_t size, size_t nmemb, void *userdata)
282 {
283         MMS_NET_ERROR_T httpRet = eMMS_UNKNOWN;
284
285         MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance();
286         MMS_PLUGIN_HTTP_CONTEXT_S *pMmsPlgCd = pHttpAgent->getMmsPldCd();
287         long length_received = size * nmemb;
288
289         if (length_received) {
290                 //Save the received buffer in a safe place.
291                 if (pMmsPlgCd->final_content_buf == NULL) {
292                         MSG_DEBUG("Body Lenghth Read = %d", length_received);
293                         pMmsPlgCd->final_content_buf = (unsigned char *)malloc((length_received + 1) * sizeof(unsigned char));
294                         memset(pMmsPlgCd->final_content_buf,0x0,((length_received + 1) * sizeof(unsigned char)));
295                         MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf);
296                 } else {
297                         //realloc pHttpEvent->bodyLen extra and memset
298                         pMmsPlgCd->final_content_buf = (unsigned char *)realloc(pMmsPlgCd->final_content_buf,
299                                         (pMmsPlgCd->bufOffset + length_received + 1) * sizeof(unsigned char));
300                         MSG_DEBUG("Body Lenghth Read = %d Content Length = %d", length_received, pMmsPlgCd->bufOffset);
301                         memset((pMmsPlgCd->final_content_buf +pMmsPlgCd->bufOffset), 0x0,
302                                         ((length_received + 1) * sizeof(unsigned char)));
303                         MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf);
304                 }
305
306                 //copy body
307                 if (pMmsPlgCd->final_content_buf != NULL) {
308                         memcpy( pMmsPlgCd->final_content_buf + pMmsPlgCd->bufOffset, ptr, length_received);
309                         MSG_DEBUG("Current g_bufOffset =%d", pMmsPlgCd->bufOffset);
310                         /*  Content  Received */
311                         MSG_DEBUG("Total Content received PTR =%0X, Content Size =%d", pMmsPlgCd->final_content_buf,
312                                                 pMmsPlgCd->bufOffset);
313                         pMmsPlgCd->bufOffset = pMmsPlgCd->bufOffset + length_received;
314                         httpRet = eMMS_UNKNOWN;
315                 }
316         } else {
317                 MSG_DEBUG("End of Data transfer");
318                 MSG_DEBUG("MmsHttpReadData Buffer Size = %d", pMmsPlgCd->bufOffset);
319                 MSG_DEBUG("MmsHttpReadData Buffer = %s", pMmsPlgCd->final_content_buf);
320
321                 if (pMmsPlgCd->bufOffset == 0) {
322                         /*  This is applicable when - M-ReadRec.inf,M-Ack.ind, M-NotifyResp.ind posted  */
323                         MSG_DEBUG(" Content Size is Zero");
324
325                         if (pMmsPlgCd->final_content_buf != NULL) {
326                         free(pMmsPlgCd->final_content_buf );
327                                 pMmsPlgCd->final_content_buf = NULL;
328                 }
329
330                         httpRet = eMMS_HTTP_EVENT_SENT_ACK_COMPLETED;
331                 } else if (pMmsPlgCd->final_content_buf != NULL && pMmsPlgCd->bufOffset != 0) {
332                         // Process Http Data
333                         MSG_DEBUG(" Send Received Data to UA");
334                         httpRet = eMMS_HTTP_RECV_DATA; // eMMS_HTTP_RECV_DATA;
335                 } else {
336                         httpRet = eMMS_UNKNOWN; // check later
337                 }
338
339                 return httpRet;
340         }
341
342         return httpRet;
343 }
344
345
346 size_t  MmsHttpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata)
347 {
348         MSG_DEBUG(" ======  HTTP_EVENT_SENT ========");
349         long length_received = size * nmemb;
350         MmsHttpReadData(ptr, size, nmemb, userdata);
351
352         return length_received;
353 }
354
355 size_t  MmsHttpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata)
356 {
357         MSG_DEBUG(" ======  HTTP_EVENT_RECEIVED ========");
358         long length_received = size * nmemb;
359         MmsHttpReadData(ptr, size, nmemb, userdata);
360
361         return length_received;
362 }
363
364 int httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
365 {
366         MSG_DEBUG("HttpCmd Init Session");
367
368         char proxyAddr[MAX_IPV4_LENGTH + 1] = {0};
369
370         snprintf(proxyAddr, MAX_IPV4_LENGTH + 1, "%s:%d", httpConfig->mmscConfig.httpProxyIpAddr, httpConfig->mmscConfig.proxyPortNo);
371         MSG_DEBUG("profileId [%d], proxyAddr [%s]", httpConfig->currentProfileId, proxyAddr);
372
373         CURL *curl_session = curl_easy_init();
374         if (NULL == curl_session) {
375                 MSG_DEBUG("curl_easy_init() failed");
376                 return eMMS_HTTP_SESSION_OPEN_FAILED;
377         }
378
379         int curl_status = curl_easy_setopt(curl_session, CURLOPT_PROXY, proxyAddr);
380         if (curl_status != CURLM_OK) {
381                 MSG_DEBUG("curl_easy_setopt(): CURLOPT_PROXY failed");
382                 curl_easy_cleanup(curl_session);
383                 return eMMS_HTTP_SESSION_OPEN_FAILED;
384         }
385
386         httpConfig->session = curl_session;
387
388         return eMMS_HTTP_SESSION_INIT;
389 }
390
391
392 int httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
393 {
394         int trId;
395
396         MSG_DEBUG("HttpCmd Post Transaction");
397         MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION");
398
399         char deviceName[1024] = {0,};
400
401         MmsPluginCmAgent::instance()->getDeviceName(deviceName);
402
403         MSG_DEBUG("deviceName: [%s]", deviceName);
404         int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName);
405
406         if (curl_status != CURLM_OK) {
407                 MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed");
408
409                 return eMMS_EXCEPTIONAL_ERROR;
410         }
411
412         MSG_PROFILE_BEGIN(libcurl);
413
414         CURLcode rc = curl_easy_perform(httpConfig->session);
415
416         MSG_PROFILE_END(libcurl);
417
418         MmsPluginHttpAgent*     httpAgent = MmsPluginHttpAgent::instance();
419         MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData();
420         if (httpConfigData->sessionHeader) {
421                 curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader);
422                 httpConfigData->sessionHeader = NULL;
423         }
424
425         if (CURLE_OK != rc) {
426                 MSG_DEBUG("curl_easy_perform return error rc[%d]", rc);
427
428                 return eMMS_HTTP_ERROR_NETWORK;
429         }
430
431         MSG_DEBUG("## End Transaction ##");
432         MSG_DEBUG("############ trID = %d ###########", trId);
433
434         srandom((unsigned int) time(NULL));
435         trId = random() % 1000000000 + 1;
436
437         httpConfig->transactionId = trId;
438
439         return eMMS_HTTP_SENT_SUCCESS;
440 }
441
442 int httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
443 {
444         int trId;
445
446         MSG_DEBUG("HttpCmd Get Transaction");
447         MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_GET_TRANSACTION");
448
449         char deviceName[1024] = {0,};
450         MmsPluginCmAgent::instance()->getDeviceName(deviceName);
451         MSG_DEBUG("deviceName: [%s]", deviceName);
452
453         int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName);
454         if (curl_status != CURLM_OK) {
455                 MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed");
456
457                 return eMMS_EXCEPTIONAL_ERROR;
458         }
459
460         CURLcode rc = curl_easy_perform(httpConfig->session);
461
462         MmsPluginHttpAgent*     httpAgent = MmsPluginHttpAgent::instance();
463         MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData();
464         if (httpConfigData->sessionHeader) {
465                 curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader);
466                 httpConfigData->sessionHeader = NULL;
467         }
468
469         if (CURLE_OK != rc) {
470                 MSG_DEBUG("curl_easy_perform return error = %d", rc);
471
472                 return eMMS_HTTP_ERROR_NETWORK;
473         }
474
475         MSG_DEBUG("## End Transaction ##");
476         MSG_DEBUG("############ trID = %d ###########", trId);
477         srandom((unsigned int) time(NULL));
478         trId = random() % 1000000000 + 1;
479         httpConfig->transactionId = trId;
480
481         return eMMS_HTTP_SENT_SUCCESS;
482 }
483
484 MmsPluginHttpAgent *MmsPluginHttpAgent::pInstance = NULL;
485 MmsPluginHttpAgent *MmsPluginHttpAgent::instance()
486 {
487         if (!pInstance)
488                 pInstance = new MmsPluginHttpAgent();
489
490         return pInstance;
491 }
492
493
494 MmsPluginHttpAgent::MmsPluginHttpAgent()
495 {
496         MSG_DEBUG("MmsPluginHttpAgent()");
497
498         bzero(&httpConfigData, sizeof(httpConfigData));
499         bzero(&mmsPlgCd, sizeof(mmsPlgCd));
500
501         httpCmdHandler.clear();
502
503         waiting = false;
504
505         httpCmdHandler[eHTTP_CMD_INIT_SESSION] = &httpCmdInitSession;
506         httpCmdHandler[eHTTP_CMD_POST_TRANSACTION] = &httpCmdPostTransaction;
507         httpCmdHandler[eHTTP_CMD_GET_TRANSACTION] = &httpCmdGetTransaction;
508 }
509
510 MmsPluginHttpAgent::~MmsPluginHttpAgent()
511 {
512
513 }
514
515 void MmsPluginHttpAgent::SetMMSProfile()
516 {
517         MSG_BEGIN();
518
519         MMSC_CONFIG_DATA_S *mmscConfig = &(httpConfigData.mmscConfig);
520
521         MmsPluginCmAgent::instance()->getHomeURL(mmscConfig->mmscUrl);
522         if (strlen(mmscConfig->mmscUrl) < 1) {
523                 strcpy(mmscConfig->mmscUrl, DEFAULT_MMSC_URL);
524         }
525
526         MmsPluginCmAgent::instance()->getProxyAddr(mmscConfig->httpProxyIpAddr);
527         mmscConfig->proxyPortNo = MmsPluginCmAgent::instance()->getProxyPort();
528
529         MSG_END();
530 }
531
532 int MmsPluginHttpAgent::cmdRequest(MMS_HTTP_CMD_TYPE_T cmdType)
533 {
534         MSG_DEBUG("cmdRequest:%x", cmdType);
535
536         int ret = 0;
537
538         ret = httpCmdHandler[cmdType](&httpConfigData);
539
540         return ret;
541 }
542
543 MMS_PLUGIN_HTTP_CONTEXT_S* MmsPluginHttpAgent::getMmsPldCd()
544 {
545         return &mmsPlgCd;
546 }
547
548 MMS_PLUGIN_HTTP_DATA_S *MmsPluginHttpAgent::getHttpConfigData()
549 {
550         return &httpConfigData;
551 }
552
553 void MmsPluginHttpAgent::setHttpWaitingFlag(bool val)
554 {
555         waiting = val;
556 }
557
558 bool MmsPluginHttpAgent::getHttpWaitingFlag()
559 {
560         return waiting;
561 }
562
563
564 int MmsPluginHttpAgent::setSession(mmsTranQEntity *qEntity)
565 {
566         MSG_DEBUG("%s %d", qEntity->pPostData, qEntity->postDataLen);
567
568         if (qEntity->eHttpCmdType == eHTTP_CMD_POST_TRANSACTION) {
569                 MSG_DEBUG("HttpCmd Post Transaction");
570                 MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION");
571
572                 curl_slist *responseHeaders = NULL;
573
574                 HttpHeaderInfo(&responseHeaders, NULL, qEntity->postDataLen);
575                 responseHeaders = curl_slist_append(responseHeaders, "Pragma: ");
576                 responseHeaders = curl_slist_append(responseHeaders, "Proxy-Connection: ");
577                 responseHeaders = curl_slist_append(responseHeaders, "Expect: ");
578                 MSG_DEBUG(" === MMSCURI = %s === ", httpConfigData.mmscConfig.mmscUrl);
579
580                 httpConfigData.sessionHeader = (void *)responseHeaders;
581
582                 MSG_DEBUG("## Start Transaction : Post ##");
583                 curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true);
584                 curl_easy_setopt(httpConfigData.session, CURLOPT_POST, true);
585                 curl_easy_setopt(httpConfigData.session, CURLOPT_URL, httpConfigData.mmscConfig.mmscUrl);
586                 curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true);
587                 curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders);
588                 curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDS, qEntity->pPostData);
589                 curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDSIZE, qEntity->postDataLen);
590                 curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, MmsHttpPostTransactionCB);
591
592                 curl_easy_setopt(httpConfigData.session, CURLOPT_TCP_NODELAY, 1);
593         } else if (qEntity->eHttpCmdType == eHTTP_CMD_GET_TRANSACTION) {
594                 MSG_DEBUG("MmsHttpInitTransactionGet  %d pGetData (%s)", qEntity->getDataLen, qEntity->pGetData);
595                 MSG_DEBUG("MmsHttpInitTransactionGet  mmscURL (%s) ", httpConfigData.mmscConfig.mmscUrl);
596
597                 char szUrl[MAX_MMSC_URL_LEN] = {0, };
598
599                 memcpy(szUrl, qEntity->pGetData, qEntity->getDataLen);
600
601                 MSG_DEBUG("MmsHttpInitTransactionGet  szURL (%s)", szUrl);
602
603                 curl_slist *responseHeaders = NULL;
604
605                 HttpHeaderInfo(&responseHeaders, szUrl, 0);
606                 responseHeaders = curl_slist_append(responseHeaders, "Pragma: ");
607                 responseHeaders = curl_slist_append(responseHeaders, "Proxy-Connection: ");
608
609                 httpConfigData.sessionHeader = (void *)responseHeaders;
610
611                 MSG_DEBUG("## Start Transaction : Get ##");
612                 curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true);
613                 curl_easy_setopt(httpConfigData.session, CURLOPT_URL, szUrl);
614                 curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true);
615                 curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders);
616                 curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, MmsHttpGetTransactionCB);
617         } else {
618                 MSG_DEBUG("Unknown eHttpCmdType [%d]", qEntity->eHttpCmdType);
619                 return -1;
620         }
621
622         return 0;
623 }
624
625
626 void MmsPluginHttpAgent::clearSession()
627 {
628         MSG_BEGIN();
629
630         if (httpConfigData.sessionHeader) {
631                 curl_slist_free_all((curl_slist *)httpConfigData.sessionHeader);
632                 httpConfigData.sessionHeader = NULL;
633         }
634
635         if (httpConfigData.session == NULL) {
636                 MSG_DEBUG("[Error]httpConfigData.session is NULL");
637                 return;
638         }
639
640         curl_easy_cleanup(httpConfigData.session);
641
642         httpConfigData.session = NULL;
643
644         MSG_END();
645 }