public CompiledConstStringValue(String s,
                                        LongValue longValue,
                                        DoubleValue doubleValue,
                                        ValueType valueType,
                                        Value key,
                                        int hashCode)
            : base(s)
        {
            setString(s);
            setLongValue(longValue);
            setDoubleValue(doubleValue);
            setValueType(valueType);

            setKey(key);
            setLowerCase(toLowerCase(Locale.ENGLISH));

            _compiledHashCode = hashCode;
        }
        /**
         * Converts to a key.
         */
        public override Value toKey()
        {
            char [] buffer = _buffer;
            int     len    = _length;

            if (len == 0)
            {
                return(this);
            }

            int  sign  = 1;
            long value = 0;

            int i  = 0;
            int ch = buffer[i];

            if (ch == '-')
            {
                if (len == 1)
                {
                    return(this);
                }

                sign = -1;
                i++;
            }

            for (; i < len; i++)
            {
                ch = buffer[i];

                if ('0' <= ch && ch <= '9')
                {
                    value = 10 * value + ch - '0';
                }
                else
                {
                    return(this);
                }
            }

            return(LongValue.create(sign * value));
        }
 /**
  * Adds to the following value.
  */
 public override Value add(long lLong)
 {
     return(LongValue.create(lLong + _value));
 }
        /**
         * Post-increment the following value.
         */
        public override Value increment(int incr)
        {
            long newValue = _value + incr;

            return(LongValue.create(newValue));
        }
        /**
         * Post-decrement the following value.
         */
        public override Value postdecr()
        {
            long newValue = _value - 1;

            return(LongValue.create(newValue));
        }
        /**
         * Pre-increment the following value.
         */
        public override Value preincr()
        {
            long newValue = _value + 1;

            return(LongValue.create(newValue));
        }
        /**
         * The previous integer
         */
        public override Value subOne()
        {
            long newValue = _value - 1;

            return(LongValue.create(newValue));
        }
            public Map.Entry <Value, Value> next()
            {
                Value val = wrapJava(_iterator.next());

                return(new ArrayValue.Entry(LongValue.create(_index++), val));
            }
Пример #9
0
        public static void addFormValue(Env env,
                                        ArrayValue array,
                                        string key,
                                        Value formValue,
                                        string [] formValueList,
                                        bool addSlashesToValues,
                                        bool isReplaceSpacesWithUnderscores)
        {
            int p = -1;
            int q = -1;

            if (key != null)
            {
                p = key.indexOf('[');
                q = key.indexOf(']', p);
            }

            if (p >= 0 && p < q)
            {
                if (p == 0)
                {
                    // php/080e
                    return;
                }

                int keyStart = 0;
                int keyEnd   = p;

                while (p > 0 && p < q)
                {
                    string currentKey = key.substring(keyStart, keyEnd);

                    if (keyStart == 0)
                    {
                        // php/081p
                        currentKey = currentKey.replace('.', '_');
                    }

                    if (isReplaceSpacesWithUnderscores)
                    {
                        // php/080h
                        currentKey = currentKey.replace(' ', '_');

                        // php/080k
                        isReplaceSpacesWithUnderscores = false;
                    }

                    StringValue currentKeyValue = env.createString(currentKey);
                    Value       currentArray    = array.get(currentKeyValue);

                    if (!currentArray.isArray())
                    {
                        currentArray = new ArrayValueImpl();
                    }

                    if (currentKeyValue.length() == 0)
                    {
                        array.append(currentArray);
                    }
                    else
                    {
                        array.put(currentKeyValue, currentArray);
                    }

                    array = currentArray.toArrayValue(env);

                    keyStart = p + 1;
                    keyEnd   = q;

                    p = key.indexOf('[', q + 1);
                    q = key.indexOf(']', p + 1);
                }

                if (keyEnd > 0)
                {
                    key = key.substring(keyStart, keyEnd);
                }
                else
                {
                    key = key.substring(keyStart);
                }

                if (isReplaceSpacesWithUnderscores)
                {
                    // php/080h
                    key = key.replace(' ', '_');
                }

                if (key.length() == 0)
                {
                    if (formValueList != null)
                    {
                        for (int i = 0; i < formValueList.length; i++)
                        {
                            Value value;

                            if (formValueList[i] != null)
                            {
                                value = env.createString(formValueList[i]);
                            }
                            else
                            {
                                value = NullValue.NULL;
                            }

                            put(array, null, value, addSlashesToValues);
                        }
                    }
                    else
                    {
                        array.put(formValue);
                    }
                }
                else if ('0' <= key[0] && key[0] <= '9')
                {
                    put(array,
                        LongValue.create(StringValue.toLong(key)),
                        formValue,
                        addSlashesToValues);
                }
                else
                {
                    put(array, env.createString(key), formValue, addSlashesToValues);
                }
            }
            else
            {
                if (key != null)
                {
                    key = key.replace('.', '_');

                    if (isReplaceSpacesWithUnderscores)
                    {
                        // php/080h
                        key = key.replace(' ', '_');
                    }

                    put(array, env.createString(key), formValue, addSlashesToValues);
                }
                else
                {
                    put(array, null, formValue, addSlashesToValues);
                }
            }
        }
Пример #10
0
        private static void addFormFile(Env env,
                                        ArrayValue files,
                                        string name,
                                        string fileName,
                                        string tmpName,
                                        string mimeType,
                                        long fileLength,
                                        bool addSlashesToValues,
                                        long maxFileSize)
        {
            int    p     = name.indexOf('[');
            string index = "";

            if (p >= 0)
            {
                index = name.substring(p);
                name  = name.substring(0, p);
            }

            // php/085j
            name = name.replace("\u0000", "");

            StringValue nameValue = env.createString(name);
            Value       v         = files.get(nameValue).toValue();
            ArrayValue  entry     = null;

            if (v instanceof ArrayValue)
            {
                entry = (ArrayValue)v;
            }

            if (entry == null)
            {
                entry = new ArrayValueImpl();
                files.put(nameValue, entry);
            }

            int error;

            // php/1667
            long uploadMaxFilesize
                = env.getIniBytes("upload_max_filesize", 2 * 1024 * 1024);

            // php/085j
            fileName = fileName.replace("\u0000", "");

            if (fileName.length() == 0)
            {
                // php/0864
                error = FileModule.UPLOAD_ERR_NO_FILE;
            }
            else if (fileLength > uploadMaxFilesize)
            {
                error = FileModule.UPLOAD_ERR_INI_SIZE;
            }
            else if (fileLength > maxFileSize)
            {
                error = FileModule.UPLOAD_ERR_FORM_SIZE;
            }
            else
            {
                error = FileModule.UPLOAD_ERR_OK;
            }

            addFormValue(env, entry, "name" + index, env.createString(fileName),
                         null, addSlashesToValues, true);

            long size;


            if (error == FileModule.UPLOAD_ERR_OK)
            {
                size = fileLength;
            }
            else
            {
                mimeType = "";
                tmpName  = "";
                size     = 0;
            }

            if (mimeType != null)
            {
                addFormValue(env, entry, "type" + index, env.createString(mimeType),
                             null, addSlashesToValues, true);
            }

            addFormValue(env, entry, "tmp_name" + index, env.createString(tmpName),
                         null, addSlashesToValues, true);

            addFormValue(env, entry, "error" + index, LongValue.create(error),
                         null, addSlashesToValues, true);

            addFormValue(env, entry, "size" + index, LongValue.create(size),
                         null, addSlashesToValues, true);

            addFormValue(env, files, name, entry, null, addSlashesToValues, true);
        }
Пример #11
0
        private static void addFormFile(Env env,
                                        ArrayValue files,
                                        string fileName,
                                        string tmpName,
                                        string mimeType,
                                        long fileLength,
                                        bool addSlashesToValues,
                                        long maxFileSize)
        {
            ArrayValue entry = new ArrayValueImpl();
            int        error;

            // php/1667
            long uploadMaxFilesize
                = env.getIniBytes("upload_max_filesize", 2 * 1024 * 1024);

            // php/085j
            fileName = fileName.replace("\u0000", "");

            if (fileName.length() == 0)
            {
                // php/0864
                error = FileModule.UPLOAD_ERR_NO_FILE;
            }
            else if (fileLength > uploadMaxFilesize)
            {
                error = FileModule.UPLOAD_ERR_INI_SIZE;
            }
            else if (fileLength > maxFileSize)
            {
                error = FileModule.UPLOAD_ERR_FORM_SIZE;
            }
            else
            {
                error = FileModule.UPLOAD_ERR_OK;
            }

            addFormValue(env, entry, "name", env.createString(fileName),
                         null, addSlashesToValues, true);

            long size;

            if (error != FileModule.UPLOAD_ERR_INI_SIZE)
            {
                size = fileLength;
            }
            else
            {
                mimeType = "";
                tmpName  = "";
                size     = 0;
            }

            if (mimeType != null)
            {
                addFormValue(env, entry, "type", env.createString(mimeType),
                             null, addSlashesToValues, true);

                entry.put("type", mimeType);
            }

            addFormValue(env, entry, "tmp_name", env.createString(tmpName),
                         null, addSlashesToValues, true);

            addFormValue(env, entry, "error", LongValue.create(error),
                         null, addSlashesToValues, true);

            addFormValue(env, entry, "size", LongValue.create(size),
                         null, addSlashesToValues, true);

            addFormValue(env, files, null, entry, null, addSlashesToValues, true);
        }
 void setPrev(LongValue prev)
 {
     _prev = prev;
 }
        public LongCacheValue(long value, LongValue next)
        {
            super(value);

            _next = next;
        }
 /**
  * Creatse a tail index.
  */
 public override Value createTailKey()
 {
     return(LongValue.create(getSize()));
 }
            public Value next()
            {
                _iterator.next();

                return(LongValue.create(_index++));
            }
Пример #16
0
 /**
  * Subtracts the following value.
  */
 public override Value sub(long rLong)
 {
     return(LongValue.create(_value - rLong));
 }
 protected void setLongValue(LongValue value)
 {
     _longValue = value;
 }
Пример #18
0
        /*
         * public override Value toAutoArray()
         * {
         * if (_value == 0)
         *  return new ArrayValueImpl();
         * else
         *  return super.toAutoArray();
         * }
         */

        /**
         * Negates the value.
         */
        public override Value neg()
        {
            return(LongValue.create(-_value));
        }
Пример #19
0
        /**
         * The next integer
         */
        public override Value addOne()
        {
            long newValue = _value + 1;

            return(LongValue.create(newValue));
        }
        /**
         * Fills the map.
         */
        private void fillMap()
        {
            if (_isFilled)
            {
                return;
            }

            _isFilled = true;

            for (Map.Entry <Value, Value> entry
                 : _env.getQuercus().getServerEnvMap().entrySet())
            {
                super.put(entry.getKey(), entry.getValue());
            }

            QuercusHttpServletRequest request = _env.getRequest();
            bool isUnicode = _env.isUnicodeSemantics();

            if (request != null)
            {
                super.put(isUnicode ? SERVER_ADDR_VU : SERVER_ADDR_V,
                          _env.createString(request.getLocalAddr()));
                super.put(isUnicode ? SERVER_NAME_VU : SERVER_NAME_V,
                          _env.createString(request.getServerName()));

                super.put(isUnicode ? SERVER_PORT_VU : SERVER_PORT_V,
                          LongValue.create(request.getServerPort()));
                super.put(isUnicode ? REMOTE_HOST_VU : REMOTE_HOST_V,
                          _env.createString(request.getRemoteHost()));
                super.put(isUnicode ? REMOTE_ADDR_VU : REMOTE_ADDR_V,
                          _env.createString(request.getRemoteAddr()));
                super.put(isUnicode ? REMOTE_PORT_VU : REMOTE_PORT_V,
                          LongValue.create(request.getRemotePort()));

                // Drupal's optional activemenu plugin only works on Apache servers!
                // bug at http://drupal.org/node/221867
                super.put(isUnicode ? SERVER_SOFTWARE_VU : SERVER_SOFTWARE_V,
                          _env.createString("Apache PHP Quercus("
                                            + _env.getQuercus().getVersion()
                                            + ")"));

                super.put(isUnicode ? SERVER_PROTOCOL_VU : SERVER_PROTOCOL_V,
                          _env.createString(request.getProtocol()));
                super.put(isUnicode ? REQUEST_METHOD_VU : REQUEST_METHOD_V,
                          _env.createString(request.getMethod()));

                string queryString = QuercusRequestAdapter.getPageQueryString(request);
                string requestURI  = QuercusRequestAdapter.getPageURI(request);
                string servletPath = QuercusRequestAdapter.getPageServletPath(request);
                string pathInfo    = QuercusRequestAdapter.getPagePathInfo(request);
                string contextPath = QuercusRequestAdapter.getPageContextPath(request);

                if (queryString != null)
                {
                    super.put(isUnicode ? QUERY_STRING_VU : QUERY_STRING_V,
                              _env.createString(queryString));
                }

                // XXX: a better way?
                // getRealPath() returns a native path
                // need to convert windows paths to resin paths
                string root = request.getRealPath("/");

                if (root == null)
                {
                    root = _env.getPwd().getFullPath();
                }

                if (root.indexOf('\\') >= 0)
                {
                    root = root.replace('\\', '/');
                    root = '/' + root;
                }

                super.put(isUnicode ? DOCUMENT_ROOT_VU : DOCUMENT_ROOT_V,
                          _env.createString(root));
                super.put(isUnicode ? SCRIPT_NAME_VU : SCRIPT_NAME_V,
                          _env.createString(contextPath + servletPath));
                super.put(isUnicode ? SCRIPT_URL_VU : SCRIPT_URL_V,
                          _env.createString(requestURI));

                if (queryString != null)
                {
                    requestURI = requestURI + '?' + queryString;
                }

                super.put(isUnicode ? REQUEST_URI_VU : REQUEST_URI_V,
                          _env.createString(requestURI));

                super.put(isUnicode ? REQUEST_TIME_VU : REQUEST_TIME_V,
                          LongValue.create(_env.getStartTime() / 1000));

                super.put(isUnicode ? REQUEST_TIME_FLOAT_VU : REQUEST_TIME_FLOAT_V,
                          DoubleValue.create(_env.getMicroTime() / 1000000.0));

                super.put(isUnicode ? SCRIPT_FILENAME_VU : SCRIPT_FILENAME_V,
                          _env.createString(request.getRealPath(servletPath)));

                if (pathInfo != null)
                {
                    super.put(isUnicode ? PATH_INFO_VU : PATH_INFO_V,
                              _env.createString(pathInfo));
                    super.put(isUnicode ? PATH_TRANSLATED_VU : PATH_TRANSLATED_V,
                              _env.createString(request.getRealPath(pathInfo)));
                }

                if (request.isSecure())
                {
                    super.put(isUnicode ? HTTPS_VU : HTTPS_V,
                              _env.createString("on"));

                    // #5402
                    super.put(isUnicode ? HTTP_X_SSL_REQUEST_VU : HTTP_X_SSL_REQUEST_V,
                              _env.createString("on"));
                }

                if (pathInfo == null)
                {
                    super.put(isUnicode ? PHP_SELF_VU : PHP_SELF_V,
                              _env.createString(contextPath + servletPath));
                }
                else
                {
                    super.put(isUnicode ? PHP_SELF_VU : PHP_SELF_V,
                              _env.createString(contextPath + servletPath + pathInfo));
                }

                // authType @is not set on Tomcat
                //String authType = request.getAuthType();
                string authHeader = request.getHeader("Authorization");

                if (authHeader != null)
                {
                    if (authHeader.indexOf("Basic") == 0)
                    {
                        super.put(isUnicode ? AUTH_TYPE_VU : AUTH_TYPE_V,
                                  _env.createString("Basic"));

                        bool userNameIsSet = false;
                        if (request.getRemoteUser() != null)
                        {
                            super.put(isUnicode ? PHP_AUTH_USER_VU : PHP_AUTH_USER_V,
                                      _env.createString(request.getRemoteUser()));
                            userNameIsSet = true;
                        }
                        string digest = authHeader.substring("Basic ".length());

                        string userPass = Base64.decode(digest);

                        int i = userPass.indexOf(':');
                        if (i > 0)
                        {
                            if (!userNameIsSet)
                            {
                                super.put(isUnicode ? PHP_AUTH_USER_VU : PHP_AUTH_USER_V,
                                          _env.createString(userPass.substring(0, i)));
                            }
                            super.put(isUnicode ? PHP_AUTH_PW_VU : PHP_AUTH_PW_V,
                                      _env.createString(userPass.substring(i + 1)));
                        }
                    }
                    else if (authHeader.indexOf("Digest") == 0)
                    {
                        super.put(isUnicode ? AUTH_TYPE_VU : AUTH_TYPE_V,
                                  _env.createString("Digest"));

                        string digest = authHeader.substring("Digest ".length());

                        super.put(isUnicode ? PHP_AUTH_DIGEST_VU : PHP_AUTH_DIGEST_V,
                                  _env.createString(digest));
                    }
                }

                Enumeration e = request.getHeaderNames();
                while (e.hasMoreElements())
                {
                    string key = (String)e.nextElement();

                    string value = request.getHeader(key);

                    if (key.equalsIgnoreCase("Host"))
                    {
                        super.put(isUnicode ? HTTP_HOST_VU : HTTP_HOST_V,
                                  _env.createString(value));
                    }
                    else if (key.equalsIgnoreCase("Content-Length"))
                    {
                        super.put(isUnicode ? CONTENT_LENGTH_VU : CONTENT_LENGTH_V,
                                  _env.createString(value));
                    }
                    else if (key.equalsIgnoreCase("Content-Type"))
                    {
                        super.put(isUnicode ? CONTENT_TYPE_VU : CONTENT_TYPE_V,
                                  _env.createString(value));
                    }
                    else
                    {
                        super.put(convertHttpKey(key), _env.createString(value));
                    }
                }
            }
        }