summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-02 22:30:27 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-02 22:30:27 +0000
commit980bcaff693a86971750d6e9ffc8ba1e561b8b3a (patch)
treed8a422e9ccd2357d6e28368447bee8cfcd26123a /src
parent990f961261d92fccadb16b495171bb619c0183f0 (diff)
the core without manual critical sections' control
git-svn-id: http://svn.miranda-ng.org/main/trunk@730 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/modules/button/button.cpp18
-rw-r--r--src/modules/clist/clisttray.cpp4
-rw-r--r--src/modules/clist/genmenu.cpp247
-rw-r--r--src/modules/icolib/skin2icons.cpp62
-rw-r--r--src/modules/icolib/skin2opts.cpp116
-rw-r--r--src/modules/netlib/netlib.cpp28
-rw-r--r--src/modules/netlib/netlibbind.cpp168
-rw-r--r--src/modules/netlib/netlibhttp.cpp27
-rw-r--r--src/modules/netlib/netlibhttpproxy.cpp92
-rw-r--r--src/modules/netlib/netliblog.cpp22
-rw-r--r--src/modules/netlib/netlibopenconn.cpp3
-rw-r--r--src/modules/netlib/netlibopts.cpp408
-rw-r--r--src/modules/netlib/netlibupnp.cpp16
13 files changed, 509 insertions, 702 deletions
diff --git a/src/modules/button/button.cpp b/src/modules/button/button.cpp
index 8889af9bf5..2f7fce43f4 100644
--- a/src/modules/button/button.cpp
+++ b/src/modules/button/button.cpp
@@ -306,14 +306,12 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
TTooltips tt;
tt.ThreadId = GetCurrentThreadId();
- EnterCriticalSection(&csTips);
+ mir_cslock lck(csTips);
if ((idx = lToolTips.getIndex(&tt)) != -1) {
mir_free(lToolTips[idx]);
lToolTips.remove(idx);
DestroyWindow(bct->hwndToolTips);
}
- LeaveCriticalSection(&csTips);
-
bct->hwndToolTips = NULL;
}
}
@@ -489,7 +487,7 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
TTooltips tt;
tt.ThreadId = GetCurrentThreadId();
- EnterCriticalSection(&csTips);
+ mir_cslock lck(csTips);
if ((idx = lToolTips.getIndex(&tt)) != -1)
bct->hwndToolTips = lToolTips[idx]->hwnd;
else {
@@ -499,7 +497,6 @@ static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg, WPARAM wParam, L
lToolTips.insert(ptt);
bct->hwndToolTips = ptt->hwnd;
}
- LeaveCriticalSection(&csTips);
}
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_IDISHWND;
@@ -646,10 +643,11 @@ int LoadButtonModule(void)
void UnloadButtonModule()
{
- if (bModuleInitialized) {
- EnterCriticalSection(&csTips);
+ if ( !bModuleInitialized)
+ return;
+
+ { mir_cslock lck(csTips);
lToolTips.destroy();
- LeaveCriticalSection(&csTips);
- DeleteCriticalSection(&csTips);
- }
+ }
+ DeleteCriticalSection(&csTips);
}
diff --git a/src/modules/clist/clisttray.cpp b/src/modules/clist/clisttray.cpp
index 013a639168..e8a3a12d3b 100644
--- a/src/modules/clist/clisttray.cpp
+++ b/src/modules/clist/clisttray.cpp
@@ -953,14 +953,14 @@ void fnUninitTray(void)
fTrayInited=FALSE;
DeleteCriticalSection(&trayLockCS);
}
-void fnLockTray(void)
+void fnLockTray(void)
{
// return; //stub to be removed
initcheck;
EnterCriticalSection(&trayLockCS);
}
-void fnUnlockTray(void)
+void fnUnlockTray(void)
{
// return; //stub to be removed
initcheck;
diff --git a/src/modules/clist/genmenu.cpp b/src/modules/clist/genmenu.cpp
index ff6ead1d75..30f856b7ee 100644
--- a/src/modules/clist/genmenu.cpp
+++ b/src/modules/clist/genmenu.cpp
@@ -138,13 +138,11 @@ int MO_DrawMenuItem(LPDRAWITEMSTRUCT dis)
if (dis == NULL)
return FALSE;
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
PMO_IntMenuItem pimi = MO_GetIntMenuItem((HGENMENU)dis->itemData);
- if (pimi == NULL || pimi->iconId == -1) {
- LeaveCriticalSection(&csMenuHook);
+ if (pimi == NULL || pimi->iconId == -1)
return FALSE;
- }
int y = (dis->rcItem.bottom - dis->rcItem.top - GetSystemMetrics(SM_CYSMICON))/2+1;
if (dis->itemState & ODS_SELECTED) {
@@ -173,7 +171,6 @@ int MO_DrawMenuItem(LPDRAWITEMSTRUCT dis)
}
else ImageList_DrawEx(pimi->parent->m_hMenuIcons, pimi->iconId, dis->hDC, 2, y, 0, 0, CLR_NONE, CLR_NONE, ILD_NORMAL);
}
- LeaveCriticalSection(&csMenuHook);
return TRUE;
}
@@ -190,20 +187,16 @@ int MO_RemoveAllObjects()
//wparam=MenuObjectHandle
INT_PTR MO_RemoveMenuObject(WPARAM wParam, LPARAM)
{
- int objidx;
-
- if ( !bIsGenMenuInited) return -1;
- EnterCriticalSection(&csMenuHook);
+ if ( !bIsGenMenuInited)
+ return -1;
- objidx = GetMenuObjbyId((int)wParam);
- if (objidx == -1) {
- LeaveCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
+ int objidx = GetMenuObjbyId((int)wParam);
+ if (objidx == -1)
return -1;
- }
delete g_menus[ objidx ];
g_menus.remove(objidx);
- LeaveCriticalSection(&csMenuHook);
return 0;
}
@@ -214,13 +207,10 @@ INT_PTR MO_ProcessHotKeys(HANDLE menuHandle, INT_PTR vKey)
if ( !bIsGenMenuInited)
return -1;
- EnterCriticalSection(&csMenuHook);
-
+ mir_cslock lck(csMenuHook);
int objidx = GetMenuObjbyId((int)menuHandle);
- if (objidx == -1) {
- LeaveCriticalSection(&csMenuHook);
+ if (objidx == -1)
return FALSE;
- }
for (PMO_IntMenuItem pimi = g_menus[objidx]->m_items.first; pimi != NULL; pimi = pimi->next) {
if (pimi->mi.hotKey == 0) continue;
@@ -230,11 +220,9 @@ INT_PTR MO_ProcessHotKeys(HANDLE menuHandle, INT_PTR vKey)
if ( !(LOWORD(pimi->mi.hotKey) & MOD_SHIFT) != !(GetKeyState(VK_SHIFT) & 0x8000)) continue;
MO_ProcessCommand(pimi, 0);
- LeaveCriticalSection(&csMenuHook);
return TRUE;
}
- LeaveCriticalSection(&csMenuHook);
return FALSE;
}
@@ -251,16 +239,14 @@ INT_PTR MO_GetProtoRootMenu(WPARAM wParam, LPARAM lParam)
if (objidx == -1)
return NULL;
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
TIntMenuObject* pmo = g_menus[objidx];
- PMO_IntMenuItem p;
- for (p = pmo->m_items.first; p != NULL; p = p->next)
+ for (PMO_IntMenuItem p = pmo->m_items.first; p != NULL; p = p->next)
if ( !lstrcmpA(p->UniqName, szProto))
- break;
+ return (INT_PTR)p;
- LeaveCriticalSection(&csMenuHook);
- return (INT_PTR)p;
+ return NULL;
}
//wparam=MenuItemHandle
@@ -272,14 +258,11 @@ INT_PTR MO_GetMenuItem(WPARAM wParam, LPARAM lParam)
return -1;
PMO_IntMenuItem pimi = MO_GetIntMenuItem((HGENMENU)wParam);
- EnterCriticalSection(&csMenuHook);
- if ( !pimi) {
- LeaveCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
+ if ( !pimi)
return -1;
- }
*mi = pimi->mi;
- LeaveCriticalSection(&csMenuHook);
return 0;
}
@@ -297,12 +280,8 @@ INT_PTR MO_GetDefaultMenuItem(WPARAM wParam, LPARAM)
return -1;
PMO_IntMenuItem pimi = MO_GetIntMenuItem((HGENMENU)wParam);
- EnterCriticalSection(&csMenuHook);
- if (pimi)
- pimi = MO_RecursiveWalkMenu(pimi, FindDefaultItem, NULL);
-
- LeaveCriticalSection(&csMenuHook);
- return (INT_PTR)pimi;
+ mir_cslock lck(csMenuHook);
+ return (pimi) ? (INT_PTR)MO_RecursiveWalkMenu(pimi, FindDefaultItem, NULL) : NULL;
}
//wparam MenuItemHandle
@@ -314,13 +293,11 @@ int MO_ModifyMenuItem(PMO_IntMenuItem menuHandle, PMO_MenuItem pmi)
if ( !bIsGenMenuInited || pmi == NULL || pmi->cbSize != sizeof(TMO_MenuItem))
return -1;
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
PMO_IntMenuItem pimi = MO_GetIntMenuItem((HGENMENU)menuHandle);
- if ( !pimi) {
- LeaveCriticalSection(&csMenuHook);
+ if ( !pimi)
return -1;
- }
if (pmi->flags & CMIM_NAME) {
FreeAndNil((void**)&pimi->mi.pszName);
@@ -362,7 +339,6 @@ int MO_ModifyMenuItem(PMO_IntMenuItem menuHandle, PMO_MenuItem pmi)
if (pmi->flags & CMIM_HOTKEY)
pimi->mi.hotKey = pmi->hotKey;
- LeaveCriticalSection(&csMenuHook);
return 0;
}
@@ -374,16 +350,9 @@ INT_PTR MO_MenuItemGetOwnerData(WPARAM wParam, LPARAM)
if ( !bIsGenMenuInited)
return -1;
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
PMO_IntMenuItem pimi = MO_GetIntMenuItem((HGENMENU)wParam);
- if ( !pimi) {
- LeaveCriticalSection(&csMenuHook);
- return -1;
- }
-
- INT_PTR res = (INT_PTR)pimi->mi.ownerdata;
- LeaveCriticalSection(&csMenuHook);
- return res;
+ return (pimi) ? (INT_PTR)pimi->mi.ownerdata : -1;
}
PMO_IntMenuItem MO_GetIntMenuItem(HGENMENU wParam)
@@ -417,22 +386,17 @@ int MO_ProcessCommandBySubMenuIdent(int menuID, int command, LPARAM lParam)
if ( !bIsGenMenuInited)
return -1;
- EnterCriticalSection(&csMenuHook);
-
- int objidx = GetMenuObjbyId(menuID);
- if (objidx == -1) {
- LeaveCriticalSection(&csMenuHook);
- return -1;
- }
+ PMO_IntMenuItem pimi;
+ {
+ mir_cslock lck(csMenuHook);
+ int objidx = GetMenuObjbyId(menuID);
+ if (objidx == -1)
+ return -1;
- PMO_IntMenuItem pimi = MO_RecursiveWalkMenu(g_menus[objidx]->m_items.first, FindMenuByCommand, (void*)command);
- if (pimi) {
- LeaveCriticalSection(&csMenuHook);
- return MO_ProcessCommand(pimi, lParam);
+ pimi = MO_RecursiveWalkMenu(g_menus[objidx]->m_items.first, FindMenuByCommand, (void*)command);
}
- LeaveCriticalSection(&csMenuHook);
- return -1;
+ return (pimi) ? MO_ProcessCommand(pimi, lParam) : -1;
}
INT_PTR MO_ProcessCommandByMenuIdent(WPARAM wParam, LPARAM lParam)
@@ -440,17 +404,15 @@ INT_PTR MO_ProcessCommandByMenuIdent(WPARAM wParam, LPARAM lParam)
if ( !bIsGenMenuInited)
return -1;
- EnterCriticalSection(&csMenuHook);
-
- for (int i=0; i < g_menus.getCount(); i++) {
- PMO_IntMenuItem pimi = MO_RecursiveWalkMenu(g_menus[i]->m_items.first, FindMenuByCommand, (void*)wParam);
- if (pimi) {
- LeaveCriticalSection(&csMenuHook);
- return MO_ProcessCommand(pimi, lParam);
- } }
+ PMO_IntMenuItem pimi;
+ {
+ mir_cslock lck(csMenuHook);
+ for (int i=0; i < g_menus.getCount(); i++)
+ if ((pimi = MO_RecursiveWalkMenu(g_menus[i]->m_items.first, FindMenuByCommand, (void*)wParam)) != NULL)
+ break;
+ }
- LeaveCriticalSection(&csMenuHook);
- return FALSE;
+ return (pimi) ? MO_ProcessCommand(pimi, lParam) : FALSE;
}
int MO_ProcessCommand(PMO_IntMenuItem aHandle, LPARAM lParam)
@@ -458,16 +420,15 @@ int MO_ProcessCommand(PMO_IntMenuItem aHandle, LPARAM lParam)
if ( !bIsGenMenuInited)
return -1;
- EnterCriticalSection(&csMenuHook);
- PMO_IntMenuItem pimi = MO_GetIntMenuItem(aHandle);
- if ( !pimi) {
- LeaveCriticalSection(&csMenuHook);
- return -1;
+ PMO_IntMenuItem pimi;
+ {
+ mir_cslock lck(csMenuHook);
+ if ((pimi = MO_GetIntMenuItem(aHandle)) == NULL)
+ return -1;
}
char *srvname = pimi->parent->ExecService;
void *ownerdata = pimi->mi.ownerdata;
- LeaveCriticalSection(&csMenuHook);
CallService(srvname, (WPARAM)ownerdata, lParam);
return 1;
}
@@ -477,26 +438,17 @@ int MO_SetOptionsMenuItem(PMO_IntMenuItem aHandle, int setting, INT_PTR value)
if ( !bIsGenMenuInited)
return -1;
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
PMO_IntMenuItem pimi = MO_GetIntMenuItem(aHandle);
- if ( !pimi) {
- LeaveCriticalSection(&csMenuHook);
+ if ( !pimi)
return -1;
- }
- int res = -1;
- __try
- {
- res = 1;
- if (setting == OPT_MENUITEMSETUNIQNAME) {
- mir_free(pimi->UniqName);
- pimi->UniqName = mir_strdup((char*)value);
- }
+ if (setting == OPT_MENUITEMSETUNIQNAME) {
+ mir_free(pimi->UniqName);
+ pimi->UniqName = mir_strdup((char*)value);
}
- __except(EXCEPTION_EXECUTE_HANDLER) {}
- LeaveCriticalSection(&csMenuHook);
- return res;
+ return 1;
}
int MO_SetOptionsMenuObject(HANDLE handle, int setting, INT_PTR value)
@@ -507,39 +459,35 @@ int MO_SetOptionsMenuObject(HANDLE handle, int setting, INT_PTR value)
if ( !bIsGenMenuInited)
return -1;
- EnterCriticalSection(&csMenuHook);
- __try
- {
- pimoidx = GetMenuObjbyId((int)handle);
- res = pimoidx != -1;
- if (res) {
- TIntMenuObject* pmo = g_menus[pimoidx];
-
- switch (setting) {
- case OPT_MENUOBJECT_SET_ONADD_SERVICE:
- FreeAndNil((void**)&pmo->onAddService);
- pmo->onAddService = mir_strdup((char*)value);
- break;
+ mir_cslock lck(csMenuHook);
- case OPT_MENUOBJECT_SET_FREE_SERVICE:
- FreeAndNil((void**)&pmo->FreeService);
- pmo->FreeService = mir_strdup((char*)value);
- break;
+ pimoidx = GetMenuObjbyId((int)handle);
+ res = pimoidx != -1;
+ if (res) {
+ TIntMenuObject* pmo = g_menus[pimoidx];
- case OPT_MENUOBJECT_SET_CHECK_SERVICE:
- FreeAndNil((void**)&pmo->CheckService);
- pmo->CheckService = mir_strdup((char*)value);
- break;
+ switch (setting) {
+ case OPT_MENUOBJECT_SET_ONADD_SERVICE:
+ FreeAndNil((void**)&pmo->onAddService);
+ pmo->onAddService = mir_strdup((char*)value);
+ break;
- case OPT_USERDEFINEDITEMS:
- pmo->m_bUseUserDefinedItems = (BOOL)value;
- break;
- }
+ case OPT_MENUOBJECT_SET_FREE_SERVICE:
+ FreeAndNil((void**)&pmo->FreeService);
+ pmo->FreeService = mir_strdup((char*)value);
+ break;
+
+ case OPT_MENUOBJECT_SET_CHECK_SERVICE:
+ FreeAndNil((void**)&pmo->CheckService);
+ pmo->CheckService = mir_strdup((char*)value);
+ break;
+
+ case OPT_USERDEFINEDITEMS:
+ pmo->m_bUseUserDefinedItems = (BOOL)value;
+ break;
}
}
- __except(EXCEPTION_EXECUTE_HANDLER) {}
- LeaveCriticalSection(&csMenuHook);
return res;
}
@@ -552,7 +500,8 @@ INT_PTR MO_CreateNewMenuObject(WPARAM, LPARAM lParam)
if ( !bIsGenMenuInited || pmp == NULL)
return -1;
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
+
TIntMenuObject* p = new TIntMenuObject();
p->id = NextObjectId++;
p->Name = mir_strdup(pmp->name);
@@ -561,8 +510,6 @@ INT_PTR MO_CreateNewMenuObject(WPARAM, LPARAM lParam)
p->m_hMenuIcons = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
(IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 15, 100);
g_menus.insert(p);
-
- LeaveCriticalSection(&csMenuHook);
return p->id;
}
@@ -582,12 +529,10 @@ static int FindParent(TMO_IntMenuItem* pimi, void* p)
INT_PTR MO_RemoveMenuItem(WPARAM wParam, LPARAM)
{
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
PMO_IntMenuItem pimi = MO_GetIntMenuItem((HGENMENU)wParam);
- if ( !pimi) {
- LeaveCriticalSection(&csMenuHook);
+ if ( !pimi)
return -1;
- }
if (pimi->submenu.first) {
MO_RecursiveWalkMenu(pimi->submenu.first, FreeMenuItem, NULL);
@@ -604,8 +549,6 @@ INT_PTR MO_RemoveMenuItem(WPARAM wParam, LPARAM)
pimi->signature = 0; // invalidate all future calls to that object
pimi->parent->freeItem(pimi);
-
- LeaveCriticalSection(&csMenuHook);
return 0;
}
@@ -642,12 +585,10 @@ PMO_IntMenuItem MO_AddNewMenuItem(HANDLE menuobjecthandle, PMO_MenuItem pmi)
if ( !(pmi->flags & CMIF_ROOTHANDLE))
return MO_AddOldNewMenuItem(menuobjecthandle, pmi);
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
int objidx = GetMenuObjbyId((int)menuobjecthandle);
- if (objidx == -1) {
- LeaveCriticalSection(&csMenuHook);
+ if (objidx == -1)
return NULL;
- }
TIntMenuObject* pmo = g_menus[objidx];
@@ -695,8 +636,6 @@ PMO_IntMenuItem MO_AddNewMenuItem(HANDLE menuobjecthandle, PMO_MenuItem pmi)
if (p->owner->last)
p->owner->last->next = p;
p->owner->last = p;
-
- LeaveCriticalSection(&csMenuHook);
return p;
}
@@ -861,22 +800,18 @@ INT_PTR MO_BuildMenu(WPARAM wParam, LPARAM lParam)
if ( !bIsGenMenuInited)
return -1;
- EnterCriticalSection(&csMenuHook);
+ mir_cslock lck(csMenuHook);
ListParam *lp = (ListParam*)lParam;
int pimoidx = GetMenuObjbyId((int)lp->MenuObjectHandle);
- if (pimoidx == -1) {
- LeaveCriticalSection(&csMenuHook);
+ if (pimoidx == -1)
return 0;
- }
#if defined(_DEBUG)
// DumpMenuItem(g_menus[pimoidx]->m_items.first);
#endif
- INT_PTR res = (INT_PTR)BuildRecursiveMenu((HMENU)wParam, g_menus[pimoidx]->m_items.first, (ListParam*)lParam);
- LeaveCriticalSection(&csMenuHook);
- return res;
+ return (INT_PTR)BuildRecursiveMenu((HMENU)wParam, g_menus[pimoidx]->m_items.first, (ListParam*)lParam);
}
#ifdef _DEBUG
@@ -1059,12 +994,12 @@ static int MO_ReloadIcon(PMO_IntMenuItem pmi, void*)
int OnIconLibChanges(WPARAM, LPARAM)
{
- EnterCriticalSection(&csMenuHook);
- for (int mo=0; mo < g_menus.getCount(); mo++)
- if ((int)hStatusMenuObject != g_menus[mo]->id) //skip status menu
- MO_RecursiveWalkMenu(g_menus[mo]->m_items.first, MO_ReloadIcon, 0);
-
- LeaveCriticalSection(&csMenuHook);
+ {
+ mir_cslock lck(csMenuHook);
+ for (int mo=0; mo < g_menus.getCount(); mo++)
+ if ((int)hStatusMenuObject != g_menus[mo]->id) //skip status menu
+ MO_RecursiveWalkMenu(g_menus[mo]->m_items.first, MO_ReloadIcon, 0);
+ }
cli.pfnReloadProtoMenus();
return 0;
@@ -1217,9 +1152,7 @@ int InitGenMenu()
bIconsDisabled = DBGetContactSettingByte(NULL, "CList", "DisableMenuIcons", 0) != 0;
- EnterCriticalSection(&csMenuHook);
bIsGenMenuInited = true;
- LeaveCriticalSection(&csMenuHook);
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
HookEvent(ME_OPT_INITIALISE, GenMenuOptInit);
@@ -1229,11 +1162,11 @@ int InitGenMenu()
int UnitGenMenu()
{
if (bIsGenMenuInited) {
- EnterCriticalSection(&csMenuHook);
- MO_RemoveAllObjects();
- bIsGenMenuInited=false;
+ { mir_cslock lck(csMenuHook);
+ MO_RemoveAllObjects();
+ bIsGenMenuInited=false;
+ }
- LeaveCriticalSection(&csMenuHook);
DeleteCriticalSection(&csMenuHook);
}
return 0;
diff --git a/src/modules/icolib/skin2icons.cpp b/src/modules/icolib/skin2icons.cpp
index 7001bbae3b..6527d7a35e 100644
--- a/src/modules/icolib/skin2icons.cpp
+++ b/src/modules/icolib/skin2icons.cpp
@@ -503,7 +503,7 @@ HANDLE IcoLib_AddNewIcon(int hLangpack, SKINICONDESC* sid)
bool utf = (sid->flags & SIDF_UNICODE) != 0;
bool utf_path = (sid->flags & SIDF_PATH_UNICODE) != 0;
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
IconItem* item = IcoLib_FindIcon(sid->pszName);
if (!item) {
@@ -565,7 +565,6 @@ HANDLE IcoLib_AddNewIcon(int hLangpack, SKINICONDESC* sid)
if (item->section)
item->section->flags = sid->flags & SIDF_SORTED;
- LeaveCriticalSection(&csIconList);
return item;
}
@@ -575,9 +574,9 @@ HANDLE IcoLib_AddNewIcon(int hLangpack, SKINICONDESC* sid)
static INT_PTR IcoLib_RemoveIcon(WPARAM, LPARAM lParam)
{
if (lParam) {
- int indx;
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
+ int indx;
if ((indx = iconList.getIndex((IconItem*)&lParam)) != -1) {
IconItem *item = iconList[ indx ];
IcoLib_FreeIcon(item);
@@ -585,7 +584,6 @@ static INT_PTR IcoLib_RemoveIcon(WPARAM, LPARAM lParam)
SAFE_FREE((void**)&item);
}
- LeaveCriticalSection(&csIconList);
return (indx == -1) ? 1 : 0;
}
return 1; // Failed
@@ -678,20 +676,12 @@ HICON IconItem_GetIcon(IconItem* item, bool big)
HICON IcoLib_GetIcon(const char* pszIconName, bool big)
{
- IconItem* item;
- HICON result = NULL;
-
if ( !pszIconName)
return hIconBlank;
- EnterCriticalSection(&csIconList);
-
- item = IcoLib_FindIcon(pszIconName);
- if (item) {
- result = IconItem_GetIcon(item, big);
- }
- LeaveCriticalSection(&csIconList);
- return result;
+ mir_cslock lck(csIconList);
+ IconItem* item = IcoLib_FindIcon(pszIconName);
+ return (item) ? IconItem_GetIcon(item, big) : NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -700,16 +690,11 @@ HICON IcoLib_GetIcon(const char* pszIconName, bool big)
HANDLE IcoLib_GetIconHandle(const char* pszIconName)
{
- IconItem* item;
-
if ( !pszIconName)
return NULL;
- EnterCriticalSection(&csIconList);
- item = IcoLib_FindIcon(pszIconName);
- LeaveCriticalSection(&csIconList);
-
- return (HANDLE)item;
+ mir_cslock lck(csIconList);
+ return IcoLib_FindIcon(pszIconName);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -722,23 +707,12 @@ HICON IcoLib_GetIconByHandle(HANDLE hItem, bool big)
if (hItem == NULL)
return NULL;
- HICON result = hIconBlank;
+ mir_cslock lck(csIconList);
IconItem* pi = (IconItem*)hItem;
+ if ( iconList.getIndex(pi) != -1)
+ return IconItem_GetIcon(pi, big);
- EnterCriticalSection(&csIconList);
-
- // we can get any junk here... but getIndex() is MUCH faster than indexOf().
- __try
- {
- if (iconList.getIndex(pi) != -1)
- result = IconItem_GetIcon(pi, big);
- }
- __except(EXCEPTION_EXECUTE_HANDLER)
- {
- }
-
- LeaveCriticalSection(&csIconList);
- return result;
+ return hIconBlank;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -748,20 +722,17 @@ HICON IcoLib_GetIconByHandle(HANDLE hItem, bool big)
HANDLE IcoLib_IsManaged(HICON hIcon)
{
- IconItem* item;
-
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
bool big;
- item = IcoLib_FindHIcon(hIcon, big);
+ IconItem* item = IcoLib_FindHIcon(hIcon, big);
if (item) {
IconSourceItem* source = big && !item->cx ? item->source_big : item->source_small;
if (source->icon_ref_count == 0)
item = NULL;
}
- LeaveCriticalSection(&csIconList);
- return NULL;
+ return item;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -771,7 +742,7 @@ HANDLE IcoLib_IsManaged(HICON hIcon)
static INT_PTR IcoLib_AddRef(WPARAM wParam, LPARAM)
{
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
bool big;
IconItem *item = IcoLib_FindHIcon((HICON)wParam, big);
@@ -785,7 +756,6 @@ static INT_PTR IcoLib_AddRef(WPARAM wParam, LPARAM)
}
}
- LeaveCriticalSection(&csIconList);
return res;
}
diff --git a/src/modules/icolib/skin2opts.cpp b/src/modules/icolib/skin2opts.cpp
index 9c6f3f2a41..97529762e3 100644
--- a/src/modules/icolib/skin2opts.cpp
+++ b/src/modules/icolib/skin2opts.cpp
@@ -71,10 +71,9 @@ static HICON ExtractIconFromPath(const TCHAR *path, int cxIcon, int cyIcon)
int IcoLib_ReleaseIcon(HICON hIcon, char* szIconName, bool big)
{
- IconItem *item = NULL;
-
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
+ IconItem *item = NULL;
if (szIconName)
item = IcoLib_FindIcon(szIconName);
@@ -93,7 +92,6 @@ int IcoLib_ReleaseIcon(HICON hIcon, char* szIconName, bool big)
}
}
- LeaveCriticalSection(&csIconList);
return res;
}
@@ -149,7 +147,7 @@ static void LoadSectionIcons(TCHAR *filename, SectionItem* sectionActive)
mir_sntprintf(path, SIZEOF(path), _T("%s,"), filename);
int suffIndx = lstrlen(path);
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
for (int indx = 0; indx < iconList.getCount(); indx++) {
IconItem *item = iconList[ indx ];
@@ -166,9 +164,8 @@ static void LoadSectionIcons(TCHAR *filename, SectionItem* sectionActive)
item->temp_file = mir_tstrdup(path);
item->temp_icon = hIcon;
item->temp_reset = FALSE;
- } }
-
- LeaveCriticalSection(&csIconList);
+ }
+ }
}
void LoadSubIcons(HWND htv, TCHAR *filename, HTREEITEM hItem)
@@ -215,13 +212,11 @@ void UndoSubItemChanges(HWND htv, HTREEITEM hItem, int cmd)
TreeItem *treeItem = (TreeItem *)tvi.lParam;
if (SECTIONPARAM_FLAGS(treeItem->value) & SECTIONPARAM_HAVEPAGE) {
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
for (int indx = 0; indx < iconList.getCount(); indx++)
if (iconList[ indx ]->section == sectionList[ SECTIONPARAM_INDEX(treeItem->value) ])
UndoChanges(indx, cmd);
-
- LeaveCriticalSection(&csIconList);
}
tvi.hItem = TreeView_GetChild(htv, tvi.hItem);
@@ -318,7 +313,7 @@ void DoIconsChanged(HWND hwndDlg)
NotifyEventHooks(hIcons2ChangedEvent, 0, 0);
iconEventActive = 0;
- EnterCriticalSection(&csIconList); // Destroy unused icons
+ mir_cslock lck(csIconList); // Destroy unused icons
for (int indx = 0; indx < iconList.getCount(); indx++) {
IconItem *item = iconList[indx];
if (item->source_small && !item->source_small->icon_ref_count) {
@@ -330,7 +325,6 @@ void DoIconsChanged(HWND hwndDlg)
IconSourceItem_ReleaseIcon(item->source_big);
}
}
- LeaveCriticalSection(&csIconList);
}
static HTREEITEM FindNamedTreeItemAt(HWND hwndTree, HTREEITEM hItem, const TCHAR *name)
@@ -665,17 +659,17 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
//
// Reset temporary data & upload sections list
//
- EnterCriticalSection(&csIconList);
{
- int indx;
- for (indx = 0; indx < iconList.getCount(); indx++) {
+ mir_cslock lck(csIconList);
+
+ for (int indx = 0; indx < iconList.getCount(); indx++) {
iconList[indx]->temp_file = NULL;
iconList[indx]->temp_icon = NULL;
iconList[indx]->temp_reset = FALSE;
}
bNeedRebuild = FALSE;
}
- LeaveCriticalSection(&csIconList);
+
//
// Setup preview listview
//
@@ -775,26 +769,25 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
LVITEM lvi = {0};
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
-
- EnterCriticalSection(&csIconList);
-
- for (int indx = 0; indx < iconList.getCount(); indx++) {
- IconItem *item = iconList[indx];
- if (item->section == sectionActive) {
- lvi.pszText = item->getDescr();
- HICON hIcon = item->temp_icon;
- if (!hIcon)
- hIcon = IconItem_GetIcon_Preview(item);
- lvi.iImage = ImageList_AddIcon(hIml, hIcon);
- lvi.lParam = indx;
- ListView_InsertItem(hPreview, &lvi);
- if (hIcon != item->temp_icon)
- SafeDestroyIcon(&hIcon);
+ {
+ mir_cslock lck(csIconList);
+
+ for (int indx = 0; indx < iconList.getCount(); indx++) {
+ IconItem *item = iconList[indx];
+ if (item->section == sectionActive) {
+ lvi.pszText = item->getDescr();
+ HICON hIcon = item->temp_icon;
+ if (!hIcon)
+ hIcon = IconItem_GetIcon_Preview(item);
+ lvi.iImage = ImageList_AddIcon(hIml, hIcon);
+ lvi.lParam = indx;
+ ListView_InsertItem(hPreview, &lvi);
+ if (hIcon != item->temp_icon)
+ SafeDestroyIcon(&hIcon);
+ }
}
}
- LeaveCriticalSection(&csIconList);
-
if (sectionActive->flags & SIDF_SORTED)
ListView_SortItems(hPreview, DoSortIconsFunc, 0);
else
@@ -816,12 +809,13 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
for (indx = 0; indx < count; indx++) {
lvi.iItem = indx;
ListView_GetItem(hPreview, &lvi);
- EnterCriticalSection(&csIconList);
- hIcon = iconList[lvi.lParam]->temp_icon;
- if ( !hIcon)
- hIcon = IconItem_GetIcon_Preview(iconList[lvi.lParam]);
- LeaveCriticalSection(&csIconList);
-
+ {
+ mir_cslock lck(csIconList);
+ hIcon = iconList[lvi.lParam]->temp_icon;
+ if ( !hIcon)
+ hIcon = IconItem_GetIcon_Preview(iconList[lvi.lParam]);
+ }
+
if (hIcon)
ImageList_ReplaceIcon(hIml, lvi.iImage, hIcon);
if (hIcon != iconList[lvi.lParam]->temp_icon) SafeDestroyIcon(&hIcon);
@@ -837,19 +831,18 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
lvi.mask = LVIF_PARAM;
lvi.iItem = wParam;
ListView_GetItem(hPreview, &lvi);
+ {
+ mir_cslock lck(csIconList);
+ IconItem *item = iconList[ lvi.lParam ];
- EnterCriticalSection(&csIconList);
- IconItem *item = iconList[ lvi.lParam ];
-
- SAFE_FREE((void**)&item->temp_file);
- SafeDestroyIcon(&item->temp_icon);
-
- TCHAR *path = (TCHAR*)lParam;
- item->temp_file = mir_tstrdup(path);
- item->temp_icon = (HICON)ExtractIconFromPath(path, item->cx, item->cy);
- item->temp_reset = FALSE;
+ SAFE_FREE((void**)&item->temp_file);
+ SafeDestroyIcon(&item->temp_icon);
- LeaveCriticalSection(&csIconList);
+ TCHAR *path = (TCHAR*)lParam;
+ item->temp_file = mir_tstrdup(path);
+ item->temp_icon = (HICON)ExtractIconFromPath(path, item->cx, item->cy);
+ item->temp_reset = FALSE;
+ }
DoOptionsChanged(hwndDlg);
}
break;
@@ -927,7 +920,7 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
switch(((LPNMHDR)lParam)->code) {
case PSN_APPLY:
{
- EnterCriticalSection(&csIconList);
+ mir_cslock lck(csIconList);
for (int indx = 0; indx < iconList.getCount(); indx++) {
IconItem *item = iconList[indx];
@@ -943,11 +936,10 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
SafeDestroyIcon(&item->temp_icon);
}
}
- LeaveCriticalSection(&csIconList);
-
- DoIconsChanged(hwndDlg);
- return TRUE;
}
+
+ DoIconsChanged(hwndDlg);
+ return TRUE;
}
break;
@@ -969,9 +961,7 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
}
}
if (bNeedRebuild) {
- EnterCriticalSection(&csIconList);
bNeedRebuild = FALSE;
- LeaveCriticalSection(&csIconList);
SendMessage(hwndDlg, DM_REBUILD_CTREE, 0, 0);
}
break;
@@ -1002,9 +992,9 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
}
}
if (bNeedRebuild) {
- EnterCriticalSection(&csIconList);
- bNeedRebuild = FALSE;
- LeaveCriticalSection(&csIconList);
+ { mir_cslock lck(csIconList);
+ bNeedRebuild = FALSE;
+ }
SendMessage(hwndDlg, DM_REBUILD_CTREE, 0, 0);
} }
break;
@@ -1012,9 +1002,8 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
case WM_DESTROY:
SaveCollapseState(GetDlgItem(hwndDlg, IDC_CATEGORYLIST));
DestroyWindow(dat->hwndIndex);
-
- EnterCriticalSection(&csIconList);
{
+ mir_cslock lck(csIconList);
for (int indx = 0; indx < iconList.getCount(); indx++) {
IconItem *item = iconList[indx];
@@ -1022,7 +1011,6 @@ INT_PTR CALLBACK DlgProcIcoLibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
SafeDestroyIcon(&item->temp_icon);
}
}
- LeaveCriticalSection(&csIconList);
SAFE_FREE((void**)&dat);
break;
diff --git a/src/modules/netlib/netlib.cpp b/src/modules/netlib/netlib.cpp
index 9c6f55aa11..bd72a8374b 100644
--- a/src/modules/netlib/netlib.cpp
+++ b/src/modules/netlib/netlib.cpp
@@ -130,8 +130,6 @@ static char *GetNetlibUserSettingString(const char *szUserModule, const char *sz
static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam)
{
NETLIBUSER *nlu=(NETLIBUSER*)lParam;
- struct NetlibUser *thisUser;
-
if (nlu == NULL || nlu->cbSize != sizeof(NETLIBUSER) || nlu->szSettingsModule == NULL
|| ( !(nlu->flags&NUF_NOOPTIONS) && nlu->szDescriptiveName == NULL)
|| (nlu->flags&NUF_HTTPGATEWAY && (nlu->pfnHttpGatewayInit == NULL))) {
@@ -139,19 +137,20 @@ static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam)
return 0;
}
- thisUser = (struct NetlibUser*)mir_calloc(sizeof(struct NetlibUser));
+ NetlibUser *thisUser = (struct NetlibUser*)mir_calloc(sizeof(struct NetlibUser));
thisUser->handleType = NLH_USER;
thisUser->user = *nlu;
- EnterCriticalSection(&csNetlibUser);
- if (netlibUser.getIndex(thisUser) >= 0)
+ int idx;
{
- LeaveCriticalSection(&csNetlibUser);
+ mir_cslock lck(csNetlibUser);
+ idx = netlibUser.getIndex(thisUser);
+ }
+ if (idx != -1) {
mir_free(thisUser);
SetLastError(ERROR_DUP_NAME);
return 0;
}
- LeaveCriticalSection(&csNetlibUser);
if (nlu->szDescriptiveName) {
thisUser->user.ptszDescriptiveName = (thisUser->user.flags&NUF_UNICODE ? mir_u2t((WCHAR*)nlu->ptszDescriptiveName) : mir_a2t(nlu->szDescriptiveName));
@@ -193,9 +192,8 @@ static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam)
thisUser->toLog=GetNetlibUserSettingInt(thisUser->user.szSettingsModule, "NLlog", 1);
- EnterCriticalSection(&csNetlibUser);
+ mir_cslock lck(csNetlibUser);
netlibUser.insert(thisUser);
- LeaveCriticalSection(&csNetlibUser);
return (INT_PTR)thisUser;
}
@@ -247,12 +245,12 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM)
case NLH_USER:
{
struct NetlibUser *nlu=(struct NetlibUser*)wParam;
- int i;
-
- EnterCriticalSection(&csNetlibUser);
- i = netlibUser.getIndex(nlu);
- if (i >= 0) netlibUser.remove(i);
- LeaveCriticalSection(&csNetlibUser);
+ {
+ mir_cslock lck(csNetlibUser);
+ int i = netlibUser.getIndex(nlu);
+ if (i >= 0)
+ netlibUser.remove(i);
+ }
NetlibFreeUserSettingsStruct(&nlu->settings);
mir_free(nlu->user.szSettingsModule);
diff --git a/src/modules/netlib/netlibbind.cpp b/src/modules/netlib/netlibbind.cpp
index 0b6aca709d..582358b619 100644
--- a/src/modules/netlib/netlibbind.cpp
+++ b/src/modules/netlib/netlibbind.cpp
@@ -25,97 +25,86 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
bool BindSocketToPort(const char *szPorts, SOCKET s, SOCKET s6, int* portn)
{
- SOCKADDR_IN sin = {0};
- sin.sin_family = AF_INET;
-
- SOCKADDR_IN6 sin6 = {0};
- sin6.sin6_family = AF_INET6;
-
- EnterCriticalSection(&csNetlibUser);
-
- if (--*portn < 0 && (s != INVALID_SOCKET || s6 != INVALID_SOCKET))
- {
- BindSocketToPort(szPorts, INVALID_SOCKET, INVALID_SOCKET, portn);
- if (*portn == 0)
- {
- LeaveCriticalSection(&csNetlibUser);
- return false;
- }
- WORD num;
- CallService(MS_UTILS_GETRANDOM, sizeof(WORD), (LPARAM)&num);
- *portn = num % *portn;
- }
-
- bool before=false;
- for (;;)
- {
- const char *psz;
- char *pszEnd;
- int portMin, portMax, port, portnum = 0;
-
- for (psz=szPorts;*psz;)
- {
- while (*psz == ' ' || *psz == ',') psz++;
- portMin = strtol(psz, &pszEnd, 0);
- if (pszEnd == psz) break;
- while (*pszEnd == ' ') pszEnd++;
- if (*pszEnd == '-')
- {
- psz = pszEnd + 1;
- portMax = strtol(psz, &pszEnd, 0);
- if (pszEnd == psz) portMax = 65535;
- if (portMin > portMax)
- {
- port = portMin;
- portMin = portMax;
- portMax = port;
- }
- }
- else portMax = portMin;
- if (portMax >= 1)
- {
- if (portMin <= 0) portMin = 1;
- for (port = portMin; port <= portMax; port++)
- {
- if (port > 65535) break;
-
- ++portnum;
-
- if (s == INVALID_SOCKET) continue;
- if ( !before && portnum <= *portn) continue;
- if (before && portnum >= *portn)
- {
- LeaveCriticalSection(&csNetlibUser);
- return false;
- }
-
- sin.sin_port = htons((WORD)port);
+ SOCKADDR_IN sin = {0};
+ sin.sin_family = AF_INET;
+
+ SOCKADDR_IN6 sin6 = {0};
+ sin6.sin6_family = AF_INET6;
+
+ mir_cslock lck(csNetlibUser);
+
+ if (--*portn < 0 && (s != INVALID_SOCKET || s6 != INVALID_SOCKET)) {
+ BindSocketToPort(szPorts, INVALID_SOCKET, INVALID_SOCKET, portn);
+ if (*portn == 0)
+ return false;
+
+ WORD num;
+ CallService(MS_UTILS_GETRANDOM, sizeof(WORD), (LPARAM)&num);
+ *portn = num % *portn;
+ }
+
+ bool before=false;
+ while (true) {
+ const char *psz;
+ char *pszEnd;
+ int portMin, portMax, port, portnum = 0;
+
+ for (psz=szPorts;*psz;) {
+ while (*psz == ' ' || *psz == ',') psz++;
+ portMin = strtol(psz, &pszEnd, 0);
+ if (pszEnd == psz)
+ break;
+ while (*pszEnd == ' ')
+ pszEnd++;
+ if (*pszEnd == '-') {
+ psz = pszEnd + 1;
+ portMax = strtol(psz, &pszEnd, 0);
+ if (pszEnd == psz) portMax = 65535;
+ if (portMin > portMax) {
+ port = portMin;
+ portMin = portMax;
+ portMax = port;
+ }
+ }
+ else portMax = portMin;
+ if (portMax >= 1) {
+ if (portMin <= 0) portMin = 1;
+ for (port = portMin; port <= portMax; port++) {
+ if (port > 65535)
+ break;
+
+ ++portnum;
+
+ if (s == INVALID_SOCKET) continue;
+ if ( !before && portnum <= *portn) continue;
+ if (before && portnum >= *portn)
+ return false;
+
+ sin.sin_port = htons((WORD)port);
bool bV4Mapped = s == INVALID_SOCKET || bind(s, (SOCKADDR*)&sin, sizeof(sin)) == 0;
sin6.sin6_port = htons((WORD)port);
bool bV6Mapped = s6 == INVALID_SOCKET || bind(s6, (PSOCKADDR)&sin6, sizeof(sin6)) == 0;
- if (bV4Mapped && bV6Mapped)
- {
- LeaveCriticalSection(&csNetlibUser);
- *portn = portnum + 1;
- return true;
- }
- }
- }
- psz = pszEnd;
- }
- if (*portn < 0)
- {
- *portn = portnum;
- LeaveCriticalSection(&csNetlibUser);
- return true;
- }
- else if (*portn >= portnum)
- *portn = 0;
- else
- before = true;
- }
+ if (bV4Mapped && bV6Mapped) {
+ *portn = portnum + 1;
+ return true;
+ }
+ }
+ }
+ psz = pszEnd;
+ }
+
+ if (*portn < 0) {
+ *portn = portnum;
+ return true;
+ }
+
+ if (*portn >= portnum)
+ *portn = 0;
+ else
+ before = true;
+ }
}
int NetlibFreeBoundPort(struct NetlibBoundPort *nlbp)
@@ -174,8 +163,9 @@ static unsigned __stdcall NetlibBindAcceptThread(void* param)
nlc->hOkToCloseEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
NetlibInitializeNestedCS(&nlc->ncsSend);
NetlibInitializeNestedCS(&nlc->ncsRecv);
-
- if (nlbp->pfnNewConnectionV2) nlbp->pfnNewConnectionV2(nlc, ntohl(sin.Ipv4.sin_addr.S_un.S_addr), nlbp->pExtra);
+
+ if (nlbp->pfnNewConnectionV2)
+ nlbp->pfnNewConnectionV2(nlc, ntohl(sin.Ipv4.sin_addr.S_un.S_addr), nlbp->pExtra);
}
NetlibUPnPDeletePortMapping(nlbp->wExPort, "TCP");
return 0;
@@ -204,7 +194,7 @@ INT_PTR NetlibBindPort(WPARAM wParam, LPARAM lParam)
nlbp->handleType = NLH_BOUNDPORT;
nlbp->nlu = nlu;
nlbp->pfnNewConnectionV2 = nlb->pfnNewConnectionV2;
-
+
nlbp->s = socket(PF_INET, SOCK_STREAM, 0);
nlbp->s6 = socket(PF_INET6, SOCK_STREAM, 0);
nlbp->pExtra = (nlb->cbSize != NETLIBBIND_SIZEOF_V1) ? nlb->pExtra : NULL;
diff --git a/src/modules/netlib/netlibhttp.cpp b/src/modules/netlib/netlibhttp.cpp
index 520f371917..7296b339bd 100644
--- a/src/modules/netlib/netlibhttp.cpp
+++ b/src/modules/netlib/netlibhttp.cpp
@@ -264,19 +264,16 @@ struct HttpSecurityContext
char* szAuthHdr = NULL;
bool justCreated = false;
- if (m_hNtlmSecurity)
- {
+ if (m_hNtlmSecurity) {
bool newAuth = !m_szProvider || !szProvider || _stricmp(m_szProvider, szProvider);
newAuth = newAuth || (m_szHost != szHost && ( !m_szHost || !szHost || _stricmp(m_szHost, szHost)));
if (newAuth)
Destroy();
}
- if (m_hNtlmSecurity == NULL)
- {
+ if (m_hNtlmSecurity == NULL) {
char szSpnStr[256] = "";
- if (szHost && _stricmp(szProvider, "Basic"))
- {
+ if (szHost && _stricmp(szProvider, "Basic")) {
unsigned long ip = inet_addr(szHost);
PHOSTENT host = (ip == INADDR_NONE) ? gethostbyname(szHost) : gethostbyaddr((char*)&ip, 4, AF_INET);
mir_snprintf(szSpnStr, SIZEOF(szSpnStr), "HTTP/%s", host && host->h_name ? host->h_name : szHost);
@@ -284,31 +281,26 @@ struct HttpSecurityContext
NetlibLogf(nlc->nlu, "Host SPN: %s", szSpnStr);
}
m_hNtlmSecurity = NetlibInitSecurityProvider(szProvider, szSpnStr[0] ? szSpnStr : NULL);
- if (m_hNtlmSecurity)
- {
+ if (m_hNtlmSecurity) {
m_szProvider = mir_strdup(szProvider);
m_szHost = mir_strdup(szHost);
justCreated = true;
}
}
- if (m_hNtlmSecurity)
- {
+ if (m_hNtlmSecurity) {
TCHAR *szLogin = NULL, *szPassw = NULL;
- if (nlc->nlu->settings.useProxyAuth)
- {
- EnterCriticalSection(&csNetlibUser);
+ if (nlc->nlu->settings.useProxyAuth) {
+ mir_cslock lck(csNetlibUser);
szLogin = mir_a2t(nlc->nlu->settings.szProxyAuthUser);
szPassw = mir_a2t(nlc->nlu->settings.szProxyAuthPassword);
- LeaveCriticalSection(&csNetlibUser);
}
szAuthHdr = NtlmCreateResponseFromChallenge(m_hNtlmSecurity,
szChallenge, szLogin, szPassw, true, complete);
- if ( !szAuthHdr)
- {
+ if ( !szAuthHdr) {
NetlibLogf(NULL, "Security login %s failed, user: " TCHAR_STR_PARAM " pssw: " TCHAR_STR_PARAM,
szProvider, szLogin ? szLogin : _T("(no user)"), szPassw ? _T("(exist)") : _T("(no psw)"));
}
@@ -318,8 +310,7 @@ struct HttpSecurityContext
mir_free(szLogin);
mir_free(szPassw);
}
- else
- complete = 1;
+ else complete = 1;
return szAuthHdr;
}
diff --git a/src/modules/netlib/netlibhttpproxy.cpp b/src/modules/netlib/netlibhttpproxy.cpp
index 2e0824d3bd..77a70a1dce 100644
--- a/src/modules/netlib/netlibhttpproxy.cpp
+++ b/src/modules/netlib/netlibhttpproxy.cpp
@@ -52,16 +52,14 @@ static int HttpGatewayReadSetResult(NetlibConnection *nlc, char *buf, int num, i
void HttpGatewayRemovePacket(NetlibConnection *nlc, int pck)
{
- EnterCriticalSection(&nlc->csHttpSequenceNums);
- while (pck-- && nlc->pHttpProxyPacketQueue != NULL)
- {
+ mir_cslock lck(nlc->csHttpSequenceNums);
+ while (pck-- && nlc->pHttpProxyPacketQueue != NULL) {
NetlibHTTPProxyPacketQueue *p = nlc->pHttpProxyPacketQueue;
nlc->pHttpProxyPacketQueue = nlc->pHttpProxyPacketQueue->next;
mir_free(p->dataBuffer);
mir_free(p);
}
- LeaveCriticalSection(&nlc->csHttpSequenceNums);
}
@@ -89,18 +87,14 @@ static bool NetlibHttpGatewaySend(struct NetlibConnection *nlc, RequestType reqT
case reqOldGet:
nlhrSend.requestType = REQUEST_GET;
nlhrSend.timeout = -1;
- if ((nlc->nlhpi.flags & NLHPIF_USEGETSEQUENCE) && (nlc->nlhpi.szHttpGetUrl != NULL))
- {
- EnterCriticalSection(&nlc->csHttpSequenceNums);
-
+ if ((nlc->nlhpi.flags & NLHPIF_USEGETSEQUENCE) && (nlc->nlhpi.szHttpGetUrl != NULL)) {
+ mir_cslock lck(nlc->csHttpSequenceNums);
mir_snprintf(szUrl, SIZEOF(szUrl), "%s%u", nlc->nlhpi.szHttpGetUrl, nlc->nlhpi.firstGetSequence++);
- if (nlc->nlhpi.flags & NLHPIF_GETPOSTSAMESEQUENCE) nlc->nlhpi.firstPostSequence++;
-
- LeaveCriticalSection(&nlc->csHttpSequenceNums);
+ if (nlc->nlhpi.flags & NLHPIF_GETPOSTSAMESEQUENCE)
+ nlc->nlhpi.firstPostSequence++;
nlhrSend.szUrl = szUrl;
}
- else
- nlhrSend.szUrl = nlc->nlhpi.szHttpGetUrl;
+ else nlhrSend.szUrl = nlc->nlhpi.szHttpGetUrl;
break;
case reqOldPost:
@@ -157,27 +151,26 @@ static bool NetlibHttpGatewaySend(struct NetlibConnection *nlc, RequestType reqT
static bool NetlibHttpGatewayStdPost(NetlibConnection *nlc, int& numPackets)
{
int np = 0, len = 0;
-
- EnterCriticalSection(&nlc->csHttpSequenceNums);
+ char *buf;
+ {
+ mir_cslock lck(nlc->csHttpSequenceNums);
- NetlibHTTPProxyPacketQueue *p = nlc->pHttpProxyPacketQueue;
- while (p != NULL && np < nlc->nlhpi.combinePackets) { ++np; len += p->dataBufferLen; p = p->next;}
+ NetlibHTTPProxyPacketQueue *p = nlc->pHttpProxyPacketQueue;
+ while (p != NULL && np < nlc->nlhpi.combinePackets) { ++np; len += p->dataBufferLen; p = p->next;}
- char *buf = (char*)alloca(len);
+ buf = (char*)alloca(len);
- numPackets = np;
- int dlen = 0;
-
- p = nlc->pHttpProxyPacketQueue;
- while (np--)
- {
- memcpy(buf + dlen, p->dataBuffer, p->dataBufferLen);
- dlen += p->dataBufferLen;
- p = p->next;
+ numPackets = np;
+ int dlen = 0;
+
+ p = nlc->pHttpProxyPacketQueue;
+ while (np--) {
+ memcpy(buf + dlen, p->dataBuffer, p->dataBufferLen);
+ dlen += p->dataBufferLen;
+ p = p->next;
+ }
}
- LeaveCriticalSection(&nlc->csHttpSequenceNums);
-
return NetlibHttpGatewaySend(nlc, reqNewPost, buf, len);
}
@@ -203,20 +196,16 @@ static bool NetlibHttpGatewayOscarPost(NetlibConnection *nlc, const char *buf, i
NetlibInitializeNestedCS(&nlcSend.ncsSend);
bool res = NetlibHttpGatewaySend(&nlcSend, reqOldPost, buf, len);
- if (res)
- {
+ if (res) {
NETLIBHTTPREQUEST *nlhrReply = NetlibHttpRecv(&nlcSend, flags | MSG_RAW | MSG_DUMPPROXY, MSG_RAW | MSG_DUMPPROXY);
- if (nlhrReply != NULL)
- {
- if (nlhrReply->resultCode != 200)
- {
+ if (nlhrReply != NULL) {
+ if (nlhrReply->resultCode != 200) {
NetlibHttpSetLastErrorUsingHttpResult(nlhrReply->resultCode);
res = false;
}
NetlibHttpFreeRequestStruct(0, (LPARAM)nlhrReply);
}
- else
- res = false;
+ else res = false;
}
NetlibDeleteNestedCS(&nlcSend.ncsSend);
@@ -226,24 +215,18 @@ static bool NetlibHttpGatewayOscarPost(NetlibConnection *nlc, const char *buf, i
nlc->s2 = nlcSend.s;
mir_free((char*)nlcSend.nloc.szHost);
- EnterCriticalSection(&nlc->csHttpSequenceNums);
-
+ mir_cslock lck(nlc->csHttpSequenceNums);
nlc->nlhpi.firstPostSequence++;
- if (nlc->nlhpi.flags & NLHPIF_GETPOSTSAMESEQUENCE) nlc->nlhpi.firstGetSequence++;
-
- LeaveCriticalSection(&nlc->csHttpSequenceNums);
+ if (nlc->nlhpi.flags & NLHPIF_GETPOSTSAMESEQUENCE)
+ nlc->nlhpi.firstGetSequence++;
return res;
}
int NetlibHttpGatewayPost(struct NetlibConnection *nlc, const char *buf, int len, int flags)
{
- struct NetlibHTTPProxyPacketQueue *p;
-
if (nlc->nlhpi.szHttpGetUrl != NULL)
- {
return NetlibHttpGatewayOscarPost(nlc, buf, len, flags) ? len : SOCKET_ERROR;
- }
/*
* Gena01 - many changes here, do compare against the other version.
@@ -256,7 +239,7 @@ static bool NetlibHttpGatewayOscarPost(NetlibConnection *nlc, const char *buf, i
* with the new plugins that use this code.
*/
- p = (NetlibHTTPProxyPacketQueue*)mir_alloc(sizeof(struct NetlibHTTPProxyPacketQueue));
+ NetlibHTTPProxyPacketQueue *p = (NetlibHTTPProxyPacketQueue*)mir_alloc(sizeof(struct NetlibHTTPProxyPacketQueue));
p->dataBuffer = (PBYTE)mir_alloc(len);
memcpy(p->dataBuffer, buf, len);
p->dataBufferLen = len;
@@ -265,19 +248,16 @@ static bool NetlibHttpGatewayOscarPost(NetlibConnection *nlc, const char *buf, i
/*
* Now check to see where to insert this in our queue
*/
- EnterCriticalSection(&nlc->csHttpSequenceNums);
+
+ mir_cslock lck(nlc->csHttpSequenceNums);
if (nlc->pHttpProxyPacketQueue == NULL)
- {
nlc->pHttpProxyPacketQueue = p;
- }
- else
- {
- struct NetlibHTTPProxyPacketQueue *t = nlc->pHttpProxyPacketQueue;
-
- while (t->next != NULL) t = t->next;
+ else {
+ NetlibHTTPProxyPacketQueue *t = nlc->pHttpProxyPacketQueue;
+ while (t->next != NULL)
+ t = t->next;
t->next = p;
}
- LeaveCriticalSection(&nlc->csHttpSequenceNums);
/*
* Gena01 - fake a Send!! tell 'em all is ok. We catch errors in Recv.
diff --git a/src/modules/netlib/netliblog.cpp b/src/modules/netlib/netliblog.cpp
index 5e312b9133..2e9f7a4365 100644
--- a/src/modules/netlib/netliblog.cpp
+++ b/src/modules/netlib/netliblog.cpp
@@ -210,7 +210,7 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa
DBWriteContactSettingTString(NULL, "Netlib", "RunAtStart", str);
DBWriteContactSettingByte(NULL, "Netlib", "ShowLogOptsAtStart", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_SHOWTHISDLGATSTART));
- EnterCriticalSection(&logOptions.cs);
+ mir_cslock lck(logOptions.cs);
mir_free(logOptions.szUserFile);
GetWindowText(GetDlgItem(hwndDlg, IDC_FILENAME), str, MAX_PATH);
@@ -230,8 +230,6 @@ static INT_PTR CALLBACK LogOptionsDlgProc(HWND hwndDlg, UINT message, WPARAM wPa
logOptions.showUser=IsDlgButtonChecked(hwndDlg, IDC_SHOWNAMES);
logOptions.toOutputDebugString=IsDlgButtonChecked(hwndDlg, IDC_TOOUTPUTDEBUGSTRING);
logOptions.toFile=IsDlgButtonChecked(hwndDlg, IDC_TOFILE);
-
- LeaveCriticalSection(&logOptions.cs);
}
{
HWND hwndFilter = GetDlgItem(logOptions.hwndOpts, IDC_FILTER);
@@ -369,32 +367,26 @@ static INT_PTR NetlibLog(WPARAM wParam, LPARAM lParam)
else
szHead[0]=0;
- if (logOptions.toOutputDebugString)
- {
+ if (logOptions.toOutputDebugString) {
if (szHead[0])
OutputDebugStringA(szHead);
OutputDebugStringA(pszMsg);
OutputDebugStringA("\n");
}
- if (logOptions.toFile && logOptions.szFile[0])
- {
- EnterCriticalSection(&logOptions.cs);
+ if (logOptions.toFile && logOptions.szFile[0]) {
+ mir_cslock lck(logOptions.cs);
- FILE *fp;
- fp = _tfopen(logOptions.szFile, _T("ab"));
- if ( !fp)
- {
+ FILE *fp = _tfopen(logOptions.szFile, _T("ab"));
+ if ( !fp) {
CreatePathToFileT(logOptions.szFile);
fp = _tfopen(logOptions.szFile, _T("at"));
}
- if (fp)
- {
+ if (fp) {
size_t len = strlen(pszMsg);
fprintf(fp, "%s%s%s", szHead, pszMsg, pszMsg[len-1] == '\n' ? "" : "\r\n");
fclose(fp);
}
- LeaveCriticalSection(&logOptions.cs);
}
LOGMSG logMsg = { szHead, pszMsg };
diff --git a/src/modules/netlib/netlibopenconn.cpp b/src/modules/netlib/netlibopenconn.cpp
index b96c27aa4d..15623461c6 100644
--- a/src/modules/netlib/netlibopenconn.cpp
+++ b/src/modules/netlib/netlibopenconn.cpp
@@ -868,12 +868,11 @@ INT_PTR NetlibOpenConnection(WPARAM wParam, LPARAM lParam)
}
if (iUPnPCleanup == 0) {
- EnterCriticalSection(&csNetlibUser);
+ mir_cslock lck(csNetlibUser);
if (iUPnPCleanup == 0) {
iUPnPCleanup = 1;
forkthread(NetlibUPnPCleanup, 0, NULL);
}
- LeaveCriticalSection(&csNetlibUser);
}
return (INT_PTR)nlc;
diff --git a/src/modules/netlib/netlibopts.cpp b/src/modules/netlib/netlibopts.cpp
index 34a07d6df7..a8dc2b77b0 100644
--- a/src/modules/netlib/netlibopts.cpp
+++ b/src/modules/netlib/netlibopts.cpp
@@ -123,7 +123,7 @@ static void CombineSettingsStructs(NETLIBUSERSETTINGS *dest, DWORD *destFlags, N
CombineSettingsStrings(&dest->szOutgoingPorts, &source->szOutgoingPorts);
}
else {
- dest->validateSSL=source->validateSSL;
+ dest->validateSSL=source->validateSSL;
dest->useProxy=source->useProxy;
dest->proxyType=source->proxyType;
dest->szProxyServer=source->szProxyServer;
@@ -160,13 +160,10 @@ static void CombineSettingsStructs(NETLIBUSERSETTINGS *dest, DWORD *destFlags, N
static void ChangeSettingIntByCheckbox(HWND hwndDlg, UINT ctrlId, int iUser, int memberOffset)
{
- int newValue, i;
-
- newValue=IsDlgButtonChecked(hwndDlg, ctrlId) != BST_CHECKED;
- CheckDlgButton(hwndDlg, ctrlId, newValue?BST_CHECKED:BST_UNCHECKED);
- if (iUser == -1)
- {
- for (i=0; i<tempSettings.getCount(); i++)
+ int newValue = IsDlgButtonChecked(hwndDlg, ctrlId) != BST_CHECKED;
+ CheckDlgButton(hwndDlg, ctrlId, newValue ? BST_CHECKED : BST_UNCHECKED);
+ if (iUser == -1) {
+ for (int i=0; i<tempSettings.getCount(); i++)
if ( !(tempSettings[i]->flags & NUF_NOOPTIONS))
*(int*)(((PBYTE)&tempSettings[i]->settings) + memberOffset) = newValue;
}
@@ -176,33 +173,28 @@ static void ChangeSettingIntByCheckbox(HWND hwndDlg, UINT ctrlId, int iUser, int
static void ChangeSettingStringByEdit(HWND hwndDlg, UINT ctrlId, int iUser, int memberOffset)
{
- int i, newValueLen;
- char *szNewValue, **ppszNew;
-
- newValueLen=GetWindowTextLength(GetDlgItem(hwndDlg, ctrlId));
- szNewValue=(char*)mir_alloc(newValueLen+1);
+ int newValueLen=GetWindowTextLength(GetDlgItem(hwndDlg, ctrlId));
+ char *szNewValue=(char*)mir_alloc(newValueLen+1);
GetDlgItemTextA(hwndDlg, ctrlId, szNewValue, newValueLen+1);
- if (iUser == -1)
- {
- for (i=0; i<tempSettings.getCount(); ++i)
- if ( !(tempSettings[i]->flags & NUF_NOOPTIONS))
- {
- ppszNew=(char**)(((PBYTE)&tempSettings[i]->settings)+memberOffset);
- if (*ppszNew) mir_free(*ppszNew);
- *ppszNew=mir_strdup(szNewValue);
+ if (iUser == -1) {
+ for (int i=0; i<tempSettings.getCount(); ++i)
+ if ( !(tempSettings[i]->flags & NUF_NOOPTIONS)) {
+ char **ppszNew=(char**)(((PBYTE)&tempSettings[i]->settings)+memberOffset);
+ mir_free(*ppszNew);
+ *ppszNew = mir_strdup(szNewValue);
}
mir_free(szNewValue);
}
else {
- ppszNew=(char**)(((PBYTE)&tempSettings[iUser]->settings)+memberOffset);
- if (*ppszNew) mir_free(*ppszNew);
- *ppszNew=szNewValue;
+ char **ppszNew=(char**)(((PBYTE)&tempSettings[iUser]->settings)+memberOffset);
+ mir_free(*ppszNew);
+ *ppszNew = szNewValue;
}
}
static void WriteSettingsStructToDb(const char *szSettingsModule, NETLIBUSERSETTINGS *settings, DWORD flags)
{
- if (flags&NUF_OUTGOING) {
+ if (flags & NUF_OUTGOING) {
char szEncodedPassword[512];
DBWriteContactSettingByte(NULL, szSettingsModule, "NLValidateSSL", (BYTE)settings->validateSSL);
DBWriteContactSettingByte(NULL, szSettingsModule, "NLUseProxy", (BYTE)settings->useProxy);
@@ -218,8 +210,8 @@ static void WriteSettingsStructToDb(const char *szSettingsModule, NETLIBUSERSETT
DBWriteContactSettingByte(NULL, szSettingsModule, "NLSpecifyOutgoingPorts", (BYTE)settings->specifyOutgoingPorts);
DBWriteContactSettingString(NULL, szSettingsModule, "NLOutgoingPorts", settings->szOutgoingPorts?settings->szOutgoingPorts:"");
}
- if (flags&NUF_INCOMING) {
- DBWriteContactSettingByte(NULL, szSettingsModule, "NLEnableUPnP", (BYTE)settings->enableUPnP);
+ if (flags & NUF_INCOMING) {
+ DBWriteContactSettingByte(NULL, szSettingsModule, "NLEnableUPnP", (BYTE)settings->enableUPnP);
DBWriteContactSettingByte(NULL, szSettingsModule, "NLSpecifyIncomingPorts", (BYTE)settings->specifyIncomingPorts);
DBWriteContactSettingString(NULL, szSettingsModule, "NLIncomingPorts", settings->szIncomingPorts?settings->szIncomingPorts:"");
}
@@ -227,91 +219,83 @@ static void WriteSettingsStructToDb(const char *szSettingsModule, NETLIBUSERSETT
void NetlibSaveUserSettingsStruct(const char *szSettingsModule, NETLIBUSERSETTINGS *settings)
{
- int i;
- NETLIBUSERSETTINGS combinedSettings={0};
- DWORD flags;
+ mir_cslock lck(csNetlibUser);
- EnterCriticalSection(&csNetlibUser);
-
- NetlibUser *thisUser, tUser;
+ NetlibUser tUser;
tUser.user.szSettingsModule = (char*)szSettingsModule;
- thisUser = netlibUser.find(&tUser);
-
+ NetlibUser *thisUser = netlibUser.find(&tUser);
if (thisUser == NULL)
- {
- LeaveCriticalSection(&csNetlibUser);
return;
- }
NetlibFreeUserSettingsStruct(&thisUser->settings);
CopySettingsStruct(&thisUser->settings, settings);
WriteSettingsStructToDb(thisUser->user.szSettingsModule, &thisUser->settings, thisUser->user.flags);
+
+ NETLIBUSERSETTINGS combinedSettings = {0};
combinedSettings.cbSize = sizeof(combinedSettings);
- for (i=0, flags=0; i < netlibUser.getCount(); ++i)
- {
- if (thisUser->user.flags & NUF_NOOPTIONS) continue;
+
+ DWORD flags = 0;
+ for (int i=0; i < netlibUser.getCount(); ++i) {
+ if (thisUser->user.flags & NUF_NOOPTIONS)
+ continue;
CombineSettingsStructs(&combinedSettings, &flags, &thisUser->settings, thisUser->user.flags);
}
- if (combinedSettings.validateSSL == 2) combinedSettings.validateSSL=0;
+ if (combinedSettings.validateSSL == 2) combinedSettings.validateSSL=0;
if (combinedSettings.useProxy == 2) combinedSettings.useProxy=0;
if (combinedSettings.proxyType == 0) combinedSettings.proxyType=PROXYTYPE_SOCKS5;
if (combinedSettings.useProxyAuth == 2) combinedSettings.useProxyAuth=0;
if (combinedSettings.dnsThroughProxy == 2) combinedSettings.dnsThroughProxy=1;
- if (combinedSettings.enableUPnP == 2) combinedSettings.enableUPnP=1;
+ if (combinedSettings.enableUPnP == 2) combinedSettings.enableUPnP=1;
if (combinedSettings.specifyIncomingPorts == 2) combinedSettings.specifyIncomingPorts=0;
WriteSettingsStructToDb("Netlib", &combinedSettings, flags);
NetlibFreeUserSettingsStruct(&combinedSettings);
- LeaveCriticalSection(&csNetlibUser);
}
static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
- {
- case WM_INITDIALOG:
- { int iUser, iItem;
+ int iUser;
- TranslateDialogDefault(hwndDlg);
- iItem=SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_ADDSTRING, 0, (LPARAM)TranslateT("<All connections>"));
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ {
+ int iItem = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_ADDSTRING, 0, (LPARAM)TranslateT("<All connections>"));
SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETITEMDATA, iItem, (LPARAM)-1);
SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETCURSEL, iItem, 0);
-
- EnterCriticalSection(&csNetlibUser);
- for (iUser = 0; iUser < netlibUser.getCount(); ++iUser)
{
- NetlibTempSettings *thisSettings = (NetlibTempSettings*)mir_calloc(sizeof(NetlibTempSettings));
- thisSettings->flags = netlibUser[iUser]->user.flags;
- thisSettings->szSettingsModule = mir_strdup(netlibUser[iUser]->user.szSettingsModule);
- CopySettingsStruct(&thisSettings->settings, &netlibUser[iUser]->settings);
- tempSettings.insert(thisSettings);
-
- if (netlibUser[iUser]->user.flags & NUF_NOOPTIONS) continue;
- iItem = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_ADDSTRING, 0,
- (LPARAM)netlibUser[iUser]->user.ptszDescriptiveName);
- SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETITEMDATA, iItem, iUser);
+ mir_cslock lck(csNetlibUser);
+ for (int iUser = 0; iUser < netlibUser.getCount(); ++iUser) {
+ NetlibTempSettings *thisSettings = (NetlibTempSettings*)mir_calloc(sizeof(NetlibTempSettings));
+ thisSettings->flags = netlibUser[iUser]->user.flags;
+ thisSettings->szSettingsModule = mir_strdup(netlibUser[iUser]->user.szSettingsModule);
+ CopySettingsStruct(&thisSettings->settings, &netlibUser[iUser]->settings);
+ tempSettings.insert(thisSettings);
+
+ if (netlibUser[iUser]->user.flags & NUF_NOOPTIONS)
+ continue;
+ iItem = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_ADDSTRING, 0, (LPARAM)netlibUser[iUser]->user.ptszDescriptiveName);
+ SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_SETITEMDATA, iItem, iUser);
+ }
}
- LeaveCriticalSection(&csNetlibUser);
-
- SendMessage(hwndDlg, M_REFRESHALL, 0, 0);
- return TRUE;
}
- case M_REFRESHALL:
- { int iUser=SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETCURSEL, 0, 0), 0);
+
+ SendMessage(hwndDlg, M_REFRESHALL, 0, 0);
+ return TRUE;
+
+ case M_REFRESHALL:
+ iUser = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETCURSEL, 0, 0), 0);
+ {
NETLIBUSERSETTINGS settings = {0};
- DWORD flags;
+ DWORD flags = 0;
- if (iUser == -1)
- {
- int i;
+ if (iUser == -1) {
settings.cbSize=sizeof(settings);
- for (i = 0, flags = 0; i < tempSettings.getCount(); ++i)
- {
+ for (int i = 0; i < tempSettings.getCount(); ++i) {
if (tempSettings[i]->flags & NUF_NOOPTIONS) continue;
CombineSettingsStructs(&settings, &flags, &tempSettings[i]->settings, tempSettings[i]->flags);
}
}
- else
- {
+ else {
NetlibFreeUserSettingsStruct(&settings);
CopySettingsStruct(&settings, &tempSettings[iUser]->settings);
flags = tempSettings[iUser]->flags;
@@ -346,44 +330,36 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam,
NetlibFreeUserSettingsStruct(&settings);
SendMessage(hwndDlg, M_REFRESHENABLING, 0, 0);
- break;
}
- case M_REFRESHENABLING:
- { int selectedProxyType;
- TCHAR str[80];
+ break;
- selectedProxyType=SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETCURSEL, 0, 0), 0);
+ case M_REFRESHENABLING:
+ {
+ int selectedProxyType = SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETCURSEL, 0, 0), 0);
+
+ TCHAR str[80];
mir_sntprintf(str, SIZEOF(str), TranslateT("(often %d)"), oftenProxyPorts[selectedProxyType]);
SetDlgItemText(hwndDlg, IDC_STOFTENPORT, str);
- if (IsDlgButtonChecked(hwndDlg, IDC_USEPROXY) != BST_UNCHECKED)
- {
+ if (IsDlgButtonChecked(hwndDlg, IDC_USEPROXY) != BST_UNCHECKED) {
int enableAuth = 0, enableUser = 0, enablePass = 0, enableServer = 1;
EnableMultipleControls(hwndDlg, useProxyControls, SIZEOF(useProxyControls), TRUE);
- if (selectedProxyType == 0)
- {
- int i;
- for (i = 0; i < tempSettings.getCount(); ++i)
- {
+ if (selectedProxyType == 0) {
+ for (int i = 0; i < tempSettings.getCount(); ++i) {
if ( !tempSettings[i]->settings.useProxy ||
tempSettings[i]->flags & NUF_NOOPTIONS || !(tempSettings[i]->flags & NUF_OUTGOING))
continue;
if (tempSettings[i]->settings.proxyType == PROXYTYPE_SOCKS4) enableUser=1;
- else
- {
- enableAuth=1;
+ else {
+ enableAuth = 1;
if (tempSettings[i]->settings.useProxyAuth)
- {
enableUser=enablePass=1;
- }
}
}
}
- else
- {
+ else {
if (selectedProxyType == PROXYTYPE_SOCKS4) enableUser=1;
- else
- {
+ else {
if (selectedProxyType == PROXYTYPE_IE) enableServer=0;
enableAuth=1;
if (IsDlgButtonChecked(hwndDlg, IDC_PROXYAUTH) != BST_UNCHECKED)
@@ -401,131 +377,123 @@ static INT_PTR CALLBACK DlgProcNetlibOpts(HWND hwndDlg, UINT msg, WPARAM wParam,
else EnableMultipleControls(hwndDlg, useProxyControls, SIZEOF(useProxyControls), FALSE);
EnableMultipleControls(hwndDlg, specifyPortsControls, SIZEOF(specifyPortsControls), IsDlgButtonChecked(hwndDlg, IDC_SPECIFYPORTS) != BST_UNCHECKED);
EnableMultipleControls(hwndDlg, specifyOPortsControls, SIZEOF(specifyOPortsControls), IsDlgButtonChecked(hwndDlg, IDC_SPECIFYPORTSO) != BST_UNCHECKED);
- break;
}
- case WM_COMMAND:
- { int iUser=SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETCURSEL, 0, 0), 0);
- switch(LOWORD(wParam))
- {
- case IDC_NETLIBUSERS:
- if (HIWORD(wParam) == CBN_SELCHANGE) SendMessage(hwndDlg, M_REFRESHALL, 0, 0);
- return 0;
-
- case IDC_LOGOPTIONS:
- NetlibLogShowOptions();
- return 0;
-
- case IDC_PROXYTYPE:
- if (HIWORD(wParam) != CBN_SELCHANGE) return 0;
- { int newValue, i;
- newValue = SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETCURSEL, 0, 0), 0);
- if (iUser == -1)
- {
- if (newValue == 0) return 0;
- for (i = 0; i < tempSettings.getCount(); ++i)
- {
- if (tempSettings[i]->flags & NUF_NOOPTIONS) continue;
- if (newValue == PROXYTYPE_HTTP && !(tempSettings[i]->flags & (NUF_HTTPCONNS|NUF_HTTPGATEWAY)))
- tempSettings[i]->settings.proxyType = PROXYTYPE_HTTPS;
- else if (newValue == PROXYTYPE_HTTPS && tempSettings[i]->flags & NUF_NOHTTPSOPTION)
- tempSettings[i]->settings.proxyType = PROXYTYPE_HTTP;
- else tempSettings[i]->settings.proxyType = newValue;
- }
- SendMessage(hwndDlg, M_REFRESHALL, 0, 0);
- }
- else
- {
- tempSettings[iUser]->settings.proxyType = newValue;
- SendMessage(hwndDlg, M_REFRESHENABLING, 0, 0);
- }
+ break;
+
+ case WM_COMMAND:
+ iUser = SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_NETLIBUSERS, CB_GETCURSEL, 0, 0), 0);
+ switch(LOWORD(wParam)) {
+ case IDC_NETLIBUSERS:
+ if (HIWORD(wParam) == CBN_SELCHANGE) SendMessage(hwndDlg, M_REFRESHALL, 0, 0);
+ return 0;
+
+ case IDC_LOGOPTIONS:
+ NetlibLogShowOptions();
+ return 0;
+
+ case IDC_PROXYTYPE:
+ if (HIWORD(wParam) != CBN_SELCHANGE) return 0;
+ {
+ int newValue = SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROXYTYPE, CB_GETCURSEL, 0, 0), 0);
+ if (iUser == -1) {
+ if (newValue == 0) return 0;
+ for (int i = 0; i < tempSettings.getCount(); ++i) {
+ if (tempSettings[i]->flags & NUF_NOOPTIONS) continue;
+ if (newValue == PROXYTYPE_HTTP && !(tempSettings[i]->flags & (NUF_HTTPCONNS|NUF_HTTPGATEWAY)))
+ tempSettings[i]->settings.proxyType = PROXYTYPE_HTTPS;
+ else if (newValue == PROXYTYPE_HTTPS && tempSettings[i]->flags & NUF_NOHTTPSOPTION)
+ tempSettings[i]->settings.proxyType = PROXYTYPE_HTTP;
+ else tempSettings[i]->settings.proxyType = newValue;
}
- break;
- case IDC_USEPROXY:
- ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, useProxy));
- break;
- case IDC_PROXYAUTH:
- ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, useProxyAuth));
- break;
- case IDC_PROXYDNS:
- ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, dnsThroughProxy));
- break;
- case IDC_SPECIFYPORTS:
- ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, specifyIncomingPorts));
- break;
- case IDC_SPECIFYPORTSO:
- ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, specifyOutgoingPorts));
- break;
- case IDC_ENABLEUPNP:
- ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, enableUPnP));
- break;
- case IDC_VALIDATESSL:
- ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, validateSSL));
- break;
- case IDC_PROXYHOST:
- if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
- ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyServer));
- break;
- case IDC_PROXYPORT:
- if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
- { int newValue, i;
- newValue=GetDlgItemInt(hwndDlg, LOWORD(wParam), NULL, FALSE);
- if (iUser == -1)
- {
- for (i = 0; i < tempSettings.getCount(); ++i)
- if ( !(tempSettings[i]->flags & NUF_NOOPTIONS))
- tempSettings[i]->settings.wProxyPort = newValue;
- }
- else tempSettings[iUser]->settings.wProxyPort = newValue;
- }
- break;
- case IDC_PROXYUSER:
- if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
- ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyAuthUser));
- break;
- case IDC_PROXYPASS:
- if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
- ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyAuthPassword));
- break;
- case IDC_PORTSRANGE:
- if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
- ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szIncomingPorts));
- break;
- case IDC_PORTSRANGEO:
- if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
- ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szOutgoingPorts));
- break;
+ SendMessage(hwndDlg, M_REFRESHALL, 0, 0);
+ }
+ else
+ {
+ tempSettings[iUser]->settings.proxyType = newValue;
+ SendMessage(hwndDlg, M_REFRESHENABLING, 0, 0);
+ }
}
- ShowWindow(GetDlgItem(hwndDlg, IDC_RECONNECTREQD), SW_SHOW);
- SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
break;
- }
- case WM_NOTIFY:
- switch(((LPNMHDR)lParam)->idFrom) {
- case 0:
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_APPLY:
- { int iUser;
- for (iUser = 0; iUser < tempSettings.getCount(); iUser++)
- NetlibSaveUserSettingsStruct(tempSettings[iUser]->szSettingsModule,
- &tempSettings[iUser]->settings);
- return TRUE;
- }
- }
- break;
+ case IDC_USEPROXY:
+ ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, useProxy));
+ break;
+ case IDC_PROXYAUTH:
+ ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, useProxyAuth));
+ break;
+ case IDC_PROXYDNS:
+ ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, dnsThroughProxy));
+ break;
+ case IDC_SPECIFYPORTS:
+ ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, specifyIncomingPorts));
+ break;
+ case IDC_SPECIFYPORTSO:
+ ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, specifyOutgoingPorts));
+ break;
+ case IDC_ENABLEUPNP:
+ ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, enableUPnP));
+ break;
+ case IDC_VALIDATESSL:
+ ChangeSettingIntByCheckbox(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, validateSSL));
+ break;
+ case IDC_PROXYHOST:
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
+ ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyServer));
+ break;
+ case IDC_PROXYPORT:
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
+ {
+ int newValue = GetDlgItemInt(hwndDlg, LOWORD(wParam), NULL, FALSE);
+ if (iUser == -1) {
+ for (int i = 0; i < tempSettings.getCount(); ++i)
+ if ( !(tempSettings[i]->flags & NUF_NOOPTIONS))
+ tempSettings[i]->settings.wProxyPort = newValue;
+ }
+ else tempSettings[iUser]->settings.wProxyPort = newValue;
}
break;
- case WM_DESTROY:
- { int iUser;
- for (iUser = 0; iUser < tempSettings.getCount(); ++iUser)
- {
- mir_free(tempSettings[iUser]->szSettingsModule);
- NetlibFreeUserSettingsStruct(&tempSettings[iUser]->settings);
- mir_free(tempSettings[iUser]);
+ case IDC_PROXYUSER:
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
+ ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyAuthUser));
+ break;
+ case IDC_PROXYPASS:
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
+ ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szProxyAuthPassword));
+ break;
+ case IDC_PORTSRANGE:
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
+ ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szIncomingPorts));
+ break;
+ case IDC_PORTSRANGEO:
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()) return 0;
+ ChangeSettingStringByEdit(hwndDlg, LOWORD(wParam), iUser, offsetof(NETLIBUSERSETTINGS, szOutgoingPorts));
+ break;
+ }
+ ShowWindow(GetDlgItem(hwndDlg, IDC_RECONNECTREQD), SW_SHOW);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_APPLY:
+ for (iUser = 0; iUser < tempSettings.getCount(); iUser++)
+ NetlibSaveUserSettingsStruct(tempSettings[iUser]->szSettingsModule,
+ &tempSettings[iUser]->settings);
+ return TRUE;
}
- tempSettings.destroy();
break;
}
+ break;
+
+ case WM_DESTROY:
+ for (iUser = 0; iUser < tempSettings.getCount(); ++iUser) {
+ mir_free(tempSettings[iUser]->szSettingsModule);
+ NetlibFreeUserSettingsStruct(&tempSettings[iUser]->settings);
+ mir_free(tempSettings[iUser]);
+ }
+ tempSettings.destroy();
+ break;
}
return FALSE;
}
@@ -534,11 +502,13 @@ static UINT expertOnlyControls[]={IDC_LOGOPTIONS};
int NetlibOptInitialise(WPARAM wParam, LPARAM)
{
int optionsCount = 0;
- EnterCriticalSection(&csNetlibUser);
- for (int i = 0; i < netlibUser.getCount(); ++i)
- if ( !(netlibUser[i]->user.flags & NUF_NOOPTIONS))
- ++optionsCount;
- LeaveCriticalSection(&csNetlibUser);
+ {
+ mir_cslock lck(csNetlibUser);
+ for (int i = 0; i < netlibUser.getCount(); ++i)
+ if ( !(netlibUser[i]->user.flags & NUF_NOOPTIONS))
+ ++optionsCount;
+ }
+
if (optionsCount == 0)
return 0;
diff --git a/src/modules/netlib/netlibupnp.cpp b/src/modules/netlib/netlibupnp.cpp
index 45009fa341..8bec975111 100644
--- a/src/modules/netlib/netlibupnp.cpp
+++ b/src/modules/netlib/netlibupnp.cpp
@@ -800,18 +800,16 @@ void NetlibUPnPCleanup(void*)
return;
{
- int i, incoming = 0;
- EnterCriticalSection(&csNetlibUser);
- for (i = 0; i < netlibUser.getCount(); ++i)
- {
- if (netlibUser[i]->user.flags & NUF_INCOMING)
- {
+ int incoming = 0;
+ mir_cslock lck(csNetlibUser);
+ for (int i = 0; i < netlibUser.getCount(); ++i)
+ if (netlibUser[i]->user.flags & NUF_INCOMING) {
incoming = 1;
break;
}
- }
- LeaveCriticalSection(&csNetlibUser);
- if ( !incoming) return;
+
+ if ( !incoming)
+ return;
}
if (findUPnPGateway())