Exemplo n.º 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;
    }
}
Exemplo n.º 2
0
static void uploader_child_init_server(apr_pool_t *pool, server_rec *s)
{
    UploaderConfig **configs;
    UploaderConfig *config;

    configs = (UploaderConfig **)AVOID_ALIGN_WARN uploader_config_array->elts;

    for (int i = 0; i < uploader_config_array->nelts; i++) {
        config = configs[i];

        try {
            config->child_init();
        } catch(const char *message) {
            logger.error(__FILE__, __LINE__, s,
                         "(%s) %s: %s", "UploaderConfig::child_init", message,
                         get_last_error_message(pool));
        }
    }
}
Exemplo n.º 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;
    }
}