]> andersk Git - moira.git/blob - clients/moira/printer.c
fix missing comments display on printcap; don't delete printcap if ^C
[moira.git] / clients / moira / printer.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif lint
4
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.
8  *      
9  *      Created:        8/16/88
10  *      By:             Theodore Y. Ts'o
11  *
12  *      $Source$
13  *      $Author$
14  *      $Header$
15  *      
16  *      Copyright 1988 by the Massachusetts Institute of Technology.
17  *
18  *      For further information on copyright and distribution 
19  *      see the file mit-copyright.h
20  */
21
22 #include <stdio.h>
23 #include <strings.h>
24 #include <ctype.h>
25 #include <moira.h>
26 #include <moira_site.h>
27 #include <menu.h>
28
29 #include "mit-copyright.h"
30 #include "defs.h"
31 #include "f_defs.h"
32 #include "globals.h"
33
34 #define DEFAULT_MACHINE "E40-PRINT-SERVER-1.MIT.EDU"
35
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).
40  */
41
42 static char ** 
43 SetDefaults(info, name)
44 char ** info;
45 char * name;
46 {
47     char spool_dir[256];
48
49     strcpy(spool_dir, "/usr/spool/printer/");
50     strcat(spool_dir, name);
51     
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;
61     
62     info[PCAP_END] = NULL;
63     return(info);
64 }
65
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.
71  */
72
73 static struct qelem *
74 GetPcapInfo(name)
75 char *name;
76
77 {
78     int stat;
79     struct qelem *elem = NULL;
80
81     if ( (stat = do_mr_query("get_printcap_entry", 1, &name,
82                               StoreInfo, (char *)&elem)) != 0) {
83             com_err(program_name, stat, NULL);
84             return(NULL);
85     }
86     return(QueueTop(elem));
87 }
88
89 /*      Function Name: PrintPcapInfo
90  *      Description: Yet another specialized print function.
91  *      Arguments: info - all info about this Printer.
92  *      Returns: none
93  */
94
95 static void
96 PrintPcapInfo(info)
97 char ** info;
98 {
99     char buf[BUFSIZ];
100     
101     if (!info)  {               /* If no informaion */
102             Put_message("PrintPcapInfo called with null info!");
103             return;
104     }
105     sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME],
106             info[PCAP_SPOOL_HOST]);
107     Put_message(buf);
108     sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s",
109             info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]);
110     Put_message(buf);
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]);
114     Put_message(buf);
115     sprintf(buf, "Comments: %s", info[PCAP_COMMENTS]);
116     Put_message(buf);
117     sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME], 
118             info[PCAP_MODWITH]);
119     Put_message(buf);
120 }
121
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
126  *                             info into.
127  *      Returns: none.
128  */
129
130 static char **
131 AskPcapInfo(info)
132 char ** info;
133 {
134     char temp_buf[BUFSIZ];
135
136     Put_message("");
137     sprintf(temp_buf, "Printcap entry for %s.", 
138             info[PCAP_NAME]);
139     Put_message(temp_buf);
140     Put_message("");
141
142     if (GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]) == SUB_ERROR)
143       return(NULL);
144     info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]);
145     if (GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]) ==
146         SUB_ERROR)
147       return(NULL);
148     if (GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]) ==
149         SUB_ERROR)
150       return(NULL);
151     if (!strcmp(info[PCAP_QSERVER], "[NONE]")) {
152         free(info[PCAP_QSERVER]);
153         info[PCAP_QSERVER] = strsave("\\[NONE\\]");
154     }
155     if (GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]) ==
156         SUB_ERROR)
157       return(NULL);
158     info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]);
159     if (GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]) ==
160         SUB_ERROR)
161       return(NULL);
162     if (GetValueFromUser("Price/page", &info[PCAP_PRICE]) == SUB_ERROR)
163       return(NULL);
164     if (GetValueFromUser("Comments", &info[PCAP_COMMENTS]) == SUB_ERROR)
165       return(NULL);
166     
167     FreeAndClear(&info[PCAP_MODTIME], TRUE);
168     FreeAndClear(&info[PCAP_MODBY], TRUE);
169     FreeAndClear(&info[PCAP_MODWITH], TRUE);
170     
171     return(info);
172 }
173
174 /* ---------------- Printer Menu ------------------ */
175
176 /*      Function Name: GetPcap
177  *      Description: Get Printcap information
178  *      Arguments: argc, argv - name of filsys in argv[1].
179  *      Returns: DM_NORMAL.
180  */
181
182 /* ARGSUSED */
183 int
184 GetPcap(argc, argv)
185 int argc;
186 char **argv;
187 {
188     struct qelem *top;
189
190     top = GetPcapInfo(argv[1]); /* get info. */
191     Loop(top, (void *) PrintPcapInfo);
192     FreeQueue(top);             /* clean the queue. */
193     return (DM_NORMAL);
194 }
195
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.
201  *      Returns: none.
202  */
203
204 void
205 RealDeletePcap(info, one_item)
206 char ** info;
207 Bool one_item;
208 {
209     int stat;
210
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.");
214     else
215             Put_message("Printcap entry deleted.");
216 }
217
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.
221  *      Returns: none.
222  */
223
224 /* ARGSUSED */
225  
226 int
227 DeletePcap(argc, argv)
228 int argc;
229 char **argv;
230 {
231     struct qelem *elem = GetPcapInfo(argv[1]);
232     QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
233
234     FreeQueue(elem);
235     return (DM_NORMAL);
236 }
237
238 /*      Function Name: AddPcap
239  *      Description: Add a printcap entry
240  *      Arguments: arc, argv - name of printer in argv[1].
241  *      Returns: DM_NORMAL.
242  */
243
244 /* ARGSUSED */
245 int
246 AddPcap(argc, argv)
247 char **argv;
248 int argc;
249 {
250     char *info[MAX_ARGS_SIZE], **args;
251     int stat;
252
253     if ( !ValidName(argv[1]) )
254         return(DM_NORMAL);
255
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.");
259         return(DM_NORMAL);
260     } else if (stat != MR_NO_MATCH) {
261         com_err(program_name, stat, " in AddPcap");
262         return(DM_NORMAL);
263     } 
264
265     args = AskPcapInfo(SetDefaults(info, argv[1]));
266     if (args == NULL) {
267         Put_message("Aborted.");
268         return(DM_NORMAL);
269     }
270
271     if ( (stat = do_mr_query("add_printcap_entry", CountArgs(args), args, 
272                               NullFunc, NULL)) != 0)
273         com_err(program_name, stat, " in AddPcap");
274
275     FreeInfo(info);
276     return (DM_NORMAL);
277 }
278
279
280 /*      Function Name: ChangePcap
281  *      Description: Do the work of changing a pcap
282  *      Arguments: argc, argv - printcap info
283  *      Returns: 
284  */
285
286 int
287 ChangePcap(info, one_item)
288 char **info;
289 Bool one_item;
290 {
291     int stat;
292
293     if (AskPcapInfo(info) == NULL)
294       return(DM_QUIT);
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.");
298         return(DM_NORMAL);
299     }
300     if ((stat = do_mr_query("add_printcap_entry", CountArgs(info), info,
301                              NullFunc, NULL)) != 0)
302         com_err(program_name, stat, " in ChngPcap");
303     return(DM_NORMAL);
304 }
305
306
307 /*      Function Name: ChngPcap
308  *      Description:   Update the printcap information
309  *      Arguments:     argc, argv - name of printer in argv[1].
310  *      Returns:       DM_NORMAL.
311  */
312
313 int
314 ChngPcap(argc, argv)
315     int argc;
316     char **argv;
317 {
318     struct qelem *elem = GetPcapInfo(argv[1]);
319     QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
320     FreeQueue(elem);
321     return(DM_NORMAL);
322 }
323
324
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).
329  */
330
331 static char ** 
332 SetPdDefaults(info, name)
333 char ** info;
334 char * name;
335 {
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;
340
341     info[PD_END] = NULL;
342     return(info);
343 }
344
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
349  *                             info into.
350  *      Returns: none.
351  */
352
353 static char **
354 AskPalladiumInfo(info)
355 char ** info;
356 {
357     char temp_buf[BUFSIZ];
358
359     Put_message("");
360     sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.", 
361             info[PD_NAME]);
362     Put_message(temp_buf);
363     Put_message("");
364
365     if (GetValueFromUser("RPC Program Number", &info[PD_IDENT]) == SUB_ERROR)
366       return(NULL);
367     if (GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]) ==
368         SUB_ERROR)
369       return(NULL);
370     info[PD_HOST] = canonicalize_hostname(info[PD_HOST]);
371     
372     FreeAndClear(&info[PD_MODTIME], TRUE);
373     FreeAndClear(&info[PD_MODBY], TRUE);
374     FreeAndClear(&info[PD_MODWITH], TRUE);
375     
376     return(info);
377 }
378
379
380 /*      Function Name: PrintPalladiumInfo
381  *      Description: Yet another specialized print function.
382  *      Arguments: info - all info about this Printer.
383  *      Returns: none
384  */
385
386 static void
387 PrintPalladiumInfo(info)
388 char ** info;
389 {
390     char buf[BUFSIZ];
391     
392     if (!info)  {               /* If no informaion */
393             Put_message("PrintPalladiumInfo called with null info!");
394             return;
395     }
396
397     sprintf(buf, "Name: %-24s Program #: %s  Host: %s",
398             info[PD_NAME], info[PD_IDENT], info[PD_HOST]);
399     Put_message(buf);
400     sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME],
401             info[PD_MODWITH]);
402     Put_message(buf);
403 }
404
405
406 static struct qelem *
407 GetPalladiumInfo(name)
408 char *name;
409 {
410     int status;
411     struct qelem *elem = NULL;
412
413     if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem))
414         != 0) {
415         com_err(program_name, status, NULL);
416         return(NULL);
417     }
418     return(QueueTop(elem));
419 }
420
421
422 int ChangePalladium(info, one_item)
423 char **info;
424 Bool one_item;
425 {
426     int status;
427
428     if (AskPalladiumInfo(info) == NULL)
429       return(DM_QUIT);
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.");
433         return(DM_NORMAL);
434     }
435     if ((status = do_mr_query("add_palladium", CountArgs(info), info,
436                                NullFunc, NULL)) != 0)
437       com_err(program_name, status, " in ChngPalladium");
438     return(DM_NORMAL);
439 }
440
441
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.
447  *      Returns: none.
448  */
449
450 void
451 RealDeletePalladium(info, one_item)
452 char ** info;
453 Bool one_item;
454 {
455     int stat;
456
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.");
460     else
461             Put_message("Palladium entry deleted.");
462 }
463
464
465 int GetPalladium(argc, argv)
466 int argc;
467 char **argv;
468 {
469     struct qelem *top;
470
471     top = GetPalladiumInfo(argv[1]);
472     Loop(top, PrintPalladiumInfo);
473     FreeQueue(top);
474     return(DM_NORMAL);
475 }
476
477
478 int AddPalladium(argc, argv)
479 int argc;
480 char **argv;
481 {
482     char *info[MAX_ARGS_SIZE], **args;
483     int status;
484
485     if (!ValidName(argv[1]))
486       return(DM_NORMAL);
487
488     if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL))
489         == 0) {
490         Put_message("A server or supervisor by that name already exists.");
491         return(DM_NORMAL);
492     } else if (status != MR_NO_MATCH) {
493         com_err(program_name, status, " in AddPalladium");
494         return(DM_NORMAL);
495     }
496
497     args = AskPalladiumInfo(SetPdDefaults(info, argv[1]));
498     if (args == NULL) {
499         Put_message("Aborted.");
500         return(DM_NORMAL);
501     }
502
503     if ((status = do_mr_query("add_palladium", CountArgs(args), args,
504                                Scream, NULL)) != 0)
505       com_err(program_name, status, " in AddPalladium");
506
507     FreeInfo(info);
508     return(DM_NORMAL);
509 }
510
511
512 int ChngPalladium(argc, argv)
513 int argc;
514 char **argv;
515 {
516     struct qelem *elem = GetPalladiumInfo(argv[1]);
517     QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor");
518     FreeQueue(elem);
519     return(DM_NORMAL);
520 }
521
522
523 int DeletePalladium(argc, argv)
524 int argc;
525 char **argv;
526 {
527     struct qelem *elem = GetPalladiumInfo(argv[1]);
528     QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor");
529     FreeQueue(elem);
530     return(DM_NORMAL);
531 }
532
533 int ShowPalladiumAlias(argc, argv)
534 int argc;
535 char **argv;
536 {
537     struct qelem *elem = NULL;
538     char *qargv[3], buf[BUFSIZ];
539     int status;
540
541     qargv[0] = argv[1];
542     qargv[1] = "PALLADIUM";
543     qargv[2] = argv[2];
544     if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) {
545         com_err(program_name, status, " in ShowPalladiumAlias");
546         return(DM_NORMAL);
547     }
548     elem = QueueTop(elem);
549     Put_message("");
550     while (elem != NULL) {
551         char **info = (char **) elem->q_data;
552         sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]);
553         Put_message(buf);
554         elem = elem->q_forw;
555     }
556
557     FreeQueue(QueueTop(elem));
558     return(DM_NORMAL);
559 }
560
561 int AddPalladiumAlias(argc, argv)
562 int argc;
563 char **argv;
564 {
565     int status;
566     char *qargv[3];
567
568     qargv[0] = argv[1];
569     qargv[1] = "PALLADIUM";
570     qargv[2] = argv[2];
571     if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0)
572       com_err(program_name, status, " in AddPalladiumAlias");
573     return(DM_NORMAL);
574 }
575
576 int DeletePalladiumAlias(argc, argv)
577 int argc;
578 char **argv;
579 {
580     int status;
581     char *qargv[3];
582
583     qargv[0] = argv[1];
584     qargv[1] = "PALLADIUM";
585     qargv[2] = argv[2];
586     if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0)
587       com_err(program_name, status, " in DeletePalladiumAlias");
588     return(DM_NORMAL);
589 }
This page took 0.106521 seconds and 5 git commands to generate.