Allocate memory for telephony information when it needs 31/194831/1
authorYu <jiung.yu@samsung.com>
Fri, 7 Dec 2018 08:41:13 +0000 (17:41 +0900)
committerYu <jiung.yu@samsung.com>
Fri, 7 Dec 2018 08:41:24 +0000 (17:41 +0900)
Change-Id: Ifec25d952f6e550e608e6ea35658f6ded4c9e3d6
Signed-off-by: Yu Jiung <jiung.yu@samsung.com>
include/inm-telephony.h
include/inm-util.h
src/inm-connman-service.c
src/inm-telephony.c

index f949aec88ba4abea2b2ad26b838ba3aad973204a..a0f0e4f84ba312fb8fdfe990dbd8b58ebcc1f0b9 100644 (file)
@@ -141,10 +141,10 @@ typedef struct {
        net_auth_type_e auth_type;
 
        /** UserName to be used during authentication */
-       char user_name[INM_PDP_AUTH_USERNAME_LEN_MAX + 1];
+       char *user_name;
 
        /** Password to be used during authentication */
-       char password[INM_PDP_AUTH_PASSWORD_LEN_MAX + 1];
+       char *password;
 } net_auth_info_s;
 
 /**
@@ -154,7 +154,7 @@ typedef struct {
        gint type;
        gboolean setup_required;
        /** Profile name(path) */
-       char profile_name[INM_PROFILE_NAME_LEN_MAX + 1];
+       char *profile_name;
        /** Service type of this profile context */
        net_service_type_e service_type;
        /** Pdn type of this profile context */
@@ -162,20 +162,21 @@ typedef struct {
        /** Roam Pdn type of this profile context */
        net_pdn_type_e roam_pdn_type;
        /** Network Access Point Name */
-       char apn[INM_PDP_APN_LEN_MAX + 1];
+       char *apn;
        /** Authentication info of the PDP profile */
        net_auth_info_s auth_info;
        /**Proxy address */
-       char proxy_addr[NET_PROXY_LEN_MAX + 1];
+       char *proxy_addr;
        /** Browser Home URL or MMS server URL */
-       char home_url[INM_HOME_URL_LEN_MAX + 1];
-       char keyword[INM_PDP_APN_LEN_MAX + 1];
+       char *home_url;
+       char *keyword;
        gboolean default_conn;
        gboolean editable;
        gboolean hidden;
 } inm_telephony_profile_s;
 
 int inm_telephony_get_pdp_profile(gchar *path, inm_telephony_profile_s *profile_info);
+void inm_telephony_destroy_pdp_profile(inm_telephony_profile_s *profile_info);
 
 #ifdef __cplusplus
 }
index 342e6e61293d43961c6ddc4c73d23f6b8dadaf13..fb50cc66dce5a4132203c4b37ae2a58569bb648d 100644 (file)
@@ -67,6 +67,13 @@ extern "C" {
                INM_LOGI("signal params type [%s]", g_variant_get_type_string(parameters));\
        } while (0)
 
+#define CHECK_STRING_AND_COPY(src, dst) do {\
+               if (!src || strlen(src) == 0) \
+                       break; \
+               g_free(dst); \
+               dst = g_strdup(src); \
+       } while (0)
+
 #define REMOVE_G_SOURCE(g_source)\
        do {\
                if ((g_source)) {\
index 1417ad3a86a6c4a43e095cae823f83ae39c9bbfc..b31ad6623fe0349079c0f744760129f139699725 100644 (file)
@@ -1289,6 +1289,9 @@ static void __destroy_service_data(gpointer user_data)
 
        INM_LOGI("[%s] removed", service_data->name);
 
+       if (service_data->type == CONNMAN_SERVICE_TYPE_CELLULAR)
+               inm_telephony_destroy_pdp_profile(&(service_data->priv_info.cell));
+
        g_free(service_data->name);
        g_free(service_data);
        __INM_FUNC_EXIT__;
@@ -1691,20 +1694,16 @@ static inline void __add_wifi_priv_info(connman_service_s *service)
 
 static inline void __add_cell_priv_info(connman_service_s *service)
 {
-       inm_telephony_profile_s telephony_info = {0,};
        int ret = 0;
        __INM_FUNC_ENTER__;
 
        if (!service)
                return;
 
-       ret = inm_telephony_get_pdp_profile(service->name, &telephony_info);
+       ret = inm_telephony_get_pdp_profile(service->name,
+                       &(service->priv_info.cell));
        if (ret < 0)
                INM_LOGI("get pdp profile failed");
-       else
-               memcpy(&(service->priv_info.cell),
-                               &telephony_info,
-                               sizeof(inm_telephony_profile_s));
 
        __INM_FUNC_EXIT__;
        return;
index 2e1fecbe5584edf9c7a38a005a9a223168fb4e95..239eb35ae9d26e4221f0c0771c4fb9324c142b06 100644 (file)
@@ -57,30 +57,6 @@ typedef struct {
        gchar profile_name[INM_PROFILE_NAME_LEN_MAX + 1];
 } inm_profile_name_s;
 
-static method_param_s tel_method_params[] = {
-               {
-                               .bus_name = TELEPHONY_SERVICE,
-                               .object_path = TELEPHONY_MASTER_PATH,
-                               .interface_name = TELEPHONY_MASTER_INTERFACE,
-                               .method_name = "GetModems",
-                               .parameters = NULL,
-               },
-               {
-                               .bus_name = TELEPHONY_SERVICE,
-                               .object_path = NULL,
-                               .interface_name = TELEPHONY_MODEM_INTERFACE,
-                               .method_name = "GetProfileList",
-                               .parameters = NULL,
-               },
-               {
-                               .bus_name = TELEPHONY_SERVICE,
-                               .object_path = NULL,
-                               .interface_name = TELEPHONY_PROFILE_INTERFACE,
-                               .method_name = "GetProfile",
-                               .parameters = NULL,
-               },
-};
-
 static void __get_modem_properties(GVariant *reply, gpointer user_data)
 {
        GVariantIter *iter = NULL;
@@ -111,9 +87,16 @@ static int __get_modem_object_path(GSList **modem_path_list)
 
        int ret = 0;
        __INM_FUNC_ENTER__;
+       method_param_s tel_method_params = {
+               .bus_name = TELEPHONY_SERVICE,
+               .object_path = TELEPHONY_MASTER_PATH,
+               .interface_name = TELEPHONY_MASTER_INTERFACE,
+               .method_name = "GetModems",
+               .parameters = NULL,
+       };
 
        ret = inm_gdbus_method_call(
-                       &(tel_method_params[TELEPHONY_CMD_GET_MODEMS]),
+                       &tel_method_params,
                        __get_modem_properties,
                        (gpointer)modem_path_list);
        if (ret != INM_GDBUS_ERROR_NONE) {
@@ -156,6 +139,13 @@ static GSList *__get_profile_list()
        int ret = 0;
 
        __INM_FUNC_ENTER__;
+       method_param_s tel_method_params = {
+               .bus_name = TELEPHONY_SERVICE,
+               .object_path = NULL,
+               .interface_name = TELEPHONY_MODEM_INTERFACE,
+               .method_name = "GetProfileList",
+               .parameters = NULL,
+       };
 
        ret = __get_modem_object_path(&modem_path_list);
        if (ret < 0) {
@@ -170,9 +160,9 @@ static GSList *__get_profile_list()
                path = (const char *)list->data;
 
                INM_LOGI("path: %s", path);
-               tel_method_params[TELEPHONY_CMD_GET_PROFILE_LIST].object_path = path;
+               tel_method_params.object_path = path;
                ret = inm_gdbus_method_call(
-                               &(tel_method_params[TELEPHONY_CMD_GET_PROFILE_LIST]),
+                               &tel_method_params,
                                __get_profiles,
                                (gpointer)&profile_list);
                if (ret != INM_GDBUS_ERROR_NONE)
@@ -282,10 +272,9 @@ static int __search_pdp_profile(char* profile_name, inm_telephony_profile_s *pro
        if (idx >= profile_cnt) {
                INM_LOGW("There is no matching PDP profiles");
                ret = -1;;
-       } else {
-               g_strlcpy(profile_info->profile_name,
-                               profile_list[idx].profile_name, INM_PROFILE_NAME_LEN_MAX);
-       }
+       } else
+               CHECK_STRING_AND_COPY(profile_list[idx].profile_name,
+                               profile_info->profile_name);
 
        g_free(profile_list);
 
@@ -296,7 +285,8 @@ static int __search_pdp_profile(char* profile_name, inm_telephony_profile_s *pro
 static inline void __get_path(const gchar *value, inm_telephony_profile_s *profile_info)
 {
        if (value != NULL)
-               g_strlcpy(profile_info->profile_name, value, INM_PROFILE_NAME_LEN_MAX);
+               CHECK_STRING_AND_COPY(value,
+                               profile_info->profile_name);
 }
 
 static inline void __get_svc_ctg_id(const gchar *value, inm_telephony_profile_s *profile_info)
@@ -313,7 +303,8 @@ static inline void __get_svc_ctg_id(const gchar *value, inm_telephony_profile_s
 static inline void __get_apn(const gchar *value, inm_telephony_profile_s *profile_info)
 {
        if (value != NULL)
-               g_strlcpy(profile_info->apn, value, INM_PDP_APN_LEN_MAX);
+               CHECK_STRING_AND_COPY(value,
+                               profile_info->apn);
 }
 
 static inline void __get_pdp_protocol(const gchar *value, inm_telephony_profile_s *profile_info)
@@ -347,26 +338,29 @@ static inline void __get_auth_type(const gchar *value, inm_telephony_profile_s *
 static inline void __get_user_name(const gchar *value, inm_telephony_profile_s *profile_info)
 {
        if (value != NULL)
-               g_strlcpy(profile_info->auth_info.user_name, value, INM_PDP_AUTH_USERNAME_LEN_MAX);
-
+               CHECK_STRING_AND_COPY(value,
+                               profile_info->auth_info.user_name);
 }
 
 static inline void __get_password(const gchar *value, inm_telephony_profile_s *profile_info)
 {
        if (value != NULL)
-               g_strlcpy(profile_info->auth_info.password, value, INM_PDP_AUTH_PASSWORD_LEN_MAX);
+               CHECK_STRING_AND_COPY(value,
+                               profile_info->auth_info.password);
 }
 
 static inline void __get_proxy_addr(const gchar *value, inm_telephony_profile_s *profile_info)
 {
        if (value != NULL)
-               g_strlcpy(profile_info->proxy_addr, value, NET_PROXY_LEN_MAX);
+               CHECK_STRING_AND_COPY(value,
+                               profile_info->proxy_addr);
 }
 
 static inline void __get_home_url(const gchar *value, inm_telephony_profile_s *profile_info)
 {
        if (value != NULL)
-               g_strlcpy(profile_info->home_url, value, INM_HOME_URL_LEN_MAX);
+               CHECK_STRING_AND_COPY(value,
+                               profile_info->home_url);
 }
 
 static inline void __get_default_conn(const gchar *value, inm_telephony_profile_s *profile_info)
@@ -383,7 +377,8 @@ static inline void __get_default_conn(const gchar *value, inm_telephony_profile_
 static inline void __get_keyword(const gchar *value, inm_telephony_profile_s *profile_info)
 {
        if (value != NULL)
-               g_strlcpy(profile_info->keyword, value, INM_PDP_APN_LEN_MAX);
+               CHECK_STRING_AND_COPY(value,
+                               profile_info->keyword);
 }
 
 static inline void __get_editable(const gchar *value, inm_telephony_profile_s *profile_info)
@@ -471,9 +466,18 @@ static int __get_profile_info(inm_telephony_profile_s *profile_info)
                return -1;
        }
 
-       tel_method_params[TELEPHONY_CMD_GET_PROFILE].object_path = profile_info->profile_name;
+       method_param_s tel_method_params = {
+
+               .bus_name = TELEPHONY_SERVICE,
+               .object_path = NULL,
+               .interface_name = TELEPHONY_PROFILE_INTERFACE,
+               .method_name = "GetProfile",
+               .parameters = NULL,
+       };
+
+       tel_method_params.object_path = profile_info->profile_name;
        ret = inm_gdbus_method_call(
-                       &(tel_method_params[TELEPHONY_CMD_GET_PROFILE]),
+                       &tel_method_params,
                        __get_profile_properties,
                        (gpointer)profile_info);
        if (ret != INM_GDBUS_ERROR_NONE) {
@@ -503,3 +507,26 @@ int inm_telephony_get_pdp_profile(gchar *path, inm_telephony_profile_s *profile_
        __INM_FUNC_EXIT__;
        return 0;
 }
+void inm_telephony_destroy_pdp_profile(inm_telephony_profile_s *profile_info)
+{
+       __INM_FUNC_ENTER__;
+       if (!profile_info)
+               return;
+
+       g_free(profile_info->profile_name);
+       profile_info->profile_name = NULL;
+       g_free(profile_info->apn);
+       profile_info->apn = NULL;
+       g_free(profile_info->auth_info.password);
+       profile_info->auth_info.password = NULL;
+       g_free(profile_info->auth_info.user_name);
+       profile_info->auth_info.user_name = NULL;
+       g_free(profile_info->proxy_addr);
+       profile_info->proxy_addr = NULL;
+       g_free(profile_info->home_url);
+       profile_info->home_url = NULL;
+       g_free(profile_info->keyword);
+       profile_info->keyword = NULL;
+
+       __INM_FUNC_EXIT__;
+}