handle host !

darcs-hash:20080626075920-34904-0aad06d788f8dbf3a03d17752ba49d866322594e.gz
This commit is contained in:
Evan Prodromou 2008-06-26 03:59:20 -04:00
parent cdcfdc8cb4
commit 64ba09f9a3
3 changed files with 19 additions and 13 deletions

View File

@ -63,7 +63,8 @@ $config =
'port' => 5222, 'port' => 5222,
'user' => 'update', 'user' => 'update',
'resource' => 'uniquename', 'resource' => 'uniquename',
'password' => 'blahblahblah'), 'password' => 'blahblahblah',
'host' => NULL), # only set if != server
); );
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');

View File

@ -37,7 +37,7 @@ function jabber_normalize_jid($jid) {
} }
} }
function jabber_connect($resource=NULL) { function jabber_connect($resource=NULL, $status=NULL) {
static $conn = NULL; static $conn = NULL;
if (!$conn) { if (!$conn) {
$conn = new XMPP(common_config('xmpp', 'server'), $conn = new XMPP(common_config('xmpp', 'server'),
@ -45,7 +45,10 @@ function jabber_connect($resource=NULL) {
common_config('xmpp', 'user'), common_config('xmpp', 'user'),
common_config('xmpp', 'password'), common_config('xmpp', 'password'),
($resource) ? $resource : ($resource) ? $resource :
common_config('xmpp', 'resource')); common_config('xmpp', 'resource'),
common_config('xmpp', 'host') ?
common_config('xmpp', 'host') :
common_config('xmpp', 'server'));
if (!$conn) { if (!$conn) {
return false; return false;
@ -55,6 +58,9 @@ function jabber_connect($resource=NULL) {
return false; return false;
} }
$conn->processUntil('session_start'); $conn->processUntil('session_start');
if ($status) {
$conn->presence($status);
}
} }
return $conn; return $conn;
} }

View File

@ -31,23 +31,27 @@ require_once(INSTALLDIR . '/lib/jabber.php');
class XMPPDaemon { class XMPPDaemon {
function XMPPDaemon() { function XMPPDaemon($resource=NULL) {
static $attrs = array('server', 'port', 'user', 'password', static $attrs = array('server', 'port', 'user', 'password',
'resource'); 'resource', 'host');
foreach ($attrs as $attr) foreach ($attrs as $attr)
{ {
$this->$attr = common_config('xmpp', $attr); $this->$attr = common_config('xmpp', $attr);
} }
if ($resource) {
$this->resource = $resource;
}
} }
function connect() { function connect() {
$this->conn = new XMPP($this->server, $this->port, $this->user, $this->conn = jabber_connect($this->resource,
$this->password, $this->resource); "Send me a message to post a notice");
);
if (!$this->conn) { if (!$this->conn) {
return false; return false;
} }
$this->conn->connect();
return !$this->conn->disconnected; return !$this->conn->disconnected;
} }
@ -181,10 +185,6 @@ class XMPPDaemon {
} }
} }
function handle_session(&$pl) {
$this->conn->presence($status="Send me a message to post a notice");
}
function log($level, $msg) { function log($level, $msg) {
common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg); common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg);
} }
@ -209,7 +209,6 @@ class XMPPDaemon {
} }
$this->conn->send($out); $this->conn->send($out);
} }
} }
$daemon = new XMPPDaemon(); $daemon = new XMPPDaemon();