]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_chat.c
* Cc: and Bcc: support. Not finished yet.
[citadel.git] / citadel / serv_chat.c
index 9baeaac74d6aecd4bf0f253aaa66b1b6b7468734..8b4e28c78586539e8c3b447a777c3358354e9986 100644 (file)
@@ -249,6 +249,7 @@ void cmd_chat(char *argbuf)
        CC->cs_flags = CC->cs_flags | CS_CHAT;
        cprintf("%d Entering chat mode (type '/help' for available commands)\n",
                START_CHAT_MODE);
+       unbuffer_output();
 
        MyLastMsg = ChatLastMsg;
 
@@ -318,7 +319,7 @@ void cmd_chat(char *argbuf)
                                        if (is_room_aide()) {
                                                cprintf(":|/kick   (kick another user out of this room) \n");
                                        }
-                                       cprintf(":|/quit   (return to the BBS) \n");
+                                       cprintf(":|/quit   (exit from this chat) \n");
                                        cprintf(":|\n");
                                        ok_cmd = 1;
                                }
@@ -408,9 +409,9 @@ void cmd_chat(char *argbuf)
 
 
 /*
- * Delete any remaining express messages
+ * Delete any remaining instant messages
  */
-void delete_express_messages(void) {
+void delete_instant_messages(void) {
        struct ExpressMessage *ptr;
 
        begin_critical_section(S_SESSION_TABLE);
@@ -428,14 +429,14 @@ void delete_express_messages(void) {
 
 
 /*
- * Poll for express messages (OLD METHOD -- ***DEPRECATED ***)
+ * Poll for instant messages (OLD METHOD -- ***DEPRECATED ***)
  */
 void cmd_pexp(char *argbuf)
 {
        struct ExpressMessage *ptr, *holdptr;
 
        if (CC->FirstExpressMessage == NULL) {
-               cprintf("%d No express messages waiting.\n", ERROR + MESSAGE_NOT_FOUND);
+               cprintf("%d No instant messages waiting.\n", ERROR + MESSAGE_NOT_FOUND);
                return;
        }
        begin_critical_section(S_SESSION_TABLE);
@@ -467,13 +468,13 @@ void cmd_pexp(char *argbuf)
 
 
 /*
- * Get express messages (new method)
+ * Get instant messages (new method)
  */
 void cmd_gexp(char *argbuf) {
        struct ExpressMessage *ptr;
 
        if (CC->FirstExpressMessage == NULL) {
-               cprintf("%d No express messages waiting.\n", ERROR + MESSAGE_NOT_FOUND);
+               cprintf("%d No instant messages waiting.\n", ERROR + MESSAGE_NOT_FOUND);
                return;
        }
 
@@ -499,7 +500,7 @@ void cmd_gexp(char *argbuf) {
 }
 
 /*
- * Asynchronously deliver express messages'
+ * Asynchronously deliver instant messages
  */
 void cmd_gexp_async(void) {
 
@@ -509,12 +510,11 @@ void cmd_gexp_async(void) {
        /* And don't do it if there's nothing to send. */
        if (CC->FirstExpressMessage == NULL) return;
 
-       cprintf("%d express msg\n", ASYNC_MSG + ASYNC_GEXP);
-       cmd_gexp("");
+       cprintf("%d instant msg\n", ASYNC_MSG + ASYNC_GEXP);
 }
 
 /*
- * Back end support function for send_express_message() and company
+ * Back end support function for send_instant_message() and company
  */
 void add_xmsg_to_context(struct CitContext *ccptr, 
                        struct ExpressMessage *newmsg) 
@@ -531,17 +531,27 @@ void add_xmsg_to_context(struct CitContext *ccptr,
                }
                findend->next = newmsg;
        }
+
+       /* If the target context is a session which can handle asynchronous
+        * messages, go ahead and set the flag for that.
+        */
+       if (ccptr->is_async) {
+               ccptr->async_waiting = 1;
+               if (ccptr->state == CON_IDLE) {
+                       ccptr->state = CON_READY;
+               }
+       }
 }
 
 
 
 
 /* 
- * This is the back end to the express message sending function.  
+ * This is the back end to the instant message sending function.  
  * Returns the number of users to which the message was sent.
  * Sending a zero-length message tests for recipients without sending messages.
  */
-int send_express_message(char *lun, char *x_user, char *x_msg)
+int send_instant_message(char *lun, char *x_user, char *x_msg)
 {
        int message_sent = 0;           /* number of successful sends */
 
@@ -623,12 +633,12 @@ int send_express_message(char *lun, char *x_user, char *x_msg)
                /* Save a copy of the message in the sender's log room,
                 * creating the room if necessary.
                 */
-               create_room(PAGELOGROOM, 4, "", 0, 1, 0);
-               msgnum = CtdlSubmitMsg(logmsg, NULL, PAGELOGROOM);
+               create_room(PAGELOGROOM, 4, "", 0, 1, 0, VIEW_BBS);
+               msgnum = CtdlSubmitMsg(logmsg, NULL, NULL, NULL, PAGELOGROOM);
 
                /* Now save a copy in the global log room, if configured */
                if (strlen(config.c_logpages) > 0) {
-                       create_room(config.c_logpages, 3, "", 0, 1, 1);
+                       create_room(config.c_logpages, 3, "", 0, 1, 1, VIEW_BBS);
                        CtdlSaveMsgPointerInRoom(config.c_logpages, msgnum, 0);
                }
 
@@ -638,7 +648,7 @@ int send_express_message(char *lun, char *x_user, char *x_msg)
                 * but we've already supplied the namespace prefix.
                 */
                while (sl != NULL) {
-                       create_room(sl->roomname, 5, "", 0, 1, 1);
+                       create_room(sl->roomname, 5, "", 0, 1, 1, VIEW_BBS);
                        CtdlSaveMsgPointerInRoom(sl->roomname, msgnum, 0);
                        sptr = sl->next;
                        free(sl);
@@ -652,13 +662,13 @@ int send_express_message(char *lun, char *x_user, char *x_msg)
 }
 
 /*
- * send express messages  <bc>
+ * send instant messages  <bc>
  */
 void cmd_sexp(char *argbuf)
 {
        int message_sent = 0;
-       char x_user[SIZ];
-       char x_msg[SIZ];
+       char x_user[USERNAME_SIZE];
+       char x_msg[1024];
        char *lun;              /* <bc> */
        char *x_big_msgbuf = NULL;
 
@@ -671,9 +681,8 @@ void cmd_sexp(char *argbuf)
        else
                lun = CC->user.fullname;
 
-       extract(x_user, argbuf, 0);
-
-       extract(x_msg, argbuf, 1);
+       extract_token(x_user, argbuf, 0, '|', sizeof x_user);
+       extract_token(x_msg, argbuf, 1, '|', sizeof x_msg);
 
        if (!x_user[0]) {
                cprintf("%d You were not previously paged.\n", ERROR + NO_SUCH_USER);
@@ -688,16 +697,22 @@ void cmd_sexp(char *argbuf)
        if (!strcmp(x_msg, "-")) {
                message_sent = PerformXmsgHooks(lun, x_user, "");
                if (message_sent == 0) {
-                       cprintf("%d '%s' is not logged in "
-                               "or is not accepting pages.\n",
-                               ERROR + NO_SUCH_USER, x_user);
+                       if (getuser(NULL, x_user))
+                               cprintf("%d '%s' does not exist.\n",
+                                               ERROR + NO_SUCH_USER, x_user);
+                       else
+                               cprintf("%d '%s' is not logged in "
+                                               "or is not accepting pages.\n",
+                                               ERROR + RESOURCE_NOT_OPEN, x_user);
                        return;
                }
+               unbuffer_output();
                cprintf("%d Transmit message (will deliver to %d users)\n",
                        SEND_LISTING, message_sent);
                x_big_msgbuf = malloc(SIZ);
                memset(x_big_msgbuf, 0, SIZ);
-               while (client_gets(x_msg), strcmp(x_msg, "000")) {
+               while (client_getln(x_msg, sizeof x_msg),
+                     strcmp(x_msg, "000")) {
                        x_big_msgbuf = realloc(x_big_msgbuf,
                               strlen(x_big_msgbuf) + strlen(x_msg) + 4);
                        if (strlen(x_big_msgbuf) > 0)
@@ -721,9 +736,13 @@ void cmd_sexp(char *argbuf)
                                cprintf(" to %d users", message_sent);
                        cprintf(".\n");
                } else {
-                       cprintf("%d '%s' is not logged in "
-                               "or is not accepting pages.\n",
-                               ERROR + NO_SUCH_USER, x_user);
+                       if (getuser(NULL, x_user))
+                               cprintf("%d '%s' does not exist.\n",
+                                               ERROR + NO_SUCH_USER, x_user);
+                       else
+                               cprintf("%d '%s' is not logged in "
+                                               "or is not accepting pages.\n",
+                                               ERROR + RESOURCE_NOT_OPEN, x_user);
                }
 
 
@@ -790,14 +809,14 @@ void cmd_reqt(char *argbuf) {
 char *serv_chat_init(void)
 {
        CtdlRegisterProtoHook(cmd_chat, "CHAT", "Begin real-time chat");
-       CtdlRegisterProtoHook(cmd_pexp, "PEXP", "Poll for express messages");
-       CtdlRegisterProtoHook(cmd_gexp, "GEXP", "Get express messages");
-       CtdlRegisterProtoHook(cmd_sexp, "SEXP", "Send an express message");
-       CtdlRegisterProtoHook(cmd_dexp, "DEXP", "Disable express messages");
+       CtdlRegisterProtoHook(cmd_pexp, "PEXP", "Poll for instant messages");
+       CtdlRegisterProtoHook(cmd_gexp, "GEXP", "Get instant messages");
+       CtdlRegisterProtoHook(cmd_sexp, "SEXP", "Send an instant message");
+       CtdlRegisterProtoHook(cmd_dexp, "DEXP", "Disable instant messages");
        CtdlRegisterProtoHook(cmd_reqt, "REQT", "Request client termination");
-       CtdlRegisterSessionHook(cmd_gexp_async, EVT_CMD);
-       CtdlRegisterSessionHook(delete_express_messages, EVT_STOP);
-       CtdlRegisterXmsgHook(send_express_message, XMSG_PRI_LOCAL);
+       CtdlRegisterSessionHook(cmd_gexp_async, EVT_ASYNC);
+       CtdlRegisterSessionHook(delete_instant_messages, EVT_STOP);
+       CtdlRegisterXmsgHook(send_instant_message, XMSG_PRI_LOCAL);
        return "$Id$";
 }