Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been able to reproduce the problem. If you add a debug line to print out the text returned by fread(), you will see that a response from the server is getting split into two pieces:</p> <p>Piece 1: <code>&lt;</code></p> <p>Piece 2: <code>challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'&gt;dmVyc2lvbj0xJm1ldGhvZD1hdXRoLnxmwHBfbG2naW4mbm9uY2U9RDI5Qjc1QUZIRORCRkUzOUE5NzYwQ0U5QkNFOUIzREM=&lt;/challenge&gt;</code></p> <p>I assume this is because the TCP packets are fragmented, but I haven't checked.</p> <p>One way to deal with this is to modify recv_xml() so that it keeps reading more information until the XML parse returns non-empty data:</p> <pre><code>function recv_xml($fp, $size=4096) { $xml = fread($fp, $size); if ($xml === "") { return null; } // parses xml $xml_parser = xml_parser_create(); xml_parse_into_struct($xml_parser, $xml, $val, $index); xml_parser_free($xml_parser); while (count($val) == 0) { // The parse failed. We probably got a partial packet. Read more $xml .= fread($fp, $size); // Have to create a new parser each time the XML changes. $xml_parser = xml_parser_create(); xml_parse_into_struct($xml_parser, $xml, $val, $index); xml_parser_free($xml_parser); } return array($val, $index); } </code></pre> <p>Edward Komissarov's answer should also fix the problem, since he directly adds that missing angular bracket. The code I have provided should work even if the split happens somewhere else.</p> <p>It's worth recognizing that the overall code is still quite brittle; it appears to be a proof of concept and not production-ready.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload