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; }
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; }