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_QSERVER] = Strsave("\\[NONE\\]");
57 info[PCAP_AUTH] = Strsave("1");
58 info[PCAP_PRICE] = Strsave("10");
59 info[PCAP_COMMENTS] = Strsave("");
60 info[PCAP_MODTIME] = info[PCAP_MODBY] = info[PCAP_MODWITH] = NULL;
62 info[PCAP_END] = NULL;
66 /* Function Name: GetPcapInfo
67 * Description: Stores the info in a queue.
68 * Arguments: name - name of the item to get information on.
69 * Returns: a pointer to the first element in the queue or null
70 * if printer not found.
79 struct qelem *elem = NULL;
81 if ( (stat = do_mr_query("get_printcap_entry", 1, &name,
82 StoreInfo, (char *)&elem)) != 0) {
83 com_err(program_name, stat, " in GetPcapInfo");
86 return(QueueTop(elem));
89 /* Function Name: PrintPcapInfo
90 * Description: Yet another specialized print function.
91 * Arguments: info - all info about this Printer.
101 if (!info) { /* If no informaion */
102 Put_message("PrintPcapInfo called with null info!");
105 sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME],
106 info[PCAP_SPOOL_HOST]);
108 sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s",
109 info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]);
111 sprintf(buf, "Authentication: %-3s Price/page: %-3s Quota Server: %s",
112 atoi(info[PCAP_AUTH]) ? "yes" : "no",
113 info[PCAP_PRICE], info[PCAP_QSERVER]);
115 sprintf(buf, "Comments: %s", info[PCAP_COMMENTS]);
117 sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME],
122 /* Function Name: AskPcapInfo.
123 * Description: This function askes the user for information about a
124 * printer and saves it into a structure.
125 * Arguments: info - a pointer the the structure to put the
134 char temp_buf[BUFSIZ];
137 sprintf(temp_buf, "Printcap entry for %s.",
139 Put_message(temp_buf);
142 if (GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]) == SUB_ERROR)
144 info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]);
145 if (GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]) ==
148 if (GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]) ==
151 if (!strcmp(info[PCAP_QSERVER], "[NONE]")) {
152 free(info[PCAP_QSERVER]);
153 info[PCAP_QSERVER] = strsave("\\[NONE\\]");
155 if (GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]) ==
158 info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]);
159 if (GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]) ==
162 if (GetValueFromUser("Price/page", &info[PCAP_PRICE]) == SUB_ERROR)
164 if (GetValueFromUser("Comments", &info[PCAP_COMMENTS]) == SUB_ERROR)
167 FreeAndClear(&info[PCAP_MODTIME], TRUE);
168 FreeAndClear(&info[PCAP_MODBY], TRUE);
169 FreeAndClear(&info[PCAP_MODWITH], TRUE);
174 /* ---------------- Printer Menu ------------------ */
176 /* Function Name: GetPcap
177 * Description: Get Printcap information
178 * Arguments: argc, argv - name of filsys in argv[1].
179 * Returns: DM_NORMAL.
190 top = GetPcapInfo(argv[1]); /* get info. */
191 Loop(top, (void *) PrintPcapInfo);
192 FreeQueue(top); /* clean the queue. */
196 /* Function Name: RealDeletePcap
197 * Description: Does the real deletion work.
198 * Arguments: info - array of char *'s containing all useful info.
199 * one_item - a Boolean that is true if only one item
200 * in queue that dumped us here.
205 RealDeletePcap(info, one_item)
211 if ( (stat = do_mr_query("delete_printcap_entry", 1,
212 &info[PCAP_NAME], Scream, NULL)) != 0)
213 com_err(program_name, stat, " printcap entry not deleted.");
215 Put_message("Printcap entry deleted.");
218 /* Function Name: DeletePcap
219 * Description: Delete a printcap entry given its name.
220 * Arguments: argc, argv - argv[1] is the name of the printer.
227 DeletePcap(argc, argv)
231 struct qelem *elem = GetPcapInfo(argv[1]);
232 QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
238 /* Function Name: AddPcap
239 * Description: Add a printcap entry
240 * Arguments: arc, argv - name of printer in argv[1].
241 * Returns: DM_NORMAL.
250 char *info[MAX_ARGS_SIZE], **args;
253 if ( !ValidName(argv[1]) )
256 if ( (stat = do_mr_query("get_printcap_entry", 1, argv + 1,
257 NullFunc, NULL)) == 0) {
258 Put_message ("A Printer by that name already exists.");
260 } else if (stat != MR_NO_MATCH) {
261 com_err(program_name, stat, " in AddPcap");
265 args = AskPcapInfo(SetDefaults(info, argv[1]));
267 Put_message("Aborted.");
271 if ( (stat = do_mr_query("add_printcap_entry", CountArgs(args), args,
272 NullFunc, NULL)) != 0)
273 com_err(program_name, stat, " in AddPcap");
280 /* Function Name: ChangePcap
281 * Description: Do the work of changing a pcap
282 * Arguments: argc, argv - printcap info
287 ChangePcap(info, one_item)
294 oldinfo = CopyInfo(info);
295 if (AskPcapInfo(info) == NULL)
297 if ((stat = do_mr_query("delete_printcap_entry", 1, &info[PCAP_NAME],
298 Scream, NULL)) != 0) {
299 com_err(program_name, stat, " printcap entry not deleted.");
302 if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info,
303 NullFunc, NULL)) != 0) {
304 com_err(program_name, stat, " in ChngPcap");
305 if ((stat = do_mr_query("add_printcap_entry", CountArgs(oldinfo) - 3,
306 oldinfo, NullFunc, NULL)) != 0)
307 com_err(program_name, stat, " while attempting to put old info back");
314 /* Function Name: ChngPcap
315 * Description: Update the printcap information
316 * Arguments: argc, argv - name of printer in argv[1].
317 * Returns: DM_NORMAL.
325 struct qelem *elem = GetPcapInfo(argv[1]);
326 QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
332 /* Function Name: SetPdDefaults
333 * Description: sets the default values for palladium additions.
334 * Arguments: info - an array of char pointers to recieve defaults.
335 * Returns: char ** (this array, now filled).
339 SetPdDefaults(info, name)
343 info[PD_NAME] = Strsave(name);
344 info[PD_IDENT] = Strsave("10000");
345 info[PD_HOST] = Strsave(DEFAULT_MACHINE);
346 info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL;
352 /* Function Name: AskPalladiumInfo.
353 * Description: This function askes the user for information about a
354 * printer and saves it into a structure.
355 * Arguments: info - a pointer the the structure to put the
361 AskPalladiumInfo(info)
364 char temp_buf[BUFSIZ];
367 sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.",
369 Put_message(temp_buf);
372 if (GetValueFromUser("RPC Program Number", &info[PD_IDENT]) == SUB_ERROR)
374 if (GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]) ==
377 info[PD_HOST] = canonicalize_hostname(info[PD_HOST]);
379 FreeAndClear(&info[PD_MODTIME], TRUE);
380 FreeAndClear(&info[PD_MODBY], TRUE);
381 FreeAndClear(&info[PD_MODWITH], TRUE);
387 /* Function Name: PrintPalladiumInfo
388 * Description: Yet another specialized print function.
389 * Arguments: info - all info about this Printer.
394 PrintPalladiumInfo(info)
399 if (!info) { /* If no informaion */
400 Put_message("PrintPalladiumInfo called with null info!");
404 sprintf(buf, "Name: %-24s Program #: %s Host: %s",
405 info[PD_NAME], info[PD_IDENT], info[PD_HOST]);
407 sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME],
413 static struct qelem *
414 GetPalladiumInfo(name)
418 struct qelem *elem = NULL;
420 if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem))
422 com_err(program_name, status, " in GetPalladiumInfo");
425 return(QueueTop(elem));
429 int ChangePalladium(info, one_item)
435 if (AskPalladiumInfo(info) == NULL)
437 if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME],
438 Scream, NULL)) != 0) {
439 com_err(program_name, status, " palladium entry not deleted.");
442 if ((status = do_mr_query("add_palladium", CountArgs(info), info,
443 NullFunc, NULL)) != 0)
444 com_err(program_name, status, " in ChngPalladium");
449 /* Function Name: RealDeletePalladium
450 * Description: Does the real deletion work.
451 * Arguments: info - array of char *'s containing all useful info.
452 * one_item - a Boolean that is true if only one item
453 * in queue that dumped us here.
458 RealDeletePalladium(info, one_item)
464 if ( (stat = do_mr_query("delete_palladium", 1,
465 &info[PD_NAME], Scream, NULL)) != 0)
466 com_err(program_name, stat, " palladium entry not deleted.");
468 Put_message("Palladium entry deleted.");
472 int GetPalladium(argc, argv)
478 top = GetPalladiumInfo(argv[1]);
479 Loop(top, PrintPalladiumInfo);
485 int AddPalladium(argc, argv)
489 char *info[MAX_ARGS_SIZE], **args;
492 if (!ValidName(argv[1]))
495 if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL))
497 Put_message("A server or supervisor by that name already exists.");
499 } else if (status != MR_NO_MATCH) {
500 com_err(program_name, status, " in AddPalladium");
504 args = AskPalladiumInfo(SetPdDefaults(info, argv[1]));
506 Put_message("Aborted.");
510 if ((status = do_mr_query("add_palladium", CountArgs(args), args,
512 com_err(program_name, status, " in AddPalladium");
519 int ChngPalladium(argc, argv)
523 struct qelem *elem = GetPalladiumInfo(argv[1]);
524 QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor");
530 int DeletePalladium(argc, argv)
534 struct qelem *elem = GetPalladiumInfo(argv[1]);
535 QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor");
540 int ShowPalladiumAlias(argc, argv)
544 struct qelem *elem = NULL;
545 char *qargv[3], buf[BUFSIZ];
549 qargv[1] = "PALLADIUM";
551 if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) {
552 com_err(program_name, status, " in ShowPalladiumAlias");
555 elem = QueueTop(elem);
557 while (elem != NULL) {
558 char **info = (char **) elem->q_data;
559 sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]);
564 FreeQueue(QueueTop(elem));
568 int AddPalladiumAlias(argc, argv)
576 qargv[1] = "PALLADIUM";
578 if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0)
579 com_err(program_name, status, " in AddPalladiumAlias");
583 int DeletePalladiumAlias(argc, argv)
591 qargv[1] = "PALLADIUM";
593 if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0)
594 com_err(program_name, status, " in DeletePalladiumAlias");