* notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Abhinav Singh nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * */ if ($argc < 2) { echo "Usage: {$argv['0']} url\n"; exit; } require_once 'jaxl.php'; JAXLLogger::$level = JAXL_DEBUG; require_once JAXL_CWD . '/http/http_client.php'; $request = new HTTPClient($argv[1]); $request->start();
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']); }
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * */ require dirname(__FILE__) . '/_bootstrap.php'; // configure logger JAXLLogger::$level = JAXLLogger::INFO; // print usage notice and parse addr/port parameters if passed JAXLLogger::cliLog("Usage: {$argv['0']} port (default: 9699)", JAXLLogger::NOTICE); $port = $argc == 2 ? $argv[1] : 9699; // initialize http server $http = new HTTPServer($port); // callback method for dispatch rule (see below) function index($request) { $request->send_response(200, array('Content-Type' => 'text/html'), '<html><head/><body><h1>Jaxl Http Server</h1><a href="/upload">upload a file</a></body></html>'); $request->close(); } // callback method for dispatch rule (see below) function upload($request) { if ($request->method == 'GET') {
/** * @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']); }