bool TestExtFile::test_read_write() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fwrite(f, "testing read/write");
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r+");
  f_fseek(f, 8);
  f_fwrite(f, "succeeds");
  f_fseek(f, 8);
  VS(f_fread(f, 8), "succeeds");
  return Count(true);
}
Esempio n. 2
0
bool TestExtMailparse::test_mailparse_stream_encode() {
    {
        String text = "hello, this is some text=hello.";
        Variant fp = f_tmpfile();
        f_fwrite(fp, text);
        f_rewind(fp);
        Variant dest = f_tmpfile();
        f_mailparse_stream_encode(fp, dest, "quoted-printable");
        f_rewind(dest);
        Variant data = f_fread(dest, 2048);
        VS(data, "hello, this is some text=3Dhello.");
    }
    {
        String text =
            "To: [email protected]\n"
            "\n"
            "blah blah blah From blah $ \" & £ blah blah blah blah blah\n"
            "From the first of the month, things will be different!\n"
            "blah blah blah From blah\n"
            "Frome is a town in Somerset.";

        f_ob_start();

        Variant fp = f_tmpfile();
        f_fwrite(fp, text);
        f_rewind(fp);

        Variant fpdest = f_tmpfile();
        f_mailparse_stream_encode(fp, fpdest, "quoted-printable");
        f_rewind(fpdest);
        f_fpassthru(fpdest);

        f_fclose(fp);
        f_fclose(fpdest);

        String output = f_ob_get_contents();
        f_ob_end_clean();
        VS(output,
           "To: [email protected]\r\n"
           "\r\n"
           "blah blah blah From blah $ \" & =C2=A3 blah blah blah blah blah\r\n"
           "=46rom the first of the month, things will be different!\r\n"
           "blah blah blah From blah\r\n"
           "Frome is a town in Somerset.");
    }

    return Count(true);
}
Esempio n. 3
0
bool f_error_log(const String& message, int message_type /* = 0 */,
                 const String& destination /* = null_string */,
                 const String& extra_headers /* = null_string */) {
  // error_log() should not invoke the user error handler,
  // so we use Logger::Error() instead of raise_warning() or raise_error()
  switch (message_type) {
  case 0:
  {
    std::string line(message.data(),
                     // Truncate to 512k
                     message.size() > (1<<19) ? (1<<19) : message.size());
    Logger::Error(line);
    return true;
  }
  case 3:
  {
    Variant outfile = f_fopen(destination, "a"); // open for append only
    if (outfile.isNull()) {
      Logger::Error("can't open error_log file!\n");
      return false;
    }
    f_fwrite(outfile.toResource(), message);
    f_fclose(outfile.toResource());
    return true;
  }
  case 2: // not used per PHP
  default:
    Logger::Error("error_log does not support message_type %d!", message_type);
    break;
  }
  return false;
}
bool TestExtFile::test_fwrite() {
  Variant f = f_fopen("test/test_ext_file.tmp", "w");
  f_fwrite(f, "testing fwrite", 7);
  f_fclose(f);

  f = f_fopen("test/test_ext_file.tmp", "r");
  VF(f, "testing");
  return Count(true);
}
Esempio n. 5
0
bool TestExtBzip2::test_bzerror() {
  Variant f = f_fopen("test/test_ext_bzip2.tmp", "w");
  f_fwrite(f, "this is a test");
  f_fclose(f);
  f = f_bzopen("test/test_ext_bzip2.tmp", "r");
  f_bzread(f);
  Variant ret = f_bzerror(f);
  f_bzclose(f);
  f_unlink("test/test_ext_bzip2.tmp");
  VS(ret, CREATE_MAP2("errno", -5, "errstr", "DATA_ERROR_MAGIC"));
  return Count(true);
}
Esempio n. 6
0
bool TestExtZlib::test_gzencode() {
  Variant zipped = f_gzencode("testing gzencode");
  Variant f = f_fopen("test/test_ext_zlib.tmp", "w");
  f_fwrite(f, zipped);
  f_fclose(f);

  f_ob_start();
  f_readgzfile("test/test_ext_zlib.tmp");
  VS(f_ob_get_clean(), "testing gzencode");
  f_ob_end_clean();
  return Count(true);
}
Esempio n. 7
0
bool TestExtBzip2::test_bzerrstr() {
  Variant f = f_fopen("test/test_ext_bzip2.tmp", "w");
  f_fwrite(f, "this is a test");
  f_fclose(f);
  f = f_bzopen("test/test_ext_bzip2.tmp", "r");
  f_bzread(f);
  String ret = f_bzerrstr(f);
  f_bzclose(f);
  f_unlink("test/test_ext_bzip2.tmp");
  VS(ret, "DATA_ERROR_MAGIC");
  return Count(true);
}
Esempio n. 8
0
bool TestExtBzip2::test_bzerrno() {
  Variant f = f_fopen("test/test_ext_bzip2.tmp", "w");
  f_fwrite(f, "this is a test");
  f_fclose(f);
  f = f_bzopen("test/test_ext_bzip2.tmp", "r");
  f_bzread(f);
  int ret = f_bzerrno(f);
  f_bzclose(f);
  f_unlink("test/test_ext_bzip2.tmp");
  VS(ret, -5);
  return Count(true);
}
Esempio n. 9
0
int libxml_streams_IO_write(void* context, const char* buffer, int len) {
    ITRACE(1, "libxml_IO_write({}, {}, {})\n", context, (void*)buffer, len);
    Trace::Indent _i;

    Resource stream(static_cast<ResourceData*>(context));
    String strBuffer(StringData::Make(buffer, len, CopyString));
    Variant ret = f_fwrite(stream, strBuffer);
    if (ret.isInteger() && ret.asInt64Val() < INT_MAX) {
        return (int)ret.asInt64Val();
    } else {
        return -1;
    }
}
Esempio n. 10
0
bool TestExtStream::test_stream_get_contents() {
  {
    Variant f = f_fopen("test/test_ext_file.txt", "r");
    VS(f_stream_get_contents(f), "Testing Ext File\n");
  }

  {
    Variant f = f_tmpfile();

    f_fwrite(f, "fwrite1");
    f_fseek(f, 0); VS(f_stream_get_contents(f), "fwrite1");

    f_fwrite(f, "fwrite2");
    f_fseek(f, 0); VS(f_stream_get_contents(f), "fwrite1fwrite2");

    f_fwrite(f, "fwrite3");
    VS(f_stream_get_contents(f), "");

    f_fclose(f);
  }

  return Count(true);
}
Esempio n. 11
0
bool TestExtStream::test_stream_get_line() {
  {
    Variant f = f_fopen("test/test_ext_file.txt", "r");
    VS(f_stream_get_line(f), "Testing Ext File\n");
  }

  {
    Variant f = f_tmpfile();
    f_fwrite(f, "stream_get_line@test");
    f_fseek(f, 0);
    VS(f_stream_get_line(f, 300, "@"), "stream_get_line");
    VS(f_stream_get_line(f, 300, "@"), "test");
    VS(f_stream_get_line(f, 300, "@"), "");
    f_fclose(f);
  }

  return Count(true);
}
Esempio n. 12
0
bool TestExtMailparse::test_mailparse_uudecode_all() {
  static const StaticString s_filename("filename");
  String text =
    "To: [email protected]\n"
    "\n"
    "hello, this is some text hello.\n"
    "blah blah blah.\n"
    "\n"
    "begin 644 test.txt\n"
    "/=&AI<R!I<R!A('1E<W0*\n"
    "`\n"
    "end";

  f_ob_start();

  Variant fp = f_tmpfile();
  f_fwrite(fp, text);

  Variant data = f_mailparse_uudecode_all(fp);
  echo("BODY\n");
  f_readfile(data[0][s_filename]);
  echo("UUE\n");
  f_readfile(data[1][s_filename]);

  f_unlink(data[0][s_filename]);
  f_unlink(data[1][s_filename]);

  String output = f_ob_get_contents();
  f_ob_end_clean();
  VS(output,
     "BODY\n"
     "To: [email protected]\n"
     "\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "UUE\n"
     "this is a test\n");

  return Count(true);
}
Esempio n. 13
0
bool f_error_log(CStrRef message, int message_type /* = 0 */,
                 CStrRef destination /* = null_string */,
                 CStrRef extra_headers /* = null_string */) {
  // error_log() should not invoke the user error handler,
  // so we use Logger::Error() instead of raise_warning() or raise_error()
  switch (message_type) {
  case 0:
  {
    std::string line(message.data(),
                     // Truncate to 512k
                     message.size() > (1<<19) ? (1<<19) : message.size());

    Logger::Error(line);

    if (!RuntimeOption::ServerExecutionMode() &&
        Logger::UseLogFile && Logger::Output) {
      // otherwise errors will go to error log without displaying on screen
      std::cerr << line;
    }
    return true;
  }
  case 3:
  {
    Variant outfile = f_fopen(destination, "a"); // open for append only
    if (outfile.isNull()) {
      Logger::Error("can't open error_log file!\n");
      return false;
    }
    f_fwrite(outfile.toResource(), message);
    f_fclose(outfile.toResource());
    return true;
  }
  case 2: // not used per PHP
  default:
    Logger::Error("error_log does not support message_type %d!", message_type);
    break;
  }
  return false;
}
Esempio n. 14
0
bool TestExtNetwork::test_fsockopen() {
  {
    Variant f = f_fsockopen("facebook.com", 80);
    VERIFY(!same(f, false));
    f_fputs(f, "GET / HTTP/1.0\n\n");
    VERIFY(!f_fread(f, 15).toString().empty());
  }
  {
    Variant f = f_fsockopen("ssl://www.facebook.com", 443);
    VERIFY(!same(f, false));
    f_fwrite(f,
             "GET / HTTP/1.1\r\n"
             "Host: www.facebook.com\r\n"
             "Connection: Close\r\n"
             "\r\n");
    StringBuffer response;
    while (!same(f_feof(f), true)) {
      Variant line = f_fgets(f, 128);
      response.append(line.toString());
    }
    VERIFY(!response.detach().empty());
  }
  return Count(true);
}
Esempio n. 15
0
File: ext_bz2.cpp Progetto: 2bj/hhvm
Variant HHVM_FUNCTION(bzwrite, const Resource& bz, const String& data,
                               int length /* = 0 */) {
  return f_fwrite(bz, data, length);
}
Esempio n. 16
0
bool TestExtMailparse::test_mailparse_msg_extract_part() {
  String text =
    "To: [email protected]\n"
    "Mime-Version: 1.0\n"
    "Content-Type: text/plain\n"
    "Subject: A simple MIME message\n"
    "\n"
    "hello, this is some text hello.\n"
    "blah blah blah.\n";

  Variant fp = f_tmpfile();
  f_fwrite(fp, text);
  f_rewind(fp);

  f_ob_start();

  Variant mime = f_mailparse_msg_create();
  f_mailparse_msg_parse(mime, text);

  echo("Extract to output\n");
  f_mailparse_msg_extract_part_file(mime, fp);

  echo("Extract and return as string\n");
  Variant result = f_mailparse_msg_extract_part_file(mime, fp, uninit_null());
  echo("-->\n");
  echo(result);

  echo("\nExtract to open file\n");
  Variant fpdest = f_tmpfile();
  f_mailparse_msg_extract_part_file(mime, fp, fpdest);
  echo("\nrewinding\n");
  f_rewind(fpdest);
  f_fpassthru(fpdest);

  echo("\nExtract via user function\n");
  f_mailparse_msg_extract_part_file(mime, fp);

  echo("\nExtract whole part to output\n");
  f_mailparse_msg_extract_whole_part_file(mime, fp);

  echo("\nExtract part from string to output\n");
  f_mailparse_msg_extract_part(mime, text);
  f_fclose(fpdest);
  f_fclose(fp);

  String output = f_ob_get_contents();
  f_ob_end_clean();

  VS(output,
     "Extract to output\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "Extract and return as string\n"
     "-->\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "Extract to open file\n"
     "\n"
     "rewinding\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "Extract via user function\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "Extract whole part to output\n"
     "To: [email protected]\n"
     "Mime-Version: 1.0\n"
     "Content-Type: text/plain\n"
     "Subject: A simple MIME message\n"
     "\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n"
     "\n"
     "Extract part from string to output\n"
     "hello, this is some text hello.\n"
     "blah blah blah.\n");

  return Count(true);
}
Esempio n. 17
0
Variant f_bzwrite(CObjRef bz, CStrRef data, int length /* = 0 */) {
  return f_fwrite(bz, data, length);
}