comparison nnchat.c @ 225:801ac37321f6

Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 01 Dec 2010 01:12:43 +0200
parents 03af28fb1c38
children f25d47398326
comparison
equal deleted inserted replaced
224:7ae0719f7763 225:801ac37321f6
402 errorMessages = tmp2; 402 errorMessages = tmp2;
403 } else 403 } else
404 errorMessages = tmp; 404 errorMessages = tmp;
405 } 405 }
406 406
407
408 BOOL checkIgnoreList(const char *name)
409 {
410 qlist_t *node = nnIgnoreList;
411 while (node != NULL) {
412 if (strcasecmp(name, (char *) node->data) == 0)
413 return TRUE;
414 node = node->next;
415 }
416 return FALSE;
417 }
418
419
407 int handleUser(nn_conn_t *conn, const char *str) 420 int handleUser(nn_conn_t *conn, const char *str)
408 { 421 {
409 const char *msg = "</USER><MESSAGE>", *p = str; 422 const char *msg = "</USER><MESSAGE>", *p = str;
410 char *q, *s, *t, *h, *p2; 423 BOOL isMine, isIgnored = FALSE;;
424 char *q, *s, *t, *h, *userName;
411 425
412 (void) conn; 426 (void) conn;
413 427
414 s = strstr(str, msg); 428 s = strstr(str, msg);
415 if (!s) return 1; 429 if (!s) return 1;
421 *q = 0; 435 *q = 0;
422 436
423 s = nn_decode_str1(s); 437 s = nn_decode_str1(s);
424 if (!s) return -1; 438 if (!s) return -1;
425 439
426 p2 = nn_decode_str1(p); 440 userName = nn_decode_str1(p);
427 if (!p2) { 441 if (!userName) {
428 th_free(s); 442 th_free(s);
429 return -2; 443 return -2;
430 } 444 }
431 445
446 isMine = strcmp(userName, optUserName) == 0;
447 if (setIgnoreMode && !isMine)
448 isIgnored = checkIgnoreList(userName);
432 449
433 if (*s == '/') { 450 if (*s == '/') {
434 /* Ignore room join/leave messages */ 451 /* Ignore room join/leave messages */
435 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from"))) 452 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from")))
436 goto error; 453 goto error;
437 454
438 t = nn_strip_tags(s + 1); 455 t = nn_strip_tags(s + 1);
439 if (!strncmp(t, "BPRV", 4)) { 456 if (!strncmp(t, "BPRV", 4)) {
440 h = nn_decode_str2(t + 1); 457 h = nn_decode_str2(t + 1);
441 if (setTarget == NULL && !strncmp(h, "PRV from ", 9)) { 458 if (!isIgnored && setTarget == NULL && !strncmp(h, "PRV from ", 9)) {
442 char *end, *name = th_strdup(h + 9); 459 setTarget = th_strdup(userName);
443 if (name != NULL && (end = strchr(name, ':')) != NULL) { 460 printMsg("PRV target autoset to '%s'\n", setTarget);
444 *end = 0;
445 setTarget = th_strdup(name);
446 printMsg("PRV target autoset to '%s'\n", setTarget);
447 }
448 th_free(name);
449 } 461 }
450 printMsg("½11½%s½0½\n", h); 462 printMsgQ(isIgnored, "½11½%s½0½\n", h);
451 } else { 463 } else {
452 h = nn_decode_str2(t); 464 h = nn_decode_str2(t);
453 printMsg("½9½* %s½0½\n", h); 465 printMsgQ(isIgnored, "½9½* %s½0½\n", h);
454 } 466 }
455 th_free(h); 467 th_free(h);
456 th_free(t); 468 th_free(t);
457 } else { 469 } else {
458 BOOL isMine = strcmp(p2, optUserName) == 0;
459 BOOL logOnly = FALSE;
460 t = nn_strip_tags(s); 470 t = nn_strip_tags(s);
461 h = nn_decode_str2(t); 471 h = nn_decode_str2(t);
462 if (setIgnoreMode) { 472 printMsgQ(isIgnored, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, userName, h);
463 qlist_t *node = nnIgnoreList;
464 while (node != NULL) {
465 if (strcasecmp(p2, (char *) node->data) == 0) {
466 logOnly = TRUE;
467 break;
468 }
469 node = node->next;
470 }
471 }
472 printMsgQ(logOnly, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p2, h);
473 th_free(h); 473 th_free(h);
474 th_free(t); 474 th_free(t);
475 } 475 }
476 476
477 error: 477 error:
478 th_free(s); 478 th_free(s);
479 th_free(p2); 479 th_free(userName);
480 return 0; 480 return 0;
481 } 481 }
482 482
483 483
484 int handleLogin(nn_conn_t *conn, const char *str) 484 int handleLogin(nn_conn_t *conn, const char *str)