From 878d72910cccf4f84c7cb45bb4c11134920f3166 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 18 Aug 2015 11:49:54 +0000 Subject: - naming conflict; - warning fixes; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@14988 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/IcqOscarJ/src/fam_04message.cpp | 199 ++++++++++++++-------------- protocols/Steam/src/steam_login.cpp | 6 +- protocols/Tlen/src/tlen_file.cpp | 209 ++++++++++++++---------------- protocols/Twitter/src/contacts.cpp | 24 ++-- 4 files changed, 213 insertions(+), 225 deletions(-) (limited to 'protocols') diff --git a/protocols/IcqOscarJ/src/fam_04message.cpp b/protocols/IcqOscarJ/src/fam_04message.cpp index 2b9c68bfca..e8afe60295 100644 --- a/protocols/IcqOscarJ/src/fam_04message.cpp +++ b/protocols/IcqOscarJ/src/fam_04message.cpp @@ -93,10 +93,10 @@ void CIcqProto::handleReplyICBM() DWORD dwFlags = 0x00000303; #ifdef DBG_CAPHTML - dwFlags |= 0x00000400; + dwFlags |= 0x00000400; #endif #ifdef DBG_CAPMTN - dwFlags |= 0x00000008; + dwFlags |= 0x00000008; #endif // Set message parameters for all channels (imitate ICQ 6) setMsgChannelParams(this, 0x0000, dwFlags); @@ -403,11 +403,11 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, size_t wLen, DWORD dwUin, char unpackWord(&pDataBuf, &wCommand); wTLVLen -= 2; - + // Command 0x0000 - Normal message/file send request // 0x0001 - Abort request // 0x0002 - Acknowledge request - debugLogA("Command is %u", wCommand); + debugLogA("Command is %u", wCommand); // Some stuff we don't use pDataBuf += 8; // dwID1 and dwID2 again @@ -506,10 +506,8 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, size_t wLen, DWORD dwUin, char // Parse the next message level if (tlv = chain->getTLV(0x2711, 1)) { if (tlv->wLen == 0x1B) { - BYTE *buf = tlv->pData; - DWORD dwUin; - - unpackLEDWord(&buf, &dwUin); + BYTE *buf2 = tlv->pData; + unpackLEDWord(&buf2, &dwUin); MCONTACT hContact = HContactFromUIN(dwUin, NULL); if (hContact == INVALID_CONTACT_ID) @@ -519,15 +517,15 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, size_t wLen, DWORD dwUin, char WORD wVersion; BYTE bMode; - unpackDWord(&buf, &dwIp); - unpackLEDWord(&buf, &dwPort); - unpackByte(&buf, &bMode); - buf += 4; // unknown + unpackDWord(&buf2, &dwIp); + unpackLEDWord(&buf2, &dwPort); + unpackByte(&buf2, &bMode); + buf2 += 4; // unknown if (dwPort) - buf += 4; // port, again? + buf2 += 4; // port, again? else - unpackLEDWord(&buf, &dwPort); - unpackLEWord(&buf, &wVersion); + unpackLEDWord(&buf2, &dwPort); + unpackLEWord(&buf2, &wVersion); setDword(hContact, "IP", dwIp); setWord(hContact, "UserPort", (WORD)dwPort); @@ -536,7 +534,7 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, size_t wLen, DWORD dwUin, char if (wVersion > 6) { cookie_reverse_connect *pCookie = (cookie_reverse_connect*)SAFE_MALLOC(sizeof(cookie_reverse_connect)); - unpackLEDWord(&buf, (DWORD*)&pCookie->ft); + unpackLEDWord(&buf2, (DWORD*)&pCookie->ft); pCookie->dwMsgID1 = dwMsgID1; pCookie->dwMsgID2 = dwMsgID2; @@ -668,12 +666,12 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, size_t wLen, MCONTACT hContac } break; - // Chat messages, handled by the chat module + // Chat messages, handled by the chat module case MTYPE_CHAT: // TODO: this type is deprecated break; - // Plugin messages, need further parsing + // Plugin messages, need further parsing case MTYPE_PLUGIN: if (wLen < wMsgLen) { // sanity check debugLogA("Error: Malformed server Greeting message"); @@ -683,7 +681,7 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, size_t wLen, MCONTACT hContac parseServRelayPluginData(pDataBuf + wMsgLen, wLen - wMsgLen, dwUin, szUID, dwMsgID1, dwMsgID2, wAckType, bFlags, wStatus, wCookie, wVersion); break; - // Everything else + // Everything else default: if (!dwUin) { // AIM cannot send this, just sanity debugLogA("Error: Malformed UIN in packet"); @@ -1135,14 +1133,14 @@ void CIcqProto::handleRecvServMsgType4(BYTE *buf, size_t wLen, DWORD dwUin, char } if (bMsgType == MTYPE_PLUGIN) { - size_t wLen = wTLVLen - 8; - int typeId; + wLen = wTLVLen - 8; debugLogA("Parsing Greeting message through server"); pmsg += wMsgLen; wLen -= wMsgLen; + int typeId; if (unpackPluginTypeId(&pmsg, &wLen, &typeId, NULL, FALSE) && wLen > 8) { size_t dwLengthToEnd, dwDataLen; @@ -1157,15 +1155,15 @@ void CIcqProto::handleRecvServMsgType4(BYTE *buf, size_t wLen, DWORD dwUin, char dwDataLen = wLen; if (typeId) { - uid_str szUID; - handleMessageTypes(dwUin, szUID, dwRecvTime, dwMsgID1, dwMsgID2, 0, 0, typeId, bFlags, 0, dwLengthToEnd, dwDataLen, (char*)pmsg, MTF_PLUGIN, NULL); + uid_str szUid; + handleMessageTypes(dwUin, szUid, dwRecvTime, dwMsgID1, dwMsgID2, 0, 0, typeId, bFlags, 0, dwLengthToEnd, dwDataLen, (char*)pmsg, MTF_PLUGIN, NULL); } else debugLogA("Unsupported plugin message type %d", typeId); } } else { - uid_str szUID; - handleMessageTypes(dwUin, szUID, dwRecvTime, dwMsgID1, dwMsgID2, 0, 0, bMsgType, bFlags, 0, wTLVLen - 8, wMsgLen, (char*)pmsg, 0, NULL); + uid_str szUid; + handleMessageTypes(dwUin, szUid, dwRecvTime, dwMsgID1, dwMsgID2, 0, 0, bMsgType, bFlags, 0, wTLVLen - 8, wMsgLen, (char*)pmsg, 0, NULL); } } } @@ -1468,8 +1466,8 @@ void CIcqProto::sendMessageTypesAck(MCONTACT hContact, int bUnicode, message_ack { if (pArgs) { if ((pArgs->msgType == MTYPE_PLAIN && !CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_MESSAGE)) - || (pArgs->msgType == MTYPE_URL && !CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_URL)) - || pArgs->msgType == MTYPE_CONTACTS) { + || (pArgs->msgType == MTYPE_URL && !CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_URL)) + || pArgs->msgType == MTYPE_CONTACTS) { if (pArgs->bType == MAT_SERVER_ADVANCED) { // Only ack message packets icq_sendAdvancedMsgAck(pArgs->dwUin, pArgs->dwMsgID1, pArgs->dwMsgID2, pArgs->wCookie, (BYTE)pArgs->msgType, pArgs->bFlags); } @@ -1513,7 +1511,8 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, pszMsgField[0] = szMsg; if (type == MTYPE_URL || type == MTYPE_AUTHREQ || type == MTYPE_ADDED || type == MTYPE_CONTACTS || type == MTYPE_EEXPRESS || type == MTYPE_WWP) { - for (char *pszMsg = szMsg, nMsgFields = 1; *pszMsg; pszMsg++) { + nMsgFields = 1; + for (char *pszMsg = szMsg; *pszMsg; pszMsg++) { if ((BYTE)*pszMsg == 0xFE) { *pszMsg = '\0'; pszMsgField[nMsgFields++] = pszMsg + 1; @@ -1672,10 +1671,9 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, char* pszNContactsEnd; int nContacts; if (nMsgFields < 3 || - (nContacts = strtol(pszMsgField[0], &pszNContactsEnd, 10)) == 0 || - pszNContactsEnd - pszMsgField[0] != (int)mir_strlen(pszMsgField[0]) || - nMsgFields < nContacts * 2 + 1) - { + (nContacts = strtol(pszMsgField[0], &pszNContactsEnd, 10)) == 0 || + pszNContactsEnd - pszMsgField[0] != (int)mir_strlen(pszMsgField[0]) || + nMsgFields < nContacts * 2 + 1) { NetLog_Uni(bThruDC, "Malformed '%s' message", "contacts"); } else { @@ -1812,72 +1810,71 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, case MTYPE_AUTONA: case MTYPE_AUTODND: case MTYPE_AUTOFFC: - { - char **szMsg = MirandaStatusToAwayMsg(AwayMsgTypeToStatus(type)); - if (szMsg) { - struct rates_status_message_response : public rates_queue_item - { - protected: - virtual rates_queue_item* copyItem(rates_queue_item *aDest = NULL) + { + char **szMsgs = MirandaStatusToAwayMsg(AwayMsgTypeToStatus(type)); + if (szMsgs) { + struct rates_status_message_response : public rates_queue_item { - rates_status_message_response *pDest = (rates_status_message_response*)aDest; - if (!pDest) - pDest = new rates_status_message_response(ppro, wGroup); - - pDest->bExtended = bExtended; - pDest->dwMsgID1 = dwMsgID1; - pDest->dwMsgID2 = dwMsgID2; - pDest->wCookie = wCookie; - pDest->wVersion = wVersion; - pDest->nMsgType = nMsgType; - - return rates_queue_item::copyItem(pDest); + protected: + virtual rates_queue_item* copyItem(rates_queue_item *aDest = NULL) + { + rates_status_message_response *pDest = (rates_status_message_response*)aDest; + if (!pDest) + pDest = new rates_status_message_response(ppro, wGroup); + + pDest->bExtended = bExtended; + pDest->dwMsgID1 = dwMsgID1; + pDest->dwMsgID2 = dwMsgID2; + pDest->wCookie = wCookie; + pDest->wVersion = wVersion; + pDest->nMsgType = nMsgType; + + return rates_queue_item::copyItem(pDest); + }; + public: + rates_status_message_response(CIcqProto *ppro, WORD wGroup) : rates_queue_item(ppro, wGroup) {}; + virtual ~rates_status_message_response() {}; + + virtual void execute() + { + char **pszMsg = ppro->MirandaStatusToAwayMsg(AwayMsgTypeToStatus(nMsgType)); + if (bExtended) + ppro->icq_sendAwayMsgReplyServExt(dwUin, szUid, dwMsgID1, dwMsgID2, wCookie, wVersion, nMsgType, pszMsg); + else if (dwUin) + ppro->icq_sendAwayMsgReplyServ(dwUin, dwMsgID1, dwMsgID2, wCookie, wVersion, (BYTE)nMsgType, pszMsg); + else + ppro->debugLogA("Error: Malformed UIN in packet"); + }; + + BOOL bExtended; + DWORD dwMsgID1; + DWORD dwMsgID2; + WORD wCookie; + WORD wVersion; + int nMsgType; }; - public: - rates_status_message_response(CIcqProto *ppro, WORD wGroup) : rates_queue_item(ppro, wGroup) {}; - virtual ~rates_status_message_response() {}; - virtual void execute() + WORD wGroup; { - char **pszMsg = ppro->MirandaStatusToAwayMsg(AwayMsgTypeToStatus(nMsgType)); - if (bExtended) - ppro->icq_sendAwayMsgReplyServExt(dwUin, szUid, dwMsgID1, dwMsgID2, wCookie, wVersion, nMsgType, pszMsg); - else if (dwUin) - ppro->icq_sendAwayMsgReplyServ(dwUin, dwMsgID1, dwMsgID2, wCookie, wVersion, (BYTE)nMsgType, pszMsg); - else - ppro->debugLogA("Error: Malformed UIN in packet"); - }; - - BOOL bExtended; - DWORD dwMsgID1; - DWORD dwMsgID2; - WORD wCookie; - WORD wVersion; - int nMsgType; - }; + mir_cslock l(m_ratesMutex); + wGroup = m_rates->getGroupFromSNAC(ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE); + } - WORD wGroup; - { - mir_cslock l(m_ratesMutex); - wGroup = m_rates->getGroupFromSNAC(ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE); + rates_status_message_response rr(this, wGroup); + rr.bExtended = (nMsgFlags & MTF_STATUS_EXTENDED) == MTF_STATUS_EXTENDED; + rr.hContact = hContact; + rr.dwUin = dwUin; + rr.szUid = szUID; + rr.dwMsgID1 = dwMsgID; + rr.dwMsgID2 = dwMsgID2; + rr.wCookie = wCookie; + rr.wVersion = wVersion; + rr.nMsgType = type; + + handleRateItem(&rr, RQT_RESPONSE); } - - rates_status_message_response rr(this, wGroup); - rr.bExtended = (nMsgFlags & MTF_STATUS_EXTENDED) == MTF_STATUS_EXTENDED; - rr.hContact = hContact; - rr.dwUin = dwUin; - rr.szUid = szUID; - rr.dwMsgID1 = dwMsgID; - rr.dwMsgID2 = dwMsgID2; - rr.wCookie = wCookie; - rr.wVersion = wVersion; - rr.nMsgType = type; - - handleRateItem(&rr, RQT_RESPONSE); } - break; - } case MTYPE_FILEREQ: // Never happens default: @@ -2192,20 +2189,20 @@ void CIcqProto::handleRecvMsgResponse(BYTE *buf, size_t wLen) break; case MTYPE_REVERSE_REQUEST: - { - cookie_reverse_connect *pReverse = (cookie_reverse_connect*)pCookieData; + { + cookie_reverse_connect *pReverse = (cookie_reverse_connect*)pCookieData; - if (pReverse->ft) { - filetransfer *ft = (filetransfer*)pReverse->ft; + if (pReverse->ft) { + filetransfer *ft = (filetransfer*)pReverse->ft; - ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); - } - debugLogA("Reverse Connect request failed"); - // Set DC status to failed - setByte(hContact, "DCStatus", 2); + ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); + } + debugLogA("Reverse Connect request failed"); + // Set DC status to failed + setByte(hContact, "DCStatus", 2); - ReleaseCookie(dwCookie); - } + ReleaseCookie(dwCookie); + } return; case MTYPE_CHAT: diff --git a/protocols/Steam/src/steam_login.cpp b/protocols/Steam/src/steam_login.cpp index 52345fef00..cddd0204e3 100644 --- a/protocols/Steam/src/steam_login.cpp +++ b/protocols/Steam/src/steam_login.cpp @@ -35,18 +35,18 @@ void CSteamProto::OnGotRsaKey(const NETLIBHTTPREQUEST *response) // encrcrypt password ptrA base64RsaEncryptedPassword; - ptrA password(getStringA("Password")); + ptrA szPassword(getStringA("Password")); DWORD error = 0; DWORD encryptedSize = 0; - if ((error = RsaEncrypt(modulus.c_str(), password, NULL, encryptedSize)) != 0) + if ((error = RsaEncrypt(modulus.c_str(), szPassword, NULL, encryptedSize)) != 0) { debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error); return; } BYTE *encryptedPassword = (BYTE*)mir_calloc(encryptedSize); - if ((error = RsaEncrypt(modulus.c_str(), password, encryptedPassword, encryptedSize)) != 0) + if ((error = RsaEncrypt(modulus.c_str(), szPassword, encryptedPassword, encryptedSize)) != 0) { debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error); return; diff --git a/protocols/Tlen/src/tlen_file.cpp b/protocols/Tlen/src/tlen_file.cpp index 20de8dafee..887ef89994 100644 --- a/protocols/Tlen/src/tlen_file.cpp +++ b/protocols/Tlen/src/tlen_file.cpp @@ -38,13 +38,13 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) p = rpacket->packet; if (rpacket->type == TLEN_FILE_PACKET_FILE_LIST) { // list of files (length & name) ft->fileCount = (int)(*((DWORD*)p)); - ft->files = (char **) mir_alloc(sizeof(char *) * ft->fileCount); - ft->filesSize = (long *) mir_alloc(sizeof(long) * ft->fileCount); + ft->files = (char **)mir_alloc(sizeof(char *) * ft->fileCount); + ft->filesSize = (long *)mir_alloc(sizeof(long) * ft->fileCount); ft->currentFile = 0; ft->allFileTotalSize = 0; ft->allFileReceivedBytes = 0; p += sizeof(DWORD); - for (i=0;ifileCount;i++) { + for (i = 0; i < ft->fileCount; i++) { ft->filesSize[i] = (long)(*((DWORD*)p)); ft->allFileTotalSize += ft->filesSize[i]; p += sizeof(DWORD); @@ -52,9 +52,9 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) memcpy(ft->files[i], p, 256); p += 256; } - if ((packet=TlenP2PPacketCreate(3*sizeof(DWORD))) == NULL) { + + if ((packet = TlenP2PPacketCreate(3 * sizeof(DWORD))) == NULL) ft->state = FT_ERROR; - } else { TlenP2PPacketSetType(packet, TLEN_FILE_PACKET_FILE_LIST_ACK); TlenP2PPacketSend(ft->s, packet); @@ -65,13 +65,11 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) } TlenP2PPacketFree(rpacket); } - else { - ft->state = FT_ERROR; - } + else ft->state = FT_ERROR; } else if (ft->state == FT_INITIALIZING) { char *fullFileName; - if ((packet=TlenP2PPacketCreate(3*sizeof(DWORD))) != NULL) { + if ((packet = TlenP2PPacketCreate(3 * sizeof(DWORD))) != NULL) { TlenP2PPacketSetType(packet, TLEN_FILE_PACKET_FILE_REQUEST); // file request TlenP2PPacketPackDword(packet, ft->currentFile); TlenP2PPacketPackDword(packet, 0); @@ -79,12 +77,12 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) TlenP2PPacketSend(ft->s, packet); TlenP2PPacketFree(packet); - fullFileName = (char *) mir_alloc(mir_strlen(ft->szSavePath) + mir_strlen(ft->files[ft->currentFile]) + 2); + fullFileName = (char *)mir_alloc(mir_strlen(ft->szSavePath) + mir_strlen(ft->files[ft->currentFile]) + 2); mir_strcpy(fullFileName, ft->szSavePath); - if (fullFileName[mir_strlen(fullFileName)-1] != '\\') + if (fullFileName[mir_strlen(fullFileName) - 1] != '\\') mir_strcat(fullFileName, "\\"); mir_strcat(fullFileName, ft->files[ft->currentFile]); - ft->fileId = _open(fullFileName, _O_BINARY|_O_WRONLY|_O_CREAT|_O_TRUNC, _S_IREAD|_S_IWRITE); + ft->fileId = _open(fullFileName, _O_BINARY | _O_WRONLY | _O_CREAT | _O_TRUNC, _S_IREAD | _S_IWRITE); ft->fileReceivedBytes = 0; ft->fileTotalSize = ft->filesSize[ft->currentFile]; ft->proto->debugLogA("Saving to [%s] [%d]", fullFileName, ft->filesSize[ft->currentFile]); @@ -92,9 +90,7 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) ft->state = FT_RECEIVING; ft->proto->debugLogA("Change to FT_RECEIVING"); } - else { - ft->state = FT_ERROR; - } + else ft->state = FT_ERROR; } else if (ft->state == FT_RECEIVING) { PROTOFILETRANSFERSTATUS pfts; @@ -116,7 +112,7 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) p = rpacket->packet; if (rpacket->type == TLEN_FILE_PACKET_FILE_DATA) { // file data int writeSize; - writeSize = rpacket->len - 2 * sizeof(DWORD) ; // skip file offset + writeSize = rpacket->len - 2 * sizeof(DWORD); // skip file offset if (_write(ft->fileId, p + 2 * sizeof(DWORD), writeSize) != writeSize) { ft->state = FT_ERROR; } @@ -125,13 +121,13 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) ft->allFileReceivedBytes += writeSize; pfts.totalProgress = ft->allFileReceivedBytes; pfts.currentFileProgress = ft->fileReceivedBytes; - ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM) &pfts); + ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&pfts); } } else if (rpacket->type == TLEN_FILE_PACKET_END_OF_FILE) { // end of file _close(ft->fileId); ft->proto->debugLogA("Finishing this file..."); - if (ft->currentFile >= ft->fileCount-1) { + if (ft->currentFile >= ft->fileCount - 1) { ft->state = FT_DONE; } else { @@ -143,9 +139,7 @@ static void TlenFileReceiveParse(TLEN_FILE_TRANSFER *ft) } TlenP2PPacketFree(rpacket); } - else { - ft->state = FT_ERROR; - } + else ft->state = FT_ERROR; } } } @@ -159,9 +153,9 @@ static void TlenFileReceivingConnection(HANDLE hConnection, DWORD, void * pExtra 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)"); - while (ft->state != FT_DONE && ft->state != FT_ERROR) { + while (ft->state != FT_DONE && ft->state != FT_ERROR) TlenFileReceiveParse(ft); - } + if (ft->state == FT_DONE) ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ft, 0); else @@ -169,17 +163,15 @@ static void TlenFileReceivingConnection(HANDLE hConnection, DWORD, void * pExtra ft->proto->debugLogA("Closing connection for this file transfer... (ft->s is now hBind)"); ft->s = slisten; ft->proto->debugLogA("ft->s is restored to %d", ft->s); - if (ft->s != hConnection) { + + if (ft->s != hConnection) Netlib_CloseHandle(hConnection); - } if (ft->hFileEvent != NULL) SetEvent(ft->hFileEvent); - } else { - Netlib_CloseHandle(hConnection); } + else Netlib_CloseHandle(hConnection); } - static void __cdecl TlenFileReceiveThread(TLEN_FILE_TRANSFER *ft) { ft->proto->debugLogA("Thread started: type=file_receive server='%s' port='%d'", ft->hostName, ft->wPort); @@ -189,19 +181,20 @@ static void __cdecl TlenFileReceiveThread(TLEN_FILE_TRANSFER *ft) nloc.szHost = ft->hostName; nloc.wPort = ft->wPort; ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, ft, 0); - HANDLE s = (HANDLE) CallService(MS_NETLIB_OPENCONNECTION, (WPARAM) ft->proto->m_hNetlibUser, (LPARAM) &nloc); + HANDLE s = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)ft->proto->m_hNetlibUser, (LPARAM)&nloc); if (s != NULL) { ft->s = s; ft->proto->debugLogA("Entering file receive loop"); TlenP2PEstablishOutgoingConnection(ft, TRUE); - while (ft->state != FT_DONE && ft->state != FT_ERROR) { + while (ft->state != FT_DONE && ft->state != FT_ERROR) TlenFileReceiveParse(ft); - } + if (ft->s) { Netlib_CloseHandle(s); + ft->s = NULL; } - ft->s = NULL; - } else { + } + else { ft->pfnNewConnectionV2 = TlenFileReceivingConnection; ft->proto->debugLogA("Connection failed - receiving as server"); s = TlenP2PListen(ft); @@ -220,7 +213,8 @@ static void __cdecl TlenFileReceiveThread(TLEN_FILE_TRANSFER *ft) CloseHandle(hEvent); ft->proto->debugLogA("Finish all files"); Netlib_CloseHandle(s); - } else { + } + else { ft->state = FT_ERROR; } } @@ -248,23 +242,22 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) char *fileBuffer; TLEN_FILE_PACKET *packet; - if (ft->state == FT_CONNECTING) { char filename[256]; // Must be 256 (0x100) - if ((packet=TlenP2PPacketCreate(sizeof(DWORD)+(ft->fileCount*(sizeof(filename)+sizeof(DWORD))))) != NULL) { + if ((packet = TlenP2PPacketCreate(sizeof(DWORD) + (ft->fileCount*(sizeof(filename) + sizeof(DWORD))))) != NULL) { // Must pause a bit, sending these two packets back to back // will break the session because the receiver cannot take it :) SleepEx(1000, TRUE); TlenP2PPacketSetLen(packet, 0); // Reuse packet TlenP2PPacketSetType(packet, TLEN_FILE_PACKET_FILE_LIST); - TlenP2PPacketPackDword(packet, (DWORD) ft->fileCount); - for (i=0; ifileCount; i++) { -// struct _stat statbuf; -// _stat(ft->files[i], &statbuf); -// TlenP2PPacketPackDword(packet, statbuf.st_size); + TlenP2PPacketPackDword(packet, (DWORD)ft->fileCount); + for (i = 0; i < ft->fileCount; i++) { + // struct _stat statbuf; + // _stat(ft->files[i], &statbuf); + // TlenP2PPacketPackDword(packet, statbuf.st_size); TlenP2PPacketPackDword(packet, ft->filesSize[i]); memset(filename, 0, sizeof(filename)); - if ((t=strrchr(ft->files[i], '\\')) != NULL) + if ((t = strrchr(ft->files[i], '\\')) != NULL) t++; else t = ft->files[i]; @@ -278,9 +271,7 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) ft->state = FT_INITIALIZING; ft->proto->debugLogA("Change to FT_INITIALIZING"); } - else { - ft->state = FT_ERROR; - } + else ft->state = FT_ERROR; } else if (ft->state == FT_INITIALIZING) { // FT_INITIALIZING TLEN_FILE_PACKET *rpacket = TlenP2PPacketReceive(ft->s); @@ -312,13 +303,13 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) ft->state = FT_ERROR; } else { - // _stat(ft->files[currentFile], &statbuf); // file size in statbuf.st_size + // _stat(ft->files[currentFile], &statbuf); // file size in statbuf.st_size ft->proto->debugLogA("Sending [%s] [%d]", ft->files[currentFile], ft->filesSize[currentFile]); - if ((ft->fileId=_open(ft->files[currentFile], _O_BINARY|_O_RDONLY)) < 0) { + if ((ft->fileId = _open(ft->files[currentFile], _O_BINARY | _O_RDONLY)) < 0) { ft->proto->debugLogA("File cannot be opened"); ft->state = FT_ERROR; } - else { + else { memset(&pfts, 0, sizeof(PROTOFILETRANSFERSTATUS)); pfts.cbSize = sizeof(PROTOFILETRANSFERSTATUS); pfts.hContact = ft->hContact; @@ -332,16 +323,16 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) pfts.currentFileSize = ft->filesSize[ft->currentFile]; //statbuf.st_size; pfts.currentFileTime = 0; ft->fileReceivedBytes = 0; - if ((packet = TlenP2PPacketCreate(2*sizeof(DWORD)+2048)) == NULL) { + if ((packet = TlenP2PPacketCreate(2 * sizeof(DWORD) + 2048)) == NULL) { ft->state = FT_ERROR; } else { TlenP2PPacketSetType(packet, TLEN_FILE_PACKET_FILE_DATA); - fileBuffer = (char *) mir_alloc(2048); + fileBuffer = (char *)mir_alloc(2048); ft->proto->debugLogA("Sending file data..."); - while ((numRead=_read(ft->fileId, fileBuffer, 2048)) > 0) { + while ((numRead = _read(ft->fileId, fileBuffer, 2048)) > 0) { TlenP2PPacketSetLen(packet, 0); // Reuse packet - TlenP2PPacketPackDword(packet, (DWORD) ft->fileReceivedBytes); + TlenP2PPacketPackDword(packet, (DWORD)ft->fileReceivedBytes); TlenP2PPacketPackDword(packet, 0); TlenP2PPacketPackBuffer(packet, fileBuffer, numRead); if (TlenP2PPacketSend(ft->s, packet)) { @@ -349,7 +340,7 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) ft->allFileReceivedBytes += numRead; pfts.totalProgress = ft->allFileReceivedBytes; pfts.currentFileProgress = ft->fileReceivedBytes; - ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM) &pfts); + ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&pfts); } else { ft->state = FT_ERROR; @@ -359,7 +350,7 @@ static void TlenFileSendParse(TLEN_FILE_TRANSFER *ft) mir_free(fileBuffer); _close(ft->fileId); if (ft->state != FT_ERROR) { - if (ft->currentFile >= ft->fileCount-1) + if (ft->currentFile >= ft->fileCount - 1) ft->state = FT_DONE; else { ft->currentFile++; @@ -408,14 +399,13 @@ static void TlenFileSendingConnection(HANDLE hConnection, DWORD, void * pExtra) ft->proto->debugLogA("Closing connection for this file transfer... (ft->s is now hBind)"); ft->s = slisten; ft->proto->debugLogA("ft->s is restored to %d", ft->s); - if (ft->s != hConnection) { + + if (ft->s != hConnection) Netlib_CloseHandle(hConnection); - } if (ft->hFileEvent != NULL) SetEvent(ft->hFileEvent); - } else { - Netlib_CloseHandle(hConnection); } + else Netlib_CloseHandle(hConnection); } int TlenFileCancelAll(TlenProtocol *proto) @@ -423,7 +413,7 @@ int TlenFileCancelAll(TlenProtocol *proto) HANDLE hEvent; int i = 0; - while ((i=TlenListFindNext(proto, LIST_FILE, 0)) >=0 ) { + while ((i = TlenListFindNext(proto, LIST_FILE, 0)) >= 0) { TLEN_LIST_ITEM *item = TlenListGetItemPtrFromIndex(proto, i); if (item != NULL) { TLEN_FILE_TRANSFER *ft = item->ft; @@ -440,7 +430,8 @@ int TlenFileCancelAll(TlenProtocol *proto) ft->hFileEvent = NULL; SetEvent(hEvent); } - } else { + } + else { ft->proto->debugLogA("freeing ft struct"); TlenP2PFreeFileTransfer(ft); } @@ -488,30 +479,31 @@ static void __cdecl TlenFileSendingThread(TLEN_FILE_TRANSFER *ft) NETLIBOPENCONNECTION nloc = { sizeof(nloc) }; nloc.szHost = ft->hostName; nloc.wPort = ft->wPort; - HANDLE s = (HANDLE) CallService(MS_NETLIB_OPENCONNECTION, (WPARAM) ft->proto->m_hNetlibUser, (LPARAM) &nloc); - if (s != NULL) { + HANDLE hConn = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)ft->proto->m_hNetlibUser, (LPARAM)&nloc); + if (hConn != NULL) { ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, ft, 0); - ft->s = s; + ft->s = hConn; TlenP2PEstablishOutgoingConnection(ft, TRUE); ft->proto->debugLogA("Entering send loop for this file connection..."); - while (ft->state != FT_DONE && ft->state != FT_ERROR) { + while (ft->state != FT_DONE && ft->state != FT_ERROR) TlenFileSendParse(ft); - } + if (ft->state == FT_DONE) ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ft, 0); else ProtoBroadcastAck(ft->proto->m_szModuleName, ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); ft->proto->debugLogA("Closing connection for this file transfer... "); - Netlib_CloseHandle(s); - } else { - ft->state = FT_ERROR; + Netlib_CloseHandle(hConn); } + else ft->state = FT_ERROR; } - } else { + } + else { ft->proto->debugLogA("Cannot allocate port to bind for file server thread, thread ended."); ft->state = FT_ERROR; } TlenListRemove(ft->proto, LIST_FILE, ft->iqId); + switch (ft->state) { case FT_DONE: ft->proto->debugLogA("Finish successfully"); @@ -533,8 +525,9 @@ static void __cdecl TlenFileSendingThread(TLEN_FILE_TRANSFER *ft) } -TLEN_FILE_TRANSFER *TlenFileCreateFT(TlenProtocol *proto, const char *jid) { - TLEN_FILE_TRANSFER *ft = (TLEN_FILE_TRANSFER *) mir_alloc(sizeof(TLEN_FILE_TRANSFER)); +TLEN_FILE_TRANSFER *TlenFileCreateFT(TlenProtocol *proto, const char *jid) +{ + 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); @@ -552,46 +545,44 @@ void TlenProcessF(XmlNode *node, ThreadData *info) int numFiles; TLEN_LIST_ITEM *item; -// if (!node->name || mir_strcmp(node->name, "f")) return; + // if (!node->name || mir_strcmp(node->name, "f")) return; if (info == NULL) return; - char *from=TlenXmlGetAttrValue(node, "f"); + char *from = TlenXmlGetAttrValue(node, "f"); if (from != NULL) { - if (strchr(from, '@') == NULL) { + if (strchr(from, '@') == NULL) mir_snprintf(jid, _countof(jid), "%s@%s", from, info->server); - } else { + else strncpy_s(jid, from, _TRUNCATE); - } - char *e=TlenXmlGetAttrValue(node, "e"); + + char *e = TlenXmlGetAttrValue(node, "e"); if (e != NULL) { if (!mir_strcmp(e, "1")) { // FILE_RECV : e='1' : File transfer request TLEN_FILE_TRANSFER *ft = TlenFileCreateFT(info->proto, jid); ft->hContact = TlenHContactFromJID(info->proto, jid); - if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) + if ((p = TlenXmlGetAttrValue(node, "i")) != NULL) ft->iqId = mir_strdup(p); szFilename[0] = '\0'; - if ((p=TlenXmlGetAttrValue(node, "c")) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "c")) != NULL) { numFiles = atoi(p); if (numFiles == 1) { - if ((p=TlenXmlGetAttrValue(node, "n")) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "n")) != NULL) { p = TlenTextDecode(p); - strncpy(szFilename, p, sizeof(szFilename)-1); + strncpy(szFilename, p, sizeof(szFilename) - 1); mir_free(p); - } else { - mir_strcpy(szFilename, Translate("1 File")); } + else mir_strcpy(szFilename, Translate("1 File")); } - else if (numFiles > 1) { + else if (numFiles > 1) mir_snprintf(szFilename, _countof(szFilename), Translate("%d Files"), numFiles); - } } if (szFilename[0] != '\0' && ft->iqId != NULL) { TCHAR* filenameT = mir_utf8decodeT((char*)szFilename); - PROTORECVFILET pre = {0}; + PROTORECVFILET pre = { 0 }; pre.dwFlags = PRFF_TCHAR; pre.fileCount = 1; pre.timestamp = time(NULL); @@ -601,7 +592,8 @@ void TlenProcessF(XmlNode *node, ThreadData *info) ft->proto->debugLogA("sending chainrecv"); ProtoChainRecvFile(ft->hContact, &pre); mir_free(filenameT); - } else { + } + else { // malformed request, reject if (ft->iqId) TlenSend(ft->proto, "", ft->iqId, from); @@ -612,8 +604,8 @@ void TlenProcessF(XmlNode *node, ThreadData *info) } else if (!mir_strcmp(e, "3")) { // FILE_RECV : e='3' : invalid transfer error - if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) { - if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "i")) != NULL) { + if ((item = TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { if (item->ft != NULL) { ProtoBroadcastAck(info->proto->m_szModuleName, item->ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, item->ft, 0); info->proto->FileCancel(NULL, item->ft); @@ -624,8 +616,8 @@ void TlenProcessF(XmlNode *node, ThreadData *info) } else if (!mir_strcmp(e, "4")) { // FILE_SEND : e='4' : File sending request was denied by the remote client - if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) { - if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "i")) != NULL) { + if ((item = TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { if (!mir_strcmp(item->ft->jid, jid)) { ProtoBroadcastAck(info->proto->m_szModuleName, item->ft->hContact, ACKTYPE_FILE, ACKRESULT_DENIED, item->ft, 0); TlenListRemove(info->proto, LIST_FILE, p); @@ -635,22 +627,20 @@ void TlenProcessF(XmlNode *node, ThreadData *info) } else if (!mir_strcmp(e, "5")) { // FILE_SEND : e='5' : File sending request was accepted - if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) { - if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "i")) != NULL) + if ((item = TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) if (!mir_strcmp(item->ft->jid, jid)) - forkthread((void (__cdecl *)(void*))TlenFileSendingThread, 0, item->ft); - } - } + forkthread((void(__cdecl *)(void*))TlenFileSendingThread, 0, item->ft); } else if (!mir_strcmp(e, "6")) { // FILE_RECV : e='6' : IP and port information to connect to get file - if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) { - if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { - if ((p=TlenXmlGetAttrValue(node, "a")) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "i")) != NULL) { + if ((item = TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "a")) != NULL) { item->ft->hostName = mir_strdup(p); - if ((p=TlenXmlGetAttrValue(node, "p")) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "p")) != NULL) { item->ft->wPort = atoi(p); - forkthread((void (__cdecl *)(void*))TlenFileReceiveThread, 0, item->ft); + forkthread((void(__cdecl *)(void*))TlenFileReceiveThread, 0, item->ft); } } } @@ -659,12 +649,12 @@ void TlenProcessF(XmlNode *node, ThreadData *info) else if (!mir_strcmp(e, "7")) { // FILE_RECV : e='7' : IP and port information to connect to send file // in case the conection to the given server was not successful - if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) { - if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { - if ((p=TlenXmlGetAttrValue(node, "a")) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "i")) != NULL) { + if ((item = TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "a")) != NULL) { if (item->ft->hostName != NULL) mir_free(item->ft->hostName); item->ft->hostName = mir_strdup(p); - if ((p=TlenXmlGetAttrValue(node, "p")) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "p")) != NULL) { item->ft->wPort = atoi(p); item->ft->state = FT_SWITCH; SetEvent(item->ft->hFileEvent); @@ -675,14 +665,13 @@ void TlenProcessF(XmlNode *node, ThreadData *info) } else if (!mir_strcmp(e, "8")) { // FILE_RECV : e='8' : transfer error - if ((p=TlenXmlGetAttrValue(node, "i")) != NULL) { - if ((item=TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { + if ((p = TlenXmlGetAttrValue(node, "i")) != NULL) { + if ((item = TlenListGetItemPtr(info->proto, LIST_FILE, p)) != NULL) { item->ft->state = FT_ERROR; - if (item->ft->hFileEvent != NULL) { + if (item->ft->hFileEvent != NULL) SetEvent(item->ft->hFileEvent); - } else { + else ProtoBroadcastAck(info->proto->m_szModuleName, item->ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, item->ft, 0); - } } } } diff --git a/protocols/Twitter/src/contacts.cpp b/protocols/Twitter/src/contacts.cpp index e9424a040f..0a621e1c13 100644 --- a/protocols/Twitter/src/contacts.cpp +++ b/protocols/Twitter/src/contacts.cpp @@ -19,13 +19,13 @@ along with this program. If not, see . #include "stdafx.h" #include "proto.h" -void TwitterProto::AddToListWorker(void *p) +void TwitterProto::AddToListWorker(void *pArg) { // TODO: what happens if there is an error? - if (p == 0) + if (pArg == 0) return; - char *name = static_cast(p); + char *name = static_cast(pArg); try { twitter_user user; @@ -57,14 +57,15 @@ MCONTACT TwitterProto::AddToList(int, PROTOSEARCHRESULT *psr) void TwitterProto::UpdateInfoWorker(void *arg) { - MCONTACT hContact = (MCONTACT) arg; + MCONTACT hContact = (MCONTACT)(DWORD_PTR)arg; twitter_user user; ptrA username(getStringA(hContact, TWITTER_KEY_UN)); if (username == NULL) return; - { mir_cslock s(twitter_lock_); + { + mir_cslock s(twitter_lock_); twit_.get_info(std::string(username), &user); } @@ -93,17 +94,18 @@ int TwitterProto::GetInfo(MCONTACT hContact, int info_type) struct search_query { search_query(const std::tstring &_query, bool _by_email) : query(_query), by_email(_by_email) - {} + { + } std::tstring query; bool by_email; }; -void TwitterProto::DoSearch(void *p) +void TwitterProto::DoSearch(void *pArg) { - if (p == 0) + if (pArg == 0) return; - search_query *query = static_cast(p); + search_query *query = static_cast(pArg); twitter_user info; bool found = false; @@ -155,7 +157,7 @@ HANDLE TwitterProto::SearchByEmail(const TCHAR *email) void TwitterProto::GetAwayMsgWorker(void *arg) { - MCONTACT hContact = (MCONTACT) arg; + MCONTACT hContact = (MCONTACT)(DWORD_PTR)arg; if (hContact == 0) return; @@ -175,7 +177,7 @@ HANDLE TwitterProto::GetAwayMsg(MCONTACT hContact) int TwitterProto::OnContactDeleted(WPARAM wParam, LPARAM) { - MCONTACT hContact = (MCONTACT) wParam; + MCONTACT hContact = (MCONTACT)wParam; if (m_iStatus != ID_STATUS_ONLINE) return 0; -- cgit v1.2.3