Commit graph

1786 commits

Author SHA1 Message Date
Jussi Kukkonen
8b93714261 implement new dbus api in the C wrapper
NOTE: GTK Client is not buildable at the moment...

The wrapper does not include the Connection object as it's not needed
in the client.
2009-11-13 11:07:36 +02:00
Patrick Ohly
fee9c3917b syncevo-dbus-server: removed special case for unauthenticated Connections
The extra "mustAuthenticate" parameter to the Session::sync() method
is replaced with temporarily setting username/password to empty
via the Session::m_syncFilter.

To catch undesired prototype changes of D-Bus API calls (as it
happened when adding that parameter), all these methods now come with
a comment that links them to the corresponding D-Bus API call.

test-dbus.py tests cover the different credential checks:
- TestConnection.testStartSync: invalid MD5 creds, no authorization
  necessary => client accepted
- TestConnection.testCredentialsWrong: invalid MD5 creds, authorization
  necessary => client rejected
- TestConnection.testCredentialsRight: correct basic creds, authorization
  necessary => client accepted
2009-11-11 10:55:15 +01:00
Patrick Ohly
3ac369433c SyncML server: accept basic authentication
The server was always asking clients to authenticate with
the more secure MD5+Nonce method. For clients which don't
support that, there was no way to tell the server to accept
them.

Changed the configuration so that basic authentication is
accepted. The server will still send a Nonce and ask for MD5 for
failed logins, so clients can (and should) use MD5+Nonce.

The motivation for this change was not a specific client, but
testing (will be committed later): sending valid credentials
in a preformatted message is easier with basic authentication,
exactly because it is susceptible to replay attacks.
2009-11-11 10:50:26 +01:00
Patrick Ohly
ba7c74846b SyncML server: explicitly state that any kind of log in is valid
Lukas pointed towards <logininitscript>return TRUE</logininitscript>
as a better way of accepting all kinds of sessions, even those with
invalid credentials. For good measure, requestedauth/requiredauth
are still set to none, even though that shouldn't matter now.
2009-11-10 18:40:44 +01:00
Patrick Ohly
81554de748 syncevo-dbus-server: Server.GetConfig() should not create configs
The Server.GetConfig() is stricly read-only. When looking at the
error message for NoSuchConfig I noticed that it creates the config
from a template with the name if the config doesn't exist yet. This
was discussed before and should have been removed, but this instance
must have slipped in.

Removed and adapted test for error message accordingly.
2009-11-10 14:33:44 +01:00
Patrick Ohly
7e757195ba D-Bus testing: check for some error reporting situations
Reading a non-existant configuration should result in
org.syncevolution.NoSuchConfig (MB#6548).

Running a sync without a valid configuration should
result in a bad status code.

Both tests passes.
2009-11-10 14:28:34 +01:00
Patrick Ohly
2a8cd7396f syncevo-dbus-server: kill old session(s) when the same client connects again (MB#7710)
The server now checks whether it has other sessions active or in the
queue with the same device ID and kills the older sessions when adding
a new one. Because it does this on each Process(), it is unlikely
(impossible?!) to to have more than one older session, but because the
session might be running or still inactive in the queue, both are
checked.

As part of testing with test-dbus.py it was observed that a connection
that was to be aborted was also closed normally first. That was because
the sync engine did not set an error status in this case. Better check
for abort requests explicitly before calling agent->shutdown(). However,
this should be fixed as part of the server progress handling (MB#7709).
2009-11-10 14:06:22 +01:00
Patrick Ohly
a20aa47c29 syncevo-dbus-server + D-Bus API: no Reply after Abort signal
It was implied, but not explicitly specified and not implemented like
this: with this patch, when a connection is aborted, the "Abort"
signal is sent and no further "Reply", not even the one which is
normally used to close the connection.
2009-11-10 14:06:22 +01:00
Patrick Ohly
10e065d463 test-dbus.py: also kill dbus-monitor at start of run
Just in case that test-dbus.py itself was killed, make sure
that we don't have any redundant dbus-monitor still running.
2009-11-10 14:06:22 +01:00
Zhu, Yongsheng
912ddf031d syncevo-dbus-server: add specific exceptions (MB#6548)
Define a DBusCxxException class in gdbus cxx bridge.
It only has 2 virtual functions: getName, getMessage,
which provide the information necessary to generate
a D-Bus error.

Then define a class DBusSyncException deriving from
DBusCxxException and SyncEvo::Exception.
Also 3 classes NoSuchConfig, NoSuchSource,
InvalidCall are based on DBusSyncException.
Turn some errors into these 3 specific errors.

Define a macro to let user have an opportunity to write
its own exception handling function. The SyncEvoHandleException()
logs the error via Exception::handle() and then overrides
the conversion of all exceptions so that they result in
an "org.syncevolution.Exception", unless specified otherwise
when throwing a DBusCXXException or dbus_error.
2009-11-10 13:39:14 +01:00
Patrick Ohly
813bb7d81a syncevo-dbus-server + syncevolution: fixed signal handling and D-Bus suspend/abort/shutdown (MB#7555)
This patch fixes signal handling and shutdown of syncevo-dbus-server
when signals were received. This problems were found in combination
with automated tests via test-dbus.py.

Signals handled by the signal handlers in the core had no effect on
syncevo-dbus-server, which called its own event loop once the
suspended or aborted sync returned. Signals received while outside
of a sync and outside of an event loop also had no effect.

Now signals are always caught by the niam() function in
syncevo-dbus-server. It uses the new SyncContext::handleSignal() API
to tell the core engine about it and in addition, remembers that
syncevo-dbus-server is meant to shut down (suspendRequested). This is
then checked by the syncevo-dbus-server event loop (DBusServer::run())
before blocking again.

The implementation of Session.Abort() and Session.Suspend() didn't
work. isSuspend() and isAbort() mixed up the state. They also did not
wake up DBusTransportAgent, so the syncevo-dbus-server might get stuck
although an abort was already requested. Partially fixed by adding
g_main_loop_quit(). It's not entirely sure whether g_main_loop_quit()
is reentrant (see below). There is other code which uses it in signal
handlers, but that doesn't mean that this is correct. The right long
term solution would be:
- avoid entering and leaving the event loop
- feed signals into the event loop as normal events

SoupTransportAgent solves this by polling for a signal once per second.
This also should be improved.

Because such code was used in several places for a connection, that common
code was moved into Connection::wakeupSession().

Things which went in unnoticed when the original signal handling was merged:
- SyncContext::getSuspendFlags() should not allow the caller to modify
  the SyncContext state. Made the returned SuspendFlags const.
- A signal handler may only call re-entrant functions (Stevens, "Advanced
  Programming in a Unix Environment", 10.6).

All printing therefore has to be done outside of the signal handlers.
Now the signal handlers just set a message and the regular code
checking for abort/suspend prints it. There's a slight race condition
(a message might get overwritten before it is printed), but printing
just the last message might actually make more sense. There might be
a slight delay between receiving the signal and printing now.
2009-11-09 20:52:28 +01:00
Zhu, Yongsheng
215a146ed9 syncevo-dbus-server: handle CTRL-C/SIGINT/SIGTERM(bug #7555)
Follow up the previous behavior of syncevolution core
about CTRL-C/SIGINT handling.
Also add SIGTERM handler to abort sync immediately.
currently dbus server checks abort/suspend requests
not only from client but also from 'CTRL-C'/SIGINT
signals.
2009-11-09 10:10:09 +01:00
Patrick Ohly
0a22c3825a Merge branch 'syncevolution-0-9-x' 2009-11-09 09:04:55 +01:00
Patrick Ohly
50098b5329 autotools + Boost: --with-boost had no effect (MB#7856)
The location of Boost specified or found in the configure script was
not used during compilation. Now it is part of the global
BACKEND_CPPFLAGS variable which is used in all parts of SyncEvolution.
2009-11-09 08:51:24 +01:00
Patrick Ohly
15b1de77b8 SyncML server: find configuration for client automatically (MB#7710)
When the syncevo-dbus-server receives a SyncML message as initial
data from a transport stub, it peeks into the data with the help
of the Synthesis server engine and our SyncEvolution_Session_CheckDevice()
and extracts the LocURI = device ID of the client. This value is
guaranteed to be in the initial SyncML message.

Then it searches for a peer configuration (still called "server
configuration" in the current code) which has the same ID in its
remoteDeviceID property and uses that configuration.

Instantiating SyncContext and Synthesis engine multiple times
is a bit tricky. The context for the SynthesisDBPlugin currently
has to be passed via a global variable, SyncContext::m_activeContext.
SyncContext::analyzeSyncMLMessage() temporarily replaces that
with the help of a new sentinal class SwapContext, which ensures
that the previous context is restored when leaving the function.
Some common code was moved around for this (SyncContext::initEngine()).

The "default config" parameter in syncevo-http-server.py was
removed because it is no longer needed. The possibility to
select some kind of config context via the path below the
sync URL still exists. This is passed to syncevo-dbus-server via
the "config" peer attribute. It has no effect there at the
moment.

TestConnection.testStartSync() in test-dbus.py covers this kind of
config selection. To run it, a peer configuration with remoteDeviceID
"sc-api-nat" must exist.
2009-11-06 12:04:51 +01:00
Patrick Ohly
ab6a01f680 SynthesisDBPlugin: added NULL context pointer checks
The Synthesis engine calls some of the functions which depend
on a context even if creating the context failed. Normally
that does not happen, but better protect against it by
checking for NULL.
2009-11-06 11:38:47 +01:00
Patrick Ohly
b73e9e8b64 synevo-dbus-server: Session.Sync() signature fix
The Session::sync() prototype was changed without taking into
account that the method has to match the Session.Sync() signature.
Automaticly generated D-Bus bindings are a double-edged sword...

This was caught by the test-dbus.py TestDBusSync test. We really
need to run that more often and eventually nightly.
2009-11-05 19:25:18 +01:00
Patrick Ohly
a272d747f9 test-dbus.py: added Connection tests
The new TestConnection suite covers some Connection API related
aspects:
- creating a connection and closing it
- sending an invalid message
- sending a valid message

Right now these tests assume that a "syncevolution_server" config
exists. They depend on getting one Abort signal per connection
to shut down each test.

The signal recording code from TestDBusSync was moved into DBusUtil
so that the different tests can share this utility code.

Some sleeps are necessary after sync sessions because SIGTERM might
get caught without properly shutting down synevo-dbus-server (MB#7555).
2009-11-05 19:23:10 +01:00
Patrick Ohly
aa15620845 test-dbus.py: more reliable process handling
First, kill all running syncevo-dbus-server instances. Having
one running was one way how the tests could have failed because
it wasn't running with the right environment.

Second, use files for output instead of in-memory pipes. The latter
might have caused deadlocks when a process writes large amount of
data.

syncevo.log and dbus.log in the current directory are used. The
additional benefit is that these files can be read while the test
runs, for example when it is deadlocked for some other reason.

Third, when syncevo-dbus-server returns with a non-zero error code,
give dbus-monitor time to settle down before stopping it. Otherwise
the final D-Bus traffic might not get recorded.
2009-11-05 19:08:51 +01:00
Patrick Ohly
b704d06a12 D-Bus API + syncev-dbus-server: Connection.Abort signal only sent once
The API spec now guarantees that the signal is only raised once for
each connection. This was unspecified earlier. This change was made
to simplify clients and make the server more deterministic.

A new test in the test-dbus.py will depend on this behavior.
2009-11-05 17:55:02 +01:00
Patrick Ohly
7cc397aae7 syncevo-dbus-server: use unbuffered output
The syncevolution binary uses unbuffered stdio. Do the same in
the syncevo-dbus-server, just to be sure. Most of our code
does explicit fflush().
2009-11-05 17:53:32 +01:00
Patrick Ohly
af46ffb4ed syncevo-dbus-server: use random session IDs
In a transport which anyone can send messages to (like in a HTTP
server), a random session ID protects a bit against someone
inserting unwanted messages into a regular session.

This patch uses the usec part of gettimeofday() to initialize
the libc random number generator. Better (and more complex)
approaches are of course possible...

The reason for implementing this now is that automated testing via
test-dbus.py also had a problem with non-unique IDs: when the
server was restarted, separate runs ended up using the same
session ID because they were initialized with the current system time
in seconds. This confused signal listeners which checked the ID.
2009-11-05 17:51:05 +01:00
Patrick Ohly
e881031cbf test-dbus.py: removed dependency on Python 2.6 and python-gobject >= 2.16
Running the script failed on Debian Lenny failed because Python
and python-gobject are too old. Python 2.6 was required because
of subprocess.terminate(), replaced with os.kill(). python-gobject
2.16 was needed for glib, which is used in some tests to run
the event loop for a short while. These tests now fail if glib
is not available, while the rest of the tests can be run normally.
2009-11-05 13:13:17 +01:00
Patrick Ohly
529c208681 client-test: unit tests not included when building statically
Due to a typo in the src/syncevolution -> src/syncevo transition,
unit tests inside libsyncevolution.a were not included in the
client-test executable. The check of libsyncevolution.a searched
for the library in synccevo instead of syncevo.
2009-11-05 13:05:30 +01:00
Patrick Ohly
c292458086 SyncML server: don't check client credentials if not required
The "mustAuthenticate" parameter in the D-Bus Server.Connect()
call was ignored, valid credentials were always required unless
username and password in the server configuration were empty.
Now this parameter is passed through and used
- to configure the Synthesis engine correctly
- to suppress asking for our password if not needed

Note that we rely on a patch that turns <requiredauth>none</requiredauth>
into "accept invalid credentials". Without that patch, the client would
have to provide no credentials at all (which SyncEvolution doesn't support).
2009-11-04 17:02:24 +01:00
Patrick Ohly
9c7b8718c6 syncevolution-http-server.py: clients must authenticate
The "must authenticate" parameter for Server.Connect() had no
effect so far. Netherless, HTTP clients should have been required
to authenticate from the beginning.
2009-11-04 17:02:24 +01:00
Patrick Ohly
28bff38747 Synthesis server: session auth and device admin
Starting with this commit, SyncEvolution implements the
Synthesis session authentication and device administration
itself. The goal is to have better control over these steps
and become independent of the SDK_textdb which implemented
this before.

The SDK_textdb works, but it has several limitations, among
them the inability to choose a password. It is also called
"demo" in the source code, which raises some doubts about
its stability.

Because the Synthesis DB interface is now used both for database
access and for session handling, the Module_CreateContext() function
can not always select a source as context. When used as session
plugin, the global context pointer is NULL.

The Synthesis engine calls us at various points to save information.
Because it is not exactly clear how long we can buffer this
information in memory, it is always flushed to disk immediately.
2009-11-04 17:02:24 +01:00
Patrick Ohly
428375c20f logging + XML config: print config when it cannot be parsed
To track down internal errors the generated XML configuration
is now printed whenever the Synthesis engine cannot parse it.
2009-11-04 17:02:24 +01:00
Patrick Ohly
082485a232 SafeConfigNode::escape(): did not work correctly for strings with ! in them
The ! sign was used as escape character and thus has to be escaped
itself. In the less strict mode this wasn't done. Shouldn't affect
SyncEvolution 0.9.1 where the code was used in strict mode for
change tracking nodes, but broke the new nonce saving.
2009-11-04 17:02:24 +01:00
Patrick Ohly
f33a48a9e7 adding templates: also need to go into test/test-dbus.py
Part of the D-Bus API testing is checking of the GetConfigs()
call for templates. So when adding a new server template, that
test must also be updated.
2009-11-04 17:02:24 +01:00
Zhu, Yongsheng
f71bb52564 syncevo-dbus-server: implement progress (bug #7134)
Calculate progress information according to progress
event from synthesis library.

Considering the most common scenario and profiling data,
current implementation will partition a sync session into
3 *big* steps: SYNC_INIT, SYNC_DATA, SYNC_UNINIT
Typically each step contains one message send and receive,
thus occupies a specified proportion.
By default, 5 data items are supposed in calculating
proportions, which affect SYNC_DATA and SYNC_UNINIT.
The main idea of dynamically adjustment is that based on
the common scenario, if there are extra operations,
such as message send/receive or many data items,
adjust proportions by re-calculate operations of each
remaining step.
Typcially possible extra operations are more than one-time
message send/receive in a step and the number
of data items is not 5. Then we re-calculate proportions
for remaing steps according to future's operations
with the remaining proportion.
2009-11-04 17:01:36 +01:00
Patrick Ohly
1c2e27a4b4 gen-autotools.sh: avoid GNU find -printf
Compilation on Mac OS X fails when using the GNU find specific
-printf command line option, so avoid it.
2009-11-04 11:12:05 +01:00
Patrick Ohly
e150801bed configure: detect incorrect use of --with-synthesis-src
--with-synthesis-src requires a parameter. Without it, "yes"
was used as value, leading to a pretty obscure error message
about "no configure script in yes".

That error message should mention --with-synthesis-src. It now
says:
  error: --with-synthesis-src=/tmp: no Synthesis configure script found in that directory
2009-11-04 11:03:24 +01:00
Patrick Ohly
5acf33ff61 SQLite backend: added server admin calls
The recently introduced enableServerMode() and serverModeEnabled()
calls must be implemented by all sync sources not derived from
TrackingSyncSource. This patch adds the calls to the SQLiteContactSource,
using the default mechanism provided for it in SyncSourceAdmin.
2009-11-03 18:28:03 +01:00
Patrick Ohly
0ecef765e3 gen-autotools.sh: avoid GNU find -printf
Compilation on Mac OS X fails when using the GNU find specific
-printf command line option, so avoid it.
2009-11-03 18:25:44 +01:00
Patrick Ohly
1af876f625 stderr redirection: detect "error" messages and show them (MB#7655)
The "GConf Error: Failed to contact configuration server..." error
message was assigned the Logger::DEV severity and thus never shown to
users. At low loglevel settings it probably also never made it into a
log file, if one was written at all.

This patch raises the severity of all output lines which contain the
word "error". Clearly this only works for non-localized error
messages, but hopefully that's the majority of the relevant error
messages on stderr.
2009-11-03 14:52:01 +01:00
Patrick Ohly
807212d7b6 testing: Client::Sync broke when removing the source array in the sync() method
The active sources must be set before calling sync(), doing it in
prepare() is too late. The right way to do it with the revised
API is via source filters: disable all sources with a filter that
applies to all sources, then enable the desired one(s) with the
right mode with a more specific filter.
2009-10-29 16:08:57 +01:00
Patrick Ohly
999a0c6099 D-Bus testing: adapted to fully implemented GetConfigs()
Now that GetConfigs() correctly returns the actual templates
list instead of a hard-coded "google", the test had to be adapted.
2009-10-29 11:03:39 +01:00
Patrick Ohly
a3bf147726 D-Bus testing: set up environment also for running under debugger
The environment with XDG_ redirected into a local directory
also needs to be passed to gdb when debugging interactively.
Otherwise the tests would not run as without gdb.
2009-10-29 11:02:31 +01:00
Patrick Ohly
6cf1e71c33 syncevo-dbus-server: fixed compiler warning
The recently merged signal timeout code initialized members
in a different order than in the class, which g++ warns about.
2009-10-29 11:00:33 +01:00
Zhu, Yongsheng
62d82e4414 syncevo-dbus-server: use enum values to represent sync statuses
Use 5 enum values to represent sync statuses,
SYNC_IDLE, SYNC_RUNNING, SYNC_ABORTING,
SYNC_SUSPENDING, SYNC_DONE
So we could use one enum variable instead of
previously 3 boolean values
2009-10-29 10:08:27 +01:00
Zhu, Yongsheng
84f6cd7a03 syncevo-dbus-server: add test script for getConfigs
Add test script in test/dbus-server-config.py to test
getConfigs, usage:
python dbus-server-config.py [servername] --getconfigs
[null or any characters]
2009-10-29 10:08:27 +01:00
Zhu, Yongsheng
8faa1908eb syncevo-dbus-server: implement getConfigs
Get available configuration templates and configured
servers in getConfigs
2009-10-29 10:08:27 +01:00
Zhu, Yongsheng
84e3bcb8e0 syncevo-dbus-server: hook up checkForSuspend and checkForAbort
Hook up checkForSuspend and checkForAbort in dbus server
and implement sleep function but not suspend and
abort when CTRL-C is entered for often sync dbus server
runs as a daemonease enter the commit message for your changes.
2009-10-29 10:08:27 +01:00
Zhu, Yongsheng
e49e79b8c1 syncevo-dbus-server: add timeout mechanism for status and progress
For status and progress, we need a timer to record when
the last signal was triggered.
Here implement a 'Timer' class and add 2 timers in session
to keep time track of emitting signals for status and progress
2009-10-29 10:08:27 +01:00
Zhu, Yongsheng
42a01c0f31 syncevo-dbus-server: change checkSource and getDatabases
when the config doesn't exist, raising an error
instead of creating server template.
2009-10-29 10:08:27 +01:00
Zhu, Yongsheng
305dc790cc syncevo-dbus-server setConfig: reserve meta information
Previous impl removes necessary meta information, such
as global synthesis and source meta.

This patch is only to remove un-set sources and don't remove
meta information for global synthesis and sources which aren't be
removed
2009-10-29 10:08:27 +01:00
GLSQA
466497fe60 l10n: Updates to Finnish (fi) translation
Transmitted-via: Transifex (translate.moblin.org)
2009-10-29 09:54:39 +01:00
GLSQA
f01a7765e2 l10n: Updates to Finnish (fi) translation
Transmitted-via: Transifex (translate.moblin.org)
2009-10-26 15:57:39 -07:00
Patrick Ohly
83e7a240ae NEWS, version: updated for 0.9.1 2009-10-26 14:44:29 +01:00