#define AL_LOG_SECTION "db" #include #include #include "server.h" #if 0 // This is still nothing. #include static void open_user(struct camu_server *server, struct nn_dir *camu_db, struct nn_dir_entry *dir) { str path; nn_dir_entry_get_path(dir, camu_db, &path); struct nn_file file; if (!nn_file_open(&file, &path, 0)) { goto out; } str buffer; nn_file_read_as_str(&file, &buffer); json_error_t error; json_t *root = json_loadb(buffer.data, buffer.length, 0, &error); al_str_free(&buffer); if (!root) { log_error("Failed to parse %.*s:%d:%d (%s).", al_str_x(&path), error.line, error.column, error.text); goto out; } struct camu_user *user = al_alloc_object(struct camu_user); al_str_from(&user->name, json_string_value(json_object_get(root, "username"))); log_info("Loaded user \"%.*s\"", al_str_x(&user->name)); al_array_push(server->users, user); json_decref(root); out: al_str_free(&path); } #endif static void open_user(struct camu_server *server, struct nn_dir *camu_db, struct nn_dir_entry *dir) { (void)server; (void)camu_db; (void)dir; } bool camu_db_open(struct camu_server *server, str *path) { struct nn_dir camu_db; if (!nn_dir_open(&camu_db, path)) { return false; } struct nn_dir_entry entry; while (nn_dir_read(&camu_db, &entry)) { if (al_str_eq(&al_str_cr(nn_dir_entry_get_os_name(&entry)), &al_str_c("users"))) { struct nn_dir users; str users_path; nn_dir_entry_get_path(&entry, &camu_db, &users_path); if (nn_dir_open(&users, &users_path)) { struct nn_dir_entry user; while (nn_dir_read(&users, &user)) { if (user.type == NNWT_ENTRY_FILE) { open_user(server, &camu_db, &user); } } nn_dir_close(&users); } al_str_free(&users_path); break; } } nn_dir_close(&camu_db); return true; } void camu_db_close(struct camu_server *server) { (void)server; }