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 /utilities.cpp | |
parent | 805aae34900744c6904cad9437506fdf860e12e7 (diff) |
another cleanup method
regex
history log
Diffstat (limited to 'utilities.cpp')
-rw-r--r-- | utilities.cpp | 135 |
1 files changed, 130 insertions, 5 deletions
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;
+}
+
|