Moved the update_user_info code into user_update_info
This commit is contained in:
parent
078470ce64
commit
326fcc467c
|
@ -512,10 +512,8 @@ EXO_TEST(adc_message_update_3, {
|
||||||
return updater2 != NULL;
|
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, {
|
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;
|
return strlen(g_user->info->cache) == 159;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
39
src/inf.c
39
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)
|
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);
|
strip_network(user, cmd);
|
||||||
hub_handle_info_low_bandwidth(hub, 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))
|
if (!adc_msg_is_empty(cmd))
|
||||||
{
|
{
|
||||||
|
|
36
src/user.c
36
src/user.c
|
@ -115,6 +115,42 @@ void user_set_info(struct user* user, struct adc_message* cmd)
|
||||||
user->info = adc_msg_incref(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)
|
static int convert_support_fourcc(int fourcc)
|
||||||
{
|
{
|
||||||
|
|
|
@ -171,9 +171,18 @@ extern void user_disconnect(struct user* user, int reason);
|
||||||
* This associates a INF message to the user.
|
* This associates a INF message to the user.
|
||||||
* If the user already has a INF message associated, then this is
|
* If the user already has a INF message associated, then this is
|
||||||
* released before setting the new one.
|
* 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);
|
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.
|
* Specify a user's state.
|
||||||
* NOTE: DON'T, unless you know what you are doing.
|
* NOTE: DON'T, unless you know what you are doing.
|
||||||
|
|
Loading…
Reference in New Issue