Exemplo n.º 1
0
        /**
         * Call the Java constructor and return the wrapped Java object.
         * If constructor @is not available, then return static class definition.
         */
        public static Object java(Env env,
                                  string className,
                                  Value [] args)
        {
            try {
                JavaClassDef def = env.getJavaClassDefinition(className);

                if (def == null)
                {
                    env.warning(L.l("could not find Java class {0}", className));
                    return(null);
                }

                Value newObj = def.callNew(env, args);

                if (newObj.isNull())
                {
                    return(new JavaValue(env, null, def));
                }
                else
                {
                    return(newObj);
                }
            } catch (Exception e) {
                log.log(Level.FINE, e.getMessage(), e);
                env.warning(e);

                return(null);
            }
        }
        /**
         * XXX: MySQL returns the table metadata on preparation of a statement,
         * but java.sql doesn't support this feature.
         */
        public bool bindResults(Env env, Value[] outParams)
        {
            int size       = outParams.length;
            int numColumns = getColumnCount(env);

            if (numColumns < 0)
            {
                numColumns = size;
            }

            for (int i = 0; i < size; i++)
            {
                Value val = outParams[i];

                if (!(val instanceof Var))
                {
                    env.error(L.l("Only variables can be passed by reference"));
                    return(false);
                }
            }

            if ((size == 0) || (size != numColumns))
            {
                env.warning(L.l("number of bound variables do not equal number of columns"));
                return(false);
            }

            _results = new Value[size];
            System.arraycopy(outParams, 0, _results, 0, size);

            return(true);
        }
            synchronized(_javaClassWrappers)
            {
                JavaClassDef def = _javaClassWrappers.get(name);

                if (def == null)
                {
                    if (log.isLoggable(Level.FINEST))
                    {
                        if (extension == null)
                        {
                            log.finest(L.l("PHP loading class {0} with type {1}",
                                           name,
                                           type.getName()));
                        }
                        else
                        {
                            log.finest(L.l(
                                           "PHP loading class {0} with type {1} providing extension {2}",
                                           name,
                                           type.getName(),
                                           extension));
                        }
                    }

                    if (javaClassDefClass != null)
                    {
                        Constructor <?> constructor
                            = javaClassDefClass.getConstructor(ModuleContext.class,
Exemplo n.º 4
0
        /**
         * Returns a constant
         *
         * @param env the quercus calling environment
         * @param name the constant name
         */
        public static Value constant(Env env, string name)
        {
            if (name == null)
            {
                env.warning(L.l("null passed as constant name"));
                return(NullValue.NULL);
            }

            int i = name.indexOf("::");

            if (i > 0)
            {
                string cls = name.substring(0, i);

                name = name.substring(i + 2);

                return(env.getClass(cls).getConstant(env, env.createString(name)));
            }
            else
            {
                Value constant = env.getConstant(name, false);

                if (constant != null)
                {
                    return(constant);
                }
                else
                {
                    env.warning(L.l("cannot find constant '{0}'", name));
                    return(NullValue.NULL);
                }
            }
        }
        /**
         * Evaluates the function.
         */
        public override Value callMethod(Env env, QuercusClass qClass, Value qThis,
                                         Value [] args)
        {
            if (args.length < _methodTable.length)
            {
                AbstractJavaMethod [] methods = _methodTable[args.length];

                if (methods != null)
                {
                    if (methods.length == 1)
                    {
                        return(methods[0].callMethod(env, qClass, qThis, args));
                    }
                    else
                    {
                        AbstractJavaMethod method
                            = getBestFitJavaMethod(methods, _restMethodTable, args);

                        return(method.callMethod(env, qClass, qThis, args));
                    }
                }
                else
                {
                    if (_restMethodTable.length == 0)
                    {
                        env.warning(L.l(
                                        "'{0}' overloaded method call with {1} arguments "
                                        + "does not match any overloaded method",
                                        getName(),
                                        args.length));

                        return(NullValue.NULL);
                    }

                    AbstractJavaMethod method
                        = getBestFitJavaMethod(methods, _restMethodTable, args);

                    return(method.callMethod(env, qClass, qThis, args));
                }
            }
            else
            {
                if (_restMethodTable.length == 0)
                {
                    env.warning(L.l(
                                    "'{0}' overloaded method call with {1} "
                                    + "arguments has too many arguments", getName(), args.length));

                    return(NullValue.NULL);
                }
                else
                {
                    AbstractJavaMethod method
                        = getBestFitJavaMethod(null, _restMethodTable, args);

                    return(method.callMethod(env, qClass, qThis, args));
                }
            }
        }
 protected Value errorProtectedAccess(Env env, Value oldThis)
 {
     return(env.error(L.l(
                          "Cannot call protected method {0}::{1}() from '{2}' context",
                          getDeclaringClassName(),
                          getName(),
                          oldThis != null ? oldThis.getClassName() : null)));
 }
Exemplo n.º 7
0
        /**
         * Parses the AFM file.
         * If the webInfLibPath @is not null or empty and @is the valid absolute path to this
         * applications WEB-INF/lib folder (or any other folder containing jars to load),
         * jars inside that folder are also searched for fonts.
         */
        public Font parse(String webInfLibPath, string name)

        {
            MergePath mergePath = new MergePath();

            mergePath.addClassPath();

            File webInfLibFile = new File(webInfLibPath);

            if (webInfLibPath != null &&
                !webInfLibPath.isEmpty() &&
                webInfLibFile.isDirectory())
            {
                string webInfPath = Vfs.lookup(webInfLibFile.getAbsolutePath());

                for (File f : webInfLibFile.listFiles())
                {
                    /*
                     * only look for files that are either jars or zips
                     */
                    if (f.isFile() &&
                        (f.getAbsolutePath().endsWith(".jar") ||
                         f.getAbsolutePath().endsWith(".zip")))
                    {
                        /*
                         * get a path object with the Jar relative to WEB-INF/lib
                         */
                        string jarPath = webInfPath.lookup(f.getName());

                        /*
                         * Encapsulate it as a JarPath, else mergePath.lookup does not look
                         * "into" the jar when looking for resources
                         */
                        mergePath.addMergePath(JarPath.create(jarPath));
                    }
                }
            }

            string path = mergePath.lookup("com/caucho/quercus/lib/pdf/font/" + name + ".afm");

            if (!path.canRead())
            {
                if ("".equals(name))
                {
                    throw new IllegalArgumentException(L.l("Missing font name"));
                }

                throw new FileNotFoundException(L.l("Can't find font '{0}'", name));
            }

            _is = path.openRead();

            try {
                return(parseTop());
            } finally {
                _is.close();
            }
        }
        /**
         * Makes sure the servlet container supports Servlet API 2.4+.
         */
        protected void checkServletAPIVersion()
        {
            int major = _servletContext.getMajorVersion();
            int minor = _servletContext.getMinorVersion();

            if (major < 2 || major == 2 && minor < 4)
            {
                throw new QuercusRuntimeException(
                          L.l("Quercus requires Servlet API 2.4+."));
            }
        }
        /**
         * Evaluates the expression.
         *
         * @param env the calling environment.
         *
         * @return the expression value.
         */
        public override Value eval(Env env)
        {
            if (!_value.isVar())
            {
                env.error(L.l("each() argument must be a variable at '{0}'", _value));
                return(NullValue.NULL);
            }

            Value value = _value.eval(env);

            _listHead.evalAssignEachValue(env, value);

            return(value);
        }
Exemplo n.º 10
0
        static JMSQueue message_get_queue(Env env, string queueName,
                                          ConnectionFactory connectionFactory)
        {
            if (connectionFactory == null)
            {
                connectionFactory = getConnectionFactory(env);
            }

            if (connectionFactory == null)
            {
                env.warning(L.l("No connection factory"));
                return(null);
            }

            try {
                Destination queue = null;

                if (queueName != null && !queueName.equals(""))
                {
                    queue = (Destination) new InitialContext().lookup(
                        "java:comp/env/" + queueName);
                }

                return(new JMSQueue(connectionFactory, queue));
            } catch (Exception e) {
                env.warning(e);

                return(null);
            }
        }
Exemplo n.º 11
0
        /**
         * Evaluates the expression.
         *
         * @param env the calling environment.
         *
         * @return the expression value.
         */
        public override Value eval(Env env)
        {
            Value qThis = env.getThis();

            QuercusClass cls = qThis.getQuercusClass();

            if (cls == null)
            {
                env.error(L.l("no calling class found"), getLocation());

                return(NullValue.NULL);
            }

            StringValue methodName = _methodName.evalStringValue(env);
            int         hash       = methodName.hashCodeCaseInsensitive();

            Value [] values = evalArgs(env, _args);

            env.pushCall(this, cls, values);

            try {
                env.checkTimeout();

                return(cls.callMethod(env, qThis, methodName, hash, values));
            } finally {
                env.popCall();
            }
        }
        public static string encodeMimeWord(String value,
                                            string charset,
                                            string scheme,
                                            string lineBreakChars,
                                            int lineLength)

        {
            if (lineLength != 76)
            {
                throw new UnimplementedException("Mime line length option");
            }

            if (!lineBreakChars.equals("\r\n"))
            {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < lineBreakChars.length(); i++)
                {
                    char ch = lineBreakChars[i];

                    string hex = Integer.toHexString(ch);

                    sb.append("0x");
                    sb.append(hex);
                }

                throw new UnimplementedException(L.l("Mime line break option: '{0}'", sb));
            }

            return(MimeUtility.encodeWord(value, charset, scheme));
        }
        /**
         * True if the server should reuse the current session id if the
         * session doesn't exist.
         */
        public void setReuseSessionId(String reuse)

        {
            if (reuse == null)
            {
                _reuseSessionId = COOKIE;
            }
            else if (reuse.equalsIgnoreCase("true") ||
                     reuse.equalsIgnoreCase("yes") ||
                     reuse.equalsIgnoreCase("cookie"))
            {
                _reuseSessionId = COOKIE;
            }
            else if (reuse.equalsIgnoreCase("false") || reuse.equalsIgnoreCase("no"))
            {
                _reuseSessionId = FALSE;
            }
            else if (reuse.equalsIgnoreCase("all"))
            {
                _reuseSessionId = TRUE;
            }
            else
            {
                throw new ConfigException(
                          L.l("'{0}' @is an invalid value for reuse-session-id.  "
                              + "'true' or 'false' are the allowed values.",
                              reuse));
            }
        }
        /**
         * Gets the name for this category.
         */
        private string getCategory(Env env, int category)
        {
            switch (category)
            {
            case StringModule.LC_MESSAGES:
                return("LC_MESSAGES");

            case StringModule.LC_ALL:
                return("LC_ALL");

            case StringModule.LC_CTYPE:
                return("LC_CTYPE");

            case StringModule.LC_NUMERIC:
                return("LC_NUMERIC");

            case StringModule.LC_TIME:
                return("LC_TIME");

            case StringModule.LC_COLLATE:
                return("LC_COLLATE");

            case StringModule.LC_MONETARY:
                return("LC_MONETARY");

            default:
                env.warning(L.l("Invalid category. Please use named constants"));
                return("LC_MESSAGES");
            }
        }
        /**
         * Evaluates the expression.
         *
         * @param env the calling environment.
         *
         * @return the expression value.
         */
        public Value eval(Env env)
        {
            QuercusClass cl = env.findClass(_className);

            if (cl == null)
            {
                env.error(L.l("no matching class {0}", _className), getLocation());
            }

            Value [] values = evalArgs(env, _args);

            Value oldThis = env.getThis();

            // php/09qe
            Value qThis = oldThis;

            env.pushCall(this, cl, values);

            try {
                env.checkTimeout();

                return(cl.callConstructor(env, qThis, values));
            } finally {
                env.popCall();
                env.setThis(oldThis);
            }
        }
        /**
         * Evaluates the expression.
         *
         * @param env the calling environment.
         *
         * @return the expression value.
         */
        public Value eval(Env env)
        {
            QuercusClass cl = env.findClass(_className);

            if (cl == null)
            {
                throw env.createErrorException(L.l("{0} @is an unknown class",
                                                   _className));
            }

            StringValue nameV = _nameV;

            AbstractFunction fun = cl.getFunction(nameV);

            Value [] values = evalArgs(env, _args);

            Value qThis = env.getThis();

            env.pushCall(this, qThis, values);

            try {
                env.checkTimeout();

                return(cl.callMethod(env, qThis, nameV, nameV.hashCode(), values));
            } finally {
                env.popCall();
            }
        }
        private Value error(Env env)
        {
            env.warning(L.l("{0}::{1}() @is an invalid callback method",
                            _obj.getClassName(), _methodName));

            return(NullValue.NULL);
        }
Exemplo n.º 18
0
        Mcrypt(Env env, string algorithm, string mode)

        {
            _algorithm = algorithm;
            _mode      = mode.toUpperCase(Locale.ENGLISH);

            string transformation = getTransformation(algorithm, mode);

            if (transformation == null)
            {
                throw new QuercusRuntimeException(L.l("'{0}' @is an unknown algorithm",
                                                      algorithm));
            }

            _cipher = Cipher.getInstance(transformation);
        }
        /**
         * Evaluates the expression.
         *
         * @param env the calling environment.
         *
         * @return the expression value.
         */
        public Value eval(Env env)
        {
            Value qThis = env.getThis();

            QuercusClass cls = qThis.getQuercusClass();

            if (cls == null)
            {
                env.error(L.l("no calling class found"), getLocation());

                return(NullValue.NULL);
            }

            Value [] values = evalArgs(env, _args);

            env.pushCall(this, cls, values);

            try {
                env.checkTimeout();

                return(cls.callMethod(env, qThis, _methodName, _hash, values));
            } finally {
                env.popCall();
            }
        }
Exemplo n.º 20
0
        public static Value unicode_decode(Env env,
                                           BinaryValue str,
                                           string encoding,
                                           @Optional int errorMode)
        {
            try {
                Decoder decoder = Decoder.create(encoding);

                return(decoder.decodeUnicode(str));
            }
            catch (UnsupportedCharsetException e) {
                log.log(Level.FINE, e.getMessage(), e);
                env.warning(L.l("unsupported charset {0}", encoding));

                return(BooleanValue.FALSE);
            }
        }
Exemplo n.º 21
0
        /**
         * Binds the user's arguments to the actual arguments.
         *
         * @param args the user's arguments
         * @return the user arguments augmented by any defaults
         */
        public Expr [] bindArguments(Env env, Expr fun, Expr [] args)
        {
            if (args.length != 0)
            {
                env.warning(L.l("too many arguments"));
            }

            return(args);
        }
Exemplo n.º 22
0
        /**
         *
         */
        private void uncaughtExceptionError(Env env, QuercusLanguageException e)
        {
            Location location = e.getLocation(env);
            string   type     = e.getValue().getClassName();
            string   message  = e.getMessage(env);

            env.error(L.l("Uncaught exception of type '{0}' with message '{1}'", type, message),
                      location);
        }
        public static SocketInputOutput socket_create(Env env,
                                                      int domain,
                                                      int type,
                                                      int protocol)
        {
            try {
                SocketInputOutput.Domain socketDomain = SocketInputOutput.Domain.AF_INET;

                switch (domain)
                {
                case AF_INET:
                    socketDomain = SocketInputOutput.Domain.AF_INET;
                    break;

                case AF_INET6:
                    socketDomain = SocketInputOutput.Domain.AF_INET6;
                    break;

                case AF_UNIX:
                    env.warning(L.l("Unix sockets not supported"));
                    return(null);

                default:
                    env.warning(L.l("Unknown domain: {0}", domain));
                    return(null);
                }

                switch (type)
                {
                case SOCK_STREAM:
                    return(new TcpInputOutput(env, new Socket(), socketDomain));

                case SOCK_DGRAM:
                    return(new UdpInputOutput(env, new DatagramSocket(), socketDomain));

                default:
                    env.warning(L.l("socket stream not socked"));
                    return(null);
                }
            } catch (Exception e) {
                env.warning(e);
                return(null);
            }
        }
        public static ReflectionParameter __construct(Env env,
                                                      StringValue funName,
                                                      StringValue paramName)
        {
            AbstractFunction fun = env.findFunction(funName);

            Arg [] args = fun.getArgs(env);

            for (int i = 0; i < args.length; i++)
            {
                if (args[i].getName().equals(paramName))
                {
                    return(new ReflectionParameter(fun, args[i]));
                }
            }

            throw new ReflectionException(env,
                                          L.l("cannot find parameter '{0}'", paramName));
        }
        /**
         * Binds the user's arguments to the actual arguments.
         *
         * @param args the user's arguments
         * @return the user arguments augmented by any defaults
         */
        public Expr [] bindArguments(Env env, Expr fun, Expr [] args)
        {
            if (args.length > 0)
            {
                log.fine(L.l("{0}incorrect number of arguments{1}",
                             env.getLocation().getMessagePrefix(),
                             env.getFunctionLocation()));
            }

            return(args);
        }
Exemplo n.º 26
0
        public static ReflectionClass __construct(Env env, Value obj)
        {
            QuercusClass cls;

            if (obj.isObject())
            {
                cls = ((ObjectValue)obj.toValue()).getQuercusClass();
            }
            else
            {
                cls = env.findClass(obj.ToString());
            }

            if (cls == null)
            {
                throw new ReflectionException(env, L.l("class '{0}' doesn't exist", obj));
            }

            return(new ReflectionClass(cls));
        }
Exemplo n.º 27
0
        private Value errorReturn(Env env, string message)
        {
            int end = Math.min(_len, _offset + 1);

            string token = _str.substring(_offset, end).ToString();

            if (message != null)
            {
                log.fine(L.l("error parsing '{0}': {1}\n  [{2}]",
                             token, message,
                             currentLine()));
            }
            else
            {
                log.fine(L.l("error parsing '{0}'\n  [{1}]", token, currentLine()));
            }

            JsonModule.setErrorLast(env, JsonModule.JSON_ERROR_SYNTAX);

            return(NullValue.NULL);
        }
        /**
         * Evaluates the function.
         */
        public Value call(Env env, Value [] args)
        {
            if (_globalId > 0)
            {
                AbstractFunction fun = env._fun[_globalId];
                env._fun[_id] = fun;

                return(fun.call(env, args));
            }

            return(env.error(L.l("'{0}' @is an unknown function.", _name)));
        }
Exemplo n.º 29
0
        public static Value __construct(Env env, @Optional string queueName)
        {
            JMSQueue queue = JMSModule.message_get_queue(env, queueName, null);

            if (queue == null)
            {
                env.warning(L.l("'{0}' @is an unknown JMSQueue", queueName));
                return(NullValue.NULL);
            }

            return(env.wrapJava(queue));
        }
        public Value evalAssignEachValue(Env env, Value value)
        {
            if (!value.isArray())
            {
                env.warning(L.l("variable passed to each must reference an array, saw {0}", value.getType()));
                return(NullValue.NULL);
            }

            ArrayValue array = value.toArrayValue(env);

            if (_varList.length > 0 && _varList[0] != null)
            {
                _varList[0].evalAssignValue(env, array.key());
            }

            if (_varList.length > 1 && _varList[1] != null)
            {
                _varList[1].evalAssignValue(env, array.current().copy());
            }

            return(array.each());
        }