2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license/
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.
19 #include <curl/curl.h>
20 #include "MmsPluginDebug.h"
21 #include "MmsPluginHttp.h"
22 #include "MmsPluginUserAgent.h"
23 #include "MmsPluginConnManWrapper.h"
25 static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer);
26 static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen);
27 static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen);
29 static MMS_NET_ERROR_T __httpReceiveData(void *ptr, size_t size, size_t nmemb, void *userdata);
30 static size_t __httpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata);
31 static size_t __httpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata);
33 static int __httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
34 static int __httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
35 static int __httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
37 static void __http_print_profile(CURL *curl);
39 /*==================================================================================================
40 FUNCTION IMPLEMENTATION
41 ==================================================================================================*/
42 static void __http_print_profile(CURL *curl)
44 double speed_upload, speed_download, total_time;
45 double size_up, size_down;
46 double content_length;
48 char *content_type = NULL;
55 MSG_DEBUG("**************************************************************************************************");
58 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
59 MSG_DEBUG("profile http Time: total %.3f seconds", total_time);
62 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
63 MSG_DEBUG("profile http Url: %s", url);
66 curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &size_up);
67 MSG_DEBUG("profile http Size: upload %.3f bytes", size_up);
69 curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &size_down);
70 MSG_DEBUG("profile http Size: download %.3f bytes", size_down);
72 curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &size);
73 MSG_DEBUG("profile http Size: header %ld bytes", size);
75 curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &size);
76 MSG_DEBUG("profile http Size: request %ld bytes", size);
79 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
80 MSG_DEBUG("profile http Speed: upload %.3f bytes/sec", speed_upload);
82 curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed_download);
83 MSG_DEBUG("profile http Speed: download %.3f bytes/sec", speed_download);
86 curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &content_type);
87 MSG_DEBUG("profile http Content: type %s", content_type);
89 curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &content_length);
90 MSG_DEBUG("profile http Content: length download %.3f", content_length);
92 curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &content_length);
93 MSG_DEBUG("profile http Content: length upload %.3f", content_length);
96 curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
97 MSG_DEBUG("profile http primary: ip %s", ip);
99 curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT, &port);
100 MSG_DEBUG("profile http primary: port %ld", port);
102 curl_easy_getinfo(curl, CURLINFO_LOCAL_IP, &ip);
103 MSG_DEBUG("profile http local: ip %s", ip);
105 curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port);
106 MSG_DEBUG("profile http local: port %ld", port);
108 MSG_DEBUG("**************************************************************************************************");
111 static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen)
113 char szBuffer[1025] = {0, };
114 char pcheader[HTTP_REQUEST_LEN] = {0, };
116 bool nResult = __httpGetHeaderField(MMS_HH_CONTENT_TYPE, szBuffer);
118 snprintf(pcheader, HTTP_REQUEST_LEN, "Content-Type: %s", szBuffer);
119 MSG_DEBUG("%s", pcheader);
120 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
123 if (ulContentLen > 0) {
124 memset(szBuffer, 0, 1025);
125 memset(pcheader, 0, HTTP_REQUEST_LEN);
126 snprintf(szBuffer, 1024, "%d", ulContentLen);
128 snprintf(pcheader, HTTP_REQUEST_LEN, "Content-Length: %s", szBuffer);
129 MSG_DEBUG("%s", pcheader);
130 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
134 memset(szBuffer, 0, 1025);
135 memset(pcheader, 0, HTTP_REQUEST_LEN);
137 __httpGetHost(szUrl, szBuffer, 1024);
138 if (strlen(szBuffer)){
139 snprintf(pcheader, HTTP_REQUEST_LEN, "Host: %s", szBuffer);
140 MSG_DEBUG("%s", pcheader);
141 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
144 memset(szBuffer, 0, 1025);
145 memset(pcheader, 0, HTTP_REQUEST_LEN);
146 nResult = __httpGetHeaderField(MMS_HH_ACCEPT, szBuffer);
148 snprintf(pcheader, HTTP_REQUEST_LEN, "Accept: %s", szBuffer);
149 MSG_DEBUG("%s", pcheader);
150 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
153 memset(szBuffer, 0, 1025);
154 memset(pcheader, 0, HTTP_REQUEST_LEN);
155 nResult = __httpGetHeaderField(MMS_HH_ACCEPT_CHARSET, szBuffer);
157 snprintf(pcheader, HTTP_REQUEST_LEN, "Accept-Charset: %s", szBuffer);
158 MSG_DEBUG("%s", pcheader);
159 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
162 memset(szBuffer, 0, 1025);
163 memset(pcheader, 0, HTTP_REQUEST_LEN);
164 nResult = __httpGetHeaderField(MMS_HH_ACCEPT_LANGUAGE, szBuffer);
166 snprintf(pcheader, HTTP_REQUEST_LEN, "Accept-Language: %s", szBuffer);
167 MSG_DEBUG("%s", pcheader);
168 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
171 memset(szBuffer, 0, 1025);
172 memset(pcheader, 0, HTTP_REQUEST_LEN);
173 nResult = __httpGetHeaderField(MMS_HH_ACCEPT_ENCODING, szBuffer);
175 snprintf(pcheader, HTTP_REQUEST_LEN, "Accept-Encoding: %s", szBuffer);
176 MSG_DEBUG("%s", pcheader);
177 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
180 memset(szBuffer, 0, 1025);
181 memset(pcheader, 0, HTTP_REQUEST_LEN);
182 nResult = __httpGetHeaderField(MMS_HH_USER_AGENT, szBuffer);
184 snprintf(pcheader, HTTP_REQUEST_LEN, "User-Agent: %s", szBuffer);
185 MSG_DEBUG("%s", pcheader);
186 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
189 memset(szBuffer, 0, 1025);
190 memset(pcheader, 0, HTTP_REQUEST_LEN);
191 nResult = __httpGetHeaderField(MMS_HH_WAP_PROFILE, szBuffer);
193 snprintf(pcheader, HTTP_REQUEST_LEN, "X-wap-profile: %s", szBuffer);
194 MSG_DEBUG("%s", pcheader);
195 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
198 if (ulContentLen > 0)//if post transaction then Disable 'Expect: 100-contine' option
199 *responseHeaders = curl_slist_append(*responseHeaders, "Expect:");
202 static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer)
207 if (szHeaderBuffer != NULL) {
208 switch (httpHeaderItem) {
209 case MMS_HH_CONTENT_TYPE:
210 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_CONTENT_TYPE);
215 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_ACCEPT);
219 case MMS_HH_ACCEPT_CHARSET:
220 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_CHARSET);
224 case MMS_HH_ACCEPT_LANGUAGE:
225 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_LANGUAGE);
229 case MMS_HH_ACCEPT_ENCODING:
230 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_ENCODING);
234 case MMS_HH_USER_AGENT:
236 char szUserAgent[1024 + 1];
238 memset(szUserAgent, 0x00, sizeof(szUserAgent));
239 snprintf(szUserAgent, 1024, "%s", MSG_MMS_HH_USER_AGENT);
241 snprintf((char *)szHeaderBuffer, 1024, "%s", szUserAgent);
246 case MMS_HH_WAP_PROFILE:
248 char szUAProfile[1024 + 1] = {0,};
250 memset(szUAProfile, 0x00, (sizeof(char)*(1024+1) ));
251 snprintf(szUAProfile, 1024, "%s", MSG_MMS_WAP_PROFILE);
253 snprintf((char *)szHeaderBuffer, 1024, "%s", szUAProfile);
259 MSG_DEBUG("invalid param");
267 static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen)
269 if (szUrl == NULL || szHost == NULL)
272 const char *prefixString = "http://";
273 const char *delim = "/\\=@";
275 int prefixLength = strlen(prefixString);
277 char *startPtr = szUrl;
278 char *movePtr = NULL;
280 MSG_DEBUG("startPtr(%s)", startPtr);
282 if (strncasecmp(startPtr, prefixString, prefixLength) == 0) {
283 MSG_DEBUG("(%s) exist", prefixString);
284 startPtr += prefixLength;
286 movePtr = strpbrk(movePtr, delim);
287 MSG_DEBUG("strpbrk --> movePtr(%s)", movePtr);
288 if (movePtr == NULL) {
289 strncpy(szHost, startPtr, nBufferLen);
290 MSG_DEBUG("szHost(%s)", szHost);
292 int nCopyLen = movePtr - startPtr;
293 strncpy(szHost, startPtr, nCopyLen);
294 MSG_DEBUG("szHost(%s)", szHost);
297 MSG_DEBUG("(%s) not exist", prefixString);
299 movePtr = strpbrk(movePtr, delim);
300 MSG_DEBUG("strpbrk --> movePtr(%s)", movePtr);
301 if (movePtr == NULL) {
302 strncpy(szHost, startPtr, nBufferLen);
303 MSG_DEBUG("szHost(%s)", szHost);
305 int nCopyLen = movePtr - startPtr;
306 strncpy(szHost, startPtr, nCopyLen);
307 MSG_DEBUG("szHost(%s)", szHost);
312 static MMS_NET_ERROR_T __httpReceiveData(void *ptr, size_t size, size_t nmemb, void *userdata)
314 MMS_NET_ERROR_T httpRet = eMMS_UNKNOWN;
316 MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance();
317 MMS_PLUGIN_HTTP_CONTEXT_S *pMmsPlgCd = pHttpAgent->getMmsPldCd();
318 long length_received = size * nmemb;
320 if (length_received) {
321 //Save the received buffer in a safe place.
322 if (pMmsPlgCd->final_content_buf == NULL) {
323 MSG_DEBUG("Body Lenghth Read = %d", length_received);
324 pMmsPlgCd->final_content_buf = (unsigned char *)malloc((length_received + 1) * sizeof(unsigned char));
326 if (pMmsPlgCd->final_content_buf == NULL) {
327 MSG_DEBUG("malloc fail");
328 return eMMS_HTTP_EVENT_RECV_DATA_ERROR;
331 memset(pMmsPlgCd->final_content_buf,0x0,((length_received + 1) * sizeof(unsigned char)));
332 MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf);
334 //realloc pHttpEvent->bodyLen extra and memset
336 unsigned char * buf = (unsigned char *)realloc(pMmsPlgCd->final_content_buf,
337 (pMmsPlgCd->bufOffset + length_received + 1) * sizeof(unsigned char));
340 MSG_DEBUG("realloc fail");
341 return eMMS_HTTP_EVENT_RECV_DATA_ERROR;
344 pMmsPlgCd->final_content_buf = buf;
345 MSG_DEBUG("Body Lenghth Read = %d Content Length = %d", length_received, pMmsPlgCd->bufOffset);
346 memset((pMmsPlgCd->final_content_buf +pMmsPlgCd->bufOffset), 0x0,
347 ((length_received + 1) * sizeof(unsigned char)));
348 MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf);
354 if (pMmsPlgCd->final_content_buf != NULL) {
355 memcpy( pMmsPlgCd->final_content_buf + pMmsPlgCd->bufOffset, ptr, length_received);
356 MSG_DEBUG("Current g_bufOffset =%d", pMmsPlgCd->bufOffset);
357 /* Content Received */
358 MSG_DEBUG("Total Content received PTR =%0X, Content Size =%d", pMmsPlgCd->final_content_buf,
359 pMmsPlgCd->bufOffset);
360 pMmsPlgCd->bufOffset = pMmsPlgCd->bufOffset + length_received;
361 httpRet = eMMS_UNKNOWN;
364 MSG_DEBUG("End of Data transfer");
365 MSG_DEBUG("MmsHttpReadData Buffer Size = %d", pMmsPlgCd->bufOffset);
366 MSG_DEBUG("MmsHttpReadData Buffer = %s", pMmsPlgCd->final_content_buf);
368 if (pMmsPlgCd->bufOffset == 0) {
369 /* This is applicable when - M-ReadRec.inf,M-Ack.ind, M-NotifyResp.ind posted */
370 MSG_DEBUG(" Content Size is Zero");
372 if (pMmsPlgCd->final_content_buf != NULL) {
373 free(pMmsPlgCd->final_content_buf );
374 pMmsPlgCd->final_content_buf = NULL;
377 httpRet = eMMS_HTTP_EVENT_SENT_ACK_COMPLETED;
378 } else if (pMmsPlgCd->final_content_buf != NULL && pMmsPlgCd->bufOffset != 0) {
380 MSG_DEBUG(" Send Received Data to UA");
381 httpRet = eMMS_HTTP_RECV_DATA; // eMMS_HTTP_RECV_DATA;
383 httpRet = eMMS_UNKNOWN; // check later
393 static size_t __httpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata)
395 MSG_DEBUG(" ====== HTTP_EVENT_SENT ========");
396 long length_received = size * nmemb;
397 __httpReceiveData(ptr, size, nmemb, userdata);
399 return length_received;
402 static size_t __httpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata)
404 MSG_DEBUG(" ====== HTTP_EVENT_RECEIVED ========");
405 long length_received = size * nmemb;
406 __httpReceiveData(ptr, size, nmemb, userdata);
408 return length_received;
411 static int __httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
413 MSG_DEBUG("HttpCmd Init Session");
415 char proxyAddr[MAX_IPV4_LENGTH + 1] = {0};
417 snprintf(proxyAddr, MAX_IPV4_LENGTH + 1, "%s:%d", httpConfig->mmscConfig.httpProxyIpAddr, httpConfig->mmscConfig.proxyPortNo);
418 MSG_DEBUG("profileId [%d], proxyAddr [%s]", httpConfig->currentProfileId, proxyAddr);
420 CURL *curl_session = curl_easy_init();
421 if (NULL == curl_session) {
422 MSG_DEBUG("curl_easy_init() failed");
423 return eMMS_HTTP_SESSION_OPEN_FAILED;
426 int curl_status = curl_easy_setopt(curl_session, CURLOPT_PROXY, proxyAddr);
427 if (curl_status != CURLM_OK) {
428 MSG_DEBUG("curl_easy_setopt(): CURLOPT_PROXY failed");
429 curl_easy_cleanup(curl_session);
430 return eMMS_HTTP_SESSION_OPEN_FAILED;
433 httpConfig->session = curl_session;
435 return eMMS_HTTP_SESSION_INIT;
439 static int __httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
443 MSG_DEBUG("HttpCmd Post Transaction");
444 MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION");
446 char deviceName[1024] = {0,};
448 MmsPluginCmAgent::instance()->getDeviceName(deviceName);
450 MSG_DEBUG("deviceName: [%s]", deviceName);
451 int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName);
453 if (curl_status != CURLM_OK) {
454 MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed");
456 return eMMS_EXCEPTIONAL_ERROR;
459 CURLcode rc = curl_easy_perform(httpConfig->session);
461 __http_print_profile(httpConfig->session);
463 MmsPluginHttpAgent* httpAgent = MmsPluginHttpAgent::instance();
464 MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData();
465 if (httpConfigData->sessionHeader) {
466 curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader);
467 httpConfigData->sessionHeader = NULL;
470 if (CURLE_OK != rc) {
471 MSG_DEBUG("curl_easy_perform return error rc[%d]", rc);
473 return eMMS_HTTP_ERROR_NETWORK;
476 MSG_DEBUG("## End Transaction ##");
478 srandom((unsigned int) time(NULL));
479 trId = random() % 1000000000 + 1;
480 MSG_DEBUG("############ trID = %d ###########", trId);
482 httpConfig->transactionId = trId;
484 return eMMS_HTTP_SENT_SUCCESS;
487 static int __httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
491 MSG_DEBUG("HttpCmd Get Transaction");
492 MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_GET_TRANSACTION");
494 char deviceName[1024] = {0,};
495 MmsPluginCmAgent::instance()->getDeviceName(deviceName);
496 MSG_DEBUG("deviceName: [%s]", deviceName);
498 int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName);
499 if (curl_status != CURLM_OK) {
500 MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed");
502 return eMMS_EXCEPTIONAL_ERROR;
505 CURLcode rc = curl_easy_perform(httpConfig->session);
507 __http_print_profile(httpConfig->session);
509 MmsPluginHttpAgent* httpAgent = MmsPluginHttpAgent::instance();
510 MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData();
511 if (httpConfigData->sessionHeader) {
512 curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader);
513 httpConfigData->sessionHeader = NULL;
516 if (CURLE_OK != rc) {
517 MSG_DEBUG("curl_easy_perform return error = %d", rc);
519 return eMMS_HTTP_ERROR_NETWORK;
522 MSG_DEBUG("## End Transaction ##");
524 srandom((unsigned int) time(NULL));
525 trId = random() % 1000000000 + 1;
526 MSG_DEBUG("############ trID = %d ###########", trId);
528 httpConfig->transactionId = trId;
530 return eMMS_HTTP_SENT_SUCCESS;
533 MmsPluginHttpAgent *MmsPluginHttpAgent::pInstance = NULL;
534 MmsPluginHttpAgent *MmsPluginHttpAgent::instance()
537 pInstance = new MmsPluginHttpAgent();
543 MmsPluginHttpAgent::MmsPluginHttpAgent()
545 MSG_DEBUG("MmsPluginHttpAgent()");
547 bzero(&httpConfigData, sizeof(httpConfigData));
548 bzero(&mmsPlgCd, sizeof(mmsPlgCd));
550 httpCmdHandler.clear();
552 httpCmdHandler[eHTTP_CMD_INIT_SESSION] = &__httpCmdInitSession;
553 httpCmdHandler[eHTTP_CMD_POST_TRANSACTION] = &__httpCmdPostTransaction;
554 httpCmdHandler[eHTTP_CMD_GET_TRANSACTION] = &__httpCmdGetTransaction;
557 MmsPluginHttpAgent::~MmsPluginHttpAgent()
562 void MmsPluginHttpAgent::SetMMSProfile()
566 MMSC_CONFIG_DATA_S *mmscConfig = &(httpConfigData.mmscConfig);
568 MmsPluginCmAgent::instance()->getHomeURL(mmscConfig->mmscUrl);
569 if (strlen(mmscConfig->mmscUrl) < 1) {
570 MSG_DEBUG("##### get Home URL Error");
573 MmsPluginCmAgent::instance()->getProxyAddr(mmscConfig->httpProxyIpAddr);
574 mmscConfig->proxyPortNo = MmsPluginCmAgent::instance()->getProxyPort();
579 int MmsPluginHttpAgent::cmdRequest(MMS_HTTP_CMD_TYPE_T cmdType)
581 MSG_DEBUG("cmdRequest:%x", cmdType);
585 ret = httpCmdHandler[cmdType](&httpConfigData);
590 MMS_PLUGIN_HTTP_CONTEXT_S* MmsPluginHttpAgent::getMmsPldCd()
595 MMS_PLUGIN_HTTP_DATA_S *MmsPluginHttpAgent::getHttpConfigData()
597 return &httpConfigData;
600 int MmsPluginHttpAgent::setSession(mmsTranQEntity *qEntity)
602 MSG_DEBUG("%s %d", qEntity->pPostData, qEntity->postDataLen);
604 if (qEntity->eHttpCmdType == eHTTP_CMD_POST_TRANSACTION) {
605 MSG_DEBUG("HttpCmd Post Transaction");
606 MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION");
608 curl_slist *responseHeaders = NULL;
610 __httpAllocHeaderInfo(&responseHeaders, httpConfigData.mmscConfig.mmscUrl, qEntity->postDataLen);
612 MSG_DEBUG(" === MMSCURI = %s === ", httpConfigData.mmscConfig.mmscUrl);
614 httpConfigData.sessionHeader = (void *)responseHeaders;
616 MSG_DEBUG("## Start Transaction : Post ##");
617 curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true);
618 curl_easy_setopt(httpConfigData.session, CURLOPT_POST, true);
619 curl_easy_setopt(httpConfigData.session, CURLOPT_URL, httpConfigData.mmscConfig.mmscUrl);
620 curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true);
621 curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders);
622 curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDS, qEntity->pPostData);
623 curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDSIZE, qEntity->postDataLen);
624 curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, __httpPostTransactionCB);
625 curl_easy_setopt(httpConfigData.session, CURLOPT_TCP_NODELAY, 1);
627 } else if (qEntity->eHttpCmdType == eHTTP_CMD_GET_TRANSACTION) {
628 MSG_DEBUG("MmsHttpInitTransactionGet %d pGetData (%s)", qEntity->getDataLen, qEntity->pGetData);
629 MSG_DEBUG("MmsHttpInitTransactionGet mmscURL (%s) ", httpConfigData.mmscConfig.mmscUrl);
631 char szUrl[MAX_MMSC_URL_LEN] = {0, };
633 memcpy(szUrl, qEntity->pGetData, qEntity->getDataLen);
635 MSG_DEBUG("MmsHttpInitTransactionGet szURL (%s)", szUrl);
637 curl_slist *responseHeaders = NULL;
639 __httpAllocHeaderInfo(&responseHeaders, szUrl, 0);
641 httpConfigData.sessionHeader = (void *)responseHeaders;
643 MSG_DEBUG("## Start Transaction : Get ##");
644 curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true);
645 curl_easy_setopt(httpConfigData.session, CURLOPT_URL, szUrl);
646 curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true);
647 curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders);
648 curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, __httpGetTransactionCB);
650 MSG_DEBUG("Unknown eHttpCmdType [%d]", qEntity->eHttpCmdType);
658 void MmsPluginHttpAgent::clearSession()
662 if (httpConfigData.sessionHeader) {
663 curl_slist_free_all((curl_slist *)httpConfigData.sessionHeader);
664 httpConfigData.sessionHeader = NULL;
667 if (httpConfigData.session == NULL) {
668 MSG_DEBUG("[Error]httpConfigData.session is NULL");
672 curl_easy_cleanup(httpConfigData.session);
674 httpConfigData.session = NULL;