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: ", 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], *newname;
137 sprintf(temp_buf, "Printcap entry for %s.",
139 Put_message(temp_buf);
142 GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]);
143 info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]);
144 GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]);
145 GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]);
146 if (!strcmp(info[PCAP_QSERVER], "[NONE]")) {
147 free(info[PCAP_QSERVER]);
148 info[PCAP_QSERVER] = strsave("\\[NONE\\]");
150 GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]);
151 info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]);
152 GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]);
153 GetValueFromUser("Price/page", &info[PCAP_PRICE]);
154 GetValueFromUser("Comments", &info[PCAP_COMMENTS]);
156 FreeAndClear(&info[PCAP_MODTIME], TRUE);
157 FreeAndClear(&info[PCAP_MODBY], TRUE);
158 FreeAndClear(&info[PCAP_MODWITH], TRUE);
163 /* ---------------- Printer Menu ------------------ */
165 /* Function Name: GetPcap
166 * Description: Get Printcap information
167 * Arguments: argc, argv - name of filsys in argv[1].
168 * Returns: DM_NORMAL.
179 top = GetPcapInfo(argv[1]); /* get info. */
180 Loop(top, (void *) PrintPcapInfo);
181 FreeQueue(top); /* clean the queue. */
185 /* Function Name: RealDeletePcap
186 * Description: Does the real deletion work.
187 * Arguments: info - array of char *'s containing all useful info.
188 * one_item - a Boolean that is true if only one item
189 * in queue that dumped us here.
194 RealDeletePcap(info, one_item)
199 char temp_buf[BUFSIZ];
201 if ( (stat = do_mr_query("delete_printcap_entry", 1,
202 &info[PCAP_NAME], Scream, NULL)) != 0)
203 com_err(program_name, stat, " printcap entry not deleted.");
205 Put_message("Printcap entry deleted.");
208 /* Function Name: DeletePcap
209 * Description: Delete a printcap entry given its name.
210 * Arguments: argc, argv - argv[1] is the name of the printer.
217 DeletePcap(argc, argv)
221 struct qelem *elem = GetPcapInfo(argv[1]);
222 QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
228 /* Function Name: AddPcap
229 * Description: Add a printcap entry
230 * Arguments: arc, argv - name of printer in argv[1].
231 * Returns: DM_NORMAL.
240 char *info[MAX_ARGS_SIZE], **args;
243 if ( !ValidName(argv[1]) )
246 if ( (stat = do_mr_query("get_printcap_entry", 1, argv + 1,
247 NullFunc, NULL)) == 0) {
248 Put_message ("A Printer by that name already exists.");
250 } else if (stat != MR_NO_MATCH) {
251 com_err(program_name, stat, " in AddPcap");
255 args = AskPcapInfo(SetDefaults(info, argv[1]));
257 if ( (stat = do_mr_query("add_printcap_entry", CountArgs(args), args,
258 NullFunc, NULL)) != 0)
259 com_err(program_name, stat, " in AddPcap");
266 /* Function Name: ChangePcap
267 * Description: Do the work of changing a pcap
268 * Arguments: argc, argv - printcap info
273 ChangePcap(info, one_item)
279 if ((stat = do_mr_query("delete_printcap_entry", 1, &info[PCAP_NAME],
280 Scream, NULL)) != 0) {
281 com_err(program_name, stat, " printcap entry not deleted.");
285 if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info,
286 NullFunc, NULL)) != 0)
287 com_err(program_name, stat, " in ChngPcap");
292 /* Function Name: ChngPcap
293 * Description: Update the printcap information
294 * Arguments: argc, argv - name of printer in argv[1].
295 * Returns: DM_NORMAL.
303 struct qelem *elem = GetPcapInfo(argv[1]);
304 QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
310 /* Function Name: SetPdDefaults
311 * Description: sets the default values for palladium additions.
312 * Arguments: info - an array of char pointers to recieve defaults.
313 * Returns: char ** (this array, now filled).
317 SetPdDefaults(info, name)
321 info[PD_NAME] = Strsave(name);
322 info[PD_IDENT] = Strsave("10000");
323 info[PD_HOST] = Strsave(DEFAULT_MACHINE);
324 info[PD_MODTIME] = info[PD_MODBY] = info[PD_MODWITH] = NULL;
330 /* Function Name: AskPalladiumInfo.
331 * Description: This function askes the user for information about a
332 * printer and saves it into a structure.
333 * Arguments: info - a pointer the the structure to put the
339 AskPalladiumInfo(info)
342 char temp_buf[BUFSIZ], *newname;
345 sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.",
347 Put_message(temp_buf);
350 GetValueFromUser("RPC Program Number", &info[PD_IDENT]);
351 GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]);
352 info[PD_HOST] = canonicalize_hostname(info[PD_HOST]);
354 FreeAndClear(&info[PD_MODTIME], TRUE);
355 FreeAndClear(&info[PD_MODBY], TRUE);
356 FreeAndClear(&info[PD_MODWITH], TRUE);
362 /* Function Name: PrintPalladiumInfo
363 * Description: Yet another specialized print function.
364 * Arguments: info - all info about this Printer.
369 PrintPalladiumInfo(info)
374 if (!info) { /* If no informaion */
375 Put_message("PrintPalladiumInfo called with null info!");
379 sprintf(buf, "Name: %-24s Program #: %s Host: %s",
380 info[PD_NAME], info[PD_IDENT], info[PD_HOST]);
382 sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME],
388 static struct qelem *
389 GetPalladiumInfo(name)
393 struct qelem *elem = NULL;
395 if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem))
397 com_err(program_name, status, NULL);
400 return(QueueTop(elem));
404 int ChangePalladium(info, one_item)
410 if ((status = do_mr_query("delete_palladium", 1, &info[PD_NAME],
411 Scream, NULL)) != 0) {
412 com_err(program_name, status, " palladium entry not deleted.");
415 AskPalladiumInfo(info);
416 if ((status = do_mr_query("add_palladium", CountArgs(info), info,
417 NullFunc, NULL)) != 0)
418 com_err(program_name, status, " in ChngPalladium");
423 /* Function Name: RealDeletePalladium
424 * Description: Does the real deletion work.
425 * Arguments: info - array of char *'s containing all useful info.
426 * one_item - a Boolean that is true if only one item
427 * in queue that dumped us here.
432 RealDeletePalladium(info, one_item)
437 char temp_buf[BUFSIZ];
439 if ( (stat = do_mr_query("delete_palladium", 1,
440 &info[PD_NAME], Scream, NULL)) != 0)
441 com_err(program_name, stat, " palladium entry not deleted.");
443 Put_message("Palladium entry deleted.");
447 int GetPalladium(argc, argv)
451 struct qelem *elem, *top;
454 top = GetPalladiumInfo(argv[1]);
455 Loop(top, PrintPalladiumInfo);
461 int AddPalladium(argc, argv)
465 char *info[MAX_ARGS_SIZE], **args;
468 if (!ValidName(argv[1]))
471 if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL))
473 Put_message("A server or supervisor by that name already exists.");
475 } else if (status != MR_NO_MATCH) {
476 com_err(program_name, status, " in AddPalladium");
480 args = AskPalladiumInfo(SetPdDefaults(info, argv[1]));
482 if ((status = do_mr_query("add_palladium", CountArgs(args), args,
484 com_err(program_name, status, " in AddPalladium");
491 int ChngPalladium(argc, argv)
495 struct qelem *elem = GetPalladiumInfo(argv[1]);
496 QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor");
502 int DeletePalladium(argc, argv)
506 struct qelem *elem = GetPalladiumInfo(argv[1]);
507 QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor");
512 int ShowPalladiumAlias(argc, argv)
516 struct qelem *elem = NULL;
517 char *qargv[3], buf[BUFSIZ];
521 qargv[1] = "PALLADIUM";
523 if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) {
524 com_err(program_name, status, " in ShowPalladiumAlias");
527 elem = QueueTop(elem);
529 while (elem != NULL) {
530 char **info = (char **) elem->q_data;
531 sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]);
536 FreeQueue(QueueTop(elem));
540 int AddPalladiumAlias(argc, argv)
548 qargv[1] = "PALLADIUM";
550 if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0)
551 com_err(program_name, status, " in AddPalladiumAlias");
555 int DeletePalladiumAlias(argc, argv)
563 qargv[1] = "PALLADIUM";
565 if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0)
566 com_err(program_name, status, " in DeletePalladiumAlias");