Merge latest trunk revisions into branch

This commit is contained in:
alexhudson
2007-08-26 19:24:57 +00:00
parent a0fbe38c89
commit f1e18a3c42
51 changed files with 2373 additions and 271 deletions
+136 -105
View File
@@ -65,15 +65,29 @@ static int HandleDSN(FILE *data, FILE *control);
#define MAX_CHARS_IN_PDBSEARCH 512
/* File open check. Warns if the handle is already in use, and tries to close that file.
* Any FILE * pointers should therefore be NULL before use, otherwise it triggers a false
* alarm
*/
#define FOPEN_CHECK(handle, path, mode) fopen_check(&(handle), (path), (mode), __LINE__)
FILE *
fopen_check(FILE **handle, char *path, char *mode, int line)
{
LogAssertF(*handle == NULL, "File handle already open on line %d", line);
int ret;
if (*handle != NULL) {
LogFailureF("File handle already open on line %d", line);
ret = fclose(*handle);
LogAssertF(ret == 0, "Couldn't close dangling file handle from line %d", line);
}
*handle = fopen(path, mode);
// LogFailureF("File open: %s, handle %ld", path, *handle);
return *handle;
}
/* File close check. Warns if it cannot close the file, and sets the file handle to NULL
*/
#define FCLOSE_CHECK(f) fclose_check(&(f), __LINE__)
int
fclose_check(FILE **fh, int line)
@@ -81,6 +95,7 @@ fclose_check(FILE **fh, int line)
int ret;
ret = fclose(*fh);
if (ret == 0) {
// LogFailureF("File close: handle %ld", *fh);
*fh = NULL;
} else {
LogFailureF("File close failed on line %d: %d", line, errno);
@@ -322,12 +337,12 @@ UpdatePushClientsRegistered(void)
static void
WriteQAgents(void)
{
FILE *handle;
FILE *handle = NULL;
handle = fopen(Conf.queueClientsPath, "wb");
FOPEN_CHECK(handle, Conf.queueClientsPath, "wb");
if (handle) {
fwrite(Queue.pushClients.array, sizeof(QueuePushClient), Queue.pushClients.count, handle);
fclose(handle);
FCLOSE_CHECK(handle);
}
}
@@ -720,11 +735,12 @@ StartOver:
FOPEN_CHECK(newFH, path, "wb");
sprintf(path, "%s/c%s.%03d",Conf.spoolPath, entry, queue);
FOPEN_CHECK(temp, path, "rb");
if (newFH
&& (stat(path, &sb) == 0)
&& (sb.st_size > 8)
&& ((qEnvelope = (unsigned char *)MemMalloc(sb.st_size + 1)) != NULL)
&& ((temp = fopen(path, "rb")) != NULL)
&& (temp)
&& (fread(qEnvelope, sizeof(unsigned char), sb.st_size, temp) == (size_t)sb.st_size)) {
/* Sort the control file as follows:
QUEUE_DATE
@@ -741,8 +757,7 @@ StartOver:
QUEUE_RECIP_REMOTE
QUEUE_THIRD_PARTY
*/
fclose(temp);
FCLOSE_CHECK(temp);
qEnvelope[sb.st_size] = '\0';
count = 0;
@@ -973,6 +988,10 @@ StartOver:
break;
}
if (temp) {
// this might be left over when the if() above fails
FCLOSE_CHECK(temp);
}
if (!newFH) {
sprintf(path, "%s/w%s.%03d",Conf.spoolPath, entry, queue);
@@ -1649,7 +1668,7 @@ StartOver:
XplConsolePrintf("bongoqueue: Last command:%s\r\n", client->buffer);
}
fclose(client->entry.work);
FCLOSE_CHECK(client->entry.work);
client->entry.work = NULL;
sprintf(client->path,"%s/w%s.%03d", Conf.spoolPath, entry, queue);
@@ -2455,8 +2474,8 @@ HandleDSN(FILE *data, FILE *control)
unsigned long id;
unsigned long *idLock;
unsigned char path[XPL_MAX_PATH + 1];
FILE *rtsControl;
FILE *rtsData;
FILE *rtsControl = NULL;
FILE *rtsData = NULL;
XplThreadID threadID;
XplMutexLock(Queue.queueIDLock);
@@ -2466,7 +2485,7 @@ HandleDSN(FILE *data, FILE *control)
sprintf(path, "%s/c%07lx.%03d", Conf.spoolPath, id, Q_INCOMING);
/* Create control file */
rtsControl = fopen(path,"wb");
FOPEN_CHECK(rtsControl, path,"wb");
if (!rtsControl) {
fprintf (stderr, "could not open rtsControl\n");
return -1;
@@ -2476,18 +2495,18 @@ HandleDSN(FILE *data, FILE *control)
/* Create data file */
sprintf(path, "%s/d%07lx.msg", Conf.spoolPath, id);
rtsData = fopen(path, "wb");
FOPEN_CHECK(rtsData, path, "wb");
if (!rtsData) {
fprintf (stderr, "could not open rtsData\n");
fclose(rtsControl);
FCLOSE_CHECK(rtsControl);
sprintf(path, "%s/d%07lx.msg", Conf.spoolPath, id);
UNLINK_CHECK(path);
return -1;
}
if (!CreateDSNMessage(data, control, rtsData, rtsControl, FALSE)) {
fclose(rtsControl);
fclose(rtsData);
FCLOSE_CHECK(rtsControl);
FCLOSE_CHECK(rtsData);
sprintf(path, "%s/d%07lx.msg", Conf.spoolPath, id);
UNLINK_CHECK(path);
@@ -2501,8 +2520,8 @@ HandleDSN(FILE *data, FILE *control)
XplSafeIncrement(Queue.queuedLocal);
fclose(rtsControl);
fclose(rtsData);
FCLOSE_CHECK(rtsControl);
FCLOSE_CHECK(rtsData);
SpoolEntryIDUnlock(idLock);
sprintf(path, "%03d%lx",Q_INCOMING, id);
@@ -2674,8 +2693,8 @@ CreateQueueThreads(BOOL failed)
unsigned long total;
unsigned long current;
unsigned char path[XPL_MAX_PATH + 1];
FILE *control;
FILE *killFile;
FILE *control = NULL;
FILE *killFile = NULL;
XplDir *dirP;
XplDir *dirEntry;
XplThreadID id;
@@ -2698,7 +2717,7 @@ CreateQueueThreads(BOOL failed)
dirP = XplOpenDir(path);
sprintf(path, "%s/fragfile", MsgGetDBFDir(NULL));
killFile = fopen(path, "wb");
FOPEN_CHECK(killFile, path, "wb");
if (!killFile) {
if (dirP) {
XplCloseDir(dirP);
@@ -2816,7 +2835,7 @@ CreateQueueThreads(BOOL failed)
dirP = XplOpenDir(path);
if (killFile) {
fclose(killFile);
FCLOSE_CHECK(killFile);
killFile=NULL;
}
@@ -2825,7 +2844,7 @@ CreateQueueThreads(BOOL failed)
#endif
sprintf(path, "%s/fragfile", MsgGetDBFDir(NULL));
killFile=fopen(path, "rb");
FOPEN_CHECK(killFile, path, "rb");
if (!killFile) {
XplConsolePrintf("bongoqueue: Could not re-open killfile.\r\n");
} else {
@@ -2839,7 +2858,7 @@ CreateQueueThreads(BOOL failed)
}
}
fclose(killFile);
FCLOSE_CHECK(killFile);
}
sprintf(path, "%s/killfile", MsgGetDBFDir(NULL));
@@ -2866,14 +2885,14 @@ CreateQueueThreads(BOOL failed)
current++;
if ((dirEntry->d_nameDOS[0] & 0xDF) == 'C' ) {
sprintf(path, "%s/c%s", Conf.spoolPath, dirEntry->d_nameDOS + 1);
control = fopen(path, "r+b");
FOPEN_CHECK(control, path, "r+b");
if (!control) {
continue;
}
fseek(control, dirEntry->d_size - 2, SEEK_SET);
fwrite("\r\n", 2, 1, control);
fclose(control);
FCLOSE_CHECK(control);
}
}
@@ -2906,7 +2925,7 @@ CommandQaddm(void *param)
unsigned char *ptr;
unsigned char *ptr2;
struct stat sb;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
if (Agent.flags & QUEUE_AGENT_DISK_SPACE_LOW) {
@@ -2947,7 +2966,10 @@ CommandQaddm(void *param)
result = DELIVER_FAILURE;
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr);
if ((stat(client->path, &sb) == 0) && ((data = fopen(client->path, "rb")) != NULL)) {
if (stat(client->path, &sb) == 0) {
FOPEN_CHECK(data, client->path, "rb");
}
if (data) {
NMAPConnections list = { 0, };
struct sockaddr_in saddr;
MDBValueStruct *vs;
@@ -2964,7 +2986,7 @@ CommandQaddm(void *param)
return(ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1));
}
fclose(data);
FCLOSE_CHECK(data);
data = NULL;
if (result==DELIVER_SUCCESS) {
@@ -2987,7 +3009,7 @@ CommandQaddq(void *param)
unsigned char *ptr;
unsigned char *ptr2;
unsigned char *ptr3;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
start = 0;
@@ -3029,7 +3051,7 @@ CommandQaddq(void *param)
LockQueueEntry(ptr+4, atoi(ptr)); */
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
data = fopen(client->path, "rb");
FOPEN_CHECK(data, client->path, "rb");
if (data) {
fseek(data, start, SEEK_SET);
} else {
@@ -3051,7 +3073,7 @@ CommandQaddq(void *param)
}
}
fclose(data);
FCLOSE_CHECK(data);
/* fixme - UnlockQueueEntry
UnlockQueueEntry(ptr+4, atoi(ptr)); */
@@ -3066,7 +3088,7 @@ CommandQabrt(void *param)
QueueClient *client = (QueueClient *)param;
if (client->entry.control) {
fclose(client->entry.control);
FCLOSE_CHECK(client->entry.control);
client->entry.control = NULL;
sprintf(client->path,"%s/c%07lx.in", Conf.spoolPath, client->entry.id);
@@ -3074,14 +3096,14 @@ CommandQabrt(void *param)
}
if (client->entry.data) {
fclose(client->entry.data);
FCLOSE_CHECK(client->entry.data);
client->entry.data = NULL;
sprintf(client->path,"%s/d%07lx.msg",Conf.spoolPath, client->entry.id);
UNLINK_CHECK(client->path);
}
if (client->entry.work) {
fclose(client->entry.work);
FCLOSE_CHECK(client->entry.work);
client->entry.work = NULL;
if (client->entry.workQueue[0] != '\0') {
@@ -3103,7 +3125,7 @@ CommandQbody(void *param)
unsigned long count = 0;
unsigned char *ptr;
struct stat sb;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 5;
@@ -3122,7 +3144,10 @@ CommandQbody(void *param)
}
sprintf(client->path,"%s/d%s.msg", Conf.spoolPath, ptr + 4);
if ((stat(client->path, &sb) == 0) && ((data = fopen(client->path, "rb")) != NULL)) {
if (stat(client->path, &sb) == 0) {
FOPEN_CHECK(data, client->path, "rb");
}
if (data) {
while (!feof(data) && !ferror(data)) {
if (fgets(client->line, CONN_BUFSIZE, data) != NULL) {
/* Note that for the QBODY command we count the blank line, unlike in QHEAD */
@@ -3140,7 +3165,7 @@ CommandQbody(void *param)
ccode = ConnWrite(client->conn, MSG1000OK, sizeof(MSG1000OK) - 1);
}
fclose(data);
FCLOSE_CHECK(data);
} else {
ccode = ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1);
}
@@ -3159,7 +3184,7 @@ CommandQbraw(void *param)
unsigned char *ptr2;
unsigned char *ptr3;
struct stat sb;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 5;
@@ -3186,7 +3211,10 @@ CommandQbraw(void *param)
}
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
if ((stat(client->path, &sb) == 0) && ((data = fopen(client->path, "rb")) != NULL)) {
if (stat(client->path, &sb) == 0) {
FOPEN_CHECK(data, client->path, "rb");
}
if (data) {
while (!feof(data) && !ferror(data)) {
if (fgets(client->line, CONN_BUFSIZE, data) != NULL) {
count += strlen(client->line);
@@ -3214,7 +3242,7 @@ CommandQbraw(void *param)
ccode = ConnWrite(client->conn, MSG1000OK, sizeof(MSG1000OK) - 1);
}
fclose(data);
FCLOSE_CHECK(data);
return(ccode);
}
@@ -3227,7 +3255,7 @@ CommandQcopy(void *param)
unsigned long target;
unsigned char *ptr;
unsigned char *ptr2;
FILE *source;
FILE *source = NULL;
QueueClient *client = (QueueClient *)param;
if (client->entry.data || client->entry.control) {
@@ -3277,7 +3305,7 @@ CommandQcopy(void *param)
/* fixme - LockQueueEntry?
LockQueueEntry(ptr+4, atoi(ptr)); */
sprintf(client->path, "%s/d%s.msg",Conf.spoolPath, ptr + 4);
source = fopen(client->path, "rb");
FOPEN_CHECK(source, client->path, "rb");
if (source) {
XplMutexLock(Queue.queueIDLock);
id = Queue.queueID++ & ((1 << 28) - 1);
@@ -3292,17 +3320,17 @@ CommandQcopy(void *param)
client->entry.id = id;
sprintf(client->path, "%s/c%07lx.in", Conf.spoolPath, id);
client->entry.control = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.control, client->path, "wb");
if (client->entry.control) {
fprintf(client->entry.control, QUEUES_DATE"%lu\r\n", time(NULL));
} else {
fclose(source);
FCLOSE_CHECK(source);
return(ConnWrite(client->conn, MSG5221SPACELOW, sizeof(MSG5221SPACELOW) - 1));
}
sprintf(client->path, "%s/d%07lx.msg", Conf.spoolPath, id);
client->entry.data = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.data, client->path, "wb");
while (!feof(source) && !ferror(source)) {
len = fread(client->line, sizeof(unsigned char), CONN_BUFSIZE, source);
@@ -3311,7 +3339,7 @@ CommandQcopy(void *param)
}
}
fclose(source);
FCLOSE_CHECK(source);
/* fixme - UnlockQueueEntry?
UnlockQueueEntry(ptr+4, atoi(ptr)); */
@@ -3357,7 +3385,7 @@ CommandQcrea(void *param)
XplMutexUnlock(Queue.queueIDLock);
sprintf(client->path, "%s/c%07lx.in", Conf.spoolPath, id);
client->entry.control = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.control, client->path, "wb");
if (client->entry.control) {
fprintf(client->entry.control, QUEUES_DATE"%lu\r\n", time(NULL));
} else {
@@ -3365,11 +3393,11 @@ CommandQcrea(void *param)
}
sprintf(client->path, "%s/d%07lx.msg", Conf.spoolPath, id);
client->entry.data = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.data, client->path, "wb");
if (client->entry.data) {
client->entry.id = id;
} else {
fclose(client->entry.control);
FCLOSE_CHECK(client->entry.control);
sprintf(client->path, "%s/c%07lx.in", Conf.spoolPath, id);
UNLINK_CHECK(client->path);
@@ -3432,7 +3460,7 @@ CommandQdone(void *param)
/* QDONE */
if (client->entry.work) {
fclose(client->entry.work);
FCLOSE_CHECK(client->entry.work);
client->entry.work = NULL;
if (client->entry.workQueue[0] != '\0') {
sprintf(client->path, "%s/w%s.%s", Conf.spoolPath, client->entry.workQueue + 4, client->entry.workQueue);
@@ -3493,7 +3521,7 @@ CommandQgrep(void *param)
char *field;
unsigned char *ptr;
BOOL found = FALSE;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 5;
@@ -3515,7 +3543,7 @@ CommandQgrep(void *param)
}
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
data = fopen(client->path, "rb");
FOPEN_CHECK(data, client->path, "rb");
if (data) {
length = strlen(field);
} else {
@@ -3548,7 +3576,7 @@ CommandQgrep(void *param)
}
}
fclose(data);
FCLOSE_CHECK(data);
if (ccode != -1) {
ccode = ConnWrite(client->conn, MSG1000OK, sizeof(MSG1000OK) - 1);
@@ -3563,7 +3591,7 @@ CommandQhead(void *param)
int ccode;
unsigned long count = 0;
unsigned char *ptr;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 5;
@@ -3583,7 +3611,7 @@ CommandQhead(void *param)
}
sprintf(client->path,"%s/d%s.msg", Conf.spoolPath, ptr+4);
data = fopen(client->path, "rb");
FOPEN_CHECK(data, client->path, "rb");
if (data) {
while (!feof(data) && !ferror(data)) {
if (fgets(client->line, CONN_BUFSIZE, data) != NULL) {
@@ -3606,7 +3634,7 @@ CommandQhead(void *param)
ccode = ConnWrite(client->conn, MSG1000OK, sizeof(MSG1000OK) - 1);
}
fclose(data);
FCLOSE_CHECK(data);
return(ccode);
}
@@ -3617,7 +3645,7 @@ CommandQinfo(void *param)
unsigned long count = 0;
unsigned char *ptr;
struct stat sb;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 5;
@@ -3637,7 +3665,10 @@ CommandQinfo(void *param)
}
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
if ((stat(client->path, &sb) == 0) && ((data = fopen(client->path, "rb")) != NULL)) {
if (stat(client->path, &sb) == 0) {
FOPEN_CHECK(data, client->path, "rb");
}
if (data) {
while (!feof(data) && !ferror(data)) {
if (fgets(client->line, CONN_BUFSIZE, data) != NULL) {
if ((client->line[0] != '\r') || (client->line[1] != '\n')) {
@@ -3652,7 +3683,7 @@ CommandQinfo(void *param)
return(ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1));
}
fclose(data);
FCLOSE_CHECK(data);
return(ConnWriteF(client->conn, "2001 %s-%s %lu %lu %lu 0 0 0 0\r\n",
ptr, ptr + 4, /* ID */
@@ -3671,7 +3702,7 @@ CommandQmodFrom(void *param)
if (!client->entry.work) {
sprintf(client->path, "%s/w%s.%s", Conf.spoolPath, client->entry.workQueue + 4, client->entry.workQueue);
client->entry.work = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.work, client->path, "wb");
if (!client->entry.work) {
return(0);
}
@@ -3696,7 +3727,7 @@ CommandQmodFlags(void *param)
if (!client->entry.work) {
sprintf(client->path, "%s/w%s.%s", Conf.spoolPath, client->entry.workQueue + 4, client->entry.workQueue);
client->entry.work = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.work, client->path, "wb");
if (!client->entry.work) {
return(0);
}
@@ -3721,7 +3752,7 @@ CommandQmodLocal(void *param)
if (!client->entry.work) {
sprintf(client->path, "%s/w%s.%s", Conf.spoolPath, client->entry.workQueue + 4, client->entry.workQueue);
client->entry.work = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.work, client->path, "wb");
if (!client->entry.work) {
return(0);
}
@@ -3746,7 +3777,7 @@ CommandQmodMailbox(void *param)
if (!client->entry.work) {
sprintf(client->path, "%s/w%s.%s", Conf.spoolPath, client->entry.workQueue + 4, client->entry.workQueue);
client->entry.work = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.work, client->path, "wb");
if (!client->entry.work) {
return(0);
}
@@ -3771,7 +3802,7 @@ CommandQmodRaw(void *param)
if (!client->entry.work) {
sprintf(client->path, "%s/w%s.%s", Conf.spoolPath, client->entry.workQueue + 4, client->entry.workQueue);
client->entry.work = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.work, client->path, "wb");
if (!client->entry.work) {
return(0);
}
@@ -3796,7 +3827,7 @@ CommandQmodTo(void *param)
if (!client->entry.work) {
sprintf(client->path, "%s/w%s.%s", Conf.spoolPath, client->entry.workQueue + 4, client->entry.workQueue);
client->entry.work = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.work, client->path, "wb");
if (!client->entry.work) {
return(0);
}
@@ -3819,7 +3850,7 @@ CommandQmime(void *param)
unsigned long i;
unsigned char *ptr;
struct stat sb;
FILE *data;
FILE *data = NULL;
MIMEReportStruct *report;
QueueClient *client = (QueueClient *)param;
@@ -3842,7 +3873,10 @@ CommandQmime(void *param)
if (!client->entry.report) {
/* Find the message size */
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
if ((stat(client->path, &sb) == 0) && ((data = fopen(client->path, "rb")) != NULL)) {
if (stat(client->path, &sb) == 0) {
FOPEN_CHECK(data, client->path, "rb");
}
if (data) {
/* Find the start of the body */
while (!feof(data) && !ferror(data)) {
if (fgets(client->line, CONN_BUFSIZE, data) != NULL) {
@@ -3878,7 +3912,7 @@ CommandQmime(void *param)
ccode = ConnWrite(client->conn, MSG5230NOMEMORYERR, sizeof(MSG5230NOMEMORYERR) - 1);
}
fclose(data);
FCLOSE_CHECK(data);
} else {
ccode = ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1);
}
@@ -3941,16 +3975,16 @@ CommandQrcp(void *param)
unsigned long id;
unsigned char *ptr;
unsigned char path[XPL_MAX_PATH + 1];
FILE *source;
FILE *source = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 4;
if (client->entry.control && client->entry.data && client->entry.id) {
fclose(client->entry.data);
FCLOSE_CHECK(client->entry.data);
client->entry.data = NULL;
fclose(client->entry.control);
FCLOSE_CHECK(client->entry.control);
client->entry.control = NULL;
} else {
return(ConnWrite(client->conn, MSG4000CANTUNLOCKENTRY, sizeof(MSG4000CANTUNLOCKENTRY) - 1));
@@ -3970,15 +4004,15 @@ CommandQrcp(void *param)
}
sprintf(client->path, "%s/c%07lx.in", Conf.spoolPath, id);
client->entry.control = fopen(client->path,"wb");
FOPEN_CHECK(client->entry.control, client->path,"wb");
if (client->entry.control) {
fprintf(client->entry.control, QUEUES_DATE"%lu\r\n", time(NULL));
sprintf(client->path, "%s/d%07lx.msg", Conf.spoolPath, id);
client->entry.data = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.data, client->path, "wb");
if (client->entry.data) {
sprintf(client->path, "%s/d%07lx.msg", Conf.spoolPath, client->entry.id);
source = fopen(client->path, "rb");
FOPEN_CHECK(source, client->path, "rb");
while (!feof(source) && !ferror(source)) {
ccode = fread(client->line, sizeof(unsigned char), CONN_BUFSIZE, source);
@@ -3987,7 +4021,7 @@ CommandQrcp(void *param)
}
}
fclose(source);
FCLOSE_CHECK(source);
sprintf(client->path,"%s/c%07lx.in",Conf.spoolPath, client->entry.id);
sprintf(path, "%s/c%07lx.%03ld", Conf.spoolPath, client->entry.id, client->entry.target);
@@ -4016,7 +4050,7 @@ CommandQrcp(void *param)
return(ccode);
}
fclose(client->entry.control);
FCLOSE_CHECK(client->entry.control);
client->entry.control = NULL;
sprintf(client->path, "%s/c%07lx.in", Conf.spoolPath, id);
@@ -4024,21 +4058,21 @@ CommandQrcp(void *param)
}
sprintf(client->path, "%s/c%07lx.in", Conf.spoolPath, client->entry.id);
client->entry.control = fopen(path, "a+b");
FOPEN_CHECK(client->entry.control, path, "a+b");
sprintf(client->path,"%s/d%07lx.msg", Conf.spoolPath, client->entry.id);
client->entry.data = fopen(path, "a+b");
FOPEN_CHECK(client->entry.data, path, "a+b");
if (client->entry.data && client->entry.control) {
ccode = ConnWrite(client->conn, "1000 Didn't copy; keeping the old entry\r\n", 41);
} else {
if (client->entry.data) {
fclose(client->entry.data);
FCLOSE_CHECK(client->entry.data);
client->entry.data = NULL;
}
if (client->entry.control) {
fclose(client->entry.control);
FCLOSE_CHECK(client->entry.control);
client->entry.data = NULL;
}
@@ -4080,26 +4114,23 @@ CommandQretr(void *param)
if (XplStrCaseCmp(ptr2, "INFO") == 0) {
sprintf(client->path, "%s/c07%s.%s", Conf.spoolPath, ptr + 4, ptr);
if ((stat(client->path, &sb) == 0)
&& ((data = fopen(client->path, "rb")) != NULL)
&& sb.st_size) {
if ((stat(client->path, &sb) == 0) && sb.st_size) {
FOPEN_CHECK(data, client->path, "rb");
}
if (data) {
ccode = ConnWriteF(client->conn, "2022 %lu Info follows\r\n", sb.st_size);
FCLOSE_CHECK(data);
} else {
if (data) {
fclose(data);
}
return(ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1));
}
} else if (XplStrCaseCmp(ptr2, "MESSAGE") == 0) {
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
if ((stat(client->path, &sb) == 0) && ((data = fopen(client->path, "rb")) != NULL)) {
if (stat(client->path, &sb) == 0) {
FOPEN_CHECK(data, client->path, "rb");
}
if (data) {
ccode = ConnWriteF(client->conn, "2023 %lu Message follows\r\n", sb.st_size);
} else {
if (data) {
fclose(data);
}
return(ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1));
}
} else {
@@ -4111,7 +4142,7 @@ CommandQretr(void *param)
ccode = ConnWrite(client->conn, MSG1000OK, sizeof(MSG1000OK) - 1);
}
fclose(data);
FCLOSE_CHECK(data);
return(ccode);
}
@@ -4134,7 +4165,7 @@ CommandQrts(void *param)
if (!client->entry.work) {
sprintf(client->path, "%s/w%s.%s", Conf.spoolPath, client->entry.workQueue + 4, client->entry.workQueue);
client->entry.work = fopen(client->path, "wb");
FOPEN_CHECK(client->entry.work, client->path, "wb");
if (!client->entry.work) {
return(0);
}
@@ -4170,10 +4201,10 @@ CommandQrun(void *param)
/* QRUN[ <queue>-<id>] */
if (*ptr == '\0') {
if (client->entry.control && client->entry.data && client->entry.id) {
fclose(client->entry.data);
FCLOSE_CHECK(client->entry.data);
client->entry.data = NULL;
fclose(client->entry.control);
FCLOSE_CHECK(client->entry.control);
client->entry.control = NULL;
} else {
return(ConnWrite(client->conn, MSG4000CANTUNLOCKENTRY, sizeof(MSG4000CANTUNLOCKENTRY) - 1));
@@ -4283,7 +4314,7 @@ CommandQsrchHeader(void *param)
unsigned char *ptr;
BOOL fieldFound=FALSE;
BOOL contentFound=FALSE;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 12;
@@ -4315,7 +4346,7 @@ CommandQsrchHeader(void *param)
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
data = fopen(client->path, "rb");
FOPEN_CHECK(data, client->path, "rb");
if (data) {
while (!feof(data) && !ferror(data)) {
if (fgets(client->line, CONN_BUFSIZE, data) != NULL) {
@@ -4351,7 +4382,7 @@ CommandQsrchHeader(void *param)
}
}
fclose(data);
FCLOSE_CHECK(data);
} else {
return(ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1));
}
@@ -4373,7 +4404,7 @@ CommandQsrchBody(void *param)
char *content;
unsigned char *ptr;
BOOL found = FALSE;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 10;
@@ -4398,7 +4429,7 @@ CommandQsrchBody(void *param)
}
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
data = fopen(client->path, "rb");
FOPEN_CHECK(data, client->path, "rb");
if (data) {
while (!feof(data) && !ferror(data)) {
if (fgets(client->line, CONN_BUFSIZE, data) != NULL) {
@@ -4421,7 +4452,7 @@ CommandQsrchBody(void *param)
}
}
fclose(data);
FCLOSE_CHECK(data);
} else {
return(ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1));
}
@@ -4449,7 +4480,7 @@ CommandQsrchBraw(void *param)
unsigned char *endPtr;
unsigned char *content;
BOOL found = FALSE;
FILE *data;
FILE *data = NULL;
QueueClient *client = (QueueClient *)param;
ptr = client->buffer + 10;
@@ -4484,7 +4515,7 @@ CommandQsrchBraw(void *param)
}
sprintf(client->path, "%s/d%s.msg", Conf.spoolPath, ptr + 4);
data = fopen(client->path, "rb");
FOPEN_CHECK(data, client->path, "rb");
if (data) {
while (!feof(data) && !ferror(data)) {
if (fgets(client->line, CONN_BUFSIZE, data) != NULL) {
@@ -4520,7 +4551,7 @@ CommandQsrchBraw(void *param)
}
fclose(data);
FCLOSE_CHECK(data);
} else {
return(ConnWrite(client->conn, MSG4224CANTREAD, sizeof(MSG4224CANTREAD) - 1));
}