diff options
-rwxr-xr-x[-rw-r--r--] | globals.h | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | headers.h | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | init.cpp | 18 | ||||
-rwxr-xr-x[-rw-r--r--] | options.cpp | 18 | ||||
-rwxr-xr-x[-rw-r--r--] | resource.h | 5 | ||||
-rwxr-xr-x[-rw-r--r--] | stopspam.cpp | 72 | ||||
-rwxr-xr-x[-rw-r--r--] | stopspam.h | 1 | ||||
-rwxr-xr-x[-rw-r--r--] | stopspam.rc | 11 | ||||
-rwxr-xr-x[-rw-r--r--] | stopspam_10.vcxproj | 4 | ||||
-rwxr-xr-x[-rw-r--r--] | utilities.cpp | 216 | ||||
-rwxr-xr-x[-rw-r--r--] | utilities.h | 3 |
11 files changed, 233 insertions, 118 deletions
diff --git a/globals.h b/globals.h index 790458e..790458e 100644..100755 --- a/globals.h +++ b/globals.h diff --git a/headers.h b/headers.h index 46b56b6..d1b6b31 100644..100755 --- a/headers.h +++ b/headers.h @@ -35,6 +35,9 @@ #include <boost/thread.hpp> #include <boost/regex.hpp> #include <boost/algorithm/string.hpp> +#include <boost/nondet_random.hpp> +#include <boost/random/variate_generator.hpp> +#include <boost/random/uniform_int.hpp> //utf8cpp #include <utf8.h> @@ -25,8 +25,9 @@ BOOL gbLogToFile=0; BOOL gbAutoAuth=0; BOOL gbAutoAddToServerList=0; BOOL gbAutoReqAuth=1; -
-HANDLE hStopSpamLogDirH=0;
+BOOL gbMathExpression = 0; + +HANDLE hStopSpamLogDirH=0; tstring gbSpammersGroup = _T("Spammers"); tstring gbAutoAuthGroup = _T("NotSpammers"); @@ -163,6 +164,7 @@ void InitVars() gbAutoReqAuth=DBGetContactSettingByte(NULL, pluginName, "AutoReqAuth", 0); gbLogToFile=DBGetContactSettingByte(NULL, pluginName, "LogSpamToFile", 0); gbHistoryLog = DBGetContactSettingByte(NULL, pluginName, "HistoryLog", 0); + gbMathExpression = DBGetContactSettingByte(NULL, pluginName, "MathExpression", 0); } @@ -176,12 +178,12 @@ static int OnSystemModulesLoaded(WPARAM wParam,LPARAM lParam) void CleanThread(); if(gbDelAllTempory || gbDelExcluded) boost::thread *thr = new boost::thread(&CleanThread); - // Folders plugin support
- if (ServiceExists(MS_FOLDERS_REGISTER_PATH))
- {
- hStopSpamLogDirH = (HANDLE) FoldersRegisterCustomPath("StopSpam", "StopSpam Logs",
- PROFILE_PATH "\\" CURRENT_PROFILE "\\StopSpamLog");
- }
+ // Folders plugin support + if (ServiceExists(MS_FOLDERS_REGISTER_PATH)) + { + hStopSpamLogDirH = (HANDLE) FoldersRegisterCustomPath("StopSpam", "StopSpam Logs", + PROFILE_PATH "\\" CURRENT_PROFILE "\\StopSpamLog"); + } return 0; } diff --git a/options.cpp b/options.cpp index 2905b76..e4c7bd6 100644..100755 --- a/options.cpp +++ b/options.cpp @@ -86,6 +86,7 @@ INT_PTR CALLBACK MessagesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar SetDlgItemText(hwnd, ID_ANSWER, gbAnswer.c_str()); SetDlgItemText(hwnd, ID_CONGRATULATION, gbCongratulation.c_str()); SetDlgItemText(hwnd, ID_AUTHREPL, gbAuthRepl.c_str()); + EnableWindow(GetDlgItem(hwnd, ID_ANSWER), !gbMathExpression); variables_skin_helpbutton(hwnd, IDC_VARS); gbVarsServiceExist?EnableWindow(GetDlgItem(hwnd, IDC_VARS),1):EnableWindow(GetDlgItem(hwnd, IDC_VARS),0); } @@ -278,6 +279,7 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar 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); + SendDlgItemMessage(hwnd, IDC_MATH_QUESTION, BM_SETCHECK, gbMathExpression ? BST_CHECKED : BST_UNCHECKED, 0 ); SetDlgItemText(hwnd, IDC_AUTOADDGROUP, gbAutoAuthGroup.c_str()); } @@ -285,6 +287,11 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar case WM_COMMAND:{ switch (LOWORD(wParam)) { + case IDC_MATH_DETAILS: + { + MessageBox(NULL, TranslateT("If math expression is turned on you can use following expression in message text:\nXX+XX-X/X*X\neach X will be replaced by one ruandom number and answer will be expression result\nMessage must contain only one expression without spaces"), _T("Info"), MB_OK); + } + break; case IDC_INVIS_DISABLE: case IDC_CASE_INSENSITIVE: case ID_DOS_INTEGRATION: @@ -365,10 +372,13 @@ 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", gbRegexMatch =
- BST_CHECKED == SendDlgItemMessage(hwnd, IDC_REGEX, BM_GETCHECK, 0, 0));
- DBWriteContactSettingByte(NULL, pluginName, "HistoryLog", gbHistoryLog =
- BST_CHECKED == SendDlgItemMessage(hwnd, IDC_HISTORY_LOG, BM_GETCHECK, 0, 0));
+ DBWriteContactSettingByte(NULL, pluginName, "RegexMatch", gbRegexMatch = + BST_CHECKED == SendDlgItemMessage(hwnd, IDC_REGEX, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "HistoryLog", gbHistoryLog = + BST_CHECKED == SendDlgItemMessage(hwnd, IDC_HISTORY_LOG, BM_GETCHECK, 0, 0)); + DBWriteContactSettingByte(NULL, pluginName, "MathExpression", gbMathExpression = + BST_CHECKED == SendDlgItemMessage(hwnd, IDC_MATH_QUESTION, BM_GETCHECK, 0, 0)); + { static tstring NewAGroupName, CurrentAGroupName; NewAGroupName = GetDlgItemString(hwnd, IDC_AUTOADDGROUP); diff --git a/resource.h b/resource.h index 47ce7f1..05f1ba3 100644..100755 --- a/resource.h +++ b/resource.h @@ -52,6 +52,9 @@ #define IDC_REGEX 1028
#define IDC_CHECK1 1029
#define IDC_HISTORY_LOG 1029
+#define IDC_MATH_QUESTION 1030
+#define IDC_BUTTON2 1031
+#define IDC_MATH_DETAILS 1031
// Next default values for new objects
//
@@ -59,7 +62,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1030
+#define _APS_NEXT_CONTROL_VALUE 1032
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/stopspam.cpp b/stopspam.cpp index 8ca9111..7df9a0b 100644..100755 --- a/stopspam.cpp +++ b/stopspam.cpp @@ -133,6 +133,7 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) // if message contains right answer... BYTE msg = 1; + static int math_answer = 0; if(gbInvisDisable) { if(CallProtoService(dbei->szModule, PS_GETSTATUS, 0, 0) == ID_STATUS_INVISIBLE) @@ -155,9 +156,9 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) } 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);
+ 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) @@ -219,7 +220,70 @@ MIRANDA_HOOK_EVENT(ME_DB_EVENT_FILTER_ADD, w, l) tstring q; if(gbInfTalkProtection) q += _T("StopSpam automatic message:\r\n"); - q += variables_parse(gbQuestion, hContact); + if(gbMathExpression) + { //parse math expression in question + tstring tmp_question = gbQuestion; + std::list<int> args; + std::list<TCHAR> actions; + std::string arg; + tstring::size_type p1 = gbQuestion.find(_T("X")), p2 = 0; + const tstring expr_chars = _T("X+-/*"); + while(expr_chars.find(gbQuestion[p1]) != tstring::npos) + { + p2 = p1; + for(p1 = gbQuestion.find(_T("X"), p1); p1 != tstring::npos; ++p1) + arg += get_random_num(1); +#ifdef UNICODE + tmp_question.replace(p2, arg.size(), toUTF16(arg)); +#else + tmp_question.replace(p2, arg.size(), arg); +#endif + args.push_back(atoi(arg.c_str())); + actions.push_back(gbQuestion[p1]); + ++p1; + } + math_answer = args.front(); + args.pop_front(); + while(!args.empty()) + { + if(!actions.empty()) + { + switch(actions.front()) + { + case _T('+'): + { + math_answer += args.front(); + args.pop_front(); + } + break; + case _T('-'): + { + math_answer -= args.front(); + args.pop_front(); + } + break; + case _T('/'): + { + math_answer /= args.front(); + args.pop_front(); + } + break; + case _T('*'): + { + math_answer *= args.front(); + args.pop_front(); + } + break; + } + actions.pop_front(); + } + else + break; + } + q += variables_parse(tmp_question, hContact); + } + else + q += variables_parse(gbQuestion, hContact); #ifdef _UNICODE char * buf=mir_utf8encodeW(q.c_str()); diff --git a/stopspam.h b/stopspam.h index 14202c7..94300b9 100644..100755 --- a/stopspam.h +++ b/stopspam.h @@ -17,6 +17,7 @@ extern BOOL gbRegexMatch; extern BOOL gbHistoryLog; extern BOOL gbInvisDisable; extern BOOL gbIgnoreURL; +extern BOOL gbMathExpression; extern tstring gbSpammersGroup; extern tstring gbQuestion; extern tstring gbAnswer; diff --git a/stopspam.rc b/stopspam.rc index 8c09470..1eec252 100644..100755 --- a/stopspam.rc +++ b/stopspam.rc @@ -13,7 +13,7 @@ #undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
-// Russian (Russia) resources
+// Русский (Россия) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
@@ -102,6 +102,9 @@ BEGIN "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
+ CONTROL "Use math expression in question",IDC_MATH_QUESTION,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,188,129,10
+ PUSHBUTTON "Details..",IDC_MATH_DETAILS,152,187,50,14
END
@@ -188,12 +191,12 @@ BEGIN END
END
-#endif // Russian (Russia) resources
+#endif // Русский (Россия) resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-// English (United States) resources
+// Английский (США) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
@@ -224,7 +227,7 @@ END #endif // APSTUDIO_INVOKED
-#endif // English (United States) resources
+#endif // Английский (США) resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/stopspam_10.vcxproj b/stopspam_10.vcxproj index cd4e6fe..07e6524 100644..100755 --- a/stopspam_10.vcxproj +++ b/stopspam_10.vcxproj @@ -239,7 +239,7 @@ </PreBuildEvent>
<ClCompile>
<Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>C:\Boost\include\boost-1_45;X:\temp\windows\libs\utf8cpp\include;X:\install\git\miranda\miranda-im\miranda\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>X:\temp\windows\libs\Boost\include;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>
@@ -259,7 +259,7 @@ </DataExecutionPrevention>
<ImportLibrary>$(OutDir)stopspam.lib</ImportLibrary>
<TargetMachine>MachineX86</TargetMachine>
- <AdditionalLibraryDirectories>C:\Boost\lib-debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>X:\temp\windows\libs\Boost\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
diff --git a/utilities.cpp b/utilities.cpp index 19c2d79..660a203 100644..100755 --- a/utilities.cpp +++ b/utilities.cpp @@ -381,13 +381,13 @@ boost::mutex clean_mutex; void CleanProtocolTmpThread(std::string proto) { - while(true)
- {
- UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0);
- if(status > ID_STATUS_OFFLINE)
- break;
- boost::this_thread::sleep(boost::posix_time::seconds(2));
- }
+ while(true) + { + UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); + if(status > ID_STATUS_OFFLINE) + break; + boost::this_thread::sleep(boost::posix_time::seconds(2)); + } std::list<HANDLE> contacts; for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) { @@ -397,11 +397,11 @@ void CleanProtocolTmpThread(std::string proto) if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0)|| (_T("Not In List")== DBGetContactSettingStringPAN(hContact,"CList","Group",_T("")))) contacts.push_back(hContact); } - boost::this_thread::sleep(boost::posix_time::seconds(5));
+ boost::this_thread::sleep(boost::posix_time::seconds(5)); clean_mutex.lock(); std::list<HANDLE>::iterator end = contacts.end(); for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i) - {
+ { LogSpamToFile(*i, _T("Deleted")); HistoryLogFunc(*i, "Deleted"); CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0); @@ -409,41 +409,41 @@ void CleanProtocolTmpThread(std::string proto) clean_mutex.unlock(); } -void CleanProtocolExclThread(std::string proto)
-{
- while(true)
- {
- UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0);
- if(status > ID_STATUS_OFFLINE)
- break;
- boost::this_thread::sleep(boost::posix_time::seconds(2));
- }
- std::list<HANDLE> contacts;
- for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0))
- {
- char *proto_tmp = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
- if(proto_tmp)
- if(!strcmp(proto.c_str(), proto_tmp))
- if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && DBGetContactSettingByte(hContact, pluginName, "Excluded", 0))
- contacts.push_back(hContact);
- }
- boost::this_thread::sleep(boost::posix_time::seconds(5));
- clean_mutex.lock();
- std::list<HANDLE>::iterator end = contacts.end();
- for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i)
- {
- LogSpamToFile(*i, _T("Deleted"));
- HistoryLogFunc(*i, "Deleted");
- CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0);
- }
- clean_mutex.unlock();
-}
+void CleanProtocolExclThread(std::string proto) +{ + while(true) + { + UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); + if(status > ID_STATUS_OFFLINE) + break; + boost::this_thread::sleep(boost::posix_time::seconds(2)); + } + std::list<HANDLE> contacts; + for(HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); hContact; hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)) + { + char *proto_tmp = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if(proto_tmp) + if(!strcmp(proto.c_str(), proto_tmp)) + if(DBGetContactSettingByte(hContact, "CList", "NotOnList", 0) && DBGetContactSettingByte(hContact, pluginName, "Excluded", 0)) + contacts.push_back(hContact); + } + boost::this_thread::sleep(boost::posix_time::seconds(5)); + clean_mutex.lock(); + std::list<HANDLE>::iterator end = contacts.end(); + for(std::list<HANDLE>::iterator i = contacts.begin(); i != end; ++i) + { + LogSpamToFile(*i, _T("Deleted")); + HistoryLogFunc(*i, "Deleted"); + CallService(MS_DB_CONTACT_DELETE, (WPARAM)*i, 0); + } + clean_mutex.unlock(); +} void CleanThread() { - std::list<std::string> protocols;
- int count = 0;
+ std::list<std::string> protocols; + int count = 0; PROTOACCOUNT **accounts; ProtoEnumAccounts(&count, &accounts); for(int i = 0; i < count; i++) @@ -452,7 +452,7 @@ void CleanThread() protocols.push_back(accounts[i]->szModuleName); } std::list<std::string>::iterator end = protocols.end(); - for(std::list<std::string>::iterator i = protocols.begin(); i != end; ++i)
+ for(std::list<std::string>::iterator i = protocols.begin(); i != end; ++i) { if(gbDelAllTempory) boost::thread *thr = new boost::thread(boost::bind(&CleanProtocolTmpThread, *i)); @@ -460,56 +460,84 @@ void CleanThread() boost::thread *thr = new boost::thread(boost::bind(&CleanProtocolExclThread, *i)); } } -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)
- {
- if(hContact == INVALID_HANDLE_VALUE)
- return;
- 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, DBEF_READ);
- }
-}
-
-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;
-}
-
+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) + { + if(hContact == INVALID_HANDLE_VALUE) + return; + 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, DBEF_READ); + } +} + +std::string toUTF8(std::wstring str) +{ + std::string ustr; + try{ + utf8::utf16to8(str.begin(), str.end(), back_inserter(ustr)); + } + catch(const std::exception &e) + { + //TODO: handle utf8cpp exceptions + } + return ustr; +} + +std::string toUTF8(std::string str) +{ + std::string ustr; + std::string tmpstr; + try{ + utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); + utf8::utf16to8(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); + } + catch(const std::exception &e) + { + //TODO: handle utf8cpp exceptions + } + return ustr; +} + + +std::wstring toUTF16(std::string str) //convert as much as possible +{ + std::wstring ustr; + std::string tmpstr; + try{ + utf8::replace_invalid(str.begin(), str.end(), back_inserter(tmpstr)); + utf8::utf8to16(tmpstr.begin(), tmpstr.end(), back_inserter(ustr)); + } + catch(const std::exception &e) + { + //TODO: handle utf8cpp exceptions + } + return ustr; +} + +std::string get_random_num(int length) +{ + std::string chars("123456789"); + std::string data; + boost::random_device rng; + boost::variate_generator<boost::random_device&, boost::uniform_int<>> gen(rng, boost::uniform_int<>(0, chars.length()-1)); + for(int i = 0; i < length; ++i) + data += chars[gen()]; + return data; +} diff --git a/utilities.h b/utilities.h index 29a0d4b..62a3ef5 100644..100755 --- a/utilities.h +++ b/utilities.h @@ -15,4 +15,5 @@ void LogSpamToFile(HANDLE hContact, tstring message); 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 +void HistoryLogFunc(HANDLE hContact, std::string message); +std::string get_random_num(int length);
\ No newline at end of file |