1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "fidoconf/fidoconf.h"
6 #include "fidoconf/common.h"
7
writeArea(FILE * f,s_area * area,char netMail)8 static int writeArea(FILE *f, s_area *area, char netMail) {
9 switch (area->msgbType) {
10
11 case (MSGTYPE_SQUISH): fprintf(f, "NETSQUISH ");
12 break;
13
14 case (MSGTYPE_SDM): fprintf(f, "NETMAIL ");
15 break;
16
17 case (MSGTYPE_JAM): fprintf(f, "NETJAM ");
18 break;
19
20 default: return -1;
21 }
22
23 if (netMail != 1) return -1;
24
25 fprintf(f, "%s\n", area->fileName);
26
27 return 0;
28 }
29
fc_print_address(FILE * f,hs_addr * paddr)30 static void fc_print_address(FILE *f, hs_addr *paddr)
31 {
32 fprintf (f, "%u:%u/%u.%u", paddr->zone, paddr->net,
33 paddr->node, paddr->point);
34 if (paddr->domain != NULL && *(paddr->domain))
35 {
36 fprintf (f, "@%s", paddr->domain);
37 }
38 }
39
40 #define ALL id_route
41 #define RFILE id_routeFile
42 #define MAIL id_routeMail
43
44 #define ROUTE 0
45 #define DIRECT 3
46 #define BOSS 6
47 #define NOPACK 9
48
49 const char *commands[] = {
50 "ROUTE", "ROUTE-FILE", "ROUTE-MAIL",
51 "DIRECT-TO", "DIRECT-MAIL", "DIRECT-FILES",
52 "ROUTE-BOSS", "ROUTE-BOSS-MAIL", "ROUTE-BOSS-FILES",
53 "NOPACK", "NOPACK-MAIL", "NOPACK-FILES"
54 };
55
fc_convert_route(FILE * f,s_route * route,int what)56 static void fc_convert_route(FILE *f, s_route *route, int what)
57 {
58 int mode = ROUTE;
59 static s_route *lastroute = NULL;
60
61 if (lastroute == NULL || route->flavour != lastroute->flavour ||
62 (route->target == NULL && lastroute->target != NULL) ||
63 (route->target != NULL && lastroute->target == NULL) ||
64 (route->target != NULL && lastroute->target != NULL &&
65 addrComp((route->target->hisAka), (lastroute->target->hisAka))) ||
66 (route->target == NULL && lastroute->target == NULL &&
67 route->routeVia != lastroute->routeVia))
68 {
69 fprintf(f, "\n");
70 if (route->target == NULL)
71 {
72 switch (route->routeVia)
73 {
74 case route_zero:
75 case nopack:
76 mode = NOPACK;
77 break;
78
79 case noroute:
80 mode = DIRECT;
81 break;
82
83 case boss:
84 mode = BOSS;
85 break;
86
87 case host:
88 case hub:
89 case route_extern:
90 fprintf (stderr, "Host, Hub and External routing is not supported "
91 "by cfroute.\n");
92 abort();
93 }
94 }
95
96 fprintf(f, "%s ", commands[mode + what]);
97
98 if (route->flavour != normal)
99 {
100 switch (route->flavour)
101 {
102 case hold: fprintf(f, "HOLD "); break;
103 case crash: fprintf(f, "CRASH "); break;
104 case direct: fprintf(f, "DIRECT "); break;
105 case immediate: fprintf(f, "IMMEDIATE "); break;
106 default: fprintf(stderr, "unknwon flavour\n"); abort();
107 }
108 }
109
110 if (route->target != NULL)
111 {
112 fc_print_address(f, &(route->target->hisAka));
113 fprintf(f, " ");
114 }
115 }
116
117 fprintf(f, "%s ", route->pattern);
118
119 lastroute = route;
120 }
121
122 #define CVT_ROUTES 1
123 #define CVT_PASSWORDS 2
124 #define CVT_SETTINGS 4
125
generateCfrouteConfig(s_fidoconfig * config,const char * fileName,int what)126 int generateCfrouteConfig(s_fidoconfig *config, const char *fileName, int what)
127 {
128 FILE *f;
129 int i;
130 s_area *area;
131
132 f = fopen(fileName, "w");
133 if (f != NULL)
134 {
135 fprintf (f,";;CFROUTE configuration file automatically generated by fc2cfr");
136 if (what & CVT_ROUTES) fprintf(f," -r");
137 if (what & CVT_PASSWORDS) fprintf(f," -p");
138 if (what & CVT_SETTINGS) fprintf(f," -s");
139 fprintf(f,"\n");
140
141 if (what & CVT_SETTINGS)
142 {
143 fprintf (f,"EOLENDSCOMMAND ; end of line terminates any comments. This avoids ambiguities.\n");
144
145 fprintf (f,";VIABOSSHOLD\n");
146 fprintf (f,";VIABOSSDIRECT ; we do NOT set VIABOSSDIRECT to mimic hpt's behaviour, but I\n");
147 fprintf (f," ; strongly recommend that you DO set VIABOSSDIRECT. Please\n");
148 fprintf (f," ; do read the cfroute documentation.\n");
149 fprintf (f,"NODOMAINDIR ; hpt and fidoconfig do not support domain outbound.\n");
150 fprintf (f,";KILLINTRANSIT ; not necessary; hpt sets the K/S flag on intransit mail\n");
151
152 fprintf (f,"\n");
153
154 if (config->logFileDir != NULL)
155 fprintf (f,"LOG %scfroute.log\n", config->logFileDir);
156
157 if (config->outbound != NULL)
158 fprintf (f,"OUTBOUND %s\n", config->outbound);
159 fprintf (f," ; cfroute must know about all your inbound\n");
160 fprintf (f," ; directories in order to find file attaches.\n");
161 if (config->inbound != NULL)
162 fprintf(f, "INBOUND %s\n", config->inbound);
163 if (config->protInbound != NULL &&
164 config->protInbound != config->inbound)
165 fprintf(f, "INBOUND %s\n", config->protInbound);
166 if (config->listInbound != NULL &&
167 config->listInbound != config->inbound)
168 fprintf(f, "INBOUND %s\n", config->listInbound);
169 if (config->tempInbound != NULL &&
170 config->tempInbound != config->inbound)
171 fprintf(f, "INBOUND %s\n", config->tempInbound);
172 if (config->localInbound != NULL &&
173 config->localInbound != config->inbound)
174 fprintf(f, "INBOUND %s\n", config->localInbound);
175
176 if (config->outtab != NULL)
177 fprintf (f,"RECODE %s\n", config->outtab);
178 if (config->lockfile != NULL)
179 fprintf (f, "CHECKFILE %s\n", config->lockfile);
180
181 fprintf (f, "\n");
182
183 fprintf (f, "MAIN ");
184 fc_print_address(f,config->addr);
185 fprintf (f, "\n");
186
187 for (i=1; i<config->addrCount; i++)
188 {
189 fprintf(f, "AKA ");
190 fc_print_address(f,config->addr + i);
191 fprintf(f, "\n");
192 }
193
194 fprintf(f, "\n");
195
196 for (i=0; i<config->netMailAreaCount; i++) {
197 writeArea(f, &(config->netMailAreas[i]), 1);
198 }
199
200 fprintf (f, "\n");
201 }
202
203 if (what & CVT_PASSWORDS)
204 {
205 for (i=0; i<config->linkCount; i++)
206 {
207 if (config->links[i].pktPwd != NULL)
208 {
209 if (config->links[i].pktPwd[0] != 0)
210 {
211 fprintf(f, "PASSWORD %s ", config->links[i].pktPwd);
212 fc_print_address(f,&(config->links[i].hisAka));
213 fprintf(f, "\n");
214 }
215 }
216 else if (config->links[i].defaultPwd != NULL)
217 {
218 if (config->links[i].defaultPwd[0] != 0)
219 {
220 fprintf(f, "PASSWORD %s ", config->links[i].defaultPwd);
221 fc_print_address(f,&(config->links[i].hisAka));
222 fprintf(f, "\n");
223 }
224 }
225 }
226
227 fprintf (f, "\n");
228 }
229
230 if (what & CVT_ROUTES)
231 {
232 fprintf (f,"TOPDOWN ; the FIRST matching route is taken - this is the same logic\n");
233 fprintf (f," ; which hpt is using\n");
234
235 /* for (i = 0; i < config->routeFileCount; i++)
236 {
237 fc_convert_route(f, config->routeFile + i, RFILE);
238 }
239 for (i = 0; i < config->routeMailCount; i++)
240 {
241 fc_convert_route(f, config->routeMail + i, MAIL);
242 } */
243 for (i = 0; i < config->routeCount; i++)
244 {
245 fc_convert_route(f, config->route + i, config->route[i].id);
246 }
247
248 fprintf (f, "\n");
249 }
250
251 return 0;
252 } else printf("Could not write %s\n", fileName);
253
254 return 1;
255 }
256
main(int argc,char * argv[])257 int main (int argc, char *argv[])
258 {
259 s_fidoconfig *config;
260 int i;
261 const char *fn = NULL;
262 int usage = 0;
263 int what = 0;
264
265 printf("fconf2cfr\n");
266 printf("---------\n");
267
268 for (i = 1; (i < argc) && (!usage) ; i++)
269 {
270 if (argv[i][0]=='-')
271 {
272 switch(argv[i][1])
273 {
274 case 'r':
275 what |= CVT_ROUTES;
276 break;
277 case 'p':
278 what |= CVT_PASSWORDS;
279 break;
280 case 's':
281 what |= CVT_SETTINGS;
282 break;
283 default:
284 usage = 1;
285 break;
286 }
287 }
288 else
289 {
290 if (fn == NULL)
291 fn = argv[i];
292 else
293 usage = 1;
294 }
295 }
296
297
298 if (fn == NULL || usage)
299 {
300 printf("\nConverts a FIDOCONFIG file to a CFROUTE configuration file. Usage:\n");
301 printf(" fc2cfr [<flag> ...] <cfrouteConfigFileName>\n\n");
302 printf("The following values are allowable for <flag>:\n");
303 printf(" -r convert routing information\n");
304 printf(" -p convert packet passwords\n");
305 printf(" -s convert misc. other settings (like netmailarea etc.)\n");
306 printf("You can combine one or more flags; if you specify no flags at all,\n");
307 printf("everything will be converted.\n");
308 printf("\nExample:\n");
309 printf(" fc2cfr cfroute.cfg\n\n");
310 printf("The location of the fidoconfig file is taken from the FIDOCONFIG\n");
311 printf("environment variable.\n");
312 return 1;
313 }
314
315 if (what == 0) what = 0xFF;
316
317 printf("Generating Config-file %s\n", fn);
318
319 config = readConfig(NULL);
320 if (config!= NULL)
321 {
322 generateCfrouteConfig(config, fn, what);
323 disposeConfig(config);
324 return 0;
325 }
326
327 return 1;
328 }
329