示例#1
0
int main(int argc, const char * const *argv)
{
    apr_pool_t *pool;
    UploaderConfig *config;
    int status;

    apr_app_initialize(&argc, &argv, NULL);
    apr_pool_create(&pool, NULL);

    config = NULL;
    status = 0;
    try {
        config = UploaderConfigReader::read(pool, CONF_FILE_NAME);
        config->child_init();

        // ベンチマーク用
        bench_count = atoi(getenv("UPLOADER_BENCH"));
        if (bench_count == 0) {
            bench_count++;
        }

        STRACE_MARKER();
        for (apr_size_t i = 0; i < bench_count; i++) {
            TemporaryPool temp_pool(pool);
            CGIResponse::Handle handle(temp_pool.get());

            status = uploader_command_handler<CGIResponse>
                (&handle, config, arg);
        }
        STRACE_MARKER();

        config->finalize();
        apr_pool_destroy(pool);
        apr_terminate();

        return status;
    } catch(const char *message) {
        std::cout << "Fatal Error: " << message << std::endl;

        if (config != NULL) {
            config->finalize();
        }
        apr_pool_destroy(pool);
        apr_terminate();

        return EXIT_FAILURE;
    }
}
示例#2
0
void UploadItemReader::read(apr_size_t item_id, UploadItem *uitem)
{
    const char *uitem_file_path;
    apr_mmap_t *uitem_file_map;
    apr_size_t version;

    TemporaryPool temp_pool(pool_);
    uitem_file_path = get_data_path(temp_pool.get(), item_id);
    File uitem_file(temp_pool.get(), uitem_file_path);

    version = read_and_check(&uitem_file, &uitem_file_map);
    switch (version) {
    case 3:
        memcpy(uitem, uitem_file_map->mm, sizeof(UploadItem::header_t));
        break;
    case 2:
        // フォーマット変換
        UploadItem::header_t *header;
        UploadItem::header_ver2x_t *header_ver2x;

        header = AS_UITEM_H(uitem);
        header_ver2x = AS_UITEM_H_VER2x(uitem_file_map->mm);

        new(header) UploadItem::header_t;
        header->id             = header_ver2x->id;
        header->index          = header_ver2x->index;
        header->download_count = header_ver2x->download_count;
        header->flags          = header_ver2x->flags;
        header->file_size      = header_ver2x->file_size;
        header->mtime          = header_ver2x->mtime;
        strncpy(header->date, header_ver2x->date, ITM_MAX_DATE_SIZE);
        strncpy(header->ip_address, header_ver2x->ip_address, ITM_MAX_IP_ADDRESS_SIZE);
        strncpy(header->file_name, header_ver2x->file_name, ITM_MAX_FILE_NAME_SIZE);
        strncpy(header->file_mime, header_ver2x->file_mime, ITM_MAX_FILE_MIME_SIZE);
        strncpy(header->file_ext, header_ver2x->file_ext, ITM_MAX_FILE_EXT_SIZE);
        strncpy(header->file_digest, header_ver2x->file_digest, ITM_MAX_FILE_DIGEST_SIZE);
        strncpy(header->remove_pass, header_ver2x->remove_pass, ITM_MAX_REMOVE_PASS_SIZE);
        strncpy(header->download_pass, header_ver2x->download_pass, ITM_MAX_DOWNLOAD_PASS_SIZE);
        strncpy(header->comment, header_ver2x->comment, ITM_MAX_COMMENT_SIZE);
        break;
    default:
        THROW(MESSAGE_BUG_FOUND);
    }
}
示例#3
0
int main(int argc, const char * const *argv)
{
    apr_pool_t *pool;
    const char *arg;
    UploaderConfig *config;
    int status;
    apr_size_t bench_count;

    apr_app_initialize(&argc, &argv, NULL);
    apr_pool_create(&pool, NULL);

    config = NULL;
    status = 0;
    try {
        arg = getenv("PATH_INFO");
        if (arg == NULL) {
            std::cout << "Location: http://";
            std::cout << CGIResponse::get_env(pool, "SERVER_NAME");

            if ((strcmp(CGIResponse::get_env(pool, "SERVER_PORT"),
                        "80") != 0)) {
                std::cout << ":" << CGIResponse::get_env(pool, "SERVER_PORT");
            }

            std::cout << CGIResponse::get_env(pool, "SCRIPT_NAME") << "/\r\n\r\n";
            return EXIT_SUCCESS;
        }

        config = CGIConfigReader::read(pool, CONF_FILE_NAME);
        config->child_init();

        // ベンチマーク用
        bench_count = atoi(getenv("UPLOADER_BENCH"));
        if (bench_count == 0) {
            bench_count++;
        }

        STRACE_MARKER();
        for (apr_size_t i = 0; i < bench_count; i++) {
            TemporaryPool temp_pool(pool);
            CGIResponse::Handle handle(temp_pool.get());

            status = uploader_command_handler<CGIResponse>
                (&handle, config, arg);
        }
        STRACE_MARKER();

        config->finalize();
        apr_pool_destroy(pool);
        apr_terminate();

        return status;
    } catch(const char *message) {
        // できれば Internal Server Error にしたいけど,問い合わせが多
        // くなりそうなので...
        std::cout << "Content-type: text/html; charset=UTF-8\r\n\r\n";
        std::cout << "Fatal Error: " << message << std::endl;

        if (config != NULL) {
            config->finalize();
        }
        apr_pool_destroy(pool);
        apr_terminate();

        return EXIT_FAILURE;
    }
}