Commit 1c6cc5ca authored by Tristan Matthews's avatar Tristan Matthews

* #9490: fixed registration state change callback that was crashing client

parent e305ef45
......@@ -32,8 +32,9 @@
#include "account.h"
#include "manager.h"
#include "dbus/configurationmanager.h"
Account::Account(const std::string& accountID, const std::string &type) :
Account::Account(const std::string &accountID, const std::string &type) :
accountID_(accountID)
, username_()
, hostname_()
......@@ -54,8 +55,7 @@ Account::Account(const std::string& accountID, const std::string &type) :
}
Account::~Account()
{
}
{}
void Account::setRegistrationState(const RegistrationState &state)
{
......@@ -63,7 +63,8 @@ void Account::setRegistrationState(const RegistrationState &state)
registrationState_ = state;
// Notify the client
Manager::instance().connectionStatusNotification();
ConfigurationManager *c(Manager::instance().getDbusManager()->getConfigurationManager());
c->registrationStateChanged(accountID_, registrationState_);
}
}
......
......@@ -447,6 +447,11 @@
<signal name="accountsChanged" tp:name-for-bindings="accountsChanged">
</signal>
<signal name="registrationStateChanged" tp:name-for-bindings="registrationStateChanged">
<arg type="s" name="accountID"/>
<arg type="i" name="registration_state"/>
</signal>
<signal name="stunStatusFailure" tp:name-for_bindings="stunStatusFailure">
<arg type="s" name="reason">
</arg>
......
......@@ -1628,11 +1628,6 @@ void ManagerImpl::startVoiceMessageNotification(const std::string& accountId,
dbus_.getCallManager()->voiceMailNotify(accountId, nb_msg);
}
void ManagerImpl::connectionStatusNotification()
{
dbus_.getConfigurationManager()->accountsChanged();
}
/**
* Multi Thread
*/
......
......@@ -399,11 +399,6 @@ class ManagerImpl {
*/
void startVoiceMessageNotification(const std::string& accountId, int nb_msg);
/**
* Notify the client through DBus that registration state has been updated
*/
void connectionStatusNotification();
/**
* ConfigurationManager - Send registration request
* @param accountId The account to register/unregister
......
......@@ -127,9 +127,7 @@ account_list_get_current()
// if we are here, it means that we have at least one registered account in the list
// So we get the first one
account_t *current = account_list_get_by_state(ACCOUNT_STATE_REGISTERED);
return current;
return account_list_get_by_state(ACCOUNT_STATE_REGISTERED);
}
void account_list_set_current(account_t *current)
......@@ -148,45 +146,28 @@ void account_list_set_current(account_t *current)
const gchar * account_state_name(account_state_t s)
{
gchar * state;
switch (s) {
case ACCOUNT_STATE_REGISTERED:
state = _("Registered");
break;
return _("Registered");
case ACCOUNT_STATE_UNREGISTERED:
state = _("Not Registered");
break;
return _("Not Registered");
case ACCOUNT_STATE_TRYING:
state = _("Trying...");
break;
return _("Trying...");
case ACCOUNT_STATE_ERROR:
state = _("Error");
break;
return _("Error");
case ACCOUNT_STATE_ERROR_AUTH:
state = _("Authentication Failed");
break;
return _("Authentication Failed");
case ACCOUNT_STATE_ERROR_NETWORK:
state = _("Network unreachable");
break;
return _("Network unreachable");
case ACCOUNT_STATE_ERROR_HOST:
state = _("Host unreachable");
break;
return _("Host unreachable");
case ACCOUNT_STATE_ERROR_CONF_STUN:
state = _("Stun configuration error");
break;
return _("Stun configuration error");
case ACCOUNT_STATE_ERROR_EXIST_STUN:
state = _("Stun server invalid");
break;
case IP2IP_PROFILE_STATUS:
state = _("Ready");
break;
return _("Stun server invalid");
default:
state = _("Invalid");
break;
return _("Invalid");
}
return state;
}
void account_list_free_elm(gpointer elm, gpointer data UNUSED)
......
......@@ -41,14 +41,12 @@
* This enum have all the states an account can take.
*/
typedef enum {
/** Invalid state */
ACCOUNT_STATE_INVALID = 0,
/** The account is registered */
ACCOUNT_STATE_REGISTERED,
/** The account is not registered */
ACCOUNT_STATE_UNREGISTERED,
/** The account is trying to register */
ACCOUNT_STATE_TRYING,
/** The account is registered */
ACCOUNT_STATE_REGISTERED,
/** Error state. The account is not registered */
ACCOUNT_STATE_ERROR,
/** An authentification error occured. Wrong password or wrong username. The account is not registered */
......@@ -57,12 +55,12 @@ typedef enum {
ACCOUNT_STATE_ERROR_NETWORK,
/** Host is unreachable. The account is not registered */
ACCOUNT_STATE_ERROR_HOST,
/** Stun server configuration error. The account is not registered */
ACCOUNT_STATE_ERROR_CONF_STUN,
/** Stun server is not existing. The account is not registered */
ACCOUNT_STATE_ERROR_EXIST_STUN,
/** IP profile status **/
IP2IP_PROFILE_STATUS
/** Stun server configuration error. The account is not registered */
ACCOUNT_STATE_ERROR_CONF_STUN,
/** Invalid state */
ACCOUNT_STATE_INVALID
} account_state_t;
/** @struct account_t
......
......@@ -237,8 +237,6 @@ void sflphone_fill_account_list(void)
acc->state = ACCOUNT_STATE_ERROR_CONF_STUN;
else if (g_strcmp0(status , "ERROR_EXIST_STUN") == 0)
acc->state = ACCOUNT_STATE_ERROR_EXIST_STUN;
else if (g_strcmp0(status, "READY") == 0)
acc->state = IP2IP_PROFILE_STATUS;
else
acc->state = ACCOUNT_STATE_INVALID;
......
......@@ -1250,23 +1250,19 @@ void update_account_from_dialog(GtkWidget *dialog, account_t *account)
else
current_protocol = g_strdup("SIP");
if (g_strcmp0(current_protocol, "SIP") == 0) {
if (!IS_IP2IP) {
DEBUG("Config: Get new credentials");
account->credential_information = get_new_credential();
if (account->credential_information)
dbus_set_credentials(account);
}
}
if (!IS_IP2IP && g_strcmp0(current_protocol, "SIP") == 0)
account->credential_information = get_new_credential();
/** @todo Verify if it's the best condition to check */
if (g_strcmp0(account->accountID, "new") == 0)
dbus_add_account(account);
else
dbus_set_account_details(account);
// propagate changes to the daemon
codec_list_update_to_daemon(account);
if (account->credential_information)
dbus_set_credentials(account);
g_free(current_protocol);
gtk_widget_destroy(dialog);
......
......@@ -94,9 +94,9 @@ static void delete_account_cb(gpointer data)
static void
run_account_dialog(const gchar *selected_accountID)
{
account_t *selected_account = account_list_get_by_id(selected_accountID);
GtkWidget *dialog = show_account_window(selected_account);
update_account_from_dialog(dialog, selected_account);
account_t *account = account_list_get_by_id(selected_accountID);
GtkWidget *dialog = show_account_window(account);
update_account_from_dialog(dialog, account);
}
static void row_activated_cb(GtkTreeView *view,
......@@ -189,7 +189,7 @@ select_account_cb(GtkTreeSelection *selection, GtkTreeModel *model)
memset(&val, 0, sizeof(val));
gtk_tree_model_get_value(model, &iter, COLUMN_ACCOUNT_ID, &val);
gchar *selected_accountID = g_strdup(g_value_get_string(&val));
gchar *selected_accountID = g_value_dup_string(&val);
g_value_unset(&val);
DEBUG("Selected account has accountID %s", selected_accountID);
......@@ -208,7 +208,7 @@ select_account_cb(GtkTreeSelection *selection, GtkTreeModel *model)
const gchar *state_name = account_state_name(selected_account->state);
if (selected_account->protocol_state_description != NULL
&& selected_account->protocol_state_code != 0) {
&& selected_account->protocol_state_code != 0) {
gchar * response = g_strdup_printf(
_("Server returned \"%s\" (%d)"),
......@@ -260,10 +260,10 @@ enable_account_cb(GtkCellRendererToggle *rend UNUSED, gchar* path,
enable, -1);
// Modify account state
const gchar * registration_state = enable ? "true" : "false";
DEBUG("Account is enabled: %s", registration_state);
const gchar * enabled_str = enable ? "true" : "false";
DEBUG("Account is enabled: %s", enabled_str);
account_replace(account, ACCOUNT_ENABLED, registration_state);
account_replace(account, ACCOUNT_ENABLED, enabled_str);
dbus_send_register(account->accountID, enable);
}
......
......@@ -21,6 +21,7 @@
The available keys / parameters are:
<ul>
<li>CONFIG_ACCOUNT_ENABLE: True or False (Default: True)</li>
<li>CONFIG_ACCOUNT_RESOLVE_ONCE</li>
<li>CONFIG_ACCOUNT_TYPE: SIP or IAX2 (Default: SIP)</li>
<li>HOSTNAME: The IP adress or hostname of the registrar</li>
<li>USERNAME: The username (or extension) of the account</li>
......@@ -446,6 +447,11 @@
<signal name="accountsChanged" tp:name-for-bindings="accountsChanged">
</signal>
<signal name="registrationStateChanged" tp:name-for-bindings="registrationStateChanged">
<arg type="s" name="accountID"/>
<arg type="i" name="registration_state"/>
</signal>
<signal name="stunStatusFailure" tp:name-for_bindings="stunStatusFailure">
<arg type="s" name="reason">
</arg>
......
......@@ -421,6 +421,17 @@ record_playback_stopped_cb(DBusGProxy *proxy UNUSED, const gchar *filepath)
update_actions();
}
static void
registration_state_changed_cb(DBusGProxy *proxy UNUSED, const gchar *accountID,
guint state, void *foo UNUSED)
{
DEBUG("DBus: Registration state changed to %s for account %s",
account_state_name(state), accountID);
account_t *acc = account_list_get_by_id(accountID);
if (acc)
acc->state = state;
}
static void
accounts_changed_cb(DBusGProxy *proxy UNUSED, void *foo UNUSED)
{
......@@ -733,6 +744,11 @@ gboolean dbus_connect(GError **error)
dbus_g_proxy_connect_signal(call_proxy, "voiceMailNotify",
G_CALLBACK(voice_mail_cb), NULL, NULL);
dbus_g_proxy_add_signal(config_proxy, "registrationStateChanged", G_TYPE_STRING,
G_TYPE_INT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(config_proxy, "registrationStateChanged",
G_CALLBACK(registration_state_changed_cb), NULL, NULL);
dbus_g_proxy_add_signal(call_proxy, "incomingMessage", G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(call_proxy, "incomingMessage",
......@@ -1091,11 +1107,10 @@ void
dbus_add_account(account_t *a)
{
g_assert(a);
g_assert(a->accountID);
g_assert(a->properties);
DEBUG("Adding %s account", a->accountID);
g_free(a->accountID);
GError *error = NULL;
if (a->accountID)
g_free(a->accountID);
a->accountID = NULL;
org_sflphone_SFLphone_ConfigurationManager_add_account(config_proxy, a->properties, &a->accountID,
&error);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment