~ubuntu-branches/ubuntu/precise/evolution-data-server/precise

« back to all changes in this revision

Viewing changes to tests/libedataserverui/test-client-examine-auth.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre, Ken VanDine, Mathieu Trudel-Lapierre
  • Date: 2011-06-23 17:40:41 UTC
  • mfrom: (1.1.88 upstream)
  • Revision ID: james.westby@ubuntu.com-20110623174041-4wd9jvs07wfinyet
Tags: 3.1.2-0ubuntu1
* New upstream version
  - bgo 589495 - Search folder by Size (KB) counts bytes, not KB (LP: #385859)
  - bgo 649757 - Filtering on a source account always succeeded (LP: #781391)
  - bgo 418954 - Add a separate entry combo for port numbers (LP: #160304)

[ Ken VanDine ]
* debian/libebook1.2-dev.install
  - Include EBook-1.2.gir
* debian/control
  - Added gir1.2-ebook-1.2 binary

[ Mathieu Trudel-Lapierre ]
* debian/control: drop libegroupwise1.2-13, libegroupwise-dev, they are now
  an independent module.
* debian/libegroupwise1.2-13.install,
  debian/libegroupwise1.2-dev.install,
  debian/lintian/libegroupwise1.2-13: dropped, see above.
* debian/control, debian/libe*.install, debian/lintian/libe*: rename and
  update files where needed to follow upstream soname changes.
* debian/control: bump evolution-data-server's Depends to libcamel-1.2-26.
* debian/rules: update to use makeshlibs with the new libcamel soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
 
 
3
#include <libedataserver/e-source-group.h>
 
4
#include <libedataserverui/e-client-utils.h>
 
5
#include <libedataserverui/e-passwords.h>
 
6
 
 
7
static void stop_main_loop (gint stop_result);
 
8
static void report_error (const gchar *operation, GError **error);
 
9
static gpointer foreach_configured_source_async_start (ESource **source);
 
10
static gboolean foreach_configured_source_async_next (gpointer *foreach_async_data, ESource **source);
 
11
static gboolean foreach_async (void);
 
12
 
 
13
static gint running_async = 0;
 
14
static EClientSourceType source_type = E_CLIENT_SOURCE_TYPE_CONTACTS;
 
15
 
 
16
static GSList *
 
17
get_known_prop_names (void)
 
18
{
 
19
        GSList *prop_names = NULL;
 
20
 
 
21
        prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_OPENED);
 
22
        prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_OPENING);
 
23
        prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_ONLINE);
 
24
        prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_READONLY);
 
25
        prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_CACHE_DIR);
 
26
        prop_names = g_slist_append (prop_names, (gpointer) CLIENT_BACKEND_PROPERTY_CAPABILITIES);
 
27
 
 
28
        return prop_names;
 
29
}
 
30
 
 
31
typedef struct _ExtraValues {
 
32
        gpointer async_data;
 
33
 
 
34
        GSList *todo_prop_names;
 
35
        GHashTable *retrieved_props;
 
36
} ExtraValues;
 
37
 
 
38
static void
 
39
extra_values_free (ExtraValues *evals)
 
40
{
 
41
        if (!evals)
 
42
                return;
 
43
 
 
44
        g_slist_free (evals->todo_prop_names);
 
45
        g_hash_table_destroy (evals->retrieved_props);
 
46
        g_free (evals);
 
47
}
 
48
 
 
49
static void
 
50
print_each_property (gpointer prop_name, gpointer prop_value, gpointer user_data)
 
51
{
 
52
        g_return_if_fail (prop_name != NULL);
 
53
 
 
54
        if (prop_value == NULL) {
 
55
                g_print ("\t   %s: NULL\n", (const gchar *) prop_name);
 
56
                return;
 
57
        }
 
58
 
 
59
        g_print ("\t   %s: ", (const gchar *) prop_name);
 
60
 
 
61
        if (g_str_equal (prop_name, CLIENT_BACKEND_PROPERTY_CAPABILITIES)) {
 
62
                GSList *values = e_client_util_parse_comma_strings (prop_value), *v;
 
63
 
 
64
                for (v = values; v; v = v->next) {
 
65
                        if (v != values)
 
66
                                g_print (", ");
 
67
 
 
68
                        g_print ("'%s'", (const gchar *) v->data);
 
69
                }
 
70
 
 
71
                e_client_util_free_string_slist (values);
 
72
        } else {
 
73
                g_print ("'%s'", (const gchar *) prop_value);
 
74
        }
 
75
 
 
76
        g_print ("\n");
 
77
}
 
78
 
 
79
static void
 
80
print_values (const ExtraValues *evals, EClient *client)
 
81
{
 
82
        const GSList *values;
 
83
 
 
84
        g_return_if_fail (evals != NULL);
 
85
 
 
86
        g_print ("\treadonly:%s\n", e_client_is_readonly (client) ? "yes" : "no");
 
87
        g_print ("\tonline:%s\n", e_client_is_online (client) ? "yes" : "no");
 
88
        g_print ("\topened:%s\n", e_client_is_opened (client) ? "yes" : "no");
 
89
        g_print ("\tcapabilities: ");
 
90
        values = e_client_get_capabilities (client);
 
91
        if (!values) {
 
92
                g_print ("NULL");
 
93
        } else {
 
94
                while (values) {
 
95
                        const gchar *cap = values->data;
 
96
 
 
97
                        g_print ("'%s'", cap);
 
98
                        if (!e_client_check_capability (client, cap))
 
99
                                g_print (" (not found in EClient)");
 
100
 
 
101
                        values = values->next;
 
102
 
 
103
                        if (values)
 
104
                                g_print (", ");
 
105
                }
 
106
        }
 
107
        g_print ("\n");
 
108
 
 
109
        g_print ("\tbackend properties:\n");
 
110
        g_hash_table_foreach (evals->retrieved_props, print_each_property, NULL);
 
111
}
 
112
 
 
113
static void
 
114
identify_source (ESource *source)
 
115
{
 
116
        const gchar *name, *uri;
 
117
        gchar *abs_uri = NULL;
 
118
 
 
119
        g_return_if_fail (source != NULL);
 
120
 
 
121
        name = e_source_peek_name (source);
 
122
        if (!name)
 
123
                name = "Unknown name";
 
124
 
 
125
        uri = e_source_peek_absolute_uri (source);
 
126
        if (!uri) {
 
127
                abs_uri = e_source_build_absolute_uri (source);
 
128
                uri = abs_uri;
 
129
        }
 
130
        if (!uri)
 
131
                uri = e_source_peek_relative_uri (source);
 
132
        if (!uri)
 
133
                uri = "Unknown uri";
 
134
 
 
135
        g_print ("\n   Checking source '%s' (%s)\n", name, uri);
 
136
 
 
137
        g_free (abs_uri);
 
138
}
 
139
 
 
140
static void client_opened_async (GObject *source_object, GAsyncResult *result, gpointer async_data);
 
141
 
 
142
static void
 
143
continue_next_source (gpointer async_data)
 
144
{
 
145
        ESource *source = NULL;
 
146
 
 
147
        g_return_if_fail (async_data != NULL);
 
148
 
 
149
        while (async_data && foreach_configured_source_async_next (&async_data, &source)) {
 
150
                identify_source (source);
 
151
                e_client_utils_open_new (source, source_type, TRUE,
 
152
                        e_client_utils_authenticate_handler, NULL,
 
153
                        NULL, client_opened_async, async_data);
 
154
                break;
 
155
        }
 
156
 
 
157
        if (!async_data) {
 
158
                running_async--;
 
159
                if (!running_async) {
 
160
                        while (source_type++, source_type < E_CLIENT_SOURCE_TYPE_LAST) {
 
161
                                if (foreach_async ())
 
162
                                        return;
 
163
                        }
 
164
 
 
165
                        stop_main_loop (0);
 
166
                }
 
167
        }
 
168
}
 
169
 
 
170
static void
 
171
client_got_backend_property_async (GObject *source_object, GAsyncResult *result, gpointer user_data)
 
172
{
 
173
        ExtraValues *evals = user_data;
 
174
        gchar *prop_value = NULL;
 
175
        GError *error = NULL;
 
176
        EClient *client;
 
177
 
 
178
        g_return_if_fail (source_object != NULL);
 
179
        g_return_if_fail (E_IS_CLIENT (source_object));
 
180
        g_return_if_fail (evals != NULL);
 
181
 
 
182
        client = E_CLIENT (source_object);
 
183
 
 
184
        if (!e_client_get_backend_property_finish (client, result, &prop_value, &error)) {
 
185
                report_error ("get backend property finish", &error);
 
186
        }
 
187
 
 
188
        g_hash_table_insert (evals->retrieved_props, evals->todo_prop_names->data, prop_value);
 
189
        evals->todo_prop_names = g_slist_remove (evals->todo_prop_names, evals->todo_prop_names->data);
 
190
 
 
191
        if (!evals->todo_prop_names) {
 
192
                /* to cache them, as it can be fetched with idle as well */
 
193
                e_client_get_capabilities (client);
 
194
 
 
195
                print_values (evals, client);
 
196
 
 
197
                g_object_unref (source_object);
 
198
 
 
199
                continue_next_source (evals->async_data);
 
200
                extra_values_free (evals);
 
201
        } else {
 
202
                e_client_get_backend_property (client, evals->todo_prop_names->data, NULL, client_got_backend_property_async, evals);
 
203
        }
 
204
}
 
205
 
 
206
static void
 
207
client_set_backend_property_async (GObject *source_object, GAsyncResult *result, gpointer user_data)
 
208
{
 
209
        ExtraValues *evals = user_data;
 
210
        GError *error = NULL;
 
211
        EClient *client;
 
212
 
 
213
        g_return_if_fail (source_object != NULL);
 
214
        g_return_if_fail (E_IS_CLIENT (source_object));
 
215
        g_return_if_fail (evals != NULL);
 
216
 
 
217
        client = E_CLIENT (source_object);
 
218
 
 
219
        if (!e_client_set_backend_property_finish (client, result, &error)) {
 
220
                /* it may fail on the set_backend_property */
 
221
                g_clear_error (&error);
 
222
        } else {
 
223
                g_printerr ("   Might fail on set_backend_property, but reported success\n");
 
224
        }
 
225
 
 
226
        e_client_get_backend_property (client, evals->todo_prop_names->data, NULL, client_got_backend_property_async, evals);
 
227
}
 
228
 
 
229
static void
 
230
client_opened_async (GObject *source_object, GAsyncResult *result, gpointer async_data)
 
231
{
 
232
        ExtraValues *evals;
 
233
        GError *error = NULL;
 
234
        EClient *client = NULL;
 
235
 
 
236
        g_return_if_fail (source_object == NULL);
 
237
        g_return_if_fail (async_data != NULL);
 
238
 
 
239
        if (!e_client_utils_open_new_finish (result, &client, &error)) {
 
240
                report_error ("client utils open new finish", &error);
 
241
                continue_next_source (async_data);
 
242
                return;
 
243
        }
 
244
 
 
245
        evals = g_new0 (ExtraValues, 1);
 
246
        evals->async_data = async_data;
 
247
        evals->todo_prop_names = get_known_prop_names ();
 
248
        evals->retrieved_props = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
 
249
 
 
250
        e_client_set_backend_property (client, "*unknown*property*", "*value*", NULL, client_set_backend_property_async, evals);
 
251
}
 
252
 
 
253
static gboolean
 
254
foreach_async (void)
 
255
{
 
256
        gpointer async_data;
 
257
        ESource *source = NULL;
 
258
 
 
259
        async_data = foreach_configured_source_async_start (&source);
 
260
        if (!async_data) {
 
261
                stop_main_loop (1);
 
262
                return FALSE;
 
263
        }
 
264
 
 
265
        running_async++;
 
266
 
 
267
        identify_source (source);
 
268
        e_client_utils_open_new (source, source_type, TRUE,
 
269
                e_client_utils_authenticate_handler, NULL,
 
270
                NULL, client_opened_async, async_data);
 
271
 
 
272
        return TRUE;
 
273
}
 
274
 
 
275
static gboolean
 
276
in_main_thread_idle_cb (gpointer unused)
 
277
{
 
278
        if (!foreach_async ())
 
279
                return FALSE;
 
280
 
 
281
        return FALSE;
 
282
}
 
283
 
 
284
static GMainLoop *loop = NULL;
 
285
static gint main_stop_result = 0;
 
286
 
 
287
static void
 
288
stop_main_loop (gint stop_result)
 
289
{
 
290
        g_return_if_fail (loop != NULL);
 
291
 
 
292
        main_stop_result = stop_result;
 
293
        g_main_loop_quit (loop);
 
294
}
 
295
 
 
296
static gint
 
297
get_main_loop_stop_result (void)
 
298
{
 
299
        return main_stop_result;
 
300
}
 
301
 
 
302
struct ForeachConfiguredData
 
303
{
 
304
        ESourceList *source_list;
 
305
        GSList *current_group;
 
306
        GSList *current_source;
 
307
};
 
308
 
 
309
static gpointer
 
310
foreach_configured_source_async_start (ESource **source)
 
311
{
 
312
        struct ForeachConfiguredData *async_data;
 
313
        ESourceList *source_list = NULL;
 
314
        GError *error = NULL;
 
315
 
 
316
        g_return_val_if_fail (source != NULL, NULL);
 
317
 
 
318
        if (!e_client_utils_get_sources (&source_list, source_type, &error)) {
 
319
                report_error ("get sources", &error);
 
320
                return NULL;
 
321
        }
 
322
 
 
323
        g_return_val_if_fail (source_list != NULL, NULL);
 
324
 
 
325
        async_data = g_new0 (struct ForeachConfiguredData, 1);
 
326
        async_data->source_list = source_list;
 
327
        async_data->current_group = e_source_list_peek_groups (source_list);
 
328
        if (!async_data->current_group) {
 
329
                gpointer ad = async_data;
 
330
 
 
331
                foreach_configured_source_async_next (&ad, source);
 
332
                return ad;
 
333
        }
 
334
 
 
335
        async_data->current_source = e_source_group_peek_sources (async_data->current_group->data);
 
336
        if (!async_data->current_source) {
 
337
                gpointer ad = async_data;
 
338
 
 
339
                if (foreach_configured_source_async_next (&ad, source))
 
340
                        return ad;
 
341
 
 
342
                return NULL;
 
343
        }
 
344
 
 
345
        *source = async_data->current_source->data;
 
346
 
 
347
        return async_data;
 
348
}
 
349
 
 
350
static gboolean
 
351
foreach_configured_source_async_next (gpointer *foreach_async_data, ESource **source)
 
352
{
 
353
        struct ForeachConfiguredData *async_data;
 
354
 
 
355
        g_return_val_if_fail (foreach_async_data != NULL, FALSE);
 
356
        g_return_val_if_fail (source != NULL, FALSE);
 
357
 
 
358
        async_data = *foreach_async_data;
 
359
        g_return_val_if_fail (async_data != NULL, FALSE);
 
360
        g_return_val_if_fail (async_data->source_list != NULL, FALSE);
 
361
        g_return_val_if_fail (async_data->current_group != NULL, FALSE);
 
362
 
 
363
        if (async_data->current_source)
 
364
                async_data->current_source = async_data->current_source->next;
 
365
        if (async_data->current_source) {
 
366
                *source = async_data->current_source->data;
 
367
                return TRUE;
 
368
        }
 
369
 
 
370
        do {
 
371
                async_data->current_group = async_data->current_group->next;
 
372
                if (async_data->current_group)
 
373
                        async_data->current_source = e_source_group_peek_sources (async_data->current_group->data);
 
374
        } while (async_data->current_group && !async_data->current_source);
 
375
 
 
376
        if (async_data->current_source) {
 
377
                *source = async_data->current_source->data;
 
378
                return TRUE;
 
379
        }
 
380
 
 
381
        g_object_unref (async_data->source_list);
 
382
        g_free (async_data);
 
383
 
 
384
        *foreach_async_data = NULL;
 
385
 
 
386
        return FALSE;
 
387
}
 
388
 
 
389
static void
 
390
report_error (const gchar *operation, GError **error)
 
391
{
 
392
        g_return_if_fail (operation != NULL);
 
393
 
 
394
        g_printerr ("Failed to %s: %s\n", operation, (error && *error) ? (*error)->message : "Unknown error");
 
395
 
 
396
        g_clear_error (error);
 
397
}
 
398
 
 
399
gint
 
400
main (gint argc, gchar **argv)
 
401
{
 
402
        g_type_init ();
 
403
        g_thread_init (NULL);
 
404
        gtk_init (&argc, &argv);
 
405
 
 
406
        e_passwords_init ();
 
407
 
 
408
        g_idle_add (in_main_thread_idle_cb, NULL);
 
409
 
 
410
        loop = g_main_loop_new (NULL, FALSE);
 
411
        g_main_loop_run (loop);
 
412
        g_main_loop_unref (loop);
 
413
 
 
414
        return get_main_loop_stop_result ();
 
415
}