Changeset 5d2bc9d
- Timestamp:
- 2013-08-01T18:17:02Z (11 years ago)
- Branches:
- master
- Children:
- 352a6b0
- Parents:
- 81265e0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
otr.c
r81265e0 r5d2bc9d 79 79 80 80 const char *op_account_name(void *opdata, const char *account, const char *protocol); 81 82 void op_convert_msg(void *opdata, ConnContext *ctx, OtrlConvertType typ, 83 char **dst, const char *src); 84 void op_convert_free(void *opdata, ConnContext *ctx, char *msg); 81 85 82 86 … … 229 233 otr_ops.handle_msg_event = NULL; // XXX 230 234 otr_ops.create_instag = NULL; // XXX 231 otr_ops.convert_msg = NULL; // XXX other plugins? de/htmlize? 235 otr_ops.convert_msg = &op_convert_msg; 236 otr_ops.convert_free = &op_convert_free; 232 237 otr_ops.timer_control = NULL; // XXX call otrl_message_poll reg'ly 233 238 … … 406 411 return msg; 407 412 } else { 408 /* XXX move this to convert callback */409 410 /* OTR has processed this message */411 ConnContext *context = otrl_context_find(irc->otr->us, iu->bu->handle,412 ic->acc->user, ic->acc->prpl->name, OTRL_INSTAG_MASTER, 0, NULL, NULL, NULL);413 414 413 /* we're done with the original msg, which will be caller-freed. */ 415 /* NB: must not change the newmsg pointer, since we free it. */ 416 msg = newmsg; 417 418 if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) { 419 /* HTML decoding */ 420 /* perform any necessary stripping that the top level would miss */ 421 if(set_getbool(&ic->bee->set, "otr_does_html") && 422 !(ic->flags & OPT_DOES_HTML) && 423 set_getbool(&ic->bee->set, "strip_html")) { 424 strip_html(msg); 425 } 426 427 /* coloring */ 428 if(set_getbool(&ic->bee->set, "otr_color_encrypted")) { 429 int color; /* color according to f'print trust */ 430 char *pre="", *sep=""; /* optional parts */ 431 const char *trust = context->active_fingerprint->trust; 432 433 if(trust && trust[0] != '\0') 434 color=3; /* green */ 435 else 436 color=5; /* red */ 437 438 /* in a query window, keep "/me " uncolored at the beginning */ 439 if(g_strncasecmp(msg, "/me ", 4) == 0 440 && irc_user_msgdest(iu) == irc->user->nick) { 441 msg += 4; /* skip */ 442 pre = "/me "; 443 } 444 445 /* comma in first place could mess with the color code */ 446 if(msg[0] == ',') { 447 /* insert a space between color spec and message */ 448 sep = " "; 449 } 450 451 msg = g_strdup_printf("%s\x03%.2d%s%s\x0F", pre, 452 color, sep, msg); 453 } 454 } 455 456 if(msg == newmsg) { 457 msg = g_strdup(newmsg); 458 } 459 otrl_message_free(newmsg); 460 return msg; 414 return newmsg; 461 415 } 462 416 } … … 477 431 } 478 432 479 ctx = otrl_context_find(irc->otr->us,480 iu->bu->handle, ic->acc->user, ic->acc->prpl->name,481 instag, 1, NULL, NULL, NULL);482 483 /* HTML encoding */484 /* consider OTR plaintext to be HTML if otr_does_html is set */485 if(ctx && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED &&486 set_getbool(&ic->bee->set, "otr_does_html") &&487 (g_strncasecmp(msg, "<html>", 6) != 0)) {488 emsg = escape_html(msg);489 }490 491 433 st = otrl_message_sending(irc->otr->us, &otr_ops, ic, 492 434 ic->acc->user, ic->acc->prpl->name, iu->bu->handle, instag, 493 emsg, NULL, &otrmsg, OTRL_FRAGMENT_SEND_SKIP, NULL, NULL, NULL); 435 emsg, NULL, &otrmsg, OTRL_FRAGMENT_SEND_ALL, &ctx, NULL, NULL); 436 494 437 if(emsg != msg) { 495 438 g_free(emsg); /* we're done with this one */ 496 439 } 440 if(otrmsg) { 441 /* Is this ever reached!? */ 442 ic->acc->prpl->buddy_msg(ic, iu->bu->handle, otrmsg, 0); 443 } 497 444 if(st) { 498 return NULL; 499 } 500 501 if(otrmsg) { 502 if(!ctx) { 503 otrl_message_free(otrmsg); 504 return NULL; 505 } 506 otr_ops.inject_message(ic, ctx->accountname, 507 ctx->protocol, ctx->username, otrmsg); 508 otrl_message_free(otrmsg); 509 } else { 510 /* note: otrl_message_sending handles policy, so that if REQUIRE_ENCRYPTION is set, 511 this case does not occur */ 512 return msg; 513 } 514 515 /* TODO: Error reporting should be done here now (if st!=0), probably. */ 445 /* TODO: Error reporting? */ 446 } 516 447 517 448 return NULL; … … 766 697 return peernick(irc, account, protocol); 767 698 } 699 700 void op_convert_msg(void *opdata, ConnContext *ctx, OtrlConvertType typ, 701 char **dst, const char *src) 702 { 703 struct im_connection *ic = 704 check_imc(opdata, ctx->accountname, ctx->protocol); 705 irc_t *irc = ic->bee->ui_data; 706 irc_user_t *iu = peeruser(irc, ctx->username, ctx->protocol); 707 708 if(typ == OTRL_CONVERT_RECEIVING) { 709 char *msg = g_strdup(src); 710 711 /* HTML decoding */ 712 if(set_getbool(&ic->bee->set, "otr_does_html") && 713 !(ic->flags & OPT_DOES_HTML) && 714 set_getbool(&ic->bee->set, "strip_html")) { 715 strip_html(msg); 716 *dst = msg; 717 } 718 719 /* coloring */ 720 if(set_getbool(&ic->bee->set, "otr_color_encrypted")) { 721 int color; /* color according to f'print trust */ 722 char *pre="", *sep=""; /* optional parts */ 723 const char *trust = ctx->active_fingerprint->trust; 724 725 if(trust && trust[0] != '\0') 726 color=3; /* green */ 727 else 728 color=5; /* red */ 729 730 /* in a query window, keep "/me " uncolored at the beginning */ 731 if(g_strncasecmp(msg, "/me ", 4) == 0 732 && irc_user_msgdest(iu) == irc->user->nick) { 733 msg += 4; /* skip */ 734 pre = "/me "; 735 } 736 737 /* comma in first place could mess with the color code */ 738 if(msg[0] == ',') { 739 /* insert a space between color spec and message */ 740 sep = " "; 741 } 742 743 *dst = g_strdup_printf("%s\x03%.2d%s%s\x0F", pre, 744 color, sep, msg); 745 g_free(msg); 746 } 747 } else { 748 /* HTML encoding */ 749 /* consider OTR plaintext to be HTML if otr_does_html is set */ 750 if(ctx && ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED && 751 set_getbool(&ic->bee->set, "otr_does_html") && 752 (g_strncasecmp(src, "<html>", 6) != 0)) { 753 *dst = escape_html(src); 754 } 755 } 756 } 757 758 void op_convert_free(void *opdata, ConnContext *ctx, char *msg) 759 { 760 g_free(msg); 761 } 762 768 763 769 764
Note: See TracChangeset
for help on using the changeset viewer.