예제 #1
0
파일: ast.c 프로젝트: 304471720/mongrel2
int AST_walk_hash(tst_t *settings, Value *data, ast_hash_walk_cb cb)
{
    struct ASTScanData scan = {.settings = settings, .cb = cb, .error = 0};
    tst_traverse(data->as.hash, ast_hash_traverse_cb, &scan);
    return scan.error;
}


Value *AST_get(tst_t *settings, tst_t *fr, bstring name, ValueType type)
{
    Pair *pair = tst_search(fr, bdata(name), blength(name));
    check_debug(pair, "Couldn't find variable %s of type %s", bdata(name), Value_type_name(type));

    Value *val = Pair_value(pair);

    if(Value_is(val, REF)) {
        val = Value_resolve(settings, val);
        check(val, "Couldn't find variable %s of type %s",
            bdata(name), Value_type_name(type));
    }

    check(val->type == type, "Invalid type for %s, should be %s not %s",
            bdata(name), Value_type_name(type), Value_type_name(val->type));

    return val;

error:
    return NULL;
}
예제 #2
0
파일: ast.c 프로젝트: 304471720/mongrel2
static void AST_destroy_cb(void *value, void *data)
{
    Pair *pair = (Pair *)value;

    AST_destroy_value(Pair_value(pair));
    Token_destroy(pair->key);
    free(pair);
}
예제 #3
0
파일: ast.c 프로젝트: 304471720/mongrel2
Value *Value_resolve(tst_t *settings, Value *val)
{
    if(Value_is(val, REF)) {
        Pair *pair = tst_search(settings, bdata(val->as.ref->data), blength(val->as.ref->data));
        check(pair != NULL, "Couldn't find variable named: %s", bdata(val->as.ref->data));
        return Pair_value(pair);
    } else {
        return val;
    }

error:
    return NULL;
}
예제 #4
0
파일: ast.c 프로젝트: 304471720/mongrel2
int AST_walk(tst_t *settings, ast_walk_cb cb)
{
    Pair *n = tst_search(settings, bdata(&DEFAULT_ROOT), blength(&DEFAULT_ROOT));
    check(n, "You didn't set a %s variable to say what servers you want.", 
            bdata(&DEFAULT_ROOT));

    Value *val = Pair_value(n);
    check(val->type == VAL_LIST, "servers variable should be a list of server configs to load.");

    return AST_walk_list(settings, val->as.list, cb);

error:
    return -1;
}
예제 #5
0
int Route_load(tst_t *settings, Pair *pair)
{
    const char *name = bdata(Pair_key(pair));
    char *sql = NULL;
    Value *val = Pair_value(pair);
    bstring type = NULL;
    int rc = 0;

    check(val, "Error loading route: %s", bdata(Pair_key(pair)));
    check(Value_is(val, CLASS), "Expected a Class but got a %s instead.",
            Value_type_name(val->type));
    Class *cls = val->as.cls;
    type = bstrcpy(Class_ident(cls));
    btolower(type);

    if(cls->id == -1) {
        if(biseqcstr(type, "dir")) {
            rc = Dir_load(settings, cls->params);
        } else if(biseqcstr(type, "proxy")) {
            rc = Proxy_load(settings, cls->params);
        } else if(biseqcstr(type, "handler")) {
            rc = Handler_load(settings, cls->params);
        } else {
            sentinel("Invalid type of route target: %s", bdata(Class_ident(cls)));
        }

        check(rc != -1, "Failed to create target for route %s", name);
        cls->id = rc;
    }

    sql = sqlite3_mprintf(bdata(&ROUTE_SQL), name, HOST_ID, cls->id, bdata(type));

    rc = DB_exec(sql, NULL, NULL);
    check(rc == 0, "Failed to intialize route.");

    sqlite3_free(sql);
    bdestroy(type);
    return 0;

error:
    if(sql) sqlite3_free(sql);
    bdestroy(type);
    return -1;
}
예제 #6
0
int Mimetypes_load(tst_t *settings, Pair *pair)
{
    const char *ext = bdata(Pair_key(pair));
    Value *val = Pair_value(pair);
    check(val, "Error loading Mimetype %s", bdata(Pair_key(pair)));

    char *sql = NULL;
    
    sql = sqlite3_mprintf(bdata(&MIMETYPE_SQL),
            ext, ext, bdata(val->as.string->data));

    int rc = DB_exec(sql, NULL, NULL);
    check(rc == 0, "Failed to add mimetype: %s=%s", 
            ext, bdata(val->as.string->data));

    sqlite3_free(sql);
    return 0;

error:
    if(sql) sqlite3_free(sql);
    return -1;
}
예제 #7
0
int Settings_load(tst_t *settings, Pair *pair)
{
    const char *name = bdata(Pair_key(pair));
    Value *val = Pair_value(pair);
    check(val, "Error loading Setting %s", bdata(Pair_key(pair)));

    char *sql = NULL;
    
    sql = sqlite3_mprintf(bdata(&SETTING_SQL),
            name, bdata(val->as.string->data));

    int rc = DB_exec(sql, NULL, NULL);
    check(rc == 0, "Failed to add setting: %s=%s",
            name, bdata(val->as.string->data));

    sqlite3_free(sql);
    return 0;

error:
    if(sql) sqlite3_free(sql);
    return -1;
}