]>
Commit | Line | Data |
---|---|---|
73c83e3d | 1 | #if (!defined(lint) && !defined(SABER)) |
2 | static char rcsid_module_c[] = "$Header$"; | |
3 | #endif lint | |
4 | ||
0a2c64cb | 5 | /* This is the file pobox.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 poboxes. | |
73c83e3d | 8 | * |
0a2c64cb | 9 | * Created: 7/10/88 |
10 | * By: Chris D. Peterson | |
73c83e3d | 11 | * |
12 | * $Source$ | |
13 | * $Author$ | |
14 | * $Header$ | |
15 | * | |
0a2c64cb | 16 | * Copyright 1988 by the Massachusetts Institute of Technology. |
73c83e3d | 17 | * |
18 | * For further information on copyright and distribution | |
19 | * see the file mit-copyright.h | |
20 | */ | |
21 | ||
73c83e3d | 22 | #include <stdio.h> |
23 | #include <strings.h> | |
24 | #include <ctype.h> | |
25 | #include <sms.h> | |
26 | #include <menu.h> | |
27 | ||
28 | #include "mit-copyright.h" | |
0a2c64cb | 29 | #include "defs.h" |
30 | #include "f_defs.h" | |
73c83e3d | 31 | #include "globals.h" |
32 | #include "infodefs.h" | |
33 | ||
34 | #define FOREIGN_BOX ("SMTP") | |
35 | #define LOCAL_BOX ("POP") | |
36 | ||
37 | /* Function Name: PrintPOBox | |
38 | * Description: Yet another specialized print function. | |
39 | * Arguments: info - all info about this PO_box. | |
40 | * Returns: SMS_CONT | |
41 | */ | |
42 | ||
43 | static void | |
44 | PrintPOBox(info) | |
45 | char ** info; | |
46 | { | |
47 | char buf[BUFSIZ]; | |
48 | ||
49 | sprintf(buf, "Address: %-10s Box: %-35s Type: %s", info[PO_NAME], | |
50 | info[PO_BOX], info[PO_TYPE]); | |
51 | Put_message(buf); | |
52 | } | |
53 | ||
54 | /* Function Name: RealPrintPOMachines | |
55 | * Description: Actually does the printing for PrintPOMachines. | |
56 | * Arguments: info, - name of machines in info[1]. | |
57 | * Returns: none. | |
58 | */ | |
59 | ||
60 | static void | |
61 | RealPrintPOMachines(info) | |
62 | char ** info; | |
63 | { | |
64 | Print(1, info + 1, (char *) NULL); | |
65 | } | |
66 | ||
67 | /* Function Name: PrintPOMachines | |
68 | * Description: Prints all current post offices. | |
69 | * Arguments: none. | |
0a2c64cb | 70 | * Returns: SUB_ERROR if the machines could not be printed. |
73c83e3d | 71 | */ |
72 | ||
0a2c64cb | 73 | static int |
73c83e3d | 74 | PrintPOMachines() |
75 | { | |
76 | register int status; | |
77 | static char * args[] = {"pop", NULL}; | |
78 | struct qelem * top = NULL; | |
79 | ||
80 | if ( (status = sms_query("get_server_locations", CountArgs(args), args, | |
0a2c64cb | 81 | StoreInfo, &top)) != SMS_SUCCESS) { |
82 | com_err(program_name, status, " in get_server_locations."); | |
83 | return(SUB_ERROR); | |
84 | } | |
73c83e3d | 85 | |
86 | top = QueueTop(top); | |
87 | Loop(top, RealPrintPOMachines); | |
88 | FreeQueue(top); | |
0a2c64cb | 89 | return(SUB_NORMAL); |
73c83e3d | 90 | } |
91 | ||
92 | /* Function Name: GetUserPOBox | |
93 | * Description: prints the users POBox information. | |
94 | * Arguments: argc, argv - name of the user in argv[1]. | |
95 | * Returns: DM_NORMAL. | |
96 | */ | |
97 | ||
98 | /* ARGSUSED */ | |
99 | int | |
100 | GetUserPOBox(argc, argv) | |
101 | int argc; | |
102 | char ** argv; | |
103 | { | |
104 | register int status; | |
105 | struct qelem * top = NULL; | |
106 | char buf[BUFSIZ]; | |
107 | ||
108 | if (!ValidName(argv[1])) | |
109 | return(DM_NORMAL); | |
110 | ||
111 | switch (status = sms_query("get_pobox", 1, argv + 1, StoreInfo, &top)) { | |
112 | case SMS_NO_MATCH: | |
113 | Put_message("This user has no P.O. Box."); | |
114 | break; | |
115 | case SMS_SUCCESS: | |
116 | sprintf(buf,"Current pobox for user %s: \n", argv[1]); | |
117 | Put_message(""); | |
118 | top = QueueTop(top); | |
119 | Loop(top, PrintPOBox); /* should only return 1 box. */ | |
120 | FreeQueue(top); | |
121 | break; | |
122 | default: | |
123 | com_err(program_name, status, "in get_pobox."); | |
124 | } | |
125 | return(DM_NORMAL); | |
126 | } | |
127 | ||
128 | /* Function Name: GetNewLocalPOBox | |
129 | * Description: get the machine for a new local pop Box for the user. | |
130 | * Arguments: local_user - name of the local user. | |
0a2c64cb | 131 | * Returns: machine - name of the machine for then new pop box, or NULL. |
73c83e3d | 132 | */ |
133 | ||
134 | static char * | |
135 | GetNewLocalPOBox(local_user) | |
136 | char * local_user; | |
137 | { | |
138 | char temp_buf[BUFSIZ]; | |
139 | ||
140 | sprintf(temp_buf, "%s did not have a previous local PO Box.", local_user); | |
141 | Put_message(temp_buf); | |
142 | sprintf(temp_buf,"%s %s", "Pick one of the following", | |
143 | "machines for this user's Post Office."); | |
144 | Put_message(temp_buf); | |
73c83e3d | 145 | Put_message(""); |
0a2c64cb | 146 | if (PrintPOMachines() == SUB_NORMAL) { |
147 | Put_message(""); | |
148 | Prompt_input("Which Machine? ", temp_buf, BUFSIZ); | |
149 | return( Strsave(temp_buf) ); | |
150 | } | |
151 | Put_message("Could not get machines to choose from, quitting."); | |
152 | return(NULL); | |
73c83e3d | 153 | } |
154 | ||
155 | /* Function Name: SetUserPOBox | |
156 | * Description: Addes or Chnages the P.O. Box for a user. | |
157 | * Arguments: argc, argv - the login name of the user in argv[1]. | |
158 | * Returns: DM_NORMAL. | |
159 | */ | |
160 | ||
161 | int | |
162 | SetUserPOBox(argc, argv) | |
163 | int argc; | |
164 | char **argv; | |
165 | { | |
166 | register int status; | |
167 | char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ]; | |
0a2c64cb | 168 | char *temp_box; |
73c83e3d | 169 | local_user = argv[1]; |
170 | ||
171 | if (!ValidName(local_user)) | |
172 | return(DM_NORMAL); | |
173 | ||
174 | (void) GetUserPOBox(argc, argv); /* print current info. */ | |
175 | ||
176 | sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user); | |
177 | switch (YesNoQuestion(temp_buf, TRUE)) { | |
178 | case TRUE: | |
179 | type = LOCAL_BOX; | |
180 | switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE)) { | |
181 | case TRUE: | |
182 | switch (status = sms_query("set_pobox_pop", 1, | |
183 | &local_user, Scream, NULL)) { | |
184 | case SMS_SUCCESS: | |
185 | return(DM_NORMAL); | |
186 | case SMS_MACHINE: | |
0a2c64cb | 187 | if ( (temp_box = GetNewLocalPOBox(local_user)) == SUB_NORMAL) { |
188 | strcpy(box, temp_box); | |
189 | free(temp_box); | |
190 | } | |
191 | else | |
192 | return(DM_NORMAL); | |
73c83e3d | 193 | break; |
194 | default: | |
195 | com_err(program_name, status, "in set_pobox_pop."); | |
196 | return(DM_NORMAL); | |
197 | } | |
198 | case FALSE: | |
0a2c64cb | 199 | if ( (temp_box = GetNewLocalPOBox(local_user)) == SUB_NORMAL) { |
200 | strcpy(box, temp_box); | |
201 | free(temp_box); | |
202 | } | |
203 | else | |
204 | return(DM_NORMAL); | |
73c83e3d | 205 | break; |
206 | default: | |
207 | return(DM_NORMAL); | |
208 | } | |
209 | break; | |
210 | case FALSE: | |
211 | type = FOREIGN_BOX; | |
212 | sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user); | |
213 | switch( YesNoQuestion(temp_buf, TRUE)) { | |
214 | case TRUE: | |
215 | if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ)) | |
216 | return(DM_NORMAL); | |
217 | break; | |
218 | case FALSE: | |
219 | default: | |
220 | return(DM_NORMAL); /* ^C hit. */ | |
221 | } | |
222 | ||
223 | args[PO_NAME] = local_user; | |
224 | args[PO_TYPE] = type; | |
225 | args[PO_BOX] = box; | |
226 | args[PO_END] = NULL; | |
227 | if ( (status = sms_query("set_pobox", CountArgs(args), args, | |
228 | Scream, NULL)) != SMS_SUCCESS ) | |
229 | com_err(program_name, status, " in ChangeUserPOBox"); | |
230 | else | |
231 | Put_message("PO Box assigned."); | |
232 | default: /* ^C hit. */ | |
233 | break; | |
234 | } | |
235 | return (DM_NORMAL); | |
236 | } | |
237 | ||
238 | /* Function Name: RemoveUserPOBox | |
239 | * Description: Removes this users POBox. | |
240 | * Arguments: argc, argv - name of user in argv[1]. | |
241 | * Returns: DM_NORMAL. | |
242 | */ | |
243 | ||
244 | /*ARGSUSED */ | |
245 | int | |
246 | RemoveUserPOBox(argc, argv) | |
247 | int argc; | |
248 | char ** argv; | |
249 | { | |
250 | register int status; | |
251 | char temp_buf[BUFSIZ]; | |
252 | ||
253 | if (!ValidName(argv[1])) | |
254 | return(DM_NORMAL); | |
255 | ||
256 | sprintf(temp_buf, | |
257 | "Are you sure that you want to remove %s's PO Box (y/n)", argv[1]); | |
258 | ||
259 | if (Confirm(temp_buf)) { | |
260 | if ( (status = sms_query("delete_pobox", 1, argv + 1, Scream, NULL)) != | |
261 | SMS_SUCCESS) | |
262 | com_err(program_name, status, "in delete_pobox."); | |
263 | else | |
264 | Put_message("PO Box removed."); | |
265 | } | |
266 | return(DM_NORMAL); | |
267 | } | |
268 | ||
269 | /* | |
270 | * Local Variables: | |
271 | * mode: c | |
272 | * c-indent-level: 4 | |
273 | * c-continued-statement-offset: 4 | |
274 | * c-brace-offset: -4 | |
275 | * c-argdecl-indent: 4 | |
276 | * c-label-offset: -4 | |
277 | * End: | |
278 | */ | |
279 | ||
280 | ||
281 | ||
282 | ||
283 | ||
284 | ||
285 | ||
286 | ||
287 | ||
288 | ||
289 | ||
290 | ||
291 | ||
292 | ||
293 | ||
294 |