Browse Source

Forgottent files

pull/5/head
Jaussoin Timothée 15 years ago
committed by Etenil
parent
commit
420dcd352f
  1. 10
      init.php
  2. 5
      js/movim.js
  3. 20
      lib/EventHandler.php
  4. 15
      lib/Jaxl/CHANGELOG
  5. 8
      lib/Jaxl/README.md
  6. 111
      lib/Jaxl/core/jaxl.class.php
  7. 11
      lib/Jaxl/core/jaxl.cron.php
  8. 8
      lib/Jaxl/core/jaxl.logger.php
  9. 3
      lib/Jaxl/core/jaxl.parser.php
  10. 2
      lib/Jaxl/core/jaxl.plugin.php
  11. 4
      lib/Jaxl/core/jaxl.util.php
  12. 45
      lib/Jaxl/xep/jaxl.0004.php
  13. 4
      lib/Jaxl/xep/jaxl.0114.php
  14. 90
      lib/Jaxl/xep/jaxl.0124.php
  15. 26
      lib/Jaxl/xep/jaxl.0133.php
  16. 2
      lib/Jaxl/xep/jaxl.0199.php
  17. 2
      lib/Jaxl/xep/jaxl.0202.php
  18. 15
      lib/Jaxl/xep/jaxl.0206.php
  19. 4
      lib/Jaxl/xmpp/xmpp.auth.php
  20. 285
      lib/Jaxl/xmpp/xmpp.class.php
  21. 32
      lib/Jaxl/xmpp/xmpp.get.php
  22. 4
      lib/Jaxl/xmpp/xmpp.send.php
  23. 3
      lib/PageBuilder.php
  24. 4
      lib/User.php
  25. 50
      lib/XMPPConnect.php
  26. 6
      lib/widgets/Chat.php
  27. 5
      lib/widgets/Friends.php
  28. 4
      themes/movim/css/style2.css

10
init.php

@ -1,6 +1,6 @@
<?php
session_commit();
//ini_set('error_reporting', E_ALL & ~E_NOTICE);
//session_commit();
ini_set('error_reporting', E_ALL & ~E_NOTICE ^ E_DEPRECATED);
session_start();
@ -37,12 +37,8 @@ define('APP_TITLE', t("MOVIM - Test Client"));
* with this.
*/
function __autoload($className) {
/* If the class is a Controller, we apply the correct path */
if(preg_match('/Properties$/',$className)) {
$file = PROPERTIES_PATH . $className;
}
else if(preg_match('/^JAXL/', $className)) {
if(preg_match('/^JAXL/', $className)) {
return;
}

5
js/movim.js

@ -89,6 +89,11 @@ function movim_poll()
poller.send();
}
function halt_poll()
{
poller.abort();
}
/**
* Sends data to the movim server through ajax.
*

20
lib/EventHandler.php

@ -9,19 +9,17 @@ class EventHandler
{
$this->conf = new GetConf();
$this->parse_tpl('main.tpl');
//array_merge($widgets, $this->parse_tpl('page.tpl'));
$this->getLoadedWidgets();
}
private function parse_tpl($template)
public function setLoadedWidgets($loaded_widgets)
{
$wids = array();
$_SESSION['loaded_widgets'] = $loaded_widgets;
}
preg_match_all('#\$this->widget\([\'"](.+?)[\'"]\);#',
file_get_contents(THEMES_PATH . $this->conf->getServerConfElement('theme') . '/' . $template),
$wids);
$this->widgets = $wids[1];
public function getLoadedWidgets()
{
$this->widgets = $_SESSION['loaded_widgets'];
}
function runEvent($type, $event)
@ -50,4 +48,4 @@ class EventHandler
}
}
?>
?>

15
lib/Jaxl/CHANGELOG

@ -1,5 +1,20 @@
version 2.1.2
-------------
- Added option to pass getSXE option to Jaxl constructor (Whether Jaxl core should return a SimpleXMLElement object of parsed string with callback payloads)
- Better handling for multi-instance jaxl applications (Use JAXL::addCore to add new instance)
Simple method of issuing unique id to each connected jaxl instance
Improved dumpStat cron to include send/rcv rate, buffer sizes in stats
Core logged class prefix log data with instance uid, pid and current clock
Parse class return false if unable to parse as xml for recv'd xmpp packet
Lots of core improvement in XMPP base class related to performance and multi-instance app handling
- Updated core class files to make use of JAXL::executePlugin method instead of JAXLPlugin::execute method
- XMPP base class now make use of socket_select() to poll opened stream efficiently (getting rid of annoying sleep)
Updated JAXLCron method to adjust to new core changes
- Added hook for jaxl_get_bosh_curl_error which is called when bosh end point returns a non-zero errno
Updated Jaxl core session variable names to avoid clash with existing session vars
Updated boshchat.php to make use of jaxl_get_bosh_curl_error to disconnect intelligently
- PHP CMS looking to integrate Jaxl in their core can now force disable auto start of php session by Jaxl core
Simple pass 'boshSession' as false with jaxl constructor config array
- Entire Jaxl core including xmpp/, xep/ and core/ class files now make use of JAXL::addPlugin instead of JAXLPlugin to register per instance callbacks
- JAXLPlugin can now register a callback for a dedicated jaxl instance in a multi-instance jaxl application
Class functionality remains backward compatible.

8
lib/Jaxl/README.md

@ -4,19 +4,17 @@ Jaxl 2.x is an object oriented XMPP framework in PHP for developing real time ap
for browsers, desktops and hand held devices. Jaxl 2.x is a robust, flexible and easy to use
version of Jaxl 1.x series which was hosted at google code.
* More robust, flexible, scalable and easy to use
* Event mechanism for registering callbacks for various xmpp events
* More robust, flexible, scalable and easy to use with event mechanism for registering callbacks for xmpp events
* Integrated support for Real Time Web (XMPP over Bosh) application development
* Support for DIGEST-MD5, PLAIN, ANONYMOUS, X-FACEBOOK-PLATFORM authentication mechanisms
* 32 implemented XMPP extensions [(XEP's)](http://xmpp.org/extensions/) including MUC, PubSub and PEP
* Setup dynamic number of parallel XMPP sessions on the fly
* Options for monitoring, usage stat collection, rate limiting, etc.
* Setup dynamic number of parallel XMPP instance on the fly
* Monitoring, Usage stat collection, rate limiting and other goodies
## Download
* For better experience download [latest stable tarball](http://code.google.com/p/jaxl/downloads/list) from *google code*
* The development version of Jaxl is hosted here at *Github*, have fun cloning the source code with Git
* Checkout Jaxl 1.x series source code from [svn repository (deprecated)](http://code.google.com/p/jaxl/source/browse/)
Warning: The development source code at Github is only intended for people that want to develop Jaxl or absolutely need the latest features still not available on the stable releases.

111
lib/Jaxl/core/jaxl.class.php

@ -46,7 +46,7 @@
// Set JAXL_BASE_PATH if not already defined by application code
if(!@constant('JAXL_BASE_PATH'))
define('JAXL_BASE_PATH', dirname(dirname(__FILE__)));
/**
* Autoload method for Jaxl library and it's applications
*
@ -94,6 +94,10 @@
return;
}
// cnt of connected instances
global $jaxl_instance_cnt;
$jaxl_instance_cnt = 0;
// Include core classes and xmpp base
jaxl_require(array(
'JAXLog',
@ -104,7 +108,7 @@
'XML',
'XMPP',
));
/**
* Jaxl class extending base XMPP class
*
@ -306,6 +310,8 @@
*/
var $openSSL = false;
var $instances = false;
/**
* @return string $name Returns name of this Jaxl client
*/
@ -344,7 +350,7 @@
*/
function shutdown($signal=false) {
$this->log("[[JAXL]] Shutting down ...");
JAXLPlugin::execute('jaxl_pre_shutdown', $signal, $this);
$this->executePlugin('jaxl_pre_shutdown', $signal);
if($this->stream) $this->endStream();
$this->stream = false;
}
@ -566,6 +572,22 @@
JAXLPlugin::remove($hook, $callback, $priority, $this->uid);
}
/**
* Use this method instead of JAXLPlugin::remove to remove a callback for connected instance only
*/
function executePlugin($hook, $payload) {
return JAXLPlugin::execute($hook, $payload, $this);
}
/**
* Add another jaxl instance in a running core
*/
function addCore($jaxl) {
$jaxl->addPlugin('jaxl_post_connect', array($jaxl, 'startStream'));
$jaxl->connect();
$this->instances['xmpp'][] = $jaxl;
}
/**
* Starts Jaxl Core
*
@ -579,7 +601,10 @@
* b) startComponent
* c) startBosh
*/
function startCore($mode=false) {
function startCore(/* $mode, $param1, $param2, ... */) {
$argv = func_get_args();
$mode = $argv[0];
if($mode) {
switch($mode) {
case 'stream':
@ -619,9 +644,6 @@
* startHTTPd converts Jaxl instance into a Jaxl socket server (may or may not be a HTTP server)
* Same Jaxl socket server instance <b>SHOULD NOT</b> be used for XMPP communications.
* Instead separate "new Jaxl();" instances should be created for such XMPP communications.
*
* @param integer $port Port at which to start the socket server
* @param integer $maxq JAXLHTTPd socket server max queue
*/
function startHTTPd($port, $maxq) {
JAXLHTTPd::start(array(
@ -656,11 +678,13 @@
* @todo Use DNS SRV lookup to set $jaxl->host from provided domain info
*/
function __construct($config=array()) {
global $jaxl_instance_cnt;
parent::__construct($config);
$this->uid = ++$jaxl_instance_cnt;
$this->ip = gethostbyname(php_uname('n'));
$this->mode = (PHP_SAPI == "cli") ? PHP_SAPI : "cgi";
$this->config = $config;
$this->pid = getmypid();
$this->uid = rand(10, 99999);
/* Mandatory params to be supplied either by jaxl.ini constants or constructor $config array */
$this->user = $this->getConfigByPriority(@$config['user'], "JAXL_USER_NAME", $this->user);
@ -671,12 +695,13 @@
/* Optional params if not configured using jaxl.ini or $config take default values */
$this->host = $this->getConfigByPriority(@$config['host'], "JAXL_HOST_NAME", $this->domain);
$this->port = $this->getConfigByPriority(@$config['port'], "JAXL_HOST_PORT", $this->port);
$this->resource = $this->getConfigByPriority(@$config['resource'], "JAXL_USER_RESC", "jaxl.".time());
$this->resource = $this->getConfigByPriority(@$config['resource'], "JAXL_USER_RESC", "jaxl.".$this->uid.".".$this->clocked);
$this->logLevel = $this->getConfigByPriority(@$config['logLevel'], "JAXL_LOG_LEVEL", $this->logLevel);
$this->logRotate = $this->getConfigByPriority(@$config['logRotate'], "JAXL_LOG_ROTATE", $this->logRotate);
$this->logPath = $this->getConfigByPriority(@$config['logPath'], "JAXL_LOG_PATH", $this->logPath);
if(!file_exists($this->logPath) && !touch($this->logPath)) throw new JAXLException("Log file ".$this->logPath." doesn't exists");
$this->pidPath = $this->getConfigByPriority(@$config['pidPath'], "JAXL_PID_PATH", $this->pidPath);
$this->mode = $this->getConfigByPriority(@$config['mode'], "JAXL_MODE", (PHP_SAPI == "cli") ? PHP_SAPI : "cgi");
if($this->mode == "cli" && !file_exists($this->pidPath) && !touch($this->pidPath)) throw new JAXLException("Pid file ".$this->pidPath." doesn't exists");
/* Resolve temporary folder path */
@ -697,21 +722,26 @@
$this->sigh = isset($config['sigh']) ? $config['sigh'] : true;
$this->dumpStat = isset($config['dumpStat']) ? $config['dumpStat'] : 300;
/* Configure instance for platforms and call parent construct */
/* Configure instance for platforms */
$this->configure($config);
parent::__construct($config);
/* Initialize xml to array class (will deprecate in future) */
$this->xml = new XML();
/* Initialize JAXLCron and register instance cron jobs */
/* Initialize JAXLCron and register core jobs */
JAXLCron::init($this);
if($this->dumpStat) JAXLCron::add(array($this, 'dumpStat'), $this->dumpStat);
if($this->logRotate) JAXLCron::add(array('JAXLog', 'logRotate'), $this->logRotate);
// include service discovery XEP-0030 and it's extensions, recommended for every XMPP entity
/* include recommended XEP's for every XMPP entity */
$this->requires(array(
'JAXL0030',
'JAXL0128'
'JAXL0030', // service discovery
'JAXL0128' // entity capabilities
));
/* initialize multi-core instance holder */
if($jaxl_instance_cnt == 1) $this->instances = array('xmpp'=>array(),'http'=>array());
$this->instances['xmpp'][] = $this;
}
/**
@ -732,18 +762,18 @@
if(!JAXLUtil::isWin() && JAXLUtil::pcntlEnabled() && $this->sigh) {
pcntl_signal(SIGTERM, array($this, "shutdown"));
pcntl_signal(SIGINT, array($this, "shutdown"));
$this->log("[[JAXL]] Registering callbacks for CTRL+C and kill.");
$this->log("[[JAXL]] Registering callbacks for CTRL+C and kill.", 4);
}
else {
$this->log("[[JAXL]] No callbacks registered for CTRL+C and kill.");
$this->log("[[JAXL]] No callbacks registered for CTRL+C and kill.", 4);
}
// check Jaxl dependency on PHP extension in cli mode
if($this->mode == "cli") {
if(($this->openSSL = JAXLUtil::sslEnabled()))
$this->log("[[JAXL]] OpenSSL extension is loaded.");
$this->log("[[JAXL]] OpenSSL extension is loaded.", 4);
else
$this->log("[[JAXL]] OpenSSL extension not loaded.");
$this->log("[[JAXL]] OpenSSL extension not loaded.", 4);
if(!function_exists('fsockopen'))
throw new JAXLException("[[JAXL]] Requires fsockopen method");
@ -768,10 +798,13 @@
* Jaxl instance periodically calls this methods every JAXL::$dumpStat seconds.
*/
function dumpStat() {
$stat = "[[JAXL]] Memory usage: ".round(memory_get_usage()/pow(1024,2), 2)." Mb";
if(function_exists('memory_get_peak_usage'))
$stat .= ", Peak usage: ".round(memory_get_peak_usage()/pow(1024,2), 2)." Mb";
$this->log($stat, 0);
$stat = "[[JAXL]] Memory:".round(memory_get_usage()/pow(1024,2), 2)."Mb";
if(function_exists('memory_get_peak_usage')) $stat .= ", PeakMemory:".round(memory_get_peak_usage()/pow(1024,2), 2)."Mb";
$stat .= ", obuffer: ".strlen($this->obuffer);
$stat .= ", buffer: ".strlen($this->buffer);
$stat .= ", RcvdRate: ".$this->totalRcvdSize/$this->clock."Kb";
$stat .= ", SentRate: ".$this->totalSentSize/$this->clock."Kb";
$this->log($stat, 1);
}
/**
@ -792,9 +825,15 @@
$xep = substr($xep, 4, 4);
if(is_numeric($xep)
&& class_exists('JAXL'.$xep)
) { return call_user_func_array(array('JAXL'.$xep, $method), $param); }
) {
$this->log("[[JAXL]] Calling JAXL$xep method ".$method, 5);
return call_user_func_array(array('JAXL'.$xep, $method), $param);
}
else { $this->log("[[JAXL]] JAXL$xep Doesn't exists in the environment"); }
}
else {
$this->log("[[JAXL]] Call to an unidentified XEP");
}
}
/**
@ -823,23 +862,23 @@
* Core method that accepts retrieved roster list and manage local cache
*/
function _handleRosterList($payload, $jaxl) {
if(is_array($payload['queryItemJid'])) {
if(@is_array($payload['queryItemJid'])) {
foreach($payload['queryItemJid'] as $key=>$jid) {
$this->_addRosterNode($jid);
$this->roster[$jid]['groups'] = $payload['queryItemGrp'][$key];
$this->roster[$jid]['name'] = $payload['queryItemName'][$key];
$this->roster[$jid]['subscription'] = $payload['queryItemSub'][$key];
$this->roster[$jid]['groups'] = @$payload['queryItemGrp'][$key];
$this->roster[$jid]['name'] = @$payload['queryItemName'][$key];
$this->roster[$jid]['subscription'] = @$payload['queryItemSub'][$key];
}
}
else {
$jid = $payload['queryItemJid'];
$jid = @$payload['queryItemJid'];
$this->_addRosterNode($jid);
$this->roster[$jid]['groups'] = $payload['queryItemGrp'];
$this->roster[$jid]['name'] = $payload['queryItemName'];
$this->roster[$jid]['subscription'] = $payload['queryItemSub'];
$this->roster[$jid]['groups'] = @$payload['queryItemGrp'];
$this->roster[$jid]['name'] = @$payload['queryItemName'];
$this->roster[$jid]['subscription'] = @$payload['queryItemSub'];
}
JAXLPlugin::execute('jaxl_post_roster_update', $payload, $this);
$this->executePlugin('jaxl_post_roster_update', $payload);
return $payload;
}
@ -864,10 +903,10 @@
) {
$this->subscribed($payload['from']);
$this->subscribe($payload['from']);
JAXLPlugin::execute('jaxl_post_subscription_request', $payload, $this);
$this->executePlugin('jaxl_post_subscription_request', $payload);
}
else if($payload['type'] == 'subscribed') {
JAXLPlugin::execute('jaxl_post_subscription_accept', $payload, $this);
$this->executePlugin('jaxl_post_subscription_accept', $payload);
}
}
return $payloads;

11
lib/Jaxl/core/jaxl.cron.php

@ -47,7 +47,7 @@
* Add periodic cron in your xmpp applications
*/
class JAXLCron {
private static $cron = array();
public static function init($jaxl) {
@ -57,12 +57,14 @@
public static function ticker($payload, $jaxl) {
foreach(self::$cron as $interval => $jobs) {
foreach($jobs as $key => $job) {
if($jaxl->clock % $interval == 0 // if cron interval matches
|| $jaxl->clocked - $job['lastCall'] > $interval // if cron interval has already passed
if($jaxl->clock != 0
&& $jaxl->clocked - $job['lastCall'] > $interval // if cron interval has already passed
) {
self::$cron[$interval][$key]['lastCall'] = $jaxl->clocked;
$arg = $job['arg'];
array_unshift($arg, $jaxl);
$jaxl->log("[[JAXLCron]] Executing cron job\nInterval:$interval, Callback:".$job['callback'], 5);
call_user_func_array($job['callback'], $arg);
}
}
@ -74,11 +76,10 @@
$arg = func_get_args();
$callback = array_shift($arg);
$interval = array_shift($arg);
self::$cron[$interval][self::generateCbSignature($callback)] = array('callback'=>$callback, 'arg'=>$arg, 'lastCall'=>time());
}
public static function delete($callback, $interval) {
public static function delete($callback, $interval) {
$sig = self::generateCbSignature($callback);
if(isset(self::$cron[$interval][$sig]))
unset(self::$cron[$interval][$sig]);

8
lib/Jaxl/core/jaxl.logger.php

@ -47,11 +47,11 @@
class JAXLog {
public static function log($log, $level=1, $jaxl=false) {
$log = '['.$jaxl->pid.':'.$jaxl->uid.'] '.date('Y-m-d H:i:s')." - ".$log;
if($level <= $jaxl->logLevel
||($level == 0 && $jaxl->mode == "cli"))
error_log($log."\n\n", 3, $jaxl->logPath);
||($level == 0 && $jaxl->mode == "cli")) {
$log = '['.$jaxl->uid.':'.$jaxl->pid.':'.$jaxl->clock.'] '.date('Y-m-d H:i:s')." - ".$log;
error_log($log."\n\n", 3, $jaxl->logPath);
}
return true;
}

3
lib/Jaxl/core/jaxl.parser.php

@ -145,7 +145,8 @@
$payload = array();
$xml = str_replace('xmlns=', 'ns=', $xml);
$xml = new SimpleXMLElement($xml);
try { $xml = @new SimpleXMLElement($xml); }
catch(Exception $e) { return false; }
$node = $xml->getName();
$parents = array();

2
lib/Jaxl/core/jaxl.plugin.php

@ -106,7 +106,7 @@
foreach(self::$registry[$uid][$hook] as $priority) {
foreach($priority as $callback) {
if($filter === false || (is_array($filter) && in_array($callback[0], $filter))) {
//$jaxl->log("[[JAXLPlugin]] Executing hook $hook for uid $uid", 5);
$jaxl->log("[[JAXLPlugin]] Executing hook $hook for uid $uid", 7);
$payload = call_user_func($callback, $payload, $jaxl);
}
}

4
lib/Jaxl/core/jaxl.util.php

@ -88,8 +88,8 @@
}
public static function getTime() {
list($usec, $sec) = explode(" ",microtime());
return (float) $sec + (float) $usec;
list($usec, $sec) = explode(" ", microtime());
return (float) $sec + (float) $usec;
}
public static function splitXML($xml) {

45
lib/Jaxl/xep/jaxl.0004.php

@ -61,16 +61,14 @@
$payload .= '<x xmlns="'.self::$ns.'" type="'.$type.'">';
if($title) $payload .= '<title>'.$title.'</title>';
if($inst) $payload .= '<instruction>'.$inst.'</instruction>';
foreach($fields as $field) {
$payload .= '<field var="'.$field['var'].'">';
$payload .= '<value>'.$field['value'].'</value>';
$payload .= '</field>';
}
$payload .= '</x>';
foreach($fields as $field) {
$payload .= '<field var="'.$field['var'].'">';
$payload .= '<value>'.$field['value'].'</value>';
$payload .= '</field>';
}
$payload .= '</x>';
unset($fields); unset($title); unset($inst); unset($type);
return $payload;
unset($payload);
}
/*
@ -78,30 +76,27 @@
*/
public static function getFormField($fields) {
$result = array();
foreach($fields as $field) {
$f = array();
$f['type'] = $field['@']['type'];
$f['label'] = $field['@']['label'];
$f['var'] = $field['@']['var'];
foreach($fields as $field) {
$f = array();
$f['type'] = $field['@']['type'];
$f['label'] = $field['@']['label'];
$f['var'] = $field['@']['var'];
$f['desc'] = $field['#']['desc'][0]['#'];
$f['required'] = $field['#']['required'][0]['#'];
$f['value'] = $field['#']['value'][0]['#'];
$f['desc'] = $field['#']['desc'][0]['#'];
$f['required'] = $field['#']['required'][0]['#'];
$f['value'] = $field['#']['value'][0]['#'];
if(is_array($field['#']['option'])) {
$f['option'] = array();
foreach($field['#']['option'] as $option) {
$f['option'][] = array('label'=>$option['@']['label'], 'value'=>$option['#']['value'][0]['#']);
}
foreach($field['#']['option'] as $option) {
$f['option'][] = array('label'=>$option['@']['label'], 'value'=>$option['#']['value'][0]['#']);
}
}
$result[] = $f;
}
unset($f); unset($field); unset($fields);
$result[] = $f;
}
return $result;
unset($result);
}
}

4
lib/Jaxl/xep/jaxl.0114.php

@ -55,7 +55,7 @@
// parse user options
$jaxl->comp['host'] = $jaxl->getConfigByPriority(@$jaxl->config['compHost'], "JAXL_COMPONENT_HOST", $jaxl->comp['host']);
$jaxl->pass['pass'] = $jaxl->getConfigByPriority(@$jaxl->config['compPass'], "JAXL_COMPONENT_PASS", $jaxl->comp['pass']);
$jaxl->comp['pass'] = $jaxl->getConfigByPriority(@$jaxl->config['compPass'], "JAXL_COMPONENT_PASS", $jaxl->comp['pass']);
// register required callbacks
$jaxl->addPlugin('jaxl_post_start', array('JAXL0114', 'handshake'));
@ -76,7 +76,7 @@
public static function preHandler($xml, $jaxl) {
if($xml == '<handshake/>') {
$xml = '';
JAXLPlugin::execute('jaxl_post_handshake', false, $jaxl);
$jaxl->executePlugin('jaxl_post_handshake', false);
}
return $xml;
}

90
lib/Jaxl/xep/jaxl.0124.php

@ -75,7 +75,8 @@
'headers' => array('Accept-Encoding: gzip, deflate','Content-Type: text/xml; charset=utf-8'),
'xmlns' => 'http://jabber.org/protocol/httpbind',
'xmlnsxmpp' => 'urn:xmpp:xbosh',
'url' => 'http://localhost:5280/http-bind'
'url' => 'http://localhost:5280/http-bind',
'session' => true
);
// parse user options
@ -83,23 +84,18 @@
$jaxl->bosh['port'] = $jaxl->getConfigByPriority(@$jaxl->config['boshPort'], "JAXL_BOSH_PORT", $jaxl->bosh['port']);
$jaxl->bosh['suffix'] = $jaxl->getConfigByPriority(@$jaxl->config['boshSuffix'], "JAXL_BOSH_SUFFIX", $jaxl->bosh['suffix']);
$jaxl->bosh['out'] = $jaxl->getConfigByPriority(@$jaxl->config['boshOut'], "JAXL_BOSH_OUT", $jaxl->bosh['out']);
$jaxl->bosh['session'] = $jaxl->getConfigByPriority(@$jaxl->config['boshSession'], "JAXL_BOSH_SESSION", $jaxl->bosh['session']);
$jaxl->bosh['url'] = "http://".$jaxl->bosh['host'].":".$jaxl->bosh['port']."/".$jaxl->bosh['suffix']."/";
// cookie params
$jaxl->bosh['cookie']['ttl'] = $jaxl->getConfigByPriority(@$jaxl->config['boshCookieTTL'], "JAXL_BOSH_COOKIE_TTL", $jaxl->bosh['cookie']['ttl']);
$jaxl->bosh['cookie']['path'] = $jaxl->getConfigByPriority(@$jaxl->config['boshCookiePath'], "JAXL_BOSH_COOKIE_PATH", $jaxl->bosh['cookie']['path']);
$jaxl->bosh['cookie']['domain'] = $jaxl->getConfigByPriority(@$jaxl->config['boshCookieDomain'], "JAXL_BOSH_COOKIE_DOMAIN", $jaxl->bosh['cookie']['domain']);
$jaxl->bosh['cookie']['https'] = $jaxl->getConfigByPriority(@$jaxl->config['boshCookieHTTPS'], "JAXL_BOSH_COOKIE_HTTPS", $jaxl->bosh['cookie']['https']);
$jaxl->bosh['cookie']['httponly'] = $jaxl->getConfigByPriority(@$jaxl->config['boshCookieHTTPOnly'], "JAXL_BOSH_COOKIE_HTTP_ONLY", $jaxl->bosh['cookie']['httponly']);
session_set_cookie_params(
$jaxl->bosh['cookie']['ttl'],
$jaxl->bosh['cookie']['path'],
$jaxl->bosh['cookie']['domain'],
$jaxl->bosh['cookie']['https'],
$jaxl->bosh['cookie']['httponly']
);
session_start();
// start session
self::startSession($jaxl);
$jaxl->addPlugin('jaxl_post_bind', array('JAXL0124', 'postBind'));
$jaxl->addPlugin('jaxl_send_xml', array('JAXL0124', 'wrapBody'));
@ -109,10 +105,25 @@
self::loadSession($jaxl);
}
public static function startSession($jaxl) {
if(!$jaxl->bosh['session']) {
$jaxl->log("[[JAXL0124]] Not starting session as forced by constructor config", 5);
return;
}
session_set_cookie_params(
$jaxl->bosh['cookie']['ttl'],
$jaxl->bosh['cookie']['path'],
$jaxl->bosh['cookie']['domain'],
$jaxl->bosh['cookie']['https'],
$jaxl->bosh['cookie']['httponly']
);
session_start();
}
public static function postHandler($payload, $jaxl) {
if(!$jaxl->bosh['out']) return $payload;
$payload = json_encode(self::$buffer);
$jaxl->log("[[BoshOut]]\n".$payload, 5);
header($jaxl->bosh['outheaders']);
@ -122,7 +133,7 @@
public static function postBind($payload, $jaxl) {
$jaxl->bosh['jid'] = $jaxl->jid;
$_SESSION['auth'] = true;
$_SESSION['jaxl_auth'] = true;
return;
}
@ -131,35 +142,36 @@
}
public static function loadSession($jaxl) {
$jaxl->bosh['rid'] = isset($_SESSION['rid']) ? (string) $_SESSION['rid'] : rand(1000, 10000);
$jaxl->bosh['sid'] = isset($_SESSION['sid']) ? (string) $_SESSION['sid'] : false;
$jaxl->lastid = isset($_SESSION['id']) ? $_SESSION['id'] : $jaxl->lastid;
$jaxl->jid = isset($_SESSION['jid']) ? $_SESSION['jid'] : $jaxl->jid;
$jaxl->log("Loading session data\n".json_encode($_SESSION), 5);
$jaxl->bosh['rid'] = isset($_SESSION['jaxl_rid']) ? (string) $_SESSION['jaxl_rid'] : rand(1000, 10000);
$jaxl->bosh['sid'] = isset($_SESSION['jaxl_sid']) ? (string) $_SESSION['jaxl_sid'] : false;
$jaxl->lastid = isset($_SESSION['jaxl_id']) ? $_SESSION['jaxl_id'] : $jaxl->lastid;
$jaxl->jid = isset($_SESSION['jaxl_jid']) ? $_SESSION['jaxl_jid'] : $jaxl->jid;
$jaxl->log("[[JAXL0124]] Loading session data\n".json_encode($_SESSION), 5);
}
public static function saveSession($xml, $jaxl) {
if($_SESSION['auth'] === true) {
$_SESSION['rid'] = isset($jaxl->bosh['rid']) ? $jaxl->bosh['rid'] : false;
$_SESSION['sid'] = isset($jaxl->bosh['sid']) ? $jaxl->bosh['sid'] : false;
$_SESSION['jid'] = $jaxl->jid;
$_SESSION['id'] = $jaxl->lastid;
if($jaxl->bosh['out'])
if($_SESSION['jaxl_auth'] === true) {
$_SESSION['jaxl_rid'] = isset($jaxl->bosh['rid']) ? $jaxl->bosh['rid'] : false;
$_SESSION['jaxl_sid'] = isset($jaxl->bosh['sid']) ? $jaxl->bosh['sid'] : false;
$_SESSION['jaxl_jid'] = $jaxl->jid;
$_SESSION['jaxl_id'] = $jaxl->lastid;
if($jaxl->bosh['out'] && $jaxl->bosh['session']) {
session_write_close();
}
if(self::$sess && $jaxl->bosh['out']) {
list($body, $xml) = self::unwrapBody($xml);
$jaxl->log("[[".$_REQUEST['jaxl']."]] Auth complete, sync now\n".json_encode($_SESSION), 5);
$jaxl->log("[[JAXL0124]] Auth complete, sync now\n".json_encode($_SESSION), 5);
return self::out(array('jaxl'=>'jaxl', 'xml'=>urlencode($xml)));
}
else {
self::$sess = true;
$jaxl->log("[[".$_REQUEST['jaxl']."]] Auth complete, commiting session now\n".json_encode($_SESSION), 5);
$jaxl->log("[[JAXL0124]] Auth complete, commiting session now\n".json_encode($_SESSION), 5);
}
}
else {
$jaxl->log("[[".$_REQUEST['jaxl']."]] Not authed yet, Not commiting session\n".json_encode($_SESSION), 5);
$jaxl->log("[[JAXL0124]] Not authed yet, Not commiting session\n".json_encode($_SESSION), 5);
}
return $xml;
@ -167,7 +179,6 @@
public static function wrapBody($xml, $jaxl) {
$body = trim($xml);
if(substr($body, 1, 4) != 'body') {
$body = '';
$body .= '<body rid="'.++$jaxl->bosh['rid'].'"';
@ -175,10 +186,8 @@
$body .= ' xmlns="http://jabber.org/protocol/httpbind">';
$body .= $xml;
$body .= "</body>";
$_SESSION['rid'] = $jaxl->bosh['rid'];
$_SESSION['jaxl_rid'] = $jaxl->bosh['rid'];
}
return $body;
}
@ -201,6 +210,8 @@
default:
break;
}
$jaxl->executePlugin('jaxl_get_bosh_curl_error', $payload);
$jaxl->log($log);
}
@ -228,21 +239,22 @@
list($body, $payload) = self::unwrapBody($payload);
if($payload == '') {
if($_SESSION['auth'] === 'disconnect') {
$_SESSION['auth'] = false;
JAXLPlugin::execute('jaxl_post_disconnect', $body, $jaxl);
if($_SESSION['jaxl_auth'] === 'disconnect') {
$_SESSION['jaxl_auth'] = false;
$jaxl->executePlugin('jaxl_post_disconnect', $body);
}
else {
JAXLPlugin::execute('jaxl_get_empty_body', $body, $jaxl);
$jaxl->executePlugin('jaxl_get_empty_body', $body);
}
}
if($_SESSION['auth'] === 'connect') {
if($_SESSION['jaxl_auth'] === 'connect') {
$arr = $jaxl->xml->xmlize($body);
if(isset($arr["body"]["@"]["sid"])) {
$_SESSION['auth'] = false;
$_SESSION['sid'] = $arr["body"]["@"]["sid"];
$_SESSION['jaxl_auth'] = false;
$_SESSION['jaxl_sid'] = $arr["body"]["@"]["sid"];
$jaxl->bosh['sid'] = $arr["body"]["@"]["sid"];
$jaxl->log("[[JAXL0124]] Updated session to ".json_encode($_SESSION), 5);
}
}
}

26
lib/Jaxl/xep/jaxl.0133.php

@ -65,7 +65,8 @@
return JAXL0050::executeCommand($jaxl, $to, $from, self::$node."#".$type, $callback);
}
public static function handleForm($payload) {
public static function handleForm($payload, $jaxl) {
print_r($payload);
$id = $payload['iq']['@']['id'];
$domain = $payload['iq']['@']['from'];
$node = $payload['iq']['#']['command'][0]['@']['node'];
@ -121,84 +122,72 @@
public static function addUser($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'add-user');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function deleteUser($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'delete-user');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function disableUser($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'disable-user');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function reEnableUser($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'reenable-user');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function endUserSession($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'end-user-session');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function getUserPassword($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'get-user-password');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function changeUserPassword($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'change-user-password');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function getUserRoster($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'get-user-roster');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function getUserLastLoginTime($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'get-user-lastlogin');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function getUserStatistics($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'user-stats');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function editBlacklist($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'edit-blacklist');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function editWhitelist($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'edit-whitelist');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
@ -226,7 +215,6 @@
$id = self::requestForm($jaxl, $domain, false, $type);
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
@ -253,28 +241,24 @@
$id = self::requestForm($jaxl, $domain, false, $type);
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function sendAnnouncementToActiveUsers($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'announce');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function setMOTD($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'set-motd');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function editMOTD($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'edit-motd');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
@ -282,14 +266,12 @@
public static function deleteMOTD($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'delete-motd');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function setWelcomeMessage($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'set-welcome');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
@ -297,28 +279,24 @@
public static function deleteWelcomeMessage($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'delete-welcome');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function editAdminList($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'edit-admin');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function restartService($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'restart');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}
public static function shutdownService($jaxl, $user, $domain, $callback) {
$id = self::requestForm($jaxl, $domain, false, 'shutdown');
self::$buffer[$id] = array('user'=>$user, 'callback'=>$callback);
unset($user); unset($domain); unset($callback);
return true;
}

2
lib/Jaxl/xep/jaxl.0199.php

@ -61,7 +61,7 @@
}
public static function handleIq($payload, $jaxl) {
if($payload['ping'] == self::$ns)
if(@$payload['ping'] == self::$ns)
return XMPPSend::iq($jaxl, 'result', false, $payload['from'], $payload['to'], false, $payload['id']);
return $payload;
}

2
lib/Jaxl/xep/jaxl.0202.php

@ -64,7 +64,7 @@
}
public static function handleIq($payload, $jaxl) {
if($payload['time'] == self::$ns) {
if(@$payload['time'] == self::$ns) {
$entityTime = '<time xmlns="'.self::$ns.'">';
$entityTime .= '<tzo>'.date('P').'</tzo>';
$entityTime .= '<utc>'.date('Y-m-d').'T'.date('H:i:s').'Z</utc>';

15
lib/Jaxl/xep/jaxl.0206.php

@ -40,7 +40,7 @@
* @copyright Abhinav Singh
* @link http://code.google.com/p/jaxl
*/
/**
* XEP-0206: XMPP over BOSH
*
@ -49,9 +49,10 @@
class JAXL0206 {
public static function init($jaxl) {
// Requires Bosh Session Manager
$jaxl->requires('JAXL0124');
$jaxl->log("[[JaxlAction]] ".$_REQUEST['jaxl']."\n".json_encode($_REQUEST), 5);
// Requires Bosh Session Manager
$jaxl->requires('JAXL0124');
}
public static function jaxl($jaxl, $xml) {
@ -59,7 +60,7 @@
}
public static function startStream($jaxl) {
$_SESSION['auth'] = 'connect';
$_SESSION['jaxl_auth'] = 'connect';
$xml = "";
$xml .= "<body";
@ -80,7 +81,7 @@
}
public static function endStream($jaxl) {
$_SESSION['auth'] = 'disconnect';
$_SESSION['jaxl_auth'] = 'disconnect';
$xml = "";
$xml .= "<body";
@ -105,7 +106,7 @@
$xml .= " xmpp:restart='true'";
$xml .= " xmlns:xmpp='".$jaxl->bosh['xmlnsxmpp']."'/>";
$_SESSION['auth'] = false;
$_SESSION['jaxl_auth'] = false;
$jaxl->sendXML($xml);
}
@ -115,7 +116,7 @@
$xml .= ' sid="'.$jaxl->bosh['sid'].'"';
$xml .= ' xmlns="http://jabber.org/protocol/httpbind"/>';
$_SESSION['auth'] = true;
$_SESSION['jaxl_auth'] = true;
$jaxl->sendXML($xml);
}

4
lib/Jaxl/xmpp/xmpp.auth.php

@ -66,9 +66,9 @@
unset($decoded[$k]);
}
list($secret, $decoded['api_key'], $decoded['session_key']) = JAXLPlugin::execute('jaxl_get_facebook_key', false, $jaxl);
list($secret, $decoded['api_key'], $decoded['session_key']) = $jaxl->executePlugin('jaxl_get_facebook_key', false);
$decoded['call_id'] = time();
$decoded['call_id'] = $jaxl->clock;
$decoded['v'] = '1.0';
$base_string = '';

285
lib/Jaxl/xmpp/xmpp.class.php

@ -40,7 +40,7 @@
* @copyright Abhinav Singh
* @link http://code.google.com/p/jaxl
*/
// include required classes
jaxl_require(array(
'JAXLPlugin',
@ -136,36 +136,7 @@
*
* @var bool
*/
var $streamBlocking = 0;
/**
* Nap in seconds between two socket reads
*
* @var integer
*/
var $getSleep = 1;
/**
* Number of packets to read in one socket read
*
* @var integer
*/
var $getPkts = false;
/**
* Size of each packet to be read from the socket
*/
var $getPktSize = false;
/**
* Number of empty packet read before aborting further reads
*/
var $getEmptyLines = false;
/**
* Maximum rate at which XMPP stanza's can flow out
*/
var $sendRate = false;
var $streamBlocking = 1;
/**
* Input XMPP stream buffer
@ -177,6 +148,11 @@
*/
var $obuffer = '';
/**
* Instance start time
*/
var $startTime = false;
/**
* Current value of instance clock
*/
@ -197,21 +173,50 @@
*/
var $lastSendTime = false;
/**
* Maximum rate at which XMPP stanza's can flow out
*/
var $sendRate = false;
/**
* Size of each packet to be read from the socket
*/
var $getPktSize = false;
/**
* Read select timeouts
*/
var $getSelectSecs = 5;
var $getSelectUsecs = 0;
/**
* Packet count and sizes
*/
var $totalRcvdPkt = 0;
var $totalRcvdSize = 0;
var $totalSentPkt = 0;
var $totalSentSize = 0;
/**
* Whether Jaxl core should return a SimpleXMLElement object of parsed string with callback payloads?
*/
var $getSXE = false;
/**
* XMPP constructor
*/
function __construct($config) {
$this->clock = 0;
$this->clocked = time();
$this->clocked = $this->startTime = time();
/* Parse configuration parameter */
$this->lastid = rand(1, 9);
$this->streamTimeout = isset($config['streamTimeout']) ? $config['streamTimeout'] : 20;
$this->rateLimit = isset($config['rateLimit']) ? $config['rateLimit'] : true;
$this->getPkts = isset($config['getPkts']) ? $config['getPkts'] : 1600;
$this->getPktSize = isset($config['getPktSize']) ? $config['getPktSize'] : 2048;
$this->getEmptyLines = isset($config['getEmptyLines']) ? $config['getEmptyLines'] : 15;
$this->sendRate = isset($config['sendRate']) ? $config['sendRate'] : 0.1;
$this->getPktSize = isset($config['getPktSize']) ? $config['getPktSize'] : 4096;
$this->sendRate = isset($config['sendRate']) ? $config['sendRate'] : .4;
$this->getSelectSecs = isset($config['getSelectSecs']) ? $config['getSelectSecs'] : 5;
$this->getSXE = isset($config['getSXE']) ? $config['getSXE'] : false;
}
/**
@ -219,22 +224,22 @@
*/
function connect() {
if(!$this->stream) {
if($this->stream = @fsockopen($this->host, $this->port, $this->streamENum, $this->streamEStr, $this->streamTimeout)) {
$this->log("[[XMPP]] Socket opened to the jabber host ".$this->host.":".$this->port." ...");
if($this->stream = @stream_socket_client("tcp://{$this->host}:{$this->port}", $this->streamENum, $this->streamEStr, $this->streamTimeout)) {
$this->log("[[XMPP]] \nSocket opened to the jabber host ".$this->host.":".$this->port." ...");
stream_set_blocking($this->stream, $this->streamBlocking);
stream_set_timeout($this->stream, $this->streamTimeout);
}
else {
$this->log("[[XMPP]] Unable to open socket to the jabber host ".$this->host.":".$this->port." ...");
$this->log("[[XMPP]] \nUnable to open socket to the jabber host ".$this->host.":".$this->port." ...");
throw new JAXLException("[[XMPP]] Unable to open socket to the jabber host");
}
}
else {
$this->log("[[XMPP]] Socket already opened to the jabber host ".$this->host.":".$this->port." ...");
$this->log("[[XMPP]] \nSocket already opened to the jabber host ".$this->host.":".$this->port." ...");
}
$ret = $this->stream ? true : false;
JAXLPlugin::execute('jaxl_post_connect', $ret, $this);
$this->executePlugin('jaxl_post_connect', $ret);
return $ret;
}
@ -272,78 +277,106 @@
* @return integer $id
*/
function getId() {
$id = JAXLPlugin::execute('jaxl_get_id', ++$this->lastid, $this);
$id = $this->executePlugin('jaxl_get_id', ++$this->lastid);
if($id === $this->lastid) return dechex($this->uid + $this->lastid);
else return $id;
}
/**
* Read connected XMPP stream for new data
*/
function getXML($nap=TRUE) {
// sleep between two reads
if($nap) sleep($this->getSleep);
// initialize empty lines read
$emptyLine = 0;
// read previous buffer
$payload = $this->buffer;
$this->buffer = '';
// read socket data
for($i=0; $i<$this->getPkts; $i++) {
if($this->stream) {
$line = fread($this->stream, $this->getPktSize);
if(strlen($line) == 0) {
$emptyLine++;
if($emptyLine > $this->getEmptyLines)
break;
* $option = null (read until data is available)
* $option = integer (read for so many seconds)
*/
function getXML() {
// prepare select streams
$streams = array(); $jaxls = $this->instances['xmpp'];
foreach($jaxls as $cnt=>$jaxl) {
if($jaxl->stream) $streams[$cnt] = $jaxl->stream;
else unset($jaxls[$cnt]);
}
// get num changed streams
$read = $streams; $write = null; $except = null; $secs = $this->getSelectSecs; $usecs = $this->getSelectUsecs;
if(false === ($changed = @stream_select(&$read, &$write, &$except, $secs, $usecs))) {
$this->log("[[XMPPGet]] \nError while reading packet from stream", 5);
}
else {
$this->log("[[XMPPGet]] $changed streams ready for read out of total ".sizeof($streams)." streams", 7);
if($changed == 0) $now = $this->clocked+$secs;
else $now = time();
foreach($read as $k=>$r) {
// get jaxl instance we are dealing with
$ret = $payload = '';
$key = array_search($r, $streams);
$jaxl = $jaxls[$key];
unset($jaxls[$key]);
// update clock
if($now > $jaxl->clocked) {
$jaxl->clock += $now-$jaxl->clocked;
$jaxl->clocked = $now;
}
else {
$payload .= $line;
// reload pending buffer
$payload = $jaxl->buffer;
$jaxl->buffer = '';
// read stream
$ret = @fread($jaxl->stream, $jaxl->getPktSize);
if(trim($ret) != '') $jaxl->log("[[XMPPGet]] \n".$ret, 4);
$jaxl->totalRcvdSize = strlen($ret);
$ret = $jaxl->executePlugin('jaxl_get_xml', $ret);
$payload .= $ret;
// route packets
$jaxl->handler($payload);
// clear buffer
if($jaxl->obuffer != '') $jaxl->sendXML();
}
foreach($jaxls as $jaxl) {
// update clock
if($now > $jaxl->clocked) {
$jaxl->clock += $now-$jaxl->clocked;
$jaxl->clocked = $now;
$payload = $jaxl->executePlugin('jaxl_get_xml', '');
}
// clear buffer
if($jaxl->obuffer != '') $jaxl->sendXML();
}
}
// update clock
$now = time();
$this->clock += $now-$this->clocked;
$this->clocked = $now;
// trim read data
$payload = trim($payload);
$payload = JAXLPlugin::execute('jaxl_get_xml', $payload, $this);
if($payload != '') $this->handler($payload);
// flush obuffer
if($this->obuffer != '') {
$payload = $this->obuffer;
$this->obuffer = '';
$this->_sendXML($payload);
}
unset($jaxls, $streams);
return $changed;
}
/**
* Send XMPP XML packet over connected stream
*/
function sendXML($xml, $force=false) {
$xml = JAXLPlugin::execute('jaxl_send_xml', $xml, $this);
if($this->mode == "cgi") {
JAXLPlugin::execute('jaxl_send_body', $xml, $this);
function sendXML($xml='', $force=false) {
$xml = $this->executePlugin('jaxl_send_xml', $xml);
if($this->mode == "cgi") {
$this->executePlugin('jaxl_send_body', $xml);
}
else {
$currSendRate = ($this->totalSentSize/(JAXLUtil::getTime()-$this->lastSendTime))/1000000;
$this->obuffer .= $xml;
if($this->rateLimit
&& !$force
&& $this->lastSendTime
&& JAXLUtil::getTime() - $this->lastSendTime < $this->sendRate
) { $this->obuffer .= $xml; }
else {
$xml = $this->obuffer.$xml;
$this->obuffer = '';
return $this->_sendXML($xml);
&& ($currSendRate > $this->sendRate)
) {
$this->log("[[XMPPSend]] rateLimit\nBufferSize:".strlen($this->obuffer).", maxSendRate:".$this->sendRate.", currSendRate:".$currSendRate, 5);
return 0;
}
$xml = $this->obuffer;
$this->obuffer = '';
return ($xml == '') ? 0 : $this->_sendXML($xml);
}
}
@ -351,21 +384,40 @@
* Send XMPP XML packet over connected stream
*/
protected function _sendXML($xml) {
if($this->stream) {
$this->lastSendTime = JAXLUtil::getTime();
if(($ret = fwrite($this->stream, $xml)) !== false) {
if($this->stream && $xml != '') {
$read = array(); $write = array($this->stream); $except = array();
$secs = null; $usecs = null;
if(false === ($changed = @stream_select(&$read, &$write, &$except, $secs, $usecs))) {
$this->log("[[XMPPSend]] \nError while trying to send packet", 5);
throw new JAXLException("[[XMPPSend]] \nError while trying to send packet");
return 0;
}
else if($changed > 0) {
$this->lastSendTime = JAXLUtil::getTime();
$xmls = JAXLUtil::splitXML($xml);
$pktCnt = count($xmls);
$this->totalSentPkt += $pktCnt;
$ret = @fwrite($this->stream, $xml);
$this->totalSentSize += $ret;
$this->log("[[XMPPSend]] $ret\n".$xml, 4);
return $ret;
}
else {
$this->log("[[XMPPSend]] Failed\n".$xml);
throw new JAXLException("[[XMPPSend]] Failed");
throw new JAXLException("[[XMPPSend]] \nFailed");
return 0;
}
return $ret;
}
else if($xml == '') {
$this->log("[[XMPPSend]] Tried to send an empty stanza, not processing", 1);
return 0;
}
else {
$this->log("[[XMPPSend]] Jaxl stream not connected to jabber host, unable to send xmpp payload...");
$this->log("[[XMPPSend]] \nJaxl stream not connected to jabber host, unable to send xmpp payload...");
throw new JAXLException("[[XMPPSend]] Jaxl stream not connected to jabber host, unable to send xmpp payload...");
return false;
return 0;
}
}
@ -373,27 +425,27 @@
* Routes incoming XMPP data to appropriate handlers
*/
function handler($payload) {
$this->log("[[XMPPGet]] \n".$payload, 4);
$buffer = array();
$payload = JAXLPlugin::execute('jaxl_pre_handler', $payload, $this);
if($payload == '' && $this->mode == 'cli') return '';
if($payload != '' && $this->mode == 'cgi') $this->log("[[XMPPGet]] \n".$payload, 4);
$payload = $this->executePlugin('jaxl_pre_handler', $payload);
$xmls = JAXLUtil::splitXML($payload);
$pktCnt = count($xmls);
$this->totalRcvdPkt += $pktCnt;
$buffer = array();
foreach($xmls as $pktNo => $xml) {
foreach($xmls as $pktNo => $xml) {
if($pktNo == $pktCnt-1) {
if(substr($xml, -1, 1) != '>') {
$this->buffer = $xml;
$this->buffer .= $xml;
break;
}
}
if(substr($xml, 0, 7) == '<stream')
$arr = $this->xml->xmlize($xml);
else
$arr = JAXLXml::parse($xml);
if(substr($xml, 0, 7) == '<stream') $arr = $this->xml->xmlize($xml);
else $arr = JAXLXml::parse($xml, $this->getSXE);
if($arr === false) { $this->buffer .= $xml; continue; }
switch(true) {
case isset($arr['stream:stream']):
XMPPGet::streamStream($arr['stream:stream'], $this);
@ -426,7 +478,7 @@
XMPPGet::iq($arr['iq'], $this);
break;
default:
$jaxl->log("[[XMPPGet]] Unrecognized payload received from jabber server...");
$jaxl->log("[[XMPPGet]] \nUnrecognized payload received from jabber server...");
throw new JAXLException("[[XMPPGet]] Unrecognized payload received from jabber server...");
break;
}
@ -434,9 +486,10 @@
if(isset($buffer['presence'])) XMPPGet::presence($buffer['presence'], $this);
if(isset($buffer['message'])) XMPPGet::message($buffer['message'], $this);
unset($buffer);
JAXLPlugin::execute('jaxl_post_handler', $payload, $this);
unset($buffer);
$this->executePlugin('jaxl_post_handler', $payload);
return $payload;
}
}

32
lib/Jaxl/xmpp/xmpp.get.php

@ -61,7 +61,7 @@
print "Unrecognized XMPP Stream...\n";
}
else if($arr['@']['xmlns'] == "jabber:component:accept") {
JAXLPlugin::execute('jaxl_post_start', $arr['@']['id'], $jaxl);
$jaxl->executePlugin('jaxl_post_start', $arr['@']['id']);
}
else if($arr['@']['xmlns'] == "jabber:client") {
$jaxl->streamId = $arr['@']['id'];
@ -87,7 +87,7 @@
foreach ($arr["#"]["mechanisms"][0]["#"]["mechanism"] as $row)
$mechanism[] = $row["#"];
JAXLPlugin::execute('jaxl_get_auth_mech', $mechanism, $jaxl);
$jaxl->executePlugin('jaxl_get_auth_mech', $mechanism);
}
else if(isset($arr["#"]["bind"]) && ($arr["#"]["bind"][0]["@"]["xmlns"] == "urn:ietf:params:xml:ns:xmpp-bind")) {
if(isset($arr["#"]["session"]))
@ -100,7 +100,7 @@
public static function streamError($arr, $jaxl) {
$desc = key($arr['#']);
$xmlns = $arr['#'][$desc]['0']['@']['xmlns'];
JAXLPlugin::execute('jaxl_get_stream_error', $arr, $jaxl);
$jaxl->executePlugin('jaxl_get_stream_error', $arr);
$jaxl->log("[[XMPPGet]] Stream error with description ".$desc." and xmlns ".$xmlns);
throw new JAXLException("[[XMPPGet]] Stream error with description ".$desc." and xmlns ".$xmlns);
return true;
@ -112,13 +112,13 @@
case 'urn:ietf:params:xml:ns:xmpp-tls':
$jaxl->log("[[XMPPGet]] Unable to start TLS negotiation, see logs for detail...");
if($jaxl->mode == "cli") throw new JAXLException("[[XMPPGet]] Unable to start TLS negotiation, see logs for detail...");
JAXLPlugin::execute('jaxl_post_auth_failure', false, $jaxl);
$jaxl->executePlugin('jaxl_post_auth_failure', false);
$jaxl->shutdown('tlsFailure');
break;
case 'urn:ietf:params:xml:ns:xmpp-sasl':
$jaxl->log("[[XMPPGet]] Unable to complete SASL Auth, see logs for detail...");
if($jaxl->mode == "cli") throw new JAXLException("[[XMPPGet]] Unable to complete SASL Auth, see logs for detail...");
JAXLPlugin::execute('jaxl_post_auth_failure', false, $jaxl);
$jaxl->executePlugin('jaxl_post_auth_failure', false);
$jaxl->shutdown('saslFailure');
break;
default:
@ -130,10 +130,8 @@
public static function proceed($arr, $jaxl) {
if($arr['xmlns'] == "urn:ietf:params:xml:ns:xmpp-tls") {
stream_set_blocking($jaxl->stream, 1);
if(!stream_socket_enable_crypto($jaxl->stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
if(!@stream_socket_enable_crypto($jaxl->stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT))
stream_socket_enable_crypto($jaxl->stream, true, STREAM_CRYPTO_METHOD_SSLv3_CLIENT);
stream_set_blocking($jaxl->stream, 0);
XMPPSend::startStream($jaxl);
}
}
@ -156,7 +154,7 @@
public static function presence($arrs, $jaxl) {
$payload = array();
foreach($arrs as $arr) $payload[] = $arr;
JAXLPlugin::execute('jaxl_get_presence', $payload, $jaxl);
$jaxl->executePlugin('jaxl_get_presence', $payload);
unset($payload);
return $arrs;
}
@ -164,7 +162,7 @@
public static function message($arrs, $jaxl) {
$payload = array();
foreach($arrs as $arr) $payload[] = $arr;
JAXLPlugin::execute('jaxl_get_message', $payload, $jaxl);
$jaxl->executePlugin('jaxl_get_message', $payload);
unset($payload);
return $arrs;
}
@ -175,7 +173,7 @@
list($user, $domain, $resource) = JAXLUtil::splitJid($jaxl->jid);
$jaxl->resource = $resource;
JAXLPlugin::execute('jaxl_post_bind', false, $jaxl);
$jaxl->executePlugin('jaxl_post_bind', false);
if($jaxl->sessionRequired) {
$jaxl->startSession();
@ -183,7 +181,7 @@
else {
$jaxl->auth = true;
$jaxl->log("[[XMPPGet]] Auth completed...");
JAXLPlugin::execute('jaxl_post_auth', false, $jaxl);
$jaxl->executePlugin('jaxl_post_auth', false);
}
}
}
@ -192,23 +190,23 @@
if($arr["type"] == "result") {
$jaxl->auth = true;
$jaxl->log("[[XMPPGet]] Auth completed...");
JAXLPlugin::execute('jaxl_post_auth', false, $jaxl);
$jaxl->executePlugin('jaxl_post_auth', false);
}
}
public static function iq($arr, $jaxl) {
switch($arr['type']) {
case 'get':
JAXLPlugin::execute('jaxl_get_iq_get', $arr, $jaxl);
$jaxl->executePlugin('jaxl_get_iq_get', $arr);
break;
case 'set':
JAXLPlugin::execute('jaxl_get_iq_set', $arr, $jaxl);
$jaxl->executePlugin('jaxl_get_iq_set', $arr);
break;
case 'result':
JAXLPlugin::execute('jaxl_get_iq_'.$arr['id'], $arr, $jaxl);
$jaxl->executePlugin('jaxl_get_iq_'.$arr['id'], $arr);
break;
case 'error':
JAXLPlugin::execute('jaxl_get_iq_'.$arr['id'], $arr, $jaxl);
$jaxl->executePlugin('jaxl_get_iq_'.$arr['id'], $arr);
break;
}
return $arr;

4
lib/Jaxl/xmpp/xmpp.send.php

@ -121,7 +121,7 @@
$xml .= self::prepareMessage($jaxl, $to, $from, $child, $type, $id, $ns);
}
JAXLPlugin::execute('jaxl_send_message', $xml, $jaxl);
$jaxl->executePlugin('jaxl_send_message', $xml);
return $jaxl->sendXML($xml);
}
@ -155,7 +155,7 @@
$xml .= self::preparePresence($jaxl, $to, $from, $child, $type, $id, $ns);
}
JAXLPlugin::execute('jaxl_send_presence', $xml, $jaxl);
$jaxl->executePlugin('jaxl_send_presence', $xml);
return $jaxl->sendXML($xml);
}

3
lib/PageBuilder.php

@ -291,6 +291,9 @@ class PageBuilder
self::$css = array_merge(self::$css, $widget->loadcss());
self::$scripts = array_merge(self::$scripts, $widget->loadjs());
// We save the loaded widgets in the session for futur Ajax calls
EventHandler::setLoadedWidgets(self::$loaded_widgets);
}
/**

4
lib/User.php

@ -71,10 +71,12 @@ class User {
function desauth()
{
unset($_SESSION['login']);
//unset($_SESSION['login']);
if(isset($this->xmppSession)) {
$this->xmppSession->logout();
}
session_destroy();
}
function getLogin()

50
lib/XMPPConnect.php

@ -17,8 +17,8 @@
*/
// Jabber external component setting
define('JAXL_COMPONENT_HOST', 'component.'.JAXL_HOST_DOMAIN);
define('JAXL_COMPONENT_PASS', 'pass');
//define('JAXL_COMPONENT_HOST', 'component.'.JAXL_HOST_DOMAIN);
//define('JAXL_COMPONENT_PASS', 'pass');
define('JAXL_COMPONENT_PORT', 5559);
define('JAXL_LOG_PATH', BASE_PATH . 'log/jaxl.log');
@ -76,38 +76,44 @@ class XMPPConnect
));
// Defining call-backs
$this->jaxl->addPlugin('jaxl_get_auth_mech', array(&$this, 'jaxl_get_auth_mech'));
$this->jaxl->addPlugin('jaxl_post_auth', array(&$this, 'jaxl_post_auth'));
$this->jaxl->addPlugin('jaxl_post_auth_failure', array(&$this, 'jaxl_post_auth_failure'));
$this->jaxl->addPlugin('jaxl_post_auth', array(&$this, 'postAuth'));
$this->jaxl->addPlugin('jaxl_post_auth_failure', array(&$this, 'postAuthFailure'));
//$this->jaxl->addPlugin('jaxl_post_disconnect', array(&$this, 'postDisconnect'));
$this->jaxl->addPlugin('jaxl_get_auth_mech', array(&$this, 'postAuthMech'));
$this->jaxl->addPlugin('jaxl_get_message', array(&$this, 'getMessage'));
//$this->jaxl->addPlugin('jaxl_get_empty_body', array(&$this, 'postEmptyBody'));
$this->jaxl->addPlugin('jaxl_get_presence', array(&$this, 'getPresence'));
$this->jaxl->addPlugin('jaxl_get_bosh_curl_error', array(&$this, 'boshCurlError'));
}
public function jaxl_post_auth($test, $test2) {
public function postAuth($test, $test2) {
$f = fopen(BASE_PATH."log/movim.log","w");
fwrite($f, "gna");
fclose($f);
}
public function jaxl_post_auth_failure() {
public function postAuthFailure() {
$this->jaxl->shutdown();
throw new MovimException("Login error.");
$user = new User();
$user->desauth();
header("?q=login&err=auth");
}
public function postDisconnect() {
}
public function boshCurlError() {
$this->jaxl->shutdown();
throw new MovimException("Bosh connection error.");
$user = new User();
$user->desauth();
}
public function jaxl_get_auth_mech($mechanism) {$this->jaxl->auth('DIGEST-MD5');} //'ANONYMOUS');}
public function postAuthMech($mechanism) {$this->jaxl->auth('DIGEST-MD5');} //'ANONYMOUS');}
public function getVCard()
{
$this->jaxl->JAXL0054('getVCard', false, $this->jaxl->jid, array(&$this, 'handlePayload'));
}
/**
* Pings the server. This must be done regularly in order to keep the
* session running.
@ -117,7 +123,12 @@ class XMPPConnect
$this->jaxl->JAXL0206('ping');
}
function getMessage($payloads = 'test') {
public function getVCard()
{
$this->jaxl->JAXL0054('getVCard', false, $this->jaxl->jid, array(&$this, 'handlePayload'));
}
public function getMessage($payloads = 'test') {
$html = '';
foreach($payloads as $payload) {
// reject offline message
@ -137,7 +148,7 @@ class XMPPConnect
}
}
function getPresence($payloads) {
public function getPresence($payloads) {
$html = '';
foreach($payloads as $payload) {
if($payload['type'] == '' || in_array($payload['type'], array('available', 'unavailable'))) {
@ -147,7 +158,8 @@ class XMPPConnect
}
}
if($html != '') {
echo $html;
$evt = new EventHandler();
$evt->runEvent('incomepresence', $html);
}
}

6
lib/widgets/Chat.php

@ -21,6 +21,7 @@ class Chat extends Widget
function WidgetLoad()
{
$this->registerEvent('incomechat', 'onIncomingChat');
$this->registerEvent('incomepresence', 'onIncomingPresence');
}
function onIncomingChat($event)
@ -28,6 +29,11 @@ class Chat extends Widget
echo "onIncomingChat was called. Message: $event";
}
function onIncomingPresence($event)
{
echo "onIncomingPresence was called. Message: $event";
}
function build()
{
?>

5
lib/widgets/Friends.php

@ -52,7 +52,8 @@ class Friends extends Widget
/*
A little example to get the vCard from the xmpp connector
*/
$xmpp = XMPPConnect::getInstance(User::getLogin()); // We get the instance of the connexion
/*$user = new User();
$xmpp = XMPPConnect::getInstance($user->getLogin()); // We get the instance of the connexion
$xmpp->getVCard(); // We send the vCard request
$vcard = $xmpp->getPayload(); // We return the result of the request
echo "<img src='data:image/png;base64,".$vcard['vCardPhotoBinVal']."' ><br />\n".
@ -71,7 +72,7 @@ class Friends extends Widget
$list["queryItemName"][$i].
" (".$list["queryItemGrp"][$i].")</a></li>";
}
echo "</ul></div>";
echo "</ul></div>";*/
?>
</div>
<?php

4
themes/movim/css/style2.css

@ -179,7 +179,7 @@ label {
display: inline;
-moz-transition: background-color 0.5s ease;
-webkit-transition: background-color 0.5s ease;
margin-left: 0px;
margin-left: -4px;
margin-right: 0px;
padding: 0px;
padding-top: 3px;
@ -293,7 +293,7 @@ label {
}
#log span.presence {
color: blue;
color: #9BBBC6;
}
#log span.state {

Loading…
Cancel
Save