* added SSL and fixed XMPP_Old

git-svn-id: svn://netflint.net/xmpphp@51 ef36c318-a008-4979-b6e8-6b496270793b
This commit is contained in:
fritzy 2008-07-25 21:39:09 +00:00
parent 1b39cfe6de
commit f7bb8d8f76
3 changed files with 25 additions and 8 deletions

View File

@ -149,6 +149,10 @@ class XMPPHP_XMLStream {
* @var float
*/
protected $last_send = 0;
/**
* @var boolean
*/
protected $use_ssl = false;
/**
* Constructor
@ -197,6 +201,15 @@ class XMPPHP_XMLStream {
return $this->lastid;
}
/**
* Set SSL
*
* @return integer
*/
public function useSSL($use=true) {
$this->use_ssl = $use;
}
/**
* Add ID Handler
*
@ -247,9 +260,11 @@ class XMPPHP_XMLStream {
} else {
$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 {
$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) {
throw new XMPPHP_Exception($e->getMessage());
}

View File

@ -213,10 +213,10 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream {
$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(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}' />");
$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);
} else {
$this->event('presence', $payload);

View File

@ -43,7 +43,9 @@ require_once "XMPP.php";
public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) {
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 array $attr
*/
protected function startXML($parser, $name, $attr) {
if($this->xml_depth == 0 and $attr['version'] != '1.0') {
public function startXML($parser, $name, $attr) {
if($this->xml_depth == 0) {
$this->session_id = $attr['ID'];
$this->authenticate();
}
@ -84,7 +86,7 @@ require_once "XMPP.php";
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>";
$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);