bmk10 / xmpphp

Automatically exported from code.google.com/p/xmpphp
0 stars 0 forks source link

Received stream processing stops if the first packet from the server has only the <stream:stream /> tag #102

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
Repeatedly run the following sequence against an Openfire server using a 
localhost connection on the same machine. The problem is intermittent, 
depending on how the server responds, but the failure occurs every time the 
condition is met.

if (!empty($xmpp_password)) {
    $conn = new XMPPHP_XMPP($xmpp_server, $xmpp_port, $xmpp_user, $xmpp_password, 'xmpphp', $xmpp_resource, $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE);
    $conn->useEncryption(true);

        try {

        $conn->connect();
        $conn->processUntil('session_start');
        $conn->presence();
        $conn->message($xmpp_rcpt, $message);   
        $conn->presence($type='unavailable');
        $conn->disconnect();

    } catch(XMPPHP_Exception $e) {
        die($e->getMessage());
    }
}
2.

Run wireshark and monitor the "lo" loopback interface with the display filter 
set to "jabber". This confirms the packet relationship.

3.

What is the expected output? What do you see instead?

The message goes through if the first response from the server includes the 
stream:features tag:

[root@boser cgi-bin]# ./proc_event.sh /var/www/html/zm/events/63/233
[root@boser cgi-bin]# 1292106662 [INFO]: Connecting to tcp://127.0.0.1:5222
1292106662 [VERBOSE]: Socket is ready; send it.
1292106662 [VERBOSE]: SENT: <stream:stream to="boser" 
xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" 
version="1.0">
1292106662 [VERBOSE]: Successfully sent 110 bytes.
1292106662 [VERBOSE]: RECV: <?xml version='1.0' 
encoding='UTF-8'?><stream:stream 
xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" 
from="netprop1.no-ip.info" id="2358abe0" xml:lang="en" 
version="1.0"><stream:features><mechanisms 
xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mecha
nism>JIVE-SHAREDSECRET</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMO
US</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression 
xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><
auth xmlns="http://jabber.org/features/iq-auth"/><register 
xmlns="http://jabber.org/features/iq-register"/></stream:features>
1292106662 [DEBUG]: Ending MECHANISM
MECHANISM .....etc

The message does not go through if the first response is only the first tag 
even though the stream:features tag follows right after.

[root@boser cgi-bin]# ./proc_event.sh /var/www/html/zm/events/63/233
[root@boser cgi-bin]# 1292107121 [INFO]: Connecting to tcp://127.0.0.1:5222
1292107121 [VERBOSE]: Socket is ready; send it.
1292107121 [VERBOSE]: SENT: <stream:stream to="boser" 
xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" 
version="1.0">
1292107121 [VERBOSE]: Successfully sent 110 bytes.
1292107121 [VERBOSE]: RECV: <?xml version='1.0' 
encoding='UTF-8'?><stream:stream 
xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" 
from="netprop1.no-ip.info" id="29e6e2d4" xml:lang="en" version="1.0">
1292107121 [VERBOSE]: RECV: <stream:features><mechanisms 
xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mecha
nism>JIVE-SHAREDSECRET</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMO
US</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression 
xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><
auth xmlns="http://jabber.org/features/iq-auth"/><register 
xmlns="http://jabber.org/features/iq-register"/></stream:features> ....STOPS 
HERE

What version of the product are you using? On what operating system?

https://github.com/cweiske/xmpphp.git May 30, 2010
Openfire Version: 3.7.0 Beta 
CentOS 5.5 32bit OS

Please provide any additional information below.

Original issue reported on code.google.com by hewmor...@yahoo.com on 11 Dec 2010 at 11:09

GoogleCodeExporter commented 9 years ago
I dug a bit into the code and found function "bufferComplete($buff)". I can fix 
my problem if I modify it to wait for the first complete tag at the beginning 
of the stream (See below). Just as a test, I hardcoded it - if this really is 
the problem/fix it needs to be made generic so it can handle any first tag.

protected function bufferComplete($buff)
    {
        if (substr($buff, -1) != '>') {
            return false;
        }
        //we always have a space since the namespace needs to be
        //declared. could be a tab, though
        $start = substr($buff, 1, strpos($buff, ' ', 2) - 1);
        $stop  = substr($buff, -strlen($start) - 3);

// Hardcoding the start of the steam to include the first complete tag -
// Test only - Not a generic solution
        $fstop = substr($buff, -strlen("stream:features") - 3);

        if ($start == '?xml') {

            if ('</' . "stream:features" . '>' == $fstop) {
            return true;
            }
        }
        if (substr($stop, -2) == '/>') {
            //one tag, i.e. <success />
            return true;
        }
        if ('</' . $start . '>' == $stop) {
            return true;
        }

        return false;
    }

Original comment by hewmor...@yahoo.com on 12 Dec 2010 at 1:01