]> andersk Git - moira.git/blob - clients/moira/pobox.c
5f03bec175807e50fbca3d6e53a98c41f044abde
[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     local_user = argv[1];
172
173     if (!ValidName(local_user))
174         return(DM_NORMAL);
175     
176     (void) GetUserPOBox(argc, argv); /* print current info. */
177     
178     sprintf(temp_buf, "Assign %s a local PO Box (y/n)", local_user);
179     switch (YesNoQuestion(temp_buf, TRUE)) {
180     case TRUE:
181         type = LOCAL_BOX;
182         switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE)) {
183         case TRUE:
184             switch (status = do_mr_query("set_pobox_pop", 1, 
185                                           &local_user, Scream, NULL)) {
186             case MR_SUCCESS:
187                 return(DM_NORMAL);
188             case MR_MACHINE:
189                 sprintf(temp_buf, "%s did not have a previous local PO Box.",
190                         local_user);
191                 Put_message(temp_buf);
192                 if ( (temp_box = GetNewLocalPOBox(local_user)) !=
193                         (char *) SUB_ERROR) {
194                     strcpy(box, temp_box);
195                     free(temp_box);
196                 }
197                 else
198                     return(DM_NORMAL);
199                 break;
200             default:
201                 com_err(program_name, status, "in set_pobox_pop.");
202                 return(DM_NORMAL);
203             }
204             break;
205         case FALSE:
206             if ( (temp_box = GetNewLocalPOBox(local_user)) !=
207                         (char *) SUB_ERROR) {
208                 strcpy(box, temp_box);
209                 free(temp_box);
210             }
211             else
212                 return(DM_NORMAL);
213             break;
214         default:
215             return(DM_NORMAL);
216         }
217         break;
218     case FALSE:
219         type = FOREIGN_BOX;
220         sprintf(temp_buf, "Set up a foreign PO Box for %s (y/n)", local_user);
221         switch( YesNoQuestion(temp_buf, TRUE)) {
222         case TRUE:
223             if (!Prompt_input("Foreign PO Box for this user? ", box, BUFSIZ))
224                 return(DM_NORMAL);
225             break;
226         case FALSE:
227         default:
228             return(DM_NORMAL);  /* ^C hit. */
229         }
230         break;
231     default:                    /* ^C hit. */
232         Put_message("Aborted.");
233         return(DM_NORMAL);
234     }
235
236     args[PO_NAME] = local_user;
237     args[PO_TYPE] = type;
238     args[PO_BOX] = box;
239     args[PO_END] = NULL;
240     if ( (status = do_mr_query("set_pobox", CountArgs(args), args, 
241                                 Scream, NULL)) != MR_SUCCESS )
242         com_err(program_name, status, " in ChangeUserPOBox");
243     else
244         Put_message("PO Box assigned.");
245
246     return (DM_NORMAL);
247 }
248
249 /*      Function Name: RemoveUserPOBox
250  *      Description: Removes this users POBox.
251  *      Arguments: argc, argv - name of user in argv[1].
252  *      Returns: DM_NORMAL.
253  */
254
255 /*ARGSUSED */
256 int
257 RemoveUserPOBox(argc, argv)
258 int argc;
259 char ** argv;
260 {
261     register int status;
262     char temp_buf[BUFSIZ];
263    
264     if (!ValidName(argv[1]))
265         return(DM_NORMAL);
266
267     sprintf(temp_buf,
268             "Are you sure that you want to remove %s's PO Box (y/n)", argv[1]);
269     
270     if (Confirm(temp_buf)) {
271         if ( (status = do_mr_query("delete_pobox", 1, argv + 1,
272                                     Scream, NULL)) != MR_SUCCESS)
273             com_err(program_name, status, "in delete_pobox.");
274         else
275             Put_message("PO Box removed.");
276     }
277     return(DM_NORMAL);
278 }
This page took 0.053512 seconds and 3 git commands to generate.