]> andersk Git - moira.git/blob - clients/moira/printer.c
sync with server: "[" isn't a wildcard character in oracle, so don't
[moira.git] / clients / moira / printer.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif
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 <string.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, " in GetPcapInfo");
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 (GetValueFromUser("Quotaserver for this printer", &info[PCAP_QSERVER]) ==
152         SUB_ERROR)
153       return(NULL);
154     info[PCAP_QSERVER] = canonicalize_hostname(info[PCAP_QSERVER]);
155     if (GetYesNoValueFromUser("Authentication required", &info[PCAP_AUTH]) ==
156         SUB_ERROR)
157       return(NULL);
158     if (GetValueFromUser("Price/page", &info[PCAP_PRICE]) == SUB_ERROR)
159       return(NULL);
160     if (GetValueFromUser("Comments", &info[PCAP_COMMENTS]) == SUB_ERROR)
161       return(NULL);
162     
163     FreeAndClear(&info[PCAP_MODTIME], TRUE);
164     FreeAndClear(&info[PCAP_MODBY], TRUE);
165     FreeAndClear(&info[PCAP_MODWITH], TRUE);
166     
167     return(info);
168 }
169
170 /* ---------------- Printer Menu ------------------ */
171
172 /*      Function Name: GetPcap
173  *      Description: Get Printcap information
174  *      Arguments: argc, argv - name of filsys in argv[1].
175  *      Returns: DM_NORMAL.
176  */
177
178 /* ARGSUSED */
179 int
180 GetPcap(argc, argv)
181 int argc;
182 char **argv;
183 {
184     struct qelem *top;
185
186     top = GetPcapInfo(argv[1]); /* get info. */
187     Loop(top, (void *) PrintPcapInfo);
188     FreeQueue(top);             /* clean the queue. */
189     return (DM_NORMAL);
190 }
191
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.
197  *      Returns: none.
198  */
199
200 void
201 RealDeletePcap(info, one_item)
202 char ** info;
203 Bool one_item;
204 {
205     int stat;
206
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.");
210     else
211             Put_message("Printcap entry deleted.");
212 }
213
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.
217  *      Returns: none.
218  */
219
220 /* ARGSUSED */
221  
222 int
223 DeletePcap(argc, argv)
224 int argc;
225 char **argv;
226 {
227     struct qelem *elem = GetPcapInfo(argv[1]);
228     QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
229
230     FreeQueue(elem);
231     return (DM_NORMAL);
232 }
233
234 /*      Function Name: AddPcap
235  *      Description: Add a printcap entry
236  *      Arguments: arc, argv - name of printer in argv[1].
237  *      Returns: DM_NORMAL.
238  */
239
240 /* ARGSUSED */
241 int
242 AddPcap(argc, argv)
243 char **argv;
244 int argc;
245 {
246     char *info[MAX_ARGS_SIZE], **args;
247     int stat;
248
249     if ( !ValidName(argv[1]) )
250         return(DM_NORMAL);
251
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.");
255         return(DM_NORMAL);
256     } else if (stat != MR_NO_MATCH) {
257         com_err(program_name, stat, " in AddPcap");
258         return(DM_NORMAL);
259     } 
260
261     args = AskPcapInfo(SetDefaults(info, argv[1]));
262     if (args == NULL) {
263         Put_message("Aborted.");
264         return(DM_NORMAL);
265     }
266
267     if ( (stat = do_mr_query("add_printcap_entry", CountArgs(args), args, 
268                               NullFunc, NULL)) != 0)
269         com_err(program_name, stat, " in AddPcap");
270
271     FreeInfo(info);
272     return (DM_NORMAL);
273 }
274
275
276 /*      Function Name: ChangePcap
277  *      Description: Do the work of changing a pcap
278  *      Arguments: argc, argv - printcap info
279  *      Returns: 
280  */
281
282 int
283 ChangePcap(info, one_item)
284 char **info;
285 Bool one_item;
286 {
287     int stat;
288     char **oldinfo;
289
290     oldinfo = CopyInfo(info);
291     if (AskPcapInfo(info) == NULL)
292       return(DM_QUIT);
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.");
296         return(DM_NORMAL);
297     }
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");
304     }
305     FreeInfo(oldinfo);
306     return(DM_NORMAL);
307 }
308
309
310 /*      Function Name: ChngPcap
311  *      Description:   Update the printcap information
312  *      Arguments:     argc, argv - name of printer in argv[1].
313  *      Returns:       DM_NORMAL.
314  */
315
316 int
317 ChngPcap(argc, argv)
318     int argc;
319     char **argv;
320 {
321     struct qelem *elem = GetPcapInfo(argv[1]);
322     QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
323     FreeQueue(elem);
324     return(DM_NORMAL);
325 }
326
327
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).
332  */
333
334 static char ** 
335 SetPdDefaults(info, name)
336 char ** info;
337 char * name;
338 {
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;
343
344     info[PD_END] = NULL;
345     return(info);
346 }
347
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
352  *                             info into.
353  *      Returns: none.
354  */
355
356 static char **
357 AskPalladiumInfo(info)
358 char ** info;
359 {
360     char temp_buf[BUFSIZ];
361
362     Put_message("");
363     sprintf(temp_buf, "Palladium Server/Supervisor entry for %s.", 
364             info[PD_NAME]);
365     Put_message(temp_buf);
366     Put_message("");
367
368     if (GetValueFromUser("RPC Program Number", &info[PD_IDENT]) == SUB_ERROR)
369       return(NULL);
370     if (GetValueFromUser("Print Server/Supervisor Host", &info[PD_HOST]) ==
371         SUB_ERROR)
372       return(NULL);
373     info[PD_HOST] = canonicalize_hostname(info[PD_HOST]);
374     
375     FreeAndClear(&info[PD_MODTIME], TRUE);
376     FreeAndClear(&info[PD_MODBY], TRUE);
377     FreeAndClear(&info[PD_MODWITH], TRUE);
378     
379     return(info);
380 }
381
382
383 /*      Function Name: PrintPalladiumInfo
384  *      Description: Yet another specialized print function.
385  *      Arguments: info - all info about this Printer.
386  *      Returns: none
387  */
388
389 static void
390 PrintPalladiumInfo(info)
391 char ** info;
392 {
393     char buf[BUFSIZ];
394     
395     if (!info)  {               /* If no informaion */
396             Put_message("PrintPalladiumInfo called with null info!");
397             return;
398     }
399
400     sprintf(buf, "Name: %-24s Program #: %s  Host: %s",
401             info[PD_NAME], info[PD_IDENT], info[PD_HOST]);
402     Put_message(buf);
403     sprintf(buf, MOD_FORMAT, info[PD_MODBY], info[PD_MODTIME],
404             info[PD_MODWITH]);
405     Put_message(buf);
406 }
407
408
409 static struct qelem *
410 GetPalladiumInfo(name)
411 char *name;
412 {
413     int status;
414     struct qelem *elem = NULL;
415
416     if ((status = do_mr_query("get_palladium", 1, &name, StoreInfo, &elem))
417         != 0) {
418         com_err(program_name, status, " in GetPalladiumInfo");
419         return(NULL);
420     }
421     return(QueueTop(elem));
422 }
423
424
425 int ChangePalladium(info, one_item)
426 char **info;
427 Bool one_item;
428 {
429     int status;
430
431     if (AskPalladiumInfo(info) == NULL)
432       return(DM_QUIT);
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.");
436         return(DM_NORMAL);
437     }
438     if ((status = do_mr_query("add_palladium", CountArgs(info), info,
439                                NullFunc, NULL)) != 0)
440       com_err(program_name, status, " in ChngPalladium");
441     return(DM_NORMAL);
442 }
443
444
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.
450  *      Returns: none.
451  */
452
453 void
454 RealDeletePalladium(info, one_item)
455 char ** info;
456 Bool one_item;
457 {
458     int stat;
459
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.");
463     else
464             Put_message("Palladium entry deleted.");
465 }
466
467
468 int GetPalladium(argc, argv)
469 int argc;
470 char **argv;
471 {
472     struct qelem *top;
473
474     top = GetPalladiumInfo(argv[1]);
475     Loop(top, PrintPalladiumInfo);
476     FreeQueue(top);
477     return(DM_NORMAL);
478 }
479
480
481 int AddPalladium(argc, argv)
482 int argc;
483 char **argv;
484 {
485     char *info[MAX_ARGS_SIZE], **args;
486     int status;
487
488     if (!ValidName(argv[1]))
489       return(DM_NORMAL);
490
491     if ((status = do_mr_query("get_palladium", 1, &argv[1], NullFunc, NULL))
492         == 0) {
493         Put_message("A server or supervisor by that name already exists.");
494         return(DM_NORMAL);
495     } else if (status != MR_NO_MATCH) {
496         com_err(program_name, status, " in AddPalladium");
497         return(DM_NORMAL);
498     }
499
500     args = AskPalladiumInfo(SetPdDefaults(info, argv[1]));
501     if (args == NULL) {
502         Put_message("Aborted.");
503         return(DM_NORMAL);
504     }
505
506     if ((status = do_mr_query("add_palladium", CountArgs(args), args,
507                                Scream, NULL)) != 0)
508       com_err(program_name, status, " in AddPalladium");
509
510     FreeInfo(info);
511     return(DM_NORMAL);
512 }
513
514
515 int ChngPalladium(argc, argv)
516 int argc;
517 char **argv;
518 {
519     struct qelem *elem = GetPalladiumInfo(argv[1]);
520     QueryLoop(elem, NullPrint, ChangePalladium, "Change the server/supervisor");
521     FreeQueue(elem);
522     return(DM_NORMAL);
523 }
524
525
526 int DeletePalladium(argc, argv)
527 int argc;
528 char **argv;
529 {
530     struct qelem *elem = GetPalladiumInfo(argv[1]);
531     QueryLoop(elem, PrintPalladiumInfo, RealDeletePalladium, "Delete server/supervisor");
532     FreeQueue(elem);
533     return(DM_NORMAL);
534 }
535
536 int ShowPalladiumAlias(argc, argv)
537 int argc;
538 char **argv;
539 {
540     struct qelem *elem = NULL;
541     char *qargv[3], buf[BUFSIZ];
542     int status;
543
544     qargv[0] = argv[1];
545     qargv[1] = "PALLADIUM";
546     qargv[2] = argv[2];
547     if ((status = do_mr_query("get_alias", 3, qargv, StoreInfo, &elem)) != 0) {
548         com_err(program_name, status, " in ShowPalladiumAlias");
549         return(DM_NORMAL);
550     }
551     elem = QueueTop(elem);
552     Put_message("");
553     while (elem != NULL) {
554         char **info = (char **) elem->q_data;
555         sprintf(buf, "Printer: %-16s Server/Supervisor: %s", info[0], info[2]);
556         Put_message(buf);
557         elem = elem->q_forw;
558     }
559
560     FreeQueue(QueueTop(elem));
561     return(DM_NORMAL);
562 }
563
564 int AddPalladiumAlias(argc, argv)
565 int argc;
566 char **argv;
567 {
568     int status;
569     char *qargv[3];
570
571     qargv[0] = argv[1];
572     qargv[1] = "PALLADIUM";
573     qargv[2] = argv[2];
574     if ((status = do_mr_query("add_alias", 3, qargv, Scream, NULL)) != 0)
575       com_err(program_name, status, " in AddPalladiumAlias");
576     return(DM_NORMAL);
577 }
578
579 int DeletePalladiumAlias(argc, argv)
580 int argc;
581 char **argv;
582 {
583     int status;
584     char *qargv[3];
585
586     qargv[0] = argv[1];
587     qargv[1] = "PALLADIUM";
588     qargv[2] = argv[2];
589     if ((status = do_mr_query("delete_alias", 3, qargv, Scream, NULL)) != 0)
590       com_err(program_name, status, " in DeletePalladiumAlias");
591     return(DM_NORMAL);
592 }
This page took 0.561338 seconds and 5 git commands to generate.