コード例 #1
0
ファイル: mod_slash.c プロジェクト: Hmaal/slash
static int
run_slash_script(request_rec* r, void* stack_top)
{
    sl_vm_t* vm;
    slash_context_t ctx;
    sl_vm_frame_t exit_frame, exception_frame;
    char* last_slash;
    SLVAL error;
    sl_static_init();
    vm = sl_init("apache2");
    sl_gc_set_stack_top(vm->arena, stack_top);
    vm->cwd = sl_alloc_buffer(vm->arena, strlen(r->canonical_filename) + 10);
    strcpy(vm->cwd, r->canonical_filename);
    last_slash = strrchr(vm->cwd, '/');
    if(last_slash) {
        *last_slash = 0;
    }
    SL_TRY(exit_frame, SL_UNWIND_ALL, {
        SL_TRY(exception_frame, SL_UNWIND_EXCEPTION, {
            ctx.headers_sent = 0;
            ctx.vm = vm;
            ctx.r = r;
            vm->data = &ctx;
            setup_request_object(vm, r);
            setup_response_object(vm);
            ap_set_content_type(r, "text/html; charset=utf-8");
            sl_do_file(vm, r->canonical_filename);
        }, error, {
            sl_response_clear(vm);
            sl_render_error_page(vm, error);
        });
コード例 #2
0
ファイル: cgi.c プロジェクト: PatrickFang/slash
static void
run_slash_script(slash_api_base_t* api, cgi_options* options, void* stack_top)
{
    sl_vm_t* vm;
    slash_context_t ctx;
    sl_vm_frame_t exit_frame, exception_frame;
    char* canonical_filename;
    SLVAL error;

    sl_static_init();
    vm = sl_init("cgi-fcgi");

    bzero(&ctx, sizeof(ctx));
    ctx.api = api;
    ctx.headers_sent = 0;
    ctx.vm = vm;
    vm->data = &ctx;

    sl_gc_set_stack_top(vm->arena, stack_top);

    load_cgi_options(vm, options);
    load_request_info(vm, options, api, &ctx.info);

#ifdef SL_TEST
    register_cgi_test_utils(vm);
#endif

    canonical_filename = ctx.info.real_canonical_filename;
#ifndef SL_TEST
    vm->cwd = ctx.info.real_canonical_dir;
#endif

    if(canonical_filename) {
        SL_TRY(exit_frame, SL_UNWIND_ALL, {
            SL_TRY(exception_frame, SL_UNWIND_EXCEPTION, {
                bool request_valid = setup_request_object(vm, &ctx.info);

                setup_response_object(vm);

                if(!request_valid) {
                    sl_error(vm, vm->lib.Error, "Invalid Request");
                }

                sl_do_file_hashbang(vm, canonical_filename,
                    api->type == SLASH_REQUEST_CGI);
            }, error, {
                sl_response_clear(vm);
                sl_render_error_page(vm, error);
            });
        }, error, {});