Moved the update_user_info code into user_update_info

This commit is contained in:
Jan Vidar Krey 2009-05-16 12:32:48 +02:00
parent 078470ce64
commit 326fcc467c
4 changed files with 47 additions and 41 deletions

View File

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

View File

@ -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))
{

View File

@ -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)
{

View File

@ -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.