Commit graph

32 commits

Author SHA1 Message Date
Patrick Ohly
edf1314def test: convert scripts to Python3
This is the result of 2to3, with the interpreter path updated manually,
tabs replaced by spaces and some obsolete packages removed.

Required because the current nightly build host no longer has Python2 installed.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2020-12-05 21:28:08 +01:00
Milan Crha
75dff12823 Python2 -> Python3
Originally developed by Milan Crha for Fedora, copied from there
by Patrick Ohly.
2020-08-09 16:31:32 +02:00
frdsktp
bcf21809d5 syncevo-http-server: stop using deprecated twisted.web.error (FDO #90419)
twisted.web.error.NoResource was replaced by
twisted.web.resource.NoResource.  This has become a real problem for
example on Fedora 22 where the old name is no longer available.
2015-06-05 14:31:43 +02:00
Tino Mettler
89dbb2d223 Use TLS instead of SSLv3
This fixes a potential security risk and connection problems with clients
that don't support SSLv3 anymore.

Closes: #772040
2014-12-12 08:45:24 +01:00
Patrick Ohly
624c357e11 http server: include time stamps in debug mode
Sometimes time stamps are necessary to understand timing-dependent
issues. A separate flag for timestamps on/off might be useful.
For now, enable them in debug mode.
2014-03-31 11:12:21 +02:00
Patrick Ohly
6655e5ebe8 syncevo-http-server: remove D-Bus timeouts
Under heavy load while testing, syncing occasionally failed with a D-Bus
message timeout, for example in the Close() call. Let's disable these timeouts
by explicitly passing something very large (infinite is not supported by the
Python bindings).

If HTTP processing takes to long, the client may resend, but in contrast to a
failed D-Bus method call that case is handled.

The increased timeout has no negative effect on detecting when
syncevo-dbus-server dies, because then the D-Bus daemon will notify
us immediately.
2014-03-26 09:48:52 +01:00
Patrick Ohly
c1384c9279 syncevo-http-server: log port which is used
This is particularly useful in combination with an URL that
has "0" as port number, because then Twisted will automatically pick
a port.
2014-01-17 16:15:16 +01:00
Patrick Ohly
4577c27fda HTTP server: handle message resends
If a client gave up waiting for the server's response and resent its message
while the server was still processing the message, syncing failed with
"protocol error: already processing a message" raised by the
syncevo-dbus-server because it wasn't prepared to handle that situation.

The right place to handle this is inside the syncevo-http-server, because it
depends on the protocol (HTTP in this case) whether resending is valid or
not. It handles that now by tracking the message that is currently in
processing and matching it against each new message. If it matches, the new
request replaces the obsolete one without sending the message again to
syncevo-dbus-server. When syncevo-dbus-server replies to the old message, the
reply is used to finish the newer request.

This situation is covered by
Client::Sync::eds_event_eds_contact::testManyDeletes with 100 items and
client and server running under valgrind. The test failed earlier and works
now.
2013-07-10 13:08:02 +02:00
Patrick Ohly
af59e95e2d syncevo-http-server: fixed printing of server debug output
Python failed to call logSyncEvoOutput() after adding the additional
'process' parameter to LogOutput because it extracts all four
parameters and then cannot pass them to logSyncEvoOutput().

Now logSyncEvoOutput() uses the new process information to instantiate
a logger with the right prefix, using 'sync' as fallback for messages
without that information (as before).
2012-09-10 14:54:29 +02:00
Patrick Ohly
7fef16f178 HTTP server: extended debugging + resource tracking
Added debug output and double-check D-Bus signal watch
handling. Explicitly remove watches. Not sure whether
they remained active earlier.

This was done as an attempt to track down a "connection: cancelled"
error in the HTTP client during stress testing. The real reason
turned out to be a deadlock inside syncevo-dbus-server caused by
libsynthesis, which prevented serving the new connection.

The shutdown of that connection remains mysterious. It seems
that Twisted itself cancelled the request.
2012-05-22 09:03:14 +00:00
Patrick Ohly
f577d249e4 syncevo-http-server: added message dumps
Each incoming and outgoing message is logged when -d is given.
Text messages are dumped verbatim.
2012-02-28 20:41:38 +00:00
Patrick Ohly
2de4eea57c syncevo-http-server: fixed error handling after unexpected end of session
The code which was meant to report a 404 error triggered a twisted internal
error. Replaced with an error page.
2011-12-16 16:24:19 +00:00
Patrick Ohly
4fc6c3e2c4 Merge remote-tracking branch 'origin/syncevolution-1-2-branch'
Conflicts:
	configure.ac
	src/syncevo-dbus-server.cpp
	src/syncevo/Cmdline.cpp
	test/ClientTest.cpp
	test/ClientTest.h
	test/generate-html.xsl
	test/runtests.py

Conflicts caused by backporting + merging back slightly modified
backports.
2011-11-28 10:16:57 +01:00
Alain Knaff
be22a465c4 syncevo-http-server: support chained SSL certificates
So far, the file pointed to by --certificate-file had to
contain the server certificated (signed by a CA known to the client)
and (optionally) a client certificate.

With this patch, the file may also contain additional intermediate
certificates which will be sent to the client (chained certificates).

See http://twistedmatrix.com/pipermail/twisted-python/2010-July/022597.html
2011-11-25 13:33:35 +00:00
Chris Kühl
9852f17a9b testing: Added SYNCEVOLUTION_DATA_DIR env variable http-server. 2011-08-26 14:23:41 +02:00
Patrick Ohly
29114abe1f syncevo-http-server: a POST with invalid session ID did not result in 404 error
The code which was meant to raise the 404 error used the wrong
exception name and thus produced a Python exception instead, which
translated into an internal server error. Raising an exception
was not the right way to produce a 404 reply.

Replaced with a combination of setResponseCode() and writing a fixed
HTML response. Purely cosmetical, did not have an effect in practice.
2011-01-03 21:40:39 +01:00
Patrick Ohly
0dea4e939c syncevo-http-server: detect premature client disconnect (BMC #10031)
The documentation of Twisted's Request.notifyFinish() doesn't say so
explicitly, but errors are passed to the Errback, not the normal
callback. Adding self.done() as both of these allows the server to
detect premature client disconnects.

That error handling code itself was not working properly: instead of
keeping the connection to syncevo-dbus-server open in case that the
client resends the POST, it close the D-Bus connection. With this
patch it is kept open.

The new SuspendProxy tests covered this failure.
2011-01-03 21:27:48 +01:00
Patrick Ohly
fe7406177d syncevo-http-server: allow clients to detect truncated replies
Including the Content-Length header allows clients to detect
incomplete replies. Without this fix the new SuspendProxy test failed
because the proxy returned a header, then truncated the connection
without sending any data. libsoup treated that as an empty reply,
which resulted in a parser error in libsmltk and aborted the sync,
without resending the POST.
2011-01-03 21:23:10 +01:00
Patrick Ohly
853d9d2b55 syncevo-http-server: removed obsolete and harmful gobject.MainLoop
Instantiating gobject.MainLoop had two negative side effects:
- shutdown after CTRL-C got stuck
- SIGCHLD after syncevo-dbus-server shutdown also caused a deadlock

Not sure why the "loop = gobject.MainLoop()" was in the code;
it doesn't seem to serve any purpose anymore.
2010-12-28 22:36:29 +01:00
Patrick Ohly
912f2992e8 syncevo-http-server: start syncevo-dbus-server explicitly (BMC #10270)
--start-syncevolution
                        sets up the right environment for syncevo-dbus-server
                        and (re)starts it explicitly, instead of depending on
                        D-Bus auto-activation; to be used when SyncEvolution
                        is not installed at the location it was compiled for
  --syncevolution-path=PATH
                        sets the installation path (the directory which
                        contains 'bin', 'libexec', etc.) to be used in
                        --start-syncevolution, default is the location where
                        syncevo-http-server itself is installed

Starting syncevo-dbus-server in a synchronous manner similar to the
traditional D-Bus get_object() is tricky. It is currently implemented
as a subprocess spawn, followed by a loop which checks for the
well-known name to appear on the session bus.

Open issues:
- What if syncevo-dbus-server was already running?
- The code is meant to restart syncevo-dbus-server on demand, but that
  doesn't work. Once the spawned process terminates, twisted seems to get
  stuck handling the SIGCHLD signal for a process it doesn't know anything about.
2010-12-28 22:36:21 +01:00
Patrick Ohly
4812b391fd syncevo-http-server: added D-Bus session handling (BMC #10270)
--start-dbus-session  creates a new D-Bus session for communication with
                        syncevo-dbus-server and (inside that server) with
                        other D-Bus services like Evolution Data Server,
                        removes it when shutting down; should only be used if
                        it is guaranteed that the current user will not have
                        another session running, because these services can
                        get confused when started multiple times; without this
                        option, syncevo-http-server a) uses the session
                        specified in the environment or b) looks for a session
                        of the current user (depends on ConsoleKit and might
                        not always work)
2010-12-28 22:34:56 +01:00
Patrick Ohly
b731f26b63 syncevo-http-server: added SSL support
--server-certificate=CERT
                        certificate file used by the server to identify itself
                        (required for https)
  --server-key=KEY      key file used by the server to identify itself
                        (optional, certificate file is used as fallback, which
                        then must contain key and certificate)

Example keys for localhost and a README for creating/using them are
included in this commit.
2010-12-28 11:31:36 +01:00
Patrick Ohly
c57e77e62a syncevo-dbus-server: expect error when closing connection after failure
Instead of logging a
  org.freedesktop.DBus.Error.UnknownMethod: Method "Close" with signature "bs" on interface "org.syncevolution.Connection" doesn't exist
error, catch this error and only print it at debug level.

This is caused by syncevo-dbus-server removing the connection
right away after sending the Abort signal, so when Close() is
called on it, the instance no longer exists. The D-Bus error
is a bit misleading.

Not calling Close() would be the alternative, but determining
in advance when Close() is not necessary is hard, so better try in
all cases.
2010-12-27 22:45:16 +01:00
Patrick Ohly
99b53ec93d syncevo-http-server: better logging of D-Bus exceptions
Exceptions from syncevo-dbus-server which will also appear as error
message from that server need to be logged at debug level, to avoid
showing internal details like stack backtrace to users.

Also, the observer must *replace* the default logging instead of
adding itself. Done with startLoggingWithObserver().

The observer replaces the default logger. As a special case
2010-12-27 22:03:30 +01:00
Patrick Ohly
e533e680b2 syncevo-http-server: show syncevo-dbus-server output (BMC #6369)
Output produced by syncevo-dbus-server is now shown as part of the
regular syncevo-http-server. It is thus no longer necessary to watch
the output of syncevo-dbus-server.
2010-12-27 18:09:30 +01:00
Patrick Ohly
fb82fb3e8e syncevo-http-server: improved logging
Added new command line options:

  -d, --debug           enables debug messages
  -q, --quiet           limits output to real error messages; ignored if
                        --debug is given
  --log-config=LOGCONFIG
                        configure logging via Python logging config file;
                        --debug and --quiet override the log level in the root
                        logger

An example config file is included in the distribution.

The output is now similar to SyncEvolution command line output:
  [DEBUG] twisted: twisted.web.server.Site starting on 9000

The implementation is based on the standard Python logging module.
Twisted output is redirected into it at log levels DEBUG and ERROR.
2010-12-27 17:40:58 +01:00
Patrick Ohly
22b4776735 syncevo-http-server: include Python script in distribution
Because people asked for it, the Twisted-based HTTP server is
now installed when D-Bus support (which it depends on) is enabled.

It is installed as "syncevo-http-server" without the .py suffix
because that is an implementation detail that might change.

Because people need a way to figure out how to start it, usage
information is provided via optparse.
2010-03-22 15:50:19 +01:00
Patrick Ohly
50c520eaaa syncevo-http-server.py: bug fix for resending
Even when the request is finished, the render method must still
call NOT_DONE_YET.
2010-03-18 18:37:38 +01:00
Patrick Ohly
7aa4d9d8c4 syncevo-http-server.py: support resending of last reply
When a client posts exactly the same data again (identified via
session ID and message content) because it didn't get a reply and we
have a reply, we can send back that reply immediately. This is not
tied to actually having that session around, because the server might
have closed and thus removed that session already (the "last reply in
session lost" problem).

Only one reply is buffered, which would be a problem if we supported
multiple parallel sessions, which syncevo-dbus-server doesn't.

This patch also adds some more debug prints and removes an obsolete
TODO comment about identifying clients which start a new session while
there is an active one for them. That is already handled inside
syncevo-dbus-server.
2010-03-18 18:37:38 +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
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
98f83c5b3c syncevo-dbus-server/syncevolution-http-server.py: SyncML HTTP server
This uses the new combined client/server Synthesis engine. When
building shared modules, the engine is opened dynamically only
while needed, thus reducing overall memory consumption.

The HTTP server is implemented in Python, using the the 'twisted'
server framework because it can use the same glib event loop as the
D-Bus binding. This allows us to keep the same event loop running
forever and react to both kinds of events.

The server takes a base url (including host name and port)
and a default configuration as name. The host name is currently
ignored. It could be used to bind to a specific interface.

The path is what a client has to use as part of his sync URL
to synchronize against the default configuration. In addition
the client can add another path to select that as his server
configuration.

For example, if the script is called with
   http://localhost:9000/syncevolution default
then syncURL = http://localhost:9000/syncevolution will synchronize
against the configuration called "default". With syncURL =
http://localhost:9000/syncevolution/my_server, it will
synchronize against "my_server".
2009-10-07 18:15:45 +02:00