JAXLUtil::get_dns_srv PHP Method

get_dns_srv() public static method

public static get_dns_srv ( $domain )
    public static function get_dns_srv($domain)
    {
        $rec = dns_get_record("_xmpp-client._tcp." . $domain, DNS_SRV);
        if (is_array($rec)) {
            if (count($rec) == 0) {
                return array($domain, 5222);
            }
            if (count($rec) > 0) {
                return array($rec[0]['target'], $rec[0]['port']);
            }
        }
    }

Usage Example

Esempio 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']);
 }
All Usage Examples Of JAXLUtil::get_dns_srv