mirror of
https://github.com/moodle/moodle.git
synced 2025-08-03 16:13:28 +02:00
MDL-16500 Removed the old Jabber class from the module and moved to a new one called xmpphp in core libraries
Also cleaned up some notices in message/edit.php
This commit is contained in:
parent
fa7bec7bef
commit
838a8eb146
17 changed files with 1378 additions and 3391 deletions
39
lib/jabber/XMPP/Exception.php
Executable file
39
lib/jabber/XMPP/Exception.php
Executable file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* XMPPHP: The PHP XMPP Library
|
||||
* Copyright (C) 2008 Nathanael C. Fritz
|
||||
* This file is part of SleekXMPP.
|
||||
*
|
||||
* XMPPHP is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* XMPPHP is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with XMPPHP; if not, write to the Free Software
|
||||
* 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>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
/**
|
||||
* XMPPHP Exception
|
||||
*
|
||||
* @category xmpphp
|
||||
* @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$
|
||||
*/
|
||||
class XMPPHP_Exception extends Exception {
|
||||
}
|
116
lib/jabber/XMPP/Log.php
Normal file
116
lib/jabber/XMPP/Log.php
Normal file
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/**
|
||||
* XMPPHP: The PHP XMPP Library
|
||||
* Copyright (C) 2008 Nathanael C. Fritz
|
||||
* This file is part of SleekXMPP.
|
||||
*
|
||||
* XMPPHP is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* XMPPHP is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with XMPPHP; if not, write to the Free Software
|
||||
* 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>
|
||||
* @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>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
* @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();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $names = array('ERROR', 'WARNING', 'INFO', 'DEBUG', 'VERBOSE');
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $runlevel;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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";
|
||||
}
|
||||
}
|
155
lib/jabber/XMPP/XMLObj.php
Normal file
155
lib/jabber/XMPP/XMLObj.php
Normal file
|
@ -0,0 +1,155 @@
|
|||
<?php
|
||||
/**
|
||||
* XMPPHP: The PHP XMPP Library
|
||||
* Copyright (C) 2008 Nathanael C. Fritz
|
||||
* This file is part of SleekXMPP.
|
||||
*
|
||||
* XMPPHP is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* XMPPHP is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with XMPPHP; if not, write to the Free Software
|
||||
* 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>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
/**
|
||||
* XMPPHP XML Object
|
||||
*
|
||||
* @category xmpphp
|
||||
* @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$
|
||||
*/
|
||||
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 = '';
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
604
lib/jabber/XMPP/XMLStream.php
Normal file
604
lib/jabber/XMPP/XMLStream.php
Normal file
|
@ -0,0 +1,604 @@
|
|||
<?php
|
||||
/**
|
||||
* XMPPHP: The PHP XMPP Library
|
||||
* Copyright (C) 2008 Nathanael C. Fritz
|
||||
* This file is part of SleekXMPP.
|
||||
*
|
||||
* XMPPHP is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* XMPPHP is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with XMPPHP; if not, write to the Free Software
|
||||
* 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>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
/** XMPPHP_Exception */
|
||||
require_once 'Exception.php';
|
||||
|
||||
/** XMPPHP_XMLObj */
|
||||
require_once 'XMLObj.php';
|
||||
|
||||
/** XMPPHP_Log */
|
||||
require_once 'Log.php';
|
||||
|
||||
/**
|
||||
* XMPPHP XML Stream
|
||||
*
|
||||
* @category xmpphp
|
||||
* @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$
|
||||
*/
|
||||
class XMPPHP_XMLStream {
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $socket;
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
protected $parser;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $buffer;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $xml_depth = 0;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $host;
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $port;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $stream_start = '<stream>';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $stream_end = '</stream>';
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $disconnected = false;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $sent_disconnect = false;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $ns_map = array();
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $current_ns = array();
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $xmlobj = null;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $nshandlers = array();
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $idhandlers = array();
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $eventhandlers = array();
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $lastid = 0;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $default_ns;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $until = '';
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $until_happened = false;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $until_payload = array();
|
||||
/**
|
||||
* @var XMPPHP_Log
|
||||
*/
|
||||
protected $log;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $reconnect = true;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $been_reset = false;
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
protected $is_server;
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $last_send = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $host
|
||||
* @param string $port
|
||||
* @param boolean $printlog
|
||||
* @param string $loglevel
|
||||
* @param boolean $is_server
|
||||
*/
|
||||
public function __construct($host = null, $port = null, $printlog = false, $loglevel = null, $is_server = false) {
|
||||
$this->reconnect = !$is_server;
|
||||
$this->is_server = $is_server;
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->setupParser();
|
||||
$this->log = new XMPPHP_Log($printlog, $loglevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* Cleanup connection
|
||||
*/
|
||||
public function __destruct() {
|
||||
if(!$this->disconnected && $this->socket) {
|
||||
$this->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the log instance
|
||||
*
|
||||
* @return XMPPHP_Log
|
||||
*/
|
||||
public function getLog() {
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next ID
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId() {
|
||||
$this->lastid++;
|
||||
return $this->lastid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add ID Handler
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $pointer
|
||||
* @param string $obj
|
||||
*/
|
||||
public function addIdHandler($id, $pointer, $obj = null) {
|
||||
$this->idhandlers[$id] = array($pointer, $obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Handler
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $ns
|
||||
* @param string $pointer
|
||||
* @param string $obj
|
||||
* @param integer $depth
|
||||
*/
|
||||
public function addHandler($name, $ns, $pointer, $obj = null, $depth = 1) {
|
||||
$this->nshandlers[] = array($name,$ns,$pointer,$obj, $depth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Evemt Handler
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $pointer
|
||||
* @param string $obj
|
||||
*/
|
||||
public function addEventHandler($name, $pointer, $obj) {
|
||||
$this->eventhanders[] = array($name, $pointer, $obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to XMPP Host
|
||||
*
|
||||
* @param integer $timeout
|
||||
* @param boolean $persistent
|
||||
* @param boolean $sendinit
|
||||
*/
|
||||
public function connect($timeout = 30, $persistent = false, $sendinit = true) {
|
||||
$this->disconnected = false;
|
||||
$this->sent_disconnect = false;
|
||||
if($persistent) {
|
||||
$conflag = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
|
||||
} else {
|
||||
$conflag = STREAM_CLIENT_CONNECT;
|
||||
}
|
||||
$this->log->log("Connecting to tcp://{$this->host}:{$this->port}");
|
||||
try {
|
||||
$this->socket = @stream_socket_client("tcp://{$this->host}:{$this->port}", $errno, $errstr, $timeout, $conflag);
|
||||
} catch (Exception $e) {
|
||||
throw new XMPPHP_Exception($e->getMessage());
|
||||
}
|
||||
if(!$this->socket) {
|
||||
$this->log->log("Could not connect.", XMPPHP_Log::LEVEL_ERROR);
|
||||
$this->disconnected = true;
|
||||
|
||||
throw new XMPPHP_Exception('Could not connect.');
|
||||
}
|
||||
stream_set_blocking($this->socket, 1);
|
||||
if($sendinit) $this->send($this->stream_start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnect XMPP Host
|
||||
*/
|
||||
public function doReconnect() {
|
||||
if(!$this->is_server) {
|
||||
$this->log->log("Reconnecting...", XMPPHP_Log::LEVEL_WARNING);
|
||||
$this->connect(30, false, false);
|
||||
$this->reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from XMPP Host
|
||||
*/
|
||||
public function disconnect() {
|
||||
$this->log->log("Disconnecting...", XMPPHP_Log::LEVEL_VERBOSE);
|
||||
$this->reconnect = false;
|
||||
$this->send($this->stream_end);
|
||||
$this->sent_disconnect = true;
|
||||
$this->processUntil('end_stream', 5);
|
||||
$this->disconnected = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Are we are disconnected?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDisconnected() {
|
||||
return $this->disconnected;
|
||||
}
|
||||
|
||||
private function __process() {
|
||||
$read = array($this->socket);
|
||||
$write = null;
|
||||
$except = null;
|
||||
$updated = @stream_select($read, $write, $except, 1);
|
||||
if ($updated > 0) {
|
||||
$buff = @fread($this->socket, 1024);
|
||||
if(!$buff) {
|
||||
if($this->reconnect) {
|
||||
$this->doReconnect();
|
||||
} else {
|
||||
fclose($this->socket);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE);
|
||||
xml_parse($this->parser, $buff, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function process() {
|
||||
$updated = '';
|
||||
while(!$this->disconnect) {
|
||||
$this->__process();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process until a timeout occurs
|
||||
*
|
||||
* @param integer $timeout
|
||||
* @return string
|
||||
*/
|
||||
public function processTime($timeout = -1) {
|
||||
$start = time();
|
||||
$updated = '';
|
||||
while(!$this->disconnected and ($timeout == -1 or time() - $start < $timeout)) {
|
||||
$this->__process();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process until a specified event or a timeout occurs
|
||||
*
|
||||
* @param string|array $event
|
||||
* @param integer $timeout
|
||||
* @return string
|
||||
*/
|
||||
public function processUntil($event, $timeout=-1) {
|
||||
$start = time();
|
||||
if(!is_array($event)) $event = array($event);
|
||||
$this->until[] = $event;
|
||||
end($this->until);
|
||||
$event_key = key($this->until);
|
||||
reset($this->until);
|
||||
$updated = '';
|
||||
while(!$this->disconnected and $this->until[$event_key] and (time() - $start < $timeout or $timeout == -1)) {
|
||||
$this->__process();
|
||||
}
|
||||
if(array_key_exists($event_key, $this->until_payload)) {
|
||||
$payload = $this->until_payload[$event_key];
|
||||
} else {
|
||||
$payload = array();
|
||||
}
|
||||
unset($this->until_payload[$event_key]);
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obsolete?
|
||||
*/
|
||||
public function Xapply_socket($socket) {
|
||||
$this->socket = $socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* XML start callback
|
||||
*
|
||||
* @see xml_set_element_handler
|
||||
*
|
||||
* @param resource $parser
|
||||
* @param string $name
|
||||
*/
|
||||
public function startXML($parser, $name, $attr) {
|
||||
if($this->been_reset) {
|
||||
$this->been_reset = false;
|
||||
$this->xml_depth = 0;
|
||||
}
|
||||
$this->xml_depth++;
|
||||
if(array_key_exists('XMLNS', $attr)) {
|
||||
$this->current_ns[$this->xml_depth] = $attr['XMLNS'];
|
||||
} else {
|
||||
$this->current_ns[$this->xml_depth] = $this->current_ns[$this->xml_depth - 1];
|
||||
if(!$this->current_ns[$this->xml_depth]) $this->current_ns[$this->xml_depth] = $this->default_ns;
|
||||
}
|
||||
$ns = $this->current_ns[$this->xml_depth];
|
||||
foreach($attr as $key => $value) {
|
||||
if(strstr($key, ":")) {
|
||||
$key = explode(':', $key);
|
||||
$key = $key[1];
|
||||
$this->ns_map[$key] = $value;
|
||||
}
|
||||
}
|
||||
if(!strstr($name, ":") === false)
|
||||
{
|
||||
$name = explode(':', $name);
|
||||
$ns = $this->ns_map[$name[0]];
|
||||
$name = $name[1];
|
||||
}
|
||||
$obj = new XMPPHP_XMLObj($name, $ns, $attr);
|
||||
if($this->xml_depth > 1) {
|
||||
$this->xmlobj[$this->xml_depth - 1]->subs[] = $obj;
|
||||
}
|
||||
$this->xmlobj[$this->xml_depth] = $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* XML end callback
|
||||
*
|
||||
* @see xml_set_element_handler
|
||||
*
|
||||
* @param resource $parser
|
||||
* @param string $name
|
||||
*/
|
||||
public function endXML($parser, $name) {
|
||||
#$this->log->log("Ending $name", XMPPHP_Log::LEVEL_DEBUG);
|
||||
#print "$name\n";
|
||||
if($this->been_reset) {
|
||||
$this->been_reset = false;
|
||||
$this->xml_depth = 0;
|
||||
}
|
||||
$this->xml_depth--;
|
||||
if($this->xml_depth == 1) {
|
||||
#clean-up old objects
|
||||
$found = false;
|
||||
foreach($this->nshandlers as $handler) {
|
||||
if($handler[4] != 1 and $this->xmlobj[2]->hasSub($handler[0])) {
|
||||
$searchxml = $this->xmlobj[2]->sub($handler[0]);
|
||||
} elseif(is_array($this->xmlobj) and array_key_exists(2, $this->xmlobj)) {
|
||||
$searchxml = $this->xmlobj[2];
|
||||
}
|
||||
if($searchxml !== null and $searchxml->name == $handler[0] and ($searchxml->ns == $handler[1] or (!$handler[1] and $searchxml->ns == $this->default_ns))) {
|
||||
if($handler[3] === null) $handler[3] = $this;
|
||||
$this->log->log("Calling {$handler[2]}", XMPPHP_Log::LEVEL_DEBUG);
|
||||
$handler[3]->$handler[2]($this->xmlobj[2]);
|
||||
}
|
||||
}
|
||||
foreach($this->idhandlers as $id => $handler) {
|
||||
if(array_key_exists('id', $this->xmlobj[2]->attrs) and $this->xmlobj[2]->attrs['id'] == $id) {
|
||||
if($handler[1] === null) $handler[1] = $this;
|
||||
$handler[1]->$handler[0]($this->xmlobj[2]);
|
||||
#id handlers are only used once
|
||||
unset($this->idhandlers[$id]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(is_array($this->xmlobj)) {
|
||||
$this->xmlobj = array_slice($this->xmlobj, 0, 1);
|
||||
if(isset($this->xmlobj[0]) && $this->xmlobj[0] instanceof XMPPHP_XMLObj) {
|
||||
$this->xmlobj[0]->subs = null;
|
||||
}
|
||||
}
|
||||
unset($this->xmlobj[2]);
|
||||
}
|
||||
if($this->xml_depth == 0 and !$this->been_reset) {
|
||||
if(!$this->disconnected) {
|
||||
if(!$this->sent_disconnect) {
|
||||
$this->send($this->stream_end);
|
||||
}
|
||||
$this->disconnected = true;
|
||||
$this->sent_disconnect = true;
|
||||
fclose($this->socket);
|
||||
if($this->reconnect) {
|
||||
$this->doReconnect();
|
||||
}
|
||||
}
|
||||
$this->event('end_stream');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* XML character callback
|
||||
* @see xml_set_character_data_handler
|
||||
*
|
||||
* @param resource $parser
|
||||
* @param string $data
|
||||
*/
|
||||
public function charXML($parser, $data) {
|
||||
if(array_key_exists($this->xml_depth, $this->xmlobj)) {
|
||||
$this->xmlobj[$this->xml_depth]->data .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event?
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $payload
|
||||
*/
|
||||
public function event($name, $payload = null) {
|
||||
$this->log->log("EVENT: $name", XMPPHP_Log::LEVEL_DEBUG);
|
||||
foreach($this->eventhandlers as $handler) {
|
||||
if($name == $handler[0]) {
|
||||
if($handler[2] === null) {
|
||||
$handler[2] = $this;
|
||||
}
|
||||
$handler[2]->$handler[1]($payload);
|
||||
}
|
||||
}
|
||||
foreach($this->until as $key => $until) {
|
||||
if(is_array($until)) {
|
||||
if(in_array($name, $until)) {
|
||||
$this->until_payload[$key][] = array($name, $payload);
|
||||
$this->until[$key] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from socket
|
||||
*/
|
||||
public function read() {
|
||||
$buff = @fread($this->socket, 1024);
|
||||
if(!$buff) {
|
||||
if($this->reconnect) {
|
||||
$this->doReconnect();
|
||||
} else {
|
||||
fclose($this->socket);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE);
|
||||
xml_parse($this->parser, $buff, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send to socket
|
||||
*
|
||||
* @param string $msg
|
||||
*/
|
||||
public function send($msg, $rec=false) {
|
||||
if($this->time() - $this->last_send < .1) {
|
||||
usleep(100000);
|
||||
}
|
||||
$wait = true;
|
||||
while($wait) {
|
||||
$read = null;
|
||||
$write = array($this->socket);
|
||||
$except = null;
|
||||
$select = @stream_select($read, $write, $except, 0, 0);
|
||||
if($select === False) {
|
||||
$this->doReconnect();
|
||||
return false;
|
||||
} elseif ($select > 0) {
|
||||
$wait = false;
|
||||
} else {
|
||||
usleep(100000);
|
||||
//$this->processTime(.25);
|
||||
}
|
||||
}
|
||||
$sentbytes = @fwrite($this->socket, $msg, 1024);
|
||||
$this->last_send = $this->time();
|
||||
$this->log->log("SENT: " . mb_substr($msg, 0, $sentbytes, '8bit'), XMPPHP_Log::LEVEL_VERBOSE);
|
||||
if($sentbytes === FALSE) {
|
||||
$this->doReconnect();
|
||||
} elseif ($sentbytes != mb_strlen($msg, '8bit')) {
|
||||
$this->send(mb_substr($msg, $sentbytes, mb_strlen($msg, '8bit'), '8bit'), true);
|
||||
}
|
||||
}
|
||||
|
||||
public function time() {
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return (float)$sec + (float)$usec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset connection
|
||||
*/
|
||||
public function reset() {
|
||||
$this->xml_depth = 0;
|
||||
unset($this->xmlobj);
|
||||
$this->xmlobj = array();
|
||||
$this->setupParser();
|
||||
if(!$this->is_server) {
|
||||
$this->send($this->stream_start);
|
||||
}
|
||||
$this->been_reset = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the XML parser
|
||||
*/
|
||||
public function setupParser() {
|
||||
$this->parser = xml_parser_create('UTF-8');
|
||||
xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
|
||||
xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
|
||||
xml_set_object($this->parser, $this);
|
||||
xml_set_element_handler($this->parser, 'startXML', 'endXML');
|
||||
xml_set_character_data_handler($this->parser, 'charXML');
|
||||
}
|
||||
}
|
321
lib/jabber/XMPP/XMPP.php
Normal file
321
lib/jabber/XMPP/XMPP.php
Normal file
|
@ -0,0 +1,321 @@
|
|||
<?php
|
||||
/**
|
||||
* XMPPHP: The PHP XMPP Library
|
||||
* Copyright (C) 2008 Nathanael C. Fritz
|
||||
* This file is part of SleekXMPP.
|
||||
*
|
||||
* XMPPHP is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* XMPPHP is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with XMPPHP; if not, write to the Free Software
|
||||
* 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>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
/** XMPPHP_XMLStream */
|
||||
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>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
* @version $Id$
|
||||
*/
|
||||
class XMPPHP_XMPP extends XMPPHP_XMLStream {
|
||||
/**
|
||||
* @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;
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send XMPP Message
|
||||
*
|
||||
* @param string $to
|
||||
* @param string $body
|
||||
* @param string $type
|
||||
* @param string $subject
|
||||
*/
|
||||
public function message($to, $body, $type = 'chat', $subject = null, $payload = 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>";
|
||||
if($payload) $out .= $payload;
|
||||
$out .= "</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='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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the roster
|
||||
*
|
||||
*/
|
||||
public function getRoster() {
|
||||
$id = $this->getID();
|
||||
$this->addIdHandler($id, 'roster_get_handler');
|
||||
$this->send("<iq xmlns='jabber:client' type='get' id='$id'><query xmlns='jabber:iq:roster' /></iq>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Roster retrieval handler
|
||||
*
|
||||
* @param string $xml
|
||||
*/
|
||||
protected function roster_get_handler($xml) {
|
||||
// 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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
111
lib/jabber/XMPP/XMPP_Old.php
Normal file
111
lib/jabber/XMPP/XMPP_Old.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
/**
|
||||
* XMPPHP: The PHP XMPP Library
|
||||
* Copyright (C) 2008 Nathanael C. Fritz
|
||||
* This file is part of SleekXMPP.
|
||||
*
|
||||
* XMPPHP is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* XMPPHP is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with XMPPHP; if not, write to the Free Software
|
||||
* 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>
|
||||
* @copyright 2008 Nathanael C. Fritz
|
||||
*/
|
||||
|
||||
/** XMPPHP_XMPP
|
||||
*
|
||||
* This file is unnecessary unless you need to connect to older, non-XMPP-compliant servers like Dreamhost's.
|
||||
* In this case, use instead of XMPPHP_XMPP, otherwise feel free to delete it.
|
||||
* The old Jabber protocol wasn't standardized, so use at your own risk.
|
||||
*
|
||||
*/
|
||||
require_once "XMPP.php";
|
||||
|
||||
class XMPPHP_XMPPOld extends XMPPHP_XMPP {
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $session_id;
|
||||
|
||||
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
|
||||
parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Override XMLStream's startXML
|
||||
*
|
||||
* @param parser $parser
|
||||
* @param string $name
|
||||
* @param array $attr
|
||||
*/
|
||||
protected function startXML($parser, $name, $attr) {
|
||||
if($this->xml_depth == 0 and $attr['version'] != '1.0') {
|
||||
$this->session_id = $attr['ID'];
|
||||
$this->authenticate();
|
||||
}
|
||||
parent::startXML($parser, $name, $attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Authenticate Info Request
|
||||
*
|
||||
*/
|
||||
public function authenticate() {
|
||||
$id = $this->getId();
|
||||
$this->addidhandler($id, 'authfieldshandler');
|
||||
$this->send("<iq type='get' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username></query></iq>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve auth fields and send auth attempt
|
||||
*
|
||||
* @param XMLObj $xml
|
||||
*/
|
||||
public function authFieldsHandler($xml) {
|
||||
$id = $this->getId();
|
||||
$this->addidhandler($id, 'oldAuthResultHandler');
|
||||
if($xml->sub('query')->hasSub('digest')) {
|
||||
$hash = sha1($this->session_id . $this->password);
|
||||
print "{$this->session_id} {$this->password}\n";
|
||||
$out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$hash}</digest><resource>{$this->resource}</resource></query></iq>";
|
||||
} else {
|
||||
$out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$this->password}</digest><resource>{$this->resource}</resource></query></iq>";
|
||||
}
|
||||
$this->send($out);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine authenticated or failure
|
||||
*
|
||||
* @param XMLObj $xml
|
||||
*/
|
||||
public function oldAuthResultHandler($xml) {
|
||||
if($xml->attrs['type'] != 'result') {
|
||||
$this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR);
|
||||
$this->disconnect();
|
||||
throw new XMPPHP_Exception('Auth failed!');
|
||||
} else {
|
||||
$this->log->log("Session started");
|
||||
$this->event('session_start');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -230,8 +230,14 @@ foreach ( $providers as $providerid => $provider){
|
|||
foreach (array('loggedin', 'loggedoff') as $state){
|
||||
$state_res = get_string($state, 'message');
|
||||
echo '<tr><td align="right">'.$state_res.'</td>'."\n";
|
||||
foreach ( $processors as $processorid => $processor){
|
||||
$checked = $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name]==1?" checked=\"checked\"":"";
|
||||
foreach ( $processors as $processorid => $processor) {
|
||||
if (!isset($preferences->{$provider->component.'_'.$provider->name.'_'.$state})) {
|
||||
$checked = '';
|
||||
} else if (!isset($preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name])) {
|
||||
$checked = '';
|
||||
} else {
|
||||
$checked = $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name]==1?" checked=\"checked\"":"";
|
||||
}
|
||||
echo '<td align="center"><input type="checkbox" name="'.$provider->component.'_'.$provider->name.'_'.$state.'['.$processor->name.']" '.$checked.' /></td>'."\n";
|
||||
}
|
||||
echo '</tr>'."\n";
|
||||
|
|
|
@ -1,504 +0,0 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
Jabber Client Library
|
||||
Version 0.9rc1
|
||||
Copyright 2002-2007, Centova Technologies Inc.
|
||||
http://www.centova.com
|
||||
|
||||
Portions Copyright 2002, Carlo Zottmann
|
||||
============================================================================
|
||||
|
||||
This file was contributed (in part or whole) by a third party, and is
|
||||
released under the GNU LGPL. Please see the CREDITS and LICENSE sections
|
||||
below for details.
|
||||
|
||||
****************************************************************************
|
||||
|
||||
DETAILS
|
||||
|
||||
This is an event-driven Jabber client class implementation. This library
|
||||
allows PHP scripts to connect to and communicate with Jabber servers.
|
||||
|
||||
|
||||
CREDITS & COPYRIGHTS
|
||||
|
||||
This class was originally based on Class.Jabber.PHP v0.4 (Copyright 2002,
|
||||
Carlo "Gossip" Zottmann).
|
||||
|
||||
The code for this class has since been nearly completely rewritten by Steve
|
||||
Blinch for Centova Technologies Inc. All such modified code is Copyright
|
||||
2002-2007, Centova Technologies Inc.
|
||||
|
||||
The original Class.Jabber.PHP was released under the GNU General Public
|
||||
License (GPL); however, we have received written permission from the
|
||||
original author and copyright holder, Carlo Zottmann, to relicense our
|
||||
version of this class and release it under the GNU Lesser General Public
|
||||
License (LGPL).
|
||||
|
||||
LICENSE
|
||||
|
||||
class_Jabber.php - Jabber Client Library
|
||||
Copyright (C) 2002-2007, Centova Technologies Inc.
|
||||
Copyright (C) 2002, Carlo Zottmann
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by the
|
||||
Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
JABBER is a registered trademark of Jabber Inc.
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file was contributed (in part or whole) by a third party, and is
|
||||
* released under the GNU LGPL. Please see the CREDITS and LICENSE sections
|
||||
* below for details.
|
||||
*
|
||||
*****************************************************************************
|
||||
*
|
||||
* DETAILS
|
||||
*
|
||||
* Connection handling class used by class_Jabber.php. Used as a generic
|
||||
* socket interface to connect to Jabber servers.
|
||||
*
|
||||
*
|
||||
* CREDITS & COPYRIGHTS
|
||||
*
|
||||
* This class was originally based on Class.Jabber.PHP v0.4 (Copyright 2002,
|
||||
* Carlo "Gossip" Zottmann).
|
||||
*
|
||||
* The code for this class has since been nearly completely rewritten by Steve
|
||||
* Blinch and Centova Technologies Inc. All such modified code is Copyright 2003-2006,
|
||||
* Centova Technologies Inc.
|
||||
*
|
||||
* The original Class.Jabber.PHP was released under the GNU General Public
|
||||
* License (GPL); however, we have received written permission from the
|
||||
* original author and copyright holder, Carlo Zottmann, to relicense our
|
||||
* version of this class and release it under the GNU Lesser General Public
|
||||
* License (LGPL).
|
||||
*
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* class_ConnectionSocket.php - Connection Socket Library
|
||||
* Part of class_Jabber.php - Jabber Client Library
|
||||
* Copyright (C) 2003-2007, Centova Technologies Inc.
|
||||
* Copyright (C) 2002, Carlo Zottmann
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this library; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
class ConnectionSocket {
|
||||
var $socket = null;
|
||||
|
||||
function socket_open($hostname,$port,$timeout) {
|
||||
if ($this->socket = @fsockopen($hostname, $port, $errno, $errstr, $timeout)) {
|
||||
socket_set_blocking($this->socket, 0);
|
||||
socket_set_timeout($this->socket, 31536000);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "{$errstr} (#{$errno})";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function socket_close() {
|
||||
return fclose($this->socket);
|
||||
}
|
||||
|
||||
function socket_write($data) {
|
||||
return fwrite($this->socket, $data);
|
||||
}
|
||||
|
||||
function socket_read($byte_count)
|
||||
{
|
||||
set_magic_quotes_runtime(0);
|
||||
$buffer = fread($this->socket, $byte_count);
|
||||
set_magic_quotes_runtime(get_magic_quotes_runtime());
|
||||
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
File diff suppressed because it is too large
Load diff
|
@ -1,264 +0,0 @@
|
|||
<?
|
||||
/*
|
||||
* This file was contributed (in part or whole) by a third party, and is
|
||||
* released under a BSD-compatible free software license. Please see the
|
||||
* CREDITS and LICENSE sections below for details.
|
||||
*
|
||||
*****************************************************************************
|
||||
*
|
||||
* DETAILS
|
||||
*
|
||||
* A PHP implementation of the Secure Hash Algorithm, SHA-1, as defined in
|
||||
* FIPS PUB 180-1. This is used by Centova only when using PHP
|
||||
* versions older than 4.3.0 (which did not support the sha1() function) and
|
||||
* the server does not have the mhash extension installed.
|
||||
*
|
||||
*
|
||||
* CREDITS/LICENSE
|
||||
*
|
||||
* Adjusted from the Javascript implementation by Joror (daan@parse.nl).
|
||||
*
|
||||
* Javascript Version 2.1 Copyright Paul Johnston 2000 - 2002.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||
*
|
||||
*/
|
||||
|
||||
class SHA1Library
|
||||
{
|
||||
/*
|
||||
* Configurable variables. You may need to tweak these to be compatible with
|
||||
* the server-side, but the defaults work in most cases.
|
||||
*/
|
||||
var $hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||
var $b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
||||
var $chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
|
||||
|
||||
/*
|
||||
* These are the functions you'll usually want to call
|
||||
* They take string arguments and return either hex or base-64 encoded strings
|
||||
*/
|
||||
function hex_sha1($s){return $this->binb2hex($this->core_sha1($this->str2binb($s),strlen($s) * $this->chrsz));}
|
||||
function b64_sha1($s){return $this->binb2b64($this->core_sha1($this->str2binb($s),strlen($s) * $this->chrsz));}
|
||||
function str_sha1($s){return $this->binb2str($this->core_sha1($this->str2binb($s),strlen($s) * $this->chrsz));}
|
||||
function hex_hmac_sha1($key, $data){ return $this->binb2hex($this->core_hmac_sha1($key, $data));}
|
||||
function b64_hmac_sha1($key, $data){ return $this->binb2b64($this->core_hmac_sha1($key, $data));}
|
||||
function str_hmac_sha1($key, $data){ return $this->binb2str($this->core_hmac_sha1($key, $data));}
|
||||
|
||||
/*
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
*/
|
||||
function sha1_vm_test()
|
||||
{
|
||||
return $this->hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the SHA-1 of an array of big-endian words, and a bit $length
|
||||
*/
|
||||
function core_sha1($x, $len)
|
||||
{
|
||||
/* append padding */
|
||||
$x[$len >> 5] |= 0x80 << (24 - $len % 32);
|
||||
$x[(($len + 64 >> 9) << 4) + 15] = $len;
|
||||
|
||||
$w = Array();
|
||||
$a = 1732584193;
|
||||
$b = -271733879;
|
||||
$c = -1732584194;
|
||||
$d = 271733878;
|
||||
$e = -1009589776;
|
||||
|
||||
for($i = 0; $i < sizeof($x); $i += 16)
|
||||
{
|
||||
$olda = $a;
|
||||
$oldb = $b;
|
||||
$oldc = $c;
|
||||
$oldd = $d;
|
||||
$olde = $e;
|
||||
|
||||
for($j = 0; $j < 80; $j++)
|
||||
{
|
||||
if ($j < 16)
|
||||
$w[$j] = $x[$i + $j];
|
||||
else
|
||||
$w[$j] = $this->rol($w[$j-3] ^ $w[$j-8] ^ $w[$j-14] ^ $w[$j-16], 1);
|
||||
|
||||
$t = $this->safe_add( $this->safe_add($this->rol($a, 5), $this->sha1_ft($j, $b, $c, $d)),
|
||||
$this->safe_add($this->safe_add($e, $w[$j]), $this->sha1_kt($j)));
|
||||
$e = $d;
|
||||
$d = $c;
|
||||
$c = $this->rol($b, 30);
|
||||
$b = $a;
|
||||
$a = $t;
|
||||
}
|
||||
|
||||
$a = $this->safe_add($a, $olda);
|
||||
$b = $this->safe_add($b, $oldb);
|
||||
$c = $this->safe_add($c, $oldc);
|
||||
$d = $this->safe_add($d, $oldd);
|
||||
$e = $this->safe_add($e, $olde);
|
||||
}
|
||||
|
||||
return Array($a, $b, $c, $d, $e);
|
||||
}
|
||||
|
||||
/*
|
||||
* Joror: PHP does not have the java(script) >>> operator, so this is a
|
||||
* replacement function. Credits to Terium.
|
||||
*/
|
||||
function zerofill_rightshift($a, $b)
|
||||
{
|
||||
$z = hexdec(80000000);
|
||||
if ($z & $a)
|
||||
{
|
||||
$a >>= 1;
|
||||
$a &= (~ $z);
|
||||
$a |= 0x40000000;
|
||||
$a >>= ($b-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$a >>= $b;
|
||||
}
|
||||
return $a;
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the appropriate triplet combination function for the current
|
||||
* iteration
|
||||
*/
|
||||
function sha1_ft($t, $b, $c, $d)
|
||||
{
|
||||
if($t < 20) return ($b & $c) | ((~$b) & $d);
|
||||
if($t < 40) return $b ^ $c ^ $d;
|
||||
if($t < 60) return ($b & $c) | ($b & $d) | ($c & $d);
|
||||
return $b ^ $c ^ $d;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the appropriate additive constant for the current iteration
|
||||
* Silly php does not understand the inline-if operator well when nested,
|
||||
* so that's why it's ()ed now.
|
||||
*/
|
||||
function sha1_kt($t)
|
||||
{
|
||||
return ($t < 20) ? 1518500249 : (($t < 40) ? 1859775393 :
|
||||
(($t < 60) ? -1894007588 : -899497514));
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the HMAC-SHA1 of a key and some data
|
||||
*/
|
||||
function core_hmac_sha1($key, $data)
|
||||
{
|
||||
$bkey = $this->str2binb($key);
|
||||
if(sizeof($bkey) > 16) $bkey = $this->core_sha1($bkey, sizeof($key) * $this->chrsz);
|
||||
|
||||
$ipad = Array();
|
||||
$opad = Array();
|
||||
|
||||
for($i = 0; $i < 16; $i++)
|
||||
{
|
||||
$ipad[$i] = $bkey[$i] ^ 0x36363636;
|
||||
$opad[$i] = $bkey[$i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
$hash = $this->core_sha1(array_merge($ipad,$this->str2binb($data)), 512 + sizeof($data) * $this->chrsz);
|
||||
return $this->core_sha1(array_merge($opad,$hash), 512 + 160);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||
* to work around bugs in some JS interpreters.
|
||||
*/
|
||||
function safe_add($x, $y)
|
||||
{
|
||||
$lsw = ($x & 0xFFFF) + ($y & 0xFFFF);
|
||||
$msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16);
|
||||
return ($msw << 16) | ($lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bitwise rotate a 32-bit number to the left.
|
||||
*/
|
||||
function rol($num, $cnt)
|
||||
{
|
||||
return ($num << $cnt) | $this->zerofill_rightshift($num, (32 - $cnt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an 8-bit or 16-bit string to an array of big-endian words
|
||||
* In 8-bit function, characters >255 have their hi-byte silently ignored.
|
||||
*/
|
||||
function str2binb($str)
|
||||
{
|
||||
$bin = Array();
|
||||
$mask = (1 << $this->chrsz) - 1;
|
||||
for($i = 0; $i < strlen($str) * $this->chrsz; $i += $this->chrsz)
|
||||
$bin[$i >> 5] |= (ord($str{$i / $this->chrsz}) & $mask) << (24 - $i%32);
|
||||
|
||||
return $bin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of big-endian words to a string
|
||||
*/
|
||||
function binb2str($bin)
|
||||
{
|
||||
$str = "";
|
||||
$mask = (1 << $this->chrsz) - 1;
|
||||
for($i = 0; $i < sizeof($bin) * 32; $i += $this->chrsz)
|
||||
$str .= chr($this->zerofill_rightshift($bin[$i>>5], 24 - $i%32) & $mask);
|
||||
return $str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of big-endian words to a hex string.
|
||||
*/
|
||||
function binb2hex($binarray)
|
||||
{
|
||||
$hex_tab = $this->hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
$str = "";
|
||||
for($i = 0; $i < sizeof($binarray) * 4; $i++)
|
||||
{
|
||||
$str .= $hex_tab{($binarray[$i>>2] >> ((3 - $i%4)*8+4)) & 0xF} .
|
||||
$hex_tab{($binarray[$i>>2] >> ((3 - $i%4)*8 )) & 0xF};
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of big-endian words to a base-64 string
|
||||
*/
|
||||
function binb2b64($binarray)
|
||||
{
|
||||
$tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
$str = "";
|
||||
for($i = 0; i < sizeof($binarray) * 4; $i += 3)
|
||||
{
|
||||
$triplet = ((($binarray[$i >> 2] >> 8 * (3 - $i %4)) & 0xFF) << 16)
|
||||
| ((($binarray[$i+1 >> 2] >> 8 * (3 - ($i+1)%4)) & 0xFF) << 8 )
|
||||
| (($binarray[$i+2 >> 2] >> 8 * (3 - ($i+2)%4)) & 0xFF);
|
||||
for($j = 0; $j < 4; $j++)
|
||||
{
|
||||
if($i * 8 + $j * 6 > sizeof($binarray) * 32) $str .= $this->b64pad;
|
||||
else $str .= $tab{($triplet >> 6*(3-j)) & 0x3F};
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists('sha1') )
|
||||
{
|
||||
function sha1( $string, $raw_output = false )
|
||||
{
|
||||
$library = &new SHA1Library();
|
||||
|
||||
return $raw_output ? $library->str_sha1($string) : $library->hex_sha1($string);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,139 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file was contributed (in part or whole) by a third party, and is
|
||||
* released under a BSD-compatible free software license. Please see the
|
||||
* CREDITS and LICENSE sections below for details.
|
||||
*
|
||||
*****************************************************************************
|
||||
*
|
||||
* DETAILS
|
||||
*
|
||||
* Provides the XML parser used by class_Jabber.php to parse Jabber XML data
|
||||
* received from the Jabber server.
|
||||
*
|
||||
*
|
||||
* CREDITS
|
||||
*
|
||||
* Originally by Hans Anderson (http://www.hansanderson.com/php/xml)
|
||||
* Adapted for class.jabber.php by Carlo Zottman (http://phpjabber.g-blog.net)
|
||||
* Adapted for class_Jabber.php by Steve Blinch (http://www.centova.com)
|
||||
*
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* xmlize() is by Hans Anderson, www.hansanderson.com/contact/
|
||||
*
|
||||
* Ye Ole "Feel Free To Use it However" License [PHP, BSD, GPL].
|
||||
* some code in xml_depth is based on code written by other PHPers
|
||||
* as well as one Perl script. Poor programming practice and organization
|
||||
* on my part is to blame for the credit these people aren't receiving.
|
||||
* None of the code was copyrighted, though.
|
||||
*
|
||||
*
|
||||
* REFERENCE
|
||||
*
|
||||
* @ = attributes
|
||||
* # = nested tags
|
||||
*
|
||||
*/
|
||||
|
||||
class XMLParser {
|
||||
|
||||
function XMLParser() {
|
||||
}
|
||||
|
||||
// xmlize()
|
||||
// (c) Hans Anderson / http://www.hansanderson.com/php/xml/
|
||||
|
||||
function xmlize($data) {
|
||||
$vals = $index = $array = array();
|
||||
$parser = xml_parser_create();
|
||||
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
|
||||
|
||||
// XML_OPTION_SKIP_WHITE is disabled as it clobbers valid
|
||||
// newlines in instant messages
|
||||
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
|
||||
xml_parse_into_struct($parser, $data, $vals, $index);
|
||||
xml_parser_free($parser);
|
||||
|
||||
$i = 0;
|
||||
|
||||
$tagname = $vals[$i]['tag'];
|
||||
$array[$tagname]['@'] = $vals[$i]['attributes'];
|
||||
$array[$tagname]['#'] = $this->_xml_depth($vals, $i);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// _xml_depth()
|
||||
// (c) Hans Anderson / http://www.hansanderson.com/php/xml/
|
||||
|
||||
function _xml_depth($vals, &$i) {
|
||||
$children = array();
|
||||
|
||||
if ($vals[$i]['value']) {
|
||||
array_push($children, trim($vals[$i]['value']));
|
||||
}
|
||||
|
||||
while (++$i < count($vals)) {
|
||||
switch ($vals[$i]['type']) {
|
||||
case 'cdata':
|
||||
array_push($children, trim($vals[$i]['value']));
|
||||
break;
|
||||
|
||||
case 'complete':
|
||||
$tagname = $vals[$i]['tag'];
|
||||
$size = sizeof($children[$tagname]);
|
||||
$children[$tagname][$size]['#'] = trim($vals[$i]['value']);
|
||||
if ($vals[$i]['attributes']) {
|
||||
$children[$tagname][$size]['@'] = $vals[$i]['attributes'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'open':
|
||||
$tagname = $vals[$i]['tag'];
|
||||
$size = sizeof($children[$tagname]);
|
||||
if ($vals[$i]['attributes']) {
|
||||
$children[$tagname][$size]['@'] = $vals[$i]['attributes'];
|
||||
$children[$tagname][$size]['#'] = $this->_xml_depth($vals, $i);
|
||||
} else {
|
||||
$children[$tagname][$size]['#'] = $this->_xml_depth($vals, $i);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'close':
|
||||
return $children;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TraverseXMLize()
|
||||
// (c) acebone@f2s.com, a HUGE help!
|
||||
|
||||
function TraverseXMLize($array, $arrName = "array", $level = 0) {
|
||||
if ($level == 0) {
|
||||
echo "<pre>";
|
||||
}
|
||||
|
||||
while (list($key, $val) = @each($array)) {
|
||||
if (is_array($val)) {
|
||||
$this->TraverseXMLize($val, $arrName . "[" . $key . "]", $level + 1);
|
||||
} else {
|
||||
echo '$' . $arrName . '[' . $key . '] = "' . $val . "\"\n";
|
||||
}
|
||||
}
|
||||
|
||||
if ($level == 0) {
|
||||
echo "</pre>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -1,224 +0,0 @@
|
|||
#!/usr/local/bin/php -q
|
||||
<?php
|
||||
/* Jabber Class Example
|
||||
* Copyright 2002-2007, Steve Blinch
|
||||
* http://code.blitzaffe.com
|
||||
* ============================================================================
|
||||
*
|
||||
* DETAILS
|
||||
*
|
||||
* Provides a very basic example of how to use class_Jabber.php.
|
||||
*
|
||||
* This example connects to a Jabber server, logs in, fetches (and displays)
|
||||
* the roster, and then waits until a message is received from another contact.
|
||||
*
|
||||
* It then starts a countdown which, in sequence:
|
||||
*
|
||||
* 1) sends a "composing" event to the other contact (eg: "so-and-so is typing a message"),
|
||||
* 2) sends a "composing stopped" event,
|
||||
* 3) sends another "composing" event",
|
||||
* 4) sends a message to the other contact,
|
||||
* 5) logs out
|
||||
*
|
||||
*/
|
||||
|
||||
// set your Jabber server hostname, username, and password here
|
||||
define("JABBER_SERVER","jabber.blitzaffe.com");
|
||||
define("JABBER_USERNAME","helium");
|
||||
define("JABBER_PASSWORD","zv4.5k1p8");
|
||||
|
||||
define("RUN_TIME",30); // set a maximum run time of 30 seconds
|
||||
define("CBK_FREQ",1); // fire a callback event every second
|
||||
|
||||
|
||||
// This class handles all events fired by the Jabber client class; you
|
||||
// can optionally use individual functions instead of a class, but this
|
||||
// method is a bit cleaner.
|
||||
class TestMessenger {
|
||||
|
||||
function TestMessenger(&$jab) {
|
||||
$this->jab = &$jab;
|
||||
$this->first_roster_update = true;
|
||||
|
||||
echo "Created!\n";
|
||||
$this->countdown = 0;
|
||||
}
|
||||
|
||||
// called when a connection to the Jabber server is established
|
||||
function handleConnected() {
|
||||
echo "Connected!\n";
|
||||
|
||||
// now that we're connected, tell the Jabber class to login
|
||||
echo "Authenticating ...\n";
|
||||
$this->jab->login(JABBER_USERNAME,JABBER_PASSWORD);
|
||||
}
|
||||
|
||||
// called after a login to indicate the the login was successful
|
||||
function handleAuthenticated() {
|
||||
echo "Authenticated!\n";
|
||||
|
||||
|
||||
echo "Fetching service list and roster ...\n";
|
||||
|
||||
// browser for transport gateways
|
||||
$this->jab->browse();
|
||||
|
||||
// retrieve this user's roster
|
||||
$this->jab->get_roster();
|
||||
|
||||
// set this user's presence
|
||||
$this->jab->set_presence("","Ya, I'm online... so what?");
|
||||
}
|
||||
|
||||
// called after a login to indicate that the login was NOT successful
|
||||
function handleAuthFailure($code,$error) {
|
||||
echo "Authentication failure: $error ($code)\n";
|
||||
|
||||
// set terminated to TRUE in the Jabber class to tell it to exit
|
||||
$this->jab->terminated = true;
|
||||
}
|
||||
|
||||
// called periodically by the Jabber class to allow us to do our own
|
||||
// processing
|
||||
function handleHeartbeat() {
|
||||
echo "Heartbeat - ";
|
||||
|
||||
// if the countdown is in progress, determine if we need to take any action
|
||||
if ($this->countdown>0) {
|
||||
$this->countdown--;
|
||||
|
||||
// display our countdown progress
|
||||
echo "Countdown: {$this->countdown}\n";
|
||||
|
||||
|
||||
// first, we want to fire our composing event
|
||||
if ($this->countdown==7) {
|
||||
echo "Composing start\n";
|
||||
$this->jab->composing($this->last_msg_from,$this->last_msg_id);
|
||||
}
|
||||
|
||||
// next, we want to indicate that we've stopped composing a message
|
||||
if ($this->countdown==5) {
|
||||
echo "Composing stop\n";
|
||||
$this->jab->composing($this->last_msg_from,$this->last_msg_id,false);
|
||||
}
|
||||
|
||||
// next, we indicate that we're composing again
|
||||
if ($this->countdown==3) {
|
||||
echo "Composing start\n";
|
||||
$this->jab->composing($this->last_msg_from,$this->last_msg_id);
|
||||
}
|
||||
|
||||
// and finally, we send a message to the remote user and tell the Jabber class
|
||||
// to exit
|
||||
if ($this->countdown==1) {
|
||||
echo "Send message\n";
|
||||
$this->jab->message($this->last_msg_from,"chat",NULL,"Hello! You said: ".$this->last_message);
|
||||
$this->jab->terminated = true;
|
||||
}
|
||||
} else {
|
||||
echo "Waiting for incoming message ...\n";
|
||||
}
|
||||
/*
|
||||
reset($this->jab->roster);
|
||||
foreach ($this->jab->roster as $jid=>$details) {
|
||||
echo "$jid\t\t\t".$details["transport"]."\t".$details["show"]."\t".$details["status"]."\n";
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// called when an error is received from the Jabber server
|
||||
function handleError($code,$error,$xmlns) {
|
||||
echo "Error: $error ($code)".($xmlns?" in $xmlns":"")."\n";
|
||||
}
|
||||
|
||||
// called when a message is received from a remote contact
|
||||
function handleMessage($from,$to,$body,$subject,$thread,$id,$extended) {
|
||||
echo "Incoming message!\n";
|
||||
echo "From: $from\t\tTo: $to\n";
|
||||
echo "Subject: $subject\tThread; $thread\n";
|
||||
echo "Body: $body\n";
|
||||
echo "ID: $id\n";
|
||||
var_dump($extended);
|
||||
echo "\n";
|
||||
|
||||
$this->last_message = $body;
|
||||
|
||||
$this->last_msg_id = $id;
|
||||
$this->last_msg_from = $from;
|
||||
|
||||
// for the purposes of our example, we start a countdown here to do some
|
||||
// random events, just for the sake of demonstration
|
||||
echo "Starting countdown\n";
|
||||
$this->countdown = 10;
|
||||
}
|
||||
|
||||
function _contact_info($contact) {
|
||||
return sprintf("Contact %s (JID %s) has status %s and message %s\n",$contact['name'],$contact['jid'],$contact['show'],$contact['status']);
|
||||
}
|
||||
|
||||
function handleRosterUpdate($jid) {
|
||||
if ($this->first_roster_update) {
|
||||
// the first roster update indicates that the entire roster has been
|
||||
// downloaded for the first time
|
||||
echo "Roster downloaded:\n";
|
||||
|
||||
foreach ($this->jab->roster as $k=>$contact) {
|
||||
echo $this->_contact_info($contact);
|
||||
}
|
||||
$this->first_roster_update = false;
|
||||
} else {
|
||||
// subsequent roster updates indicate changes for individual roster items
|
||||
$contact = $this->jab->roster[$jid];
|
||||
echo "Contact updated: " . $this->_contact_info($contact);
|
||||
}
|
||||
}
|
||||
|
||||
function handleDebug($msg,$level) {
|
||||
echo "DBG: $msg\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// include the Jabber class
|
||||
require_once("class_Jabber.php");
|
||||
|
||||
// create an instance of the Jabber class
|
||||
$display_debug_info = false;
|
||||
$jab = new Jabber($display_debug_info);
|
||||
|
||||
// create an instance of our event handler class
|
||||
$test = new TestMessenger($jab);
|
||||
|
||||
// set handlers for the events we wish to be notified about
|
||||
$jab->set_handler("connected",$test,"handleConnected");
|
||||
$jab->set_handler("authenticated",$test,"handleAuthenticated");
|
||||
$jab->set_handler("authfailure",$test,"handleAuthFailure");
|
||||
$jab->set_handler("heartbeat",$test,"handleHeartbeat");
|
||||
$jab->set_handler("error",$test,"handleError");
|
||||
$jab->set_handler("message_normal",$test,"handleMessage");
|
||||
$jab->set_handler("message_chat",$test,"handleMessage");
|
||||
$jab->set_handler("debug_log",$test,"handleDebug");
|
||||
$jab->set_handler("rosterupdate",$test,"handleRosterUpdate");
|
||||
|
||||
echo "Connecting ...\n";
|
||||
|
||||
// connect to the Jabber server
|
||||
if (!$jab->connect(JABBER_SERVER)) {
|
||||
die("Could not connect to the Jabber server!\n");
|
||||
}
|
||||
|
||||
// now, tell the Jabber class to begin its execution loop
|
||||
$jab->execute(CBK_FREQ,RUN_TIME);
|
||||
|
||||
// Note that we will not reach this point (and the execute() method will not
|
||||
// return) until $jab->terminated is set to TRUE. The execute() method simply
|
||||
// loops, processing data from (and to) the Jabber server, and firing events
|
||||
// (which are handled by our TestMessenger class) until we tell it to terminate.
|
||||
//
|
||||
// This event-based model will be familiar to programmers who have worked on
|
||||
// desktop applications, particularly in Win32 environments.
|
||||
|
||||
// disconnect from the Jabber server
|
||||
$jab->disconnect();
|
||||
?>
|
|
@ -40,39 +40,7 @@ define("JABBER_PASSWORD","");
|
|||
define("RUN_TIME",15); // set a maximum run time of 15 seconds
|
||||
|
||||
require_once($CFG->dirroot.'/message/output/lib.php');
|
||||
require_once($CFG->dirroot.'/message/output/jabber/jabberclass/class_Jabber.php');
|
||||
|
||||
class JabberMessenger {
|
||||
function JabberMessenger(&$jab, $message) {
|
||||
$this->jab = &$jab;
|
||||
$this->message = $message;
|
||||
$this->first_roster_update = true;
|
||||
$this->countdown = 0;
|
||||
}
|
||||
// called when a connection to the Jabber server is established
|
||||
function handleConnected() {
|
||||
$this->jab->login(JABBER_USERNAME,JABBER_PASSWORD);
|
||||
}
|
||||
// called after a login to indicate the the login was successful
|
||||
function handleAuthenticated() {
|
||||
global $DB;
|
||||
$userfrom = $DB->get_record('user', array('id' => $this->message->useridfrom));
|
||||
$userto = $DB->get_record('user', array('id' => $this->message->useridto));
|
||||
|
||||
$jabberdest = get_user_preferences('message_processor_jabber_jabberid', $userto->email , $userto->id);
|
||||
if (empty($jabberdest)){
|
||||
$jabberdest = $userto->email;
|
||||
}
|
||||
$this->jab->message($jabberdest,"chat",NULL,fullname($userfrom)." says: ".$this->message->fullmessage);
|
||||
$this->jab->terminated = true;
|
||||
}
|
||||
// called after a login to indicate that the login was NOT successful
|
||||
function handleAuthFailure($code,$error) {
|
||||
// set terminated to TRUE in the Jabber class to tell it to exit
|
||||
$this->jab->terminated = true;
|
||||
}
|
||||
}
|
||||
|
||||
require_once($CFG->libdir.'/jabber/XMPP/XMPP.php');
|
||||
|
||||
class message_output_jabber extends message_output {
|
||||
|
||||
|
@ -82,26 +50,31 @@ class message_output_jabber extends message_output {
|
|||
* @return true if ok, false if error
|
||||
*/
|
||||
function send_message($message){
|
||||
global $DB;
|
||||
|
||||
//jabber object
|
||||
$jab = new Jabber(True);
|
||||
// create an instance of our event handler class
|
||||
$test = new JabberMessenger($jab, $message);
|
||||
|
||||
// set handlers for the events we wish to be notified about
|
||||
$jab->set_handler("connected",$test,"handleConnected");
|
||||
$jab->set_handler("authenticated",$test,"handleAuthenticated");
|
||||
$jab->set_handler("authfailure",$test,"handleAuthFailure");
|
||||
|
||||
if (!$jab->connect(JABBER_SERVER)) {
|
||||
if (!$userfrom = $DB->get_record('user', array('id' => $message->useridfrom))) {
|
||||
return false;
|
||||
}
|
||||
if (!$userto = $DB->get_record('user', array('id' => $this->message->useridto))) {
|
||||
return false;
|
||||
}
|
||||
if (!$jabberaddress = get_user_preferences('message_processor_jabber_jabberid', $userto->email, $userto->id)) {
|
||||
$jabberaddress = $userto->email;
|
||||
}
|
||||
$jabbermessage = fullname($userfrom).': '.$message->fullmessage;
|
||||
|
||||
// now, tell the Jabber class to begin its execution loop
|
||||
// don't way for events
|
||||
$jab->execute(-1,RUN_TIME);
|
||||
$jab->disconnect();
|
||||
$conection = new XMPPHP_XMPP(JABBER_SERVER, 5222, JABBER_USERNAME, JABBER_PASSWORD, 'moodle', JABBER_SERVER);
|
||||
|
||||
try {
|
||||
$conn->connect();
|
||||
$conn->processUntil('session_start');
|
||||
$conn->presence();
|
||||
$conn->message($jabberaddress, $jabbermessage);
|
||||
$conn->disconnect();
|
||||
} catch(XMPPHP_Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
* @package
|
||||
*/
|
||||
|
||||
$plugin->version = 2008072401;
|
||||
$plugin->requires = 2008072401;
|
||||
$plugin->version = 2008090900;
|
||||
$plugin->requires = 2008091500;
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2008091000; // YYYYMMDD = date of the last version bump
|
||||
$version = 2008091500; // YYYYMMDD = date of the last version bump
|
||||
// XX = daily increments
|
||||
|
||||
$release = '2.0 dev (Build: 20080915)'; // Human-friendly version name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue