]> andersk Git - moira.git/blame - clients/moira/pobox.c
Change strings.h to string.h (we weren't using any BSD-isms anyway!)
[moira.git] / clients / moira / pobox.c
CommitLineData
73c83e3d 1#if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
3#endif lint
4
8defc06b 5/* This is the file pobox.c for the MOIRA Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the MOIRA database.
0a2c64cb 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>
24419c79 23#include <string.h>
73c83e3d 24#include <ctype.h>
8defc06b 25#include <moira.h>
26#include <moira_site.h>
73c83e3d 27#include <menu.h>
28
29#include "mit-copyright.h"
0a2c64cb 30#include "defs.h"
31#include "f_defs.h"
73c83e3d 32#include "globals.h"
73c83e3d 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.
8defc06b 40 * Returns: MR_CONT
73c83e3d 41 */
42
43static void
44PrintPOBox(info)
45char ** 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);
25ee8d50 52 sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]);
53 Put_message(buf);
73c83e3d 54}
55
56/* Function Name: RealPrintPOMachines
57 * Description: Actually does the printing for PrintPOMachines.
58 * Arguments: info, - name of machines in info[1].
59 * Returns: none.
60 */
61
62static void
63RealPrintPOMachines(info)
64char ** info;
65{
66 Print(1, info + 1, (char *) NULL);
67}
68
69/* Function Name: PrintPOMachines
70 * Description: Prints all current post offices.
71 * Arguments: none.
0a2c64cb 72 * Returns: SUB_ERROR if the machines could not be printed.
73c83e3d 73 */
74
0a2c64cb 75static int
73c83e3d 76PrintPOMachines()
77{
78 register int status;
79 static char * args[] = {"pop", NULL};
80 struct qelem * top = NULL;
81
8defc06b 82 if ( (status = do_mr_query("get_server_locations", CountArgs(args), args,
83 StoreInfo, (char *)&top)) != MR_SUCCESS) {
0a2c64cb 84 com_err(program_name, status, " in get_server_locations.");
85 return(SUB_ERROR);
86 }
73c83e3d 87
88 top = QueueTop(top);
89 Loop(top, RealPrintPOMachines);
90 FreeQueue(top);
0a2c64cb 91 return(SUB_NORMAL);
73c83e3d 92}
93
94/* Function Name: GetUserPOBox
95 * Description: prints the users POBox information.
96 * Arguments: argc, argv - name of the user in argv[1].
97 * Returns: DM_NORMAL.
98 */
99
100/* ARGSUSED */
101int
102GetUserPOBox(argc, argv)
103int argc;
104char ** argv;
105{
106 register int status;
107 struct qelem * top = NULL;
108 char buf[BUFSIZ];
109
110 if (!ValidName(argv[1]))
111 return(DM_NORMAL);
112
8defc06b 113 switch (status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
14f99d7d 114 (char *)&top)) {
8defc06b 115 case MR_NO_MATCH:
73c83e3d 116 Put_message("This user has no P.O. Box.");
117 break;
8defc06b 118 case MR_SUCCESS:
73c83e3d 119 sprintf(buf,"Current pobox for user %s: \n", argv[1]);
120 Put_message("");
121 top = QueueTop(top);
122 Loop(top, PrintPOBox); /* should only return 1 box. */
123 FreeQueue(top);
124 break;
125 default:
54a99f03 126 com_err(program_name, status, " in get_pobox.");
73c83e3d 127 }
128 return(DM_NORMAL);
129}
130
131/* Function Name: GetNewLocalPOBox
132 * Description: get the machine for a new local pop Box for the user.
133 * Arguments: local_user - name of the local user.
0a2c64cb 134 * Returns: machine - name of the machine for then new pop box, or NULL.
73c83e3d 135 */
136
137static char *
138GetNewLocalPOBox(local_user)
139char * local_user;
140{
141 char temp_buf[BUFSIZ];
142
73c83e3d 143 sprintf(temp_buf,"%s %s", "Pick one of the following",
144 "machines for this user's Post Office.");
145 Put_message(temp_buf);
73c83e3d 146 Put_message("");
0a2c64cb 147 if (PrintPOMachines() == SUB_NORMAL) {
148 Put_message("");
57bfac11 149 if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ))
150 return((char *) SUB_ERROR);
2aaf43e0 151 return(canonicalize_hostname(strsave(temp_buf)));
0a2c64cb 152 }
153 Put_message("Could not get machines to choose from, quitting.");
6f368c99 154 return((char *) SUB_ERROR);
73c83e3d 155}
156
157/* Function Name: SetUserPOBox
158 * Description: Addes or Chnages the P.O. Box for a user.
159 * Arguments: argc, argv - the login name of the user in argv[1].
160 * Returns: DM_NORMAL.
161 */
162
163int
164SetUserPOBox(argc, argv)
165int argc;
166char **argv;
167{
168 register int status;
169 char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ];
0a2c64cb 170 char *temp_box;
2f25313c 171 struct qelem * top = NULL;
73c83e3d 172 local_user = argv[1];
173
174 if (!ValidName(local_user))
175 return(DM_NORMAL);
176
2f25313c 177 /* Print the current PO Box info */
178 switch (status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
179 (char *)&top)) {
180 case MR_SUCCESS:
181 sprintf(temp_buf,"Current pobox for user %s: \n", local_user);
182 Put_message("");
183 top = QueueTop(top);
184 Loop(top, PrintPOBox); /* should only return 1 box. */
185 FreeQueue(top);
186 break;
187 case MR_NO_MATCH:
188 Put_message("This user has no P.O. Box.");
189 break;
190 default:
191 com_err(program_name, status, " in get_pobox.");
192 return(DM_NORMAL);
193 }
194
73c83e3d 195 sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
196 switch (YesNoQuestion(temp_buf, TRUE)) {
197 case TRUE:
198 type = LOCAL_BOX;
199 switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE)) {
200 case TRUE:
8defc06b 201 switch (status = do_mr_query("set_pobox_pop", 1,
14f99d7d 202 &local_user, Scream, NULL)) {
8defc06b 203 case MR_SUCCESS:
73c83e3d 204 return(DM_NORMAL);
8defc06b 205 case MR_MACHINE:
54a99f03 206 sprintf(temp_buf, "%s did not have a previous local PO Box.",
207 local_user);
208 Put_message(temp_buf);
6f368c99 209 if ( (temp_box = GetNewLocalPOBox(local_user)) !=
210 (char *) SUB_ERROR) {
0a2c64cb 211 strcpy(box, temp_box);
212 free(temp_box);
213 }
214 else
215 return(DM_NORMAL);
73c83e3d 216 break;
217 default:
2f25313c 218 com_err(program_name, status, " in set_pobox_pop.");
73c83e3d 219 return(DM_NORMAL);
220 }
6f368c99 221 break;
73c83e3d 222 case FALSE:
6f368c99 223 if ( (temp_box = GetNewLocalPOBox(local_user)) !=
224 (char *) SUB_ERROR) {
225 strcpy(box, temp_box);
226 free(temp_box);
227 }
228 else
229 return(DM_NORMAL);
73c83e3d 230 break;
231 default:
232 return(DM_NORMAL);
233 }
234 break;
235 case FALSE:
236 type = FOREIGN_BOX;
237 sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
238 switch( YesNoQuestion(temp_buf, TRUE)) {
239 case TRUE:
240 if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ))
241 return(DM_NORMAL);
242 break;
243 case FALSE:
244 default:
245 return(DM_NORMAL); /* ^C hit. */
246 }
25ee8d50 247 break;
73c83e3d 248 default: /* ^C hit. */
57bfac11 249 Put_message("Aborted.");
250 return(DM_NORMAL);
73c83e3d 251 }
6f368c99 252
253 args[PO_NAME] = local_user;
254 args[PO_TYPE] = type;
255 args[PO_BOX] = box;
256 args[PO_END] = NULL;
8defc06b 257 if ( (status = do_mr_query("set_pobox", CountArgs(args), args,
258 Scream, NULL)) != MR_SUCCESS )
6f368c99 259 com_err(program_name, status, " in ChangeUserPOBox");
260 else
261 Put_message("PO Box assigned.");
262
73c83e3d 263 return (DM_NORMAL);
264}
265
266/* Function Name: RemoveUserPOBox
267 * Description: Removes this users POBox.
268 * Arguments: argc, argv - name of user in argv[1].
269 * Returns: DM_NORMAL.
270 */
271
272/*ARGSUSED */
273int
274RemoveUserPOBox(argc, argv)
275int argc;
276char ** argv;
277{
278 register int status;
279 char temp_buf[BUFSIZ];
280
281 if (!ValidName(argv[1]))
282 return(DM_NORMAL);
283
284 sprintf(temp_buf,
285 "Are you sure that you want to remove %s's PO Box (y/n)", argv[1]);
286
287 if (Confirm(temp_buf)) {
8defc06b 288 if ( (status = do_mr_query("delete_pobox", 1, argv + 1,
289 Scream, NULL)) != MR_SUCCESS)
2f25313c 290 com_err(program_name, status, " in delete_pobox.");
73c83e3d 291 else
292 Put_message("PO Box removed.");
293 }
294 return(DM_NORMAL);
295}
This page took 0.121117 seconds and 5 git commands to generate.