]> code.citadel.org Git - citadel.git/blobdiff - citadel/citadel.c
* Fixed a small bug in the GDBM backend (deprecated, but the bug was very
[citadel.git] / citadel / citadel.c
index 10ebb3045b787e18b94c1776c54688099d246ba6..bc55bca1a3bb8afca8342f118f276ad47f7e18d7 100644 (file)
@@ -30,7 +30,6 @@
 #include <sys/ioctl.h>
 #include <signal.h>
 #include <pwd.h>
-#include <setjmp.h>
 #include <stdarg.h>
 #include <errno.h>
 
 struct march *march = NULL;
 
 /* globals associated with the client program */
-char temp[PATH_MAX];           /* Name of general temp file */
-char temp2[PATH_MAX];          /* Name of general temp file */
-char tempdir[PATH_MAX];                /* Name of general temp dir */
-char editor_path[SIZ];         /* path to external editor */
+char temp[PATH_MAX];           /* Name of general-purpose temp file */
+char temp2[PATH_MAX];          /* Name of general-purpose temp file */
+char tempdir[PATH_MAX];                /* Name of general-purpose temp directory */
+char editor_paths[MAX_EDITORS][SIZ];   /* paths to external editors */
 char printcmd[SIZ];            /* print command */
 int editor_pid = (-1);
 char fullname[USERNAME_SIZE];
-jmp_buf nextbuf;
 struct CtdlServInfo serv_info; /* Info on the server connected */
 int screenwidth;
 int screenheight;
@@ -114,25 +112,27 @@ CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
  */
 void logoff(CtdlIPC *ipc, int code)
 {
-    int lp;
+       int lp;
+
        if (editor_pid > 0) {   /* kill the editor if it's running */
                kill(editor_pid, SIGHUP);
        }
 
-    /* Free the ungoto list */
-    for (lp = 0; lp < uglistsize; lp++)
-      free (uglist[lp]);
+       /* Free the ungoto list */
+       for (lp = 0; lp < uglistsize; lp++) {
+               free(uglist[lp]);
+       }
 
-/* shut down the server... but not if the logoff code is 3, because
- * that means we're exiting because we already lost the server
+/* Shut down the server connection ... but not if the logoff code is 3,
+ * because that means we're exiting because we already lost the server.
  */
-       if (code != 3)
+       if (code != 3) {
                CtdlIPCQuit(ipc);
+       }
 
 /*
  * now clean up various things
  */
-
        screen_delete();
 
        unlink(temp);
@@ -175,8 +175,8 @@ void catch_sigcont(int signum)
 }
 
 
-
 /* general purpose routines */
+
 /* display a file */
 void formout(CtdlIPC *ipc, char *name)
 {
@@ -355,8 +355,9 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
                                uglistlsn[lp] = uglistlsn[lp+1];
                        }
                        ugpos--;
-               } else
+               } else {
                        uglistsize++;
+               }
         
                uglist[ugpos] = malloc(strlen(room_name)+1);
                strcpy(uglist[ugpos], room_name);
@@ -382,12 +383,11 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
         */
        if (r / 100 != 2) {
                struct march *march = NULL;
-               int r;  /* IPC result code; hides higher-level r */
 
                best_match = 0;
                strcpy(bbb, "");
 
-               r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, -1, &march, aaa);
+               r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, AllFloors, &march, aaa);
                if (r / 100 == 1) {
                        /* Run the roomlist; free the data as we go */
                        struct march *mp = march;       /* Current */
@@ -499,7 +499,7 @@ void gotonext(CtdlIPC *ipc)
         * If it is, pop the first room off the list and go there.
         */
        if (march == NULL) {
-               r = CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages, -1, &march, buf);
+               r = CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages, AllFloors, &march, buf);
 /* add _BASEROOM_ to the end of the march list, so the user will end up
  * in the system base room (usually the Lobby>) at the end of the loop
  */
@@ -737,7 +737,7 @@ int set_password(CtdlIPC *ipc)
        if (!strcasecmp(pass1, pass2)) {
                CtdlIPCChangePassword(ipc, pass1, buf);
                scr_printf("%s\n", buf);
-               offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
+               offer_to_remember_password(ipc, hostbuf, portbuf, fullname, pass1);
                return (0);
        } else {
                scr_printf("*** They don't match... try again.\n");
@@ -759,8 +759,9 @@ void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
        /* be nice and identify ourself to the server */
        CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
                 (ipc->isLocal ? "local" : CITADEL),
-                (supplied_hostname) ? supplied_hostname : "", buf);
-                /* (locate_host(buf), buf)); */
+                (supplied_hostname) ? supplied_hostname : 
+                /* Look up the , in the bible if you're confused */
+                (locate_host(buf), buf), buf);
 
        /* Tell the server what our preferred content formats are */
        if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/html|text/plain") / 100 )== 2) {
@@ -949,7 +950,7 @@ int main(int argc, char **argv)
 #ifdef HAVE_OPENSSL
        arg_encrypt = RC_DEFAULT;
 #endif
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
        arg_screen = RC_DEFAULT;
 #endif
 
@@ -978,13 +979,13 @@ int main(int argc, char **argv)
 #endif
                }
                if (!strcmp(argv[a], "-s")) {
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
                        arg_screen = RC_NO;
 #endif
                        argc = shift(argc, argv, a, 1);
                }
                if (!strcmp(argv[a], "-S")) {
-#ifdef HAVE_CURSES_H
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
                        arg_screen = RC_YES;
 #endif
                        argc = shift(argc, argv, a, 1);
@@ -1034,6 +1035,9 @@ int main(int argc, char **argv)
                error_printf("Can't connect: %s\n", strerror(errno));
                logoff(NULL, 3);
        }
+#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
+       CtdlIPC_SetNetworkStatusCallback(ipc, wait_indicator);
+#endif
        ipc_for_signal_handlers = ipc;  /* KLUDGE cover your eyes */
 
        CtdlIPC_getline(ipc, aaa);
@@ -1156,13 +1160,13 @@ int main(int argc, char **argv)
        
        if (r / 100 == 2) {
                load_user_info(aaa);
-               offer_to_remember_password(hostbuf, portbuf,
+               offer_to_remember_password(ipc, hostbuf, portbuf,
                                           fullname, password);
                goto PWOK;
        }
        scr_printf("<< wrong password >>\n");
        if (strlen(rc_password) > 0)
-               logoff(ipc, 0);
+               logoff(ipc, 2);
        goto GSTA;
 
 NEWUSR:        if (strlen(rc_password) == 0) {
@@ -1192,12 +1196,13 @@ NEWUSR: if (strlen(rc_password) == 0) {
                        enable_color = 0;
        }
 
-       scr_printf("%s\nAccess level: %d (%s)\n"
+       color(BRIGHT_WHITE);
+       scr_printf("\n%s\nAccess level: %d (%s)\n"
                   "User #%ld / Login #%d",
                   fullname, axlevel, axdefs[(int) axlevel],
                   usernum, timescalled);
        if (lastcall > 0L) {
-               scr_printf(" / Last login: %s\n",
+               scr_printf(" / Last login: %s",
                           asctime(localtime(&lastcall)));
        }
        scr_printf("\n");
@@ -1264,9 +1269,9 @@ NEWUSR:   if (strlen(rc_password) == 0) {
        uglistsize = 0;
 
        if (newnow == 1)
-               readmsgs(ipc, 3, 1, 5);
+               readmsgs(ipc, LastMessages, ReadForward, 5);
        else
-               readmsgs(ipc, 1, 1, 0);
+               readmsgs(ipc, NewMessages, ReadForward, 0);
 
        /* MAIN COMMAND LOOP */
        do {
@@ -1319,31 +1324,40 @@ NEWUSR: if (strlen(rc_password) == 0) {
                                dotgoto(ipc, "_MAIL_", 1, 0);
                                break;
                        case 20:
-                               updatels(ipc);
-                               dotgoto(ipc, argbuf, 0, 0);
+                               if (strlen(argbuf) > 0) {
+                                       updatels(ipc);
+                                       dotgoto(ipc, argbuf, 0, 0);
+                               }
                                break;
                        case 52:
-                               if (rc_alt_semantics)
-                                       updatelsa(ipc);
-                               dotgoto(ipc, argbuf, 0, 0);
+                               if (strlen(argbuf) > 0) {
+                                       if (rc_alt_semantics) {
+                                               updatelsa(ipc);
+                                       }
+                                       dotgoto(ipc, argbuf, 0, 0);
+                               }
+                               break;
+                       case 95: /* what exactly is the numbering scheme supposed to be anyway? */
+                               dotungoto(ipc, argbuf);
                                break;
                        case 10:
-                               readmsgs(ipc, 0, 1, 0);
+                               readmsgs(ipc, AllMessages, ReadForward, 0);
                                break;
                        case 9:
-                               readmsgs(ipc, 3, 1, 5);
+                               readmsgs(ipc, LastMessages, ReadForward, 5);
                                break;
                        case 13:
-                               readmsgs(ipc, 1, 1, 0);
+                               readmsgs(ipc, NewMessages, ReadForward, 0);
                                break;
                        case 11:
-                               readmsgs(ipc, 0, (-1), 0);
+                               readmsgs(ipc, AllMessages, ReadReverse, 0);
                                break;
                        case 12:
-                               readmsgs(ipc, 2, (-1), 0);
+                               readmsgs(ipc, OldMessages, ReadReverse, 0);
                                break;
                        case 71:
-                               readmsgs(ipc, 3, 1, atoi(argbuf));
+                               readmsgs(ipc, LastMessages, ReadForward,
+                                               atoi(argbuf));
                                break;
                        case 7:
                                forget(ipc);
@@ -1416,13 +1430,10 @@ NEWUSR: if (strlen(rc_password) == 0) {
                                validate(ipc);
                                break;
                        case 29:
-                               if (!rc_alt_semantics)
-                                       updatels(ipc);
-                               termn8 = 1;
-                               break;
                        case 30:
-                               if (!rc_alt_semantics)
+                               if (!rc_alt_semantics) {
                                        updatels(ipc);
+                               }
                                termn8 = 1;
                                break;
                        case 48:
@@ -1480,7 +1491,8 @@ NEWUSR:   if (strlen(rc_password) == 0) {
                        case 15:
                                scr_printf("Are you sure (y/n)? ");
                                if (yesno() == 1) {
-                                       updatels(ipc);
+                                       if (!rc_alt_semantics)
+                                               updatels(ipc);
                                        a = 0;
                                        termn8 = 1;
                                }
@@ -1490,10 +1502,11 @@ NEWUSR: if (strlen(rc_password) == 0) {
                                scr_printf("All users will be disconnected!  "
                                           "Really terminate the server? ");
                                if (yesno() == 1) {
+                                       if (!rc_alt_semantics)
+                                               updatels(ipc);
                                        r = CtdlIPCTerminateServerNow(ipc, aaa);
                                        scr_printf("%s\n", aaa);
                                        if (r / 100 == 2) {
-                                               updatels(ipc);
                                                a = 0;
                                                termn8 = 1;
                                        }
@@ -1664,7 +1677,7 @@ NEWUSR:   if (strlen(rc_password) == 0) {
                                break;
 
                        case 70:
-                               edit_system_message(argbuf);
+                               edit_system_message(ipc, argbuf);
                                break;
 
                        case 19:
@@ -1688,10 +1701,24 @@ NEWUSR: if (strlen(rc_password) == 0) {
                                page_user(ipc);
                                break;
 
+                       default: /* allow some math on the command */
+                               /* commands 100... to 100+MAX_EDITORS-1 will
+                                  call the appropriate editor... in other
+                                  words, command numbers 100+ will match
+                                  the citadel.rc keys editor0, editor1, etc.*/
+                               if (mcmd >= 100 && mcmd < (100+MAX_EDITORS))
+                               {
+                                       /* entmsg mode >=2 select editor */
+                                       entmsg(ipc, 0, mcmd - 100 + 2);
+                                       break;
+                               }
                        }       /* end switch */
        } while (termn8 == 0);
 
- TERMN8:       scr_printf("%s logged out.\n", fullname);
+TERMN8:        scr_printf("%s logged out.", fullname);
+       termn8 = 0;
+       color(ORIGINAL_PAIR);
+       scr_printf("\n");
        while (march != NULL) {
                remove_march(march->march_name, 0);
        }