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 /****************************************************/
91 if ((whoami = rindex(argv[0], '/')) == NULL)
95 uname = calloc(20, 1);
96 if ((current_li = (List_info *) malloc(sizeof(List_info)))
97 == (List_info *) NULL) {
98 (void) sprintf(buf, ": allocating list info");
102 current_li->acl = (char *) NULL;
103 current_li->desc = (char *) NULL;
104 current_li->expdate = (char *) NULL;
106 if ((uname = getlogin()) == NULL) {
107 struct passwd *getpwuid();
109 uname = getpwuid((int) getuid())->pw_name;
111 uname = (uname && strlen(uname)) ? ds(uname) : "";
113 printf("Connecting to database for %s...please hold on.\n", uname);
115 status = sms_connect();
117 (void) sprintf(buf, "\nConnection to SMS server failed");
123 (void) sprintf(buf, "\nAuthorization failed.\n");
129 if ((LINES < 24) || (COLS < 60)) {
130 Put_message("Display window too small.\n\n");
131 (void) sprintf(buf, "Current window parameters are (%d \
132 lines, %d columns)\n", LINES, COLS);
134 Put_message("Please resize your window\n");
135 Put_message("to at least 24 lines and 60 columns.\n");
140 position[0] = oldpos[0] = 1;
144 display_menu(main_menu);
152 com_err(whoami, status, buf);
156 /****************************************************/
163 oldpos[level] = position[level];
165 currow = DISPROW + 2;
167 toggle = num_members = moreflg = 0;
170 if (position[level] == 7)
173 c = ascbuff[position[level]];
177 case 'L' & 037: /* clear screen */
178 display_menu(main_menu);
183 highlight(main_menu);
189 case '1': /* show all lists */
195 case '2': /* get all members of a list */
198 (void) list_members();
201 case '3': /* display list which user is a recipient */
207 case '4': /* show description */
213 case '5': /* add to list */
219 case '6': /* delete */
225 case 27: /* up arrow */
231 if (!position[level])
237 if (position[level] > 7)
247 highlight(main_menu);
251 /****************************************************/
257 show_text(DISPROW, STARTCOL, "Show information about a list.\n\r");
258 buf = calloc((unsigned)1024, 1);
259 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
261 if (fetch_list_info(buf, current_li) == 0) {
262 (void) sprintf(buf, "Description: %s\n\r", current_li->desc);
263 if (strlen(buf) > 60)
264 (void) display_buff(buf);
266 show_text(currow, STARTCOL, buf);
268 (void) sprintf(buf, "List Administrator: %s", current_li->acl);
269 show_text(currow, STARTCOL, buf);
271 (void) sprintf(buf, "Expiration date: %s", current_li->expdate);
272 show_text(currow, STARTCOL, buf);
276 show_text(currow, STARTCOL, "madm: No such list found.");
279 show_text(currow, STARTCOL, "Press any Key to continue...");
285 /****************************************************/
298 printbuf = calloc((unsigned)maxcol, 1);
299 for (i = 0; i <= strlen(buf); i++) {
300 printbuf[cnt] = buf[i];
303 (void) start_display_buff(printbuf);
306 printbuf = calloc((unsigned)maxcol, 1);
309 if (strlen(buf) % maxcol != 0) {
310 (void) start_display_buff(printbuf);
316 /****************************************************/
317 start_display_buff(buff)
325 if (currow >= LINES - 2) {
328 mvcur(0, 0, currow, STARTCOL);
330 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
331 Put_message("Flushing query...");
336 currow = DISPROW + 2;
337 show_text(currow, STARTCOL, "continued");
340 show_text(currow, STARTCOL, buff);
345 /****************************************************/
348 static char *argv[] = {
349 "add_member_to_list",
357 show_text(DISPROW, STARTCOL, "Add yourself to a list\n\r");
358 buf = calloc(LISTMAX, 1);
359 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
361 argv[1] = strsave(buf);
362 argv[2] = strsave("user");
363 argv[3] = strsave(uname);
364 if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
366 com_err(whoami, status, " found.\n");
369 (void) sprintf(buf, "User %s added to list\r", uname);
370 show_text(DISPROW + 3, STARTCOL, buf);
372 currow = DISPROW + 4;
373 show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
379 /****************************************************/
382 static char *argv[] = {
383 "delete_member_from_list",
391 show_text(DISPROW, STARTCOL, "Remove yourself from a list\n\r");
392 buf = calloc(LISTMAX, 1);
393 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
395 argv[1] = strsave(buf);
396 argv[2] = strsave("user");
397 argv[3] = strsave(uname);
398 if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
400 com_err(whoami, status, " found.\n");
403 (void) sprintf(buf, "User %s deleted from list\r", uname);
404 show_text(DISPROW + 3, STARTCOL, buf);
406 currow = DISPROW + 4;
407 show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
413 /****************************************************/
420 nargv[1] = strsave("user");
421 nargv[2] = strsave(uname);
422 buf = calloc(BUFSIZ, 1);
423 (void) sprintf(buf, "%s is on the following lists:\r", uname);
424 show_text(DISPROW, STARTCOL, buf);
425 mvcur(0, 0, currow, STARTCOL);
427 if (status = sms_query("get_lists_of_member", 2, nargv + 1,
428 print_1, (char *) NULL)) {
430 com_err(whoami, status, " in get_lists_of_member");
432 show_text(currow, STARTCOL, "Press any Key to continue...");
438 /****************************************************/
443 show_text(DISPROW, STARTCOL, "This function may take a while...proceed[y]?");
445 if (c == 'n' || c == 'N') {
446 erase_line(DISPROW, STARTCOL);
449 move(DISPROW + 1, STARTCOL);
450 addstr("Processing query...please hold");
452 (void) list_all_groups();
455 /****************************************************/
458 print_1(argc, argv, callback)
460 char *argv[], *callback;
464 /* no newline 'cause Put_message adds one */
465 (void) sprintf(buf, "%s\r", argv[0]);
466 (void) start_display(buf);
471 /****************************************************/
474 print_all(argc, argv, callback)
476 char *argv[], *callback;
483 erase_line(DISPROW + 1, STARTCOL);
484 show_text(DISPROW + 1, STARTCOL, "All mailing lists:");
487 (void) sprintf(buf, "%s\r", argv[0]);
488 (void) start_display(buf);
493 /****************************************************/
498 if (status = sms_query("get_all_visible_maillists", 0, (char **) NULL,
499 print_all, (char *) NULL)) {
501 com_err(whoami, status, " in list_all_groups\n");
505 return (DM_NORMAL); /* HA! */
508 /****************************************************/
516 move(DISPROW, STARTCOL);
517 mvcur(0, 0, DISPROW, STARTCOL);
519 buf = calloc(LISTMAX, 1);
520 if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
521 (void) sprintf(buffer, "The members of list '%s' are:", buf);
522 show_text(DISPROW + 1, STARTCOL, buffer);
524 if (status = sms_query("get_members_of_list", 1, argv,
525 print_2, (char *) NULL)) {
527 com_err(whoami, status, " found.\n");
531 show_text(currow, STARTCOL, "List is empty (no members).");
538 return (DM_NORMAL); /* HA! */
541 /****************************************************/
544 print_2(argc, argv, callback)
546 char *argv[], *callback;
551 (void) sprintf(buf, "%s %s", argv[0], argv[1]);
552 (void) start_display(buf);
557 /****************************************************/
566 buffer = calloc(50, 1);
567 if (currow >= LINES - 2) {
570 mvcur(0, 0, currow, STARTCOL);
572 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
573 Put_message("Flushing query...");
578 currow = DISPROW + 2;
579 (void) sprintf(buffer, "Continued (Page %d)", page);
580 show_text(currow, STARTCOL, buffer);
585 show_text(currow, STARTCOL, buff);
587 show_text(currow, SECONDCOL, buff);
594 /****************************************************/
604 buffer = calloc(50, 1);
606 (void) sprintf(buffer, "End of List. %d Total Members\r", num_members);
607 show_text(currow, STARTCOL, buffer);
609 show_text(currow, STARTCOL, "Press any key to continue...");
615 /****************************************************/
623 mvcur(0, 0, STARTROW, STARTCOL);
625 for (i = 0; i <= menu->num_items - 1; i++) {
626 move(STARTROW + i, STARTCOL);
628 addstr(menu->items[i]);
631 center_text(STARTROW + menu->num_items + 2,
632 "Enter a number, <up arrow>, or <down arrow>.");
634 center_text(STARTROW + menu->num_items + 3,
635 "Press 'q' to exit, <return> to confirm choice.");
637 center_text(STARTROW + menu->num_items + 3,
638 "Press 'q' to exit, 'r' for main menu, <return> to confirm choice.");
641 highlight(main_menu);
644 /****************************************************/
649 main_menu = (MENU *) malloc((unsigned) sizeof(MENU));
650 main_menu->num_items = 7;
651 main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items);
654 (void) sprintf(buf, "Mail List Program for %s", uname);
655 main_menu->title = strsave(buf);
656 main_menu->items[0] = strsave("1. Show all mailing lists.");
657 main_menu->items[1] = strsave("2. Get all members of a mailing list.");
658 main_menu->items[2] = strsave("3. Display lists of which you are a member.");
659 main_menu->items[3] = strsave("4. Show description of list.");
660 main_menu->items[4] = strsave("5. Add yourself to a mailing list.");
661 main_menu->items[5] = strsave("6. Delete yourself from a mailing list.");
662 main_menu->items[6] = strsave("q. Quit.");
665 /****************************************************/
668 help_menu = (MENU *) malloc((unsigned) sizeof(MENU));
669 help_menu->num_items = 5;
670 help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items);
672 help_menu->title = strsave("madm is designed as a basic mail list administration program.");
673 help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like");
674 help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the");
675 help_menu->items[2] = strsave("program listmaint.");
676 help_menu->items[3] = strsave(" ");
677 help_menu->items[4] = strsave("Press any key to continue.");
680 /****************************************************/
686 if (oldpos[level] != position[level]) {
687 move(STARTROW + oldpos[level] - 1, STARTCOL);
689 addstr(menu->items[oldpos[level] - 1]);
693 move(STARTROW + position[level] - 1, STARTCOL);
695 addstr(menu->items[position[level] - 1]);
701 /****************************************************/
705 move(0, MAX(0, (COLS - strlen(buff)) >> 1));
712 /****************************************************/
713 center_text(row, buff)
717 move(row, MAX(0, (COLS - strlen(buff)) >> 1));
722 /****************************************************/
723 show_text(row, col, buff)
727 mvcur(0, 0, row, col);
732 /****************************************************/
739 buff = calloc((unsigned)COLS, 1);
740 for (i = 0; i <= COLS - 2; i++)
742 buff[i] = 0; /* just to be sure ! */
744 mvcur(0, 0, row, col);
749 /****************************************************/
756 /****************************************************/
766 maxcol = 80; /* limit width */
768 buff = calloc((unsigned)maxcol + 1, 1);
769 for (i = 0; i <= maxcol - 1; i++)
771 buff[i] = 0; /* just to be sure ! */
772 mvcur(0, 0, erase_row, STARTCOL);
774 for (i = erase_row; i <= currow - 1; i++) {
775 printf("%s\n\r", buff);
778 mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL);
782 /****************************************************/
789 if ((p = calloc((unsigned)1, (unsigned)(strlen(s) + 1))) != NULL) {
793 Put_message("error in alloc\n\r");
797 /****************************************************/
798 /* jean's routine ??? */
802 com_err(whoami, status, "\nAn SMS update returned a value -- programmer \
808 /****************************************************/
811 fetch_list_info(list, li)
818 if ((status = sms_query("get_list_info", 1, argv,
819 get_list_info, (char *) NULL)) == 0) {
823 com_err(whoami, status, " found.\n");
830 get_list_info(argc, argv)
836 free(current_li->acl);
837 current_li->acl = strsave(argv[2]);
838 if (current_li->desc)
839 free(current_li->desc);
840 current_li->desc = strsave(argv[3]);
841 if (current_li->expdate)
842 free(current_li->expdate);
843 current_li->expdate = strsave(argv[4]);
850 /****************************************************/
851 /* Prompt the user for input */
853 Prompt(prompt, buf, buflen)
862 printf("%s", prompt);
864 for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) {
874 display_menu(main_menu);
880 if (strlen(buf) < 1)/* only \n or \r in buff */
901 if (abs(strlen(p) - strlen(buf)) >= buflen) {
911 (void) putchar(CTL('G'));
925 register char *newstr = malloc((unsigned) strlen(str) + 1);
927 if (newstr == (char *) NULL)
928 return ((char *) NULL);
930 return (strcpy(newstr, str));
937 * c-continued-statement-offset: 4
939 * c-argdecl-indent: 4