]> 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 d22f5ec9ef2e0a6b4eca14659fbd729638e5adbf..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 "serv_chat.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
+#include "dynloader.h"
 
 struct ChatLine *ChatQueue = NULL;
 int ChatLastMsg = 0;
 
+extern struct CitContext *ContextList;
+
+#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)
 {      
@@ -59,7 +87,7 @@ void allwrite(char *cmdbuf, int flag, char *roomname, char *username)
                }
 
        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));
@@ -69,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);
@@ -132,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)
 {
@@ -170,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;
@@ -283,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");
@@ -293,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,7 +346,7 @@ void cmd_chat(char *argbuf)
                        {
                           if ((clptr->chat_seq > MyLastMsg) && ((!clptr->chat_username[0]) || (!strncasecmp(un, clptr->chat_username, 32))))
                           {
-                             if ((!clptr->chat_room[0]) || (!strncasecmp(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);
                              }
@@ -328,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) {
@@ -349,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>