Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: xmpphp/xmpphp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: Iperity/xmpphp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Feb 23, 2010

  1. Fix that damn cpu-hogging bug

    cweiske committed Feb 23, 2010
    Copy the full SHA
    6744ba5 View commit details

Commits on Feb 24, 2010

  1. Copy the full SHA
    b855049 View commit details

Commits on Feb 25, 2010

  1. Copy the full SHA
    28ab998 View commit details
  2. Copy the full SHA
    eefdf7d View commit details
  3. Copy the full SHA
    efb71fa View commit details
  4. Copy the full SHA
    d228a30 View commit details
  5. Copy the full SHA
    2e8149f View commit details

Commits on Feb 26, 2010

  1. Copy the full SHA
    3e81567 View commit details

Commits on Feb 27, 2010

  1. fix notice when no have resourse (from icq for example)

    Ivan Borzenkov committed Feb 27, 2010
    Copy the full SHA
    b25d781 View commit details
  2. fix - can not set priority 0

    Ivan Borzenkov committed Feb 27, 2010
    Copy the full SHA
    bde0880 View commit details

Commits on Feb 28, 2010

  1. fix issue #2: tls does not work anymore with 4k fix. the magic soluti…

    …on is to set the stream non-blocking after the first part of the packet has been received, and setting it back afterwards
    cweiske committed Feb 28, 2010
    Copy the full SHA
    c74544c View commit details
  2. update readme

    cweiske committed Feb 28, 2010
    Copy the full SHA
    71f0d64 View commit details
  3. Copy the full SHA
    7f28fd2 View commit details

Commits on Mar 7, 2010

  1. reverting "use XMPPHP/ folder instead of dirname(__FILE__) which is i…

    …nefficient"
    
    method whis relative path not work for lib - random current dir
    dirname faster and not need change include_path
    
    more info on
    http://stackoverflow.com/questions/2220443/whats-better-of-requiredirname-file-myparent-php-than-just-require
    Ivan Borzenkov committed Mar 7, 2010
    Copy the full SHA
    43b4bc9 View commit details
  2. Add to roster

    Ivan Borzenkov committed Mar 7, 2010
    Copy the full SHA
    6e1b55f View commit details
  3. add patch from http://code.google.com/p/xmpphp/issues/detail?id=67 - …

    …Digest MD5
    Ivan Borzenkov committed Mar 7, 2010
    Copy the full SHA
    b26491c View commit details
  4. Copy the full SHA
    7d2ef0e View commit details

Commits on Mar 9, 2010

  1. add PHPDOC to adduser

    Ivan Borzenkov committed Mar 9, 2010
    Copy the full SHA
    6abf075 View commit details
  2. Return stream_blocking and add false check

    Ivan Borzenkov committed Mar 9, 2010
    Copy the full SHA
    eb08b04 View commit details

Commits on Apr 14, 2010

  1. Copy the full SHA
    8cf4349 View commit details
  2. Copy the full SHA
    794ef37 View commit details
  3. Copy the full SHA
    94d3a03 View commit details
  4. Copy the full SHA
    21f4d5c View commit details

Commits on May 29, 2010

  1. fix wrong xml type when getting roster items added (as per RFC3921, 7…

    ….4. "Adding a Roster Item". Thanks to neustradamus@jabber.org for notifying me about that
    cweiske committed May 29, 2010
    Copy the full SHA
    e584413 View commit details

Commits on May 30, 2010

  1. Add to roster

    Ivan Borzenkov authored and cweiske committed May 30, 2010
    Copy the full SHA
    06600d4 View commit details
  2. add patch from http://code.google.com/p/xmpphp/issues/detail?id=67 - …

    …Digest MD5
    Ivan Borzenkov authored and cweiske committed May 30, 2010
    Copy the full SHA
    1e40322 View commit details
  3. add PHPDOC to adduser

    Ivan Borzenkov authored and cweiske committed May 30, 2010
    Copy the full SHA
    8625895 View commit details
  4. Merge

    Merge remote branch 'github-ivan1986/master'
    cweiske committed May 30, 2010
    Copy the full SHA
    07a9b7e View commit details

Commits on Jun 10, 2011

  1. Use double quotes when printing XML attributes, since htmlspecialchar…

    …s won't convert single quotes in the attribute values by default.
    kmontag committed Jun 10, 2011
    Copy the full SHA
    03b7dc6 View commit details
  2. Merge pull request #7 from kmontag/patch-1

    XML attribute-printing fix
    cweiske committed Jun 10, 2011
    Copy the full SHA
    fd9cac3 View commit details

Commits on Dec 27, 2012

  1. Add custom patches

    nbruning committed Dec 27, 2012
    Copy the full SHA
    416eefe View commit details
18 changes: 17 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -3,8 +3,13 @@ About
XMPPHP is an elegant PHP library for XMPP (aka Jabber, Google Talk, etc).

Homepage: http://code.google.com/p/xmpphp
This fork: http://github.com/cweiske/xmpphp/
Chatroom: xmpphp@conference.psi-im.org (XMPP MUC)
PEAR package: http://pearhub.org/projects/cwXMPPHP/

Author: Nathan Fritz, jabber id: fritzy [at] netflint.net
Co-Author: Stephan Wentz, jabber id: stephan [at] jabber.wentz.it
Co-Author: Stephan Wentz, jabber id: stephan [at] wentz.it
Maintainer of this fork: Christian Weiske <cweiske@cweiske.de>

If you have any questions (no matter how dumb), please send me an IM. I enjoy
helping people with my code.
@@ -29,6 +34,17 @@ Documentation
For now, look at the examples. In the near future, I'll have better
documentation on the website.

Installation
================================================================================
Either get the code from github, the last release from google code
or install the PEAR package from pearhub.org:
$ pear channel-discover pearhub.org
$ pear install pearhub/cwXMPPHP

The code on google code is not being actively maintained anymore, so
don't expect current releases there.


TODO
================================================================================
* Documentation
6 changes: 4 additions & 2 deletions XMPPHP/BOSH.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
*/

/** XMPPHP_XMLStream */
require_once dirname(__FILE__) . "/XMPP.php";
require_once 'XMPPHP/XMPP.php';

/**
* XMPPHP Main Class
@@ -65,7 +65,9 @@ public function connect($server, $wait='1', $session=false) {
$body->addAttribute('to', $this->host);
$body->addAttribute('route', "xmpp:{$this->host}:{$this->port}");
$body->addAttribute('secure','true');
$body->addAttribute('xmpp:version','1.6', 'urn:xmpp:xbosh');
$body->addAttribute('ver','1.6');
// Important: use xmpp:version 1.0!
$body->addAttribute('xmpp:version','1.0', 'urn:xmpp:xbosh');
$body->addAttribute('wait', strval($wait));
$body->addAttribute('ack','1');
$body->addAttribute('xmlns:xmpp','urn:xmpp:xbosh');
6 changes: 4 additions & 2 deletions XMPPHP/Roster.php
Original file line number Diff line number Diff line change
@@ -118,15 +118,17 @@ public function isContact($jid) {
* @param string $status
*/
public function setPresence($presence, $priority, $show, $status) {
list($jid, $resource) = explode('/', $presence, 2);
$presence = explode('/', $presence, 2);
$jid = $presence[0];
$resource = isset($presence[1]) ? $presence[1] : '';
if ($show != 'unavailable') {
if (!$this->isContact($jid)) {
$this->addContact($jid, 'not-in-roster');
}
$resource = $resource ? $resource : '';
$this->roster_array[$jid]['presence'][$resource] = array('priority' => $priority, 'show' => $show, 'status' => $status);
} else { //Nuke unavailable resources to save memory
unset($this->roster_array[$jid]['resource'][$resource]);
unset($this->roster_array[$jid]['presence'][$resource]);
}
}

2 changes: 1 addition & 1 deletion XMPPHP/XMLObj.php
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ public function toString($str = '') {
foreach($this->attrs as $key => $value) {
if($key != 'xmlns') {
$value = htmlspecialchars($value);
$str .= "$key='$value' ";
$str .= "$key=\"$value\" ";
}
}
$str .= ">";
107 changes: 69 additions & 38 deletions XMPPHP/XMLStream.php
Original file line number Diff line number Diff line change
@@ -27,13 +27,13 @@
*/

/** XMPPHP_Exception */
require_once dirname(__FILE__) . '/Exception.php';
require_once 'XMPPHP/Exception.php';

/** XMPPHP_XMLObj */
require_once dirname(__FILE__) . '/XMLObj.php';
require_once 'XMPPHP/XMLObj.php';

/** XMPPHP_Log */
require_once dirname(__FILE__) . '/Log.php';
require_once 'XMPPHP/Log.php';

/**
* XMPPHP XML Stream
@@ -55,10 +55,6 @@ class XMPPHP_XMLStream {
* @var resource
*/
protected $parser;
/**
* @var string
*/
protected $buffer;
/**
* @var integer
*/
@@ -362,8 +358,11 @@ public function disconnect() {
$this->reconnect = false;
$this->send($this->stream_end);
$this->sent_disconnect = true;
$this->processUntil('end_stream', 5);
$this->disconnected = true;
// NATHAN: prevent re-entrance of processUntil
// If this method is called from a callback, we are re-entering xml_parse which does not work correctly
// $this->processUntil('end_stream', 5);
// NATHAN: enable the next line to set $disconnected before actually receiving stream_end
// $this->disconnected = true;
}

/**
@@ -390,7 +389,10 @@ protected function bufferComplete($buff)
}
//we always have a space since the namespace needs to be
//declared. could be a tab, though
$start = substr($buff, 1, strpos($buff, ' ', 2) - 1);
$start = substr(
$buff, 1,
min(strpos($buff, '>', 2), strpos($buff, ' ', 2)) - 1
);
$stop = substr($buff, -strlen($start) - 3);

if ($start == '?xml') {
@@ -416,16 +418,18 @@ protected function bufferComplete($buff)
* @param mixed $maximum Limit when to return
* - 0: only read if data is immediately ready
* - NULL: wait forever and ever
* - integer: process for this amount of milliseconds
* - integer: process for this amount of microseconds
* @param boolean $return_when_received Immediately return when data have been
* received
*
* @return boolean True when all goes well, false when something fails
*/
private function __process($maximum = 5, $return_when_received = false)
// needs to be overridden for BOSH; cannot be private
protected function __process($maximum = 5, $return_when_received = false)
{
$remaining = $maximum;

$buff = '';

do {
$starttime = (microtime(true) * 1000000);
$read = array($this->socket);
@@ -438,43 +442,67 @@ private function __process($maximum = 5, $return_when_received = false)
$secs = 0;
$usecs = 0;
} else {
$usecs = $remaining % 1000000;
// NATHAN: don't use % here, as it will convert the operands to integers causing integer overflow.
$usecs = fmod($remaining, 1000000);
$secs = floor(($remaining - $usecs) / 1000000);
}
$updated = @stream_select($read, $write, $except, $secs, $usecs);
// echo "stream_select returns " . ($updated === FALSE ? "false" : $updated). " timeout = $secs / $usecs\n";
if ($updated === false) {
$this->log->log("Error on stream_select()", XMPPHP_Log::LEVEL_VERBOSE);
if ($this->reconnect) {
$this->doReconnect();
} else {
fclose($this->socket);
// NATHAN: only fclose if socket not null, set disconnected = false
// NATHAN: see http://code.google.com/p/xmpphp/issues/detail?id=53
if ($this->socket) fclose($this->socket);
$this->disconnected = TRUE;
$this->socket = NULL;
return false;
}
} else if ($updated > 0) {
$buff = '';
do {
$part = stream_socket_recvfrom($this->socket, 4096);
if (!$part) {
if($this->reconnect) {
$this->doReconnect();
} else {
fclose($this->socket);
$this->socket = NULL;
return false;
}
if ($buff != '') {
//disable blocking for now because fread() will
// block until the 4k are full if we already
// read a part of the packet
stream_set_blocking($this->socket, 0);
}
$part = fread($this->socket, 4096);
stream_set_blocking($this->socket, 1);
// NATHAN: check for feof (when server closes socket)
// Note: feof() does not work for sockets with stream_socket_enable_crypto set.
// The library will wait forever for a <stream:features>, while ejabberd has actually sent the tag.
$meta = stream_get_meta_data($this->socket);
$isEndOfFile = $meta['eof'];
if ($part === false || ($part == '' && $isEndOfFile)) {
if($this->reconnect) {
$this->doReconnect();
} else {
// NATHAN: only fclose if socket not null, set disconnected = false
// NATHAN: see http://code.google.com/p/xmpphp/issues/detail?id=53
if ($this->socket) fclose($this->socket);
$this->disconnected = TRUE;
$this->socket = NULL;
return false;
}
$this->log->log("RECV: $part", XMPPHP_Log::LEVEL_VERBOSE);
$buff .= $part;
} while (!$this->bufferComplete($buff));

xml_parse($this->parser, $buff, false);
if ($return_when_received) {
return true;
}
$this->log->log("RECV: $part", XMPPHP_Log::LEVEL_VERBOSE);
$buff .= $part;
} else {
# $updated == 0 means no changes during timeout.
}

// Complete buffer ?
// NATHAN: bufferComplete code did not work when XML tags are split across buffers.
// We just pass all the data to xml_parse, which will correctly deal with partial tags.
// if ($this->bufferComplete($buff)) {
xml_parse($this->parser, $buff, false);
if ($return_when_received) {
return true;
}
$buff = '';
// }

$endtime = (microtime(true)*1000000);
$time_past = $endtime - $starttime;
$remaining = $remaining - $time_past;
@@ -536,7 +564,7 @@ public function processUntil($event, $timeout = -1)
) {
$maximum = $timeout == -1
? NULL
: time() - $start;
: ($timeout - (time() - $start)) * 1000000;
$ret = $this->__process($maximum, true);
if (!$ret) {
break;
@@ -545,12 +573,14 @@ public function processUntil($event, $timeout = -1)

if (array_key_exists($event_key, $this->until_payload)) {
$payload = $this->until_payload[$event_key];
unset($this->until_payload[$event_key]);
unset($this->until_count[$event_key]);
unset($this->until[$event_key]);
} else {
$payload = array();
}
// NATHAN: release event data even if timeout occurred
// See http://code.google.com/p/xmpphp/issues/detail?id=92
unset($this->until_payload[$event_key]);
unset($this->until_count[$event_key]);
unset($this->until[$event_key]);

return $payload;
}
@@ -656,7 +686,8 @@ public function endXML($parser, $name) {
}
}
foreach($this->idhandlers as $id => $handler) {
if(array_key_exists('id', $this->xmlobj[2]->attrs) and $this->xmlobj[2]->attrs['id'] == $id) {
// TALKTO: add isset condition
if(isset($this->xmlobj[2]->attrs) && 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
Loading