]> code.citadel.org Git - citadel.git/commitdiff
* Convert whobbs, serv_info, misc. functions to new IPC code
authorMichael Hampton <io_error@uncensored.citadel.org>
Sat, 29 Jun 2002 15:55:08 +0000 (15:55 +0000)
committerMichael Hampton <io_error@uncensored.citadel.org>
Sat, 29 Jun 2002 15:55:08 +0000 (15:55 +0000)
citadel/ChangeLog
citadel/Makefile.in
citadel/citadel.c
citadel/citadel_ipc.c
citadel/citadel_ipc.h
citadel/client_crypto.c
citadel/commands.c
citadel/rooms.c
citadel/whobbs.c

index e8b744e4826987c5b988130c927a49e4aa751c74..fec946fa2d6db15d550f1297001552577af528f4 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 591.59  2002/06/29 15:55:07  error
+ * Convert whobbs, serv_info, misc. functions to new IPC code
+
  Revision 591.58  2002/06/27 03:10:04  error
  * rooms.c: converted most functions to new IPC code
 
@@ -3782,3 +3785,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 9dd2e2e81376ab95ba4a16fa269be64d67e645cb..867470864cde2c751245a2d90d728feaf5e412fd 100644 (file)
@@ -81,7 +81,7 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c \
        logging.c messages.c msgbase.c msgform.c serv_spam.c \
        policy.c readlog.c migratenet.c screen.c serv_mrtg.c \
        room_ops.c rooms.c routines.c routines2.c serv_chat.c serv_crypto.c \
-       serv_info.c serv_test.c setup.c snprintf.c stats.c serv_vcard.c \
+       serv_test.c setup.c snprintf.c stats.c serv_vcard.c \
        support.c sysdep.c tools.c user_ops.c userlist.c serv_expire.c \
        whobbs.c sendcommand.c mime_parser.c base64.c getutline.c \
        auth.c chkpwd.c html.c vcard.c serv_upgrade.c serv_vandelay.c \
@@ -110,10 +110,10 @@ serv_modules: $(SERV_MODULES)
 citadel$(EXEEXT): ipc_c_tcp.o citadel.o rooms.o routines.o \
        routines2.o messages.o screen.o citadel_ipc.o \
        client_passwords.o md5.o client_crypto.o \
-       commands.o client_chat.o serv_info.o tools.o $(LIBOBJS)
+       commands.o client_chat.o tools.o $(LIBOBJS)
        $(CC) ipc_c_tcp.o citadel.o rooms.o routines.o \
        routines2.o messages.o screen.o citadel_ipc.o \
-       commands.o client_chat.o serv_info.o tools.o \
+       commands.o client_chat.o tools.o \
        client_passwords.o md5.o client_crypto.o \
        $(LIBOBJS) $(LDFLAGS) -o citadel $(LIBS)
 
@@ -221,8 +221,8 @@ setup: setup.o tools.o
 chkpwd: chkpwd.o auth.o config.o
        $(CC) chkpwd.o auth.o config.o $(LDFLAGS) -o chkpwd $(chkpwd_LIBS)
 
-whobbs$(EXEEXT): whobbs.o ipc_c_tcp.o tools.o client_crypto.o $(LIBOBJS)
-       $(CC) whobbs.o ipc_c_tcp.o tools.o client_crypto.o $(LIBOBJS) $(LDFLAGS) -o whobbs $(LIBS)
+whobbs$(EXEEXT): whobbs.o ipc_c_tcp.o tools.o client_crypto.o citadel_ipc.o $(LIBOBJS)
+       $(CC) whobbs.o ipc_c_tcp.o tools.o client_crypto.o citadel_ipc.o  $(LIBOBJS) $(LDFLAGS) -o whobbs $(LIBS)
 
 migratenet$(EXEEXT): migratenet.o config.o ipc_c_tcp.o client_crypto.o tools.o libcitserver.la $(LIBOBJS)
        $(LIBTOOL) $(CC) migratenet.o config.o ipc_c_tcp.o client_crypto.o tools.o libcitserver.la $(LIBOBJS) $(LDFLAGS) -o migratenet $(LIBS)
index b226398bfe7bd366893719f545486775e31c98fa..29b658cb1fb1a17775219e6f48043f3004d94c32 100644 (file)
@@ -35,7 +35,6 @@
 
 #include "citadel.h"
 #include "axdefs.h"
-#include "serv_info.h"
 #include "routines.h"
 #include "routines2.h"
 #include "rooms.h"
@@ -101,10 +100,10 @@ char rc_floor_mode;
 char floor_mode;
 char curr_floor = 0;           /* number of current floor */
 char floorlist[128][SIZ];      /* names of floors */
-char express_msgs = 0;         /* express messages waiting! */
 int termn8 = 0;                        /* Set to nonzero to cause a logoff */
 int secure;                    /* Set to nonzero when wire is encrypted */
 
+extern char express_msgs;      /* express messages waiting! */
 extern int rc_ansi_color;      /* ansi color value from citadel.rc */
 extern int next_lazy_cmd;
 
@@ -729,9 +728,9 @@ int set_password(void)
  */
 void get_serv_info(char *supplied_hostname)
 {
-       char buf[512];
+       char buf[SIZ];
 
-       CtdlInternalGetServInfo(&serv_info);
+       CtdlIPCServerInfo(&serv_info, buf);
 
        /* be nice and identify ourself to the server */
        CtdlIPCIdentifySoftware(SERVER_TYPE, 0, REV_LEVEL,
@@ -757,6 +756,8 @@ void who_is_online(int longlist)
        time_t idletime, idlehours, idlemins, idlesecs;
        int last_session = (-1);
        int skipidle = 0;
+       char *listing = NULL;
+       int r;                          /* IPC response code */
     
        if (longlist == 2) {
                longlist = 0;
@@ -773,11 +774,15 @@ void who_is_online(int longlist)
                color(DIM_WHITE);
                pprintf("--- --- ------------------------- -------------------- ------------------------\n");
        }
-       serv_puts("RWHO");
-       serv_gets(buf);
-       if (buf[0] == '1') {
-               while (serv_gets(buf), strcmp(buf, "000")) {
-               int isidle = 0;
+       r = CtdlIPCOnlineUsers(&listing, &timenow, buf);
+       if (r / 100 == 1) {
+               while (strlen(listing) > 0) {
+                       int isidle = 0;
+                       
+                       /* Get another line */
+                       extract_token(buf, listing, 0, '\n');
+                       remove_token(listing, 0, '\n');
+
                        extract(username, buf, 1);
                        extract(roomname, buf, 2);
                        extract(fromhost, buf, 3);
@@ -794,12 +799,11 @@ void who_is_online(int longlist)
                                        strcat(roomname, " ");
                                }
                                strcpy(&roomname[14], "[idle]");
-                       if (skipidle)
-                  isidle = 1;
+                               if (skipidle)
+                                       isidle = 1;
                        }
 
                        if (longlist) {
-
                                extract(actual_user, buf, 8);
                                extract(actual_room, buf, 9);
                                extract(actual_host, buf, 10);
index ef3e3cdc046905f757064d92122ff7a14fc7d576..986add022a197e243ec3ea1ab95922bac927d981 100644 (file)
@@ -28,7 +28,7 @@
 #ifdef THREADED_CLIENT
 pthread_mutex_t rwlock;
 #endif
-extern char express_msgs;
+char express_msgs = 0;
 
 static volatile int download_in_progress = 0;  /* download file open */
 static volatile int upload_in_progress = 0;    /* upload file open */
@@ -42,14 +42,7 @@ int CtdlIPCNoop(void)
 {
        char aaa[128];
 
-       register int ret;
-
-       netio_lock();
-       serv_puts("NOOP");
-       serv_gets(aaa);
-       ret = atoi(aaa);
-       netio_unlock();
-       return ret;
+       return CtdlIPCGenericCommand("NOOP", NULL, 0, NULL, NULL, aaa);
 }
 
 
@@ -399,11 +392,8 @@ int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime,
        if (ret / 100 == 1) {
                if (!as_mime) {
                        while (strlen(bbb) > 4 && bbb[4] == '=') {
-                               int a;
-
                                extract_token(aaa, bbb, 0, '\n');
-                               a = strlen(aaa);
-                               safestrncpy(bbb, &bbb[a + 1], strlen(bbb) - a);
+                               remove_token(bbb, 0, '\n');
 
                                if (!strncasecmp(aaa, "nhdr=yes", 8))
                                        mret[0]->nhdr = 1;
@@ -450,7 +440,7 @@ int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime,
                                }
                        }
                        /* Eliminate "text\n" */
-                       safestrncpy(bbb, &bbb[5], strlen(bbb) - 4);
+                       remove_token(bbb, 0, '\n');
                }
                if (strlen(bbb)) {
                        /* Strip trailing whitespace */
@@ -480,16 +470,52 @@ int CtdlIPCWhoKnowsRoom(char **listing, char *cret)
 
 
 /* INFO */
-int CtdlIPCServerInfo(char **listing, char *cret)
+int CtdlIPCServerInfo(struct CtdlServInfo *ServInfo, char *cret)
 {
        register int ret;
        size_t bytes;
+       char *listing = NULL;
+       char buf[SIZ];
 
        if (!cret) return -2;
-       if (!listing) return -2;
-       if (*listing) return -2;
+       if (!ServInfo) return -2;
+
+       ret = CtdlIPCGenericCommand("INFO", NULL, 0, &listing, &bytes, cret);
+       if (ret / 100 == 1) {
+               int line = 0;
+
+               while (*listing && strlen(listing)) {
+                       extract_token(buf, listing, 0, '\n');
+                       remove_token(listing, 0, '\n');
+                       switch (line++) {
+                       case 0:         ServInfo->serv_pid = atoi(buf);
+                                       break;
+                       case 1:         strcpy(ServInfo->serv_nodename,buf);
+                                       break;
+                       case 2:         strcpy(ServInfo->serv_humannode,buf);
+                                       break;
+                       case 3:         strcpy(ServInfo->serv_fqdn,buf);
+                                       break;
+                       case 4:         strcpy(ServInfo->serv_software,buf);
+                                       break;
+                       case 5:         ServInfo->serv_rev_level = atoi(buf);
+                                       break;
+                       case 6:         strcpy(ServInfo->serv_bbs_city,buf);
+                                       break;
+                       case 7:         strcpy(ServInfo->serv_sysadm,buf);
+                                       break;
+                       case 9:         strcpy(ServInfo->serv_moreprompt,buf);
+                                       break;
+                       case 10:        ServInfo->serv_ok_floors = atoi(buf);
+                                       break;
+                       case 11:        ServInfo->serv_paging_level = atoi(buf);
+                                       break;
+                       case 13:        ServInfo->serv_supports_qnop = atoi(buf);
+                                       break;
+                       }
+               }
 
-       ret = CtdlIPCGenericCommand("INFO", NULL, 0, listing, &bytes, cret);
+       }
        return ret;
 }
 
index 81c941297c5619c21ffdeab8d8833ee83178e98f..1928b28cfad5edc3ef2ded252f4ac808d7035ca5 100644 (file)
@@ -74,7 +74,7 @@ int CtdlIPCGetMessages(int which, int whicharg, const char *template,
 int CtdlIPCGetSingleMessage(long msgnum, int headers, int as_mime,
                struct ctdlipcmessage **mret, char *cret);
 int CtdlIPCWhoKnowsRoom(char **listing, char *cret);
-int CtdlIPCServerInfo(char **listing, char *cret);
+int CtdlIPCServerInfo(struct CtdlServInfo *ServInfo, char *cret);
 int CtdlIPCReadDirectory(char **listing, char *cret);
 int CtdlIPCSetLastRead(long msgnum, char *cret);
 int CtdlIPCInviteUserToRoom(const char *username, char *cret);
index 64cd11f0758f3086d04a7e022f7cb75b697c573a..ec6ab2538a98173f204551e21f86e561fbc9030c 100644 (file)
@@ -13,6 +13,7 @@
 #include <sys/types.h>
 #include "citadel.h"
 #include "client_crypto.h"
+#include "citadel_ipc.h"
 #include "ipc.h"
 
 #ifdef HAVE_OPENSSL
@@ -149,6 +150,7 @@ int starttls(void)
 {
 #ifdef HAVE_OPENSSL
        int a;
+       int r;                          /* IPC response code */
        char buf[SIZ];
        SSL_METHOD *ssl_method;
        DH *dh;
@@ -271,9 +273,16 @@ int starttls(void)
        serv_puts("STLS");
        serv_gets(buf);
        if (buf[0] != '2') {
-               error_printf("Server can't start TLS: %s\n", &buf[4]);
+               error_printf("Server can't start TLS: %s\n", buf);
                return 0;
        }
+       /* New code
+       r = CtdlIPCStartEncryption(buf);
+       if (r / 100 != 2) {
+               error_printf("Server can't start TLS: %s\n", buf);
+               return 0;
+       }
+       */
 
        /* Do SSL/TLS handshake */
        if ((a = SSL_connect(ssl)) < 1) {
index 1c64c81a3af79998767a3e4f27b8534cb6e151f3..cdb04f9e8cee9e6873e61a032edeab983ad4c0e3 100644 (file)
@@ -346,6 +346,7 @@ void set_keepalives(int s)
 static time_t idlet = 0;
 static void really_do_keepalive(void) {
        char buf[1024];
+       int r;                          /* IPC response code */
 
        time(&idlet);
 
@@ -353,10 +354,8 @@ static void really_do_keepalive(void) {
         * wait for a response.
         */
        if (keepalives_enabled == KA_YES) {
-               serv_puts("NOOP");
-               serv_gets(buf);
-               if (buf[3] == '*') {
-                       express_msgs = 1;
+               r = CtdlIPCNoop();
+               if (express_msgs > 0) {
                        if (ok_to_interrupt == 1) {
                                scr_printf("\r%64s\r", "");
                                print_express();
index 7c390c32c65fed0a596860992667a34c9d509191..6e49307044dd517d567979078fd5d9ee82acb287 100644 (file)
@@ -393,6 +393,7 @@ void editthisroom(void)
        int rorder;
        int expire_mode = 0;
        int expire_value = 0;
+       int r;                          /* IPC response code */
 
        /* Fetch the existing room config */
        serv_puts("GETR");
@@ -1154,6 +1155,7 @@ void edit_floor(void)
        char buf[SIZ];
        int expire_mode = 0;
        int expire_value = 0;
+       int r;                          /* IPC response code */
 
        load_floorlist();
 
@@ -1201,7 +1203,7 @@ void edit_floor(void)
        /* Save it */
        r = CtdlIPCSetMessageExpirationPolicy(1, expire_mode,
                                              expire_value, buf);
-       r = CtdlIPCEditFloor(curr_floor, &floorlist[(int)curr_floor][0]);
+       r = CtdlIPCEditFloor(curr_floor, &floorlist[(int)curr_floor][0], buf);
        scr_printf("%s\n", buf);
        load_floorlist();
 }
index 68573d1d4d7502a4e421e6e3dcb18b54bb83c6dd..80bc241b555fc535342a3ba7209645de308b862a 100644 (file)
@@ -5,11 +5,13 @@
  *
  */
 
+#include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
 #include "citadel.h"
+#include "citadel_ipc.h"
 #include "ipc.h"
 #include "tools.h"
 
@@ -46,7 +48,6 @@ int main(int argc, char **argv)
 {
        char buf[512];
        char nodetitle[SIZ];
-       int a;
        int www = 0;
        int s_pid = 0;
        int my_pid = 0;
@@ -56,6 +57,10 @@ int main(int argc, char **argv)
        char s_room[SIZ];
        char s_host[SIZ];
        char s_client[SIZ];
+       int r;                  /* IPC response code */
+       time_t timenow;
+       char *listing = NULL;
+       struct CtdlServInfo *serv_info = NULL;
 
        /* If this environment variable is set, we assume that the program
         * is being called as a cgi-bin from a webserver and will output
@@ -70,16 +75,11 @@ int main(int argc, char **argv)
                logoff(atoi(buf));
                }
        strcpy(nodetitle, "this BBS");
-       serv_puts("INFO");
-       serv_gets(buf);
-       if (buf[0]=='1') {
-               a = 0;
-               while (serv_gets(buf), strcmp(buf,"000")) {
-                       if (a==0) my_pid = atoi(buf);
-                       if (a==2) strcpy(nodetitle, buf);
-                       ++a;
-                       }
-               }
+       r = CtdlIPCServerInfo(serv_info, buf);
+       if (r / 100 == 1) {
+               my_pid = serv_info->serv_pid;
+               strcpy(nodetitle, serv_info->serv_humannode);
+       }
        
        if (www) {
                printf( "Content-type: text/html\n"
@@ -103,10 +103,9 @@ int main(int argc, char **argv)
                printf("</H1>\n");
        }
 
-       serv_puts("RWHO");
-       serv_gets(buf);
-       if (buf[0]!='1') {
-               fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
+       r = CtdlIPCOnlineUsers(&listing, &timenow, buf);
+       if (r / 100 != 1) {
+               fprintf(stderr,"%s: %s\n",argv[0], buf);
                logoff(atoi(buf));
        }
 
@@ -120,11 +119,13 @@ int main(int argc, char **argv)
                printf( "Session         User name               "
                        "Room                  From host\n");
                printf( "------- ------------------------- "
-                       "-------------------- ------------------------\n");
+                       "------------------- ------------------------\n");
        }
 
 
-       while (serv_gets(buf), strcmp(buf,"000")) {
+       while (strlen(listing) > 0) {
+               extract_token(buf, listing, 0, '\n');
+               remove_token(listing, 0, '\n');
 
                /* Escape some stuff if we're using www mode */
                if (www) escapize(buf, sizeof buf);
@@ -156,10 +157,9 @@ int main(int argc, char **argv)
                        "once per minute)</FONT>\n"
                        "</BODY></HTML>\n");
 
-       serv_puts("QUIT");
-       serv_gets(buf);
-       return 0;
-       }
+       r = CtdlIPCQuit();
+       return (r / 100 == 2) ? 0 : r;
+}
 
 
 #ifndef HAVE_STRERROR