|
|
1.1 root 1: /* scfglib2.c */
2:
3: /* Synchronet configuration library routines */
4:
1.1.1.2 ! root 5: /* $Id: scfglib2.c,v 1.42 2009/02/16 07:13:20 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
1.1.1.2 ! root 11: * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39: #include "scfglib.h"
40:
41: /****************************************************************************/
1.1.1.2 ! root 42: /* Reads in FILE.CNF and initializes the associated variables */
1.1 root 43: /****************************************************************************/
44: BOOL read_file_cfg(scfg_t* cfg, char* error)
45: {
46: char str[MAX_PATH+1],fname[13],c,cmd[LEN_CMD+1];
1.1.1.2 ! root 47: short i,j;
! 48: int16_t n;
! 49: long offset=0;
! 50: int32_t t;
1.1 root 51: FILE *instream;
52:
53: strcpy(fname,"file.cnf");
54: sprintf(str,"%s%s",cfg->ctrl_dir,fname);
55: if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
56: sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
57: return(FALSE);
58: }
59:
60: get_int(cfg->min_dspace,instream);
61: get_int(cfg->max_batup,instream);
62:
63: get_int(cfg->max_batdn,instream);
64:
65: get_int(cfg->max_userxfer,instream);
66:
67: get_int(t,instream); /* unused - was cdt_byte_value */
68: get_int(cfg->cdt_up_pct,instream);
69: get_int(cfg->cdt_dn_pct,instream);
70: get_int(t,instream); /* unused - was temp_ext */
71: get_str(cmd,instream); /* unused - was temp_cmd */
72: get_int(cfg->leech_pct,instream);
73: get_int(cfg->leech_sec,instream);
74: get_int(cfg->file_misc,instream);
75:
76: for(i=0;i<30;i++)
77: get_int(n,instream);
78:
79: /**************************/
80: /* Extractable File Types */
81: /**************************/
82:
83: get_int(cfg->total_fextrs,instream);
84:
85: if(cfg->total_fextrs) {
86: if((cfg->fextr=(fextr_t **)malloc(sizeof(fextr_t *)*cfg->total_fextrs))==NULL)
87: return allocerr(instream,error,offset,fname,sizeof(fextr_t*)*cfg->total_fextrs);
88: } else
89: cfg->fextr=NULL;
90:
91: for(i=0; i<cfg->total_fextrs; i++) {
92: if(feof(instream))
93: break;
94: if((cfg->fextr[i]=(fextr_t *)malloc(sizeof(fextr_t)))==NULL)
95: return allocerr(instream,error,offset,fname,sizeof(fextr_t));
96: memset(cfg->fextr[i],0,sizeof(fextr_t));
97: get_str(cfg->fextr[i]->ext,instream);
98: get_str(cfg->fextr[i]->cmd,instream);
99: get_str(cfg->fextr[i]->arstr,instream);
100: cfg->fextr[i]->ar=ARSTR(cfg->fextr[i]->arstr,cfg);
101:
102: for(j=0;j<8;j++)
103: get_int(n,instream);
104: }
105: cfg->total_fextrs=i;
106:
107: /***************************/
108: /* Compressable File Types */
109: /***************************/
110:
111: get_int(cfg->total_fcomps,instream);
112:
113: if(cfg->total_fcomps) {
114: if((cfg->fcomp=(fcomp_t **)malloc(sizeof(fcomp_t *)*cfg->total_fcomps))==NULL)
115: return allocerr(instream,error,offset,fname,sizeof(fcomp_t*)*cfg->total_fcomps);
116: } else
117: cfg->fcomp=NULL;
118:
119: for(i=0; i<cfg->total_fcomps; i++) {
120: if(feof(instream))
121: break;
122: if((cfg->fcomp[i]=(fcomp_t *)malloc(sizeof(fcomp_t)))==NULL)
123: return allocerr(instream,error,offset,fname,sizeof(fcomp_t));
124: memset(cfg->fcomp[i],0,sizeof(fcomp_t));
125: get_str(cfg->fcomp[i]->ext,instream);
126: get_str(cfg->fcomp[i]->cmd,instream);
127: get_str(cfg->fcomp[i]->arstr,instream);
128: cfg->fcomp[i]->ar=ARSTR(cfg->fcomp[i]->arstr,cfg);
129:
130: for(j=0;j<8;j++)
131: get_int(n,instream);
132: }
133: cfg->total_fcomps=i;
134:
135: /***********************/
136: /* Viewable File Types */
137: /***********************/
138:
139: get_int(cfg->total_fviews,instream);
140:
141: if(cfg->total_fviews) {
142: if((cfg->fview=(fview_t **)malloc(sizeof(fview_t *)*cfg->total_fviews))==NULL)
143: return allocerr(instream,error,offset,fname,sizeof(fview_t*)*cfg->total_fviews);
144: } else
145: cfg->fview=NULL;
146:
147: for(i=0; i<cfg->total_fviews; i++) {
148: if(feof(instream)) break;
149: if((cfg->fview[i]=(fview_t *)malloc(sizeof(fview_t)))==NULL)
150: return allocerr(instream,error,offset,fname,sizeof(fview_t));
151: memset(cfg->fview[i],0,sizeof(fview_t));
152: get_str(cfg->fview[i]->ext,instream);
153: get_str(cfg->fview[i]->cmd,instream);
154: get_str(cfg->fview[i]->arstr,instream);
155: cfg->fview[i]->ar=ARSTR(cfg->fview[i]->arstr,cfg);
156:
157: for(j=0;j<8;j++)
158: get_int(n,instream);
159: }
160: cfg->total_fviews=i;
161:
162: /***********************/
163: /* Testable File Types */
164: /***********************/
165:
166: get_int(cfg->total_ftests,instream);
167:
168: if(cfg->total_ftests) {
169: if((cfg->ftest=(ftest_t **)malloc(sizeof(ftest_t *)*cfg->total_ftests))==NULL)
170: return allocerr(instream,error,offset,fname,sizeof(ftest_t*)*cfg->total_ftests);
171: } else
172: cfg->ftest=NULL;
173:
174: for(i=0; i<cfg->total_ftests; i++) {
175: if(feof(instream)) break;
176: if((cfg->ftest[i]=(ftest_t *)malloc(sizeof(ftest_t)))==NULL)
177: return allocerr(instream,error,offset,fname,sizeof(ftest_t));
178: memset(cfg->ftest[i],0,sizeof(ftest_t));
179: get_str(cfg->ftest[i]->ext,instream);
180: get_str(cfg->ftest[i]->cmd,instream);
181: get_str(cfg->ftest[i]->workstr,instream);
182: get_str(cfg->ftest[i]->arstr,instream);
183: cfg->ftest[i]->ar=ARSTR(cfg->ftest[i]->arstr,cfg);
184:
185: for(j=0;j<8;j++)
186: get_int(n,instream);
187: }
188: cfg->total_ftests=i;
189:
190: /*******************/
191: /* Download events */
192: /*******************/
193:
194: get_int(cfg->total_dlevents,instream);
195:
196: if(cfg->total_dlevents) {
197: if((cfg->dlevent=(dlevent_t **)malloc(sizeof(dlevent_t *)*cfg->total_dlevents))
198: ==NULL)
199: return allocerr(instream,error,offset,fname,sizeof(dlevent_t*)*cfg->total_dlevents);
200: } else
201: cfg->dlevent=NULL;
202:
203: for(i=0; i<cfg->total_dlevents; i++) {
204: if(feof(instream)) break;
205: if((cfg->dlevent[i]=(dlevent_t *)malloc(sizeof(dlevent_t)))==NULL)
206: return allocerr(instream,error,offset,fname,sizeof(dlevent_t));
207: memset(cfg->dlevent[i],0,sizeof(dlevent_t));
208: get_str(cfg->dlevent[i]->ext,instream);
209: get_str(cfg->dlevent[i]->cmd,instream);
210: get_str(cfg->dlevent[i]->workstr,instream);
211: get_str(cfg->dlevent[i]->arstr,instream);
212: cfg->dlevent[i]->ar=ARSTR(cfg->dlevent[i]->arstr,cfg);
213:
214: for(j=0;j<8;j++)
215: get_int(n,instream);
216: }
217: cfg->total_dlevents=i;
218:
219:
220: /***************************/
221: /* File Transfer Protocols */
222: /***************************/
223:
224: get_int(cfg->total_prots,instream);
225:
226: if(cfg->total_prots) {
227: if((cfg->prot=(prot_t **)malloc(sizeof(prot_t *)*cfg->total_prots))==NULL)
228: return allocerr(instream,error,offset,fname,sizeof(prot_t*)*cfg->total_prots);
229: } else
230: cfg->prot=NULL;
231:
232: for(i=0;i<cfg->total_prots;i++) {
233: if(feof(instream)) break;
234: if((cfg->prot[i]=(prot_t *)malloc(sizeof(prot_t)))==NULL)
235: return allocerr(instream,error,offset,fname,sizeof(prot_t));
236: memset(cfg->prot[i],0,sizeof(prot_t));
237:
238: get_int(cfg->prot[i]->mnemonic,instream);
239: get_str(cfg->prot[i]->name,instream);
240: get_str(cfg->prot[i]->ulcmd,instream);
241: get_str(cfg->prot[i]->dlcmd,instream);
242: get_str(cfg->prot[i]->batulcmd,instream);
243: get_str(cfg->prot[i]->batdlcmd,instream);
244: get_str(cfg->prot[i]->blindcmd,instream);
245: get_str(cfg->prot[i]->bicmd,instream);
246: get_int(cfg->prot[i]->misc,instream);
247: get_str(cfg->prot[i]->arstr,instream);
248: cfg->prot[i]->ar=ARSTR(cfg->prot[i]->arstr,cfg);
249:
250: for(j=0;j<8;j++)
251: get_int(n,instream);
252: }
253: cfg->total_prots=i;
254:
255: /************************/
256: /* Alternate File Paths */
257: /************************/
258:
259: get_int(cfg->altpaths,instream);
260:
261: if(cfg->altpaths) {
262: if((cfg->altpath=(char **)malloc(sizeof(char *)*cfg->altpaths))==NULL)
263: return allocerr(instream,error,offset,fname,sizeof(char *)*cfg->altpaths);
264: } else
265: cfg->altpath=NULL;
266:
267: for(i=0;i<cfg->altpaths;i++) {
268: if(feof(instream)) break;
269: fread(str,LEN_DIR+1,1,instream);
270: offset+=LEN_DIR+1;
271: backslash(str);
272: j=LEN_DIR+1;
273: if((cfg->altpath[i]=(char *)malloc(j))==NULL)
274: return allocerr(instream,error,offset,fname,j);
275: memset(cfg->altpath[i],0,j);
276: strcpy(cfg->altpath[i],str);
277: for(j=0;j<8;j++)
278: get_int(n,instream);
279: }
280:
281: cfg->altpaths=i;
282:
283: /******************/
284: /* File Libraries */
285: /******************/
286:
287: get_int(cfg->total_libs,instream);
288:
289: if(cfg->total_libs) {
290: if((cfg->lib=(lib_t **)malloc(sizeof(lib_t *)*cfg->total_libs))==NULL)
291: return allocerr(instream,error,offset,fname,sizeof(lib_t *)*cfg->total_libs);
292: } else
293: cfg->lib=NULL;
294:
295: for(i=0;i<cfg->total_libs;i++) {
296: if(feof(instream)) break;
297: if((cfg->lib[i]=(lib_t *)malloc(sizeof(lib_t)))==NULL)
298: return allocerr(instream,error,offset,fname,sizeof(lib_t));
299: memset(cfg->lib[i],0,sizeof(lib_t));
300: cfg->lib[i]->offline_dir=INVALID_DIR;
301:
302: get_str(cfg->lib[i]->lname,instream);
303: get_str(cfg->lib[i]->sname,instream);
304:
305: get_str(cfg->lib[i]->arstr,instream);
306: cfg->lib[i]->ar=ARSTR(cfg->lib[i]->arstr,cfg);
307:
308: get_str(cfg->lib[i]->parent_path,instream);
309:
310: get_str(cfg->lib[i]->code_prefix,instream);
311:
312: get_int(c,instream);
313:
314: for(j=0;j<3;j++)
315: get_int(n,instream); /* 0x0000 */
316:
317: for(j=0;j<16;j++)
318: get_int(n,instream); /* 0xffff */
319: }
320: cfg->total_libs=i;
321:
322: /********************/
323: /* File Directories */
324: /********************/
325:
326: cfg->sysop_dir=cfg->user_dir=cfg->upload_dir=INVALID_DIR;
327: get_int(cfg->total_dirs,instream);
328:
329: if(cfg->total_dirs) {
330: if((cfg->dir=(dir_t **)malloc(sizeof(dir_t *)*(cfg->total_dirs+1)))==NULL)
331: return allocerr(instream,error,offset,fname,sizeof(dir_t *)*(cfg->total_dirs+1));
332: } else
333: cfg->dir=NULL;
334:
335: for(i=0;i<cfg->total_dirs;i++) {
336: if(feof(instream)) break;
337: if((cfg->dir[i]=(dir_t *)malloc(sizeof(dir_t)))==NULL)
338: return allocerr(instream,error,offset,fname,sizeof(dir_t));
339: memset(cfg->dir[i],0,sizeof(dir_t));
340:
341: get_int(cfg->dir[i]->lib,instream);
342: get_str(cfg->dir[i]->lname,instream);
343: get_str(cfg->dir[i]->sname,instream);
344:
345: if(!stricmp(cfg->dir[i]->sname,"SYSOP")) /* Sysop upload directory */
346: cfg->sysop_dir=i;
347: else if(!stricmp(cfg->dir[i]->sname,"USER")) /* User to User xfer dir */
348: cfg->user_dir=i;
349: else if(!stricmp(cfg->dir[i]->sname,"UPLOADS")) /* Upload directory */
350: cfg->upload_dir=i;
351: else if(!stricmp(cfg->dir[i]->sname,"OFFLINE")) /* Offline files dir */
352: cfg->lib[cfg->dir[i]->lib]->offline_dir=i;
353:
354: get_str(cfg->dir[i]->code_suffix,instream);
355:
356: get_str(cfg->dir[i]->data_dir,instream);
357:
358: get_str(cfg->dir[i]->arstr,instream);
359: get_str(cfg->dir[i]->ul_arstr,instream);
360: get_str(cfg->dir[i]->dl_arstr,instream);
361: get_str(cfg->dir[i]->op_arstr,instream);
362:
363: cfg->dir[i]->ar=ARSTR(cfg->dir[i]->arstr,cfg);
364: cfg->dir[i]->ul_ar=ARSTR(cfg->dir[i]->ul_arstr,cfg);
365: cfg->dir[i]->dl_ar=ARSTR(cfg->dir[i]->dl_arstr,cfg);
366: cfg->dir[i]->op_ar=ARSTR(cfg->dir[i]->op_arstr,cfg);
367:
368: get_str(cfg->dir[i]->path,instream);
369:
370: get_str(cfg->dir[i]->upload_sem,instream);
371:
372: get_int(cfg->dir[i]->maxfiles,instream);
373: if(cfg->dir[i]->maxfiles>MAX_FILES)
374: cfg->dir[i]->maxfiles=MAX_FILES;
375: get_str(cfg->dir[i]->exts,instream);
376: get_int(cfg->dir[i]->misc,instream);
377: get_int(cfg->dir[i]->seqdev,instream);
378: get_int(cfg->dir[i]->sort,instream);
379: get_str(cfg->dir[i]->ex_arstr,instream);
380: cfg->dir[i]->ex_ar=ARSTR(cfg->dir[i]->ex_arstr,cfg);
381:
382: get_int(cfg->dir[i]->maxage,instream);
383: get_int(cfg->dir[i]->up_pct,instream);
384: get_int(cfg->dir[i]->dn_pct,instream);
385: get_int(c,instream);
386: for(j=0;j<24;j++)
387: get_int(n,instream);
388: }
389:
390: cfg->total_dirs=i;
391:
392: /**********************/
393: /* Text File Sections */
394: /**********************/
395:
396: get_int(cfg->total_txtsecs,instream);
397:
398:
399: if(cfg->total_txtsecs) {
400: if((cfg->txtsec=(txtsec_t **)malloc(sizeof(txtsec_t *)*cfg->total_txtsecs))==NULL)
401: return allocerr(instream,error,offset,fname,sizeof(txtsec_t *)*cfg->total_txtsecs);
402: } else
403: cfg->txtsec=NULL;
404:
405: for(i=0;i<cfg->total_txtsecs;i++) {
406: if(feof(instream)) break;
407: if((cfg->txtsec[i]=(txtsec_t *)malloc(sizeof(txtsec_t)))==NULL)
408: return allocerr(instream,error,offset,fname,sizeof(txtsec_t));
409: memset(cfg->txtsec[i],0,sizeof(txtsec_t));
410:
411: get_str(cfg->txtsec[i]->name,instream);
412: get_str(cfg->txtsec[i]->code,instream);
413: get_str(cfg->txtsec[i]->arstr,instream);
414: cfg->txtsec[i]->ar=ARSTR(cfg->txtsec[i]->arstr,cfg);
415:
416: for(j=0;j<8;j++)
417: get_int(n,instream);
418: }
419: cfg->total_txtsecs=i;
420:
421: fclose(instream);
422: return(TRUE);
423: }
424:
425: /****************************************************************************/
426: /* Reads in XTRN.CNF and initializes the associated variables */
427: /****************************************************************************/
428: BOOL read_xtrn_cfg(scfg_t* cfg, char* error)
429: {
430: char str[MAX_PATH+1],fname[13],c;
1.1.1.2 ! root 431: short i,j;
! 432: int16_t n;
1.1 root 433: long offset=0;
434: FILE *instream;
435:
436: strcpy(fname,"xtrn.cnf");
437: sprintf(str,"%s%s",cfg->ctrl_dir,fname);
438: if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
439: sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
440: return(FALSE);
441: }
442:
443: /*************/
444: /* Swap list */
445: /*************/
446:
447: get_int(cfg->total_swaps,instream);
448:
449: if(cfg->total_swaps) {
450: if((cfg->swap=(swap_t **)malloc(sizeof(swap_t *)*cfg->total_swaps))==NULL)
451: return allocerr(instream,error,offset,fname,sizeof(swap_t *)*cfg->total_swaps);
452: } else
453: cfg->swap=NULL;
454:
455: for(i=0;i<cfg->total_swaps;i++) {
456: if(feof(instream)) break;
457: if((cfg->swap[i]=(swap_t *)malloc(sizeof(swap_t)))==NULL)
458: return allocerr(instream,error,offset,fname,sizeof(swap_t));
459: get_str(cfg->swap[i]->cmd,instream);
460: }
461: cfg->total_swaps=i;
462:
463: /********************/
464: /* External Editors */
465: /********************/
466:
467: get_int(cfg->total_xedits,instream);
468:
469: if(cfg->total_xedits) {
470: if((cfg->xedit=(xedit_t **)malloc(sizeof(xedit_t *)*cfg->total_xedits))==NULL)
471: return allocerr(instream,error,offset,fname,sizeof(xedit_t *)*cfg->total_xedits);
472: } else
473: cfg->xedit=NULL;
474:
475: for(i=0;i<cfg->total_xedits;i++) {
476: if(feof(instream)) break;
477: if((cfg->xedit[i]=(xedit_t *)malloc(sizeof(xedit_t)))==NULL)
478: return allocerr(instream,error,offset,fname,sizeof(xedit_t));
479: memset(cfg->xedit[i],0,sizeof(xedit_t));
480:
481: get_str(cfg->xedit[i]->name,instream);
482: get_str(cfg->xedit[i]->code,instream);
483: get_str(cfg->xedit[i]->lcmd,instream);
484: get_str(cfg->xedit[i]->rcmd,instream);
485:
486: get_int(cfg->xedit[i]->misc,instream);
487: get_str(cfg->xedit[i]->arstr,instream);
488: cfg->xedit[i]->ar=ARSTR(cfg->xedit[i]->arstr,cfg);
489:
490: get_int(cfg->xedit[i]->type,instream);
491: get_int(c,instream);
492: for(j=0;j<7;j++)
493: get_int(n,instream);
494: }
495: cfg->total_xedits=i;
496:
497:
498: /*****************************/
499: /* External Program Sections */
500: /*****************************/
501:
502: get_int(cfg->total_xtrnsecs,instream);
503:
504: if(cfg->total_xtrnsecs) {
505: if((cfg->xtrnsec=(xtrnsec_t **)malloc(sizeof(xtrnsec_t *)*cfg->total_xtrnsecs))
506: ==NULL)
507: return allocerr(instream,error,offset,fname,sizeof(xtrnsec_t *)*cfg->total_xtrnsecs);
508: } else
509: cfg->xtrnsec=NULL;
510:
511: for(i=0;i<cfg->total_xtrnsecs;i++) {
512: if(feof(instream)) break;
513: if((cfg->xtrnsec[i]=(xtrnsec_t *)malloc(sizeof(xtrnsec_t)))==NULL)
514: return allocerr(instream,error,offset,fname,sizeof(xtrnsec_t));
515: memset(cfg->xtrnsec[i],0,sizeof(xtrnsec_t));
516:
517: get_str(cfg->xtrnsec[i]->name,instream);
518: get_str(cfg->xtrnsec[i]->code,instream);
519: get_str(cfg->xtrnsec[i]->arstr,instream);
520: cfg->xtrnsec[i]->ar=ARSTR(cfg->xtrnsec[i]->arstr,cfg);
521:
522: for(j=0;j<8;j++)
523: get_int(n,instream);
524: }
525: cfg->total_xtrnsecs=i;
526:
527:
528: /*********************/
529: /* External Programs */
530: /*********************/
531:
532: get_int(cfg->total_xtrns,instream);
533:
534: if(cfg->total_xtrns) {
535: if((cfg->xtrn=(xtrn_t **)malloc(sizeof(xtrn_t *)*cfg->total_xtrns))==NULL)
536: return allocerr(instream,error,offset,fname,sizeof(xtrn_t *)*cfg->total_xtrns);
537: } else
538: cfg->xtrn=NULL;
539:
540: for(i=0;i<cfg->total_xtrns;i++) {
541: if(feof(instream)) break;
542: if((cfg->xtrn[i]=(xtrn_t *)malloc(sizeof(xtrn_t)))==NULL)
543: return allocerr(instream,error,offset,fname,sizeof(xtrn_t));
544: memset(cfg->xtrn[i],0,sizeof(xtrn_t));
545:
546: get_int(cfg->xtrn[i]->sec,instream);
547: get_str(cfg->xtrn[i]->name,instream);
548: get_str(cfg->xtrn[i]->code,instream);
549: get_str(cfg->xtrn[i]->arstr,instream);
550: get_str(cfg->xtrn[i]->run_arstr,instream);
551: cfg->xtrn[i]->ar=ARSTR(cfg->xtrn[i]->arstr,cfg);
552: cfg->xtrn[i]->run_ar=ARSTR(cfg->xtrn[i]->run_arstr,cfg);
553:
554: get_int(cfg->xtrn[i]->type,instream);
555: get_int(cfg->xtrn[i]->misc,instream);
556: get_int(cfg->xtrn[i]->event,instream);
557: get_int(cfg->xtrn[i]->cost,instream);
558: get_str(cfg->xtrn[i]->cmd,instream);
559: get_str(cfg->xtrn[i]->clean,instream);
560: get_str(cfg->xtrn[i]->path,instream);
561: get_int(cfg->xtrn[i]->textra,instream);
562: get_int(cfg->xtrn[i]->maxtime,instream);
563: for(j=0;j<7;j++)
564: get_int(n,instream);
565: }
566: cfg->total_xtrns=i;
567:
568:
569: /****************/
570: /* Timed Events */
571: /****************/
572:
573: get_int(cfg->total_events,instream);
574:
575: if(cfg->total_events) {
576: if((cfg->event=(event_t **)malloc(sizeof(event_t *)*cfg->total_events))==NULL)
577: return allocerr(instream,error,offset,fname,sizeof(event_t *)*cfg->total_events);
578: } else
579: cfg->event=NULL;
580:
581: for(i=0;i<cfg->total_events;i++) {
582: if(feof(instream)) break;
583: if((cfg->event[i]=(event_t *)malloc(sizeof(event_t)))==NULL)
584: return allocerr(instream,error,offset,fname,sizeof(event_t));
585: memset(cfg->event[i],0,sizeof(event_t));
586:
587: get_str(cfg->event[i]->code,instream);
588: get_str(cfg->event[i]->cmd,instream);
589: get_int(cfg->event[i]->days,instream);
590: get_int(cfg->event[i]->time,instream);
591: get_int(cfg->event[i]->node,instream);
592: get_int(cfg->event[i]->misc,instream);
593: get_str(cfg->event[i]->dir,instream);
594: get_int(cfg->event[i]->freq,instream);
595: get_int(cfg->event[i]->mdays,instream);
1.1.1.2 ! root 596: get_int(cfg->event[i]->months,instream);
1.1 root 597:
1.1.1.2 ! root 598: for(j=0;j<4;j++)
1.1 root 599: get_int(n,instream);
600: }
601: cfg->total_events=i;
602:
603: /********************************/
604: /* Native (32-bit) Program list */
605: /********************************/
606:
607: get_int(cfg->total_natvpgms,instream);
608:
609: if(cfg->total_natvpgms) {
610: if((cfg->natvpgm=(natvpgm_t **)malloc(sizeof(natvpgm_t *)*cfg->total_natvpgms))==NULL)
611: return allocerr(instream,error,offset,fname,sizeof(natvpgm_t *)*cfg->total_natvpgms);
612: } else
613: cfg->natvpgm=NULL;
614:
615: for(i=0;i<cfg->total_natvpgms;i++) {
616: if(feof(instream)) break;
617: if((cfg->natvpgm[i]=(natvpgm_t *)malloc(sizeof(natvpgm_t)))==NULL)
618: return allocerr(instream,error,offset,fname,sizeof(natvpgm_t));
619: get_str(cfg->natvpgm[i]->name,instream);
620: cfg->natvpgm[i]->misc=0;
621: }
622: cfg->total_natvpgms=i;
623: for(i=0;i<cfg->total_natvpgms;i++) {
624: if(feof(instream)) break;
625: get_int(cfg->natvpgm[i]->misc,instream);
626: }
627:
628: /*******************/
629: /* Global Hot Keys */
630: /*******************/
631:
632: get_int(cfg->total_hotkeys,instream);
633:
634: if(cfg->total_hotkeys) {
635: if((cfg->hotkey=(hotkey_t **)malloc(sizeof(hotkey_t *)*cfg->total_hotkeys))==NULL)
636: return allocerr(instream,error,offset,fname,sizeof(hotkey_t *)*cfg->total_hotkeys);
637: } else
638: cfg->hotkey=NULL;
639:
640: for(i=0;i<cfg->total_hotkeys;i++) {
641: if(feof(instream)) break;
642: if((cfg->hotkey[i]=(hotkey_t *)malloc(sizeof(hotkey_t)))==NULL)
643: return allocerr(instream,error,offset,fname,sizeof(hotkey_t));
644: memset(cfg->hotkey[i],0,sizeof(hotkey_t));
645:
646: get_int(cfg->hotkey[i]->key,instream);
647: get_str(cfg->hotkey[i]->cmd,instream);
648:
649: for(j=0;j<8;j++)
650: get_int(n,instream);
651: }
652: cfg->total_hotkeys=i;
653:
654: /************************************/
655: /* External Program-related Toggles */
656: /************************************/
657: get_int(cfg->xtrn_misc,instream);
658:
659: fclose(instream);
660: return(TRUE);
661: }
662:
663: /****************************************************************************/
664: /* Reads in CHAT.CNF and initializes the associated variables */
665: /****************************************************************************/
666: BOOL read_chat_cfg(scfg_t* cfg, char* error)
667: {
668: char str[MAX_PATH+1],fname[13];
1.1.1.2 ! root 669: short i,j;
! 670: int16_t n;
1.1 root 671: long offset=0;
672: FILE *instream;
673:
674: strcpy(fname,"chat.cnf");
675: sprintf(str,"%s%s",cfg->ctrl_dir,fname);
676: if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
677: sprintf(error,"%d (%s) opening %s",errno,STRERROR(errno),str);
678: return(FALSE);
679: }
680:
681: /*********/
682: /* Gurus */
683: /*********/
684:
685: get_int(cfg->total_gurus,instream);
686:
687: if(cfg->total_gurus) {
688: if((cfg->guru=(guru_t **)malloc(sizeof(guru_t *)*cfg->total_gurus))==NULL)
689: return allocerr(instream,error,offset,fname,sizeof(guru_t *)*cfg->total_gurus);
690: } else
691: cfg->guru=NULL;
692:
693: for(i=0;i<cfg->total_gurus;i++) {
694: if(feof(instream)) break;
695: if((cfg->guru[i]=(guru_t *)malloc(sizeof(guru_t)))==NULL)
696: return allocerr(instream,error,offset,fname,sizeof(guru_t));
697: memset(cfg->guru[i],0,sizeof(guru_t));
698:
699: get_str(cfg->guru[i]->name,instream);
700: get_str(cfg->guru[i]->code,instream);
701:
702: get_str(cfg->guru[i]->arstr,instream);
703: cfg->guru[i]->ar=ARSTR(cfg->guru[i]->arstr,cfg);
704:
705: for(j=0;j<8;j++)
706: get_int(n,instream);
707: }
708: cfg->total_chans=i;
709:
710:
711: /********************/
712: /* Chat Action Sets */
713: /********************/
714:
715: get_int(cfg->total_actsets,instream);
716:
717: if(cfg->total_actsets) {
718: if((cfg->actset=(actset_t **)malloc(sizeof(actset_t *)*cfg->total_actsets))==NULL)
719: return allocerr(instream,error,offset,fname,sizeof(actset_t *)*cfg->total_actsets);
720: } else
721: cfg->actset=NULL;
722:
723: for(i=0;i<cfg->total_actsets;i++) {
724: if(feof(instream)) break;
725: if((cfg->actset[i]=(actset_t *)malloc(sizeof(actset_t)))==NULL)
726: return allocerr(instream,error,offset,fname,sizeof(actset_t));
727: get_str(cfg->actset[i]->name,instream);
728: }
729: cfg->total_actsets=i;
730:
731:
732: /****************/
733: /* Chat Actions */
734: /****************/
735:
736: get_int(cfg->total_chatacts,instream);
737:
738: if(cfg->total_chatacts) {
739: if((cfg->chatact=(chatact_t **)malloc(sizeof(chatact_t *)*cfg->total_chatacts))
740: ==NULL)
741: return allocerr(instream,error,offset,fname,sizeof(chatact_t *)*cfg->total_chatacts);
742: } else
743: cfg->chatact=NULL;
744:
745: for(i=0;i<cfg->total_chatacts;i++) {
746: if(feof(instream)) break;
747: if((cfg->chatact[i]=(chatact_t *)malloc(sizeof(chatact_t)))==NULL)
748: return allocerr(instream,error,offset,fname,sizeof(chatact_t));
749: memset(cfg->chatact[i],0,sizeof(chatact_t));
750:
751: get_int(cfg->chatact[i]->actset,instream);
752: get_str(cfg->chatact[i]->cmd,instream);
753: get_str(cfg->chatact[i]->out,instream);
754: for(j=0;j<8;j++)
755: get_int(n,instream);
756: }
757:
758: cfg->total_chatacts=i;
759:
760:
761: /***************************/
762: /* Multinode Chat Channels */
763: /***************************/
764:
765: get_int(cfg->total_chans,instream);
766:
767: if(cfg->total_chans) {
768: if((cfg->chan=(chan_t **)malloc(sizeof(chan_t *)*cfg->total_chans))==NULL)
769: return allocerr(instream,error,offset,fname,sizeof(chan_t *)*cfg->total_chans);
770: } else
771: cfg->chan=NULL;
772:
773: for(i=0;i<cfg->total_chans;i++) {
774: if(feof(instream)) break;
775: if((cfg->chan[i]=(chan_t *)malloc(sizeof(chan_t)))==NULL)
776: return allocerr(instream,error,offset,fname,sizeof(chan_t));
777: memset(cfg->chan[i],0,sizeof(chan_t));
778:
779: get_int(cfg->chan[i]->actset,instream);
780: get_str(cfg->chan[i]->name,instream);
781:
782: get_str(cfg->chan[i]->code,instream);
783:
784: get_str(cfg->chan[i]->arstr,instream);
785: cfg->chan[i]->ar=ARSTR(cfg->chan[i]->arstr,cfg);
786:
787: get_int(cfg->chan[i]->cost,instream);
788: get_int(cfg->chan[i]->guru,instream);
789: get_int(cfg->chan[i]->misc,instream);
790: for(j=0;j<8;j++)
791: get_int(n,instream);
792: }
793: cfg->total_chans=i;
794:
795:
796: /**************/
797: /* Chat Pages */
798: /**************/
799:
800: get_int(cfg->total_pages,instream);
801:
802: if(cfg->total_pages) {
803: if((cfg->page=(page_t **)malloc(sizeof(page_t *)*cfg->total_pages))==NULL)
804: return allocerr(instream,error,offset,fname,sizeof(page_t *)*cfg->total_pages);
805: } else
806: cfg->page=NULL;
807:
808: for(i=0;i<cfg->total_pages;i++) {
809: if(feof(instream)) break;
810: if((cfg->page[i]=(page_t *)malloc(sizeof(page_t)))==NULL)
811: return allocerr(instream,error,offset,fname,sizeof(page_t));
812: memset(cfg->page[i],0,sizeof(page_t));
813:
814: get_str(cfg->page[i]->cmd,instream);
815:
816: get_str(cfg->page[i]->arstr,instream);
817: cfg->page[i]->ar=ARSTR(cfg->page[i]->arstr,cfg);
818:
819: get_int(cfg->page[i]->misc,instream);
820: for(j=0;j<8;j++)
821: get_int(n,instream);
822: }
823: cfg->total_pages=i;
824:
825:
826: fclose(instream);
827: return(TRUE);
828: }
829:
830: /****************************************************************************/
831: /* Read one line of up to 256 characters from the file pointed to by */
832: /* 'stream' and put upto 'maxlen' number of character into 'outstr' and */
833: /* truncate spaces off end of 'outstr'. */
834: /****************************************************************************/
835: char *readline(long *offset, char *outstr, int maxlen, FILE *instream)
836: {
837: char str[257];
838:
839: if(fgets(str,256,instream)==NULL)
840: return(NULL);
841: sprintf(outstr,"%.*s",maxlen,str);
842: truncsp(outstr);
843: (*offset)+=maxlen;
844: return(outstr);
845: }
846:
847: /****************************************************************************/
848: /* Turns char string of flags into a long */
849: /****************************************************************************/
850: long aftol(char *str)
851: {
852: char ch;
853: size_t c=0;
854: ulong l=0UL;
855:
856: while(str[c]) {
857: ch=toupper(str[c]);
858: if(ch>='A' && ch<='Z')
859: l|=FLAG(ch);
860: c++;
861: }
862: return(l);
863: }
864:
865: /*****************************************************************************/
866: /* Converts a long into an ASCII Flag string (A-Z) that represents bits 0-25 */
867: /*****************************************************************************/
868: char *ltoaf(long l,char *str)
869: {
870: size_t c=0;
871:
872: while(c<26) {
873: if(l&(long)(1L<<c))
874: str[c]='A'+c;
875: else str[c]=' ';
876: c++;
877: }
878: str[c]=0;
879: return(str);
880: }
881:
882: /****************************************************************************/
883: /* Returns the actual attribute code from a string of ATTR characters */
884: /****************************************************************************/
885: uchar attrstr(char *str)
886: {
887: uchar atr;
888: ulong l=0;
889:
890: atr=LIGHTGRAY;
891: while(str[l]) {
892: switch(toupper(str[l])) {
893: case 'H': /* High intensity */
894: atr|=HIGH;
895: break;
896: case 'I': /* Blink */
897: atr|=BLINK;
898: break;
899: case 'K': /* Black */
900: atr=(atr&0xf8)|BLACK;
901: break;
902: case 'W': /* White */
903: atr=(atr&0xf8)|LIGHTGRAY;
904: break;
905: case 'R':
906: atr=(uchar)((atr&0xf8)|RED);
907: break;
908: case 'G':
909: atr=(uchar)((atr&0xf8)|GREEN);
910: break;
911: case 'Y': /* Yellow */
912: atr=(uchar)((atr&0xf8)|BROWN);
913: break;
914: case 'B':
915: atr=(uchar)((atr&0xf8)|BLUE);
916: break;
917: case 'M':
918: atr=(uchar)((atr&0xf8)|MAGENTA);
919: break;
920: case 'C':
921: atr=(uchar)((atr&0xf8)|CYAN);
922: break;
923: case '0': /* Black Background */
924: atr=(uchar)(atr&0x8f);
925: break;
926: case '1': /* Red Background */
927: atr=(uchar)((atr&0x8f)|BG_RED);
928: break;
929: case '2': /* Green Background */
930: atr=(uchar)((atr&0x8f)|BG_GREEN);
931: break;
932: case '3': /* Yellow Background */
933: atr=(uchar)((atr&0x8f)|BG_BROWN);
934: break;
935: case '4': /* Blue Background */
936: atr=(uchar)((atr&0x8f)|BG_BLUE);
937: break;
938: case '5': /* Magenta Background */
939: atr=(uchar)((atr&0x8f)|BG_MAGENTA);
940: break;
941: case '6': /* Cyan Background */
942: atr=(uchar)((atr&0x8f)|BG_CYAN);
943: break;
944: case '7': /* White Background */
945: atr=(uchar)((atr&0x8f)|BG_LIGHTGRAY);
946: break;
947: }
948: l++;
949: }
950: return(atr);
951: }
952:
953: void free_file_cfg(scfg_t* cfg)
954: {
955: uint i;
956:
957: if(cfg->fextr!=NULL) {
958: for(i=0;i<cfg->total_fextrs;i++) {
959: FREE_AR(cfg->fextr[i]->ar);
960: FREE_AND_NULL(cfg->fextr[i]);
961: }
962: FREE_AND_NULL(cfg->fextr);
963: }
964:
965: if(cfg->fcomp!=NULL) {
966: for(i=0;i<cfg->total_fcomps;i++) {
967: FREE_AR(cfg->fcomp[i]->ar);
968: FREE_AND_NULL(cfg->fcomp[i]);
969: }
970: FREE_AND_NULL(cfg->fcomp);
971: }
972:
973: if(cfg->fview!=NULL) {
974: for(i=0;i<cfg->total_fviews;i++) {
975: FREE_AR(cfg->fview[i]->ar);
976: FREE_AND_NULL(cfg->fview[i]);
977: }
978: FREE_AND_NULL(cfg->fview);
979: }
980:
981: if(cfg->ftest!=NULL) {
982: for(i=0;i<cfg->total_ftests;i++) {
983: FREE_AR(cfg->ftest[i]->ar);
984: FREE_AND_NULL(cfg->ftest[i]);
985: }
986: FREE_AND_NULL(cfg->ftest);
987: }
988:
989: if(cfg->dlevent!=NULL) {
990: for(i=0;i<cfg->total_dlevents;i++) {
991: FREE_AR(cfg->dlevent[i]->ar);
992: FREE_AND_NULL(cfg->dlevent[i]);
993: }
994: FREE_AND_NULL(cfg->dlevent);
995: }
996:
997: if(cfg->prot!=NULL) {
998: for(i=0;i<cfg->total_prots;i++) {
999: FREE_AR(cfg->prot[i]->ar);
1000: FREE_AND_NULL(cfg->prot[i]);
1001: }
1002: FREE_AND_NULL(cfg->prot);
1003: }
1004:
1005: if(cfg->altpath!=NULL) {
1006: for(i=0;i<cfg->altpaths;i++)
1007: FREE_AND_NULL(cfg->altpath[i]);
1008: FREE_AND_NULL(cfg->altpath);
1009: }
1010:
1011: if(cfg->lib!=NULL) {
1012: for(i=0;i<cfg->total_libs;i++) {
1013: FREE_AR(cfg->lib[i]->ar);
1014: FREE_AND_NULL(cfg->lib[i]);
1015: }
1016: FREE_AND_NULL(cfg->lib);
1017: }
1018:
1019: if(cfg->dir!=NULL) {
1020: for(i=0;i<cfg->total_dirs;i++) {
1021: #if 0 /*ndef SCFG */
1022: if(cfg->dir[i]->data_dir!=cfg->data_dir_dirs)
1023: FREE_AND_NULL(cfg->dir[i]->data_dir);
1024: #endif
1025: FREE_AR(cfg->dir[i]->ar);
1026: FREE_AR(cfg->dir[i]->ul_ar);
1027: FREE_AR(cfg->dir[i]->dl_ar);
1028: FREE_AR(cfg->dir[i]->op_ar);
1029: FREE_AR(cfg->dir[i]->ex_ar);
1030: FREE_AND_NULL(cfg->dir[i]);
1031: }
1032: FREE_AND_NULL(cfg->dir);
1033: }
1034:
1035: if(cfg->txtsec!=NULL) {
1036: for(i=0;i<cfg->total_txtsecs;i++) {
1037: FREE_AR(cfg->txtsec[i]->ar);
1038: FREE_AND_NULL(cfg->txtsec[i]);
1039: }
1040: FREE_AND_NULL(cfg->txtsec);
1041: }
1042: }
1043:
1044: void free_chat_cfg(scfg_t* cfg)
1045: {
1046: int i;
1047:
1048: if(cfg->actset!=NULL) {
1049: for(i=0;i<cfg->total_actsets;i++) {
1050: FREE_AND_NULL(cfg->actset[i]);
1051: }
1052: FREE_AND_NULL(cfg->actset);
1053: }
1054:
1055: if(cfg->chatact!=NULL) {
1056: for(i=0;i<cfg->total_chatacts;i++) {
1057: FREE_AND_NULL(cfg->chatact[i]);
1058: }
1059: FREE_AND_NULL(cfg->chatact);
1060: }
1061:
1062: if(cfg->chan!=NULL) {
1063: for(i=0;i<cfg->total_chans;i++) {
1064: FREE_AR(cfg->chan[i]->ar);
1065: FREE_AND_NULL(cfg->chan[i]);
1066: }
1067: FREE_AND_NULL(cfg->chan);
1068: }
1069:
1070: if(cfg->guru!=NULL) {
1071: for(i=0;i<cfg->total_gurus;i++) {
1072: FREE_AR(cfg->guru[i]->ar);
1073: FREE_AND_NULL(cfg->guru[i]);
1074: }
1075: FREE_AND_NULL(cfg->guru);
1076: }
1077:
1078: if(cfg->page!=NULL) {
1079: for(i=0;i<cfg->total_pages;i++) {
1080: FREE_AR(cfg->page[i]->ar);
1081: FREE_AND_NULL(cfg->page[i]);
1082: }
1083: FREE_AND_NULL(cfg->page);
1084: }
1085:
1086: }
1087:
1088: void free_xtrn_cfg(scfg_t* cfg)
1089: {
1090: int i;
1091:
1092: if(cfg->swap!=NULL) {
1093: for(i=0;i<cfg->total_swaps;i++) {
1094: FREE_AND_NULL(cfg->swap[i]);
1095: }
1096: FREE_AND_NULL(cfg->swap);
1097: }
1098:
1099: if(cfg->xedit!=NULL) {
1100: for(i=0;i<cfg->total_xedits;i++) {
1101: FREE_AR(cfg->xedit[i]->ar);
1102: FREE_AND_NULL(cfg->xedit[i]);
1103: }
1104: FREE_AND_NULL(cfg->xedit);
1105: }
1106:
1107: if(cfg->xtrnsec!=NULL) {
1108: for(i=0;i<cfg->total_xtrnsecs;i++) {
1109: FREE_AR(cfg->xtrnsec[i]->ar);
1110: FREE_AND_NULL(cfg->xtrnsec[i]);
1111: }
1112: FREE_AND_NULL(cfg->xtrnsec);
1113: }
1114:
1115: if(cfg->xtrn!=NULL) {
1116: for(i=0;i<cfg->total_xtrns;i++) {
1117: FREE_AR(cfg->xtrn[i]->ar);
1118: FREE_AR(cfg->xtrn[i]->run_ar);
1119: FREE_AND_NULL(cfg->xtrn[i]);
1120: }
1121: FREE_AND_NULL(cfg->xtrn);
1122: }
1123:
1124: if(cfg->event!=NULL) {
1125: for(i=0;i<cfg->total_events;i++) {
1126: FREE_AND_NULL(cfg->event[i]);
1127: }
1128: FREE_AND_NULL(cfg->event);
1129: }
1130:
1131: if(cfg->natvpgm!=NULL) {
1132: for(i=0;i<cfg->total_natvpgms;i++) {
1133: FREE_AND_NULL(cfg->natvpgm[i]);
1134: }
1135: FREE_AND_NULL(cfg->natvpgm);
1136: }
1137: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.