From 03a0b643b94d5aa7f9c129fe73eea314d099cf56 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 7 Sep 2013 12:09:27 +0000 Subject: shameful end of the group processing zoo, part 1 git-svn-id: http://svn.miranda-ng.org/main/trunk@5994 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/AimOscar/src/utility.cpp | 2 +- protocols/FacebookRM/src/connection.cpp | 2 +- protocols/FacebookRM/src/dialogs.cpp | 2 +- protocols/Gadu-Gadu/src/import.cpp | 82 ++------------------------- protocols/IcqOscarJ/src/icq_proto.h | 1 - protocols/IcqOscarJ/src/icq_servlist.cpp | 49 ++-------------- protocols/JabberG/src/jabber.h | 1 - protocols/JabberG/src/jabber_iq_handlers.cpp | 8 +-- protocols/JabberG/src/jabber_iqid.cpp | 5 +- protocols/JabberG/src/jabber_misc.cpp | 49 ---------------- protocols/JabberG/src/jabber_privacy.cpp | 26 +-------- protocols/MSN/src/msn_srv.cpp | 6 +- protocols/Skype/src/skype_account.cpp | 2 +- protocols/Skype/src/skype_dialogs.cpp | 2 +- protocols/Tlen/src/tlen.h | 2 - protocols/Tlen/src/tlen_avatar.cpp | 6 +- protocols/Tlen/src/tlen_file.cpp | 4 +- protocols/Tlen/src/tlen_iqid.cpp | 4 +- protocols/Tlen/src/tlen_misc.cpp | 85 ---------------------------- protocols/Tlen/src/tlen_muc.cpp | 2 +- protocols/Tlen/src/tlen_p2p_new.cpp | 6 +- protocols/Tlen/src/tlen_p2p_old.cpp | 4 +- protocols/Tlen/src/tlen_picture.cpp | 4 +- protocols/Tlen/src/tlen_svc.cpp | 12 ++-- protocols/Tlen/src/tlen_thread.cpp | 6 +- protocols/Tlen/src/tlen_voice.cpp | 8 +-- 26 files changed, 51 insertions(+), 329 deletions(-) (limited to 'protocols') diff --git a/protocols/AimOscar/src/utility.cpp b/protocols/AimOscar/src/utility.cpp index 1600e3dc3a..1ae59c437f 100644 --- a/protocols/AimOscar/src/utility.cpp +++ b/protocols/AimOscar/src/utility.cpp @@ -372,7 +372,7 @@ void create_group(const char *group) if (strcmp(group, AIM_DEFAULT_GROUP) == 0) return; TCHAR* szGroupName = mir_utf8decodeT(group); - CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)szGroupName); + Clist_CreateGroup(0, szGroupName); mir_free(szGroupName); } diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index afe0fbcf45..38e00a4fc2 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -187,7 +187,7 @@ bool FacebookProto::NegotiateConnection() // Create default group for new contacts ptrT groupName( getTStringA(FACEBOOK_KEY_DEF_GROUP)); if (groupName != NULL) - CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)groupName); + Clist_CreateGroup(0, groupName); return facy.login(user, pass); } diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp index 1d968768af..b2181d8aa9 100644 --- a/protocols/FacebookRM/src/dialogs.cpp +++ b/protocols/FacebookRM/src/dialogs.cpp @@ -422,7 +422,7 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp if (lstrlen(tstr) > 0) { proto->setTString(FACEBOOK_KEY_DEF_GROUP, tstr); - CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)tstr); + Clist_CreateGroup( 0, tstr); } else proto->delSetting(FACEBOOK_KEY_DEF_GROUP); diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index 11cf777cd9..6299539c8a 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -20,81 +20,6 @@ #include "gg.h" -//////////////////////////////////////////////////////////////////////////////// -// Checks if a group already exists in Miranda with -// the specified name. -// Returns 1 if a group with the name exists, returns 0 otherwise. -int GroupNameExists(const char *name) -{ - char idstr[33]; - DBVARIANT dbv; - int i; - - for (i = 0; ; i++) { - _itoa(i, idstr, 10); - if (db_get_s(NULL, "CListGroups", idstr, &dbv, DBVT_ASCIIZ)) break; - if (!strcmp(dbv.pszVal + 1, name)) { - db_free(&dbv); - return 1; - } - db_free(&dbv); - } - return 0; -} - - -//////////////////////////////////////////////////////////////////////////////// -// Creates a group with a specified name in the -// Miranda contact list. -// Returns proper group name - -char *CreateGroup(char *groupName) -{ - int groupId; - char groupIdStr[11]; - char groupName2[127]; - char *p; - DBVARIANT dbv; - - // Cleanup group name from weird characters - - // Skip first break - while(*groupName && *groupName == '\\') groupName++; - - p = strrchr(groupName, '\\'); - // Cleanup end - while(p && !(*(p + 1))) - { - *p = 0; - p = strrchr(groupName, '\\'); - } - // Create upper groups - if (p) - { - *p = 0; - CreateGroup(groupName); - *p = '\\'; - } - - // Is this a duplicate? - if (!GroupNameExists(groupName)) - { - lstrcpynA(groupName2 + 1, groupName, (int)strlen(groupName) + 1); - - // Find an unused id - for (groupId = 0; ; groupId++) { - _itoa(groupId, groupIdStr,10); - if (db_get_s(NULL, "CListGroups", groupIdStr, &dbv, DBVT_ASCIIZ)) - break; - db_free(&dbv); - } - - groupName2[0] = 1|GROUPF_EXPANDED; // 1 is required so we never get '\0' - db_set_s(NULL, "CListGroups", groupIdStr, groupName2); - } - return groupName; -} - char *gg_makecontacts(GGPROTO *gg, int cr) { string_t s = string_init(NULL); @@ -290,8 +215,11 @@ void GGPROTO::parsecontacts(char *contacts) netlog("parsecontacts(): Found contact %d with nickname \"%s\".", uin, strNick); #endif // Write group - if (hContact && strGroup) - db_set_s(hContact, "CList", "Group", CreateGroup(strGroup)); + if (hContact && strGroup) { + ptrT tszGrpName( mir_a2t(strGroup)); + Clist_CreateGroup(0, tszGrpName); + db_set_ts(hContact, "CList", "Group", tszGrpName); + } // Write misc data if (hContact && strFirstName){ diff --git a/protocols/IcqOscarJ/src/icq_proto.h b/protocols/IcqOscarJ/src/icq_proto.h index af852a7b8f..98dfb90c1c 100644 --- a/protocols/IcqOscarJ/src/icq_proto.h +++ b/protocols/IcqOscarJ/src/icq_proto.h @@ -678,7 +678,6 @@ struct CIcqProto : public PROTO void resetServContactAuthState(HANDLE hContact, DWORD dwUin); void FlushSrvGroupsCache(); - int getCListGroupHandle(const char *szGroup); int getCListGroupExists(const char *szGroup); int moveContactToCListGroup(HANDLE hContact, const char *szGroup); /// TODO: this should be DB function diff --git a/protocols/IcqOscarJ/src/icq_servlist.cpp b/protocols/IcqOscarJ/src/icq_servlist.cpp index 7110e3ea2e..3d5c88e85d 100644 --- a/protocols/IcqOscarJ/src/icq_servlist.cpp +++ b/protocols/IcqOscarJ/src/icq_servlist.cpp @@ -1571,40 +1571,6 @@ void CIcqProto::setServListGroupLinkID(const char *szPath, WORD wGroupID) db_unset(NULL, szModule, szPath); } - -// this function takes all backslashes in szGroup as group-level separators -int CIcqProto::getCListGroupHandle(const char *szGroup) -{ - char *pszGroup = (char*)szGroup; - int hParentGroup = 0, hGroup = 0; - - if (!strlennull(szGroup)) return 0; // no group - - if (strrchr(szGroup, '\\')) - { // create parent group - char *szSeparator = (char*)strrchr(szGroup, '\\'); - - *szSeparator = '\0'; - hParentGroup = getCListGroupHandle(szGroup); - *szSeparator = '\\'; - // take only sub-group name - pszGroup = ++szSeparator; - } - - int size = strlennull(szGroup) + 2; - TCHAR *tszGroup = (TCHAR*)_alloca(size * sizeof(TCHAR)); - - if (utf8_to_tchar_static(pszGroup, tszGroup, size)) - hGroup = CallService(MS_CLIST_GROUPCREATE, hParentGroup, (LPARAM)tszGroup); // 0.7+ - -#ifdef _DEBUG - NetLog_Server("Obtained CList group \"%s\" handle %x", szGroup, hGroup); -#endif - - return hGroup; -} - - // determine if the specified clist group path exists //!! this function is not thread-safe due to the use of cli->pfnGetGroupName() int CIcqProto::getCListGroupExists(const char *szGroup) @@ -1612,7 +1578,6 @@ int CIcqProto::getCListGroupExists(const char *szGroup) if (!szGroup) return 0; - int hGroup = 0; int size = strlennull(szGroup) + 2; TCHAR *tszGroup = (TCHAR*)_alloca(size * sizeof(TCHAR)); @@ -1622,23 +1587,21 @@ int CIcqProto::getCListGroupExists(const char *szGroup) if (!tszGroupName) break; - if (!_tcscmp(tszGroup, tszGroupName)) { - // we have found the group - hGroup = i; - break; - } + // we have found the group + if (!_tcscmp(tszGroup, tszGroupName)) + return i; } - return hGroup; + return 0; } int CIcqProto::moveContactToCListGroup(HANDLE hContact, const char *szGroup) { - int hGroup = getCListGroupHandle(szGroup); + HANDLE hGroup = Clist_CreateGroup(0, _A2T(szGroup)); if (ServiceExists(MS_CLIST_CONTACTCHANGEGROUP)) - return CallService(MS_CLIST_CONTACTCHANGEGROUP, (WPARAM)hContact, hGroup); + return CallService(MS_CLIST_CONTACTCHANGEGROUP, (WPARAM)hContact, (LPARAM)hGroup); else /// TODO: is this neccessary ? return db_set_utf(hContact, "CList", "Group", szGroup); } diff --git a/protocols/JabberG/src/jabber.h b/protocols/JabberG/src/jabber.h index 1a20f671c9..585f434a88 100644 --- a/protocols/JabberG/src/jabber.h +++ b/protocols/JabberG/src/jabber.h @@ -676,7 +676,6 @@ int g_OnToolbarInit(WPARAM, LPARAM); void JabberChatDllError(void); int JabberCompareJids(const TCHAR *jid1, const TCHAR *jid2); -void JabberContactListCreateGroup(TCHAR* groupName); TCHAR* EscapeChatTags(TCHAR* pszText); TCHAR* UnEscapeChatTags(TCHAR* str_in); diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index 24d72a83f6..aa00846287 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -608,14 +608,12 @@ BOOL CJabberProto::OnRosterPushRequest(HXML, CJabberIqInfo *pInfo) } else db_unset(hContact, "CList", "MyHandle"); - if ( !m_options.IgnoreRosterGroups) - { + if ( !m_options.IgnoreRosterGroups) { if (item->group != NULL) { - JabberContactListCreateGroup(item->group); + Clist_CreateGroup(0, item->group); db_set_ts(hContact, "CList", "Group", item->group); } - else - db_unset(hContact, "CList", "Group"); + else db_unset(hContact, "CList", "Group"); } } mir_free(nick); diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 17c070d9fd..aa906cdc4e 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -484,7 +484,7 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo* pInfo) if ( !m_options.IgnoreRosterGroups) { if (item->group != NULL) { - JabberContactListCreateGroup(item->group); + Clist_CreateGroup(0, item->group); // Don't set group again if already correct, or Miranda may show wrong group count in some case DBVARIANT dbv; @@ -495,8 +495,7 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo* pInfo) } else db_set_ts(hContact, "CList", "Group", item->group); } - else - db_unset(hContact, "CList", "Group"); + else db_unset(hContact, "CList", "Group"); } if (hContact != NULL) { diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index f66613402b..d5f38fb6e7 100644 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -64,55 +64,6 @@ int JabberCompareJids(const TCHAR *jid1, const TCHAR *jid2) JabberStripJid(jid2, szTempJid2, SIZEOF(szTempJid2))); } -/////////////////////////////////////////////////////////////////////////////// -// JabberContactListCreateGroup() - -static void JabberContactListCreateClistGroup(TCHAR* groupName) -{ - char str[33]; - int i; - DBVARIANT dbv; - - for (i=0;;i++) { - _itoa(i, str, 10); - if ( db_get_ts(NULL, "CListGroups", str, &dbv)) - break; - TCHAR *name = dbv.ptszVal; - if (name[0]!='\0' && !_tcscmp(name+1, groupName)) { - // Already exists, no need to create - db_free(&dbv); - return; - } - db_free(&dbv); - } - - // Create new group with id = i (str is the text representation of i) - TCHAR newName[128]; - newName[0] = 1 | GROUPF_EXPANDED; - _tcsncpy(newName+1, groupName, SIZEOF(newName)-1); - newName[ SIZEOF(newName)-1] = '\0'; - db_set_ts(NULL, "CListGroups", str, newName); - CallService(MS_CLUI_GROUPADDED, i+1, 0); -} - -void JabberContactListCreateGroup(TCHAR* groupName) -{ - TCHAR name[128], *p; - - if (groupName == NULL || groupName[0]=='\0' || groupName[0]=='\\') return; - - _tcsncpy(name, groupName, SIZEOF(name)); - name[ SIZEOF(name)-1] = '\0'; - for (p=name; *p!='\0'; p++) { - if (*p == '\\') { - *p = '\0'; - JabberContactListCreateClistGroup(name); - *p = '\\'; - } - } - JabberContactListCreateClistGroup(name); -} - /////////////////////////////////////////////////////////////////////////////// // JabberDBAddAuthRequest() diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp index abe3a5dead..a0b7704844 100644 --- a/protocols/JabberG/src/jabber_privacy.cpp +++ b/protocols/JabberG/src/jabber_privacy.cpp @@ -642,7 +642,6 @@ protected: void CListResetOptions(HWND hwndList); void CListFilter(HWND hwndList); bool CListIsGroup(HANDLE hGroup); - HANDLE CListFindGroupByName(TCHAR *name); void CListResetIcons(HWND hwndList, HANDLE hItem, bool hide=false); void CListSetupIcons(HWND hwndList, HANDLE hItem, int iSlot, DWORD dwProcess, BOOL bAction); HANDLE CListAddContact(HWND hwndList, TCHAR *jid); @@ -1373,29 +1372,6 @@ bool CJabberDlgPrivacyLists::CListIsGroup(HANDLE hGroup) return result; } -HANDLE CJabberDlgPrivacyLists::CListFindGroupByName(TCHAR *name) -{ - char idstr[33]; - DBVARIANT dbv; - - HANDLE hGroup = 0; - - for (int i= 0; !hGroup; i++) - { - _itoa(i, idstr, 10); - - if ( db_get_ts(NULL, "CListGroups", idstr, &dbv)) - break; - - if ( !_tcscmp(dbv.ptszVal + 1, name)) - hGroup = (HANDLE)(i+1); - - db_free(&dbv); - } - - return hGroup; -} - void CJabberDlgPrivacyLists::CListResetIcons(HWND, HANDLE hItem, bool hide) { for (int i = 0; i < 4; i++) @@ -1477,7 +1453,7 @@ void CJabberDlgPrivacyLists::CListApplyList(HWND hwndList, CPrivacyList *pList) } case Group: { - HANDLE hGroup = CListFindGroupByName(pRule->GetValue()); + HANDLE hGroup = Clist_GroupExists(pRule->GetValue()); hItem = m_clcClist.FindGroup(hGroup); break; } diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp index 984f49d2c6..1fcdb0eba2 100644 --- a/protocols/MSN/src/msn_srv.cpp +++ b/protocols/MSN/src/msn_srv.cpp @@ -39,11 +39,7 @@ void CMsnProto::MSN_AddGroup(const char* grpName, const char *grpId, bool init) grpList.insert(p); if (init) - { - TCHAR* szGroupName = mir_utf8decodeT(grpName); - CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)szGroupName); - mir_free(szGroupName); - } + Clist_CreateGroup(0, ptrT( mir_utf8decodeT(grpName))); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Skype/src/skype_account.cpp b/protocols/Skype/src/skype_account.cpp index d62613e1d1..218639d919 100644 --- a/protocols/Skype/src/skype_account.cpp +++ b/protocols/Skype/src/skype_account.cpp @@ -151,7 +151,7 @@ void CSkypeProto::SetAccountSettings() if ( !getTString(SKYPE_SETTINGS_DEF_GROUP, &dbv) && lstrlen(dbv.ptszVal) > 0) { this->Log(L"Setting default group for new contacts"); - ::CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)dbv.ptszVal); + ::Clist_CreateGroup(0, dbv.ptszVal); ::db_free(&dbv); } } diff --git a/protocols/Skype/src/skype_dialogs.cpp b/protocols/Skype/src/skype_dialogs.cpp index 88d0254bcc..3a830b2471 100644 --- a/protocols/Skype/src/skype_dialogs.cpp +++ b/protocols/Skype/src/skype_dialogs.cpp @@ -174,7 +174,7 @@ INT_PTR CALLBACK CSkypeProto::SkypeMainOptionsProc(HWND hwnd, UINT message, WPAR if (lstrlen(tstr) > 0) { ::db_set_ts(NULL, proto->m_szModuleName, SKYPE_SETTINGS_DEF_GROUP, tstr); - ::CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)tstr); + ::Clist_CreateGroup(0, tstr); } else ::db_unset(NULL, proto->m_szModuleName, SKYPE_SETTINGS_DEF_GROUP); diff --git a/protocols/Tlen/src/tlen.h b/protocols/Tlen/src/tlen.h index e271a3d915..c6b4b64845 100644 --- a/protocols/Tlen/src/tlen.h +++ b/protocols/Tlen/src/tlen.h @@ -496,8 +496,6 @@ void TlenStringAppend(char **str, int *sizeAlloced, const char *fmt, ...); void TlenDBAddEvent(TlenProtocol *proto, HANDLE hContact, int eventType, DWORD flags, PBYTE pBlob, DWORD cbBlob); void TlenDBAddAuthRequest(TlenProtocol *proto, char *jid, char *nick); HANDLE TlenDBCreateContact(TlenProtocol *proto, char *jid, char *nick, BOOL temporary); -void TlenContactListCreateGroup(char *groupName); -unsigned long TlenForkThread(void (__cdecl *threadcode)(void*), unsigned long stacksize, void *arg); // tlen_svc.cpp int TlenRunSearch(TlenProtocol *proto); // tlen_opt.cpp diff --git a/protocols/Tlen/src/tlen_avatar.cpp b/protocols/Tlen/src/tlen_avatar.cpp index f832ba9188..2fd8436226 100644 --- a/protocols/Tlen/src/tlen_avatar.cpp +++ b/protocols/Tlen/src/tlen_avatar.cpp @@ -298,7 +298,7 @@ void TlenGetAvatar(TlenProtocol *proto, HANDLE hContact) { TLENGETAVATARTHREADDATA *data = (TLENGETAVATARTHREADDATA *)mir_alloc(sizeof(TLENGETAVATARTHREADDATA)); data->proto = proto; data->hContact = hContact; - TlenForkThread(TlenGetAvatarThread, 0, data); + forkthread(TlenGetAvatarThread, 0, data); } } @@ -361,7 +361,7 @@ void TlenRemoveAvatar(TlenProtocol *proto) { req->cbSize = sizeof(NETLIBHTTPREQUEST); req->requestType = proto->threadData->tlenConfig.avatarGetMthd; req->szUrl = request; - TlenForkThread(TlenRemoveAvatarRequestThread, 0, data); + forkthread(TlenRemoveAvatarRequestThread, 0, data); } } @@ -401,7 +401,7 @@ void TlenUploadAvatar(TlenProtocol *proto, unsigned char *data, int dataLen, int threadData->data = (char *) mir_alloc(dataLen); memcpy(threadData->data, data, dataLen); threadData->length = dataLen; - TlenForkThread(TlenUploadAvatarRequestThread, 0, threadData); + forkthread(TlenUploadAvatarRequestThread, 0, threadData); } } diff --git a/protocols/Tlen/src/tlen_file.cpp b/protocols/Tlen/src/tlen_file.cpp index 2bfb56f791..fed69c8ae6 100644 --- a/protocols/Tlen/src/tlen_file.cpp +++ b/protocols/Tlen/src/tlen_file.cpp @@ -654,7 +654,7 @@ void TlenProcessF(XmlNode *node, ThreadData *info) if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) { if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { if (!strcmp(item->ft->jid, jid)) - TlenForkThread((void (__cdecl *)(void*))TlenFileSendingThread, 0, item->ft); + forkthread((void (__cdecl *)(void*))TlenFileSendingThread, 0, item->ft); } } } @@ -666,7 +666,7 @@ void TlenProcessF(XmlNode *node, ThreadData *info) item->ft->hostName = mir_strdup(p); if ((p=TlenXmlGetAttrValue(node, "p")) != NULL) { item->ft->wPort = atoi(p); - TlenForkThread((void (__cdecl *)(void*))TlenFileReceiveThread, 0, item->ft); + forkthread((void (__cdecl *)(void*))TlenFileReceiveThread, 0, item->ft); } } } diff --git a/protocols/Tlen/src/tlen_iqid.cpp b/protocols/Tlen/src/tlen_iqid.cpp index a9637df40c..a7638ad549 100644 --- a/protocols/Tlen/src/tlen_iqid.cpp +++ b/protocols/Tlen/src/tlen_iqid.cpp @@ -107,7 +107,7 @@ void TlenResultSetRoster(TlenProtocol *proto, XmlNode *queryNode) { if (item->group) mir_free(item->group); if ((groupNode=TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) { item->group = TlenGroupDecode(groupNode->text); - TlenContactListCreateGroup(item->group); + Clist_CreateGroup(0, _A2T(item->group)); // Don't set group again if already correct, or Miranda may show wrong group count in some case if (!db_get(hContact, "CList", "Group", &dbv)) { if (strcmp(dbv.pszVal, item->group)) @@ -179,7 +179,7 @@ void TlenIqResultRoster(TlenProtocol *proto, XmlNode *iqNode) if (item->group) mir_free(item->group); if ((groupNode=TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) { item->group = TlenGroupDecode(groupNode->text); - TlenContactListCreateGroup(item->group); + Clist_CreateGroup(0, _A2T(item->group)); // Don't set group again if already correct, or Miranda may show wrong group count in some case if (!db_get(hContact, "CList", "Group", &dbv)) { if (strcmp(dbv.pszVal, item->group)) diff --git a/protocols/Tlen/src/tlen_misc.cpp b/protocols/Tlen/src/tlen_misc.cpp index 4c05d5e566..7876d2348e 100644 --- a/protocols/Tlen/src/tlen_misc.cpp +++ b/protocols/Tlen/src/tlen_misc.cpp @@ -123,88 +123,3 @@ HANDLE TlenDBCreateContact(TlenProtocol *proto, char *jid, char *nick, BOOL temp } return hContact; } - -static void TlenContactListCreateClistGroup(char *groupName) -{ - char str[33], newName[128]; - int i; - DBVARIANT dbv; - char *name; - - for (i=0;;i++) { - itoa(i, str, 10); - if (db_get(NULL, "CListGroups", str, &dbv)) - break; - name = dbv.pszVal; - if (name[0] != '\0' && !strcmp(name+1, groupName)) { - // Already exist, no need to create - db_free(&dbv); - return; - } - db_free(&dbv); - } - - // Create new group with id = i (str is the text representation of i) - newName[0] = 1 | GROUPF_EXPANDED; - strncpy(newName+1, groupName, sizeof(newName)-1); - newName[sizeof(newName)-1] = '\0'; - db_set_s(NULL, "CListGroups", str, newName); - CallService(MS_CLUI_GROUPADDED, i+1, 0); -} - -void TlenContactListCreateGroup(char *groupName) -{ - char name[128]; - char *p; - - if (groupName == NULL || groupName[0] == '\0' || groupName[0] == '\\') return; - - strncpy(name, groupName, sizeof(name)); - name[sizeof(name)-1] = '\0'; - for (p=name; *p != '\0'; p++) { - if (*p == '\\') { - *p = '\0'; - TlenContactListCreateClistGroup(name); - *p = '\\'; - } - } - TlenContactListCreateClistGroup(name); -} - - -struct FORK_ARG { - HANDLE hEvent; - void (__cdecl *threadcode)(void*); - void *arg; -}; - -static void __cdecl forkthread_r(struct FORK_ARG *fa) -{ - void (*callercode)(void*) = fa->threadcode; - void *arg = fa->arg; - Thread_Push(0); - SetEvent(fa->hEvent); - callercode(arg); - Thread_Pop(); - return; -} - -unsigned long TlenForkThread( - void (__cdecl *threadcode)(void*), - unsigned long stacksize, - void *arg -) -{ - unsigned long rc; - struct FORK_ARG fa; - - fa.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - fa.threadcode = threadcode; - fa.arg = arg; - rc = _beginthread((void (__cdecl *)(void*))forkthread_r, stacksize, &fa); - if ((unsigned long) -1L != rc) { - WaitForSingleObject(fa.hEvent, INFINITE); - } - CloseHandle(fa.hEvent); - return rc; -} diff --git a/protocols/Tlen/src/tlen_muc.cpp b/protocols/Tlen/src/tlen_muc.cpp index a62601b760..102a54ffbd 100644 --- a/protocols/Tlen/src/tlen_muc.cpp +++ b/protocols/Tlen/src/tlen_muc.cpp @@ -996,7 +996,7 @@ static int TlenMUCQueryContacts(TlenProtocol *proto, const char *roomId) { MUCSENDQUERYTHREADDATA *threadData = (MUCSENDQUERYTHREADDATA *)mir_alloc(sizeof(MUCSENDQUERYTHREADDATA)); threadData->proto = proto; threadData->roomId = mir_strdup(roomId); - TlenForkThread(TlenMUCCSendQueryResultThread, 0, (void *)threadData); + forkthread(TlenMUCCSendQueryResultThread, 0, (void *)threadData); return 1; } diff --git a/protocols/Tlen/src/tlen_p2p_new.cpp b/protocols/Tlen/src/tlen_p2p_new.cpp index 74e7e28f8d..c8a9c49ea2 100644 --- a/protocols/Tlen/src/tlen_p2p_new.cpp +++ b/protocols/Tlen/src/tlen_p2p_new.cpp @@ -331,8 +331,8 @@ void __cdecl TlenProcessP2P(XmlNode *node, ThreadData *info) { TlenBindUDPSocket(item->ft); TlenSend(info->proto, "", item->ft->jid, item->ft->localName, item->ft->wLocalPort, item->ft->localName, item->ft->wLocalPort, item->ft->id2); - TlenForkThread((void (__cdecl *)(void*))TlenNewFileReceiveThread, 0, item->ft); - TlenForkThread((void (__cdecl *)(void*))TlenNewFileSendThread, 0, item->ft); + forkthread((void (__cdecl *)(void*))TlenNewFileReceiveThread, 0, item->ft); + forkthread((void (__cdecl *)(void*))TlenNewFileSendThread, 0, item->ft); } } else if (!strcmp(s, "4")) { /* IP and port */ @@ -340,7 +340,7 @@ void __cdecl TlenProcessP2P(XmlNode *node, ThreadData *info) { TlenLog(info->proto, "step = 4"); item->ft->hostName = mir_strdup(TlenXmlGetAttrValue(dcng, "pa")); item->ft->wPort = atoi(TlenXmlGetAttrValue(dcng, "pp")); - TlenForkThread((void (__cdecl *)(void*))TlenNewFileReceiveThread, 0, item->ft); + forkthread((void (__cdecl *)(void*))TlenNewFileReceiveThread, 0, item->ft); } } diff --git a/protocols/Tlen/src/tlen_p2p_old.cpp b/protocols/Tlen/src/tlen_p2p_old.cpp index 4eb07d5be6..92ee4b6681 100644 --- a/protocols/Tlen/src/tlen_p2p_old.cpp +++ b/protocols/Tlen/src/tlen_p2p_old.cpp @@ -348,7 +348,7 @@ static TLEN_SOCKET TlenP2PBindSocks4(SOCKSBIND * sb, TLEN_FILE_TRANSFER *ft) strcpy(sb->szHost, inet_ntoa(in)); sb->wPort = htons(*(PWORD)(buf+2)); ft->s = s; - TlenForkThread((void (__cdecl *)(void*))TlenFileBindSocks4Thread, 0, ft); + forkthread((void (__cdecl *)(void*))TlenFileBindSocks4Thread, 0, ft); return s; } @@ -448,7 +448,7 @@ static TLEN_SOCKET TlenP2PBindSocks5(SOCKSBIND * sb, TLEN_FILE_TRANSFER *ft) sb->wPort = htons(*(PWORD)(buf+len)); ft->s = s; - TlenForkThread((void (__cdecl *)(void*))TlenFileBindSocks5Thread, 0, ft); + forkthread((void (__cdecl *)(void*))TlenFileBindSocks5Thread, 0, ft); return s; } diff --git a/protocols/Tlen/src/tlen_picture.cpp b/protocols/Tlen/src/tlen_picture.cpp index d121d0984e..25618f9bec 100644 --- a/protocols/Tlen/src/tlen_picture.cpp +++ b/protocols/Tlen/src/tlen_picture.cpp @@ -98,7 +98,7 @@ static void TlenPsPost(TlenProtocol *proto, TLEN_LIST_ITEM *item) { TLENPSREQUESTTHREADDATA *threadData = (TLENPSREQUESTTHREADDATA *)mir_alloc(sizeof(TLENPSREQUESTTHREADDATA)); threadData->proto = proto; threadData->item = item; - TlenForkThread(TlenPsPostThread, 0, threadData); + forkthread(TlenPsPostThread, 0, threadData); } static void TlenPsGetThread(void *ptr) { @@ -171,7 +171,7 @@ static void TlenPsGet(TlenProtocol *proto, TLEN_LIST_ITEM *item) { TLENPSREQUESTTHREADDATA *threadData = (TLENPSREQUESTTHREADDATA *)mir_alloc(sizeof(TLENPSREQUESTTHREADDATA)); threadData->proto = proto; threadData->item = item; - TlenForkThread(TlenPsGetThread, 0, threadData); + forkthread(TlenPsGetThread, 0, threadData); } void TlenProcessPic(XmlNode *node, TlenProtocol *proto) { diff --git a/protocols/Tlen/src/tlen_svc.cpp b/protocols/Tlen/src/tlen_svc.cpp index c8298b9b88..558358bb2e 100644 --- a/protocols/Tlen/src/tlen_svc.cpp +++ b/protocols/Tlen/src/tlen_svc.cpp @@ -359,7 +359,7 @@ static void TlenConnect(TlenProtocol *proto, int initialStatus) oldStatus = proto->m_iStatus; proto->m_iStatus = ID_STATUS_CONNECTING; ProtoBroadcastAck(proto->m_szModuleName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) oldStatus, proto->m_iStatus); - thread->hThread = (HANDLE) TlenForkThread((void (__cdecl *)(void*))TlenServerThread, 0, thread); + thread->hThread = (HANDLE) forkthread((void (__cdecl *)(void*))TlenServerThread, 0, thread); } } @@ -602,7 +602,7 @@ int TlenProtocol::SendMsg(HANDLE hContact, int flags, const char* msgRAW) char msgType[16]; if (!isOnline || db_get(hContact, m_szModuleName, "jid", &dbv)) { - TlenForkThread(TlenSendMessageFailedThread, 0, new SENDACKTHREADDATA(this, hContact, 2)); + forkthread(TlenSendMessageFailedThread, 0, new SENDACKTHREADDATA(this, hContact, 2)); return 2; } @@ -619,11 +619,11 @@ int TlenProtocol::SendMsg(HANDLE hContact, int flags, const char* msgRAW) if (!strcmp(msg, "")) { TlenSend(this, "", dbv.pszVal); - TlenForkThread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id)); + forkthread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id)); } else if (!strcmp(msg, "")) { TlenSend(this, "", dbv.pszVal, "pic", 0x757f044, id); - TlenForkThread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id)); + forkthread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id)); } else { if ((msgEnc=TlenTextEncode(msg)) != NULL) { @@ -645,7 +645,7 @@ int TlenProtocol::SendMsg(HANDLE hContact, int flags, const char* msgRAW) else TlenSend(this, "%s", dbv.pszVal, msgType, id, msgEnc); - TlenForkThread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id)); + forkthread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id)); } else { if ((item=TlenListGetItemPtr(this, LIST_ROSTER, dbv.pszVal)) != NULL) @@ -705,7 +705,7 @@ INT_PTR TlenProtocol::GetAvatarInfo(WPARAM wParam, LPARAM lParam) HANDLE TlenProtocol::GetAwayMsg(HANDLE hContact) { SENDACKTHREADDATA *tdata = new SENDACKTHREADDATA(this, hContact, 0); - TlenForkThread((void (__cdecl *)(void*))TlenGetAwayMsgThread, 0, (void*)tdata); + forkthread((void (__cdecl *)(void*))TlenGetAwayMsgThread, 0, (void*)tdata); return (HANDLE)1; } diff --git a/protocols/Tlen/src/tlen_thread.cpp b/protocols/Tlen/src/tlen_thread.cpp index 5f143389ae..f9fe2ef01e 100644 --- a/protocols/Tlen/src/tlen_thread.cpp +++ b/protocols/Tlen/src/tlen_thread.cpp @@ -277,7 +277,7 @@ void __cdecl TlenServerThread(ThreadData *info) if (info->proto->m_iDesiredStatus != ID_STATUS_OFFLINE) { info->proto->isConnected = TRUE; - TlenForkThread(TlenKeepAliveThread, 0, info->proto); + forkthread(TlenKeepAliveThread, 0, info->proto); TlenXmlInitState(&xmlState); TlenXmlSetCallback(&xmlState, 1, ELEM_OPEN, (void (__cdecl *)(XmlNode *,void *))TlenProcessStreamOpening, info); @@ -795,7 +795,7 @@ static void TlenProcessIq(XmlNode *node, ThreadData *info) if (item->group) mir_free(item->group); if ((groupNode=TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) { item->group = TlenGroupDecode(groupNode->text); - TlenContactListCreateGroup(item->group); + Clist_CreateGroup(0, _A2T(item->group)); db_set_s(hContact, "CList", "Group", item->group); } else { @@ -1353,7 +1353,7 @@ static void TlenProcessV(XmlNode *node, ThreadData *info) if ((p=TlenXmlGetAttrValue(node, "p")) != NULL) { item->ft->wPort = atoi(p); TlenVoiceStart(item->ft, 0); - //TlenForkThread((void (__cdecl *)(void*))TlenVoiceReceiveThread, 0, item->ft); + //forkthread((void (__cdecl *)(void*))TlenVoiceReceiveThread, 0, item->ft); } } } diff --git a/protocols/Tlen/src/tlen_voice.cpp b/protocols/Tlen/src/tlen_voice.cpp index a0b2c7ccd6..cff67606c0 100644 --- a/protocols/Tlen/src/tlen_voice.cpp +++ b/protocols/Tlen/src/tlen_voice.cpp @@ -936,11 +936,11 @@ int TlenVoiceStart(TLEN_FILE_TRANSFER *ft, int mode) TlenLog(ft->proto, "starting voice %d", mode); if (mode == 0) { - TlenForkThread((void (__cdecl *)(void*))TlenVoiceReceiveThread, 0, ft); + forkthread((void (__cdecl *)(void*))TlenVoiceReceiveThread, 0, ft); } else if (mode == 1) { - TlenForkThread((void (__cdecl *)(void*))TlenVoiceSendingThread, 0, ft); + forkthread((void (__cdecl *)(void*))TlenVoiceSendingThread, 0, ft); } else { - TlenForkThread((void (__cdecl *)(void*))TlenVoiceDlgThread, 0, ft); + forkthread((void (__cdecl *)(void*))TlenVoiceDlgThread, 0, ft); } return 0; } @@ -1065,7 +1065,7 @@ int TlenVoiceAccept(TlenProtocol *proto, const char *id, const char *from) ACCEPTDIALOGDATA *data = (ACCEPTDIALOGDATA *)mir_alloc(sizeof(ACCEPTDIALOGDATA)); data->proto = proto; data->item = item; - TlenForkThread((void (__cdecl *)(void*))TlenVoiceAcceptDlgThread, 0, data); + forkthread((void (__cdecl *)(void*))TlenVoiceAcceptDlgThread, 0, data); } else if (proto->isOnline) { item->ft = TlenFileCreateFT(proto, from); item->ft->iqId = mir_strdup(id); -- cgit v1.2.3