int sflphone_place_call(callable_obj_t * c, SFLPhoneClient *client) { account_t * account = NULL; if (c == NULL) { g_warning("Callable object is NULL while making new call"); return -1; } g_debug("Placing call from %s to %s using account %s", c->_display_name, c->_peer_number, c->_accountID); if (c->_state != CALL_STATE_DIALING) { g_warning("Call not in state dialing, cannot place call"); return -1; } if (!c->_peer_number || strlen(c->_peer_number) == 0) { g_warning("No peer number set for this call"); return -1; } // Get the account for this call if (strlen(c->_accountID) != 0) { g_debug("Account %s already set for this call", c->_accountID); account = account_list_get_by_id(c->_accountID); } else { g_debug("No account set for this call, use first of the list"); account = account_list_get_current(); } // Make sure the previously found account is registered, take first one registered elsewhere if (account) { const gchar *status = account_lookup(account, CONFIG_ACCOUNT_REGISTRATION_STATUS); if (!utf8_case_equal(status, "REGISTERED")) { // Place the call with the first registered account account = account_list_get_by_state(ACCOUNT_STATE_REGISTERED); } } // If there is no account specified or found, fallback on IP2IP call if(account == NULL) { g_debug("Could not find an account for this call, making ip to ip call"); account = account_list_get_by_id("IP2IP"); if (account == NULL) { g_warning("Actions: Could not determine any account for this call"); return -1; } } // 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, client); c->_history_state = g_strdup(OUTGOING_STRING); return 0; }
account_t* account_list_get_current() { // No account registered if (account_list_get_registered_accounts() == 0) return NULL; // if we are here, it means that we have at least one registered account in the list // So we get the first one return account_list_get_by_state(ACCOUNT_STATE_REGISTERED); }