private static ConstArrayValue toUnicodeArray(Env env, ArrayValue array)
        {
            ArrayValueImpl copy = new ArrayValueImpl();

            Iterator <Map.Entry <Value, Value> > iter = array.getIterator(env);

            while (iter.hasNext())
            {
                Map.Entry <Value, Value> entry = iter.next();

                Value key   = entry.getKey();
                Value value = entry.getValue();

                if (key.isString())
                {
                    key = key.toUnicodeValue(env);
                }

                if (value.isString())
                {
                    value = value.toUnicodeValue(env);
                }

                copy.put(key, value);
            }

            return(new ConstArrayValue(copy));
        }
Beispiel #2
0
        public static ArrayValue getModifierNames(int modifierValue)
        {
            ArrayValue array = new ArrayValueImpl();


            return(array);
        }
Beispiel #3
0
        /**
         * Returns the supported key sizes
         */
        public Value get_supported_key_sizes()
        {
            ArrayValue value = new ArrayValueImpl();

            // php/1q0c - can mix any key size with any block size
            if (McryptModule.MCRYPT_RIJNDAEL_128.equals(_algorithm))
            {
                value.put(128 / 8);
                value.put(192 / 8);
                value.put(256 / 8);
            }
            else if (McryptModule.MCRYPT_RIJNDAEL_192.equals(_algorithm))
            {
                value.put(128 / 8);
                value.put(192 / 8);
                value.put(256 / 8);
            }
            else if (McryptModule.MCRYPT_RIJNDAEL_256.equals(_algorithm))
            {
                value.put(128 / 8);
                value.put(192 / 8);
                value.put(256 / 8);
            }
            else if (McryptModule.MCRYPT_3DES.equals(_algorithm))
            {
                value.put(24);
            }
            else if (McryptModule.MCRYPT_DES.equals(_algorithm))
            {
                value.put(8);
            }

            return(value);
        }
        public ArrayValue getINIEntries(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            for (ModuleInfo moduleInfo : env.getQuercus().getModules())
            {
                Set <String> extensionSet = moduleInfo.getLoadedExtensions();

                if (extensionSet.contains(_name))
                {
                    IniDefinitions iniDefs = moduleInfo.getIniDefinitions();

                    Set <Map.Entry <String, IniDefinition> > entrySet = iniDefs.entrySet();

                    if (entrySet != null)
                    {
                        for (Map.Entry <String, IniDefinition> entry : entrySet)
                        {
                            array.put(StringValue.create(entry.getKey()),
                                      entry.getValue().getValue(env));
                        }
                    }
                }
            }

            return(array);
        }
        public override StringValue serialize(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            StringValue objStr   = env.createString("obj");
            StringValue valueStr = env.createString("inf");

            ObjectEntry entry = _head;

            while (entry != null)
            {
                ArrayValue inner = new ArrayValueImpl();

                inner.put(objStr, entry.getObject());
                inner.put(valueStr, entry.getValue());

                array.append(inner);

                entry = entry.getNext();
            }

            string str = VariableModule.serialize(env, array);

            return(env.createString(str));
        }
        public override Value wrap(Env env, Object obj)
        {
            if (!_isInit)
            {
                init();
            }

            ArrayValueImpl arrayValueImpl = new ArrayValueImpl();

            // XXX: needs to go into constructor
            Class componentClass = getType().getComponentType();

            MarshalFactory factory = getModuleContext().getMarshalFactory();
            Marshal        componentClassMarshal = factory.create(componentClass);

            int length = Array.getLength(obj);

            for (int i = 0; i < length; i++)
            {
                Object component = Array.get(obj, i);

                arrayValueImpl.put(componentClassMarshal.unmarshal(env, component));
            }

            return(arrayValueImpl);
        }
Beispiel #7
0
        public static Value get_defined_vars(Env env)
        {
            ArrayValue result = new ArrayValueImpl();

            Map <StringValue, EnvVar> map = env.getEnv();

            for (Map.Entry <StringValue, EnvVar> entry : map.entrySet())
            {
                result.append(entry.getKey(),
                              entry.getValue().get());
            }

            Map <StringValue, EnvVar> globalMap = env.getGlobalEnv();

            if (map != globalMap)
            {
                for (Map.Entry <StringValue, EnvVar> entry : globalMap.entrySet())
                {
                    result.append(entry.getKey(),
                                  entry.getValue().get());
                }
            }

            return(result);
        }
Beispiel #8
0
        public static Value class_parents(Env env,
                                          Value obj,
                                          @Optional bool autoload)
        {
            QuercusClass cls;

            if (obj.isObject())
            {
                cls = ((ObjectValue)obj.toObject(env)).getQuercusClass();
            }
            else
            {
                cls = env.findClass(obj.ToString(), autoload, true, true);
            }

            if (cls != null)
            {
                ArrayValue array = new ArrayValueImpl();

                QuercusClass parent = cls;

                while ((parent = parent.getParent()) != null)
                {
                    string name = parent.getName();

                    array.put(name, name);
                }

                return(array);
            }
            else
            {
                return(BooleanValue.FALSE);
            }
        }
Beispiel #9
0
        public Value getTransitions(@Optional int timestampBegin,
                                    @Optional int timestampEnd)
        {
            ArrayValue array = new ArrayValueImpl();

            return(array);
        }
Beispiel #10
0
        /**
         * Evaluates the expression.
         *
         * @param env the calling environment.
         *
         * @return the expression value.
         */
        public Value eval(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            for (int i = 0; i < _values.length; i++)
            {
                Expr keyExpr = _keys[i];

                Value value = _values[i].evalArg(env, true);
                // php/0471
                value = value.toRefValue();

                if (keyExpr != null)
                {
                    Value key = keyExpr.evalArg(env, true).toLocalValue();

                    array.put(key, value);
                }
                else
                {
                    array.put(value);
                }
            }

            return(array);
        }
Beispiel #11
0
        protected override ArrayValue getCookies()
        {
            ArrayValue array         = new ArrayValueImpl();
            bool       isMagicQuotes = getIniBoolean("magic_quotes_gpc");

            Value  serverEnv = getGlobalValue("_SERVER");
            string cookies   = serverEnv.get(createString("HTTP_COOKIE")).ToString();

            int i   = 0;
            int j   = 0;
            int len = cookies.length();

            while ((j = cookies.indexOf(';', i)) >= 0)
            {
                if (j == i)
                {
                    i = j + 1;
                    continue;
                }

                addCookie(array, cookies, i, j, isMagicQuotes);

                i = j + 1;
            }

            if (i < len)
            {
                addCookie(array, cookies, i, len, isMagicQuotes);
            }

            return(array);
        }
Beispiel #12
0
        public ArrayValue getProperties(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            HashMap <StringValue, ClassField> fieldMap = _cls.getClassFields();

            for (ClassField field : fieldMap.values())
            {
                /// XXX: private fields of parent classes are hidden
                ReflectionProperty prop
                    = ReflectionProperty.create(env, _cls, field.getName(), false);

                array.put(env.wrapJava(prop));
            }

            ArrayList <StringValue> staticFieldList = _cls.getStaticFieldNames();

            for (StringValue fieldName : staticFieldList)
            {
                ReflectionProperty prop
                    = ReflectionProperty.create(env, _cls, fieldName, true);

                array.put(env.wrapJava(prop));
            }

            return(array);
        }
Beispiel #13
0
        private static void addAbbreviation(ArrayValue array,
                                            TimeZone tz,
                                            bool isDST)
        {
            ArrayValueImpl zone = new ArrayValueImpl();

            zone.put("dst", isDST);

            int offset = tz.getRawOffset() / 1000;

            if (isDST)
            {
                offset += tz.getDSTSavings() / 1000;
            }

            zone.put("offset", offset);
            zone.put("timezone_id", tz.getID());

            string name  = tz.getDisplayName(isDST, TimeZone.SHORT);
            Value  nameV = StringValue.create(name.toLowerCase(Locale.ENGLISH));

            Value zones = array.get(nameV);

            if (zones.isNull())
            {
                zones = new ArrayValueImpl();

                array.put(nameV, zones);
            }

            zones.put(zone);
        }
Beispiel #14
0
        public ArrayValue getInterfaces(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            findInterfaces(env, array, _cls);

            return(array);
        }
Beispiel #15
0
        /**
         * Evaluates the function.
         */
        public override Value callMethodRef(Env env,
                                            QuercusClass qClass,
                                            Value qThis,
                                            Value [] args)
        {
            ArrayValueImpl arrayArgs = new ArrayValueImpl(args);

            return(_call.callMethodRef(env, qClass, qThis,
                                       _name, arrayArgs));
        }
        /**
         * Calls a user function
         */
        public static Value call_user_func_array(Env env,
                                                 Callable function,
                                                 Value arg)
        {
            if (function == null)
            {
                env.warning("call_user_func_array: first argument @is not a valid function");
                return(NullValue.NULL);
            }

            ArrayValue argArray;

            if (arg.isArray())
            {
                argArray = arg.toArray();
            }
            else
            {
                argArray = new ArrayValueImpl().append(arg);
            }

            Value [] args;

            if (argArray != null)
            {
                args = new Value[argArray.getSize()];

                int i = 0;

                for (Map.Entry <Value, Value> entry : argArray.entrySet())
                {
                    ArrayValue.Entry arrayEntry = (ArrayValue.Entry)entry;

                    args[i++] = arrayEntry.getRawValue();
                }
            }
            else
            {
                args = new Value[0];
            }

            // nam: 2012-04-30 this works for interpreted, but need to also work for compiled
            //QuercusClass oldCallingClass = env.getCallingClass();
            //env.pushCall(new CallExpr(function.getCallbackName(), Expr.NULL_ARGS), null, args);

            try {
                return(function.call(env, args).copyReturn());
            }
            finally {
                //env.popCall();

                //env.setCallingClass(oldCallingClass);
            }
        }
        protected override ArrayValue createArgv()
        {
            ArrayValue array = new ArrayValueImpl();

            String[] argv = _argv;

            for (int i = 0; i < argv.length; i++)
            {
                array.put(argv[i]);
            }

            return(array);
        }
Beispiel #18
0
        public ArrayValue getParameters(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

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

            for (int i = 0; i < args.length; i++)
            {
                array.put(env.wrapJava(new ReflectionParameter(_callable, args[i])));
            }

            return(array);
        }
Beispiel #19
0
        public ArrayValue getMethods(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            MethodMap <AbstractFunction> map = _cls.getMethodMap();

            for (AbstractFunction method : map.values())
            {
                array.put(env.wrapJava(new ReflectionMethod(_cls.getName(), method)));
            }

            return(array);
        }
        /*
         * Returns an array of decoded Mime headers/fields.
         */
        public static Value decodeMimeHeaders(Env env,
                                              StringValue encodedHeaders,
                                              string charset)

        {
            ArrayValue headers = new ArrayValueImpl();

            try {
                Enumeration <Header> enumeration
                    = new InternetHeaders(encodedHeaders.toInputStream()).getAllHeaders();

                while (enumeration.hasMoreElements())
                {
                    Header header = enumeration.nextElement();

                    StringValue name
                        = QuercusMimeUtility.decodeMime(env, header.getName(), charset);
                    StringValue val
                        = QuercusMimeUtility.decodeMime(env, header.getValue(), charset);

                    Value headerName;
                    if ((headerName = headers.containsKey(name)) == null)
                    {
                        headers.put(name, val);
                        continue;
                    }

                    ArrayValue inner;
                    if (headerName.isArray())
                    {
                        inner = headerName.toArrayValue(env);
                    }
                    else
                    {
                        inner = new ArrayValueImpl();
                        inner.put(headerName);
                    }

                    inner.put(val);
                    headers.put(name, inner);
                }

                return(headers);
            } catch (MessagingException e) {
                log.log(Level.FINE, e.getMessage(), e);
                env.warning(e.getMessage());

                return(BooleanValue.FALSE);
            }
        }
Beispiel #21
0
        /**
         * Returns a PHP associative array of JSON object.
         */
        private Value decodeObjectToArray(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            _offset++;

            while (true)
            {
                skipWhitespace();

                if (_len <= _offset || _str[_offset] == '}')
                {
                    _offset++;
                    break;
                }

                Value name = jsonDecodeImpl(env, false);

                skipWhitespace();

                if (_offset >= _len || _str[_offset++] != ':')
                {
                    return(errorReturn(env, "expected ':'"));
                }

                array.append(name, jsonDecodeImpl(env, false));

                skipWhitespace();

                char ch;

                if (_offset >= _len)
                {
                    return(errorReturn(env, "expected either ',' or '}'"));
                }
                else if ((ch = _str[_offset++]) == ',')
                {
                }
                else if (ch == '}')
                {
                    break;
                }
                else
                {
                    return(errorReturn(env, "expected either ',' or '}'"));
                }
            }

            return(array);
        }
Beispiel #22
0
        public static ArrayValue listIdentifiers()
        {
            ArrayValue array = new ArrayValueImpl();

            string [] ids = TimeZone.getAvailableIDs();

            java.util.Arrays.sort(ids);

            for (int i = 0; i < ids.length; i++)
            {
                array.put(ids[i]);
            }

            return(array);
        }
        public StreamContextResource(ArrayValue options, ArrayValue parameters)
        {
            if (options == null)
            {
                options = new ArrayValueImpl();
            }

            if (parameters == null)
            {
                parameters = new ArrayValueImpl();
            }

            _options    = options;
            _parameters = parameters;
        }
 /**
  * Sets the unparsedEntityDecl handler
  *
  * @param handler
  * @return true always even if handler @is disabled
  */
 public bool xml_set_unparsed_entity_decl_handler(Env env, Value handler)
 {
     if (_obj == null)
     {
         _unparsedEntityDeclHandler = handler.toCallable(env, false);
     }
     else
     {
         Value value = new ArrayValueImpl();
         value.put(_obj);
         value.put(handler);
         _unparsedEntityDeclHandler = value.toCallable(env, false);
     }
     return(true);
 }
 /**
  * Sets the notationDecl handler
  *
  * @param handler
  * @return true always even if handler @is disabled
  */
 public bool xml_set_notation_decl_handler(Env env, Value handler)
 {
     if (_obj == null)
     {
         _notationDeclHandler = handler.toCallable(env, false);
     }
     else
     {
         Value value = new ArrayValueImpl();
         value.put(_obj);
         value.put(handler);
         _notationDeclHandler = value.toCallable(env, false);
     }
     return(true);
 }
        private ArrayValue createAndFillArray()
        {
            ArrayValue array = new ArrayValueImpl();

            for (Map.Entry <StringValue, EnvVar> entry : _env.getGlobalEnv()
                 .entrySet())
            {
                Value key = entry.getKey();
                Value val = entry.getValue().get();

                array.put(key, val);
            }

            return(array);
        }
Beispiel #27
0
        public ArrayValue getConstants(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            HashMap <StringValue, Value> _constMap = _cls.getConstantMap(env);

            for (Map.Entry <StringValue, Value> entry : _constMap.entrySet())
            {
                Value name = entry.getKey();

                array.put(name, entry.getValue());
            }

            return(array);
        }
        /**
         * Sets the character data handler function.
         *
         * @param handler can be empty string or FALSE
         * @return true always even if handler @is disabled
         */
        public bool xml_set_character_data_handler(Env env, Value handler)
        {
            if (_obj == null)
            {
                _characterDataHandler = handler.toCallable(env, false);
            }
            else
            {
                Value value = new ArrayValueImpl();
                value.put(_obj);
                value.put(handler);
                _characterDataHandler = value.toCallable(env, false);
            }

            return(true);
        }
        public static Value func_get_args(Env env)
        {
            Value [] args = env.getFunctionArgs();

            ArrayValue result = new ArrayValueImpl();

            if (args != null)
            {
                for (int i = 0; i < args.length; i++)
                {
                    result.put(args[i]);
                }
            }

            return(result);
        }
        public ArrayValue getClassNames(Env env)
        {
            ArrayValue array = new ArrayValueImpl();

            HashSet <String> exts = env.getModuleContext().getExtensionClasses(_name);

            if (exts != null)
            {
                for (String name : exts)
                {
                    array.put(name);
                }
            }

            return(array);
        }