Example #1
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);
  }
Example #2
0
  static void fillPost(
      Env env,
      ArrayValue postArray,
      ArrayValue files,
      InputStream is,
      String contentType,
      String encoding,
      int contentLength,
      boolean addSlashesToValues,
      boolean isAllowUploads) {
    long maxPostSize = env.getIniBytes("post_max_size", 0);

    try {
      if (encoding == null) encoding = env.getHttpInputEncoding();

      if (contentType != null && contentType.startsWith("multipart/form-data")) {

        String boundary = getBoundary(contentType);

        ReadStream rs = new ReadStream(new VfsStream(is, null));

        if (boundary == null) {
          env.warning(L.l("multipart/form-data POST is missing boundary"));

          return;
        }

        MultipartStream ms = new MultipartStream(rs, boundary);

        if (encoding != null) ms.setEncoding(encoding);

        readMultipartStream(env, ms, postArray, files, addSlashesToValues, isAllowUploads);

        rs.close();

        if (rs.getLength() > maxPostSize) {
          env.warning(
              L.l("POST length of {0} exceeds max size of {1}", rs.getLength(), maxPostSize));

          postArray.clear();
          files.clear();

          return;
        }
      } else {
        StringValue bb = env.createBinaryBuilder();

        bb.appendReadAll(is, Integer.MAX_VALUE);

        if (bb.length() > maxPostSize) {
          env.warning(L.l("POST length of {0} exceeds max size of {1}", bb.length(), maxPostSize));
          return;
        }

        env.setInputData(bb);

        if (contentType != null && contentType.startsWith("application/x-www-form-urlencoded"))
          StringUtility.parseStr(env, bb, postArray, false, encoding);
      }

    } catch (IOException e) {
      env.warning(e);
    } finally {
    }
  }
Example #3
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);
  }