Commit graph

427 commits

Author SHA1 Message Date
Lance Stout
6c57bb0553 Simplify stringifying XML 2012-09-24 20:59:51 -07:00
Lance Stout
c2ae1ee891 Remove race condition when aborting while connecting/reconnecting. 2012-09-18 10:35:53 -07:00
Lance Stout
fb3e6b7e35 Don't break checking certs for localhost. 2012-09-13 11:00:29 -07:00
Florian Fieber
e510875f64 Fix certificate expiration scheduler
timedelta.seconds does not store the total seconds of a time span.
Internally, seconds is the next smaller unit to days, hence
timedelta.seconds will never exceed (or reach) the number of seconds
in a day (60*60*24=86400)
2012-08-23 00:22:22 -07:00
Lance Stout
c6ac64ed2d Help prevent race condition dealing with auto_reconnect 2012-08-14 09:54:38 -07:00
Lance Stout
f7a710e55b Add abort() method to kill the session and stop all processing without properly closing the stream. 2012-08-10 14:12:05 -07:00
Lance Stout
4e12e228cb Fix tracking service name for DIGEST-MD5 2012-08-10 12:40:28 -07:00
Lance Stout
aebcf6ff82 Re-add connection delay after exhausting DNS records. 2012-08-07 01:38:15 -07:00
Lance Stout
8c2ece3bca Ensure self._der_cert exists even if no certs are used. 2012-08-04 21:37:46 -07:00
Lance Stout
80a90a6221 Prevent auto_reconnect interference when disconnecting. 2012-08-04 21:10:45 -07:00
Lance Stout
167d1ce97b Add fields for setting client cert and key for SASL EXTERNAL. 2012-07-30 19:15:10 -07:00
Lance Stout
422e77ae40 Don't wait to retry connection if out of DNS records. 2012-07-29 17:26:04 -07:00
Jonas Wielicki
e3fab66dfb Allow tasks to remove themselves during execution
The scheduler class is now capable with dealing with tasks which remove
themselves from the scheduler during execution.

Additionally, some optimizations were applied by use of iterators and
some functions better suited for the purpose.

Please peer-review, all tests pass.
2012-07-27 10:45:23 -07:00
Lance Stout
98b7e8b10a Fix initializing plugins in stanzas with a language set. 2012-07-25 01:33:17 -07:00
Lance Stout
9a08dfc7d4 Add support for using CDATA for escaping.
CDATA escaping is disabled by default, but may be enabled by setting:

    self.use_cdata = True

Closes issue #114
2012-07-24 03:25:55 -07:00
Lance Stout
3e43b36a9d Standardize importing of queue class.
This will make it easier to enable gevent support.
2012-07-24 02:39:54 -07:00
Lance Stout
d06897a635 Add backwards compatibility shim for the old jid.py location. 2012-07-24 01:43:20 -07:00
Lance Stout
e4e18a416f Add validation for JIDs. 2012-07-24 01:43:20 -07:00
Lance Stout
917faecdcb Fix issue of roster data being split across multiple rosters.
Resolved by always normalizing JIDs to bare form, regardless of if they
are JID objects or strings.

Also simplified related code to prefer use of JID objects instead of
strings so they don't need to be parsed multiple times.
2012-07-19 23:54:18 -07:00
Lance Stout
51fee28bf4 Add a warning log if dnspython is not found for SRV lookup.
Closes issue #183
2012-07-16 19:38:50 -07:00
Lance Stout
5df3839b7a Add method to remove a filter. 2012-07-10 01:37:23 -07:00
Lance Stout
99701c947e Prevent None from being added to the schedule from a timing issue. 2012-07-09 22:59:26 -07:00
Jay Farrimond
88b5e60807 only log cert errors if not handled by user 2012-07-05 13:38:26 -07:00
Lance Stout
100e504b7f Resolve xml:lang issue with duplicated elements depending on ordering. 2012-06-22 18:19:17 -07:00
Lance Stout
1ad171dfe5 Fix issue with setting subelements values with default langs. 2012-06-20 23:19:52 -07:00
Lance Stout
2a78570d65 Fix setting IPv6 default configuration option. 2012-06-20 22:21:34 -07:00
Lance Stout
e86444e5fb Make the use of IPv6 configurable.
Set self.use_ipv6 = False before connecting.

Fixes issue #175
2012-06-20 19:39:24 -07:00
Lance Stout
433ee08687 Allow message and presence stanzas to be embedded as substanzas. 2012-06-19 16:20:54 -07:00
Lance Stout
7858d969d8 Remove usage of deprecated getchildren() method. 2012-06-19 09:47:31 -07:00
Lance Stout
d92aa05b5c PEP8 formatting updates. 2012-06-19 01:29:48 -07:00
Lance Stout
534aaf2b2a Properly handle certs with no extensions. 2012-06-19 00:01:02 -07:00
Lance Stout
f824950552 Enable using xml:lang with normal interfaces.
Using the special language value '*' will return a dictionary of all
such elements keyed by language.

    >>> msg = Message()
    >>> msg['body'] = 'Hi!'
    >>> msg['body|sv'] = 'Hej!'
    >>> print(msg)
    '<message xmlns="jabber:client">
      <body>Hi!</body>
      <body xml:lang="sv">Hej!</body>
    </message>'
    >>> print(msg['body|*'])
    OrderedDict(
        ('', 'Hi!'),
        ('sv', 'Hej!'))

Remaining items:

- Stanza path matching does not support language specifiers for normal
  interfaces, only for plugins.
2012-06-18 22:00:33 -07:00
Lance Stout
181aea737d Add initial support for xml:lang for streams and stanza plugins.
Remaining items are suitable default actions for language supporting
interfaces.
2012-06-18 22:00:33 -07:00
Lance Stout
a08c2161a7 Ensure that ssl_invalid_cert returns PEM formatted certifcate data. 2012-06-15 15:29:53 -07:00
Lance Stout
c39ad7dfbb Prevent duplicate certificate expiration timers. 2012-06-13 09:13:33 -07:00
Lance Stout
6cfb5cb14c Add extra check for the cert in the expiration handler. 2012-06-09 11:01:45 -07:00
Lance Stout
4b37a4706f Fix SSL handshake handling when not using legacy SSL.
Fixes issue #172
2012-06-09 11:01:11 -07:00
Lance Stout
7b1564947d Ensure that all SSL cert error handling is overridable using event handlers.
Relevant events:

    ssl_invalid_cert
    ssl_invalid_chain
    ssl_expired_cert
2012-06-09 11:00:55 -07:00
Lance Stout
98677fd602 Don't add cert expiration timer if no certs are being used. 2012-06-04 11:53:58 -07:00
Lance Stout
856a826eea Fix syntax error in line continuation. 2012-06-01 14:09:14 -07:00
Lance Stout
387ef513d6 Check that the session is still alive before sending data.
Fixes issue #168
2012-06-01 13:50:38 -07:00
Lance Stout
350a2b8bbc Preemptively mark threads as exited if calling disconnect(). 2012-05-31 22:04:45 -07:00
Lance Stout
c9093c9972 Handle not being able to connect using IPv6 if the host does not support it. 2012-05-27 16:33:21 -07:00
Lance Stout
f49311ef9e Add better certificate handling.
Certificate host names are now matched (using DNS, SRV, XMPPAddr, and
Common Name), along with expiration check.

Scheduled event to reset the stream once the server's cert expires.

Handle invalid cert trust chains gracefully now.
2012-05-22 03:56:06 -07:00
Lance Stout
678e529efc Remove unused xmlstream test client.
It's in the repo history if we need it later.
2012-05-17 22:27:03 -07:00
Lance Stout
e918a86028 Make the error message better regarding hanged threads.
All event handlers which call disconnect() MUST be registered using
`add_event_handler(..., threaded=True)` in order to prevent temporarily
deadlocking until a timeout occurs.

This is required because disconnect() waits for the main threads to
exit before returning, including the event processing thread. Since
handlers registered without `threaded=True` run in the event processing
thread, the disconnect() call will deadlock.
2012-05-10 10:22:38 -07:00
Lance Stout
03dedfc871 Windows doesn't support inet_pton. 2012-05-06 12:17:50 -07:00
Lance Stout
9e86a7b357 Tidy up and add tests for multi_attrib plugins. 2012-05-05 14:01:13 -07:00
Erik Larsson
fa86f956ef added multifactory and support for it to register_stanza_plugin 2012-04-30 22:19:17 +02:00
Lance Stout
bf8a9dc20d Add logging note about potential cause of disconnect() deadlock. 2012-04-29 14:48:14 -07:00
Lance Stout
08716c35fd Set a timeout when waiting for threads.
If calling disconnect() from a non-threaded event handler, deadlock can
happen as disconnect() is waiting for threads to close, but the event
runner is blocked by a handler waiting for disconnect() to return.

It is best to specify threaded=True for event handlers which may call
disconnect().
2012-04-29 14:45:00 -07:00
Lance Stout
2eeaf4d80c Use provided stanza ID. 2012-04-25 13:55:46 -07:00
Lance Stout
0cc14cee4d Ensure that SSL errors are handled in Py3.3 2012-04-24 16:11:49 -07:00
Lance Stout
a20a9c505d Track threads to ensure all have exited when disconnecting. 2012-04-22 18:13:36 -07:00
Lance Stout
913738444e Count and track the main threads, so we can delay disconnecting until all have quit. 2012-04-21 10:36:39 -07:00
Lance Stout
8ee30179ea Add _use_daemons flag to XMLStream to run all threads in daemon mode.
This WILL make the Python interpreter produce exceptions on shutdown.
2012-04-20 15:21:31 -07:00
Lance Stout
cb2469322b Handle using provided weakrefs as stanza parent references.
Fixes issue #159
2012-04-14 11:13:38 -04:00
Lance Stout
94aa6673ca Check for the stop event more aggressively in the send thread. 2012-04-13 08:27:11 -04:00
Lance Stout
4cd5d3b3b5 Fix DNS resolution results for IP literals. 2012-04-10 14:08:33 -04:00
Lance Stout
15ef273141 Add a prefix to stanza ID values to ensure that they are unique per client. 2012-04-08 21:15:53 -04:00
Lance Stout
aedbecd673 Correct the statemachine's ensure_any method.
It had not been updated to use the new condition instead of the old
threading event.
2012-04-06 17:39:51 -04:00
Lance Stout
51e5aee830 Add default mapping of localhost to ::1 and 127.0.0.1 2012-04-06 15:08:21 -04:00
Lance Stout
48504ed5e2 Display IPv6 literal addresses in brackets. 2012-04-01 19:32:12 -07:00
Lance Stout
4d4d1e0ee5 Improve connection handling by not delaying until all DNS records are tried. 2012-03-30 10:12:44 -07:00
Lance Stout
c1d36cad46 Add better DNS resolver wrapper. 2012-03-30 10:12:43 -07:00
Lance Stout
912463ed6a Fix sending data after </stream>
Clearing the session_started_event before sending </stream> will
pause the send loop so that we don't continue sending data after
the </stream>.
2012-03-28 23:53:55 -07:00
Lance Stout
94923ae898 Improve handling disconnections.
- Add option for disconnecting without sending </stream>:

    self.disconnect(send_close=False)

- Optionally distinguish between session_end and disconnected based
  on if </stream> was sent.

    self.end_session_on_disconnect = False
2012-03-27 23:24:42 -07:00
Lance Stout
a1ddd88208 Add support for a new type of stanza interface: bool
The set of bool_interfaces provides default behaviour for
checking/setting the presence of empty subelements.

The prime example of this would be:

    bool_interfaces = set(['required'])

This would mean that ``stanza['required']`` would return ``True`` for:

    <stanza>
       <required />
    </stanza>

and ``False`` for:

    <stanza />

Likewise, assigning ``stanza['required'] = True`` would add an empty
``<required />`` element, and setting it to ``False`` would remove
such an element if it exists.
2012-03-27 21:05:50 -07:00
Lance Stout
ee6a9b981a Simplify sending whitespace keepalives.
Now that we have the send lock, we can use now=True.
2012-03-27 20:53:27 -07:00
Lance Stout
fa4c52e499 Correct handling of acks for XEP-0198 under heavy load. 2012-03-21 13:00:43 -07:00
Lance Stout
d5484808a7 Respect reattempt=False setting when reconnecting. 2012-03-21 10:28:26 -07:00
Lance Stout
59d1b8e131 Correct connect() documentation, don't delay attempts if reattempt=False.
See issue #152
2012-03-20 09:56:39 -07:00
Lance Stout
fbdf2bed49 Add out_sync filter category.
Added option to XMLStream.send() to skip applying filters.

Filters in the out_sync group are synced with placing stanza content
either on the wire directly or into the send queue. Because of this,
out_sync filters should not block.
2012-03-18 00:59:45 -07:00
Lance Stout
9f43d31bf5 Add setting for maximum number of reconnection attempts.
Setting self.reconnect_max_attempts to a non-None value will limit
the number of times a connection attempt will be made before quiting
and raising a 'connection_failed' event.
2012-03-12 16:19:18 -07:00
Lance Stout
4cb8a8d389 Modify the cert event to provide the PEM encoded cert in all cases. 2012-03-07 15:03:35 -08:00
Lance Stout
53bcd33e1d Let disconnect() wait for its lock for a few seconds.
This should eliminate most debug statements about not being
able to acquire a lock during disconnect.
2012-02-22 07:57:13 -08:00
Lance Stout
ecd6ad6930 Fix incompatibility with clearing an element between ElementTree and cElementTree 2012-02-19 20:27:53 -08:00
Lance Stout
c36073b40e xml.etree.ElementTree raises ExpatError instead of SyntaxError or ParseError. 2012-02-19 20:27:19 -08:00
Lance Stout
94b57d232d More pyflakes cleanup. 2012-02-18 11:44:05 -08:00
Lance Stout
c43c7be86c Make last_xml usage a little more explict. 2012-02-17 11:40:07 -08:00
Lance Stout
c58462f154 Fix undeclared variable usage for reconnect. 2012-02-17 11:12:48 -08:00
Lance Stout
fb2582e53b Fix fixing remove_stanza()
Fixes issue #146
2012-02-16 07:25:44 -08:00
Lance Stout
d807613117 Don't retrieve cert until a connection is made. 2012-02-16 07:02:56 -08:00
Lance Stout
6d922d00c3 Fix remove_stanza().
Fixes issue #146
2012-02-16 07:02:19 -08:00
Lance Stout
61ea84093b Don't shutdown completely after handling SyntaxError.
The ``shutdown = True`` line was preventing the stream from reconnecting
after handling the error.

Fixes issues #101, #145
2012-02-10 19:28:12 -08:00
Lance Stout
e76d6a481f Fix undefined variable references when DNS timeouts. 2012-02-10 19:20:17 -08:00
Lance Stout
ca5145c210 Fix IPv6 query logging. 2012-02-10 06:46:51 +01:00
Lance Stout
1a272fd276 Add support for querying and connecting to IPv6 addresses.
Tested using servers provided by Florian Jensen (flosoft.biz)
during the 2012 FOSDEM XMPP Summit.

Fixes issue #94.
2012-02-09 21:28:28 -08:00
Lance Stout
952260b423 Add ssl_cert event (direct).
The payload is a dictionary of parsed cert data, as provided by
Python's getpeercert() socket method. It unfortunately does not
provide much detail beyond basic info.
2012-02-04 14:16:37 +01:00
Lance Stout
f98e5a03de Fix typo s/is_set/is_set() 2012-02-02 18:14:48 +01:00
Lance Stout
3ab7c8bcc3 Make socket_error run as a direct event to ensure that it is handled.
Socket errors that occur before stream processing begins could not be
handled as the event loop would not be running yet.

Resolves issue #142
2012-01-28 18:54:46 -08:00
Lance Stout
1e01903072 Revert "Remove stream feature handlers on session_start."
This reverts commit 4274f49ada.

The SASL mech was choking on this, so let's send it back for some
more refining.
2012-01-18 11:51:00 -08:00
Lance Stout
86d8736dcc Hash JIDs based on full JID string.
This makes JID objects equivalent to strings in dictionaries, etc.

>>> j = JID('foo@example.com')
>>> s = 'foo@example.com'
>>> d = {j: 'yay'}
>>> d[j]
'yay'
>>> d[s]
'yay'
>>> d[s] = 'yay!!'
>>> d[j]
'yay!!'
2012-01-17 23:03:48 -08:00
Lance Stout
2923f56561 Pre-parse StanzaPath paths to speed up matching.
The parsing and namespace cleaning isn't terribly expensive, but it does
add up. It was adding an extra 5sec when processing 100,000 basic
message stanzas.
2012-01-17 22:28:44 -08:00
Lance Stout
4274f49ada Remove stream feature handlers on session_start.
Based on profiling, using around 35 stream handlers quarters the number
of basic message stanzas that can be processed in a second, in
comparison to only using the bare minimum of four handlers.

To help, we can drop handlers for stream features once the session
has started. So that we can re-enable these handlers when a stream
must restart, the 'stream_start' event has been added which fires
whenever a stream header is received.

The 'stream_start' event is a more generic replacement for the
existing start_stream_handler() method.
2012-01-17 22:14:24 -08:00
Lance Stout
de35848500 Don't serialize XML unless we need to. 2012-01-14 10:54:48 -08:00
Lance Stout
e0545bf0bc Merge branch 'develop' into develop-1.1 2011-12-31 01:29:12 -05:00
Lance Stout
03bc38f7e3 Add docs on using Iq stanzas. 2011-12-31 01:28:41 -05:00
Lance Stout
1a61bdb302 Ensure that stanza plugins work as expected if the XML is appended. 2011-12-28 09:53:22 -05:00
Lance Stout
2f2ebb37e4 Merge branch 'develop' into develop-1.1 2011-12-27 18:05:42 -05:00