Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from Cobrowser/bosh_parameter
Browse files Browse the repository at this point in the history
feat(prebind): added boshparameters
  • Loading branch information
Piotr committed Feb 17, 2015
2 parents 619ec04 + b25c038 commit 305788e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
.svn
.idea
62 changes: 53 additions & 9 deletions lib/XmppPrebind.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,21 @@ class XmppPrebind {

protected $mechanisms = array();

// the Bosh attributes for use in a client using this prebound session
protected $wait;
protected $requests;
protected $ver;
protected $polling;
protected $inactivity;
protected $hold;
protected $to;
protected $ack;
protected $accept;
protected $maxpause;

/**
* Session creation response
*
*
* @var DOMDocument
*/
public $response;
Expand Down Expand Up @@ -126,7 +138,7 @@ public function connect($username, $password, $route = false) {
$this->jid = $username . '@' . $this->jabberHost;

if($this->resource) {
$this->jid .= '/' . $this->resource;
$this->jid .= '/' . $this->resource;
}

$this->password = $password;
Expand All @@ -135,10 +147,22 @@ public function connect($username, $password, $route = false) {

$body = self::getBodyFromXml($response);
$this->sid = $body->getAttribute('sid');

// set the Bosh Attributes
$this->wait = $body->getAttribute('wait');
$this->requests = $body->getAttribute('requests');
$this->ver = $body->getAttribute('ver');
$this->polling = $body->getAttribute('polling');
$this->inactivity = $body->getAttribute('inactivity');
$this->hold = $body->getAttribute('hold');
$this->to = $body->getAttribute('to');
$this->accept = $body->getAttribute('accept');
$this->maxpause = $body->getAttribute('maxpause');

$this->debug($this->sid, 'sid');

$mechanisms = $body->getElementsByTagName('mechanism');

foreach ($mechanisms as $value) {
$this->mechanisms[] = $value->nodeValue;
}
Expand Down Expand Up @@ -194,6 +218,27 @@ public function auth() {
return true;
}

/**
* Get BOSH parameters to properly setup the BOSH client
*
* @return array
*/
public function getBoshInfo()
{
return array(
'wait' => $this->wait,
'requests' => $this->requests,
'ver' => $this->ver,
'polling' => $this->polling,
'inactivity' => $this->inactivity,
'hold' => $this->hold,
'to' => $this->to,
'ack' => $this->ack,
'accept' => $this->accept,
'maxpause' => $this->maxpause,
);
}

/**
* Get jid, sid and rid for attaching
*
Expand Down Expand Up @@ -316,7 +361,7 @@ protected function sendInitialConnection($route = false) {
$body->appendChild(self::getNewTextAttribute($domDocument, 'xmlns:xmpp', self::XMLNS_BOSH));
$body->appendChild(self::getNewTextAttribute($domDocument, 'xmpp:version', '1.0'));
$body->appendChild(self::getNewTextAttribute($domDocument, 'wait', $waitTime));

if ($route)
{
$body->appendChild(self::getNewTextAttribute($domDocument, 'route', $route));
Expand Down Expand Up @@ -507,11 +552,11 @@ public static function compatibleGzInflate($gzData) {
$i = $i + 2 + $xlen;
}
if ( $flg & 8 )
$i = strpos($gzData, "\0", $i) + 1;
$i = strpos($gzData, "\0", $i) + 1;
if ( $flg & 16 )
$i = strpos($gzData, "\0", $i) + 1;
$i = strpos($gzData, "\0", $i) + 1;
if ( $flg & 2 )
$i = $i + 2;
$i = $i + 2;
}
return gzinflate( substr($gzData, $i, -8) );
} else {
Expand Down Expand Up @@ -619,12 +664,11 @@ protected static function getBodyFromXml($xml) {
protected function getAndIncrementRid() {
return $this->rid++;
}

}

/**
* Standard XmppPrebind Exception
*/
class XmppPrebindException extends Exception{}

class XmppPrebindConnectionException extends XmppPrebindException {}
class XmppPrebindConnectionException extends XmppPrebindException{}

0 comments on commit 305788e

Please sign in to comment.