Replacing free with g_free based on changes in util_removeQuotes.
[platform/core/telephony/tel-plugin-imc.git] / src / s_ss.c
old mode 100644 (file)
new mode 100755 (executable)
index 0781ac7..35083be
@@ -206,7 +206,7 @@ static void _ss_ussd_notification(TcorePlugin *p, const char *ussd_str, enum tel
        }
        dbg("noti.str - %s", noti.str);
 
-       core_obj = tcore_plugin_ref_core_object(p, "ss");
+       core_obj = tcore_plugin_ref_core_object(p, CORE_OBJECT_TYPE_SS);
        tcore_server_send_notification(tcore_plugin_ref_server(p),
                                                                   core_obj,
                                                                   TNOTI_SS_USSD,
@@ -256,7 +256,7 @@ static gboolean on_notification_ss_ussd(CoreObject *o, const void *data, void *u
                        if (str) {
                                memset(str, 0x00, strlen(ussd_string) - 1);
                        } else {
-                               dbg("malloc failed")
+                               dbg("malloc failed");
                                if (NULL != tokens) {
                                        tcore_at_tok_free(tokens);
                                }
@@ -339,12 +339,12 @@ static gboolean on_notification_ss_ussd(CoreObject *o, const void *data, void *u
 
                        _ss_ussd_response(ur, ussd_str, type, status);
                }
-               
-CATCH:  
+
+CATCH:
                if (NULL != tokens) {
                        tcore_at_tok_free(tokens);
                }
-               
+
                if (NULL != str) {
                        free(str);
                }
@@ -437,7 +437,7 @@ static gboolean on_notification_ss_info(CoreObject *o, const void *data, void *u
        dbg("function enter");
 
        plugin = tcore_object_ref_plugin(o);
-       co = tcore_plugin_ref_core_object(plugin, "call");
+       co = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL);
        if (!co) {
                dbg("[ error ] plugin_ref_core_object : call");
                return FALSE;
@@ -597,9 +597,7 @@ OUT:
                tcore_at_tok_free(tokens);
        }
 
-       if (NULL != number) {
-               g_free(number);
-       }
+       g_free(number);
        return TRUE;
 }
 
@@ -733,10 +731,10 @@ static void on_response_ss_forwarding_set(TcorePending *p, int data_len, const v
        CoreObject *o = 0;
        UserRequest *ur = 0, *dup_ur = 0;
        struct ss_confirm_info *info = 0;
-       struct tresp_ss_forwarding resp;
+       struct tresp_ss_forwarding resp = {0,};
        GSList *tokens = NULL;
        const char *line;
-       int err;
+       int error;
        const TcoreATResponse *response;
 
        dbg("function enter");
@@ -750,18 +748,19 @@ static void on_response_ss_forwarding_set(TcorePending *p, int data_len, const v
        if (response->success > 0) {
                dbg("RESPONSE OK");
                resp.err = SS_ERROR_NONE;
-               resp.record = 0;
        } else {
                dbg("RESPONSE NOT OK");
-               resp.record = 0;
+
+               /* Extract Error */
                line = (const char *) response->final_response;
                tokens = tcore_at_tok_new(line);
 
                if (g_slist_length(tokens) < 1) {
-                       dbg("err cause not specified or string corrupted");
+                       dbg("Error cause not specified or string corrupted");
                        resp.err = SS_ERROR_SYSTEMFAILURE;
                } else {
-                       err = atoi(g_slist_nth_data(tokens, 0));
+                       error = atoi(g_slist_nth_data(tokens, 0));
+                       err("Error: [%d]", error);
                        // / TODO: CMEE error mapping is required.
                        resp.err = SS_ERROR_SYSTEMFAILURE;
                }
@@ -802,7 +801,7 @@ static void on_response_ss_waiting_set(TcorePending *p, int data_len, const void
        UserRequest *ur = 0;
        UserRequest *ur_dup = 0;
        struct ss_confirm_info *info = 0;
-       struct tresp_ss_waiting resp;
+       struct tresp_ss_waiting resp = {0,};
        GSList *tokens = NULL;
        const char *line;
        int err;
@@ -813,40 +812,43 @@ static void on_response_ss_waiting_set(TcorePending *p, int data_len, const void
        core_obj = tcore_pending_ref_core_object(p);
        ur = tcore_pending_ref_user_request(p);
 
-       info = (struct ss_confirm_info *) user_data;
+       info = (struct ss_confirm_info *)user_data;
 
        if (response->success > 0) {
                dbg("RESPONSE OK");
                resp.err = SS_ERROR_NONE;
-               resp.record = 0;
        } else {
                dbg("RESPONSE NOT OK");
-               resp.record = 0;
+
+               /* Extract Error */
                line = (const char *) response->final_response;
                tokens = tcore_at_tok_new(line);
 
                if (g_slist_length(tokens) < 1) {
-                       dbg("err cause not specified or string corrupted");
+                       dbg("Error cause not specified or string corrupted");
                        resp.err = SS_ERROR_SYSTEMFAILURE;
                } else {
                        err = atoi(g_slist_nth_data(tokens, 0));
-                       // / TODO: CMEE error mapping is required.
+
+                       /* TODO: CMEE error mapping is required. */
                        resp.err = SS_ERROR_SYSTEMFAILURE;
                }
+
+               /* Free tokens */
                tcore_at_tok_free(tokens);
        }
 
-       dbg("on_response_ss_waiting_set - rsp.err : %d, ur : %x, class : %d", resp.err, ur, info->class);
-
+       dbg("Call Waiting - Error: [%d], UR: [0x%x] class: [0x%2x]", resp.err, ur, info->class);
        if (resp.err == SS_ERROR_NONE) {
                ur_dup = tcore_user_request_ref(ur);
-               dbg("Get waiting call status");
+
+               dbg("Get Call Waiting status");
                _ss_waiting_get(core_obj, ur_dup, info->class, info->resp);
        } else {
                if (ur) {
                        tcore_user_request_send_response(ur, info->resp, sizeof(struct tresp_ss_waiting), &resp);
                } else {
-                       dbg("[ error ] ur is 0");
+                       err("User request is NULL");
                }
        }
        g_free(user_data);
@@ -958,7 +960,7 @@ static void on_response_ss_barring_get(TcorePending *p, int data_len, const void
                dbg("total records : %d", countRecords);
        } else {
                countRecords = 0;
-               dbg("no active status - return to user")
+               dbg("no active status - return to user");
        }
        resp.record_num = countRecords;
        resp.record = 0;
@@ -1072,7 +1074,7 @@ error:
                resp.record_num = countValidRecords;
                resp.err = SS_ERROR_NONE;
        } else {
-               dbg("no active status - return to user")
+               dbg("no active status - return to user");
        }
 
        if (response->success > 0) {
@@ -1138,7 +1140,7 @@ static void on_response_ss_forwarding_get(TcorePending *p, int data_len, const v
                dbg("total records : %d", countRecords);
        } else {
                countRecords = 0;
-               dbg("no active status - return to user")
+               dbg("no active status - return to user");
        }
        resp.record_num = countRecords;
        resp.record = 0;
@@ -1242,7 +1244,7 @@ error:
                resp.record_num = countValidRecords;
                resp.err = SS_ERROR_NONE;
        } else {
-               dbg("no active status - return to user")
+               dbg("no active status - return to user");
        }
 
        if (response->success > 0) {
@@ -1291,7 +1293,7 @@ static void on_response_ss_waiting_get(TcorePending *p, int data_len, const void
        char *classx_str, *status;
        const TcoreATResponse *response;
 
-       dbg("function enter")
+       dbg("function enter");
        response = data;
        ur = tcore_pending_ref_user_request(p);
        info = (struct ss_confirm_info *) user_data;
@@ -1302,7 +1304,7 @@ static void on_response_ss_waiting_get(TcorePending *p, int data_len, const void
                dbg("total records : %d", countRecords);
        } else {
                countRecords = 0;
-               dbg("no active status - return to user")
+               dbg("no active status - return to user");
        }
        resp.record_num = countRecords;
        resp.record = 0;
@@ -1384,7 +1386,7 @@ error:
                resp.record_num = countValidRecords;
                resp.err = SS_ERROR_NONE;
        } else {
-               dbg("no active status - return to user")
+               dbg("no active status - return to user");
        }
 
        if (response->success > 0) {
@@ -1433,7 +1435,7 @@ static void on_response_ss_cli_get(TcorePending *p, int data_len, const void *da
        GSList *tokens = NULL;
        const TcoreATResponse *response;
 
-       dbg("function enter")
+       dbg("function enter");
        response = data;
        ur = tcore_pending_ref_user_request(p);
        p_type = (enum telephony_ss_cli_type *) (user_data);
@@ -1444,7 +1446,7 @@ static void on_response_ss_cli_get(TcorePending *p, int data_len, const void *da
 
                if (*p_type == SS_CLI_TYPE_CLIR) {
                        // +CLIR: <n> <m>
-                       dbg("CLI type is CLIR")
+                       dbg("CLI type is CLIR");
                        // parse <n>
                        status = g_slist_nth_data(tokens, 0);
 
@@ -1689,7 +1691,7 @@ static TReturn _ss_barring_set(CoreObject *o, UserRequest *ur, enum telephony_ss
        g_free(cmd_str);
 
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -1805,7 +1807,7 @@ static TReturn _ss_barring_get(CoreObject *o,
        g_free(cmd_str);
 
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -1880,7 +1882,7 @@ static TReturn s_ss_barring_change_password(CoreObject *o, UserRequest *ur)
        ret = _ss_request_message(pending, o, ur, on_response_ss_barring_change_pwd, user_data);
        g_free(cmd_str);
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -2078,7 +2080,7 @@ static TReturn _ss_forwarding_set(CoreObject *o, UserRequest *ur, enum telephony
        g_free(cmd_str);
 
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -2193,7 +2195,7 @@ static TReturn _ss_forwarding_get(CoreObject *o,
        g_free(cmd_str);
 
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -2322,7 +2324,7 @@ static TReturn _ss_waiting_set(CoreObject *o, UserRequest *ur, enum telephony_ss
        ret = _ss_request_message(pending, o, ur, on_response_ss_waiting_set, user_data);
        g_free(cmd_str);
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -2344,7 +2346,7 @@ static TReturn _ss_waiting_get(CoreObject *o,
        TcorePending *pending = NULL;
        TcoreATRequest *req;
 
-       dbg("function  enter")
+       dbg("function  enter");
        switch (class) {
        case SS_CLASS_ALL_TELE:
                classx = 7;
@@ -2391,7 +2393,7 @@ static TReturn _ss_waiting_get(CoreObject *o,
        ret = _ss_request_message(pending, o, ur, on_response_ss_waiting_get, user_data);
        g_free(cmd_str);
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -2515,7 +2517,7 @@ static TReturn s_ss_cli_get_status(CoreObject *o, UserRequest *ur)
        ret = _ss_request_message(pending, o, ur, on_response_ss_cli_get, user_data);
        g_free(cmd_str);
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -2573,7 +2575,7 @@ static TReturn s_ss_send_ussd(CoreObject *o, UserRequest *ur)
        g_free(cmd_str);
 
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                if (user_data != NULL) {
                        g_free(user_data);
                }
@@ -2634,7 +2636,7 @@ static TReturn s_ss_manage_call_send(CoreObject *o, UserRequest *ur, const char
 
        ret = _ss_request_message(pending, o, ur, (TcorePendingResponseCallback) cb, user_data);
        if (!ret) {
-               dbg("AT request sent failed ")
+               dbg("AT request sent failed ");
                return TCORE_RETURN_FAILURE;
        }
        return TCORE_RETURN_SUCCESS;
@@ -2751,45 +2753,30 @@ static TReturn s_ss_manage_call_4dn_send(CoreObject *o, UserRequest *ur, const c
        return ret;
 }
 
-gboolean s_ss_init(TcorePlugin *p, TcoreHal *h)
+gboolean s_ss_init(TcorePlugin *cp, CoreObject *co_ss)
 {
-       CoreObject *so = 0, *co = 0;
-       struct property_call_info *data = 0;
+       CoreObject *co_call = NULL;
 
-       so = tcore_ss_new(p, "ss", &ss_ops, h);
-       if (!so) {
-               dbg("[ error ] ss_new()");
-               return FALSE;
-       }
+       tcore_ss_override_ops(co_ss, &ss_ops);
 
-       co = tcore_plugin_ref_core_object(p, "call");
-       if (!co) {
-               dbg("[ error ] plugin_ref_core_object");
+
+       co_call = tcore_plugin_ref_core_object(cp,
+                                               CORE_OBJECT_TYPE_CALL);
+       if (co_call == NULL) {
+               err("Can't find CALL core object");
                return FALSE;
        }
 
-       tcore_call_control_set_operations(co, &call_ops);
-
-       tcore_object_add_callback(so, "+CSSU", on_notification_ss_info, 0);
-       tcore_object_add_callback(so, "+CSSI", on_notification_ss_info, 0);
-       tcore_object_add_callback(so, "+CUSD", on_notification_ss_ussd, 0);
+       tcore_call_override_ops(co_call, NULL, &call_ops);
 
-       data = calloc(sizeof(struct property_call_info *), 1);
-       tcore_plugin_link_property(p, "SS", data);
+       tcore_object_override_callback(co_ss, "+CSSU", on_notification_ss_info, NULL);
+       tcore_object_override_callback(co_ss, "+CSSI", on_notification_ss_info, NULL);
+       tcore_object_override_callback(co_ss, "+CUSD", on_notification_ss_ussd, NULL);
 
        return TRUE;
 }
 
-void s_ss_exit(TcorePlugin *p)
+void s_ss_exit(TcorePlugin *cp, CoreObject *co_ss)
 {
-       CoreObject *o;
-       struct property_network_info *data;
-
-       o = tcore_plugin_ref_core_object(p, "ss");
-
-       data = tcore_plugin_ref_property(p, "SS");
-       if (data)
-               free(data);
-
-       tcore_ss_free(o);
+       dbg("Exit");
 }