From 326fcc467c057bd17045b28f43fde4d185c11809 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Sat, 16 May 2009 12:32:48 +0200 Subject: [PATCH] Moved the update_user_info code into user_update_info --- autotest/test_message.tcc | 4 +--- src/inf.c | 39 +-------------------------------------- src/user.c | 36 ++++++++++++++++++++++++++++++++++++ src/user.h | 9 +++++++++ 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/autotest/test_message.tcc b/autotest/test_message.tcc index 7cc8d76..b56d4ce 100644 --- a/autotest/test_message.tcc +++ b/autotest/test_message.tcc @@ -512,10 +512,8 @@ EXO_TEST(adc_message_update_3, { return updater2 != NULL; }); -extern void update_user_info(struct hub_info* hub, struct user* u, struct adc_message* cmd); - EXO_TEST(adc_message_update_4, { - update_user_info(g_user->hub, g_user, updater2); + user_update_info(g_user, updater2); return strlen(g_user->info->cache) == 159; }); diff --git a/src/inf.c b/src/inf.c index 592cda0..1b032ca 100644 --- a/src/inf.c +++ b/src/inf.c @@ -626,43 +626,6 @@ static int user_is_registered(struct user* user) } -void update_user_info(struct hub_info* hub, struct user* u, struct adc_message* cmd) -{ - char prefix[2]; - char* argument; - size_t n = 0; - struct adc_message* cmd_new = adc_msg_copy(u->info); - if (!cmd_new) - { - /* FIXME: OOM! */ - return; - } - - /* - * FIXME: Optimization potential: - * - * remove parts of cmd that do not really change anything in cmd_new. - * this can save bandwidth if clients send multiple updates for information - * that does not really change anything. - */ - argument = adc_msg_get_argument(cmd, n++); - while (argument) - { - if (strlen(argument) >= 2) - { - prefix[0] = argument[0]; - prefix[1] = argument[1]; - adc_msg_replace_named_argument(cmd_new, prefix, argument+2); - } - - hub_free(argument); - argument = adc_msg_get_argument(cmd, n++); - } - user_set_info(u, cmd_new); - adc_msg_free(cmd_new); -} - - static int check_is_hub_full(struct hub_info* hub, struct user* user) { /* @@ -853,7 +816,7 @@ int hub_handle_info(struct hub_info* hub, struct user* user, const struct adc_me strip_network(user, cmd); hub_handle_info_low_bandwidth(hub, user, cmd); - update_user_info(hub, user, cmd); + user_update_info(user, cmd); if (!adc_msg_is_empty(cmd)) { diff --git a/src/user.c b/src/user.c index 3197c04..fa9b505 100644 --- a/src/user.c +++ b/src/user.c @@ -115,6 +115,42 @@ void user_set_info(struct user* user, struct adc_message* cmd) user->info = adc_msg_incref(cmd); } +void user_update_info(struct user* u, struct adc_message* cmd) +{ + char prefix[2]; + char* argument; + size_t n = 0; + struct adc_message* cmd_new = adc_msg_copy(u->info); + if (!cmd_new) + { + /* FIXME: OOM! */ + return; + } + + /* + * FIXME: Optimization potential: + * + * remove parts of cmd that do not really change anything in cmd_new. + * this can save bandwidth if clients send multiple updates for information + * that does not really change anything. + */ + argument = adc_msg_get_argument(cmd, n++); + while (argument) + { + if (strlen(argument) >= 2) + { + prefix[0] = argument[0]; + prefix[1] = argument[1]; + adc_msg_replace_named_argument(cmd_new, prefix, argument+2); + } + + hub_free(argument); + argument = adc_msg_get_argument(cmd, n++); + } + user_set_info(u, cmd_new); + adc_msg_free(cmd_new); +} + static int convert_support_fourcc(int fourcc) { diff --git a/src/user.h b/src/user.h index 1c97185..2b7da8e 100644 --- a/src/user.h +++ b/src/user.h @@ -171,9 +171,18 @@ extern void user_disconnect(struct user* user, int reason); * This associates a INF message to the user. * If the user already has a INF message associated, then this is * released before setting the new one. + * + * @param info new inf message (can be NULL) */ extern void user_set_info(struct user* user, struct adc_message* info); +/** + * Update a user's INF message. + * Will parse replace all ellements in the user's inf message with + * the parameters from the cmd (merge operation). + */ +extern void user_update_info(struct user* user, struct adc_message* cmd); + /** * Specify a user's state. * NOTE: DON'T, unless you know what you are doing.