| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: (C) 1999-2011 Novell, Inc. (www.novell.com) |
| 3 |
* SPDX-FileContributor: Chenthill Palanisamy <[email protected]> |
| 4 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#undef EDS_DISABLE_DEPRECATED |
| 8 |
|
| 9 |
#include <math.h> |
| 10 |
#include <stdlib.h> |
| 11 |
#include <string.h> |
| 12 |
#include <glib/gstdio.h> |
| 13 |
|
| 14 |
#include <libebook/libebook.h> |
| 15 |
#include <libedata-book/libedata-book.h> |
| 16 |
|
| 17 |
#include "ews-oab-decoder.h" |
| 18 |
#include "ews-oab-props.h" |
| 19 |
|
| 20 |
struct _db_data { |
| 21 |
GSList *contact_collector; |
| 22 |
GSList *sha1_collector; |
| 23 |
guint collected_length; |
| 24 |
EBookSqlite *summary; |
| 25 |
const gchar *folderid; |
| 26 |
}; |
| 27 |
|
| 28 |
static void |
| 29 |
ews_test_store_contact (EContact *contact, |
| 30 |
goffset offset, |
| 31 |
const gchar *sha1, |
| 32 |
guint percent, |
| 33 |
gpointer user_data, |
| 34 |
GCancellable *cancellable, |
| 35 |
GError **error) |
| 36 |
{ |
| 37 |
struct _db_data *data = (struct _db_data *) user_data; |
| 38 |
|
| 39 |
data->contact_collector = g_slist_prepend (data->contact_collector, g_object_ref (contact)); |
| 40 |
data->sha1_collector = g_slist_prepend (data->sha1_collector, g_strdup (sha1)); |
| 41 |
data->collected_length += 1; |
| 42 |
|
| 43 |
if (data->collected_length == 1000 || percent >= 100) { |
| 44 |
data->contact_collector = g_slist_reverse (data->contact_collector); |
| 45 |
e_book_sqlite_add_contacts (data->summary, data->contact_collector, |
| 46 |
data->sha1_collector, |
| 47 |
FALSE, NULL, error); |
| 48 |
g_print ("percent complete %d \n", percent); |
| 49 |
|
| 50 |
g_slist_free_full (data->contact_collector, g_object_unref); |
| 51 |
g_slist_free_full (data->sha1_collector, g_free); |
| 52 |
data->contact_collector = NULL; |
| 53 |
data->sha1_collector = NULL; |
| 54 |
data->collected_length = 0; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
gint |
| 59 |
main (gint argc, |
| 60 |
gchar *argv[]) |
| 61 |
{ |
| 62 |
EBookSqlite *summary; |
| 63 |
EwsOabDecoder *eod; |
| 64 |
GError *err = NULL; |
| 65 |
GTimer *timer; |
| 66 |
struct _db_data data; |
| 67 |
|
| 68 |
g_type_init (); |
| 69 |
|
| 70 |
if (argc != 3) { |
| 71 |
g_print ("Pass the oab filename and cache dir as argument \n"); |
| 72 |
return -1; |
| 73 |
} |
| 74 |
|
| 75 |
summary = e_book_sqlite_new (argv[2], NULL, NULL, &err); |
| 76 |
if (err) { |
| 77 |
printf("err: %s\n", err->message); |
| 78 |
exit(1); |
| 79 |
} |
| 80 |
eod = ews_oab_decoder_new (argv[1], argv[2], &err); |
| 81 |
if (err) { |
| 82 |
printf("err: %s\n", err->message); |
| 83 |
exit(1); |
| 84 |
} |
| 85 |
|
| 86 |
data.sha1_collector = data.contact_collector = NULL; |
| 87 |
data.collected_length = 0; |
| 88 |
data.summary = summary; |
| 89 |
data.folderid = "de"; |
| 90 |
|
| 91 |
timer = g_timer_new (); |
| 92 |
g_timer_start (timer); |
| 93 |
if (!ews_oab_decoder_decode (eod, NULL, ews_test_store_contact, &data, NULL, &err)) { |
| 94 |
g_print ("Unable to decode %s \n", err->message); |
| 95 |
} |
| 96 |
g_timer_stop (timer); |
| 97 |
g_print ("Time elapsed %lf \n", g_timer_elapsed (timer, NULL)); |
| 98 |
|
| 99 |
if (err) |
| 100 |
g_clear_error (&err); |
| 101 |
|
| 102 |
g_object_unref (eod); |
| 103 |
g_object_unref (summary); |
| 104 |
|
| 105 |
return 0; |
| 106 |
} |
| 107 |
|