From 9b1fc3cd956ce527bd744c538db6cfb5fff572e6 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Thu, 19 Feb 2015 21:48:19 +0000 Subject: SkypeClassic: - Fixed an ambiguous message box - Fixed uninitialized variables - fixed potential double free - other cleanup git-svn-id: http://svn.miranda-ng.org/main/trunk@12205 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeClassic/src/skype.cpp | 56 +++++++++++---------- protocols/SkypeClassic/src/skype.h | 7 --- protocols/SkypeClassic/src/skypeapi.cpp | 89 +++++++++++++++++---------------- protocols/SkypeClassic/src/skypeapi.h | 4 -- 4 files changed, 76 insertions(+), 80 deletions(-) (limited to 'protocols/SkypeClassic/src') diff --git a/protocols/SkypeClassic/src/skype.cpp b/protocols/SkypeClassic/src/skype.cpp index cc72190567..60c5f89556 100644 --- a/protocols/SkypeClassic/src/skype.cpp +++ b/protocols/SkypeClassic/src/skype.cpp @@ -73,7 +73,10 @@ char cmdMessage[12] = "MESSAGE", cmdPartner[8] = "PARTNER"; // Compatibility com // Direct assignment of user properties to a DB-Setting -static const settings_map m_settings[] = { +struct settings_map { + char *SkypeSetting; + char *MirandaSetting; +} m_settings[] = { { "LANGUAGE", "Language1" }, { "PROVINCE", "State" }, { "CITY", "City" }, @@ -84,9 +87,6 @@ static const settings_map m_settings[] = { { "ABOUT", "About" } }; -// Imported Globals -extern status_map status_codes[]; - BOOL(WINAPI *MyEnableThemeDialogTexture)(HANDLE, DWORD) = 0; HMODULE hUxTheme = 0; @@ -273,8 +273,9 @@ int HookContactDeleted(WPARAM wParam, LPARAM) { return 0; } -void GetInfoThread(void *hContact) +void GetInfoThread(void *arg) { + MCONTACT hContact = (MCONTACT)arg; DBVARIANT dbv; int i; char *ptr; @@ -289,7 +290,7 @@ void GetInfoThread(void *hContact) LOG(("GetInfoThread started.")); EnterCriticalSection(&QueryThreadMutex); - if (db_get_s((MCONTACT)hContact, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) + if (db_get_s(hContact, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) { LOG(("GetInfoThread terminated, cannot find Skype Name for contact %08X.", hContact)); LeaveCriticalSection(&QueryThreadMutex); @@ -305,7 +306,7 @@ void GetInfoThread(void *hContact) if (ptr = SkypeGet("USER", dbv.pszVal, "FULLNAME")) { if (*ptr && !bSetNick && db_get_b(NULL, SKYPE_PROTONAME, "ShowFullname", 1)) { // No Displayname and FULLNAME requested - db_set_utf((MCONTACT)hContact, SKYPE_PROTONAME, "Nick", ptr); + db_set_utf(hContact, SKYPE_PROTONAME, "Nick", ptr); bSetNick = TRUE; } free(ptr); @@ -313,7 +314,7 @@ void GetInfoThread(void *hContact) if (!bSetNick) { // Still no nick set, so use SKYPE Nickname - db_set_s((MCONTACT)hContact, SKYPE_PROTONAME, "Nick", dbv.pszVal); + db_set_s(hContact, SKYPE_PROTONAME, "Nick", dbv.pszVal); } @@ -331,7 +332,7 @@ void GetInfoThread(void *hContact) ACKDATA ack = { 0 }; ack.cbSize = sizeof(ACKDATA); ack.szModule = SKYPE_PROTONAME; - ack.hContact = (MCONTACT)hContact; + ack.hContact = hContact; ack.type = ACKTYPE_AVATAR; ack.result = ACKRESULT_STATUS; @@ -345,7 +346,7 @@ void GetInfoThread(void *hContact) if (ptr = SkypeGet("USER", dbv.pszVal, m_settings[i].SkypeSetting)) free(ptr); } - ProtoBroadcastAck(SKYPE_PROTONAME, (MCONTACT)hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0); + ProtoBroadcastAck(SKYPE_PROTONAME, hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0); LeaveCriticalSection(&QueryThreadMutex); db_free(&dbv); LOG(("GetInfoThread terminated gracefully.")); @@ -365,7 +366,7 @@ time_t SkypeTime(time_t *timer) void BasicSearchThread(char *nick) { PROTOSEARCHRESULT psr = { 0 }; - char *cmd = NULL, *token = NULL, *ptr = NULL, *nextoken; + char *cmd = NULL, *token = NULL, *ptr = NULL; time_t st; LOG(("BasicSearchThread started.")); @@ -374,6 +375,7 @@ void BasicSearchThread(char *nick) { if (SkypeSend("SEARCH USERS %s", nick) == 0 && (cmd = SkypeRcvTime("USERS", st, INFINITE))) { if (strncmp(cmd, "ERROR", 5)) { psr.cbSize = sizeof(psr); + char *nextoken = 0; for (token = strtok_r(cmd + 5, ", ", &nextoken); token; token = strtok_r(NULL, ", ", &nextoken)) { psr.nick = psr.id = _A2T(token); psr.lastName = NULL; @@ -447,7 +449,7 @@ INT_PTR ImportHistory(WPARAM wParam, LPARAM) { } int SearchFriends(void) { - char *ptr, *token, *pStat, *nextoken; + char *ptr, *token, *pStat; int iRet = 0; time_t st; @@ -456,6 +458,7 @@ int SearchFriends(void) { { if (strncmp(ptr, "ERROR", 5)) { if (ptr[5]) { + char *nextoken = 0; for (token = strtok_r(ptr + 5, ", ", &nextoken); token; token = strtok_r(NULL, ", ", &nextoken)) { if (!(pStat = SkypeGet("USER", token, "ONLINESTATUS"))) { @@ -534,16 +537,18 @@ void __cdecl ProcessAuthRq(void *pPmsg) { } void __cdecl SearchUsersWaitingMyAuthorization() { - char *cmd, *token, *nextoken; + if (SkypeSend("#UWA SEARCH USERSWAITINGMYAUTHORIZATION")) + return; - if (SkypeSend("#UWA SEARCH USERSWAITINGMYAUTHORIZATION") || !(cmd = SkypeRcv("#UWA USERS", INFINITE))) + char *cmd = SkypeRcv("#UWA USERS", INFINITE); + if (!cmd) return; if (!strncmp(cmd, "ERROR", 5)) { free(cmd); return; } - token = strtok_r(cmd + 10, ", ", &nextoken); + char *nextoken = 0, *token = strtok_r(cmd + 10, ", ", &nextoken); while (token) { QueryUserWaitingAuthorization(token, NULL); token = strtok_r(NULL, ", ", &nextoken); @@ -574,7 +579,7 @@ void __cdecl SearchRecentChats(void *) { return; } - char *token, *nextoken; + char *token, *nextoken = 0; for (token = strtok_r(cmd + 10, ", ", &nextoken); token; token = strtok_r(NULL, ", ", &nextoken)) { char *pszStatus = SkypeGet("CHAT", token, "STATUS"); @@ -1112,8 +1117,6 @@ void FetchMessageThread(fetchmsg_arg *pargs) { db_get_s(NULL, SKYPE_PROTONAME, SKYPE_NAME, &dbv); if (dbv.pszVal && !strcmp(who, dbv.pszVal)) { - char *pTok, *nextoken; - // It's from me.. But to whom? // CHATMESSAGE .. USERS doesn't return anything, so we have to query the CHAT-Object if (!(ptr = SkypeGetErr("CHAT", chat, "ACTIVEMEMBERS"))) { @@ -1121,6 +1124,7 @@ void FetchMessageThread(fetchmsg_arg *pargs) { __leave; } + char *pTok, *nextoken = 0; for (pTok = strtok_r(ptr, " ", &nextoken); pTok; pTok = strtok_r(NULL, " ", &nextoken)) { if (strcmp(pTok, dbv.pszVal)) break; // Take the first dude in the list who is not me } @@ -1393,14 +1397,14 @@ static int MsglCmpProc(const void *pstPElement, const void *pstPToFind) } void MessageListProcessingThread(char *str) { - char *token, *nextoken, *chat = NULL; + char *token, *nextoken = 0, *chat = NULL; fetchmsg_arg *args; TYP_LIST *hListMsgs = List_Init(32); // Frst we need to sort the message timestamps for ((token = strtok_r(str+1, ", ", &nextoken)); token; token = strtok_r(NULL, ", ", &nextoken)) { if (args = (fetchmsg_arg*)calloc(1, sizeof(fetchmsg_arg) + sizeof(DWORD))) { - strncpy(args->msgnum, token, sizeof(args->msgnum)); + strncpy(args->msgnum, token, sizeof(args->msgnum)-1); args->getstatus = TRUE; args->bIsRead = *str; args->bDontMarkSeen = *str; @@ -1806,7 +1810,7 @@ LRESULT APIENTRY WndProc(HWND hWndDlg, UINT message, UINT wParam, LONG lParam) break; } if (!strncmp(szSkypeMsg, "APPLICATION libpurple_typing", 28)) { - char *nextoken, *p; + char *nextoken = 0, *p; if (p = strtok_r(szSkypeMsg + 29, " ", &nextoken)) { @@ -1847,7 +1851,7 @@ LRESULT APIENTRY WndProc(HWND hWndDlg, UINT message, UINT wParam, LONG lParam) } } if (!strncmp(szSkypeMsg, "USER ", 5)) { - char *nextoken; + char *nextoken = 0; buf = _strdup(szSkypeMsg + 5); if ((nick = strtok_r(buf, " ", &nextoken)) && (ptr = strtok_r(NULL, " ", &nextoken))) @@ -1896,9 +1900,9 @@ LRESULT APIENTRY WndProc(HWND hWndDlg, UINT message, UINT wParam, LONG lParam) * error handling. */ if (!strcmp(ptr, "FULLNAME")) { - char *nm; + char *nm = strtok_r(NULL, " ", &nextoken); - if (nm = strtok_r(NULL, " ", &nextoken)) + if (nm) { db_set_utf(hContact, SKYPE_PROTONAME, "FirstName", nm); if (!(nm = strtok_r(NULL, "", &nextoken))) @@ -2176,7 +2180,7 @@ LRESULT APIENTRY WndProc(HWND hWndDlg, UINT message, UINT wParam, LONG lParam) // If new message is available, fetch it ptr[0] = 0; if (!(args = (fetchmsg_arg *)calloc(1, sizeof(*args)))) break; - strncpy(args->msgnum, pMsgNum, sizeof(args->msgnum)); + strncpy(args->msgnum, pMsgNum, sizeof(args->msgnum)-1); args->getstatus = FALSE; //args->bIsRead = strncmp(ptr+8, "READ", 4) == 0; pthread_create((pThreadFunc)FetchMessageThreadSync, args); @@ -2480,7 +2484,7 @@ void RetrieveUserAvatar(void *param) // Got it MoveFileExA(pszTempFile, AvatarFile, MOVEFILE_REPLACE_EXISTING); AI.format = PA_FORMAT_JPEG; - strcpy(AI.filename, AvatarFile); + strncpy(AI.filename, AvatarFile,SIZEOF(AI.filename)-1); ack.hProcess = (HANDLE)&AI; } diff --git a/protocols/SkypeClassic/src/skype.h b/protocols/SkypeClassic/src/skype.h index b1c2ee4523..7ad0ce8a99 100644 --- a/protocols/SkypeClassic/src/skype.h +++ b/protocols/SkypeClassic/src/skype.h @@ -151,10 +151,3 @@ int InitVSApi(); int FreeVSApi(); MCONTACT GetMetaHandle(DWORD dwId); void LaunchSkypeAndSetStatusThread(void *newStatus); - -// Structs - -typedef struct { - char *SkypeSetting; - char *MirandaSetting; -} settings_map; diff --git a/protocols/SkypeClassic/src/skypeapi.cpp b/protocols/SkypeClassic/src/skypeapi.cpp index 7cf33f03eb..bd8b8d6d11 100644 --- a/protocols/SkypeClassic/src/skypeapi.cpp +++ b/protocols/SkypeClassic/src/skypeapi.cpp @@ -35,7 +35,11 @@ extern char DefaultAvatarsFolder[MAX_PATH+1], *pszProxyCallout, protocol, g_szPr static TYP_MSGQ SkypeMsgs, SkypeSendQueue; -status_map status_codes[] = { +//status_map +struct status_map { + int id; + char *szStat; +} status_codes[] = { {ID_STATUS_AWAY, "AWAY"}, {ID_STATUS_NA, "NA"}, {ID_STATUS_DND, "DND"}, @@ -47,9 +51,6 @@ status_map status_codes[] = { {0, NULL} }; -//status_map - - static mir_cs ConnectMutex, SendMutex; static BOOL rcvThreadRunning=FALSE, isConnecting = FALSE; static SOCKET ClientSocket=INVALID_SOCKET; @@ -100,7 +101,6 @@ void rcvThread(char *dummy) { unsigned char cmd=0, nSlot; unsigned int length; char *buf=NULL; - COPYDATASTRUCT CopyData; int rcv; if (!UseSockets) return; @@ -130,18 +130,21 @@ void rcvThread(char *dummy) { LOG(("rcvThread OPEN_SLOT")); if (!(rcv = Recv(ClientSocket, (char*)&lenfn, sizeof(lenfn))) || !(rcv = Recv(ClientSocket, szFileName, lenfn))) { - LOG(("OPEN_SLOT failed: rcv=%d", rcv)); - rcv=0; + LOG(("OPEN_SLOT failed: rcv=0")); break; } utf8_decode(szFileName, &pszUTFFile); for (nSlot=0; nSlot=sizeof(m_FileSlots)/sizeof(m_FileSlots[0])) cmd=0; + if (m_FileSlots[nSlot]==INVALID_HANDLE_VALUE) + break; + if (nSlot>=sizeof(m_FileSlots)/sizeof(m_FileSlots[0])) + cmd=0; else { - if ((m_FileSlots[nSlot] = CreateFileA(pszUTFFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) - !=INVALID_HANDLE_VALUE) nSlot++; else nSlot=0; + if ((m_FileSlots[nSlot] = CreateFileA(pszUTFFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) !=INVALID_HANDLE_VALUE) + nSlot++; + else + nSlot=0; } free(pszUTFFile); LOG(("rcvThread OPEN_SLOT(%s) -> %d", szFileName, nSlot)); @@ -161,17 +164,13 @@ void rcvThread(char *dummy) { case CLOSE_SLOT: LOG(("rcvThread CLOSE_SLOT")); if (!(rcv = Recv(ClientSocket, (char*)&nSlot, sizeof(nSlot)))) { - LOG(("CLOSE_SLOT failed: rcv=%d")); - rcv=0; + LOG(("CLOSE_SLOT failed: rcv=0")); break; } LOG(("rcvThread CLOSE_SLOT(%d)", nSlot)); CloseHandle(m_FileSlots[nSlot-1]); m_FileSlots[nSlot-1]=INVALID_HANDLE_VALUE; - if (rcv) { - continue; - } - break; + continue; } } } @@ -192,7 +191,8 @@ void rcvThread(char *dummy) { //send(ClientSocket, (char *)&cmd, sizeof(cmd), 0); } else { LOG(("Received message: %s", buf)); - + + COPYDATASTRUCT CopyData; CopyData.dwData=0; CopyData.lpData=buf; CopyData.cbData=(DWORD)strlen(buf)+1; @@ -202,11 +202,11 @@ void rcvThread(char *dummy) { } } free(buf); + buf = 0; } } void sendThread(char *dummy) { - COPYDATASTRUCT CopyData; LRESULT SendResult; int oldstatus; unsigned int length; @@ -226,6 +226,7 @@ void sendThread(char *dummy) { } SendResult = 0; } else { + COPYDATASTRUCT CopyData; CopyData.dwData=0; CopyData.lpData=szMsg; CopyData.cbData=length+1; @@ -698,14 +699,15 @@ int SkypeMsgCollectGarbage(time_t age) { * -1 - Failure */ INT_PTR SkypeCall(WPARAM wParam, LPARAM lParam) { + MCONTACT hContact = (MCONTACT) wParam; DBVARIANT dbv; char *msg=0; int res; - if (!db_get_s((MCONTACT)wParam, SKYPE_PROTONAME, "CallId", &dbv)) { + if (!db_get_s(hContact, SKYPE_PROTONAME, "CallId", &dbv)) { res = -1; // no direct return, because dbv needs to be freed } else { - if (db_get_s((MCONTACT)wParam, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) return -1; + if (db_get_s(hContact, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) return -1; msg=(char *)malloc(strlen(dbv.pszVal)+6); strcpy(msg, "CALL "); strcat(msg, dbv.pszVal); @@ -730,28 +732,29 @@ INT_PTR SkypeCall(WPARAM wParam, LPARAM lParam) { */ INT_PTR SkypeCallHangup(WPARAM wParam, LPARAM lParam) { + MCONTACT hContact = (MCONTACT) wParam; DBVARIANT dbv; char *msg=0; - int res = -1; - if (!db_get_s((MCONTACT)wParam, SKYPE_PROTONAME, "CallId", &dbv)) { + if (!db_get_s(hContact, SKYPE_PROTONAME, "CallId", &dbv)) { msg=(char *)malloc(strlen(dbv.pszVal)+21); sprintf(msg, "SET %s STATUS FINISHED", dbv.pszVal); //sprintf(msg, "ALTER CALL %s HANGUP", dbv.pszVal); - res=SkypeSend(msg); + int res=SkypeSend(msg); #if _DEBUG - db_unset((MCONTACT)wParam, SKYPE_PROTONAME, "CallId"); + db_unset(hContact, SKYPE_PROTONAME, "CallId"); #endif //} else { - // if (db_get((HANDLE)wParam, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) return -1; + // if (db_get(hContact, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) return -1; // msg=(char *)malloc(strlen(dbv.pszVal)+6); // strcpy(msg, "CALL "); // strcat(msg, dbv.pszVal); // res=SkypeSend(msg); + return res; } db_free(&dbv); free(msg); - return res; + return -1; } /* FixNumber @@ -1011,14 +1014,15 @@ void SkypeOutCallErrorCheck(char *szCallId) { * -1 - Failure */ INT_PTR SkypeOutCall(WPARAM wParam, LPARAM lParam) { + MCONTACT hContact = (MCONTACT) wParam; DBVARIANT dbv; int res = -1; - if (wParam && !db_get_s((MCONTACT)wParam, SKYPE_PROTONAME, "CallId", &dbv)) { + if (wParam && !db_get_s(hContact, SKYPE_PROTONAME, "CallId", &dbv)) { res=SkypeSend("SET %s STATUS FINISHED", dbv.pszVal); pthread_create(( pThreadFunc )SkypeOutCallErrorCheck, _strdup(dbv.pszVal)); db_free(&dbv); - } else if (!CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DIAL), NULL, DialDlgProc, (LPARAM)wParam)) return -1; + } else if (!CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_DIAL), NULL, DialDlgProc, (LPARAM)hContact)) return -1; return res; } @@ -1030,14 +1034,14 @@ INT_PTR SkypeOutCall(WPARAM wParam, LPARAM lParam) { * -1 - Failure */ INT_PTR SkypeHoldCall(WPARAM wParam, LPARAM lParam) { + MCONTACT hContact = (MCONTACT) wParam; DBVARIANT dbv; - int retval; LOG(("SkypeHoldCall started")); - if (!wParam || db_get_s((MCONTACT)wParam, SKYPE_PROTONAME, "CallId", &dbv)) + if (!wParam || db_get_s(hContact, SKYPE_PROTONAME, "CallId", &dbv)) return -1; - retval = SkypeSend ("SET %s STATUS %s", dbv.pszVal, - db_get_b((MCONTACT)wParam, SKYPE_PROTONAME, "OnHold", 0)?"INPROGRESS":"ONHOLD"); + int retval = SkypeSend ("SET %s STATUS %s", dbv.pszVal, + db_get_b(hContact, SKYPE_PROTONAME, "OnHold", 0)?"INPROGRESS":"ONHOLD"); db_free(&dbv); return retval; } @@ -1229,12 +1233,12 @@ INT_PTR SkypeSetAvatar(WPARAM wParam, LPARAM lParam) { * -1 - Failure */ INT_PTR SkypeSendGuiFile(WPARAM wParam, LPARAM) { + MCONTACT hContact = (MCONTACT) wParam; DBVARIANT dbv; - int retval; - if (!wParam || db_get_s((MCONTACT)wParam, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) + if (!wParam || db_get_s(hContact, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) return -1; - retval=SkypeSend("OPEN FILETRANSFER %s", dbv.pszVal); + int retval=SkypeSend("OPEN FILETRANSFER %s", dbv.pszVal); db_free(&dbv); return retval; } @@ -1277,11 +1281,11 @@ INT_PTR SkypeChatCreate(WPARAM wParam, LPARAM lParam) { INT_PTR SkypeBlockContact(WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; MCONTACT hContact = (MCONTACT)wParam; - int iRet = 0; if (!hContact || db_get_s(hContact, SKYPE_PROTONAME, SKYPE_NAME, &dbv)) return -1; + int iRet = 0; if (SkypeSend("SET USER %s ISBLOCKED %s", dbv.pszVal, db_get_b(hContact, SKYPE_PROTONAME, "IsBlocked", 0) ? "FALSE" : "TRUE")) iRet = -1; db_free(&dbv); @@ -1386,9 +1390,9 @@ char *GetSkypeErrorMsg(char *str) { * FALSE- nope, sorry */ BOOL testfor(char *what, DWORD maxwait) { - char *res; - - if ((res=SkypeRcv(what, maxwait))==NULL) return FALSE; + char *res = SkypeRcv(what, maxwait); + if (res==NULL) + return FALSE; free(res); return TRUE; } @@ -1396,9 +1400,8 @@ BOOL testfor(char *what, DWORD maxwait) { char SendSkypeproxyCommand(char command) { int length=0; char reply=0; - BOOL res; - res = send(ClientSocket, (char *)&length, sizeof(length), 0)==SOCKET_ERROR + BOOL res = send(ClientSocket, (char *)&length, sizeof(length), 0)==SOCKET_ERROR || send(ClientSocket, (char *)&command, sizeof(command), 0)==SOCKET_ERROR || recv(ClientSocket, (char *)&reply, sizeof(reply), 0)==SOCKET_ERROR; if (res) @@ -1717,7 +1720,7 @@ static int _ConnectToSkypeAPI(char *path, int iStart) { int oldstatus=SkypeStatus; InterlockedExchange((long *)&SkypeStatus, (int)ID_STATUS_OFFLINE); ProtoBroadcastAck(SKYPE_PROTONAME, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) oldstatus, SkypeStatus); - OUTPUT(TranslateT("ERROR: Skype not running / too old / working!")); + OUTPUT(TranslateT("ERROR: Skype not running / too old / not working!")); return -1; } } diff --git a/protocols/SkypeClassic/src/skypeapi.h b/protocols/SkypeClassic/src/skypeapi.h index d5a8053a8f..120b7fb462 100644 --- a/protocols/SkypeClassic/src/skypeapi.h +++ b/protocols/SkypeClassic/src/skypeapi.h @@ -15,10 +15,6 @@ #define MAX_ENTRIES 128 // Max. 128 number-Entries in Dial-dlg. -typedef struct { - int id; - char *szStat; -} status_map; // Prototypes int SkypeMsgInit(void); -- cgit v1.2.3