Skip to content
Snippets Groups Projects
Commit aadc235d authored by Alexandre Savard's avatar Alexandre Savard
Browse files

#9981: Refactor place call function's logic

parent 2ceaf1dd
No related branches found
No related tags found
No related merge requests found
...@@ -749,16 +749,24 @@ sflphone_place_call(callable_obj_t * c) ...@@ -749,16 +749,24 @@ sflphone_place_call(callable_obj_t * c)
{ {
account_t * account = NULL; account_t * account = NULL;
DEBUG("Actions: Placing call with %s @ %s and accountid %s", c->_display_name, c->_peer_number, c->_accountID); if(c == NULL) {
ERROR("Actions: Callable object is NULL while making new call");
if (c->_state != CALL_STATE_DIALING)
return -1; return -1;
}
DEBUG("Actions: Placing call from %s to %s using account %s", c->_display_name, c->_peer_number, c->_accountID);
if (!*c->_peer_number) if (c->_state != CALL_STATE_DIALING) {
ERROR("Actions: Call not in state dialing, cannot place call");
return -1; return -1;
}
DEBUG("Actions: Get account for this call"); if (!c->_peer_number || strlen(c->_peer_number) == 0) {
ERROR("Actions: No peer number set for this call");
return -1;
}
// Get the account for this call
if (strlen(c->_accountID) != 0) { if (strlen(c->_accountID) != 0) {
DEBUG("Actions: Account %s already set for this call", c->_accountID); DEBUG("Actions: Account %s already set for this call", c->_accountID);
account = account_list_get_by_id(c->_accountID); account = account_list_get_by_id(c->_accountID);
...@@ -767,30 +775,31 @@ sflphone_place_call(callable_obj_t * c) ...@@ -767,30 +775,31 @@ sflphone_place_call(callable_obj_t * c)
account = account_list_get_current(); account = account_list_get_current();
} }
if (account == NULL) { // Make sure the previously found account is registered, take first one registered elsewhere
DEBUG("Actions: Unexpected condition: account_t is NULL in %s at %d for accountID %s", __FILE__, __LINE__, c->_accountID); if (account) {
return -1; gpointer status = g_hash_table_lookup(account->properties, "Status");
if (!utf8_case_equal(status, "REGISTERED")) {
// Place the call with the first registered account
account = account_list_get_by_state(ACCOUNT_STATE_REGISTERED);
}
} }
gpointer status = g_hash_table_lookup(account->properties, "Status"); // If there is no account specified or found, fallback on IP2IP call
if (utf8_case_equal(status, "REGISTERED")) { if(account == NULL) {
/* The call is made with the current account */ DEBUG("Actions: Could not find an account for this call, making ip to ip call");
// free memory for previous account id and get a new one account = account_list_get_by_id("IP2IP");
g_free(c->_accountID); if (account == NULL) {
c->_accountID = g_strdup(account->accountID); ERROR("Actions: Could not determine any account for this call");
dbus_place_call(c); return -1;
} else { }
/* Place the call with the first registered account
* and switch the current account.
* If we are here, we can be sure that there is at least one.
*/
account = account_list_get_by_state(ACCOUNT_STATE_REGISTERED);
g_free(c->_accountID);
c->_accountID = g_strdup(account->accountID);
dbus_place_call(c);
notify_current_account(account);
} }
// free memory for previous account id and use the new one in case it changed
g_free(c->_accountID);
c->_accountID = g_strdup(account->accountID);
dbus_place_call(c);
notify_current_account(account);
c->_history_state = g_strdup(OUTGOING_STRING); c->_history_state = g_strdup(OUTGOING_STRING);
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment