Removed the logging facility from citserver, use syslog instead
[citadel.git] / citadel / textclient / citadel.c
index a50b8a85f96ec7f47428e7999aa60b2ff00b5340..94ca65341bd8b62e59fecc0d1556e0815b597762 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * Main source module for the client program.
  *
  * Copyright (c) 1987-2009 by the citadel.org team
 
 #define IFEXPERT if (userflags&US_EXPERT)
 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
-#define IFAIDE if (axlevel>=6)
-#define IFNAIDE if (axlevel<6)
+#define IFAIDE if (axlevel>=AxAideU)
+#define IFNAIDE if (axlevel<AxAideU)
 
 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2);
-
 march *marchptr = NULL;
+extern char *moreprompt;
 
 /* globals associated with the client program */
 char temp[PATH_MAX];           /* Name of general-purpose temp file */
@@ -98,7 +96,7 @@ char *uglist[UGLISTLEN]; /* size of the ungoto list */
 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
 int uglistsize = 0;
 char is_mail = 0;              /* nonzero when we're in a mail room */
-char axlevel = 0;              /* access level */
+char axlevel = AxDeleted;              /* access level */
 char is_room_aide = 0;         /* boolean flag, 1 if room aide */
 int timescalled;
 int posted;
@@ -130,12 +128,12 @@ int enable_syslog = 0;
 
 
 /*
- * CtdlLogPrintf()  ...   Write logging information; 
+ * syslog()  ...   Write logging information; 
  *                  simple here to have the same 
  *                  symbols in the client.
  */
 
-void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...) {   
+void syslog(enum LogLevel loglevel, const char *format, ...) {   
        va_list arg_ptr;
 
        va_start(arg_ptr, format);
@@ -170,8 +168,6 @@ void ctdl_logoff(char *file, int line, CtdlIPC *ipc, int code)
 /*
  * now clean up various things
  */
-       screen_delete();
-
        unlink(temp);
        unlink(temp2);
        nukedir(tempdir);
@@ -232,9 +228,7 @@ void formout(CtdlIPC *ipc, char *name)
                return;
        }
        if (text) {
-               fmout(screenwidth, NULL, text, NULL,
-                     ((userflags & US_PAGINATOR) ? 1 : 0),
-                     screenheight, 1, 1);
+               fmout(screenwidth, NULL, text, NULL, 1);
                free(text);
        }
 }
@@ -251,12 +245,12 @@ void userlist(CtdlIPC *ipc, char *patn)
 
        r = CtdlIPCUserListing(ipc, patn, &listing, buf);
        if (r / 100 != 1) {
-               pprintf("%s\n", buf);
+               scr_printf("%s\n", buf);
                return;
        }
 
-       pprintf("       User Name           Num  L Last Visit Logins Messages\n");
-       pprintf("------------------------- ----- - ---------- ------ --------\n");
+       scr_printf("       User Name           Num  L Last Visit Logins Messages\n");
+       scr_printf("------------------------- ----- - ---------- ------ --------\n");
        if (listing != NULL) while (!IsEmptyStr(listing)) {
                extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');
@@ -264,22 +258,22 @@ void userlist(CtdlIPC *ipc, char *patn)
                if (sigcaught == 0) {
                    extract_token(fl, buf, 0, '|', sizeof fl);
                    if (pattern(fl, patn) >= 0) {
-                       pprintf("%-25s ", fl);
-                       pprintf("%5ld %d ", extract_long(buf, 2),
+                       scr_printf("%-25s ", fl);
+                       scr_printf("%5ld %d ", extract_long(buf, 2),
                               extract_int(buf, 1));
                        lc = extract_long(buf, 3);
                        localtime_r(&lc, &tmbuf);
-                       pprintf("%02d/%02d/%04d ",
+                       scr_printf("%02d/%02d/%04d ",
                               (tmbuf.tm_mon + 1),
                               tmbuf.tm_mday,
                               (tmbuf.tm_year + 1900));
-                       pprintf("%6ld %8ld\n", extract_long(buf, 4), extract_long(buf, 5));
+                       scr_printf("%6ld %8ld\n", extract_long(buf, 4), extract_long(buf, 5));
                    }
 
                }
        }
        free(listing);
-       pprintf("\n");
+       scr_printf("\n");
 }
 
 
@@ -477,6 +471,7 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
        switch(room->RRdefaultview) {
                case VIEW_BBS:
                case VIEW_MAILBOX:
+               case VIEW_BLOG:
                                        entmsg_ok = 1;
                                        break;
                default:
@@ -536,9 +531,15 @@ void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
                        rv = system(rc_gotmail_cmd);
                }
        }
-       status_line(ipc->ServInfo.humannode, ipc->ServInfo.site_location,
-                       room_name, secure, newmailcount);
        free(room);
+
+       if (screenwidth>5) snprintf(&status_line[1], screenwidth-1, "%s  |  %s  |  %s  |  %s  |  %d new mail  |",
+               (secure ? "Encrypted" : "Unencrypted"),
+               ipc->ServInfo.humannode,
+               ipc->ServInfo.site_location,
+               room_name,
+               newmailcount
+       );
 }
 
 /* Goto next room having unread messages.
@@ -603,7 +604,6 @@ void forget_all_rooms_on(CtdlIPC *ipc, int ffloor)
        int r;                          /* IPC response code */
 
        scr_printf("Forgetting all rooms on %s...\n", &floorlist[ffloor][0]);
-       scr_flush();
        remove_march("_FLOOR_", ffloor);
        r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, ffloor, &flist, buf);
        if (r / 100 != 1) {
@@ -949,7 +949,7 @@ void read_config(CtdlIPC *ipc)
        /* get misc user info */   
        r = CtdlIPCGetBio(ipc, fullname, &resp, buf);
        if (r / 100 != 1) {
-               pprintf("%s\n", buf);
+               scr_printf("%s\n", buf);
                return;
        }
        extract_token(_fullname, buf, 1, '|', sizeof fullname);
@@ -981,8 +981,6 @@ void read_config(CtdlIPC *ipc)
        scr_printf("\n");
 
        /* show preferences */
-       scr_printf("Your screen width: ");                                     color(BRIGHT_CYAN); scr_printf("%d",   /*user->USscreenwidth*/ screenwidth);          color(DIM_WHITE); 
-       scr_printf(", height: ");                                              color(BRIGHT_CYAN); scr_printf("%d\n", /*user->USscreenheight*/ screenheight);        color(DIM_WHITE);  
        scr_printf("Are you an experienced Citadel user: ");                   color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXPERT) ? "Yes" : "No");     color(DIM_WHITE);
        scr_printf("Print last old message on New message request: ");         color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_LASTOLD)? "Yes" : "No");     color(DIM_WHITE);
        scr_printf("Prompt after each message: ");                             color(BRIGHT_CYAN); scr_printf("%s\n", (!(user->flags & US_NOPROMPT))? "Yes" : "No"); color(DIM_WHITE);
@@ -1026,7 +1024,7 @@ void system_info(CtdlIPC *ipc)
        mrtg_active_users = extract_int(resp, 0);
        remove_token(resp, 0, '\n');
        extract_token(mrtg_server_uptime, resp, 0, '\n', sizeof mrtg_server_uptime);
-    free(resp);
+       free(resp);
        resp = NULL;
 
        /* get high message# */
@@ -1087,7 +1085,7 @@ void check_screen_dims(void)
        if (have_xterm) {       /* dynamically size screen if on an xterm */
                if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
                        if (xwinsz.height)
-                               screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
+                               screenheight = (int) xwinsz.height;
                        if (xwinsz.width)
                                screenwidth = (int) xwinsz.width;
                }
@@ -1158,6 +1156,7 @@ void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
        char buf[SIZ];
 
        CtdlIPCServerInfo(ipc, buf);
+       moreprompt = ipc->ServInfo.moreprompt;
 
        /* be nice and identify ourself to the server */
        CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
@@ -1272,13 +1271,13 @@ void who_is_online(CtdlIPC *ipc, int longlist)
 
        if (!longlist) {
                color(BRIGHT_WHITE);
-               pprintf("           User Name               Room          ");
-               if (screenwidth >= 80) pprintf(" Idle        From host");
-               pprintf("\n");
+               scr_printf("           User Name               Room          ");
+               if (screenwidth >= 80) scr_printf(" Idle        From host");
+               scr_printf("\n");
                color(DIM_WHITE);
-               pprintf("   ------------------------- --------------------");
-               if (screenwidth >= 80) pprintf(" ---- ------------------------");
-               pprintf("\n");
+               scr_printf("   ------------------------- --------------------");
+               if (screenwidth >= 80) scr_printf(" ---- ------------------------");
+               scr_printf("\n");
        }
        r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
        listing = SortOnlineUsers(listing);
@@ -1312,13 +1311,13 @@ void who_is_online(CtdlIPC *ipc, int longlist)
                                extract_token(actual_room, buf, 9, '|', sizeof actual_room);
                                extract_token(actual_host, buf, 10, '|', sizeof actual_host);
 
-                               pprintf("  Flags: %s\n", flags);
-                               pprintf("Session: %d\n", extract_int(buf, 0));
-                               pprintf("   Name: %s\n", username);
-                               pprintf("In room: %s\n", roomname);
-                               pprintf("   Host: %s\n", fromhost);
-                               pprintf(" Client: %s\n", clientsoft);
-                               pprintf("   Idle: %ld:%02ld:%02ld\n",
+                               scr_printf("  Flags: %s\n", flags);
+                               scr_printf("Session: %d\n", extract_int(buf, 0));
+                               scr_printf("   Name: %s\n", username);
+                               scr_printf("In room: %s\n", roomname);
+                               scr_printf("   Host: %s\n", fromhost);
+                               scr_printf(" Client: %s\n", clientsoft);
+                               scr_printf("   Idle: %ld:%02ld:%02ld\n",
                                        (long) idlehours,
                                        (long) idlemins,
                                        (long) idlesecs);
@@ -1326,59 +1325,59 @@ void who_is_online(CtdlIPC *ipc, int longlist)
                                if ( (!IsEmptyStr(actual_user)&&
                                      !IsEmptyStr(actual_room)&&
                                      !IsEmptyStr(actual_host))) {
-                                       pprintf("(really ");
-                                       if (!IsEmptyStr(actual_user)) pprintf("<%s> ", actual_user);
-                                       if (!IsEmptyStr(actual_room)) pprintf("in <%s> ", actual_room);
-                                       if (!IsEmptyStr(actual_host)) pprintf("from <%s> ", actual_host);
-                                       pprintf(")\n");
+                                       scr_printf("(really ");
+                                       if (!IsEmptyStr(actual_user)) scr_printf("<%s> ", actual_user);
+                                       if (!IsEmptyStr(actual_room)) scr_printf("in <%s> ", actual_room);
+                                       if (!IsEmptyStr(actual_host)) scr_printf("from <%s> ", actual_host);
+                                       scr_printf(")\n");
                                }
-                               pprintf("\n");
+                               scr_printf("\n");
 
                        } else {
                                if (isidle == 0) {
                                        if (extract_int(buf, 0) == last_session) {
-                                               pprintf("        ");
+                                               scr_printf("        ");
                                        }
                                        else {
                                                color(BRIGHT_MAGENTA);
-                                               pprintf("%-3s", flags);
+                                               scr_printf("%-3s", flags);
                                        }
                                        last_session = extract_int(buf, 0);
                                        color(BRIGHT_CYAN);
-                                       pprintf("%-25s ", username);
+                                       scr_printf("%-25s ", username);
                                        color(BRIGHT_MAGENTA);
                                        roomname[20] = 0;
-                                       pprintf("%-20s", roomname);
+                                       scr_printf("%-20s", roomname);
 
                                        if (screenwidth >= 80) {
-                                               pprintf(" ");
+                                               scr_printf(" ");
                                                if (idletime > rc_idle_threshold) {
                                                        /* over 1000d, must be gone fishing */
                                                        if (idlehours > 23999) {
-                                                               pprintf("fish");
+                                                               scr_printf("fish");
                                                        /* over 10 days */
                                                        } else if (idlehours > 239) {
-                                                               pprintf("%3ldd", idlehours / 24);
+                                                               scr_printf("%3ldd", idlehours / 24);
                                                        /* over 10 hours */
                                                        } else if (idlehours > 9) {
-                                                               pprintf("%1ldd%02ld",
+                                                               scr_printf("%1ldd%02ld",
                                                                        idlehours / 24,
                                                                        idlehours % 24);
                                                        /* less than 10 hours */
                                                        }
                                                        else {
-                                                               pprintf("%1ld:%02ld", idlehours, idlemins);
+                                                               scr_printf("%1ld:%02ld", idlehours, idlemins);
                                                        }
                                                }
                                                else {
-                                                       pprintf("    ");
+                                                       scr_printf("    ");
                                                }
-                                               pprintf(" ");
+                                               scr_printf(" ");
                                                color(BRIGHT_CYAN);
                                                fromhost[24] = '\0';
-                                               pprintf("%-24s", fromhost);
+                                               scr_printf("%-24s", fromhost);
                                        }
-                                       pprintf("\n");
+                                       scr_printf("\n");
                                        color(DIM_WHITE);
                                }
                        }
@@ -1407,8 +1406,7 @@ int shift(int argc, char **argv, int start, int count) {
 }
 
 static void statusHook(char *s) {
-       sln_printf(s);
-       sln_flush();
+       scr_printf(s);
 }
 
 /*
@@ -1459,16 +1457,15 @@ int main(int argc, char **argv)
 
        eCrash_Init(&params);
 #endif 
-       setIPCDeathHook(screen_delete);
-       setIPCErrorPrintf(err_printf);
+       setIPCErrorPrintf(scr_printf);
        setCryptoStatusHook(statusHook);
        
        /* Permissions sanity check - don't run citadel setuid/setgid */
        if (getuid() != geteuid()) {
-               err_printf("Please do not run citadel setuid!\n");
+               scr_printf("Please do not run citadel setuid!\n");
                logoff(NULL, 3);
        } else if (getgid() != getegid()) {
-               err_printf("Please do not run citadel setgid!\n");
+               scr_printf("Please do not run citadel setgid!\n");
                logoff(NULL, 3);
        }
 
@@ -1486,9 +1483,6 @@ int main(int argc, char **argv)
 #ifdef HAVE_OPENSSL
        arg_encrypt = RC_DEFAULT;
 #endif
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-       arg_screen = RC_DEFAULT;
-#endif
 
        /* 
         * Handle command line options as if we were called like /bin/login
@@ -1514,18 +1508,6 @@ int main(int argc, char **argv)
                        return 1;
 #endif
                }
-               if (!strcmp(argv[a], "-s")) {
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-                       arg_screen = RC_NO;
-#endif
-                       argc = shift(argc, argv, a, 1);
-               }
-               if (!strcmp(argv[a], "-S")) {
-#if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
-                       arg_screen = RC_YES;
-#endif
-                       argc = shift(argc, argv, a, 1);
-               }
                if (!strcmp(argv[a], "-p")) {
                        struct stat st;
                
@@ -1568,17 +1550,19 @@ int main(int argc, char **argv)
        newprompt("Connect to (return for local server): ", hostbuf, 64);
 #endif
 
-       sln_printf("Attaching to server... \r");
-       sln_flush();
+       scr_printf("Attaching to server...\n");
        ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
        if (!ipc) {
-               screen_delete();
                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
+
+       CtdlIPC_SetNetworkStatusCallback(ipc, scr_wait_indicator);
+
+       if (!(ipc->isLocal)) {
+               scr_printf("Connected to %s [%s].\n", ipc->ip_hostname, ipc->ip_address);
+       }
+
        ipc_for_signal_handlers = ipc;  /* KLUDGE cover your eyes */
 
        CtdlIPC_chat_recv(ipc, aaa);
@@ -1623,10 +1607,6 @@ int main(int argc, char **argv)
        get_serv_info(ipc, telnet_client_host);
        scr_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode,
                   ipc->ServInfo.site_location);
-       scr_flush();
-
-       status_line(ipc->ServInfo.humannode, ipc->ServInfo.site_location, NULL,
-                   secure, -1);
 
        screenwidth = 80;       /* default screen dimensions */
        screenheight = 24;
@@ -1680,6 +1660,12 @@ int main(int argc, char **argv)
                mcmd = 29;
                goto TERMN8;
        }
+
+       /* FIXME this is a stupid way to do guest mode but it's a reasonable test harness FIXME */
+       if ( (ipc->ServInfo.guest_logins) && (!strcasecmp(fullname, "guest")) ) {
+               goto PWOK;
+       }
+
        /* sign on to the server */
        r = CtdlIPCTryLogin(ipc, fullname, aaa);
        if (r / 100 != 3)
@@ -1776,7 +1762,7 @@ NEWUSR:   if (IsEmptyStr(rc_password)) {
                                rv = system(rc_gotmail_cmd);
                        }
                }
-               if ((axlevel >= 6) && (chek.needvalid > 0)) {
+               if ((axlevel >= AxAideU) && (chek.needvalid > 0)) {
                        scr_printf("*** Users need validation\n");
                }
                if (chek.needregis > 0) {
@@ -1802,17 +1788,11 @@ NEWUSR: if (IsEmptyStr(rc_password)) {
        screenwidth = 80;
        screenheight = 24;
        r = CtdlIPCGetConfig(ipc, &myself, aaa);
-       if (r == 2) {
-               screenwidth = myself->USscreenwidth;
-               screenheight = myself->USscreenheight;
-       }
        if (getenv("TERM") != NULL)
                if (!strcmp(getenv("TERM"), "xterm")) {
                        have_xterm = 1;
                }
-#ifdef TIOCGWINSZ
        check_screen_dims();
-#endif
 
        set_floor_mode(ipc);
 
@@ -2115,21 +2095,6 @@ NEWUSR:  if (IsEmptyStr(rc_password)) {
                                chatmode(ipc);
                                break;
 
-                       case 2:
-                               if (ipc->isLocal) {
-                                       screen_reset();
-                                       stty_ctdl(SB_RESTORE);
-                                       snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
-                                                "exec ./subsystem %ld %d %d", fullname,
-                                                usernum, screenwidth, axlevel);
-                                       ka_system(aaa);
-                                       stty_ctdl(SB_NO_INTR);
-                                       screen_set();
-                               } else {
-                                       scr_printf("*** Can't run doors when server is not local.\n");
-                               }
-                               break;
-
                        case 17:
                                who_is_online(ipc, 0);
                                break;
@@ -2349,11 +2314,10 @@ TERMN8: scr_printf("%s logged out.", fullname);
                remove_march(marchptr->march_name, 0);
        }
        if (mcmd == 30) {
-               sln_printf("\n\nType 'off' to disconnect, or next user...\n");
+               scr_printf("\n\nType 'off' to disconnect, or next user...\n");
        }
        CtdlIPCLogout(ipc);
        if ((mcmd == 29) || (mcmd == 15)) {
-               screen_delete();
                stty_ctdl(SB_RESTORE);
                formout(ipc, "goodbye");
                logoff(ipc, 0);