diff --git a/CHANGELOG.md b/CHANGELOG.md index 16a2b30..676935b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,30 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). -## 6.2.13 (TBD) +## 7.0.1 (TBD) + +## 7.0.0 (2017-03-06) + +This release includes merges from the upstream original php-java-bridge 7.0.1, +Due to license restrictions, the PHPDebugger.java additions have **not** been merged +in the 7.0.0 version. See [#49](https://github.com/belgattitude/php-java-bridge/issues/49) + + +### Added + +- Added configuration `enableDirectoryIndex()` in `JavaBridgeRunner` and changed its + value to `true`, set it to `false` to prevent directory listing. See [#43](https://github.com/belgattitude/php-java-bridge/issues/43). +- Documentation: added embedding recipes (wip, see [#51](https://github.com/belgattitude/php-java-bridge/issues/51) for progress) + +### Bugfix + +- **Upstream-7.0.1:** Bugfix in `WriterOutputStream.java`. ### Updated -- gradlew updated to v3.4.0 +- **Upstream-7.0.1:** Legacy Java.inc updated with upstream support for PHP7 + and rebuilt of javainc.java, proxy... *(Note that Java.inc is kept for upstream + compat, but have been deprecated in the fork in favour of soluble-japha instead)* ## 6.2.12 (2017-02-21) diff --git a/VERSION b/VERSION index 1a400c8..9fe9ff9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.2.11 +7.0.1 diff --git a/build.gradle b/build.gradle index 665bcd6..04d85db 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ apply plugin: 'maven-publish' group = "io.soluble.pjb" archivesBaseName = 'php-java-bridge' //version = "6.2.11" -version = "6.2.13-SNAPSHOT" +version = "7.0.1-SNAPSHOT" description = "PHPJavaBridge server (soluble fork)" ext { diff --git a/build.xml b/build.xml index 155b27a..46d1e55 100644 --- a/build.xml +++ b/build.xml @@ -20,6 +20,7 @@ + @@ -88,6 +89,21 @@ + + + + + + + + + + + diff --git a/doc/legacy/ChangeLog b/doc/legacy/ChangeLog index c8b7e45..015c5f8 100644 --- a/doc/legacy/ChangeLog +++ b/doc/legacy/ChangeLog @@ -1,3 +1,22 @@ +2017-02-25 + + * PhpDebugger.inc: Removed + + * Client.inc: Warning fixed. + + * PHPDebugger.php: Rewritten to use latest protocol + + * Util.java, FCGIConnectionFactory.java, IFCGIProcessFactory.java, NPChannelFactory.java, SocketChannelFactory.java, CGIRunner.java, FCGIProcess.java, FastCGIProxy.java, ContextLoaderListener.java, FCGIProcess.java, FastCGIServlet.java: Use PHPDebuger.php + +2017-02-01 + + * WriterOutputStream.java: Fixed crash. + + +2017-01-30 + + * Protocol.inc, PHPDebugger.php, PHPDebugger.inc, Parser.inc, Options.inc, NativeParser.inc, JavaProxy.inc, JavaBridge.inc, GlobalRef.inc, Client.inc: Changed constructor + 2010-06-01 * php/java/script/servlet/EngineFactory.java diff --git a/doc/legacy/NEWS b/doc/legacy/NEWS index 1750b2e..9f0ae3c 100644 --- a/doc/legacy/NEWS +++ b/doc/legacy/NEWS @@ -3,6 +3,23 @@ php-java-bridge NEWS -- history of user-visible changes. Please send bug reports, questions and suggestions to . +Version 7.0.0 + +* Fixed a bug in Java.inc and Client.inc + +* PHPDebugger.php now uses the latest protocol and is now part of the PHP/Java Bridge. It can be switched off by addint the following line to WEB-INF/web.xml: + php_include_debuggerOff + + +Version 6.2.3 + +* Fixed a bug in WriterOutputStream. + + +Version 6.2.2 + +* Changed old constructor to __construct + Version 6.2.1 * java_session(null, false) now returns false if a session does not exist. diff --git a/doc/notes_fork_status.md b/doc/notes_fork_status.md index 5422cd3..660b349 100644 --- a/doc/notes_fork_status.md +++ b/doc/notes_fork_status.md @@ -21,6 +21,7 @@ Latest version 6.2.1 has been released long ago but, AFAIK, proved stable and ma - [x] Travis CI support with soluble-japha client suite [tests](https://github.com/belgattitude/php-java-bridge/blob/master/.travis/run_soluble_japha_phpunit_tests.sh) - [x] Clean-up of obsolete code and unused resources. - [x] Releases starting at 6.2.10 +- [x] Merged upstream changes for 7.0.1 (without GPL debugger). See [#49](https://github.com/belgattitude/php-java-bridge/issues/49) - [ ] Deprecate and remove completely the `Java.inc` client. - [ ] Security review and safe practices. - [ ] Documentation (always a wip) diff --git a/doc/recipes_embedding.md b/doc/recipes_embedding.md new file mode 100644 index 0000000..dbb6072 --- /dev/null +++ b/doc/recipes_embedding.md @@ -0,0 +1,69 @@ +# Embed recipes + +> This document is currently a work-in-progess stub. To learn more +> see the [#51](https://github.com/belgattitude/php-java-bridge/issues/51) +> and feel free to contribute. + +## Introduction + +The php-java-bridge provides a standalone server (`JavaBridgeRunner`) for +embedding the bridge. In the soluble fork, this internal server have been +deprecated in favour of embedded Tomcat, Jetty... adopted more widely. + + +## Embedded containers + + +### Tomcat + + +1. Add the embedded tomcat in your dependencies: + + With maven: + + ```xml + + org.apache.tomcat.embed + tomcat-embed-core + 7.0.75 + + + org.apache.tomcat + tomcat-juli + 7.0.75 + + ``` + + With gradle + + ```gradle + // todo + ``` + +2. Register servlet and start tomcat. + + ```java + public void startTomcat() { + Tomcat tomcat = new Tomcat(); + tomcat.setPort(8087); + Context ctx = tomcat.addContext("/", new File(".").getAbsolutePath()); + Tomcat.addServlet(ctx, "jbs", new JavaBridgeServlet()); + ctx.addServletMapping("/*", "jbs"); + try { + tomcat.start(); + log("started, now waiting for connections..."); + tomcat.getServer().await(); + } catch (Exception e) { + warning(e.getMessage()); + } + } + ``` + +### Jetty + +> The doPut() method Seems buggy right now. See [#43](https://github.com/belgattitude/php-java-bridge/issues/43) + +### Undertow + +(todo) + diff --git a/legacy/server/META-INF/MANIFEST.MF b/legacy/server/META-INF/MANIFEST.MF index 12b38ca..5ee635b 100644 --- a/legacy/server/META-INF/MANIFEST.MF +++ b/legacy/server/META-INF/MANIFEST.MF @@ -1,4 +1,4 @@ Manifest-Version: 1.0 -Main-Class: php.java.bridge.Standalone +Main-Class: io.soluble.pjb.bridge.Standalone Created-By: 1.5.0 (Sun Microsystems Inc.) Class-Path: php-script.jar script-api.jar log4j.jar diff --git a/legacy/server/META-INF/java/Client.inc b/legacy/server/META-INF/java/Client.inc index 59b024c..ba3e9c9 100644 --- a/legacy/server/META-INF/java/Client.inc +++ b/legacy/server/META-INF/java/Client.inc @@ -53,7 +53,7 @@ require_once(java_get_base()."/GlobalRef.inc"); */ class java_SimpleFactory { public $client; - function java_SimpleFactory($client) { + function __construct($client) { $this->client = $client; } function getProxy($result, $signature, $exception, $wrap) { @@ -138,7 +138,7 @@ class java_CacheEntry { public $fmt, $signature, $factory, $java; public $resultVoid; - function java_CacheEntry($fmt, $signature, $factory, $resultVoid) { + function __construct($fmt, $signature, $factory, $resultVoid) { $this->fmt = $fmt; $this->signature = $signature; $this->factory = $factory; @@ -155,7 +155,7 @@ class java_Arg { public $factory, $val; public $signature; // class type - function java_Arg($client) { + function __construct($client) { $this->client = $client; $this->factory = $client->simpleFactory; } @@ -211,8 +211,8 @@ class java_CompositeArg extends java_Arg { public $type; // for A and X public $counter; - function java_CompositeArg($client, $type) { - parent::java_Arg($client); + function __construct($client, $type) { + parent::__construct($client); $this->type = $type; $this->val = array(); $this->counter = 0; @@ -237,8 +237,8 @@ class java_CompositeArg extends java_Arg { class java_ApplyArg extends java_CompositeArg { public $m, $p, $v, $n; // see PROTOCOL.TXT - function java_ApplyArg($client, $type, $m, $p, $v, $n) { - parent::java_CompositeArg($client, $type); + function __construct($client, $type, $m, $p, $v, $n) { + parent::__construct($client, $type); $this->m = $m; $this->p = $p; $this->v = $v; @@ -261,7 +261,7 @@ class java_Client /* implements IDocHandler */ { $arrayProxyFactory, $exceptionProxyFactory, $throwExceptionProxyFactory; public $arg; - public $asyncCtx, $cancelProxyCreationCounter; + public $asyncCtx, $cancelProxyCreationTag; public $globalRef; public $stack; @@ -279,7 +279,7 @@ class java_Client /* implements IDocHandler */ { // do not finish protocol if ags construction fails due to PHP OutOfMemory error public $inArgs; - function java_Client() { + function __construct() { $this->RUNTIME = array(); $this->RUNTIME["NOTICE"]='***USE echo java_inspect(jVal) OR print_r(java_values(jVal)) TO SEE THE CONTENTS OF THIS JAVA OBJECT!***'; @@ -299,7 +299,7 @@ class java_Client /* implements IDocHandler */ { $this->globalRef = new java_GlobalRef(); - $this->asyncCtx = $this->cancelProxyCreationCounter = 0; + $this->asyncCtx = $this->cancelProxyCreationTag = 0; $this->methodCache = $this->defaultCache; diff --git a/legacy/server/META-INF/java/GlobalRef.inc b/legacy/server/META-INF/java/GlobalRef.inc index b9decde..d3e03ea 100644 --- a/legacy/server/META-INF/java/GlobalRef.inc +++ b/legacy/server/META-INF/java/GlobalRef.inc @@ -53,7 +53,7 @@ class java_GlobalRef { public $map; - function java_GlobalRef() { + function __construct() { $this->map = array(); } diff --git a/legacy/server/META-INF/java/JavaBridge.inc b/legacy/server/META-INF/java/JavaBridge.inc index f990285..33e9104 100644 --- a/legacy/server/META-INF/java/JavaBridge.inc +++ b/legacy/server/META-INF/java/JavaBridge.inc @@ -174,10 +174,10 @@ if(!function_exists("java_get_base")) { function java_virtual($path, $return=false) { $req = java_context()->getHttpServletRequest(); - $req = new java("io.soluble.pjb.servlet.VoidInputHttpServletRequest", $req); + $req = new java("php.java.servlet.VoidInputHttpServletRequest", $req); $res = java_context()->getHttpServletResponse(); - $res = new java("io.soluble.pjb.servlet.RemoteHttpServletResponse", $res); + $res = new java("php.java.servlet.RemoteHttpServletResponse", $res); $req->getRequestDispatcher($path)->include($req, $res); if ($return) return $res->getBufferContents(); @@ -390,7 +390,7 @@ if(!function_exists("java_get_base")) { * ByteArrayOutputStream out; * OutputStreamWriter writer; * e.getContext().setWriter(writer=new OutputStreamWriter(out=new ByteArrayOutputStream())); - * Object res=e.eval(new io.soluble.pjb.script.URLReader(new URL("http://localhost/calculateSales.php"))); + * Object res=e.eval(new php.java.script.URLReader(new URL("http://localhost/calculateSales.php"))); * System.err.println(((Invocable)e).invokeFunction("calculateSales", new Object[]{month})); * ((Closeable)e).close(); * System.err.println("PHP exit() code:" + String.valueOf(res)); diff --git a/legacy/server/META-INF/java/JavaProxy.inc b/legacy/server/META-INF/java/JavaProxy.inc index 56041c5..eef5ccd 100644 --- a/legacy/server/META-INF/java/JavaProxy.inc +++ b/legacy/server/META-INF/java/JavaProxy.inc @@ -215,6 +215,14 @@ function java_unwrap ($object) { function java_values($object) { return java_values_internal($object); } +/** + * Only for internal use. + * @access private + */ +function java_reset() { + $client=__javaproxy_Client_getClient(); + return $client->invokeMethod(0, "reset", array()); +} /** * Only for internal use * @access private @@ -348,6 +356,9 @@ function java_cast($object, $type) { */ function java_require($arg) { trigger_error('java_require() not supported anymore. Please use __java=$java; $this->__signature=$signature; $this->__client = __javaproxy_Client_getClient(); @@ -674,7 +685,7 @@ class java_JavaProxy implements java_JavaType { class java_objectIterator implements Iterator { private $var; - function java_ObjectIterator($javaProxy) { + function __construct($javaProxy) { $this->var = java_cast ($javaProxy, "A"); } function rewind() { @@ -885,7 +896,7 @@ class Java extends java_AbstractJava { * @see function Java * @see function java_values */ - function Java() { + function __construct() { $client = $this->__client = __javaproxy_Client_getClient(); $args = func_get_args(); @@ -904,7 +915,7 @@ class Java extends java_AbstractJava { case 'boolean': array_push($args2, $val); $sig.='@b'; break; case 'integer': array_push($args2, $val); $sig.='@i'; break; case 'double': array_push($args2, $val); $sig.='@d'; break; - case 'string': array_push($args2, htmlspecialchars($val, ENT_COMPAT)); $sig.='@s'; break; + case 'string': array_push($args2, htmlspecialchars($val, ENT_COMPAT,"ISO-8859-1")); $sig.='@s'; break; case 'array':$sig="~INVALID"; break; case 'object': if($val instanceof java_JavaType) { @@ -996,7 +1007,7 @@ class Java extends java_AbstractJava { case 'boolean': array_push($args2, $val); $sig.='@b'; break; case 'integer': array_push($args2, $val); $sig.='@i'; break; case 'double': array_push($args2, $val); $sig.='@d'; break; - case 'string': array_push($args2, htmlspecialchars($val, ENT_COMPAT)); $sig.='@s'; break; + case 'string': array_push($args2, htmlspecialchars($val, ENT_COMPAT,"ISO-8859-1")); $sig.='@s'; break; case 'array':$sig="~INVALID"; break; case 'object': if($val instanceof java_JavaType) { @@ -1050,7 +1061,7 @@ class Java extends java_AbstractJava { * @access private */ class java_InternalJava extends Java { - function java_InternalJava($proxy) { + function __construct($proxy) { $this->__delegate = $proxy; $this->__java = $proxy->__java; $this->__signature = $proxy->__signature; @@ -1062,7 +1073,7 @@ class java_InternalJava extends Java { * @access private */ class java_class extends Java { - function java_class() { + function __construct() { $this->__client = __javaproxy_Client_getClient(); $args = func_get_args(); @@ -1107,7 +1118,7 @@ class java_exception extends Exception implements java_JavaType { * throw $ex; * */ - function java_exception() { + function __construct() { $this->__client = __javaproxy_Client_getClient(); $args = func_get_args(); @@ -1192,7 +1203,7 @@ class JavaException extends java_exception {} * @access private */ class java_InternalException extends JavaException { - function java_InternalException($proxy, $exception) { + function __construct($proxy, $exception) { $this->__delegate = $proxy; $this->__java = $proxy->__java; $this->__signature = $proxy->__signature; @@ -1205,7 +1216,7 @@ class java_InternalException extends JavaException { * @access private */ class java_JavaProxyProxy extends Java { - function java_JavaProxyProxy($client) { + function __construct($client) { $this->__client = $client; } } diff --git a/legacy/server/META-INF/java/NativeParser.inc b/legacy/server/META-INF/java/NativeParser.inc index d4a88a0..6d80a77 100644 --- a/legacy/server/META-INF/java/NativeParser.inc +++ b/legacy/server/META-INF/java/NativeParser.inc @@ -53,7 +53,7 @@ class java_NativeParser { public $buf; - function java_NativeParser($handler) { + function __construct($handler) { $this->handler = $handler; $this->parser = xml_parser_create(); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); diff --git a/legacy/server/META-INF/java/PHPDebugger.php b/legacy/server/META-INF/java/PHPDebugger.php new file mode 100644 index 0000000..0120575 --- /dev/null +++ b/legacy/server/META-INF/java/PHPDebugger.php @@ -0,0 +1,2288 @@ += 3.5.2 + * + * - Open Window -> Preferences -> Servers and set Default Web Server to: http://localhost:8080 + * - Deploy JavaBridgeTemplate.war + * - Create a new Project using .../apache-tomcat-7.0.75/webapps/JavaBridgeTemplate as directory + * - Open index.php and start debugger: Default Web Server with Zend Debugger (other options default) + * - Click debug + * + * To debug standalone applications, remove zend_extension=ZendDebugger.so from your php.ini and set: + * + * + * ;; activate the PHPDebugger in the php.ini + * auto_prepend_file=PHPDebugger.php + * + * + * - Debug your PHP scripts as usual. + * + * + * @category java + * @package pdb + * @author Jost Boekemeier + * @license GPL+Classpath exception + * @version 7.0 + * @link http://php-java-bridge.sf.net/phpdebugger + */ + + +/** @access private */ +define ("PDB_DEBUG", 0); +set_time_limit (0); +if(!function_exists("token_get_all")) { + dl("tokenizer.so"); +} + +if ($pdb_script_orig = $pdb_script = pdb_getDebugHeader("X_JAVABRIDGE_INCLUDE", $_SERVER)) { + if ($pdb_script!="@") { + if (($_SERVER['REMOTE_ADDR']=='127.0.0.1') || (($pdb_script = realpath($pdb_script)) && (!strncmp($_SERVER['DOCUMENT_ROOT'], $pdb_script, strlen($_SERVER['DOCUMENT_ROOT']))))) { + if(pdb_getDebugHeader("X_JAVABRIDGE_INCLUDE", $_SERVER)>=10) { // include Java.inc as well + require_once("Java.inc"); + } + chdir (dirname ($pdb_script)); + $_SERVER['SCRIPT_FILENAME'] = $pdb_script; // set to the original script filename + } else { + trigger_error("illegal access: ".$pdb_script_orig, E_USER_ERROR); + unset($pdb_script); + } + } +} + + + +if (!class_exists("pdb_Parser")) { + /** + * The PHP parser + * @access private + */ + class pdb_Parser { + const BLOCK = 1; + const STATEMENT = 2; + const EXPRESSION = 3; + const FUNCTION_BLOCK = 4; // BLOCK w/ STEP() as last statement + + private $scriptName, $content; + private $code; + private $output; + private $line, $currentLine; + private $beginStatement, $inPhp, $inDQuote; + + /** + * Create a new PHP parser + * @param string the script name + * @param string the script content + * @access private + */ + public function __construct($scriptName, $content) { + $this->scriptName = $scriptName; + $this->content = $content; + $this->code = token_get_all($content); + $this->output = ""; + $this->line = $this->currentLine = 0; + $this->beginStatement = $this->inPhp = $this->inDQuote = false; + } + + private function toggleDQuote($chr) { + if ($chr == '"') $this->inDQuote = !$this->inDQuote; + } + + private function each() { + $next = each ($this->code); + if ($next) { + $cur = current($this->code); + if (is_array($cur)) { + $this->currentLine = $cur[2] + ($cur[1][0] == "\n" ? substr_count($cur[1], "\n") : 0); + if ($this->isWhitespace($cur)) { + $this->write($cur[1]); + return $this->each(); + } + } + else + $this->toggleDQuote($cur); + } + return $next; + } + + private function write($code) { + //echo "write:::".$code."\n"; + $this->output.=$code; + } + + private function writeInclude($once) { + $name = ""; + while(1) { + if (!$this->each()) die("parse error"); + $val = current($this->code); + if (is_array($val)) { + $name.=$val[1]; + } else { + if ($val==';') break; + $name.=$val; + } + } + if (PDB_DEBUG == 2) + $this->write("EVAL($name);"); + else + $this->write("eval('?>'.pdb_startInclude($name, $once)); pdb_endInclude();"); + } + + private function writeCall() { + while(1) { + if (!$this->each()) die("parse error"); + $val = current($this->code); + if (is_array($val)) { + $this->write($val[1]); + } else { + $this->write($val); + if ($val=='{') break; + } + } + $scriptName = addslashes($this->scriptName); + $this->write("\$__pdb_CurrentFrame=pdb_startCall(\"$scriptName\", {$this->currentLine});"); + } + + private function writeStep($pLevel) { + $token = current($this->code); + if ($this->inPhp && !$pLevel && !$this->inDQuote && $this->beginStatement && !$this->isWhitespace($token) && ($this->line != $this->currentLine)) { + $line = $this->line = $this->currentLine; + $scriptName = addslashes($this->scriptName); + if (PDB_DEBUG == 2) + $this->write(";STEP($line);"); + else + $this->write(";pdb_step(\"$scriptName\", $line, pdb_getDefinedVars(get_defined_vars(), (isset(\$this) ? \$this : NULL)));"); + } + } + + private function writeNext() { + $this->next(); + $token = current($this->code); + if (is_array($token)) $token = $token[1]; + $this->write($token); + } + + private function nextIs($chr) { + $i = 0; + while(each($this->code)) { + $cur = current($this->code); + $i++; + if (is_array($cur)) { + switch ($cur[0]) { + case T_COMMENT: + case T_DOC_COMMENT: + case T_WHITESPACE: + break; /* skip */ + default: + while($i--) prev($this->code); + return false; /* not found */ + } + } else { + while($i--) prev($this->code); + return $cur == $chr; /* found */ + } + } + while($i--) prev($this->code); + return false; /* not found */ + } + + private function nextTokenIs($ar) { + $i = 0; + while(each($this->code)) { + $cur = current($this->code); + $i++; + if (is_array($cur)) { + switch ($cur[0]) { + case T_COMMENT: + case T_DOC_COMMENT: + case T_WHITESPACE: + break; /* skip */ + default: + while($i--) prev($this->code); + return (in_array($cur[0], $ar)); + } + } else { + break; /* not found */ + } + } + while($i--) prev($this->code); + return false; /* not found */ + } + + private function isWhitespace($token) { + $isWhitespace = false; + switch($token[0]) { + case T_COMMENT: + case T_DOC_COMMENT: + case T_WHITESPACE: + $isWhitespace = true; + break; + } + return $isWhitespace; + } + private function next() { + if (!$this->each()) trigger_error("parse error", E_USER_ERROR); + } + + private function parseBlock () { + $this->parse(self::BLOCK); + } + private function parseFunction () { + $this->parse(self::FUNCTION_BLOCK); + } + private function parseStatement () { + $this->parse(self::STATEMENT); + } + private function parseExpression () { + $this->parse(self::EXPRESSION); + } + + private function parse ($type) { + pdb_Logger::debug("parse:::$type"); + + $this->beginStatement = true; + $pLevel = 0; + + do { + $token = current($this->code); + if (!is_array($token)) { + pdb_Logger::debug(":::".$token); + if (!$pLevel && $type==self::FUNCTION_BLOCK && $token=='}') $this->writeStep($pLevel); + $this->write($token); + if ($this->inPhp && !$this->inDQuote) { + $this->beginStatement = false; + switch($token) { + case '(': + $pLevel++; + break; + case ')': + if (!--$pLevel && $type==self::EXPRESSION) return; + break; + case '{': + $this->next(); + $this->parseBlock(); + break; + case '}': + if (!$pLevel) return; + break; + case ';': + if (!$pLevel) { + if ($type==self::STATEMENT) return; + $this->beginStatement = true; + } + break; + } + } + } else { + pdb_Logger::debug(":::".$token[1].":(".token_name($token[0]).')'); + + if ($this->inDQuote) { + $this->write($token[1]); + continue; + } + + switch($token[0]) { + + case T_OPEN_TAG: + case T_START_HEREDOC: + case T_OPEN_TAG_WITH_ECHO: + $this->beginStatement = $this->inPhp = true; + $this->write($token[1]); + break; + + case T_END_HEREDOC: + case T_CLOSE_TAG: + $this->writeStep($pLevel); + + $this->write($token[1]); + $this->beginStatement = $this->inPhp = false; + break; + + case T_FUNCTION: + $this->write($token[1]); + $this->writeCall(); + $this->next(); + $this->parseFunction(); + $this->beginStatement = true; + break; + + case T_ELSE: + $this->write($token[1]); + if ($this->nextIs('{')) { + $this->writeNext(); + $this->next(); + + $this->parseBlock(); + } else { + $this->next(); + + /* create an artificial block */ + $this->write('{'); + $this->beginStatement = true; + $this->writeStep($pLevel); + $this->parseStatement(); + $this->write('}'); + + } + if ($type==self::STATEMENT) return; + + $this->beginStatement = true; + break; + + case T_DO: + $this->writeStep($pLevel); + $this->write($token[1]); + if ($this->nextIs('{')) { + $this->writeNext(); + $this->next(); + + $this->parseBlock(); + $this->next(); + + } else { + $this->next(); + + /* create an artificial block */ + $this->write('{'); + $this->beginStatement = true; + $this->writeStep($pLevel); + $this->parseStatement(); + $this->next(); + $this->write('}'); + } + $token = current($this->code); + $this->write($token[1]); + + if ($token[0]!=T_WHILE) trigger_error("parse error", E_USER_ERROR); + $this->next(); + $this->parseExpression(); + + if ($type==self::STATEMENT) return; + + $this->beginStatement = true; + break; + + case T_CATCH: + case T_IF: + case T_ELSEIF: + case T_FOR: + case T_FOREACH: + case T_WHILE: + $this->writeStep($pLevel); + + $this->write($token[1]); + $this->next(); + + $this->parseExpression(); + + if ($this->nextIs('{')) { + $this->writeNext(); + $this->next(); + + $this->parseBlock(); + + + } else { + $this->next(); + /* create an artificial block */ + $this->write('{'); + $this->beginStatement = true; + $this->writeStep($pLevel); + $this->parseStatement(); + $this->write('}'); + } + + if ($this->nextTokenIs(array(T_ELSE, T_ELSEIF, T_CATCH))) { + $this->beginStatement = false; + } else { + if ($type==self::STATEMENT) return; + $this->beginStatement = true; + } + break; + + case T_REQUIRE_ONCE: + case T_INCLUDE_ONCE: + case T_INCLUDE: + case T_REQUIRE: + $this->writeStep($pLevel); + $this->writeInclude((($token[0]==T_REQUIRE_ONCE) || ($token[0]==T_INCLUDE_ONCE)) ? 1 : 0); + + if ($type==self::STATEMENT) return; + + $this->beginStatement = true; + break; + + case T_CLASS: + $this->write($token[1]); + $this->writeNext(); + if ($this->nextIs('{')) { + $this->writeNext(); + $this->next(); + $this->parseBlock(); + $this->beginStatement = true; + } else { + $this->writeNext(); + $this->beginStatement = false; + } + break; + + case T_CASE: + case T_DEFAULT: + case T_PUBLIC: + case T_PRIVATE: + case T_PROTECTED: + case T_STATIC: + case T_CONST: + case T_GLOBAL: + case T_ABSTRACT: + $this->write($token[1]); + $this->beginStatement = false; + break; + + default: + $this->writeStep($pLevel); + $this->write($token[1]); + $this->beginStatement = false; + break; + + } + } + } while($this->each()); + } + + /** + * parse the given PHP script + * @return the parsed PHP script + * @access private + */ + public function parseScript() { + do { + $this->parseBlock(); + } while($this->each()); + + return $this->output; + } + } +} + +/** + * @access private + */ +class pdb_Logger { + const FATAL = 1; + const INFO = 2; + const VERBOSE = 3; + const DEBUG = 4; + + private static $logLevel = 0; + private static $logFileName; + + private static function println($msg, $level) { + if (!self::$logLevel) self::$logLevel=PDB_DEBUG?self::DEBUG:self::INFO; + if ($level <= self::$logLevel) { + static $file = null; + if(!isset(self::$logFileName)) { + self::$logFileName = $_SERVER['HOME'].DIRECTORY_SEPARATOR."pdb_PHPDebugger.inc.log"; + } + if (!$file) $file = fopen(self::$logFileName, "ab") or die("fopen"); + fwrite($file, time().": "); + fwrite($file, $msg."\n"); + fflush($file); + } + } + + public static function logFatal($msg) { + self::println($msg, self::FATAL); + } + public static function logInfo($msg) { + self::println($msg, self::INFO); + } + public static function logMessage($msg) { + self::println($msg, self::VERBOSE); + } + public static function logDebug($msg) { + self::println($msg, self::DEBUG); + } + public static function debug($msg) { + self::logDebug($msg); + } + public static function log($msg) { + self::logMessage($msg); + } + public static function setLogLevel($level) { + self::$logLevel=$level; + } + public static function setLogFileName($name) { + self::$logFileName = $name; + } +} + +/** + * @access private + */ +class pdb_Environment { + public $filename, $stepNext; + public $vars, $line, $firstLine; + public $parent; + + public function __construct($parent, $filename, $stepNext, $firstLine) { + $this->parent = $parent; + $this->filename = $filename; + $this->stepNext = $stepNext; + $this->firstLine = $firstLine; + $this->line = -1; + } + + public function update ($line, &$vars) { + $this->line = $line; + $this->vars = &$vars; + } + public function __toString() { + return "pdb_Environment: {$this->filename}, {$this->firstLine} - {$this->line}"; + } +} + +/** + * @access private + */ +abstract class pdb_Message { + public $session; + + public abstract function getType(); + + public function __construct($session) { + $this->session = $session; + } + + public function serialize() { + $this->session->out->writeShort($this->getType()); + } + + private static $messages = array(); + public static function register($message) { + pdb_Message::$messages[$message->getType()] = $message; + } + public function getMessageById($id) { + $message = pdb_Message::$messages[$id]; + return $message; + } + public function getMessage() { + $id = $this->session->in->readShort(); + $message = $this->getMessageById($id); + if (!$message) trigger_error("invalid message: $id", E_USER_ERROR); + $message->deserialize(); + return $message; + } + + protected function handleContinueProcessFile($message) { + $code = $this->session->parseCode($this->currentFrame->filename, file_get_contents($this->currentFrame->filename)); + if (PDB_DEBUG) pdb_Logger::debug( "parse file:::" . $code ."\n"); + if (!PDB_DEBUG) ob_start(); + self::doEval ($code); + $output = $this->getMessageById(pdb_OutputNotification::TYPE); + if(!PDB_DEBUG) $output->setOutput(ob_get_contents()); + if(!PDB_DEBUG) ob_end_clean(); + $output->serialize(); + $this->status = 42; //FIXME + $this->getMessageById(pdb_DebugScriptEndedNotification::TYPE)->serialize(); + return true; + } + private static function doEval($__pdb_Code) { + return eval ("?>".$__pdb_Code); + } + protected function handleStep($message) { + return false; + } + protected function handleGo($message) { + foreach ($this->session->allFrames as $frame) { + $frame->stepNext = false; + } + return true; // exit + } + public function handleRequests () { + $this->ignoreInterrupt = false; + + $this->serialize(); + while(1) { + $message = $this->getMessage(); + switch ($message->getType()) { + case pdb_SetProtocolRequest::TYPE: + $message->ack(); + break; + case pdb_StartRequest::TYPE: + $message->ack(); + $this->getMessageById(pdb_StartProcessFileNotification::TYPE)->serialize(); + break; + case pdb_ContinueProcessFileNotification::TYPE: + if ($this->handleContinueProcessFile($message)) return pdb_ContinueProcessFileNotification::TYPE; + break; + case pdb_AddBreakpointRequest::TYPE: + $message->ack(); + break; + case pdb_RemoveBreakpointRequest::TYPE: + $message->ack(); + break; + case pdb_RemoveAllBreakpointsRequest::TYPE: + $message->ack(); + break; + case pdb_GetCallStackRequest::TYPE: + $message->ack(); + break; + case pdb_GetCWDRequest::TYPE: + $message->ack(); + break; + case pdb_GetVariableValueRequest::TYPE: + $message->ack(); + break; + case pdb_AddFilesRequest::TYPE: + $message->ack(); + break; + case pdb_FileContentExtendedRequest::TYPE: + $message->ack(); + break; + case pdb_MsgEvalRequest::TYPE: + $message->ack(); + break; + case pdb_GoRequest::TYPE: + $message->ack(); + if ($this->handleGo($message)) return pdb_GoRequest::TYPE; + break; + case pdb_StepOverRequest::TYPE: + $message->ack(); + if ($this->handleStep($message)) return pdb_StepOverRequest::TYPE; + break; + case pdb_StepIntoRequest::TYPE: + $message->ack(); + if ($this->handleStep($message)) return pdb_StepIntoRequest::TYPE; + break; + case pdb_StepOutRequest::TYPE: + $message->ack(); + if ($this->handleStep($message)) return pdb_StepOutRequest::TYPE; + break; + case pdb_End::TYPE: + $this->session->end(); + default: trigger_error("protocol error: $message", E_USER_ERROR); + } + } + } +} +/** + * @access private + */ +abstract class pdb_MessageRequest extends pdb_Message { + public abstract function ack(); +} + +/** + * @access private + */ +class pdb_Serializer { + private $serial; + private $depth; + + private function doSerialize ($o, $depth) { + $serial = &$this->serial; + + switch(gettype($o)) { + case 'object': + $serial.="O:"; + $serial.=strlen(get_class($o)); + $serial.=":\""; + $serial.=get_class($o); + $serial.="\":"; + $serial.=count((array)$o); + + if ($depth <= $this->depth) { + $serial.=":{"; + foreach((array)$o as $k=>$v) { + $serial.=serialize($k); + $this->doSerialize($v, $depth+1); + } + $serial.="}"; + } else { + $serial .= ";"; + } + break; + + case 'array': + $serial.="a:"; + $serial.=count($o); + + if ($depth <= $this->depth) { + $serial.=":{"; + foreach($o as $k=>$v) { + $serial.=serialize($k); + $this->doSerialize($v, $depth+1); + } + $serial.="}"; + } else { + $serial.=";"; + } + break; + default: + $serial.=serialize($o); + break; + } + } + + public function serialize ($obj, $depth) { + $this->serial = ""; + $this->depth = $depth; + + $this->doSerialize ($obj, 1); + + return $this->serial; + } +} + +/** + * @access private + */ +class pdb_DebugSessionStart extends pdb_Message { + const TYPE = 2005; + + public $status; + public $end; + + private $breakFirstLine; + private $enable; + public $uri; + public $query; + public $options; + + public $in, $out; + private $outputNotification; + + public $lines; + public $breakpoints; + + public $currentTopLevelFrame, $currentFrame; + public $allFrames; // should be a weak map so that frames could be gc'ed + + public $ignoreInterrupt; + + public $serializer; + + public $includedScripts; + + public function getType() { + return self::TYPE; + } + public function __construct($options) { + parent::__construct($this); + $this->end = true; + if (isset($_SERVER["SCRIPT_FILENAME"]) && isset($_SERVER["QUERY_STRING"])&&!extension_loaded("Zend Debugger")) { + $filename = $uri = $_SERVER["SCRIPT_FILENAME"]; + $queryStr = $_SERVER["QUERY_STRING"]; + } else { + $this->enable = false; + return; + } + + $params = explode('&', $queryStr); + $args = array(); + for ($i=0; $iend = false; + + $this->in =new pdb_In($io, $this); + $this->out=new pdb_Out($io, $this); + } + public function end() { + $this->end = true; + if (PDB_DEBUG) pdb_Logger::debug( "end() called"); + exit(0); + } + /** + * @access private + */ + public function flushOutput() { + if (!isset($this->outputNotification)) + $this->outputNotification = $this->getMessageById(pdb_OutputNotification::TYPE); + + $this->outputNotification->setOutput(ob_get_contents()); + if (!PDB_DEBUG) ob_clean(); + $this->outputNotification->serialize(); + } + + /** + * @access private + */ + public function resolveIncludePath($scriptName) { + if (file_exists($scriptName)) return realpath($scriptName); + $paths = explode(PATH_SEPARATOR, get_include_path()); + $name = $scriptName; + foreach ($paths as $path) { + $scriptName = realpath("${path}${name}"); + if ($scriptName) return $scriptName; + } + trigger_error("file $scriptName not found", E_USER_ERROR); + } + + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt(2004102501); + $out->writeString($this->currentFrame->filename); + $out->writeString($this->uri); + $out->writeString($this->query); + $out->writeString($this->options); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function handleRequests () { + if ($this->enable) { + set_error_handler("pdb_error_handler"); + register_shutdown_function("pdb_shutdown"); + + parent::handleRequests(); + if (PDB_DEBUG) pdb_Logger::debug( "exit({$this->status})"); + exit ($this->status); } + } + public function hasBreakpoint($scriptName, $line) { + if ($this->breakFirstLine) {$this->breakFirstLine = false; return true;} + + if ($this->currentFrame->stepNext) return true; + + foreach ($this->breakpoints as $breakpoint) { + if($breakpoint->type==1) { + if ($breakpoint->file==$scriptName&&$breakpoint->line==$line) return true; + } + } + + return false; + } + function parseCode($filename, $contents) { + $parser = new pdb_Parser($filename, $contents); + return $parser->parseScript(); + } + + public function __toString() { + return "pdb_DebugSessionStart: {$this->currentFrame->filename}"; + } +} + + +/** + * @access private + */ +class pdb_HeaderOutputNotification extends pdb_Message { + const TYPE = 2008; + private $out; + + public function setOutput($out) { + $this->out = $out; + } + protected function getAsciiOutput() { + return $this->out; + } + protected function getEncodedOutput () { + return $this->out; //FIXME + } + protected function getOutput() { + return $this->getAsciiOutput(); + } + public function getType() { + return self::TYPE; + } + + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeString($this->getOutput()); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_HeaderOutputNotification: ".$this->getOutput(); + } +} + +/** + * @access private + */ +class pdb_OutputNotification extends pdb_HeaderOutputNotification { + const TYPE = 2004; + + public function getType() { + return self::TYPE; + } + protected function getOutput() { + return $this->getEncodedOutput(); + } + public function __toString () { + return "pdb_OutputNotification: ".$this->getAsciiOutput(); + } +} + +/** + * @access private + */ +class pdb_ErrorNotification extends pdb_Message { + const TYPE = 2006; + private $type, $filename, $lineno, $error; + + public function getType() { + return self::TYPE; + } + public function setError($type, $filename, $lineno, $error) { + $this->type = $type; + $this->filename = $filename; + $this->lineno = $lineno; + $this->error = $error; + } + + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->type); + $out->writeString($this->filename); + $out->writeInt($this->lineno); + $out->writeString($this->error); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_ErrorNotification: {$this->error} at {$this->filename} line {$this->lineno}"; + } +} + +/** + * @access private + */ +class pdb_DebugScriptEndedNotification extends pdb_Message { + const TYPE = 2002; + + public function getType() { + return self::TYPE; + } + + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeShort($this->session->status); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_DebugScriptEndedNotification: {$this->session->status}"; + } +} + + +/** + * @access private + */ +class pdb_ReadyNotification extends pdb_Message { + const TYPE = 2003; + + public function getType() { + return self::TYPE; + } + + protected function handleStep($message) { + return true; + } + + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeString($this->session->currentFrame->filename); + $out->writeInt($this->session->currentFrame->line); + $out->writeInt(0); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_ReadyNotification: {$this->session->currentFrame->filename}, {$this->session->currentFrame->line}"; + } +} + +/** + * @access private + */ +class pdb_SetProtocolRequest extends pdb_MessageRequest { + const TYPE = 10000; + public $id; + public $protocolId; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + $this->protocolId = $in->readInt(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_SetProtocolResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_SetProtocolRequest: ". $this->protocolId; + } +} + +/** + * @access private + */ +class pdb_SetProtocolResponse extends pdb_Message { + const TYPE = 11000; + private $req; + + public function __construct ($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + + // use fixed id instead of $out->writeInt($this->req->protocolId); + $out->writeInt(2012121702); + + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_SetProtocolResponse: "; + } +} + +/** + * @access private + */ +class pdb_StartRequest extends pdb_MessageRequest { + const TYPE = 1; + public $id; + public $protocolId; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + + public function ack() { + $res = new pdb_StartResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_StartRequest: "; + } +} + +/** + * @access private + */ +class pdb_AddFilesRequest extends pdb_MessageRequest { + const TYPE = 38; + public $id; + public $pathSize; + public $paths; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + $this->pathSize = $in->readInt(); + $this->paths = array(); + for($i=0; $i<$this->pathSize; $i++) { + $this->paths[] = $in->readString(); + } + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + + public function ack() { + $res = new pdb_AddFilesResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_AddFilesRequest: "; + } +} +/** + * @access private + */ +class pdb_FileContentExtendedRequest extends pdb_MessageRequest { + const TYPE = 10002; + public $id; + public $size; + public $checksum; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + $this->size = $in->readInt(); + $this->checksum = $in->readInt(); + + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + + public function ack() { + $res = new pdb_FileContentExtendedResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_FileContentExtendedRequest: "; + } +} + +/** + * @access private + */ +class pdb_AddFilesResponse extends pdb_Message { + const TYPE = 1038; + private $req; + + public function __construct ($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + $out->writeInt(0); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_AddFilesResponse: "; + } +} + +/** + * @access private + */ +class pdb_FileContentExtendedResponse extends pdb_Message { + const TYPE = 11001; + private $req; + + public function __construct ($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + $out->writeInt(0); // fixme: status + $out->writeInt(0); // fixme: string: filecontent + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_FileContentExtendedResponse: "; + } +} + +/** + * @access private + */ +class pdb_StartResponse extends pdb_Message { + const TYPE = 1001; + private $req; + + public function __construct ($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + $out->writeInt(0); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_StartResponse: "; + } +} +/** + * @access private + */ +class pdb_StartProcessFileNotification extends pdb_Message { + const TYPE = 2009; + public function __construct ($session) { + parent::__construct($session); + } + protected function handleContinueProcessFile($message) { + return true; // next + } + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeString($this->session->currentFrame->filename); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_StartProcessFileNotification: {$this->session->currentFrame->filename}"; + } +} + +/** + * @access private + */ +class pdb_ContinueProcessFileNotification extends pdb_Message { + const TYPE = 2010; + public function getType() { + return self::TYPE; + } + public function deserialize() { + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_ContinueProcessFileNotification: "; + } +} + +/** + * @access private + */ +class pdb_Breakpoint { + public $type, $lifeTime, $file, $line, $condition; + private $id; + + public function __construct($type, $lifeTime, $file, $line, $condition, $id) { + $this->type = $type; + $this->lifeTime = $lifeTime; + $this->file = $file; + $this->line = $line; + $this->condition = $condition; + $this->id = $id; + } + public function __toString () { + return "pdb_Breakpoint: "; + } +} +/** + * @access private + */ +class pdb_AddBreakpointResponse extends pdb_Message { + const TYPE = 1021; + private $req; + private $id; + + private static function getId() { + static $id = 0; + return ++$id; + } + + public function __construct($req) { + parent::__construct($req->session); + $this->req = $req; + $this->id = self::getId(); + $this->session->breakpoints[$this->id] = new pdb_Breakpoint($req->type, $req->lifeTime, $req->file, $req->line, $req->condition, $this->id); + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + $out->writeInt(0); + $out->writeInt($this->id); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_AddBreakpointResponse: {$this->id}"; + } +} + +/** + * @access private + */ +class pdb_RemoveBreakpointResponse extends pdb_Message { + const TYPE = 1022; + private $req; + private $id; + private $failure; + + public function __construct($req) { + parent::__construct($req->session); + $this->req = $req; + + $this->remove(); + } + + protected function remove() { + if (isset($this->session->breakpoints[$this->req->bpId])) { + unset($this->session->breakpoints[$this->req->bpId]); + $this->failure = 0; + } else { + $this->failure = -1; + } + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + $out->writeInt($this->failure); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_RemoveBreakpointResponse: {$this->id}"; + } +} +/** + * @access private + */ +class pdb_RemoveAllBreakpointsResponse extends pdb_RemoveBreakpointResponse { + const TYPE = 1023; + public function __construct($req) { + parent::__construct($req); + } + + protected function remove() { + $keys = array_keys($this->session->breakpoints); + foreach($keys as $key) + unset($this->session->breakpoints[$key]); + + $this->failure = 0; + } + + public function getType() { + return self::TYPE; + } + + public function __toString () { + return "pdb_RemoveAllBreakpoinstResponse: {$this->id}"; + } +} + +/** + * @access private + */ +class pdb_AddBreakpointRequest extends pdb_MessageRequest { + const TYPE = 21; + public $id; + public $type; + public $lifeTime; + + public $file; + public $line; + + public $condition; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + $this->type = $in->readShort(); + $this->lifeType = $in->readShort(); + switch($this->type) { + case 1: + $this->file = $in->readString(); + $this->line = $in->readInt(); + break; + case 2: + $this->condition = $in->readString(); + break; + default: + trigger_error("invalid breakpoint", E_USER_ERROR); + } + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_AddBreakpointResponse ($this); + $res->serialize(); + } + public function __toString () { + if ($this->type == 1) + return "pdb_AddBreakpointRequest: {$this->file}, {$this->line}"; + else + return "pdb_AddBreakpointRequest: {$this->condition}"; + } +} +/** + * @access private + */ +class pdb_RemoveAllBreakpointsRequest extends pdb_MessageRequest { + const TYPE = 23; + public $id; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_RemoveAllBreakpointsResponse ($this); + $res->serialize(); + } + public function __toString () { + return "pdb_RemoveAllBreakpointsRequest "; + } +} +/** + * @access private + */ +class pdb_RemoveBreakpointRequest extends pdb_RemoveAllBreakpointsRequest { + const TYPE = 22; + public $bpId; + + public function getType() { + return self::TYPE; + } + + public function deserialize() { + parent::deserialize(); + $in = $this->session->in; + $this->bpId = $in->readInt(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_RemoveBreakpointResponse ($this); + $res->serialize(); + } + public function __toString () { + return "pdb_RemoveBreakpointRequest: {$this->bpId}"; + } +} + +/** + * @access private + */ +class pdb_GetCallStackResponse extends pdb_Message { + const TYPE = 1034; + private $req; + + public function __construct($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + + for($frame=$this->session->currentFrame; $frame; $frame=$frame->parent) + $environments[] = $frame; + + $environments = array_reverse($environments); + $n = count($environments); + + $out->writeInt($n); + for ($i=0; $i<$n; $i++) { + $env = $environments[$i]; + $out->writeString($env->filename); + $out->writeInt($env->line); + $out->writeInt(0); + $out->writeString($env->filename); + $out->writeInt($env->firstLine); + $out->writeInt(0); + $out->writeInt(0); //fixme: params + } + + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_GetCallStackResponse: "; + } +} +/** + * @access private + */ +class pdb_GetCallStackRequest extends pdb_MessageRequest { + const TYPE = 34; + public $id; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_GetCallStackResponse ($this); + $res->serialize(); + } + public function __toString () { + return "pdb_GetCallStackRequest: "; + } +} + + +/** + * @access private + */ +class pdb_GetCWDResponse extends pdb_Message { + const TYPE = 1036; + private $req; + + public function __construct ($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + $out->writeInt(0); + $out->writeString(getcwd()); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_GetCWDResponse: "; + } +} + +/** + * @access private + */ +class pdb_GetCWDRequest extends pdb_MessageRequest { + const TYPE = 36; + public $id; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_GetCWDResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_GetCWDRequest: "; + } +} + +/** + * @access private + */ +class pdb_MsgEvalResponse extends pdb_Message { + const TYPE = 1031; + private $req; + + public function __construct ($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + if (PDB_DEBUG) pdb_Logger::debug( "evalcode:::".$this->req->code."\n"); + $error = 0; + $code = $this->req->code; + $res = eval("return $code ?>"); + $out->writeInt($error); + $out->writeString($res); + + if (PDB_DEBUG) pdb_Logger::debug("pdb_MsgEvalResponse: ".print_r($res, true)); + $out->flush(); + } + public function __toString () { + return "pdb_MsgEvalResponse: "; + } +} +/** + * @access private + */ +class pdb_GetVariableValueResponse extends pdb_Message { + const TYPE = 1032; + private $req; + + public function __construct ($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + if (PDB_DEBUG) pdb_Logger::debug( "evalcode:::".$this->req->code."\n"); + $error = 0; + if ($this->req->code[0]=='$') { + + $this->session->end = true; + $key = substr($this->req->code, 1); + if (isset($this->session->currentFrame->vars[$key])) { + $var = $this->session->currentFrame->vars[$key]; + $paths = $this->req->paths; + foreach ($paths as $path) { + if (is_object($var)) { + $var = $var->$path; + } else { + $var = $var[$path]; + } + } + } else { + $var = "${key} not found!"; + $error = -1; + } + $ser = $this->session->serializer->serialize($var, $this->req->depth); + $this->session->end = false; + + $out->writeInt($error); + $out->writeString($ser); + if (PDB_DEBUG) pdb_Logger::debug("pdb_GetVariableValueResponse: ".print_r($var, true).": ${ser}, error: ${error}"); + } else { + if (PDB_DEBUG) pdb_Logger::debug(print_r($this->session->currentFrame->vars, true)); + + $this->session->end = true; + $vars = $this->session->currentFrame->vars; + $ser = $this->session->serializer->serialize($vars, $this->req->depth); + $this->session->end = false; + + $out->writeInt($error); + $out->writeString($ser); + if (PDB_DEBUG) pdb_Logger::debug("pdb_GetVariableValueResponse: ".print_r($vars, true).": ${ser}, error: ${error}"); + } + $out->flush(); + } + public function __toString () { + return "pdb_GetVariableValueResponse: "; + } +} + +/** + * @access private + */ +class pdb_MsgEvalRequest extends pdb_MessageRequest { + const TYPE = 31; + public $id; + public $code; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + $this->code = $in->readString(); + + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_MsgEvalResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_MsgEvalRequest: {$this->code}"; + } +} + +/** + * @access private + */ +class pdb_GetVariableValueRequest extends pdb_MessageRequest { + const TYPE = 32; + public $id; + public $code; + public $depth; + public $paths; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + $this->code = $in->readString(); + $this->depth = $in->readInt(); + + $this->paths = array(); + $length = $in->readInt(); + while($length--) { + $this->paths[] = $in->readString(); + } + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_GetVariableValueResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_GetVariableValueRequest: {$this->code}, {$this->depth}, paths::".print_r($this->paths, true); + } +} + +/** + * @access private + */ +class pdb_StepOverResponse extends pdb_Message { + const TYPE = 1012; + private $req; + + public function __construct($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->req->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + $out->writeInt(0); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_StepOverResponse: "; + } +} + +/** + * @access private + */ +class pdb_StepOverRequest extends pdb_MessageRequest { + const TYPE = 12; + public $id; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_StepOverResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_StepOverRequest: "; + } +} + +/** + * @access private + */ +class pdb_StepIntoResponse extends pdb_StepOverResponse { + const TYPE = 1011; + public function getType() { + return self::TYPE; + } + public function __toString () { + return "pdb_StepIntoResponse: "; + } +} + +/** + * @access private + */ +class pdb_StepIntoRequest extends pdb_StepOverRequest { + const TYPE = 11; + public function getType() { + return self::TYPE; + } + public function ack() { + $res = new pdb_StepIntoResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_StepIntoRequest: "; + } +} + +/** + * @access private + */ +class pdb_StepOutResponse extends pdb_StepOverResponse { + const TYPE = 1013; + public function getType() { + return self::TYPE; + } + public function __toString () { + return "pdb_StepOutResponse: "; + } +} + +/** + * @access private + */ +class pdb_StepOutRequest extends pdb_StepOverRequest { + const TYPE = 13; + public function getType() { + return self::TYPE; + } + public function ack() { + $res = new pdb_StepOutResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_OutIntoRequest: "; + } +} + +/** + * @access private + */ +class pdb_GoResponse extends pdb_Message { + const TYPE = 1014; + private $req; + + public function __construct ($req) { + parent::__construct($req->session); + $this->req = $req; + } + + public function getType() { + return self::TYPE; + } + public function serialize() { + $out = $this->session->out; + parent::serialize(); + $out->writeInt($this->req->id); + $out->writeInt(0); + $out->flush(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_GoResponse: "; + } +} + +/** + * @access private + */ +class pdb_GoRequest extends pdb_MessageRequest { + const TYPE = 14; + public $id; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + $in = $this->session->in; + $this->id = $in->readInt(); + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function ack() { + $res = new pdb_GoResponse($this); + $res->serialize(); + } + public function __toString () { + return "pdb_GoRequest: "; + } +} +/** + * @access private + */ +class pdb_End extends pdb_Message { + const TYPE = 3; + public $id; + + public function getType() { + return self::TYPE; + } + public function deserialize() { + if (PDB_DEBUG) pdb_Logger::debug( "$this"); + } + public function __toString () { + return "pdb_End: "; + } +} + +/** + * @access private + */ +class pdb_In { + private $in; + private $len; + private $session; + + public function __construct($in, $session) { + $this->in = $in; + $this->len = 0; + $this->session = $session; + } + private function readBytes($n) { + $str = ""; + while ($n) { + $s = fread($this->in, $n); + if (feof($this->in)) $this->session->end(); + + $n -= strlen($s); + + $str.=$s; + } + return $str; + } + public function read() { + if(!$this->len) { + $str = $this->readBytes(4); + $lenDesc = unpack("N", $str); + $this->len = array_pop($lenDesc); + } + } + public function readShort() { + $this->read(); + + $this->len-=2; + $str = $this->readBytes(2); + $lenDesc = unpack("n", $str); + return array_pop($lenDesc); + } + public function readInt() { + $this->read(); + + $this->len-=4; + $str = $this->readBytes(4); + $lenDesc = unpack("N", $str); + return array_pop($lenDesc); + } + public function readString() { + $this->read(); + + $length = $this->readInt(); + $this->len-=$length; + return $this->readBytes($length); + } + public function __toString () { + return "pdb_In: "; + } +} +/** + * @access private + */ +class pdb_Out { + private $out; + private $buf; + private $session; + + public function __construct($out, $session) { + $this->out = $out; + $this->buf = ""; + $this->session = $session; + } + + public function writeShort($val) { + $this->buf.=pack("n", $val); + } + public function writeInt($val) { + $this->buf.=pack("N", $val); + } + public function writeString($str) { + $length = strlen($str); + $this->writeInt($length); + $this->buf.=$str; + } + public function writeUTFString($str) { + $this->writeString(urlencode($str)); + } + public function flush() { + $length = strlen($this->buf); + $this->buf = pack("N", $length).$this->buf; + fwrite($this->out, $this->buf); + if (feof($this->out)) $this->session->end(); + $this->buf = ""; + } + public function __toString () { + return "pdb_Out: "; + } +} +$pdb_dbg = new pdb_DebugSessionStart("&debug_fastfile=1"); +pdb_Message::register(new pdb_SetProtocolRequest($pdb_dbg)); +pdb_Message::register(new pdb_StartRequest($pdb_dbg)); +pdb_Message::register(new pdb_AddFilesRequest($pdb_dbg)); +pdb_Message::register(new pdb_FileContentExtendedRequest($pdb_dbg)); +pdb_Message::register(new pdb_ContinueProcessFileNotification($pdb_dbg)); +pdb_Message::register(new pdb_AddBreakpointRequest($pdb_dbg)); +pdb_Message::register(new pdb_RemoveBreakpointRequest($pdb_dbg)); +pdb_Message::register(new pdb_RemoveAllBreakpointsRequest($pdb_dbg)); +pdb_Message::register(new pdb_GetCallStackRequest($pdb_dbg)); +pdb_Message::register(new pdb_GetCWDRequest($pdb_dbg)); +pdb_Message::register(new pdb_GetVariableValueRequest($pdb_dbg)); +pdb_Message::register(new pdb_MsgEvalRequest($pdb_dbg)); +pdb_Message::register(new pdb_StepOverRequest($pdb_dbg)); +pdb_Message::register(new pdb_StepIntoRequest($pdb_dbg)); +pdb_Message::register(new pdb_StepOutRequest($pdb_dbg)); +pdb_Message::register(new pdb_GoRequest($pdb_dbg)); +pdb_Message::register(new pdb_End($pdb_dbg)); + +pdb_Message::register(new pdb_StartProcessFileNotification($pdb_dbg)); +pdb_Message::register(new pdb_ReadyNotification($pdb_dbg)); +pdb_Message::register(new pdb_DebugScriptEndedNotification($pdb_dbg)); +pdb_Message::register(new pdb_HeaderOutputNotification($pdb_dbg)); +pdb_Message::register(new pdb_OutputNotification($pdb_dbg)); +pdb_Message::register(new pdb_ErrorNotification($pdb_dbg)); + +/** + * @access private + */ +function pdb_getDefinedVars($vars1, $vars2) { + //if(isset($vars2)) $vars1['pbd_This'] = $vars2; + + unset($vars1['__pdb_Code']); // see pdb_Message::doEval() + + return $vars1; +} +/** + * @access private + */ +function pdb_startCall($scriptName, $line) { + global $pdb_dbg; + + $stepNext = $pdb_dbg->currentFrame->stepNext == pdb_StepIntoRequest::TYPE ? pdb_StepIntoRequest::TYPE : false; + + pdb_Logger::debug("startCall::$scriptName, $stepNext"); + + $env = new pdb_Environment($pdb_dbg->currentFrame, $scriptName, $stepNext, $line); + $pdb_dbg->allFrames[] = $env; + + return $env; +} + +/** + * @access private + */ +function pdb_startInclude($scriptName, $once) { + global $pdb_dbg; + + $scriptName = $pdb_dbg->resolveIncludePath($scriptName); + + // include only from a top-level environment + // initial line# and vars may be wrong due to a side-effect in step + $pdb_dbg->session->currentFrame = $pdb_dbg->session->currentTopLevelFrame; + + $stepNext = $pdb_dbg->currentFrame->stepNext == pdb_StepIntoRequest::TYPE ? pdb_StepIntoRequest::TYPE : false; + $pdb_dbg->currentFrame = new pdb_Environment($pdb_dbg->currentFrame, $scriptName, $stepNext, 1); + $pdb_dbg->allFrames[] = $pdb_dbg->currentFrame; + + /* BEGIN: StartProcessFileNotification */ + $pdb_dbg->getMessageById(pdb_StartProcessFileNotification::TYPE)->handleRequests(); + /* ... set breakpoints ... */ + /* END: ContinueProcessFileNotification */ + + if ($once && isset($pdb_dbg->includedScripts[$scriptName])) + $code = ""; + else + $code = $pdb_dbg->parseCode(realpath($scriptName), file_get_contents($scriptName)); + + $pdb_dbg->currentTopLevelFrame = $pdb_dbg->currentFrame; + + if (PDB_DEBUG) pdb_Logger::debug("include:::$code"); + + if ($once) $pdb_dbg->includedScripts[$scriptName] = true; + return $code; // eval -> pdb_step/MSG_READY or pdb_endInclude/MSG_READY OR FINISH +} +/** + * @access private + */ +function pdb_endInclude() { + global $pdb_dbg; + + $pdb_dbg->currentFrame = $pdb_dbg->currentTopLevelFrame = $pdb_dbg->currentTopLevelFrame->parent; +} + + +/** + * @access private + */ +function pdb_step($filename, $line, $vars) { + global $pdb_dbg; + if ($pdb_dbg->ignoreInterrupt) return; + + $pdb_dbg->ignoreInterrupt = true; + + // pull the current frame from the stack or the top-level environment + $pdb_dbg->currentFrame = (isset($vars['__pdb_CurrentFrame'])) ? $vars['__pdb_CurrentFrame'] : $pdb_dbg->currentTopLevelFrame; + unset($vars['__pdb_CurrentFrame']); + + $pdb_dbg->currentFrame->update($line, $vars); + + if ($pdb_dbg->hasBreakpoint($filename, $line)) { + $pdb_dbg->flushOutput(); + $stepNext = $pdb_dbg->getMessageById(pdb_ReadyNotification::TYPE)->handleRequests(); + pdb_Logger::logDebug("continue"); + /* clear all dynamic breakpoints */ + foreach ($pdb_dbg->allFrames as $currentFrame) + $currentFrame->stepNext = false; + + /* set new dynamic breakpoint */ + if ($stepNext != pdb_GoRequest::TYPE) { + $currentFrame = $pdb_dbg->currentFrame; + + /* break in current frame or frame below */ + if ($stepNext != pdb_StepOutRequest::TYPE) + $currentFrame->stepNext = $stepNext; + + /* or break in any parent */ + while ($currentFrame = $currentFrame->parent) { + $currentFrame->stepNext = $stepNext; + } + } + } + $pdb_dbg->ignoreInterrupt = false; +} + +/** + * @access private + */ +function pdb_error_handler($errno, $errstr, $errfile, $errline) { + global $pdb_dbg; + if (PDB_DEBUG) pdb_Logger::debug("PHP error $errno: $errstr in $errfile line $errline"); + if ($pdb_dbg->end) return false; + + $msg = $pdb_dbg->getMessageById(pdb_ErrorNotification::TYPE); + $msg->setError($errno, $errfile, $errline, $errstr); + $msg->serialize(); + return true; +} + +/** + * @access private + */ +function pdb_shutdown() { + global $pdb_dbg; + if (PDB_DEBUG) pdb_Logger::debug("PHP error: ".print_r(error_get_last(), true)); + if ($pdb_dbg->end) return; + + $error = error_get_last(); + if ($error) { + $msg = $pdb_dbg->getMessageById(pdb_ErrorNotification::TYPE); + $msg->setError($error['type'], $error['file'], $error['line'], $error['message']); + $msg->serialize(); + } +} + + +function pdb_getDebugHeader($name,$array) { + if (array_key_exists($name,$array)) return $array[$name]; + $name="HTTP_$name"; + if (array_key_exists($name,$array)) return $array[$name]; + return null; +} + + +if (isset($pdb_script) && pdb_script!="@") { + $pdb_dbg->handleRequests(); + require_once($pdb_script); +} + +?> diff --git a/legacy/server/META-INF/java/Parser.inc b/legacy/server/META-INF/java/Parser.inc index a2e9753..b2127d5 100644 --- a/legacy/server/META-INF/java/Parser.inc +++ b/legacy/server/META-INF/java/Parser.inc @@ -53,7 +53,7 @@ require_once(java_get_base()."/NativeParser.inc"); class java_Parser { public $parser; - function java_Parser($handler) { + function __construct($handler) { if(function_exists("xml_parser_create")) { $this->parser = new java_NativeParser($handler); $handler->RUNTIME["PARSER"]="NATIVE"; diff --git a/legacy/server/META-INF/java/Protocol.inc b/legacy/server/META-INF/java/Protocol.inc index f5fdfc2..edbd9b4 100644 --- a/legacy/server/META-INF/java/Protocol.inc +++ b/legacy/server/META-INF/java/Protocol.inc @@ -90,7 +90,7 @@ class java_EmptyChannel { protected $handler; private $res; - function java_EmptyChannel($handler) { + function __construct($handler) { $this->handler = $handler; } function shutdownBrokenConnection () {} @@ -158,7 +158,7 @@ class java_EmptyChannel { abstract class java_SocketChannel extends java_EmptyChannel { public $peer, $host; - function java_SocketChannel($peer, $host) { + function __construct($peer, $host) { $this->peer = $peer; $this->host = $host; } @@ -218,7 +218,7 @@ class java_ChunkedSocketChannel extends java_SocketChannel { class java_SocketHandler { public $protocol, $channel; - function java_SocketHandler($protocol, $channel) { + function __construct($protocol, $channel) { $this->protocol = $protocol; $this->channel = $channel; } @@ -293,7 +293,7 @@ class java_SimpleHttpHandler extends java_SocketHandler { or $this->protocol->handler->shutdownBrokenConnection("Broken local connection handle"); } - function java_SimpleHttpHandler($protocol, $ssl, $host, $port) { + function __construct($protocol, $ssl, $host, $port) { $this->cookies = array(); $this->protocol = $protocol; $this->ssl = $ssl; @@ -453,8 +453,8 @@ class java_SimpleHttpTunnelHandler extends java_SimpleHttpHandler { fgets($this->socket, 3); // \r\n fclose($this->socket); } - function java_SimpleHttpTunnelHandler($protocol, $ssl, $host, $port) { - parent::java_SimpleHttpHandler($protocol, $ssl, $host, $port); + function __construct($protocol, $ssl, $host, $port) { + parent::__construct($protocol, $ssl, $host, $port); $this->open(); } function read($size) { @@ -705,7 +705,7 @@ class java_Protocol { $java=file_exists(ini_get("extension_dir")."/JavaBridge.jar")?ini_get("extension_dir")."/JavaBridge.jar":(java_get_base()."/JavaBridge.jar"); if (!file_exists($java)) throw new java_IOException("Could not find $java in ".getcwd().". Download it from http://sf.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_".JAVA_PEAR_VERSION."/exploded/JavaBridge.jar/download and try again."); - $java_cmd = "java -Dio.soluble.pjb.bridge.daemon=true -jar \"${java}\" INET_LOCAL:$channelName 0"; + $java_cmd = "java -Dphp.java.bridge.daemon=true -jar \"${java}\" INET_LOCAL:$channelName 0"; if (!$again) throw new java_ConnectException("No Java back end! Please run it with: $java_cmd. Error message: $errstr ($errno)"); @@ -738,7 +738,7 @@ class java_Protocol { return $this->createHttpHandler(); } } - function java_Protocol ($client) { + function __construct ($client) { $this->client = $client; $this->handler = $this->createHandler(); } @@ -851,7 +851,7 @@ class java_Protocol { } function writeString($name) { $this->client->currentArgumentsFormat.=$format=""; - $this->write(sprintf($format, htmlspecialchars($name, ENT_COMPAT))); + $this->write(sprintf($format, htmlspecialchars($name, ENT_COMPAT,"ISO-8859-1"))); } function writeBoolean($boolean) { @@ -881,7 +881,7 @@ class java_Protocol { /* the following routines are not cached */ function writeException($object, $str) { - $this->write(sprintf("",$object, htmlspecialchars($str, ENT_COMPAT))); + $this->write(sprintf("",$object, htmlspecialchars($str, ENT_COMPAT,"ISO-8859-1"))); } function writeCompositeBegin_a() { $this->write(""); @@ -893,7 +893,7 @@ class java_Protocol { $this->write(""); } function writePairBegin_s($key) { - $this->write(sprintf("

", htmlspecialchars($key, ENT_COMPAT))); + $this->write(sprintf("

", htmlspecialchars($key, ENT_COMPAT,"ISO-8859-1"))); } function writePairBegin_n($key) { $this->write(sprintf("

",$key)); diff --git a/legacy/server/META-INF/java/SimpleParser.inc b/legacy/server/META-INF/java/SimpleParser.inc index 24b314c..b1b9970 100644 --- a/legacy/server/META-INF/java/SimpleParser.inc +++ b/legacy/server/META-INF/java/SimpleParser.inc @@ -62,7 +62,7 @@ class java_ParserString { */ class java_ParserTag { public $n, $strings; - function java_ParserTag() { + function __construct() { $this->strings = array(); $this->n = 0; } @@ -78,7 +78,7 @@ class java_SimpleParser { public $tag, $buf, $len, $s; public $type; - function java_SimpleParser($handler) { + function __construct($handler) { $this->handler = $handler; $this->tag = array(new java_ParserTag(), new java_ParserTag(), new java_ParserTag()); $this->len = $this->SLEN; diff --git a/legacy/server/META-INF/services/javax.script.ScriptEngineFactory b/legacy/server/META-INF/services/javax.script.ScriptEngineFactory index 21d0319..5dd16c8 100644 --- a/legacy/server/META-INF/services/javax.script.ScriptEngineFactory +++ b/legacy/server/META-INF/services/javax.script.ScriptEngineFactory @@ -1,9 +1,9 @@ # list of script engine factories # -# php => php.java.script.PhpScriptEngineFactory -# php-invocable => php.java.script.InvocablePhpScriptEngineFactory -# php-interactive => php.java.script.InteractivePhpScriptEngineFactory +# php => io.soluble.pjb.script.PhpScriptEngineFactory +# php-invocable => io.soluble.pjb.script.InvocablePhpScriptEngineFactory +# php-interactive => io.soluble.pjb.script.InteractivePhpScriptEngineFactory -php.java.script.PhpScriptEngineFactory -php.java.script.InvocablePhpScriptEngineFactory -php.java.script.InteractivePhpScriptEngineFactory +io.soluble.pjb.script.PhpScriptEngineFactory +io.soluble.pjb.script.InvocablePhpScriptEngineFactory +io.soluble.pjb.script.InteractivePhpScriptEngineFactory diff --git a/src/main/java/io/soluble/pjb/bridge/JavaBridgeRunner.java b/src/main/java/io/soluble/pjb/bridge/JavaBridgeRunner.java index dc20637..9c11be4 100644 --- a/src/main/java/io/soluble/pjb/bridge/JavaBridgeRunner.java +++ b/src/main/java/io/soluble/pjb/bridge/JavaBridgeRunner.java @@ -63,6 +63,8 @@ public class JavaBridgeRunner extends HttpServer { protected static JavaBridgeRunner runner; protected final ContextServer contextServer; + private boolean directoryIndexEnabled = true; + protected JavaBridgeRunner(String serverPort, boolean isSecure) throws IOException { super(serverPort, isSecure); @@ -165,6 +167,19 @@ public static synchronized JavaBridgeRunner getRequiredInstance() throws IOExcep return runner; } + /** + * Enable listing of directory index, if a directory is served. + */ + public void enableDirectoryIndex() { + directoryIndexEnabled = true; + } + + /** + * Disable listing of directory index, if a directory is served. + */ + public void disableDirectoryIndex() { + directoryIndexEnabled = false; + } /** * Create a server socket. @@ -248,7 +263,7 @@ protected void doPut(HttpRequest req, HttpResponse res) throws IOException { * @throws IOException */ protected boolean showDirectory(String fullName, File f, int length, HttpRequest req, HttpResponse res) throws IOException { - if (!f.isDirectory()) return false; + // assert f.isDirectory() ByteArrayOutputStream xout = new ByteArrayOutputStream(); try (PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(xout, Util.UTF8)))) { out.println(""); @@ -370,7 +385,7 @@ protected boolean handleScriptContent(String name, String params, File f, int le } /** - * Display a simple text file + * Display a simple text file. * * @param name * @param f The full name as a file @@ -446,10 +461,21 @@ protected void handleDoGet(HttpRequest req, HttpResponse res) throws IOException long l = f.length(); if (l >= Integer.MAX_VALUE) throw new IOException("file " + name + " too large"); int length = (int) l; - if (showDirectory(name, f, length, req, res)) return; - if (handleScriptContent(name, params, f, length, req, res)) return; - showTextFile(name, params, f, length, req, res, (!name.endsWith(".html")) || "show".equals(params)); - return; + if (f.isDirectory()) { + if (directoryIndexEnabled) { + showDirectory(name, f, length, req, res); + } else { + // TODO: What now? 404? 403? setStatus is not implemented in the HttpResponse object + // of this internal http server + } + return; + } else { // assert !f.isDirectory() + // TODO: Here comes a BUG: handleScriptContent(...) does nothing but return true, + // hence showTextFile(...) is never called; will comment it out for now + // if (handleScriptContent(name, params, f, length, req, res)) return; + showTextFile(name, params, f, length, req, res, (!name.endsWith(".html")) || "show".equals(params)); + return; + } } if (cache != null && name.endsWith("Java.inc")) { res.setContentLength(cache.length); @@ -466,7 +492,7 @@ protected void handleDoGet(HttpRequest req, HttpResponse res) throws IOException out.write(buf); return; } catch (SecurityException e) {/*ignore*/ - } catch (Exception e) { + } catch (IOException | IllegalAccessException | IllegalArgumentException | NoSuchFieldException e) { Util.printStackTrace(e); } } diff --git a/src/main/java/io/soluble/pjb/bridge/JavaInc.java b/src/main/java/io/soluble/pjb/bridge/JavaInc.java index e579cba..854941e 100644 --- a/src/main/java/io/soluble/pjb/bridge/JavaInc.java +++ b/src/main/java/io/soluble/pjb/bridge/JavaInc.java @@ -72,9 +72,9 @@ public class JavaInc { "}\n"+ "function java_virtual($path,$return=false) {\n"+ "$req=java_context()->getHttpServletRequest();\n"+ -"$req=new java(\"io.soluble.pjb.servlet.VoidInputHttpServletRequest\",$req);\n"+ +"$req=new java(\"php.java.servlet.VoidInputHttpServletRequest\",$req);\n"+ "$res=java_context()->getHttpServletResponse();\n"+ -"$res=new java(\"io.soluble.pjb.servlet.RemoteHttpServletResponse\",$res);\n"+ +"$res=new java(\"php.java.servlet.RemoteHttpServletResponse\",$res);\n"+ "$req->getRequestDispatcher($path)->include($req,$res);\n"+ "if ($return) return $res->getBufferContents();\n"+ "echo $res->getBufferContents();\n"+ @@ -149,7 +149,7 @@ public class JavaInc { "else define(\"JAVA_PREFER_VALUES\",0);\n"+ "class java_SimpleFactory {\n"+ "public $client;\n"+ -"function java_SimpleFactory($client) {\n"+ +"function __construct($client) {\n"+ "$this->client=$client;\n"+ "}\n"+ "function getProxy($result,$signature,$exception,$wrap) {\n"+ @@ -208,7 +208,7 @@ public class JavaInc { "class java_CacheEntry {\n"+ "public $fmt,$signature,$factory,$java;\n"+ "public $resultVoid;\n"+ -"function java_CacheEntry($fmt,$signature,$factory,$resultVoid) {\n"+ +"function __construct($fmt,$signature,$factory,$resultVoid) {\n"+ "$this->fmt=$fmt;\n"+ "$this->signature=$signature;\n"+ "$this->factory=$factory;\n"+ @@ -220,7 +220,7 @@ public class JavaInc { "public $exception;\n"+ "public $factory,$val;\n"+ "public $signature;\n"+ -"function java_Arg($client) {\n"+ +"function __construct($client) {\n"+ "$this->client=$client;\n"+ "$this->factory=$client->simpleFactory;\n"+ "}\n"+ @@ -266,8 +266,8 @@ public class JavaInc { "public $idx;\n"+ "public $type;\n"+ "public $counter;\n"+ -"function java_CompositeArg($client,$type) {\n"+ -"parent::java_Arg($client);\n"+ +"function __construct($client,$type) {\n"+ +"parent::__construct($client);\n"+ "$this->type=$type;\n"+ "$this->val=array();\n"+ "$this->counter=0;\n"+ @@ -288,8 +288,8 @@ public class JavaInc { "}\n"+ "class java_ApplyArg extends java_CompositeArg {\n"+ "public $m,$p,$v,$n;\n"+ -"function java_ApplyArg($client,$type,$m,$p,$v,$n) {\n"+ -"parent::java_CompositeArg($client,$type);\n"+ +"function __construct($client,$type,$m,$p,$v,$n) {\n"+ +"parent::__construct($client,$type);\n"+ "$this->m=$m;\n"+ "$this->p=$p;\n"+ "$this->v=$v;\n"+ @@ -305,7 +305,7 @@ public class JavaInc { "$proxyFactory,$iteratorProxyFacroty,\n"+ "$arrayProxyFactory,$exceptionProxyFactory,$throwExceptionProxyFactory;\n"+ "public $arg;\n"+ -"public $asyncCtx,$cancelProxyCreationCounter;\n"+ +"public $asyncCtx,$cancelProxyCreationTag;\n"+ "public $globalRef;\n"+ "public $stack;\n"+ "public $defaultCache=array(),$asyncCache=array(),$methodCache;\n"+ @@ -314,7 +314,7 @@ public class JavaInc { "public $cachedJavaPrototype;\n"+ "public $sendBuffer,$preparedToSendBuffer;\n"+ "public $inArgs;\n"+ -"function java_Client() {\n"+ +"function __construct() {\n"+ "$this->RUNTIME=array();\n"+ "$this->RUNTIME[\"NOTICE\"]='***USE echo java_inspect(jVal) OR print_r(java_values(jVal)) TO SEE THE CONTENTS OF THIS JAVA OBJECT!***';\n"+ "$this->parser=new java_Parser($this);\n"+ @@ -328,7 +328,7 @@ public class JavaInc { "$this->cachedJavaPrototype=new java_JavaProxyProxy($this);\n"+ "$this->simpleArg=new java_Arg($this);\n"+ "$this->globalRef=new java_GlobalRef();\n"+ -"$this->asyncCtx=$this->cancelProxyCreationCounter=0;\n"+ +"$this->asyncCtx=$this->cancelProxyCreationTag=0;\n"+ "$this->methodCache=$this->defaultCache;\n"+ "$this->inArgs=false;\n"+ "}\n"+ @@ -649,7 +649,7 @@ public class JavaInc { "register_shutdown_function(\"java_shutdown\");\n"+ "class java_GlobalRef {\n"+ "public $map;\n"+ -"function java_GlobalRef() {\n"+ +"function __construct() {\n"+ "$this->map=array();\n"+ "}\n"+ "function add($object) {\n"+ @@ -665,7 +665,7 @@ public class JavaInc { "public $parser,$handler;\n"+ "public $level,$event;\n"+ "public $buf;\n"+ -"function java_NativeParser($handler) {\n"+ +"function __construct($handler) {\n"+ "$this->handler=$handler;\n"+ "$this->parser=xml_parser_create();\n"+ "xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,0);\n"+ @@ -711,7 +711,7 @@ public class JavaInc { "}\n"+ "class java_Parser {\n"+ "public $parser;\n"+ -"function java_Parser($handler) {\n"+ +"function __construct($handler) {\n"+ "if(function_exists(\"xml_parser_create\")) {\n"+ "$this->parser=new java_NativeParser($handler);\n"+ "$handler->RUNTIME[\"PARSER\"]=\"NATIVE\";\n"+ @@ -755,7 +755,7 @@ public class JavaInc { "class java_EmptyChannel {\n"+ "protected $handler;\n"+ "private $res;\n"+ -"function java_EmptyChannel($handler) {\n"+ +"function __construct($handler) {\n"+ "$this->handler=$handler;\n"+ "}\n"+ "function shutdownBrokenConnection () {}\n"+ @@ -808,7 +808,7 @@ public class JavaInc { "}\n"+ "abstract class java_SocketChannel extends java_EmptyChannel {\n"+ "public $peer,$host;\n"+ -"function java_SocketChannel($peer,$host) {\n"+ +"function __construct($peer,$host) {\n"+ "$this->peer=$peer;\n"+ "$this->host=$host;\n"+ "}\n"+ @@ -847,7 +847,7 @@ public class JavaInc { "}\n"+ "class java_SocketHandler {\n"+ "public $protocol,$channel;\n"+ -"function java_SocketHandler($protocol,$channel) {\n"+ +"function __construct($protocol,$channel) {\n"+ "$this->protocol=$protocol;\n"+ "$this->channel=$channel;\n"+ "}\n"+ @@ -898,7 +898,7 @@ public class JavaInc { "$this->protocol->handler->read(1)\n"+ "or $this->protocol->handler->shutdownBrokenConnection(\"Broken local connection handle\");\n"+ "}\n"+ -"function java_SimpleHttpHandler($protocol,$ssl,$host,$port) {\n"+ +"function __construct($protocol,$ssl,$host,$port) {\n"+ "$this->cookies=array();\n"+ "$this->protocol=$protocol;\n"+ "$this->ssl=$ssl;\n"+ @@ -1020,8 +1020,8 @@ public class JavaInc { "fgets($this->socket,3);\n"+ "fclose($this->socket);\n"+ "}\n"+ -"function java_SimpleHttpTunnelHandler($protocol,$ssl,$host,$port) {\n"+ -"parent::java_SimpleHttpHandler($protocol,$ssl,$host,$port);\n"+ +"function __construct($protocol,$ssl,$host,$port) {\n"+ +"parent::__construct($protocol,$ssl,$host,$port);\n"+ "$this->open();\n"+ "}\n"+ "function read($size) {\n"+ @@ -1227,7 +1227,7 @@ public class JavaInc { "$java=file_exists(ini_get(\"extension_dir\").\"/JavaBridge.jar\")?ini_get(\"extension_dir\").\"/JavaBridge.jar\":(java_get_base().\"/JavaBridge.jar\");\n"+ "if (!file_exists($java))\n"+ "throw new java_IOException(\"Could not find $java in \".getcwd().\". Download it from http://sf.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_\".JAVA_PEAR_VERSION.\"/exploded/JavaBridge.jar/download and try again.\");\n"+ -"$java_cmd=\"java -Dio.soluble.pjb.bridge.daemon=true -jar \\\"${java}\\\" INET_LOCAL:$channelName 0\";\n"+ +"$java_cmd=\"java -Dphp.java.bridge.daemon=true -jar \\\"${java}\\\" INET_LOCAL:$channelName 0\";\n"+ "if (!$again)\n"+ "throw new java_ConnectException(\"No Java back end! Please run it with: $java_cmd. Error message: $errstr ($errno)\");\n"+ "if (!java_checkCliSapi())\n"+ @@ -1254,7 +1254,7 @@ public class JavaInc { "return $this->createHttpHandler();\n"+ "}\n"+ "}\n"+ -"function java_Protocol ($client) {\n"+ +"function __construct ($client) {\n"+ "$this->client=$client;\n"+ "$this->handler=$this->createHandler();\n"+ "}\n"+ @@ -1352,7 +1352,7 @@ public class JavaInc { "}\n"+ "function writeString($name) {\n"+ "$this->client->currentArgumentsFormat.=$format=\"\";\n"+ -"$this->write(sprintf($format,htmlspecialchars($name,ENT_COMPAT)));\n"+ +"$this->write(sprintf($format,htmlspecialchars($name,ENT_COMPAT,\"ISO-8859-1\")));\n"+ "}\n"+ "function writeBoolean($boolean) {\n"+ "$this->client->currentArgumentsFormat.=$format=\"\";\n"+ @@ -1379,7 +1379,7 @@ public class JavaInc { "$this->write(sprintf($format,$object));\n"+ "}\n"+ "function writeException($object,$str) {\n"+ -"$this->write(sprintf(\"\",$object,htmlspecialchars($str,ENT_COMPAT)));\n"+ +"$this->write(sprintf(\"\",$object,htmlspecialchars($str,ENT_COMPAT,\"ISO-8859-1\")));\n"+ "}\n"+ "function writeCompositeBegin_a() {\n"+ "$this->write(\"\");\n"+ @@ -1391,7 +1391,7 @@ public class JavaInc { "$this->write(\"\");\n"+ "}\n"+ "function writePairBegin_s($key) {\n"+ -"$this->write(sprintf(\"

\",htmlspecialchars($key,ENT_COMPAT)));\n"+ +"$this->write(sprintf(\"

\",htmlspecialchars($key,ENT_COMPAT,\"ISO-8859-1\")));\n"+ "}\n"+ "function writePairBegin_n($key) {\n"+ "$this->write(sprintf(\"

\",$key));\n"+ @@ -1422,7 +1422,7 @@ public class JavaInc { "}\n"+ "class java_ParserTag {\n"+ "public $n,$strings;\n"+ -"function java_ParserTag() {\n"+ +"function __construct() {\n"+ "$this->strings=array();\n"+ "$this->n=0;\n"+ "}\n"+ @@ -1432,7 +1432,7 @@ public class JavaInc { "public $handler;\n"+ "public $tag,$buf,$len,$s;\n"+ "public $type;\n"+ -"function java_SimpleParser($handler) {\n"+ +"function __construct($handler) {\n"+ "$this->handler=$handler;\n"+ "$this->tag=array(new java_ParserTag(),new java_ParserTag(),new java_ParserTag());\n"+ "$this->len=$this->SLEN;\n"+ @@ -1609,6 +1609,10 @@ public class JavaInc { "function java_values($object) {\n"+ "return java_values_internal($object);\n"+ "}\n"+ +"function java_reset() {\n"+ +"$client=__javaproxy_Client_getClient();\n"+ +"return $client->invokeMethod(0,\"reset\",array());\n"+ +"}\n"+ "function java_inspect_internal($object) {\n"+ "if(!$object instanceof java_JavaType) throw new java_IllegalArgumentException($object);\n"+ "$client=__javaproxy_Client_getClient();\n"+ @@ -1656,6 +1660,9 @@ public class JavaInc { "}\n"+ "function java_require($arg) {\n"+ "trigger_error('java_require() not supported anymore. Please use tomcat or jee hot deployment instead',E_USER_WARNING);\n"+ +"$client=__javaproxy_Client_getClient();\n"+ +"return $client->invokeMethod(0,\"updateJarLibraryPath\",\n"+ +"array($arg,ini_get(\"extension_dir\")));\n"+ "}\n"+ "function java_get_lifetime ()\n"+ "{\n"+ @@ -1718,7 +1725,7 @@ public class JavaInc { "public $__signature;\n"+ "public $__client;\n"+ "public $__tempGlobalRef;\n"+ -"function java_JavaProxy($java,$signature){\n"+ +"function __construct($java,$signature){\n"+ "$this->__java=$java;\n"+ "$this->__signature=$signature;\n"+ "$this->__client=__javaproxy_Client_getClient();\n"+ @@ -1764,7 +1771,7 @@ public class JavaInc { "}\n"+ "class java_objectIterator implements Iterator {\n"+ "private $var;\n"+ -"function java_ObjectIterator($javaProxy) {\n"+ +"function __construct($javaProxy) {\n"+ "$this->var=java_cast ($javaProxy,\"A\");\n"+ "}\n"+ "function rewind() {\n"+ @@ -1883,7 +1890,7 @@ public class JavaInc { "}\n"+ "}\n"+ "class Java extends java_AbstractJava {\n"+ -"function Java() {\n"+ +"function __construct() {\n"+ "$client=$this->__client=__javaproxy_Client_getClient();\n"+ "$args=func_get_args();\n"+ "$name=array_shift($args);\n"+ @@ -1896,7 +1903,7 @@ public class JavaInc { "case 'boolean': array_push($args2,$val); $sig.='@b'; break;\n"+ "case 'integer': array_push($args2,$val); $sig.='@i'; break;\n"+ "case 'double': array_push($args2,$val); $sig.='@d'; break;\n"+ -"case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT)); $sig.='@s'; break;\n"+ +"case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT,\"ISO-8859-1\")); $sig.='@s'; break;\n"+ "case 'array':$sig=\"~INVALID\"; break;\n"+ "case 'object':\n"+ "if($val instanceof java_JavaType) {\n"+ @@ -1959,7 +1966,7 @@ public class JavaInc { "case 'boolean': array_push($args2,$val); $sig.='@b'; break;\n"+ "case 'integer': array_push($args2,$val); $sig.='@i'; break;\n"+ "case 'double': array_push($args2,$val); $sig.='@d'; break;\n"+ -"case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT)); $sig.='@s'; break;\n"+ +"case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT,\"ISO-8859-1\")); $sig.='@s'; break;\n"+ "case 'array':$sig=\"~INVALID\"; break;\n"+ "case 'object':\n"+ "if($val instanceof java_JavaType) {\n"+ @@ -2004,7 +2011,7 @@ public class JavaInc { "}\n"+ "}\n"+ "class java_InternalJava extends Java {\n"+ -"function java_InternalJava($proxy) {\n"+ +"function __construct($proxy) {\n"+ "$this->__delegate=$proxy;\n"+ "$this->__java=$proxy->__java;\n"+ "$this->__signature=$proxy->__signature;\n"+ @@ -2012,7 +2019,7 @@ public class JavaInc { "}\n"+ "}\n"+ "class java_class extends Java {\n"+ -"function java_class() {\n"+ +"function __construct() {\n"+ "$this->__client=__javaproxy_Client_getClient();\n"+ "$args=func_get_args();\n"+ "$name=array_shift($args);\n"+ @@ -2028,7 +2035,7 @@ public class JavaInc { "public $__delegate;\n"+ "public $__signature;\n"+ "public $__hasDeclaredExceptions;\n"+ -"function java_exception() {\n"+ +"function __construct() {\n"+ "$this->__client=__javaproxy_Client_getClient();\n"+ "$args=func_get_args();\n"+ "$name=array_shift($args);\n"+ @@ -2069,7 +2076,7 @@ public class JavaInc { "}\n"+ "class JavaException extends java_exception {}\n"+ "class java_InternalException extends JavaException {\n"+ -"function java_InternalException($proxy,$exception) {\n"+ +"function __construct($proxy,$exception) {\n"+ "$this->__delegate=$proxy;\n"+ "$this->__java=$proxy->__java;\n"+ "$this->__signature=$proxy->__signature;\n"+ @@ -2078,7 +2085,7 @@ public class JavaInc { "}\n"+ "}\n"+ "class java_JavaProxyProxy extends Java {\n"+ -"function java_JavaProxyProxy($client) {\n"+ +"function __construct($client) {\n"+ "$this->__client=$client;\n"+ "}\n"+ "}\n"+ diff --git a/src/main/java/io/soluble/pjb/bridge/Util.java b/src/main/java/io/soluble/pjb/bridge/Util.java index 620dd41..e7ee159 100644 --- a/src/main/java/io/soluble/pjb/bridge/Util.java +++ b/src/main/java/io/soluble/pjb/bridge/Util.java @@ -176,15 +176,17 @@ private Util() {} * Useful if you have non-pure java libraries (=libraries which * use the Java Native Interface to load native dll's or shared * libraries). + * LEGACY-CODE: no usages */ + @Deprecated public static final String DEFAULT_EXT_DIRS[] = {"/usr/share/java/ext", "/usr/java/packages/lib/ext"}; - //TODO: platform neutrality /** * Set to true if the VM is gcj, false otherwise + * LEGACY-CODE: no usages */ - public static final boolean IS_GNU_JAVA = checkVM(); - //TODO: drop GNU Java support + @Deprecated + public static final boolean IS_GNU_JAVA = false; //- checkVM(); /** * The name of the extension, usually "JavaBridge" or "MonoBridge" diff --git a/src/main/java/io/soluble/pjb/bridge/http/ChunkedInputStream.java b/src/main/java/io/soluble/pjb/bridge/http/ChunkedInputStream.java index 14d115f..34314ef 100644 --- a/src/main/java/io/soluble/pjb/bridge/http/ChunkedInputStream.java +++ b/src/main/java/io/soluble/pjb/bridge/http/ChunkedInputStream.java @@ -50,15 +50,12 @@ private static int[] getAscii() { for (int i = 48; i < 58; i++) { ascii[i] = i - 48; } - ; for (int i = 65; i < 71; i++) { ascii[i] = i - 55; } - ; for (int i = 97; i < 103; i++) { ascii[i] = i - 87; } - ; return ascii; } @@ -78,6 +75,7 @@ public ChunkedInputStream(InputStream in) { /** * {@inheritDoc} */ + @Override public int read(byte[] buf, int pos, int len) throws IOException { int c, i; int count; @@ -106,15 +104,14 @@ public int read(byte[] buf, int pos, int len) throws IOException { remaining = new byte[packetLen]; remainLen = 0; - for (c = 0; (i = in.read(remaining, c, packetLen - c)) > 0; c += i) - ; + for (c = 0; (i = in.read(remaining, c, packetLen - c)) > 0; c += i) { + } if ((c != packetLen)) throw new IOException("read chunked"); - for (c = 0; (i = in.read(rn, c, 2 - c)) > 0; c += i) - ; + for (c = 0; (i = in.read(rn, c, 2 - c)) > 0; c += i) { + } if ((c != 2)) throw new IOException("read \r\n"); - // store remaining if (len >= packetLen) { count = packetLen; diff --git a/src/main/java/io/soluble/pjb/bridge/http/HttpResponse.java b/src/main/java/io/soluble/pjb/bridge/http/HttpResponse.java index 67afdb5..8385028 100644 --- a/src/main/java/io/soluble/pjb/bridge/http/HttpResponse.java +++ b/src/main/java/io/soluble/pjb/bridge/http/HttpResponse.java @@ -41,7 +41,7 @@ */ public class HttpResponse { - private HashMap headers; + private final HashMap headers; private OutputStream outputStream; private boolean headersWritten; @@ -56,6 +56,7 @@ public HttpResponse(OutputStream outputStream) { this.headers = new HashMap(); this.outputStream = new BufferedOutputStream(outputStream) { + @Override public void write(byte buf[], int pos, int len) throws IOException { if (!headersWritten) { headersWritten = true; diff --git a/src/main/java/io/soluble/pjb/bridge/http/WriterOutputStream.java b/src/main/java/io/soluble/pjb/bridge/http/WriterOutputStream.java index 9fd3dd8..db08183 100644 --- a/src/main/java/io/soluble/pjb/bridge/http/WriterOutputStream.java +++ b/src/main/java/io/soluble/pjb/bridge/http/WriterOutputStream.java @@ -31,39 +31,30 @@ /** * A PrintWriter backed by an OutputStream. - * * @author jostb + * */ public class WriterOutputStream extends DefaultCharsetWriterOutputStream { protected String charsetName = Util.DEFAULT_ENCODING; - private boolean written = false; /** * The encoding used for char[] -> byte[] conversion - * * @param charsetName */ public void setEncoding(String charsetName) { - if (written) throw new IllegalStateException("setEncoding"); this.charsetName = charsetName; } - /** * Create a new PhpScriptWriter. - * * @param out The OutputStream */ public WriterOutputStream(Writer out) { super(out); } - - /** - * {@inheritDoc} - */ + /**{@inheritDoc}*/ public void write(byte b[], int off, int len) throws IOException { - written = true; - String s = new String(b, off, len, charsetName); + String s = new String (b, off, len, charsetName); out.write(s); } -} +} \ No newline at end of file diff --git a/src/main/resources/META-INF/java/Java.inc b/src/main/resources/META-INF/java/Java.inc index 47dbe7c..5cc52af 100644 --- a/src/main/resources/META-INF/java/Java.inc +++ b/src/main/resources/META-INF/java/Java.inc @@ -70,9 +70,9 @@ trigger_error('Please use getHttpServletResponse(); -$res=new java("io.soluble.pjb.servlet.RemoteHttpServletResponse",$res); +$res=new java("php.java.servlet.RemoteHttpServletResponse",$res); $req->getRequestDispatcher($path)->include($req,$res); if ($return) return $res->getBufferContents(); echo $res->getBufferContents(); @@ -147,7 +147,7 @@ if ($java_ini=get_cfg_var("java.prefer_values")) define("JAVA_PREFER_VALUES",$ja else define("JAVA_PREFER_VALUES",0); class java_SimpleFactory { public $client; -function java_SimpleFactory($client) { +function __construct($client) { $this->client=$client; } function getProxy($result,$signature,$exception,$wrap) { @@ -206,7 +206,7 @@ trigger_error("Unchecked exception detected: ".java_truncate($result->__toString class java_CacheEntry { public $fmt,$signature,$factory,$java; public $resultVoid; -function java_CacheEntry($fmt,$signature,$factory,$resultVoid) { +function __construct($fmt,$signature,$factory,$resultVoid) { $this->fmt=$fmt; $this->signature=$signature; $this->factory=$factory; @@ -218,7 +218,7 @@ public $client; public $exception; public $factory,$val; public $signature; -function java_Arg($client) { +function __construct($client) { $this->client=$client; $this->factory=$client->simpleFactory; } @@ -264,8 +264,8 @@ public $parentArg; public $idx; public $type; public $counter; -function java_CompositeArg($client,$type) { -parent::java_Arg($client); +function __construct($client,$type) { +parent::__construct($client); $this->type=$type; $this->val=array(); $this->counter=0; @@ -286,8 +286,8 @@ $this->factory=$this->client->simpleFactory; } class java_ApplyArg extends java_CompositeArg { public $m,$p,$v,$n; -function java_ApplyArg($client,$type,$m,$p,$v,$n) { -parent::java_CompositeArg($client,$type); +function __construct($client,$type,$m,$p,$v,$n) { +parent::__construct($client,$type); $this->m=$m; $this->p=$p; $this->v=$v; @@ -303,7 +303,7 @@ public $simpleFactory, $proxyFactory,$iteratorProxyFacroty, $arrayProxyFactory,$exceptionProxyFactory,$throwExceptionProxyFactory; public $arg; -public $asyncCtx,$cancelProxyCreationCounter; +public $asyncCtx,$cancelProxyCreationTag; public $globalRef; public $stack; public $defaultCache=array(),$asyncCache=array(),$methodCache; @@ -312,7 +312,7 @@ public $currentCacheKey,$currentArgumentsFormat; public $cachedJavaPrototype; public $sendBuffer,$preparedToSendBuffer; public $inArgs; -function java_Client() { +function __construct() { $this->RUNTIME=array(); $this->RUNTIME["NOTICE"]='***USE echo java_inspect(jVal) OR print_r(java_values(jVal)) TO SEE THE CONTENTS OF THIS JAVA OBJECT!***'; $this->parser=new java_Parser($this); @@ -326,7 +326,7 @@ $this->throwExceptionProxyFactory=new java_ThrowExceptionProxyFactory($this); $this->cachedJavaPrototype=new java_JavaProxyProxy($this); $this->simpleArg=new java_Arg($this); $this->globalRef=new java_GlobalRef(); -$this->asyncCtx=$this->cancelProxyCreationCounter=0; +$this->asyncCtx=$this->cancelProxyCreationTag=0; $this->methodCache=$this->defaultCache; $this->inArgs=false; } @@ -647,7 +647,7 @@ $client->protocol->keepAlive(); register_shutdown_function("java_shutdown"); class java_GlobalRef { public $map; -function java_GlobalRef() { +function __construct() { $this->map=array(); } function add($object) { @@ -663,7 +663,7 @@ class java_NativeParser { public $parser,$handler; public $level,$event; public $buf; -function java_NativeParser($handler) { +function __construct($handler) { $this->handler=$handler; $this->parser=xml_parser_create(); xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,0); @@ -709,7 +709,7 @@ sprintf("protocol error: %s. Check the back end log for details.",$this->buf)); } class java_Parser { public $parser; -function java_Parser($handler) { +function __construct($handler) { if(function_exists("xml_parser_create")) { $this->parser=new java_NativeParser($handler); $handler->RUNTIME["PARSER"]="NATIVE"; @@ -753,7 +753,7 @@ return $compatibility; class java_EmptyChannel { protected $handler; private $res; -function java_EmptyChannel($handler) { +function __construct($handler) { $this->handler=$handler; } function shutdownBrokenConnection () {} @@ -806,7 +806,7 @@ $this->checkE(); } abstract class java_SocketChannel extends java_EmptyChannel { public $peer,$host; -function java_SocketChannel($peer,$host) { +function __construct($peer,$host) { $this->peer=$peer; $this->host=$host; } @@ -845,7 +845,7 @@ function keepAlive() { $this->keepAliveSC(); $this->checkE(); fclose ($this->pee } class java_SocketHandler { public $protocol,$channel; -function java_SocketHandler($protocol,$channel) { +function __construct($protocol,$channel) { $this->protocol=$protocol; $this->channel=$channel; } @@ -896,7 +896,7 @@ $this->protocol->client->sendBuffer=null; $this->protocol->handler->read(1) or $this->protocol->handler->shutdownBrokenConnection("Broken local connection handle"); } -function java_SimpleHttpHandler($protocol,$ssl,$host,$port) { +function __construct($protocol,$ssl,$host,$port) { $this->cookies=array(); $this->protocol=$protocol; $this->ssl=$ssl; @@ -1018,8 +1018,8 @@ fgets($this->socket,JAVA_RECV_SIZE); fgets($this->socket,3); fclose($this->socket); } -function java_SimpleHttpTunnelHandler($protocol,$ssl,$host,$port) { -parent::java_SimpleHttpHandler($protocol,$ssl,$host,$port); +function __construct($protocol,$ssl,$host,$port) { +parent::__construct($protocol,$ssl,$host,$port); $this->open(); } function read($size) { @@ -1225,7 +1225,7 @@ if (!$peer) { $java=file_exists(ini_get("extension_dir")."/JavaBridge.jar")?ini_get("extension_dir")."/JavaBridge.jar":(java_get_base()."/JavaBridge.jar"); if (!file_exists($java)) throw new java_IOException("Could not find $java in ".getcwd().". Download it from http://sf.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_".JAVA_PEAR_VERSION."/exploded/JavaBridge.jar/download and try again."); -$java_cmd="java -Dio.soluble.pjb.bridge.daemon=true -jar \"${java}\" INET_LOCAL:$channelName 0"; +$java_cmd="java -Dphp.java.bridge.daemon=true -jar \"${java}\" INET_LOCAL:$channelName 0"; if (!$again) throw new java_ConnectException("No Java back end! Please run it with: $java_cmd. Error message: $errstr ($errno)"); if (!java_checkCliSapi()) @@ -1252,7 +1252,7 @@ return $this->createSimpleHandler($defaultChannel); return $this->createHttpHandler(); } } -function java_Protocol ($client) { +function __construct ($client) { $this->client=$client; $this->handler=$this->createHandler(); } @@ -1350,7 +1350,7 @@ $this->flush(); } function writeString($name) { $this->client->currentArgumentsFormat.=$format=""; -$this->write(sprintf($format,htmlspecialchars($name,ENT_COMPAT))); +$this->write(sprintf($format,htmlspecialchars($name,ENT_COMPAT,"ISO-8859-1"))); } function writeBoolean($boolean) { $this->client->currentArgumentsFormat.=$format=""; @@ -1377,7 +1377,7 @@ $this->client->currentArgumentsFormat.=$format=""; $this->write(sprintf($format,$object)); } function writeException($object,$str) { -$this->write(sprintf("",$object,htmlspecialchars($str,ENT_COMPAT))); +$this->write(sprintf("",$object,htmlspecialchars($str,ENT_COMPAT,"ISO-8859-1"))); } function writeCompositeBegin_a() { $this->write(""); @@ -1389,7 +1389,7 @@ function writeCompositeEnd() { $this->write(""); } function writePairBegin_s($key) { -$this->write(sprintf("

",htmlspecialchars($key,ENT_COMPAT))); +$this->write(sprintf("

",htmlspecialchars($key,ENT_COMPAT,"ISO-8859-1"))); } function writePairBegin_n($key) { $this->write(sprintf("

",$key)); @@ -1420,7 +1420,7 @@ return substr($this->string,$this->off,$this->length); } class java_ParserTag { public $n,$strings; -function java_ParserTag() { +function __construct() { $this->strings=array(); $this->n=0; } @@ -1430,7 +1430,7 @@ public $SLEN=256; public $handler; public $tag,$buf,$len,$s; public $type; -function java_SimpleParser($handler) { +function __construct($handler) { $this->handler=$handler; $this->tag=array(new java_ParserTag(),new java_ParserTag(),new java_ParserTag()); $this->len=$this->SLEN; @@ -1607,6 +1607,10 @@ return $client->globalRef->get($client->invokeMethod(0,"unwrapClosure",array($ob function java_values($object) { return java_values_internal($object); } +function java_reset() { +$client=__javaproxy_Client_getClient(); +return $client->invokeMethod(0,"reset",array()); +} function java_inspect_internal($object) { if(!$object instanceof java_JavaType) throw new java_IllegalArgumentException($object); $client=__javaproxy_Client_getClient(); @@ -1654,6 +1658,9 @@ return java_cast_internal($object,$type); } function java_require($arg) { trigger_error('java_require() not supported anymore. Please use __java=$java; $this->__signature=$signature; $this->__client=__javaproxy_Client_getClient(); @@ -1762,7 +1769,7 @@ return ""; } class java_objectIterator implements Iterator { private $var; -function java_ObjectIterator($javaProxy) { +function __construct($javaProxy) { $this->var=java_cast ($javaProxy,"A"); } function rewind() { @@ -1881,7 +1888,7 @@ $args=func_get_args(); return $this->__call("offsetUnset",$args); } } class Java extends java_AbstractJava { -function Java() { +function __construct() { $client=$this->__client=__javaproxy_Client_getClient(); $args=func_get_args(); $name=array_shift($args); @@ -1894,7 +1901,7 @@ switch(gettype($val=$args[$i])) { case 'boolean': array_push($args2,$val); $sig.='@b'; break; case 'integer': array_push($args2,$val); $sig.='@i'; break; case 'double': array_push($args2,$val); $sig.='@d'; break; -case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT)); $sig.='@s'; break; +case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT,"ISO-8859-1")); $sig.='@s'; break; case 'array':$sig="~INVALID"; break; case 'object': if($val instanceof java_JavaType) { @@ -1957,7 +1964,7 @@ switch(gettype($val=$args[$i])) { case 'boolean': array_push($args2,$val); $sig.='@b'; break; case 'integer': array_push($args2,$val); $sig.='@i'; break; case 'double': array_push($args2,$val); $sig.='@d'; break; -case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT)); $sig.='@s'; break; +case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT,"ISO-8859-1")); $sig.='@s'; break; case 'array':$sig="~INVALID"; break; case 'object': if($val instanceof java_JavaType) { @@ -2002,7 +2009,7 @@ return $retval; } } class java_InternalJava extends Java { -function java_InternalJava($proxy) { +function __construct($proxy) { $this->__delegate=$proxy; $this->__java=$proxy->__java; $this->__signature=$proxy->__signature; @@ -2010,7 +2017,7 @@ $this->__client=$proxy->__client; } } class java_class extends Java { -function java_class() { +function __construct() { $this->__client=__javaproxy_Client_getClient(); $args=func_get_args(); $name=array_shift($args); @@ -2026,7 +2033,7 @@ public $__serialID,$__java,$__client; public $__delegate; public $__signature; public $__hasDeclaredExceptions; -function java_exception() { +function __construct() { $this->__client=__javaproxy_Client_getClient(); $args=func_get_args(); $name=array_shift($args); @@ -2067,7 +2074,7 @@ return $this->__delegate->__toExceptionString($this->getTraceAsString()); } class JavaException extends java_exception {} class java_InternalException extends JavaException { -function java_InternalException($proxy,$exception) { +function __construct($proxy,$exception) { $this->__delegate=$proxy; $this->__java=$proxy->__java; $this->__signature=$proxy->__signature; @@ -2076,7 +2083,7 @@ $this->__hasDeclaredExceptions=$exception; } } class java_JavaProxyProxy extends Java { -function java_JavaProxyProxy($client) { +function __construct($client) { $this->__client=$client; } } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index c4fdc97..e03265f 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -18,6 +18,16 @@ php_exec php-cgi + + + + + + php_include_debugger + Off