2 Miscellaneous definitions for the UUCP package.
4 Copyright (C) 1991, 1992 Ian Lance Taylor
6 This file is part of the Taylor UUCP package.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 This program 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 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 The author of the program may be contacted at ian@airs.com or
23 c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
27 /* These structures are used in prototypes but are not defined in this
30 struct uuconf_timespan;
33 /* The tlog enumeration holds the different types of logging. */
36 /* Normal log entry. */
38 /* Error log entry. */
40 /* Fatal log entry. */
44 /* Debugging log entry. */
46 /* Start debugging log entry. */
48 /* Continue debugging log entry. */
50 /* End debugging log entry. */
55 /* The tstatus_type enumeration holds the kinds of status information
56 we put in the status file. The order of entries here corresponds
57 to the order of entries in the azStatus array. */
60 /* Conversation complete. */
62 /* Port unavailable. */
68 /* Handshake failed. */
69 STATUS_HANDSHAKE_FAILED,
70 /* Failed after logging in. */
72 /* Talking to remote system. */
74 /* Wrong time to call. */
76 /* Number of status values. */
80 /* An array to convert status entries to strings. If more status entries
81 are added, this array must be extended. */
82 extern const char *azStatus[];
84 /* The sstatus structure holds the contents of a system status file. */
87 /* Current status of conversation. */
88 enum tstatus_type ttype;
89 /* Number of failed retries. */
91 /* Time of last call in seconds since epoch (determined by
94 /* Number of seconds until a retry is permitted. */
98 /* How long we have to wait for the next call, given the number of retries
99 we have already made. This should probably be configurable. */
100 #define CRETRY_WAIT(c) ((c) * 10 * 60)
102 /* The scmd structure holds a complete UUCP command. */
105 /* Command ('S' for send, 'R' for receive, 'X' for execute, 'E' for
106 simple execution, 'H' for hangup, 'Y' for hangup confirm, 'N' for
109 /* At least one compiler needs an explicit padding byte here. */
111 /* Sequence handle for fsysdep_did_work. */
113 /* File name to transfer from. */
115 /* File name to transfer to. */
117 /* User who requested transfer. */
120 const char *zoptions;
121 /* Temporary file name ('S' and 'E'). */
123 /* Mode to give newly created file ('S' and 'E'). */
125 /* User to notify on remote system (optional; 'S' and 'E'). */
127 /* File size (-1 if not supplied) ('S', 'E' and 'R'). */
129 /* Command to execute ('E'). */
131 /* Position to restart from ('R'). */
137 /* We allow independent control over several different types of
138 debugging output, using a bit string with individual bits dedicated
139 to particular debugging types. */
141 /* The bit string is stored in iDebug. */
144 /* Debug abnormal events. */
145 #define DEBUG_ABNORMAL (01)
146 /* Debug chat scripts. */
147 #define DEBUG_CHAT (02)
148 /* Debug initial handshake. */
149 #define DEBUG_HANDSHAKE (04)
150 /* Debug UUCP protocol. */
151 #define DEBUG_UUCP_PROTO (010)
152 /* Debug protocols. */
153 #define DEBUG_PROTO (020)
154 /* Debug port actions. */
155 #define DEBUG_PORT (040)
156 /* Debug configuration files. */
157 #define DEBUG_CONFIG (0100)
158 /* Debug spool directory actions. */
159 #define DEBUG_SPOOLDIR (0200)
160 /* Debug executions. */
161 #define DEBUG_EXECUTE (0400)
162 /* Debug incoming data. */
163 #define DEBUG_INCOMING (01000)
164 /* Debug outgoing data. */
165 #define DEBUG_OUTGOING (02000)
167 /* Maximum possible value for iDebug. */
168 #define DEBUG_MAX (03777)
170 /* Intializer for array of debug names. The index of the name in the
171 array is the corresponding bit position in iDebug. We only check
172 for prefixes, so these names only need to be long enough to
173 distinguish each name from every other. The last entry must be
174 NULL. The string "all" is also recognized to turn on all
176 #define DEBUG_NAMES \
177 { "a", "ch", "h", "u", "pr", "po", "co", "s", "e", "i", "o", NULL }
179 /* The prefix to use to turn off all debugging. */
180 #define DEBUG_NONE "n"
182 /* Check whether a particular type of debugging is being done. */
183 #define FDEBUGGING(i) ((iDebug & (i)) != 0)
185 /* These macros are used to output debugging information. I use
186 several different macros depending on the number of arguments
187 because no macro can take a variable number of arguments and I
188 don't want to use double parentheses. */
189 #define DEBUG_MESSAGE0(i, z) \
190 do { if (FDEBUGGING (i)) ulog (LOG_DEBUG, (z)); } while (0)
191 #define DEBUG_MESSAGE1(i, z, a1) \
192 do { if (FDEBUGGING (i)) ulog (LOG_DEBUG, (z), (a1)); } while (0)
193 #define DEBUG_MESSAGE2(i, z, a1, a2) \
194 do { if (FDEBUGGING (i)) ulog (LOG_DEBUG, (z), (a1), (a2)); } while (0)
195 #define DEBUG_MESSAGE3(i, z, a1, a2, a3) \
198 if (FDEBUGGING (i)) \
199 ulog (LOG_DEBUG, (z), (a1), (a2), (a3)); \
202 #define DEBUG_MESSAGE4(i, z, a1, a2, a3, a4) \
205 if (FDEBUGGING (i)) \
206 ulog (LOG_DEBUG, (z), (a1), (a2), (a3), (a4)); \
210 #else /* DEBUG <= 1 */
212 /* If debugging information is not being compiled, provide versions of
213 the debugging macros which just disappear. */
214 #define DEBUG_MESSAGE0(i, z)
215 #define DEBUG_MESSAGE1(i, z, a1)
216 #define DEBUG_MESSAGE2(i, z, a1, a2)
217 #define DEBUG_MESSAGE3(i, z, a1, a2, a3)
218 #define DEBUG_MESSAGE4(i, z, a1, a2, a3, a4)
220 #endif /* DEBUG <= 1 */
224 /* Given an unknown system name, return information for an unknown
225 system. If unknown systems are not permitted, this returns FALSE.
226 Otherwise, it translates the name as necessary for the spool
227 directory, and fills in *qsys. */
228 extern boolean funknown_system P((pointer puuconf, const char *zsystem,
229 struct uuconf_system *qsys));
231 /* See whether a file belongs in the spool directory. */
232 extern boolean fspool_file P((const char *zfile));
234 /* See if the current time matches a time span. If not, return FALSE.
235 Otherwise, return TRUE and set *pival and *pcretry to the values
236 from the matching element of the span. */
237 extern boolean ftimespan_match P((const struct uuconf_timespan *qspan,
238 long *pival, int *pcretry));
240 /* Determine the maximum size that may ever be transferred, given a
241 timesize span. If there are any time gaps larger than 1 hour not
242 described by the timesize span, this returns -1. Otherwise it
243 returns the largest size that may be transferred at some time. */
244 extern long cmax_size_ever P((const struct uuconf_timespan *qtimesize));
246 /* Send mail about a file transfer. */
247 extern boolean fmail_transfer P((boolean fok, const char *zuser,
248 const char *zmail, const char *zwhy,
249 const char *zfrom, const char *zfromsys,
250 const char *zto, const char *ztosys,
251 const char *zsaved));
253 /* See whether a file is in one of a list of directories. The zpubdir
254 argument is used to pass the directory names to zsysdep_local_file.
255 If fcheck is FALSE, this does not check accessibility. Otherwise,
256 if freadable is TRUE, the user zuser must have read access to the
257 file and all appropriate directories; if freadable is FALSE zuser
258 must have write access to the appropriate directories. The zuser
259 argument may be NULL, in which case all users must have the
260 appropriate access (this is used for a remote request). */
261 extern boolean fin_directory_list P((const char *zfile,
268 /* Parse a command string. */
269 extern boolean fparse_cmd P((char *zcmd, struct scmd *qcmd));
271 /* Make a log entry. */
273 #define GNUC_VERSION __GNUC__
275 #define GNUC_VERSION 0
278 #if ANSI_C && HAVE_VFPRINTF
279 extern void ulog P((enum tlog ttype, const char *zfmt, ...))
281 __attribute__ ((format (printf, 2, 3)))
290 /* Report an error returned by one of the uuconf routines. */
291 extern void ulog_uuconf P((enum tlog ttype, pointer puuconf,
294 /* Set the function to call if a fatal error occurs. */
295 extern void ulog_fatal_fn P((void (*pfn) P((void))));
297 /* If ffile is TRUE, send log entries to the log file rather than to
299 extern void ulog_to_file P((pointer puuconf, boolean ffile));
301 /* Set the ID number used by the logging functions. */
302 extern void ulog_id P((int iid));
304 /* Set the system name used by the logging functions. */
305 extern void ulog_system P((const char *zsystem));
307 /* Set the system and user name used by the logging functions. */
308 extern void ulog_user P((const char *zuser));
310 /* Set the device name used by the logging functions. */
311 extern void ulog_device P((const char *zdevice));
313 /* Close the log file. */
314 extern void ulog_close P((void));
316 /* Make an entry in the statistics file. */
317 extern void ustats P((boolean fsucceeded, const char *zuser,
318 const char *zsystem, boolean fsent,
319 long cbytes, long csecs, long cmicros,
322 /* Close the statistics file. */
323 extern void ustats_close P((void));
326 /* A debugging routine to output a buffer. This outputs zhdr, the
327 buffer length clen, and the contents of the buffer in quotation
329 extern void udebug_buffer P((const char *zhdr, const char *zbuf,
332 /* A debugging routine to make a readable version of a character.
333 This takes a buffer at least 5 bytes long, and returns the length
334 of the string it put into it (not counting the null byte). */
335 extern size_t cdebug_char P((char *z, int ichar));
337 /* Parse a debugging option string. This can either be a number or a
338 comma separated list of debugging names. This returns a value for
340 extern int idebug_parse P((const char *));
342 #endif /* DEBUG <= 1 */
344 /* Copy one file to another. */
345 extern boolean fcopy_file P((const char *zfrom, const char *zto,
346 boolean fpublic, boolean fmkdirs));
348 /* Copy an open file to another. */
349 extern boolean fcopy_open_file P((openfile_t efrom, const char *zto,
350 boolean fpublic, boolean fmkdirs));
352 /* Translate escape sequences in a buffer, leaving the result in the
353 same buffer and returning the length. */
354 extern size_t cescape P((char *zbuf));
356 /* Get a buffer to hold a string of a given size. The buffer should
357 be freed with ubuffree. */
358 extern char *zbufalc P((size_t csize));
360 /* Call zbufalc to allocate a buffer and copy a string into it. */
361 extern char *zbufcpy P((const char *z));
363 /* Free up a buffer returned by zbufalc or zbufcpy. */
364 extern void ubuffree P((char *z));
366 /* Allocate memory without fail. */
367 extern pointer xmalloc P((size_t));
369 /* Realloc memory without fail. */
370 extern pointer xrealloc P((pointer, size_t));
372 /* Free memory (accepts NULL pointers, which some libraries erroneously
374 extern void xfree P((pointer));
376 /* Global variables. */
378 /* The name of the program being run. This is statically initialized,
379 although it should perhaps be set from argv[0]. */
380 extern char abProgram[];
382 /* When a signal occurs, the signal handlers sets the appropriate
383 element of the arrays afSignal and afLog_signal to TRUE. The
384 afSignal array is used to check whether a signal occurred. The
385 afLog_signal array tells ulog to log the signal; ulog will clear
386 the element after logging it, which means that if a signal comes in
387 at just the right moment it will not be logged. It will always be
388 recorded in afSignal, though. At the moment we handle 5 signals:
389 SIGHUP, SIGINT, SIGQUIT, SIGTERM and SIGPIPE (the Unix code also
390 handles SIGALRM). If we want to handle more, the afSignal array
391 must be extended; I see little point to handling any of the other
392 ANSI C or POSIX signals, as they are either unlikely to occur
393 (SIGABRT, SIGUSR1) or nearly impossible to handle cleanly (SIGILL,
394 SIGSEGV). SIGHUP is only logged if fLog_sighup is TRUE. */
395 #define INDEXSIG_SIGHUP (0)
396 #define INDEXSIG_SIGINT (1)
397 #define INDEXSIG_SIGQUIT (2)
398 #define INDEXSIG_SIGTERM (3)
399 #define INDEXSIG_SIGPIPE (4)
400 #define INDEXSIG_COUNT (5)
402 extern volatile sig_atomic_t afSignal[INDEXSIG_COUNT];
403 extern volatile sig_atomic_t afLog_signal[INDEXSIG_COUNT];
404 extern boolean fLog_sighup;
406 /* The names of the signals to use in error messages, as an
407 initializer for an array. */
408 #define INDEXSIG_NAMES \
409 { "hangup", "interrupt", "quit", "termination", "SIGPIPE" }
411 /* Check to see whether we've received a signal. It would be nice if
412 we could use a single variable for this, but we sometimes want to
413 clear our knowledge of a signal and that would cause race
414 conditions (clearing a single element of the array is not a race
415 assuming that we don't care about a particular signal, even if it
416 occurs after we've examined the array). */
417 #define FGOT_SIGNAL() \
418 (afSignal[INDEXSIG_SIGHUP] || afSignal[INDEXSIG_SIGINT] \
419 || afSignal[INDEXSIG_SIGQUIT] || afSignal[INDEXSIG_SIGTERM] \
420 || afSignal[INDEXSIG_SIGPIPE])
422 /* If we get a SIGINT in uucico, we continue the current communication
423 session but don't start any new ones. This macros checks for any
424 signal other than SIGINT, which means we should get out
426 #define FGOT_QUIT_SIGNAL() \
427 (afSignal[INDEXSIG_SIGHUP] || afSignal[INDEXSIG_SIGQUIT] \
428 || afSignal[INDEXSIG_SIGTERM] || afSignal[INDEXSIG_SIGPIPE])
430 /* File being sent. */
431 extern openfile_t eSendfile;
433 /* File being received. */
434 extern openfile_t eRecfile;
436 /* Device name to log. This is set by fconn_open. It may be NULL. */
437 extern char *zLdevice;
439 /* If not NULL, ulog calls this function before outputting anything.
440 This is used to support cu. */
441 extern void (*pfLstart) P((void));
443 /* If not NULL, ulog calls this function after outputting everything.
444 This is used to support cu. */
445 extern void (*pfLend) P((void));