]> andersk Git - moira.git/blame - clients/moira/pobox.c
removed lint
[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>
23#include <strings.h>
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);
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
60static void
61RealPrintPOMachines(info)
62char ** 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 73static int
73c83e3d 74PrintPOMachines()
75{
76 register int status;
77 static char * args[] = {"pop", NULL};
78 struct qelem * top = NULL;
79
8defc06b 80 if ( (status = do_mr_query("get_server_locations", CountArgs(args), args,
81 StoreInfo, (char *)&top)) != MR_SUCCESS) {
0a2c64cb 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 */
99int
100GetUserPOBox(argc, argv)
101int argc;
102char ** 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
8defc06b 111 switch (status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo,
14f99d7d 112 (char *)&top)) {
8defc06b 113 case MR_NO_MATCH:
73c83e3d 114 Put_message("This user has no P.O. Box.");
115 break;
8defc06b 116 case MR_SUCCESS:
73c83e3d 117 sprintf(buf,"Current pobox for user %s: \n", argv[1]);
118 Put_message("");
119 top = QueueTop(top);
120 Loop(top, PrintPOBox); /* should only return 1 box. */
121 FreeQueue(top);
122 break;
123 default:
124 com_err(program_name, status, "in get_pobox.");
125 }
126 return(DM_NORMAL);
127}
128
129/* Function Name: GetNewLocalPOBox
130 * Description: get the machine for a new local pop Box for the user.
131 * Arguments: local_user - name of the local user.
0a2c64cb 132 * Returns: machine - name of the machine for then new pop box, or NULL.
73c83e3d 133 */
134
135static char *
136GetNewLocalPOBox(local_user)
137char * local_user;
138{
139 char temp_buf[BUFSIZ];
140
141 sprintf(temp_buf, "%s did not have a previous local PO Box.", local_user);
142 Put_message(temp_buf);
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("");
149 Prompt_input("Which Machine? ", temp_buf, BUFSIZ);
2aaf43e0 150 return(canonicalize_hostname(strsave(temp_buf)));
0a2c64cb 151 }
152 Put_message("Could not get machines to choose from, quitting.");
6f368c99 153 return((char *) SUB_ERROR);
73c83e3d 154}
155
156/* Function Name: SetUserPOBox
157 * Description: Addes or Chnages the P.O. Box for a user.
158 * Arguments: argc, argv - the login name of the user in argv[1].
159 * Returns: DM_NORMAL.
160 */
161
162int
163SetUserPOBox(argc, argv)
164int argc;
165char **argv;
166{
167 register int status;
168 char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ];
0a2c64cb 169 char *temp_box;
73c83e3d 170 local_user = argv[1];
171
172 if (!ValidName(local_user))
173 return(DM_NORMAL);
174
175 (void) GetUserPOBox(argc, argv); /* print current info. */
176
177 sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
178 switch (YesNoQuestion(temp_buf, TRUE)) {
179 case TRUE:
180 type = LOCAL_BOX;
181 switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE)) {
182 case TRUE:
8defc06b 183 switch (status = do_mr_query("set_pobox_pop", 1,
14f99d7d 184 &local_user, Scream, NULL)) {
8defc06b 185 case MR_SUCCESS:
73c83e3d 186 return(DM_NORMAL);
8defc06b 187 case MR_MACHINE:
6f368c99 188 if ( (temp_box = GetNewLocalPOBox(local_user)) !=
189 (char *) SUB_ERROR) {
0a2c64cb 190 strcpy(box, temp_box);
191 free(temp_box);
192 }
193 else
194 return(DM_NORMAL);
73c83e3d 195 break;
196 default:
197 com_err(program_name, status, "in set_pobox_pop.");
198 return(DM_NORMAL);
199 }
6f368c99 200 break;
73c83e3d 201 case FALSE:
6f368c99 202 if ( (temp_box = GetNewLocalPOBox(local_user)) !=
203 (char *) SUB_ERROR) {
204 strcpy(box, temp_box);
205 free(temp_box);
206 }
207 else
208 return(DM_NORMAL);
73c83e3d 209 break;
210 default:
211 return(DM_NORMAL);
212 }
213 break;
214 case FALSE:
215 type = FOREIGN_BOX;
216 sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
217 switch( YesNoQuestion(temp_buf, TRUE)) {
218 case TRUE:
219 if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ))
220 return(DM_NORMAL);
221 break;
222 case FALSE:
223 default:
224 return(DM_NORMAL); /* ^C hit. */
225 }
226
73c83e3d 227 default: /* ^C hit. */
7b53f00f 228 type = "NONE";
73c83e3d 229 break;
230 }
6f368c99 231
232 args[PO_NAME] = local_user;
233 args[PO_TYPE] = type;
234 args[PO_BOX] = box;
235 args[PO_END] = NULL;
8defc06b 236 if ( (status = do_mr_query("set_pobox", CountArgs(args), args,
237 Scream, NULL)) != MR_SUCCESS )
6f368c99 238 com_err(program_name, status, " in ChangeUserPOBox");
239 else
240 Put_message("PO Box assigned.");
241
73c83e3d 242 return (DM_NORMAL);
243}
244
245/* Function Name: RemoveUserPOBox
246 * Description: Removes this users POBox.
247 * Arguments: argc, argv - name of user in argv[1].
248 * Returns: DM_NORMAL.
249 */
250
251/*ARGSUSED */
252int
253RemoveUserPOBox(argc, argv)
254int argc;
255char ** argv;
256{
257 register int status;
258 char temp_buf[BUFSIZ];
259
260 if (!ValidName(argv[1]))
261 return(DM_NORMAL);
262
263 sprintf(temp_buf,
264 "Are you sure that you want to remove %s's PO Box (y/n)", argv[1]);
265
266 if (Confirm(temp_buf)) {
8defc06b 267 if ( (status = do_mr_query("delete_pobox", 1, argv + 1,
268 Scream, NULL)) != MR_SUCCESS)
73c83e3d 269 com_err(program_name, status, "in delete_pobox.");
270 else
271 Put_message("PO Box removed.");
272 }
273 return(DM_NORMAL);
274}
This page took 0.104179 seconds and 5 git commands to generate.