]> andersk Git - moira.git/blame - clients/moira/pobox.c
Code style cleanup. (No functional changes)
[moira.git] / clients / moira / pobox.c
CommitLineData
73c83e3d 1#if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
7798ebc3 3#endif
73c83e3d 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.
5eaef520 8 *
0a2c64cb 9 * Created: 7/10/88
10 * By: Chris D. Peterson
73c83e3d 11 *
12 * $Source$
13 * $Author$
14 * $Header$
5eaef520 15 *
0a2c64cb 16 * Copyright 1988 by the Massachusetts Institute of Technology.
73c83e3d 17 *
5eaef520 18 * For further information on copyright and distribution
73c83e3d 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
5eaef520 43static void PrintPOBox(char **info)
73c83e3d 44{
5eaef520 45 char buf[BUFSIZ];
46
47 sprintf(buf, "Address: %-10s Box: %-35s Type: %s", info[PO_NAME],
48 info[PO_BOX], info[PO_TYPE]);
49 Put_message(buf);
50 sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]);
51 Put_message(buf);
73c83e3d 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
5eaef520 60static void RealPrintPOMachines(char **info)
73c83e3d 61{
5eaef520 62 Print(1, info + 1, NULL);
73c83e3d 63}
64
65/* Function Name: PrintPOMachines
66 * Description: Prints all current post offices.
67 * Arguments: none.
0a2c64cb 68 * Returns: SUB_ERROR if the machines could not be printed.
73c83e3d 69 */
70
5eaef520 71static int PrintPOMachines(void)
73c83e3d 72{
5eaef520 73 register int status;
74 static char *args[] = {"pop", NULL};
75 struct qelem *top = NULL;
76
77 if ((status = do_mr_query("get_server_locations", CountArgs(args), args,
78 StoreInfo, (char *)&top)))
79 {
80 com_err(program_name, status, " in get_server_locations.");
81 return SUB_ERROR;
0a2c64cb 82 }
5eaef520 83
84 top = QueueTop(top);
85 Loop(top, RealPrintPOMachines);
86 FreeQueue(top);
87 return SUB_NORMAL;
73c83e3d 88}
89
90/* Function Name: GetUserPOBox
91 * Description: prints the users POBox information.
92 * Arguments: argc, argv - name of the user in argv[1].
93 * Returns: DM_NORMAL.
94 */
95
5eaef520 96int GetUserPOBox(int argc, char **argv)
73c83e3d 97{
5eaef520 98 register int status;
99 struct qelem *top = NULL;
100 char buf[BUFSIZ];
101
102 if (!ValidName(argv[1]))
103 return DM_NORMAL;
104
105 switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
106 (char *)&top)))
107 {
8defc06b 108 case MR_NO_MATCH:
5eaef520 109 Put_message("This user has no P.O. Box.");
110 break;
8defc06b 111 case MR_SUCCESS:
5eaef520 112 sprintf(buf, "Current pobox for user %s: \n", argv[1]);
113 Put_message("");
114 top = QueueTop(top);
115 Loop(top, PrintPOBox); /* should only return 1 box. */
116 FreeQueue(top);
117 break;
73c83e3d 118 default:
5eaef520 119 com_err(program_name, status, " in get_pobox.");
73c83e3d 120 }
5eaef520 121 return DM_NORMAL;
73c83e3d 122}
123
124/* Function Name: GetNewLocalPOBox
125 * Description: get the machine for a new local pop Box for the user.
126 * Arguments: local_user - name of the local user.
0a2c64cb 127 * Returns: machine - name of the machine for then new pop box, or NULL.
73c83e3d 128 */
129
5eaef520 130static char *GetNewLocalPOBox(char *local_user)
73c83e3d 131{
5eaef520 132 char temp_buf[BUFSIZ];
133
134 sprintf(temp_buf, "%s %s", "Pick one of the following",
135 "machines for this user's Post Office.");
136 Put_message(temp_buf);
137 Put_message("");
138 if (PrintPOMachines() == SUB_NORMAL)
139 {
140 Put_message("");
141 if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ))
142 return (char *) SUB_ERROR;
143 return canonicalize_hostname(strsave(temp_buf));
0a2c64cb 144 }
5eaef520 145 Put_message("Could not get machines to choose from, quitting.");
146 return (char *) SUB_ERROR;
73c83e3d 147}
148
149/* Function Name: SetUserPOBox
150 * Description: Addes or Chnages the P.O. Box for a user.
151 * Arguments: argc, argv - the login name of the user in argv[1].
152 * Returns: DM_NORMAL.
153 */
154
5eaef520 155int SetUserPOBox(int argc, char **argv)
73c83e3d 156{
5eaef520 157 register int status;
158 char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ];
159 char *temp_box;
160 struct qelem *top = NULL;
161 local_user = argv[1];
162
163 if (!ValidName(local_user))
164 return DM_NORMAL;
165
166 /* Print the current PO Box info */
167 switch ((status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
168 (char *)&top)))
169 {
2f25313c 170 case MR_SUCCESS:
5eaef520 171 sprintf(temp_buf, "Current pobox for user %s: \n", local_user);
172 Put_message("");
173 top = QueueTop(top);
174 Loop(top, PrintPOBox); /* should only return 1 box. */
175 FreeQueue(top);
176 break;
2f25313c 177 case MR_NO_MATCH:
5eaef520 178 Put_message("This user has no P.O. Box.");
179 break;
2f25313c 180 default:
5eaef520 181 com_err(program_name, status, " in get_pobox.");
182 return DM_NORMAL;
2f25313c 183 }
184
5eaef520 185 sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
186 switch (YesNoQuestion(temp_buf, TRUE))
187 {
73c83e3d 188 case TRUE:
5eaef520 189 type = LOCAL_BOX;
190 switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE))
191 {
73c83e3d 192 case TRUE:
5eaef520 193 switch ((status = do_mr_query("set_pobox_pop", 1,
194 &local_user, Scream, NULL)))
195 {
8defc06b 196 case MR_SUCCESS:
5eaef520 197 return DM_NORMAL;
8defc06b 198 case MR_MACHINE:
5eaef520 199 sprintf(temp_buf, "%s did not have a previous local PO Box.",
200 local_user);
201 Put_message(temp_buf);
202 if ((temp_box = GetNewLocalPOBox(local_user)) !=
203 (char *) SUB_ERROR)
204 {
205 strcpy(box, temp_box);
206 free(temp_box);
0a2c64cb 207 }
5eaef520 208 else
209 return DM_NORMAL;
210 break;
73c83e3d 211 default:
5eaef520 212 com_err(program_name, status, " in set_pobox_pop.");
213 return DM_NORMAL;
73c83e3d 214 }
5eaef520 215 break;
73c83e3d 216 case FALSE:
5eaef520 217 if ((temp_box = GetNewLocalPOBox(local_user)) !=
218 (char *) SUB_ERROR)
219 {
220 strcpy(box, temp_box);
221 free(temp_box);
6f368c99 222 }
5eaef520 223 else
224 return DM_NORMAL;
225 break;
73c83e3d 226 default:
5eaef520 227 return DM_NORMAL;
73c83e3d 228 }
5eaef520 229 break;
73c83e3d 230 case FALSE:
5eaef520 231 type = FOREIGN_BOX;
232 sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
233 switch (YesNoQuestion(temp_buf, TRUE))
234 {
73c83e3d 235 case TRUE:
5eaef520 236 if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ))
237 return DM_NORMAL;
238 break;
73c83e3d 239 case FALSE:
240 default:
5eaef520 241 return DM_NORMAL; /* ^C hit. */
73c83e3d 242 }
5eaef520 243 break;
73c83e3d 244 default: /* ^C hit. */
5eaef520 245 Put_message("Aborted.");
246 return DM_NORMAL;
73c83e3d 247 }
6f368c99 248
5eaef520 249 args[PO_NAME] = local_user;
250 args[PO_TYPE] = type;
251 args[PO_BOX] = box;
252 args[PO_END] = NULL;
253 if ((status = do_mr_query("set_pobox", CountArgs(args), args,
254 Scream, NULL)))
255 com_err(program_name, status, " in ChangeUserPOBox");
256 else
257 Put_message("PO Box assigned.");
258
259 return DM_NORMAL;
73c83e3d 260}
261
262/* Function Name: RemoveUserPOBox
263 * Description: Removes this users POBox.
264 * Arguments: argc, argv - name of user in argv[1].
265 * Returns: DM_NORMAL.
266 */
267
5eaef520 268int RemoveUserPOBox(int argc, char **argv)
73c83e3d 269{
5eaef520 270 register int status;
271 char temp_buf[BUFSIZ];
272
273 if (!ValidName(argv[1]))
274 return DM_NORMAL;
275
276 sprintf(temp_buf, "Are you sure that you want to remove %s's PO Box (y/n)",
277 argv[1]);
278
279 if (Confirm(temp_buf))
280 {
281 if ((status = do_mr_query("delete_pobox", 1, argv + 1,
282 Scream, NULL)))
283 com_err(program_name, status, " in delete_pobox.");
284 else
285 Put_message("PO Box removed.");
73c83e3d 286 }
5eaef520 287 return DM_NORMAL;
73c83e3d 288}
This page took 2.519549 seconds and 5 git commands to generate.