*/
+#include <stdlib.h>
+#include <unistd.h>
#include <stdio.h>
#include <regex.h>
+#include <sys/stat.h>
#include <libcitadel.h>
-
#include "md5.h"
-
#include "ctdl_module.h"
#include "citserver.h"
#include "control.h"
#include "genstamp.h"
#include "room_ops.h"
#include "user_ops.h"
-
#include "internet_addressing.h"
#include "euidindex.h"
#include "msgbase.h"
) {
CC->download_fp = tmpfile();
if (CC->download_fp == NULL) {
- syslog(LOG_EMERG, "msgbase: mime_download() couldn't write: %s", strerror(errno));
+ syslog(LOG_EMERG, "msgbase: mime_download() couldn't write: %m");
cprintf("%d cannot open temporary file: %s\n", ERROR + INTERNAL_ERROR, strerror(errno));
return;
}
rv = fwrite(content, length, 1, CC->download_fp);
if (rv <= 0) {
- syslog(LOG_EMERG, "msgbase: mime_download() Couldn't write: %s", strerror(errno));
+ syslog(LOG_EMERG, "msgbase: mime_download() Couldn't write: %m");
cprintf("%d unable to write tempfile.\n", ERROR + TOO_BIG);
fclose(CC->download_fp);
CC->download_fp = NULL;
ret->ser = malloc(ret->len);
if (ret->ser == NULL) {
- syslog(LOG_ERR, "msgbase: CtdlSerializeMessage() malloc(%ld) failed: %s",
- (long)ret->len, strerror(errno)
- );
+ syslog(LOG_ERR, "msgbase: CtdlSerializeMessage() malloc(%ld) failed: %m", (long)ret->len);
ret->len = 0;
ret->ser = NULL;
return;
/* Decide where bounces need to be delivered */
if ((recps != NULL) && (recps->bounce_to == NULL))
{
- if (CC->logged_in)
- snprintf(bounce_to, sizeof bounce_to, "%s@%s",
- CC->user.fullname, CtdlGetConfigStr("c_nodename"));
- else
- snprintf(bounce_to, sizeof bounce_to, "%s@%s",
- msg->cm_fields[eAuthor], msg->cm_fields[eNodeName]);
+ if (CC->logged_in) {
+ snprintf(bounce_to, sizeof bounce_to, "%s@%s", CC->user.fullname, CtdlGetConfigStr("c_nodename"));
+ }
+ else {
+ snprintf(bounce_to, sizeof bounce_to, "%s@%s", msg->cm_fields[eAuthor], msg->cm_fields[eNodeName]);
+ }
recps->bounce_to = bounce_to;
}
size_t maxlen, /* maximum message length */
StrBuf *exist, /* if non-null, append to it;
exist is ALWAYS freed */
- int crlf, /* CRLF newlines instead of LF */
- int *sock /* socket handle or 0 for this session's client socket */
+ int crlf /* CRLF newlines instead of LF */
)
{
StrBuf *Message;
/* read in the lines of message text one by one */
do {
- if (sock != NULL) {
- if ((CtdlSockGetLine(sock, LineBuf, 5) < 0) ||
- (*sock == -1))
- finished = 1;
- }
- else {
- if (CtdlClientGetLine(LineBuf) < 0) finished = 1;
+ if (CtdlClientGetLine(LineBuf) < 0) {
+ finished = 1;
}
- if ((StrLength(LineBuf) == tlen) &&
- (!strcmp(ChrPtr(LineBuf), terminator)))
+ if ((StrLength(LineBuf) == tlen) && (!strcmp(ChrPtr(LineBuf), terminator))) {
finished = 1;
-
+ }
if ( (!flushing) && (!finished) ) {
if (crlf) {
StrBufAppendBufPlain(LineBuf, HKEY("\r\n"), 0);
return Message;
}
-void DeleteAsyncMsg(ReadAsyncMsg **Msg)
-{
- if (*Msg == NULL)
- return;
- FreeStrBuf(&(*Msg)->MsgBuf);
-
- free(*Msg);
- *Msg = NULL;
-}
-
-ReadAsyncMsg *NewAsyncMsg(const char *terminator, /* token signalling EOT */
- long tlen,
- size_t maxlen, /* maximum message length */
- size_t expectlen, /* if we expect a message, how long should it be? */
- StrBuf *exist, /* if non-null, append to it;
- exist is ALWAYS freed */
- long eLen, /* length of exist */
- int crlf /* CRLF newlines instead of LF */
- )
-{
- ReadAsyncMsg *NewMsg;
-
- NewMsg = (ReadAsyncMsg *)malloc(sizeof(ReadAsyncMsg));
- memset(NewMsg, 0, sizeof(ReadAsyncMsg));
-
- if (exist == NULL) {
- long len;
-
- if (expectlen == 0) {
- len = 4 * SIZ;
- }
- else {
- len = expectlen + 10;
- }
- NewMsg->MsgBuf = NewStrBufPlain(NULL, len);
- }
- else {
- NewMsg->MsgBuf = NewStrBufDup(exist);
- }
- /* Do we need to change leading ".." to "." for SMTP escaping? */
- if ((tlen == 1) && (*terminator == '.')) {
- NewMsg->dodot = 1;
- }
-
- NewMsg->terminator = terminator;
- NewMsg->tlen = tlen;
-
- NewMsg->maxlen = maxlen;
-
- NewMsg->crlf = crlf;
-
- return NewMsg;
-}
-
-/*
- * Back end function used by CtdlMakeMessage() and similar functions
- */
-eReadState CtdlReadMessageBodyAsync(AsyncIO *IO)
-{
- ReadAsyncMsg *ReadMsg;
- int MsgFinished = 0;
- eReadState Finished = eMustReadMore;
-
-#ifdef BIGBAD_IODBG
- char fn [SIZ];
- FILE *fd;
- const char *pch = ChrPtr(IO->SendBuf.Buf);
- const char *pchh = IO->SendBuf.ReadWritePointer;
- long nbytes;
-
- if (pchh == NULL)
- pchh = pch;
-
- nbytes = StrLength(IO->SendBuf.Buf) - (pchh - pch);
- snprintf(fn, SIZ, "/tmp/foolog_ev_%s.%d",
- ((CitContext*)(IO->CitContext))->ServiceName,
- IO->SendBuf.fd);
-
- fd = fopen(fn, "a+");
- if (fd == NULL) {
- syslog(LOG_ERR, "%s: %s", fn, strerror(errno));
- cit_backtrace();
- exit(1);
- }
-#endif
-
- ReadMsg = IO->ReadMsg;
-
- /* read in the lines of message text one by one */
- do {
- Finished = StrBufChunkSipLine(IO->IOBuf, &IO->RecvBuf);
-
- switch (Finished) {
- case eMustReadMore: /// read new from socket...
-#ifdef BIGBAD_IODBG
- if (IO->RecvBuf.ReadWritePointer != NULL) {
- nbytes = StrLength(IO->RecvBuf.Buf) - (IO->RecvBuf.ReadWritePointer - ChrPtr(IO->RecvBuf.Buf));
- fprintf(fd, "Read; Line unfinished: %ld Bytes still in buffer [", nbytes);
-
- fwrite(IO->RecvBuf.ReadWritePointer, nbytes, 1, fd);
-
- fprintf(fd, "]\n");
- } else {
- fprintf(fd, "BufferEmpty! \n");
- }
- fclose(fd);
-#endif
- return Finished;
- break;
- case eBufferNotEmpty: /* shouldn't happen... */
- case eReadSuccess: /// done for now...
- break;
- case eReadFail: /// WHUT?
- ///todo: shut down!
- break;
- }
-
-
- if ((StrLength(IO->IOBuf) == ReadMsg->tlen) &&
- (!strcmp(ChrPtr(IO->IOBuf), ReadMsg->terminator))) {
- MsgFinished = 1;
-#ifdef BIGBAD_IODBG
- fprintf(fd, "found Terminator; Message Size: %d\n", StrLength(ReadMsg->MsgBuf));
-#endif
- }
- else if (!ReadMsg->flushing) {
-
-#ifdef BIGBAD_IODBG
- fprintf(fd, "Read Line: [%d][%s]\n", StrLength(IO->IOBuf), ChrPtr(IO->IOBuf));
-#endif
-
- /* Unescape SMTP-style input of two dots at the beginning of the line */
- if ((ReadMsg->dodot) &&
- (StrLength(IO->IOBuf) == 2) && /* TODO: do we just unescape lines with two dots or any line? */
- (!strcmp(ChrPtr(IO->IOBuf), "..")))
- {
-#ifdef BIGBAD_IODBG
- fprintf(fd, "UnEscaped!\n");
-#endif
- StrBufCutLeft(IO->IOBuf, 1);
- }
-
- if (ReadMsg->crlf) {
- StrBufAppendBufPlain(IO->IOBuf, HKEY("\r\n"), 0);
- }
- else {
- StrBufAppendBufPlain(IO->IOBuf, HKEY("\n"), 0);
- }
-
- StrBufAppendBuf(ReadMsg->MsgBuf, IO->IOBuf, 0);
- }
-
- /* if we've hit the max msg length, flush the rest */
- if (StrLength(ReadMsg->MsgBuf) >= ReadMsg->maxlen) ReadMsg->flushing = 1;
-
- } while (!MsgFinished);
-
-#ifdef BIGBAD_IODBG
- fprintf(fd, "Done with reading; %s.\n, ",
- (MsgFinished)?"Message Finished": "FAILED");
- fclose(fd);
-#endif
- if (MsgFinished)
- return eReadSuccess;
- else
- return eReadFail;
-}
-
/*
* Back end function used by CtdlMakeMessage() and similar functions
size_t maxlen, /* maximum message length */
StrBuf *exist, /* if non-null, append to it;
exist is ALWAYS freed */
- int crlf, /* CRLF newlines instead of LF */
- int *sock /* socket handle or 0 for this session's client socket */
+ int crlf /* CRLF newlines instead of LF */
)
{
StrBuf *Message;
tlen,
maxlen,
exist,
- crlf,
- sock);
+ crlf
+ );
if (Message == NULL)
return NULL;
else
}
else {
StrBuf *MsgBody;
- MsgBody = CtdlReadMessageBodyBuf(HKEY("000"), CtdlGetConfigLong("c_maxmsglen"), NULL, 0, 0);
+ MsgBody = CtdlReadMessageBodyBuf(HKEY("000"), CtdlGetConfigLong("c_maxmsglen"), NULL, 0);
if (MsgBody != NULL) {
CM_SetAsFieldSB(msg, eMesageText, &MsgBody);
}
new_arcq.arcq_delta = incr;
rv = fwrite(&new_arcq, sizeof(struct arcq), 1, arcfp);
if (rv == -1) {
- syslog(LOG_EMERG, "%s: %s", file_arcq, strerror(errno));
+ syslog(LOG_EMERG, "%s: %m", file_arcq);
}
fflush(arcfp);
{
rv = fwrite(new_arcq + offset, 1, the_size - offset, arcfp);
if (rv == -1) {
- syslog(LOG_EMERG, "%s: %s", file_arcq, strerror(errno));
+ syslog(LOG_ERR, "%s: %m", file_arcq);
}
else {
offset += rv;
r = link(file_arcq, file_arcq_temp);
if (r != 0) {
- syslog(LOG_ERR, "%s: %s", file_arcq_temp, strerror(errno));
+ syslog(LOG_ERR, "%s: %m", file_arcq_temp);
end_critical_section(S_SUPPMSGMAIN);
return(num_records_processed);
}
fp = fopen(file_arcq_temp, "rb");
if (fp == NULL) {
- syslog(LOG_ERR, "%s: %s", file_arcq_temp, strerror(errno));
+ syslog(LOG_ERR, "%s: %m", file_arcq_temp);
return(num_records_processed);
}
fclose(fp);
r = unlink(file_arcq_temp);
if (r != 0) {
- syslog(LOG_ERR, "%s: %s", file_arcq_temp, strerror(errno));
+ syslog(LOG_ERR, "%s: %m", file_arcq_temp);
}
return(num_records_processed);