summaryrefslogtreecommitdiff
path: root/plugins/ProxySwitch
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-06-24 18:00:48 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-06-24 18:00:48 +0300
commit6126ea3b146d8b8ed2b908528d473aa7c0b12b62 (patch)
treec6bf29490f9d71a8516bbb8d6e75962cfe62a42f /plugins/ProxySwitch
parent6979bd026c4a05f1ee75844edb4d01c90d5410b0 (diff)
homemade array removed
Diffstat (limited to 'plugins/ProxySwitch')
-rw-r--r--plugins/ProxySwitch/src/ip.cpp68
-rw-r--r--plugins/ProxySwitch/src/main.cpp7
-rw-r--r--plugins/ProxySwitch/src/proxy.cpp7
-rw-r--r--plugins/ProxySwitch/src/stdafx.h21
4 files changed, 39 insertions, 64 deletions
diff --git a/plugins/ProxySwitch/src/ip.cpp b/plugins/ProxySwitch/src/ip.cpp
index 8ed30c7664..3841ceb37f 100644
--- a/plugins/ProxySwitch/src/ip.cpp
+++ b/plugins/ProxySwitch/src/ip.cpp
@@ -11,7 +11,7 @@ wchar_t tempstr[MAX_SECONDLINE];
/* ################################################################################ */
-void IP_WatchDog(void *arg)
+void IP_WatchDog(void*)
{
OVERLAPPED overlap;
DWORD ret;
@@ -158,12 +158,10 @@ int Create_NIF_List(NETWORK_INTERFACE_LIST *list)
PIP_ADAPTER_INFO pAdapterInfo, pAdapt;
PIP_ADDR_STRING pAddrStr;
PIP_ADAPTER_ADDRESSES pAddresses, pAddr;
- PNETWORK_INTERFACE nif;
ULONG outBufLen;
wchar_t *tmp_opt, *intf, *rest, *name;
BOOL skip;
DWORD out;
- UCHAR idx;
// prepare and load IP_ADAPTER_ADDRESSES
outBufLen = 0;
@@ -212,7 +210,7 @@ int Create_NIF_List(NETWORK_INTERFACE_LIST *list)
// add a new interface into the list
list->count++;
list->item = (PNETWORK_INTERFACE)mir_realloc(list->item, list->count * sizeof(NETWORK_INTERFACE));
- nif = &(list->item[list->count - 1]);
+ PNETWORK_INTERFACE nif = &(list->item[list->count - 1]);
ZeroMemory(nif, sizeof(NETWORK_INTERFACE));
// copy AdapterName
@@ -272,7 +270,7 @@ int Create_NIF_List(NETWORK_INTERFACE_LIST *list)
while (pAddrStr) {
if (mir_strcmp("0.0.0.0", pAddrStr->IpAddress.String)) {
nif->IPcount++; // count IP addresses
- outBufLen += strlen(pAddrStr->IpAddress.String); // count length of IPstr
+ outBufLen += (ULONG)strlen(pAddrStr->IpAddress.String); // count length of IPstr
}
pAddrStr = pAddrStr->Next;
if (pAddrStr) outBufLen += 2; // count length of IPstr (add ", ")
@@ -304,11 +302,10 @@ int Create_NIF_List(NETWORK_INTERFACE_LIST *list)
mir_free(pAddresses);
mir_cslock lck(csConnection_List);
- for (idx = 0; idx < Connection_List.count; idx++) {
- nif = Find_NIF_IP(*list, Connection_List.item[idx].IP);
- if (nif) {
+ for (auto &it : g_arConnections) {
+ PNETWORK_INTERFACE nif = Find_NIF_IP(*list, it->IP);
+ if (nif)
nif->Bound = 1;
- }
}
return 0;
@@ -701,65 +698,44 @@ void Free_Range_List(IP_RANGE_LIST *list)
}
-int ManageConnections(WPARAM wParam, LPARAM lParam)
+int ManageConnections(WPARAM wParam, LPARAM)
{
NETLIBCONNECTIONEVENTINFO *info = (NETLIBCONNECTIONEVENTINFO *)wParam;
- int found;
- UCHAR i;
+ ACTIVE_CONNECTION *pFound = nullptr;
mir_cslock lck(csConnection_List);
- found = -1;
- for (i = 0; i < Connection_List.count; i++) {
- if (Connection_List.item[i].IP == info->local.sin_addr.s_addr && Connection_List.item[i].Port == info->local.sin_port) {
- found = i;
+ for (auto &it : g_arConnections)
+ if (it->IP == info->local.sin_addr.s_addr && it->Port == info->local.sin_port) {
+ pFound = it;
break;
}
- }
- if ((found >= 0 && info->connected) || (found == -1 && !info->connected)) {
+
+ if ((pFound && info->connected) || (!pFound && !info->connected))
return 0;
- }
- if (found >= 0) {
- Connection_List.count--;
- for (i = found; i < Connection_List.count; i++)
- memcpy(&(Connection_List.item[i]), &(Connection_List.item[i + 1]), sizeof(ACTIVE_CONNECTION));
- }
- else {
- if (Connection_List.count >= Connection_List._alloc) {
- Connection_List._alloc += 10;
- Connection_List.item = (PACTIVE_CONNECTION)mir_realloc(Connection_List.item, Connection_List._alloc * sizeof(ACTIVE_CONNECTION));
- }
- Connection_List.item[Connection_List.count].IP = info->local.sin_addr.s_addr;
- Connection_List.item[Connection_List.count].Port = info->local.sin_port;
- Connection_List.count++;
- }
- SetEvent(hEventRebound);
+ if (!pFound)
+ g_arConnections.insert(new ACTIVE_CONNECTION(info->local.sin_addr.s_addr, info->local.sin_port));
+ else
+ g_arConnections.remove(g_arConnections.indexOf(&pFound));
+ SetEvent(hEventRebound);
return 0;
}
void UnboundConnections(LONG *OldIP, LONG *NewIP)
{
- UCHAR i, j;
LONG *IP;
while (OldIP != NULL && *OldIP != 0) {
IP = NewIP;
while (IP != NULL && *IP != 0 && *IP != *OldIP)
IP++;
+
if (IP == NULL || *IP != *OldIP) {
mir_cslock lck(csConnection_List);
- i = 0;
- while (i < Connection_List.count) {
- if (Connection_List.item[i].IP == (ULONG)*OldIP) {
- Connection_List.count--;
- for (j = i; j < Connection_List.count; j++)
- memcpy(&(Connection_List.item[j]), &(Connection_List.item[j + 1]), sizeof(ACTIVE_CONNECTION));
- }
- else {
- i++;
- }
- }
+ for (auto &it : g_arConnections.rev_iter())
+ if (it->IP == (ULONG)*OldIP)
+ g_arConnections.remove(g_arConnections.indexOf(&it));
}
OldIP++;
}
diff --git a/plugins/ProxySwitch/src/main.cpp b/plugins/ProxySwitch/src/main.cpp
index b83d2588a6..5721bfc1b2 100644
--- a/plugins/ProxySwitch/src/main.cpp
+++ b/plugins/ProxySwitch/src/main.cpp
@@ -29,10 +29,12 @@ CMPlugin::CMPlugin() :
HGENMENU hEnableDisablePopupMenu = 0;
+OBJLIST<ACTIVE_CONNECTION> g_arConnections(10, PtrKeySortT);
+mir_cs csConnection_List;
+
NETWORK_INTERFACE_LIST NIF_List;
mir_cs csNIF_List;
-ACTIVE_CONNECTION_LIST Connection_List;
-mir_cs csConnection_List;
+
HANDLE hEventRebound = NULL;
wchar_t opt_useProxy[MAX_IPLIST_LENGTH];
@@ -251,7 +253,6 @@ int CMPlugin::Load()
LoadSettings();
- ZeroMemory(&Connection_List, sizeof(Connection_List));
Create_NIF_List_Ex(&NIF_List);
if (opt_ie || opt_miranda || opt_firefox) {
diff --git a/plugins/ProxySwitch/src/proxy.cpp b/plugins/ProxySwitch/src/proxy.cpp
index 5ab1c50dfb..bed73e9fb6 100644
--- a/plugins/ProxySwitch/src/proxy.cpp
+++ b/plugins/ProxySwitch/src/proxy.cpp
@@ -28,7 +28,7 @@ int Enum_Settings(const char *szSetting, LPARAM lParam)
return 0;
}
-int Enum_Modules(const char *szModuleName, DWORD ofsModuleName, LPARAM lParam)
+int Enum_Modules(const char *szModuleName, DWORD, LPARAM lParam)
{
//DBCONTACTENUMSETTINGS e;
MCONTACT hContact = NULL;
@@ -286,9 +286,8 @@ char Firefox_Installed(void)
if (SHGetSpecialFolderPath(NULL, path, CSIDL_APPDATA, 0)) {
mir_wstrcat(path, L"\\Mozilla\\Firefox\\Profiles");
- if (_wstat(path, &info) == 0 && info.st_mode & _S_IFDIR == _S_IFDIR) {
+ if (_wstat(path, &info) == 0 && (info.st_mode & _S_IFDIR) == _S_IFDIR)
return 1;
- }
}
return 0;
}
@@ -297,7 +296,7 @@ char Firefox_Installed(void)
void Disconnect_All_Protocols(PPROTO_SETTINGS settings, int disconnect)
{
- int count, c, i, status;
+ int count = 0, c, i, status;
PROTOCOLDESCRIPTOR **plist;
Proto_EnumProtocols(&c, &plist);
diff --git a/plugins/ProxySwitch/src/stdafx.h b/plugins/ProxySwitch/src/stdafx.h
index 59ccea28cd..8e0de00058 100644
--- a/plugins/ProxySwitch/src/stdafx.h
+++ b/plugins/ProxySwitch/src/stdafx.h
@@ -68,23 +68,22 @@ typedef struct {
} NETWORK_INTERFACE_LIST;
// structure holding an information about local end of an active connections
-typedef struct {
- ULONG IP;
- unsigned short Port;
-} ACTIVE_CONNECTION, *PACTIVE_CONNECTION;
+struct ACTIVE_CONNECTION
+{
+ ACTIVE_CONNECTION(ULONG _ip, unsigned short _port) :
+ IP(_ip),
+ Port(_port)
+ {}
-// list of structures holding local end of active connections
-typedef struct {
- PACTIVE_CONNECTION item;
- UCHAR count;
- UCHAR _alloc;
-} ACTIVE_CONNECTION_LIST;
+ ULONG IP;
+ unsigned short Port;
+};
+extern OBJLIST<ACTIVE_CONNECTION> g_arConnections;
/**** Global variables *********************************************************************/
extern NETWORK_INTERFACE_LIST NIF_List;
-extern ACTIVE_CONNECTION_LIST Connection_List;
extern mir_cs csNIF_List;
extern mir_cs csConnection_List;
extern HANDLE hEventRebound;