Esempio n. 1
0
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);
        });
Esempio n. 2
0
File: cli.c Progetto: Hmaal/slash
static sl_vm_t*
setup_vm(void* stack_top)
{
    sl_static_init();
    sl_vm_t* vm = sl_init("cli");
    sl_gc_set_stack_top(vm->arena, stack_top);
    setup_vm_request(vm);
    setup_vm_response(vm);
    return vm;
}
Esempio n. 3
0
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, {});
Esempio n. 4
0
static void
handle_request(slash_context_t* ctx, void* dummy)
{
    sl_catch_frame_t frame;
    SLVAL err;
    char* script_filename = "";
    sl_vm_t* vm = sl_init();
    pthread_t me = ctx->thread;
    ctx->vm = vm;
    ctx->vm->data = ctx;
    ctx->sent_headers = 0;
    sl_gc_set_stack_top(ctx->vm->arena, dummy);
    
    setup_request_object(ctx->vm, &ctx->request, &script_filename);
    setup_response_object(ctx->vm);
    SL_TRY(frame, SL_UNWIND_ALL, {
        sl_do_file(ctx->vm, (uint8_t*)script_filename);
    }, err, {