HUGE PATCH. This moves all of mime_parser.c and all
[citadel.git] / citadel / whobbs.c
index e78983c2e79e9ff5ae1e190236c2467020362233..9c0db8216e9383b22c8594b500fd23d46c297284 100644 (file)
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "citadel_ipc.h"
-#include "ipc.h"
-#include "tools.h"
+#include "citadel_dirs.h"
 
 void logoff(int code)
 {
@@ -22,22 +23,30 @@ void logoff(int code)
 
 static void escapize(char *buf, size_t n) {
        char hold[512];
-       int i;
+       int i, len;
+       size_t tmp;
 
        strcpy(hold, buf);
        strcpy(buf, "");
-
-       for (i=0; i<strlen(hold); ++i) {
-               size_t tmp = strlen(buf);
-
-               if (hold[i]=='<')
+       tmp = 0;
+       len = strlen(hold);
+       for (i=0; i<len; ++i) {
+               if (hold[i]=='<') {
                        snprintf(&buf[tmp], n - tmp, "&lt;");
-               else if (hold[i]=='>')
+                       tmp += 4;
+               }
+               else if (hold[i]=='>'){
                        snprintf(&buf[tmp], n - tmp, "&gt;");
-               else if (hold[i]==34)
+                       tmp += 4;
+               }
+               else if (hold[i]==34){
                        snprintf(&buf[tmp], n - tmp, "&quot;");
-               else
+                       tmp += 6;
+               }
+               else{
                        snprintf(&buf[tmp], n - tmp, "%c", hold[i]);
+                       tmp ++;
+               }
        }
 }
 
@@ -60,7 +69,15 @@ int main(int argc, char **argv)
        int r;                  /* IPC response code */
        time_t timenow;
        char *listing = NULL;
-       struct CtdlServInfo *serv_info = NULL;
+       CtdlIPC *ipc = NULL;
+       int relh=0;
+       int home=0;
+       char relhome[PATH_MAX]="";
+       char ctdldir[PATH_MAX]=CTDLDIR;
+
+       CtdlInitBase64Table();
+
+       calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
 
        /* If this environment variable is set, we assume that the program
         * is being called as a cgi-bin from a webserver and will output
@@ -68,17 +85,21 @@ int main(int argc, char **argv)
         */     
        if (getenv("REQUEST_METHOD") != NULL) www = 1;
 
-       attach_to_server(argc, argv, hostbuf, portbuf);
-       serv_gets(buf);
+       ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
+       if (!ipc) {
+               fprintf(stderr, "Server not available: %s\n", strerror(errno));
+               logoff(errno);
+       }
+       CtdlIPC_chat_recv(ipc, buf);
        if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
                fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
                logoff(atoi(buf));
                }
-       strcpy(nodetitle, "this BBS");
-       r = CtdlIPCServerInfo(serv_info, buf);
+       strcpy(nodetitle, "this Citadel site");
+       r = CtdlIPCServerInfo(ipc, buf);
        if (r / 100 == 1) {
-               my_pid = serv_info->serv_pid;
-               strcpy(nodetitle, serv_info->serv_humannode);
+               my_pid = ipc->ServInfo.pid;
+               strcpy(nodetitle, ipc->ServInfo.humannode);
        }
        
        if (www) {
@@ -103,7 +124,7 @@ int main(int argc, char **argv)
                printf("</H1>\n");
        }
 
-       r = CtdlIPCOnlineUsers(&listing, &timenow, buf);
+       r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
        if (r / 100 != 1) {
                fprintf(stderr,"%s: %s\n",argv[0], buf);
                logoff(atoi(buf));
@@ -123,18 +144,18 @@ int main(int argc, char **argv)
        }
 
 
-       while (strlen(listing) > 0) {
-               extract_token(buf, listing, 0, '\n');
+       while (!IsEmptyStr(listing)) {
+               extract_token(buf, listing, 0, '\n', sizeof buf);
                remove_token(listing, 0, '\n');
 
                /* Escape some stuff if we're using www mode */
                if (www) escapize(buf, sizeof buf);
 
                s_pid = extract_int(buf,0);
-               extract(s_user,buf,1);
-               extract(s_room,buf,2);
-               extract(s_host,buf,3);
-               extract(s_client,buf,4);
+               extract_token(s_user, buf, 1, '|', sizeof s_user);
+               extract_token(s_room, buf, 2, '|', sizeof s_room);
+               extract_token(s_host, buf, 3, '|', sizeof s_host);
+               extract_token(s_client, buf, 4, '|', sizeof s_client);
                if (s_pid != my_pid) {
 
                        if (www) printf("<TR><TD>");
@@ -142,9 +163,9 @@ int main(int argc, char **argv)
                        printf("%c", 
                                ((s_pid == my_pid) ? '*' : ' '));
                        if (www) printf("</TD><TD>");
-                       printf("%-25s", s_user);
+                       printf("%-26s", s_user);
                        if (www) printf("</TD><TD>");
-                       printf("%-20s ", s_room);
+                       printf("%-19s ", s_room);
                        if (www) printf("</TD><TD>");
                        printf("%-24s\n", s_host);
                        if (www) printf("</TD><TD>%s</TD></TR>\n", s_client);
@@ -158,7 +179,7 @@ int main(int argc, char **argv)
                        "once per minute)</FONT>\n"
                        "</BODY></HTML>\n");
 
-       r = CtdlIPCQuit();
+       r = CtdlIPCQuit(ipc);
        return (r / 100 == 2) ? 0 : r;
 }