2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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
8 * http://www.tizenopensource.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.
17 #include "MmsPluginHttp.h"
18 #include "MmsPluginUserAgent.h"
21 #include "MmsPluginConnManWrapper.h"
22 #include <curl/curl.h>
24 static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer);
25 static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen);
26 static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen);
28 static MMS_NET_ERROR_T __httpReceiveData(void *ptr, size_t size, size_t nmemb, void *userdata);
29 static size_t __httpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata);
30 static size_t __httpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata);
32 static int __httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
33 static int __httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
34 static int __httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig);
36 static void __http_print_profile(CURL *curl);
38 /*==================================================================================================
39 FUNCTION IMPLEMENTATION
40 ==================================================================================================*/
41 static void __http_print_profile(CURL *curl)
43 double speed_upload, speed_download, total_time;
44 double size_up, size_down;
45 double content_length;
47 char *content_type = NULL;
54 MSG_DEBUG("**************************************************************************************************");
57 curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total_time);
58 MSG_DEBUG("profile http Time: total %.3f seconds", total_time);
61 curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
62 MSG_DEBUG("profile http Url: %s", url);
65 curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &size_up);
66 MSG_DEBUG("profile http Size: upload %.3f bytes", size_up);
68 curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &size_down);
69 MSG_DEBUG("profile http Size: download %.3f bytes", size_down);
71 curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &size);
72 MSG_DEBUG("profile http Size: header %ld bytes", size);
74 curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &size);
75 MSG_DEBUG("profile http Size: request %ld bytes", size);
78 curl_easy_getinfo(curl, CURLINFO_SPEED_UPLOAD, &speed_upload);
79 MSG_DEBUG("profile http Speed: upload %.3f bytes/sec", speed_upload);
81 curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed_download);
82 MSG_DEBUG("profile http Speed: download %.3f bytes/sec", speed_download);
85 curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &content_type);
86 MSG_DEBUG("profile http Content: type %s", content_type);
88 curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &content_length);
89 MSG_DEBUG("profile http Content: length download %.3f", content_length);
91 curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_UPLOAD, &content_length);
92 MSG_DEBUG("profile http Content: length upload %.3f", content_length);
95 curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip);
96 MSG_DEBUG("profile http primary: ip %s", ip);
98 curl_easy_getinfo(curl, CURLINFO_PRIMARY_PORT, &port);
99 MSG_DEBUG("profile http primary: port %ld", port);
101 curl_easy_getinfo(curl, CURLINFO_LOCAL_IP, &ip);
102 MSG_DEBUG("profile http local: ip %s", ip);
104 curl_easy_getinfo(curl, CURLINFO_LOCAL_PORT, &port);
105 MSG_DEBUG("profile http local: port %ld", port);
107 MSG_DEBUG("**************************************************************************************************");
110 static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen)
112 char szBuffer[1025] = {0, };
113 char pcheader[HTTP_REQUEST_LEN] = {0, };
115 bool nResult = __httpGetHeaderField(MMS_HH_CONTENT_TYPE, szBuffer);
117 snprintf(pcheader, HTTP_REQUEST_LEN, "Content-Type: %s", szBuffer);
118 MSG_DEBUG("%s", pcheader);
119 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
122 if (ulContentLen > 0) {
123 memset(szBuffer, 0, 1025);
124 memset(pcheader, 0, HTTP_REQUEST_LEN);
125 snprintf(szBuffer, 1024, "%d", ulContentLen);
127 snprintf(pcheader, HTTP_REQUEST_LEN, "Content-Length: %s", szBuffer);
128 MSG_DEBUG("%s", pcheader);
129 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
133 memset(szBuffer, 0, 1025);
134 memset(pcheader, 0, HTTP_REQUEST_LEN);
136 __httpGetHost(szUrl, szBuffer, 1024);
137 if (strlen(szBuffer)){
138 snprintf(pcheader, HTTP_REQUEST_LEN, "Host: %s", szBuffer);
139 MSG_DEBUG("%s", pcheader);
140 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
143 memset(szBuffer, 0, 1025);
144 memset(pcheader, 0, HTTP_REQUEST_LEN);
145 nResult = __httpGetHeaderField(MMS_HH_ACCEPT, szBuffer);
147 snprintf(pcheader, HTTP_REQUEST_LEN, "Accept: %s", szBuffer);
148 MSG_DEBUG("%s", pcheader);
149 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
152 memset(szBuffer, 0, 1025);
153 memset(pcheader, 0, HTTP_REQUEST_LEN);
154 nResult = __httpGetHeaderField(MMS_HH_ACCEPT_CHARSET, szBuffer);
156 snprintf(pcheader, HTTP_REQUEST_LEN, "Accept-Charset: %s", szBuffer);
157 MSG_DEBUG("%s", pcheader);
158 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
161 memset(szBuffer, 0, 1025);
162 memset(pcheader, 0, HTTP_REQUEST_LEN);
163 nResult = __httpGetHeaderField(MMS_HH_ACCEPT_LANGUAGE, szBuffer);
165 snprintf(pcheader, HTTP_REQUEST_LEN, "Accept-Language: %s", szBuffer);
166 MSG_DEBUG("%s", pcheader);
167 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
170 memset(szBuffer, 0, 1025);
171 memset(pcheader, 0, HTTP_REQUEST_LEN);
172 nResult = __httpGetHeaderField(MMS_HH_USER_AGENT, szBuffer);
174 snprintf(pcheader, HTTP_REQUEST_LEN, "User-Agent: %s", szBuffer);
175 MSG_DEBUG("%s", pcheader);
176 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
179 memset(szBuffer, 0, 1025);
180 memset(pcheader, 0, HTTP_REQUEST_LEN);
181 nResult = __httpGetHeaderField(MMS_HH_WAP_PROFILE, szBuffer);
183 snprintf(pcheader, HTTP_REQUEST_LEN, "X-wap-profile: %s", szBuffer);
184 MSG_DEBUG("%s", pcheader);
185 *responseHeaders = curl_slist_append(*responseHeaders, pcheader);
188 if (ulContentLen > 0)//if post transaction then Disable 'Expect: 100-contine' option
189 *responseHeaders = curl_slist_append(*responseHeaders, "Expect:");
192 static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer)
197 if (szHeaderBuffer != NULL) {
198 switch (httpHeaderItem) {
199 case MMS_HH_CONTENT_TYPE:
200 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_CONTENT_TYPE);
205 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_ACCEPT);
209 case MMS_HH_ACCEPT_CHARSET:
210 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_CHARSET);
214 case MMS_HH_ACCEPT_LANGUAGE:
215 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_LANGUAGE);
219 case MMS_HH_ACCEPT_ENCODING:
220 snprintf((char *)szHeaderBuffer, 1024, "%s", MSG_MMS_HH_ENCODING);
224 case MMS_HH_USER_AGENT:
226 char szUserAgent[1024 + 1];
228 memset(szUserAgent, 0x00, sizeof(szUserAgent));
229 snprintf(szUserAgent, 1024, "%s", MSG_MMS_HH_USER_AGENT);
231 snprintf((char *)szHeaderBuffer, 1024, "%s", szUserAgent);
236 case MMS_HH_WAP_PROFILE:
238 char szUAProfile[1024 + 1] = {0,};
240 memset(szUAProfile, 0x00, (sizeof(char)*(1024+1) ));
241 snprintf(szUAProfile, 1024, "%s", MSG_MMS_WAP_PROFILE);
243 snprintf((char *)szHeaderBuffer, 1024, "%s", szUAProfile);
249 MSG_DEBUG("invalid param");
257 static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen)
259 if (szUrl == NULL || szHost == NULL)
262 const char *prefixString = "http://";
263 const char *delim = "/\\=@";
265 int prefixLength = strlen(prefixString);
267 char *startPtr = szUrl;
268 char *movePtr = NULL;
270 MSG_DEBUG("startPtr(%s)", startPtr);
272 if (strncasecmp(startPtr, prefixString, prefixLength) == 0) {
273 MSG_DEBUG("(%s) exist", prefixString);
274 startPtr += prefixLength;
276 movePtr = strpbrk(movePtr, delim);
277 MSG_DEBUG("strpbrk --> movePtr(%s)", movePtr);
278 if (movePtr == NULL) {
279 strncpy(szHost, startPtr, nBufferLen);
280 MSG_DEBUG("szHost(%s)", szHost);
282 int nCopyLen = movePtr - startPtr;
283 strncpy(szHost, startPtr, nCopyLen);
284 MSG_DEBUG("szHost(%s)", szHost);
287 MSG_DEBUG("(%s) not exist", prefixString);
289 movePtr = strpbrk(movePtr, delim);
290 MSG_DEBUG("strpbrk --> movePtr(%s)", movePtr);
291 if (movePtr == NULL) {
292 strncpy(szHost, startPtr, nBufferLen);
293 MSG_DEBUG("szHost(%s)", szHost);
295 int nCopyLen = movePtr - startPtr;
296 strncpy(szHost, startPtr, nCopyLen);
297 MSG_DEBUG("szHost(%s)", szHost);
302 static MMS_NET_ERROR_T __httpReceiveData(void *ptr, size_t size, size_t nmemb, void *userdata)
304 MMS_NET_ERROR_T httpRet = eMMS_UNKNOWN;
306 MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance();
307 MMS_PLUGIN_HTTP_CONTEXT_S *pMmsPlgCd = pHttpAgent->getMmsPldCd();
308 long length_received = size * nmemb;
310 if (length_received) {
311 //Save the received buffer in a safe place.
312 if (pMmsPlgCd->final_content_buf == NULL) {
313 MSG_DEBUG("Body Lenghth Read = %d", length_received);
314 pMmsPlgCd->final_content_buf = (unsigned char *)malloc((length_received + 1) * sizeof(unsigned char));
316 if (pMmsPlgCd->final_content_buf == NULL) {
317 MSG_DEBUG("malloc fail");
318 return eMMS_HTTP_EVENT_RECV_DATA_ERROR;
321 memset(pMmsPlgCd->final_content_buf,0x0,((length_received + 1) * sizeof(unsigned char)));
322 MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf);
324 //realloc pHttpEvent->bodyLen extra and memset
326 unsigned char * buf = (unsigned char *)realloc(pMmsPlgCd->final_content_buf,
327 (pMmsPlgCd->bufOffset + length_received + 1) * sizeof(unsigned char));
330 MSG_DEBUG("realloc fail");
331 return eMMS_HTTP_EVENT_RECV_DATA_ERROR;
334 pMmsPlgCd->final_content_buf = buf;
335 MSG_DEBUG("Body Lenghth Read = %d Content Length = %d", length_received, pMmsPlgCd->bufOffset);
336 memset((pMmsPlgCd->final_content_buf +pMmsPlgCd->bufOffset), 0x0,
337 ((length_received + 1) * sizeof(unsigned char)));
338 MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf);
344 if (pMmsPlgCd->final_content_buf != NULL) {
345 memcpy( pMmsPlgCd->final_content_buf + pMmsPlgCd->bufOffset, ptr, length_received);
346 MSG_DEBUG("Current g_bufOffset =%d", pMmsPlgCd->bufOffset);
347 /* Content Received */
348 MSG_DEBUG("Total Content received PTR =%0X, Content Size =%d", pMmsPlgCd->final_content_buf,
349 pMmsPlgCd->bufOffset);
350 pMmsPlgCd->bufOffset = pMmsPlgCd->bufOffset + length_received;
351 httpRet = eMMS_UNKNOWN;
354 MSG_DEBUG("End of Data transfer");
355 MSG_DEBUG("MmsHttpReadData Buffer Size = %d", pMmsPlgCd->bufOffset);
356 MSG_DEBUG("MmsHttpReadData Buffer = %s", pMmsPlgCd->final_content_buf);
358 if (pMmsPlgCd->bufOffset == 0) {
359 /* This is applicable when - M-ReadRec.inf,M-Ack.ind, M-NotifyResp.ind posted */
360 MSG_DEBUG(" Content Size is Zero");
362 if (pMmsPlgCd->final_content_buf != NULL) {
363 free(pMmsPlgCd->final_content_buf );
364 pMmsPlgCd->final_content_buf = NULL;
367 httpRet = eMMS_HTTP_EVENT_SENT_ACK_COMPLETED;
368 } else if (pMmsPlgCd->final_content_buf != NULL && pMmsPlgCd->bufOffset != 0) {
370 MSG_DEBUG(" Send Received Data to UA");
371 httpRet = eMMS_HTTP_RECV_DATA; // eMMS_HTTP_RECV_DATA;
373 httpRet = eMMS_UNKNOWN; // check later
383 static size_t __httpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata)
385 MSG_DEBUG(" ====== HTTP_EVENT_SENT ========");
386 long length_received = size * nmemb;
387 __httpReceiveData(ptr, size, nmemb, userdata);
389 return length_received;
392 static size_t __httpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata)
394 MSG_DEBUG(" ====== HTTP_EVENT_RECEIVED ========");
395 long length_received = size * nmemb;
396 __httpReceiveData(ptr, size, nmemb, userdata);
398 return length_received;
401 static int __httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
403 MSG_DEBUG("HttpCmd Init Session");
405 char proxyAddr[MAX_IPV4_LENGTH + 1] = {0};
407 snprintf(proxyAddr, MAX_IPV4_LENGTH + 1, "%s:%d", httpConfig->mmscConfig.httpProxyIpAddr, httpConfig->mmscConfig.proxyPortNo);
408 MSG_DEBUG("profileId [%d], proxyAddr [%s]", httpConfig->currentProfileId, proxyAddr);
410 CURL *curl_session = curl_easy_init();
411 if (NULL == curl_session) {
412 MSG_DEBUG("curl_easy_init() failed");
413 return eMMS_HTTP_SESSION_OPEN_FAILED;
416 int curl_status = curl_easy_setopt(curl_session, CURLOPT_PROXY, proxyAddr);
417 if (curl_status != CURLM_OK) {
418 MSG_DEBUG("curl_easy_setopt(): CURLOPT_PROXY failed");
419 curl_easy_cleanup(curl_session);
420 return eMMS_HTTP_SESSION_OPEN_FAILED;
423 httpConfig->session = curl_session;
425 return eMMS_HTTP_SESSION_INIT;
429 static int __httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
433 MSG_DEBUG("HttpCmd Post Transaction");
434 MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION");
436 char deviceName[1024] = {0,};
438 MmsPluginCmAgent::instance()->getDeviceName(deviceName);
440 MSG_DEBUG("deviceName: [%s]", deviceName);
441 int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName);
443 if (curl_status != CURLM_OK) {
444 MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed");
446 return eMMS_EXCEPTIONAL_ERROR;
449 CURLcode rc = curl_easy_perform(httpConfig->session);
451 __http_print_profile(httpConfig->session);
453 MmsPluginHttpAgent* httpAgent = MmsPluginHttpAgent::instance();
454 MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData();
455 if (httpConfigData->sessionHeader) {
456 curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader);
457 httpConfigData->sessionHeader = NULL;
460 if (CURLE_OK != rc) {
461 MSG_DEBUG("curl_easy_perform return error rc[%d]", rc);
463 return eMMS_HTTP_ERROR_NETWORK;
466 MSG_DEBUG("## End Transaction ##");
468 srandom((unsigned int) time(NULL));
469 trId = random() % 1000000000 + 1;
470 MSG_DEBUG("############ trID = %d ###########", trId);
472 httpConfig->transactionId = trId;
474 return eMMS_HTTP_SENT_SUCCESS;
477 static int __httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig)
481 MSG_DEBUG("HttpCmd Get Transaction");
482 MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_GET_TRANSACTION");
484 char deviceName[1024] = {0,};
485 MmsPluginCmAgent::instance()->getDeviceName(deviceName);
486 MSG_DEBUG("deviceName: [%s]", deviceName);
488 int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName);
489 if (curl_status != CURLM_OK) {
490 MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed");
492 return eMMS_EXCEPTIONAL_ERROR;
495 CURLcode rc = curl_easy_perform(httpConfig->session);
497 __http_print_profile(httpConfig->session);
499 MmsPluginHttpAgent* httpAgent = MmsPluginHttpAgent::instance();
500 MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData();
501 if (httpConfigData->sessionHeader) {
502 curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader);
503 httpConfigData->sessionHeader = NULL;
506 if (CURLE_OK != rc) {
507 MSG_DEBUG("curl_easy_perform return error = %d", rc);
509 return eMMS_HTTP_ERROR_NETWORK;
512 MSG_DEBUG("## End Transaction ##");
514 srandom((unsigned int) time(NULL));
515 trId = random() % 1000000000 + 1;
516 MSG_DEBUG("############ trID = %d ###########", trId);
518 httpConfig->transactionId = trId;
520 return eMMS_HTTP_SENT_SUCCESS;
523 MmsPluginHttpAgent *MmsPluginHttpAgent::pInstance = NULL;
524 MmsPluginHttpAgent *MmsPluginHttpAgent::instance()
527 pInstance = new MmsPluginHttpAgent();
533 MmsPluginHttpAgent::MmsPluginHttpAgent()
535 MSG_DEBUG("MmsPluginHttpAgent()");
537 bzero(&httpConfigData, sizeof(httpConfigData));
538 bzero(&mmsPlgCd, sizeof(mmsPlgCd));
540 httpCmdHandler.clear();
542 httpCmdHandler[eHTTP_CMD_INIT_SESSION] = &__httpCmdInitSession;
543 httpCmdHandler[eHTTP_CMD_POST_TRANSACTION] = &__httpCmdPostTransaction;
544 httpCmdHandler[eHTTP_CMD_GET_TRANSACTION] = &__httpCmdGetTransaction;
547 MmsPluginHttpAgent::~MmsPluginHttpAgent()
552 void MmsPluginHttpAgent::SetMMSProfile()
556 MMSC_CONFIG_DATA_S *mmscConfig = &(httpConfigData.mmscConfig);
558 MmsPluginCmAgent::instance()->getHomeURL(mmscConfig->mmscUrl);
559 if (strlen(mmscConfig->mmscUrl) < 1) {
560 strcpy(mmscConfig->mmscUrl, DEFAULT_MMSC_URL);
563 MmsPluginCmAgent::instance()->getProxyAddr(mmscConfig->httpProxyIpAddr);
564 mmscConfig->proxyPortNo = MmsPluginCmAgent::instance()->getProxyPort();
569 int MmsPluginHttpAgent::cmdRequest(MMS_HTTP_CMD_TYPE_T cmdType)
571 MSG_DEBUG("cmdRequest:%x", cmdType);
575 ret = httpCmdHandler[cmdType](&httpConfigData);
580 MMS_PLUGIN_HTTP_CONTEXT_S* MmsPluginHttpAgent::getMmsPldCd()
585 MMS_PLUGIN_HTTP_DATA_S *MmsPluginHttpAgent::getHttpConfigData()
587 return &httpConfigData;
590 int MmsPluginHttpAgent::setSession(mmsTranQEntity *qEntity)
592 MSG_DEBUG("%s %d", qEntity->pPostData, qEntity->postDataLen);
594 if (qEntity->eHttpCmdType == eHTTP_CMD_POST_TRANSACTION) {
595 MSG_DEBUG("HttpCmd Post Transaction");
596 MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION");
598 curl_slist *responseHeaders = NULL;
600 __httpAllocHeaderInfo(&responseHeaders, httpConfigData.mmscConfig.mmscUrl, qEntity->postDataLen);
602 MSG_DEBUG(" === MMSCURI = %s === ", httpConfigData.mmscConfig.mmscUrl);
604 httpConfigData.sessionHeader = (void *)responseHeaders;
606 MSG_DEBUG("## Start Transaction : Post ##");
607 curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true);
608 curl_easy_setopt(httpConfigData.session, CURLOPT_POST, true);
609 curl_easy_setopt(httpConfigData.session, CURLOPT_URL, httpConfigData.mmscConfig.mmscUrl);
610 curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true);
611 curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders);
612 curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDS, qEntity->pPostData);
613 curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDSIZE, qEntity->postDataLen);
614 curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, __httpPostTransactionCB);
615 curl_easy_setopt(httpConfigData.session, CURLOPT_TCP_NODELAY, 1);
617 } else if (qEntity->eHttpCmdType == eHTTP_CMD_GET_TRANSACTION) {
618 MSG_DEBUG("MmsHttpInitTransactionGet %d pGetData (%s)", qEntity->getDataLen, qEntity->pGetData);
619 MSG_DEBUG("MmsHttpInitTransactionGet mmscURL (%s) ", httpConfigData.mmscConfig.mmscUrl);
621 char szUrl[MAX_MMSC_URL_LEN] = {0, };
623 memcpy(szUrl, qEntity->pGetData, qEntity->getDataLen);
625 MSG_DEBUG("MmsHttpInitTransactionGet szURL (%s)", szUrl);
627 curl_slist *responseHeaders = NULL;
629 __httpAllocHeaderInfo(&responseHeaders, szUrl, 0);
631 httpConfigData.sessionHeader = (void *)responseHeaders;
633 MSG_DEBUG("## Start Transaction : Get ##");
634 curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true);
635 curl_easy_setopt(httpConfigData.session, CURLOPT_URL, szUrl);
636 curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true);
637 curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders);
638 curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, __httpGetTransactionCB);
640 MSG_DEBUG("Unknown eHttpCmdType [%d]", qEntity->eHttpCmdType);
648 void MmsPluginHttpAgent::clearSession()
652 if (httpConfigData.sessionHeader) {
653 curl_slist_free_all((curl_slist *)httpConfigData.sessionHeader);
654 httpConfigData.sessionHeader = NULL;
657 if (httpConfigData.session == NULL) {
658 MSG_DEBUG("[Error]httpConfigData.session is NULL");
662 curl_easy_cleanup(httpConfigData.session);
664 httpConfigData.session = NULL;