]> andersk Git - moira.git/blame - clients/moira/printer.c
handle states better; free krbmap info when done
[moira.git] / clients / moira / printer.c
CommitLineData
cc5b487a 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 SMS Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the SMS 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 <sms.h>
cc3056a6 26#include <sms_app.h>
cc5b487a 27#include <menu.h>
28
29#include "mit-copyright.h"
30#include "defs.h"
31#include "f_defs.h"
32#include "globals.h"
cc5b487a 33
34#define PCAP_NAME 0
35#define PCAP_SPOOL_HOST 1
36#define PCAP_SPOOL_DIR 2
37#define PCAP_RPRINTER 3
38#define PCAP_COMMENTS 4
39#define PCAP_MODTIME 5
40#define PCAP_MODBY 6
41#define PCAP_MODWITH 7
42#define PCAP_END 8
43
44#define DEFAULT_MACHINE "E40-PRINT-SERVER-1.MIT.EDU"
45
46/* Function Name: SetDefaults
47 * Description: sets the default values for filesystem additions.
48 * Arguments: info - an array of char pointers to recieve defaults.
49 * Returns: char ** (this array, now filled).
50 */
51
52static char **
53SetDefaults(info, name)
54char ** info;
55char * name;
56{
57 char spool_dir[256];
58
59 strcpy(spool_dir, "/usr/spool/printer/");
60 strcat(spool_dir, name);
61
62 info[PCAP_NAME] = Strsave(name);
63 info[PCAP_SPOOL_HOST] = Strsave(DEFAULT_MACHINE);
64 info[PCAP_SPOOL_DIR] = Strsave(spool_dir);
65 info[PCAP_RPRINTER] = Strsave(name);
66 info[PCAP_COMMENTS] = Strsave("");
67 info[PCAP_MODTIME] = info[PCAP_MODBY] = info[PCAP_MODWITH] = NULL;
68
69 info[PCAP_END] = NULL;
70 return(info);
71}
72
73/* Function Name: GetPcapInfo
74 * Description: Stores the info in a queue.
75 * Arguments: name - name of the item to get information on.
76 * Returns: a pointer to the first element in the queue or null
77 * if printer not found.
78 */
79
80static struct qelem *
81GetPcapInfo(name)
82char *name;
83
84{
85 int stat;
86 struct qelem *elem = NULL;
87
14f99d7d 88 if ( (stat = do_sms_query("get_printcap", 1, &name,
89 StoreInfo, (char *)&elem)) != 0) {
cc5b487a 90 com_err(program_name, stat, NULL);
91 return(NULL);
92 }
93 return(QueueTop(elem));
94}
95
96/* Function Name: PrintPcapInfo
97 * Description: Yet another specialized print function.
98 * Arguments: info - all info about this Printer.
99 * Returns: none
100 */
101
102static void
103PrintPcapInfo(info)
104char ** info;
105{
106 char buf[BUFSIZ];
107
108 if (!info) { /* If no informaion */
109 Put_message("PrintPcapInfo called with null info!");
110 return;
111 }
112 sprintf(buf, "Printer: %-35s Spool host: %s", info[PCAP_NAME],
113 info[PCAP_SPOOL_HOST]);
114 Put_message(buf);
115 sprintf(buf, "Spool directory: %-27s Remote Printer Name: %s",
116 info[PCAP_SPOOL_DIR], info[PCAP_RPRINTER]);
117 Put_message(buf);
118 sprintf(buf, "Comments: ", info[PCAP_COMMENTS]);
119 Put_message(buf);
120 sprintf(buf, MOD_FORMAT, info[PCAP_MODBY], info[PCAP_MODTIME],
121 info[PCAP_MODWITH]);
122 Put_message(buf);
123}
124
125/* Function Name: AskPcapInfo.
126 * Description: This function askes the user for information about a
127 * printer and saves it into a structure.
128 * Arguments: info - a pointer the the structure to put the
129 * info into.
130 * Returns: none.
131 */
132
133static char **
134AskPcapInfo(info)
135char ** info;
136{
137 char temp_buf[BUFSIZ], *newname;
138
139 Put_message("");
140 sprintf(temp_buf, "Printcap entry for %s.",
141 info[FS_NAME]);
142 Put_message(temp_buf);
143 Put_message("");
144
145 GetValueFromUser("Printer Server", &info[PCAP_SPOOL_HOST]);
2aaf43e0 146 info[PCAP_SPOOL_HOST] = canonicalize_hostname(info[PCAP_SPOOL_HOST]);
cc5b487a 147 GetValueFromUser("Spool Directory", &info[PCAP_SPOOL_DIR]);
148 GetValueFromUser("Remote Printer Name", &info[PCAP_RPRINTER]);
149 GetValueFromUser("Comments", &info[PCAP_COMMENTS]);
150
151 FreeAndClear(&info[PCAP_MODTIME], TRUE);
152 FreeAndClear(&info[PCAP_MODBY], TRUE);
153 FreeAndClear(&info[PCAP_MODWITH], TRUE);
154
155 return(info);
156}
157
158/* ---------------- Printer Menu ------------------ */
159
160/* Function Name: GetPcap
161 * Description: Get Printcap information
162 * Arguments: argc, argv - name of filsys in argv[1].
163 * Returns: DM_NORMAL.
164 */
165
166/* ARGSUSED */
167int
168GetPcap(argc, argv)
169int argc;
170char **argv;
171{
172 struct qelem *top;
173
174 top = GetPcapInfo(argv[1]); /* get info. */
175 Loop(top, (void *) PrintPcapInfo);
176 FreeQueue(top); /* clean the queue. */
177 return (DM_NORMAL);
178}
179
180/* Function Name: RealDeletePcap
181 * Description: Does the real deletion work.
182 * Arguments: info - array of char *'s containing all useful info.
183 * one_item - a Boolean that is true if only one item
184 * in queue that dumped us here.
185 * Returns: none.
186 */
187
188void
189RealDeletePcap(info, one_item)
190char ** info;
191Bool one_item;
192{
193 int stat;
194 char temp_buf[BUFSIZ];
195
14f99d7d 196 if ( (stat = do_sms_query("delete_printcap", 1,
197 &info[FS_NAME], Scream, NULL)) != 0)
cc5b487a 198 com_err(program_name, stat, " printcap entry not deleted.");
199 else
200 Put_message("Printcap entry deleted.");
201}
202
203/* Function Name: DeletePcap
204 * Description: Delete a printcap entry given its name.
205 * Arguments: argc, argv - argv[1] is the name of the printer.
206 * Returns: none.
207 */
208
209/* ARGSUSED */
210
211int
212DeletePcap(argc, argv)
213int argc;
214char **argv;
215{
216 struct qelem *elem = GetPcapInfo(argv[1]);
217 QueryLoop(elem, PrintPcapInfo, RealDeletePcap, "Delete Printer");
218
219 FreeQueue(elem);
220 return (DM_NORMAL);
221}
222
223/* Function Name: AddPcap
224 * Description: Add a printcap entry
225 * Arguments: arc, argv - name of printer in argv[1].
226 * Returns: DM_NORMAL.
227 */
228
229/* ARGSUSED */
230int
231AddPcap(argc, argv)
232char **argv;
233int argc;
234{
235 char *info[MAX_ARGS_SIZE], **args;
236 int stat;
237
238 if ( !ValidName(argv[1]) )
239 return(DM_NORMAL);
240
14f99d7d 241 if ( (stat = do_sms_query("get_printcap", 1, argv + 1,
242 NullFunc, NULL)) == 0) {
cc5b487a 243 Put_message ("A Printer by that name already exists.");
244 return(DM_NORMAL);
245 } else if (stat != SMS_NO_MATCH) {
246 com_err(program_name, stat, " in AddPcap");
247 return(DM_NORMAL);
248 }
249
250 args = AskPcapInfo(SetDefaults(info, argv[1]));
251
14f99d7d 252 if ( (stat = do_sms_query("add_printcap", CountArgs(args), args,
253 NullFunc, NULL)) != 0)
cc5b487a 254 com_err(program_name, stat, " in AddPcap");
255
256 FreeInfo(info);
257 return (DM_NORMAL);
258}
259
260
f03f1f1b 261/* Function Name: ChangePcap
262 * Description: Do the work of changing a pcap
263 * Arguments: argc, argv - printcap info
264 * Returns:
265 */
266
267int
268ChangePcap(info, one_item)
269char **info;
270Bool one_item;
271{
272 int stat;
273
14f99d7d 274 if ((stat = do_sms_query("delete_printcap", 1, &info[FS_NAME],
275 Scream, NULL)) != 0) {
f03f1f1b 276 com_err(program_name, stat, " printcap entry not deleted.");
277 return(DM_NORMAL);
278 }
279 AskPcapInfo(info);
14f99d7d 280 if ((stat = do_sms_query("add_printcap", CountArgs(info), info,
281 NullFunc, NULL)) != 0)
f03f1f1b 282 com_err(program_name, stat, " in ChngPcap");
283 return(DM_NORMAL);
284}
285
286
287/* Function Name: ChngPcap
288 * Description: Update the printcap information
289 * Arguments: argc, argv - name of printer in argv[1].
290 * Returns: DM_NORMAL.
291 */
292
293int
294ChngPcap(argc, argv)
295 int argc;
296 char **argv;
297{
298 struct qelem *elem = GetPcapInfo(argv[1]);
299 QueryLoop(elem, NullPrint, ChangePcap, "Change the printer");
300 FreeQueue(elem);
301 return(DM_NORMAL);
302}
This page took 0.089359 seconds and 5 git commands to generate.