]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_chat.c
* added RCS Id keyword strings to sources
[citadel.git] / citadel / serv_chat.c
index 22b36ed07ef3cd73f5acfe9561d6e31f0f6acee6..022ce07aaaa92d76734b13a130e326cc049fbce1 100644 (file)
@@ -1,3 +1,4 @@
+/* $Id$ */
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/time.h>
 #include <sys/wait.h>
 #include <string.h>
+#include <limits.h>
 #include <pthread.h>
 #include "citadel.h"
 #include "server.h"
 #include <syslog.h>
-#ifdef NEED_SELECT_H
+#ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
-#include "proto.h"
+#include "serv_chat.h"
+#include "sysdep_decls.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "dynloader.h"
 
-extern struct config config;
-
-typedef struct CitContext t_context;
+struct ChatLine *ChatQueue = NULL;
+int ChatLastMsg = 0;
 
 extern struct CitContext *ContextList;
 
-struct ChatLine *ChatQueue = NULL;
-int ChatLastMsg = 0;
+#define MODULE_NAME    "Chat module"
+#define MODULE_AUTHOR  "Art Cancro"
+#define MODULE_EMAIL   "ajc@uncnsrd.mt-kisco.ny.us"
+#define MAJOR_VERSION  0
+#define MINOR_VERSION  2
 
+static struct DLModule_Info info =
+{
+  MODULE_NAME,
+  MODULE_AUTHOR,
+  MODULE_EMAIL,
+  MAJOR_VERSION,
+  MINOR_VERSION
+};
+
+struct DLModule_Info *Dynamic_Module_Init(void)
+{
+   CtdlRegisterProtoHook(cmd_chat, "CHAT",
+                        "Initiates a real-time chat session");
+   CtdlRegisterProtoHook(cmd_pexp, "PEXP", "Poll for express messages");
+   CtdlRegisterProtoHook(cmd_sexp, "SEXP", "Send an express message");
+   return &info;
+}
 
 void allwrite(char *cmdbuf, int flag, char *roomname, char *username)
 {      
@@ -54,14 +80,14 @@ void allwrite(char *cmdbuf, int flag, char *roomname, char *username)
        {
                sprintf(bcast,":|<%s whispers %s>", un, cmdbuf);
        }
-       if ((strucmp(cmdbuf,"NOOP")) && (flag !=2)) {
+       if ((strcasecmp(cmdbuf,"NOOP")) && (flag !=2)) {
                fp = fopen(CHATLOG,"a");
                fprintf(fp,"%s\n",bcast);
                fclose(fp);
                }
 
        clnew = (struct ChatLine *) malloc(sizeof(struct ChatLine));
-       bzero(clnew, sizeof(struct ChatLine));
+       memset(clnew, 0, sizeof(struct ChatLine));
        if (clnew == NULL) {
                fprintf(stderr, "citserver: cannot alloc chat line: %s\n",
                        strerror(errno));
@@ -71,9 +97,14 @@ void allwrite(char *cmdbuf, int flag, char *roomname, char *username)
        time(&now);
        clnew->next = NULL;
        clnew->chat_time = now;
-       strncpy(clnew->chat_room, roomname, 19);
+       strncpy(clnew->chat_room, roomname, sizeof clnew->chat_room);
+       clnew->chat_room[sizeof clnew->chat_room - 1] = 0;
        if (username)
-          strncpy(clnew->chat_username, username, 31); 
+         {
+           strncpy(clnew->chat_username, username,
+                   sizeof clnew->chat_username);
+           clnew->chat_username[sizeof clnew->chat_username - 1] = 0;
+         }
        else
           clnew->chat_username[0] = '\0';
        strcpy(clnew->chat_text, bcast);
@@ -120,7 +151,7 @@ t_context *find_context(char **unstr)
       else
          name = t_cc->curr_user;
       tptr = *unstr;
-      if ((!struncmp(name, tptr, strlen(name))) && (tptr[strlen(name)] == ' '))
+      if ((!strncasecmp(name, tptr, strlen(name))) && (tptr[strlen(name)] == ' '))
       {
          found_cc = t_cc;
          *unstr = &(tptr[strlen(name)+1]);
@@ -134,7 +165,6 @@ t_context *find_context(char **unstr)
 /*
  * List users in chat.  Setting allflag to 1 also lists users elsewhere.
  */
 
 void do_chat_listing(int allflag)
 {
@@ -143,7 +173,7 @@ void do_chat_listing(int allflag)
        cprintf(":|\n:| Users currently in chat:\n");
        begin_critical_section(S_SESSION_TABLE);
        for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) {
-               if ( (!strucmp(ccptr->cs_room, "<chat>"))
+               if ( (!strcasecmp(ccptr->cs_room, "<chat>"))
                   && ((ccptr->cs_flags & CS_STEALTH) == 0)) {
                        cprintf(":| %-25s <%s>\n", (ccptr->fake_username[0]) ? ccptr->fake_username : ccptr->curr_user, ccptr->chat_room);
                        }
@@ -154,7 +184,7 @@ void do_chat_listing(int allflag)
                cprintf(":|\n:| Users not in chat:\n");
                for (ccptr = ContextList; ccptr != NULL; ccptr = ccptr->next) 
                {
-                       if ( (strucmp(ccptr->cs_room, "<chat>"))
+                       if ( (strcasecmp(ccptr->cs_room, "<chat>"))
                           && ((ccptr->cs_flags & CS_STEALTH) == 0)) 
                        {
                                cprintf(":| %-25s <%s>:\n", (ccptr->fake_username[0]) ? ccptr->fake_username : ccptr->curr_user, (ccptr->fake_roomname[0]) ? ccptr->fake_roomname : ccptr->cs_room);
@@ -172,7 +202,7 @@ void cmd_chat(char *argbuf)
        char cmdbuf[256];
        char *un;
        char *strptr1;
-       char hold_cs_room[20];
+       char hold_cs_room[ROOMNAMELEN];
        int MyLastMsg, ThisLastMsg;
        struct ChatLine *clptr;
        struct CitContext *t_context;
@@ -212,14 +242,14 @@ void cmd_chat(char *argbuf)
                        time(&CC->lastcmd);
                        time(&CC->lastidle);
 
-                       if ( (!strucmp(cmdbuf,"exit"))
-                       ||(!strucmp(cmdbuf,"/exit"))
-                       ||(!strucmp(cmdbuf,"quit"))
-                       ||(!strucmp(cmdbuf,"logout"))
-                       ||(!strucmp(cmdbuf,"logoff"))
-                       ||(!strucmp(cmdbuf,"/q"))
-                       ||(!strucmp(cmdbuf,".q"))
-                       ||(!strucmp(cmdbuf,"/quit"))
+                       if ( (!strcasecmp(cmdbuf,"exit"))
+                       ||(!strcasecmp(cmdbuf,"/exit"))
+                       ||(!strcasecmp(cmdbuf,"quit"))
+                       ||(!strcasecmp(cmdbuf,"logout"))
+                       ||(!strcasecmp(cmdbuf,"logoff"))
+                       ||(!strcasecmp(cmdbuf,"/q"))
+                       ||(!strcasecmp(cmdbuf,".q"))
+                       ||(!strcasecmp(cmdbuf,"/quit"))
                                ) strcpy(cmdbuf,"000");
        
                        if (!strcmp(cmdbuf,"000")) {
@@ -233,10 +263,10 @@ void cmd_chat(char *argbuf)
                                return;
                                }
        
-                       if ((!strucmp(cmdbuf,"/help"))
-                       ||(!strucmp(cmdbuf,"help"))
-                       ||(!strucmp(cmdbuf,"/?"))
-                       ||(!strucmp(cmdbuf,"?"))) {
+                       if ((!strcasecmp(cmdbuf,"/help"))
+                       ||(!strcasecmp(cmdbuf,"help"))
+                       ||(!strcasecmp(cmdbuf,"/?"))
+                       ||(!strcasecmp(cmdbuf,"?"))) {
                                cprintf(":|\n");
                                cprintf(":|Available commands: \n");
                                cprintf(":|/help   (prints this message) \n");
@@ -249,27 +279,27 @@ void cmd_chat(char *argbuf)
                                cprintf(":|\n");
                                ok_cmd = 1;
                                }
-                       if (!strucmp(cmdbuf,"/who")) {
+                       if (!strcasecmp(cmdbuf,"/who")) {
                                do_chat_listing(0);
                                ok_cmd = 1;
                                }
-                       if (!strucmp(cmdbuf,"/whobbs")) {
+                       if (!strcasecmp(cmdbuf,"/whobbs")) {
                                do_chat_listing(1);
                                ok_cmd = 1;
                                }
-                       if (!struncmp(cmdbuf,"/me ",4)) {
+                       if (!strncasecmp(cmdbuf,"/me ",4)) {
                                allwrite(&cmdbuf[4],1, CC->chat_room, NULL);
                                ok_cmd = 1;
                                }
                                
-                       if (!struncmp(cmdbuf,"/msg ", 5))
+                       if (!strncasecmp(cmdbuf,"/msg ", 5))
                        {
                           ok_cmd =1;
                           strptr1 = &cmdbuf[5];
                            if ((t_context = find_context(&strptr1)))
                           {
                              allwrite(strptr1, 2, "", CC->curr_user);
-                             if (strucmp(CC->curr_user, t_context->curr_user))
+                             if (strcasecmp(CC->curr_user, t_context->curr_user))
                                 allwrite(strptr1, 2, "", t_context->curr_user);
                           }
                           else
@@ -277,7 +307,7 @@ void cmd_chat(char *argbuf)
                         cprintf("\n");
                         }
 
-                       if (!struncmp(cmdbuf,"/join ", 6))
+                       if (!strncasecmp(cmdbuf,"/join ", 6))
                        {
                           ok_cmd = 1;
                           allwrite("<changing rooms>",0, CC->chat_room, NULL);
@@ -285,7 +315,9 @@ void cmd_chat(char *argbuf)
                              strcpy(CC->chat_room, "Main room");
                           else
                           {
-                             strncpy(CC->chat_room, &cmdbuf[6], 20);
+                             strncpy(CC->chat_room, &cmdbuf[6],
+                                     sizeof CC->chat_room);
+                             CC->chat_room[sizeof CC->chat_room - 1] = 0;
                           }
                           allwrite("<joining room>",0, CC->chat_room, NULL);
                           cprintf("\n");
@@ -295,7 +327,7 @@ void cmd_chat(char *argbuf)
                                allwrite(cmdbuf,0, CC->chat_room, NULL);
                                }
 
-                       if (!ok_cmd)
+                       if ((!ok_cmd) && (cmdbuf[0]) && (cmdbuf[0] != '\n'))
                           cprintf(":|Command %s is not understood.\n", cmdbuf);
                           
                        strcpy(cmdbuf, "");
@@ -312,9 +344,9 @@ void cmd_chat(char *argbuf)
                        ThisLastMsg = ChatLastMsg;
                        for (clptr=ChatQueue; clptr!=NULL; clptr=clptr->next) 
                        {
-                          if ((clptr->chat_seq > MyLastMsg) && ((!clptr->chat_username[0]) || (!struncmp(un, clptr->chat_username, 32))))
+                          if ((clptr->chat_seq > MyLastMsg) && ((!clptr->chat_username[0]) || (!strncasecmp(un, clptr->chat_username, 32))))
                           {
-                             if ((!clptr->chat_room[0]) || (!struncmp(CC->chat_room, clptr->chat_room, 20)))
+                             if ((!clptr->chat_room[0]) || (!strncasecmp(CC->chat_room, clptr->chat_room, ROOMNAMELEN)))
                              {
                                 cprintf("%s\n", clptr->chat_text);
                              }
@@ -330,7 +362,7 @@ void cmd_chat(char *argbuf)
 /*
  * poll for express messages
  */
-void cmd_pexp(void) {
+void cmd_pexp(char *argbuf) /* arg unused */ {
        struct ExpressMessage *emptr;
 
        if (CC->FirstExpressMessage == NULL) {
@@ -351,19 +383,6 @@ void cmd_pexp(void) {
        cprintf("000\n");
        }
 
-/*
- * returns an asterisk if there are any express messages waiting,
- * space otherwise.
- */
-char check_express(void) {
-       if (CC->FirstExpressMessage == NULL) {
-               return(' ');
-               }
-       else {
-               return('*');
-               }
-       }
-
 
 /*
  * send express messages  <bc>
@@ -406,7 +425,7 @@ void cmd_sexp(char *argbuf)
           return;
        }
 
-       if ( (!strucmp(x_user, "broadcast")) && (CC->usersupp.axlevel < 6) ) {
+       if ( (!strcasecmp(x_user, "broadcast")) && (CC->usersupp.axlevel < 6) ) {
                cprintf("%d Higher access required to send a broadcast.\n",
                        ERROR+HIGHER_ACCESS_REQUIRED);
                return;
@@ -422,14 +441,14 @@ void cmd_sexp(char *argbuf)
                else
                   un = ccptr->usersupp.fullname;
                   
-               if ( (!strucmp(un, x_user))
-                  || (!strucmp(x_user, "broadcast")) ) {
+               if ( (!strcasecmp(un, x_user))
+                  || (!strcasecmp(x_user, "broadcast")) ) {
                        strcpy(ccptr->last_pager, CC->curr_user);
                        emnew = (struct ExpressMessage *)
                                malloc(sizeof(struct ExpressMessage));
                        emnew->next = NULL;
                        sprintf(emnew->em_text, "%s from %s:\n %s\n",
-                               ( (!strucmp(x_user, "broadcast")) ? "Broadcast message" : "Message" ),
+                               ( (!strcasecmp(x_user, "broadcast")) ? "Broadcast message" : "Message" ),
                                lun, x_msg);
 
                        if (ccptr->FirstExpressMessage == NULL) {