~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to gnome/src/accountlist.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-05-19 21:46:37 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120519214637-la8rbrford5kj6m3
Tags: 1.1.0-1
* New upstream release 
  - Fixes "FTBFS with libccrtp-dev/2.0.2 from experimental" (Closes: #663282)
* NEW Maintainer: Debian VoIP Team - Thanks Francois for your work.
  - (Closes: #665789: O: sflphone -- SIP and IAX2 compatible VoIP phone)
* Added Build-Depends: libdbus-c++-bin
* Add gcc47-fixes.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 *  as that of the covered work.
30
30
 */
31
31
 
 
32
#include <glib/gi18n.h>
 
33
#include "str_utils.h"
 
34
#include "dbus.h"
32
35
#include "accountlist.h"
 
36
#include "logger.h"
33
37
#include "actions.h"
34
38
#include "unused.h"
35
39
 
42
46
    for (guint i = 0; i < size; i++) {
43
47
        account_t *tmp = account_list_get_nth(i);
44
48
 
45
 
        if (g_strcasecmp(tmp->accountID, account->accountID) == 0)
 
49
        if (utf8_case_equal(tmp->accountID, account->accountID))
46
50
            return i;
47
51
    }
48
52
 
50
54
    return -1;
51
55
}
52
56
 
53
 
 
54
57
/* GCompareFunc to compare a accountID (gchar* and a account_t) */
55
58
static gint is_accountID_struct(gconstpointer a, gconstpointer b)
56
59
{
73
76
 
74
77
void account_list_init()
75
78
{
 
79
    account_list_free();
76
80
    accountQueue = g_queue_new();
77
81
}
78
82
 
96
100
account_t *
97
101
account_list_get_by_id(const gchar * const accountID)
98
102
{
 
103
    g_assert(accountID);
99
104
    GList * c = g_queue_find_custom(accountQueue, accountID, is_accountID_struct);
100
105
 
101
106
    if (c)
123
128
 
124
129
    // if we are here, it means that we have at least one registered account in the list
125
130
    // So we get the first one
126
 
    account_t *current = account_list_get_by_state(ACCOUNT_STATE_REGISTERED);
127
 
 
128
 
    return current;
 
131
    return account_list_get_by_state(ACCOUNT_STATE_REGISTERED);
129
132
}
130
133
 
131
134
void account_list_set_current(account_t *current)
144
147
 
145
148
const gchar * account_state_name(account_state_t s)
146
149
{
147
 
    gchar * state;
148
 
 
149
150
    switch (s) {
150
151
        case ACCOUNT_STATE_REGISTERED:
151
 
            state = _("Registered");
152
 
            break;
 
152
            return _("Registered");
153
153
        case ACCOUNT_STATE_UNREGISTERED:
154
 
            state = _("Not Registered");
155
 
            break;
 
154
            return _("Not Registered");
156
155
        case ACCOUNT_STATE_TRYING:
157
 
            state = _("Trying...");
158
 
            break;
 
156
            return _("Trying...");
159
157
        case ACCOUNT_STATE_ERROR:
160
 
            state = _("Error");
161
 
            break;
 
158
            return _("Error");
162
159
        case ACCOUNT_STATE_ERROR_AUTH:
163
 
            state = _("Authentication Failed");
164
 
            break;
 
160
            return _("Authentication Failed");
165
161
        case ACCOUNT_STATE_ERROR_NETWORK:
166
 
            state = _("Network unreachable");
167
 
            break;
 
162
            return _("Network unreachable");
168
163
        case ACCOUNT_STATE_ERROR_HOST:
169
 
            state = _("Host unreachable");
170
 
            break;
171
 
        case ACCOUNT_STATE_ERROR_CONF_STUN:
172
 
            state = _("Stun configuration error");
173
 
            break;
 
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");
176
 
            break;
177
 
        case IP2IP_PROFILE_STATUS:
178
 
            state = _("Ready");
179
 
            break;
 
168
            return _("Stun server invalid");
 
169
        case ACCOUNT_STATE_IP2IP_READY:
 
170
            return _("Ready");
180
171
        default:
181
 
            state = _("Invalid");
182
 
            break;
 
172
            return _("Invalid");
183
173
    }
184
 
 
185
 
    return state;
186
174
}
187
175
 
188
176
void account_list_free_elm(gpointer elm, gpointer data UNUSED)
189
177
{
190
178
    account_t *a = elm;
191
179
    g_free(a->accountID);
 
180
    a->accountID = NULL;
192
181
    g_free(a);
193
182
}
194
183
 
195
184
void account_list_free()
196
185
{
197
 
    g_queue_foreach(accountQueue, account_list_free_elm, NULL);
198
 
    g_queue_free(accountQueue);
 
186
    if (accountQueue) {
 
187
        g_queue_foreach(accountQueue, account_list_free_elm, NULL);
 
188
        g_queue_free(accountQueue);
 
189
        accountQueue = NULL;
 
190
    }
199
191
}
200
192
 
201
193
void
222
214
    guint res = 0;
223
215
 
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))
226
218
            res++;
227
219
 
228
220
    return res;
229
221
}
230
222
 
231
 
gchar* account_list_get_current_id(void)
 
223
const gchar* account_list_get_current_id(void)
232
224
{
233
225
    account_t *current = account_list_get_current();
234
226
 
235
227
    if (current)
236
228
        return current->accountID;
237
229
    else
238
 
        return "";
 
230
        return NULL;
 
231
}
 
232
 
 
233
void account_list_remove(const gchar *accountID)
 
234
{
 
235
    account_t *target = account_list_get_by_id(accountID);
 
236
    if (target) {
 
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);
 
240
#else
 
241
        g_queue_remove(accountQueue, target);
 
242
#endif
 
243
    }
 
244
 
239
245
}
240
246
 
241
247
gchar * account_list_get_ordered_list(void)
243
249
    gchar *order = strdup("");
244
250
 
245
251
    for (guint i = 0; i < account_list_get_size(); i++) {
246
 
        account_t * account = NULL;
247
 
        account = account_list_get_nth(i);
248
 
 
249
 
        if (account != NULL) {
 
252
        account_t * account = account_list_get_nth(i);
 
253
        if (account) {
250
254
            gchar *new_order = g_strconcat(order, account->accountID, "/", NULL);
251
255
            g_free(order);
252
256
            order = new_order;
263
267
    account_t *current = account_list_get_current();
264
268
 
265
269
    if (current) {
266
 
        gchar * account_mailbox = g_hash_table_lookup(current->properties, ACCOUNT_MAILBOX);
 
270
        gchar * account_mailbox = account_lookup(current, ACCOUNT_MAILBOX);
267
271
 
268
 
        if (account_mailbox && g_strcasecmp(account_mailbox, "") != 0)
 
272
        if (account_mailbox && !utf8_case_equal(account_mailbox, ""))
269
273
            return TRUE;
270
274
    }
271
275
 
275
279
void current_account_set_message_number(guint nb)
276
280
{
277
281
    account_t *current = account_list_get_current();
278
 
 
279
282
    if (current)
280
283
        current->_messages_number = nb;
281
284
}
283
286
guint current_account_get_message_number(void)
284
287
{
285
288
    account_t *current = account_list_get_current();
286
 
 
287
289
    if (current)
288
290
        return current->_messages_number;
289
291
    else
293
295
gboolean current_account_has_new_message(void)
294
296
{
295
297
    account_t *current = account_list_get_current();
296
 
 
297
 
    if (current)
298
 
        return (current->_messages_number > 0);
299
 
 
300
 
    return FALSE;
 
298
    return current && current->_messages_number > 0;
 
299
}
 
300
 
 
301
gboolean account_is_IP2IP(const account_t *account)
 
302
{
 
303
    g_assert(account);
 
304
    return g_strcmp0(account->accountID, IP2IP_PROFILE) == 0;
 
305
}
 
306
 
 
307
static gboolean is_type(const account_t *account, const gchar *type)
 
308
{
 
309
    const gchar *account_type = account_lookup(account, ACCOUNT_TYPE);
 
310
    return g_strcmp0(account_type, type) == 0;
 
311
}
 
312
 
 
313
gboolean account_is_SIP(const account_t *account)
 
314
{
 
315
    return is_type(account, "SIP");
 
316
}
 
317
 
 
318
gboolean account_is_IAX(const account_t *account)
 
319
{
 
320
    return is_type(account, "IAX");
 
321
}
 
322
 
 
323
account_t *create_default_account()
 
324
{
 
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);
 
330
    return account;
 
331
}
 
332
 
 
333
account_t *create_account_with_ID(const gchar *ID)
 
334
{
 
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);
 
340
    return account;
 
341
}
 
342
 
 
343
void initialize_credential_information(account_t *account)
 
344
{
 
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);
 
352
    }
 
353
}
 
354
 
 
355
void account_replace(account_t *account, const gchar *key, const gchar *value)
 
356
{
 
357
    g_assert(account && account->properties);
 
358
    g_hash_table_replace(account->properties, g_strdup(key), g_strdup(value));
 
359
}
 
360
 
 
361
void account_insert(account_t *account, const gchar *key, const gchar *value)
 
362
{
 
363
    g_assert(account && account->properties);
 
364
    g_hash_table_insert(account->properties, g_strdup(key), g_strdup(value));
 
365
}
 
366
 
 
367
gpointer account_lookup(const account_t *account, gconstpointer key)
 
368
{
 
369
    g_assert(account && account->properties);
 
370
    return g_hash_table_lookup(account->properties, key);
301
371
}