From 37684729283f62fd7f1e74bc2b318dc9ad2cb695 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Fri, 17 Jan 2025 12:12:01 -0500 Subject: Account for dependency changes, platform testing Signed-off-by: Andrew Opalach --- src/server/common.h | 4 ++-- src/server/db.c | 34 +++++++++++++++++++++------------- src/server/server.c | 35 ++++++++++++++++++----------------- 3 files changed, 41 insertions(+), 32 deletions(-) (limited to 'src/server') diff --git a/src/server/common.h b/src/server/common.h index 9948c02..80afb9b 100644 --- a/src/server/common.h +++ b/src/server/common.h @@ -56,8 +56,8 @@ AL_UNUSED_FUNCTION_PUSH static bool camu_is_url(str *s, u32 i) { - return al_str_cmp(s, al_str_c("https://"), i, 8) == 0 - || al_str_cmp(s, al_str_c("http://"), i, 7) == 0; + return al_str_cmp(s, &al_str_c("https://"), i, 8) == 0 + || al_str_cmp(s, &al_str_c("http://"), i, 7) == 0; } AL_UNUSED_FUNCTION_POP diff --git a/src/server/db.c b/src/server/db.c index ce4c99e..4cc449e 100644 --- a/src/server/db.c +++ b/src/server/db.c @@ -4,28 +4,34 @@ #include "server.h" -static bool open_user(struct camu_server *server, struct nn_dir_entry *dir) +// This is still nothing. + +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, &dir->path, 0)) { - return false; + if (!nn_file_open(&file, &path, 0)) { + goto out; } str s; nn_file_read_as_str(&file, &s); json_error_t error; - json_t *root = json_loadb(s.data, s.len, 0, &error); + json_t *root = json_loadb(s.data, s.length, 0, &error); if (!root) { al_log_error("server", "Failed to parse %.*s:%d:%d (%s).", - AL_STR_PRINTF(&dir->path), error.line, error.column, error.text); - return false; + al_str_fmt(&path), error.line, error.column, error.text); + al_str_free(&s); + 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"))); - al_log_info("server", "Loaded user \"%.*s\"", AL_STR_PRINTF(&user->name)); + al_log_info("server", "Loaded user \"%.*s\"", al_str_fmt(&user->name)); al_array_push(server->users, user); json_decref(root); al_str_free(&s); - return true; +out: + al_str_free(&path); } bool camu_db_open(struct camu_server *server, str *path) @@ -36,20 +42,22 @@ bool camu_db_open(struct camu_server *server, str *path) } struct nn_dir_entry entry; while (nn_dir_read(&camu_db, &entry)) { - if (al_str_eq(&entry.name, al_str_c("users"))) { + if (al_str_eq(&al_str_cr(nn_dir_entry_get_os_name(&entry)), &al_str_c("users"))) { struct nn_dir users; - if (nn_dir_open(&users, &entry.path)) { + 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, &user); + open_user(server, &camu_db, &user); } - nn_dir_entry_free(&user); } nn_dir_close(&users); } + al_str_free(&users_path); + break; } - nn_dir_entry_free(&entry); } nn_dir_close(&camu_db); return true; diff --git a/src/server/server.c b/src/server/server.c index e949ee1..bdc1f96 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -58,7 +58,7 @@ static void write_user_state(struct camu_server *server, struct camu_user *user, { (void)user; #ifdef CAMU_HAVE_PORTAL - nn_packet_write_u32(packet, server->bridge.searches.size); + nn_packet_write_u32(packet, server->bridge.searches.count); struct camu_search *search; al_array_foreach(server->bridge.searches, i, search) { nn_packet_write_s32(packet, search->id); @@ -99,7 +99,7 @@ static bool identify_callback(void *userdata, struct nn_rpc_connection *conn, } client->user = user; al_array_push(server->clients, client); - al_log_info("server", "User \"%.*s\" logged in.", AL_STR_PRINTF(&user->name)); + al_log_info("server", "User \"%.*s\" logged in.", al_str_fmt(&user->name)); write_user_state(server, user, rpacket); break; } @@ -111,7 +111,7 @@ static bool identify_callback(void *userdata, struct nn_rpc_connection *conn, al_str_clone(&sink->name, &name); sink->server = server; al_array_push(server->sinks, sink); - handle_toggle_sink(server, al_str_c("default"), sink, true); + handle_toggle_sink(server, &al_str_c("default"), sink, true); al_log_info("server", "New sink."); break; } @@ -187,7 +187,7 @@ static void process_pending(struct camu_resource *resource) array(struct lia_list_entry *) pending; // resource->pending may be edited during a list_pump() call. al_array_clone(pending, resource->pending); - resource->pending.size = 0; + resource->pending.count = 0; struct lia_list_entry *entry; al_array_foreach(pending, i, entry) { lia_list_pump(entry->list); @@ -270,12 +270,12 @@ static void client_portal_callback(void *userdata0, void *userdata1, struct camu case CAMU_CLIENT_GET_PAGE: { struct camu_result_page *page = result->page; nn_packet_write_u32(packet, page->num); - nn_packet_write_u32(packet, page->posts.size); + nn_packet_write_u32(packet, page->posts.count); struct camu_post *post; al_array_foreach_ptr(page->posts, i, post) { nn_packet_write_post(packet, post); } - nn_packet_write_u32(packet, page->list.size); + nn_packet_write_u32(packet, page->list.count); str *unique_id; al_array_foreach_ptr(page->list, i, unique_id) { nn_packet_write_str(packet, unique_id); @@ -346,14 +346,14 @@ out: static struct cch_entry *entry_from_post(struct camu_server *server, struct camu_post *post, u32 index) { struct cch_entry *entry = NULL; - if (index <= post->media.size) { + if (index <= post->media.count) { struct camu_post_media *media = &al_array_at(post->media, index); if (!al_str_is_empty(&media->url)) { entry = cch_handler_http_create(&media->url, server->loop); } } if (!entry) { - al_log_warn("server", "Failed to load resource %.*s %u.", AL_STR_PRINTF(&post->unique_id), index); + al_log_warn("server", "Failed to load resource %.*s %u.", al_str_fmt(&post->unique_id), index); return NULL; } entry->handler->maybe_spawn_worker(entry->handler, 0); @@ -371,7 +371,7 @@ static void simple_search_portal_callback(void *userdata0, void *userdata1, stru return; } case CAMU_CLIENT_GET_PAGE: { - if (!result->page || al_array_is_empty(result->page->list)) break; + if (!result->page || !result->page->list.count) break; struct camu_post *post = camu_post_cache_get(&server->cache, &al_array_at(result->page->list, 0)); if (!post) break; struct cch_entry *entry = entry_from_post(server, post, 0); @@ -436,9 +436,10 @@ static void handle_add_command(struct camu_server *server, struct lia_list *list str url; nn_packet_read_str(packet, &url); u32 track = 0; - if (url.len > 7) { - s64 index = al_str_to_long(al_str_substr(&url, 7, url.len), 10); - if (index > 0 && index <= entry->chapters.size) + if (url.length > 7) { + bool error; + s64 index = al_str_to_long(&al_str_substr(&url, 7, url.length), 10, &error); + if (!error && index <= entry->chapters.count) track = (u32)index - 1; } entry->chapter = &al_array_at(entry->chapters, track); @@ -479,12 +480,12 @@ static void handle_add_command(struct camu_server *server, struct lia_list *list resource->load = LIANA_ENTRY_PREPARING; str query; if (al_str_at(&search, 0) == ';') { // search. - al_str_clone(&query, al_str_substr(&search, 1, search.len)); + al_str_clone(&query, &al_str_substr(&search, 1, search.length)); } else { al_str_from(&query, "link:"); al_str_cat(&query, &search); } - camu_portal_create_search(&server->bridge, al_str_c("youtube"), &query, simple_search_portal_callback, portal); + camu_portal_create_search(&server->bridge, &al_str_c("youtube"), &query, simple_search_portal_callback, portal); al_str_free(&query); break; } @@ -615,7 +616,7 @@ static void connection_closed_callback(void *userdata, struct nn_rpc_connection struct camu_server_client *client; al_array_foreach(server->clients, i, client) { if (client->conn == conn) { - al_log_info("server", "User \"%.*s\" logged out.", AL_STR_PRINTF(&client->user->name)); + al_log_info("server", "User \"%.*s\" logged out.", al_str_fmt(&client->user->name)); cleanup_client(client); al_array_remove_at(server->clients, i); break; @@ -656,7 +657,7 @@ static bool multiplex_callback(void *userdata, u8 id, struct nn_packet_stream *s void camu_server_init(struct camu_server *server, struct nn_event_loop *loop) { server->loop = loop; - server->addr = al_str_zero(); + server->addr = al_str_null(); al_array_init(server->nodes); al_array_init(server->clients); al_array_init(server->sinks); @@ -664,7 +665,7 @@ void camu_server_init(struct camu_server *server, struct nn_event_loop *loop) al_array_init(server->lists); struct lia_list *list = al_alloc_object(struct lia_list); - lia_list_init(list, al_str_c("default")); + lia_list_init(list, &al_str_c("default")); list->callback = list_callback; list->userdata = server; al_array_push(server->lists, list); -- cgit v1.2.3-101-g0448