Fix call waiting crash
[platform/core/telephony/tel-plugin-imc.git] / src / s_ss.c
index 40e46fc..0d76b6e 100644 (file)
@@ -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);
                }
@@ -733,10 +733,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 +750,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 +803,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 +814,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 +962,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 +1076,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 +1142,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 +1246,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 +1295,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 +1306,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 +1388,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 +1437,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 +1448,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 +1693,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 +1809,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 +1884,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 +2082,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 +2197,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 +2326,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 +2348,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 +2395,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 +2519,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 +2577,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 +2638,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;
@@ -2760,7 +2764,7 @@ gboolean s_ss_init(TcorePlugin *cp, CoreObject *co_ss)
 
        co_call = tcore_plugin_ref_core_object(cp,
                                                CORE_OBJECT_TYPE_CALL);
-       if (co_call) {
+       if (co_call == NULL) {
                err("Can't find CALL core object");
                return FALSE;
        }