summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/SkypeClassic/SkypeClassic_12.vcxproj2
-rw-r--r--protocols/SkypeClassic/SkypeClassic_12.vcxproj.filters6
-rw-r--r--protocols/SkypeClassic/src/filexfer.cpp180
3 files changed, 98 insertions, 90 deletions
diff --git a/protocols/SkypeClassic/SkypeClassic_12.vcxproj b/protocols/SkypeClassic/SkypeClassic_12.vcxproj
index b7868c7487..21ea50b56b 100644
--- a/protocols/SkypeClassic/SkypeClassic_12.vcxproj
+++ b/protocols/SkypeClassic/SkypeClassic_12.vcxproj
@@ -49,6 +49,7 @@
<ClCompile Include="src\alogon.cpp" />
<ClCompile Include="src\contacts.cpp" />
<ClCompile Include="src\debug.cpp" />
+ <ClCompile Include="src\filexfer.cpp" />
<ClCompile Include="src\gchat.cpp" />
<ClCompile Include="src\memlist.cpp" />
<ClCompile Include="src\msglist.cpp" />
@@ -66,6 +67,7 @@
<ClInclude Include="src\alogon.h" />
<ClInclude Include="src\contacts.h" />
<ClInclude Include="src\debug.h" />
+ <ClInclude Include="src\filexfer.h" />
<ClInclude Include="src\gchat.h" />
<ClInclude Include="src\memlist.h" />
<ClInclude Include="src\msglist.h" />
diff --git a/protocols/SkypeClassic/SkypeClassic_12.vcxproj.filters b/protocols/SkypeClassic/SkypeClassic_12.vcxproj.filters
index 1bdc0d088b..79f43911bf 100644
--- a/protocols/SkypeClassic/SkypeClassic_12.vcxproj.filters
+++ b/protocols/SkypeClassic/SkypeClassic_12.vcxproj.filters
@@ -63,6 +63,9 @@
<ClCompile Include="src\util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\filexfer.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\alogon.h">
@@ -119,6 +122,9 @@
<ClInclude Include="src\version.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="src\filexfer.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="res\add.ico">
diff --git a/protocols/SkypeClassic/src/filexfer.cpp b/protocols/SkypeClassic/src/filexfer.cpp
index e27afa9f42..21d475460c 100644
--- a/protocols/SkypeClassic/src/filexfer.cpp
+++ b/protocols/SkypeClassic/src/filexfer.cpp
@@ -12,7 +12,8 @@ INT_PTR SkypeRecvFile(WPARAM, LPARAM lParam)
DBEVENTINFO dbei = { 0 };
CCSDATA *ccs = (CCSDATA *)lParam;
PROTORECVEVENT *pre = (PROTORECVEVENT *)ccs->lParam;
- size_t cbFilename, nFiles;
+ size_t cbFilename;
+ int nFiles;
INT_PTR ret = 0;
db_unset(ccs->hContact, "CList", "Hidden");
@@ -22,14 +23,15 @@ INT_PTR SkypeRecvFile(WPARAM, LPARAM lParam)
if (pre->flags & PREF_CREATEREAD) dbei.flags |= DBEF_READ;
if (pre->flags & PREF_UTF) dbei.flags |= DBEF_UTF;
dbei.eventType = EVENTTYPE_FILE;
- dbei.cbBlob=sizeof(DWORD);
+ dbei.cbBlob = sizeof(DWORD);
if (pre->flags & PREF_UNICODE) {
- for(nFiles=0;cbFilename=wcslen((wchar_t*)&pre->szMessage[dbei.cbBlob])*sizeof(wchar_t);nFiles++)
- dbei.cbBlob+=cbFilename+sizeof(wchar_t);
- dbei.cbBlob+=sizeof(wchar_t);
- } else {
- for(nFiles=0;cbFilename=strlen(&pre->szMessage[dbei.cbBlob]);nFiles++)
- dbei.cbBlob+=cbFilename+1;
+ for (nFiles = 0; cbFilename = wcslen((wchar_t*)&pre->szMessage[dbei.cbBlob])*sizeof(wchar_t); nFiles++)
+ dbei.cbBlob += DWORD(cbFilename) + sizeof(wchar_t);
+ dbei.cbBlob += sizeof(wchar_t);
+ }
+ else {
+ for (nFiles = 0; cbFilename = strlen(&pre->szMessage[dbei.cbBlob]); nFiles++)
+ dbei.cbBlob += DWORD(cbFilename) + 1;
dbei.cbBlob++;
}
dbei.pBlob = (PBYTE)pre->szMessage;
@@ -40,23 +42,24 @@ INT_PTR SkypeRecvFile(WPARAM, LPARAM lParam)
/* Allocate basic entry and fill some stuff we already know */
if (pEntry->pfts = calloc(1, cbSize)) {
PROTOFILETRANSFERSTATUS *pfts = (PROTOFILETRANSFERSTATUS*)pEntry->pfts;
- size_t iOffs=sizeof(DWORD);
+ size_t iOffs = sizeof(DWORD);
pfts->cbSize = cbSize;
pfts->hContact = ccs->hContact;
pfts->totalFiles = nFiles;
- if (pfts->pszFiles=(char**)calloc(nFiles+1, sizeof(char*))) {
+ if (pfts->pszFiles = (char**)calloc(nFiles + 1, sizeof(char*))) {
if (pre->flags & PREF_UNICODE) {
wchar_t *pFN;
- for (size_t i=0; cbFilename=wcslen(pFN=(wchar_t*)&pre->szMessage[iOffs])*sizeof(wchar_t); i++) {
- pfts->pszFiles[i]=(char*)wcsdup(pFN);
- iOffs+=cbFilename+sizeof(wchar_t);
+ for (size_t i = 0; cbFilename = wcslen(pFN = (wchar_t*)&pre->szMessage[iOffs])*sizeof(wchar_t); i++) {
+ pfts->pszFiles[i] = (char*)wcsdup(pFN);
+ iOffs += cbFilename + sizeof(wchar_t);
}
- } else {
+ }
+ else {
char *pFN;
- for(size_t i=0;cbFilename=strlen(pFN=&pre->szMessage[iOffs]);i++) {
- pfts->pszFiles[i]=strdup(pFN);
- iOffs+=cbFilename+1;
+ for (size_t i = 0; cbFilename = strlen(pFN = &pre->szMessage[iOffs]); i++) {
+ pfts->pszFiles[i] = strdup(pFN);
+ iOffs += cbFilename + 1;
}
if (pre->flags & PREF_UTF) pfts->flags |= PFTS_UTF;
}
@@ -71,25 +74,28 @@ INT_PTR SkypeSendFile(WPARAM, LPARAM lParam)
{
CCSDATA *ccs = (CCSDATA *)lParam;
DBVARIANT dbv;
- char *mymsgcmd, *utfmsg = NULL, *pszFile=NULL;
+ char *mymsgcmd, *utfmsg = NULL, *pszFile = NULL;
TCHAR **files = (TCHAR**)ccs->lParam;
- int nFiles, iLen = 0, ret=0;
+ int nFiles, ret = 0;
BYTE bIsChatroom = 0 != db_get_b(ccs->hContact, SKYPE_PROTONAME, "ChatRoom", 0);
if (bIsChatroom) {
if (db_get_s(ccs->hContact, SKYPE_PROTONAME, "ChatRoomID", &dbv))
return 0;
mymsgcmd = "CHATFILE";
- } else {
+ }
+ else {
if (db_get_s(ccs->hContact, SKYPE_PROTONAME, SKYPE_NAME, &dbv))
return 0;
mymsgcmd = "FILE";
}
- for (nFiles=0; files[nFiles]; nFiles++) {
- utfmsg=(char*)make_utf8_string(files[nFiles]);
- iLen+=strlen(utfmsg)+3;
- if (pszFile=pszFile?(char*)realloc(pszFile, iLen):(char*)calloc(1,iLen)) {
- if (nFiles>0) strcat(pszFile, ",");
+
+ size_t iLen = 0;
+ for (nFiles = 0; files[nFiles]; nFiles++) {
+ utfmsg = (char*)make_utf8_string(files[nFiles]);
+ iLen += strlen(utfmsg) + 3;
+ if (pszFile = pszFile ? (char*)realloc(pszFile, iLen) : (char*)calloc(1, iLen)) {
+ if (nFiles > 0) strcat(pszFile, ",");
strcat(pszFile, "\"");
strcat(pszFile, utfmsg);
strcat(pszFile, "\"");
@@ -98,16 +104,16 @@ INT_PTR SkypeSendFile(WPARAM, LPARAM lParam)
}
if (pszFile) {
if (SkypeSend("%s %s %s", mymsgcmd, dbv.pszVal, pszFile) == 0) {
- /* No chatmessage IDs available for filetransfers, there is no possibility
- * in SkypeKit to check if incoming filetransfer SENT message belongs to
+ /* No chatmessage IDs available for filetransfers, there is no possibility
+ * in SkypeKit to check if incoming filetransfer SENT message belongs to
* the last file sent :( */
char *str = SkypeRcvTime("CHATFILE", SkypeTime(NULL), INFINITE);
if (str) {
if (strncmp(str, "ERROR", 5)) {
- char *pTok=strtok(str+9, " ");
+ char *pTok = strtok(str + 9, " ");
if (pTok) {
- ret=strtoul(pTok, NULL, 10);
+ ret = strtoul(pTok, NULL, 10);
TYP_MSGLENTRY *pEntry = MsgList_Add(ret, INVALID_HANDLE_VALUE);
if (pEntry) {
DWORD cbSize = sizeof(PROTOFILETRANSFERSTATUS);
@@ -119,9 +125,9 @@ INT_PTR SkypeSendFile(WPARAM, LPARAM lParam)
pfts->hContact = ccs->hContact;
pfts->totalFiles = nFiles;
pfts->flags = PFTS_SENDING;
- if (pfts->pszFiles=(char**)calloc(nFiles+1, sizeof(char*))) {
- for (int i=0; i<nFiles; i++)
- ((TCHAR**)pfts->pszFiles)[i]=_tcsdup(files[i]);
+ if (pfts->pszFiles = (char**)calloc(nFiles + 1, sizeof(char*))) {
+ for (int i = 0; i < nFiles; i++)
+ ((TCHAR**)pfts->pszFiles)[i] = _tcsdup(files[i]);
}
}
@@ -144,7 +150,7 @@ INT_PTR SkypeFileAllow(WPARAM, LPARAM lParam)
return 0;
TYP_MSGLENTRY *pEntry = MsgList_FindMessage(ccs->wParam);
- if(!pEntry)
+ if (!pEntry)
return 0;
char *pszMsgNum, szMsgNum[16];
@@ -157,7 +163,7 @@ INT_PTR SkypeFileAllow(WPARAM, LPARAM lParam)
char *pszDir = (char*)make_utf8_string((wchar_t*)ccs->lParam);
if (pszDir) {
for (pszMsgNum = strtok(pszXferIDs, ", "); pszMsgNum; pszMsgNum = strtok(NULL, ", ")) {
- if (SkypeSend("ALTER FILETRANSFER %s ACCEPT %s", pszMsgNum, pszDir)!=-1) {
+ if (SkypeSend("ALTER FILETRANSFER %s ACCEPT %s", pszMsgNum, pszDir) != -1) {
char *ptr = SkypeRcv("ALTER FILETRANSFER ACCEPT", 2000);
if (ptr) {
if (strncmp(ptr, "ERROR", 5))
@@ -184,14 +190,14 @@ INT_PTR SkypeFileCancel(WPARAM, LPARAM lParam)
char *pszMsgNum, szMsgNum[16], *ptr;
sprintf(szMsgNum, "%d", ccs->wParam);
char *pszXferIDs = SkypeGetErr("CHATMESSAGE", szMsgNum, "FILETRANSFERS");
- if (!pszXferIDs)
+ if (!pszXferIDs)
return 0;
INT_PTR ret = 1;
for (pszMsgNum = strtok(pszXferIDs, ", "); pszMsgNum; pszMsgNum = strtok(NULL, ", ")) {
- if (SkypeSend ("ALTER FILETRANSFER %s CANCEL", pszMsgNum)!=-1) {
- if (ptr=SkypeRcv("ALTER FILETRANSFER CANCEL", 2000)) {
+ if (SkypeSend("ALTER FILETRANSFER %s CANCEL", pszMsgNum) != -1) {
+ if (ptr = SkypeRcv("ALTER FILETRANSFER CANCEL", 2000)) {
if (strncmp(ptr, "ERROR", 5))
- ret=0;
+ ret = 0;
free(ptr);
}
}
@@ -203,10 +209,8 @@ INT_PTR SkypeFileCancel(WPARAM, LPARAM lParam)
void FXFreePFTS(void *Ppfts)
{
PROTOFILETRANSFERSTATUS *pfts = (PROTOFILETRANSFERSTATUS*)Ppfts;
-
- if (pfts->pszFiles)
- {
- for (int i=0; i<pfts->totalFiles; i++)
+ if (pfts->pszFiles) {
+ for (int i = 0; i < pfts->totalFiles; i++)
free(pfts->pszFiles[i]);
free(pfts->pszFiles);
free(pfts->szWorkingDir);
@@ -220,48 +224,42 @@ BOOL FXHandleRecv(PROTORECVEVENT *pre, MCONTACT hContact)
size_t cbMsg = sizeof(DWORD), cbNewSize;
char szMsgNum[16];
- sprintf (szMsgNum, "%d", pre->lParam);
+ sprintf(szMsgNum, "%d", pre->lParam);
char *pszXferIDs = SkypeGetErr("CHATMESSAGE", szMsgNum, "FILETRANSFERS");
- if (!pszXferIDs)
+ if (!pszXferIDs)
return FALSE;
- for (char *pszMsgNum = strtok(pszXferIDs, ", "); pszMsgNum; pszMsgNum = strtok(NULL, ", "))
- {
+
+ for (char *pszMsgNum = strtok(pszXferIDs, ", "); pszMsgNum; pszMsgNum = strtok(NULL, ", ")) {
char *pszStatus = SkypeGetErrID("FILETRANSFER", pszMsgNum, "STATUS");
- if (pszStatus)
- {
- if (!strcmp(pszStatus, "NEW") || !strcmp(pszStatus, "PLACEHOLDER"))
- {
+ if (pszStatus) {
+ if (!strcmp(pszStatus, "NEW") || !strcmp(pszStatus, "PLACEHOLDER")) {
char *pszType = SkypeGetErr("FILETRANSFER", pszMsgNum, "TYPE");
- if (pszType)
- {
- if (!strcmp(pszType, "INCOMING"))
- {
+ if (pszType) {
+ if (!strcmp(pszType, "INCOMING")) {
char *pszFN = SkypeGetErr("FILETRANSFER", pszMsgNum, "FILENAME");
- if (pszFN)
- {
- cbNewSize = cbMsg+strlen(pszFN)+2;
- if ((pre->szMessage = (char*)realloc(pre->szMessage, cbNewSize)))
- {
- memcpy(pre->szMessage+cbMsg, pszFN, cbNewSize-cbMsg-1);
- cbMsg=cbNewSize-1;
- } else pszMsgNum=NULL;
+ if (pszFN) {
+ cbNewSize = cbMsg + strlen(pszFN) + 2;
+ if ((pre->szMessage = (char*)realloc(pre->szMessage, cbNewSize))) {
+ memcpy(pre->szMessage + cbMsg, pszFN, cbNewSize - cbMsg - 1);
+ cbMsg = cbNewSize - 1;
+ }
+ else pszMsgNum = NULL;
pre->flags |= PREF_UTF;
free(pszFN);
}
}
- free (pszType);
+ free(pszType);
}
}
free(pszStatus);
}
}
free(pszXferIDs);
- if (pre->szMessage)
- {
- CCSDATA ccs = {0};
+ if (pre->szMessage) {
+ *((TCHAR*)&pre->szMessage[cbMsg]) = 0;
+ *((DWORD*)pre->szMessage) = pre->lParam;
- *((TCHAR*)&pre->szMessage[cbMsg])=0;
- *((DWORD*)pre->szMessage)=pre->lParam;
+ CCSDATA ccs = { 0 };
ccs.szProtoService = PSR_FILE;
ccs.hContact = hContact;
ccs.wParam = 0;
@@ -273,7 +271,8 @@ BOOL FXHandleRecv(PROTORECVEVENT *pre, MCONTACT hContact)
return FALSE;
}
-typedef struct {
+typedef struct
+{
BOOL bStatus;
char szNum[16];
char szArg[32];
@@ -289,14 +288,14 @@ void FXHandleMessageThread(ft_args *pargs)
DWORD dwChat = strtoul(pszChat, NULL, 10);
TYP_MSGLENTRY *pEntry = MsgList_FindMessage(dwChat);
- if(!pEntry) {
+ if (!pEntry) {
free(pargs);
free(pszChat);
return;
}
MCONTACT hContact = ((PROTOFILETRANSFERSTATUS*)pEntry->pfts)->hContact;
- if(!hContact) {
+ if (!hContact) {
free(pargs);
free(pszChat);
return;
@@ -314,12 +313,12 @@ void FXHandleMessageThread(ft_args *pargs)
else if (!strcmp(pargs->szArg, "COMPLETED")) {
// Check if all transfers from this message are completed.
char *pszMsgNum, *pszStatus;
- BOOL bAllComplete=TRUE;
+ BOOL bAllComplete = TRUE;
char *pszXferIDs = SkypeGetErr("CHATMESSAGE", pszChat, "FILETRANSFERS");
if (pszXferIDs) {
for (pszMsgNum = strtok(pszXferIDs, ", "); pszMsgNum; pszMsgNum = strtok(NULL, ", ")) {
- if (pszStatus=SkypeGetErrID("FILETRANSFER", pszMsgNum, "STATUS")) {
- if (strcmp(pszStatus, "COMPLETED")) bAllComplete=FALSE;
+ if (pszStatus = SkypeGetErrID("FILETRANSFER", pszMsgNum, "STATUS")) {
+ if (strcmp(pszStatus, "COMPLETED")) bAllComplete = FALSE;
free(pszStatus);
if (!bAllComplete) break;
}
@@ -331,32 +330,33 @@ void FXHandleMessageThread(ft_args *pargs)
}
}
}
- } else {
+ }
+ else {
// BYTESTRANSFERRED
- PROTOFILETRANSFERSTATUS pfts={0};
+ PROTOFILETRANSFERSTATUS pfts = { 0 };
char *pszMsgNum;
int i;
// This always needs some fetching to fill PFTS :/
char *pszXferIDs = SkypeGetErr("CHATMESSAGE", pszChat, "FILETRANSFERS");
- if (pszXferIDs) {
- for (pszMsgNum = strtok(pszXferIDs, ", "),i=0; pszMsgNum; pszMsgNum = strtok(NULL, ", "),i++) {
+ if (pszXferIDs) {
+ for (pszMsgNum = strtok(pszXferIDs, ", "), i = 0; pszMsgNum; pszMsgNum = strtok(NULL, ", "), i++) {
DWORD dwTransferred;
- BOOL bIsCurFil = strcmp(pargs->szNum,pszMsgNum)==0;
+ BOOL bIsCurFil = strcmp(pargs->szNum, pszMsgNum) == 0;
if (bIsCurFil)
pfts.currentFileNumber = i;
char *pszcbFile = SkypeGetErr("FILETRANSFER", pszMsgNum, "FILESIZE");
if (pszcbFile) {
dwTransferred = strtoul(pszcbFile, NULL, 10);
- pfts.totalBytes+=dwTransferred;
- if (bIsCurFil) pfts.currentFileSize=dwTransferred;
+ pfts.totalBytes += dwTransferred;
+ if (bIsCurFil) pfts.currentFileSize = dwTransferred;
free(pszcbFile);
}
if (pszcbFile = SkypeGetErrID("FILETRANSFER", pszMsgNum, "BYTESTRANSFERRED")) {
dwTransferred = strtoul(pszcbFile, NULL, 10);
- pfts.totalProgress+=dwTransferred;
- if (bIsCurFil) pfts.currentFileProgress=dwTransferred;
+ pfts.totalProgress += dwTransferred;
+ if (bIsCurFil) pfts.currentFileProgress = dwTransferred;
free(pszcbFile);
}
}
@@ -378,19 +378,19 @@ void FXHandleMessageThread(ft_args *pargs)
BOOL FXHandleMessage(const char *pszMsg)
{
- ft_args args={0};
+ ft_args args = { 0 };
- const char *pTok=strchr(pszMsg, ' ');
+ const char *pTok = strchr(pszMsg, ' ');
if (!pTok)
return FALSE;
- strncpy(args.szNum, pszMsg, pTok-pszMsg);
- pszMsg=pTok+1;
- if (!(pTok=strchr(pszMsg, ' '))) return FALSE;
+ strncpy(args.szNum, pszMsg, pTok - pszMsg);
+ pszMsg = pTok + 1;
+ if (!(pTok = strchr(pszMsg, ' '))) return FALSE;
pTok++;
- if (!(args.bStatus=!strncmp(pszMsg, "STATUS", 6)) && strncmp(pszMsg, "BYTESTRANSFERRED", 16))
+ if (!(args.bStatus = !strncmp(pszMsg, "STATUS", 6)) && strncmp(pszMsg, "BYTESTRANSFERRED", 16))
return FALSE;
- ft_args *pargs=(ft_args*)malloc(sizeof(args));
+ ft_args *pargs = (ft_args*)malloc(sizeof(args));
if (!pargs) return TRUE;
strncpy(args.szArg, pTok, sizeof(args.szArg));
memcpy(pargs, &args, sizeof(args));