Exemple #1
0
  private static void put(ArrayValue array, Value key, Value value, boolean addSlashes) {
    if (addSlashes && value.isString()) {
      value = StringModule.addslashes(value.toStringValue());
    }

    if (key == null) array.put(value);
    else array.put(key, value);
  }
Exemple #2
0
  /** Converts to an array. */
  @Override
  public ArrayValue toArray() {
    ArrayValue array = new ArrayValueImpl();

    for (Map.Entry<Value, Value> entry : entrySet()) {
      array.put(entry.getKey(), entry.getValue());
    }

    return array;
  }
Exemple #3
0
  public Value receive(Env env, @Optional("1") long timeout) throws JMSException {
    Message message = _consumer.receive(timeout);

    if (message == null) return BooleanValue.FALSE;

    if (message instanceof ObjectMessage) {
      Object object = ((ObjectMessage) message).getObject();

      return env.wrapJava(object);
    } else if (message instanceof TextMessage) {
      return env.createString(((TextMessage) message).getText());
    } else if (message instanceof StreamMessage) {
      Object object = ((StreamMessage) message).readObject();

      return env.wrapJava(object);
    } else if (message instanceof BytesMessage) {
      BytesMessage bytesMessage = (BytesMessage) message;
      int length = (int) bytesMessage.getBodyLength();

      StringValue bb = env.createBinaryBuilder(length);

      TempBuffer tempBuffer = TempBuffer.allocate();
      int sublen;

      while (true) {
        sublen = bytesMessage.readBytes(tempBuffer.getBuffer());

        if (sublen > 0) bb.append(tempBuffer.getBuffer(), 0, sublen);
        else break;
      }

      TempBuffer.free(tempBuffer);

      return bb;
    } else if (message instanceof MapMessage) {
      MapMessage mapMessage = (MapMessage) message;

      Enumeration mapNames = mapMessage.getMapNames();

      ArrayValue array = new ArrayValueImpl();

      while (mapNames.hasMoreElements()) {
        String name = mapNames.nextElement().toString();

        Object object = mapMessage.getObject(name);

        array.put(env.createString(name), env.wrapJava(object));
      }

      return array;
    } else {
      return BooleanValue.FALSE;
    }
  }
Exemple #4
0
  private static void addFormFile(
      Env env,
      ArrayValue files,
      String fileName,
      String tmpName,
      String mimeType,
      long fileLength,
      boolean addSlashesToValues,
      long maxFileSize) {
    ArrayValue entry = new ArrayValueImpl();
    int error;

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

    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);

    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);

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

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

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

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

    addFormValue(env, files, null, entry, null, addSlashesToValues);
  }
Exemple #5
0
  /**
   * @param env the PHP executing environment
   * @return array of fieldDirect objects
   */
  public Value getFieldDirectArray(Env env) {
    ArrayValue array = new ArrayValueImpl();

    try {
      int numColumns = getMetaData().getColumnCount();

      for (int i = 0; i < numColumns; i++) {
        array.put(fetchFieldDirect(env, i));
      }

      return array;
    } catch (SQLException e) {
      log.log(Level.FINE, e.toString(), e);
      return BooleanValue.FALSE;
    }
  }
Exemple #6
0
  public static void addFormValue(
      Env env,
      ArrayValue array,
      String key,
      Value formValue,
      String[] formValueList,
      boolean addSlashesToValues) {
    int p = -1;
    int q = -1;

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

    if (p >= 0 && p < q) {
      String index = key;

      Value keyValue;
      Value existingValue;

      if (p > 0) {
        key = key.substring(0, p);

        key = key.replaceAll("\\.", "_");

        keyValue = env.createString(key);
        existingValue = array.get(keyValue);

        if (existingValue == null || !existingValue.isset()) {
          existingValue = new ArrayValueImpl();
          array.put(keyValue, existingValue);
        } else if (!existingValue.isArray()) {
          // existing is overwritten
          // php/115g

          existingValue = new ArrayValueImpl();
          array.put(keyValue, existingValue);
        }

        array = (ArrayValue) existingValue;
      }

      int p1;
      while ((p1 = index.indexOf('[', q)) > 0) {
        key = index.substring(p + 1, q);

        if (key.equals("")) {
          existingValue = new ArrayValueImpl();
          array.put(existingValue);
        } else {
          keyValue = env.createString(key);
          existingValue = array.get(keyValue);

          if (existingValue == null || !existingValue.isset()) {
            existingValue = new ArrayValueImpl();
            array.put(keyValue, existingValue);
          } else if (!existingValue.isArray()) {
            existingValue = new ArrayValueImpl().put(existingValue);
            array.put(keyValue, existingValue);
          }
        }

        array = (ArrayValue) existingValue;

        p = p1;
        q = index.indexOf(']', p);
      }

      if (q > 0) index = index.substring(p + 1, q);
      else index = index.substring(p + 1);

      if (index.equals("")) {
        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' <= index.charAt(0) && index.charAt(0) <= '9')
        put(array, LongValue.create(StringValue.toLong(index)), formValue, addSlashesToValues);
      else put(array, env.createString(index), formValue, addSlashesToValues);
    } else {
      if (key != null) {
        key = key.replaceAll("\\.", "_");
        put(array, env.createString(key), formValue, addSlashesToValues);
      } else {
        put(array, null, formValue, addSlashesToValues);
      }
    }
  }
Exemple #7
0
  private static void addFormFile(
      Env env,
      ArrayValue files,
      String name,
      String fileName,
      String tmpName,
      String mimeType,
      long fileLength,
      boolean addSlashesToValues,
      long maxFileSize) {
    int p = name.indexOf('[');
    String index = "";
    if (p >= 0) {
      index = name.substring(p);
      name = name.substring(0, p);
    }

    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);

    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);

    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);
    }

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

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

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

    addFormValue(env, files, name, entry, null, addSlashesToValues);
  }