/**
         * Creates and initializes a new session manager.
         */
        public QuercusSessionManager(QuercusContext quercus)
        {
            _sessions    = new LruCache <String, SessionArrayValue>(_sessionMax);
            _sessionIter = _sessions.values();

            _persistentStore = quercus.getSessionCache();
        }
 public GoogleEnv(QuercusContext quercus,
                  QuercusPage page,
                  WriteStream @out,
                  QuercusHttpServletRequest request,
                  QuercusHttpServletResponse response)
 {
     super(quercus, page, @out, request, response);
 }
        /**
         * Returns the Quercus instance.
         */
        protected QuercusContext getQuercus()
        {
            if (_quercus == null)
            {
                _quercus = new QuercusContext();
            }

            return(_quercus);
        }
        public CliEnv(QuercusContext quercus,
                      QuercusPage page,
                      WriteStream @out,
                      String[] argv)
        {
            super(quercus, page, @out, null, null);

            _argv = argv;
        }
        /**
         * Set the ini value for the given scope.
         */
        public void set(QuercusContext quercus, string s)
        {
            StringValue value = null;

            if (s != null)
            {
                value = new ConstStringValue(s);
            }

            set(quercus, value);
        }
示例#6
0
        /**
         * Creates a new quercus program
         *
         * @param quercus the owning quercus engine
         * @param sourceFile the path to the source file
         * @param statement the top-level statement
         */
        public QuercusProgram(QuercusContext quercus,
                              string sourceFile,
                              QuercusPage page)
        {
            _quercus      = quercus;
            _sourceFile   = sourceFile;
            _compiledPage = page;

            _depend = new BasicDependencyContainer();

            _topDepend = new BasicDependencyContainer();
            _topDepend.setCheckInterval(quercus.getDependencyCheckInterval());
            _topDepend.add(new PageDependency());
        }
示例#7
0
        private DefinitionState(DefinitionState oldState, bool isLazy)
        {
            _isLazy = true;

            _quercus  = oldState._quercus;
            _isStrict = oldState._isStrict;

            _funMap      = oldState._funMap;
            _lowerFunMap = oldState._lowerFunMap;

            _classDefMap      = oldState._classDefMap;
            _lowerClassDefMap = oldState._lowerClassDefMap;

            _crc = oldState._crc;
        }
示例#8
0
        public DefinitionState(QuercusContext quercus)
        {
            _quercus = quercus;

            _isStrict = quercus.isStrict();

            _funMap      = new HashMap <StringValue, AbstractFunction>(256, 0.25F);
            _classDefMap = new HashMap <String, ClassDef>(256, 0.25F);

            if (!_isStrict)
            {
                _lowerFunMap = new HashMap <StringValue, AbstractFunction>(256, 0.25F);

                _lowerClassDefMap = new HashMap <String, ClassDef>(256, 0.25F);
            }
        }
示例#9
0
        /**
         * Creates a new quercus program
         *
         * @param quercus the owning quercus engine
         * @param sourceFile the path to the source file
         * @param statement the top-level statement
         */
        public QuercusProgram(QuercusContext quercus,
                              string sourceFile,
                              HashMap <StringValue, Function> functionMap,
                              ArrayList <Function> functionList,
                              HashMap <String, InterpretedClassDef> classMap,
                              ArrayList <InterpretedClassDef> classList,
                              FunctionInfo functionInfo,
                              Statement statement)
        {
            _quercus = quercus;

            _depend = new BasicDependencyContainer();
            _depend.setCheckInterval(quercus.getDependencyCheckInterval());

            _topDepend = new BasicDependencyContainer();
            _topDepend.setCheckInterval(quercus.getDependencyCheckInterval());
            _topDepend.add(new PageDependency());

            _sourceFile = sourceFile;
            if (sourceFile != null)
            {
                addDepend(sourceFile);
            }

            _functionMap  = functionMap;
            _functionList = functionList;

            for (Map.Entry <StringValue, Function> entry : functionMap.entrySet())
            {
                _functionMapLowerCase.put(entry.getKey().toLowerCase(Locale.ENGLISH),
                                          entry.getValue());
            }

            _classMap  = classMap;
            _classList = classList;

            _functionInfo = functionInfo;
            _statement    = statement;
        }
        public string getAsString(QuercusContext quercus)
        {
            StringValue value = getAsStringValue(quercus);

            return((value.length() == 0) ? null : value.ToString());
        }
示例#11
0
        /**
         * evaluates based on a reader.
         */
        public Object eval(ScriptContext cxt)

        {
            QuercusContext quercus = _engine.getQuercus();
            Env            env     = null;

            try {
                Writer writer = cxt.getWriter();

                WriteStream out;

                if (writer != null)
                {
                    WriterStreamImpl s = new WriterStreamImpl();
                    s.setWriter(writer);
                    WriteStream os = new WriteStream(s);

                    os.setNewlineString("\n");

                    string outputEncoding = quercus.getOutputEncoding();

                    if (outputEncoding == null)
                    {
                        outputEncoding = "utf-8";
                    }

                    try {
                        os.setEncoding(outputEncoding);
                    }
                    catch (Exception e) {
                        log.log(Level.FINE, e.getMessage(), e);
                    }

                    @out = os;
                }
                else
                {
                    @out = new NullWriteStream();
                }

                QuercusPage page = new InterpretedPage(_program);

                env = new Env(quercus, page, @out, null, null);

                env.setScriptContext(cxt);

                // php/214g
                env.start();

                Object result = null;

                try {
                    Value value = _program.execute(env);

                    if (value != null)
                    {
                        //if (value instanceof JavaValue || value instanceof JavaAdapter) {
                        //  result = value.toJavaObject();
                        //}
                        //else {
                        //  result = value;
                        //}

                        result = value;
                    }
                }
                catch (QuercusExitException e) {
                    //php/2148
                }

                @out.flushBuffer();
                @out.free();

                return(result);

                /*
                 * } catch (ScriptException e) {
                 * throw e;
                 */
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new ScriptException(e);
            } catch (Throwable e) {
                throw new RuntimeException(e);
            } finally {
                if (env != null)
                {
                    env.close();
                }
            }
        }
示例#12
0
 /**
  * Initialize the program
  *
  * @param quercus the owning engine
  */
 public void init(QuercusContext quercus)
 {
 }
 public FunctionInfo(QuercusContext quercus, ClassDef classDef, string name)
 {
     _quercus  = quercus;
     _classDef = classDef;
     _name     = name;
 }
        /**
         * Service.
         */
        public override void service(HttpServletRequest request,
                                     HttpServletResponse response)

        {
            Env         env = null;
            WriteStream ws  = null;

            QuercusHttpServletRequest  req = new QuercusHttpServletRequestImpl(request);
            QuercusHttpServletResponse res = new QuercusHttpServletResponseImpl(response);

            try {
                string path = getPath(req);

                QuercusPage page;

                try {
                    page = getQuercus().parse(path);
                }
                catch (FileNotFoundException e) {
                    // php/2001
                    log.log(Level.FINER, e.ToString(), e);

                    response.sendError(HttpServletResponse.SC_NOT_FOUND);

                    return;
                }

                ws = openWrite(response);

                // php/2002
                // for non-Resin containers
                // for servlet filters that do post-request work after Quercus
                ws.setDisableCloseSource(true);

                // php/6006
                ws.setNewlineString("\n");

                QuercusContext quercus = getQuercus();

                env = quercus.createEnv(page, ws, req, res);

                // php/815d
                env.setPwd(path.getParent());

                quercus.setServletContext(new QuercusServletContextImpl(_servletContext));

                try {
                    env.start();

                    // php/2030, php/2032, php/2033
                    // Jetty hides server classes from web-app
                    // http://docs.codehaus.org/display/JETTY/Classloading
                    //
                    // env.setGlobalValue("request", env.wrapJava(request));
                    // env.setGlobalValue("response", env.wrapJava(response));
                    // env.setGlobalValue("servletContext", env.wrapJava(_servletContext));

                    StringValue prepend
                        = quercus.getIniValue("auto_prepend_file").ToStringValue(env);
                    if (prepend.length() > 0)
                    {
                        string prependPath = env.lookup(prepend);

                        if (prependPath == null)
                        {
                            env.error(L.l("auto_prepend_file '{0}' not found.", prepend));
                        }
                        else
                        {
                            QuercusPage prependPage = getQuercus().parse(prependPath);
                            prependPage.executeTop(env);
                        }
                    }

                    env.executeTop();

                    StringValue append
                        = quercus.getIniValue("auto_append_file").ToStringValue(env);
                    if (append.length() > 0)
                    {
                        string appendPath = env.lookup(append);

                        if (appendPath == null)
                        {
                            env.error(L.l("auto_append_file '{0}' not found.", append));
                        }
                        else
                        {
                            QuercusPage appendPage = getQuercus().parse(appendPath);
                            appendPage.executeTop(env);
                        }
                    }
                    //   return;
                }
                catch (QuercusExitException e) {
                    throw e;
                }
                catch (QuercusErrorException e) {
                    throw e;
                }
                catch (QuercusLineRuntimeException e) {
                    log.log(Level.FINE, e.ToString(), e);

                    ws.println(e.getMessage());
                    //  return;
                }
                catch (QuercusValueException e) {
                    log.log(Level.FINE, e.ToString(), e);

                    ws.println(e.ToString());

                    //  return;
                }
                catch (StackOverflowError e) {
                    RuntimeException myException
                        = new RuntimeException(L.l("StackOverflowError at {0}", env.getLocation()), e);

                    throw myException;
                }
                catch (Throwable e) {
                    if (response.isCommitted())
                    {
                        e.printStackTrace(ws.getPrintWriter());
                    }

                    ws = null;

                    throw e;
                }
                finally {
                    if (env != null)
                    {
                        env.close();
                    }

                    // don't want a flush for an exception
                    if (ws != null && env.getDuplex() == null)
                    {
                        ws.close();
                    }
                }
            }
            catch (QuercusDieException e) {
                // normal exit
                log.log(Level.FINE, e.ToString(), e);
            }
            catch (QuercusExitException e) {
                // normal exit
                log.log(Level.FINER, e.ToString(), e);
            }
            catch (QuercusErrorException e) {
                // error exit
                log.log(Level.FINE, e.ToString(), e);
            }
            catch (RuntimeException e) {
                throw e;
            }
            catch (Throwable e) {
                handleThrowable(response, e);
            }
        }
 public GoogleEnv(QuercusContext quercus)
     : base(quercus)
 {
 }
 public BooleanValue getAsBooleanValue(QuercusContext quercus)
 {
     return(getAsBooleanValue(null, quercus.getIniMap(false)));
 }
 public LongValue getAsLongValue(QuercusContext quercus)
 {
     return(getAsLongValue(null, quercus.getIniMap(false)));
 }
 public QuercusEngine()
 {
     _quercus = new QuercusContext();
 }
            private static string getContentType(Env env, string name)
            {
                QuercusContext quercus = env.getQuercus();

                QuercusServletContext context = quercus.getServletContext();

                if (context != null)
                {
                    string mimeType = context.getMimeType(name);

                    if (mimeType != null)
                    {
                        return(mimeType);
                    }
                    else
                    {
                        return("application/octet-stream");
                    }
                }
                else
                {
                    int i = name.lastIndexOf('.');

                    if (i < 0)
                    {
                        return("application/octet-stream");
                    }
                    else if (name.endsWith(".txt"))
                    {
                        return("text/plain");
                    }
                    else if (name.endsWith(".jpg") || name.endsWith(".jpeg"))
                    {
                        return("image/jpeg");
                    }
                    else if (name.endsWith(".gif"))
                    {
                        return("image/gif");
                    }
                    else if (name.endsWith(".tif") || name.endsWith(".tiff"))
                    {
                        return("image/tiff");
                    }
                    else if (name.endsWith(".png"))
                    {
                        return("image/png");
                    }
                    else if (name.endsWith(".htm") || name.endsWith(".html"))
                    {
                        return("text/html");
                    }
                    else if (name.endsWith(".xml"))
                    {
                        return("text/xml");
                    }
                    else
                    {
                        return("application/octet-stream");
                    }
                }
            }
 public StringValue getAsStringValue(QuercusContext quercus)
 {
     return(get(null, quercus.getIniMap(false)).ToStringValue());
 }
 /**
  * Returns the value set for name, or the default from the definition if
  * it has not been set.
  */
 public Value getValue(QuercusContext quercus)
 {
     return(get(null, quercus.getIniMap(false)));
 }
        /*
         * private LongValue toLongValue(Value value)
         * {
         * if (value instanceof LongValue)
         *  return (LongValue) value;
         * else if (! (value instanceof StringValue))
         *  return LongValue.create(value.toLong());
         *
         * string valueAsString = value.ToString().trim();
         *
         * if (valueAsString.length() == 0)
         *  return LongValue.ZERO;
         *
         * char suffix = valueAsString[valueAsString.length(] - 1);
         *
         * long val = value.toLong();
         *
         * if (suffix == 'G')
         *  val = 1024 * 1024 * val;
         * else if (suffix == 'M')
         *  val = 1024 * 1024 * val;
         * else if (suffix == 'K')
         *  val = 1024 * val;
         *
         * return LongValue.create(val);
         * }
         */

        /**
         * Set the ini value for the given scope.
         */
        public void set(QuercusContext quercus, Value value)
        {
            set(quercus.getIniMap(true), PHP_INI_SYSTEM, value);
        }
示例#23
0
 /**
  * Constructor.
  */
 public PageManager(QuercusContext quercus)
 {
     _quercus = quercus;
 }
 public bool getAsBoolean(QuercusContext quercus)
 {
     return(getAsBooleanValue(quercus).toBoolean());
 }