1 /* $NetBSD: supcparse.c,v 1.13 2006/03/22 16:54:26 christos Exp $ */
4 * Copyright (c) 1992 Carnegie Mellon University
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie Mellon
25 * the rights to redistribute these changes.
28 * sup collection parsing routines
29 **********************************************************************
32 * 7-July-93 Nate Williams at Montana State University
33 * Modified SUP to use gzip based compression when sending files
34 * across the network to save BandWidth
36 * Revision 1.6 92/08/11 12:07:38 mrt
37 * Added use-rel-suffix option corresponding to -u switch.
40 * Revision 1.5 92/02/08 18:24:19 mja
41 * Added "keep" supfile option, corresponding to -k switch.
44 * Revision 1.4 91/05/16 14:49:50 ern
45 * Change default timeout from none to 3 hours so we don't accumalute
46 * processes running sups to dead hosts especially for users.
47 * [91/05/16 14:49:21 ern]
50 * 10-Feb-88 Glenn Marcy (gm0w) at Carnegie-Mellon University
51 * Added timeout to backoff.
53 * 28-Jun-87 Glenn Marcy (gm0w) at Carnegie-Mellon University
54 * Added code for "release" support. Removed obsolete options.
56 * 25-May-87 Doug Philips (dwp) at Carnegie-Mellon University
57 * Split off from sup.c
59 **********************************************************************
63 #include "supextern.h"
66 extern char _argbreak
; /* break character from nxtarg */
68 typedef enum { /* supfile options */
69 OHOST
, OBASE
, OHOSTBASE
, OPREFIX
, ORELEASE
,
70 ONOTIFY
, OLOGIN
, OPASSWORD
, OCRYPT
,
71 OBACKUP
, ODELETE
, OEXECUTE
, OOLD
, OTIMEOUT
, OKEEP
, OURELSUF
,
81 { "hostbase", OHOSTBASE
},
82 { "prefix", OPREFIX
},
83 { "release", ORELEASE
},
84 { "notify", ONOTIFY
},
86 { "password", OPASSWORD
},
88 { "backup", OBACKUP
},
89 { "delete", ODELETE
},
90 { "execute", OEXECUTE
},
92 { "timeout", OTIMEOUT
},
94 { "use-rel-suffix", OURELSUF
},
95 { "compress", OCOMPRESS
}
98 static void passdelim(char **, char);
101 passdelim(char **ptr
, char delim
)
102 { /* skip over delimiter */
103 *ptr
= skipover(*ptr
, " \t");
104 if (_argbreak
!= delim
&& **ptr
== delim
) {
106 *ptr
= skipover(*ptr
, " \t");
111 parsecoll(COLLECTION
* c
, char *collname
, char *args
)
118 c
->Cname
= estrdup(collname
);
129 c
->Ctimeout
= 3 * 60 * 60; /* default to 3 hours instead of no
134 args
= skipover(args
, " \t");
135 while (*(arg
= nxtarg(&args
, " \t="))) {
136 for (opno
= 0; opno
< sizeofA(options
); opno
++)
137 if (strcmp(arg
, options
[opno
].op_name
) == 0)
139 if (opno
== sizeofA(options
)) {
140 logerr("Invalid supfile option %s for collection %s",
144 option
= options
[opno
].op_enum
;
147 passdelim(&args
, '=');
149 arg
= nxtarg(&args
, ", \t");
150 (void) Tinsert(&c
->Chtree
, arg
, FALSE
);
152 p
= skipover(args
, " \t");
155 } while (arg
!= args
);
158 passdelim(&args
, '=');
159 arg
= nxtarg(&args
, " \t");
160 c
->Cbase
= estrdup(arg
);
163 passdelim(&args
, '=');
164 arg
= nxtarg(&args
, " \t");
165 c
->Chbase
= estrdup(arg
);
168 passdelim(&args
, '=');
169 arg
= nxtarg(&args
, " \t");
170 c
->Cprefix
= estrdup(arg
);
173 passdelim(&args
, '=');
174 arg
= nxtarg(&args
, " \t");
175 c
->Crelease
= estrdup(arg
);
178 passdelim(&args
, '=');
179 arg
= nxtarg(&args
, " \t");
180 c
->Cnotify
= estrdup(arg
);
183 passdelim(&args
, '=');
184 arg
= nxtarg(&args
, " \t");
185 c
->Clogin
= estrdup(arg
);
188 passdelim(&args
, '=');
189 arg
= nxtarg(&args
, " \t");
190 c
->Cpswd
= estrdup(arg
);
193 passdelim(&args
, '=');
194 arg
= nxtarg(&args
, " \t");
195 c
->Ccrypt
= estrdup(arg
);
198 c
->Cflags
|= CFBACKUP
;
201 c
->Cflags
|= CFDELETE
;
204 c
->Cflags
|= CFEXECUTE
;
213 c
->Cflags
|= CFURELSUF
;
216 c
->Cflags
|= CFCOMPRESS
;
219 passdelim(&args
, '=');
220 arg
= nxtarg(&args
, " \t");
221 c
->Ctimeout
= atoi(arg
);
230 getwhen(char *collection
, char *relsuffix
)
232 char buf
[STRINGLENGTH
];
237 (void) sprintf(buf
, FILEWHEN
, collection
, relsuffix
);
239 if ((fp
= fopen(buf
, "r")) == NULL
)
242 if (fgets(buf
, sizeof(buf
), fp
) == NULL
) {
248 if ((tstamp
= strtol(buf
, &ep
, 0)) == -1 || *ep
!= '\n')
255 putwhen(char *fname
, time_t tstamp
)
258 if ((fp
= fopen(fname
, "w")) == NULL
)
260 if (fprintf(fp
, "%lu\n", (u_long
) tstamp
) < 0) {