1 #if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
5 /* This is the file printer.c for the MOIRA Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the MOIRA database.
7 * It Contains: Functions for handling the printers.
10 * By: Theodore Y. Ts'o
16 * Copyright 1988 by the Massachusetts Institute of Technology.
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
26 #include <moira_site.h>
29 #include "mit-copyright.h"
34 #define DEFAULT_MACHINE "E40-PRINT-SERVER-1.MIT.EDU"
36 /* Function Name: SetDefaults
37 * Description: sets the default values for filesystem additions.
38 * Arguments: info - an array of char pointers to recieve defaults.
39 * Returns: char ** (this array, now filled).
43 SetDefaults(info, name)
49 strcpy(spool_dir, "/usr/spool/printer/");
50 strcat(spool_dir, name);
52 info[PCAP_NAME] = Strsave(name);
53 info[PCAP_SPOOL_HOST] = Strsave(DEFAULT_MACHINE);
54 info[PCAP_SPOOL_DIR] = Strsave(spool_dir);
55 info[PCAP_RPRINTER] = Strsave(name);
56 info[PCAP_COMMENTS] = Strsave("");
57 info[PCAP_MODTIME] = info[PCAP_MODBY] = info[PCAP_MODWITH] = NULL;
59 info[PCAP_END] = NULL;
63 /* Function Name: GetPcapInfo
64 * Description: Stores the info in a queue.
65 * Arguments: name - name of the item to get information on.
66 * Returns: a pointer to the first element in the queue or null
67 * if printer not found.
76 struct qelem *elem = NULL;
78 if ( (stat = do_mr_query("get_printcap", 1, &name,
79 StoreInfo, (char *)&elem)) != 0) {
80 com_err(program_name, stat, NULL);
83 return(QueueTop(elem));
86 /* Function Name: PrintPcapInfo
87 * Description: Yet another specialized print function.
88 * Arguments: info - all info about this Printer.
98 if (!info) { /* If no informaion */
99 Put_message("PrintPcapInfo called with null info!");
102 sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME],
103 info[PCAP_SPOOL_HOST]);
105 sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s",
106 info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]);
108 sprintf(buf, "Comments: ", info[PCAP_COMMENTS]);
110 sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME],
115 /* Function Name: AskPcapInfo.
116 * Description: This function askes the user for information about a
117 * printer and saves it into a structure.
118 * Arguments: info - a pointer the the structure to put the
127 char temp_buf[BUFSIZ], *newname;
130 sprintf(temp_buf, "Printcap entry for %s.",
132 Put_message(temp_buf);
135 GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]);
136 info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]);
137 GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]);
138 GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]);
139 GetValueFromUser("Comments", &info[PCAP_COMMENTS]);
141 FreeAndClear(&info[PCAP_MODTIME], TRUE);
142 FreeAndClear(&info[PCAP_MODBY], TRUE);
143 FreeAndClear(&info[PCAP_MODWITH], TRUE);
148 /* ---------------- Printer Menu ------------------ */
150 /* Function Name: GetPcap
151 * Description: Get Printcap information
152 * Arguments: argc, argv - name of filsys in argv[1].
153 * Returns: DM_NORMAL.
164 top = GetPcapInfo(argv[1]); /* get info. */
165 Loop(top, (void *) PrintPcapInfo);
166 FreeQueue(top); /* clean the queue. */
170 /* Function Name: RealDeletePcap
171 * Description: Does the real deletion work.
172 * Arguments: info - array of char *'s containing all useful info.
173 * one_item - a Boolean that is true if only one item
174 * in queue that dumped us here.
179 RealDeletePcap(info, one_item)
184 char temp_buf[BUFSIZ];
186 if ( (stat = do_mr_query("delete_printcap", 1,
187 &info[PCAP_NAME], Scream, NULL)) != 0)
188 com_err(program_name, stat, " printcap entry not deleted.");
190 Put_message("Printcap entry deleted.");
193 /* Function Name: DeletePcap
194 * Description: Delete a printcap entry given its name.
195 * Arguments: argc, argv - argv[1] is the name of the printer.
202 DeletePcap(argc, argv)
206 struct qelem *elem = GetPcapInfo(argv[1]);
207 QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
213 /* Function Name: AddPcap
214 * Description: Add a printcap entry
215 * Arguments: arc, argv - name of printer in argv[1].
216 * Returns: DM_NORMAL.
225 char *info[MAX_ARGS_SIZE], **args;
228 if ( !ValidName(argv[1]) )
231 if ( (stat = do_mr_query("get_printcap", 1, argv + 1,
232 NullFunc, NULL)) == 0) {
233 Put_message ("A Printer by that name already exists.");
235 } else if (stat != MR_NO_MATCH) {
236 com_err(program_name, stat, " in AddPcap");
240 args = AskPcapInfo(SetDefaults(info, argv[1]));
242 if ( (stat = do_mr_query("add_printcap", CountArgs(args), args,
243 NullFunc, NULL)) != 0)
244 com_err(program_name, stat, " in AddPcap");
251 /* Function Name: ChangePcap
252 * Description: Do the work of changing a pcap
253 * Arguments: argc, argv - printcap info
258 ChangePcap(info, one_item)
264 if ((stat = do_mr_query("delete_printcap", 1, &info[PCAP_NAME],
265 Scream, NULL)) != 0) {
266 com_err(program_name, stat, " printcap entry not deleted.");
270 if ((stat = do_mr_query("add_printcap", CountArgs(info), info,
271 NullFunc, NULL)) != 0)
272 com_err(program_name, stat, " in ChngPcap");
277 /* Function Name: ChngPcap
278 * Description: Update the printcap information
279 * Arguments: argc, argv - name of printer in argv[1].
280 * Returns: DM_NORMAL.
288 struct qelem *elem = GetPcapInfo(argv[1]);
289 QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
295 /* Function Name: SetPdDefaults
296 * Description: sets the default values for palladium additions.
297 * Arguments: info - an array of char pointers to recieve defaults.
298 * Returns: char ** (this array, now filled).
302 SetPdDefaults(info, name)
306 info[PD_NAME] = Strsave(name);
307 info[PD_IDENT] = Strsave("10000");
308 info[PD_HOST] = Strsave(DEFAULT_MACHINE);
309 info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL;
315 /* Function Name: AskPalladiumInfo.
316 * Description: This function askes the user for information about a
317 * printer and saves it into a structure.
318 * Arguments: info - a pointer the the structure to put the
324 AskPalladiumInfo(info)
327 char temp_buf[BUFSIZ], *newname;
330 sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.",
332 Put_message(temp_buf);
335 GetValueFromUser("RPC Program Number", &info[PD_IDENT]);
336 GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]);
337 info[PD_HOST] = canonicalize_hostname(info[PD_HOST]);
339 FreeAndClear(&info[PD_MODTIME], TRUE);
340 FreeAndClear(&info[PD_MODBY], TRUE);
341 FreeAndClear(&info[PD_MODWITH], TRUE);
347 /* Function Name: PrintPalladiumInfo
348 * Description: Yet another specialized print function.
349 * Arguments: info - all info about this Printer.
354 PrintPalladiumInfo(info)
359 if (!info) { /* If no informaion */
360 Put_message("PrintPalladiumInfo called with null info!");
364 sprintf(buf, "Name: %-24s Program #: %s Host: %s",
365 info[PD_NAME], info[PD_IDENT], info[PD_HOST]);
367 sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME],
373 static struct qelem *
374 GetPalladiumInfo(name)
378 struct qelem *elem = NULL;
380 if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem))
382 com_err(program_name, status, NULL);
385 return(QueueTop(elem));
389 int ChangePalladium(info, one_item)
395 if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME],
396 Scream, NULL)) != 0) {
397 com_err(program_name, status, " palladium entry not deleted.");
400 AskPalladiumInfo(info);
401 if ((status = do_mr_query("add_palladium", CountArgs(info), info,
402 NullFunc, NULL)) != 0)
403 com_err(program_name, status, " in ChngPalladium");
408 /* Function Name: RealDeletePalladium
409 * Description: Does the real deletion work.
410 * Arguments: info - array of char *'s containing all useful info.
411 * one_item - a Boolean that is true if only one item
412 * in queue that dumped us here.
417 RealDeletePalladium(info, one_item)
422 char temp_buf[BUFSIZ];
424 if ( (stat = do_mr_query("delete_palladium", 1,
425 &info[PD_NAME], Scream, NULL)) != 0)
426 com_err(program_name, stat, " palladium entry not deleted.");
428 Put_message("Palladium entry deleted.");
432 int GetPalladium(argc, argv)
436 struct qelem *elem, *top;
439 top = GetPalladiumInfo(argv[1]);
440 Loop(top, PrintPalladiumInfo);
446 int AddPalladium(argc, argv)
450 char *info[MAX_ARGS_SIZE], **args;
453 if (!ValidName(argv[1]))
456 if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL))
458 Put_message("A server or supervisor by that name already exists.");
460 } else if (status != MR_NO_MATCH) {
461 com_err(program_name, status, " in AddPalladium");
465 args = AskPalladiumInfo(SetPdDefaults(info, argv[1]));
467 if ((status = do_mr_query("add_palladium", CountArgs(args), args,
469 com_err(program_name, status, " in AddPalladium");
476 int ChngPalladium(argc, argv)
480 struct qelem *elem = GetPalladiumInfo(argv[1]);
481 QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor");
487 int DeletePalladium(argc, argv)
491 struct qelem *elem = GetPalladiumInfo(argv[1]);
492 QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor");
497 int ShowPalladiumAlias(argc, argv)
501 struct qelem *elem = NULL;
502 char *qargv[3], buf[BUFSIZ];
506 qargv[1] = "PALLADIUM";
508 if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) {
509 com_err(program_name, status, " in ShowPalladiumAlias");
512 elem = QueueTop(elem);
514 while (elem != NULL) {
515 char **info = (char **) elem->q_data;
516 sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]);
521 FreeQueue(QueueTop(elem));
525 int AddPalladiumAlias(argc, argv)
533 qargv[1] = "PALLADIUM";
535 if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0)
536 com_err(program_name, status, " in AddPalladiumAlias");
540 int DeletePalladiumAlias(argc, argv)
548 qargv[1] = "PALLADIUM";
550 if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0)
551 com_err(program_name, status, " in DeletePalladiumAlias");