From 22239f0909233b37275047a8c553570ab9f2bce6 Mon Sep 17 00:00:00 2001 From: Seunghwan Lee Date: Tue, 24 Sep 2013 13:42:36 +0900 Subject: [PATCH] MMS ConnManWrapper UserAgent Http sync to private Change-Id: I06362fe59c01d81acac73fc81938086d346c3bee --- include/common/MsgQueue.h | 14 + include/utils/MsgDebug.h | 43 +- include/utils/MsgException.h | 1 + msg-service.rule | 10 +- packaging/msg-service.spec | 1 + plugin/mms_plugin/CMakeLists.txt | 2 +- plugin/mms_plugin/MmsPluginConnManWrapper.cpp | 718 +++++++++++++-------- plugin/mms_plugin/MmsPluginHttp.cpp | 567 ++++++++-------- plugin/mms_plugin/MmsPluginUserAgent.cpp | 164 ++--- .../mms_plugin/include/MmsPluginConnManWrapper.h | 25 +- plugin/mms_plugin/include/MmsPluginHttp.h | 63 +- 11 files changed, 945 insertions(+), 663 deletions(-) diff --git a/include/common/MsgQueue.h b/include/common/MsgQueue.h index 562994a..82ccfed 100755 --- a/include/common/MsgQueue.h +++ b/include/common/MsgQueue.h @@ -32,6 +32,7 @@ public: int size(); bool empty(); void clear(); + bool checkExist(T const & qItem, bool(cmp)(T const &, T const &)); private: Mutex mx; std::list q; @@ -94,5 +95,18 @@ template void MsgThdSafeQ::clear() q.clear(); } +template bool MsgThdSafeQ::checkExist(T const & qItem, bool(cmp)(T const &, T const &)) +{ + MutexLocker lock(mx); + + for(typename list::iterator iterPos = q.begin(); iterPos != q.end(); ++iterPos) { + + if (cmp(qItem, *iterPos) == true) + return true; + } + + return false; +} + #endif // __MsgThdSafeQ_H__ diff --git a/include/utils/MsgDebug.h b/include/utils/MsgDebug.h index f609cf7..98d44e7 100755 --- a/include/utils/MsgDebug.h +++ b/include/utils/MsgDebug.h @@ -78,8 +78,47 @@ int get_tid(); do\ {\ SLOGD(" END <<<< \n\n");\ - } \ - while( 0 ) + } while( 0 ) + +#define MSG_INFO(fmt, args...)\ + do\ + {\ + SLOGI("* Info * " fmt "\n\n", ##args);\ + } while( 0 ) + +#define MSG_WARN(fmt, args...)\ + do {\ + SLOGW("* Warning * " fmt "\n\n", ##args)\ + } while( 0 ) + +#define MSG_ERR(fmt, args...)\ + do {\ + SLOGE("* Error * " fmt "\n\n", ##args);\ + } while( 0 ) + + +#define MSG_ERR_RET_VM(expr, val, fmt, arg...)\ + do {\ + if (expr) {\ + MSG_ERR(fmt, ##arg);\ + return (val);\ + }\ + } while (0) + +#define MSG_ERR_RET_M(expr, fmt, arg...)\ + do {\ + if (expr) {\ + MSG_ERR(fmt, ##arg);\ + return;\ + }\ + } while (0) + +#define MSG_WARN_M(expr, fmt, arg...)\ + do {\ + if (expr) {\ + MSG_WARN(fmt, ##arg);\ + }\ + } while (0) #define MSG_PROFILE_BEGIN(pfid) \ unsigned int __prf_l1_##pfid = __LINE__; \ diff --git a/include/utils/MsgException.h b/include/utils/MsgException.h index ad1ab20..23ef2c7 100755 --- a/include/utils/MsgException.h +++ b/include/utils/MsgException.h @@ -69,6 +69,7 @@ public: SECURITY_ERROR, SERVER_READY_ERROR = 13, + REQ_EXIST_ERROR, // dont erase NUM_ERRORS. place a new error code in ahead of NUM_ERRORS NUM_ERRORS }; diff --git a/msg-service.rule b/msg-service.rule index 3666607..6f5203a 100644 --- a/msg-service.rule +++ b/msg-service.rule @@ -27,8 +27,16 @@ msg-service data-provider-master::badge.client w msg-service oma-dm-agent::vconf_external r -msg-servive deviced::display rw +msg-service deviced::display rw org.tizen.quickpanel msg-service rx org.tizen.indicator msg-service rwx org.tizen.lockscreen msg-service rx + +msg-service net-config rw +msg-service connman rw + +net-config msg-service rw +connman msg-service rw + +system::use_internet msg-service rw \ No newline at end of file diff --git a/packaging/msg-service.spec b/packaging/msg-service.spec index 336bab8..21452ab 100755 --- a/packaging/msg-service.spec +++ b/packaging/msg-service.spec @@ -43,6 +43,7 @@ BuildRequires: pkgconfig(svi) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(feedback) +BuildRequires: pkgconfig(capi-network-connection) %description Description: Messaging Framework Library diff --git a/plugin/mms_plugin/CMakeLists.txt b/plugin/mms_plugin/CMakeLists.txt index ee1f975..a0f874a 100755 --- a/plugin/mms_plugin/CMakeLists.txt +++ b/plugin/mms_plugin/CMakeLists.txt @@ -45,7 +45,7 @@ INCLUDE_DIRECTORIES( ) INCLUDE(FindPkgConfig) -pkg_check_modules(mms_plugin_pkgs REQUIRED glib-2.0 network libxml-2.0 drm-client libcurl mm-fileinfo mmutil-jpeg vconf dlog media-thumbnail) +pkg_check_modules(mms_plugin_pkgs REQUIRED glib-2.0 network libxml-2.0 drm-client libcurl mm-fileinfo mmutil-jpeg vconf dlog media-thumbnail capi-network-connection) FOREACH(flag ${mms_plugin_pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/plugin/mms_plugin/MmsPluginConnManWrapper.cpp b/plugin/mms_plugin/MmsPluginConnManWrapper.cpp index 3e26517..5dac38c 100755 --- a/plugin/mms_plugin/MmsPluginConnManWrapper.cpp +++ b/plugin/mms_plugin/MmsPluginConnManWrapper.cpp @@ -17,122 +17,353 @@ #include #include "MmsPluginConnManWrapper.h" #include "MmsPluginDebug.h" +#include "MmsPluginHttp.h" +#include +#include "net_connection.h" -void network_print_profile(net_profile_info_t *ProfInfo) +#define MMS_CONTEXT_INVOKE_WAIT_TIME 30 +#define MMS_CONNECTION_API_WAIT_TIME 50 + +#define MMS_FREE(obj)\ + if (obj){\ + free(obj);\ + obj = NULL;\ + } + + +static Mutex g_mx; +static CndVar g_cv; +static connection_h connection = NULL; + +void __connection_profile_print(connection_profile_h profile) { - int di = 0; - - unsigned char *ipaddr; - unsigned char *netmaskaddr; - unsigned char *gwaddr; - net_dev_info_t *net_info; - - if (ProfInfo->profile_type == NET_DEVICE_CELLULAR) { - ipaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.IpAddr.Data.Ipv4.s_addr; - netmaskaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.SubnetMask.Data.Ipv4.s_addr; - gwaddr = (unsigned char *)&ProfInfo->ProfileInfo.Pdp.net_info.GatewayAddr.Data.Ipv4.s_addr; - net_info = &(ProfInfo->ProfileInfo.Pdp.net_info); + int ret; + char *profile_id = NULL; + char *profile_name = NULL; + char *interface_name = NULL; + char *ip_address = NULL; + char *subnet_mask = NULL; + char *gateway_address = NULL; + char *dns_address = NULL; + char *proxy_address = NULL; + char *apn = NULL; + char *user_name = NULL; + char *password = NULL; + char *home_url = NULL; + bool is_roaming; + + connection_profile_type_e profile_type; + connection_profile_state_e profile_state; + connection_ip_config_type_e ip_type = CONNECTION_IP_CONFIG_TYPE_NONE; + connection_proxy_type_e proxy_type; + connection_cellular_service_type_e service_type = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN; + connection_cellular_auth_type_e auth_type = CONNECTION_CELLULAR_AUTH_TYPE_NONE; + + MSG_DEBUG("**************************************************************************************************"); + ret = connection_profile_get_id(profile, &profile_id); + MSG_DEBUG("Profile Id = [%s]", profile_id); + + ret = connection_profile_get_name(profile, &profile_name); + MSG_DEBUG("Profile Name = [%s]", profile_name); + + ret = connection_profile_get_type(profile, &profile_type); + + if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) { + MSG_DEBUG("Profile Type = [CELLULAR]"); + } else if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) { + MSG_DEBUG("Profile Type = [WIFI]"); + } else if (profile_type == CONNECTION_PROFILE_TYPE_ETHERNET) { + MSG_DEBUG("Profile Type = [ETHERNET]"); + } else if (profile_type == CONNECTION_PROFILE_TYPE_BT) { + MSG_DEBUG("Profile Type = [BT]"); + } else { + MSG_DEBUG("Profile Type = Unknown [%d]", profile_type); + } + + ret = connection_profile_get_network_interface_name(profile, &interface_name); + MSG_DEBUG("Profile Interface Name = [%s]", interface_name); + + ret = connection_profile_get_state(profile, &profile_state); + if (profile_state == CONNECTION_PROFILE_STATE_DISCONNECTED) { + MSG_DEBUG("Profile State = [DISCONNECTED]"); + } else if (profile_state == CONNECTION_PROFILE_STATE_ASSOCIATION) { + MSG_DEBUG("Profile State = [ASSOCIATION]"); + } else if (profile_state == CONNECTION_PROFILE_STATE_CONFIGURATION) { + MSG_DEBUG("Profile State = [CONFIGURATION]"); + } else if (profile_state == CONNECTION_PROFILE_STATE_CONNECTED) { + MSG_DEBUG("Profile State = [CONNECTED]"); } else { - MSG_DEBUG("Error!!! Invalid profile type\n"); - return; + MSG_DEBUG("Profile State = Unknown [%d]", profile_state); } + ret = connection_profile_get_ip_config_type(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_type); + MSG_DEBUG("Profile Ip Config Type = [%d]", ip_type); + + ret = connection_profile_get_ip_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_address); + MSG_DEBUG("Profile Ip Address = [%s]", ip_address); + + ret = connection_profile_get_subnet_mask(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &subnet_mask); + MSG_DEBUG("Profile Subnet Mask = [%s]", subnet_mask); + + ret = connection_profile_get_gateway_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &gateway_address); + MSG_DEBUG("Profile Gateway Address = [%s]", gateway_address); + + ret = connection_profile_get_dns_address(profile, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &dns_address); + MSG_DEBUG("Profile Dns Address = [%s]", dns_address); + + ret = connection_profile_get_proxy_type(profile, &proxy_type); + MSG_DEBUG("Profile Proxy Type = [%d]", proxy_type); + + ret = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address); + MSG_DEBUG("Profile Proxy Address = [%s]", proxy_address); + + ret = connection_profile_get_cellular_service_type(profile, &service_type); + if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET) { + MSG_DEBUG("Profile Service Type = [INTERNET]"); + } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_MMS) { + MSG_DEBUG("Profile Service Type = [MMS]"); + } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET) { + MSG_DEBUG("Profile Service Type = [PREPAID_INTERNET]"); + } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS) { + MSG_DEBUG("Profile Service Type = [PREPAID_MMS]"); + } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING) { + MSG_DEBUG("Profile Service Type = [TETHERING]"); + } else if (service_type == CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION) { + MSG_DEBUG("Profile Service Type = [APPLICATION]"); + } else { + MSG_DEBUG("Profile Service Type = [Unknown][%d]", service_type); + } + + ret = connection_profile_get_cellular_apn(profile, &apn); + MSG_DEBUG("Profile Apn = [%s]", apn); + + ret = connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password); + MSG_DEBUG("Profile Auth Type = [%d]", &auth_type); + MSG_DEBUG("Profile Auth Name = [%s]", &user_name); + MSG_DEBUG("Profile Auth Passward = [%s]", &password); + + ret = connection_profile_get_cellular_home_url(profile, &home_url); + MSG_DEBUG("Profile Home Url = [%s]", home_url); + + ret = connection_profile_is_cellular_roaming(profile, &is_roaming); + MSG_DEBUG("Profile Roaming = [%d]", is_roaming); MSG_DEBUG("**************************************************************************************************"); - MSG_DEBUG("Profile Name = [%s]\n", ProfInfo->ProfileName); - - if (ProfInfo->ProfileState == NET_STATE_TYPE_IDLE) - MSG_DEBUG("Profile State = [idle]\n"); - else if (ProfInfo->ProfileState == NET_STATE_TYPE_FAILURE) - MSG_DEBUG("Profile State = [failure]\n"); - else if (ProfInfo->ProfileState == NET_STATE_TYPE_ASSOCIATION) - MSG_DEBUG("Profile State = [association]\n"); - else if (ProfInfo->ProfileState == NET_STATE_TYPE_CONFIGURATION) - MSG_DEBUG("Profile State = [configuration]\n"); - else if (ProfInfo->ProfileState == NET_STATE_TYPE_READY) - MSG_DEBUG("Profile State = [ready]\n"); - else if (ProfInfo->ProfileState == NET_STATE_TYPE_ONLINE) - MSG_DEBUG("Profile State = [online]\n"); - else if (ProfInfo->ProfileState == NET_STATE_TYPE_DISCONNECT) - MSG_DEBUG("Profile State = [disconnect]\n"); - else - MSG_DEBUG("Profile State = [unknown]\n"); + MMS_FREE(profile_id); + MMS_FREE(profile_name); + MMS_FREE(interface_name); + MMS_FREE(ip_address); + MMS_FREE(subnet_mask); + MMS_FREE(gateway_address); + MMS_FREE(dns_address); + MMS_FREE(proxy_address); + MMS_FREE(apn); + MMS_FREE(user_name); + MMS_FREE(password); + MMS_FREE(home_url); +} + +static void __connection_type_changed_cb(connection_type_e type, void* user_data) +{ + MSG_DEBUG("Type changed callback, connection type : %d", type); +} + +static void __connection_ip_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data) +{ + MSG_DEBUG("IP changed callback, IPv4 address : %s, IPv6 address : %s", + ipv4_address, (ipv6_address ? ipv6_address : "NULL")); +} - MSG_DEBUG("Profile Type = [pdp]\n"); +static void __connection_proxy_changed_cb(const char* ipv4_address, const char* ipv6_address, void* user_data) +{ + MSG_DEBUG("Proxy changed callback, IPv4 address : %s, IPv6 address : %s", + ipv4_address, (ipv6_address ? ipv6_address : "NULL")); +} - if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_GPRS) - MSG_DEBUG("Profile Protocol Type = [GPRS]\n"); - else if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_EDGE) - MSG_DEBUG("Profile Protocol Type = [EDGE]\n"); - else if (ProfInfo->ProfileInfo.Pdp.ProtocolType == NET_PDP_TYPE_UMTS) - MSG_DEBUG("Profile Protocol Type = [UMTS]\n"); +static void __connection_profile_opened_cb(connection_error_e result, void* user_data) +{ + if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS) + MSG_DEBUG("Connection open Succeeded [%d]", result); else - MSG_DEBUG("Profile Protocol Type = [NONE]\n"); + MSG_DEBUG("Connection open Failed, err : %d", result); - MSG_DEBUG("Profile APN = [%s]\n", ProfInfo->ProfileInfo.Pdp.Apn); + MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance(); - if (ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType == NET_PDP_AUTH_PAP) - MSG_DEBUG("Profile Auth Type = [PAP]\n"); - else if (ProfInfo->ProfileInfo.Pdp.AuthInfo.AuthType == NET_PDP_AUTH_CHAP) - MSG_DEBUG("Profile Auth Type = [CHAP]\n"); + cmAgent->open_callback(result, user_data); +} + +static void __connection_profile_closed_cb(connection_error_e result, void* user_data) +{ + if (result == CONNECTION_ERROR_NONE) + MSG_DEBUG("Connection close Succeeded"); else - MSG_DEBUG("Profile Auth Type = [NONE]\n"); - - MSG_DEBUG("Profile Auth UserName = [%s]\n", ProfInfo->ProfileInfo.Pdp.AuthInfo.UserName); - MSG_DEBUG("Profile Auth Password = [%s]\n", ProfInfo->ProfileInfo.Pdp.AuthInfo.Password); - MSG_DEBUG("Profile Home URL = [%s]\n", ProfInfo->ProfileInfo.Pdp.HomeURL); - MSG_DEBUG("Profile MCC = [%s]\n", ProfInfo->ProfileInfo.Pdp.Mcc); - MSG_DEBUG("Profile MNC = [%s]\n", ProfInfo->ProfileInfo.Pdp.Mnc); - MSG_DEBUG("Profile Roaming = [%d]\n", (int)ProfInfo->ProfileInfo.Pdp.Roaming); - MSG_DEBUG("Profile Setup Required = [%d]\n", (int)ProfInfo->ProfileInfo.Pdp.SetupRequired); - MSG_DEBUG("Profile Favourite = [%d]\n", (int)ProfInfo->Favourite); - MSG_DEBUG("Profile Device Name = [%s]\n", net_info->DevName); - MSG_DEBUG("Profile DNS Count = [%d]\n", net_info->DnsCount); - for (di = 0; di < net_info->DnsCount; di++) { - unsigned char *dns = (unsigned char *)&net_info->DnsAddr[di].Data.Ipv4.s_addr; - MSG_DEBUG("Profile DNS Address %d = [%d.%d.%d.%d]\n", di+1, dns[0], dns[1], dns[2], dns[3]); + MSG_DEBUG("Connection close Failed, err : %d", result); + + MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance(); + + cmAgent->close_callback(result, user_data); +} + +static gboolean __connection_create(void *pVoid) +{ + MSG_BEGIN(); + + bool ret = false; + bool *ret_val = (bool *)pVoid; + + if (connection) { + MSG_DEBUG("connection already exist"); + ret = true; + } else { + int err = connection_create(&connection); + + if (CONNECTION_ERROR_NONE == err) { + connection_set_type_changed_cb(connection, __connection_type_changed_cb, NULL); + connection_set_ip_address_changed_cb(connection, __connection_ip_changed_cb, NULL); + connection_set_proxy_address_changed_cb(connection, __connection_proxy_changed_cb, NULL); + ret = true; + MSG_DEBUG("Client registration success [%p] ", connection); + } else { + MSG_DEBUG("Client registration failed %d", err); + } } - if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_DYNAMIC) - MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_DYNAMIC]\n"); - else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_STATIC) - MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_STATIC]\n"); - else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_FIXED) - MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_FIXED]\n"); - else if (net_info->IpConfigType == NET_IP_CONFIG_TYPE_OFF) - MSG_DEBUG("Profile IPv4 Method = [NET_IP_CONFIG_TYPE_OFF]\n"); - else - MSG_DEBUG("Profile IPv4 Method = [UNKNOWN]\n"); - - MSG_DEBUG("Profile IP Address = [%d.%d.%d.%d]\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); - MSG_DEBUG("Profile Netmask = [%d.%d.%d.%d]\n", netmaskaddr[0], netmaskaddr[1], netmaskaddr[2], netmaskaddr[3]); - MSG_DEBUG("Profile Gateway = [%d.%d.%d.%d]\n", gwaddr[0], gwaddr[1], gwaddr[2], gwaddr[3]); - - if (net_info->ProxyMethod == NET_PROXY_TYPE_DIRECT) - MSG_DEBUG("Proxy Method = [direct]\n"); - else if (net_info->ProxyMethod == NET_PROXY_TYPE_AUTO) - MSG_DEBUG("Proxy Method = [auto]\n"); - else if (net_info->ProxyMethod == NET_PROXY_TYPE_MANUAL) - MSG_DEBUG("Proxy Method = [manual]\n"); - else - MSG_DEBUG("Proxy Method = [unknown]\n"); + if (ret_val) { + *ret_val = ret; + } + + MSG_END(); + return FALSE; +} - MSG_DEBUG("Profile Proxy = [%s]\n", net_info->ProxyAddr); +static gboolean __connection_destroy(void *pVoid) +{ + MSG_BEGIN(); - MSG_DEBUG("**************************************************************************************************"); + int rv; + int netOpenResult = NET_ERR_NONE; + + if (connection != NULL) { + rv = connection_destroy(connection); + connection = NULL; + MSG_DEBUG("connection destory !!"); + } else { + MSG_DEBUG("Cannot connection destroy : Handle is NULL"); + rv = CONNECTION_ERROR_INVALID_OPERATION; + } + + MSG_END(); + return FALSE; } +static gboolean __connection_profile_open(void *pVoid) +{ + MSG_BEGIN(); + + int netOpenResult = NET_ERR_NONE; + int *ret_val = (int *)pVoid; + connection_profile_h profile; + int err; -void network_evt_cb (net_event_info_t *event_cb, void *user_data) + err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile); + + if (err != CONNECTION_ERROR_NONE) { + MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err); + netOpenResult = NET_ERR_UNKNOWN; + } else { + + if (connection_open_profile(connection, profile, __connection_profile_opened_cb, NULL) != CONNECTION_ERROR_NONE) { + MSG_DEBUG("Connection open Failed!!"); + netOpenResult = NET_ERR_UNKNOWN; + } + } + + connection_profile_destroy(profile); + + if (ret_val) { + *ret_val = netOpenResult; + } + + MSG_END(); + + return FALSE; +} + +static gboolean __connection_profile_close(void *pVoid) { MSG_BEGIN(); - MmsPluginCmAgent::instance()->processCBdatas(event_cb, user_data); + int netOpenResult = NET_ERR_NONE; + + int *ret_val = (int *)pVoid; + + connection_profile_h profile; + int err; + + err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile); + + if (err != CONNECTION_ERROR_NONE) { + MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err); + netOpenResult = NET_ERR_UNKNOWN; + } else { + + if (connection_close_profile(connection, profile, __connection_profile_closed_cb, NULL) != CONNECTION_ERROR_NONE) { + MSG_DEBUG("Connection close Failed!!"); + netOpenResult = NET_ERR_UNKNOWN; + } + + } + + connection_profile_destroy(profile); + + if (ret_val) { + *ret_val = netOpenResult; + } MSG_END(); + + return FALSE; +} + + +void context_invoke_end_cb(gpointer data) +{ + g_mx.lock(); + + MSG_DEBUG("@@ SIGNAL @@"); + + g_cv.signal(); + + g_mx.unlock(); } +/* + * Network api should run at g_main_loop to receive callback + * */ +void context_invoke(GSourceFunc func, void *ret) +{ + MSG_BEGIN(); + + int time_ret = 0; + + g_mx.lock(); + + g_main_context_invoke_full(NULL, G_PRIORITY_HIGH, func, ret, context_invoke_end_cb); + + MSG_DEBUG("@@ WAIT @@"); + + time_ret = g_cv.timedwait(g_mx.pMutex(), MMS_CONTEXT_INVOKE_WAIT_TIME); + g_mx.unlock(); + + if (time_ret == ETIMEDOUT) { + MSG_DEBUG("@@ WAKE by timeout@@"); + } else { + MSG_DEBUG("@@ WAKE by signal@@"); + } + + MSG_END(); +} MmsPluginCmAgent *MmsPluginCmAgent::pInstance = NULL; @@ -149,77 +380,77 @@ MmsPluginCmAgent::MmsPluginCmAgent() MSG_BEGIN(); isCmOpened = false; - bzero(&mmsProfile, sizeof (net_profile_info_t)); + isCmRegistered = false; + + home_url = NULL; + interface_name = NULL; + proxy_address = NULL; MSG_END(); } MmsPluginCmAgent::~MmsPluginCmAgent() { - + MMS_FREE(home_url); + MMS_FREE(interface_name); + MMS_FREE(proxy_address); } -bool MmsPluginCmAgent::registration() +bool MmsPluginCmAgent::open() { MSG_BEGIN(); - bool registResult = true; + int netOpenResult = NET_ERR_NONE; - if (net_register_client((net_event_cb_t) network_evt_cb, NULL) != NET_ERR_NONE) { - MSG_DEBUG("Error!! net_register_client() failed.\n"); - registResult = false; - } + lock(); - MSG_END(); + if (isCmOpened == false) { - return registResult; -} + isCmRegistered = false; -bool MmsPluginCmAgent::open() -{ - MSG_BEGIN(); + context_invoke(__connection_create, &isCmRegistered); - if (!isCmOpened) { - if (!registration()) - return false; + if (isCmRegistered == true) { - int netOpenResult = NET_ERR_NONE; - net_service_type_t service_type = NET_SERVICE_MMS; + MSG_DEBUG("net_open_connection for MMS"); - netOpenResult = net_open_connection_with_preference(service_type); - if (netOpenResult != NET_ERR_NONE) { - MSG_DEBUG("Error!! net_open_connection_with_profile() failed. [%d]", netOpenResult); - deregistration(); - return false; - } + context_invoke(__connection_profile_open, &netOpenResult); - MSG_DEBUG("WAITING UNTIL Network Connection Open."); + if (netOpenResult == NET_ERR_NONE) { - lock(); + MSG_DEBUG("## WAITING UNTIL Network Connection Open. ##"); - int time_ret = 0; - time_ret = cv.timedwait(mx.pMutex(), 50); + int time_ret = 0; - unlock(); + time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME); // isCmOpened will changed by processCBdatas - if (time_ret == ETIMEDOUT) { - MSG_DEBUG("Network Connection Open Time Out."); - deregistration(); - return false; - } else { - if(!isCmOpened) { - MSG_DEBUG("Network connection open failed"); - deregistration(); - return false; + MSG_DEBUG("## WAKE ##"); + + if (time_ret == ETIMEDOUT) { + MSG_DEBUG("Network Connection Open Time Out."); + } + + if(!isCmOpened) { + MSG_DEBUG("Network Connection Open Failed"); + } + + } else { //error + MSG_FATAL("Error!! net_open_connection_with_profile() failed. [%d]", netOpenResult); } + + if (isCmOpened == false) { + context_invoke( __connection_destroy, NULL); + } + + } else { + MSG_FATAL("## Failed network callback registration ##"); } } else { MSG_DEBUG("Network is already opened."); - return false; } + unlock(); MSG_END(); - return isCmOpened; } @@ -228,221 +459,142 @@ void MmsPluginCmAgent::close() { MSG_BEGIN(); + lock(); + if (isCmOpened) { int netOpenResult = NET_ERR_NONE; - netOpenResult = net_close_connection(mmsProfile.ProfileName); - if (netOpenResult != NET_ERR_NONE) { - MSG_DEBUG("Error!! net_close_connection() failed.\n"); - deregistration(); - return; - } + context_invoke(__connection_profile_close, &netOpenResult); + + if (netOpenResult == NET_ERR_NONE) { - MSG_DEBUG("WAITING UNTIL Network Connection Close."); + MSG_DEBUG("## WAITING UNTIL Network Connection Close. ##"); - lock(); + int time_ret = 0; - int time_ret = 0; - time_ret = cv.timedwait(mx.pMutex(), 50); + time_ret = cv.timedwait(mx.pMutex(), MMS_CONNECTION_API_WAIT_TIME); - unlock(); + MSG_DEBUG("## WAKE ##"); - if (time_ret == ETIMEDOUT) { - MSG_DEBUG("Network Connection Close Timed Out."); + if (time_ret == ETIMEDOUT) { + MSG_DEBUG("Network Connection Close Timed Out."); + } + + } else { + MSG_DEBUG("Error!! net_close_connection() failed"); } - deregistration(); isCmOpened = false; } else { MSG_DEBUG ("Network Connection is not opened."); - return; } -} - - -void MmsPluginCmAgent::deregistration() -{ - MSG_BEGIN(); - int netOpenResult = NET_ERR_NONE; + if (isCmRegistered == true) { + context_invoke(__connection_destroy, NULL); + isCmRegistered = false; + } - netOpenResult = net_deregister_client(); - if (netOpenResult != NET_ERR_NONE) - MSG_DEBUG("Error!! net_deregister_client() failed. [%d]", netOpenResult); - else - MSG_DEBUG ("net_deregister_client() Success."); + unlock(); MSG_END(); } - -void MmsPluginCmAgent::processCBdatas(net_event_info_t *event_cb, void *user_data) +void MmsPluginCmAgent::open_callback(connection_error_e result, void* user_data) { - MSG_BEGIN(); + lock(); - net_dev_info_t *dev_info = NULL; - net_profile_info_t *prof_info = NULL; - - switch (event_cb->Event) { - case NET_EVENT_NET_CONFIGURE_RSP: - MSG_DEBUG("Received Network Configuration response: %d \n", event_cb->Error); - dev_info = (net_dev_info_t *)event_cb->Data; - - /*Successful PDP Activation*/ - if (event_cb->Error == NET_ERR_NONE) { - char *ip = (char *)&dev_info->IpAddr.Data.Ipv4; - char *netmask = (char *)&dev_info->SubnetMask.Data.Ipv4; - char *gateway = (char *)&dev_info->GatewayAddr.Data.Ipv4; - char *dns1 = (char *)&dev_info->DnsAddr[0].Data.Ipv4.s_addr; - char *dns2 = (char *)&dev_info->DnsAddr[1].Data.Ipv4.s_addr; - - MSG_DEBUG("= IP address [%d.%d.%d.%d]\n", - (int)ip[0], ip[1], ip[2], ip[3]); - MSG_DEBUG("= Netmask [%d.%d.%d.%d]\n", - (int)netmask[0], netmask[1], netmask[2], netmask[3]); - MSG_DEBUG("= Gateway [%d.%d.%d.%d]\n", - (int)gateway[0], gateway[1], gateway[2], gateway[3]); - MSG_DEBUG("= DNS address [%d.%d.%d.%d]\n", - (int)dns1[0], dns1[1], dns1[2], dns1[3]); - MSG_DEBUG("= DNS2 address [%d.%d.%d.%d]\n", - (int)dns2[0], dns2[1], dns2[2], dns2[3]); - MSG_DEBUG("= Device name [%s]\n", dev_info->DevName); - MSG_DEBUG("= Profile name [%s]\n", dev_info->ProfileName); - } else { - MSG_DEBUG("Error!!! Network Configuration Failed %d \n", event_cb->Error); - } - break; + connection_profile_h profile; + connection_cellular_state_e state; + int err; - /*Response from Datacom for PDP Activation Request*/ - case NET_EVENT_OPEN_IND: - MSG_DEBUG("Got Open Indication\n"); - MSG_DEBUG("Received ACTIVATION response: %d \n", event_cb->Error); - break; - case NET_EVENT_OPEN_RSP: - MSG_DEBUG("Got Open RSP\n"); - MSG_DEBUG("Received ACTIVATION response: %d \n", event_cb->Error); - prof_info = (net_profile_info_t *)event_cb->Data; + if (result == CONNECTION_ERROR_NONE || result == CONNECTION_ERROR_ALREADY_EXISTS) { - /*Successful PDP Activation*/ - if (event_cb->Error == NET_ERR_NONE || event_cb->Error == NET_ERR_ACTIVE_CONNECTION_EXISTS) { - network_print_profile(prof_info); + err = connection_get_cellular_state(connection, &state); - lock(); + MSG_DEBUG("connection_get_cellular_state ret [%d], state [%d]", err, state); - memcpy(&mmsProfile, prof_info, sizeof(net_profile_info_t)); + err = connection_get_default_cellular_service_profile(connection, CONNECTION_CELLULAR_SERVICE_TYPE_MMS, &profile); + if (err != CONNECTION_ERROR_NONE) { + MSG_DEBUG("connection_get_default_cellular_service_profile Failed!! [%d]", err); + } + + if (profile) { isCmOpened = true; - signal(); - unlock(); - } else { - MSG_DEBUG("Activation Failed %d \n", event_cb->Error); // open failed - lock(); - isCmOpened = false; - signal(); - unlock(); - } - break; + MMS_FREE(this->home_url); + MMS_FREE(this->interface_name); + MMS_FREE(this->proxy_address); - case NET_EVENT_CLOSE_RSP: - MSG_DEBUG("Got Close RSP\n"); + err = connection_profile_get_cellular_home_url(profile, &this->home_url); + err = connection_profile_get_network_interface_name(profile, &this->interface_name); + err = connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &this->proxy_address); - lock(); + __connection_profile_print(profile); - bzero(&mmsProfile, sizeof(net_profile_info_t)); - isCmOpened = false; - signal(); - - unlock(); - break; - - case NET_EVENT_CLOSE_IND: - MSG_DEBUG("Got Close IND\n"); - break; - case NET_EVENT_PROFILE_MODIFY_IND: - MSG_DEBUG("Received Profile modified Indication\n"); - MSG_DEBUG("No. of profile [%d]\n", event_cb->Datalength); - break; - case NET_EVENT_NET_STATE_IND: - MSG_DEBUG("Received NET_EVENT_NET_STATE_IND\n"); - break; - default : - MSG_DEBUG("Error! Unknown Event = %d\n\n", event_cb->Event); - break; + connection_profile_destroy(profile); + } + + } else { + MSG_DEBUG("connection open profile Failed!! [%d]", result); } - MSG_END(); -} + MSG_DEBUG("## SIGNAL ##"); + signal(); + unlock(); +} -bool MmsPluginCmAgent::getDeviceName(char *deviceName) +void MmsPluginCmAgent::close_callback(connection_error_e result, void* user_data) { - if (!isCmOpened) - return false; + lock(); - int deviceNameLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.DevName); + MMS_FREE(this->home_url); + MMS_FREE(this->interface_name); + MMS_FREE(this->proxy_address); - if (deviceNameLength > 0) { - strncpy(deviceName, mmsProfile.ProfileInfo.Pdp.net_info.DevName, deviceNameLength); - deviceName[deviceNameLength] = '\0'; - return true; - } + isCmOpened = false; + MSG_DEBUG("## SIGNAL ##"); + signal(); - return false; + unlock(); } - -bool MmsPluginCmAgent::getHomeURL(char *homeURL) +bool MmsPluginCmAgent::getInterfaceName(const char **deviceName) { if (!isCmOpened) return false; - int homeURLLength = strlen(mmsProfile.ProfileInfo.Pdp.HomeURL); + if (deviceName == NULL) + return false; - if (homeURLLength > 0) { - strncpy(homeURL, mmsProfile.ProfileInfo.Pdp.HomeURL, homeURLLength); - homeURL[homeURLLength] = '\0'; - return true; - } + *deviceName = interface_name; - return false; + return true; } - -bool MmsPluginCmAgent::getProxyAddr(char *proxyAddr) +bool MmsPluginCmAgent::getHomeUrl(const char **homeURL) { if (!isCmOpened) return false; - int proxyAddrLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr); - - if (proxyAddrLength > 0) { - if (strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':') == NULL) - return false; + if (homeURL == NULL) + return false; - proxyAddrLength = proxyAddrLength - strlen(strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':')); - strncpy(proxyAddr, mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, proxyAddrLength); - proxyAddr[proxyAddrLength] = '\0'; + *homeURL = home_url; - return true; - } - - return false; + return true; } -int MmsPluginCmAgent::getProxyPort() +bool MmsPluginCmAgent::getProxyAddr(const char **proxyAddr) { if (!isCmOpened) - return -1; + return false; - int proxyAddrLength = strlen(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr); + if (proxyAddr == NULL) + return false; - if (proxyAddrLength > 0) { - char *pPort = strchr(mmsProfile.ProfileInfo.Pdp.net_info.ProxyAddr, ':') + 1; - /* pPort cannot be NULL */ - return atoi(pPort); - } + *proxyAddr = proxy_address; - return -1; + return true; } - diff --git a/plugin/mms_plugin/MmsPluginHttp.cpp b/plugin/mms_plugin/MmsPluginHttp.cpp index cbdcd22..5d5a4f9 100755 --- a/plugin/mms_plugin/MmsPluginHttp.cpp +++ b/plugin/mms_plugin/MmsPluginHttp.cpp @@ -22,23 +22,42 @@ #include "MmsPluginUserAgent.h" #include "MmsPluginConnManWrapper.h" -static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer); -static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen); -static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen); - -static MMS_NET_ERROR_T __httpReceiveData(void *ptr, size_t size, size_t nmemb, void *userdata); -static size_t __httpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata); -static size_t __httpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata); +#define MMS_FREE(obj)\ + if (obj){\ + free(obj);\ + obj = NULL;\ + } -static int __httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig); -static int __httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig); -static int __httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig); static void __http_print_profile(CURL *curl); +static int __http_debug_cb (CURL *input_curl, curl_infotype input_info_type, char *input_data , size_t input_size, void *input_void); + +static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int ulContentLen); +static bool __httpGetHeaderField(MMS_HTTP_HEADER_FIELD_T httpHeaderItem, char *szHeaderBuffer); +static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen); /*================================================================================================== FUNCTION IMPLEMENTATION ==================================================================================================*/ +static int __http_progress_cb(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) +{ + MSG_DEBUG("download(%.0f/%.0f) : upload(%.0f/%.0f)", dlnow, dltotal, ulnow, ultotal); + return 0; +} + +static int __http_debug_cb (CURL *input_curl, curl_infotype input_info_type, char *input_data , size_t input_size, void *input_void) +{ + MSG_DEBUG("curl_infotype [%d] : %s", input_info_type, input_data); + return 0; +} + +static size_t __http_write_response_cb(void *ptr, size_t size, size_t nmemb, void *data) +{ + MSG_BEGIN(); + FILE *writehere = (FILE *)data; + return fwrite(ptr, size, nmemb, writehere); +} + static void __http_print_profile(CURL *curl) { double speed_upload, speed_download, total_time; @@ -167,7 +186,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int MSG_DEBUG("%s", pcheader); *responseHeaders = curl_slist_append(*responseHeaders, pcheader); } - +/* NOW not support gzip, deflate encoding in MMS Plugin memset(szBuffer, 0, 1025); memset(pcheader, 0, HTTP_REQUEST_LEN); nResult = __httpGetHeaderField(MMS_HH_ACCEPT_ENCODING, szBuffer); @@ -176,7 +195,7 @@ static void __httpAllocHeaderInfo(curl_slist **responseHeaders, char *szUrl, int MSG_DEBUG("%s", pcheader); *responseHeaders = curl_slist_append(*responseHeaders, pcheader); } - +*/ memset(szBuffer, 0, 1025); memset(pcheader, 0, HTTP_REQUEST_LEN); nResult = __httpGetHeaderField(MMS_HH_USER_AGENT, szBuffer); @@ -309,369 +328,373 @@ static void __httpGetHost(char *szUrl, char *szHost, int nBufferLen) } } -static MMS_NET_ERROR_T __httpReceiveData(void *ptr, size_t size, size_t nmemb, void *userdata) +static int __http_multi_perform(void *session) { - MMS_NET_ERROR_T httpRet = eMMS_UNKNOWN; + MSG_BEGIN(); - MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance(); - MMS_PLUGIN_HTTP_CONTEXT_S *pMmsPlgCd = pHttpAgent->getMmsPldCd(); - long length_received = size * nmemb; + CURLM *multi_handle; + CURLMcode rcm; - if (length_received) { - //Save the received buffer in a safe place. - if (pMmsPlgCd->final_content_buf == NULL) { - MSG_DEBUG("Body Lenghth Read = %d", length_received); - pMmsPlgCd->final_content_buf = (unsigned char *)malloc((length_received + 1) * sizeof(unsigned char)); + int still_running; + int ret = 0; + bool abort_flag = false; - if (pMmsPlgCd->final_content_buf == NULL) { - MSG_DEBUG("malloc fail"); - return eMMS_HTTP_EVENT_RECV_DATA_ERROR; - } + CURLMsg *msg; + int msgs_left; - memset(pMmsPlgCd->final_content_buf,0x0,((length_received + 1) * sizeof(unsigned char))); - MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf); - } else { - //realloc pHttpEvent->bodyLen extra and memset + multi_handle = curl_multi_init(); - unsigned char * buf = (unsigned char *)realloc(pMmsPlgCd->final_content_buf, - (pMmsPlgCd->bufOffset + length_received + 1) * sizeof(unsigned char)); + if (curl_multi_add_handle(multi_handle, session) != 0) { + MSG_DEBUG("curl_multi_add_handle is failed"); + curl_multi_cleanup(multi_handle); + return -1; + } - if (buf == NULL) { - MSG_DEBUG("realloc fail"); - return eMMS_HTTP_EVENT_RECV_DATA_ERROR; - } + /* we start some action by calling perform right away */ + rcm = curl_multi_perform(multi_handle, &still_running); + MSG_DEBUG("curl_multi_perform first end : rcm = %d, still_running = %d", rcm, still_running); + + do { + struct timeval timeout; + int rc; /* select() return code */ + + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int maxfd = -1; + + long curl_timeo = -1; + + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + + /* set a suitable timeout to play around with */ + timeout.tv_sec = 10; + timeout.tv_usec = 0; + + curl_multi_timeout(multi_handle, &curl_timeo); + if(curl_timeo >= 0) { + MSG_DEBUG("curl_timeo = %ld", curl_timeo); + timeout.tv_sec = curl_timeo / 1000; + if(timeout.tv_sec > 1) + timeout.tv_sec = 1; + else + timeout.tv_usec = (curl_timeo % 1000) * 1000; + } + + curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); - pMmsPlgCd->final_content_buf = buf; - MSG_DEBUG("Body Lenghth Read = %d Content Length = %d", length_received, pMmsPlgCd->bufOffset); - memset((pMmsPlgCd->final_content_buf +pMmsPlgCd->bufOffset), 0x0, - ((length_received + 1) * sizeof(unsigned char))); - MSG_DEBUG(" Global g_final_content_buf=%0x", pMmsPlgCd->final_content_buf); + /* In a real-world program you OF COURSE check the return code of the + function calls. On success, the value of maxfd is guaranteed to be + greater or equal than -1. We call select(maxfd + 1, ...), specially in + case of (maxfd == -1), we call select(0, ...), which is basically equal + to sleep. */ + rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); + switch(rc) { + case -1: + /* select error */ + MSG_DEBUG("select error"); + break; + case 0: /* timeout */ + default: /* action */ + rcm = curl_multi_perform(multi_handle, &still_running); + break; } - //copy body - if (pMmsPlgCd->final_content_buf != NULL) { - memcpy( pMmsPlgCd->final_content_buf + pMmsPlgCd->bufOffset, ptr, length_received); - MSG_DEBUG("Current g_bufOffset =%d", pMmsPlgCd->bufOffset); - /* Content Received */ - MSG_DEBUG("Total Content received PTR =%0X, Content Size =%d", pMmsPlgCd->final_content_buf, - pMmsPlgCd->bufOffset); - pMmsPlgCd->bufOffset = pMmsPlgCd->bufOffset + length_received; - httpRet = eMMS_UNKNOWN; + abort_flag = MmsPluginHttpAgent::instance()->getAbortFlag(); + if (abort_flag == true) { + MSG_DEBUG("abort flag is Set"); + ret = -1; } - } else { - MSG_DEBUG("End of Data transfer"); - MSG_DEBUG("MmsHttpReadData Buffer Size = %d", pMmsPlgCd->bufOffset); - MSG_DEBUG("MmsHttpReadData Buffer = %s", pMmsPlgCd->final_content_buf); - if (pMmsPlgCd->bufOffset == 0) { - /* This is applicable when - M-ReadRec.inf,M-Ack.ind, M-NotifyResp.ind posted */ - MSG_DEBUG(" Content Size is Zero"); + MSG_DEBUG("curl_multi_perform end : rcm = %d, still_running = %d, abort_flag = %d", rcm, still_running, abort_flag); - if (pMmsPlgCd->final_content_buf != NULL) { - free(pMmsPlgCd->final_content_buf ); - pMmsPlgCd->final_content_buf = NULL; - } + } while(still_running && (abort_flag == false)); - httpRet = eMMS_HTTP_EVENT_SENT_ACK_COMPLETED; - } else if (pMmsPlgCd->final_content_buf != NULL && pMmsPlgCd->bufOffset != 0) { - // Process Http Data - MSG_DEBUG(" Send Received Data to UA"); - httpRet = eMMS_HTTP_RECV_DATA; // eMMS_HTTP_RECV_DATA; - } else { - httpRet = eMMS_UNKNOWN; // check later - } + while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) { + if (msg->msg == CURLMSG_DONE) { - return httpRet; + if (msg->easy_handle == session) { + MSG_DEBUG("HTTP transfer completed with status %d", msg->data.result); + curl_multi_remove_handle(multi_handle, session); + } else { + MSG_DEBUG("Unknown handle HTTP transfer completed with status %d", msg->data.result); + } + } } - return httpRet; -} + curl_multi_cleanup(multi_handle); + MSG_END(); + return ret; +} -static size_t __httpPostTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata) +MmsPluginHttpAgent *MmsPluginHttpAgent::pInstance = NULL; +MmsPluginHttpAgent *MmsPluginHttpAgent::instance() { - MSG_DEBUG(" ====== HTTP_EVENT_SENT ========"); - long length_received = size * nmemb; - __httpReceiveData(ptr, size, nmemb, userdata); + if (!pInstance) + { + pInstance = new MmsPluginHttpAgent(); + } - return length_received; + return pInstance; } -static size_t __httpGetTransactionCB(void *ptr, size_t size, size_t nmemb, void *userdata) + +MmsPluginHttpAgent::MmsPluginHttpAgent() { - MSG_DEBUG(" ====== HTTP_EVENT_RECEIVED ========"); - long length_received = size * nmemb; - __httpReceiveData(ptr, size, nmemb, userdata); + MSG_BEGIN(); - return length_received; + abort = false; + respfile = NULL; + session_header = NULL; + session_option = NULL; + + transaction_type = MMS_HTTP_TRANSACTION_TYPE_UNKNOWN; + MSG_END(); } -static int __httpCmdInitSession(MMS_PLUGIN_HTTP_DATA_S *httpConfig) +MmsPluginHttpAgent::~MmsPluginHttpAgent() { - MSG_DEBUG("HttpCmd Init Session"); - - char proxyAddr[MAX_IPV4_LENGTH + 1] = {0}; - - snprintf(proxyAddr, MAX_IPV4_LENGTH + 1, "%s:%d", httpConfig->mmscConfig.httpProxyIpAddr, httpConfig->mmscConfig.proxyPortNo); - MSG_DEBUG("profileId [%d], proxyAddr [%s]", httpConfig->currentProfileId, proxyAddr); + MSG_BEGIN(); - CURL *curl_session = curl_easy_init(); - if (NULL == curl_session) { - MSG_DEBUG("curl_easy_init() failed"); - return eMMS_HTTP_SESSION_OPEN_FAILED; + if (session_header) { + MSG_DEBUG("session header is exist : free session header"); + curl_slist_free_all((curl_slist *)session_header); + session_header = NULL; } - int curl_status = curl_easy_setopt(curl_session, CURLOPT_PROXY, proxyAddr); - if (curl_status != CURLM_OK) { - MSG_DEBUG("curl_easy_setopt(): CURLOPT_PROXY failed"); - curl_easy_cleanup(curl_session); - return eMMS_HTTP_SESSION_OPEN_FAILED; + if (session_option) { + MSG_DEBUG("session is exist : cleanup session"); + curl_easy_cleanup(session_option); + session_option = NULL; } - httpConfig->session = curl_session; - - return eMMS_HTTP_SESSION_INIT; + MSG_END(); } - -static int __httpCmdPostTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig) +void MmsPluginHttpAgent::initSession() { - int trId; - - MSG_DEBUG("HttpCmd Post Transaction"); - MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION"); - - char deviceName[1024] = {0,}; - - MmsPluginCmAgent::instance()->getDeviceName(deviceName); - - MSG_DEBUG("deviceName: [%s]", deviceName); - int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName); + MSG_BEGIN(); - if (curl_status != CURLM_OK) { - MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed"); + this->transaction_type = MMS_HTTP_TRANSACTION_TYPE_UNKNOWN; - return eMMS_EXCEPTIONAL_ERROR; + if (session_header) { + MSG_DEBUG("session header is exist : free session header"); + curl_slist_free_all((curl_slist *)session_header); + session_header = NULL; } - CURLcode rc = curl_easy_perform(httpConfig->session); - - __http_print_profile(httpConfig->session); - - MmsPluginHttpAgent* httpAgent = MmsPluginHttpAgent::instance(); - MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData(); - if (httpConfigData->sessionHeader) { - curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader); - httpConfigData->sessionHeader = NULL; + if (session_option) { + MSG_DEBUG("session is exist : cleanup session"); + curl_easy_cleanup(session_option); + session_option = NULL; } - if (CURLE_OK != rc) { - MSG_DEBUG("curl_easy_perform return error rc[%d]", rc); - - return eMMS_HTTP_ERROR_NETWORK; + if (respfile) { + fclose(respfile); + respfile = NULL; } - MSG_DEBUG("## End Transaction ##"); - - srandom((unsigned int) time(NULL)); - trId = random() % 1000000000 + 1; - MSG_DEBUG("############ trID = %d ###########", trId); - - httpConfig->transactionId = trId; + initAbortFlag(); - return eMMS_HTTP_SENT_SUCCESS; + MSG_END(); } -static int __httpCmdGetTransaction(MMS_PLUGIN_HTTP_DATA_S *httpConfig) +void MmsPluginHttpAgent::clearSession() { - int trId; - - MSG_DEBUG("HttpCmd Get Transaction"); - MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_GET_TRANSACTION"); - - char deviceName[1024] = {0,}; - MmsPluginCmAgent::instance()->getDeviceName(deviceName); - MSG_DEBUG("deviceName: [%s]", deviceName); + MSG_BEGIN(); - int curl_status = curl_easy_setopt(httpConfig->session, CURLOPT_INTERFACE, deviceName); - if (curl_status != CURLM_OK) { - MSG_DEBUG("curl_easy_setopt(): CURLOPT_INTERFACE failed"); + this->transaction_type = MMS_HTTP_TRANSACTION_TYPE_UNKNOWN; - return eMMS_EXCEPTIONAL_ERROR; + if (session_header) { + MSG_DEBUG("session header is exist : free session header"); + curl_slist_free_all((curl_slist *)session_header); + session_header = NULL; } - CURLcode rc = curl_easy_perform(httpConfig->session); - - __http_print_profile(httpConfig->session); - - MmsPluginHttpAgent* httpAgent = MmsPluginHttpAgent::instance(); - MMS_PLUGIN_HTTP_DATA_S *httpConfigData = httpAgent->getHttpConfigData(); - if (httpConfigData->sessionHeader) { - curl_slist_free_all((curl_slist *)httpConfigData->sessionHeader); - httpConfigData->sessionHeader = NULL; + if (session_option) { + MSG_DEBUG("session is exist : cleanup session"); + curl_easy_cleanup(session_option); + session_option = NULL; } - if (CURLE_OK != rc) { - MSG_DEBUG("curl_easy_perform return error = %d", rc); - - return eMMS_HTTP_ERROR_NETWORK; + if (respfile) { + fclose(respfile); + respfile = NULL; } - MSG_DEBUG("## End Transaction ##"); - - srandom((unsigned int) time(NULL)); - trId = random() % 1000000000 + 1; - MSG_DEBUG("############ trID = %d ###########", trId); - - httpConfig->transactionId = trId; - - return eMMS_HTTP_SENT_SUCCESS; + initAbortFlag(); + MSG_END(); } -MmsPluginHttpAgent *MmsPluginHttpAgent::pInstance = NULL; -MmsPluginHttpAgent *MmsPluginHttpAgent::instance() +MMS_HTTP_ERROR_E MmsPluginHttpAgent::setSession(http_request_info_s &request_info) { - if (!pInstance) - pInstance = new MmsPluginHttpAgent(); - - return pInstance; -} - + MSG_BEGIN(); + MMS_HTTP_ERROR_E http_error = MMS_HTTP_ERROR_NONE; + int content_len = 0; + char *url = NULL; -MmsPluginHttpAgent::MmsPluginHttpAgent() -{ - MSG_DEBUG("MmsPluginHttpAgent()"); + // Verify request info + if (request_info.transaction_type != MMS_HTTP_TRANSACTION_TYPE_GET + && request_info.transaction_type != MMS_HTTP_TRANSACTION_TYPE_POST) + { + MSG_ERR("transaction_type of request_info is Invaild [%d]", request_info.transaction_type); + goto __CATCH; + } - bzero(&httpConfigData, sizeof(httpConfigData)); - bzero(&mmsPlgCd, sizeof(mmsPlgCd)); + if (request_info.transaction_type == MMS_HTTP_TRANSACTION_TYPE_POST) { - httpCmdHandler.clear(); + if (request_info.post_data == NULL || request_info.post_data_len == 0) { + MSG_ERR("post data info is Invaild"); + goto __CATCH; + } + } - httpCmdHandler[eHTTP_CMD_INIT_SESSION] = &__httpCmdInitSession; - httpCmdHandler[eHTTP_CMD_POST_TRANSACTION] = &__httpCmdPostTransaction; - httpCmdHandler[eHTTP_CMD_GET_TRANSACTION] = &__httpCmdGetTransaction; -} + if (request_info.url == NULL || request_info.proxy == NULL || request_info.interface == NULL) { + MSG_ERR("request_info parameter invalid url [%s], proxy [%s] interface [%s]", request_info.url, request_info.proxy, request_info.interface); + goto __CATCH; + } -MmsPluginHttpAgent::~MmsPluginHttpAgent() -{ + //Set type + this->transaction_type = request_info.transaction_type; + MSG_DEBUG("set transaction type [%d]", this->transaction_type); -} + //Set http Headers + if (this->transaction_type == MMS_HTTP_TRANSACTION_TYPE_POST) { + content_len = request_info.post_data_len; + } else { //MMS_HTTP_TRANSACTION_TYPE_GET + content_len = 0; + } -void MmsPluginHttpAgent::SetMMSProfile() -{ - MSG_BEGIN(); + url = strdup(request_info.url); - MMSC_CONFIG_DATA_S *mmscConfig = &(httpConfigData.mmscConfig); + if (url) { + __httpAllocHeaderInfo((curl_slist**)&session_header, url, content_len); + if (session_header == NULL) { + MSG_ERR("Failed to __httpAllocHeaderInfo"); + goto __CATCH; + } - MmsPluginCmAgent::instance()->getHomeURL(mmscConfig->mmscUrl); - if (strlen(mmscConfig->mmscUrl) < 1) { - MSG_DEBUG("##### get Home URL Error"); + free(url); + url = NULL; + } else { + MSG_ERR("Failed to strdup"); + goto __CATCH; } - MmsPluginCmAgent::instance()->getProxyAddr(mmscConfig->httpProxyIpAddr); - mmscConfig->proxyPortNo = MmsPluginCmAgent::instance()->getProxyPort(); - MSG_END(); -} + //Set curl option + session_option = curl_easy_init(); + if (session_option == NULL) { + MSG_DEBUG("curl_easy_init() failed"); + goto __CATCH; + } -int MmsPluginHttpAgent::cmdRequest(MMS_HTTP_CMD_TYPE_T cmdType) -{ - MSG_DEBUG("cmdRequest:%x", cmdType); + curl_easy_setopt(session_option, CURLOPT_PROXY, request_info.proxy); + curl_easy_setopt(session_option, CURLOPT_VERBOSE, true); + curl_easy_setopt(session_option, CURLOPT_URL, request_info.url); + curl_easy_setopt(session_option, CURLOPT_NOPROGRESS, true); + curl_easy_setopt(session_option, CURLOPT_HTTPHEADER, session_header); + curl_easy_setopt(session_option, CURLOPT_DEBUGFUNCTION , __http_debug_cb); + curl_easy_setopt(session_option, CURLOPT_INTERFACE, request_info.interface); + //curl_easy_setopt(httpConfigData.session, CURLOPT_PROGRESSFUNCTION, __http_progress_cb); //for debug + + if (respfile) { + curl_easy_setopt(session_option, CURLOPT_WRITEFUNCTION, __http_write_response_cb); + curl_easy_setopt(session_option, CURLOPT_WRITEDATA, respfile); + } - int ret = 0; + if (transaction_type == MMS_HTTP_TRANSACTION_TYPE_POST) { + curl_easy_setopt(session_option, CURLOPT_POST, true); + curl_easy_setopt(session_option, CURLOPT_POSTFIELDS, request_info.post_data); + curl_easy_setopt(session_option, CURLOPT_POSTFIELDSIZE, request_info.post_data_len); + // curl_easy_setopt(session_option, CURLOPT_TCP_NODELAY, 1); + } - ret = httpCmdHandler[cmdType](&httpConfigData); + MSG_END(); + return http_error; - return ret; -} +__CATCH: -MMS_PLUGIN_HTTP_CONTEXT_S* MmsPluginHttpAgent::getMmsPldCd() -{ - return &mmsPlgCd; -} + clearSession(); -MMS_PLUGIN_HTTP_DATA_S *MmsPluginHttpAgent::getHttpConfigData() -{ - return &httpConfigData; + MSG_END(); + return http_error; } -int MmsPluginHttpAgent::setSession(mmsTranQEntity *qEntity) +MMS_HTTP_ERROR_E MmsPluginHttpAgent::startTransaction() { - MSG_DEBUG("%s %d", qEntity->pPostData, qEntity->postDataLen); + MSG_BEGIN(); + MMS_HTTP_ERROR_E http_error = MMS_HTTP_ERROR_NONE; - if (qEntity->eHttpCmdType == eHTTP_CMD_POST_TRANSACTION) { - MSG_DEBUG("HttpCmd Post Transaction"); - MSG_DEBUG(" === HTTP Agent Thread : Signal ==> eMMS_HTTP_SIGNAL_POST_TRANSACTION"); + int rc = __http_multi_perform(session_option); - curl_slist *responseHeaders = NULL; + __http_print_profile(session_option); - __httpAllocHeaderInfo(&responseHeaders, httpConfigData.mmscConfig.mmscUrl, qEntity->postDataLen); + if (rc != 0) { + MSG_DEBUG("curl_easy_perform return error rc [%d]", rc); + http_error = MMS_HTTP_ERROR_TRANSACTION; + } - MSG_DEBUG(" === MMSCURI = %s === ", httpConfigData.mmscConfig.mmscUrl); + MSG_END(); + return http_error; +} - httpConfigData.sessionHeader = (void *)responseHeaders; +MMS_HTTP_ERROR_E MmsPluginHttpAgent::httpRequest(http_request_info_s &request_info) +{ + MSG_BEGIN(); - MSG_DEBUG("## Start Transaction : Post ##"); - curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true); - curl_easy_setopt(httpConfigData.session, CURLOPT_POST, true); - curl_easy_setopt(httpConfigData.session, CURLOPT_URL, httpConfigData.mmscConfig.mmscUrl); - curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true); - curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders); - curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDS, qEntity->pPostData); - curl_easy_setopt(httpConfigData.session, CURLOPT_POSTFIELDSIZE, qEntity->postDataLen); - curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, __httpPostTransactionCB); - curl_easy_setopt(httpConfigData.session, CURLOPT_TCP_NODELAY, 1); + const char *conf_filename = MSG_DATA_PATH"mms.conf"; - } else if (qEntity->eHttpCmdType == eHTTP_CMD_GET_TRANSACTION) { - MSG_DEBUG("MmsHttpInitTransactionGet %d pGetData (%s)", qEntity->getDataLen, qEntity->pGetData); - MSG_DEBUG("MmsHttpInitTransactionGet mmscURL (%s) ", httpConfigData.mmscConfig.mmscUrl); + MMS_HTTP_ERROR_E http_error = MMS_HTTP_ERROR_NONE; - char szUrl[MAX_MMSC_URL_LEN] = {0, }; + this->initSession(); - memcpy(szUrl, qEntity->pGetData, qEntity->getDataLen); + respfile = fopen(conf_filename, "wb"); - MSG_DEBUG("MmsHttpInitTransactionGet szURL (%s)", szUrl); + //set session + http_error = this->setSession(request_info); + if (http_error != MMS_HTTP_ERROR_NONE) { + MSG_DEBUG("Fail to setSession"); + goto __CATCH; + } - curl_slist *responseHeaders = NULL; + //transaction + http_error = this->startTransaction(); + if (http_error != MMS_HTTP_ERROR_NONE) { + MSG_DEBUG("Fail to startTransaction"); + goto __CATCH; + } - __httpAllocHeaderInfo(&responseHeaders, szUrl, 0); + //close conf file & load response data + if (respfile) { - httpConfigData.sessionHeader = (void *)responseHeaders; + fclose(respfile); + respfile = NULL; - MSG_DEBUG("## Start Transaction : Get ##"); - curl_easy_setopt(httpConfigData.session, CURLOPT_VERBOSE, true); - curl_easy_setopt(httpConfigData.session, CURLOPT_URL, szUrl); - curl_easy_setopt(httpConfigData.session, CURLOPT_NOPROGRESS, true); - curl_easy_setopt(httpConfigData.session, CURLOPT_HTTPHEADER, responseHeaders); - curl_easy_setopt(httpConfigData.session, CURLOPT_WRITEFUNCTION, __httpGetTransactionCB); - } else { - MSG_DEBUG("Unknown eHttpCmdType [%d]", qEntity->eHttpCmdType); - return -1; + if (g_file_get_contents(conf_filename, &request_info.response_data, &request_info.response_data_len, NULL) == false) { + MSG_DEBUG("Fail to g_file_get_contents"); + } } - return 0; -} - + this->clearSession(); -void MmsPluginHttpAgent::clearSession() -{ - MSG_BEGIN(); + MSG_END(); + return http_error; - if (httpConfigData.sessionHeader) { - curl_slist_free_all((curl_slist *)httpConfigData.sessionHeader); - httpConfigData.sessionHeader = NULL; - } +__CATCH: - if (httpConfigData.session == NULL) { - MSG_DEBUG("[Error]httpConfigData.session is NULL"); - return; + if (respfile) { + fclose(respfile); + respfile = NULL; } - curl_easy_cleanup(httpConfigData.session); - - httpConfigData.session = NULL; + this->clearSession(); MSG_END(); + return http_error; } diff --git a/plugin/mms_plugin/MmsPluginUserAgent.cpp b/plugin/mms_plugin/MmsPluginUserAgent.cpp index 851c843..24592fa 100755 --- a/plugin/mms_plugin/MmsPluginUserAgent.cpp +++ b/plugin/mms_plugin/MmsPluginUserAgent.cpp @@ -30,6 +30,7 @@ #include "MmsPluginCodec.h" #include "MmsPluginDrm.h" #include "MmsPluginStorage.h" +#include "MmsPluginUtil.h" extern MmsHeader mmsHeader; @@ -183,6 +184,18 @@ void updatePduType(mmsTranQEntity *qEntity) PRINT_PDU_TYPE(qEntity->eMmsPduType); } +bool compare_func(mmsTranQEntity const &a, mmsTranQEntity const &b) +{ + if (a.msgId == b.msgId) { + if ((a.eMmsPduType == eMMS_RETRIEVE_MANUAL || a.eMmsPduType == eMMS_RETRIEVE_AUTO) + &&(b.eMmsPduType == eMMS_RETRIEVE_MANUAL || b.eMmsPduType == eMMS_RETRIEVE_AUTO)) { + return true; + } + } + + return false; +} + MmsPluginUaManager *MmsPluginUaManager::pInstance = NULL; MmsPluginUaManager::MmsPluginUaManager() @@ -231,12 +244,65 @@ MMS_NET_ERROR_T MmsPluginUaManager::submitHandler(mmsTranQEntity *qEntity) MmsPluginHttpAgent* httpAgent = MmsPluginHttpAgent::instance(); + http_request_info_s request_info = {}; + + char *http_url = NULL; + + memset(&request_info, 0x00, sizeof(request_info)); + + const char *home_url = NULL; + const char *proxy_addr = NULL; + const char *interfaceName = NULL; + + MmsPluginCmAgent::instance()->getProxyAddr(&proxy_addr); + MmsPluginCmAgent::instance()->getInterfaceName(&interfaceName); + MmsPluginCmAgent::instance()->getHomeUrl(&home_url); + + if (qEntity->eHttpCmdType == eHTTP_CMD_POST_TRANSACTION) { + + request_info.transaction_type = MMS_HTTP_TRANSACTION_TYPE_POST; + + request_info.url = home_url; + + request_info.proxy = proxy_addr; + + request_info.interface = interfaceName; + + request_info.post_data = qEntity->pPostData; + + request_info.post_data_len = qEntity->postDataLen; + + } else { + request_info.transaction_type = MMS_HTTP_TRANSACTION_TYPE_GET; + + http_url = (char *)calloc(1, qEntity->getDataLen + 1); + + memcpy(http_url, qEntity->pGetData, qEntity->getDataLen); + + request_info.url = http_url; + + request_info.proxy = proxy_addr; + + request_info.interface = interfaceName; + } + + while (retryCount < RETRY_MAX) { - ret = httpAgent->cmdRequest(qEntity->eHttpCmdType); + + ret = httpAgent->httpRequest(request_info); // Process result - if (ret == eMMS_HTTP_SENT_SUCCESS) { + if (ret == MMS_HTTP_ERROR_NONE) { MSG_DEBUG("Submit request sent"); + + if (qEntity->pGetData) { + free(qEntity->pGetData); + qEntity->pGetData = NULL; + } + + qEntity->pGetData = request_info.response_data; + qEntity->getDataLen = request_info.response_data_len; + break; } else if (ret == eMMS_HTTP_ERROR_NETWORK) { retryCount++; @@ -248,34 +314,15 @@ MMS_NET_ERROR_T MmsPluginUaManager::submitHandler(mmsTranQEntity *qEntity) } } + if (http_url) + free(http_url); + return ret; } MMS_NET_ERROR_T MmsPluginUaManager::waitingConf(mmsTranQEntity *qEntity) { - MMS_NET_ERROR_T ret = eMMS_HTTP_ERROR_UNKNOWN; - MmsPluginHttpAgent *pHttpAgent = MmsPluginHttpAgent::instance(); - MMS_PLUGIN_HTTP_CONTEXT_S *pMmsPldCd = NULL; - - pMmsPldCd = pHttpAgent->getMmsPldCd(); - - if (qEntity->pGetData) { - free(qEntity->pGetData); - qEntity->pGetData = NULL; - } - qEntity->getDataLen = pMmsPldCd->bufOffset; - qEntity->pGetData = (char *)calloc(1, pMmsPldCd->bufOffset + 1); - - memcpy(qEntity->pGetData, pMmsPldCd->final_content_buf, pMmsPldCd->bufOffset); - free(pMmsPldCd->final_content_buf); - pMmsPldCd->final_content_buf = NULL; - pMmsPldCd->bufOffset = 0; - - MSG_DEBUG("dataLen:%d pData:(%s)", qEntity->getDataLen, qEntity->pGetData); - - ret = eMMS_HTTP_CONF_SUCCESS; - - return ret; + return eMMS_HTTP_CONF_SUCCESS; } void MmsPluginUaManager::run() @@ -283,10 +330,6 @@ void MmsPluginUaManager::run() MSG_BEGIN(); MmsPluginCmAgent *cmAgent = MmsPluginCmAgent::instance(); - MmsPluginHttpAgent *httpAgent = MmsPluginHttpAgent::instance(); - - int trId; -// CURL *session = NULL; int msgId; @@ -362,8 +405,6 @@ void MmsPluginUaManager::run() goto CLEANUP; } - httpAgent->SetMMSProfile(); - while (!mmsTranQ.empty()) { MSG_DEBUG("###### mmsTranQ.size [%d]", mmsTranQ.size()); @@ -382,21 +423,12 @@ void MmsPluginUaManager::run() MmsPluginStorage::instance()->updateNetStatus(msgId, MSG_NETWORK_RETRIEVING); } - if (httpAgent->cmdRequest(eHTTP_CMD_INIT_SESSION) == eMMS_HTTP_SESSION_OPEN_FAILED) { - MSG_DEBUG("HTTP session open failed"); - // cm close - cmAgent->close(); - // delete all request from reqQEntities - goto CLEANUP; - } - // MMS Transaction MSG_DEBUG("\n\n =================== MMS Transaction Start ========================"); do { - httpAgent->setSession(&reqEntity); - if (submitHandler(&reqEntity) != eMMS_HTTP_SENT_SUCCESS) { + if (submitHandler(&reqEntity) != MMS_HTTP_ERROR_NONE) { MSG_DEBUG("Transaction Error: submit failed"); MmsPluginEventHandler::instance()->handleMmsError(&reqEntity); @@ -406,7 +438,6 @@ void MmsPluginUaManager::run() } MSG_DEBUG("submitHandler(&reqEntity) success."); - trId = httpAgent->getHttpConfigData()->transactionId; MSG_DEBUG("#### MMS PDU TYPE = %d ####", reqEntity.eMmsPduType); @@ -474,7 +505,7 @@ void MmsPluginUaManager::run() break; } - MsgSettingGetBool(MMS_RECV_DELIVERY_RECEIPT, &bReportAllowed); + MsgSettingGetBool(MMS_SEND_REPORT_ALLOWED, &bReportAllowed); MSG_DEBUG("conf received successfully -2"); MSG_DEBUG("reqEntity.eMmsPduType [%d]", reqEntity.eMmsPduType); @@ -515,7 +546,9 @@ void MmsPluginUaManager::run() mmsTranQ.push_front(reqEntity); - remove(filepath); + if (remove(filepath) != 0) { + MSG_DEBUG("Error removing file"); + } MSG_DEBUG("Submit Ind"); } else if (reqEntity.eMmsPduType == eMMS_RETRIEVE_MANUAL_CONF) { @@ -566,6 +599,7 @@ void MmsPluginUaManager::run() MmsPluginEventHandler::instance()->handleMmsError(&reqEntity); break; } + } while (reqEntity.isCompleted == false); MSG_DEBUG("==== MMS Transaction Completed ====\n\n"); @@ -580,8 +614,6 @@ void MmsPluginUaManager::run() reqEntity.pGetData = NULL; } - // Http Session Close - httpAgent->clearSession(); } // Request CM Close @@ -634,6 +666,11 @@ void MmsPluginUaManager::getMmsPduData(mmsTranQEntity *qEntity) void MmsPluginUaManager::addMmsReqEntity(mmsTranQEntity req) { + if (mmsTranQ.checkExist(req, compare_func) == true) { + MSG_DEBUG("request Already Exist, req_id = %d", req.msgId); + THROW(MsgException::REQ_EXIST_ERROR, "MMS request already exist"); + } + MSG_DEBUG("New MMS Tran Added"); mmsTranQ.push_back(req); lock(); @@ -667,39 +704,7 @@ bool MmsPluginUaManager::processReceivedData(int msgId, char *pRcvdBody, int rcv if (MmsReadMsgBody(msgId, true, true, retrievedFilePath) == false) { MSG_DEBUG("The MMS Message might include drm contents!!!"); - -#ifdef __SUPPORT_DRM__ - if (MmsDrm2GetConvertState() == MMS_DRM2_CONVERT_REQUIRED) { - bool bRetToConvert = true; - MSG_MESSAGE_INFO_S pMsg = {0, }; - - pMsg.msgId = msgId; - - bRetToConvert = MmsDrm2ConvertMsgBody(mmsHeader.msgType.szOrgFilePath); - - MmsDrm2SetConvertState(MMS_DRM2_CONVERT_FINISH); - - if (bRetToConvert) { - int ret; - ret = remove(mmsHeader.msgType.szOrgFilePath); - if (ret != 0) { - MSG_DEBUG("remove fail\n"); - goto ERR_MMS_UA_PROCESS_CONF; - } - - ret = rename(MMS_DECODE_DRM_CONVERTED_TEMP_FILE, mmsHeader.msgType.szOrgFilePath); - if (ret != 0) { - MSG_DEBUG("rename fail\n"); - goto ERR_MMS_UA_PROCESS_CONF; - } - - if (MmsDrm2ReadMsgConvertedBody(&pMsg, true, true, retrievedFilePath) == false) { - MSG_DEBUG("MmsLoadMsg:MmsDrm2ReadMsgConvertedBody() returns false\n"); - goto ERR_MMS_UA_PROCESS_CONF; - } - } - } -#endif + goto ERR_MMS_UA_PROCESS_CONF; } MSG_END(); @@ -724,3 +729,4 @@ ERR_MMS_UA_PROCESS_CONF: } } + diff --git a/plugin/mms_plugin/include/MmsPluginConnManWrapper.h b/plugin/mms_plugin/include/MmsPluginConnManWrapper.h index fb6a31a..eddbd69 100755 --- a/plugin/mms_plugin/include/MmsPluginConnManWrapper.h +++ b/plugin/mms_plugin/include/MmsPluginConnManWrapper.h @@ -20,6 +20,8 @@ #include #include #include "MsgMutex.h" +#include +#include "net_connection.h" class MmsPluginCmAgent { @@ -32,36 +34,33 @@ public: bool getCmStatus() { return isCmOpened; } - void processCBdatas(net_event_info_t *event_cb, void *user_data); - - bool getDeviceName(char *deviceName); - bool getHomeURL(char *homeURL); - bool getProxyAddr(char *proxyAddr); - int getProxyPort(); + void open_callback(connection_error_e result, void* user_data); + void close_callback(connection_error_e result, void* user_data); + bool getInterfaceName(const char **deviceName); + bool getProxyAddr(const char **proxyAddr); + bool getHomeUrl(const char **homeURL); private: MmsPluginCmAgent(); ~MmsPluginCmAgent(); static MmsPluginCmAgent *pInstance; - /* register/deregister is called once at initialization/finalization of MMS plugin */ - bool registration(); - void deregistration(); - - void lock() { mx.lock(); } void unlock() { mx.unlock(); } void signal() { cv.signal(); } void setCmStatus() { isCmOpened = true; } void resetCmStatus() { isCmOpened = false; } - // shared variable between CmAgent and Dnet callback bool isCmOpened; + bool isCmRegistered; + + char *home_url; + char *interface_name; + char *proxy_address; Mutex mx; CndVar cv; - net_profile_info_t mmsProfile; }; #endif //MMS_PLUGIN_CONNMAN_H diff --git a/plugin/mms_plugin/include/MmsPluginHttp.h b/plugin/mms_plugin/include/MmsPluginHttp.h index ea3c9dd..d090de6 100755 --- a/plugin/mms_plugin/include/MmsPluginHttp.h +++ b/plugin/mms_plugin/include/MmsPluginHttp.h @@ -19,6 +19,7 @@ #include #include "MmsPluginTypes.h" +#include "MsgMutex.h" #define MSG_MMS_HH_CONTENT_TYPE "application/vnd.wap.mms-message" #define MSG_MMS_HH_ACCEPT "application/vnd.wap.mms-message, */*" @@ -43,23 +44,46 @@ enum _MMS_HTTP_HEADER_FIELD_E { MMS_HH_WAP_PROFILE }; +typedef enum _MMS_HTTP_TRANSACTION_TYPE_E { + MMS_HTTP_TRANSACTION_TYPE_UNKNOWN = 0, + MMS_HTTP_TRANSACTION_TYPE_GET, + MMS_HTTP_TRANSACTION_TYPE_POST, +} MMS_HTTP_TRANSACTION_TYPE_E; + +typedef enum _MMS_HTTP_ERROR_E { + MMS_HTTP_ERROR_NONE = 0, + MMS_HTTP_ERROR_ABORT, + MMS_HTTP_ERROR_TRANSACTION_TYPE, + MMS_HTTP_ERROR_TRANSACTION, +} MMS_HTTP_ERROR_E; + +typedef struct _http_session_info_s { + MMS_HTTP_TRANSACTION_TYPE_E transaction_type; + const char *url; + const char *proxy; + const char *interface; + const char *post_data; + unsigned int post_data_len; + char *response_data; + unsigned int response_data_len; +} http_request_info_s; + class MmsPluginHttpAgent { public: static MmsPluginHttpAgent *instance(); - int cmdRequest(MMS_HTTP_CMD_TYPE_T cmdType); - - int setSession(mmsTranQEntity *qEntity); - - void clearSession(); - - void SetMMSProfile(); + MMS_HTTP_ERROR_E httpRequest(http_request_info_s &request_info); - MMS_PLUGIN_HTTP_DATA_S *getHttpConfigData(); - MMS_PLUGIN_HTTP_CONTEXT_S *getMmsPldCd(); + void setAbortFlag(){ + MutexLocker locker(mx); + abort = true; + }; - MMS_PLUGIN_HTTP_DATA_S httpConfigData; + bool getAbortFlag(){ + MutexLocker locker(mx); + return abort; + }; private: static MmsPluginHttpAgent *pInstance; @@ -67,9 +91,24 @@ class MmsPluginHttpAgent MmsPluginHttpAgent(); ~MmsPluginHttpAgent(); - MMS_PLUGIN_HTTP_CONTEXT_S mmsPlgCd; + void initSession(); + MMS_HTTP_ERROR_E setSession(http_request_info_s &request_info); + MMS_HTTP_ERROR_E startTransaction(); + void clearSession(); + + void initAbortFlag(){ + MutexLocker locker(mx); + abort = false; + }; + + MMS_HTTP_TRANSACTION_TYPE_E transaction_type; + + void *session_header; + void *session_option; - std::map httpCmdHandler; + FILE *respfile; + bool abort; + Mutex mx; }; #endif //MMS_PLUGIN_HTTP_H -- 2.7.4