2 * Copyright (C) 2005-2006 Patrick Ohly
3 * Copyright (C) 2007 Funambol
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <posix/base/posixlog.h>
25 #include <spds/spdsutils.h>
33 #include <glib-object.h>
36 #include "SyncEvolutionCmdline.h"
37 #include "EvolutionSyncSource.h"
38 #include "EvolutionSyncClient.h"
40 #if defined(ENABLE_MAEMO) && defined (ENABLE_EBOOK)
44 extern "C" EContact *e_contact_new_from_vcard(const char *vcard)
46 static typeof(e_contact_new_from_vcard) *impl;
49 impl = (typeof(impl))dlsym(RTLD_NEXT, "e_contact_new_from_vcard");
52 // Old versions of EDS-DBus parse_changes_array() call
53 // e_contact_new_from_vcard() with a pointer which starts
54 // with a line break; Evolution is not happy with that and
55 // refuses to parse it. This code forwards until it finds
56 // the first non-whitespace, presumably the BEGIN:VCARD.
57 while (*vcard && isspace(*vcard)) {
61 return impl ? impl(vcard) : NULL;
65 #ifdef LOG_HAVE_SET_LOGGER
66 class CmdLineLogger : public POSIXLog {
68 virtual void printLine(bool firstLine,
71 const char *shortTime,
74 const char *levelPrefix,
76 POSIXLog::printLine(firstLine,
84 if (level <= LOG_LEVEL_INFO &&
86 /* POSIXLog is printing to file, therefore print important lines to stdout */
87 fprintf(stdout, "%s [%s] %s\n",
96 int main( int argc, char **argv )
99 // EDS-DBus uses potentially long-running calls which may fail due
100 // to the default 25s timeout. Some of these can be replaced by
101 // their async version, but e_book_async_get_changes() still
104 // The workaround for this is to link the binary against a libdbus
105 // which has the dbus-timeout.patch and thus let's users and
106 // the application increase the default timeout.
107 setenv("DBUS_DEFAULT_TIMEOUT", "600000", 0);
110 #if defined(HAVE_GLIB) && defined(HAVE_EDS)
111 // this is required on Maemo and does not harm either on a normal
112 // desktop system with Evolution
116 #ifdef LOG_HAVE_SET_LOGGER
117 static CmdLineLogger logger;
118 Log::setLogger(&logger);
124 setLogFile(NULL, "-");
126 LOG.setLevel(LOG_LEVEL_INFO);
128 setvbuf(stderr, NULL, _IONBF, 0);
129 setvbuf(stdout, NULL, _IONBF, 0);
131 // Expand PATH to cover the directory we were started from?
132 // This might be needed to find normalize_vcard.
133 char *exe = strdup(argv[0]);
134 if (strchr(exe, '/') ) {
135 char *dir = dirname(exe);
137 char *oldpath = getenv("PATH");
143 setenv("PATH", path.c_str(), 1);
148 SyncEvolutionCmdline cmdline(argc, argv, cout, cerr);
149 if (cmdline.parse() &&
155 } catch ( const std::exception &ex ) {
156 LOG.error( "%s", ex.what() );
158 LOG.error( "unknown error" );