diff options
| author | George Hazan <george.hazan@gmail.com> | 2015-11-11 15:06:35 +0000 | 
|---|---|---|
| committer | George Hazan <george.hazan@gmail.com> | 2015-11-11 15:06:35 +0000 | 
| commit | 9dbda7a1ea9d0ac91e02bf4e605618203faf83bc (patch) | |
| tree | a9bd5e9b1d65664ac00635d8fd2ecd1217df5c85 | |
| parent | d6990ccddb9d6f432fd0392e241d48f95102cf13 (diff) | |
thread library:
- _beginthread replaced with CreateThread();
- functions forkthread & forkthreadex removed;
- macroses mir_forkthread, mir_forkthreadex & mir_forkthreadowner became real functions;
git-svn-id: http://svn.miranda-ng.org/main/trunk@15710 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
33 files changed, 205 insertions, 188 deletions
diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib Binary files differindex e9b47a15a4..adf79d9616 100644 --- a/bin10/lib/mir_core.lib +++ b/bin10/lib/mir_core.lib diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib Binary files differindex 820219fdba..94ba8545b0 100644 --- a/bin10/lib/mir_core64.lib +++ b/bin10/lib/mir_core64.lib diff --git a/bin12/lib/mir_core.lib b/bin12/lib/mir_core.lib Binary files differindex e9b47a15a4..adf79d9616 100644 --- a/bin12/lib/mir_core.lib +++ b/bin12/lib/mir_core.lib diff --git a/bin12/lib/mir_core64.lib b/bin12/lib/mir_core64.lib Binary files differindex 820219fdba..94ba8545b0 100644 --- a/bin12/lib/mir_core64.lib +++ b/bin12/lib/mir_core64.lib diff --git a/bin14/lib/mir_core.lib b/bin14/lib/mir_core.lib Binary files differindex e9b47a15a4..adf79d9616 100644 --- a/bin14/lib/mir_core.lib +++ b/bin14/lib/mir_core.lib diff --git a/bin14/lib/mir_core64.lib b/bin14/lib/mir_core64.lib Binary files differindex 820219fdba..94ba8545b0 100644 --- a/bin14/lib/mir_core64.lib +++ b/bin14/lib/mir_core64.lib diff --git a/include/delphi/m_core.inc b/include/delphi/m_core.inc index 624d5cd317..acc558ece9 100644 --- a/include/delphi/m_core.inc +++ b/include/delphi/m_core.inc @@ -553,9 +553,13 @@ function Thread_Pop():int_ptr; stdcall;  procedure Thread_Wait(); stdcall;
                   external CoreDLL name 'Thread_Wait';
 -function forkthread(func:pThreadFunc; stacksize:uint; arg:pointer):uint_ptr; stdcall;
 -                 external CoreDLL name 'forkthread';
 -function forkthreadex(sec:pointer; stacksize:uint; func:pThreadFuncEx; owner:pointer; arg:pointer; thraddr:puint_ptr):uint_ptr; stdcall;
 +function mir_forkthread(aFunc:pThreadFunc; arg:pointer):THANDLE; stdcall;
 +                 external CoreDLL name 'forkthreadex';
 +
 +function mir_forkthreadex(aFunc:pThreadFuncEx; arg:pointer; pThreadID:puint_ptr):THANDLE; stdcall;
 +                 external CoreDLL name 'forkthreadex';
 +
 +function mir_forkthreadowner(aFunc:pThreadFuncOwner; owner:pointer; arg:pointer; pThreadID:puint_ptr):THANDLE; stdcall;
                   external CoreDLL name 'forkthreadex';
  procedure Thread_SetName(const szThreadName:PAnsiChar); stdcall;
 diff --git a/include/delphi/m_helpers.inc b/include/delphi/m_helpers.inc index 3bad7b4ed7..21d5570f0a 100644 --- a/include/delphi/m_helpers.inc +++ b/include/delphi/m_helpers.inc @@ -16,10 +16,6 @@ function CreateVersionStringPlugin(pluginInfo:PPluginInfoEx;buf:PAnsiChar):PAnsi  function PLUGIN_MAKE_VERSION(a,b,c,d: Cardinal): int;
  function PLUGIN_CMP_VERSION(verA: LongInt; verB: LongInt): int;
 -function mir_forkthread(aFunc:pThreadFunc; arg:pointer):THANDLE; {inline}
 -function mir_forkthreadex(aFunc:pThreadFuncEx; arg:pointer; pThreadID:puint_ptr):THANDLE; {inline}
 -function mir_forkthreadowner(aFunc:pThreadFuncOwner; owner:pointer; arg:pointer; pThreadID:puint_ptr):THANDLE; {inline}
 -
  function Netlib_CloseHandle(Handle: THANDLE): int;
  function Netlib_GetBase64DecodedBufferSize(const cchEncoded: int): int;
  function Netlib_GetBase64EncodedBufferSize(const cbDecoded: int): int;
 @@ -188,24 +184,6 @@ begin    Inc(Result, (verA and $FF000000) - (verB and $FF000000));
  end;
 -
 -function mir_forkthread(aFunc:pThreadFunc; arg:pointer):THANDLE;
 -  {$IFDEF AllowInline}inline;{$ENDIF}
 -begin
 -	result:=forkthread(aFunc, 0, arg);
 -end;
 -function mir_forkthreadex(aFunc:pThreadFuncEx; arg:pointer; pThreadID:puint_ptr):THANDLE;
 -  {$IFDEF AllowInline}inline;{$ENDIF}
 -begin
 -	result:=forkthreadex(nil, 0, aFunc, nil, arg, pThreadID);
 -end;
 -function mir_forkthreadowner(aFunc:pThreadFuncOwner; owner:pointer; arg:pointer; pThreadID:puint_ptr):THANDLE;
 -  {$IFDEF AllowInline}inline;{$ENDIF}
 -begin
 -	result:=forkthreadex(nil, 0, pThreadFuncEx(aFunc), owner, arg, pThreadID);
 -end;
 -
 -
  function Netlib_CloseHandle(Handle: THANDLE): int;
    {$IFDEF AllowInline}inline;{$ENDIF}
  begin
 diff --git a/include/m_core.h b/include/m_core.h index 0634c63d7a..a9a900f03c 100644 --- a/include/m_core.h +++ b/include/m_core.h @@ -554,32 +554,27 @@ public:  ///////////////////////////////////////////////////////////////////////////////
  // threads
 -typedef void (__cdecl *pThreadFunc)(void*);
 -typedef unsigned (__stdcall *pThreadFuncEx)(void*);
 -typedef unsigned (__cdecl *pThreadFuncOwner)(void *owner, void* param);
 +typedef void (__cdecl *pThreadFunc)(void *param);
 +typedef unsigned (__stdcall *pThreadFuncEx)(void *param);
 +typedef unsigned (__cdecl *pThreadFuncOwner)(void *owner, void *param);
  #if defined( __cplusplus )
 -	MIR_CORE_DLL(INT_PTR) Thread_Push(HINSTANCE hInst, void* pOwner=NULL);
 +	MIR_CORE_DLL(INT_PTR) Thread_Push(HINSTANCE hInst, void* pOwner = NULL);
  #else
  	MIR_CORE_DLL(INT_PTR) Thread_Push(HINSTANCE hInst, void* pOwner);
  #endif
  MIR_CORE_DLL(INT_PTR) Thread_Pop(void);
  MIR_CORE_DLL(void)    Thread_Wait(void);
 -MIR_CORE_DLL(UINT_PTR) forkthread(pThreadFunc, unsigned long stacksize, void *arg);
 -MIR_CORE_DLL(UINT_PTR) forkthreadex(void *sec, unsigned stacksize, pThreadFuncEx, void* owner, void *arg, unsigned *thraddr);
 -
 -__forceinline HANDLE mir_forkthread(pThreadFunc aFunc, void* arg)
 -{	return (HANDLE)forkthread(aFunc, 0, arg);
 -}
 -
 -__forceinline HANDLE mir_forkthreadex(pThreadFuncEx aFunc, void* arg, unsigned* pThreadID)
 -{	return (HANDLE)forkthreadex(NULL, 0, aFunc, NULL, arg, pThreadID);
 -}
 -
 -__forceinline HANDLE mir_forkthreadowner(pThreadFuncOwner aFunc, void* owner, void* arg, unsigned* pThreadID)
 -{	return (HANDLE)forkthreadex(NULL, 0, (pThreadFuncEx)aFunc, owner, arg, pThreadID);
 -}
 +#if defined( __cplusplus )
 +MIR_CORE_DLL(HANDLE) mir_forkthread(pThreadFunc aFunc, void *arg = NULL);
 +MIR_CORE_DLL(HANDLE) mir_forkthreadex(pThreadFuncEx aFunc, void *arg = NULL, unsigned *pThreadID = NULL);
 +MIR_CORE_DLL(HANDLE) mir_forkthreadowner(pThreadFuncOwner aFunc, void *owner, void *arg = NULL, unsigned *pThreadID = NULL);
 +#else
 +MIR_CORE_DLL(HANDLE) mir_forkthread(pThreadFunc aFunc, void *arg);
 +MIR_CORE_DLL(HANDLE) mir_forkthreadex(pThreadFuncEx aFunc, void *arg, unsigned *pThreadID);
 +MIR_CORE_DLL(HANDLE) mir_forkthreadowner(pThreadFuncOwner aFunc, void *owner, void *arg, unsigned *pThreadID);
 +#endif
  MIR_CORE_DLL(void) Thread_SetName(const char *szThreadName);
 diff --git a/plugins/AVS/src/main.cpp b/plugins/AVS/src/main.cpp index 11f0b0ec86..373f536ed4 100644 --- a/plugins/AVS/src/main.cpp +++ b/plugins/AVS/src/main.cpp @@ -43,7 +43,7 @@ HANDLE hEventChanged, hEventContactAvatarChanged, hMyAvatarChanged;  void   InitServices();
 -static int ComparePicture(const protoPicCacheEntry* p1, const protoPicCacheEntry* p2)
 +static int ComparePicture(const protoPicCacheEntry *p1, const protoPicCacheEntry *p2)
  {
  	if ((mir_strcmp(p1->szProtoname, "Global avatar") == 0) || strstr(p1->szProtoname, "Global avatar"))
  		return -1;
 diff --git a/plugins/Clist_nicer/src/clcitems.cpp b/plugins/Clist_nicer/src/clcitems.cpp index 6dbfb937d6..63d7141a98 100644 --- a/plugins/Clist_nicer/src/clcitems.cpp +++ b/plugins/Clist_nicer/src/clcitems.cpp @@ -452,14 +452,8 @@ void LoadSkinItemToCache(TExtraCache *cEntry)  int __fastcall CLVM_GetContactHiddenStatus(MCONTACT hContact, char *szProto, struct ClcData *dat)
  {
  	int dbHidden = cfg::getByte(hContact, "CList", "Hidden", 0);		// default hidden state, always respect it.
 -	int filterResult = 1;
 -	DBVARIANT dbv = { 0 };
 -	char szTemp[64];
 -	TCHAR szGroupMask[256];
 -	DWORD dwLocalMask;
  	// always hide subcontacts (but show them on embedded contact lists)
 -
  	if (dat != NULL && dat->bHideSubcontacts && cfg::dat.bMetaEnabled && db_mc_isSub(hContact))
  		return 1;
 @@ -470,7 +464,8 @@ int __fastcall CLVM_GetContactHiddenStatus(MCONTACT hContact, char *szProto, str  		szProto = GetContactProto(hContact);
  	// check stickies first (priority), only if we really have stickies defined (CLVM_STICKY_CONTACTS is set).
  	if (cfg::dat.bFilterEffective & CLVM_STICKY_CONTACTS) {
 -		if ((dwLocalMask = cfg::getDword(hContact, "CLVM", cfg::dat.current_viewmode, 0)) != 0) {
 +		DWORD dwLocalMask = cfg::getDword(hContact, "CLVM", cfg::dat.current_viewmode, 0);
 +		if (dwLocalMask != 0) {
  			if (cfg::dat.bFilterEffective & CLVM_FILTER_STICKYSTATUS) {
  				WORD wStatus = cfg::getWord(hContact, szProto, "Status", ID_STATUS_OFFLINE);
  				return !((1 << (wStatus - ID_STATUS_OFFLINE)) & HIWORD(dwLocalMask));
 @@ -478,31 +473,37 @@ int __fastcall CLVM_GetContactHiddenStatus(MCONTACT hContact, char *szProto, str  			return 0;
  		}
  	}
 +
  	// check the proto, use it as a base filter result for all further checks
 +	int filterResult = 1;
  	if (cfg::dat.bFilterEffective & CLVM_FILTER_PROTOS) {
 +		char szTemp[64];
  		mir_snprintf(szTemp, "%s|", szProto);
  		filterResult = strstr(cfg::dat.protoFilter, szTemp) ? 1 : 0;
  	}
 +	
  	if (cfg::dat.bFilterEffective & CLVM_FILTER_GROUPS) {
 -		if (!cfg::getTString(hContact, "CList", "Group", &dbv)) {
 -			mir_sntprintf(szGroupMask, _T("%s|"), &dbv.ptszVal[1]);
 +		ptrT tszGroup(db_get_tsa(hContact, "CList", "Group"));
 +		if (tszGroup != NULL) {
 +			TCHAR szGroupMask[256];
 +			mir_sntprintf(szGroupMask, _T("%s|"), LPTSTR(tszGroup)+1);
  			filterResult = (cfg::dat.filterFlags & CLVM_PROTOGROUP_OP) ? (filterResult | (_tcsstr(cfg::dat.groupFilter, szGroupMask) ? 1 : 0)) : (filterResult & (_tcsstr(cfg::dat.groupFilter, szGroupMask) ? 1 : 0));
 -			mir_free(dbv.ptszVal);
  		}
  		else if (cfg::dat.filterFlags & CLVM_INCLUDED_UNGROUPED)
  			filterResult = (cfg::dat.filterFlags & CLVM_PROTOGROUP_OP) ? filterResult : filterResult & 1;
  		else
  			filterResult = (cfg::dat.filterFlags & CLVM_PROTOGROUP_OP) ? filterResult : filterResult & 0;
  	}
 +
  	if (cfg::dat.bFilterEffective & CLVM_FILTER_STATUS) {
  		WORD wStatus = cfg::getWord(hContact, szProto, "Status", ID_STATUS_OFFLINE);
  		filterResult = (cfg::dat.filterFlags & CLVM_GROUPSTATUS_OP) ? ((filterResult | ((1 << (wStatus - ID_STATUS_OFFLINE)) & cfg::dat.statusMaskFilter ? 1 : 0))) : (filterResult & ((1 << (wStatus - ID_STATUS_OFFLINE)) & cfg::dat.statusMaskFilter ? 1 : 0));
  	}
 +
  	if (cfg::dat.bFilterEffective & CLVM_FILTER_LASTMSG) {
 -		DWORD now;
  		TExtraCache *p = cfg::getCache(hContact, szProto);
  		if (p) {
 -			now = cfg::dat.t_now;
 +			DWORD now = cfg::dat.t_now;
  			now -= cfg::dat.lastMsgFilter;
  			if (cfg::dat.bFilterEffective & CLVM_FILTER_LASTMSG_OLDERTHAN)
  				filterResult = filterResult & (p->dwLastMsgTime < now);
 diff --git a/plugins/HTTPServer/src/main.cpp b/plugins/HTTPServer/src/main.cpp index 628267d374..3490f07599 100644 --- a/plugins/HTTPServer/src/main.cpp +++ b/plugins/HTTPServer/src/main.cpp @@ -591,11 +591,10 @@ void ConnectionOpen(HANDLE hNewConnection, DWORD dwRemoteIP)  	in_addr stAddr;
  	stAddr.S_un.S_addr = htonl(dwRemoteIP);
 -	CLHttpUser * pclUser = new CLHttpUser(hNewConnection, stAddr);
 -	forkthread(HandleNewConnection, 0, (void*)pclUser);
 +	CLHttpUser *pclUser = new CLHttpUser(hNewConnection, stAddr);
 +	mir_forkthread(HandleNewConnection, pclUser);
  }
 -
  /////////////////////////////////////////////////////////////////////
  // Member Function : nProtoAck
  // Type            : Global
 diff --git a/plugins/Non-IM Contact/src/timer.cpp b/plugins/Non-IM Contact/src/timer.cpp index f67610cae2..18fdf21778 100644 --- a/plugins/Non-IM Contact/src/timer.cpp +++ b/plugins/Non-IM Contact/src/timer.cpp @@ -51,7 +51,7 @@ void timerFunc(void*)  void CALLBACK timerProc(HWND, UINT, UINT_PTR, DWORD)
  {
  	// new thread for the timer...
 -	forkthread(timerFunc, 0, 0);
 +	mir_forkthread(timerFunc);
  }
  //=====================================================
 diff --git a/protocols/Tlen/src/tlen_avatar.cpp b/protocols/Tlen/src/tlen_avatar.cpp index baa05c1f2f..15c352612f 100644 --- a/protocols/Tlen/src/tlen_avatar.cpp +++ b/protocols/Tlen/src/tlen_avatar.cpp @@ -33,8 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  void TlenGetAvatarFileName(TlenProtocol *proto, TLEN_LIST_ITEM *item, TCHAR* ptszDest, int cbLen)  { -	 -	int tPathLen = mir_sntprintf(ptszDest, cbLen, TEXT("%s\\%S"), VARST( TEXT("%miranda_avatarcache%")), proto->m_szModuleName); +	int tPathLen = mir_sntprintf(ptszDest, cbLen, TEXT("%s\\%S"), VARST(TEXT("%miranda_avatarcache%")), proto->m_szModuleName);  	if (_taccess(ptszDest, 0)) {  		int ret = CreateDirectoryTreeT(ptszDest);  		if (ret == 0) @@ -49,7 +48,7 @@ void TlenGetAvatarFileName(TlenProtocol *proto, TLEN_LIST_ITEM *item, TCHAR* pts  	int format = PA_FORMAT_PNG; -	ptszDest[ tPathLen++ ] = '\\'; +	ptszDest[tPathLen++] = '\\';  	if (item != NULL)  		format = item->avatarFormat;  	else if (proto->threadData != NULL) @@ -58,18 +57,19 @@ void TlenGetAvatarFileName(TlenProtocol *proto, TLEN_LIST_ITEM *item, TCHAR* pts  		format = db_get_dw(NULL, proto->m_szModuleName, "AvatarFormat", PA_FORMAT_UNKNOWN);  	const TCHAR *tszFileType = ProtoGetAvatarExtension(format); -	if ( item != NULL ) -		mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S%s"), ptrA( TlenSha1(item->jid)), tszFileType); +	if (item != NULL) +		mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S%s"), ptrA(TlenSha1(item->jid)), tszFileType);  	else  		mir_sntprintf(ptszDest + tPathLen, MAX_PATH - tPathLen, TEXT("%S_avatar%s"), proto->m_szModuleName, tszFileType);  } -static void RemoveAvatar(TlenProtocol *proto, MCONTACT hContact) { -	TCHAR tFileName[ MAX_PATH ]; -	if (hContact == NULL) { +static void RemoveAvatar(TlenProtocol *proto, MCONTACT hContact) +{ +	TCHAR tFileName[MAX_PATH]; +	if (hContact == NULL)  		proto->threadData->avatarHash[0] = '\0'; -	} -	TlenGetAvatarFileName( proto, NULL, tFileName, _countof(tFileName)-1); + +	TlenGetAvatarFileName(proto, NULL, tFileName, _countof(tFileName) - 1);  	DeleteFile(tFileName);  	db_unset(hContact, "ContactPhoto", "File");  	db_unset(hContact, proto->m_szModuleName, "AvatarHash"); @@ -77,7 +77,8 @@ static void RemoveAvatar(TlenProtocol *proto, MCONTACT hContact) {  	ProtoBroadcastAck(proto->m_szModuleName, NULL, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0);  } -static void SetAvatar(TlenProtocol *proto, MCONTACT hContact, TLEN_LIST_ITEM *item, char *data, int len, DWORD format) { +static void SetAvatar(TlenProtocol *proto, MCONTACT hContact, TLEN_LIST_ITEM *item, char *data, int len, DWORD format) +{  	TCHAR filename[MAX_PATH];  	char md5[33];  	mir_md5_state_t ctx; @@ -86,52 +87,56 @@ static void SetAvatar(TlenProtocol *proto, MCONTACT hContact, TLEN_LIST_ITEM *it  	if (format == PA_FORMAT_UNKNOWN && len > 4)  		format = ProtoGetBufferFormat(data); -	mir_md5_init( &ctx ); -	mir_md5_append( &ctx, ( BYTE* )data, len); -	mir_md5_finish( &ctx, ( BYTE* )digest ); +	mir_md5_init(&ctx); +	mir_md5_append(&ctx, (BYTE*)data, len); +	mir_md5_finish(&ctx, (BYTE*)digest); -	sprintf( md5, "%08x%08x%08x%08x", (int)htonl(digest[0]), (int)htonl(digest[1]), (int)htonl(digest[2]), (int)htonl(digest[3])); //!!!!!!!!!!!!!! +	sprintf(md5, "%08x%08x%08x%08x", (int)htonl(digest[0]), (int)htonl(digest[1]), (int)htonl(digest[2]), (int)htonl(digest[3])); //!!!!!!!!!!!!!!  	if (item != NULL) {  		char *hash = item->avatarHash;  		item->avatarFormat = format;  		item->avatarHash = mir_strdup(md5);  		mir_free(hash); -	} else { +	} +	else {  		proto->threadData->avatarFormat = format;  		mir_strcpy(proto->threadData->avatarHash, md5);  	} -	TlenGetAvatarFileName(proto, item, filename, _countof(filename)-1); +	TlenGetAvatarFileName(proto, item, filename, _countof(filename) - 1);  	DeleteFile(filename); -	FILE *out = _tfopen(filename, TEXT("wb") ); +	FILE *out = _tfopen(filename, TEXT("wb"));  	if (out != NULL) {  		fwrite(data, len, 1, out);  		fclose(out); -		db_set_ts(hContact, "ContactPhoto", "File", filename ); -		db_set_s(hContact, proto->m_szModuleName, "AvatarHash",  md5); -		db_set_dw(hContact, proto->m_szModuleName, "AvatarFormat",  format); -	} else { +		db_set_ts(hContact, "ContactPhoto", "File", filename); +		db_set_s(hContact, proto->m_szModuleName, "AvatarHash", md5); +		db_set_dw(hContact, proto->m_szModuleName, "AvatarFormat", format); +	} +	else {  		TCHAR buffer[128];  		mir_sntprintf(buffer, TranslateT("Cannot save new avatar file \"%s\" Error:\n\t%s (Error: %d)"), filename, _tcserror(errno), errno);  		PUShowMessageT(buffer, SM_WARNING);  		proto->debugLog(buffer);  		return;  	} -	ProtoBroadcastAck( proto->m_szModuleName, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL , 0); +	ProtoBroadcastAck(proto->m_szModuleName, hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0);  } -int TlenProcessAvatarNode(TlenProtocol *proto, XmlNode *avatarNode, TLEN_LIST_ITEM *item) { +int TlenProcessAvatarNode(TlenProtocol *proto, XmlNode *avatarNode, TLEN_LIST_ITEM *item) +{  	XmlNode *aNode;  	char *oldHash = NULL;  	char *md5 = NULL, *type = NULL;  	MCONTACT hContact = NULL; -	if (item != NULL) { -		if ((hContact=TlenHContactFromJID(proto, item->jid)) == NULL) return 0; -	} -	if (item == NULL) { +	if (item != NULL) +		if ((hContact = TlenHContactFromJID(proto, item->jid)) == NULL) +			return 0; + +	if (item == NULL)  		oldHash = proto->threadData->avatarHash; -	} else { +	else  		oldHash = item->avatarHash; -	} +  	if (avatarNode != NULL) {  		aNode = TlenXmlGetChild(avatarNode, "a");  		if (aNode != NULL) { @@ -139,6 +144,7 @@ int TlenProcessAvatarNode(TlenProtocol *proto, XmlNode *avatarNode, TLEN_LIST_IT  			md5 = TlenXmlGetAttrValue(aNode, "md5");  		}  	} +  	if (md5 != NULL) {  		/* check contact's avatar hash - md5 */  		if (oldHash == NULL || mir_strcmp(oldHash, md5)) { @@ -148,7 +154,8 @@ int TlenProcessAvatarNode(TlenProtocol *proto, XmlNode *avatarNode, TLEN_LIST_IT  			TlenGetAvatar(proto, hContact);  			return 1;  		} -	} else { +	} +	else {  		/* remove avatar */  		if (oldHash != NULL) {  			if (item != NULL) { @@ -163,14 +170,15 @@ int TlenProcessAvatarNode(TlenProtocol *proto, XmlNode *avatarNode, TLEN_LIST_IT  	return 0;  } -void TlenProcessPresenceAvatar(TlenProtocol *proto, XmlNode *node, TLEN_LIST_ITEM *item) { +void TlenProcessPresenceAvatar(TlenProtocol *proto, XmlNode *node, TLEN_LIST_ITEM *item) +{  	MCONTACT hContact=TlenHContactFromJID(proto, item->jid);  	if (hContact != NULL)  		TlenProcessAvatarNode(proto, TlenXmlGetChild(node, "avatar"), item);  } - -static char *replaceTokens(const char *base, const char *uri, const char *login, const char* token, int type, int access) { +static char *replaceTokens(const char *base, const char *uri, const char *login, const char* token, int type, int access) +{  	char *result;  	int i, l, size;  	l = (int)mir_strlen(uri); @@ -219,16 +227,16 @@ static char *replaceTokens(const char *base, const char *uri, const char *login,  	return result;  } -  static int getAvatarMutex = 0; -typedef struct { +struct TLENGETAVATARTHREADDATA +{  	TlenProtocol *proto;  	MCONTACT hContact; -} TLENGETAVATARTHREADDATA; - -static void TlenGetAvatarThread(void *ptr) { +}; +static void TlenGetAvatarThread(void *ptr) +{  	TLEN_LIST_ITEM *item = NULL;  	TLENGETAVATARTHREADDATA *data = (TLENGETAVATARTHREADDATA *)ptr;  	MCONTACT hContact = data->hContact; @@ -238,15 +246,17 @@ static void TlenGetAvatarThread(void *ptr) {  		login = TlenNickFromJID(jid);  		item = TlenListGetItemPtr(data->proto, LIST_ROSTER, jid);  		mir_free(jid); -	} else { +	} +	else {  		if (data->proto->threadData != NULL)  			login = mir_strdup(data->proto->threadData->username);  	} +	  	if ((data->proto->threadData != NULL && hContact == NULL) || item != NULL) {  		DWORD format = PA_FORMAT_UNKNOWN; -		if (item != NULL) { +		if (item != NULL)  			item->newAvatarDownloading = TRUE; -		} +  		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)); @@ -258,9 +268,9 @@ static void TlenGetAvatarThread(void *ptr) {  		req.dataLength = 0;  		req.szUrl = request;  		NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)&req); -		if (item != NULL) { +		if (item != NULL)  			item->newAvatarDownloading = FALSE; -		} +  		if (resp != NULL) {  			if (resp->resultCode/100 == 2) {  				if (resp->dataLength > 0) { @@ -284,41 +294,42 @@ static void TlenGetAvatarThread(void *ptr) {  						}  					}  					SetAvatar(data->proto, hContact, item, resp->pData, resp->dataLength, format); -				} else { -					RemoveAvatar(data->proto, hContact);  				} +				else RemoveAvatar(data->proto, hContact);  			}  			CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)resp);  		}  		mir_free(request);  		mir_free(login);  	} -	if (hContact == NULL) { +	 +	if (hContact == NULL)  		getAvatarMutex = 0; -	}  +  	mir_free(login);  	mir_free(data);  } -void TlenGetAvatar(TlenProtocol *proto, MCONTACT hContact) { +void TlenGetAvatar(TlenProtocol *proto, MCONTACT hContact) +{  	if (hContact == NULL) { -		if (getAvatarMutex != 0) { +		if (getAvatarMutex != 0)  			return; -		} +  		getAvatarMutex = 1;  	} -	{ -		TLENGETAVATARTHREADDATA *data = (TLENGETAVATARTHREADDATA *)mir_alloc(sizeof(TLENGETAVATARTHREADDATA)); -		data->proto = proto; -		data->hContact = hContact; -		forkthread(TlenGetAvatarThread, 0, data); -	} + +	TLENGETAVATARTHREADDATA *data = (TLENGETAVATARTHREADDATA *)mir_alloc(sizeof(TLENGETAVATARTHREADDATA)); +	data->proto = proto; +	data->hContact = hContact; +	mir_forkthread(TlenGetAvatarThread, data);  } -typedef struct { +struct TLENREMOVEAVATARTHREADDATA +{  	TlenProtocol *proto;  	NETLIBHTTPREQUEST *req; -} TLENREMOVEAVATARTHREADDATA; +};  static void TlenRemoveAvatarRequestThread(void *ptr) {  	TLENREMOVEAVATARTHREADDATA *data = (TLENREMOVEAVATARTHREADDATA*)ptr; @@ -336,15 +347,17 @@ static void TlenRemoveAvatarRequestThread(void *ptr) {  } -typedef struct { +struct TLENUPLOADAVATARTHREADDATA +{  	TlenProtocol *proto;  	NETLIBHTTPREQUEST *req;  	char *data;  	int  length; -} TLENUPLOADAVATARTHREADDATA; +}; -boolean checkUploadAvatarResponse(TlenProtocol *proto, NETLIBHTTPREQUEST *resp){ -	if (resp == NULL){ +boolean checkUploadAvatarResponse(TlenProtocol *proto, NETLIBHTTPREQUEST *resp) +{ +	if (resp == NULL) {  		proto->debugLogA("Error while setting avatar on Tlen account (no response)");  		PUShowMessageT(TranslateT("Error while setting avatar on Tlen account (no response)"), SM_WARNING);  		return false; @@ -354,7 +367,7 @@ boolean checkUploadAvatarResponse(TlenProtocol *proto, NETLIBHTTPREQUEST *resp){  		PUShowMessageT(TranslateT("Error while setting avatar on Tlen account (invalid response)"), SM_WARNING);  		return false;  	} -	if (strncmp(resp->pData, "<ok", 3)){ +	if (strncmp(resp->pData, "<ok", 3)) {  		proto->debugLogA("Error while setting avatar on Tlen account: %s", resp->pData);  		PUShowMessageT(TranslateT("Error while setting avatar on Tlen account"), SM_WARNING);  		return false; @@ -362,7 +375,8 @@ boolean checkUploadAvatarResponse(TlenProtocol *proto, NETLIBHTTPREQUEST *resp){  	return true;  } -static void TlenUploadAvatarRequestThread(void *ptr) { +static void TlenUploadAvatarRequestThread(void *ptr) +{  	TLENUPLOADAVATARTHREADDATA *data = (TLENUPLOADAVATARTHREADDATA *) ptr;  	NETLIBHTTPREQUEST *req = data->req;  	NETLIBHTTPREQUEST *resp = (NETLIBHTTPREQUEST *)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)data->proto->m_hNetlibUser, (LPARAM)req); @@ -378,28 +392,29 @@ static void TlenUploadAvatarRequestThread(void *ptr) {  	mir_free(data);  } -void TlenRemoveAvatar(TlenProtocol *proto) { +void TlenRemoveAvatar(TlenProtocol *proto) +{  	if (proto->threadData != NULL) {  		TLENREMOVEAVATARTHREADDATA *data = (TLENREMOVEAVATARTHREADDATA *)mir_alloc(sizeof(TLENREMOVEAVATARTHREADDATA));  		NETLIBHTTPREQUEST *req = (NETLIBHTTPREQUEST *)mir_alloc(sizeof(NETLIBHTTPREQUEST)); -		data->proto =proto; +		data->proto = proto;  		data->req = req;  		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;  		req->szUrl = request; -		forkthread(TlenRemoveAvatarRequestThread, 0, data); +		mir_forkthread(TlenRemoveAvatarRequestThread, data);  	}  } - -void TlenUploadAvatar(TlenProtocol *proto, unsigned char *data, int dataLen, int access) { +void TlenUploadAvatar(TlenProtocol *proto, unsigned char *data, int dataLen, int access) +{  	NETLIBHTTPHEADER *headers;  	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"; +		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)mir_strlen(mpartHead), sizeTail = (int)mir_strlen(mpartTail);  		char *request = replaceTokens(proto->threadData->tlenConfig.mailBase, proto->threadData->tlenConfig.avatarUpload, "", proto->threadData->avatarToken, 0, access);  		TLENUPLOADAVATARTHREADDATA *threadData = (TLENUPLOADAVATARTHREADDATA *)mir_alloc(sizeof(TLENUPLOADAVATARTHREADDATA)); @@ -423,10 +438,10 @@ void TlenUploadAvatar(TlenProtocol *proto, unsigned char *data, int dataLen, int  		req->dataLength = size;  		req->pData = (char*)buffer;  		threadData->req = req; -		threadData->data = (char *) mir_alloc(dataLen); +		threadData->data = (char*)mir_alloc(dataLen);  		memcpy(threadData->data, data, dataLen);  		threadData->length = dataLen; -		forkthread(TlenUploadAvatarRequestThread, 0, threadData); +		mir_forkthread(TlenUploadAvatarRequestThread, threadData);  	}  } diff --git a/protocols/Tlen/src/tlen_file.cpp b/protocols/Tlen/src/tlen_file.cpp index f97f47efae..49f62d50e9 100644 --- a/protocols/Tlen/src/tlen_file.cpp +++ b/protocols/Tlen/src/tlen_file.cpp @@ -630,7 +630,7 @@ void TlenProcessF(XmlNode *node, ThreadData *info)  				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);
 +							mir_forkthread((pThreadFunc)TlenFileSendingThread, item->ft);
  			}
  			else if (!mir_strcmp(e, "6")) {
  				// FILE_RECV : e='6' : IP and port information to connect to get file
 @@ -640,7 +640,7 @@ void TlenProcessF(XmlNode *node, ThreadData *info)  							item->ft->hostName = mir_strdup(p);
  							if ((p = TlenXmlGetAttrValue(node, "p")) != NULL) {
  								item->ft->wPort = atoi(p);
 -								forkthread((void(__cdecl *)(void*))TlenFileReceiveThread, 0, item->ft);
 +								mir_forkthread((pThreadFunc)TlenFileReceiveThread, item->ft);
  							}
  						}
  					}
 diff --git a/protocols/Tlen/src/tlen_p2p_new.cpp b/protocols/Tlen/src/tlen_p2p_new.cpp index a2155c16e5..6afb490b0d 100644 --- a/protocols/Tlen/src/tlen_p2p_new.cpp +++ b/protocols/Tlen/src/tlen_p2p_new.cpp @@ -319,8 +319,8 @@ void __cdecl TlenProcessP2P(XmlNode *node, ThreadData *info) {  					TlenBindUDPSocket(item->ft);
  					TlenSend(info->proto, "<iq to='%s'><query xmlns='p2p'><dcng  la='%s' lp='%d' pa='%s' pp='%d' i='%s' k='5' s='4'/></query></iq>",
  						item->ft->jid, item->ft->localName, item->ft->wLocalPort, item->ft->localName, item->ft->wLocalPort, item->ft->id2);
 -					forkthread((void (__cdecl *)(void*))TlenNewFileReceiveThread, 0, item->ft);
 -					forkthread((void (__cdecl *)(void*))TlenNewFileSendThread, 0, item->ft);
 +					mir_forkthread((pThreadFunc)TlenNewFileReceiveThread, item->ft);
 +					mir_forkthread((pThreadFunc)TlenNewFileSendThread, item->ft);
  				}
  			} else if (!mir_strcmp(s, "4")) {
  				/* IP and port */
 @@ -328,7 +328,7 @@ void __cdecl TlenProcessP2P(XmlNode *node, ThreadData *info) {  					info->proto->debugLogA("step = 4");
  					item->ft->hostName = mir_strdup(TlenXmlGetAttrValue(dcng, "pa"));
  					item->ft->wPort = atoi(TlenXmlGetAttrValue(dcng, "pp"));
 -					forkthread((void (__cdecl *)(void*))TlenNewFileReceiveThread, 0, item->ft);
 +					mir_forkthread((pThreadFunc)TlenNewFileReceiveThread, item->ft);
  				}
  			}
 diff --git a/protocols/Tlen/src/tlen_p2p_old.cpp b/protocols/Tlen/src/tlen_p2p_old.cpp index 267748a5f1..a2265f6e8a 100644 --- a/protocols/Tlen/src/tlen_p2p_old.cpp +++ b/protocols/Tlen/src/tlen_p2p_old.cpp @@ -339,7 +339,7 @@ static HANDLE TlenP2PBindSocks4(SOCKSBIND * sb, TLEN_FILE_TRANSFER *ft)  	strncpy(sb->szHost, inet_ntoa(in), sizeof(sb->szHost)-1);
  	sb->wPort = htons(*(PWORD)(buf+2));
  	ft->s = s;
 -	forkthread((void (__cdecl *)(void*))TlenFileBindSocks4Thread, 0, ft);
 +	mir_forkthread(pThreadFunc(TlenFileBindSocks4Thread), ft);
  	return s;
  }
 @@ -436,7 +436,7 @@ static HANDLE TlenP2PBindSocks5(SOCKSBIND * sb, TLEN_FILE_TRANSFER *ft)  	sb->wPort = htons(*(PWORD)(buf+len));
  	ft->s = s;
 -	forkthread((void (__cdecl *)(void*))TlenFileBindSocks5Thread, 0, ft);
 +	mir_forkthread(pThreadFunc(TlenFileBindSocks5Thread), ft);
  	return s;
  }
 diff --git a/protocols/Tlen/src/tlen_picture.cpp b/protocols/Tlen/src/tlen_picture.cpp index 7279e831d2..765792a643 100644 --- a/protocols/Tlen/src/tlen_picture.cpp +++ b/protocols/Tlen/src/tlen_picture.cpp @@ -89,7 +89,7 @@ static void TlenPsPost(TlenProtocol *proto, TLEN_LIST_ITEM *item) {  	TLENPSREQUESTTHREADDATA *threadData = (TLENPSREQUESTTHREADDATA *)mir_alloc(sizeof(TLENPSREQUESTTHREADDATA));
  	threadData->proto = proto;
  	threadData->item = item;
 -	forkthread(TlenPsPostThread, 0, threadData);
 +	mir_forkthread(TlenPsPostThread, threadData);
  }
  static void TlenPsGetThread(void *ptr) {
 @@ -162,7 +162,7 @@ static void TlenPsGet(TlenProtocol *proto, TLEN_LIST_ITEM *item) {  	TLENPSREQUESTTHREADDATA *threadData = (TLENPSREQUESTTHREADDATA *)mir_alloc(sizeof(TLENPSREQUESTTHREADDATA));
  	threadData->proto = proto;
  	threadData->item = item;
 -	forkthread(TlenPsGetThread, 0, threadData);
 +	mir_forkthread(TlenPsGetThread, threadData);
  }
  void TlenProcessPic(XmlNode *node, TlenProtocol *proto) {
 diff --git a/protocols/Tlen/src/tlen_svc.cpp b/protocols/Tlen/src/tlen_svc.cpp index 5c8fa5d869..5a367388f1 100644 --- a/protocols/Tlen/src/tlen_svc.cpp +++ b/protocols/Tlen/src/tlen_svc.cpp @@ -355,7 +355,7 @@ static void TlenConnect(TlenProtocol *proto, int initialStatus)  		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);
 +		thread->hThread = mir_forkthread((pThreadFunc)TlenServerThread, thread);
  	}
  }
 @@ -611,7 +611,7 @@ int TlenProtocol::SendMsg(MCONTACT hContact, int, const char* msgRAW)  {
  	DBVARIANT dbv;
  	if (!isOnline || db_get(hContact, m_szModuleName, "jid", &dbv)) {
 -		forkthread(TlenSendMessageFailedThread, 0, new SENDACKTHREADDATA(this, hContact, 2));
 +		mir_forkthread(TlenSendMessageFailedThread, new SENDACKTHREADDATA(this, hContact, 2));
  		return 2;
  	}
 @@ -623,11 +623,11 @@ int TlenProtocol::SendMsg(MCONTACT hContact, int, const char* msgRAW)  	if (!mir_strcmp(msg, "<alert>")) {
  		TlenSend(this, "<m tp='a' to='%s'/>", dbv.pszVal);
 -		forkthread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id));
 +		mir_forkthread(TlenSendMessageAckThread, new SENDACKTHREADDATA(this, hContact, id));
  	}
  	else if (!mir_strcmp(msg, "<image>")) {
  		TlenSend(this, "<message to='%s' type='%s' crc='%x' idt='%d'/>", dbv.pszVal, "pic", 0x757f044, id);
 -		forkthread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id));
 +		mir_forkthread(TlenSendMessageAckThread, new SENDACKTHREADDATA(this, hContact, id));
  	}
  	else {
  		char *msgEnc = TlenTextEncode(msg);
 @@ -647,7 +647,7 @@ int TlenProtocol::SendMsg(MCONTACT hContact, int, const char* msgRAW)  				else
  					TlenSend(this, "<message to='%s' type='%s' id='" TLEN_IQID "%d'><body>%s</body><x xmlns='jabber:x:event'><composing/></x></message>", dbv.pszVal, msgType, id, msgEnc);
 -				forkthread(TlenSendMessageAckThread, 0, new SENDACKTHREADDATA(this, hContact, id));
 +				mir_forkthread(TlenSendMessageAckThread, new SENDACKTHREADDATA(this, hContact, id));
  			}
  			else {
  				if ((item = TlenListGetItemPtr(this, LIST_ROSTER, dbv.pszVal)) != NULL)
 @@ -707,7 +707,7 @@ INT_PTR TlenProtocol::GetAvatarInfo(WPARAM wParam, LPARAM lParam)  HANDLE TlenProtocol::GetAwayMsg(MCONTACT hContact)
  {
  	SENDACKTHREADDATA *tdata = new SENDACKTHREADDATA(this, hContact, 0);
 -	forkthread((void(__cdecl *)(void*))TlenGetAwayMsgThread, 0, (void*)tdata);
 +	mir_forkthread((pThreadFunc)TlenGetAwayMsgThread, tdata);
  	return (HANDLE)1;
  }
 diff --git a/protocols/Tlen/src/tlen_thread.cpp b/protocols/Tlen/src/tlen_thread.cpp index 3567701282..99a27ba533 100644 --- a/protocols/Tlen/src/tlen_thread.cpp +++ b/protocols/Tlen/src/tlen_thread.cpp @@ -280,7 +280,7 @@ void __cdecl TlenServerThread(ThreadData *info)  		if (info->proto->m_iDesiredStatus != ID_STATUS_OFFLINE) {
  			info->proto->isConnected = TRUE;
 -			forkthread(TlenKeepAliveThread, 0, info->proto);
 +			mir_forkthread(TlenKeepAliveThread, info->proto);
  			TlenXmlInitState(&xmlState);
  			TlenXmlSetCallback(&xmlState, 1, ELEM_OPEN, (void (__cdecl *)(XmlNode *,void *))TlenProcessStreamOpening, info);
 @@ -1266,7 +1266,7 @@ static void TlenProcessV(XmlNode *node, ThreadData *info)  							if ((p=TlenXmlGetAttrValue(node, "p")) != NULL) {
  								item->ft->wPort = atoi(p);
  								TlenVoiceStart(item->ft, 0);
 -								//forkthread((void (__cdecl *)(void*))TlenVoiceReceiveThread, 0, item->ft);
 +								//forkthread((pThreadFunc)TlenVoiceReceiveThread, 0, item->ft);
  							}
  						}
  					}
 diff --git a/protocols/Tlen/src/tlen_voice.cpp b/protocols/Tlen/src/tlen_voice.cpp index 00d0afacb8..f35a51d4fa 100644 --- a/protocols/Tlen/src/tlen_voice.cpp +++ b/protocols/Tlen/src/tlen_voice.cpp @@ -914,13 +914,13 @@ int TlenVoiceStart(TLEN_FILE_TRANSFER *ft, int mode)  	ft->proto->debugLogA("starting voice %d", mode);
  	if (mode == 0) {
 -		forkthread((void(__cdecl *)(void*))TlenVoiceReceiveThread, 0, ft);
 +		mir_forkthread((pThreadFunc)TlenVoiceReceiveThread, ft);
  	}
  	else if (mode == 1) {
 -		forkthread((void(__cdecl *)(void*))TlenVoiceSendingThread, 0, ft);
 +		mir_forkthread((pThreadFunc)TlenVoiceSendingThread, ft);
  	}
  	else {
 -		forkthread((void(__cdecl *)(void*))TlenVoiceDlgThread, 0, ft);
 +		mir_forkthread((pThreadFunc)TlenVoiceDlgThread, ft);
  	}
  	return 0;
  }
 @@ -1050,7 +1050,7 @@ int TlenVoiceAccept(TlenProtocol *proto, const char *id, const char *from)  					ACCEPTDIALOGDATA *data = (ACCEPTDIALOGDATA *)mir_alloc(sizeof(ACCEPTDIALOGDATA));
  					data->proto = proto;
  					data->item = item;
 -					forkthread((void(__cdecl *)(void*))TlenVoiceAcceptDlgThread, 0, data);
 +					mir_forkthread((pThreadFunc)TlenVoiceAcceptDlgThread, data);
  				}
  				else if (proto->isOnline) {
  					item->ft = TlenFileCreateFT(proto, from);
 diff --git a/src/core/stdemail/src/email.cpp b/src/core/stdemail/src/email.cpp index f07e3d8060..d0a0f17f48 100644 --- a/src/core/stdemail/src/email.cpp +++ b/src/core/stdemail/src/email.cpp @@ -46,7 +46,7 @@ static INT_PTR SendEMailCommand(WPARAM hContact, LPARAM lParam)  	mir_strcpy(szUrl, "mailto:");
  	mir_strcat(szUrl, dbv.pszVal);
  	mir_free(dbv.pszVal);
 -	forkthread(SendEmailThread, 0, szUrl);
 +	mir_forkthread(SendEmailThread, szUrl);
  	return 0;
  }
 diff --git a/src/core/stdfile/src/fileexistsdlg.cpp b/src/core/stdfile/src/fileexistsdlg.cpp index ef765b56bf..ba340963ff 100644 --- a/src/core/stdfile/src/fileexistsdlg.cpp +++ b/src/core/stdfile/src/fileexistsdlg.cpp @@ -233,7 +233,7 @@ INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM  			lisi->hwndDlg = hwndDlg;
  			lisi->szFilename = mir_tstrdup(fts->tszCurrentFile);
  			//can be a little slow, so why not?
 -			forkthread(LoadIconsAndTypesThread, 0, lisi);
 +			mir_forkthread(LoadIconsAndTypesThread, lisi);
  			SetFocus(hwndFocus);
  			SetWindowLongPtr(hwndFocus, GWL_STYLE, GetWindowLongPtr(hwndFocus, GWL_STYLE) | BS_DEFPUSHBUTTON);
  		}
 diff --git a/src/core/stdfile/src/filesenddlg.cpp b/src/core/stdfile/src/filesenddlg.cpp index 75d955897b..14bf93cf53 100644 --- a/src/core/stdfile/src/filesenddlg.cpp +++ b/src/core/stdfile/src/filesenddlg.cpp @@ -313,7 +313,7 @@ INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l  		switch (LOWORD(wParam)) {
  		case IDC_CHOOSE:
  			EnableWindow(hwndDlg, FALSE);
 -			forkthread(ChooseFilesThread, 0, hwndDlg);
 +			mir_forkthread(ChooseFilesThread, hwndDlg);
  			break;
  		case IDOK:
 diff --git a/src/core/stdfile/src/filexferdlg.cpp b/src/core/stdfile/src/filexferdlg.cpp index 804318123b..9dc6c22447 100644 --- a/src/core/stdfile/src/filexferdlg.cpp +++ b/src/core/stdfile/src/filexferdlg.cpp @@ -530,7 +530,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR  						vstsi->hwndReply = hwndDlg;  						vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]);  						vstsi->returnCode = dat->transferStatus.currentFileNumber; -						forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi); +						mir_forkthread((void(*)(void*))RunVirusScannerThread, vstsi);  					}  				}  				break; @@ -673,7 +673,7 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR  							}  							SetFtStatus(hwndDlg, LPGENT("Scanning for viruses..."), FTS_TEXT);  							if (vstsi) -								forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi); +								mir_forkthread((void(*)(void*))RunVirusScannerThread, vstsi);  						}  						else dat->fs = NULL; /* protocol will free structure */ diff --git a/src/core/stduihist/src/history.cpp b/src/core/stduihist/src/history.cpp index f5ef654864..7c8fd84bc1 100644 --- a/src/core/stduihist/src/history.cpp +++ b/src/core/stduihist/src/history.cpp @@ -221,7 +221,7 @@ static INT_PTR CALLBACK DlgProcHistory(HWND hwndDlg, UINT msg, WPARAM wParam, LP  			EnableWindow(GetDlgItem(hwndDlg, IDC_LIST), FALSE);
  			hInfo->hContact = hContact;
  			hInfo->hwnd = hwndDlg;
 -			forkthread(FillHistoryThread, 0, hInfo);
 +			mir_forkthread(FillHistoryThread, hInfo);
  		}
  		return TRUE;
 diff --git a/src/mir_app/src/miranda.cpp b/src/mir_app/src/miranda.cpp index 6c908228ba..43f32a6111 100644 --- a/src/mir_app/src/miranda.cpp +++ b/src/mir_app/src/miranda.cpp @@ -254,7 +254,7 @@ int WINAPI mir_main(LPTSTR cmdLine)  		// ensure that the kernel hooks the SystemShutdownProc() after all plugins
  		HookEvent(ME_SYSTEM_SHUTDOWN, SystemShutdownProc);
 -		forkthread(compactHeapsThread, 0, NULL);
 +		mir_forkthread(compactHeapsThread);
  		CreateServiceFunction(MS_SYSTEM_SETIDLECALLBACK, SystemSetIdleCallback);
  		CreateServiceFunction(MS_SYSTEM_GETIDLE, SystemGetIdle);
  		dwEventTime = GetTickCount();
 diff --git a/src/mir_app/src/netlibopenconn.cpp b/src/mir_app/src/netlibopenconn.cpp index 5ffbce24ed..5219375678 100644 --- a/src/mir_app/src/netlibopenconn.cpp +++ b/src/mir_app/src/netlibopenconn.cpp @@ -865,7 +865,7 @@ INT_PTR NetlibOpenConnection(WPARAM wParam, LPARAM lParam)  		mir_cslock lck(csNetlibUser);  		if (iUPnPCleanup == 0) {  			iUPnPCleanup = 1; -			forkthread(NetlibUPnPCleanup, 0, NULL); +			mir_forkthread(NetlibUPnPCleanup);  		}  	} diff --git a/src/mir_app/src/searchresults.cpp b/src/mir_app/src/searchresults.cpp index b75ca7746d..514dd03f6a 100644 --- a/src/mir_app/src/searchresults.cpp +++ b/src/mir_app/src/searchresults.cpp @@ -210,7 +210,7 @@ int BeginSearch(HWND, struct FindAddDlgData *dat, const char *szProto, const cha  		if (failures) {
  			//infuriatingly vague error message. fixme.
  			if (dat->searchCount == 0) {
 -				forkthread(BeginSearchFailed, 0, NULL);
 +				mir_forkthread(BeginSearchFailed);
  				mir_free(dat->search);
  				dat->search = NULL;
  				return 1;
 @@ -225,7 +225,7 @@ int BeginSearch(HWND, struct FindAddDlgData *dat, const char *szProto, const cha  		if (dat->search[0].hProcess == NULL) {
  			//infuriatingly vague error message. fixme.
  			PROTOACCOUNT *pa = Proto_GetAccount(szProto);
 -			forkthread(BeginSearchFailed, 0, mir_tstrdup(pa->tszAccountName));
 +			mir_forkthread(BeginSearchFailed, mir_tstrdup(pa->tszAccountName));
  			mir_free(dat->search);
  			dat->search = NULL;
  			dat->searchCount = 0;
 diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 83c787d57f..fb89dde82b 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -73,8 +73,8 @@ Utf8DecodeW                    @72  Utf8Encode                     @73
  Utf8EncodeCP                   @74
  Utf8EncodeW                    @75
 -forkthread                     @76
 -forkthreadex                   @77
 +mir_forkthread                 @76
 +mir_forkthreadex               @77
  ltrim                          @78
  ltrimp                         @79
  mir_a2u                        @80
 @@ -987,3 +987,4 @@ mir_sha256_final @1144  mir_sha256_hash @1145
  mir_sha256_init @1146
  mir_sha256_write @1147
 +mir_forkthreadowner @1148
 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 86b36cd57a..f7cb356fdb 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -73,8 +73,8 @@ Utf8DecodeW                    @72  Utf8Encode                     @73
  Utf8EncodeCP                   @74
  Utf8EncodeW                    @75
 -forkthread                     @76
 -forkthreadex                   @77
 +mir_forkthread                 @76
 +mir_forkthreadex               @77
  ltrim                          @78
  ltrimp                         @79
  mir_a2u                        @80
 @@ -987,3 +987,4 @@ mir_sha256_final @1144  mir_sha256_hash @1145
  mir_sha256_init @1146
  mir_sha256_write @1147
 +mir_forkthreadowner @1148
 diff --git a/src/mir_core/src/openurl.cpp b/src/mir_core/src/openurl.cpp index 00b2813322..3da41fb107 100644 --- a/src/mir_core/src/openurl.cpp +++ b/src/mir_core/src/openurl.cpp @@ -68,11 +68,11 @@ static void OpenURLThread(void *arg)  MIR_CORE_DLL(void) Utils_OpenUrl(const char *pszUrl, bool bOpenInNewWindow)
  {
  	if (pszUrl)
 -		forkthread(OpenURLThread, 0, new TOpenUrlInfo(mir_a2t(pszUrl), bOpenInNewWindow));
 +		mir_forkthread(OpenURLThread, new TOpenUrlInfo(mir_a2t(pszUrl), bOpenInNewWindow));
  }
  MIR_CORE_DLL(void) Utils_OpenUrlW(const wchar_t *pszUrl, bool bOpenInNewWindow)
  {
  	if (pszUrl)
 -		forkthread(OpenURLThread, 0, new TOpenUrlInfo(mir_wstrdup(pszUrl), bOpenInNewWindow));
 +		mir_forkthread(OpenURLThread, new TOpenUrlInfo(mir_wstrdup(pszUrl), bOpenInNewWindow));
  }
 diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp index dddcfe2d83..8f73d5bb4d 100644 --- a/src/mir_core/src/threads.cpp +++ b/src/mir_core/src/threads.cpp @@ -108,7 +108,7 @@ struct FORK_ARG  /////////////////////////////////////////////////////////////////////////////////////////
  // forkthread - starts a new thread
 -void __cdecl forkthread_r(void *arg)
 +DWORD WINAPI forkthread_r(void *arg)
  {
  	FORK_ARG *fa = (FORK_ARG*)arg;
  	pThreadFunc callercode = fa->threadcode;
 @@ -120,26 +120,31 @@ void __cdecl forkthread_r(void *arg)  	SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  	Thread_Pop();
 +	return 0;
  }
 -MIR_CORE_DLL(UINT_PTR) forkthread(void(__cdecl *threadcode)(void*), unsigned long stacksize, void *arg)
 +MIR_CORE_DLL(HANDLE) mir_forkthread(void(__cdecl *threadcode)(void*), void *arg)
  {
  	FORK_ARG fa;
  	fa.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  	fa.threadcode = threadcode;
  	fa.arg = arg;
 -	UINT_PTR rc = _beginthread(forkthread_r, stacksize, &fa);
 -	if ((UINT_PTR)-1L != rc)
 +
 +	DWORD threadID;
 +	HANDLE hThread = CreateThread(NULL, 0, forkthread_r, &fa, 0, &threadID);
 +	if (hThread != NULL) {
  		WaitForSingleObject(fa.hEvent, INFINITE);
 +		CloseHandle(hThread);
 +	}
  	CloseHandle(fa.hEvent);
 -	return rc;
 +	return hThread;
  }
  /////////////////////////////////////////////////////////////////////////////////////////
  // forkthreadex - starts a new thread with the extended info and returns the thread id
 -unsigned __stdcall forkthreadex_r(void * arg)
 +DWORD WINAPI forkthreadex_r(void * arg)
  {
  	struct FORK_ARG *fa = (struct FORK_ARG *)arg;
  	pThreadFuncEx threadcode = fa->threadcodeex;
 @@ -160,25 +165,43 @@ unsigned __stdcall forkthreadex_r(void * arg)  	return rc;
  }
 -MIR_CORE_DLL(UINT_PTR) forkthreadex(
 -	void *sec,
 -	unsigned stacksize,
 -	unsigned(__stdcall *threadcode)(void*),
 -	void *owner,
 -	void *arg,
 -	unsigned *thraddr)
 +MIR_CORE_DLL(HANDLE) mir_forkthreadex(pThreadFuncEx aFunc, void* arg, unsigned *pThreadID)
 +{
 +	struct FORK_ARG fa = { 0 };
 +	fa.threadcodeex = aFunc;
 +	fa.arg = arg;
 +	fa.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
 +
 +	DWORD threadID = 0;
 +	HANDLE hThread = CreateThread(NULL, 0, forkthreadex_r, &fa, 0, &threadID);
 +	if (hThread != NULL)
 +		WaitForSingleObject(fa.hEvent, INFINITE);
 +
 +	if (pThreadID != NULL)
 +		*pThreadID = threadID;
 +
 +	CloseHandle(fa.hEvent);
 +	return hThread;
 +}
 +
 +MIR_CORE_DLL(HANDLE) mir_forkthreadowner(pThreadFuncOwner aFunc, void *owner, void *arg, unsigned *pThreadID)
  {
  	struct FORK_ARG fa = { 0 };
 -	fa.threadcodeex = threadcode;
 +	fa.threadcodeex = (pThreadFuncEx)aFunc;
  	fa.arg = arg;
  	fa.owner = owner;
  	fa.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
 -	UINT_PTR rc = _beginthreadex(sec, stacksize, forkthreadex_r, (void *)&fa, 0, thraddr);
 -	if (rc)
 +
 +	DWORD threadID = 0;
 +	HANDLE hThread = CreateThread(NULL, 0, forkthreadex_r, &fa, 0, &threadID);
 +	if (hThread != NULL)
  		WaitForSingleObject(fa.hEvent, INFINITE);
 +	if (pThreadID != NULL)
 +		*pThreadID = threadID;
 +
  	CloseHandle(fa.hEvent);
 -	return rc;
 +	return hThread;
  }
  /////////////////////////////////////////////////////////////////////////////////////////
  | 
