'port' => 5222,
'user' => 'update',
'resource' => 'uniquename',
- 'password' => 'blahblahblah'),
+ 'password' => 'blahblahblah',
+ 'host' => NULL), # only set if != server
);
$config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
}
}
-function jabber_connect($resource=NULL) {
+function jabber_connect($resource=NULL, $status=NULL) {
static $conn = NULL;
if (!$conn) {
$conn = new XMPP(common_config('xmpp', 'server'),
common_config('xmpp', 'user'),
common_config('xmpp', 'password'),
($resource) ? $resource :
- common_config('xmpp', 'resource'));
+ common_config('xmpp', 'resource'),
+ common_config('xmpp', 'host') ?
+ common_config('xmpp', 'host') :
+ common_config('xmpp', 'server'));
if (!$conn) {
return false;
return false;
}
$conn->processUntil('session_start');
+ if ($status) {
+ $conn->presence($status);
+ }
}
return $conn;
}
class XMPPDaemon {
- function XMPPDaemon() {
+ function XMPPDaemon($resource=NULL) {
static $attrs = array('server', 'port', 'user', 'password',
- 'resource');
+ 'resource', 'host');
foreach ($attrs as $attr)
{
$this->$attr = common_config('xmpp', $attr);
}
+
+ if ($resource) {
+ $this->resource = $resource;
+ }
}
function connect() {
- $this->conn = new XMPP($this->server, $this->port, $this->user,
- $this->password, $this->resource);
+ $this->conn = jabber_connect($this->resource,
+ "Send me a message to post a notice");
+ );
if (!$this->conn) {
return false;
}
- $this->conn->connect();
return !$this->conn->disconnected;
}
}
}
- function handle_session(&$pl) {
- $this->conn->presence($status="Send me a message to post a notice");
- }
-
function log($level, $msg) {
common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg);
}
}
$this->conn->send($out);
}
-
}
$daemon = new XMPPDaemon();