1/* iniglb.c
2   Initialize the global information structure.
3
4   Copyright (C) 1992, 1994, 1995, 2002 Ian Lance Taylor
5
6   This file is part of the Taylor UUCP uuconf library.
7
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.
12
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.
17
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.
21
22   The author of the program may be contacted at ian@airs.com.
23   */
24
25#include "uucnfi.h"
26
27#if USE_RCS_ID
28const char _uuconf_iniglb_rcsid[] = "$Id: iniglb.c,v 1.14 2002/03/05 19:10:42 ian Rel $";
29#endif
30
31#include <errno.h>
32
33/* Initialize the global information structure.  */
34
35int
36_uuconf_iinit_global (pqglobal)
37     struct sglobal **pqglobal;
38{
39  pointer pblock;
40  register struct sprocess *qprocess;
41  char *azargs[3];
42  int iret;
43
44  pblock = uuconf_malloc_block ();
45  if (pblock == NULL)
46    return UUCONF_MALLOC_FAILED;
47
48  *pqglobal = (struct sglobal *) uuconf_malloc (pblock,
49						sizeof (struct sglobal));
50  if (*pqglobal == NULL)
51    {
52      uuconf_free_block (pblock);
53      return UUCONF_MALLOC_FAILED;
54    }
55
56  (*pqglobal)->qprocess = ((struct sprocess *)
57			   uuconf_malloc (pblock,
58					  sizeof (struct sprocess)));
59  if ((*pqglobal)->qprocess == NULL)
60    {
61      uuconf_free_block (pblock);
62      *pqglobal = NULL;
63      return UUCONF_MALLOC_FAILED;
64    }
65
66  (*pqglobal)->pblock = pblock;
67  (*pqglobal)->ierrno = 0;
68  (*pqglobal)->ilineno = 0;
69  (*pqglobal)->zfilename = NULL;
70
71  qprocess = (*pqglobal)->qprocess;
72
73  qprocess->zlocalname = NULL;
74  qprocess->zspooldir = SPOOLDIR;
75  qprocess->zpubdir = PUBDIR;
76#ifdef LOCKDIR
77  qprocess->zlockdir = LOCKDIR;
78#else
79  qprocess->zlockdir = SPOOLDIR;
80#endif
81  qprocess->zlogfile = LOGFILE;
82  qprocess->zstatsfile = STATFILE;
83  qprocess->zdebugfile = DEBUGFILE;
84  qprocess->zdebug = "";
85  qprocess->fstrip_login = TRUE;
86  qprocess->fstrip_proto = TRUE;
87  qprocess->cmaxuuxqts = 0;
88  qprocess->zrunuuxqt = NULL;
89  qprocess->fv2 = TRUE;
90  qprocess->fhdb = TRUE;
91  qprocess->pzdialcodefiles = NULL;
92  qprocess->pztimetables = NULL;
93  qprocess->zconfigfile = NULL;
94  qprocess->pzsysfiles = NULL;
95  qprocess->pzportfiles = NULL;
96  qprocess->pzdialfiles = NULL;
97  qprocess->pzpwdfiles = NULL;
98  qprocess->pzcallfiles = NULL;
99  qprocess->qunknown = NULL;
100  qprocess->fread_syslocs = FALSE;
101  qprocess->qsyslocs = NULL;
102  qprocess->qvalidate = NULL;
103  qprocess->fuses_myname = FALSE;
104  qprocess->zv2systems = NULL;
105  qprocess->zv2devices = NULL;
106  qprocess->zv2userfile = NULL;
107  qprocess->zv2cmds = NULL;
108  qprocess->pzhdb_systems = NULL;
109  qprocess->pzhdb_devices = NULL;
110  qprocess->pzhdb_dialers = NULL;
111  qprocess->fhdb_read_permissions = FALSE;
112  qprocess->qhdb_permissions = NULL;
113
114  azargs[0] = NULL;
115  azargs[1] = (char *) "Evening";
116  azargs[2] = (char *) "Wk1705-0755,Sa,Su";
117  iret = _uuconf_itimetable ((pointer) *pqglobal, 3, azargs,
118			     (pointer) NULL, (pointer) NULL);
119  if (UUCONF_ERROR_VALUE (iret) == UUCONF_SUCCESS)
120    {
121      azargs[1] = (char *) "Night";
122      azargs[2] = (char *) "Wk2305-0755,Sa,Su2305-1655";
123      iret = _uuconf_itimetable ((pointer) *pqglobal, 3, azargs,
124				 (pointer) NULL, (pointer) NULL);
125    }
126  if (UUCONF_ERROR_VALUE (iret) == UUCONF_SUCCESS)
127    {
128      azargs[1] = (char *) "NonPeak";
129      azargs[2] = (char *) "Wk1805-0655,Sa,Su";
130      iret = _uuconf_itimetable ((pointer) *pqglobal, 3, azargs,
131				 (pointer) NULL, (pointer) NULL);
132    }
133  if (UUCONF_ERROR_VALUE (iret) != UUCONF_SUCCESS)
134    {
135      uuconf_free_block (pblock);
136      *pqglobal = NULL;
137
138      /* Strip off any special bits, since there's no global
139	 structure.  */
140      return UUCONF_ERROR_VALUE (iret);
141    }
142
143  return UUCONF_SUCCESS;
144}
145
146/* Add a timetable.  This is also called by the Taylor UUCP
147   initialization code, as well as by the Taylor UUCP sys file code
148   (although the latter is obsolete).  There's no point in putting
149   this in a separate file, since everything must call
150   _uuconf_init_global.  There is a race condition here if this is
151   called by two different threads on a sys file command, but the sys
152   file command is obsolete anyhow.  */
153
154/*ARGSUSED*/
155int
156_uuconf_itimetable (pglobal, argc, argv, pvar, pinfo)
157     pointer pglobal;
158     int argc ATTRIBUTE_UNUSED;
159     char **argv;
160     pointer pvar ATTRIBUTE_UNUSED;
161     pointer pinfo ATTRIBUTE_UNUSED;
162{
163  struct sglobal *qglobal = (struct sglobal *) pglobal;
164  int iret;
165
166  iret = _uuconf_iadd_string (qglobal, argv[1], FALSE, FALSE,
167			      &qglobal->qprocess->pztimetables,
168			      qglobal->pblock);
169  if (iret != UUCONF_SUCCESS)
170    return iret | UUCONF_CMDTABRET_EXIT;
171
172  iret = _uuconf_iadd_string (qglobal, argv[2], FALSE, FALSE,
173			      &qglobal->qprocess->pztimetables,
174			      qglobal->pblock);
175  if (iret != UUCONF_SUCCESS)
176    return iret | UUCONF_CMDTABRET_EXIT;
177
178  return UUCONF_CMDTABRET_KEEP;
179}
180