7 static char rcsid_mailmaint_c[] = "$Header$";
11 /***********************************************************************/
12 /* mailmaint.c - pjlevine - 20 August 1987
15 /***********************************************************************/
22 #include <sys/types.h>
24 #include "mit-copyright.h"
32 #define CTL(ch) ((ch) & 037)
33 #define MAX(A,B) ((A) > (B) ? (A) : (B))
40 typedef struct list_info {
46 static char *ascbuff = {"0123456789"};
49 static List_info *current_li = (List_info *) NULL;
50 static int get_list_info();
51 static int fetch_list_info();
63 typedef struct _menu {
69 MENU *main_menu, *help_menu;
71 int position[2], oldpos[2];
72 int level, found_some, currow, page, num_members;
73 int moreflg, toggle, first_time;
77 /****************************************************/
87 extern void sms_com_err_hook();
91 set_com_err_hook(sms_com_err_hook);
94 * This shouldn't be here.... the experienced user will catch the error
95 * -- the inexperienced one will just be confused.
97 * if (getenv("TERM") == (char *) NULL) { Put_message("Please set your TERM
98 * environment variable\n"); goto punt; } if (getenv("TERMCAP") == (char
99 * *) NULL) { Put_message("Please set your TERMCAP environment
100 * variable\n"); goto punt; }
103 if ((whoami = rindex(argv[0], '/')) == NULL)
107 uname = calloc(20, 1);
108 if ((current_li = (List_info *) malloc(sizeof(List_info)))
109 == (List_info *) NULL) {
110 (void) sprintf(buf, ": allocating list info");
114 current_li->acl = (char *) NULL;
115 current_li->desc = (char *) NULL;
116 current_li->expdate = (char *) NULL;
118 if ((uname = getlogin()) == NULL) {
119 struct passwd *getpwuid();
121 uname = getpwuid((int) getuid())->pw_name;
123 uname = (uname && strlen(uname)) ? ds(uname) : "";
125 printf("Connecting to database for %s...please hold on.\n", uname);
127 status = sms_connect();
129 (void) sprintf(buf, "\nConnection to SMS server failed");
135 (void) sprintf(buf, "\nAuthorization failed.\n");
141 if ((LINES < 24) || (COLS < 60)) {
142 Put_message("Display window too small.\n\n");
143 (void) sprintf(buf, "Current window parameters are (%d \
144 lines, %d columns)\n", LINES, COLS);
146 Put_message("Please resize your window\n");
147 Put_message("to at least 24 lines and 60 columns.\n");
152 position[0] = oldpos[0] = 1;
156 display_menu(main_menu);
165 com_err(whoami, status, buf);
166 /* sms_disconnect(); */
170 /****************************************************/
177 oldpos[level] = position[level];
179 currow = DISPROW + 2;
181 toggle = num_members = moreflg = 0;
184 if (position[level] == 7)
187 c = ascbuff[position[level]];
191 case 'L' & 037: /* clear screen */
192 display_menu(main_menu);
197 highlight(main_menu);
203 case '1': /* show all lists */
209 case '2': /* get all members of a list */
212 (void) list_members();
215 case '3': /* display list which user is a recipient */
221 case '4': /* show description */
227 case '5': /* add to list */
233 case '6': /* delete */
239 case 27: /* up arrow */
245 if (!position[level])
251 if (position[level] > 7)
261 highlight(main_menu);
265 /****************************************************/
271 show_text(DISPROW, STARTCOL, "Show information about a list.\n\r");
272 buf = calloc((unsigned)1024, 1);
273 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
275 if (fetch_list_info(buf, current_li) == 0) {
276 (void) sprintf(buf, "Description: %s\n\r", current_li->desc);
277 if (strlen(buf) > 60)
278 (void) display_buff(buf);
280 show_text(currow, STARTCOL, buf);
282 (void) sprintf(buf, "List Administrator: %s", current_li->acl);
283 show_text(currow, STARTCOL, buf);
285 (void) sprintf(buf, "Expiration date: %s", current_li->expdate);
286 show_text(currow, STARTCOL, buf);
290 show_text(currow, STARTCOL, "madm: No such list found.");
293 show_text(currow, STARTCOL, "Press any Key to continue...");
299 /****************************************************/
312 printbuf = calloc((unsigned)maxcol, 1);
313 for (i = 0; i <= strlen(buf); i++) {
314 printbuf[cnt] = buf[i];
317 (void) start_display_buff(printbuf);
320 printbuf = calloc((unsigned)maxcol, 1);
323 if (strlen(buf) % maxcol != 0) {
324 (void) start_display_buff(printbuf);
330 /****************************************************/
331 start_display_buff(buff)
339 if (currow >= LINES - 2) {
342 mvcur(0, 0, currow, STARTCOL);
344 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
345 Put_message("Flushing query...");
350 currow = DISPROW + 2;
351 show_text(currow, STARTCOL, "continued");
354 show_text(currow, STARTCOL, buff);
359 /****************************************************/
362 static char *argv[] = {
363 "add_member_to_list",
371 show_text(DISPROW, STARTCOL, "Add yourself to a list\n\r");
372 buf = calloc(LISTMAX, 1);
373 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
375 argv[1] = strsave(buf);
376 argv[2] = strsave("user");
377 argv[3] = strsave(uname);
378 if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
380 com_err(whoami, status, " found.\n");
383 (void) sprintf(buf, "User %s added to list\r", uname);
384 show_text(DISPROW + 3, STARTCOL, buf);
386 currow = DISPROW + 4;
387 show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
393 /****************************************************/
396 static char *argv[] = {
397 "delete_member_from_list",
405 show_text(DISPROW, STARTCOL, "Remove yourself from a list\n\r");
406 buf = calloc(LISTMAX, 1);
407 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
409 argv[1] = strsave(buf);
410 argv[2] = strsave("user");
411 argv[3] = strsave(uname);
412 if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
414 com_err(whoami, status, " found.\n");
417 (void) sprintf(buf, "User %s deleted from list\r", uname);
418 show_text(DISPROW + 3, STARTCOL, buf);
420 currow = DISPROW + 4;
421 show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
427 /****************************************************/
434 nargv[1] = strsave("user");
435 nargv[2] = strsave(uname);
436 buf = calloc(BUFSIZ, 1);
437 (void) sprintf(buf, "%s is on the following lists:\r", uname);
438 show_text(DISPROW, STARTCOL, buf);
439 mvcur(0, 0, currow, STARTCOL);
441 if (status = sms_query("get_lists_of_member", 2, nargv + 1,
442 print_1, (char *) NULL)) {
444 com_err(whoami, status, " in get_lists_of_member");
446 show_text(currow, STARTCOL, "Press any Key to continue...");
452 /****************************************************/
457 show_text(DISPROW, STARTCOL, "This function may take a while...proceed[y]?");
459 if (c == 'n' || c == 'N') {
460 erase_line(DISPROW, STARTCOL);
463 move(DISPROW + 1, STARTCOL);
464 addstr("Processing query...please hold");
466 (void) list_all_groups();
469 /****************************************************/
472 print_1(argc, argv, callback)
474 char *argv[], *callback;
478 /* no newline 'cause Put_message adds one */
479 (void) sprintf(buf, "%s\r", argv[0]);
480 (void) start_display(buf);
485 /****************************************************/
488 print_all(argc, argv, callback)
490 char *argv[], *callback;
497 erase_line(DISPROW + 1, STARTCOL);
498 show_text(DISPROW + 1, STARTCOL, "All mailing lists:");
501 (void) sprintf(buf, "%s\r", argv[0]);
502 (void) start_display(buf);
507 /****************************************************/
512 if (status = sms_query("get_all_visible_maillists", 0, (char **) NULL,
513 print_all, (char *) NULL)) {
515 com_err(whoami, status, " in list_all_groups\n");
519 return (DM_NORMAL); /* HA! */
522 /****************************************************/
530 move(DISPROW, STARTCOL);
531 mvcur(0, 0, DISPROW, STARTCOL);
533 buf = calloc(LISTMAX, 1);
534 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
535 (void) sprintf(buffer, "The members of list '%s' are:", buf);
536 show_text(DISPROW + 1, STARTCOL, buffer);
538 if (status = sms_query("get_members_of_list", 1, argv,
539 print_2, (char *) NULL)) {
541 com_err(whoami, status, " found.\n");
545 show_text(currow, STARTCOL, "List is empty (no members).");
552 return (DM_NORMAL); /* HA! */
555 /****************************************************/
558 print_2(argc, argv, callback)
560 char *argv[], *callback;
565 (void) sprintf(buf, "%s %s", argv[0], argv[1]);
566 (void) start_display(buf);
571 /****************************************************/
580 buffer = calloc(50, 1);
581 if (currow >= LINES - 2) {
584 mvcur(0, 0, currow, STARTCOL);
586 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
587 Put_message("Flushing query...");
592 currow = DISPROW + 2;
593 (void) sprintf(buffer, "Continued (Page %d)", page);
594 show_text(currow, STARTCOL, buffer);
599 show_text(currow, STARTCOL, buff);
601 show_text(currow, SECONDCOL, buff);
608 /****************************************************/
618 buffer = calloc(50, 1);
620 (void) sprintf(buffer, "End of List. %d Total Members\r", num_members);
621 show_text(currow, STARTCOL, buffer);
623 show_text(currow, STARTCOL, "Press any key to continue...");
629 /****************************************************/
637 mvcur(0, 0, STARTROW, STARTCOL);
639 for (i = 0; i <= menu->num_items - 1; i++) {
640 move(STARTROW + i, STARTCOL);
642 addstr(menu->items[i]);
645 center_text(STARTROW + menu->num_items + 2,
646 "Enter a number, <up arrow>, or <down arrow>.");
648 center_text(STARTROW + menu->num_items + 3,
649 "Press 'q' to exit, <return> to confirm choice.");
651 center_text(STARTROW + menu->num_items + 3,
652 "Press 'q' to exit, 'r' for main menu, <return> to confirm choice.");
655 highlight(main_menu);
658 /****************************************************/
663 main_menu = (MENU *) malloc((unsigned) sizeof(MENU));
664 main_menu->num_items = 7;
665 main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items);
668 (void) sprintf(buf, "Mail List Program for %s", uname);
669 main_menu->title = strsave(buf);
670 main_menu->items[0] = strsave("1. Show all mailing lists.");
671 main_menu->items[1] = strsave("2. Get all members of a mailing list.");
672 main_menu->items[2] = strsave("3. Display lists of which you are a member.");
673 main_menu->items[3] = strsave("4. Show description of list.");
674 main_menu->items[4] = strsave("5. Add yourself to a mailing list.");
675 main_menu->items[5] = strsave("6. Delete yourself from a mailing list.");
676 main_menu->items[6] = strsave("q. Quit.");
679 /****************************************************/
682 help_menu = (MENU *) malloc((unsigned) sizeof(MENU));
683 help_menu->num_items = 5;
684 help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items);
686 help_menu->title = strsave("madm is designed as a basic mail list administration program.");
687 help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like");
688 help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the");
689 help_menu->items[2] = strsave("program listmaint.");
690 help_menu->items[3] = strsave(" ");
691 help_menu->items[4] = strsave("Press any key to continue.");
694 /****************************************************/
700 if (oldpos[level] != position[level]) {
701 move(STARTROW + oldpos[level] - 1, STARTCOL);
703 addstr(menu->items[oldpos[level] - 1]);
707 move(STARTROW + position[level] - 1, STARTCOL);
709 addstr(menu->items[position[level] - 1]);
715 /****************************************************/
719 move(0, MAX(0, (COLS - strlen(buff)) >> 1));
726 /****************************************************/
727 center_text(row, buff)
731 move(row, MAX(0, (COLS - strlen(buff)) >> 1));
736 /****************************************************/
737 show_text(row, col, buff)
741 mvcur(0, 0, row, col);
746 /****************************************************/
753 buff = calloc((unsigned)COLS, 1);
754 for (i = 0; i <= COLS - 2; i++)
756 buff[i] = 0; /* just to be sure ! */
758 mvcur(0, 0, row, col);
763 /****************************************************/
770 /****************************************************/
780 maxcol = 80; /* limit width */
782 buff = calloc((unsigned)maxcol + 1, 1);
783 for (i = 0; i <= maxcol - 1; i++)
785 buff[i] = 0; /* just to be sure ! */
786 mvcur(0, 0, erase_row, STARTCOL);
788 for (i = erase_row; i <= currow - 1; i++) {
789 printf("%s\n\r", buff);
792 mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL);
796 /****************************************************/
803 if ((p = calloc((unsigned)1, (unsigned)(strlen(s) + 1))) != NULL) {
807 Put_message("error in alloc\n\r");
811 /****************************************************/
812 /* jean's routine ??? */
816 com_err(whoami, status, "\nAn SMS update returned a value -- programmer \
822 /****************************************************/
825 fetch_list_info(list, li)
832 if ((status = sms_query("get_list_info", 1, argv,
833 get_list_info, (char *) NULL)) == 0) {
837 com_err(whoami, status, " found.\n");
844 get_list_info(argc, argv)
850 free(current_li->acl);
851 current_li->acl = strsave(argv[2]);
852 if (current_li->desc)
853 free(current_li->desc);
854 current_li->desc = strsave(argv[3]);
855 if (current_li->expdate)
856 free(current_li->expdate);
857 current_li->expdate = strsave(argv[4]);
864 /****************************************************/
865 /* Prompt the user for input */
867 Prompt(prompt, buf, buflen)
876 printf("%s", prompt);
878 for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) {
888 display_menu(main_menu);
894 if (strlen(buf) < 1)/* only /n or /r in buff */
915 if (abs(strlen(p) - strlen(buf)) >= buflen) {
925 (void) putchar(CTL('G'));
939 register char *newstr = malloc((unsigned) strlen(str) + 1);
941 if (newstr == (char *) NULL)
942 return ((char *) NULL);
944 return (strcpy(newstr, str));
951 * c-continued-statement-offset: 4
953 * c-argdecl-indent: 4