2 * Copyright (C) 2005-2009 Patrick Ohly <patrick.ohly@gmx.de>
3 * Copyright (C) 2009 Intel Corporation
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) version 3.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include <glib-object.h>
32 #include <syncevo/Cmdline.h>
33 #include "EvolutionSyncSource.h"
34 #include <syncevo/SyncContext.h>
35 #include <syncevo/LogRedirect.h>
36 #include "CmdlineSyncClient.h"
40 #include <syncevo/declarations.h>
43 #if defined(ENABLE_MAEMO) && defined (ENABLE_EBOOK)
45 // really override the symbol, even if redefined by EDSAbiWrapper
46 #undef e_contact_new_from_vcard
47 extern "C" EContact *e_contact_new_from_vcard(const char *vcard)
49 static typeof(e_contact_new_from_vcard) *impl;
52 impl = (typeof(impl))dlsym(RTLD_NEXT, "e_contact_new_from_vcard");
55 // Old versions of EDS-DBus parse_changes_array() call
56 // e_contact_new_from_vcard() with a pointer which starts
57 // with a line break; Evolution is not happy with that and
58 // refuses to parse it. This code forwards until it finds
59 // the first non-whitespace, presumably the BEGIN:VCARD.
60 while (*vcard && isspace(*vcard)) {
64 return impl ? impl(vcard) : NULL;
69 * This is a class derived from Cmdline. The purpose
70 * is to implement the factory method 'createSyncClient' to create
71 * new implemented 'CmdlineSyncClient' objects.
73 class KeyringSyncCmdline : public Cmdline {
75 KeyringSyncCmdline(int argc, const char * const * argv, ostream &out, ostream &err):
76 Cmdline(argc, argv, out, err)
79 * create a user implemented sync client.
81 SyncContext* createSyncClient() {
82 return new CmdlineSyncClient(m_server, true, m_keyring);
87 int main( int argc, char **argv )
90 // EDS-DBus uses potentially long-running calls which may fail due
91 // to the default 25s timeout. Some of these can be replaced by
92 // their async version, but e_book_async_get_changes() still
95 // The workaround for this is to link the binary against a libdbus
96 // which has the dbus-timeout.patch and thus let's users and
97 // the application increase the default timeout.
98 setenv("DBUS_DEFAULT_TIMEOUT", "600000", 0);
101 // Intercept stderr and route it through our logging.
102 // stdout is printed normally. Deconstructing it when
103 // leaving main() does one final processing of pending
105 LogRedirect redirect(false);
107 #if defined(HAVE_GLIB)
108 // this is required when using glib directly or indirectly
113 setvbuf(stderr, NULL, _IONBF, 0);
114 setvbuf(stdout, NULL, _IONBF, 0);
116 // Expand PATH to cover the directory we were started from?
117 // This might be needed to find normalize_vcard.
118 char *exe = strdup(argv[0]);
119 if (strchr(exe, '/') ) {
120 char *dir = dirname(exe);
122 char *oldpath = getenv("PATH");
128 setenv("PATH", path.c_str(), 1);
136 * don't log errors to cerr: LogRedirect cannot distinguish
137 * between our valid error messages and noise from other
138 * libs, therefore it would get suppressed (logged at
139 * level DEVELOPER, while output is at most INFO)
141 KeyringSyncCmdline cmdline(argc, argv, cout, cout);
142 if (cmdline.parse() &&
148 } catch ( const std::exception &ex ) {
149 SE_LOG_ERROR(NULL, NULL, "%s", ex.what());
151 SE_LOG_ERROR(NULL, NULL, "unknown error");