public function render($format, $mml, $latex, $properties, $outProperties)
 {
     $servicesClass = Type::resolveClass("com.wiris.editor.services.PublicServices");
     $getInstance = Reflect::field($servicesClass, "getInstance");
     $publicServices = Reflect::callMethod($servicesClass, $getInstance, null);
     $args = new _hx_array(array());
     $args->push($mml);
     $args->push($latex);
     $args->push($properties);
     $args->push($outProperties);
     try {
         if (_hx_index_of($format, "png", null) !== -1) {
             $renderPngMethod = Reflect::field($publicServices, "renderPng");
             $pngObject = Reflect::callMethod($publicServices, $renderPngMethod, $args);
             $pngBytes = $pngObject;
             return haxe_io_Bytes::ofData($pngBytes);
         } else {
             if (_hx_index_of($format, "svg", null) !== -1) {
                 $renderSvgMethod = Reflect::field($publicServices, "renderSvg");
                 $svgObject = Reflect::callMethod($publicServices, $renderSvgMethod, $args);
                 $svgString = $svgObject;
                 return haxe_io_Bytes::ofString($svgString);
             } else {
                 throw new HException("Unexpected image format.");
             }
         }
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         $e = $_ex_;
         throw new HException($e->getMessage());
     }
 }
 public function storeData($digest, $service, $stream)
 {
     $formula = $this->getAndCheckFolder(com_wiris_plugin_api_ConfigurationKeys::$CACHE_FOLDER);
     $parent = $this->getFolderStore($formula, $digest);
     $parent->mkdirs();
     $store = $this->getFileStoreWithParent($parent, $digest, $this->getExtension($service));
     $store->writeBinary(haxe_io_Bytes::ofData($stream));
 }
Exemplo n.º 3
0
 public function request($post)
 {
     $proxy = $this->getProxy();
     if ($proxy !== null && $proxy->host !== null && strlen($proxy->host) > 0) {
         $hpa = $proxy->auth;
         if ($hpa->user !== null && strlen($hpa->user) > 0) {
             $data = _hx_deref(new com_wiris_system_Base64())->encodeBytes(haxe_io_Bytes::ofString($hpa->user . ":" . $hpa->pass))->toString();
             $this->setHeader("Proxy-Authorization", "Basic " . $data);
         }
     }
     parent::request($post);
 }
Exemplo n.º 4
0
 public function readBytes($s, $p, $l)
 {
     if (feof($this->__f)) {
         php_io_FileInput_2($this, $l, $p, $s);
     }
     $r = fread($this->__f, $l);
     if ($r === false) {
         php_io_FileInput_3($this, $l, $p, $r, $s);
     }
     $b = haxe_io_Bytes::ofString($r);
     $s->blit($p, $b, 0, strlen($r));
     return strlen($r);
 }
Exemplo n.º 5
0
 public function readBytes($s, $p, $l)
 {
     if (feof($this->__f)) {
         throw new HException(new haxe_io_Eof());
     }
     $r = fread($this->__f, $l);
     if ($r === false) {
         throw new HException(haxe_io_Error::Custom("An error occurred"));
     }
     $b = haxe_io_Bytes::ofString($r);
     $s->blit($p, $b, 0, strlen($r));
     return strlen($r);
 }
 public function readBytes($s, $p, $l)
 {
     if (feof($this->__f)) {
         return eval("if(isset(\$this)) \$»this =& \$this;throw new HException(new haxe_io_Eof());\n\t\t\t\treturn \$»r;\n\t\t\t");
     }
     $r = fread($this->__f, $l);
     if ($r === false) {
         return eval("if(isset(\$this)) \$»this =& \$this;throw new HException(haxe_io_Error::Custom(\"An error occurred\"));\n\t\t\t\treturn \$»r2;\n\t\t\t");
     }
     $b = haxe_io_Bytes::ofString($r);
     $s->blit($p, $b, 0, strlen($r));
     return strlen($r);
 }
Exemplo n.º 7
0
 public function read($nbytes)
 {
     $s = haxe_io_Bytes::alloc($nbytes);
     $p = 0;
     while ($nbytes > 0) {
         $k = $this->readBytes($s, $p, $nbytes);
         if ($k === 0) {
             throw new HException(haxe_io_Error::$Blocked);
         }
         $p += $k;
         $nbytes -= $k;
         unset($k);
     }
     return $s;
 }
Exemplo n.º 8
0
 public function decodeBytes($bytes)
 {
     return haxe_io_Bytes::ofString(base64_decode($bytes->b));
 }
Exemplo n.º 9
0
 static function fromBytes($s)
 {
     $bs = haxe_io_Bytes::ofData($s);
     return $bs->toString();
 }
Exemplo n.º 10
0
 public function getTestPage()
 {
     $random = "" . _hx_string_rec(Math::floor(Math::random() * 9999), "");
     $mml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow><msqrt><mn>" . $random . "</mn></msqrt></mrow></math>";
     $testName = null;
     $reportText = null;
     $solutionLink = null;
     $condition = null;
     $output = "";
     $output .= "<html><head>\r\n";
     $output .= "<title>WIRIS plugin test page</title><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" /><style type=\"text/css\">/*<!--*/html {font-family: sans-serif;}h2 {margin-left: 1em;}h3 {margin-left: 2em;}p {margin-left: 3em;}p.concrete {margin-left: 4em;}.ok {font-weight: bold;color: #0c0;}.error {font-weight: bold;color: #f00;}/*-->*/</style><style type=\"text/css\">body{font-family: Arial;}span{font-weight: bold;}span.ok {color: #009900;}span.error {color: #dd0000;}table, th, td, tr {border: solid 1px #000000;border-collapse:collapse;padding: 5px;}th{background-color: #eeeeee;}img{border:none;}</style>\r\n";
     $output .= "<script src=\"../core/WIRISplugins.js?viewer=image\" ></script>\r\n";
     $output .= "</head><body><h1>WIRIS plugin test page</h1>\r\n";
     $output .= "<table><tr><th>Test</th><th>Report</th><th>Status</th></tr>\r\n";
     $testName = "WIRIS plugin version";
     try {
         $s = com_wiris_system_Storage::newResourceStorage("VERSION")->read();
         $reportText = "<b>" . $s . "</b>";
         $solutionLink = "";
         $condition = true;
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         $ex = $_ex_;
         $reportText = "Missing version";
         $solutionLink = "";
         $condition = false;
     }
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Creating and storing data";
     $solutionLink = "";
     $param = array();
     $outp = array();
     $imageUrl = $this->plugin->newRender()->createImage($mml, $param, $outp);
     $reportText = "<a href=\"" . $imageUrl . "\" />" . $imageUrl . "</a>";
     $condition = true;
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Retrieving data";
     $solutionLink = "";
     $reportText = "<img src=\"" . $imageUrl . "\" />";
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "JavaScript MathML filter";
     $solutionLink = "";
     $reportText = $mml;
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Host platform";
     $solutionLink = "";
     $platform = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$HOST_PLATFORM, "failed");
     $reportText = $platform;
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Filter test";
     $solutionLink = "";
     $condition = true;
     $p = null;
     $p = array();
     $p["savemode"] = "safeXml";
     $s2 = str_replace("<", com_wiris_plugin_impl_TestImpl_0($this, $condition, $ex, $imageUrl, $mml, $outp, $output, $p, $param, $platform, $random, $reportText, $solutionLink, $testName), $mml);
     $s2 = str_replace(">", com_wiris_plugin_impl_TestImpl_1($this, $condition, $ex, $imageUrl, $mml, $outp, $output, $p, $param, $platform, $random, $reportText, $s2, $solutionLink, $testName), $s2);
     $s2 = str_replace("\"", com_wiris_plugin_impl_TestImpl_2($this, $condition, $ex, $imageUrl, $mml, $outp, $output, $p, $param, $platform, $random, $reportText, $s2, $solutionLink, $testName), $s2);
     $reportText = $this->plugin->newTextService()->filter("square root: " . $s2, $p);
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     $testName = "Connecting to www.wiris.net";
     $solutionLink = "";
     $condition = true;
     try {
         $h = new com_wiris_plugin_impl_HttpImpl("http://www.wiris.net", null);
         $h->request(true);
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         $ex2 = $_ex_;
         $condition = false;
     }
     $reportText = "Checking if WIRIS server is reachable";
     $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     if (Type::resolveClass("com.wiris.editor.services.PublicServices") !== null) {
         $condition = true;
         $testName = "Testing integrated services";
         $reportText = "WIRIS Services installed";
         $solutionLink = "";
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $isLicensed = $this->plugin->isEditorLicensed();
         $condition = false;
         $testName = "WIRIS editor license";
         $reportText = "Checking WIRIS editor valid license";
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $isLicensed);
     } else {
         $reportText = "WIRIS Services not installed";
     }
     $debug = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$DEBUG, "false") === "true";
     if ($debug) {
         $testName = "Font family";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$FONT_FAMILY, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Configuration file";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CONFIGURATION_PATH, "") . "\\configuration.ini";
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Cache path";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CACHE_FOLDER, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Formula path";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$FORMULA_FOLDER, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Integration path";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$INTEGRATION_PATH, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "Context path";
         $solutionLink = "";
         $condition = true;
         $reportText = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CONTEXT_PATH, "");
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "default-configuration.ini load";
         $solutionLink = "";
         $defaultConfiguration = com_wiris_system_Storage::newResourceStorage("default-configuration.ini")->read();
         $condition = $defaultConfiguration !== null && strlen($defaultConfiguration) > 0;
         if ($condition) {
             $reportText = "Length: " . _hx_string_rec(strlen($defaultConfiguration), "");
         } else {
             $reportText = "Not found!";
         }
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
         $testName = "cas.png load";
         $solutionLink = "";
         $casPng = com_wiris_system_Storage::newResourceStorage("cas.png")->readBinary();
         $casPngLength = 0;
         if ($casPng !== null) {
             $casPngLength = haxe_io_Bytes::ofData($casPng)->length;
             $condition = $casPngLength > 0;
         } else {
             $condition = false;
         }
         if ($condition) {
             $reportText = "Length: " . _hx_string_rec($casPngLength, "");
         } else {
             $reportText = "Not found!";
         }
         $output .= $this->createTableRow($testName, $reportText, $solutionLink, $condition);
     }
     $output .= "<div id=\"haxe:trace\"></div>";
     return $output;
 }
Exemplo n.º 11
0
 public function showImage($digest, $mml, $param)
 {
     if ($digest === null && $mml === null) {
         throw new HException("Missing parameters 'formula' or 'mml'.");
     }
     if ($digest !== null && $mml !== null) {
         throw new HException("Only one parameter 'formula' or 'mml' is valid.");
     }
     $atts = false;
     if ($digest === null && $mml !== null) {
         $digest = $this->computeDigest($mml, $param);
     }
     $formula = $this->plugin->getStorageAndCache()->decodeDigest($digest);
     if ($formula === null) {
         throw new HException("Formula associated to digest not found.");
     }
     if (StringTools::startsWith($formula, "<")) {
         throw new HException("Not implemented.");
     }
     $iniFile = com_wiris_util_sys_IniFile::newIniFileFromString($formula);
     $renderParams = $iniFile->getProperties();
     $i = null;
     $ss = $this->getEditorParametersList();
     if ($param !== null) {
         $_g1 = 0;
         $_g = $ss->length;
         while ($_g1 < $_g) {
             $i1 = $_g1++;
             $key = $ss[$i1];
             $value = com_wiris_system_PropertiesTools::getProperty($param, $key, null);
             if ($value !== null) {
                 $atts = true;
                 $renderParams->set($key, $value);
             }
             unset($value, $key, $i1);
         }
     }
     if ($atts) {
         if ($mml !== null) {
             $digest = $this->computeDigest($mml, com_wiris_system_PropertiesTools::toProperties($renderParams));
         } else {
             $digest = $this->computeDigest($renderParams->get("mml"), com_wiris_system_PropertiesTools::toProperties($renderParams));
         }
     }
     $store = $this->plugin->getStorageAndCache();
     $bs = null;
     $bs = $store->retreiveData($digest, "png");
     if ($bs === null) {
         $_g1 = 0;
         $_g = $ss->length;
         while ($_g1 < $_g) {
             $i1 = $_g1++;
             $key = $ss[$i1];
             if (!$renderParams->exists($key)) {
                 $confKey = com_wiris_plugin_api_ConfigurationKeys::$imageConfigProperties->get($key);
                 if ($confKey !== null) {
                     $value = $this->plugin->getConfiguration()->getProperty($confKey, null);
                     if ($value !== null) {
                         $renderParams->set($key, $value);
                     }
                     unset($value);
                 }
                 unset($confKey);
             }
             unset($key, $i1);
         }
         $h = new com_wiris_plugin_impl_HttpImpl($this->plugin->getImageServiceURL(null), null);
         $this->plugin->addReferer($h);
         $this->plugin->addProxy($h);
         $iter = $renderParams->keys();
         while ($iter->hasNext()) {
             $key = $iter->next();
             $h->setParameter($key, $renderParams->get($key));
             unset($key);
         }
         $h->request(true);
         $b = haxe_io_Bytes::ofString($h->getData());
         $store->storeData($digest, "png", $b->b);
         $bs = $b->b;
     }
     return $bs;
 }
Exemplo n.º 12
0
 static function getBytes($path)
 {
     return haxe_io_Bytes::ofString(sys_io_File::getContent($path));
 }
 public function readString($len)
 {
     $b = haxe_io_Bytes::alloc($len);
     $this->readFullBytes($b, 0, $len);
     return $b->toString();
 }
 static function parseMultipart($onPart, $onData)
 {
     $a = $_POST;
     if (get_magic_quotes_gpc()) {
         reset($a);
         while (list($k, $v) = each($a)) {
             $a[$k] = stripslashes((string) $v);
         }
     }
     $post = php_Lib::hashOfAssociativeArray($a);
     if (null == $post) {
         throw new HException('null iterable');
     }
     $__hx__it = $post->keys();
     while ($__hx__it->hasNext()) {
         unset($key);
         $key = $__hx__it->next();
         call_user_func_array($onPart, array($key, ""));
         $v = $post->get($key);
         if (is_array($v)) {
             $map = php_Lib::hashOfAssociativeArray($v);
             $first = true;
             if (null == $map) {
                 throw new HException('null iterable');
             }
             $__hx__it2 = $map->iterator();
             while ($__hx__it2->hasNext()) {
                 unset($val);
                 $val = $__hx__it2->next();
                 if (!$first) {
                     call_user_func_array($onPart, array($key, ""));
                 }
                 call_user_func_array($onData, array(haxe_io_Bytes::ofString($val), 0, strlen($val)));
                 $first = false;
             }
             unset($map, $first);
         } else {
             call_user_func_array($onData, array(haxe_io_Bytes::ofString($v), 0, strlen($v)));
         }
         unset($v);
     }
     if (!isset($_FILES)) {
         return;
     }
     $parts = new _hx_array(array_keys($_FILES));
     $_g = 0;
     while ($_g < $parts->length) {
         $part = $parts[$_g];
         ++$_g;
         $info = $_FILES[$part];
         $tmp = $info["tmp_name"];
         $file = $info["name"];
         $err = $info["error"];
         if ($err > 0) {
             switch ($err) {
                 case 1:
                     throw new HException("The uploaded file exceeds the max size of " . _hx_string_or_null(ini_get("upload_max_filesize")));
                     break;
                 case 2:
                     throw new HException("The uploaded file exceeds the max file size directive specified in the HTML form (max is" . _hx_string_or_null(_hx_string_or_null(ini_get("post_max_size")) . ")"));
                     break;
                 case 3:
                     throw new HException("The uploaded file was only partially uploaded");
                     break;
                 case 4:
                     continue 2;
                     break;
                 case 6:
                     throw new HException("Missing a temporary folder");
                     break;
                 case 7:
                     throw new HException("Failed to write file to disk");
                     break;
                 case 8:
                     throw new HException("File upload stopped by extension");
                     break;
             }
         }
         call_user_func_array($onPart, array($part, $file));
         if ("" !== $file) {
             $h = fopen($tmp, "r");
             $bsize = 8192;
             while (!feof($h)) {
                 $buf = fread($h, $bsize);
                 $size = strlen($buf);
                 call_user_func_array($onData, array(haxe_io_Bytes::ofString($buf), 0, $size));
                 unset($size, $buf);
             }
             fclose($h);
             unset($h, $bsize);
         }
         unset($tmp, $part, $info, $file, $err);
     }
 }
Exemplo n.º 15
0
 public function writeBinary($bs)
 {
     $bytes = haxe_io_Bytes::ofData($bs);
     $fo = sys_io_File::write($this->location, true);
     $fo->writeBytes($bytes, 0, $bytes->length);
 }
Exemplo n.º 16
0
 static function decodeBase64($imageParameter)
 {
     $b = new com_wiris_system_Base64();
     $dataDecoded = $b->decodeBytes(haxe_io_Bytes::ofString($imageParameter));
     return $dataDecoded;
 }
Exemplo n.º 17
0
 public function storeData($digest, $service, $stream)
 {
     $formula = $this->getAndCheckFolder(com_wiris_plugin_api_ConfigurationKeys::$CACHE_FOLDER);
     $store = com_wiris_util_sys_Store::newStoreWithParent(com_wiris_util_sys_Store::newStore($formula), $digest . $this->getExtension($service));
     $store->writeBinary(haxe_io_Bytes::ofData($stream));
 }
Exemplo n.º 18
0
 public function writeFloat($x)
 {
     $this->write(haxe_io_Bytes::ofString(pack("f", $x)));
 }
Exemplo n.º 19
0
 public function createImage($mml, $param, &$output)
 {
     $output = $output;
     if ($mml === null) {
         throw new HException("Missing parameter 'mml'.");
     }
     $digest = $this->computeDigest($mml, $param);
     $contextPath = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$CONTEXT_PATH, "/");
     $showImagePath = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$SHOWIMAGE_PATH, null);
     $saveMode = $this->plugin->getConfiguration()->getProperty(com_wiris_plugin_api_ConfigurationKeys::$SAVE_MODE, "xml");
     $s = "";
     if ($param !== null && com_wiris_system_PropertiesTools::getProperty($param, "metrics", "false") === "true") {
         $s = $this->getMetrics($digest, $output);
     }
     $a = "";
     if ($param !== null && com_wiris_system_PropertiesTools::getProperty($param, "accessible", "false") === "true") {
         $lang = com_wiris_system_PropertiesTools::getProperty($param, "lang", "en");
         $text = $this->safeMath2Accessible($mml, $lang, $param);
         if ($output === null) {
             $a = "&text=" . rawurlencode($text);
         } else {
             $output["alt"] = $text;
         }
     }
     $rparam = "";
     if ($param !== null && com_wiris_system_PropertiesTools::getProperty($param, "refererquery", null) !== null) {
         $refererquery = com_wiris_system_PropertiesTools::getProperty($param, "refererquery", null);
         $rparam = "&refererquery=" . $refererquery;
     }
     if ($param !== null && com_wiris_system_PropertiesTools::getProperty($param, "base64", null) !== null || $saveMode === "base64") {
         $bs = $this->showImage($digest, null, $param);
         $by = haxe_io_Bytes::ofData($bs);
         $b64 = _hx_deref(new com_wiris_system_Base64())->encodeBytes($by);
         return "data:image/png;base64," . $b64->toString();
     } else {
         return com_wiris_plugin_impl_RenderImpl::concatPath($contextPath, $showImagePath) . rawurlencode($digest) . $s . $a . $rparam;
     }
 }
Exemplo n.º 20
0
 public function readAll($bufsize = null)
 {
     if ($bufsize === null) {
         $bufsize = 8192;
     }
     $buf = haxe_io_Bytes::alloc($bufsize);
     $total = new haxe_io_BytesBuffer();
     try {
         while (true) {
             $len = $this->readBytes($buf, 0, $bufsize);
             if ($len === 0) {
                 throw new HException(haxe_io_Error::$Blocked);
             }
             if ($len < 0 || $len > $buf->length) {
                 throw new HException(haxe_io_Error::$OutsideBounds);
             }
             $total->b .= substr($buf->b, 0, $len);
             unset($len);
         }
     } catch (Exception $»e) {
         $_ex_ = $»e instanceof HException ? $»e->e : $»e;
         if (($e = $_ex_) instanceof haxe_io_Eof) {
         } else {
             throw $»e;
         }
     }
     return $total->getBytes();
 }
Exemplo n.º 21
0
 static function string2ByteData_iso8859_1($str)
 {
     return haxe_io_Bytes::ofString($str);
 }
Exemplo n.º 22
0
 public function unserialize()
 {
     $_g = null;
     $p = $this->pos++;
     $_g = ord(substr($this->buf, $p, 1));
     switch ($_g) {
         case 110:
             return null;
             break;
         case 116:
             return true;
             break;
         case 102:
             return false;
             break;
         case 122:
             return 0;
             break;
         case 105:
             return $this->readDigits();
             break;
         case 100:
             $p1 = $this->pos;
             while (true) {
                 $c = ord(substr($this->buf, $this->pos, 1));
                 if ($c >= 43 && $c < 58 || $c === 101 || $c === 69) {
                     $this->pos++;
                 } else {
                     break;
                 }
                 unset($c);
             }
             return Std::parseFloat(_hx_substr($this->buf, $p1, $this->pos - $p1));
             break;
         case 121:
             $len = $this->readDigits();
             if (haxe_Unserializer_3($this, $_g, $len) !== 58 || $this->length - $this->pos < $len) {
                 throw new HException("Invalid string length");
             }
             $s = _hx_substr($this->buf, $this->pos, $len);
             $this->pos += $len;
             $s = urldecode($s);
             $this->scache->push($s);
             return $s;
             break;
         case 107:
             return Math::$NaN;
             break;
         case 109:
             return Math::$NEGATIVE_INFINITY;
             break;
         case 112:
             return Math::$POSITIVE_INFINITY;
             break;
         case 97:
             $buf = $this->buf;
             $a = new _hx_array(array());
             $this->cache->push($a);
             while (true) {
                 $c1 = ord(substr($this->buf, $this->pos, 1));
                 if ($c1 === 104) {
                     $this->pos++;
                     break;
                 }
                 if ($c1 === 117) {
                     $this->pos++;
                     $n = $this->readDigits();
                     $a[$a->length + $n - 1] = null;
                     unset($n);
                 } else {
                     $a->push($this->unserialize());
                 }
                 unset($c1);
             }
             return $a;
             break;
         case 111:
             $o = _hx_anonymous(array());
             $this->cache->push($o);
             $this->unserializeObject($o);
             return $o;
             break;
         case 114:
             $n1 = $this->readDigits();
             if ($n1 < 0 || $n1 >= $this->cache->length) {
                 throw new HException("Invalid reference");
             }
             return $this->cache[$n1];
             break;
         case 82:
             $n2 = $this->readDigits();
             if ($n2 < 0 || $n2 >= $this->scache->length) {
                 throw new HException("Invalid string reference");
             }
             return $this->scache[$n2];
             break;
         case 120:
             throw new HException($this->unserialize());
             break;
         case 99:
             $name = $this->unserialize();
             $cl = $this->resolver->resolveClass($name);
             if ($cl === null) {
                 throw new HException("Class not found " . _hx_string_or_null($name));
             }
             $o1 = Type::createEmptyInstance($cl);
             $this->cache->push($o1);
             $this->unserializeObject($o1);
             return $o1;
             break;
         case 119:
             $name1 = $this->unserialize();
             $edecl = $this->resolver->resolveEnum($name1);
             if ($edecl === null) {
                 throw new HException("Enum not found " . _hx_string_or_null($name1));
             }
             $e = $this->unserializeEnum($edecl, $this->unserialize());
             $this->cache->push($e);
             return $e;
             break;
         case 106:
             $name2 = $this->unserialize();
             $edecl1 = $this->resolver->resolveEnum($name2);
             if ($edecl1 === null) {
                 throw new HException("Enum not found " . _hx_string_or_null($name2));
             }
             $this->pos++;
             $index = $this->readDigits();
             $tag = _hx_array_get(Type::getEnumConstructs($edecl1), $index);
             if ($tag === null) {
                 throw new HException("Unknown enum index " . _hx_string_or_null($name2) . "@" . _hx_string_rec($index, ""));
             }
             $e1 = $this->unserializeEnum($edecl1, $tag);
             $this->cache->push($e1);
             return $e1;
             break;
         case 108:
             $l = new HList();
             $this->cache->push($l);
             $buf1 = $this->buf;
             while (ord(substr($this->buf, $this->pos, 1)) !== 104) {
                 $l->add($this->unserialize());
             }
             $this->pos++;
             return $l;
             break;
         case 98:
             $h = new haxe_ds_StringMap();
             $this->cache->push($h);
             $buf2 = $this->buf;
             while (ord(substr($this->buf, $this->pos, 1)) !== 104) {
                 $s1 = $this->unserialize();
                 $h->set($s1, $this->unserialize());
                 unset($s1);
             }
             $this->pos++;
             return $h;
             break;
         case 113:
             $h1 = new haxe_ds_IntMap();
             $this->cache->push($h1);
             $buf3 = $this->buf;
             $c2 = null;
             $p3 = $this->pos++;
             $c2 = ord(substr($this->buf, $p3, 1));
             while ($c2 === 58) {
                 $i = $this->readDigits();
                 $h1->set($i, $this->unserialize());
                 $p4 = $this->pos++;
                 $c2 = ord(substr($this->buf, $p4, 1));
                 unset($p4);
                 unset($i);
             }
             if ($c2 !== 104) {
                 throw new HException("Invalid IntMap format");
             }
             return $h1;
             break;
         case 77:
             $h2 = new haxe_ds_ObjectMap();
             $this->cache->push($h2);
             $buf4 = $this->buf;
             while (ord(substr($this->buf, $this->pos, 1)) !== 104) {
                 $s2 = $this->unserialize();
                 $h2->set($s2, $this->unserialize());
                 unset($s2);
             }
             $this->pos++;
             return $h2;
             break;
         case 118:
             $d = Date::fromString(_hx_substr($this->buf, $this->pos, 19));
             $this->cache->push($d);
             $this->pos += 19;
             return $d;
             break;
         case 115:
             $len1 = $this->readDigits();
             $buf5 = $this->buf;
             if (haxe_Unserializer_4($this, $_g, $buf5, $len1) !== 58 || $this->length - $this->pos < $len1) {
                 throw new HException("Invalid bytes length");
             }
             $codes = haxe_Unserializer::$CODES;
             if ($codes === null) {
                 $codes = haxe_Unserializer::initCodes();
                 haxe_Unserializer::$CODES = $codes;
             }
             $i1 = $this->pos;
             $rest = $len1 & 3;
             $size = null;
             $size = ($len1 >> 2) * 3 + haxe_Unserializer_5($this, $_g, $buf5, $codes, $i1, $len1, $rest, $size);
             $max = $i1 + ($len1 - $rest);
             $bytes = haxe_io_Bytes::alloc($size);
             $bpos = 0;
             while ($i1 < $max) {
                 $c11 = $codes[haxe_Unserializer_6($this, $_g, $bpos, $buf5, $bytes, $codes, $i1, $len1, $max, $rest, $size)];
                 $c21 = $codes[haxe_Unserializer_7($this, $_g, $bpos, $buf5, $bytes, $c11, $codes, $i1, $len1, $max, $rest, $size)];
                 $pos = $bpos++;
                 $bytes->b[$pos] = chr($c11 << 2 | $c21 >> 4);
                 unset($pos);
                 $c3 = $codes[haxe_Unserializer_8($this, $_g, $bpos, $buf5, $bytes, $c11, $c21, $codes, $i1, $len1, $max, $rest, $size)];
                 $pos1 = $bpos++;
                 $bytes->b[$pos1] = chr($c21 << 4 | $c3 >> 2);
                 unset($pos1);
                 $c4 = $codes[haxe_Unserializer_9($this, $_g, $bpos, $buf5, $bytes, $c11, $c21, $c3, $codes, $i1, $len1, $max, $rest, $size)];
                 $pos2 = $bpos++;
                 $bytes->b[$pos2] = chr($c3 << 6 | $c4);
                 unset($pos2);
                 unset($c4, $c3, $c21, $c11);
             }
             if ($rest >= 2) {
                 $c12 = $codes[haxe_Unserializer_10($this, $_g, $bpos, $buf5, $bytes, $codes, $i1, $len1, $max, $rest, $size)];
                 $c22 = $codes[haxe_Unserializer_11($this, $_g, $bpos, $buf5, $bytes, $c12, $codes, $i1, $len1, $max, $rest, $size)];
                 $pos3 = $bpos++;
                 $bytes->b[$pos3] = chr($c12 << 2 | $c22 >> 4);
                 if ($rest === 3) {
                     $c31 = $codes[haxe_Unserializer_12($this, $_g, $bpos, $buf5, $bytes, $c12, $c22, $codes, $i1, $len1, $max, $rest, $size)];
                     $pos4 = $bpos++;
                     $bytes->b[$pos4] = chr($c22 << 4 | $c31 >> 2);
                 }
             }
             $this->pos += $len1;
             $this->cache->push($bytes);
             return $bytes;
             break;
         case 67:
             $name3 = $this->unserialize();
             $cl1 = $this->resolver->resolveClass($name3);
             if ($cl1 === null) {
                 throw new HException("Class not found " . _hx_string_or_null($name3));
             }
             $o2 = Type::createEmptyInstance($cl1);
             $this->cache->push($o2);
             $o2->hxUnserialize($this);
             if (haxe_Unserializer_13($this, $_g, $cl1, $name3, $o2) !== 103) {
                 throw new HException("Invalid custom data");
             }
             return $o2;
             break;
         default:
             break;
     }
     $this->pos--;
     throw new HException("Invalid char " . _hx_string_or_null(_hx_char_at($this->buf, $this->pos)) . " at position " . _hx_string_rec($this->pos, ""));
 }
Exemplo n.º 23
0
 public function writeString($s)
 {
     $b = haxe_io_Bytes::ofString($s);
     $this->writeFullBytes($b, 0, $b->length);
 }
Exemplo n.º 24
0
 static function decode($s, $base)
 {
     $b = new haxe_BaseCode(haxe_io_Bytes::ofString($base));
     return $b->decodeString($s);
 }
Exemplo n.º 25
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));
     }
 }
Exemplo n.º 26
0
 public function readHttpResponse($api, $sock)
 {
     $b = new haxe_io_BytesBuffer();
     $k = 4;
     $s = haxe_io_Bytes::alloc(4);
     $sock->setTimeout($this->cnxTimeout);
     while (true) {
         $p = $sock->input->readBytes($s, 0, $k);
         while ($p !== $k) {
             $p += $sock->input->readBytes($s, $p, $k - $p);
         }
         if ($k < 0 || $k > $s->length) {
             throw new HException(haxe_io_Error::$OutsideBounds);
         }
         $b->b .= _hx_string_or_null(substr($s->b, 0, $k));
         switch ($k) {
             case 1:
                 $c = ord($s->b[0]);
                 if ($c === 10) {
                     break 2;
                 }
                 if ($c === 13) {
                     $k = 3;
                 } else {
                     $k = 4;
                 }
                 break;
             case 2:
                 $c1 = ord($s->b[1]);
                 if ($c1 === 10) {
                     if (ord($s->b[0]) === 13) {
                         break 2;
                     }
                     $k = 4;
                 } else {
                     if ($c1 === 13) {
                         $k = 3;
                     } else {
                         $k = 4;
                     }
                 }
                 break;
             case 3:
                 $c2 = ord($s->b[2]);
                 if ($c2 === 10) {
                     if (ord($s->b[1]) !== 13) {
                         $k = 4;
                     } else {
                         if (ord($s->b[0]) !== 10) {
                             $k = 2;
                         } else {
                             break 2;
                         }
                     }
                 } else {
                     if ($c2 === 13) {
                         if (ord($s->b[1]) !== 10 || ord($s->b[0]) !== 13) {
                             $k = 1;
                         } else {
                             $k = 3;
                         }
                     } else {
                         $k = 4;
                     }
                 }
                 break;
             case 4:
                 $c3 = ord($s->b[3]);
                 if ($c3 === 10) {
                     if (ord($s->b[2]) !== 13) {
                         continue 2;
                     } else {
                         if (ord($s->b[1]) !== 10 || ord($s->b[0]) !== 13) {
                             $k = 2;
                         } else {
                             break 2;
                         }
                     }
                 } else {
                     if ($c3 === 13) {
                         if (ord($s->b[2]) !== 10 || ord($s->b[1]) !== 13) {
                             $k = 3;
                         } else {
                             $k = 1;
                         }
                     }
                 }
                 break;
         }
         unset($p);
     }
     $headers = _hx_explode("\r\n", $b->getBytes()->toString());
     $response = $headers->shift();
     $rp = _hx_explode(" ", $response);
     $status = Std::parseInt($rp[1]);
     if ($status === 0 || $status === null) {
         throw new HException("Response status error");
     }
     $headers->pop();
     $headers->pop();
     $this->responseHeaders = new haxe_ds_StringMap();
     $size = null;
     $chunked = false;
     $_g = 0;
     while ($_g < $headers->length) {
         $hline = $headers[$_g];
         ++$_g;
         $a = _hx_explode(": ", $hline);
         $hname = $a->shift();
         $hval = null;
         if ($a->length === 1) {
             $hval = $a[0];
         } else {
             $hval = $a->join(": ");
         }
         $s1 = rtrim($hval);
         $hval = ltrim($s1);
         unset($s1);
         $this->responseHeaders->set($hname, $hval);
         $_g1 = strtolower($hname);
         switch ($_g1) {
             case "content-length":
                 $size = Std::parseInt($hval);
                 break;
             case "transfer-encoding":
                 $chunked = strtolower($hval) === "chunked";
                 break;
         }
         unset($_g1);
         unset($hval, $hname, $hline, $a);
     }
     $this->onStatus($status);
     $chunk_re = new EReg("^([0-9A-Fa-f]+)[ ]*\r\n", "m");
     $this->chunk_size = null;
     $this->chunk_buf = null;
     $bufsize = 1024;
     $buf = haxe_io_Bytes::alloc($bufsize);
     if ($size === null) {
         if (!$this->noShutdown) {
             $sock->shutdown(false, true);
         }
         try {
             while (true) {
                 $len = $sock->input->readBytes($buf, 0, $bufsize);
                 if ($chunked) {
                     if (!$this->readChunk($chunk_re, $api, $buf, $len)) {
                         break;
                     }
                 } else {
                     $api->writeBytes($buf, 0, $len);
                 }
                 unset($len);
             }
         } catch (Exception $__hx__e) {
             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
             if (($e = $_ex_) instanceof haxe_io_Eof) {
             } else {
                 throw $__hx__e;
             }
         }
     } else {
         $api->prepare($size);
         try {
             while ($size > 0) {
                 $len1 = $sock->input->readBytes($buf, 0, $size > $bufsize ? $bufsize : $size);
                 if ($chunked) {
                     if (!$this->readChunk($chunk_re, $api, $buf, $len1)) {
                         break;
                     }
                 } else {
                     $api->writeBytes($buf, 0, $len1);
                 }
                 $size -= $len1;
                 unset($len1);
             }
         } catch (Exception $__hx__e) {
             $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e;
             if (($e1 = $_ex_) instanceof haxe_io_Eof) {
                 throw new HException("Transfer aborted");
             } else {
                 throw $__hx__e;
             }
         }
     }
     if ($chunked && ($this->chunk_size !== null || $this->chunk_buf !== null)) {
         throw new HException("Invalid chunk");
     }
     if ($status < 200 || $status >= 400) {
         throw new HException("Http Error #" . _hx_string_rec($status, ""));
     }
     $api->close();
 }