]> andersk Git - moira.git/blobdiff - clients/mailmaint/mailmaint.c
don't print prompt message over data line
[moira.git] / clients / mailmaint / mailmaint.c
index 033345ca1c6f7c370a7374756606748611007dfd..2a64c8a2a86803f9172e6538da4c9dc1d4907585 100644 (file)
@@ -3,9 +3,12 @@
  *     $Header$
  */
 
+/*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
+/*  For copying and distribution information, please see the file */
+/*  <mit-copyright.h>. */
+
 #ifndef lint
 static char rcsid_mailmaint_c[] = "$Header$";
-
 #endif lint
 
 /***********************************************************************/
@@ -20,8 +23,12 @@ static char rcsid_mailmaint_c[] = "$Header$";
 #include <strings.h>
 #include <curses.h>
 #include <sys/types.h>
+#include <varargs.h>
+#include <com_err.h>
 #include <ctype.h>
-#include "mit-copyright.h"
+#include <sms.h>
+#include <sms_app.h>
+#include <mit-copyright.h>
 
 #define STARTCOL 0
 #define STARTROW 3
@@ -32,15 +39,24 @@ static char rcsid_mailmaint_c[] = "$Header$";
 #define CTL(ch)  ((ch) & 037)
 #define MAX(A,B) ((A) > (B) ? (A) : (B))
 
-static char *whoami;
+char *whoami;          /* should not be static, for logging package */
 static int status;
 static void scream();
-char *ds();
+extern char *strsave();
+int menu_err_hook();
 
 typedef struct list_info {
-    char *acl;
+    int active;
+    int public;
+    int hidden;
+    int maillist;
+    int group;
+    char *acl_type;
+    char *acl_name;
     char *desc;
-    char *expdate;
+    char *modtime;
+    char *modby;
+    char *modwith;
 }         List_info;
 
 static char *ascbuff = {"0123456789"};
@@ -52,9 +68,8 @@ static int fetch_list_info();
 
 char *malloc();
 char *rindex();
-char *strcpy();
 char *getlogin();
-char *strsave();
+extern char *strsave();
 char *getenv();
 char *calloc();
 
@@ -81,25 +96,13 @@ main(argc, argv)
     char *argv[];
 
 {
-
+    int (*old_hook)();
     int use_menu = 1;
     char buf[BUFSIZ];
-    extern void sms_com_err_hook();
 
     init_sms_err_tbl();
     init_krb_err_tbl();
-    set_com_err_hook(sms_com_err_hook);
-
-    /*
-     * This shouldn't be here.... the experienced user will catch the error
-     * -- the inexperienced one will just be confused. 
-     *
-     * if (getenv("TERM") == (char *) NULL) { Put_message("Please set your TERM
-     * environment variable\n"); goto punt; } if (getenv("TERMCAP") == (char
-     * *) NULL) { Put_message("Please set your TERMCAP environment
-     * variable\n"); goto punt; } 
-     *
-     */
+
     if ((whoami = rindex(argv[0], '/')) == NULL)
        whoami = argv[0];
     else
@@ -111,26 +114,29 @@ main(argc, argv)
        goto punt;
     }
     else {
-       current_li->acl = (char *) NULL;
+       current_li->acl_type = (char *) NULL;
+       current_li->acl_name = (char *) NULL;
        current_li->desc = (char *) NULL;
-       current_li->expdate = (char *) NULL;
+       current_li->modtime = (char *) NULL;
+       current_li->modby = (char *) NULL;
+       current_li->modwith = (char *) NULL;
     }
     if ((uname = getlogin()) == NULL) {
        struct passwd *getpwuid();
 
        uname = getpwuid((int) getuid())->pw_name;
     }
-    uname = (uname && strlen(uname)) ? ds(uname) : "";
+    uname = (uname && strlen(uname)) ? strsave(uname) : "";
 
     printf("Connecting to database for %s...please hold on.\n", uname);
 
-    status = sms_connect();
+    status = sms_connect(SMS_SERVER);
     if (status) {
        (void) sprintf(buf, "\nConnection to SMS server failed");
        goto punt;
     }
 
-    status = sms_auth();
+    status = sms_auth("mailmaint");
     if (status) {
        (void) sprintf(buf, "\nAuthorization failed.\n");
        goto punt;
@@ -149,6 +155,7 @@ lines, %d columns)\n", LINES, COLS);
        }
        raw();
        noecho();
+       old_hook = set_com_err_hook(menu_err_hook);
        position[0] = oldpos[0] = 1;
        level = 0;
        pack_main_menu();
@@ -157,13 +164,12 @@ lines, %d columns)\n", LINES, COLS);
        get_main_input();
        cls();
        endwin();
+       set_com_err_hook(old_hook);
     }
-    sms_disconnect();
     exit(0);
 
 punt:
     com_err(whoami, status, buf);
-/*     sms_disconnect(); */
     exit(1);
 }
 
@@ -270,7 +276,7 @@ show_list_info()
 
     show_text(DISPROW, STARTCOL, "Show information about a list.\n\r");
     buf = calloc((unsigned)1024, 1);
-    if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
+    if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) {
        Put_message("\n\r");
        if (fetch_list_info(buf, current_li) == 0) {
            (void) sprintf(buf, "Description: %s\n\r", current_li->desc);
@@ -279,19 +285,22 @@ show_list_info()
            else
                show_text(currow, STARTCOL, buf);
            currow++;
-           (void) sprintf(buf, "List Administrator: %s", current_li->acl);
+           (void) sprintf(buf, "List Administrator: %s %s",
+                          current_li->acl_type, current_li->acl_name);
            show_text(currow, STARTCOL, buf);
            currow++;
-           (void) sprintf(buf, "Expiration date: %s", current_li->expdate);
+           (void) sprintf(buf, "Modified on %s by user %s with %s",
+                          current_li->modtime, current_li->modby,
+                          current_li->modwith);
            show_text(currow, STARTCOL, buf);
            currow++;
        }
        else {
-           show_text(currow, STARTCOL, "madm: No such list found.");
+           show_text(currow, STARTCOL, "mailmaint: No such list found.");
            currow++;
        }
        show_text(currow, STARTCOL, "Press any Key to continue...");
-       c = getchar();
+       (void) getchar();
     }
     clrwin(DISPROW);
 }
@@ -341,7 +350,7 @@ start_display_buff(buff)
        currow++;
        mvcur(0, 0, currow, STARTCOL);
        refresh();
-       if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
+       if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) {
            Put_message("Flushing query...");
            moreflg = 1;
            return (0);
@@ -359,23 +368,19 @@ start_display_buff(buff)
 /****************************************************/
 add_member()
 {
-    static char *argv[] = {
-       "add_member_to_list",
-       0,
-       0,
-       0
-       };
+    char *argv[3];
     char *buf;
     char c;
 
     show_text(DISPROW, STARTCOL, "Add yourself to a list\n\r");
     buf = calloc(LISTMAX, 1);
-    if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
+    if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) {
        Put_message("\r\n");
-       argv[1] = strsave(buf);
-       argv[2] = strsave("user");
-       argv[3] = strsave(uname);
-       if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
+       argv[0] = strsave(buf);
+       argv[1] = strsave("user");
+       argv[2] = strsave(uname);
+       if (status = sms_query("add_member_to_list", 3, argv,
+                              scream, (char *) NULL)) {
            Put_message("\r\n");
            com_err(whoami, status, " found.\n");
        }
@@ -385,7 +390,7 @@ add_member()
        }
        currow = DISPROW + 4;
        show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
-       c = getchar();
+       (void) getchar();
     }
     clrwin(DISPROW);
 }
@@ -393,23 +398,19 @@ add_member()
 /****************************************************/
 delete_member()
 {
-    static char *argv[] = {
-       "delete_member_from_list",
-       0,
-       0,
-       0
-       };
+    char *argv[3];
     char *buf;
     char c;
 
     show_text(DISPROW, STARTCOL, "Remove yourself from a list\n\r");
     buf = calloc(LISTMAX, 1);
-    if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
+    if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) {
        Put_message("\r\n");
-       argv[1] = strsave(buf);
-       argv[2] = strsave("user");
-       argv[3] = strsave(uname);
-       if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
+       argv[0] = strsave(buf);
+       argv[1] = strsave("user");
+       argv[2] = strsave(uname);
+       if (status = sms_query("delete_member_from_list", 3, argv,
+                              scream, (char *) NULL)) {
            Put_message("\r\n");
            com_err(whoami, status, " found.\n");
        }
@@ -419,7 +420,7 @@ delete_member()
        }
        currow = DISPROW + 4;
        show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
-       c = getchar();
+       (void) getchar();
     }
     clrwin(DISPROW);
 }
@@ -431,7 +432,7 @@ list_by_member()
     char *buf;
     char c;
 
-    nargv[1] = strsave("user");
+    nargv[1] = strsave("ruser");
     nargv[2] = strsave(uname);
     buf = calloc(BUFSIZ, 1);
     (void) sprintf(buf, "%s is on the following lists:\r", uname);
@@ -443,8 +444,9 @@ list_by_member()
        Put_message("\r\n");
        com_err(whoami, status, " in get_lists_of_member");
     }
+    currow++;
     show_text(currow, STARTCOL, "Press any Key to continue...");
-    c = getchar();
+    (void) getchar();
     clrwin(DISPROW);
     return;
 }
@@ -454,16 +456,19 @@ show_all()
 {
     char c;
 
-    show_text(DISPROW, STARTCOL, "This function may take a while...proceed[y]?");
+    show_text(DISPROW, STARTCOL, "This function may take a \
+while... proceed? [y] ");
     c = getchar();
-    if (c == 'n' || c == 'N') {
-       erase_line(DISPROW, STARTCOL);
-       return;
+    if (c == 'y' || c == 'Y' || c == '\n') {
+       move(DISPROW + 1, STARTCOL);
+       addstr("Processing query...please hold");
+       refresh();
+       (void) list_all_groups();
     }
-    move(DISPROW + 1, STARTCOL);
-    addstr("Processing query...please hold");
-    refresh();
-    (void) list_all_groups();
+    else
+       erase_line(DISPROW, STARTCOL);
+    return;
+
 }
 
 /****************************************************/
@@ -507,9 +512,12 @@ print_all(argc, argv, callback)
 /****************************************************/
 list_all_groups()
 {
-
+    char *argv[5];
+    argv[0] = argv[3] = "true";
+    argv[1] = argv[4] = "dontcare";
+    argv[2] = "false";
     first_time = 1;
-    if (status = sms_query("get_all_visible_maillists", 0, (char **) NULL,
+    if (status = sms_query("qualified_get_lists", 5, argv,
                           print_all, (char *) NULL)) {
        Put_message("\r\n");
        com_err(whoami, status, " in list_all_groups\n");
@@ -531,7 +539,7 @@ list_members()
     mvcur(0, 0, DISPROW, STARTCOL);
     refresh();
     buf = calloc(LISTMAX, 1);
-    if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
+    if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) {
        (void) sprintf(buffer, "The members of list '%s' are:", buf);
        show_text(DISPROW + 1, STARTCOL, buffer);
        argv[0] = buf;
@@ -544,6 +552,10 @@ list_members()
        if (!found_some) {
            show_text(currow, STARTCOL, "List is empty (no members).");
            currow++;
+           show_text(currow, STARTCOL, "Press any key to continue...");
+           getchar();
+           clrwin(DISPROW);
+           return;
        }
        end_display();
        return(0);
@@ -583,7 +595,7 @@ start_display(buff)
        currow++;
        mvcur(0, 0, currow, STARTCOL);
        refresh();
-       if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
+       if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) {
            Put_message("Flushing query...");
            moreflg = 1;
            return (0);
@@ -621,7 +633,7 @@ end_display()
     show_text(currow, STARTCOL, buffer);
     currow++;
     show_text(currow, STARTCOL, "Press any key to continue...");
-    c = getchar();
+    (void) getchar();
     clrwin(DISPROW);
 
 }
@@ -683,7 +695,7 @@ pack_help_menu()
     help_menu->num_items = 5;
     help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items);
 
-    help_menu->title = strsave("madm is designed as a basic mail list administration program.");
+    help_menu->title = strsave("mailmaint is designed as a basic mail list administration program.");
     help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like");
     help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the");
     help_menu->items[2] = strsave("program listmaint.");
@@ -794,22 +806,7 @@ clrwin(erase_row)
 }
 
 /****************************************************/
-char *
-strsave(s)
-    char *s;
-{
-    char *p;
 
-    if ((p = calloc((unsigned)1, (unsigned)(strlen(s) + 1))) != NULL) {
-       (void) strcpy(p, s);
-    }
-    else
-       Put_message("error in alloc\n\r");
-    return (p);
-}
-
-/****************************************************/
-/* jean's routine ??? */
 static void 
 scream()
 {
@@ -829,14 +826,7 @@ fetch_list_info(list, li)
     char *argv[1];
 
     argv[0] = list;
-    if ((status = sms_query("get_list_info", 1, argv,
-                           get_list_info, (char *) NULL)) == 0) {
-       return status;
-    }
-    else {
-       com_err(whoami, status, " found.\n");
-       return status;
-    }
+    return sms_query("get_list_info", 1, argv, get_list_info, (char *) NULL);
 }
 
 /* ARGSUSED */
@@ -846,15 +836,24 @@ get_list_info(argc, argv)
     char **argv;
 {
 
-    if (current_li->acl)
-       free(current_li->acl);
-    current_li->acl = strsave(argv[2]);
+    if (current_li->acl_type)
+       free(current_li->acl_type);
+    current_li->acl_type = strsave(argv[7]);
+    if (current_li->acl_name)
+       free(current_li->acl_name);
+    current_li->acl_name = strsave(argv[8]);
     if (current_li->desc)
        free(current_li->desc);
-    current_li->desc = strsave(argv[3]);
-    if (current_li->expdate)
-       free(current_li->expdate);
-    current_li->expdate = strsave(argv[4]);
+    current_li->desc = strsave(argv[9]);
+    if (current_li->modtime)
+       free(current_li->modtime);
+    current_li->modtime = strsave(argv[10]);
+    if (current_li->modby)
+       free(current_li->modby);
+    current_li->modby = strsave(argv[11]);
+    if (current_li->modwith)
+       free(current_li->modwith);
+    current_li->modwith = strsave(argv[12]);
     return (0);
 }
 
@@ -864,10 +863,11 @@ get_list_info(argc, argv)
 /****************************************************/
 /* Prompt the user for input */
 int 
-Prompt(prompt, buf, buflen)
+Prompt(prompt, buf, buflen, crok)
     char *prompt;
     char *buf;
     int buflen;
+    int crok;
 {
     int c;
     char *p;
@@ -889,9 +889,10 @@ Prompt(prompt, buf, buflen)
            return (0);
        case '\n':
        case '\r':
-           Put_message("\r");
+           if (crok)
+               Put_message("\r");
            *p = '\0';
-           if (strlen(buf) < 1)/* only /n or /r in buff */
+           if (strlen(buf) < 1)/* only \n or \r in buff */
                return (-1);
            else
                return (1);
@@ -900,15 +901,15 @@ Prompt(prompt, buf, buflen)
            if (p > buf) {
                p--;
                x--;
-               Put_message("\b");
-               Put_message(" ");
-               Put_message("\b");
+               printf("\b \b");
            }
            break;
        case CTL('U'):
        case CTL('G'):
        case CTL('['):
            x = oldx;
+           while (p-- > buf)
+               printf("\b \b");
            p = buf;
            break;
        default:
@@ -929,28 +930,36 @@ Prompt(prompt, buf, buflen)
     return(0);
 }
 
+
 /*
- * duplicate string 
+ * Hook function to cause error messages to be printed through
+ * curses instead of around it.
  */
-char *
-ds(str)
-    char *str;
-{
-    register char *newstr = malloc((unsigned) strlen(str) + 1);
 
-    if (newstr == (char *) NULL)
-       return ((char *) NULL);
-    else
-       return (strcpy(newstr, str));
+int
+menu_err_hook(who, code, fmt, args)
+    char *who;
+    int code;
+    char *fmt;
+    va_list args;
+{
+    char buf[BUFSIZ], *cp;
+
+    FILE _strbuf;
+
+    (void) strcpy(buf, who);
+    for (cp = buf; *cp; cp++);
+    *cp++ = ':';
+    *cp++ = ' ';
+    if (code) {
+       (void) strcpy(cp, error_message(code));
+       while (*cp)
+           cp++;
+    }
+    _strbuf._flag = _IOWRT + _IOSTRG;
+    _strbuf._ptr = cp;
+    _strbuf._cnt = BUFSIZ - (cp - buf);
+    _doprnt(fmt, args, &_strbuf);
+    (void) putc('\0', &_strbuf);
+    Put_message(buf);
 }
-
-/*
- * 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.059278 seconds and 4 git commands to generate.