* BOSH and Stream Handling Fixes

git-svn-id: svn://netflint.net/xmpphp@57 ef36c318-a008-4979-b6e8-6b496270793b
This commit is contained in:
fritzy 2008-09-21 21:30:00 +00:00
parent f1b4f5b175
commit 02a3f3dc5d
3 changed files with 18 additions and 13 deletions

View File

@ -51,7 +51,7 @@ class XMPPHP_BOSH extends XMPPHP_XMPP {
$this->use_encryption = false; $this->use_encryption = false;
$this->session = $session; $this->session = $session;
$this->rid = 0; $this->rid = 3001;
$this->sid = null; $this->sid = null;
if($session) if($session)
{ {
@ -86,8 +86,11 @@ class XMPPHP_BOSH extends XMPPHP_XMPP {
$ch = curl_init($this->http_server); $ch = curl_init($this->http_server);
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); curl_setopt($ch, CURLOPT_POSTFIELDS, $body->asXML());
curl_setopt ($ch, CURLOPT_POSTFIELDS, Array('upfile' => $body->asXML())); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$header = array('Accept-Encoding: gzip, deflate','Content-Type: text/xml; charset=utf-8');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$output = ''; $output = '';
if($recv) { if($recv) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@ -130,12 +133,14 @@ class XMPPHP_BOSH extends XMPPHP_XMPP {
$idx = key($this->http_buffer); $idx = key($this->http_buffer);
$buffer = $this->http_buffer[$idx]; $buffer = $this->http_buffer[$idx];
unset($this->http_buffer[$idx]); unset($this->http_buffer[$idx]);
$xml = new SimpleXMLElement($buffer); if($buffer) {
$children = $xml->xpath('child::node()'); $xml = new SimpleXMLElement($buffer);
foreach ($children as $child) { $children = $xml->xpath('child::node()');
$buff = $child->asXML(); foreach ($children as $child) {
$this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE); $buff = $child->asXML();
xml_parse($this->parser, $buff, false); $this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE);
xml_parse($this->parser, $buff, false);
}
} }
} }
} }
@ -164,7 +169,7 @@ class XMPPHP_BOSH extends XMPPHP_XMPP {
} }
public function loadSession() { public function loadSession() {
if(is_array($_SESSION['XMPPHP_BOSH'])) { if(isset($_SESSION['XMPPHP_BOSH']) and is_array($_SESSION['XMPPHP_BOSH'])) {
foreach($_SESSION['XMPPHP_BOSH'] as $key => $value) { foreach($_SESSION['XMPPHP_BOSH'] as $key => $value) {
#print "Loading $key as $value<br/>"; #print "Loading $key as $value<br/>";
$this->$key = $value; $this->$key = $value;
@ -175,7 +180,7 @@ class XMPPHP_BOSH extends XMPPHP_XMPP {
public function saveSession() { public function saveSession() {
$_SESSION['XMPPHP_BOSH'] = Array(); $_SESSION['XMPPHP_BOSH'] = Array();
#$variables = Array('server', 'user', 'password', 'resource', 'fulljid', 'basejid', 'authed', 'session_started', 'auto_subscribe', 'use_encryption', 'host', 'port', 'stream_start', 'stream_end', 'disconnected', 'sent_disconnected', 'ns_map', 'current_ns', 'lastid', 'default_ns', 'been_reset', 'last_send', 'use_ssl', 'rid', 'sid', 'http_server','http_buffer', 'xml_depth'); #$variables = Array('server', 'user', 'password', 'resource', 'fulljid', 'basejid', 'authed', 'session_started', 'auto_subscribe', 'use_encryption', 'host', 'port', 'stream_start', 'stream_end', 'disconnected', 'sent_disconnected', 'ns_map', 'current_ns', 'lastid', 'default_ns', 'been_reset', 'last_send', 'use_ssl', 'rid', 'sid', 'http_server','http_buffer', 'xml_depth');
$variables = Array('rid', 'sid'); $variables = Array('rid', 'sid', 'authed');
foreach ($variables as $key) { foreach ($variables as $key) {
#print "Saving $key as {$this->$key}<br/>"; #print "Saving $key as {$this->$key}<br/>";
flush(); flush();

View File

@ -374,7 +374,7 @@ class XMPPHP_XMLStream {
end($this->until); end($this->until);
$event_key = key($this->until); $event_key = key($this->until);
reset($this->until); reset($this->until);
$until_count[$event_key] = 0; $this->until_count[$event_key] = 0;
$updated = ''; $updated = '';
while(!$this->disconnected and $this->until_count[$event_key] < 1 and (time() - $start < $timeout or $timeout == -1)) { while(!$this->disconnected and $this->until_count[$event_key] < 1 and (time() - $start < $timeout or $timeout == -1)) {
$this->__process(); $this->__process();

View File

@ -240,7 +240,7 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream {
protected function features_handler($xml) { protected function features_handler($xml) {
if($xml->hasSub('starttls') and $this->use_encryption) { if($xml->hasSub('starttls') and $this->use_encryption) {
$this->send("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required /></starttls>"); $this->send("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required /></starttls>");
} elseif($xml->hasSub('bind')) { } elseif($xml->hasSub('bind') and $this->authed) {
$id = $this->getId(); $id = $this->getId();
$this->addIdHandler($id, 'resource_bind_handler'); $this->addIdHandler($id, 'resource_bind_handler');
$this->send("<iq xmlns=\"jabber:client\" type=\"set\" id=\"$id\"><bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"><resource>{$this->resource}</resource></bind></iq>"); $this->send("<iq xmlns=\"jabber:client\" type=\"set\" id=\"$id\"><bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"><resource>{$this->resource}</resource></bind></iq>");