2
0
mirror of https://github.com/msantos/xmppipe synced 2024-11-13 13:10:32 +00:00
Commit Graph

42 Commits

Author SHA1 Message Date
Michael Santos
07174101b4 encoding: remove useless lookup, sprintf 2016-09-04 09:45:20 -04:00
Michael Santos
1426be5902 Update README 2016-09-03 09:39:57 -04:00
Michael Santos
def456835b Add README 2016-09-02 12:08:11 -04:00
Michael Santos
072e8542ae alloc: log sizes on error 2016-06-27 07:08:51 -04:00
Michael Santos
7d4672a99a enomem: log function name
xmppipe occasionally crashes with an "allocation failure" message. Log
the function name for debugging.
2016-06-17 09:56:03 -04:00
Michael Santos
e96427bb36 Fix signed/unsigned integer comparison 2016-03-21 10:14:53 -04:00
Michael Santos
a7717f381e Add compiler hardening flags 2016-02-03 10:17:31 -05:00
Michael Santos
fc09ca4ff1 Be explicit with checks 2015-07-21 09:44:08 -04:00
Michael Santos
d0792db2f8 darwin/sunos: include uuid.h 2015-07-07 09:00:28 -04:00
Michael Santos
a392e836a0 Compile on BSDs
Use uuid_create(3) and uuid_to_string(3) to create the message id on
BSDs. Only tested on FreeBSD but should work on OpenBSD and NetBSD.

Add untested support for compiling on Solaris and Mac OS X:

* SmartOS has libuuid installed by default with rsyslog via pkgsrc

* Mac OS X has libuuid as part of libSystem:

http://lists.apple.com/archives/unix-porting/2009/Aug/msg00006.html
2015-07-01 09:31:44 -04:00
Michael Santos
c814208bad Remove check for negative unsigned integer O.o 2015-06-30 12:19:20 -04:00
Michael Santos
69f97cd872 Add "to" field to message
Distinguish which user received a message. Possibly useful if multiple
sessions are logged in or someone directly messages the bot.
2015-06-29 10:29:44 -04:00
Michael Santos
4310fe0e6b Exit when disconnected 2015-06-28 10:34:41 -04:00
Michael Santos
1a680daa48 example: read in larger chunks of data
Lengthen the poll delay to read in larger chunks of data. With a poll
value of 1 ms, there could be a large protocol message overhead: 1
character per XML stanza.
2015-06-15 16:55:41 -04:00
Michael Santos
5b7c7a1b64 example: tunnel SSH over XMPP
Server (system with access to the SSH and XMPP server):

 # ssh-over-xmpp server <conference> <IP address> <port>
 ssh-over-xmpp server sshxmpp 1.2.3.4 22

Client (system with access to the XMPP server):

 ssh -o ProxyCommand="ssh-over-xmpp client sshxmpp" 127.0.0.1
2015-06-13 09:13:27 -04:00
Michael Santos
633bc390cb Test string is NULL, not first character of string 2015-06-12 10:16:56 -04:00
Michael Santos
e82fc91bfb xmpp_stanza_get_name: check for NULL 2015-06-11 09:55:54 -04:00
Michael Santos
37bd93160b Reset ping failures after any response
Use a fixed ping handler rather than scheduling a ping handler per ping
request.

If the XMPP client or server is busy, many outstanding ping requests
can be waiting, resulting in a number of ping handlers being queued.
Each of the ping handlers does the same thing (resets the failure count
to 0) but any dropped pings resulted in the handlers being queued
forever.
2015-06-10 07:49:21 -04:00
Michael Santos
c3c83f9d72 Lower the default buffer size
For ejabberd and the mongooseim fork of ejabbered, 4097 bytes is around
the maximum message size before messages are dropped (the extra byte is
for libstrophe to put the terminating NULL. Otherwise, with a buffer
of 4096, the message will be broken up into 2 parts, with the second
consisting of the last byte of the message).

With base64 encoding, the message size will increase to 4097 * 4 / 3
bytes. When sending streams of binary data (cat'ing a file over XMPP,
ssh over XMPP, ...), stream management will get backlogged and messages
will disappear.

So halve the default buffer size. Is it too big for other jabber
servers? It is one of the mysteries but the "-b" option exists for those.
2015-06-03 10:08:37 -04:00
Michael Santos
1975057b6d -m -> -b
Rename the buffer size switch to something more memorable. Add a missing
break in the option processing switch statement.
2015-06-02 08:17:28 -04:00
Michael Santos
4c69352f19 stream management: flow control
Implement flow control by monitoring the number of unacked stream
requests and the number of unprocessed stanzas. If either exceeds a user
controlled limit, xmppipe will stop reading from stdin. Further stream
requests will be generated whenever the keepalive timeout is reached and
an XMPP ping is sent.

ejabberd/mongooseim will close the connection if there are about 5
unacked stream requests. xmppipe should probably do the same thing.

With these changes, binaries can be reliably (but slowly) sent over
XMPP. ssh over XMPP is also working reliably (with light testing). Because
of the increase in size due to base64 encoding, the buffer size needs
to be reduced so the encoded message is under 4k (-m 1024 is ok).
2015-06-01 09:39:22 -04:00
Michael Santos
5c14db6448 sm: request ack for every stanza
When stdin is closed with stream management enabled, xmppipe waits for
the ack to match the number of stanzas sent to ensure all the data has
been flushed to the server.

The server may not respond to every stream request and a stream request
message is generated only when a stanza is sent. Since stdin is closed,
the only traffic is the XMPP pings which are sent out every 60 seconds
by default. The result is, when stdin is closed, it may take several
minutes for xmppipe to exit.

Work around the problem by sending a stream management request for every
stanza.
2015-05-31 08:56:04 -04:00
Michael Santos
147e0d7c2b Consistenly check xmpp get ops for NULL values 2015-05-30 10:41:36 -04:00
Michael Santos
c4499fa4df example: clean up the bot script 2015-05-27 10:55:05 -04:00
Michael Santos
16ec036134 Fix format warnings 2015-05-26 07:43:45 -04:00
Michael Santos
da5fecd041 makefile: static target, link against libresolv
libresolv is required for base64 encoding.
2015-05-25 10:20:04 -04:00
Michael Santos
3ae0a9f88f Transparently base64 encode data to MUC
Optionally base64 encode data sent to and from a conference, allowing
transfer of binary data.

This could also be accomplished by piping in base64 encoded data:

    base64 /bin/ls | xmppipe

However the base64 command does not work with streams of data.
2015-05-24 10:27:59 -04:00
Michael Santos
bcf7c1b2e8 Check libstrophe funs for NULL return values
Ensure XML elements may exist in the stanza before attempting to use
them.
2015-05-23 09:06:24 -04:00
Michael Santos
4cbd8ec1c3 Add wrappers around libstrophe funs that may fail
Check for errors on libstrophe functions that return non-void. Some of
the funs have undocumented failure conditions (e.g.,
xmpp_stanza_copy()). Others return less than zero or enum values. To
account for future discoveries, use a wrapper instead of a macro.
2015-05-22 09:48:15 -04:00
Michael Santos
ef7e414af6 Exit on connection failure
Should output a better error message based on the status returned to
handle_connection.
2015-05-21 10:11:22 -04:00
Michael Santos
de7200819d Fix memory leak on NULL 2015-05-20 07:29:47 -04:00
Michael Santos
cf501f5fde Optionally disable XMPP pings 2015-05-19 08:03:02 -04:00
Michael Santos
fdab8a8901 Initial support for XEP-0198 stream management
Request stream management for the session by default. The rate of requests
and acks is controlled by the -I option. With stream management, the
client can check when all stanzas have been flushed to the server. For
example, the following works:

    cat /path/textfile | xmppipe -o transfer -r sender

    # on another system
    xmppipe -o transfer -r receiver > tmpfile

The behaviour is to always attempt enabling stream management. The XEP
is ambiguous about the response to an enable when stream management is
not offered. Presumably the server will respond with "failure".

So the code should probably have 2 checks:

* if stream management is offered as a feature, send an enable
* if the server responds with "enabled", handle requests
2015-05-18 09:27:47 -04:00
Michael Santos
a233caf32c Set default keepalive failure limit 2015-05-16 11:10:31 -04:00
Michael Santos
246c148d0e Track ping replies
Set a limit on the number of pings without a reply and exit if the limit
is reached. Useful for detecing broken network connections due to
network changes.

The default configuration will take about 4 minutes to detect failure
(1 keepalive every 60 seconds, tolerate 3 failures).
2015-05-16 10:58:20 -04:00
Michael Santos
4cbee9c78c Optionally specify server address/port 2015-05-16 09:54:35 -04:00
Michael Santos
c983814007 Exit on connection failure
No point shutting down nicely if the connection has failed: exit
immediately and print out an error.

The error is the same whether the connection has failed due to a DNS
lookup, TCP connection or authentication failure. Running in debug mode
can show the reason for failure. libstrophe has an enum indicating the
connection state; maybe this can be used for better error reporting.
2015-05-15 10:00:38 -04:00
Michael Santos
353951298e Generate a unique ID per message
Add a ID per message. Seems to fix the duplicate messages seen with MUCs
on the Conversations android client whenever the network is switched
(e.g., from wifi to cell).

Introduce a dependency on Linux's libuuid which introduces portability
issues. However, it should be simple to add support for the BSD UUID
interface.

libuuid was used because it is a fast and simple way of generating
a unique id.  Realistically, the ID only needs to be unique within
the MUC and so could probably be replaced with an sprintf() combining
time of day, PID and a random number.
2015-05-14 06:56:58 -04:00
Michael Santos
4325445536 Exit on presence errors
Force exiting on nick conflicts. xmppipe could generate a unique resource
(e.g., xmppipe-<pid>) but it prevents accidentally having two instances
running in a room.
2015-05-13 07:37:34 -04:00
Michael Santos
849507ad5d mucxxx -> muc_xxx; ERR -> XMPPIPE_ERR 2015-05-12 14:09:14 -04:00
Michael Santos
3d79e9fda8 Forward stdin over XMPP 2015-05-11 15:19:35 -04:00
Michael Santos
9a2d4b64ca Initial commit 2015-05-11 15:10:42 -04:00