Ejemplo n.º 1
0
 public function body_is_closed()
 {
     $body_tag = new EReg("/(body)", "i");
     $found = $body_tag->match($this->body);
     if ($found) {
         $this->body = _hx_string_or_null($body_tag->matchedLeft()) . "/body" . _hx_string_or_null($body_tag->matchedRight());
     }
     return $found;
 }
 static function extractVersion($searchString, $s)
 {
     $index = _hx_index_of($s, $searchString, null);
     if ($index < 0) {
         return null;
     }
     $re = new EReg("(\\d+)\\.(\\d+)[^ ();]*", "");
     if (!$re->match(_hx_substr($s, $index + strlen($searchString) + 1, null))) {
         return null;
     }
     return _hx_anonymous(array("version" => $re->matched(0), "majorVersion" => Std::parseInt($re->matched(1)), "minorVersion" => Std::parseInt($re->matched(2))));
 }
Ejemplo n.º 3
0
 static function parse($str)
 {
     haxe_Log::trace("Parsing URI from: " . $str, _hx_anonymous(array("fileName" => "URI.hx", "lineNumber" => 131, "className" => "sinatra.URI", "methodName" => "parse")));
     $abs = new EReg(sinatra_URI::$PATTERN_REMOVE_WHITESPACE->replace(sinatra_URI::$PATTERN_ABS_URI, ""), "");
     if ($abs->match($str)) {
         haxe_Log::trace("IT'S AN ABSOLUTE URI!", _hx_anonymous(array("fileName" => "URI.hx", "lineNumber" => 135, "className" => "sinatra.URI", "methodName" => "parse")));
         return new sinatra_URI($abs, true);
     }
     $rel = new EReg(sinatra_URI::$PATTERN_REMOVE_WHITESPACE->replace(sinatra_URI::$PATTERN_REL_URI, ""), "");
     if ($rel->match($str)) {
         haxe_Log::trace("IT'S A RELATIVE URI!", _hx_anonymous(array("fileName" => "URI.hx", "lineNumber" => 141, "className" => "sinatra.URI", "methodName" => "parse")));
         return new sinatra_URI($rel, false);
     }
     haxe_Log::trace("Invalid URI", _hx_anonymous(array("fileName" => "URI.hx", "lineNumber" => 145, "className" => "sinatra.URI", "methodName" => "parse")));
     return null;
 }
Ejemplo n.º 4
0
 public function customRequest($post, $api, $sock = null, $method = null)
 {
     $url_regexp = new EReg("^(https?://)?([a-zA-Z\\.0-9-]+)(:[0-9]+)?(.*)\$", "");
     if (!$url_regexp->match($this->url)) {
         $this->onError("Invalid URL");
         return;
     }
     $secure = $url_regexp->matched(1) === "https://";
     if ($sock === null) {
         if ($secure) {
             $sock = new php_net_SslSocket();
         } else {
             $sock = new sys_net_Socket();
         }
     }
     $host = $url_regexp->matched(2);
     $portString = $url_regexp->matched(3);
     $request = $url_regexp->matched(4);
     if ($request === "") {
         $request = "/";
     }
     $port = $portString === null || $portString === "" ? $secure ? 443 : 80 : Std::parseInt(_hx_substr($portString, 1, strlen($portString) - 1));
     $data = null;
     $multipart = _hx_field($this, "file") !== null;
     $boundary = null;
     $uri = null;
     if ($multipart) {
         $post = true;
         $boundary = Std::string(Std::random(1000)) . Std::string(Std::random(1000)) . Std::string(Std::random(1000)) . Std::string(Std::random(1000));
         while (strlen($boundary) < 38) {
             $boundary = "-" . $boundary;
         }
         $b = new StringBuf();
         if (null == $this->params) {
             throw new HException('null iterable');
         }
         $»it = $this->params->keys();
         while ($»it->hasNext()) {
             $p = $»it->next();
             $b->add("--");
             $b->add($boundary);
             $b->add("\r\n");
             $b->add("Content-Disposition: form-data; name=\"");
             $b->add($p);
             $b->add("\"");
             $b->add("\r\n");
             $b->add("\r\n");
             $b->add($this->params->get($p));
             $b->add("\r\n");
         }
         $b->add("--");
         $b->add($boundary);
         $b->add("\r\n");
         $b->add("Content-Disposition: form-data; name=\"");
         $b->add($this->file->param);
         $b->add("\"; filename=\"");
         $b->add($this->file->filename);
         $b->add("\"");
         $b->add("\r\n");
         $b->add("Content-Type: " . "application/octet-stream" . "\r\n" . "\r\n");
         $uri = $b->b;
     } else {
         if (null == $this->params) {
             throw new HException('null iterable');
         }
         $»it = $this->params->keys();
         while ($»it->hasNext()) {
             $p = $»it->next();
             if ($uri === null) {
                 $uri = "";
             } else {
                 $uri .= "&";
             }
             $uri .= rawurlencode($p) . "=" . rawurlencode($this->params->get($p));
         }
     }
     $b = new StringBuf();
     if ($method !== null) {
         $b->add($method);
         $b->add(" ");
     } else {
         if ($post) {
             $b->add("POST ");
         } else {
             $b->add("GET ");
         }
     }
     if (_hx_field(_hx_qtype("haxe.Http"), "PROXY") !== null) {
         $b->add("http://");
         $b->add($host);
         if ($port !== 80) {
             $b->add(":");
             $b->add($port);
         }
     }
     $b->add($request);
     if (!$post && $uri !== null) {
         if (_hx_index_of($request, "?", 0) >= 0) {
             $b->add("&");
         } else {
             $b->add("?");
         }
         $b->add($uri);
     }
     $b->add(" HTTP/1.1\r\nHost: " . $host . "\r\n");
     if ($this->postData !== null) {
         $b->add("Content-Length: " . _hx_string_rec(strlen($this->postData), "") . "\r\n");
     } else {
         if ($post && $uri !== null) {
             if ($multipart || $this->headers->get("Content-Type") === null) {
                 $b->add("Content-Type: ");
                 if ($multipart) {
                     $b->add("multipart/form-data");
                     $b->add("; boundary=");
                     $b->add($boundary);
                 } else {
                     $b->add("application/x-www-form-urlencoded");
                 }
                 $b->add("\r\n");
             }
             if ($multipart) {
                 $b->add("Content-Length: " . _hx_string_rec(strlen($uri) + $this->file->size + strlen($boundary) + 6, "") . "\r\n");
             } else {
                 $b->add("Content-Length: " . _hx_string_rec(strlen($uri), "") . "\r\n");
             }
         }
     }
     if (null == $this->headers) {
         throw new HException('null iterable');
     }
     $»it = $this->headers->keys();
     while ($»it->hasNext()) {
         $h = $»it->next();
         $b->add($h);
         $b->add(": ");
         $b->add($this->headers->get($h));
         $b->add("\r\n");
     }
     $b->add("\r\n");
     if ($this->postData !== null) {
         $b->add($this->postData);
     } else {
         if ($post && $uri !== null) {
             $b->add($uri);
         }
     }
     try {
         if (_hx_field(_hx_qtype("haxe.Http"), "PROXY") !== null) {
             $sock->connect(new sys_net_Host(haxe_Http::$PROXY->host), haxe_Http::$PROXY->port);
         } else {
             $sock->connect(new sys_net_Host($host), $port);
         }
         $sock->write($b->b);
         if ($multipart) {
             $bufsize = 4096;
             $buf = haxe_io_Bytes::alloc($bufsize);
             while ($this->file->size > 0) {
                 $size = haxe_Http_4($this, $api, $b, $boundary, $buf, $bufsize, $data, $host, $method, $multipart, $port, $portString, $post, $request, $secure, $sock, $uri, $url_regexp);
                 $len = 0;
                 try {
                     $len = $this->file->io->readBytes($buf, 0, $size);
                 } catch (Exception $»e) {
                     $_ex_ = $»e instanceof HException ? $»e->e : $»e;
                     if (($e = $_ex_) instanceof haxe_io_Eof) {
                         break;
                     } else {
                         throw $»e;
                     }
                 }
                 $sock->output->writeFullBytes($buf, 0, $len);
                 $this->file->size -= $len;
                 unset($size, $len, $e);
             }
             $sock->write("\r\n");
             $sock->write("--");
             $sock->write($boundary);
             $sock->write("--");
         }
         $this->readHttpResponse($api, $sock);
         $sock->close();
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         $e = $_ex_;
         try {
             $sock->close();
         } catch (Exception $»e) {
             $_ex_ = $»e instanceof HException ? $»e->e : $»e;
             $e1 = $_ex_;
         }
         $this->onError(Std::string($e));
     }
 }
Ejemplo n.º 5
0
 static function indentXml($xml, $space)
 {
     $depth = 0;
     $opentag = new EReg("^<([\\w-_]+)[^>]*>\$", "");
     $autotag = new EReg("^<([\\w-_]+)[^>]*/>\$", "");
     $closetag = new EReg("^</([\\w-_]+)>\$", "");
     $cdata = new EReg("^<!\\[CDATA\\[[^\\]]*\\]\\]>\$", "");
     $res = new StringBuf();
     $end = 0;
     $start = null;
     $text = null;
     while ($end < strlen($xml) && ($start = _hx_index_of($xml, "<", $end)) !== -1) {
         $text = $start > $end;
         if ($text) {
             $res->add(_hx_substr($xml, $end, $start - $end));
         }
         $end = _hx_index_of($xml, ">", $start) + 1;
         $aux = _hx_substr($xml, $start, $end - $start);
         if ($autotag->match($aux)) {
             $res->add("\n");
             $i = null;
             $_g = 0;
             while ($_g < $depth) {
                 $i1 = $_g++;
                 $res->add($space);
                 unset($i1);
             }
             unset($_g);
             $res->add($aux);
             unset($i);
         } else {
             if ($opentag->match($aux)) {
                 $res->add("\n");
                 $i = null;
                 $_g = 0;
                 while ($_g < $depth) {
                     $i1 = $_g++;
                     $res->add($space);
                     unset($i1);
                 }
                 unset($_g);
                 $res->add($aux);
                 $depth++;
                 unset($i);
             } else {
                 if ($closetag->match($aux)) {
                     $depth--;
                     if (!$text) {
                         $res->add("\n");
                         $i = null;
                         $_g = 0;
                         while ($_g < $depth) {
                             $i1 = $_g++;
                             $res->add($space);
                             unset($i1);
                         }
                         unset($_g);
                         unset($i);
                     }
                     $res->add($aux);
                 } else {
                     if ($cdata->match($aux)) {
                         $res->add($aux);
                     } else {
                         haxe_Log::trace("WARNING! malformed XML at character " . _hx_string_rec($end, "") . ":" . $xml, _hx_anonymous(array("fileName" => "WXmlUtils.hx", "lineNumber" => 583, "className" => "com.wiris.util.xml.WXmlUtils", "methodName" => "indentXml")));
                         $res->add($aux);
                     }
                 }
             }
         }
         unset($aux);
     }
     return trim($res->b);
 }
Ejemplo n.º 6
0
 static function isIdentifierStart($c)
 {
     $letterPattern = new EReg("[a-z]", "i");
     $str = chr($c);
     return $letterPattern->match($str) || $str === "_";
 }
Ejemplo n.º 7
0
 public function buildCond($whereParam, $sob, $phValues, $first = null)
 {
     if ($first === null) {
         $first = true;
     }
     $sb = new StringBuf();
     $where = _hx_explode(",", $whereParam);
     if ($where->length === 0) {
         return false;
     }
     $_g = 0;
     while ($_g < $where->length) {
         $w = $where[$_g];
         ++$_g;
         $wData = _hx_string_call($w, "split", array("|"));
         $values = $wData->slice(2, null);
         $filter_tables = null;
         if (Util::any2bool($this->param) && $this->param->exists("filter_tables") && Util::any2bool($this->param->get("filter_tables"))) {
             $jt = $this->param->get("filter_tables");
             $filter_tables = _hx_explode(",", $jt);
             unset($jt);
         }
         haxe_Log::trace(Std::string($wData) . ":" . _hx_string_or_null($this->joinTable) . ":" . Std::string($filter_tables), _hx_anonymous(array("fileName" => "Model.hx", "lineNumber" => 386, "className" => "Model", "methodName" => "buildCond")));
         if (_hx_deref(new EReg("^pay_[a-zA-Z_]+\\.", ""))->match($wData[0]) && _hx_array_get(_hx_explode(".", $wData[0]), 0) !== $this->joinTable) {
             continue;
         }
         if ($first) {
             $sb->add(" WHERE ");
         } else {
             $sb->add(" AND ");
         }
         $first = false;
         $_g1 = strtoupper($wData[1]);
         switch ($_g1) {
             case "BETWEEN":
                 if (!($values->length === 2) && Lambda::hforeach($values, array(new _hx_lambda(array(&$_g, &$_g1, &$filter_tables, &$first, &$phValues, &$sb, &$sob, &$values, &$w, &$wData, &$where, &$whereParam), "Model_13"), 'execute'))) {
                     S::hexit("BETWEEN needs 2 values - got only:" . _hx_string_or_null($values->join(",")));
                 }
                 $sb->add($this->quoteField($wData[0]));
                 $sb->add(" BETWEEN ? AND ?");
                 $phValues->push(new _hx_array(array($wData[0], $values[0])));
                 $phValues->push(new _hx_array(array($wData[0], $values[1])));
                 break;
             case "IN":
                 $sb->add($this->quoteField($wData[0]));
                 $sb->add(" IN(");
                 $sb->add($values->map(array(new _hx_lambda(array(&$_g, &$_g1, &$filter_tables, &$first, &$phValues, &$sb, &$sob, &$values, &$w, &$wData, &$where, &$whereParam), "Model_14"), 'execute'))->join(","));
                 $sb->add(")");
                 break;
             case "LIKE":
                 $sb->add($this->quoteField($wData[0]));
                 $sb->add(" LIKE ?");
                 $phValues->push(new _hx_array(array($wData[0], $wData[2])));
                 break;
             default:
                 $sb->add($this->quoteField($wData[0]));
                 if (_hx_deref(new EReg("^(<|>)", ""))->match($wData[1])) {
                     $eR = new EReg("^(<|>)", "");
                     $eR->match($wData[1]);
                     $val = Std::parseFloat($eR->matchedRight());
                     $sb->add(_hx_string_or_null($eR->matched(0)) . "?");
                     $phValues->push(new _hx_array(array($wData[0], $val)));
                     continue 2;
                 }
                 if ($wData[1] === "NULL") {
                     $sb->add(" IS NULL");
                 } else {
                     $sb->add(" = ?");
                     $phValues->push(new _hx_array(array($wData[0], $wData[1])));
                 }
                 break;
         }
         unset($_g1);
         unset($wData, $w, $values, $filter_tables);
     }
     $sob->add($sb->b);
     return true;
 }
Ejemplo n.º 8
0
 static function parse($str)
 {
     $abs = new EReg("^" . sinatra_utils_URI::$PATTERN_REMOVE_WHITESPACE->replace(sinatra_utils_URI::$PATTERN_ABS_URI, "") . "\$", "");
     if ($abs->match($str)) {
         return new sinatra_utils_URI($abs, true);
     }
     $rel = new EReg("^" . sinatra_utils_URI::$PATTERN_REMOVE_WHITESPACE->replace(sinatra_utils_URI::$PATTERN_REL_URI, "") . "\$", "");
     if ($rel->match($str)) {
         return new sinatra_utils_URI($rel, false);
     }
     throw new HException("Invalid URI");
 }