2 System information subroutines.
4 Copyright (C) 1992, 1993, 1995 Ian Lance Taylor
6 This file is part of the Taylor UUCP uuconf library.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 The author of the program may be contacted at ian@airs.com or
23 c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
29 const char _uuconf_syssub_rcsid[] = "$FreeBSD$";
34 /* This macro operates on every string (char *) field in struct
36 #define SYSTEM_STRINGS(OP) \
40 OP (uuconf_zalternate); \
42 OP (uuconf_zmax_remote_debug); \
44 OP (uuconf_zcall_login); \
45 OP (uuconf_zcall_password); \
46 OP (uuconf_zcalled_login); \
47 OP (uuconf_zprotocols); \
48 OP (uuconf_zpubdir); \
49 OP (uuconf_zlocalname); \
53 /* This macro operates on every string array (char **) field in struct
55 #define SYSTEM_STRING_ARRAYS(OP) \
58 OP (uuconf_pzalias); \
59 OP (uuconf_pzlocal_send); \
60 OP (uuconf_pzremote_send); \
61 OP (uuconf_pzlocal_receive); \
62 OP (uuconf_pzremote_receive); \
65 OP (uuconf_pzforward_from); \
66 OP (uuconf_pzforward_to); \
67 OP (uuconf_schat.uuconf_pzchat); \
68 OP (uuconf_schat.uuconf_pzprogram); \
69 OP (uuconf_schat.uuconf_pzfail); \
70 OP (uuconf_scalled_chat.uuconf_pzchat); \
71 OP (uuconf_scalled_chat.uuconf_pzprogram); \
72 OP (uuconf_scalled_chat.uuconf_pzfail); \
76 /* This macro operations on every timespan pointer (struct
77 uuconf_timespan *) in struct uuconf_system. */
78 #define SYSTEM_TIMESPANS(OP) \
81 OP (uuconf_qtimegrade); \
82 OP (uuconf_qcalltimegrade); \
83 OP (uuconf_qcalledtimegrade); \
84 OP (uuconf_qcall_local_size); \
85 OP (uuconf_qcall_remote_size); \
86 OP (uuconf_qcalled_local_size); \
87 OP (uuconf_qcalled_remote_size); \
91 /* This macro operates on every boolean value (of type int, although
92 some type int are not boolean) field in uuconf_system. */
93 #define SYSTEM_BOOLEANS(OP) \
97 OP (uuconf_fcalled); \
98 OP (uuconf_fcallback); \
99 OP (uuconf_fsequence); \
100 OP (uuconf_fsend_request); \
101 OP (uuconf_frec_request); \
102 OP (uuconf_fcall_transfer); \
103 OP (uuconf_fcalled_transfer); \
104 OP (uuconf_schat.uuconf_fstrip); \
105 OP (uuconf_scalled_chat.uuconf_fstrip); \
109 /* This macro operates on every generic integer (type int or long) in
111 #define SYSTEM_INTEGERS(OP) \
114 OP (uuconf_cmax_retries); \
115 OP (uuconf_csuccess_wait); \
117 OP (uuconf_ihighbaud); \
118 OP (uuconf_cfree_space); \
119 OP (uuconf_schat.uuconf_ctimeout); \
120 OP (uuconf_scalled_chat.uuconf_ctimeout); \
124 /* There is no macro for uuconf_qalternate, uuconf_zport,
125 uuconf_qport, uuconf_qproto_params, or uuconf_palloc. */
127 /* Clear the contents of a struct uuconf_system. */
130 _uuconf_uclear_system (q)
131 struct uuconf_system *q;
133 #define CLEAR(x) q->x = (char *) &_uuconf_unset
134 SYSTEM_STRINGS (CLEAR);
136 #define CLEAR(x) q->x = (char **) &_uuconf_unset
137 SYSTEM_STRING_ARRAYS (CLEAR);
139 #define CLEAR(x) q->x = (struct uuconf_timespan *) &_uuconf_unset
140 SYSTEM_TIMESPANS (CLEAR);
142 #define CLEAR(x) q->x = -1
143 SYSTEM_BOOLEANS (CLEAR);
144 SYSTEM_INTEGERS (CLEAR);
146 q->uuconf_qalternate = NULL;
147 q->uuconf_zport = (char *) &_uuconf_unset;
148 q->uuconf_qport = (struct uuconf_port *) &_uuconf_unset;
149 q->uuconf_qproto_params = (struct uuconf_proto_param *) &_uuconf_unset;
150 q->uuconf_palloc = NULL;
153 /* Default the contents of one struct uuconf_system to the contents of
154 another. This default alternate by alternate. Any additional
155 alternates in q default to the last alternate of qdefault. If the
156 faddalternates arguments is TRUE, additional alternates or qdefault
157 are added to q; these alternates are copies of the first alternate
158 of q, and defaults are set from the additional alternates of
162 _uuconf_isystem_default (qglobal, qset, qdefault, faddalternates)
163 struct sglobal *qglobal;
164 struct uuconf_system *qset;
165 struct uuconf_system *qdefault;
166 boolean faddalternates;
168 struct uuconf_system *qalt;
170 if (qset->uuconf_palloc != qdefault->uuconf_palloc)
171 qset->uuconf_palloc =
172 _uuconf_pmalloc_block_merge (qset->uuconf_palloc,
173 qdefault->uuconf_palloc);
175 /* If we are adding alternates from the default, make sure we have
176 at least as many alternates in qset as we do in qdefault. Each
177 new alternate we create gets initialized to the first alternate
181 struct uuconf_system **pq, *qdef;
183 for (qdef = qdefault, pq = &qset;
185 qdef = qdef->uuconf_qalternate, pq = &(*pq)->uuconf_qalternate)
189 *pq = ((struct uuconf_system *)
190 uuconf_malloc (qset->uuconf_palloc,
191 sizeof (struct uuconf_system)));
194 qglobal->ierrno = errno;
195 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
198 (*pq)->uuconf_qalternate = NULL;
203 for (qalt = qset; qalt != NULL; qalt = qalt->uuconf_qalternate)
206 if (qalt->x == (char *) &_uuconf_unset) qalt->x = qdefault->x
207 SYSTEM_STRINGS (DEFAULT);
210 if (qalt->x == (char **) &_uuconf_unset) qalt->x = qdefault->x
211 SYSTEM_STRING_ARRAYS (DEFAULT);
214 if (qalt->x == (struct uuconf_timespan *) &_uuconf_unset) \
215 qalt->x = qdefault->x
216 SYSTEM_TIMESPANS (DEFAULT);
218 #define DEFAULT(x) if (qalt->x < 0) qalt->x = qdefault->x
219 SYSTEM_BOOLEANS (DEFAULT);
220 SYSTEM_INTEGERS (DEFAULT);
223 /* We only copy over zport if both zport and qport are NULL,
224 because otherwise a default zport would override a specific
226 if (qalt->uuconf_zport == (char *) &_uuconf_unset
227 && qalt->uuconf_qport == (struct uuconf_port *) &_uuconf_unset)
228 qalt->uuconf_zport = qdefault->uuconf_zport;
229 if (qalt->uuconf_qport == (struct uuconf_port *) &_uuconf_unset)
230 qalt->uuconf_qport = qdefault->uuconf_qport;
232 if (qalt->uuconf_qproto_params
233 == (struct uuconf_proto_param *) &_uuconf_unset)
234 qalt->uuconf_qproto_params = qdefault->uuconf_qproto_params;
235 else if (qdefault->uuconf_qproto_params != NULL)
238 struct uuconf_proto_param *qd, *qa;
240 /* Merge in the default protocol parameters, so that a
241 system with 'g' protocol parameters won't lose the
242 default 'i' protocol parameters. */
245 for (qd = qdefault->uuconf_qproto_params;
246 qd->uuconf_bproto != '\0';
252 for (qa = qalt->uuconf_qproto_params;
253 (qa->uuconf_bproto != '\0'
254 && qa->uuconf_bproto != qd->uuconf_bproto);
257 if (qa->uuconf_bproto == '\0')
266 struct uuconf_proto_param *qnew;
268 qnew = ((struct uuconf_proto_param *)
269 uuconf_malloc (qset->uuconf_palloc,
271 * sizeof (struct uuconf_proto_param))));
274 qglobal->ierrno = errno;
275 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
277 memcpy ((pointer) qnew, (pointer) qalt->uuconf_qproto_params,
278 ca * sizeof (struct uuconf_proto_param));
280 for (qd = qdefault->uuconf_qproto_params;
281 qd->uuconf_bproto != '\0';
284 for (qa = qalt->uuconf_qproto_params;
285 (qa->uuconf_bproto != '\0'
286 && qa->uuconf_bproto != qd->uuconf_bproto);
289 if (qa->uuconf_bproto == '\0')
291 qnew[ca + cnew] = *qd;
295 qnew[ca + cnew].uuconf_bproto = '\0';
296 uuconf_free (qset->uuconf_palloc, qalt->uuconf_qproto_params);
297 qalt->uuconf_qproto_params = qnew;
301 if (qdefault->uuconf_qalternate != NULL)
302 qdefault = qdefault->uuconf_qalternate;
305 return UUCONF_SUCCESS;
308 /* Put in the basic defaults. This ensures that the fields are valid
309 on every uuconf_system structure. */
312 _uuconf_isystem_basic_default (qglobal, q)
313 struct sglobal *qglobal;
314 register struct uuconf_system *q;
318 iret = UUCONF_SUCCESS;
320 for (; q != NULL && iret == UUCONF_SUCCESS; q = q->uuconf_qalternate)
322 /* The default of 26 allowable retries is traditional. */
323 if (q->uuconf_cmax_retries < 0)
324 q->uuconf_cmax_retries = 26;
325 if (q->uuconf_schat.uuconf_pzchat == (char **) &_uuconf_unset)
327 q->uuconf_schat.uuconf_pzchat = NULL;
328 iret = _uuconf_iadd_string (qglobal, (char *) "\"\"", FALSE,
330 &q->uuconf_schat.uuconf_pzchat,
332 if (iret != UUCONF_SUCCESS)
334 iret = _uuconf_iadd_string (qglobal, (char *) "\\r\\c", FALSE,
336 &q->uuconf_schat.uuconf_pzchat,
338 if (iret != UUCONF_SUCCESS)
340 iret = _uuconf_iadd_string (qglobal, (char *) "ogin:", FALSE,
342 &q->uuconf_schat.uuconf_pzchat,
344 if (iret != UUCONF_SUCCESS)
346 iret = _uuconf_iadd_string (qglobal, (char *) "-BREAK", FALSE,
348 &q->uuconf_schat.uuconf_pzchat,
350 if (iret != UUCONF_SUCCESS)
352 iret = _uuconf_iadd_string (qglobal, (char *) "-ogin:", FALSE,
354 &q->uuconf_schat.uuconf_pzchat,
356 if (iret != UUCONF_SUCCESS)
358 iret = _uuconf_iadd_string (qglobal, (char *) "-BREAK", FALSE,
360 &q->uuconf_schat.uuconf_pzchat,
362 if (iret != UUCONF_SUCCESS)
364 iret = _uuconf_iadd_string (qglobal, (char *) "-ogin:", FALSE,
366 &q->uuconf_schat.uuconf_pzchat,
368 if (iret != UUCONF_SUCCESS)
370 iret = _uuconf_iadd_string (qglobal, (char *) "\\L", FALSE,
372 &q->uuconf_schat.uuconf_pzchat,
374 if (iret != UUCONF_SUCCESS)
376 iret = _uuconf_iadd_string (qglobal, (char *) "word:", FALSE,
378 &q->uuconf_schat.uuconf_pzchat,
380 if (iret != UUCONF_SUCCESS)
382 iret = _uuconf_iadd_string (qglobal, (char *) "\\P", FALSE,
384 &q->uuconf_schat.uuconf_pzchat,
386 if (iret != UUCONF_SUCCESS)
389 if (q->uuconf_schat.uuconf_ctimeout < 0)
390 q->uuconf_schat.uuconf_ctimeout = 10;
391 if (q->uuconf_schat.uuconf_fstrip < 0)
392 q->uuconf_schat.uuconf_fstrip = TRUE;
393 if (q->uuconf_scalled_chat.uuconf_ctimeout < 0)
394 q->uuconf_scalled_chat.uuconf_ctimeout = 60;
395 if (q->uuconf_scalled_chat.uuconf_fstrip < 0)
396 q->uuconf_scalled_chat.uuconf_fstrip = TRUE;
397 if (q->uuconf_fsend_request < 0)
398 q->uuconf_fsend_request = TRUE;
399 if (q->uuconf_frec_request < 0)
400 q->uuconf_frec_request = TRUE;
401 if (q->uuconf_fcall_transfer < 0)
402 q->uuconf_fcall_transfer = TRUE;
403 if (q->uuconf_fcalled_transfer < 0)
404 q->uuconf_fcalled_transfer = TRUE;
405 if (q->uuconf_pzlocal_send == (char **) &_uuconf_unset)
407 q->uuconf_pzlocal_send = NULL;
408 iret = _uuconf_iadd_string (qglobal, (char *) ZROOTDIR, FALSE,
409 FALSE, &q->uuconf_pzlocal_send,
411 if (iret != UUCONF_SUCCESS)
414 if (q->uuconf_pzremote_send == (char **) &_uuconf_unset)
416 q->uuconf_pzremote_send = NULL;
417 iret = _uuconf_iadd_string (qglobal, (char *) "~", FALSE, FALSE,
418 &q->uuconf_pzremote_send,
420 if (iret != UUCONF_SUCCESS)
423 if (q->uuconf_pzlocal_receive == (char **) &_uuconf_unset)
425 q->uuconf_pzlocal_receive = NULL;
426 iret = _uuconf_iadd_string (qglobal, (char *) "~", FALSE, FALSE,
427 &q->uuconf_pzlocal_receive,
429 if (iret != UUCONF_SUCCESS)
432 if (q->uuconf_pzremote_receive == (char **) &_uuconf_unset)
434 q->uuconf_pzremote_receive = NULL;
435 iret = _uuconf_iadd_string (qglobal, (char *) "~", FALSE, FALSE,
436 &q->uuconf_pzremote_receive,
438 if (iret != UUCONF_SUCCESS)
442 if (q->uuconf_pzpath == (char **) &_uuconf_unset)
449 zdup = (char *) uuconf_malloc (q->uuconf_palloc, sizeof CMDPATH);
452 qglobal->ierrno = errno;
453 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
456 memcpy ((pointer) zdup, (pointer) CMDPATH, sizeof CMDPATH);
459 if ((c = _uuconf_istrsplit (zdup, '\0', &pz, &csplit)) < 0)
461 qglobal->ierrno = errno;
462 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
464 q->uuconf_pzpath = (char **) uuconf_malloc (q->uuconf_palloc,
467 if (q->uuconf_pzpath == NULL)
469 qglobal->ierrno = errno;
470 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
472 memcpy ((pointer) q->uuconf_pzpath, (pointer) pz,
473 c * sizeof (char *));
474 q->uuconf_pzpath[c] = NULL;
478 if (q->uuconf_pzcmds == (char **) &_uuconf_unset)
480 q->uuconf_pzcmds = ((char **)
481 uuconf_malloc (q->uuconf_palloc,
482 3 * sizeof (const char *)));
483 if (q->uuconf_pzcmds == NULL)
485 qglobal->ierrno = errno;
486 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
488 q->uuconf_pzcmds[0] = (char *) "rnews";
489 q->uuconf_pzcmds[1] = (char *) "rmail";
490 q->uuconf_pzcmds[2] = NULL;
493 if (q->uuconf_cfree_space < 0)
494 q->uuconf_cfree_space = DEFAULT_FREE_SPACE;
496 if (q->uuconf_zpubdir == (const char *) &_uuconf_unset)
497 q->uuconf_zpubdir = qglobal->qprocess->zpubdir;
499 #define SET(x) if (q->x == (char *) &_uuconf_unset) q->x = NULL
502 #define SET(x) if (q->x == (char **) &_uuconf_unset) q->x = NULL
503 SYSTEM_STRING_ARRAYS(SET);
506 if (q->x == (struct uuconf_timespan *) &_uuconf_unset) q->x = NULL
507 SYSTEM_TIMESPANS (SET);
509 #define SET(x) if (q->x < 0) q->x = 0
510 SYSTEM_BOOLEANS (SET);
511 SYSTEM_INTEGERS (SET);
514 if (q->uuconf_zport == (char *) &_uuconf_unset)
515 q->uuconf_zport = NULL;
516 if (q->uuconf_qport == (struct uuconf_port *) &_uuconf_unset)
517 q->uuconf_qport = NULL;
518 if (q->uuconf_qproto_params
519 == (struct uuconf_proto_param *) &_uuconf_unset)
520 q->uuconf_qproto_params = NULL;