* changed indents back to tabs (ung)
* fixed several bugs in the issue list git-svn-id: svn://netflint.net/xmpphp@45 ef36c318-a008-4979-b6e8-6b496270793b
This commit is contained in:
parent
9793c80e60
commit
9bfd715564
158
XMPPHP/Log.php
158
XMPPHP/Log.php
@ -19,98 +19,98 @@
|
|||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
* @category xmpphp
|
* @category xmpphp
|
||||||
* @package XMPPHP
|
* @package XMPPHP
|
||||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||||
* @copyright 2008 Nathanael C. Fritz
|
* @copyright 2008 Nathanael C. Fritz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XMPPHP Log
|
* XMPPHP Log
|
||||||
*
|
*
|
||||||
* @package XMPPHP
|
* @package XMPPHP
|
||||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||||
* @copyright 2008 Nathanael C. Fritz
|
* @copyright 2008 Nathanael C. Fritz
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
class XMPPHP_Log {
|
class XMPPHP_Log {
|
||||||
|
|
||||||
const LEVEL_ERROR = 0;
|
const LEVEL_ERROR = 0;
|
||||||
const LEVEL_WARNING = 1;
|
const LEVEL_WARNING = 1;
|
||||||
const LEVEL_INFO = 2;
|
const LEVEL_INFO = 2;
|
||||||
const LEVEL_DEBUG = 3;
|
const LEVEL_DEBUG = 3;
|
||||||
const LEVEL_VERBOSE = 4;
|
const LEVEL_VERBOSE = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $data = array();
|
protected $data = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $names = array('ERROR', 'WARNING', 'INFO', 'DEBUG', 'VERBOSE');
|
protected $names = array('ERROR', 'WARNING', 'INFO', 'DEBUG', 'VERBOSE');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
protected $runlevel;
|
protected $runlevel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
protected $printout;
|
protected $printout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param boolean $printout
|
* @param boolean $printout
|
||||||
* @param string $runlevel
|
* @param string $runlevel
|
||||||
*/
|
*/
|
||||||
public function __construct($printout = false, $runlevel = self::LEVEL_INFO) {
|
public function __construct($printout = false, $runlevel = self::LEVEL_INFO) {
|
||||||
$this->printout = (boolean)$printout;
|
$this->printout = (boolean)$printout;
|
||||||
$this->runlevel = (int)$runlevel;
|
$this->runlevel = (int)$runlevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a message to the log data array
|
* Add a message to the log data array
|
||||||
* If printout in this instance is set to true, directly output the message
|
* If printout in this instance is set to true, directly output the message
|
||||||
*
|
*
|
||||||
* @param string $msg
|
* @param string $msg
|
||||||
* @param integer $runlevel
|
* @param integer $runlevel
|
||||||
*/
|
*/
|
||||||
public function log($msg, $runlevel = self::LEVEL_INFO) {
|
public function log($msg, $runlevel = self::LEVEL_INFO) {
|
||||||
$time = time();
|
$time = time();
|
||||||
$this->data[] = array($this->runlevel, $msg, $time);
|
$this->data[] = array($this->runlevel, $msg, $time);
|
||||||
if($this->printout and $runlevel <= $this->runlevel) {
|
if($this->printout and $runlevel <= $this->runlevel) {
|
||||||
$this->writeLine($msg, $runlevel, $time);
|
$this->writeLine($msg, $runlevel, $time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output the complete log.
|
* Output the complete log.
|
||||||
* Log will be cleared if $clear = true
|
* Log will be cleared if $clear = true
|
||||||
*
|
*
|
||||||
* @param boolean $clear
|
* @param boolean $clear
|
||||||
* @param integer $runlevel
|
* @param integer $runlevel
|
||||||
*/
|
*/
|
||||||
public function printout($clear = true, $runlevel = null) {
|
public function printout($clear = true, $runlevel = null) {
|
||||||
if($runlevel === null) {
|
if($runlevel === null) {
|
||||||
$runlevel = $this->runlevel;
|
$runlevel = $this->runlevel;
|
||||||
}
|
}
|
||||||
foreach($this->data as $data) {
|
foreach($this->data as $data) {
|
||||||
if($runlevel <= $data[0]) {
|
if($runlevel <= $data[0]) {
|
||||||
$this->writeLine($data[1], $runlevel, $data[2]);
|
$this->writeLine($data[1], $runlevel, $data[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($clear) {
|
if($clear) {
|
||||||
$this->data = array();
|
$this->data = array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
* @category xmpphp
|
* @category xmpphp
|
||||||
* @package XMPPHP
|
* @package XMPPHP
|
||||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||||
* @copyright 2008 Nathanael C. Fritz
|
* @copyright 2008 Nathanael C. Fritz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -29,127 +29,127 @@
|
|||||||
* XMPPHP XML Object
|
* XMPPHP XML Object
|
||||||
*
|
*
|
||||||
* @category xmpphp
|
* @category xmpphp
|
||||||
* @package XMPPHP
|
* @package XMPPHP
|
||||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||||
* @copyright 2008 Nathanael C. Fritz
|
* @copyright 2008 Nathanael C. Fritz
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
class XMPPHP_XMLObj {
|
class XMPPHP_XMLObj {
|
||||||
/**
|
/**
|
||||||
* Tag name
|
* Tag name
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $name;
|
public $name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Namespace
|
* Namespace
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $ns;
|
public $ns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attributes
|
* Attributes
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $attrs = array();
|
public $attrs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subs?
|
* Subs?
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $subs = array();
|
public $subs = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Node data
|
* Node data
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $data = '';
|
public $data = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $ns
|
* @param string $ns
|
||||||
* @param array $attrs
|
* @param array $attrs
|
||||||
* @param string $data
|
* @param string $data
|
||||||
*/
|
*/
|
||||||
public function __construct($name, $ns = '', $attrs = array(), $data = '') {
|
public function __construct($name, $ns = '', $attrs = array(), $data = '') {
|
||||||
$this->name = strtolower($name);
|
$this->name = strtolower($name);
|
||||||
$this->ns = $ns;
|
$this->ns = $ns;
|
||||||
if(is_array($attrs) && count($attrs)) {
|
if(is_array($attrs) && count($attrs)) {
|
||||||
foreach($attrs as $key => $value) {
|
foreach($attrs as $key => $value) {
|
||||||
$this->attrs[strtolower($key)] = $value;
|
$this->attrs[strtolower($key)] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dump this XML Object to output.
|
* Dump this XML Object to output.
|
||||||
*
|
*
|
||||||
* @param integer $depth
|
* @param integer $depth
|
||||||
*/
|
*/
|
||||||
public function printObj($depth = 0) {
|
public function printObj($depth = 0) {
|
||||||
print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
|
print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
|
||||||
print "\n";
|
print "\n";
|
||||||
foreach($this->subs as $sub) {
|
foreach($this->subs as $sub) {
|
||||||
$sub->printObj($depth + 1);
|
$sub->printObj($depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return this XML Object in xml notation
|
* Return this XML Object in xml notation
|
||||||
*
|
*
|
||||||
* @param string $str
|
* @param string $str
|
||||||
*/
|
*/
|
||||||
public function toString($str = '') {
|
public function toString($str = '') {
|
||||||
$str .= "<{$this->name} xmlns='{$this->ns}' ";
|
$str .= "<{$this->name} xmlns='{$this->ns}' ";
|
||||||
foreach($this->attrs as $key => $value) {
|
foreach($this->attrs as $key => $value) {
|
||||||
if($key != 'xmlns') {
|
if($key != 'xmlns') {
|
||||||
$value = htmlspecialchars($value);
|
$value = htmlspecialchars($value);
|
||||||
$str .= "$key='$value' ";
|
$str .= "$key='$value' ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$str .= ">";
|
$str .= ">";
|
||||||
foreach($this->subs as $sub) {
|
foreach($this->subs as $sub) {
|
||||||
$str .= $sub->toString();
|
$str .= $sub->toString();
|
||||||
}
|
}
|
||||||
$body = htmlspecialchars($this->data);
|
$body = htmlspecialchars($this->data);
|
||||||
$str .= "$body</{$this->name}>";
|
$str .= "$body</{$this->name}>";
|
||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Has this XML Object the given sub?
|
* Has this XML Object the given sub?
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function hasSub($name) {
|
public function hasSub($name) {
|
||||||
foreach($this->subs as $sub) {
|
foreach($this->subs as $sub) {
|
||||||
if($sub->name == $name) return true;
|
if($sub->name == $name) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a sub
|
* Return a sub
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param string $attrs
|
* @param string $attrs
|
||||||
* @param string $ns
|
* @param string $ns
|
||||||
*/
|
*/
|
||||||
public function sub($name, $attrs = null, $ns = null) {
|
public function sub($name, $attrs = null, $ns = null) {
|
||||||
foreach($this->subs as $sub) {
|
foreach($this->subs as $sub) {
|
||||||
if($sub->name == $name) {
|
if($sub->name == $name) {
|
||||||
return $sub;
|
return $sub;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1076
XMPPHP/XMLStream.php
1076
XMPPHP/XMLStream.php
File diff suppressed because it is too large
Load Diff
506
XMPPHP/XMPP.php
506
XMPPHP/XMPP.php
@ -19,9 +19,9 @@
|
|||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
* @category xmpphp
|
* @category xmpphp
|
||||||
* @package XMPPHP
|
* @package XMPPHP
|
||||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||||
* @copyright 2008 Nathanael C. Fritz
|
* @copyright 2008 Nathanael C. Fritz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -32,250 +32,250 @@ require_once "XMLStream.php";
|
|||||||
* XMPPHP Main Class
|
* XMPPHP Main Class
|
||||||
*
|
*
|
||||||
* @category xmpphp
|
* @category xmpphp
|
||||||
* @package XMPPHP
|
* @package XMPPHP
|
||||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||||
* @copyright 2008 Nathanael C. Fritz
|
* @copyright 2008 Nathanael C. Fritz
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
class XMPPHP_XMPP extends XMPPHP_XMLStream {
|
class XMPPHP_XMPP extends XMPPHP_XMLStream {
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $server;
|
protected $server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $password;
|
protected $password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $resource;
|
protected $resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $fulljid;
|
protected $fulljid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $basejid;
|
protected $basejid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
protected $authed = false;
|
protected $authed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
protected $auto_subscribe = false;
|
protected $auto_subscribe = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
protected $use_encryption = true;
|
protected $use_encryption = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param string $host
|
* @param string $host
|
||||||
* @param integer $port
|
* @param integer $port
|
||||||
* @param string $user
|
* @param string $user
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @param string $resource
|
* @param string $resource
|
||||||
* @param string $server
|
* @param string $server
|
||||||
* @param boolean $printlog
|
* @param boolean $printlog
|
||||||
* @param string $loglevel
|
* @param string $loglevel
|
||||||
*/
|
*/
|
||||||
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
|
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
|
||||||
parent::__construct($host, $port, $printlog, $loglevel);
|
parent::__construct($host, $port, $printlog, $loglevel);
|
||||||
|
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
$this->resource = $resource;
|
$this->resource = $resource;
|
||||||
if(!$server) $server = $host;
|
if(!$server) $server = $host;
|
||||||
$this->basejid = $this->user . '@' . $this->host;
|
$this->basejid = $this->user . '@' . $this->host;
|
||||||
|
|
||||||
$this->stream_start = '<stream:stream to="' . $server . '" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">';
|
$this->stream_start = '<stream:stream to="' . $server . '" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">';
|
||||||
$this->stream_end = '</stream:stream>';
|
$this->stream_end = '</stream:stream>';
|
||||||
$this->default_ns = 'jabber:client';
|
$this->default_ns = 'jabber:client';
|
||||||
|
|
||||||
$this->addHandler('features', 'http://etherx.jabber.org/streams', 'features_handler');
|
$this->addHandler('features', 'http://etherx.jabber.org/streams', 'features_handler');
|
||||||
$this->addHandler('success', 'urn:ietf:params:xml:ns:xmpp-sasl', 'sasl_success_handler');
|
$this->addHandler('success', 'urn:ietf:params:xml:ns:xmpp-sasl', 'sasl_success_handler');
|
||||||
$this->addHandler('failure', 'urn:ietf:params:xml:ns:xmpp-sasl', 'sasl_failure_handler');
|
$this->addHandler('failure', 'urn:ietf:params:xml:ns:xmpp-sasl', 'sasl_failure_handler');
|
||||||
$this->addHandler('proceed', 'urn:ietf:params:xml:ns:xmpp-tls', 'tls_proceed_handler');
|
$this->addHandler('proceed', 'urn:ietf:params:xml:ns:xmpp-tls', 'tls_proceed_handler');
|
||||||
$this->addHandler('message', 'jabber:client', 'message_handler');
|
$this->addHandler('message', 'jabber:client', 'message_handler');
|
||||||
$this->addHandler('presence', 'jabber:client', 'presence_handler');
|
$this->addHandler('presence', 'jabber:client', 'presence_handler');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn encryption on/ff
|
* Turn encryption on/ff
|
||||||
*
|
*
|
||||||
* @param boolean $useEncryption
|
* @param boolean $useEncryption
|
||||||
*/
|
*/
|
||||||
public function useEncryption($useEncryption = true) {
|
public function useEncryption($useEncryption = true) {
|
||||||
$this->use_encryption = $useEncryption;
|
$this->use_encryption = $useEncryption;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turn on auto-authorization of subscription requests.
|
* Turn on auto-authorization of subscription requests.
|
||||||
*
|
*
|
||||||
* @param boolean $autoSubscribe
|
* @param boolean $autoSubscribe
|
||||||
*/
|
*/
|
||||||
public function autoSubscribe($autoSubscribe = true) {
|
public function autoSubscribe($autoSubscribe = true) {
|
||||||
$this->auto_subscribe = $autoSubscribe;
|
$this->auto_subscribe = $autoSubscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send XMPP Message
|
* Send XMPP Message
|
||||||
*
|
*
|
||||||
* @param string $to
|
* @param string $to
|
||||||
* @param string $body
|
* @param string $body
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
*/
|
*/
|
||||||
public function message($to, $body, $type = 'chat', $subject = null) {
|
public function message($to, $body, $type = 'chat', $subject = null) {
|
||||||
$to = htmlspecialchars($to);
|
$to = htmlspecialchars($to);
|
||||||
$body = htmlspecialchars($body);
|
$body = htmlspecialchars($body);
|
||||||
$subject = htmlspecialchars($subject);
|
$subject = htmlspecialchars($subject);
|
||||||
|
|
||||||
$out = "<message from='{$this->fulljid}' to='$to' type='$type'>";
|
$out = "<message from='{$this->fulljid}' to='$to' type='$type'>";
|
||||||
if($subject) $out .= "<subject>$subject</subject>";
|
if($subject) $out .= "<subject>$subject</subject>";
|
||||||
$out .= "<body>$body</body></message>";
|
$out .= "<body>$body</body></message>";
|
||||||
|
|
||||||
$this->send($out);
|
$this->send($out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Presence
|
* Set Presence
|
||||||
*
|
*
|
||||||
* @param string $status
|
* @param string $status
|
||||||
* @param string $show
|
* @param string $show
|
||||||
* @param string $to
|
* @param string $to
|
||||||
*/
|
*/
|
||||||
public function presence($status = null, $show = 'available', $to = null) {
|
public function presence($status = null, $show = 'available', $to = null, $type='available') {
|
||||||
$type = '';
|
if($type == 'available') $type = '';
|
||||||
$to = htmlspecialchars($to);
|
$to = htmlspecialchars($to);
|
||||||
$status = htmlspecialchars($status);
|
$status = htmlspecialchars($status);
|
||||||
if($show == 'unavailable') $type = 'unavailable';
|
if($show == 'unavailable') $type = 'unavailable';
|
||||||
|
|
||||||
$out = "<presence";
|
$out = "<presence";
|
||||||
if($to) $out .= " to='$to'";
|
if($to) $out .= " to='$to'";
|
||||||
if($type) $out .= " type='$type'";
|
if($type) $out .= " type='$type'";
|
||||||
if($show == 'available' and !$status) {
|
if($show == 'available' and !$status) {
|
||||||
$out .= "/>";
|
$out .= "/>";
|
||||||
} else {
|
} else {
|
||||||
$out .= ">";
|
$out .= ">";
|
||||||
if($show != 'available') $out .= "<show>$show</show>";
|
if($show != 'available') $out .= "<show>$show</show>";
|
||||||
if($status) $out .= "<status>$status</status>";
|
if($status) $out .= "<status>$status</status>";
|
||||||
$out .= "</presence>";
|
$out .= "</presence>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->send($out);
|
$this->send($out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message handler
|
* Message handler
|
||||||
*
|
*
|
||||||
* @param string $xml
|
* @param string $xml
|
||||||
*/
|
*/
|
||||||
public function message_handler($xml) {
|
public function message_handler($xml) {
|
||||||
if(isset($xml->attrs['type'])) {
|
if(isset($xml->attrs['type'])) {
|
||||||
$payload['type'] = $xml->attrs['type'];
|
$payload['type'] = $xml->attrs['type'];
|
||||||
} else {
|
} else {
|
||||||
$payload['type'] = 'chat';
|
$payload['type'] = 'chat';
|
||||||
}
|
}
|
||||||
$payload['from'] = $xml->attrs['from'];
|
$payload['from'] = $xml->attrs['from'];
|
||||||
$payload['body'] = $xml->sub('body')->data;
|
$payload['body'] = $xml->sub('body')->data;
|
||||||
$this->log->log("Message: {$xml->sub('body')->data}", XMPPHP_Log::LEVEL_DEBUG);
|
$this->log->log("Message: {$xml->sub('body')->data}", XMPPHP_Log::LEVEL_DEBUG);
|
||||||
$this->event('message', $payload);
|
$this->event('message', $payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Presence handler
|
* Presence handler
|
||||||
*
|
*
|
||||||
* @param string $xml
|
* @param string $xml
|
||||||
*/
|
*/
|
||||||
public function presence_handler($xml) {
|
public function presence_handler($xml) {
|
||||||
$payload['type'] = (isset($xml->attrs['type'])) ? $xml->attrs['type'] : 'available';
|
$payload['type'] = (isset($xml->attrs['type'])) ? $xml->attrs['type'] : 'available';
|
||||||
$payload['show'] = (isset($xml->sub('show')->data)) ? $xml->sub('show')->data : $payload['type'];
|
$payload['show'] = (isset($xml->sub('show')->data)) ? $xml->sub('show')->data : $payload['type'];
|
||||||
$payload['from'] = $xml->attrs['from'];
|
$payload['from'] = $xml->attrs['from'];
|
||||||
$payload['status'] = (isset($xml->sub('status')->data)) ? $xml->sub('status')->data : '';
|
$payload['status'] = (isset($xml->sub('status')->data)) ? $xml->sub('status')->data : '';
|
||||||
$this->log->log("Presence: {$payload['from']} [{$payload['show']}] {$payload['status']}", XMPPHP_Log::LEVEL_DEBUG);
|
$this->log->log("Presence: {$payload['from']} [{$payload['show']}] {$payload['status']}", XMPPHP_Log::LEVEL_DEBUG);
|
||||||
if($xml->attrs['type'] == 'subscribe') {
|
if($xml->attrs['type'] == 'subscribe') {
|
||||||
if($this->auto_subscribe) $this->send("<presence type='subscribed' to='{$xml->attrs['from']}' from='{$this->fulljid}' /><presence type='subscribe' to='{$xml->attrs['from']}' from='{$this->fulljid}' />");
|
if($this->auto_subscribe) $this->send("<presence type='subscribed' to='{$xml->attrs['from']}' from='{$this->fulljid}' /><presence type='subscribe' to='{$xml->attrs['from']}' from='{$this->fulljid}' />");
|
||||||
$this->event('subscription_requested', $payload);
|
$this->event('subscription_requested', $payload);
|
||||||
} elseif($xml->attrs['type'] == 'subscribed') {
|
} elseif($xml->attrs['type'] == 'subscribed') {
|
||||||
$this->event('subscription_accepted', $payload);
|
$this->event('subscription_accepted', $payload);
|
||||||
} else {
|
} else {
|
||||||
$this->event('presence', $payload);
|
$this->event('presence', $payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Features handler
|
* Features handler
|
||||||
*
|
*
|
||||||
* @param string $xml
|
* @param string $xml
|
||||||
*/
|
*/
|
||||||
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')) {
|
||||||
$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>");
|
||||||
} else {
|
} else {
|
||||||
$this->log->log("Attempting Auth...");
|
$this->log->log("Attempting Auth...");
|
||||||
$this->send("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>" . base64_encode("\x00" . $this->user . "\x00" . $this->password) . "</auth>");
|
$this->send("<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>" . base64_encode("\x00" . $this->user . "\x00" . $this->password) . "</auth>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SASL success handler
|
* SASL success handler
|
||||||
*
|
*
|
||||||
* @param string $xml
|
* @param string $xml
|
||||||
*/
|
*/
|
||||||
protected function sasl_success_handler($xml) {
|
protected function sasl_success_handler($xml) {
|
||||||
$this->log->log("Auth success!");
|
$this->log->log("Auth success!");
|
||||||
$this->authed = true;
|
$this->authed = true;
|
||||||
$this->reset();
|
$this->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SASL feature handler
|
* SASL feature handler
|
||||||
*
|
*
|
||||||
* @param string $xml
|
* @param string $xml
|
||||||
*/
|
*/
|
||||||
protected function sasl_failure_handler($xml) {
|
protected function sasl_failure_handler($xml) {
|
||||||
$this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR);
|
$this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR);
|
||||||
$this->disconnect();
|
$this->disconnect();
|
||||||
|
|
||||||
throw new XMPPHP_Exception('Auth failed!');
|
throw new XMPPHP_Exception('Auth failed!');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resource bind handler
|
* Resource bind handler
|
||||||
*
|
*
|
||||||
* @param string $xml
|
* @param string $xml
|
||||||
*/
|
*/
|
||||||
protected function resource_bind_handler($xml) {
|
protected function resource_bind_handler($xml) {
|
||||||
if($xml->attrs['type'] == 'result') {
|
if($xml->attrs['type'] == 'result') {
|
||||||
$this->log->log("Bound to " . $xml->sub('bind')->sub('jid')->data);
|
$this->log->log("Bound to " . $xml->sub('bind')->sub('jid')->data);
|
||||||
$this->fulljid = $xml->sub('bind')->sub('jid')->data;
|
$this->fulljid = $xml->sub('bind')->sub('jid')->data;
|
||||||
}
|
}
|
||||||
$id = $this->getId();
|
$id = $this->getId();
|
||||||
$this->addIdHandler($id, 'session_start_handler');
|
$this->addIdHandler($id, 'session_start_handler');
|
||||||
$this->send("<iq xmlns='jabber:client' type='set' id='$id'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>");
|
$this->send("<iq xmlns='jabber:client' type='set' id='$id'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the roster
|
* Retrieves the roster
|
||||||
@ -296,24 +296,24 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream {
|
|||||||
// TODO: make this work
|
// TODO: make this work
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session start handler
|
* Session start handler
|
||||||
*
|
*
|
||||||
* @param string $xml
|
* @param string $xml
|
||||||
*/
|
*/
|
||||||
protected function session_start_handler($xml) {
|
protected function session_start_handler($xml) {
|
||||||
$this->log->log("Session started");
|
$this->log->log("Session started");
|
||||||
$this->event('session_start');
|
$this->event('session_start');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TLS proceed handler
|
* TLS proceed handler
|
||||||
*
|
*
|
||||||
* @param string $xml
|
* @param string $xml
|
||||||
*/
|
*/
|
||||||
protected function tls_proceed_handler($xml) {
|
protected function tls_proceed_handler($xml) {
|
||||||
$this->log->log("Starting TLS encryption");
|
$this->log->log("Starting TLS encryption");
|
||||||
stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
|
stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
|
||||||
$this->reset();
|
$this->reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user