diff options
-rw-r--r-- | nohtml/common.h | 1 | ||||
-rw-r--r-- | nohtml/filter.cpp | 159 | ||||
-rw-r--r-- | nohtml/nohtml.cpp | 2 | ||||
-rw-r--r-- | nohtml/nohtml.rc | 35 | ||||
-rw-r--r-- | nohtml/options.cpp | 42 | ||||
-rw-r--r-- | nohtml/options.h | 8 | ||||
-rw-r--r-- | nohtml/resource.h | 7 | ||||
-rw-r--r-- | nohtml/version.h | 2 |
8 files changed, 173 insertions, 83 deletions
diff --git a/nohtml/common.h b/nohtml/common.h index a2f77aa..dff856c 100644 --- a/nohtml/common.h +++ b/nohtml/common.h @@ -44,6 +44,7 @@ #include <stdio.h>
#include <m_utils.h>
#include <m_updater.h>
+#include <m_popup.h>
#define MODULE "nohtml"
diff --git a/nohtml/filter.cpp b/nohtml/filter.cpp index 5d60445..230cab7 100644 --- a/nohtml/filter.cpp +++ b/nohtml/filter.cpp @@ -3,38 +3,54 @@ #include "options.h"
#include "conv.h"
-int FilterSendMessage(WPARAM wParam, LPARAM lParam) {
- CCSDATA *ccs = (CCSDATA *) lParam;
- char *old_message = (char *)ccs->lParam;
+void LOG(char *message) {
+#ifdef _DEBUG
+ PUShowMessage(message, SM_NOTIFY);
+#endif
+}
+
+bool ContactIsOTREncrypted(HANDLE hContact) {
+ return (DBGetContactSettingByte(hContact, "OTR", "Encrypted", 0) != 0);
+}
+int FilterSendMessage(WPARAM wParam, LPARAM lParam) {
+ CCSDATA *ccs = (CCSDATA *) lParam;
+ char *old_message = (char *)ccs->lParam;
char *buf = 0;
- if(ccs->wParam & PREF_UNICODE) {
- wchar_t *messagew = (wchar_t *)&old_message[strlen(old_message)+1];
- wchar_t* smsg=strip_carrots(messagew);
- wchar_t* html_msg;
- if(options.html) {
- html_msg=bbcodes_to_html(smsg);
- delete[] smsg;
- } else
- html_msg = smsg;
-
- buf=(char *)malloc(wcslen(html_msg)*3+3);
- WideCharToMultiByte( CP_ACP, 0,html_msg, -1,buf,wcslen(html_msg)+1, NULL, NULL);
- memcpy(&buf[strlen(buf)+1],html_msg,lstrlen(buf)*2+2);
- delete[] html_msg;
- } else {
- char* smsg=strip_carrots(old_message);
- char* html_msg;
- if(options.html) {
- html_msg=bbcodes_to_html(smsg);
- delete[] smsg;
- } else
- html_msg = smsg;
-
- buf = strdup(html_msg);
- delete[] html_msg;
+
+ if(options.filter_out) {
+ if((options.apply_to & ATF_ALL)
+ || ((options.apply_to & ATF_OTR) && ContactIsOTREncrypted(ccs->hContact)))
+ {
+ if(ccs->wParam & PREF_UNICODE) {
+ wchar_t *messagew = (wchar_t *)&old_message[strlen(old_message)+1];
+ wchar_t* smsg=strip_carrots(messagew);
+ wchar_t* html_msg;
+ if(options.html) {
+ html_msg=bbcodes_to_html(smsg);
+ delete[] smsg;
+ } else
+ html_msg = smsg;
+
+ buf=(char *)malloc(wcslen(html_msg)*3+3);
+ WideCharToMultiByte( CP_ACP, 0,html_msg, -1,buf,wcslen(html_msg)+1, NULL, NULL);
+ memcpy(&buf[strlen(buf)+1],html_msg,lstrlen(buf)*2+2);
+ delete[] html_msg;
+ } else {
+ char* smsg=strip_carrots(old_message);
+ char* html_msg;
+ if(options.html) {
+ html_msg=bbcodes_to_html(smsg);
+ delete[] smsg;
+ } else
+ html_msg = smsg;
+
+ buf = strdup(html_msg);
+ delete[] html_msg;
+ }
+ ccs->lParam = (LPARAM)buf;
+ }
}
- ccs->lParam = (LPARAM)buf;
int ret = CallService(MS_PROTO_CHAINSEND, wParam, lParam);
ccs->lParam = (LPARAM)old_message;
@@ -50,50 +66,55 @@ int FilterSendMessageW(WPARAM wParam, LPARAM lParam) { }
int FilterRecvMessage(WPARAM wParam, LPARAM lParam) {
- CCSDATA *ccs = (CCSDATA *) lParam;
- PROTORECVEVENT *pre = (PROTORECVEVENT *) ccs->lParam;
-
+ CCSDATA *ccs = (CCSDATA *) lParam;
+ PROTORECVEVENT *pre = (PROTORECVEVENT *) ccs->lParam;
char *old_message = pre->szMessage;
-
char* buf = 0;
- if(ccs->wParam & PREF_UNICODE) {
- wchar_t *messagew = (wchar_t *)&old_message[strlen(old_message)+1];
- //LOG("Recieved a unicode message.");
- wchar_t* wbuf=(wchar_t*)&pre->szMessage[lstrlen(pre->szMessage)+1];
- wchar_t* st_wbuf;
- if(options.bbcodes)
- {
- //LOG("Converting from html to bbcodes then stripping leftover html.(U)");
- wchar_t* bbuf=html_to_bbcodes(wbuf);
- st_wbuf=strip_html(bbuf);
- delete[] bbuf;
- }
- else
- {
- //LOG("Stripping html.(U)");
- st_wbuf=strip_html(wbuf);
- }
- //delete[] pre->szMessage; not necessary - done in server.cpp
- buf=(char *)malloc(wcslen(st_wbuf)*3+3);
- WideCharToMultiByte( CP_ACP, 0,st_wbuf, -1,buf,wcslen(st_wbuf)+1, NULL, NULL);
- memcpy(&buf[strlen(buf)+1],st_wbuf,lstrlen(buf)*2+2);
- delete[] st_wbuf;
- pre->szMessage = buf;
- } else {
- //LOG("Recieved a non-unicode message.");
- if(options.bbcodes)
- {
- //LOG("Converting from html to bbcodes then stripping leftover html.");
- char* bbuf=html_to_bbcodes(pre->szMessage);
- buf=strip_html(bbuf);
- delete[] bbuf;
- }
- else
+
+ if(options.filter_in) {
+ if((options.apply_to & ATF_ALL)
+ || ((options.apply_to & ATF_OTR) && ContactIsOTREncrypted(ccs->hContact)))
{
- //LOG("Stripping html.");
- buf=strip_html(pre->szMessage);
+ if(pre->flags & PREF_UNICODE) {
+ LOG("Recieved a unicode message.");
+ wchar_t *messagew = (wchar_t *)&old_message[strlen(old_message)+1];
+ //wchar_t* wbuf=(wchar_t*)&pre->szMessage[lstrlen(pre->szMessage)+1];
+ wchar_t* st_wbuf;
+ if(options.bbcodes)
+ {
+ LOG("Converting from html to bbcodes then stripping leftover html.(U)");
+ wchar_t* bbuf=html_to_bbcodes(messagew);
+ st_wbuf=strip_html(bbuf);
+ delete[] bbuf;
+ }
+ else
+ {
+ LOG("Stripping html.(U)");
+ st_wbuf=strip_html(messagew);
+ }
+ //delete[] pre->szMessage; not necessary - done in server.cpp
+ buf=(char *)malloc(wcslen(st_wbuf)*3+3);
+ WideCharToMultiByte( CP_ACP, 0,st_wbuf, -1,buf,wcslen(st_wbuf)+1, NULL, NULL);
+ memcpy(&buf[strlen(buf)+1],st_wbuf,lstrlen(buf)*2+2);
+ delete[] st_wbuf;
+ pre->szMessage = buf;
+ } else {
+ LOG("Recieved a non-unicode message.");
+ if(options.bbcodes)
+ {
+ LOG("Converting from html to bbcodes then stripping leftover html.");
+ char* bbuf=html_to_bbcodes(pre->szMessage);
+ buf=strip_html(bbuf);
+ delete[] bbuf;
+ }
+ else
+ {
+ LOG("Stripping html.");
+ buf=strip_html(pre->szMessage);
+ }
+ pre->szMessage = buf;
+ }
}
- pre->szMessage = buf;
}
int ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam);
diff --git a/nohtml/nohtml.cpp b/nohtml/nohtml.cpp index f684a7f..77fbf35 100644 --- a/nohtml/nohtml.cpp +++ b/nohtml/nohtml.cpp @@ -21,7 +21,7 @@ PLUGININFOEX pluginInfo={ __AUTHOREMAIL,
__COPYRIGHT,
__AUTHORWEB,
- 0,
+ UNICODE_AWARE, //not transient
0,
// TODO: generate your own GUID!!
{ 0xD78C8249, 0xE8DB, 0x46B1, { 0x92, 0xF3, 0x88, 0xE6, 0xDC, 0x96, 0x4E, 0x8D } }
diff --git a/nohtml/nohtml.rc b/nohtml/nohtml.rc index 3c1052e..631c10a 100644 --- a/nohtml/nohtml.rc +++ b/nohtml/nohtml.rc @@ -26,14 +26,20 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT // Dialog
//
-IDD_OPT1 DIALOGEX 0, 0, 246, 179
+IDD_OPT1 DIALOGEX 0, 0, 246, 219
STYLE DS_SETFONT | WS_POPUP
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
- CONTROL "Replace HTML with BBCodes",IDC_CHK_BBCODES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,41,39,111,10
- GROUPBOX "Incoming Messages",IDC_STATIC,15,15,165,54
- CONTROL "Replace BBCodes with HTML",IDC_CHK_HTML,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,41,97,111,10
- GROUPBOX "Outgoing Messages",IDC_STATIC,15,73,165,54
+ CONTROL "Replace HTML with BBCodes",IDC_CHK_BBCODES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,62,118,161,10
+ GROUPBOX "Incoming Messages",IDC_STATIC,36,85,192,54
+ CONTROL "Replace BBCodes with HTML",IDC_CHK_HTML,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,62,179,161,10
+ GROUPBOX "Outgoing Messages",IDC_STATIC,36,145,192,54
+ GROUPBOX "Apply To",IDC_STATIC,36,27,192,53
+ CONTROL "Remove HTML from outgoing messages",IDC_CHK_FILTEROUT,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,53,161,161,10
+ CONTROL "All contacts",IDC_CHK_ALL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,53,42,161,10
+ CONTROL "OTR encrypted sessions",IDC_CHK_OTR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,53,56,161,10
+ CONTROL "Remove HTML",IDC_CHK_FILTERIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,53,101,161,10
END
@@ -62,6 +68,25 @@ END #endif // APSTUDIO_INVOKED
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_OPT1, DIALOG
+ BEGIN
+ VERTGUIDE, 36
+ VERTGUIDE, 53
+ VERTGUIDE, 62
+ BOTTOMMARGIN, 217
+ END
+END
+#endif // APSTUDIO_INVOKED
+
#endif // Neutral (Default) resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/nohtml/options.cpp b/nohtml/options.cpp index c27afb3..bda3de4 100644 --- a/nohtml/options.cpp +++ b/nohtml/options.cpp @@ -5,13 +5,21 @@ Options options;
void LoadOptions() {
- options.bbcodes = (DBGetContactSettingDword(0, MODULE, "BBCodes", 0) != 0);
- options.html = (DBGetContactSettingDword(0, MODULE, "HTML", 0) != 0);
+ options.filter_in = (DBGetContactSettingByte(0, MODULE, "FilterIn", 1) != 0);
+ options.filter_out = (DBGetContactSettingByte(0, MODULE, "FilterOut", 0) != 0);
+ options.bbcodes = (DBGetContactSettingByte(0, MODULE, "BBCodes", 0) != 0);
+ options.html = (DBGetContactSettingByte(0, MODULE, "HTML", 0) != 0);
+
+ options.apply_to = DBGetContactSettingDword(0, MODULE, "ApplyTo", ATF_ALL);
}
void SaveOptions() {
- DBWriteContactSettingDword(0, MODULE, "BBCodes", options.bbcodes ? 1 : 0);
- DBWriteContactSettingDword(0, MODULE, "HTML", options.html ? 1 : 0);
+ DBWriteContactSettingByte(0, MODULE, "FilterIn", options.filter_in ? 1 : 0);
+ DBWriteContactSettingByte(0, MODULE, "FilterOut", options.filter_out ? 1 : 0);
+ DBWriteContactSettingByte(0, MODULE, "BBCodes", options.bbcodes ? 1 : 0);
+ DBWriteContactSettingByte(0, MODULE, "HTML", options.html ? 1 : 0);
+
+ DBWriteContactSettingDword(0, MODULE, "ApplyTo", options.apply_to);
}
BOOL CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {
@@ -20,11 +28,31 @@ BOOL CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) switch ( msg ) {
case WM_INITDIALOG:
TranslateDialogDefault( hwndDlg );
+ CheckDlgButton(hwndDlg, IDC_CHK_FILTERIN, options.filter_in);
+ CheckDlgButton(hwndDlg, IDC_CHK_FILTEROUT, options.filter_out);
CheckDlgButton(hwndDlg, IDC_CHK_BBCODES, options.bbcodes);
CheckDlgButton(hwndDlg, IDC_CHK_HTML, options.html);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_BBCODES), IsDlgButtonChecked(hwndDlg, IDC_CHK_FILTERIN));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_HTML), IsDlgButtonChecked(hwndDlg, IDC_CHK_FILTEROUT));
+
+ CheckDlgButton(hwndDlg, IDC_CHK_ALL, options.apply_to & ATF_ALL);
+ CheckDlgButton(hwndDlg, IDC_CHK_OTR, options.apply_to & ATF_OTR);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_OTR), !IsDlgButtonChecked(hwndDlg, IDC_CHK_ALL));
+
return FALSE;
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED) {
+ switch(LOWORD(wParam)) {
+ case IDC_CHK_FILTERIN:
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_BBCODES), IsDlgButtonChecked(hwndDlg, IDC_CHK_FILTERIN));
+ break;
+ case IDC_CHK_FILTEROUT:
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_HTML), IsDlgButtonChecked(hwndDlg, IDC_CHK_FILTEROUT));
+ break;
+ case IDC_CHK_ALL:
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_OTR), !IsDlgButtonChecked(hwndDlg, IDC_CHK_ALL));
+ break;
+ }
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
}
break;
@@ -34,8 +62,14 @@ BOOL CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) switch (((LPNMHDR)lParam)->code)
{
case PSN_APPLY:
+ options.filter_in = IsDlgButtonChecked(hwndDlg, IDC_CHK_FILTERIN);
+ options.filter_out = IsDlgButtonChecked(hwndDlg, IDC_CHK_FILTEROUT);
options.bbcodes = IsDlgButtonChecked(hwndDlg, IDC_CHK_BBCODES);
options.html = IsDlgButtonChecked(hwndDlg, IDC_CHK_HTML);
+
+ options.apply_to = (IsDlgButtonChecked(hwndDlg, IDC_CHK_ALL) ? ATF_ALL : 0);
+ options.apply_to |= (IsDlgButtonChecked(hwndDlg, IDC_CHK_OTR) ? ATF_OTR : 0);
+
SaveOptions();
break;
}
diff --git a/nohtml/options.h b/nohtml/options.h index d5c7dba..0717be5 100644 --- a/nohtml/options.h +++ b/nohtml/options.h @@ -1,9 +1,13 @@ #ifndef _OPTIONS_INC
#define _OPTIONS_INC
+// flags for 'apply_to' value below
+#define ATF_ALL 0x01
+#define ATF_OTR 0x02
+
typedef struct {
- bool bbcodes;
- bool html;
+ bool filter_in, filter_out, bbcodes, html;
+ int apply_to; // bitwize 'or' of ATF_* flags above - 'ALL' overrides all others
} Options;
extern Options options;
diff --git a/nohtml/resource.h b/nohtml/resource.h index d8ab8e5..d237061 100644 --- a/nohtml/resource.h +++ b/nohtml/resource.h @@ -5,6 +5,11 @@ #define IDD_OPT1 109
#define IDC_CHK_BBCODES 1001
#define IDC_CHK_HTML 1002
+#define IDC_CHK_FILTEROUT 1003
+#define IDC_CHK_ALL 1004
+#define IDC_CHECK2 1005
+#define IDC_CHK_OTR 1005
+#define IDC_CHK_FILTERIN 1006
// Next default values for new objects
//
@@ -12,7 +17,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 120
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1002
+#define _APS_NEXT_CONTROL_VALUE 1006
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/nohtml/version.h b/nohtml/version.h index b8bc27c..bc811db 100644 --- a/nohtml/version.h +++ b/nohtml/version.h @@ -5,7 +5,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 0
#define __RELEASE_NUM 0
-#define __BUILD_NUM 2
+#define __BUILD_NUM 3
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
#define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM
|