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 (GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]) ==
154 info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]);
155 if (GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]) ==
158 if (GetValueFromUser("Price/page", &info[PCAP_PRICE]) == SUB_ERROR)
160 if (GetValueFromUser("Comments", &info[PCAP_COMMENTS]) == SUB_ERROR)
163 FreeAndClear(&info[PCAP_MODTIME], TRUE);
164 FreeAndClear(&info[PCAP_MODBY], TRUE);
165 FreeAndClear(&info[PCAP_MODWITH], TRUE);
170 /* ---------------- Printer Menu ------------------ */
172 /* Function Name: GetPcap
173 * Description: Get Printcap information
174 * Arguments: argc, argv - name of filsys in argv[1].
175 * Returns: DM_NORMAL.
186 top = GetPcapInfo(argv[1]); /* get info. */
187 Loop(top, (void *) PrintPcapInfo);
188 FreeQueue(top); /* clean the queue. */
192 /* Function Name: RealDeletePcap
193 * Description: Does the real deletion work.
194 * Arguments: info - array of char *'s containing all useful info.
195 * one_item - a Boolean that is true if only one item
196 * in queue that dumped us here.
201 RealDeletePcap(info, one_item)
207 if ( (stat = do_mr_query("delete_printcap_entry", 1,
208 &info[PCAP_NAME], Scream, NULL)) != 0)
209 com_err(program_name, stat, " printcap entry not deleted.");
211 Put_message("Printcap entry deleted.");
214 /* Function Name: DeletePcap
215 * Description: Delete a printcap entry given its name.
216 * Arguments: argc, argv - argv[1] is the name of the printer.
223 DeletePcap(argc, argv)
227 struct qelem *elem = GetPcapInfo(argv[1]);
228 QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
234 /* Function Name: AddPcap
235 * Description: Add a printcap entry
236 * Arguments: arc, argv - name of printer in argv[1].
237 * Returns: DM_NORMAL.
246 char *info[MAX_ARGS_SIZE], **args;
249 if ( !ValidName(argv[1]) )
252 if ( (stat = do_mr_query("get_printcap_entry", 1, argv + 1,
253 NullFunc, NULL)) == 0) {
254 Put_message ("A Printer by that name already exists.");
256 } else if (stat != MR_NO_MATCH) {
257 com_err(program_name, stat, " in AddPcap");
261 args = AskPcapInfo(SetDefaults(info, argv[1]));
263 Put_message("Aborted.");
267 if ( (stat = do_mr_query("add_printcap_entry", CountArgs(args), args,
268 NullFunc, NULL)) != 0)
269 com_err(program_name, stat, " in AddPcap");
276 /* Function Name: ChangePcap
277 * Description: Do the work of changing a pcap
278 * Arguments: argc, argv - printcap info
283 ChangePcap(info, one_item)
290 oldinfo = CopyInfo(info);
291 if (AskPcapInfo(info) == NULL)
293 if ((stat = do_mr_query("delete_printcap_entry", 1, &info[PCAP_NAME],
294 Scream, NULL)) != 0) {
295 com_err(program_name, stat, " printcap entry not deleted.");
298 if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info,
299 NullFunc, NULL)) != 0) {
300 com_err(program_name, stat, " in ChngPcap");
301 if ((stat = do_mr_query("add_printcap_entry", CountArgs(oldinfo) - 3,
302 oldinfo, NullFunc, NULL)) != 0)
303 com_err(program_name, stat, " while attempting to put old info back");
310 /* Function Name: ChngPcap
311 * Description: Update the printcap information
312 * Arguments: argc, argv - name of printer in argv[1].
313 * Returns: DM_NORMAL.
321 struct qelem *elem = GetPcapInfo(argv[1]);
322 QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
328 /* Function Name: SetPdDefaults
329 * Description: sets the default values for palladium additions.
330 * Arguments: info - an array of char pointers to recieve defaults.
331 * Returns: char ** (this array, now filled).
335 SetPdDefaults(info, name)
339 info[PD_NAME] = Strsave(name);
340 info[PD_IDENT] = Strsave("10000");
341 info[PD_HOST] = Strsave(DEFAULT_MACHINE);
342 info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL;
348 /* Function Name: AskPalladiumInfo.
349 * Description: This function askes the user for information about a
350 * printer and saves it into a structure.
351 * Arguments: info - a pointer the the structure to put the
357 AskPalladiumInfo(info)
360 char temp_buf[BUFSIZ];
363 sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.",
365 Put_message(temp_buf);
368 if (GetValueFromUser("RPC Program Number", &info[PD_IDENT]) == SUB_ERROR)
370 if (GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]) ==
373 info[PD_HOST] = canonicalize_hostname(info[PD_HOST]);
375 FreeAndClear(&info[PD_MODTIME], TRUE);
376 FreeAndClear(&info[PD_MODBY], TRUE);
377 FreeAndClear(&info[PD_MODWITH], TRUE);
383 /* Function Name: PrintPalladiumInfo
384 * Description: Yet another specialized print function.
385 * Arguments: info - all info about this Printer.
390 PrintPalladiumInfo(info)
395 if (!info) { /* If no informaion */
396 Put_message("PrintPalladiumInfo called with null info!");
400 sprintf(buf, "Name: %-24s Program #: %s Host: %s",
401 info[PD_NAME], info[PD_IDENT], info[PD_HOST]);
403 sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME],
409 static struct qelem *
410 GetPalladiumInfo(name)
414 struct qelem *elem = NULL;
416 if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem))
418 com_err(program_name, status, " in GetPalladiumInfo");
421 return(QueueTop(elem));
425 int ChangePalladium(info, one_item)
431 if (AskPalladiumInfo(info) == NULL)
433 if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME],
434 Scream, NULL)) != 0) {
435 com_err(program_name, status, " palladium entry not deleted.");
438 if ((status = do_mr_query("add_palladium", CountArgs(info), info,
439 NullFunc, NULL)) != 0)
440 com_err(program_name, status, " in ChngPalladium");
445 /* Function Name: RealDeletePalladium
446 * Description: Does the real deletion work.
447 * Arguments: info - array of char *'s containing all useful info.
448 * one_item - a Boolean that is true if only one item
449 * in queue that dumped us here.
454 RealDeletePalladium(info, one_item)
460 if ( (stat = do_mr_query("delete_palladium", 1,
461 &info[PD_NAME], Scream, NULL)) != 0)
462 com_err(program_name, stat, " palladium entry not deleted.");
464 Put_message("Palladium entry deleted.");
468 int GetPalladium(argc, argv)
474 top = GetPalladiumInfo(argv[1]);
475 Loop(top, PrintPalladiumInfo);
481 int AddPalladium(argc, argv)
485 char *info[MAX_ARGS_SIZE], **args;
488 if (!ValidName(argv[1]))
491 if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL))
493 Put_message("A server or supervisor by that name already exists.");
495 } else if (status != MR_NO_MATCH) {
496 com_err(program_name, status, " in AddPalladium");
500 args = AskPalladiumInfo(SetPdDefaults(info, argv[1]));
502 Put_message("Aborted.");
506 if ((status = do_mr_query("add_palladium", CountArgs(args), args,
508 com_err(program_name, status, " in AddPalladium");
515 int ChngPalladium(argc, argv)
519 struct qelem *elem = GetPalladiumInfo(argv[1]);
520 QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor");
526 int DeletePalladium(argc, argv)
530 struct qelem *elem = GetPalladiumInfo(argv[1]);
531 QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor");
536 int ShowPalladiumAlias(argc, argv)
540 struct qelem *elem = NULL;
541 char *qargv[3], buf[BUFSIZ];
545 qargv[1] = "PALLADIUM";
547 if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) {
548 com_err(program_name, status, " in ShowPalladiumAlias");
551 elem = QueueTop(elem);
553 while (elem != NULL) {
554 char **info = (char **) elem->q_data;
555 sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]);
560 FreeQueue(QueueTop(elem));
564 int AddPalladiumAlias(argc, argv)
572 qargv[1] = "PALLADIUM";
574 if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0)
575 com_err(program_name, status, " in AddPalladiumAlias");
579 int DeletePalladiumAlias(argc, argv)
587 qargv[1] = "PALLADIUM";
589 if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0)
590 com_err(program_name, status, " in DeletePalladiumAlias");