Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / prefs / TCPPrefs / AROSTCPPrefs.h
blob0ae6a71232862e60e1f4f5c4c5c19bc3d85f6b85
1 #include <string.h>
2 #include <stdio.h>
3 #include <stdlib.h>
5 #ifdef __cplusplus
7 class Tokenizer
9 public:
10 char *tokenizerLine;
11 char *token;
12 FILE *tokenizedFile;
13 bool newline;
14 bool fend;
16 void openTokenFile(char * FileName)
18 tokenizedFile = fopen(FileName, "r");
19 token = NULL;
20 newline = true;
21 if (!tokenizedFile)
22 fend = true;
23 else{
24 tokenizerLine = new char[8192];
25 fend = false;
26 newline = true;
30 void closeTokenFile()
32 if (tokenizedFile) {
33 fclose(tokenizedFile);
34 delete tokenizerLine;
35 fend = true;
36 token = NULL;
40 void getNextToken(char* tk)
42 char *tstring;
44 newline = false;
45 if (token != NULL) {
46 token = strtok(NULL, tk);
47 if (!token)
48 getNextToken(tk);
49 }else {
50 newline = true;
51 if (!feof(tokenizedFile)) {
52 tokenizerLine[0] = 0;
53 fgets(tokenizerLine, 8192, tokenizedFile);
54 if (tokenizerLine == NULL) {
55 token = NULL;
56 getNextToken(tk);
57 }else
58 token = strtok(tokenizerLine, tk);
59 }else
60 fend = true;
65 extern "C"
67 class TCPPrefs
69 public:
70 char IP[1000];
71 char mask[1000];
72 char gate[1000];
73 char DNS[2][1000];
74 bool DHCP;
75 char interf[4096];
76 char host[1000];
77 char domain[1000];
78 char config[8192]; // arostcp/db path here
79 Tokenizer tok;
81 TCPPrefs()
83 strcpy(IP, "10.1.0.1");
84 strcpy(mask, "255.255.255.0");
85 strcpy(gate, "10.1.0.250");
86 strcpy(DNS[0], "10.1.0.251");
87 strcpy(DNS[1], "10.1.0.252");
88 strcpy(interf, "DEVS:networks/prm-rtl8029.device");
89 strcpy(host, "aros1");
90 strcpy(domain, "arosnet.com");
91 DHCP = false;
92 strcpy(config, "ENV:AROSTCP/db");
95 void readPrefs()
97 char *FileName;
98 char *temp;
99 bool comment = false;
100 //bool NewLine;
101 char *tstring;
103 temp = new char[30];
104 strcpy(temp, "ENV:AROSTCP/Config");
105 tok.openTokenFile(temp);
106 if (tok.tokenizedFile) {
107 tok.getNextToken(" \n");
108 strlcpy(config, tok.token,8191);
109 tok.closeTokenFile();
110 }else
111 strcpy(config, "ENV:AROSTCP/db");
113 FileName = new char[strlen(config) + 20];
115 sprintf(FileName, "%s/general.config", config);
116 tok.openTokenFile(FileName);
117 while (!tok.fend) {
118 if (tok.newline) { // read tokens from the beginning of line
119 if (tok.token) {
120 if (strcmp(tok.token, "HOSTNAME") == 0) {
121 tok.getNextToken("=\n");
122 tstring = strchr(tok.token, '.');
123 strlcpy(domain, tstring + 1,999);
124 tstring[0] = 0;
125 strlcpy(host, tok.token,999);
129 tok.getNextToken("=\n");
131 tok.closeTokenFile();
133 sprintf(FileName, "%s/interfaces", config);
134 tok.openTokenFile(FileName);
135 // reads only first uncommented interface
136 while (!tok.fend) {
137 tok.getNextToken(" \n");
138 if (tok.token) {
139 if (tok.newline) comment = false;
140 if (strncmp(tok.token, "#", 1) == 0) comment = true;
142 if (!comment) {
143 if (strncmp(tok.token, "DEV=", 4) == 0) {
144 tstring = strchr(tok.token, '=');
145 strlcpy(interf, tstring + 1,4095);
147 if (strncmp(tok.token, "IP=", 3) == 0) {
148 tstring = strchr(tok.token, '=');
149 strlcpy(IP, tstring + 1,999);
151 if (strncmp(tok.token, "MASK=", 5) == 0) {
152 tstring = strchr(tok.token, '=');
153 strlcpy(mask, tstring + 1,999);
158 tok.closeTokenFile();
160 sprintf(FileName, "%s/netdb-myhost", config);
161 tok.openTokenFile(FileName);
162 int dnsc = 0;
163 while (!tok.fend) {
164 tok.getNextToken(" \n");
165 if (tok.token) {
166 if (strncmp(tok.token, "NAMESERVER", 4) == 0) {
167 tok.getNextToken(" \n");
168 strlcpy(DNS[dnsc], tok.token,999);
169 dnsc++;
170 if (dnsc > 1) dnsc = 1;
174 tok.closeTokenFile();
176 sprintf(FileName, "%s/static-routes", config);
177 tok.openTokenFile(FileName);
178 while (!tok.fend) {
179 tok.getNextToken(" \n");
180 if (tok.token) {
181 if (strncmp(tok.token, "DEFAULT", 4) == 0) {
182 tok.getNextToken(" \n");
183 if (strncmp(tok.token, "GATEWAY", 4) == 0) {
184 tok.getNextToken(" \n");
185 strlcpy(gate, tok.token,999);
190 tok.closeTokenFile();
192 sprintf(FileName, "%s/DHCP", config);
193 tok.openTokenFile(FileName);
194 while (!tok.fend) {
195 tok.getNextToken(" \n");
196 if (tok.token) {
197 if (strncmp(tok.token, "True", 4) == 0) {
198 DHCP = true;
199 break;
201 else {
202 DHCP = false;
203 break;
208 tok.closeTokenFile();
210 delete FileName;
211 delete temp;
214 int writePrefs(char* dokad)
216 FILE *ConfFile;
217 char *FileName;
219 FileName = new char[strlen(dokad) + 20];
221 ConfFile = fopen("ENV:AROSTCP/Config", "w");
222 if (!ConfFile) return 0;
223 fprintf(ConfFile, "ENV:AROSTCP/db");
224 fclose(ConfFile);
226 ConfFile = fopen("ENVARC:AROSTCP/Config", "w");
227 if (ConfFile) {
228 fprintf(ConfFile, "ENV:AROSTCP/db");
229 fclose(ConfFile);
232 sprintf(FileName, "%s/DHCP", dokad);
233 ConfFile = fopen(FileName, "w");
234 if (!ConfFile) return 0;
235 fprintf(ConfFile, "%s\n", (DHCP) ? "True" : "False");
236 fclose(ConfFile);
238 sprintf(FileName, "%s/general.config", dokad);
239 ConfFile = fopen(FileName, "w");
240 if (!ConfFile) return 0;
241 fprintf(ConfFile, "USELOOPBACK=YES\n");
242 fprintf(ConfFile, "DEBUGSANA=NO\n");
243 fprintf(ConfFile, "USENS=SECOND\n");
244 fprintf(ConfFile, "GATEWAY=NO\n");
245 fprintf(ConfFile, "HOSTNAME=%s.%s\n", host, domain);
246 fprintf(ConfFile, "LOG FILTERFILE=5\n");
247 fprintf(ConfFile, "GUI PANEL=MUI\n");
248 fprintf(ConfFile, "OPENGUI=YES\n");
249 fclose(ConfFile);
251 sprintf(FileName, "%s/interfaces", dokad);
252 ConfFile = fopen(FileName, "w");
253 if (!ConfFile) return 0;
254 fprintf(ConfFile,"eth0 DEV=%s UNIT=0 NOTRACKING IP=%s NETMASK=%s UP\n",interf,IP,mask);
256 fclose(ConfFile);
258 sprintf(FileName, "%s/netdb-myhost", dokad);
259 ConfFile = fopen(FileName, "w");
260 if (!ConfFile) return 0;
261 fprintf(ConfFile, "HOST %s %s.%s %s\n", IP, host, domain, host);
262 fprintf(ConfFile, "HOST %s gateway\n", gate);
263 fprintf(ConfFile, "; Domain names\n");
264 // DOMAIN dupa.com.pl
265 //fprintf(ConfFile,"DOMAIN %d.%d.%d. %s\n",IP[0]&mask[0],IP[1]&mask[1],IP[2]&mask[2],domain);
266 //fprintf(ConfFile,"DOMAIN %d.%d.%d.%d %s\n",IP[0]&mask[0],IP[1]&mask[1],IP[2]&mask[2],IP[3]&mask[3],domain);
267 fprintf(ConfFile, "; Name servers\n");
268 fprintf(ConfFile, "NAMESERVER %s\n", DNS[0]);
269 fprintf(ConfFile, "NAMESERVER %s\n", DNS[1]);
270 fclose(ConfFile);
272 sprintf(FileName, "%s/static-routes", dokad);
273 ConfFile = fopen(FileName, "w");
274 if (!ConfFile) return 0;
275 fprintf(ConfFile, "DEFAULT GATEWAY %s\n", gate);
276 fclose(ConfFile);
278 delete FileName;
279 return 1;
285 #else
286 void ReadTCPPrefs();
287 int WriteTCPPrefs(char* DestDir);
289 char* GetIP();
290 char* GetMask();
291 char* GetGate();
292 char* GetDNS(int m);
293 int GetDHCP();
294 char* GetInterf();
295 char* GetHost();
296 char* GetDomain();
298 void SetIP(char * w);
299 void SetMask(char * w);
300 void SetGate(char * w);
301 void SetDNS(int m, char * w);
302 void SetDHCP(int w);
303 void SetInterf(char* w);
304 void SetHost(char* w);
305 void SetDomain(char* w);
307 #endif