Fix call waiting crash
[platform/core/telephony/tel-plugin-imc.git] / src / s_call.c
index 8a06e10..7a89ac9 100644 (file)
@@ -844,7 +844,7 @@ static void on_confirmation_call_outgoing(TcorePending *p, int data_len, const v
                err("User Request is NULL");
        }
 
-       dbg("Exit")
+       dbg("Exit");
        return;
 }
 
@@ -1491,21 +1491,49 @@ static void on_confirmation_call_swap(TcorePending *p, int data_len, const void
        return;
 }
 
-static void on_confirmation_set_sound_path(TcorePending *p, int data_len, const void *data, void *user_data)
+static void on_confirmation_set_sound_path(TcorePending *p, int data_len,
+                                               const void *data,
+                                               void *user_data)
 {
        const TcoreATResponse *resp = data;
        struct tnoti_call_sound_path *snd_path = user_data;
+       struct tresp_call_sound_set_path resp_set_sound_path;
+       UserRequest *ur = tcore_pending_ref_user_request(p);
        TcorePlugin *plugin = tcore_pending_ref_plugin(p);
+       CoreObject *co_call;
 
-       if (resp->success > 0) {
-               tcore_server_send_notification(tcore_plugin_ref_server(plugin),
-                                                               tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL),
-                                                               TNOTI_CALL_SOUND_PATH,
-                                                               sizeof(struct tnoti_call_sound_path),
-                                                               (void *)snd_path);
-       } else {
-               dbg("Error in set sound path");
+       if (ur == NULL) {
+               err("User Request is NULL");
+               g_free(user_data);
+               return;
+       }
+
+       if (resp->success <= 0) {
+
+               dbg("RESPONSE NOT OK");
+               resp_set_sound_path.err = TRUE;
+
+               goto out;
        }
+
+       dbg("RESPONSE OK");
+       resp_set_sound_path.err = FALSE;
+
+       co_call = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_CALL);
+
+       /* Notify control plugin about sound path */
+       tcore_server_send_notification(tcore_plugin_ref_server(plugin),
+                                       co_call, TNOTI_CALL_SOUND_PATH,
+                                       sizeof(struct tnoti_call_sound_path),
+                                       snd_path);
+
+out:
+       /* Answer TAPI request */
+       tcore_user_request_send_response(ur, TRESP_CALL_SET_SOUND_PATH,
+                               sizeof(resp_set_sound_path),
+                               &resp_set_sound_path);
+
+       g_free(user_data);
 }
 
 static void on_confirmation_call_set_source_sound_path(TcorePending *p, int data_len, const void *data, void *user_data)
@@ -2453,7 +2481,7 @@ static void on_notification_call_incoming(CoreObject *o, const void *data, void
                return;
        }
 
-       dbg("freeing  at token")
+       dbg("freeing  at token");
        tcore_at_tok_free(tokens);
 
        eflag = g_new0(gboolean, 1);
@@ -2603,7 +2631,7 @@ static TReturn s_call_outgoing(CoreObject *o, UserRequest *ur)
 
        data = (struct treq_call_dial *) tcore_user_request_ref_data(ur, 0);
        if (data->type == CALL_TYPE_VIDEO) {
-               dbg("invalid call type")
+               dbg("invalid call type");
                return TCORE_RETURN_FAILURE;
        }
 
@@ -3009,7 +3037,7 @@ static TReturn s_call_send_dtmf(CoreObject *o, UserRequest *ur)
        g_free(cmd_str);
 
        if (!ret) {
-               dbg("AT request sent failed")
+               dbg("AT request sent failed");
                return TCORE_RETURN_FAILURE;
        }
 
@@ -3079,8 +3107,14 @@ static TReturn s_call_set_sound_path(CoreObject *o, UserRequest *ur)
        }
 
        if (g_str_has_prefix(cp_name, "mfld_blackbay") == TRUE) {
-               struct tnoti_call_sound_path tnoti_snd_path;
-               tnoti_snd_path.path = sound_path->path;
+               struct tnoti_call_sound_path *tnoti_snd_path;
+
+               tnoti_snd_path = g_try_new0(struct tnoti_call_sound_path, 1);
+               if (!tnoti_snd_path)
+                       return TCORE_RETURN_ENOMEM;
+
+               tnoti_snd_path->path = sound_path->path;
+
                /* Configure modem I2S1 to 8khz, mono, PCM if routing to bluetooth */
                if (sound_path->path == CALL_SOUND_PATH_BLUETOOTH || sound_path->path == CALL_SOUND_PATH_STEREO_BLUETOOTH) {
                        call_prepare_and_send_pending_request(o, "AT+XDRV=40,4,3,0,1,0,0,0,0,0,0,0,21", NULL, TCORE_AT_NO_RESULT, NULL);
@@ -3109,7 +3143,7 @@ static TReturn s_call_set_sound_path(CoreObject *o, UserRequest *ur)
                dbg("XDRV req-cmd for source type  : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
                tcore_pending_set_request_data(pending, 0, req);
                ur_dup = tcore_user_request_ref(ur);
-               ret = _call_request_message(pending, o, ur_dup, on_confirmation_set_sound_path, &tnoti_snd_path);
+               ret = _call_request_message(pending, o, ur_dup, on_confirmation_set_sound_path, tnoti_snd_path);
 
        } else {