* added SSL and fixed XMPP_Old
git-svn-id: svn://netflint.net/xmpphp@51 ef36c318-a008-4979-b6e8-6b496270793b
This commit is contained in:
parent
1b39cfe6de
commit
f7bb8d8f76
@ -149,6 +149,10 @@ class XMPPHP_XMLStream {
|
|||||||
* @var float
|
* @var float
|
||||||
*/
|
*/
|
||||||
protected $last_send = 0;
|
protected $last_send = 0;
|
||||||
|
/**
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $use_ssl = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -197,6 +201,15 @@ class XMPPHP_XMLStream {
|
|||||||
return $this->lastid;
|
return $this->lastid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set SSL
|
||||||
|
*
|
||||||
|
* @return integer
|
||||||
|
*/
|
||||||
|
public function useSSL($use=true) {
|
||||||
|
$this->use_ssl = $use;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add ID Handler
|
* Add ID Handler
|
||||||
*
|
*
|
||||||
@ -247,9 +260,11 @@ class XMPPHP_XMLStream {
|
|||||||
} else {
|
} else {
|
||||||
$conflag = STREAM_CLIENT_CONNECT;
|
$conflag = STREAM_CLIENT_CONNECT;
|
||||||
}
|
}
|
||||||
$this->log->log("Connecting to tcp://{$this->host}:{$this->port}");
|
$conntype = 'tcp';
|
||||||
|
if($this->use_ssl) $conntype = 'ssl';
|
||||||
|
$this->log->log("Connecting to $conntype://{$this->host}:{$this->port}");
|
||||||
try {
|
try {
|
||||||
$this->socket = @stream_socket_client("tcp://{$this->host}:{$this->port}", $errno, $errstr, $timeout, $conflag);
|
$this->socket = @stream_socket_client("$conntype://{$this->host}:{$this->port}", $errno, $errstr, $timeout, $conflag);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new XMPPHP_Exception($e->getMessage());
|
throw new XMPPHP_Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
|
@ -213,10 +213,10 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream {
|
|||||||
$payload['from'] = $xml->attrs['from'];
|
$payload['from'] = $xml->attrs['from'];
|
||||||
$payload['status'] = (isset($xml->sub('status')->data)) ? $xml->sub('status')->data : '';
|
$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);
|
$this->log->log("Presence: {$payload['from']} [{$payload['show']}] {$payload['status']}", XMPPHP_Log::LEVEL_DEBUG);
|
||||||
if($xml->attrs['type'] == 'subscribe') {
|
if(array_key_exists('type', $xml->attrs) and $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}' />");
|
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);
|
$this->event('subscription_requested', $payload);
|
||||||
} elseif($xml->attrs['type'] == 'subscribed') {
|
} elseif(array_key_exists('type', $xml->attrs) and $xml->attrs['type'] == 'subscribed') {
|
||||||
$this->event('subscription_accepted', $payload);
|
$this->event('subscription_accepted', $payload);
|
||||||
} else {
|
} else {
|
||||||
$this->event('presence', $payload);
|
$this->event('presence', $payload);
|
||||||
|
@ -43,7 +43,9 @@ require_once "XMPP.php";
|
|||||||
|
|
||||||
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
|
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
|
||||||
parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
|
parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel);
|
||||||
|
if(!$server) $server = $host;
|
||||||
|
$this->stream_start = '<stream:stream to="' . $server . '" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">';
|
||||||
|
$this->fulljid = "{$user}@{$server}/{$resource}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,8 +55,8 @@ require_once "XMPP.php";
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $attr
|
* @param array $attr
|
||||||
*/
|
*/
|
||||||
protected function startXML($parser, $name, $attr) {
|
public function startXML($parser, $name, $attr) {
|
||||||
if($this->xml_depth == 0 and $attr['version'] != '1.0') {
|
if($this->xml_depth == 0) {
|
||||||
$this->session_id = $attr['ID'];
|
$this->session_id = $attr['ID'];
|
||||||
$this->authenticate();
|
$this->authenticate();
|
||||||
}
|
}
|
||||||
@ -84,7 +86,7 @@ require_once "XMPP.php";
|
|||||||
print "{$this->session_id} {$this->password}\n";
|
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>";
|
$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 {
|
} 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>";
|
$out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><password>{$this->password}</password><resource>{$this->resource}</resource></query></iq>";
|
||||||
}
|
}
|
||||||
$this->send($out);
|
$this->send($out);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user