summaryrefslogtreecommitdiff
path: root/plugins/ProxySwitch/src/stdafx.h
blob: f9044260f360912f7260a372340a90c3008fed9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#ifndef proxySwitch_h
#define proxySwitch_h

#include <winsock2.h>
#include <windows.h>
#include <iprtrmib.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <commctrl.h>
#include <Wininet.h>
#include <shlobj.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <malloc.h>

#include "newpluginapi.h"
#include "m_system.h"
#include "m_options.h"
#include "m_clist.h"
#include "m_skin.h"
#include "m_langpack.h"
#include "m_popup.h"
#include "m_database.h"
#include "m_netlib.h"
#include "m_utils.h"
#include "m_protocols.h"
#include "m_protosvc.h"

#include <m_proxySwitch.h>

#include "resource.h"
#include "version.h"

#define MODULENAME "ProxySwitch"

struct CMPlugin : public PLUGIN<CMPlugin>
{
	CMPlugin();

	int Load() override;
	int Unload() override;
};

#define NVL(x) x == NULL ? "" : x
#define NVLW(x) x == NULL ? L"" : x

#define MAX_IPLIST_LENGTH 500

/**** Types ********************************************************************************/

// structure holding network interface description and information
struct NETWORK_INTERFACE : public MZeroedObject
{
	~NETWORK_INTERFACE()
	{
		mir_free(IP);
	}

	ptrA  AdapterName;
	ptrW  FriendlyName;
	ptrA  IPstr;
	LONG *IP;
	UCHAR IPcount;
	HGENMENU MenuItem;
	bool  Bound, Disabled;
};

typedef OBJLIST<NETWORK_INTERFACE> NETWORK_INTERFACE_LIST;

extern NETWORK_INTERFACE_LIST g_arNIF;
extern mir_cs csNIF_List;

// structure holding an information about local end of an active connections
struct ACTIVE_CONNECTION
{
	ACTIVE_CONNECTION(ULONG _ip, unsigned short _port) :
		IP(_ip),
		Port(_port)
	{}

	ULONG IP;
	unsigned short Port;
};

extern OBJLIST<ACTIVE_CONNECTION> g_arConnections;
extern mir_cs csConnection_List;

/**** Global variables *********************************************************************/

extern HANDLE hEventRebound;

/**** Options ******************************************************************************/

extern wchar_t opt_useProxy[MAX_IPLIST_LENGTH];
extern wchar_t opt_noProxy[MAX_IPLIST_LENGTH];
extern wchar_t opt_hideIntf[MAX_IPLIST_LENGTH];
extern UINT opt_defaultColors;
extern UINT opt_popups;
extern UINT opt_showProxyState;
extern UINT opt_miranda;
extern UINT opt_ie;
extern UINT opt_firefox;
extern UINT opt_alwayReconnect;
extern UINT opt_startup;
extern UINT opt_not_restarted;
extern COLORREF opt_bgColor;
extern COLORREF opt_txtColor;

void LoadSettings(void);
void SaveSettings(void);

/**** Service & Event handlers *************************************************************/

void PopupMyIPAddrs(const wchar_t *msg);

int OptInit(WPARAM wParam, LPARAM lParam);
int Init(WPARAM wParam, LPARAM lParam);
void UpdateInterfacesMenu(void);
void UpdatePopupMenu(BOOL State);

/**** Network ******************************************************************************/

#define NETORDER(a) ((((a) & 0xFFL)<<24) | (((a) & 0xFF00L)<<8) | (((a) & 0xFF0000L)>>8) | (((a) & 0xFF000000L)>>24))

#define INCUPD_INTACT     0
#define INCUPD_CONN_BIND  1
#define INCUPD_UPDATED    2
#define INCUPD_CONN_LOST  3
#define INCUPD(x, y) x = (x) > (y) ? (x) : (y)

#define DIGITS L"0123456789"
#define CMP_SKIP 0
#define CMP_MASK 1
#define CMP_SPAN 2
#define CMP_END  3

typedef struct {
	unsigned char cmpType;
	union { ULONG loIP; ULONG net; };
	union { ULONG hiIP; ULONG mask; };
} IP_RANGE, *PIP_RANGE;

typedef struct {
	PIP_RANGE item;
	UCHAR count;
} IP_RANGE_LIST;

void IP_WatchDog(void *arg);

int Create_NIF_List(NETWORK_INTERFACE_LIST *list);
int Create_NIF_List_Ex(NETWORK_INTERFACE_LIST *list);
int IncUpdate_NIF_List(NETWORK_INTERFACE_LIST *trg, NETWORK_INTERFACE_LIST &src);
wchar_t *Print_NIF_List(NETWORK_INTERFACE_LIST &list, const wchar_t *msg);
wchar_t *Print_NIF(NETWORK_INTERFACE *nif);

int Create_Range_List(IP_RANGE_LIST *list, wchar_t *str, BOOL prioritized);
int Match_Range_List(IP_RANGE_LIST range, NETWORK_INTERFACE_LIST &ip);
void Free_Range_List(IP_RANGE_LIST *list);

int ManageConnections(WPARAM wParam, LPARAM lParam);
void UnboundConnections(LONG *OldIP, LONG *NewIP);

/**** Proxy/Connection Modification and Query routines *************************************/

#define MAXLABELLENGTH 64

#define PROXY_NO_CONFIG -2
#define PROXY_MIXED     -1
#define PROXY_DISABLED   0
#define PROXY_ENABLED    1

typedef struct {
	char ModuleName[MAXLABELLENGTH];
	char SettingName[MAXLABELLENGTH];
} PROXY_SETTING, *PPROXY_SETTING;

typedef struct {
	PPROXY_SETTING item;
	UCHAR count;
	const char *_current_module;
	UCHAR _alloc;
} PROXY_SETTINGS, *PPROXY_SETTINGS;

typedef struct {
	char ProtoName[MAXLABELLENGTH];
	DWORD Status;
} PROTO_SETTING, *PPROTO_SETTING;

typedef struct {
	PPROTO_SETTING item;
	UCHAR count;
} PROTO_SETTINGS, *PPROTO_SETTINGS;

void Create_Proxy_Settings_List(PPROXY_SETTINGS ps);
void Free_Proxy_Settings_List(PPROXY_SETTINGS ps);
char Get_Miranda_Proxy_Status(void);
void Set_Miranda_Proxy_Status(char proxy);
char Get_IE_Proxy_Status(void);
void Set_IE_Proxy_Status(char proxy);
char Get_Firefox_Proxy_Status(void);
void Set_Firefox_Proxy_Status(char proxy);
char Firefox_Installed(void);
void Disconnect_All_Protocols(PPROTO_SETTINGS settings, int disconnect);
void Connect_All_Protocols(PPROTO_SETTINGS settings);
#endif