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, NULL);
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)
293 if (AskPcapInfo(info) == NULL)
295 if ((stat = do_mr_query("delete_printcap_entry", 1, &info[PCAP_NAME],
296 Scream, NULL)) != 0) {
297 com_err(program_name, stat, " printcap entry not deleted.");
300 if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info,
301 NullFunc, NULL)) != 0)
302 com_err(program_name, stat, " in ChngPcap");
307 /* Function Name: ChngPcap
308 * Description: Update the printcap information
309 * Arguments: argc, argv - name of printer in argv[1].
310 * Returns: DM_NORMAL.
318 struct qelem *elem = GetPcapInfo(argv[1]);
319 QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
325 /* Function Name: SetPdDefaults
326 * Description: sets the default values for palladium additions.
327 * Arguments: info - an array of char pointers to recieve defaults.
328 * Returns: char ** (this array, now filled).
332 SetPdDefaults(info, name)
336 info[PD_NAME] = Strsave(name);
337 info[PD_IDENT] = Strsave("10000");
338 info[PD_HOST] = Strsave(DEFAULT_MACHINE);
339 info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL;
345 /* Function Name: AskPalladiumInfo.
346 * Description: This function askes the user for information about a
347 * printer and saves it into a structure.
348 * Arguments: info - a pointer the the structure to put the
354 AskPalladiumInfo(info)
357 char temp_buf[BUFSIZ];
360 sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.",
362 Put_message(temp_buf);
365 if (GetValueFromUser("RPC Program Number", &info[PD_IDENT]) == SUB_ERROR)
367 if (GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]) ==
370 info[PD_HOST] = canonicalize_hostname(info[PD_HOST]);
372 FreeAndClear(&info[PD_MODTIME], TRUE);
373 FreeAndClear(&info[PD_MODBY], TRUE);
374 FreeAndClear(&info[PD_MODWITH], TRUE);
380 /* Function Name: PrintPalladiumInfo
381 * Description: Yet another specialized print function.
382 * Arguments: info - all info about this Printer.
387 PrintPalladiumInfo(info)
392 if (!info) { /* If no informaion */
393 Put_message("PrintPalladiumInfo called with null info!");
397 sprintf(buf, "Name: %-24s Program #: %s Host: %s",
398 info[PD_NAME], info[PD_IDENT], info[PD_HOST]);
400 sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME],
406 static struct qelem *
407 GetPalladiumInfo(name)
411 struct qelem *elem = NULL;
413 if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem))
415 com_err(program_name, status, NULL);
418 return(QueueTop(elem));
422 int ChangePalladium(info, one_item)
428 if (AskPalladiumInfo(info) == NULL)
430 if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME],
431 Scream, NULL)) != 0) {
432 com_err(program_name, status, " palladium entry not deleted.");
435 if ((status = do_mr_query("add_palladium", CountArgs(info), info,
436 NullFunc, NULL)) != 0)
437 com_err(program_name, status, " in ChngPalladium");
442 /* Function Name: RealDeletePalladium
443 * Description: Does the real deletion work.
444 * Arguments: info - array of char *'s containing all useful info.
445 * one_item - a Boolean that is true if only one item
446 * in queue that dumped us here.
451 RealDeletePalladium(info, one_item)
457 if ( (stat = do_mr_query("delete_palladium", 1,
458 &info[PD_NAME], Scream, NULL)) != 0)
459 com_err(program_name, stat, " palladium entry not deleted.");
461 Put_message("Palladium entry deleted.");
465 int GetPalladium(argc, argv)
471 top = GetPalladiumInfo(argv[1]);
472 Loop(top, PrintPalladiumInfo);
478 int AddPalladium(argc, argv)
482 char *info[MAX_ARGS_SIZE], **args;
485 if (!ValidName(argv[1]))
488 if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL))
490 Put_message("A server or supervisor by that name already exists.");
492 } else if (status != MR_NO_MATCH) {
493 com_err(program_name, status, " in AddPalladium");
497 args = AskPalladiumInfo(SetPdDefaults(info, argv[1]));
499 Put_message("Aborted.");
503 if ((status = do_mr_query("add_palladium", CountArgs(args), args,
505 com_err(program_name, status, " in AddPalladium");
512 int ChngPalladium(argc, argv)
516 struct qelem *elem = GetPalladiumInfo(argv[1]);
517 QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor");
523 int DeletePalladium(argc, argv)
527 struct qelem *elem = GetPalladiumInfo(argv[1]);
528 QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor");
533 int ShowPalladiumAlias(argc, argv)
537 struct qelem *elem = NULL;
538 char *qargv[3], buf[BUFSIZ];
542 qargv[1] = "PALLADIUM";
544 if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) {
545 com_err(program_name, status, " in ShowPalladiumAlias");
548 elem = QueueTop(elem);
550 while (elem != NULL) {
551 char **info = (char **) elem->q_data;
552 sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]);
557 FreeQueue(QueueTop(elem));
561 int AddPalladiumAlias(argc, argv)
569 qargv[1] = "PALLADIUM";
571 if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0)
572 com_err(program_name, status, " in AddPalladiumAlias");
576 int DeletePalladiumAlias(argc, argv)
584 qargv[1] = "PALLADIUM";
586 if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0)
587 com_err(program_name, status, " in DeletePalladiumAlias");