get_dns_srv() public static method

public static get_dns_srv ( $domain )
Exemplo n.º 1
0
 public function __construct($config)
 {
     // env
     $this->cfg = $config;
     $strict = isset($this->cfg['strict']) ? $this->cfg['strict'] : TRUE;
     if ($strict) {
         $this->add_exception_handlers();
     }
     $this->mode = PHP_SAPI;
     $this->local_ip = gethostbyname(php_uname('n'));
     $this->pid = getmypid();
     // initialize core modules
     $this->ev = new JAXLEvent();
     // jid object
     $jid = @$this->cfg['jid'] ? new XMPPJid($this->cfg['jid']) : null;
     // handle signals
     if (extension_loaded('pcntl')) {
         pcntl_signal(SIGHUP, array($this, 'signal_handler'));
         pcntl_signal(SIGINT, array($this, 'signal_handler'));
         pcntl_signal(SIGTERM, array($this, 'signal_handler'));
     }
     // create .jaxl directory in JAXL_CWD
     // for our /tmp, /run and /log folders
     // overwrite these using jaxl config array
     $this->priv_dir = @$this->cfg['priv_dir'] ? $this->cfg['priv_dir'] : JAXL_CWD . "/.jaxl";
     $this->tmp_dir = $this->priv_dir . "/tmp";
     $this->pid_dir = $this->priv_dir . "/run";
     $this->log_dir = $this->priv_dir . "/log";
     $this->sock_dir = $this->priv_dir . "/sock";
     if (!is_dir($this->priv_dir)) {
         mkdir($this->priv_dir);
     }
     if (!is_dir($this->tmp_dir)) {
         mkdir($this->tmp_dir);
     }
     if (!is_dir($this->pid_dir)) {
         mkdir($this->pid_dir);
     }
     if (!is_dir($this->log_dir)) {
         mkdir($this->log_dir);
     }
     if (!is_dir($this->sock_dir)) {
         mkdir($this->sock_dir);
     }
     // setup logger
     if (isset($this->cfg['log_path'])) {
         JAXLLogger::$path = $this->cfg['log_path'];
     }
     //else JAXLLogger::$path = $this->log_dir."/jaxl.log";
     if (isset($this->cfg['log_level'])) {
         JAXLLogger::$level = $this->log_level = $this->cfg['log_level'];
     } else {
         JAXLLogger::$level = $this->log_level;
     }
     // touch pid file
     if ($this->mode == "cli") {
         touch($this->get_pid_file_path());
         _info("created pid file " . $this->get_pid_file_path());
     }
     // include mandatory xmpp xeps
     // service discovery and entity caps
     // are recommended for every xmpp entity
     $this->require_xep(array('0030', '0115'));
     // do dns lookup, update $cfg['host'] and $cfg['port'] if not already specified
     $host = @$this->cfg['host'];
     $port = @$this->cfg['port'];
     if (!$host && !$port && $jid) {
         // this dns lookup is blocking
         _info("dns srv lookup for " . $jid->domain);
         list($host, $port) = JAXLUtil::get_dns_srv($jid->domain);
     }
     $this->cfg['host'] = $host;
     $this->cfg['port'] = $port;
     // choose appropriate transport
     // if 'bosh_url' cfg is defined include 0206
     if (@$this->cfg['bosh_url']) {
         _debug("including bosh xep");
         $this->require_xep('0206');
         $transport = $this->xeps['0206'];
     } else {
         list($host, $port) = JAXLUtil::get_dns_srv($jid->domain);
         $stream_context = @$this->cfg['stream_context'];
         $transport = new JAXLSocketClient($stream_context);
     }
     // initialize xmpp stream with configured transport
     parent::__construct($transport, $jid, @$this->cfg['pass'], @$this->cfg['resource'] ? 'jaxl#' . $this->cfg['resource'] : 'jaxl#' . md5(time()), @$this->cfg['force_tls']);
 }
Exemplo n.º 2
0
$body = file_get_contents("php://input");
$body = new SimpleXMLElement($body);
$attrs = $body->attributes();
if (!@$attrs['to'] && !@$attrs['rid'] && !@$attrs['wait'] && !@$attrs['hold']) {
    echo "invalid input";
    exit;
}
//
// initialize JAXL object with initial config
//
require_once 'jaxl.php';
$to = $attrs['to'];
$rid = $attrs['rid'];
$wait = $attrs['wait'];
$hold = $attrs['hold'];
echo $to . " " . $rid . " " . $wait . " " . $hold;
exit;
list($host, $port) = JAXLUtil::get_dns_srv($to);
$client = new JAXL(array('domain' => $to, 'host' => $host, 'port' => $port, 'bosh_url' => 'http://localhost:5280/http-bind', 'bosh_rid' => $rid, 'bosh_wait' => $wait, 'bosh_hold' => $hold, 'auth_type' => 'ANONYMOUS'));
$client->add_cb('on_auth_success', function () {
    global $client;
    _info($client->full_jid->to_string());
    _info($client->xeps['0206']->sid);
    _info($client->xeps['0206']->rid);
    exit;
});
//
// finally start configured xmpp stream
//
$client->start();
echo "done\n";
Exemplo n.º 3
0
Arquivo: jaxl.php Projeto: jaxl/JAXL
 /**
  * @param array $config
  */
 public function __construct(array $config)
 {
     $cfg_defaults = array('auth_type' => 'PLAIN', 'bosh_hold' => null, 'bosh_rid' => null, 'bosh_url' => null, 'bosh_wait' => null, 'domain' => null, 'force_tls' => false, 'host' => null, 'jid' => null, 'log_colorize' => $this->log_colorize, 'log_level' => $this->log_level, 'log_path' => JAXLLogger::$path, 'multi_client' => false, 'pass' => false, 'port' => null, 'priv_dir' => getcwd() . '/.jaxl', 'protocol' => null, 'resource' => null, 'stream_context' => null, 'strict' => true);
     $this->cfg = array_merge($cfg_defaults, $config);
     // setup logger
     JAXLLogger::$path = $this->cfg['log_path'];
     JAXLLogger::$level = $this->log_level = $this->cfg['log_level'];
     JAXLLogger::$colorize = $this->log_colorize = $this->cfg['log_colorize'];
     // env
     if ($this->cfg['strict']) {
         JAXLLogger::info("strict mode enabled, adding exception handlers. ' .\n                'Set 'strict' => false inside JAXL config to disable this");
         JAXLException::addHandlers();
     }
     $this->mode = PHP_SAPI;
     $this->local_ip = gethostbyname(php_uname('n'));
     $this->pid = getmypid();
     // jid object
     $jid = $this->cfg['jid'] !== null ? new XMPPJid($this->cfg['jid']) : null;
     // handle signals
     if (extension_loaded('pcntl')) {
         pcntl_signal(SIGHUP, array($this, 'signal_handler'));
         pcntl_signal(SIGINT, array($this, 'signal_handler'));
         pcntl_signal(SIGTERM, array($this, 'signal_handler'));
     }
     // Create .jaxl directory for our /tmp, /run and /log folders
     // overwrite these using jaxl config array
     $this->priv_dir = $this->cfg['priv_dir'];
     $this->tmp_dir = $this->priv_dir . "/tmp";
     $this->pid_dir = $this->priv_dir . "/run";
     $this->log_dir = $this->priv_dir . "/log";
     $this->sock_dir = $this->priv_dir . "/sock";
     if (!is_dir($this->priv_dir)) {
         mkdir($this->priv_dir);
     }
     if (!is_dir($this->tmp_dir)) {
         mkdir($this->tmp_dir);
     }
     if (!is_dir($this->pid_dir)) {
         mkdir($this->pid_dir);
     }
     if (!is_dir($this->log_dir)) {
         mkdir($this->log_dir);
     }
     if (!is_dir($this->sock_dir)) {
         mkdir($this->sock_dir);
     }
     // touch pid file
     if ($this->mode == "cli") {
         touch($this->get_pid_file_path());
         JAXLLogger::info("created pid file " . $this->get_pid_file_path());
     }
     // include mandatory xmpp xeps
     // service discovery and entity caps
     // are recommended for every xmpp entity
     $this->require_xep(array('0030', '0115'));
     // do dns lookup, update $cfg['host'] and $cfg['port'] if not already specified
     if (($this->cfg['host'] === null || $this->cfg['port'] === null) && $jid) {
         // this dns lookup is blocking
         JAXLLogger::info("dns srv lookup for " . $jid->domain);
         list($host, $port) = JAXLUtil::get_dns_srv($jid->domain);
         if ($this->cfg['host'] === null) {
             $this->cfg['host'] = $host;
         }
         if ($this->cfg['port'] === null) {
             $this->cfg['port'] = $port;
         }
     }
     // choose appropriate transport
     // if 'bosh_url' cfg is defined include 0206
     if (isset($this->cfg['bosh_url'])) {
         JAXLLogger::debug("including bosh xep");
         $this->require_xep('0206');
         $transport = $this->xeps['0206'];
     } else {
         $transport = new JAXLSocketClient($this->cfg['stream_context']);
     }
     // lifecycle events callback
     $this->ev = new JAXLEvent($this->cfg['multi_client'] ? array(&$this) : array());
     // initialize xmpp stream with configured transport
     parent::__construct($transport, $jid, $this->cfg['pass'], $this->cfg['resource'] !== null ? 'jaxl#' . $this->cfg['resource'] : 'jaxl#' . md5(time()), $this->cfg['force_tls']);
 }