Exemple #1
0
        public int read(char [] buffer, int offset, int length)
        {
            // XXX: should be reimplemented

            Value output;

            if (_env.isUnicodeSemantics())
            {
                output = _wrapper.callMethod(_env, STREAM_READ_U,
                                             LongValue.create(length));
            }
            else
            {
                output = _wrapper.callMethod(_env, STREAM_READ,
                                             LongValue.create(length));
            }

            if (output.length() == 0)
            {
                return(-1);
            }

            byte [] outputBytes = output.ToString().getBytes();

            if (outputBytes.length < length)
            {
                length = outputBytes.length;
            }

            System.arraycopy(outputBytes, 0, buffer, offset, length);

            return(length);
        }
 /**
  * Add an unsupported ini default for an ini that has a long value.
  */
 public IniDefinition addUnsupported(String name, long deflt, int scope)
 {
     return(addUnsupported(name,
                           IniDefinition.Type.LONG,
                           LongValue.create(deflt),
                           scope));
 }
        public void writeTo(Env env, OutputStream os)

        {
            long length = _length;

            long totalWritten = 0;

            LongValue lengthV = LongValue.create(length);

            while (totalWritten < length)
            {
                StringValue str
                    = _callback.call(env, _curl, _fileV, lengthV).ToStringValue(env);

                int count = str.length();

                if (count == 0)
                {
                    break;
                }

                str.writeTo(os);

                totalWritten += count;
            }
        }
 public Value unmarshal(Env env, Object value)
 {
   if (value == null)
     return LongValue.ZERO;
   else
     return LongValue.create(((Number) value).longValue());
 }
Exemple #5
0
        /**
         * Prepares this statement with the given query.
         *
         * @param query SQL query
         * @return true on success or false on failure
         */
        public override bool prepare(Env env, string query)
        {
            string queryStr = query.ToString();

            _preparedMapping.clear();

            // Map any unsorted or duplicated params.
            // Ex: INSERT INTO test VALUES($2, $1) or
            //     INSERT INTO test VALUES($1, $1)
            Pattern pattern = Pattern.compile("\\$([0-9]+)");
            Matcher matcher = pattern.matcher(queryStr);

            while (matcher.find())
            {
                int phpParam;
                try {
                    phpParam = Integer.parseInt(matcher.group(1));
                } catch (Exception ex) {
                    _preparedMapping.clear();
                    return(false);
                }
                _preparedMapping.add(LongValue.create(phpParam));
            }

            // Make the PHP query a JDBC like query
            // replacing ($1 -> ?) with question marks.
            // XXX: replace this with Matcher.appendReplacement
            // above when StringBuilder @is supported.
            queryStr = queryStr.replaceAll("\\$[0-9]+", "?");

            // Prepare the JDBC query
            return(super.prepare(env, queryStr));
        }
        public int execute(Env env, Value stillRunning)
        {
            if (_runningCount == 0)
            {
                stillRunning.set(LongValue.ZERO);

                return(CurlModule.CURLM_OK);
            }
            else if (_runningCount < 0)
            {
                _runningCount = _curlList.size();

                for (CurlResource curl : _curlList)
                {
                    curl.execute(env, false);

                    _msgQueue.add(curl);
                }
            }

            _runningCount--;

            stillRunning.set(LongValue.create(_runningCount));

            if (_runningCount == 0)
            {
                return(CurlModule.CURLM_OK);
            }
            else
            {
                return(CurlModule.CURLM_CALL_MULTI_PERFORM);
            }
        }
Exemple #7
0
        /**
         * Returns the error code for xml parser
         */
        public Value xml_get_error_code(Xml parser)
        {
            if (parser == null)
            {
                return(BooleanValue.FALSE);
            }

            return(LongValue.create(parser.getErrorCode()));
        }
Exemple #8
0
        /**
         * Returns the parser's byte
         */
        public Value xml_get_current_byte_index(Xml parser)
        {
            if (parser == null)
            {
                return(BooleanValue.FALSE);
            }

            return(LongValue.create(parser.getByteIndex()));
        }
        /**
         * Returns the file's uncompressed size.
         *
         * @return false if zipEntry @is null
         */
        public Value zip_entry_filesize(@NotNull QuercusZipEntry entry)
        {
            if (entry == null)
            {
                return(BooleanValue.FALSE);
            }

            return(LongValue.create(entry.zip_entry_filesize()));
        }
Exemple #10
0
        /**
         * Returns the parser's column
         */
        public Value xml_get_current_column_number(Xml parser)
        {
            if (parser == null)
            {
                return(BooleanValue.FALSE);
            }

            return(LongValue.create(parser.getColumn()));
        }
        /**
         * Returns the error code from the last operation.
         *
         * @param env
         * @param curl
         */
        public static Value curl_errno(Env env,
                                       @NotNull CurlResource curl)
        {
            if (curl == null)
            {
                return(BooleanValue.FALSE);
            }

            return(LongValue.create(curl.getErrorCode()));
        }
        public Value mhash_get_block_size(int hash)
        {
            MhashAlgorithm algorithm = _algorithmMap.get(hash);

            if (algorithm == null || algorithm.createMessageDigest() == null)
            {
                return(BooleanValue.FALSE);
            }

            return(LongValue.create(512)); // XXX: stubbed
        }
 public Value unmarshal(Env env, Object value)
 {
     if (value == null)
     {
         return(LongValue.ZERO);
     }
     else
     {
         return(LongValue.create(((Number)value).longValue()));
     }
 }
Exemple #14
0
            public void write(int b)

            {
                if (_env.isUnicodeSemantics())
                {
                    _wrapper.callMethod(_env, STREAM_WRITE_U, LongValue.create(b));
                }
                else
                {
                    _wrapper.callMethod(_env, STREAM_WRITE, LongValue.create(b));
                }
            }
        public ListHeadExpr(ArrayList <Expr> varList)
        {
            _varList = new Expr[varList.size()];
            varList.toArray(_varList);

            _keyList = new Value[varList.size()];

            for (int i = 0; i < varList.size(); i++)
            {
                _keyList[i] = LongValue.create(i);
            }
        }
        public static Value func_num_args(Env env)
        {
            Value [] args = env.getFunctionArgs();

            if (args != null && args.length > 0)
            {
                return(LongValue.create(args.length));
            }
            else
            {
                return(LongValue.ZERO);
            }
        }
Exemple #17
0
        /**
         * Sets the position.
         */
        public bool setPosition(long offset)
        {
            LongValue offsetValue = LongValue.create(offset);
            LongValue whenceValue = LongValue.create(SEEK_SET);

            if (_env.isUnicodeSemantics())
            {
                return(_wrapper.callMethod(_env, STREAM_SEEK_U,
                                           offsetValue, whenceValue).toBoolean());
            }
            else
            {
                return(_wrapper.callMethod(_env, STREAM_SEEK,
                                           offsetValue, whenceValue).toBoolean());
            }
        }
Exemple #18
0
        public long seek(long offset, int whence)
        {
            LongValue offsetValue = LongValue.create(offset);
            LongValue whenceValue = LongValue.create(whence);

            if (_env.isUnicodeSemantics())
            {
                return(_wrapper.callMethod(_env, STREAM_SEEK_U,
                                           offsetValue, whenceValue).toLong());
            }
            else
            {
                return(_wrapper.callMethod(_env, STREAM_SEEK,
                                           offsetValue, whenceValue).toLong());
            }
        }
Exemple #19
0
        /**
         * Reads a Binary string.
         */
        public StringValue read(int length)

        {
            Value output;

            if (_env.isUnicodeSemantics())
            {
                output = _wrapper.callMethod(_env, STREAM_READ_U,
                                             LongValue.create(length));
            }
            else
            {
                output = _wrapper.callMethod(_env, STREAM_READ,
                                             LongValue.create(length));
            }

            return(output.toBinaryValue(_env));
        }
        public Value readInfo(Env env, Value msgsInQueue)
        {
            if (_msgQueue.size() == 0)
            {
                return(BooleanValue.FALSE);
            }

            StringValue msgStr    = env.createString("msg");
            StringValue resultStr = env.createString("result");
            StringValue handleStr = env.createString("handle");

            CurlResource curl = _msgQueue.remove(0);

            ArrayValue array = new ArrayValueImpl();

            array.put(msgStr, LongValue.create(CurlModule.CURLMSG_DONE));
            array.put(resultStr, LongValue.create(CurlModule.CURLE_OK));
            array.put(handleStr, curl);

            msgsInQueue.set(LongValue.create(_msgQueue.size()));

            return(array);
        }
Exemple #21
0
        /**
         * Parses the string.
         */
        public static ArrayValue token_get_all(Env env, StringValue s)
        {
            ArrayValue result = new ArrayValueImpl();

            Token lexer = new Token(env, s);
            int   token;

            while ((token = lexer.nextToken()) >= 0)
            {
                if (0x20 <= token && token <= 0x7f)
                {
                    result.put(env.createString((char)token));
                }
                else
                {
                    result.put(new ArrayValueImpl()
                               .append(LongValue.create(token))
                               .append(lexer.getLexeme()));
                }
            }

            return(result);
        }
        /**
         * Returns an object with the following fields: name, table, max_length,
         * not_null, primary_key, multiple_key, numeric,
         * blob, type, unsigned, zerofill.
         * <p/>
         * NOTE: does not have a field for unique_key.
         *
         * @param env the PHP executing environment
         * @param maxLength the field maximum length
         * @param tableName the field table name
         * @param type the field type
         * @return the next field in the result set or
         * false if no information @is available
         */
        public Value fetchField(Env env,
                                int maxLength,
                                string tableName,
                                string type)
        {
            if (_rs == null)
            {
                return(BooleanValue.FALSE);
            }

            ObjectValue result = env.createObject();

            try {
                if (!_isValid)
                {
                    _isValid = true;
                    _rs.next();
                }

                result.putField(env, "name", env.createString(_rs.getString(1)));
                result.putField(env, "table", env.createString(tableName));
                result.putField(env, "max_length", LongValue.create(maxLength));

                if (!isInResultString(4, "YES"))
                {
                    result.putField(env, "not_null", LongValue.ONE);
                }
                else
                {
                    result.putField(env, "not_null", LongValue.ZERO);
                }

                if (isInResultString(5, "PRI"))
                {
                    result.putField(env, "primary_key", LongValue.ONE);
                }
                else
                {
                    result.putField(env, "primary_key", LongValue.ZERO);
                }

                if (isInResultString(5, "MUL"))
                {
                    result.putField(env, "multiple_key", LongValue.ONE);
                }
                else
                {
                    result.putField(env, "multiple_key", LongValue.ZERO);
                }

                if (isInResultString(2, "int") || isInResultString(2, "real"))
                {
                    result.putField(env, "numeric", LongValue.ONE);
                }
                else
                {
                    result.putField(env, "numeric", LongValue.ZERO);
                }

                if (isInResultString(2, "blob"))
                {
                    result.putField(env, "blob", LongValue.ONE);
                }
                else
                {
                    result.putField(env, "blob", LongValue.ZERO);
                }

                result.putField(env, "type", env.createString(type));

                if (isInResultString(2, "unsigned"))
                {
                    result.putField(env, "unsigned", LongValue.ONE);
                }
                else
                {
                    result.putField(env, "unsigned", LongValue.ZERO);
                }

                if (isInResultString(2, "zerofill"))
                {
                    result.putField(env, "zerofill", LongValue.ONE);
                }
                else
                {
                    result.putField(env, "zerofill", LongValue.ZERO);
                }

                return(result);
            }
            catch (SQLException e) {
                log.log(Level.FINE, e.ToString(), e);
                return(BooleanValue.FALSE);
            }
        }
Exemple #23
0
        /**
         * Returns cache information.
         */
        public Value apc_cache_info(Env env,
                                    @Optional string type,
                                    @Optional bool limited)
        {
            ArrayValue value = new ArrayValueImpl();

            if (_cache != null)
            {
                value.put("num_slots", _cache.getCapacity());
                value.put("ttl", 0);
                value.put("num_hits", _cache.getHitCount());
                value.put("num_misses", _cache.getMissCount());
                value.put("start_time", 0);
            }
            else
            {
                value.put("num_slots", 0);
                value.put("ttl", 0);
                value.put("num_hits", 0);
                value.put("num_misses", 0);
                value.put("start_time", 0);
            }

            ArrayValueImpl cacheList = new ArrayValueImpl();

            value.put(env.createString("cache_list"), cacheList);

            if ("user".equals(type) && _cache != null && !limited)
            {
                ArrayList <String> keys   = new ArrayList <String>();
                ArrayList <Entry>  values = new ArrayList <Entry>();

                synchronized(_cache)
                {
                    Iterator <LruCache.Entry <String, Entry> > iter = _cache.iterator();

                    while (iter.hasNext())
                    {
                        LruCache.Entry <String, Entry> lruEntry = iter.next();

                        keys.add(lruEntry.getKey());
                        values.add(lruEntry.getValue());
                    }
                }

                for (int i = 0; i < keys.size(); i++)
                {
                    string key        = keys.get(i);
                    Entry  entryValue = values.get(i);

                    if (entryValue.isValid(env))
                    {
                        ArrayValueImpl array = new ArrayValueImpl();
                        cacheList.put(array);

                        array.put(env.createString("info"), env.createString(key));
                        array.put(env.createString("ttl"),
                                  LongValue.create(entryValue.getTTL(env)));
                        array.put(env.createString("type"), env.createString("user"));
                        array.put(env.createString("num_hits"),
                                  LongValue.create(entryValue.getHitCount()));
                    }
                }
            }

            return(value);
        }
Exemple #24
0
        /**
         * Transfer data to the server.
         */
        protected void transfer(Env env)

        {
            super.transfer(env);

            CurlHttpConnection conn = getHttpConnection();
            OutputStream       @out = conn.getOutputStream();

            CurlResource curl = getCurlResource();

            try {
                BinaryInput in = curl.getUploadFile();
                long length = curl.getUploadFileSize();

                long totalWritten = 0;

                if (curl.getReadCallback() != null)
                {
                    Callable callback = curl.getReadCallback();

                    Value     fileV   = env.wrapJava(in);
                    LongValue lengthV = LongValue.create(length);

                    while (totalWritten < length)
                    {
                        StringValue str
                            = callback.call(env, fileV, lengthV).ToStringValue(env);

                        int count = str.length();

                        if (count == 0)
                        {
                            break;
                        }

                        str.writeTo(out);

                        totalWritten += count;
                    }
                }
                else
                {
                    byte [] buffer = new byte[1024 * 4];

                    while (totalWritten < length)
                    {
                        int count = in.read(buffer, 0, buffer.length);

                        if (count < 0)
                        {
                            break;
                        }

                        @out.write(buffer, 0, count);

                        totalWritten += count;
                    }
                }
            }
            finally {
                @out.close();
            }
        }
 /**
  * Evaluates the expression.
  *
  * @param env the calling environment.
  *
  * @return the expression value.
  */
 public Value eval(Env env)
 {
     return(LongValue.create(_expr.evalLong(env)));
 }
 public override Value key(Env env)
 {
     return(LongValue.create(_iterCount));
 }
 protected static void addConstant(Map <StringValue, Value> map,
                                   string name, long value)
 {
     map.put(new ConstStringValue(name), LongValue.create(value));
 }
Exemple #28
0
 public override Value toValue(Env env, string encoding)
 {
     return(LongValue.create(_index));
 }
Exemple #29
0
 public LiteralLongExpr(Location location, long value)
 {
     super(location);
     _value    = value;
     _objValue = LongValue.create(_value);
 }
Exemple #30
0
 public StreamBucket(Env env, BinaryValue data)
 {
     putField(env, "data", data);
     putField(env, "datalen", LongValue.create(data.length()));
 }