From 1468a7f080de048e7c301af58d890d530c5ee685 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Fri, 20 Feb 2015 22:55:24 +0000 Subject: Tlen: memory leaks fixed. git-svn-id: http://svn.miranda-ng.org/main/trunk@12225 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tlen/src/tlen_avatar.cpp | 47 +++++------- protocols/Tlen/src/tlen_file.cpp | 60 +++++++--------- protocols/Tlen/src/tlen_iqid.cpp | 61 ++++++++-------- protocols/Tlen/src/tlen_p2p_new.cpp | 42 +++++------ protocols/Tlen/src/tlen_svc.cpp | 140 ++++++++++++++++-------------------- protocols/Tlen/src/tlen_thread.cpp | 100 ++++++++++++++------------ 6 files changed, 208 insertions(+), 242 deletions(-) (limited to 'protocols/Tlen/src') diff --git a/protocols/Tlen/src/tlen_avatar.cpp b/protocols/Tlen/src/tlen_avatar.cpp index 2d00b0a5a7..ba336d2660 100644 --- a/protocols/Tlen/src/tlen_avatar.cpp +++ b/protocols/Tlen/src/tlen_avatar.cpp @@ -69,7 +69,7 @@ static void RemoveAvatar(TlenProtocol *proto, MCONTACT hContact) { if (hContact == NULL) { proto->threadData->avatarHash[0] = '\0'; } - TlenGetAvatarFileName( proto, NULL, tFileName, sizeof tFileName ); + TlenGetAvatarFileName( proto, NULL, tFileName, SIZEOF(tFileName)-1); DeleteFile(tFileName); db_unset(hContact, "ContactPhoto", "File"); db_unset(hContact, proto->m_szModuleName, "AvatarHash"); @@ -100,7 +100,7 @@ static void SetAvatar(TlenProtocol *proto, MCONTACT hContact, TLEN_LIST_ITEM *it proto->threadData->avatarFormat = format; strcpy(proto->threadData->avatarHash, md5); } - TlenGetAvatarFileName(proto, item, filename, sizeof filename ); + TlenGetAvatarFileName(proto, item, filename, SIZEOF(filename)-1); DeleteFile(filename); FILE *out = _tfopen(filename, TEXT("wb") ); if (out != NULL) { @@ -123,8 +123,7 @@ int TlenProcessAvatarNode(TlenProtocol *proto, XmlNode *avatarNode, TLEN_LIST_IT XmlNode *aNode; char *oldHash = NULL; char *md5 = NULL, *type = NULL; - MCONTACT hContact; - hContact = NULL; + MCONTACT hContact = NULL; if (item != NULL) { if ((hContact=TlenHContactFromJID(proto, item->jid)) == NULL) return 0; } @@ -165,9 +164,9 @@ int TlenProcessAvatarNode(TlenProtocol *proto, XmlNode *avatarNode, TLEN_LIST_IT } void TlenProcessPresenceAvatar(TlenProtocol *proto, XmlNode *node, TLEN_LIST_ITEM *item) { - MCONTACT hContact; - if ((hContact=TlenHContactFromJID(proto, item->jid)) == NULL) return; - TlenProcessAvatarNode(proto, TlenXmlGetChild(node, "avatar"), item); + MCONTACT hContact=TlenHContactFromJID(proto, item->jid); + if (hContact != NULL) + TlenProcessAvatarNode(proto, TlenXmlGetChild(node, "avatar"), item); } @@ -231,11 +230,8 @@ typedef struct { static void TlenGetAvatarThread(void *ptr) { TLEN_LIST_ITEM *item = NULL; - NETLIBHTTPREQUEST req; - NETLIBHTTPREQUEST *resp; TLENGETAVATARTHREADDATA *data = (TLENGETAVATARTHREADDATA *)ptr; MCONTACT hContact = data->hContact; - char *request; char *login = NULL; if (hContact != NULL) { char *jid = TlenJIDFromHContact(data->proto, hContact); @@ -251,7 +247,8 @@ static void TlenGetAvatarThread(void *ptr) { if (item != NULL) { item->newAvatarDownloading = TRUE; } - request = replaceTokens(data->proto->threadData->tlenConfig.mailBase, data->proto->threadData->tlenConfig.avatarGet, login, data->proto->threadData->avatarToken, 0, 0); + char *request = replaceTokens(data->proto->threadData->tlenConfig.mailBase, data->proto->threadData->tlenConfig.avatarGet, login, data->proto->threadData->avatarToken, 0, 0); + NETLIBHTTPREQUEST req; memset(&req, 0, sizeof(req)); req.cbSize = sizeof(req); req.requestType = data->proto->threadData->tlenConfig.avatarGetMthd; @@ -260,7 +257,7 @@ static void TlenGetAvatarThread(void *ptr) { req.headers = NULL; req.dataLength = 0; req.szUrl = request; - resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)&req); + NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)&req); if (item != NULL) { item->newAvatarDownloading = FALSE; } @@ -298,7 +295,8 @@ static void TlenGetAvatarThread(void *ptr) { } if (hContact == NULL) { getAvatarMutex = 0; - } + } + mir_free(login); mir_free(data); } @@ -323,10 +321,9 @@ typedef struct { } TLENREMOVEAVATARTHREADDATA; static void TlenRemoveAvatarRequestThread(void *ptr) { - NETLIBHTTPREQUEST *resp; TLENREMOVEAVATARTHREADDATA *data = (TLENREMOVEAVATARTHREADDATA*)ptr; NETLIBHTTPREQUEST *req = (NETLIBHTTPREQUEST *)data->req; - resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)req); + NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)req); mir_free(req->szUrl); mir_free(req->headers); mir_free(req->pData); @@ -366,10 +363,9 @@ boolean checkUploadAvatarResponse(TlenProtocol *proto, NETLIBHTTPREQUEST *resp){ } static void TlenUploadAvatarRequestThread(void *ptr) { - NETLIBHTTPREQUEST *resp; - TLENUPLOADAVATARTHREADDATA * data = (TLENUPLOADAVATARTHREADDATA *) ptr; + TLENUPLOADAVATARTHREADDATA *data = (TLENUPLOADAVATARTHREADDATA *) ptr; NETLIBHTTPREQUEST *req = data->req; - resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)req); + NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)req); if (checkUploadAvatarResponse(data->proto, resp)) { CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp); SetAvatar(data->proto, NULL, NULL, data->data, data->length, PA_FORMAT_PNG); @@ -383,14 +379,12 @@ static void TlenUploadAvatarRequestThread(void *ptr) { } void TlenRemoveAvatar(TlenProtocol *proto) { - NETLIBHTTPREQUEST *req; - char *request; if (proto->threadData != NULL) { TLENREMOVEAVATARTHREADDATA *data = (TLENREMOVEAVATARTHREADDATA *)mir_alloc(sizeof(TLENREMOVEAVATARTHREADDATA)); - req = (NETLIBHTTPREQUEST *)mir_alloc(sizeof(NETLIBHTTPREQUEST)); + NETLIBHTTPREQUEST *req = (NETLIBHTTPREQUEST *)mir_alloc(sizeof(NETLIBHTTPREQUEST)); data->proto =proto; data->req = req; - request = replaceTokens(proto->threadData->tlenConfig.mailBase, proto->threadData->tlenConfig.avatarRemove, "", proto->threadData->avatarToken, 0, 0); + char *request = replaceTokens(proto->threadData->tlenConfig.mailBase, proto->threadData->tlenConfig.avatarRemove, "", proto->threadData->avatarToken, 0, 0); memset(req, 0, sizeof(NETLIBHTTPREQUEST)); req->cbSize = sizeof(NETLIBHTTPREQUEST); req->requestType = proto->threadData->tlenConfig.avatarGetMthd; @@ -401,19 +395,16 @@ void TlenRemoveAvatar(TlenProtocol *proto) { void TlenUploadAvatar(TlenProtocol *proto, unsigned char *data, int dataLen, int access) { - NETLIBHTTPREQUEST *req; NETLIBHTTPHEADER *headers; - TLENUPLOADAVATARTHREADDATA *threadData; - char *request; unsigned char *buffer; if (proto->threadData != NULL && dataLen > 0 && data != NULL) { char *mpartHead = "--AaB03x\r\nContent-Disposition: form-data; name=\"filename\"; filename=\"plik.png\"\r\nContent-Type: image/png\r\n\r\n"; char *mpartTail = "\r\n--AaB03x--\r\n"; int size, sizeHead = (int)strlen(mpartHead), sizeTail = (int)strlen(mpartTail); - request = replaceTokens(proto->threadData->tlenConfig.mailBase, proto->threadData->tlenConfig.avatarUpload, "", proto->threadData->avatarToken, 0, access); - threadData = (TLENUPLOADAVATARTHREADDATA *)mir_alloc(sizeof(TLENUPLOADAVATARTHREADDATA)); + char *request = replaceTokens(proto->threadData->tlenConfig.mailBase, proto->threadData->tlenConfig.avatarUpload, "", proto->threadData->avatarToken, 0, access); + TLENUPLOADAVATARTHREADDATA *threadData = (TLENUPLOADAVATARTHREADDATA *)mir_alloc(sizeof(TLENUPLOADAVATARTHREADDATA)); threadData->proto = proto; - req = (NETLIBHTTPREQUEST *)mir_alloc(sizeof(NETLIBHTTPREQUEST)); + NETLIBHTTPREQUEST *req = (NETLIBHTTPREQUEST *)mir_alloc(sizeof(NETLIBHTTPREQUEST)); headers = (NETLIBHTTPHEADER *)mir_alloc(sizeof(NETLIBHTTPHEADER)); memset(req, 0, sizeof(NETLIBHTTPREQUEST)); req->cbSize = sizeof(NETLIBHTTPREQUEST); diff --git a/protocols/Tlen/src/tlen_file.cpp b/protocols/Tlen/src/tlen_file.cpp index ef073b9ec2..869097190d 100644 --- a/protocols/Tlen/src/tlen_file.cpp +++ b/protocols/Tlen/src/tlen_file.cpp @@ -31,9 +31,7 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) { int i; char *p; - TLEN_FILE_PACKET *rpacket, *packet; - - rpacket = NULL; + TLEN_FILE_PACKET *rpacket = NULL, *packet; if (ft->state == FT_CONNECTING) { rpacket = TlenP2PPacketReceive(ft->s); if (rpacket != NULL) { @@ -154,13 +152,10 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) static void TlenFileReceivingConnection(HANDLE hConnection, DWORD dwRemoteIP, void * pExtra) { - HANDLE slisten; - TLEN_FILE_TRANSFER *ft; - TlenProtocol *proto = (TlenProtocol *)pExtra; - ft = TlenP2PEstablishIncomingConnection(proto, hConnection, LIST_FILE, TRUE); + TLEN_FILE_TRANSFER *ft = TlenP2PEstablishIncomingConnection(proto, hConnection, LIST_FILE, TRUE); if (ft != NULL) { - slisten = ft->s; + HANDLE slisten = ft->s; ft->s = hConnection; ft->proto->debugLogA("Set ft->s to %d (saving %d)", hConnection, slisten); ft->proto->debugLogA("Entering send loop for this file connection... (ft->s is hConnection)"); @@ -211,14 +206,12 @@ static void __cdecl TlenFileReceiveThread(TLEN_FILE_TRANSFER *ft) ft->proto->debugLogA("Connection failed - receiving as server"); s = TlenP2PListen(ft); if (s != NULL) { - HANDLE hEvent; - char *nick; ft->s = s; - hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); ft->hFileEvent = hEvent; ft->currentFile = 0; ft->state = FT_CONNECTING; - nick = TlenNickFromJID(ft->jid); + char *nick = TlenNickFromJID(ft->jid); TlenSend(ft->proto, "", nick, ft->iqId, ft->localName, ft->wLocalPort); mir_free(nick); ft->proto->debugLogA("Waiting for the file to be received..."); @@ -235,8 +228,7 @@ static void __cdecl TlenFileReceiveThread(TLEN_FILE_TRANSFER *ft) if (ft->state == FT_DONE) ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ft, 0); else { - char *nick; - nick = TlenNickFromJID(ft->jid); + char *nick = TlenNickFromJID(ft->jid); TlenSend(ft->proto, "", nick, ft->iqId); mir_free(nick); ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); @@ -254,7 +246,7 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) char *p, *t; int currentFile, numRead; char *fileBuffer; - TLEN_FILE_PACKET *rpacket, *packet; + TLEN_FILE_PACKET *packet; if (ft->state == FT_CONNECTING) { @@ -291,7 +283,7 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) } } else if (ft->state == FT_INITIALIZING) { // FT_INITIALIZING - rpacket = TlenP2PPacketReceive(ft->s); + TLEN_FILE_PACKET *rpacket = TlenP2PPacketReceive(ft->s); ft->proto->debugLogA("FT_INITIALIZING: recv %d", rpacket); if (rpacket == NULL) { ft->state = FT_ERROR; @@ -301,7 +293,7 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) p = rpacket->packet; // TYPE: TLEN_FILE_PACKET_FILE_LIST_ACK will be ignored // LEN: 0 - if (rpacket->type == TLEN_FILE_PACKET_FILE_LIST_ACK) { + /*if (rpacket->type == TLEN_FILE_PACKET_FILE_LIST_ACK) { } // Then the receiver will request each file @@ -310,7 +302,7 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) // (DWORD) file number // (DWORD) 0 // (DWORD) 0 - else if (rpacket->type == TLEN_FILE_PACKET_FILE_REQUEST) { + else */if (rpacket->type == TLEN_FILE_PACKET_FILE_REQUEST) { PROTOFILETRANSFERSTATUS pfts; //struct _stat statbuf; @@ -388,6 +380,7 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) TlenP2PPacketFree(rpacket); } else { + TlenP2PPacketFree(rpacket); ft->state = FT_ERROR; } } @@ -396,10 +389,9 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) static void TlenFileSendingConnection(HANDLE hConnection, DWORD dwRemoteIP, void * pExtra) { HANDLE slisten; - TLEN_FILE_TRANSFER *ft; TlenProtocol *proto = (TlenProtocol *)pExtra; - ft = TlenP2PEstablishIncomingConnection(proto, hConnection, LIST_FILE, TRUE); + TLEN_FILE_TRANSFER *ft = TlenP2PEstablishIncomingConnection(proto, hConnection, LIST_FILE, TRUE); if (ft != NULL) { slisten = ft->s; ft->s = hConnection; @@ -428,12 +420,12 @@ static void TlenFileSendingConnection(HANDLE hConnection, DWORD dwRemoteIP, void int TlenFileCancelAll(TlenProtocol *proto) { - TLEN_LIST_ITEM *item; HANDLE hEvent; int i = 0; while ((i=TlenListFindNext(proto, LIST_FILE, 0)) >=0 ) { - if ((item=TlenListGetItemPtrFromIndex(proto, i)) != NULL) { + TLEN_LIST_ITEM *item = TlenListGetItemPtrFromIndex(proto, i); + if (item != NULL) { TLEN_FILE_TRANSFER *ft = item->ft; TlenListRemoveByIndex(proto, i); if (ft != NULL) { @@ -460,21 +452,19 @@ int TlenFileCancelAll(TlenProtocol *proto) static void __cdecl TlenFileSendingThread(TLEN_FILE_TRANSFER *ft) { - HANDLE s = NULL; - HANDLE hEvent; char *nick; ft->proto->debugLogA("Thread started: type=tlen_file_send"); ft->mode = FT_SEND; ft->pfnNewConnectionV2 = TlenFileSendingConnection; - s = TlenP2PListen(ft); + HANDLE s = TlenP2PListen(ft); if (s != NULL) { ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, ft, 0); ft->s = s; //TlenLog("ft->s = %d", s); //TlenLog("fileCount = %d", ft->fileCount); - hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); ft->hFileEvent = hEvent; ft->currentFile = 0; ft->state = FT_CONNECTING; @@ -544,8 +534,7 @@ static void __cdecl TlenFileSendingThread(TLEN_FILE_TRANSFER *ft) TLEN_FILE_TRANSFER *TlenFileCreateFT(TlenProtocol *proto, const char *jid) { - TLEN_FILE_TRANSFER *ft; - ft = (TLEN_FILE_TRANSFER *) mir_alloc(sizeof(TLEN_FILE_TRANSFER)); + TLEN_FILE_TRANSFER *ft = (TLEN_FILE_TRANSFER *) mir_alloc(sizeof(TLEN_FILE_TRANSFER)); memset(ft, 0, sizeof(TLEN_FILE_TRANSFER)); ft->proto = proto; ft->jid = mir_strdup(jid); @@ -558,8 +547,7 @@ TLEN_FILE_TRANSFER *TlenFileCreateFT(TlenProtocol *proto, const char *jid) { */ void TlenProcessF(XmlNode *node, ThreadData *info) { - TLEN_FILE_TRANSFER *ft; - char *from, *p, *e; + char *p; char jid[128], szFilename[MAX_PATH]; int numFiles; TLEN_LIST_ITEM *item; @@ -567,18 +555,18 @@ void TlenProcessF(XmlNode *node, ThreadData *info) // if (!node->name || strcmp(node->name, "f")) return; if (info == NULL) return; - if ((from=TlenXmlGetAttrValue(node, "f")) != NULL) { - + char *from=TlenXmlGetAttrValue(node, "f"); + if (from != NULL) { if (strchr(from, '@') == NULL) { mir_snprintf(jid, SIZEOF(jid), "%s@%s", from, info->server); } else { strncpy_s(jid, from, _TRUNCATE); } - if ((e=TlenXmlGetAttrValue(node, "e")) != NULL) { - + char *e=TlenXmlGetAttrValue(node, "e"); + if (e != NULL) { if (!strcmp(e, "1")) { // FILE_RECV : e='1' : File transfer request - ft = TlenFileCreateFT(info->proto, jid); + TLEN_FILE_TRANSFER *ft = TlenFileCreateFT(info->proto, jid); ft->hContact = TlenHContactFromJID(info->proto, jid); if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) @@ -590,7 +578,7 @@ void TlenProcessF(XmlNode *node, ThreadData *info) if (numFiles == 1) { if ((p=TlenXmlGetAttrValue(node, "n")) != NULL) { p = TlenTextDecode(p); - strncpy(szFilename, p, sizeof(szFilename)); + strncpy(szFilename, p, sizeof(szFilename)-1); mir_free(p); } else { strcpy(szFilename, Translate("1 File")); diff --git a/protocols/Tlen/src/tlen_iqid.cpp b/protocols/Tlen/src/tlen_iqid.cpp index a03d1a7614..acc67c7cd3 100644 --- a/protocols/Tlen/src/tlen_iqid.cpp +++ b/protocols/Tlen/src/tlen_iqid.cpp @@ -129,14 +129,14 @@ void TlenResultSetRoster(TlenProtocol *proto, XmlNode *queryNode) { void TlenIqResultRoster(TlenProtocol *proto, XmlNode *iqNode) { - XmlNode *queryNode; - char *type; char *str; // RECVED: roster information // ACTION: populate LIST_ROSTER and create contact for any new rosters - if ((type=TlenXmlGetAttrValue(iqNode, "type")) == NULL) return; - if ((queryNode=TlenXmlGetChild(iqNode, "query")) == NULL) return; + char *type=TlenXmlGetAttrValue(iqNode, "type"); + if (type == NULL) return; + XmlNode *queryNode=TlenXmlGetChild(iqNode, "query"); + if (queryNode == NULL) return; if (!strcmp(type, "result")) { str = TlenXmlGetAttrValue(queryNode, "xmlns"); @@ -238,22 +238,24 @@ void TlenIqResultRoster(TlenProtocol *proto, XmlNode *iqNode) // Tlen actually use jabber:iq:search for other users vCard or jabber:iq:register for own vCard void TlenIqResultVcard(TlenProtocol *proto, XmlNode *iqNode) { - XmlNode *queryNode, *itemNode, *n; - char *type, *jid; + char *jid; char text[128]; MCONTACT hContact; char *nText; // TlenLog(" iqIdGetVcard (tlen)"); - if ((type=TlenXmlGetAttrValue(iqNode, "type")) == NULL) return; + char *type=TlenXmlGetAttrValue(iqNode, "type"); + if (type == NULL) return; if (!strcmp(type, "result")) { BOOL hasFirst, hasLast, hasNick, hasEmail, hasCity, hasAge, hasGender, hasSchool, hasLookFor, hasOccupation; DBVARIANT dbv; int i; - if ((queryNode=TlenXmlGetChild(iqNode, "query")) == NULL) return; - if ((itemNode=TlenXmlGetChild(queryNode, "item")) == NULL) return; + XmlNode *queryNode=TlenXmlGetChild(iqNode, "query"); + if (queryNode == NULL) return; + XmlNode *itemNode=TlenXmlGetChild(queryNode, "item"); + if (itemNode == NULL) return; if ((jid=TlenXmlGetAttrValue(itemNode, "jid")) != NULL) { if (db_get(NULL, proto->m_szModuleName, "LoginServer", &dbv)) return; if (strchr(jid, '@') != NULL) { @@ -275,7 +277,7 @@ void TlenIqResultVcard(TlenProtocol *proto, XmlNode *iqNode) } hasFirst = hasLast = hasNick = hasEmail = hasCity = hasAge = hasGender = hasOccupation = hasLookFor = hasSchool = FALSE; for (i=0; inumChild; i++) { - n = itemNode->child[i]; + XmlNode *n = itemNode->child[i]; if (n == NULL || n->name == NULL) continue; if (!strcmp(n->name, "first")) { if (n->text != NULL) { @@ -398,16 +400,19 @@ void TlenIqResultVcard(TlenProtocol *proto, XmlNode *iqNode) void TlenIqResultSearch(TlenProtocol *proto, XmlNode *iqNode) { XmlNode *queryNode, *itemNode, *n; - char *type, *jid, *str; - int id, i, found; + char *jid; + int i, found = 0; TLEN_SEARCH_RESULT jsr = {0}; DBVARIANT dbv = {0}; - found = 0; // TlenLog(" iqIdGetSearch"); - if ((type=TlenXmlGetAttrValue(iqNode, "type")) == NULL) return; - if ((str=TlenXmlGetAttrValue(iqNode, "id")) == NULL) return; - id = atoi(str+strlen(TLEN_IQID)); + char *type = TlenXmlGetAttrValue(iqNode, "type"); + if (type == NULL) + return; + char *str = TlenXmlGetAttrValue(iqNode, "id"); + if (str == NULL) + return; + int id = atoi(str+strlen(TLEN_IQID)); if (!strcmp(type, "result")) { if ((queryNode=TlenXmlGetChild(iqNode, "query")) == NULL) return; @@ -520,9 +525,9 @@ void GetConfigItem(XmlNode *node, char *dest, BOOL bMethod, int *methodDest) { void TlenIqResultTcfg(TlenProtocol *proto, XmlNode *iqNode) { XmlNode *queryNode, *miniMailNode, *node; - char *type; - if ((type=TlenXmlGetAttrValue(iqNode, "type")) == NULL) return; + char *type=TlenXmlGetAttrValue(iqNode, "type"); + if (type == NULL) return; if (!strcmp(type, "result")) { if ((queryNode=TlenXmlGetChild(iqNode, "query")) == NULL) return; if ((miniMailNode=TlenXmlGetChild(queryNode, "mini-mail")) == NULL) return; @@ -557,11 +562,10 @@ void TlenIqResultVersion(TlenProtocol *proto, XmlNode *iqNode) { XmlNode *queryNode = TlenXmlGetChild(iqNode, "query"); if (queryNode != NULL) { - char* from; - if (( from=TlenXmlGetAttrValue( iqNode, "from" )) != NULL ) { - TLEN_LIST_ITEM *item; - if (( item=TlenListGetItemPtr( proto, LIST_ROSTER, from )) != NULL) { - MCONTACT hContact; + char *from = TlenXmlGetAttrValue(iqNode, "from"); + if (from != NULL ) { + TLEN_LIST_ITEM *item = TlenListGetItemPtr(proto, LIST_ROSTER, from); + if (item != NULL) { XmlNode *n; if ( item->software ) mir_free( item->software ); if ( item->version ) mir_free( item->version ); @@ -578,7 +582,8 @@ void TlenIqResultVersion(TlenProtocol *proto, XmlNode *iqNode) item->system = TlenTextDecode( n->text ); else item->system = NULL; - if (( hContact=TlenHContactFromJID(proto, item->jid )) != NULL ) { + MCONTACT hContact = TlenHContactFromJID(proto, item->jid); + if (hContact != NULL) { if (item->software != NULL) { db_set_s(hContact, proto->m_szModuleName, "MirVer", item->software); } else { @@ -594,14 +599,14 @@ void TlenIqResultInfo(TlenProtocol *proto, XmlNode *iqNode) { XmlNode *queryNode = TlenXmlGetChild(iqNode, "query"); if (queryNode != NULL) { - char* from; - if (( from=TlenXmlGetAttrValue( queryNode, "from" )) != NULL ) { + char *from=TlenXmlGetAttrValue(queryNode, "from"); + if (from != NULL ) { TLEN_LIST_ITEM *item; if (( item=TlenListGetItemPtr( proto, LIST_ROSTER, from )) != NULL) { - MCONTACT hContact; XmlNode *version = TlenXmlGetChild(queryNode, "version"); item->protocolVersion = TlenTextDecode(version->text); - if (( hContact=TlenHContactFromJID(proto, item->jid )) != NULL ) { + MCONTACT hContact=TlenHContactFromJID(proto, item->jid); + if (hContact != NULL) { if (item->software == NULL) { char str[128]; mir_snprintf(str, SIZEOF(str), "Tlen Protocol %s", item->protocolVersion); diff --git a/protocols/Tlen/src/tlen_p2p_new.cpp b/protocols/Tlen/src/tlen_p2p_new.cpp index 1591e93c99..ec7ebdd473 100644 --- a/protocols/Tlen/src/tlen_p2p_new.cpp +++ b/protocols/Tlen/src/tlen_p2p_new.cpp @@ -27,15 +27,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void logInfo(const char *filename, const char *fmt, ...) { - SYSTEMTIME time; - char *str; va_list vararg; - int strsize; FILE *flog=fopen(filename,"at"); if (flog != NULL) { + SYSTEMTIME time; GetLocalTime(&time); va_start(vararg, fmt); - str = (char *) mir_alloc(strsize=2048); + int strsize=2048; + char *str = (char *) mir_alloc(strsize); while (mir_vsnprintf(str, strsize, fmt, vararg) == -1) str = (char *) realloc(str, strsize+=2048); va_end(vararg); @@ -131,9 +130,6 @@ void __cdecl TlenNewFileSendThread(TLEN_FILE_TRANSFER *ft) if (fout != NULL) { fprintf(fout, "START:"); } - if (fout != NULL) { - fclose(fout); - } for (step = 0; step < 10; step ++) { // while (ft->udps != INVALID_SOCKET) { int alen; @@ -160,10 +156,12 @@ void __cdecl TlenNewFileSendThread(TLEN_FILE_TRANSFER *ft) } if (fout != NULL) { fprintf(fout, "\n"); - fclose(fout); } SleepEx(1000, TRUE); } + if (fout != NULL) { + fclose(fout); + } } ft->proto->debugLogA("P2P send thread ended"); } @@ -246,11 +244,10 @@ void __cdecl TlenProcessP2P(XmlNode *node, ThreadData *info) { id = TlenXmlGetAttrValue(fs, "i"); if (e != NULL) { if (!strcmp(e, "1")) { - char *c, *s; TLEN_FILE_TRANSFER * ft = (TLEN_FILE_TRANSFER *) mir_alloc(sizeof(TLEN_FILE_TRANSFER)); memset(ft, 0, sizeof(TLEN_FILE_TRANSFER)); - c = TlenXmlGetAttrValue(fs, "c"); - s = TlenXmlGetAttrValue(fs, "s"); + char *c = TlenXmlGetAttrValue(fs, "c"); + char *s = TlenXmlGetAttrValue(fs, "s"); ft->jid = mir_strdup(from); ft->proto = info->proto; ft->hContact = TlenHContactFromJID(info->proto, from); @@ -289,28 +286,21 @@ void __cdecl TlenProcessP2P(XmlNode *node, ThreadData *info) { } else if (vs != NULL) { } else if (dcng != NULL) { - char *s, *id, *id2; info->proto->debugLogA("DCNG"); - s = TlenXmlGetAttrValue(dcng, "s"); - id2 = TlenXmlGetAttrValue(dcng, "i"); - id = TlenXmlGetAttrValue(dcng, "mi"); + char *s = TlenXmlGetAttrValue(dcng, "s"); + char *id2 = TlenXmlGetAttrValue(dcng, "i"); + char *id = TlenXmlGetAttrValue(dcng, "mi"); if (!strcmp(s, "1")) { /* Keys */ - /* n - name (file_send) */ - /* k - ??? */ - /* v - ??? */ /* s - step */ /* i - id of the file */ - /* ck - aes key */ /* ks - key size (in bytes) */ - /* iv - aes initial vector */ /* mi - p2p connection id */ - char *n, *k, *v, *ck, *iv; - n = TlenXmlGetAttrValue(dcng, "n"); - k = TlenXmlGetAttrValue(dcng, "k"); - v = TlenXmlGetAttrValue(dcng, "v"); - ck = TlenXmlGetAttrValue(dcng, "ck"); - iv = TlenXmlGetAttrValue(dcng, "iv"); + char *n = TlenXmlGetAttrValue(dcng, "n"); // n - name (file_send) + char *k = TlenXmlGetAttrValue(dcng, "k"); // k - ??? + char *v = TlenXmlGetAttrValue(dcng, "v"); // v - ??? + char *ck = TlenXmlGetAttrValue(dcng, "ck"); // ck - aes key + char *iv = TlenXmlGetAttrValue(dcng, "iv"); // iv - aes initial vector if (!strcmp(n, "file_send")) { if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, id)) != NULL) { item->id2 = mir_strdup(id2); diff --git a/protocols/Tlen/src/tlen_svc.cpp b/protocols/Tlen/src/tlen_svc.cpp index 98dbafca2b..3ae3ed75e6 100644 --- a/protocols/Tlen/src/tlen_svc.cpp +++ b/protocols/Tlen/src/tlen_svc.cpp @@ -35,19 +35,22 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. DWORD_PTR TlenProtocol::GetCaps(int type, MCONTACT hContact) { - if (type == PFLAGNUM_1) + switch(type) { + case PFLAGNUM_1: return PF1_IM|PF1_AUTHREQ|PF1_SERVERCLIST|PF1_MODEMSG|PF1_BASICSEARCH|PF1_SEARCHBYEMAIL|PF1_EXTSEARCH|PF1_EXTSEARCHUI|PF1_SEARCHBYNAME|PF1_FILE;//|PF1_VISLIST|PF1_INVISLIST; - if (type == PFLAGNUM_2) + case PFLAGNUM_2: return PF2_ONLINE|PF2_INVISIBLE|PF2_SHORTAWAY|PF2_LONGAWAY|PF2_HEAVYDND|PF2_FREECHAT; - if (type == PFLAGNUM_3) + case PFLAGNUM_3: return PF2_ONLINE|PF2_INVISIBLE|PF2_SHORTAWAY|PF2_LONGAWAY|PF2_HEAVYDND|PF2_FREECHAT; - if (type == PFLAGNUM_4) + case PFLAGNUM_4: return PF4_FORCEAUTH|PF4_NOCUSTOMAUTH|PF4_SUPPORTTYPING|PF4_AVATARS|PF4_IMSENDOFFLINE|PF4_OFFLINEFILES; - if (type == PFLAG_UNIQUEIDTEXT) - return (DWORD_PTR) Translate("Tlen login"); - if (type == PFLAG_UNIQUEIDSETTING) - return (DWORD_PTR) "jid"; - return 0; + case PFLAG_UNIQUEIDTEXT: + return (INT_PTR) Translate("Tlen login"); + case PFLAG_UNIQUEIDSETTING: + return (INT_PTR) "jid"; + default: + return 0; + } } INT_PTR TlenProtocol::GetName(WPARAM wParam, LPARAM lParam) @@ -84,12 +87,12 @@ void TlenResetSearchQuery(TlenProtocol *proto) { HANDLE TlenProtocol::SearchBasic(const PROTOCHAR* id) { - char *jid; int iqId = 0; if (!isOnline) return 0; if (id == NULL) return 0; char* id_A = mir_t2a(id); - if ((jid=TlenTextEncode(id_A)) != NULL) { + char *jid=TlenTextEncode(id_A); + if (jid != NULL) { searchJID = mir_strdup(id_A); TlenResetSearchQuery(this); TlenStringAppend(&searchQuery, &searchQueryLen, "%s", jid); @@ -102,14 +105,14 @@ HANDLE TlenProtocol::SearchBasic(const PROTOCHAR* id) HANDLE TlenProtocol::SearchByEmail(const PROTOCHAR* email) { - char *emailEnc; int iqId = 0; if (!isOnline) return 0; if (email == NULL) return 0; char* email_A = mir_t2a(email); - if ((emailEnc=TlenTextEncode(email_A)) != NULL) { + char *emailEnc=TlenTextEncode(email_A); + if (emailEnc != NULL) { TlenResetSearchQuery(this); TlenStringAppend(&searchQuery, &searchQueryLen, "%s", emailEnc); iqId = TlenRunSearch(this); @@ -121,16 +124,15 @@ HANDLE TlenProtocol::SearchByEmail(const PROTOCHAR* email) HANDLE TlenProtocol::SearchByName(const PROTOCHAR* nickT, const PROTOCHAR* firstNameT, const PROTOCHAR* lastNameT) { + if (!isOnline) return 0; - char* nick = mir_t2a(nickT); - char* firstName = mir_t2a(firstNameT); - char* lastName = mir_t2a(lastNameT); + char *nick = mir_t2a(nickT); + char *firstName = mir_t2a(firstNameT); + char *lastName = mir_t2a(lastNameT); char *p; int iqId = 0; - if (!isOnline) return 0; - TlenResetSearchQuery(this); if (nick != NULL && nick[0] != '\0') { @@ -163,11 +165,10 @@ HWND TlenProtocol::CreateExtendedSearchUI(HWND owner) HWND TlenProtocol::SearchAdvanced(HWND owner) { - int iqId; if (!isOnline) return 0; TlenResetSearchQuery(this); - iqId = TlenSerialNext(this); + int iqId = TlenSerialNext(this); if ((searchQuery = TlenAdvSearchCreateQuery(owner, iqId)) != NULL) { iqId = TlenRunSearch(this); } @@ -177,16 +178,15 @@ HWND TlenProtocol::SearchAdvanced(HWND owner) static MCONTACT AddToListByJID(TlenProtocol *proto, const char *newJid, DWORD flags) { - MCONTACT hContact; - char *jid, *nick; - - if ((hContact=TlenHContactFromJID(proto, newJid)) == NULL) { + MCONTACT hContact = TlenHContactFromJID(proto, newJid); + if (hContact == NULL) { // not already there: add - jid = mir_strdup(newJid); _strlwr(jid); + char *jid = mir_strdup(newJid); _strlwr(jid); hContact = (MCONTACT) CallService(MS_DB_CONTACT_ADD, 0, 0); CallService(MS_PROTO_ADDTOCONTACT, hContact, (LPARAM) proto->m_szModuleName); db_set_s(hContact, proto->m_szModuleName, "jid", jid); - if ((nick=TlenNickFromJID(newJid)) == NULL) + char *nick=TlenNickFromJID(newJid); + if (nick == NULL) nick = mir_strdup(newJid); db_set_s(hContact, "CList", "MyHandle", nick); mir_free(nick); @@ -216,12 +216,10 @@ static MCONTACT AddToListByJID(TlenProtocol *proto, const char *newJid, DWORD fl MCONTACT TlenProtocol::AddToList(int flags, PROTOSEARCHRESULT *psr) { - MCONTACT hContact; TLEN_SEARCH_RESULT *jsr = (TLEN_SEARCH_RESULT*)psr; if (jsr->hdr.cbSize != sizeof(TLEN_SEARCH_RESULT)) return NULL; - hContact = AddToListByJID(this, jsr->jid, flags); // wParam is flag e.g. PALF_TEMPORARY - return hContact; + return AddToListByJID(this, jsr->jid, flags);// wParam is flag e.g. PALF_TEMPORARY } MCONTACT TlenProtocol::AddToListByEvent(int flags, int iContact, MEVENT hDbEvent) @@ -295,9 +293,9 @@ int TlenProtocol::Authorize(MEVENT hDbEvent) // Automatically add this user to my roster if option is enabled if (db_get_b(NULL, m_szModuleName, "AutoAdd", TRUE) == TRUE) { MCONTACT hContact; - TLEN_LIST_ITEM *item; + TLEN_LIST_ITEM *item = TlenListGetItemPtr(this, LIST_ROSTER, jid); - if ((item=TlenListGetItemPtr(this, LIST_ROSTER, jid)) == NULL || (item->subscription != SUB_BOTH && item->subscription != SUB_TO)) { + if (item == NULL || (item->subscription != SUB_BOTH && item->subscription != SUB_TO)) { debugLogA("Try adding contact automatically jid=%s", jid); if ((hContact=AddToListByJID(this, jid, 0)) != NULL) { // Trigger actual add by removing the "NotOnList" added by AddToListByJID() @@ -348,15 +346,12 @@ int TlenProtocol::AuthDeny(MEVENT hDbEvent, const PROTOCHAR* szReason) static void TlenConnect(TlenProtocol *proto, int initialStatus) { if (!proto->isConnected) { - ThreadData *thread; - int oldStatus; - - thread = (ThreadData *) mir_alloc(sizeof(ThreadData)); + ThreadData *thread = (ThreadData *) mir_alloc(sizeof(ThreadData)); memset(thread, 0, sizeof(ThreadData)); thread->proto = proto; proto->m_iDesiredStatus = initialStatus; - oldStatus = proto->m_iStatus; + int 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) forkthread((void (__cdecl *)(void*))TlenServerThread, 0, thread); @@ -568,12 +563,12 @@ static void __cdecl TlenGetAwayMsgThread(void *ptr) { DBVARIANT dbv; SENDACKTHREADDATA *data = (SENDACKTHREADDATA *)ptr; - TLEN_LIST_ITEM *item; Sleep(50); if (!db_get(data->hContact, data->proto->m_szModuleName, "jid", &dbv)) { - if ((item=TlenListGetItemPtr(data->proto, LIST_ROSTER, dbv.pszVal)) != NULL) { + TLEN_LIST_ITEM *item=TlenListGetItemPtr(data->proto, LIST_ROSTER, dbv.pszVal); + if (item != NULL) { db_free(&dbv); ProtoBroadcastAck(data->proto->m_szModuleName, data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, item->statusMessage==NULL ? (LPARAM)NULL : (LPARAM)(TCHAR*)_A2T(item->statusMessage)); @@ -585,13 +580,13 @@ static void __cdecl TlenGetAwayMsgThread(void *ptr) data->proto->ProtoBroadcastAck(data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)dbv2.ptszVal); db_free(&dbv2); } else { - data->proto->ProtoBroadcastAck(data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)NULL); + data->proto->ProtoBroadcastAck(data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, NULL); } } db_free(&dbv); } } else { - data->proto->ProtoBroadcastAck(data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)NULL); + data->proto->ProtoBroadcastAck(data->hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, NULL); } delete data; @@ -611,10 +606,6 @@ INT_PTR TlenProtocol::SendAlert(WPARAM hContact, LPARAM lParam) int TlenProtocol::SendMsg(MCONTACT hContact, int flags, const char* msgRAW) { DBVARIANT dbv; - char *msgEnc; - TLEN_LIST_ITEM *item; - char msgType[16]; - if (!isOnline || db_get(hContact, m_szModuleName, "jid", &dbv)) { forkthread(TlenSendMessageFailedThread, 0, new SENDACKTHREADDATA(this, hContact, 2)); return 2; @@ -628,6 +619,9 @@ int TlenProtocol::SendMsg(MCONTACT hContact, int flags, const char* msgRAW) else msg = mir_strdup(msgRAW); + TLEN_LIST_ITEM *item; + char msgType[16]; + int id = TlenSerialNext(this); @@ -640,7 +634,8 @@ int TlenProtocol::SendMsg(MCONTACT hContact, int flags, const char* msgRAW) forkthread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id)); } else { - if ((msgEnc=TlenTextEncode(msg)) != NULL) { + char *msgEnc=TlenTextEncode(msg); + if (msgEnc != NULL) { if (TlenListExist(this, LIST_CHATROOM, dbv.pszVal) && strchr(dbv.pszVal, '/') == NULL) strcpy(msgType, "groupchat"); else if (db_get_b(hContact, m_szModuleName, "bChat", FALSE)) @@ -649,9 +644,6 @@ int TlenProtocol::SendMsg(MCONTACT hContact, int flags, const char* msgRAW) strcpy(msgType, "chat"); if (!strcmp(msgType, "groupchat") || db_get_b(NULL, m_szModuleName, "MsgAck", FALSE) == FALSE) { - SENDACKTHREADDATA *tdata = (SENDACKTHREADDATA*) mir_alloc(sizeof(SENDACKTHREADDATA)); - tdata->proto = this; - tdata->hContact = hContact; if (!strcmp(msgType, "groupchat")) TlenSend(this, "%s", dbv.pszVal, msgType, msgEnc); else if (!strcmp(msgType, "privchat")) @@ -680,12 +672,12 @@ int TlenProtocol::SendMsg(MCONTACT hContact, int flags, const char* msgRAW) INT_PTR TlenProtocol::GetAvatarInfo(WPARAM wParam, LPARAM lParam) { + if (!tlenOptions.enableAvatars) return GAIR_NOAVATAR; BOOL downloadingAvatar = FALSE; char *avatarHash = NULL; TLEN_LIST_ITEM *item = NULL; DBVARIANT dbv; PROTO_AVATAR_INFORMATIONT* AI = ( PROTO_AVATAR_INFORMATIONT* )lParam; - if (!tlenOptions.enableAvatars) return GAIR_NOAVATAR; if (AI->hContact != NULL) { if (!db_get(AI->hContact, m_szModuleName, "jid", &dbv)) { @@ -704,7 +696,7 @@ INT_PTR TlenProtocol::GetAvatarInfo(WPARAM wParam, LPARAM lParam) return GAIR_NOAVATAR; if (avatarHash != NULL && !downloadingAvatar) { - TlenGetAvatarFileName(this, item, AI->filename, sizeof(AI->filename)); + TlenGetAvatarFileName(this, item, AI->filename, SIZEOF(AI->filename)-1); AI->format = ( AI->hContact == NULL ) ? threadData->avatarFormat : item->avatarFormat; return GAIR_SUCCESS; } @@ -730,18 +722,15 @@ int TlenProtocol::RecvAwayMsg(MCONTACT hContact, int mode, PROTORECVEVENT* evt) HANDLE TlenProtocol::FileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szPath) { - TLEN_FILE_TRANSFER *ft; - TLEN_LIST_ITEM *item; - char *nick; - if (!isOnline) return 0; - ft = (TLEN_FILE_TRANSFER *) hTransfer; + TLEN_FILE_TRANSFER *ft = (TLEN_FILE_TRANSFER *) hTransfer; ft->szSavePath = mir_strdup(mir_t2a(szPath)); //TODO convert to PROTOCHAR* - if ((item=TlenListAdd(this, LIST_FILE, ft->iqId)) != NULL) { + TLEN_LIST_ITEM *item = TlenListAdd(this, LIST_FILE, ft->iqId); + if (item != NULL) { item->ft = ft; } - nick = TlenNickFromJID(ft->jid); + char *nick = TlenNickFromJID(ft->jid); if (ft->newP2P) { TlenSend(this, "", ft->jid, ft->jid, ft->iqId); } else { @@ -753,13 +742,10 @@ HANDLE TlenProtocol::FileAllow(MCONTACT hContact, HANDLE hTransfer, const PROTOC int TlenProtocol::FileDeny(MCONTACT hContact, HANDLE hTransfer, const PROTOCHAR* szReason) { - TLEN_FILE_TRANSFER *ft; - char *nick; - if (!isOnline) return 1; - ft = (TLEN_FILE_TRANSFER *) hTransfer; - nick = TlenNickFromJID(ft->jid); + TLEN_FILE_TRANSFER *ft = (TLEN_FILE_TRANSFER *) hTransfer; + char *nick = TlenNickFromJID(ft->jid); if (ft->newP2P) { TlenSend(this, "", ft->iqId, nick);\ } else { @@ -795,18 +781,15 @@ int TlenProtocol::FileCancel(MCONTACT hContact, HANDLE hTransfer) HANDLE TlenProtocol::SendFile(MCONTACT hContact, const PROTOCHAR* szDescription, PROTOCHAR** ppszFiles) { - TLEN_FILE_TRANSFER *ft; int i, j; struct _stat statbuf; DBVARIANT dbv; char *nick, *p, idStr[10]; - TLEN_LIST_ITEM *item; - int id; if (!isOnline) return 0; // if (db_get_w(ccs->hContact, m_szModuleName, "Status", ID_STATUS_OFFLINE) == ID_STATUS_OFFLINE) return 0; if (db_get(hContact, m_szModuleName, "jid", &dbv)) return 0; - ft = TlenFileCreateFT(this, dbv.pszVal); + TLEN_FILE_TRANSFER *ft = TlenFileCreateFT(this, dbv.pszVal); for (ft->fileCount=0; ppszFiles[ft->fileCount]; ft->fileCount++); ft->files = (char **) mir_alloc(sizeof(char *) * ft->fileCount); ft->filesSize = (long *) mir_alloc(sizeof(long) * ft->fileCount); @@ -828,9 +811,10 @@ HANDLE TlenProtocol::SendFile(MCONTACT hContact, const PROTOCHAR* szDescription, ft->currentFile = 0; db_free(&dbv); - id = TlenSerialNext(this); + int id = TlenSerialNext(this); mir_snprintf(idStr, SIZEOF(idStr), "%d", id); - if ((item=TlenListAdd(this, LIST_FILE, idStr)) != NULL) { + TLEN_LIST_ITEM *item = TlenListAdd(this, LIST_FILE, idStr); + if (item != NULL) { ft->iqId = mir_strdup(idStr); nick = TlenNickFromJID(ft->jid); item->ft = ft; @@ -897,19 +881,18 @@ static char* settingToChar( DBCONTACTWRITESETTING* cws ) int TlenProtocol::TlenDbSettingChanged(WPARAM wParam, LPARAM lParam) { + MCONTACT hContact = (MCONTACT) wParam; DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam; // no action for hContact == NULL or when offline - if ((HANDLE) wParam == NULL) return 0; + if (hContact == NULL) return 0; if (!isConnected) return 0; if (!strcmp(cws->szModule, "CList")) { - MCONTACT hContact; DBVARIANT dbv; TLEN_LIST_ITEM *item; - char *szProto, *nick, *jid, *group; + char *nick, *jid, *group; - hContact = (MCONTACT) wParam; - szProto = GetContactProto(hContact); + char *szProto = GetContactProto(hContact); if (szProto == NULL || strcmp(szProto, m_szModuleName)) return 0; // A contact's group is changed if (!strcmp(cws->szSetting, "Group")) { @@ -1040,9 +1023,9 @@ int TlenProtocol::TlenContactDeleted(WPARAM wParam, LPARAM lParam) DBVARIANT dbv; if (!db_get(wParam, m_szModuleName, "jid", &dbv)) { - char *jid, *p, *q; + char *p, *q; - jid = dbv.pszVal; + char *jid = dbv.pszVal; if ((p=strchr(jid, '@')) != NULL) { if ((q=strchr(p, '/')) != NULL) *q = '\0'; @@ -1060,11 +1043,11 @@ int TlenProtocol::TlenContactDeleted(WPARAM wParam, LPARAM lParam) int TlenProtocol::UserIsTyping(MCONTACT hContact, int type) { DBVARIANT dbv; - TLEN_LIST_ITEM *item; if (!isOnline) return 0; if (!db_get(hContact, m_szModuleName, "jid", &dbv)) { - if ((item=TlenListGetItemPtr(this, LIST_ROSTER, dbv.pszVal)) != NULL /*&& item->wantComposingEvent == TRUE*/) { + TLEN_LIST_ITEM *item = TlenListGetItemPtr(this, LIST_ROSTER, dbv.pszVal); + if (item != NULL /*&& item->wantComposingEvent == TRUE*/) { switch (type) { case PROTOTYPE_SELFTYPING_OFF: TlenSend(this, "", dbv.pszVal); @@ -1175,8 +1158,9 @@ INT_PTR TlenProtocol::GetAvatarCaps(WPARAM wParam, LPARAM lParam) return 10 * 1024; case AF_FETCHIFCONTACTOFFLINE: return 1; + default: + return 0; } - return 0; } int TlenProtocol::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam) diff --git a/protocols/Tlen/src/tlen_thread.cpp b/protocols/Tlen/src/tlen_thread.cpp index dd9300d471..8d786d2da5 100644 --- a/protocols/Tlen/src/tlen_thread.cpp +++ b/protocols/Tlen/src/tlen_thread.cpp @@ -101,10 +101,7 @@ static VOID NTAPI TlenPasswordCreateDialogApcProc(ULONG_PTR param) void __cdecl TlenServerThread(ThreadData *info) { - DBVARIANT dbv; - char jidStr[128]; char *connectHost; - char *buffer; int datalen; XmlState xmlState; int tlenNetworkBufferSize; @@ -131,6 +128,7 @@ void __cdecl TlenServerThread(ThreadData *info) info->proto->threadData = info; + DBVARIANT dbv; if (!db_get(NULL, info->proto->m_szModuleName, "LoginName", &dbv)) { strncpy(info->username, dbv.pszVal, sizeof(info->username)); info->username[sizeof(info->username)-1] = '\0'; @@ -155,7 +153,8 @@ void __cdecl TlenServerThread(ThreadData *info) loginErr = LOGINERR_NONETWORK; } } - + + char jidStr[128]; if (loginErr == 0) { if (!info->proto->tlenOptions.savePassword) { // Ugly hack: continue logging on only the return value is &(onlinePassword[0]) @@ -191,7 +190,8 @@ void __cdecl TlenServerThread(ThreadData *info) } tlenNetworkBufferSize = 2048; - if ((buffer=(char *) mir_alloc(tlenNetworkBufferSize+1)) == NULL) { // +1 is for '\0' when debug logging this buffer + char *buffer = (char *) mir_alloc(tlenNetworkBufferSize+1); // +1 is for '\0' when debug logging this buffer + if (buffer == NULL) { info->proto->debugLogA("Thread ended, network buffer cannot be allocated"); loginErr = LOGINERR_NONETWORK; } @@ -203,9 +203,10 @@ void __cdecl TlenServerThread(ThreadData *info) ProtoBroadcastAck(info->proto->m_szModuleName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) oldStatus, info->proto->m_iStatus); ProtoBroadcastAck(info->proto->m_szModuleName, NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, loginErr); mir_free(info); + mir_free(buffer); return; } - + mir_snprintf(jidStr, SIZEOF(jidStr), "%s@%s", info->username, info->server); db_set_s(NULL, info->proto->m_szModuleName, "jid", jidStr); @@ -399,14 +400,13 @@ void __cdecl TlenServerThread(ThreadData *info) static void TlenSendAuth(TlenProtocol *proto) { int iqId; - char *p; - char *str; char text[128]; - str = TlenPasswordHash(proto->threadData->password); + char *str = TlenPasswordHash(proto->threadData->password); mir_snprintf(text, SIZEOF(text), "%s%s", proto->threadData->streamId, str); mir_free(str); str = TlenSha1(text); - if ((p=TlenTextEncode(proto->threadData->username)) != NULL) { + char *p=TlenTextEncode(proto->threadData->username); + if (p != NULL) { iqId = TlenSerialNext(proto->threadData->proto); TlenIqAdd(proto, iqId, IQ_PROC_NONE, TlenIqResultAuth); TlenSend(proto, "%s%sttlen.pl", iqId, p /*info->username*/, str); @@ -418,26 +418,25 @@ static void TlenSendAuth(TlenProtocol *proto) { /* processing tag sent from server on session opening */ static void TlenProcessStreamOpening(XmlNode *node, ThreadData *info) { - char *sid, *s; - if (node->name == NULL || strcmp(node->name, "s")) return; - if ((sid=TlenXmlGetAttrValue(node, "i")) != NULL) { + char *sid=TlenXmlGetAttrValue(node, "i"); + if (sid != NULL) { if (info->streamId) mir_free(info->streamId); info->streamId = mir_strdup(sid); } - if ((s=TlenXmlGetAttrValue(node, "s")) != NULL && !strcmp(s, "1")) { + char *s=TlenXmlGetAttrValue(node, "s"); + if (s != NULL && !strcmp(s, "1")) { int i; - char *k1, *k2, *k3; unsigned char aes_key[32]; char aes_key_str[140], aes_iv_str[40]; mpi k1_mpi, k2_mpi, aes_mpi; size_t slen; - k1=TlenXmlGetAttrValue(node, "k1"); - k2=TlenXmlGetAttrValue(node, "k2"); - k3=TlenXmlGetAttrValue(node, "k3"); + char *k1=TlenXmlGetAttrValue(node, "k1"); + char *k2=TlenXmlGetAttrValue(node, "k2"); + char *k3=TlenXmlGetAttrValue(node, "k3"); memset(&info->aes_in_context, 0, sizeof (aes_context)); memset(&info->aes_out_context, 0, sizeof (aes_context)); @@ -516,26 +515,30 @@ static void TlenProcessProtocol(XmlNode *node, ThreadData *info) static void TlenProcessCipher(XmlNode *node, ThreadData *info) { - char *type; - type=TlenXmlGetAttrValue(node, "type"); + char *type=TlenXmlGetAttrValue(node, "type"); info->useAES = TRUE; TlenSend(info->proto, ""); TlenSendAuth(info->proto); } -static void TlenProcessIqGetVersion(TlenProtocol *proto, XmlNode* node) +static void TlenProcessIqGetVersion(TlenProtocol *proto, XmlNode *node) { OSVERSIONINFO osvi = { 0 }; char mversion[256]; - char* from, *version, *mver; + char *mver; char* os = NULL; - TLEN_LIST_ITEM *item; if (proto->m_iStatus == ID_STATUS_INVISIBLE) return; if (!proto->tlenOptions.enableVersion) return; - if (( from=TlenXmlGetAttrValue( node, "from" )) == NULL ) return; - if (( item=TlenListGetItemPtr( proto, LIST_ROSTER, from )) ==NULL) return; - version = TlenTextEncode( TLEN_VERSION_STRING ); + char *from = TlenXmlGetAttrValue(node, "from"); + if (from == NULL) + return; + + TLEN_LIST_ITEM *item = TlenListGetItemPtr(proto, LIST_ROSTER, from); + if (item == NULL) + return; + + char *version = TlenTextEncode(TLEN_VERSION_STRING); osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); if ( GetVersionEx( &osvi )) { switch ( osvi.dwPlatformId ) { @@ -580,9 +583,8 @@ static void TlenProcessIqGetVersion(TlenProtocol *proto, XmlNode* node) // Support for Tlen avatars - avatar token used to access web interface static void TlenProcessAvatar(XmlNode* node, ThreadData *info) { - XmlNode *tokenNode, *aNode; - tokenNode = TlenXmlGetChild(node, "token"); - aNode = TlenXmlGetChild(node, "a"); + XmlNode *tokenNode = TlenXmlGetChild(node, "token"); + XmlNode *aNode = TlenXmlGetChild(node, "a"); if (tokenNode != NULL) { char *token = tokenNode->text; strcpy(info->avatarToken, token); @@ -597,7 +599,7 @@ static void TlenProcessMessage(XmlNode *node, ThreadData *info) { MCONTACT hContact; XmlNode *bodyNode, *subjectNode, *xNode, *n; - char *from, *type, *nick, *p, *localMessage, *idStr; + char *nick, *p, *localMessage, *idStr; DWORD msgTime; BOOL delivered, composing; int i; @@ -606,14 +608,16 @@ static void TlenProcessMessage(XmlNode *node, ThreadData *info) if (!node->name || strcmp(node->name, "message")) return; - if ((type=TlenXmlGetAttrValue(node, "type")) != NULL && !strcmp(type, "error")) { + char *type=TlenXmlGetAttrValue(node, "type"); + if (type != NULL && !strcmp(type, "error")) { } else { - if ((from=TlenXmlGetAttrValue(node, "from")) != NULL) { - char *fromJid = TlenLoginFromJID(from); + char *from=TlenXmlGetAttrValue(node, "from"); + if (from != NULL) { if (info->proto->tlenOptions.ignoreAdvertisements && strstr(from, "b73@tlen.pl") == from) { return; } + char *fromJid = TlenLoginFromJID(from); // If message is from a stranger (not in roster), item is NULL item = TlenListGetItemPtr(info->proto, LIST_ROSTER, fromJid); isChatRoomJid = TlenListExist(info->proto, LIST_CHATROOM, from); @@ -730,7 +734,7 @@ static void TlenProcessIq(XmlNode *node, ThreadData *info) { MCONTACT hContact; XmlNode *queryNode = NULL; - char *type, *jid, *nick; + char *jid, *nick; char *xmlns = NULL; char *idStr, *str; int id; @@ -738,7 +742,7 @@ static void TlenProcessIq(XmlNode *node, ThreadData *info) TLEN_IQ_PFUNC pfunc; if (!node->name || strcmp(node->name, "iq")) return; - type=TlenXmlGetAttrValue(node, "type"); + char *type=TlenXmlGetAttrValue(node, "type"); // if ((type=TlenXmlGetAttrValue(node, "type")) == NULL) return; id = -1; @@ -892,19 +896,23 @@ static void TlenProcessIq(XmlNode *node, ThreadData *info) */ static void TlenProcessW(XmlNode *node, ThreadData *info) { - MCONTACT hContact; - char *f, *e, *s, *body; + char *e, *s; char *str, *localMessage; int strSize; - if (!node->name || strcmp(node->name, "w")) return; - if ((body=node->text) == NULL) return; + if (!node->name || strcmp(node->name, "w")) + return; - if ((f=TlenXmlGetAttrValue(node, "f")) != NULL) { + char *body=node->text; + if (body == NULL) + return; + char *f = TlenXmlGetAttrValue(node, "f"); + if (f != NULL) { char webContactName[128]; mir_snprintf(webContactName, SIZEOF(webContactName), Translate("%s Web Messages"), info->proto->m_szModuleName); - if ((hContact=TlenHContactFromJID(info->proto, webContactName)) == NULL) { + MCONTACT hContact = TlenHContactFromJID(info->proto, webContactName); + if (hContact == NULL) { hContact = TlenDBCreateContact(info->proto, webContactName, webContactName, TRUE); } @@ -1069,14 +1077,13 @@ static void TlenMailPopup(TlenProtocol *proto, char *title, char *emailInfo) */ static void TlenProcessN(XmlNode *node, ThreadData *info) { - char *f, *s; char *str, *popupTitle, *popupText; int strSize; if (!node->name || strcmp(node->name, "n")) return; - s = TlenXmlGetAttrValue(node, "s"); - f = TlenXmlGetAttrValue(node, "f"); + char *s = TlenXmlGetAttrValue(node, "s"); + char *f = TlenXmlGetAttrValue(node, "f"); if (s != NULL && f != NULL) { str = NULL; strSize = 0; @@ -1183,10 +1190,11 @@ static void TlenProcessV(XmlNode *node, ThreadData *info) { char jid[128]; TLEN_LIST_ITEM *item; - char *from, *id, *e, *p; + char *id, *e, *p; // if (!node->name || strcmp(node->name, "v")) return; - if ((from=TlenXmlGetAttrValue(node, "f")) != NULL) { + char *from=TlenXmlGetAttrValue(node, "f"); + if (from != NULL) { if (strchr(from, '@') == NULL) { mir_snprintf(jid, SIZEOF(jid), "%s@%s", from, info->server); } else { -- cgit v1.2.3