* BOSH fixes
git-svn-id: svn://netflint.net/xmpphp@56 ef36c318-a008-4979-b6e8-6b496270793b
This commit is contained in:
parent
34048957e0
commit
f1b4f5b175
@ -55,11 +55,9 @@ class XMPPHP_BOSH extends XMPPHP_XMPP {
|
|||||||
$this->sid = null;
|
$this->sid = null;
|
||||||
if($session)
|
if($session)
|
||||||
{
|
{
|
||||||
print "loading session...";
|
|
||||||
$this->loadSession();
|
$this->loadSession();
|
||||||
}
|
}
|
||||||
if(!$this->sid) {
|
if(!$this->sid) {
|
||||||
print "loading...";
|
|
||||||
$body = $this->__buildBody();
|
$body = $this->__buildBody();
|
||||||
$body->addAttribute('hold','1');
|
$body->addAttribute('hold','1');
|
||||||
$body->addAttribute('to', $this->host);
|
$body->addAttribute('to', $this->host);
|
||||||
@ -74,6 +72,10 @@ class XMPPHP_BOSH extends XMPPHP_XMPP {
|
|||||||
$response = $this->__sendBody($body);
|
$response = $this->__sendBody($body);
|
||||||
$rxml = new SimpleXMLElement($response);
|
$rxml = new SimpleXMLElement($response);
|
||||||
$this->sid = $rxml['sid'];
|
$this->sid = $rxml['sid'];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$buff = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>";
|
||||||
|
xml_parse($this->parser, $buff, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,15 +164,22 @@ class XMPPHP_BOSH extends XMPPHP_XMPP {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function loadSession() {
|
public function loadSession() {
|
||||||
foreach($_SESSION['XMPPHP_BOSH'] as $key => $value) {
|
if(is_array($_SESSION['XMPPHP_BOSH'])) {
|
||||||
$this[$key] = $value;
|
foreach($_SESSION['XMPPHP_BOSH'] as $key => $value) {
|
||||||
|
#print "Loading $key as $value<br/>";
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveSession() {
|
public function saveSession() {
|
||||||
$_SESSION['XMPPHP_BOSH'] = Array();
|
$_SESSION['XMPPHP_BOSH'] = Array();
|
||||||
foreach ($this as $key => $value) {
|
#$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');
|
||||||
$_SESSION['XMPPHP_BOSH'][$key] = $value;
|
$variables = Array('rid', 'sid');
|
||||||
|
foreach ($variables as $key) {
|
||||||
|
#print "Saving $key as {$this->$key}<br/>";
|
||||||
|
flush();
|
||||||
|
$_SESSION['XMPPHP_BOSH'][$key] = (string) $this->$key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,5 +112,6 @@ class XMPPHP_Log {
|
|||||||
protected function writeLine($msg, $runlevel, $time) {
|
protected function writeLine($msg, $runlevel, $time) {
|
||||||
//echo date('Y-m-d H:i:s', $time)." [".$this->names[$runlevel]."]: ".$msg."\n";
|
//echo date('Y-m-d H:i:s', $time)." [".$this->names[$runlevel]."]: ".$msg."\n";
|
||||||
echo $time." [".$this->names[$runlevel]."]: ".$msg."\n";
|
echo $time." [".$this->names[$runlevel]."]: ".$msg."\n";
|
||||||
|
flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,56 @@
|
|||||||
<?php
|
<?php
|
||||||
#example coming soon
|
session_start();
|
||||||
|
header('content-type', 'plain/text');
|
||||||
|
// activate full error reporting
|
||||||
|
//error_reporting(E_ALL & E_STRICT);
|
||||||
|
|
||||||
|
include 'XMPPHP/BOSH.php';
|
||||||
|
print "<pre>";
|
||||||
|
|
||||||
|
#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
|
||||||
|
#If this doesn't work, are you running 64-bit PHP with < 5.2.6?
|
||||||
|
$conn = new XMPPHP_BOSH('server.tld', 5280, 'user', 'password', 'xmpphp', 'server.tld', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_INFO);
|
||||||
|
$conn->autoSubscribe();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(isset($_SESSION['messages'])) {
|
||||||
|
foreach($_SESSION['messages'] as $msg) {
|
||||||
|
print $msg;
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$conn->connect('http://server.tld:5280/xmpp-httpbind', 1, true);
|
||||||
|
#while(true) {
|
||||||
|
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'));
|
||||||
|
foreach($payloads as $event) {
|
||||||
|
$pl = $event[1];
|
||||||
|
switch($event[0]) {
|
||||||
|
case 'message':
|
||||||
|
if(!isset($_SESSION['messages'])) $_SESSION['message'] = Array();
|
||||||
|
$msg = "---------------------------------------------------------------------------------\n{$pl['from']}: {$pl['body']}\n";
|
||||||
|
print $msg;
|
||||||
|
$_SESSION['messages'][] = $msg;
|
||||||
|
flush();
|
||||||
|
$conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);
|
||||||
|
if($pl['body'] == 'quit') $conn->disconnect();
|
||||||
|
if($pl['body'] == 'break') $conn->send("</end>");
|
||||||
|
break;
|
||||||
|
case 'presence':
|
||||||
|
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
|
||||||
|
break;
|
||||||
|
case 'session_start':
|
||||||
|
print "Session Start\n";
|
||||||
|
$conn->getRoster();
|
||||||
|
$conn->presence($status="Cheese!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#}
|
||||||
|
} catch(XMPPHP_Exception $e) {
|
||||||
|
die($e->getMessage());
|
||||||
|
}
|
||||||
|
$conn->saveSession();
|
||||||
|
|
||||||
|
print "</pre>";
|
||||||
|
print "<img src='http://xmpp.org/images/xmpp.png' onload='window.location.reload()' />";
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user