-
Notifications
You must be signed in to change notification settings - Fork 2
/
ns.c
203 lines (185 loc) · 4.33 KB
/
ns.c
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
/*
* TwinSock - "Troy's Windows Sockets"
*
* Copyright (C) 1994 Troy Rollo <troy@cbme.unsw.EDU.AU>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the license in the file LICENSE.TXT included
* with the TwinSock distribution.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "twinsock.h"
extern HINSTANCE hinst;
#define RESOLV_DOMAIN 101
#define RESOLV_NS1 111
#define RESOLV_NS2 121
#define RESOLV_NS3 131
#define RESOLV_OVERRIDE 141
static void
SetNSItem( char *pchBuffer,
HWND hDlg,
int iItem)
{
char *pchDot;
int i;
for (i = 0; pchBuffer && i < 4; i++)
{
if (pchBuffer)
{
pchDot = strchr(pchBuffer, '.');
if (pchDot)
*pchDot++ = 0;
SetDlgItemText(hDlg, iItem + i, pchBuffer);
pchBuffer = pchDot;
}
}
}
static void
FillResolvDialog(HWND hDlg)
{
static char achBuffer[256];
GetTwinSockSetting("Resolver", "Domain", "", achBuffer, sizeof(achBuffer));
SetDlgItemText(hDlg, RESOLV_DOMAIN, achBuffer);
GetTwinSockSetting("Resolver", "Server1", "", achBuffer, sizeof(achBuffer));
SetNSItem(achBuffer, hDlg, RESOLV_NS1);
GetTwinSockSetting("Resolver", "Server2", "", achBuffer, sizeof(achBuffer));
SetNSItem(achBuffer, hDlg, RESOLV_NS2);
GetTwinSockSetting("Resolver", "Server3", "", achBuffer, sizeof(achBuffer));
SetNSItem(achBuffer, hDlg, RESOLV_NS3);
GetTwinSockSetting("Resolver", "Override", "0", achBuffer, sizeof(achBuffer));
SendDlgItemMessage(hDlg, RESOLV_OVERRIDE, BM_SETCHECK, (*achBuffer == '1'), 0);
}
static void
VerifyResolvOK(HWND hDlg)
{
int i, j;
int idCtl;
BOOL bOneEmpty = FALSE;
BOOL bOK = TRUE;
BOOL bOverride;
char *c;
int nValue;
static char achBuffer[256];
bOverride = SendDlgItemMessage(hDlg, RESOLV_OVERRIDE, BM_GETCHECK, 0, 0);
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
{
idCtl = RESOLV_NS1 + 10 * i + j;
GetDlgItemText(hDlg, idCtl, achBuffer, sizeof(achBuffer));
if (strlen(achBuffer) > 3)
bOK = FALSE;
for (c = achBuffer; *c; c++)
if (!isdigit(*c))
bOK = FALSE;
if (*achBuffer == 0)
{
if (j == 0)
bOneEmpty = TRUE;
else if (!bOneEmpty)
bOK = FALSE;
}
else if (bOneEmpty)
{
bOK = FALSE;
}
else
{
nValue = atoi(achBuffer);
if (nValue > 255)
bOK = FALSE;
}
}
if (!i && bOverride && bOneEmpty)
bOK = FALSE;
}
GetDlgItemText(hDlg, RESOLV_DOMAIN, achBuffer, sizeof(achBuffer));
if (bOverride && !*achBuffer)
bOK = FALSE;
EnableWindow(GetDlgItem(hDlg, IDOK), bOK);
}
static char *achResNames[3] =
{
"Server1", "Server2", "Server3"
};
static void
ReadResolvDialog(HWND hDlg)
{
int i, j;
int idCtl;
BOOL bOneEmpty = FALSE;
BOOL bOK = TRUE;
BOOL bOverride;
char *c;
int nValue;
static char achBuffer[256];
char achSmallBuf[20];
bOverride = SendDlgItemMessage(hDlg, RESOLV_OVERRIDE, BM_GETCHECK, 0, 0);
WritePrivateProfileString("Resolver", "Override", bOverride ? "1" : "0", "TWINSOCK.INI");
for (i = 0; i < 3; i++)
{
achBuffer[0] = 0;
for (j = 0; j < 4; j++)
{
idCtl = RESOLV_NS1 + 10 * i + j;
GetDlgItemText(hDlg, idCtl, achSmallBuf, sizeof(achSmallBuf));
if (*achSmallBuf)
{
if (j > 0)
strcat(achBuffer, ".");
strcat(achBuffer, achSmallBuf);
}
}
WritePrivateProfileString("Resolver", achResNames[i], achBuffer, "TWINSOCK.INI");
}
GetDlgItemText(hDlg, RESOLV_DOMAIN, achBuffer, sizeof(achBuffer));
WritePrivateProfileString("Resolver", "Domain", achBuffer, "TWINSOCK.INI");
}
#pragma argsused
BOOL CALLBACK
ResolvDlgProc( HWND hDlg,
UINT wMsg,
WPARAM wParam,
LPARAM lParam)
{
switch(wMsg)
{
case WM_INITDIALOG:
FillResolvDialog(hDlg);
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
ReadResolvDialog(hDlg);
EndDialog(hDlg, TRUE);
break;
case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
default:
VerifyResolvOK(hDlg);
break;
}
break;
}
return FALSE;
}
BOOL
ResolvEdit(HWND hwndParent)
{
FARPROC fpDlgProc;
BOOL bStatus;
fpDlgProc = MakeProcInstance((FARPROC) ResolvDlgProc, hinst);
bStatus = DialogBox(hinst, "NS_DLG", hwndParent, fpDlgProc);
FreeProcInstance(fpDlgProc);
return bStatus;
}