* migrated cmd_ent3() to CtdlSaveMessage()
authorArt Cancro <ajc@citadel.org>
Sun, 19 Sep 1999 15:57:08 +0000 (15:57 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 19 Sep 1999 15:57:08 +0000 (15:57 +0000)
citadel/ChangeLog
citadel/config.c
citadel/file_ops.c
citadel/msgbase.c
citadel/msgbase.h
citadel/serv_chat.c

index 792690e4907495476c918206a8c00eb023cc4c22..9548e46902928da5dd47624683565ec128cb5a87 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 1.367  1999/09/19 15:57:06  ajc
+* migrated cmd_ent3() to CtdlSaveMessage()
+
 Revision 1.366  1999/09/19 05:13:57  ajc
 * Debugged the new version of CtdlWriteObject()
 
@@ -1253,4 +1256,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
-
index ed8fe1dc0d40475ef8f1622f45aba7de444048ce..a9ad7f7115f16551ccd41cad69b9995e9fbd0b79 100644 (file)
@@ -31,15 +31,18 @@ void get_config(void) {
 
        if (chdir(home_specified ? bbs_home_directory : BBSDIR) != 0) {
                fprintf(stderr,
-                "Cannot start.\nThere is no Citadel installation in %s\n%s\n",
+                       "This program could not be started.\n"
+                       "Unable to change directory to %s\n"
+                       "Error: %s\n",
                        (home_specified ? bbs_home_directory : BBSDIR),
                        strerror(errno));
                exit(1);
        }
        cfp = fopen("citadel.config", "rb");
        if (cfp == NULL) {
-               fprintf(stderr, "Cannot start.\n");
-               fprintf(stderr, "There is no citadel.config in %s\n%s\n",
+               fprintf(stderr, "This program could not be started.\n"
+                       "Unable to open %s/citadel.config\n"
+                       "Error: %s\n",
                        (home_specified ? bbs_home_directory : BBSDIR),
                        strerror(errno));
                exit(1);
index 955228e0b2e0cd05fe02adfce14728ca8c1d10d4..6dfccb4e239ffe92983297b94a81f9ffb247add0 100644 (file)
@@ -552,7 +552,7 @@ void cmd_ucls(char *cmd)
                sprintf(upload_notice,
                        "NEW UPLOAD: '%s'\n %s\n",
                        CC->upl_file,CC->upl_comment);
-               quickie_message(CC->curr_user, CC->quickroom.QRname,
+               quickie_message(CC->curr_user, NULL, CC->quickroom.QRname,
                                upload_notice);
                }
        else {
index 38b4d69c75718c4b043cdc6cee176f30cfa29ce1..2b77e3d1506659aba844b1304e262cde11cf6125 100644 (file)
 
 extern struct config config;
 
-/* FIX dumb stub function */
-void save_message(char *junk, char *more_junk, char *foo, int wahw, int ee) {
-}
-
 /*
  * This function is self explanatory.
  * (What can I say, I'm in a weird mood today...)
@@ -1278,7 +1274,7 @@ void CtdlSaveMsg(struct CtdlMessage *msg, /* message to save */
 /*
  * Convenience function for generating small administrative messages.
  */
-void quickie_message(char *from, char *room, char *text)
+void quickie_message(char *from, char *to, char *room, char *text)
 {
        struct CtdlMessage *msg;
 
@@ -1290,6 +1286,8 @@ void quickie_message(char *from, char *room, char *text)
        msg->cm_fields['A'] = strdoop(from);
        msg->cm_fields['O'] = strdoop(room);
        msg->cm_fields['N'] = strdoop(NODENAME);
+       if (to != NULL)
+               msg->cm_fields['R'] = strdoop(to);
        msg->cm_fields['M'] = strdoop(text);
 
        CtdlSaveMsg(msg, "", room, MES_LOCAL, 1);
@@ -1569,13 +1567,13 @@ SKFALL: b = MES_NORMAL;
 void cmd_ent3(char *entargs)
 {
        char recp[256];
-       char buf[256];
        int a;
        int e = 0;
+       unsigned char ch, which_field;
        struct usersupp tempUS;
        long msglen;
-       long bloklen;
-       FILE *fp;
+       struct CtdlMessage *msg;
+       char *tempbuf;
 
        if (CC->internal_pgm == 0) {
                cprintf("%d This command is for internal programs only.\n",
@@ -1610,37 +1608,60 @@ void cmd_ent3(char *entargs)
                        }
                }
        }
+
        /* At this point, message has been approved. */
        if (extract_int(entargs, 0) == 0) {
                cprintf("%d OK to send\n", OK);
                return;
        }
-       /* open a temp file to hold the message */
-       fp = fopen(CC->temp, "wb");
-       if (fp == NULL) {
-               cprintf("%d Cannot open %s: %s\n",
-                       ERROR + INTERNAL_ERROR,
-                       CC->temp, strerror(errno));
+
+       msglen = extract_long(entargs, 2);
+       msg = mallok(sizeof(struct CtdlMessage));
+       if (msg == NULL) {
+               cprintf("%d Out of memory\n", ERROR+INTERNAL_ERROR);
                return;
        }
-       msglen = extract_long(entargs, 2);
-       cprintf("%d %ld\n", SEND_BINARY, msglen);
-       while (msglen > 0L) {
-               bloklen = ((msglen >= 255L) ? 255 : msglen);
-               client_read(buf, (int) bloklen);
-               fwrite(buf, (int) bloklen, 1, fp);
-               msglen = msglen - bloklen;
+
+       memset(msg, 0, sizeof(struct CtdlMessage));
+       tempbuf = mallok(msglen);
+       if (tempbuf == NULL) {
+               cprintf("%d Out of memory\n", ERROR+INTERNAL_ERROR);
+               phree(msg);
+               return;
        }
-       fclose(fp);
 
-       save_message(CC->temp, recp, "", e, 0);
+       cprintf("%d %ld\n", SEND_BINARY, msglen);
+
+       client_read(&ch, 1);                            /* 0xFF magic number */
+       msg->cm_magic = CTDLMESSAGE_MAGIC;
+       client_read(&ch, 1);                            /* anon type */
+       msg->cm_anon_type = ch;
+       client_read(&ch, 1);                            /* format type */
+       msg->cm_format_type = ch;
+       msglen = msglen - 3;
+
+       while (msglen > 0) {
+               client_read(&which_field, 1);
+               --msglen;
+               tempbuf[0] = 0;
+               do {
+                       client_read(&ch, 1);
+                       a = strlen(tempbuf);
+                       tempbuf[a+1] = 0;
+                       tempbuf[a] = ch;
+               } while ( (a != 0) && (msglen > 0) );
+               msg->cm_fields[which_field] = strdoop(tempbuf);
+       }
+
+       CtdlSaveMsg(msg, recp, "", e, 0);
+       CtdlFreeMessage(msg);
+       phree(tempbuf);
 }
 
 
 /*
  * API function to delete messages which match a set of criteria
  * (returns the actual number of messages deleted)
- * FIX ... still need to implement delete by content type
  */
 int CtdlDeleteMessages(char *room_name,                /* which room */
                       long dmsgnum,            /* or "0" for any */
@@ -1874,6 +1895,9 @@ void AdjRefCount(long msgnum, int incr)
 
 /*
  * Write a generic object to this room
+ *
+ * Note: this could be much more efficient.  Right now we use two temporary
+ * files, and still pull the message into memory as with all others.
  */
 void CtdlWriteObject(char *req_room,           /* Room to stuff it in */
                        char *content_type,     /* MIME type of this object */
@@ -1953,7 +1977,6 @@ void CtdlWriteObject(char *req_room,              /* Room to stuff it in */
        unlink(filename);
 
        /* Create the requested room if we have to. */
-       lprintf(9, "Checking room\n");
        if (getroom(&qrbuf, roomname) != 0) {
                create_room(roomname, 4, "", 0);
        }
@@ -1965,11 +1988,6 @@ void CtdlWriteObject(char *req_room,             /* Room to stuff it in */
                        CtdlDeleteMessages(roomname, 0L, content_type));
        }
        /* Now write the data */
-       lprintf(9, "Calling CtdlSaveMsg()\n");
        CtdlSaveMsg(msg, "", roomname, MES_LOCAL, 1);
-       lprintf(9, "is valid? %d\n",
-               is_valid_message(msg) );
-       lprintf(9, "Calling CtdlFreeMsg()\n");
        CtdlFreeMessage(msg);
-       lprintf(9, "Done.\n");
 }
index 44062be5f913a2ac781ed5cec1293ad63470ee2b..3eaf237e3979ad147718c2cfa433b5fda6b200bf 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$ */
 
-#define aide_message(text)      quickie_message("Citadel",AIDEROOM,text)
+#define aide_message(text)      quickie_message("Citadel",NULL,AIDEROOM,text)
 
 struct sermsgret {
        size_t len;
@@ -40,7 +40,7 @@ void cmd_opna (char *cmdbuf);
 long send_message (struct CtdlMessage *, int, FILE *);
 void loadtroom (void);
 void CtdlSaveMsg(struct CtdlMessage *, char *, char *, int, int);
-void quickie_message (char *, char *, char *);
+void quickie_message (char *, char *, char *, char *);
 struct CtdlMessage *make_message (struct usersupp *, char *,
                   char *, int, int, int, char *);
 void cmd_ent0 (char *entargs);
index 197ace6dd1e19c32be44b4e9401ce581b3b5e0d4..62be9914fdafa2a9d25d5fccda7999478e07c5ae 100644 (file)
@@ -496,26 +496,11 @@ int send_express_message(char *lun, char *x_user, char *x_msg)
        }
        end_critical_section(S_SESSION_TABLE);
 
-       /* Log the page to disk if configured to do so 
-
-
-       ****** FIX FIX FIX   add this back in *************
-
+       /* Log the page to disk if configured to do so  */
        if ((strlen(config.c_logpages) > 0) && (do_send) ) {
-               fp = fopen(CC->temp, "wb");
-               fprintf(fp, "%c%c%c", 255, MES_NORMAL, 0);
-               fprintf(fp, "Psysop%c", 0);
-               fprintf(fp, "T%ld%c", (long)time(NULL), 0);
-               fprintf(fp, "A%s%c", lun, 0);
-               fprintf(fp, "R%s%c", x_user, 0);
-               fprintf(fp, "O%s%c", config.c_logpages, 0);
-               fprintf(fp, "N%s%c", NODENAME, 0);
-               fprintf(fp, "M%s\n%c", x_msg, 0);
-               fclose(fp);
-               save_message(CC->temp, "", config.c_logpages, MES_LOCAL, 1);
-               unlink(CC->temp);
+               quickie_message(lun, x_user, config.c_logpages, x_msg);
        }
-       *************************************/
+
        return (message_sent);
 }