diff options
author | George Hazan <george.hazan@gmail.com> | 2013-09-07 12:09:27 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-09-07 12:09:27 +0000 |
commit | 03a0b643b94d5aa7f9c129fe73eea314d099cf56 (patch) | |
tree | 221081ffe0602905765815d302b02d1f761cf100 /protocols/Tlen/src | |
parent | 0ac4b544972fb011e7c7c69e60a1d5d180ada0ac (diff) |
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
Diffstat (limited to 'protocols/Tlen/src')
-rw-r--r-- | protocols/Tlen/src/tlen.h | 2 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_avatar.cpp | 6 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_file.cpp | 4 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_iqid.cpp | 4 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_misc.cpp | 85 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_muc.cpp | 2 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_p2p_new.cpp | 6 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_p2p_old.cpp | 4 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_picture.cpp | 4 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_svc.cpp | 12 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_thread.cpp | 6 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_voice.cpp | 8 |
12 files changed, 28 insertions, 115 deletions
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, "<iq to='%s'><query xmlns='p2p'><dcng la='%s' lp='%d' pa='%s' pp='%d' i='%s' k='5' s='4'/></query></iq>",
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, "<alert>")) {
TlenSend(this, "<m tp='a' to='%s'/>", dbv.pszVal);
- TlenForkThread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id));
+ forkthread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id));
}
else if (!strcmp(msg, "<image>")) {
TlenSend(this, "<message to='%s' type='%s' crc='%x' idt='%d'/>", 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, "<message to='%s' type='%s' id='"TLEN_IQID"%d'><body>%s</body><x xmlns='jabber:x:event'><composing/></x></message>", 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);
|