From a54a72a0480cfb752f971f769189068ab296fa6f Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 12 Dec 1998 02:15:09 +0000 Subject: [PATCH] Brought over message reading functions from old WebCit --- webcit/ChangeLog | 3 + webcit/Makefile.in | 7 +- webcit/child.h | 2 + webcit/messages.c | 257 +++++++++++++++++++++++++++++++++++++++ webcit/static/empty.html | 5 + webcit/tools.c | 11 ++ webcit/webcit.c | 59 ++------- 7 files changed, 295 insertions(+), 49 deletions(-) create mode 100644 webcit/messages.c create mode 100644 webcit/static/empty.html diff --git a/webcit/ChangeLog b/webcit/ChangeLog index f89fb6557..7fd4d9bd9 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,3 +1,6 @@ +Fri Dec 11 21:14:36 EST 1998 Art Cancro + * Brought over message reading functions from old WebCit + 1998-12-10 Nathan Bryant * context_loop.c: really fix the SO_LINGER stuff * webserver.c: remove commented-out references to SO_LINGER diff --git a/webcit/Makefile.in b/webcit/Makefile.in index a008a7cca..1444065b8 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -33,9 +33,9 @@ snprintf.o: snprintf.c webcit: webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \ - roomops.o tools.o + roomops.o tools.o messages.o $(CC) webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o \ - tools.o roomops.o -o webcit + tools.o roomops.o messages.o -o webcit webcit.o: webcit.c webcit.h child.h $(CC) $(CFLAGS) $(DEFS) -c webcit.c @@ -60,3 +60,6 @@ tools.o: tools.c webcit.h roomops.o: roomops.c webcit.h child.h $(CC) $(CFLAGS) $(DEFS) -c roomops.c + +messages.o: messages.c webcit.h child.h + $(CC) $(CFLAGS) $(DEFS) -c messages.c diff --git a/webcit/child.h b/webcit/child.h index e19c2efb7..5d3b69eb9 100644 --- a/webcit/child.h +++ b/webcit/child.h @@ -39,3 +39,5 @@ long extract_long(char *source, long int parmnum); void dump_vars(void); void embed_main_menu(void); void serv_read(char *buf, int bytes); +int haschar(char *st, char ch); +void readloop(char *oper); diff --git a/webcit/messages.c b/webcit/messages.c new file mode 100644 index 000000000..3e006c0dc --- /dev/null +++ b/webcit/messages.c @@ -0,0 +1,257 @@ +#include +#include +#include +#include +#include +#include +#include +#include "webcit.h" +#include "child.h" + +char reply_to[512]; +long msgarr[1024]; + +/* + * Look for URL's embedded in a buffer and make them linkable. We use a + * target window in order to keep the BBS session in its own window. + */ +void url(buf) +char buf[]; { + + int pos; + int start,end; + char ench; + char urlbuf[256]; + char outbuf[256]; + + start = (-1); + end = strlen(buf); + ench = 0; + + for (pos=0; pos0)&&(buf[start-1]=='<')) ench = '>'; + if ((start>0)&&(buf[start-1]=='[')) ench = ']'; + if ((start>0)&&(buf[start-1]=='(')) ench = ')'; + if ((start>0)&&(buf[start-1]=='{')) ench = '}'; + + for (pos=strlen(buf); pos>start; --pos) { + if ((buf[pos]==' ')||(buf[pos]==ench)) end = pos; + } + + strncpy(urlbuf,&buf[start],end-start); + urlbuf[end-start] = 0; + + + strncpy(outbuf,buf,start); + sprintf(&outbuf[start],"%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c", + LB,QU,urlbuf,QU,QU,TARGET,QU,RB,urlbuf,LB,RB); + strcat(outbuf,&buf[end]); + strcpy(buf,outbuf); + } + + +void read_message(msgnum, oper) +long msgnum; +char *oper; { + char buf[256]; + char m_subject[256]; + char from[256]; + long now; + struct tm *tm; + int format_type = 0; + int nhdr = 0; + int bq = 0; + + sprintf(buf,"MSG0 %ld",msgnum); + serv_puts(buf); + serv_gets(buf); + if (buf[0]!='1') { + wprintf("ERROR: %s
\n",&buf[4]); + return; + } + + wprintf(""); + + if (is_room_aide) { + wprintf(""); + } + + wprintf("
\n"); + wprintf(" "); + strcpy(m_subject,""); + + strcpy(reply_to,"nobody...xxxxx"); + while(serv_gets(buf), strncasecmp(buf,"text",4)) { + if (!strncasecmp(buf,"nhdr=yes",8)) nhdr=1; + if (nhdr==1) buf[0]='_'; + if (!strncasecmp(buf,"type=",5)) + format_type=atoi(&buf[5]); + if (!strncasecmp(buf,"from=",5)) { + wprintf("from %s ",&buf[5]); + strcpy(from,&buf[5]); + } + if (!strncasecmp(buf,"path=",5)) + strcpy(reply_to,&buf[5]); + if (!strncasecmp(buf,"subj=",5)) + strcpy(m_subject,&buf[5]); + if ((!strncasecmp(buf,"hnod=",5)) + && (strcasecmp(&buf[5],serv_info.serv_humannode))) + wprintf("(%s) ",&buf[5]); + if ((!strncasecmp(buf,"room=",5)) + && (strcasecmp(&buf[5],wc_roomname))) + wprintf("in %s> ",&buf[5]); + + if (!strncasecmp(buf,"node=",5)) { + if ( (room_flags&QR_NETWORK) + || ((strcasecmp(&buf[5],serv_info.serv_nodename) + &&(strcasecmp(&buf[5],serv_info.serv_fqdn))))) + { + wprintf("@%s ",&buf[5]); + } + if ((!strcasecmp(&buf[5],serv_info.serv_nodename)) + ||(!strcasecmp(&buf[5],serv_info.serv_fqdn))) + { + strcpy(reply_to,from); + } + else if (haschar(&buf[5],'.')==0) { + sprintf(reply_to,"%s @ %s",from,&buf[5]); + } + } + + if (!strncasecmp(buf,"rcpt=",5)) + wprintf("to %s ",&buf[5]); + if (!strncasecmp(buf,"time=",5)) { + now=atol(&buf[5]); + tm=(struct tm *)localtime(&now); + strcpy(buf,(char *)asctime(tm)); buf[strlen(buf)-1]=0; + strcpy(&buf[16],&buf[19]); + wprintf("%s ",&buf[4]); + } + } + + if (nhdr==1) wprintf("****"); + wprintf(""); + + wprintf("Move", oper); + + wprintf("  "); + + wprintf("Del", oper); + + wprintf("
\n"); + + if (strlen(m_subject)>0) { + wprintf("Subject: %s
\n",m_subject); + } + + if (format_type == 0) { + fmout(NULL); + } + else { + while(serv_gets(buf), strcmp(buf,"000")) { + while ((strlen(buf)>0)&&(isspace(buf[strlen(buf)-1]))) + buf[strlen(buf)-1] = 0; + if ((bq==0)&& +((!strncmp(buf,">",1))||(!strncmp(buf," >",2))||(!strncmp(buf," :-)",4)))) { + wprintf(""); + bq = 1; + } + else if ((bq==1)&& +(strncmp(buf,">",1))&&(strncmp(buf," >",2))&&(strncmp(buf," :-)",4))) { + wprintf(""); + bq = 0; + } + wprintf(""); + url(buf); + escputs(buf); + wprintf("
\n"); + } + } + } + + + +/* + * load message pointers from the server + */ +int load_msg_ptrs(servcmd) +char *servcmd; { + char buf[256]; + int nummsgs; + + nummsgs = 0; + serv_puts(servcmd); + serv_gets(buf); + if (buf[0]!='1') { + wprintf("%s
\n",&buf[4]); + return(nummsgs); + } + while (serv_gets(buf), strcmp(buf,"000")) { + msgarr[nummsgs] = atol(buf); + ++nummsgs; + } + return(nummsgs); + } + + +/* + * command loop for reading messages + */ +void readloop(char *oper) { + char cmd[256]; + int a; + int nummsgs; + + printf("HTTP/1.0 200 OK\n"); + output_headers(); + wprintf("Messages\n"); + wprintf("\n"); + + wprintf("
%s - ",wc_roomname); + if (!strcmp(oper,"readnew")) { + strcpy(cmd,"MSGS NEW"); + wprintf("new messages"); + } + else if (!strcmp(oper,"readold")) { + strcpy(cmd,"MSGS OLD"); + wprintf("old messages"); + } + else { + strcpy(cmd,"MSGS ALL"); + wprintf("all messages"); + } + wprintf("

\n"); + + nummsgs = load_msg_ptrs(cmd); + if (nummsgs == 0) { + if (!strcmp(oper,"readnew")) { + wprintf("No new messages in this room.\n"); + } + else if (!strcmp(oper,"readold")) { + wprintf("No old messages in this room.\n"); + } + else { + wprintf("This room is empty.\n"); + } + goto DONE; + } + + for (a=0; a\n"); + wDumpContent(); + } + + diff --git a/webcit/static/empty.html b/webcit/static/empty.html new file mode 100644 index 000000000..7b0576a45 --- /dev/null +++ b/webcit/static/empty.html @@ -0,0 +1,5 @@ + +Empty Page + + +0)&&(buf[start-1]=='<')) ench = '>'; - if ((start>0)&&(buf[start-1]=='[')) ench = ']'; - if ((start>0)&&(buf[start-1]=='(')) ench = ')'; - if ((start>0)&&(buf[start-1]=='{')) ench = '}'; - - for (pos=strlen(buf); pos>start; --pos) { - if ((buf[pos]==' ')||(buf[pos]==ench)) end = pos; - } - - strncpy(urlbuf,&buf[start],end-start); - urlbuf[end-start] = 0; - - - strncpy(outbuf,buf,start); - sprintf(&outbuf[start],"%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c", - LB,QU,urlbuf,QU,QU,TARGET,QU,RB,urlbuf,LB,RB); - strcat(outbuf,&buf[end]); - strcpy(buf,outbuf); - } - - - - void getz(char *buf) { if (fgets(buf, 256, stdin) == NULL) strcpy(buf, ""); else { @@ -606,6 +559,18 @@ fclose(fp); do_logout(); } + else if (!strcasecmp(action, "readnew")) { + readloop("readnew"); + } + + else if (!strcasecmp(action, "readold")) { + readloop("readold"); + } + + else if (!strcasecmp(action, "readfwd")) { + readloop("readfwd"); + } + /* When all else fails... */ else { printf("HTTP/1.0 200 OK\n"); -- 2.39.2