diff options
-rw-r--r-- | protocols/Tlen/src/tlen.h | 11 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_iq.cpp | 14 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_list.cpp | 47 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_presence.cpp | 4 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_svc.cpp | 10 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_util.cpp | 13 |
6 files changed, 25 insertions, 74 deletions
diff --git a/protocols/Tlen/src/tlen.h b/protocols/Tlen/src/tlen.h index 7e0a43759b..4e6d281214 100644 --- a/protocols/Tlen/src/tlen.h +++ b/protocols/Tlen/src/tlen.h @@ -309,19 +309,19 @@ struct TlenProtocol : public PROTO<TlenProtocol> int listsCount;
struct TLEN_LIST_ITEM_STRUCT *lists;
- CRITICAL_SECTION csLists;
+ mir_cs csLists;
int iqCount;
int iqAlloced;
struct TLEN_IQ_FUNC_STRUCT *iqList;
- CRITICAL_SECTION csIqList;
+ mir_cs csIqList;
- CRITICAL_SECTION csSerial;
+ mir_cs csSerial;
unsigned int serial;
BOOL isOnline;
BOOL isConnected;
- CRITICAL_SECTION modeMsgMutex;
+ mir_cs modeMsgMutex;
void initMenuItems();
HGENMENU hMenuRoot;
@@ -332,7 +332,7 @@ struct TlenProtocol : public PROTO<TlenProtocol> char *searchQuery;
int searchQueryLen;
- CRITICAL_SECTION csSend;
+ mir_cs csSend;
HWND voiceDlgHWND;
struct TLEN_VOICE_CONTROL_STRUCT *playbackControl;
@@ -455,7 +455,6 @@ int TlenWsRecvAES(TlenProtocol *proto, char *data, long datalen, aes_context *ae // tlen_util.cpp
void TlenSerialInit(TlenProtocol *proto);
-void TlenSerialUninit(TlenProtocol *proto);
unsigned int TlenSerialNext(TlenProtocol *proto);
int TlenSend(TlenProtocol *proto, const char *fmt, ...);
MCONTACT TlenHContactFromJID(TlenProtocol *proto, const char *jid);
diff --git a/protocols/Tlen/src/tlen_iq.cpp b/protocols/Tlen/src/tlen_iq.cpp index 1f2ec5a410..84440d19ed 100644 --- a/protocols/Tlen/src/tlen_iq.cpp +++ b/protocols/Tlen/src/tlen_iq.cpp @@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void TlenIqInit(TlenProtocol *proto)
{
- InitializeCriticalSection(&proto->csIqList);
proto->iqList = NULL;
proto->iqCount = 0;
proto->iqAlloced = 0;
@@ -38,17 +37,15 @@ void TlenIqUninit(TlenProtocol *proto) proto->iqList = NULL;
proto->iqCount = 0;
proto->iqAlloced = 0;
- DeleteCriticalSection(&proto->csIqList);
}
static void TlenIqRemove(TlenProtocol *proto, int index)
{
- EnterCriticalSection(&proto->csIqList);
+ mir_cslock lck(proto->csIqList);
if (index >= 0 && index<proto->iqCount) {
memmove(proto->iqList+index, proto->iqList+index+1, sizeof(TLEN_IQ_FUNC)*(proto->iqCount-index-1));
proto->iqCount--;
}
- LeaveCriticalSection(&proto->csIqList);
}
static void TlenIqExpire(TlenProtocol *proto)
@@ -56,7 +53,7 @@ static void TlenIqExpire(TlenProtocol *proto) int i;
time_t expire;
- EnterCriticalSection(&proto->csIqList);
+ mir_cslock lck(proto->csIqList);
expire = time(NULL) - 120; // 2 minute
i = 0;
while (i < proto->iqCount) {
@@ -65,7 +62,6 @@ static void TlenIqExpire(TlenProtocol *proto) else
i++;
}
- LeaveCriticalSection(&proto->csIqList);
}
TLEN_IQ_PFUNC TlenIqFetchFunc(TlenProtocol *proto, int iqId)
@@ -73,7 +69,7 @@ TLEN_IQ_PFUNC TlenIqFetchFunc(TlenProtocol *proto, int iqId) int i;
TLEN_IQ_PFUNC res;
- EnterCriticalSection(&proto->csIqList);
+ mir_cslock lck(proto->csIqList);
TlenIqExpire(proto);
for (i=0; i<proto->iqCount && proto->iqList[i].iqId != iqId; i++);
if (i < proto->iqCount) {
@@ -83,7 +79,6 @@ TLEN_IQ_PFUNC TlenIqFetchFunc(TlenProtocol *proto, int iqId) else {
res = (TLEN_IQ_PFUNC) NULL;
}
- LeaveCriticalSection(&proto->csIqList);
return res;
}
@@ -91,7 +86,7 @@ void TlenIqAdd(TlenProtocol *proto, unsigned int iqId, TLEN_IQ_PROCID procId, TL {
int i;
- EnterCriticalSection(&proto->csIqList);
+ mir_cslock lck(proto->csIqList);
if (procId == IQ_PROC_NONE)
i = proto->iqCount;
else
@@ -109,6 +104,5 @@ void TlenIqAdd(TlenProtocol *proto, unsigned int iqId, TLEN_IQ_PROCID procId, TL proto->iqList[i].requestTime = time(NULL);
if (i == proto->iqCount) proto->iqCount++;
}
- LeaveCriticalSection(&proto->csIqList);
}
diff --git a/protocols/Tlen/src/tlen_list.cpp b/protocols/Tlen/src/tlen_list.cpp index ee6b5820da..ddd31b3340 100644 --- a/protocols/Tlen/src/tlen_list.cpp +++ b/protocols/Tlen/src/tlen_list.cpp @@ -31,20 +31,18 @@ void TlenListInit(TlenProtocol *proto) {
proto->lists = NULL;
proto->listsCount = 0;
- InitializeCriticalSection(&proto->csLists);
}
void TlenListUninit(TlenProtocol *proto)
{
TlenListWipe(proto);
- DeleteCriticalSection(&proto->csLists);
}
void TlenListWipe(TlenProtocol *proto)
{
int i;
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
for (i=0; i<proto->listsCount; i++)
TlenListFreeItemInternal(&(proto->lists[i]));
if (proto->lists != NULL) {
@@ -52,13 +50,12 @@ void TlenListWipe(TlenProtocol *proto) proto->lists = NULL;
}
proto->listsCount=0;
- LeaveCriticalSection(&proto->csLists);
}
void TlenListWipeSpecial(TlenProtocol *proto)
{
int i;
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
for (i=0; i<proto->listsCount; i++) {
if (proto->lists[i].list != LIST_FILE && proto->lists[i].list != LIST_VOICE) {
TlenListFreeItemInternal(&(proto->lists[i]));
@@ -68,7 +65,6 @@ void TlenListWipeSpecial(TlenProtocol *proto) }
}
proto->lists = (TLEN_LIST_ITEM *) mir_realloc(proto->lists, sizeof(TLEN_LIST_ITEM)*proto->listsCount);
- LeaveCriticalSection(&proto->csLists);
}
static void TlenListFreeItemInternal(TLEN_LIST_ITEM *item)
@@ -117,17 +113,15 @@ int TlenListExist(TlenProtocol *proto, TLEN_LIST list, const char *jid) s = GetItemId(list, jid);
len = strlen(s);
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
for (i=0; i<proto->listsCount; i++)
if (proto->lists[i].list == list) {
p = proto->lists[i].jid;
if (p && strlen(p) >= len && (p[(int)len] == '\0' || p[(int)len] == '/') && !strncmp(p, s, len)) {
- LeaveCriticalSection(&proto->csLists);
mir_free(s);
return i+1;
}
}
- LeaveCriticalSection(&proto->csLists);
mir_free(s);
return 0;
}
@@ -137,9 +131,8 @@ TLEN_LIST_ITEM *TlenListAdd(TlenProtocol *proto, TLEN_LIST list, const char *jid char *s;
TLEN_LIST_ITEM *item;
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
if ((item=TlenListGetItemPtr(proto, list, jid)) != NULL) {
- LeaveCriticalSection(&proto->csLists);
return item;
}
@@ -168,7 +161,6 @@ TLEN_LIST_ITEM *TlenListAdd(TlenProtocol *proto, TLEN_LIST list, const char *jid item->versionRequested = FALSE;
item->infoRequested = FALSE;
proto->listsCount++;
- LeaveCriticalSection(&proto->csLists);
return item;
}
@@ -177,10 +169,9 @@ void TlenListRemove(TlenProtocol *proto, TLEN_LIST list, const char *jid) {
int i;
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
i = TlenListExist(proto, list, jid);
if (!i) {
- LeaveCriticalSection(&proto->csLists);
return;
}
i--;
@@ -188,7 +179,6 @@ void TlenListRemove(TlenProtocol *proto, TLEN_LIST list, const char *jid) proto->listsCount--;
memmove(proto->lists+i, proto->lists+i+1, sizeof(TLEN_LIST_ITEM)*(proto->listsCount-i));
proto->lists = (TLEN_LIST_ITEM *) mir_realloc(proto->lists, sizeof(TLEN_LIST_ITEM)*proto->listsCount);
- LeaveCriticalSection(&proto->csLists);
}
void TlenListRemoveList(TlenProtocol *proto, TLEN_LIST list)
@@ -203,24 +193,22 @@ void TlenListRemoveList(TlenProtocol *proto, TLEN_LIST list) void TlenListRemoveByIndex(TlenProtocol *proto, int index)
{
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
if (index >= 0 && index<proto->listsCount) {
TlenListFreeItemInternal(&(proto->lists[index]));
proto->listsCount--;
memmove(proto->lists+index, proto->lists+index+1, sizeof(TLEN_LIST_ITEM)*(proto->listsCount-index));
proto->lists = (TLEN_LIST_ITEM *) mir_realloc(proto->lists, sizeof(TLEN_LIST_ITEM)*proto->listsCount);
}
- LeaveCriticalSection(&proto->csLists);
}
void TlenListAddResource(TlenProtocol *proto, TLEN_LIST list, const char *jid, int status, const char *statusMessage)
{
int i;
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
i = TlenListExist(proto, list, jid);
if (!i) {
- LeaveCriticalSection(&proto->csLists);
return;
}
i--;
@@ -231,34 +219,29 @@ void TlenListAddResource(TlenProtocol *proto, TLEN_LIST list, const char *jid, i proto->lists[i].statusMessage = mir_strdup(statusMessage);
else
proto->lists[i].statusMessage = NULL;
- LeaveCriticalSection(&proto->csLists);
}
void TlenListRemoveResource(TlenProtocol *proto, TLEN_LIST list, const char *jid)
{
int i;
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
i = TlenListExist(proto, list, jid);
if (!i) {
- LeaveCriticalSection(&proto->csLists);
return;
}
i--;
- LeaveCriticalSection(&proto->csLists);
}
int TlenListFindNext(TlenProtocol *proto, TLEN_LIST list, int fromOffset)
{
int i;
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
i = (fromOffset >= 0) ? fromOffset : 0;
for (; i<proto->listsCount; i++)
if (proto->lists[i].list == list) {
- LeaveCriticalSection(&proto->csLists);
return i;
}
- LeaveCriticalSection(&proto->csLists);
return -1;
}
@@ -266,14 +249,12 @@ TLEN_LIST_ITEM *TlenListGetItemPtr(TlenProtocol *proto, TLEN_LIST list, const ch {
int i;
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
i = TlenListExist(proto, list, jid);
if (!i) {
- LeaveCriticalSection(&proto->csLists);
return NULL;
}
i--;
- LeaveCriticalSection(&proto->csLists);
return &(proto->lists[i]);
}
@@ -286,30 +267,26 @@ TLEN_LIST_ITEM *TlenListFindItemPtrById2(TlenProtocol *proto, TLEN_LIST list, co len = strlen(id);
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
for (i=0; i<proto->listsCount; i++) {
if (proto->lists[i].list == list) {
p = proto->lists[i].id2;
if (p != NULL) {
if (!strncmp(p, id, len)) {
- LeaveCriticalSection(&proto->csLists);
return &(proto->lists[i]);
}
}
}
}
- LeaveCriticalSection(&proto->csLists);
return NULL;
}
TLEN_LIST_ITEM *TlenListGetItemPtrFromIndex(TlenProtocol *proto, int index)
{
- EnterCriticalSection(&proto->csLists);
+ mir_cslock lck(proto->csLists);
if (index >= 0 && index<proto->listsCount) {
- LeaveCriticalSection(&proto->csLists);
return &(proto->lists[index]);
}
- LeaveCriticalSection(&proto->csLists);
return NULL;
}
diff --git a/protocols/Tlen/src/tlen_presence.cpp b/protocols/Tlen/src/tlen_presence.cpp index 3f4785206e..e9e4b11fe7 100644 --- a/protocols/Tlen/src/tlen_presence.cpp +++ b/protocols/Tlen/src/tlen_presence.cpp @@ -203,7 +203,7 @@ static void TlenSendPresenceTo(TlenProtocol *proto, int status, char *to) // Send <presence/> update for status (we won't handle ID_STATUS_OFFLINE here) // Note: tlenModeMsg is already encoded using TlenTextEncode() - EnterCriticalSection(&proto->modeMsgMutex); + mir_cslock lck(proto->modeMsgMutex); showBody = NULL; statusMsg = NULL; @@ -309,8 +309,6 @@ static void TlenSendPresenceTo(TlenProtocol *proto, int status, char *to) } setOwnStatusOnCList(proto, proto->m_iStatus, statusMsg); - - LeaveCriticalSection(&proto->modeMsgMutex); } diff --git a/protocols/Tlen/src/tlen_svc.cpp b/protocols/Tlen/src/tlen_svc.cpp index 3ae3ed75e6..96e20cdc21 100644 --- a/protocols/Tlen/src/tlen_svc.cpp +++ b/protocols/Tlen/src/tlen_svc.cpp @@ -420,7 +420,7 @@ int TlenProtocol::SetAwayMsg(int iStatus, const PROTOCHAR* msg) debugLogA("SetAwayMsg called, wParam=%d lParam=%s", iStatus, newModeMsg);
- EnterCriticalSection(&modeMsgMutex);
+ mir_cslock lck(modeMsgMutex);
switch (iStatus) {
case ID_STATUS_ONLINE:
@@ -445,7 +445,6 @@ int TlenProtocol::SetAwayMsg(int iStatus, const PROTOCHAR* msg) szMsg = &modeMsgs.szInvisible;
break;
default:
- LeaveCriticalSection(&modeMsgMutex);
return 1;
}
@@ -464,7 +463,6 @@ int TlenProtocol::SetAwayMsg(int iStatus, const PROTOCHAR* msg) }
}
- LeaveCriticalSection(&modeMsgMutex);
return 0;
}
@@ -1222,9 +1220,6 @@ TlenProtocol::TlenProtocol( const char *aProtoName, const TCHAR *aUserName) : {
TlenInitServicesVTbl(this);
- InitializeCriticalSection(&modeMsgMutex);
- InitializeCriticalSection(&csSend);
-
hTlenNudge = CreateProtoEvent("/Nudge");
HookProtoEvent(ME_OPT_INITIALISE, &TlenProtocol::OptionsInit);
@@ -1261,9 +1256,6 @@ TlenProtocol::~TlenProtocol() DestroyHookableEvent(hTlenNudge);
TlenListUninit(this);
TlenIqUninit(this);
- TlenSerialUninit(this);
- DeleteCriticalSection(&modeMsgMutex);
- DeleteCriticalSection(&csSend);
TlenWsUninit(this);
mir_free(modeMsgs.szOnline);
diff --git a/protocols/Tlen/src/tlen_util.cpp b/protocols/Tlen/src/tlen_util.cpp index 981c6da6fb..228f8dae8e 100644 --- a/protocols/Tlen/src/tlen_util.cpp +++ b/protocols/Tlen/src/tlen_util.cpp @@ -28,24 +28,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void TlenSerialInit(TlenProtocol *proto)
{
- InitializeCriticalSection(&proto->csSerial);
proto->serial = 0;
}
-void TlenSerialUninit(TlenProtocol *proto)
-{
- DeleteCriticalSection(&proto->csSerial);
-}
-
-
unsigned int TlenSerialNext(TlenProtocol *proto)
{
unsigned int ret;
- EnterCriticalSection(&proto->csSerial);
+ mir_cslock lck(proto->csSerial);
ret = proto->serial;
proto->serial++;
- LeaveCriticalSection(&proto->csSerial);
return ret;
}
@@ -58,7 +50,7 @@ int TlenSend(TlenProtocol *proto, const char *fmt, ...) va_list vararg;
int result = 0;
- EnterCriticalSection(&proto->csSend);
+ mir_cslock lck(proto->csSend);
va_start(vararg,fmt);
size = 512;
@@ -78,7 +70,6 @@ int TlenSend(TlenProtocol *proto, const char *fmt, ...) result = TlenWsSend(proto, proto->threadData->s, str, size);
}
}
- LeaveCriticalSection(&proto->csSend);
mir_free(str);
return result;
|