home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
OS2OMMM.SRC
/
OMMMMAKE.C
< prev
next >
Wrap
Text File
|
1989-02-12
|
15KB
|
524 lines
/***************************************************************************/
/*** ***/
/*** oMMM - The Outbound Matrix Message Masher ***/
/*** Copyright 1989 BS Software ***/
/*** ***/
/*** FILENAME: OMMMMAKE.C ***/
/*** ***/
/*** Bundle maker ***/
/*** ***/
/*** Based on the original oMMM, a portion of ***/
/*** the Opus Computer-Based Conversation System ***/
/*** Copyright 1986, Wynn Wagner III ***/
/*** ***/
/***************************************************************************/
/*** ***/
/*** Tabs set at every 4th column ***/
/*** ***/
/***************************************************************************/
/*
Polytron Version Control System Comments:
The revision of this file is *** $Revision: 1.40 $ ***
History of changes from 1.30 release version
$Log: C:/OMMM/PROJFILE/OMMMMAKE.C_V $
*
* Rev 1.40 12 Feb 1989 4:56:00 Marshall Presnell
* Public Release Version 1.40
*
* Rev 1.32 31 Jan 1989 0:58:08 Marshall Presnell
* oMMM 1.35 Beta Release Version
*
* Rev 1.31 30 Jan 1989 21:29:54 Marshall Presnell
* Multiple file requests from single messages now insert CR/LF in the .REQ file
*
* Rev 1.30 23 Jan 1989 17:53:56 Marshall Presnell
* Public Source Code Release - Version 1.30
*/
/*--------------------------------------------------------------------------*/
/* Include files */
/*--------------------------------------------------------------------------*/
#include "ommm.h"
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <time.h>
#ifdef TURBO_C
# include <dir.h>
#else
# include <direct.h>
#endif
#ifdef MSC
# include <sys\types.h>
#endif
#include <sys\stat.h>
#ifdef ZTC
# include <dos.h>
#endif
/*--------------------------------------------------------------------------*/
/* Static function declarations */
/*--------------------------------------------------------------------------*/
/* ... NONE ... */
/*--------------------------------------------------------------------------*/
/* Static variable definitions */
/*--------------------------------------------------------------------------*/
static FILE * fh;
static FILE * flo = NULL;
static FILE * req = NULL;
static struct _msg msg;
static struct _msghdr msghdr;
static struct _msglist * numbers;
/*--------------------------------------------------------------------------*/
/* External variable declarations */
/*--------------------------------------------------------------------------*/
/* ... NONE ... */
/*--------------------------------------------------------------------------*/
/* Local Definitions */
/*--------------------------------------------------------------------------*/
#ifdef ZTC
# define O_BINARY 0
#endif
/****************************************************************************/
/*--------------------------------------------------------------------------*/
/* MAKE BUNDLE */
/*--------------------------------------------------------------------------*/
void
make_bundle()
{
char flagchar = 'O';
char oldflag;
char messagefile[64];
char file_attached[64];
char file_path[64];
char flist[64];
char file_name[64];
/*--------------------------------------------------------------------*/
/* Build OUT files */
/*--------------------------------------------------------------------*/
# if defined(MSC)
tzset(); /* not supported currently by the zortech library */
# endif
buffer = malloc(BUFFER_SIZE + 1);
if (!buffer) {
printf("MEM");
return;
}
outfile = NULL;
while (root) {
/*--------------------------------------------------------------*/
/* Copy messages to the OUT file */
/*--------------------------------------------------------------*/
numbers = root->firstmsg;
while (numbers) {
printf("\r%-4d ", numbers->number);
/*--------------------------------------------------------*/
/* Open the message file and read its header */
/*--------------------------------------------------------*/
sprintf(template, "%s%d.MSG", message_path, numbers->number);
strcpy(messagefile, template);
errno = 0;
if ((fh = fopen(template, "r+b")) == NULL) {
cputs("\nCan't open ");
perror(template);
continue;
}
if (fread(&msg, 1, sizeof(struct _msg),fh) != sizeof(struct _msg)) {
cputs("\nHeader corrupted ");
perror(template);
continue;
}
if (msg.attr & MSGFILE)
flagchar = 'D';
if (msg.attr & MSGSENT) {
fclose(fh);
fh = NULL;
continue;
}
/*--------------------------------------------------------*/
/* Create/Append REQ file for file requests */
/*--------------------------------------------------------*/
else if ((msg.attr & MSGFRQ) || (msg.attr & MSGURQ)) {
if (!req) {
sprintf(template, "%s%04x%04x.REQ",
adjust_packet_path(root->id3), root->id1, root->id2);
req = fopen(template, "at");
}
j = 0;
flist[0] = 0;
{ /* file requests */
long timediff;
FILE *fp = NULL;
time_t reqtime = time(NULL);
time_t updtime = 0;
time_t filetime = 0;
char *path = NULL;
char *name = NULL;
char *password = NULL;
char buffer[128];
char *s = NULL, *t = NULL, *p = NULL;
struct _dta fileinfo;
struct stat buf;
long filesize = 0;
int status;
if (msg.attr & MSGURQ) {
strcpy(template,adjust_packet_path(root->id3));
fp = fopen(strcat(template, "requests.upd"), "at");
}
strncpy(buffer, msg.subj, 72);
s = strtok(buffer, " ,");
# if defined(MSC)
timediff = timezone;
# else
timediff = 0;
# endif
while (s != NULL) {
/* get the first file name */
filetime = 0;
if ((t = strchr(s,'!')) != NULL)
*t = '\0';
status = dir_findfirst(s, 0, &fileinfo);
if (t)
*t = '!';
/* strip out the pathname */
if ((t = strrchr(s, '\\')) == NULL)
t = strrchr(s, '/');
if (t == NULL) {
path = getcwd(NULL, 64);
name = s;
} else {
*t = NULL;
path = strdup(s);
*t++ = '\\';
name = t;
}
/*
* get the next token and
* check for a password
*/
s = strtok(NULL, " ,");
if ((s != NULL) && (*s == '!')) {
password = strdup(s + 1);
s = strtok(NULL, " ,");
}
if ((t = strchr(name, '!')) != NULL) {
if (password != NULL)
free(password);
password = strdup(t + 1);
*t = '\0';
}
/*
* process each file matching
* the filespec
*/
p = malloc(strlen(path) + 14 + 2);
while ((status == 0) && (msg.attr & MSGURQ)) {
filesize = max(fileinfo.size,filesize);
strcpy(p,path);
strcat(p,"\\");
strncat(p,fileinfo.name,14);
stat(p,&buf);
filetime = max(buf.st_atime,filetime) - timediff;
status = dir_findnext(&fileinfo);
}
free(p);
updtime = filetime;
if (name)
fputs(name,req);
if (password)
fprintf(req," !%s",password);
if (msg.attr & MSGURQ)
fprintf(req," +%ld",filetime);
fprintf(req,"\n");
if (msg.attr & MSGURQ)
fprintf(fp, "%s %s %+ld %d:%d/%d %ld %ld %ld\n", name, path, updtime, root->id3, root->id1, root->id2, filetime, filesize, reqtime);
free(path);
path = NULL;
if (password != NULL) {
free(password);
password = NULL;
}
}
if (fp)
fclose(fp);
fp = NULL;
}
fclose(fh);
fh = NULL;
if (!keepmsgs)
unlink(messagefile);
else {
if (!pms) {
sprintf(template, "%s%04x%04x.PMS", adjust_packet_path(root->id3), root->id1, root->id2);
pms = fopen(template, "at");
}
fprintf(pms, "%d.MSG\n", numbers->number);
}
if (msg.attr & MSGFRQ)
printf(" ... To: %d:%d/%d (REQ)", root->id3,root->id1, root->id2);
if (msg.attr & MSGURQ)
printf(" ... To: %d:%d/%d (UPDATE)", root->id3,root->id1, root->id2);
numbers = numbers->next;
continue;
}
oldflag = flagchar;
switch (flagchar) {
case 'O':
if ((msg.attr & MSGCRASH) || (msg.attr & MSGHOLD)) {
flagchar = (char) ((msg.attr & MSGHOLD) ? 'H' : 'C');
if (outfile)
fwrite("\0\0", 1,2,outfile);
open_outfile(flagchar, root->id1, root->id2, root->id3, 1);
}
break;
case 'D':
if ((msg.attr & MSGCRASH) || (msg.attr & MSGHOLD)) {
flagchar = (char) ((msg.attr & MSGHOLD) ? 'H' : 'C');
if (outfile)
fwrite("\0\0", 1,2,outfile);
open_outfile(flagchar, root->id1, root->id2, root->id3, 1);
}
break;
case 'C':
if (!(msg.attr & MSGCRASH)) {
flagchar = (char) ((msg.attr & MSGHOLD) ? 'H' : 'O');
if (outfile)
fwrite("\0\0", 1,2,outfile);
open_outfile(flagchar, root->id1, root->id2, root->id3, 1);
}
break;
case 'H':
if (!(msg.attr & MSGHOLD)) {
flagchar = (char) ((msg.attr & MSGCRASH) ? 'C' : 'O');
if (outfile)
fwrite("\0\0", 1, 2, outfile);
open_outfile(flagchar, root->id1, root->id2, root->id3, 1);
}
break;
}
if (outfile == NULL) {
open_outfile(flagchar, root->id1, root->id2, root->id3, 1);
if (outfile == NULL) {
printf("OPEN");
free(buffer);
return;
}
}
/*--------------------------------------------------------*/
/* Copy message header */
/*--------------------------------------------------------*/
msghdr.ver = BUNDLE_VERSION;
msghdr.orignode = msg.orig;
msghdr.destnode = msg.dest;
msghdr.orignet = msg.orig_net;
msghdr.destnet = msg.dest_net;
msghdr.attr = (msg.attr & RETAIN);
msghdr.cost = 0;
errno = 0;
fwrite((char *) &msghdr, sizeof(struct _msghdr),1,outfile);
if (errno) {
perror("\nError writing header");
continue;
}
if (date_conv)
convert_date(msg.date);
fwrite(msg.date, 1,1 + strlen(msg.date),outfile);
fwrite(msg.to, 1,1 + strlen(msg.to),outfile);
fwrite(msg.from, 1,1 + strlen(msg.from),outfile);
/*--------------------------------------------------------*/
/* Create/Append FLO file for file attaches */
/*--------------------------------------------------------*/
if (((msg.attr & (MSGLOCAL | MSGFILE)) == (MSGLOCAL | MSGFILE)) || ((msg.attr & (MSGFWD | MSGFILE)) == (MSGFWD | MSGFILE))) {
if (!flo) {
if (flagchar == 'O')
flagchar = 'F';
sprintf(template, "%s%04x%04x.%cLO", adjust_packet_path(root->id3), root->id1, root->id2, flagchar);
flo = fopen(template, "at");
}
j = 0;
flist[0] = 0;
while (msg.subj[j]) {
if (msg.subj[j] == ' ') {
++j;
continue;
}
for (i = j; msg.subj[i]; i++) {
if (msg.subj[i] == ' ') {
break;
} else
file_attached[i - j] = msg.subj[i];
}
file_attached[i - j] = 0;
j = i;
if (!dir_findfirst(file_attached, NORMAL, &dta)) {
extract_parts(file_path, file_name, flist, file_attached);
fputs(file_path, flo);
fputs(dta.name, flo);
while (!dir_findnext(&dta)) {
fputc('\n', flo);
fputs(file_path, flo);
fputs(dta.name, flo);
}
fputc('\n', flo);
} else {
printf(" can't find file '%s' - not sent\n", file_attached);
}
}
fwrite(flist, 1,1 + strlen(flist),outfile);
} else
fwrite(msg.subj, 1,1 + strlen(msg.subj),outfile);
/*--------------------------------------------------------*/
/* Copy message body */
/*--------------------------------------------------------*/
copy_msg(fh, outfile, buffer, BUFFER_SIZE);
/*--------------------------------------------------------*/
/* Handle KILL/SENT messages */
/*--------------------------------------------------------*/
if (msg.attr & (MSGKILL | MSGFWD | MSGCPT | MSGFRQ | MSGURQ)) {
fclose(fh);
fh = NULL;
if (!keepmsgs)
unlink(messagefile);
else {
if (!pms) {
sprintf(template, "%s%04x%04x.PMS", adjust_packet_path(root->id3), root->id1, root->id2);
pms = fopen(template, "at");
}
fprintf(pms, "%d.MSG\n", numbers->number);
}
/*--------------------------------------------------------*/
/* Mark as SENT for non-Kill/Sent messages */
/*--------------------------------------------------------*/
} else {
fseek(fh, 0L, SEEK_SET);
msg.attr |= MSGSENT;
fwrite((char *) &msg, sizeof(struct _msg),1,fh);
fclose(fh);
fh = NULL;
}
numbers = numbers->next;
flagchar = oldflag;
}
putc('\n', stdout);
if (outfile != NULL) {
fwrite("\0\0", 1, 2, outfile);
fclose(outfile);
outfile = NULL;
}
flagchar = 'O';
if (flo) {
fclose(flo);
flo = NULL;
}
if (req) {
fclose(req);
req = NULL;
}
if (pms && keepmsgs) {
fclose(pms);
pms = NULL;
}
root = root->next;
}
free(buffer);
}
/*--------------------------------------------------------------------------*/
/* END OF FILE */
/*--------------------------------------------------------------------------*/