]> andersk Git - moira.git/blobdiff - clients/moira/pobox.c
characters -> letters & numbers
[moira.git] / clients / moira / pobox.c
index 1e219a5a94e177fdd1abab920574ad401f7ae4f9..3620ccf17221af0b5033870ee358c27850d5e147 100644 (file)
@@ -2,35 +2,34 @@
   static char rcsid_module_c[] = "$Header$";
 #endif lint
 
-/*     This is the file ***FILE for allmaint, the SMS client that allows
- *      a user to maintaint most important parts of the SMS database.
- *     It Contains: 
+/*     This is the file pobox.c for the SMS Client, which allows a nieve
+ *      user to quickly and easily maintain most parts of the SMS database.
+ *     It Contains: Functions for handling the poboxes.
  *     
- *     Created:        
- *     By:             
+ *     Created:        7/10/88
+ *     By:             Chris D. Peterson
  *
  *      $Source$
  *      $Author$
  *      $Header$
  *     
- *     Copyright 1987, 1988 by the Massachusetts Institute of Technology.
+ *     Copyright 1988 by the Massachusetts Institute of Technology.
  *
  *     For further information on copyright and distribution 
  *     see the file mit-copyright.h
  */
 
-
 #include <stdio.h>
 #include <strings.h>
 #include <ctype.h>
 #include <sms.h>
+#include <sms_app.h>
 #include <menu.h>
 
 #include "mit-copyright.h"
-#include "allmaint.h"
-#include "allmaint_funcs.h"
+#include "defs.h"
+#include "f_defs.h"
 #include "globals.h"
-#include "infodefs.h"
 
 #define FOREIGN_BOX ("SMTP")
 #define LOCAL_BOX ("POP")
@@ -68,23 +67,26 @@ char ** info;
 /*     Function Name: PrintPOMachines
  *     Description: Prints all current post offices.
  *     Arguments: none.
- *     Returns: none.
+ *     Returns: SUB_ERROR if the machines could not be printed.
  */
 
-static void
+static int
 PrintPOMachines()
 {
     register int status;
     static char * args[] = {"pop", NULL};
     struct qelem * top = NULL;
     
-    if ( (status = sms_query("get_server_locations", CountArgs(args), args,
-                            StoreInfo, &top)) != SMS_SUCCESS)
-       com_err(program_name, status, "in get_server_locations.");
+    if ( (status = do_sms_query("get_server_locations", CountArgs(args), args,
+                               StoreInfo, (char *)&top)) != SMS_SUCCESS) {
+       com_err(program_name, status, " in get_server_locations.");
+       return(SUB_ERROR);
+    }
     
     top = QueueTop(top);
     Loop(top, RealPrintPOMachines);
     FreeQueue(top);
+    return(SUB_NORMAL);
 }
 
 /*     Function Name: GetUserPOBox
@@ -106,7 +108,8 @@ char ** argv;
     if (!ValidName(argv[1]))
        return(DM_NORMAL);
     
-    switch (status = sms_query("get_pobox", 1, argv + 1, StoreInfo, &top)) {
+    switch (status = do_sms_query("get_pobox", 1, argv + 1, StoreInfo, 
+                                 (char *)&top)) {
     case SMS_NO_MATCH:
        Put_message("This user has no P.O. Box.");
        break;
@@ -126,7 +129,7 @@ char ** argv;
 /*     Function Name: GetNewLocalPOBox
  *     Description: get the machine for a new local pop Box for the user.
  *     Arguments: local_user - name of the local user.
- *     Returns: machine - name of the machine for then new pop box.
+ *     Returns: machine - name of the machine for then new pop box, or NULL.
  */
 
 static char *
@@ -140,10 +143,14 @@ char * local_user;
     sprintf(temp_buf,"%s %s", "Pick one of the following",
            "machines for this user's Post Office.");
     Put_message(temp_buf);
-    PrintPOMachines();
     Put_message("");
-    Prompt_input("Which Machine? ", temp_buf, BUFSIZ);
-    return( Strsave(temp_buf) );
+    if (PrintPOMachines() == SUB_NORMAL) {
+       Put_message("");
+       Prompt_input("Which Machine? ", temp_buf, BUFSIZ);
+       return(canonicalize_hostname(strsave(temp_buf)));
+    }
+    Put_message("Could not get machines to choose from, quitting.");
+    return((char *) SUB_ERROR);
 }
 
 /*     Function Name: SetUserPOBox
@@ -159,6 +166,7 @@ char **argv;
 {
     register int status;
     char *type, temp_buf[BUFSIZ], *local_user, *args[10], box[BUFSIZ];
+    char *temp_box;
     local_user = argv[1];
 
     if (!ValidName(local_user))
@@ -172,19 +180,32 @@ char **argv;
        type = LOCAL_BOX;
        switch (YesNoQuestion("Use Previous Local Box (y/n)", TRUE)) {
        case TRUE:
-           switch (status = sms_query("set_pobox_pop", 1, 
-                                      &local_user, Scream, NULL)) {
+           switch (status = do_sms_query("set_pobox_pop", 1, 
+                                         &local_user, Scream, NULL)) {
            case SMS_SUCCESS:
                return(DM_NORMAL);
            case SMS_MACHINE:
-               strcpy(box, GetNewLocalPOBox(local_user));
+               if ( (temp_box = GetNewLocalPOBox(local_user)) !=
+                       (char *) SUB_ERROR) {
+                   strcpy(box, temp_box);
+                   free(temp_box);
+               }
+               else
+                   return(DM_NORMAL);
                break;
            default:
                com_err(program_name, status, "in set_pobox_pop.");
                return(DM_NORMAL);
            }
+           break;
        case FALSE:
-           strcpy(box, GetNewLocalPOBox(local_user));
+           if ( (temp_box = GetNewLocalPOBox(local_user)) !=
+                       (char *) SUB_ERROR) {
+               strcpy(box, temp_box);
+               free(temp_box);
+           }
+           else
+               return(DM_NORMAL);
            break;
        default:
            return(DM_NORMAL);
@@ -203,18 +224,20 @@ char **argv;
            return(DM_NORMAL);  /* ^C hit. */
        }
        
-       args[PO_NAME] = local_user;
-       args[PO_TYPE] = type;
-       args[PO_BOX] = box;
-       args[PO_END] = NULL;
-       if ( (status = sms_query("set_pobox", CountArgs(args), args, 
-                                Scream, NULL)) != SMS_SUCCESS )
-           com_err(program_name, status, " in ChangeUserPOBox");
-       else
-           Put_message("PO Box assigned.");
     default:                   /* ^C hit. */
        break;
     }
+
+    args[PO_NAME] = local_user;
+    args[PO_TYPE] = type;
+    args[PO_BOX] = box;
+    args[PO_END] = NULL;
+    if ( (status = do_sms_query("set_pobox", CountArgs(args), args, 
+                               Scream, NULL)) != SMS_SUCCESS )
+       com_err(program_name, status, " in ChangeUserPOBox");
+    else
+       Put_message("PO Box assigned.");
+
     return (DM_NORMAL);
 }
 
@@ -240,38 +263,11 @@ char ** argv;
            "Are you sure that you want to remove %s's PO Box (y/n)", argv[1]);
     
     if (Confirm(temp_buf)) {
-       if ( (status = sms_query("delete_pobox", 1, argv + 1, Scream, NULL)) !=
-           SMS_SUCCESS)
+       if ( (status = do_sms_query("delete_pobox", 1, argv + 1,
+                                   Scream, NULL)) != SMS_SUCCESS)
            com_err(program_name, status, "in delete_pobox.");
        else
            Put_message("PO Box removed.");
     }
     return(DM_NORMAL);
 }
-
-/*
- * Local Variables:
- * mode: c
- * c-indent-level: 4
- * c-continued-statement-offset: 4
- * c-brace-offset: -4
- * c-argdecl-indent: 4
- * c-label-offset: -4
- * End:
- */
-
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
This page took 0.043465 seconds and 4 git commands to generate.