145
148
const gchar * account_state_name(account_state_t s)
150
151
case ACCOUNT_STATE_REGISTERED:
151
state = _("Registered");
152
return _("Registered");
153
153
case ACCOUNT_STATE_UNREGISTERED:
154
state = _("Not Registered");
154
return _("Not Registered");
156
155
case ACCOUNT_STATE_TRYING:
157
state = _("Trying...");
156
return _("Trying...");
159
157
case ACCOUNT_STATE_ERROR:
162
159
case ACCOUNT_STATE_ERROR_AUTH:
163
state = _("Authentication Failed");
160
return _("Authentication Failed");
165
161
case ACCOUNT_STATE_ERROR_NETWORK:
166
state = _("Network unreachable");
162
return _("Network unreachable");
168
163
case ACCOUNT_STATE_ERROR_HOST:
169
state = _("Host unreachable");
171
case ACCOUNT_STATE_ERROR_CONF_STUN:
172
state = _("Stun configuration error");
164
return _("Host unreachable");
165
case ACCOUNT_STATE_ERROR_NOT_ACCEPTABLE:
166
return _("Not acceptable");
174
167
case ACCOUNT_STATE_ERROR_EXIST_STUN:
175
state = _("Stun server invalid");
177
case IP2IP_PROFILE_STATUS:
168
return _("Stun server invalid");
169
case ACCOUNT_STATE_IP2IP_READY:
181
state = _("Invalid");
188
176
void account_list_free_elm(gpointer elm, gpointer data UNUSED)
190
178
account_t *a = elm;
191
179
g_free(a->accountID);
195
184
void account_list_free()
197
g_queue_foreach(accountQueue, account_list_free_elm, NULL);
198
g_queue_free(accountQueue);
187
g_queue_foreach(accountQueue, account_list_free_elm, NULL);
188
g_queue_free(accountQueue);
224
216
for (guint i = 0; i < account_list_get_size(); i++)
225
if (account_list_get_nth(i) -> state == (ACCOUNT_STATE_REGISTERED))
217
if (account_list_get_nth(i)->state == (ACCOUNT_STATE_REGISTERED))
231
gchar* account_list_get_current_id(void)
223
const gchar* account_list_get_current_id(void)
233
225
account_t *current = account_list_get_current();
236
228
return current->accountID;
233
void account_list_remove(const gchar *accountID)
235
account_t *target = account_list_get_by_id(accountID);
237
#if GLIB_CHECK_VERSION(2, 30, 0)
238
if (!g_queue_remove(accountQueue, target))
239
ERROR("Could not remove account with ID %s", accountID);
241
g_queue_remove(accountQueue, target);
241
247
gchar * account_list_get_ordered_list(void)
293
295
gboolean current_account_has_new_message(void)
295
297
account_t *current = account_list_get_current();
298
return (current->_messages_number > 0);
298
return current && current->_messages_number > 0;
301
gboolean account_is_IP2IP(const account_t *account)
304
return g_strcmp0(account->accountID, IP2IP_PROFILE) == 0;
307
static gboolean is_type(const account_t *account, const gchar *type)
309
const gchar *account_type = account_lookup(account, ACCOUNT_TYPE);
310
return g_strcmp0(account_type, type) == 0;
313
gboolean account_is_SIP(const account_t *account)
315
return is_type(account, "SIP");
318
gboolean account_is_IAX(const account_t *account)
320
return is_type(account, "IAX");
323
account_t *create_default_account()
325
account_t *account = g_new0(account_t, 1);
326
account->accountID = g_strdup("new"); // FIXME: maybe replace with NULL?
327
account->properties = dbus_get_account_details("");
328
sflphone_fill_codec_list_per_account(account);
329
initialize_credential_information(account);
333
account_t *create_account_with_ID(const gchar *ID)
335
account_t *account = g_new0(account_t, 1);
336
account->accountID = g_strdup(ID);
337
account->properties = dbus_get_account_details(ID);
338
sflphone_fill_codec_list_per_account(account);
339
initialize_credential_information(account);
343
void initialize_credential_information(account_t *account)
345
if (!account->credential_information) {
346
account->credential_information = g_ptr_array_sized_new(1);
347
GHashTable * new_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
348
g_hash_table_insert(new_table, g_strdup(ACCOUNT_REALM), g_strdup("*"));
349
g_hash_table_insert(new_table, g_strdup(ACCOUNT_USERNAME), g_strdup(""));
350
g_hash_table_insert(new_table, g_strdup(ACCOUNT_PASSWORD), g_strdup(""));
351
g_ptr_array_add(account->credential_information, new_table);
355
void account_replace(account_t *account, const gchar *key, const gchar *value)
357
g_assert(account && account->properties);
358
g_hash_table_replace(account->properties, g_strdup(key), g_strdup(value));
361
void account_insert(account_t *account, const gchar *key, const gchar *value)
363
g_assert(account && account->properties);
364
g_hash_table_insert(account->properties, g_strdup(key), g_strdup(value));
367
gpointer account_lookup(const account_t *account, gconstpointer key)
369
g_assert(account && account->properties);
370
return g_hash_table_lookup(account->properties, key);