Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/otr.c @ 2213:0c78d31c753d
Change otr_send() prototype
This patch updates otr_send() in order to differenciate original and
encrypted messages.
It should also fix a memory leak of OTR-encrypted messages.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 05 Nov 2015 19:46:09 +0100 |
parents | 9fb1ccf291cc |
children | ba1a770dd632 |
comparison
equal
deleted
inserted
replaced
2212:778280b01bcb | 2213:0c78d31c753d |
---|---|
596 return 1; | 596 return 1; |
597 } | 597 } |
598 return 0; | 598 return 0; |
599 } | 599 } |
600 | 600 |
601 int otr_send(char **msg, const char *buddy) | 601 char *otr_send(const char *msg, const char *buddy, int *encryption_status) |
602 { | 602 { |
603 gcry_error_t err; | 603 gcry_error_t err; |
604 char *newmessage = NULL; | 604 char *newmessage = NULL; |
605 char *htmlmsg; | 605 char *htmlmsg, *rmsg; |
606 ConnContext *ctx = otr_get_context(buddy); | 606 ConnContext *ctx = otr_get_context(buddy); |
607 | |
608 *encryption_status = 0; | |
609 | |
610 if (!msg || !buddy || !encryption_status) | |
611 return NULL; | |
607 | 612 |
608 if (ctx->msgstate == OTRL_MSGSTATE_PLAINTEXT) | 613 if (ctx->msgstate == OTRL_MSGSTATE_PLAINTEXT) |
609 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, | 614 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, |
610 #ifdef HAVE_LIBOTR3 | 615 #ifdef HAVE_LIBOTR3 |
611 ctx->protocol, ctx->username, *msg, NULL, | 616 ctx->protocol, ctx->username, msg, NULL, |
612 &newmessage, NULL, NULL); | 617 &newmessage, NULL, NULL); |
613 #else | 618 #else |
614 // INSTAG XXX | 619 // INSTAG XXX |
615 ctx->protocol, ctx->username, OTRL_INSTAG_BEST, | 620 ctx->protocol, ctx->username, OTRL_INSTAG_BEST, |
616 *msg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP, | 621 msg, NULL, &newmessage, OTRL_FRAGMENT_SEND_SKIP, |
617 NULL, NULL, NULL); | 622 NULL, NULL, NULL); |
618 #endif | 623 #endif |
619 else { | 624 else { |
620 htmlmsg = html_escape(*msg); | 625 htmlmsg = html_escape(msg); |
621 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, | 626 err = otrl_message_sending(userstate, &ops, NULL, ctx->accountname, |
622 #ifdef HAVE_LIBOTR3 | 627 #ifdef HAVE_LIBOTR3 |
623 ctx->protocol, ctx->username, htmlmsg, NULL, | 628 ctx->protocol, ctx->username, htmlmsg, NULL, |
624 &newmessage, NULL, NULL); | 629 &newmessage, NULL, NULL); |
625 #else | 630 #else |
629 NULL, NULL, NULL); | 634 NULL, NULL, NULL); |
630 #endif | 635 #endif |
631 g_free(htmlmsg); | 636 g_free(htmlmsg); |
632 } | 637 } |
633 | 638 |
634 if (err) | 639 if (err || !newmessage) |
635 *msg = NULL; /*something went wrong, don't send the plain-message! */ | 640 return NULL; /* something went wrong, don't send the plain-message! */ |
636 | 641 |
637 if (!err && newmessage) { | 642 if (cb_policy(NULL, ctx) & OTRL_POLICY_REQUIRE_ENCRYPTION || |
638 *msg = g_strdup(newmessage); | 643 ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) |
639 otrl_message_free(newmessage); | 644 *encryption_status = 1; |
640 if (cb_policy(NULL, ctx) & OTRL_POLICY_REQUIRE_ENCRYPTION || | 645 |
641 ctx->msgstate == OTRL_MSGSTATE_ENCRYPTED) | 646 /* Check the new message is not empty */ |
642 return 1; | 647 if (newmessage[0] || !msg[0]) { |
643 } | 648 rmsg = g_strdup(newmessage); |
644 return 0; | 649 } else { |
650 rmsg = NULL; | |
651 *encryption_status = 0; | |
652 } | |
653 | |
654 otrl_message_free(newmessage); | |
655 return rmsg; | |
645 } | 656 } |
646 | 657 |
647 /* Prints OTR connection state */ | 658 /* Prints OTR connection state */ |
648 void otr_print_info(const char *buddy) | 659 void otr_print_info(const char *buddy) |
649 { | 660 { |