diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-10-31 03:17:54 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-10-31 03:17:54 +0300 |
commit | c73d5cfe85557d038e21f35712a679ca8061f6f1 (patch) | |
tree | 3eb98f75b0e3fe8a22645f92277f60e9c20379b1 | |
parent | 805aae34900744c6904cad9437506fdf860e12e7 (diff) |
another cleanup method
regex
history log
-rw-r--r-- | headers.h | 8 | ||||
-rw-r--r-- | init.cpp | 17 | ||||
-rw-r--r-- | options.cpp | 14 | ||||
-rw-r--r-- | resource.h | 5 | ||||
-rw-r--r-- | stopspam.cpp | 44 | ||||
-rw-r--r-- | stopspam.h | 2 | ||||
-rw-r--r-- | stopspam.rc | 16 | ||||
-rw-r--r-- | stopspam_10.vcxproj | 7 | ||||
-rw-r--r-- | utilities.cpp | 135 | ||||
-rw-r--r-- | utilities.h | 10 |
10 files changed, 205 insertions, 53 deletions
@@ -31,5 +31,13 @@ #include "resource.h" #include "utilities.h" +//boost +#include <boost/thread.hpp> +#include <boost/regex.hpp> +#include <boost/algorithm/string.hpp> + +//utf8cpp +#include <utf8.h> + #include <m_dos.h> @@ -15,8 +15,10 @@ BOOL gbIgnoreContacts = 0; BOOL gbExclude = 1; BOOL gbDelExcluded = 0; BOOL gbDelAllTempory = 0; +BOOL gbHistoryLog = 0; BOOL gbDosServiceIntegration = 0; BOOL gbCaseInsensitive = 0; +BOOL gbRegexMatch = 0; BOOL gbInvisDisable = 0; BOOL gbIgnoreURL = 1; BOOL gbLogToFile=0; @@ -52,12 +54,12 @@ UTF8_INTERFACE utfi; PLUGININFOEX pluginInfoEx = { sizeof(PLUGININFOEX), 0, - PLUGIN_MAKE_VERSION(0, 0, 1, 9), + PLUGIN_MAKE_VERSION(0, 0, 2, 0), pluginDescription, - "Roman Miklashevsky", + "Roman Miklashevsky, sss, Elzor", "sss123next@list.ru", "© 2004-2010 Roman Miklashevsky, A. Petkevich, Kosh&chka, sss, Elzor", - "http://sss.chaoslab.ru:81/tracker/mim_plugs/", + "http://sss.chaoslab.ru/tracker/mim_plugs/", UNICODE_AWARE, 0, MIID_STOPSPAM @@ -152,6 +154,7 @@ void InitVars() gbDelExcluded = DBGetContactSettingByte(NULL, pluginName, "DelExcluded", 0); gbDelAllTempory = DBGetContactSettingByte(NULL, pluginName, "DelAllTempory", 0); gbCaseInsensitive = DBGetContactSettingByte(NULL, pluginName, "CaseInsensitive", 0); + gbRegexMatch = DBGetContactSettingByte(NULL, pluginName, "RegexMatch", 0); gbInvisDisable = DBGetContactSettingByte(NULL, pluginName, "DisableInInvis", 0); gbIgnoreURL = DBGetContactSettingByte(NULL, pluginName, "IgnoreURL", 0); gbAutoAuthGroup = DBGetContactSettingStringPAN(NULL, pluginName, "AutoAuthGroup", _T("Not Spammers")); @@ -159,6 +162,7 @@ void InitVars() gbAutoAddToServerList=DBGetContactSettingByte(NULL, pluginName, "AutoAddToServerList", 0); gbAutoReqAuth=DBGetContactSettingByte(NULL, pluginName, "AutoReqAuth", 0); gbLogToFile=DBGetContactSettingByte(NULL, pluginName, "LogSpamToFile", 0); + gbHistoryLog = DBGetContactSettingByte(NULL, pluginName, "HistoryLog", 0); } @@ -169,10 +173,9 @@ static int OnSystemModulesLoaded(WPARAM wParam,LPARAM lParam) if (ServiceExists(MS_VARS_FORMATSTRING)) gbVarsServiceExist = TRUE; InitVars(); - if(gbDelExcluded) - RemoveExcludedUsers(); - if(gbDelAllTempory) - RemoveTmp(0,0); + void CleanThread(); + if(gbDelAllTempory || gbDelExcluded) + boost::thread *thr = new boost::thread(CleanThread); // Folders plugin support
if (ServiceExists(MS_FOLDERS_REGISTER_PATH))
{
diff --git a/options.cpp b/options.cpp index ecb81e2..ac62a70 100644 --- a/options.cpp +++ b/options.cpp @@ -276,6 +276,9 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar SendDlgItemMessage(hwnd, IDC_AUTOAUTH, BM_SETCHECK, gbAutoAuth ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(hwnd, IDC_ADDTOSRVLST, BM_SETCHECK, gbAutoAddToServerList ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(hwnd, IDC_REQAUTH, BM_SETCHECK, gbAutoReqAuth ? BST_CHECKED : BST_UNCHECKED, 0); + SendDlgItemMessage(hwnd, IDC_REGEX, BM_SETCHECK, gbRegexMatch ? BST_CHECKED : BST_UNCHECKED, 0); + SendDlgItemMessage(hwnd, IDC_HISTORY_LOG, BM_SETCHECK, gbHistoryLog ? BST_CHECKED : BST_UNCHECKED, 0); + SetDlgItemText(hwnd, IDC_AUTOADDGROUP, gbAutoAuthGroup.c_str()); } return TRUE; @@ -295,6 +298,8 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar case IDC_ADDTOSRVLST: case IDC_REQAUTH: case IDC_AUTOADDGROUP: + case IDC_REGEX: + case IDC_HISTORY_LOG: SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); break; @@ -328,12 +333,7 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar strcpy(szNumber, "0"); while(strcmp(DBGetContactSettingStringPAN_A(NULL, "CListGroups", szNumber, "0").c_str(), "0") != 0) { -#if defined(_MSC_VER) && _MSC_VER >= 1300 - _itoa_s(GroupNumber, szNumber, sizeof(szNumber), 10); -#else _itoa(GroupNumber, szNumber, 10); - -#endif wcscpy(szValue, DBGetContactSettingStringPAN(NULL, "CListGroups", szNumber, _T("0")).c_str()); if(wcscmp(NewGroupName.c_str(), szValue + 1) == 0) { @@ -365,6 +365,10 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar BST_CHECKED == SendDlgItemMessage(hwnd, IDC_ADDTOSRVLST, BM_GETCHECK, 0, 0)); DBWriteContactSettingByte(NULL, pluginName, "AutoReqAuth", gbAutoReqAuth = BST_CHECKED == SendDlgItemMessage(hwnd, IDC_REQAUTH, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "RegexMatch", gbAutoReqAuth =
+ BST_CHECKED == SendDlgItemMessage(hwnd, IDC_REGEX, BM_GETCHECK, 0, 0));
+ DBWriteContactSettingByte(NULL, pluginName, "HistoryLog", gbAutoReqAuth =
+ BST_CHECKED == SendDlgItemMessage(hwnd, IDC_HISTORY_LOG, BM_GETCHECK, 0, 0));
{ static tstring NewAGroupName, CurrentAGroupName; NewAGroupName = GetDlgItemString(hwnd, IDC_AUTOADDGROUP); @@ -49,6 +49,9 @@ #define IDC_LOGSPAMTOFILE 1027
#define ID_REMOVE_TMP_ALL 1027
#define ID_LOGSPAMTOFILE 1027
+#define IDC_REGEX 1028
+#define IDC_CHECK1 1029
+#define IDC_HISTORY_LOG 1029
// Next default values for new objects
//
@@ -56,7 +59,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1028
+#define _APS_NEXT_CONTROL_VALUE 1030
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/stopspam.cpp b/stopspam.cpp index cc876af..d76d79a 100644 --- a/stopspam.cpp +++ b/stopspam.cpp @@ -62,14 +62,9 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_ADDED, wParam, lParam) } if(msg) { -#ifdef _UNICODE char * buff=mir_utf8encodeW(variables_parse(gbAuthRepl, hcntct).c_str()); CallContactService(hcntct, PSS_MESSAGE, PREF_UTF, (LPARAM) buff); mir_free(buff); -#else - CallContactService(hcntct, PSS_MESSAGE, 0, (LPARAM) variables_parse(gbAuthRepl, hcntct).c_str()); -#endif - }; delete dbei.pBlob; return 1; @@ -125,23 +120,15 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) tstring message; - if(dbei->flags & DBEF_UTF){ - WCHAR* msg_u; + if(dbei->flags & DBEF_UTF) + { + wchar_t* msg_u; char* msg_a = mir_strdup(( char* )dbei->pBlob ); mir_utf8decode( msg_a, &msg_u ); -#ifdef _UNICODE message = msg_u; -#else - message = mir_u2a(msg_u); -#endif } - else{ -#ifdef _UNICODE + else message = mir_a2u((char*)(dbei->pBlob)); -#else - message = (char*)(dbei->pBlob); -#endif - } // if message contains right answer... @@ -153,8 +140,27 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) else if(DBGetContactSettingWord(hContact,dbei->szModule,"ApparentMode",0) == ID_STATUS_OFFLINE) msg = 0; //is it useful ? } - - if(gbCaseInsensitive?(!Stricmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))):( !_tcscmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str())))) + bool answered = false; + if(!gbRegexMatch) + answered = gbCaseInsensitive?(!Stricmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))):( !_tcscmp(message.c_str(), (variables_parse(gbAnswer, hContact).c_str()))); + else + { + if(gbCaseInsensitive) + { + std::string check(toUTF8(variables_parse(gbAnswer, hContact))), msg(toUTF8(message)); + boost::algorithm::to_upper(check); + boost::algorithm::to_upper(msg); + boost::regex expr(check); + answered = boost::regex_search(msg.begin(), msg.end(), expr); + } + else + { + std::string check(toUTF8(variables_parse(gbAnswer, hContact))), msg(toUTF8(message));
+ boost::regex expr(check);
+ answered = boost::regex_search(msg.begin(), msg.end(), expr);
+ } + } + if(answered) { // unhide contact DBDeleteContactSetting(hContact, "CList", "Hidden"); @@ -13,6 +13,8 @@ extern BOOL gbDelExcluded; extern BOOL gbDosServiceIntegration; extern BOOL gbDelNotInList; extern BOOL gbCaseInsensitive; +extern BOOL gbRegexMatch; +extern BOOL gbHistoryLog; extern BOOL gbInvisDisable; extern BOOL gbIgnoreURL; extern tstring gbSpammersGroup; diff --git a/stopspam.rc b/stopspam.rc index 9d80b99..8c09470 100644 --- a/stopspam.rc +++ b/stopspam.rc @@ -92,14 +92,16 @@ BEGIN EDITTEXT ID_SPECIALGROUPNAME,217,15,79,12,ES_AUTOHSCROLL
CONTROL "Ignore URL in messages and auth requests",ID_IGNOREURL,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,100,287,10
- CONTROL "Add contact to server list",IDC_ADDTOSRVLST,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,22,123,187,10
- EDITTEXT IDC_AUTOADDGROUP,210,121,76,14,ES_AUTOHSCROLL
- GROUPBOX "After congratulation (ICQ only)",IDC_STATIC,15,112,278,51
- CONTROL "Automatically grant authorization",IDC_AUTOAUTH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,22,135,263,10
+ CONTROL "Add contact to server list",IDC_ADDTOSRVLST,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,22,146,187,10
+ EDITTEXT IDC_AUTOADDGROUP,210,144,76,14,ES_AUTOHSCROLL
+ GROUPBOX "After congratulation (ICQ only)",IDC_STATIC,15,135,278,51
+ CONTROL "Automatically grant authorization",IDC_AUTOAUTH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,22,158,263,10
CONTROL "Request authorization from contacts which pass stopspam test",IDC_REQAUTH,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,22,147,267,10
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,22,170,267,10
CONTROL "Remove all tempory contacts after restart",ID_REMOVE_TMP_ALL,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,55,287,8
+ CONTROL "Use regex for answers checking",IDC_REGEX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,111,287,10
+ CONTROL "Log Spammers to system history",IDC_HISTORY_LOG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,121,218,10
END
@@ -153,7 +155,7 @@ END //
VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,0,1,9
+ FILEVERSION 0,0,2,0
PRODUCTVERSION 0,7,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
@@ -172,7 +174,7 @@ BEGIN VALUE "Comments", "Licensed under the terms of the GNU General Public License"
VALUE "CompanyName", " "
VALUE "FileDescription", "StopSpam plugin for Miranda IM"
- VALUE "FileVersion", "0.0.1.9"
+ VALUE "FileVersion", "0.0.2.0"
VALUE "InternalName", "stopspam"
VALUE "LegalCopyright", "Copyright © 2000-2010 Miranda IM Project. This software is released under the terms of the GNU General Public License."
VALUE "OriginalFilename", "stopspam.dll"
diff --git a/stopspam_10.vcxproj b/stopspam_10.vcxproj index 9f9b8ce..2e65fa0 100644 --- a/stopspam_10.vcxproj +++ b/stopspam_10.vcxproj @@ -100,8 +100,8 @@ </PreBuildEvent>
<ClCompile>
<Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>X:\temp\windows\libs\boost;X:\install\git\miranda\miranda-im\miranda\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;STOPSPAM_EXPORTS;%(PreprocessorDefinitions);_UNICODE;UNICODE</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>X:\temp\windows\libs\boost;X:\temp\windows\libs\utf8cpp\include;X:\install\git\miranda\miranda-im\miranda\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;STOPSPAM_EXPORTS;%(PreprocessorDefinitions);_UNICODE;UNICODE;_CRT_SECURE_NO_DEPRECATE</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@@ -248,7 +248,7 @@ <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
- <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>X:\temp\windows\libs\boost;X:\temp\windows\libs\utf8cpp\include;X:\install\git\miranda\miranda-im\miranda\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;STOPSPAM_EXPORTS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
@@ -274,6 +274,7 @@ <ImportLibrary>
</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
+ <AdditionalLibraryDirectories>X:\temp\windows\libs\boost\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
<Command>
diff --git a/utilities.cpp b/utilities.cpp index d625682..7b6657d 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -90,7 +90,7 @@ void DeleteCListGroupsByName(TCHAR* szGroupName) DBWriteContactSettingByte(NULL, "CList", "ConfirmDelete",ConfirmDelete); } - +/* void RemoveExcludedUsers() { HANDLE hContact; @@ -175,10 +175,11 @@ void RemoveTemporaryUsers() delete plist; }; DeleteCListGroupsByName(_T("Not In List")); -} +}*/ int RemoveTmp(WPARAM,LPARAM) { - RemoveTemporaryUsers(); + void CleanThread(); + CleanThread(); return 0; } tstring variables_parse(tstring const &tstrFormat, HANDLE hContact){ @@ -376,10 +377,134 @@ void LogSpamToFile(HANDLE hContact, tstring message) } -void CleanProtocolThread(char* proto) +boost::mutex clean_mutex; + +void CleanProtocolTmpThread(char* proto) { + boost::this_thread::sleep(boost::posix_time::seconds(5)); + std::list<HANDLE> contacts; + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact;) + { + if(!strcmp(proto, (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0))) + if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)|| (_T("Not In List")== DBGetContactSettingStringPAN(hContact,"CList","Group",_T("")))) + contacts.push_back(hContact); + } + clean_mutex.lock(); + std::list<HANDLE>::iterator end = contacts.end(); + for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i) + {
+ CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0); + LogSpamToFile(*i, _T("Deleted")); + HistoryLogFunc(*i, "Deleted"); + } + clean_mutex.unlock(); } +void CleanProtocolExclThread(char* proto)
+{
+ boost::this_thread::sleep(boost::posix_time::seconds(5));
+ std::list<HANDLE> contacts;
+ for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact;)
+ {
+ if(!strcmp(proto, (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)))
+ if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && DBGetContactSettingByte(hContact, pluginName, "Excluded", 0))
+ contacts.push_back(hContact);
+ }
+ clean_mutex.lock();
+ std::list<HANDLE>::iterator end = contacts.end();
+ for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i)
+ {
+ CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0);
+ LogSpamToFile(*i, _T("Deleted"));
+ HistoryLogFunc(*i, "Deleted");
+ }
+ clean_mutex.unlock();
+}
+ + void CleanThread() { -}
\ No newline at end of file + std::list<std::string> protocols;
+ int count = 0;
+ PROTOACCOUNT **accounts; + ProtoEnumAccounts(&count, &accounts); + for(int i = 0; i < count; i++) + protocols.push_back(accounts[i]->szModuleName); + while(!protocols.empty()) + { + std::list<std::list<std::string>::iterator> elements_to_clean; + std::list<std::string>::iterator end = protocols.end(); + for(std::list<std::string>::iterator i = protocols.begin(); i != end; ++i) + {
+ UINT status = CallProtoService(i->c_str(), PS_GETSTATUS, 0, 0);
+ if(status>= ID_STATUS_CONNECTING && status <= ID_STATUS_OFFLINE)
+ ;
+ else + { + if(gbDelAllTempory) + boost::thread *thr = new boost::thread(boost::bind(CleanProtocolTmpThread, (char*)i->c_str())); + if(gbDelExcluded) + boost::thread *thr = new boost::thread(boost::bind(CleanProtocolExclThread, (char*)i->c_str())); + elements_to_clean.push_back(i); + } + } + if(!elements_to_clean.empty()) + { + std::list<std::list<std::string>::iterator>::iterator end = elements_to_clean.end(); + for(std::list<std::list<std::string>::iterator>::iterator i = elements_to_clean.begin(); i != end; ++i) + protocols.erase(*i); + } + boost::this_thread::sleep(boost::posix_time::seconds(1)); + } +} +void HistoryLog(HANDLE hContact, char *data, int event_type, int flags)
+{
+ DBEVENTINFO Event = {0};
+ Event.cbSize = sizeof(Event);
+ Event.szModule = pluginName;
+ Event.eventType = event_type;
+ Event.flags = flags | DBEF_UTF;
+ Event.timestamp = (DWORD)time(NULL);
+ Event.cbBlob = strlen(data)+1;
+ Event.pBlob = (PBYTE)_strdup(data);
+ CallService(MS_DB_EVENT_ADD, (WPARAM)(HANDLE)hContact,(LPARAM)&Event);
+}
+void HistoryLogFunc(HANDLE hContact, std::string message)
+{
+ if(gbHistoryLog)
+ {
+ std::string msg = message;
+ msg.append("\n");
+ msg.append("Protocol: ").append((char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)).append(" Contact:");
+ msg.append(toUTF8((TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR))).append(" ID: ");
+ msg.append(toUTF8(GetContactUid(hContact,toUTF16((char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0)))));
+ HistoryLog(NULL, (char*)msg.c_str(), EVENTTYPE_MESSAGE, 0);
+ }
+}
+
+std::string toUTF8(std::wstring str)
+{
+ std::string ustr;
+ utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr));
+ return ustr;
+}
+
+std::string toUTF8(std::string str)
+{
+ std::string ustr;
+ std::string tmpstr;
+ utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr));
+ utf8::utf16to8(tmpstr.begin(), tmpstr.end(), back_inserter(ustr));
+ return ustr;
+}
+
+
+std::wstring toUTF16(std::string str) //convert as much as possible
+{
+ std::wstring ustr;
+ std::string tmpstr;
+ utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr));
+ utf8::utf8to16(tmpstr.begin(), tmpstr.end(), back_inserter(ustr));
+ return ustr;
+}
+
diff --git a/utilities.h b/utilities.h index 3e03382..29a0d4b 100644 --- a/utilities.h +++ b/utilities.h @@ -12,9 +12,7 @@ BOOL IsUrlContains(TCHAR * Str); void DeleteCListGroupsByName(TCHAR* szGroupName); tstring GetContactUid(HANDLE hContact, std::string Protocol); void LogSpamToFile(HANDLE hContact, tstring message); -struct hContact_entry -{ - HANDLE hContact; - struct hContact_entry *next; -}; - +std::string toUTF8(std::wstring str); +std::string toUTF8(std::string str); +std::wstring toUTF16(std::string str); +void HistoryLogFunc(HANDLE hContact, std::string message);
\ No newline at end of file |