From 50b715009438967fa9b37a62649db216ce8021b7 Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 25 Apr 2007 15:34:26 +0000 Subject: git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@145 4f64403b-2f21-0410-a795-97e2b3489a10 --- nohtml/filter.cpp | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 nohtml/filter.cpp (limited to 'nohtml/filter.cpp') diff --git a/nohtml/filter.cpp b/nohtml/filter.cpp new file mode 100644 index 0000000..4d3ed77 --- /dev/null +++ b/nohtml/filter.cpp @@ -0,0 +1,126 @@ +#include "common.h" +#include "filter.h" +#include "options.h" +#include "conv.h" + +int FilterSendMessage(WPARAM wParam, LPARAM lParam) { + CCSDATA *ccs = (CCSDATA *) lParam; + char *message = (char *)ccs->lParam; + + // TODO: process 'message' and/or 'messagew' below + if(ccs->wParam & PREF_UNICODE) { + wchar_t *messagew = (wchar_t *)&message[strlen(message)+1]; + } else { + } + + return CallService(MS_PROTO_CHAINSEND, wParam, lParam); +} + +int FilterSendMessageW(WPARAM wParam, LPARAM lParam) { + CCSDATA *ccs = (CCSDATA *) lParam; + ccs->wParam |= PREF_UNICODE; + + return FilterSendMessage(wParam, lParam); +} + +int FilterRecvMessage(WPARAM wParam, LPARAM 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 + { + //LOG("Stripping html."); + buf=strip_html(pre->szMessage); + } + pre->szMessage = buf; + } + + int ret = CallService(MS_PROTO_CHAINRECV, wParam, lParam); + pre->szMessage = old_message; + return ret; +} + +int NewContact(WPARAM wParam, LPARAM lParam) { + // add filter + HANDLE hContact = (HANDLE)wParam; + CallService( MS_PROTO_ADDTOCONTACT, ( WPARAM )hContact, ( LPARAM )MODULE ); + + return 0; +} + +void RegisterFilter() { + PROTOCOLDESCRIPTOR pd = {0}; + pd.cbSize = sizeof(pd); + pd.szName = MODULE "Filter"; + // TODO: modify this to reflect the purpose of your plugin + pd.type = PROTOTYPE_FILTER; + CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd); +} + +HANDLE hEventNewContact; +#define NUM_FILTER_SERVICES 3 +HANDLE hServices[NUM_FILTER_SERVICES]; + +void AddFilterToContacts() { + // this adds us as a filter to all existing and new contacts + // TODO: modify this (and the NewContact function above) to include only the contacts required + HANDLE hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDFIRST, 0, 0 ); + while ( hContact != NULL ) { + CallService( MS_PROTO_ADDTOCONTACT, ( WPARAM )hContact, ( LPARAM )(MODULE "Filter")); + hContact = ( HANDLE )CallService( MS_DB_CONTACT_FINDNEXT,( WPARAM )hContact, 0 ); + } + + hEventNewContact = HookEvent(ME_DB_CONTACT_ADDED, NewContact); +} + +void CreateFilterServices() { + // create our services + int i = 0; + hServices[i++] = CreateProtoServiceFunction(MODULE "Filter", PSS_MESSAGE, FilterSendMessage); + hServices[i++] = CreateProtoServiceFunction(MODULE "Filter", PSS_MESSAGE"W", FilterSendMessageW); + hServices[i++] = CreateProtoServiceFunction(MODULE "Filter", PSR_MESSAGE, FilterRecvMessage); + + // remember to modify the NUM_FILTER_SERVICES #define above if you add more services! +} + +void DeinitFilter() { + UnhookEvent(hEventNewContact); + + for(int i = 0; i < NUM_FILTER_SERVICES; i++) + DestroyServiceFunction(hServices[i]); +} \ No newline at end of file -- cgit v1.2.3