* 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
|
||||
*
|
||||
* @category xmpphp
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
/**
|
||||
* XMPPHP Log
|
||||
*
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
* @version $Id$
|
||||
* @version $Id$
|
||||
*/
|
||||
class XMPPHP_Log {
|
||||
|
||||
const LEVEL_ERROR = 0;
|
||||
const LEVEL_WARNING = 1;
|
||||
const LEVEL_INFO = 2;
|
||||
const LEVEL_DEBUG = 3;
|
||||
const LEVEL_VERBOSE = 4;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
const LEVEL_ERROR = 0;
|
||||
const LEVEL_WARNING = 1;
|
||||
const LEVEL_INFO = 2;
|
||||
const LEVEL_DEBUG = 3;
|
||||
const LEVEL_VERBOSE = 4;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $names = array('ERROR', 'WARNING', 'INFO', 'DEBUG', 'VERBOSE');
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $names = array('ERROR', 'WARNING', 'INFO', 'DEBUG', 'VERBOSE');
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $runlevel;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $runlevel;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $printout;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $printout;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param boolean $printout
|
||||
* @param string $runlevel
|
||||
*/
|
||||
public function __construct($printout = false, $runlevel = self::LEVEL_INFO) {
|
||||
$this->printout = (boolean)$printout;
|
||||
$this->runlevel = (int)$runlevel;
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param boolean $printout
|
||||
* @param string $runlevel
|
||||
*/
|
||||
public function __construct($printout = false, $runlevel = self::LEVEL_INFO) {
|
||||
$this->printout = (boolean)$printout;
|
||||
$this->runlevel = (int)$runlevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a message to the log data array
|
||||
* If printout in this instance is set to true, directly output the message
|
||||
*
|
||||
* @param string $msg
|
||||
* @param integer $runlevel
|
||||
*/
|
||||
public function log($msg, $runlevel = self::LEVEL_INFO) {
|
||||
$time = time();
|
||||
$this->data[] = array($this->runlevel, $msg, $time);
|
||||
if($this->printout and $runlevel <= $this->runlevel) {
|
||||
$this->writeLine($msg, $runlevel, $time);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add a message to the log data array
|
||||
* If printout in this instance is set to true, directly output the message
|
||||
*
|
||||
* @param string $msg
|
||||
* @param integer $runlevel
|
||||
*/
|
||||
public function log($msg, $runlevel = self::LEVEL_INFO) {
|
||||
$time = time();
|
||||
$this->data[] = array($this->runlevel, $msg, $time);
|
||||
if($this->printout and $runlevel <= $this->runlevel) {
|
||||
$this->writeLine($msg, $runlevel, $time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the complete log.
|
||||
* Log will be cleared if $clear = true
|
||||
*
|
||||
* @param boolean $clear
|
||||
* @param integer $runlevel
|
||||
*/
|
||||
public function printout($clear = true, $runlevel = null) {
|
||||
if($runlevel === null) {
|
||||
$runlevel = $this->runlevel;
|
||||
}
|
||||
foreach($this->data as $data) {
|
||||
if($runlevel <= $data[0]) {
|
||||
$this->writeLine($data[1], $runlevel, $data[2]);
|
||||
}
|
||||
}
|
||||
if($clear) {
|
||||
$this->data = array();
|
||||
}
|
||||
}
|
||||
|
||||
protected function writeLine($msg, $runlevel, $time) {
|
||||
//echo date('Y-m-d H:i:s', $time)." [".$this->names[$runlevel]."]: ".$msg."\n";
|
||||
echo $time." [".$this->names[$runlevel]."]: ".$msg."\n";
|
||||
}
|
||||
/**
|
||||
* Output the complete log.
|
||||
* Log will be cleared if $clear = true
|
||||
*
|
||||
* @param boolean $clear
|
||||
* @param integer $runlevel
|
||||
*/
|
||||
public function printout($clear = true, $runlevel = null) {
|
||||
if($runlevel === null) {
|
||||
$runlevel = $this->runlevel;
|
||||
}
|
||||
foreach($this->data as $data) {
|
||||
if($runlevel <= $data[0]) {
|
||||
$this->writeLine($data[1], $runlevel, $data[2]);
|
||||
}
|
||||
}
|
||||
if($clear) {
|
||||
$this->data = array();
|
||||
}
|
||||
}
|
||||
|
||||
protected function writeLine($msg, $runlevel, $time) {
|
||||
//echo date('Y-m-d H:i:s', $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
|
||||
*
|
||||
* @category xmpphp
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
@ -29,127 +29,127 @@
|
||||
* XMPPHP XML Object
|
||||
*
|
||||
* @category xmpphp
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
* @version $Id$
|
||||
* @version $Id$
|
||||
*/
|
||||
class XMPPHP_XMLObj {
|
||||
/**
|
||||
* Tag name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Namespace
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ns;
|
||||
|
||||
/**
|
||||
* Attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $attrs = array();
|
||||
|
||||
/**
|
||||
* Subs?
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subs = array();
|
||||
|
||||
/**
|
||||
* Node data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $data = '';
|
||||
/**
|
||||
* Tag name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Namespace
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ns;
|
||||
|
||||
/**
|
||||
* Attributes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $attrs = array();
|
||||
|
||||
/**
|
||||
* Subs?
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $subs = array();
|
||||
|
||||
/**
|
||||
* Node data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $data = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $ns
|
||||
* @param array $attrs
|
||||
* @param string $data
|
||||
*/
|
||||
public function __construct($name, $ns = '', $attrs = array(), $data = '') {
|
||||
$this->name = strtolower($name);
|
||||
$this->ns = $ns;
|
||||
if(is_array($attrs) && count($attrs)) {
|
||||
foreach($attrs as $key => $value) {
|
||||
$this->attrs[strtolower($key)] = $value;
|
||||
}
|
||||
}
|
||||
$this->data = $data;
|
||||
}
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $ns
|
||||
* @param array $attrs
|
||||
* @param string $data
|
||||
*/
|
||||
public function __construct($name, $ns = '', $attrs = array(), $data = '') {
|
||||
$this->name = strtolower($name);
|
||||
$this->ns = $ns;
|
||||
if(is_array($attrs) && count($attrs)) {
|
||||
foreach($attrs as $key => $value) {
|
||||
$this->attrs[strtolower($key)] = $value;
|
||||
}
|
||||
}
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump this XML Object to output.
|
||||
*
|
||||
* @param integer $depth
|
||||
*/
|
||||
public function printObj($depth = 0) {
|
||||
print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
|
||||
print "\n";
|
||||
foreach($this->subs as $sub) {
|
||||
$sub->printObj($depth + 1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Dump this XML Object to output.
|
||||
*
|
||||
* @param integer $depth
|
||||
*/
|
||||
public function printObj($depth = 0) {
|
||||
print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data;
|
||||
print "\n";
|
||||
foreach($this->subs as $sub) {
|
||||
$sub->printObj($depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this XML Object in xml notation
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function toString($str = '') {
|
||||
$str .= "<{$this->name} xmlns='{$this->ns}' ";
|
||||
foreach($this->attrs as $key => $value) {
|
||||
if($key != 'xmlns') {
|
||||
$value = htmlspecialchars($value);
|
||||
$str .= "$key='$value' ";
|
||||
}
|
||||
}
|
||||
$str .= ">";
|
||||
foreach($this->subs as $sub) {
|
||||
$str .= $sub->toString();
|
||||
}
|
||||
$body = htmlspecialchars($this->data);
|
||||
$str .= "$body</{$this->name}>";
|
||||
return $str;
|
||||
}
|
||||
/**
|
||||
* Return this XML Object in xml notation
|
||||
*
|
||||
* @param string $str
|
||||
*/
|
||||
public function toString($str = '') {
|
||||
$str .= "<{$this->name} xmlns='{$this->ns}' ";
|
||||
foreach($this->attrs as $key => $value) {
|
||||
if($key != 'xmlns') {
|
||||
$value = htmlspecialchars($value);
|
||||
$str .= "$key='$value' ";
|
||||
}
|
||||
}
|
||||
$str .= ">";
|
||||
foreach($this->subs as $sub) {
|
||||
$str .= $sub->toString();
|
||||
}
|
||||
$body = htmlspecialchars($this->data);
|
||||
$str .= "$body</{$this->name}>";
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has this XML Object the given sub?
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasSub($name) {
|
||||
foreach($this->subs as $sub) {
|
||||
if($sub->name == $name) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Has this XML Object the given sub?
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasSub($name) {
|
||||
foreach($this->subs as $sub) {
|
||||
if($sub->name == $name) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a sub
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $attrs
|
||||
* @param string $ns
|
||||
*/
|
||||
public function sub($name, $attrs = null, $ns = null) {
|
||||
foreach($this->subs as $sub) {
|
||||
if($sub->name == $name) {
|
||||
return $sub;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return a sub
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $attrs
|
||||
* @param string $ns
|
||||
*/
|
||||
public function sub($name, $attrs = null, $ns = null) {
|
||||
foreach($this->subs as $sub) {
|
||||
if($sub->name == $name) {
|
||||
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
|
||||
*
|
||||
* @category xmpphp
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
@ -32,250 +32,250 @@ require_once "XMLStream.php";
|
||||
* XMPPHP Main Class
|
||||
*
|
||||
* @category xmpphp
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @package XMPPHP
|
||||
* @author Nathanael C. Fritz <JID: fritzy@netflint.net>
|
||||
* @author Stephan Wentz <JID: stephan@jabber.wentz.it>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
* @version $Id$
|
||||
* @version $Id$
|
||||
*/
|
||||
class XMPPHP_XMPP extends XMPPHP_XMLStream {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $server;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fulljid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $basejid;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $authed = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $auto_subscribe = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $use_encryption = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $host
|
||||
* @param integer $port
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $resource
|
||||
* @param string $server
|
||||
* @param boolean $printlog
|
||||
* @param string $loglevel
|
||||
*/
|
||||
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
|
||||
parent::__construct($host, $port, $printlog, $loglevel);
|
||||
|
||||
$this->user = $user;
|
||||
$this->password = $password;
|
||||
$this->resource = $resource;
|
||||
if(!$server) $server = $host;
|
||||
$this->basejid = $this->user . '@' . $this->host;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $fulljid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $basejid;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $authed = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $auto_subscribe = false;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $use_encryption = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $host
|
||||
* @param integer $port
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $resource
|
||||
* @param string $server
|
||||
* @param boolean $printlog
|
||||
* @param string $loglevel
|
||||
*/
|
||||
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
|
||||
parent::__construct($host, $port, $printlog, $loglevel);
|
||||
|
||||
$this->user = $user;
|
||||
$this->password = $password;
|
||||
$this->resource = $resource;
|
||||
if(!$server) $server = $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_end = '</stream:stream>';
|
||||
$this->default_ns = 'jabber:client';
|
||||
|
||||
$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('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('message', 'jabber:client', 'message_handler');
|
||||
$this->addHandler('presence', 'jabber:client', 'presence_handler');
|
||||
}
|
||||
$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->default_ns = 'jabber:client';
|
||||
|
||||
$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('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('message', 'jabber:client', 'message_handler');
|
||||
$this->addHandler('presence', 'jabber:client', 'presence_handler');
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn encryption on/ff
|
||||
*
|
||||
* @param boolean $useEncryption
|
||||
*/
|
||||
public function useEncryption($useEncryption = true) {
|
||||
$this->use_encryption = $useEncryption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on auto-authorization of subscription requests.
|
||||
*
|
||||
* @param boolean $autoSubscribe
|
||||
*/
|
||||
public function autoSubscribe($autoSubscribe = true) {
|
||||
$this->auto_subscribe = $autoSubscribe;
|
||||
}
|
||||
/**
|
||||
* Turn encryption on/ff
|
||||
*
|
||||
* @param boolean $useEncryption
|
||||
*/
|
||||
public function useEncryption($useEncryption = true) {
|
||||
$this->use_encryption = $useEncryption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn on auto-authorization of subscription requests.
|
||||
*
|
||||
* @param boolean $autoSubscribe
|
||||
*/
|
||||
public function autoSubscribe($autoSubscribe = true) {
|
||||
$this->auto_subscribe = $autoSubscribe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send XMPP Message
|
||||
*
|
||||
* @param string $to
|
||||
* @param string $body
|
||||
* @param string $type
|
||||
* @param string $subject
|
||||
*/
|
||||
public function message($to, $body, $type = 'chat', $subject = null) {
|
||||
$to = htmlspecialchars($to);
|
||||
$body = htmlspecialchars($body);
|
||||
$subject = htmlspecialchars($subject);
|
||||
|
||||
$out = "<message from='{$this->fulljid}' to='$to' type='$type'>";
|
||||
if($subject) $out .= "<subject>$subject</subject>";
|
||||
$out .= "<body>$body</body></message>";
|
||||
|
||||
$this->send($out);
|
||||
}
|
||||
/**
|
||||
* Send XMPP Message
|
||||
*
|
||||
* @param string $to
|
||||
* @param string $body
|
||||
* @param string $type
|
||||
* @param string $subject
|
||||
*/
|
||||
public function message($to, $body, $type = 'chat', $subject = null) {
|
||||
$to = htmlspecialchars($to);
|
||||
$body = htmlspecialchars($body);
|
||||
$subject = htmlspecialchars($subject);
|
||||
|
||||
$out = "<message from='{$this->fulljid}' to='$to' type='$type'>";
|
||||
if($subject) $out .= "<subject>$subject</subject>";
|
||||
$out .= "<body>$body</body></message>";
|
||||
|
||||
$this->send($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Presence
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $show
|
||||
* @param string $to
|
||||
*/
|
||||
public function presence($status = null, $show = 'available', $to = null) {
|
||||
$type = '';
|
||||
$to = htmlspecialchars($to);
|
||||
$status = htmlspecialchars($status);
|
||||
if($show == 'unavailable') $type = 'unavailable';
|
||||
|
||||
$out = "<presence";
|
||||
if($to) $out .= " to='$to'";
|
||||
if($type) $out .= " type='$type'";
|
||||
if($show == 'available' and !$status) {
|
||||
$out .= "/>";
|
||||
} else {
|
||||
$out .= ">";
|
||||
if($show != 'available') $out .= "<show>$show</show>";
|
||||
if($status) $out .= "<status>$status</status>";
|
||||
$out .= "</presence>";
|
||||
}
|
||||
|
||||
$this->send($out);
|
||||
}
|
||||
/**
|
||||
* Set Presence
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $show
|
||||
* @param string $to
|
||||
*/
|
||||
public function presence($status = null, $show = 'available', $to = null, $type='available') {
|
||||
if($type == 'available') $type = '';
|
||||
$to = htmlspecialchars($to);
|
||||
$status = htmlspecialchars($status);
|
||||
if($show == 'unavailable') $type = 'unavailable';
|
||||
|
||||
$out = "<presence";
|
||||
if($to) $out .= " to='$to'";
|
||||
if($type) $out .= " type='$type'";
|
||||
if($show == 'available' and !$status) {
|
||||
$out .= "/>";
|
||||
} else {
|
||||
$out .= ">";
|
||||
if($show != 'available') $out .= "<show>$show</show>";
|
||||
if($status) $out .= "<status>$status</status>";
|
||||
$out .= "</presence>";
|
||||
}
|
||||
|
||||
$this->send($out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Message handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
public function message_handler($xml) {
|
||||
if(isset($xml->attrs['type'])) {
|
||||
$payload['type'] = $xml->attrs['type'];
|
||||
} else {
|
||||
$payload['type'] = 'chat';
|
||||
}
|
||||
$payload['from'] = $xml->attrs['from'];
|
||||
$payload['body'] = $xml->sub('body')->data;
|
||||
$this->log->log("Message: {$xml->sub('body')->data}", XMPPHP_Log::LEVEL_DEBUG);
|
||||
$this->event('message', $payload);
|
||||
}
|
||||
/**
|
||||
* Message handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
public function message_handler($xml) {
|
||||
if(isset($xml->attrs['type'])) {
|
||||
$payload['type'] = $xml->attrs['type'];
|
||||
} else {
|
||||
$payload['type'] = 'chat';
|
||||
}
|
||||
$payload['from'] = $xml->attrs['from'];
|
||||
$payload['body'] = $xml->sub('body')->data;
|
||||
$this->log->log("Message: {$xml->sub('body')->data}", XMPPHP_Log::LEVEL_DEBUG);
|
||||
$this->event('message', $payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Presence handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
public function presence_handler($xml) {
|
||||
$payload['type'] = (isset($xml->attrs['type'])) ? $xml->attrs['type'] : 'available';
|
||||
$payload['show'] = (isset($xml->sub('show')->data)) ? $xml->sub('show')->data : $payload['type'];
|
||||
$payload['from'] = $xml->attrs['from'];
|
||||
$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);
|
||||
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}' />");
|
||||
$this->event('subscription_requested', $payload);
|
||||
} elseif($xml->attrs['type'] == 'subscribed') {
|
||||
$this->event('subscription_accepted', $payload);
|
||||
} else {
|
||||
$this->event('presence', $payload);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Presence handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
public function presence_handler($xml) {
|
||||
$payload['type'] = (isset($xml->attrs['type'])) ? $xml->attrs['type'] : 'available';
|
||||
$payload['show'] = (isset($xml->sub('show')->data)) ? $xml->sub('show')->data : $payload['type'];
|
||||
$payload['from'] = $xml->attrs['from'];
|
||||
$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);
|
||||
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}' />");
|
||||
$this->event('subscription_requested', $payload);
|
||||
} elseif($xml->attrs['type'] == 'subscribed') {
|
||||
$this->event('subscription_accepted', $payload);
|
||||
} else {
|
||||
$this->event('presence', $payload);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Features handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function features_handler($xml) {
|
||||
if($xml->hasSub('starttls') and $this->use_encryption) {
|
||||
$this->send("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required /></starttls>");
|
||||
} elseif($xml->hasSub('bind')) {
|
||||
$id = $this->getId();
|
||||
$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>");
|
||||
} else {
|
||||
$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>");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Features handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function features_handler($xml) {
|
||||
if($xml->hasSub('starttls') and $this->use_encryption) {
|
||||
$this->send("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required /></starttls>");
|
||||
} elseif($xml->hasSub('bind')) {
|
||||
$id = $this->getId();
|
||||
$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>");
|
||||
} else {
|
||||
$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>");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SASL success handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function sasl_success_handler($xml) {
|
||||
$this->log->log("Auth success!");
|
||||
$this->authed = true;
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* SASL feature handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function sasl_failure_handler($xml) {
|
||||
$this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR);
|
||||
$this->disconnect();
|
||||
|
||||
throw new XMPPHP_Exception('Auth failed!');
|
||||
}
|
||||
/**
|
||||
* SASL success handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function sasl_success_handler($xml) {
|
||||
$this->log->log("Auth success!");
|
||||
$this->authed = true;
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* SASL feature handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function sasl_failure_handler($xml) {
|
||||
$this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR);
|
||||
$this->disconnect();
|
||||
|
||||
throw new XMPPHP_Exception('Auth failed!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resource bind handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function resource_bind_handler($xml) {
|
||||
if($xml->attrs['type'] == 'result') {
|
||||
$this->log->log("Bound to " . $xml->sub('bind')->sub('jid')->data);
|
||||
$this->fulljid = $xml->sub('bind')->sub('jid')->data;
|
||||
}
|
||||
$id = $this->getId();
|
||||
$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>");
|
||||
}
|
||||
/**
|
||||
* Resource bind handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function resource_bind_handler($xml) {
|
||||
if($xml->attrs['type'] == 'result') {
|
||||
$this->log->log("Bound to " . $xml->sub('bind')->sub('jid')->data);
|
||||
$this->fulljid = $xml->sub('bind')->sub('jid')->data;
|
||||
}
|
||||
$id = $this->getId();
|
||||
$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>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the roster
|
||||
@ -296,24 +296,24 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream {
|
||||
// TODO: make this work
|
||||
}
|
||||
|
||||
/**
|
||||
* Session start handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function session_start_handler($xml) {
|
||||
$this->log->log("Session started");
|
||||
$this->event('session_start');
|
||||
}
|
||||
/**
|
||||
* Session start handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function session_start_handler($xml) {
|
||||
$this->log->log("Session started");
|
||||
$this->event('session_start');
|
||||
}
|
||||
|
||||
/**
|
||||
* TLS proceed handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function tls_proceed_handler($xml) {
|
||||
$this->log->log("Starting TLS encryption");
|
||||
stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
|
||||
$this->reset();
|
||||
}
|
||||
/**
|
||||
* TLS proceed handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function tls_proceed_handler($xml) {
|
||||
$this->log->log("Starting TLS encryption");
|
||||
stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
|
||||
$this->reset();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user