Browse code

imc: expect the second param only if first is set

- bits of formatting for imc_handle_create()

(cherry picked from commit c08620f6427d59749396fe2762e340328ce69c41)

Daniel-Constantin Mierla authored on 05/04/2021 15:35:12
Showing 1 changed files
... ...
@@ -349,8 +349,12 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,
349 349
 
350 350
 	memset(&room, '\0', sizeof(room));
351 351
 
352
-	if (cmd->param[0].s) params++;
353
-	if (cmd->param[1].s) params++;
352
+	if (cmd->param[0].s) {
353
+		params++;
354
+		if (cmd->param[1].s) {
355
+			params++;
356
+		}
357
+	}
354 358
 
355 359
 	switch(params) {
356 360
 	case 0:
... ...
@@ -361,7 +365,9 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,
361 365
 		/* With one parameter, if the value is "private", it indicates
362 366
 		 * a private room, otherwise it is the URI of the room and we
363 367
 		 * create a public room. */
364
-		if (cmd->param[0].len == IMC_ROOM_PRIVATE_LEN && !strncasecmp(cmd->param[0].s, IMC_ROOM_PRIVATE, cmd->param[0].len)) {
368
+		if (cmd->param[0].len == IMC_ROOM_PRIVATE_LEN
369
+				&& !strncasecmp(cmd->param[0].s, IMC_ROOM_PRIVATE,
370
+					cmd->param[0].len)) {
365 371
 			ps = cmd->param[0];
366 372
 		} else {
367 373
 			rs = cmd->param[0];
... ...
@@ -384,7 +390,8 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,
384 390
 		goto error;
385 391
 
386 392
 	if (ps.s) {
387
-		if (ps.len == IMC_ROOM_PRIVATE_LEN && !strncasecmp(ps.s, IMC_ROOM_PRIVATE, ps.len)) {
393
+		if (ps.len == IMC_ROOM_PRIVATE_LEN
394
+				&& !strncasecmp(ps.s, IMC_ROOM_PRIVATE, ps.len)) {
388 395
 			flag_room |= IMC_ROOM_PRIV;
389 396
 			LM_DBG("Room with private flag on\n");
390 397
 		} else {
... ...
@@ -443,10 +450,12 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,
443 450
 		LM_ERR("Failed to add member [%.*s]\n", STR_FMT(&src->uri));
444 451
 		goto error;
445 452
 	}
446
-	LM_DBG("Added [%.*s] as member to room [%.*s]\n", STR_FMT(&member->uri), STR_FMT(&rm->uri));
453
+	LM_DBG("Added [%.*s] as member to room [%.*s]\n", STR_FMT(&member->uri),
454
+			STR_FMT(&rm->uri));
447 455
 
448 456
 	body.s = imc_body_buf;
449
-	body.len = snprintf(body.s, sizeof(imc_body_buf), msg_user_joined.s, STR_FMT(format_uri(member->uri)));
457
+	body.len = snprintf(body.s, sizeof(imc_body_buf), msg_user_joined.s,
458
+			STR_FMT(format_uri(member->uri)));
450 459
 
451 460
 	if (body.len < 0) {
452 461
 		LM_ERR("Error while building response\n");