diff options
author | George Hazan <george.hazan@gmail.com> | 2012-07-02 22:30:27 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-07-02 22:30:27 +0000 |
commit | 980bcaff693a86971750d6e9ffc8ba1e561b8b3a (patch) | |
tree | d8a422e9ccd2357d6e28368447bee8cfcd26123a /src/modules/netlib | |
parent | 990f961261d92fccadb16b495171bb619c0183f0 (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/modules/netlib')
-rw-r--r-- | src/modules/netlib/netlib.cpp | 28 | ||||
-rw-r--r-- | src/modules/netlib/netlibbind.cpp | 168 | ||||
-rw-r--r-- | src/modules/netlib/netlibhttp.cpp | 27 | ||||
-rw-r--r-- | src/modules/netlib/netlibhttpproxy.cpp | 92 | ||||
-rw-r--r-- | src/modules/netlib/netliblog.cpp | 22 | ||||
-rw-r--r-- | src/modules/netlib/netlibopenconn.cpp | 3 | ||||
-rw-r--r-- | src/modules/netlib/netlibopts.cpp | 408 | ||||
-rw-r--r-- | src/modules/netlib/netlibupnp.cpp | 16 |
8 files changed, 341 insertions, 423 deletions
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())
|