]> andersk Git - moira.git/blob - clients/moira/pobox.c
fixed a couple of typos in error messages
[moira.git] / clients / moira / pobox.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif lint
4
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.
7  *      It Contains: Functions for handling the poboxes.
8  *      
9  *      Created:        7/10/88
10  *      By:             Chris D. Peterson
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 <moira.h>
26 #include <moira_site.h>
27 #include <menu.h>
28
29 #include "mit-copyright.h"
30 #include "defs.h"
31 #include "f_defs.h"
32 #include "globals.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: MR_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     sprintf(buf, MOD_FORMAT, info[4], info[3], info[5]);
53     Put_message(buf);
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
62 static void
63 RealPrintPOMachines(info)
64 char ** 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.
72  *      Returns: SUB_ERROR if the machines could not be printed.
73  */
74
75 static int
76 PrintPOMachines()
77 {
78     register int status;
79     static char * args[] = {"pop", NULL};
80     struct qelem * top = NULL;
81     
82     if ( (status = do_mr_query("get_server_locations", CountArgs(args), args,
83                                 StoreInfo, (char *)&top)) != MR_SUCCESS) {
84         com_err(program_name, status, " in get_server_locations.");
85         return(SUB_ERROR);
86     }
87     
88     top = QueueTop(top);
89     Loop(top, RealPrintPOMachines);
90     FreeQueue(top);
91     return(SUB_NORMAL);
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 */
101 int
102 GetUserPOBox(argc, argv)
103 int argc;
104 char ** 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     
113     switch (status = do_mr_query("get_pobox", 1, argv + 1, StoreInfo, 
114                                   (char *)&top)) {
115     case MR_NO_MATCH:
116         Put_message("This user has no P.O. Box.");
117         break;
118     case MR_SUCCESS:
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:
126         com_err(program_name, status, " in get_pobox.");
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.
134  *      Returns: machine - name of the machine for then new pop box, or NULL.
135  */
136
137 static char *
138 GetNewLocalPOBox(local_user)
139 char * local_user;
140 {
141     char temp_buf[BUFSIZ];
142
143     sprintf(temp_buf,"%s %s", "Pick one of the following",
144             "machines for this user's Post Office.");
145     Put_message(temp_buf);
146     Put_message("");
147     if (PrintPOMachines() == SUB_NORMAL) {
148         Put_message("");
149         if (!Prompt_input("Which Machine? ", temp_buf, BUFSIZ))
150           return((char *) SUB_ERROR);
151         return(canonicalize_hostname(strsave(temp_buf)));
152     }
153     Put_message("Could not get machines to choose from, quitting.");
154     return((char *) SUB_ERROR);
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
163 int
164 SetUserPOBox(argc, argv)
165 int argc;
166 char **argv;
167 {
168     register int status;
169     char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ];
170     char *temp_box;
171     struct qelem * top = NULL;
172     local_user = argv[1];
173
174     if (!ValidName(local_user))
175         return(DM_NORMAL);
176     
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
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:
201             switch (status = do_mr_query("set_pobox_pop", 1, 
202                                           &local_user, Scream, NULL)) {
203             case MR_SUCCESS:
204                 return(DM_NORMAL);
205             case MR_MACHINE:
206                 sprintf(temp_buf, "%s did not have a previous local PO Box.",
207                         local_user);
208                 Put_message(temp_buf);
209                 if ( (temp_box = GetNewLocalPOBox(local_user)) !=
210                         (char *) SUB_ERROR) {
211                     strcpy(box, temp_box);
212                     free(temp_box);
213                 }
214                 else
215                     return(DM_NORMAL);
216                 break;
217             default:
218                 com_err(program_name, status, " in set_pobox_pop.");
219                 return(DM_NORMAL);
220             }
221             break;
222         case FALSE:
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);
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         }
247         break;
248     default:                    /* ^C hit. */
249         Put_message("Aborted.");
250         return(DM_NORMAL);
251     }
252
253     args[PO_NAME] = local_user;
254     args[PO_TYPE] = type;
255     args[PO_BOX] = box;
256     args[PO_END] = NULL;
257     if ( (status = do_mr_query("set_pobox", CountArgs(args), args, 
258                                 Scream, NULL)) != MR_SUCCESS )
259         com_err(program_name, status, " in ChangeUserPOBox");
260     else
261         Put_message("PO Box assigned.");
262
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 */
273 int
274 RemoveUserPOBox(argc, argv)
275 int argc;
276 char ** 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)) {
288         if ( (status = do_mr_query("delete_pobox", 1, argv + 1,
289                                     Scream, NULL)) != MR_SUCCESS)
290             com_err(program_name, status, " in delete_pobox.");
291         else
292             Put_message("PO Box removed.");
293     }
294     return(DM_NORMAL);
295 }
This page took 0.055774 seconds and 5 git commands to generate.