From 06aa5cb671852d3eb8059be57222442d84a4fa86 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Mon, 26 Jun 2017 15:13:40 +1000 Subject: [PATCH] Move all handling of SED messages and notices into ctcp.c, re-enable SED notices Actual encryped messages and notices are now printed directly from do_sed() / do_reply_sed(). Inline CTCP replacement is only done if the message cannot be decrypted (for the [ENCRYPTED MESSAGE] placeholder). This removes the need for the global flag 'sed' to alter the NOTICE and PRIVMSG handling. A side-effect of this is that SED PRIVMSGs now do not go through the usual PRIVMSG ignore and flood handling. This is acceptable because messages can only go through this path if the sender has actually been added as a SED peer with /ENCRYPT, and it still goes through the CTCP ignore and flood handling. --- Changelog | 3 +++ include/ctcp.h | 1 - source/ctcp.c | 27 ++++++++++++--------------- source/notice.c | 9 --------- source/parse.c | 7 ------- 5 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Changelog b/Changelog index 1adc849..dc3dd67 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,8 @@ [Changes 1.2.2] +* Move all handling of SED messages and notices into ctcp.c, re-enable + SED notices. (caf) + * Handle SED-encrypted CTCP replies properly. (caf) * Add sent_nick flag to NickList struct, bump MODULE_VERSION. (caf) diff --git a/include/ctcp.h b/include/ctcp.h index 1a2cb0a..40d2575 100644 --- a/include/ctcp.h +++ b/include/ctcp.h @@ -55,7 +55,6 @@ extern CtcpEntryDll *dll_ctcp; -extern int sed; extern int in_ctcp_flag; #define CTCP_DELIM_CHAR '\001' diff --git a/source/ctcp.c b/source/ctcp.c index d3c3c16..ed2b500 100644 --- a/source/ctcp.c +++ b/source/ctcp.c @@ -184,9 +184,6 @@ static char *ctcp_type[] = "NOTICE" }; -/* This is set to one if we parsed an SED */ -int sed = 0; - /* * in_ctcp_flag is set to true when IRCII is handling a CTCP request. This * is used by the ctcp() sending function to force NOTICEs to be used in any @@ -632,7 +629,6 @@ static char *try_decrypt(char *from, char *to, char *msg) CTCP_HANDLER(do_sed) { char *ret; - char *ret2; ret = try_decrypt(from, to, cmd); @@ -642,16 +638,17 @@ CTCP_HANDLER(do_sed) * There might be a CTCP message in there, * so we see if we can find it. */ - ret2 = m_strdup(do_ctcp(from, to, ret)); - sed = 1; + char *ptr = do_ctcp(from, to, ret); + if (*ptr && do_hook(ENCRYPTED_PRIVMSG_LIST, "%s %s %s", from, to, ptr)) + put_it("%s",convert_output_format(fget_string_var(FORMAT_ENCRYPTED_PRIVMSG_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from, FromUserHost, to, ptr)); + *ret = 0; } else { - ret2 = m_strdup("[ENCRYPTED MESSAGE]"); + ret = m_strdup("[ENCRYPTED MESSAGE]"); } - new_free(&ret); - return ret2; + return ret; } /* do_sed_reply: Same as do_sed, but CTCPs within the SED are handled as @@ -659,7 +656,6 @@ CTCP_HANDLER(do_sed) CTCP_HANDLER(do_sed_reply) { char *ret; - char *ret2; ret = try_decrypt(from, to, cmd); @@ -669,16 +665,17 @@ CTCP_HANDLER(do_sed_reply) * There might be a CTCP reply in there, * so we see if we can find it. */ - ret2 = m_strdup(do_notice_ctcp(from, to, ret)); - sed = 1; + char *ptr = do_notice_ctcp(from, to, ret); + if (*ptr && do_hook(ENCRYPTED_NOTICE_LIST, "%s %s %s", from, to, ptr)) + put_it("%s",convert_output_format(fget_string_var(FORMAT_ENCRYPTED_NOTICE_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from, FromUserHost, to, ptr)); + *ret = 0; } else { - ret2 = m_strdup("[ENCRYPTED MESSAGE]"); + ret = m_strdup("[ENCRYPTED MESSAGE]"); } - new_free(&ret); - return ret2; + return ret; } CTCP_HANDLER(do_utc) diff --git a/source/notice.c b/source/notice.c index 5609b34..314a5c5 100644 --- a/source/notice.c +++ b/source/notice.c @@ -574,15 +574,6 @@ void parse_notice(char *from, char **Args) goto notice_cleanup; } - if (sed && !do_hook(ENCRYPTED_NOTICE_LIST, "%s %s %s", from, to, line)) - { -#if 0 - put_it("%s", convert_output_format(fget_string_var(FORMAT_ENCRYPTED_NOTICE_FSET), "%s %s %s %s", update_clock(GET_TIME), from, FromUserHost, line)); -#endif - sed = 0; - goto notice_cleanup; - } - if (!check_chanwall_notice(from, line, list_type)) { char *s; diff --git a/source/parse.c b/source/parse.c index 1a5c555..b316caa 100644 --- a/source/parse.c +++ b/source/parse.c @@ -613,13 +613,6 @@ static void p_privmsg(char *from, char **Args) else no_flood = check_flooding(from, flood_type, ptr, NULL); - if (sed == 1) - { - if (do_hook(ENCRYPTED_PRIVMSG_LIST,"%s %s %s",from, to, ptr)) - put_it("%s",convert_output_format(fget_string_var(FORMAT_ENCRYPTED_PRIVMSG_FSET), "%s %s %s %s %s", update_clock(GET_TIME), from, FromUserHost, to, ptr)); - sed = 0; - } - else { int added_to_tab = 0; if (list_type == PUBLIC_LIST || list_type == PUBLIC_OTHER_LIST || list_type == PUBLIC_MSG_LIST)