コード例 #1
0
ファイル: mod_slash.c プロジェクト: Hmaal/slash
static void
setup_request_object(sl_vm_t* vm, request_rec* r)
{
    struct iter_args ia;
    
    sl_request_opts_t opts;
    opts.method       = (char*)r->method;
    opts.uri          = r->uri;
    opts.path_info    = r->path_info;
    opts.query_string = r->args;
    opts.remote_addr  = r->connection->remote_ip;
    opts.content_type = (char*)apr_table_get(r->headers_in, "content-type");
    
    ia.count = 0;
    ia.capacity = 4;
    ia.kvs = sl_alloc(vm->arena, sizeof(sl_request_key_value_t) * ia.capacity);
    ia.vm = vm;
    apr_table_do(iterate_apr_table, &ia, r->headers_in, NULL);
    opts.header_count = ia.count;
    opts.headers = ia.kvs;
    
    ap_add_common_vars(r);
    ap_add_cgi_vars(r);
    ia.count = 0;
    ia.capacity = 4;
    ia.kvs = sl_alloc(vm->arena, sizeof(sl_request_key_value_t) * ia.capacity);
    ia.vm = vm;
    apr_table_do(iterate_apr_table, &ia, r->subprocess_env, NULL);
    opts.env_count = ia.count;
    opts.env = ia.kvs;
    
    read_post_data(vm, &opts, r);
    
    sl_request_set_opts(vm, &opts);
}
コード例 #2
0
ファイル: cgi.c プロジェクト: PatrickFang/slash
static bool
setup_request_object(sl_vm_t* vm, slash_request_info_t* info)
{
    bool result = true;
    sl_request_opts_t opts;

    opts.method       =
        info->request_method ? info->request_method->value : "GET";

    opts.uri          = info->real_uri ? info->real_uri : "";
    opts.path_info    = info->real_path_info ? info->real_path_info : "";
    opts.query_string = info->query_string ? info->query_string->value : "";
    opts.remote_addr  = info->remote_addr ? info->remote_addr->value : "";
    opts.content_type = info->content_type ? info->content_type->value : NULL;

    opts.header_count = info->http_headers->count;
    opts.headers      = info->http_headers->kvs;
    
    opts.env_count    = info->environment->count;
    opts.env          = info->environment->kvs;
    
    result = read_post_data(vm, &opts, info);

    sl_request_set_opts(vm, &opts);

    return result;
}
コード例 #3
0
ファイル: slash-fcgi.c プロジェクト: tinkertim/slash
static void
setup_request_object(sl_vm_t* vm, FCGX_Request* request, char** script_filename)
{
    sl_request_opts_t opts;
    size_t i, j, env_i = 0, header_i = 0;
    char* value;
    opts.method = "GET";
    opts.uri = "";
    opts.path_info = NULL;
    opts.query_string = NULL;
    opts.remote_addr = "";
    for(i = 0; request->envp[i]; i++) {
        env_i++;
    }
    opts.env = sl_alloc(vm->arena, sizeof(sl_request_key_value_t) * env_i);
    opts.headers = sl_alloc(vm->arena, sizeof(sl_request_key_value_t) * env_i);
    env_i = 0;
    for(i = 0; request->envp[i]; i++) {
        value = strchr(request->envp[i], '=');
        if(!value) {
            continue;
        }
        *value++ = 0;
        opts.env[env_i].name = request->envp[i];
        opts.env[env_i].value = value;
        env_i++;
        if(memcmp(request->envp[i], "HTTP_", 5) == 0) {
            opts.headers[header_i].name = sl_alloc(vm->arena, strlen(request->envp[i]));
            for(j = 0; request->envp[i][j + 5]; j++) {
                if(request->envp[i][j + 5] == '_') {
                    opts.headers[header_i].name[j] = '-';
                } else {
                    if(request->envp[i][j + 5 - 1] == '_') {
                        opts.headers[header_i].name[j] = request->envp[i][j + 5];
                    } else {
                        opts.headers[header_i].name[j] = tolower(request->envp[i][j + 5]);
                    }
                }
            }
            opts.headers[header_i].value = value;
            header_i++;
        }
        if(strcmp(request->envp[i], "REQUEST_METHOD") == 0)  { opts.method       = value; }
        if(strcmp(request->envp[i], "REQUEST_URI") == 0)     { opts.uri          = value; }
        if(strcmp(request->envp[i], "PATH_INFO") == 0)       { opts.path_info    = value; }
        if(strcmp(request->envp[i], "QUERY_STRING") == 0)    { opts.query_string = value; }
        if(strcmp(request->envp[i], "REMOTE_ADDR") == 0)     { opts.remote_addr  = value; }
        if(strcmp(request->envp[i], "CONTENT_TYPE") == 0)    { opts.content_type = value; }
        if(strcmp(request->envp[i], "SCRIPT_FILENAME") == 0) { *script_filename  = value; }
    }
    opts.header_count = header_i;
    opts.env_count    = env_i;
    opts.post_data    = "";
    opts.post_length  = 0;
    sl_request_set_opts(vm, &opts);
}
コード例 #4
0
ファイル: cli.c プロジェクト: Hmaal/slash
static void
setup_vm_request(sl_vm_t* vm)
{
    char** orig_env = sl_environ(vm);

    sl_request_opts_t req;
    req.method          = "";
    req.uri             = "";
    req.path_info       = "";
    req.query_string    = "";
    req.remote_addr     = "";
    req.content_type    = "";

    req.header_count    = 0;
    req.post_length     = 0;

    req.env_count = 0;
    for(char** env = orig_env; *env; env++) {
        req.env_count++;
    }

    sl_request_key_value_t env[req.env_count];
    for(size_t i = 0; i < req.env_count; i++) {
        char* e = sl_alloc(vm->arena, strlen(orig_env[i]) + 1);
        strcpy(e, orig_env[i]);
        char* v = strchr(e, '=');
        if(!v) {
            continue;
        }
        *v = 0;
        env[i].name = e;
        env[i].value = v + 1;
    }

    req.env = env;
    sl_request_set_opts(vm, &req);
}