From 1a62d80e7f7e87212cf24401f3c0e884d701b24c Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 19 Sep 1999 15:57:08 +0000 Subject: [PATCH] * migrated cmd_ent3() to CtdlSaveMessage() --- citadel/ChangeLog | 4 ++- citadel/config.c | 9 ++++-- citadel/file_ops.c | 2 +- citadel/msgbase.c | 78 ++++++++++++++++++++++++++++----------------- citadel/msgbase.h | 4 +-- citadel/serv_chat.c | 21 ++---------- 6 files changed, 63 insertions(+), 55 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 792690e49..9548e4690 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/config.c b/citadel/config.c index ed8fe1dc0..a9ad7f711 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -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); diff --git a/citadel/file_ops.c b/citadel/file_ops.c index 955228e0b..6dfccb4e2 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -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 { diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 38b4d69c7..2b77e3d15 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -35,10 +35,6 @@ 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"); } diff --git a/citadel/msgbase.h b/citadel/msgbase.h index 44062be5f..3eaf237e3 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -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); diff --git a/citadel/serv_chat.c b/citadel/serv_chat.c index 197ace6dd..62be9914f 100644 --- a/citadel/serv_chat.c +++ b/citadel/serv_chat.c @@ -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); } -- 2.30.2