Skip to content

Commit

Permalink
imc: expect the second param only if first is set
Browse files Browse the repository at this point in the history
- bits of formatting for imc_handle_create()
  • Loading branch information
miconda committed Apr 5, 2021
1 parent ef31c82 commit c08620f
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/modules/imc/imc_cmd.c
Expand Up @@ -349,8 +349,12 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,

memset(&room, '\0', sizeof(room));

if (cmd->param[0].s) params++;
if (cmd->param[1].s) params++;
if (cmd->param[0].s) {
params++;
if (cmd->param[1].s) {
params++;
}
}

switch(params) {
case 0:
Expand All @@ -361,7 +365,9 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,
/* With one parameter, if the value is "private", it indicates
* a private room, otherwise it is the URI of the room and we
* create a public room. */
if (cmd->param[0].len == IMC_ROOM_PRIVATE_LEN && !strncasecmp(cmd->param[0].s, IMC_ROOM_PRIVATE, cmd->param[0].len)) {
if (cmd->param[0].len == IMC_ROOM_PRIVATE_LEN
&& !strncasecmp(cmd->param[0].s, IMC_ROOM_PRIVATE,
cmd->param[0].len)) {
ps = cmd->param[0];
} else {
rs = cmd->param[0];
Expand All @@ -384,7 +390,8 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,
goto error;

if (ps.s) {
if (ps.len == IMC_ROOM_PRIVATE_LEN && !strncasecmp(ps.s, IMC_ROOM_PRIVATE, ps.len)) {
if (ps.len == IMC_ROOM_PRIVATE_LEN
&& !strncasecmp(ps.s, IMC_ROOM_PRIVATE, ps.len)) {
flag_room |= IMC_ROOM_PRIV;
LM_DBG("Room with private flag on\n");
} else {
Expand Down Expand Up @@ -443,10 +450,12 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,
LM_ERR("Failed to add member [%.*s]\n", STR_FMT(&src->uri));
goto error;
}
LM_DBG("Added [%.*s] as member to room [%.*s]\n", STR_FMT(&member->uri), STR_FMT(&rm->uri));
LM_DBG("Added [%.*s] as member to room [%.*s]\n", STR_FMT(&member->uri),
STR_FMT(&rm->uri));

body.s = imc_body_buf;
body.len = snprintf(body.s, sizeof(imc_body_buf), msg_user_joined.s, STR_FMT(format_uri(member->uri)));
body.len = snprintf(body.s, sizeof(imc_body_buf), msg_user_joined.s,
STR_FMT(format_uri(member->uri)));

if (body.len < 0) {
LM_ERR("Error while building response\n");
Expand Down

0 comments on commit c08620f

Please sign in to comment.