1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "lutil.h"
#include "bwrite.h"
#include "ftn.h"
#include "ftnmsg.h"
extern FILE *openpkt(FILE *,faddr *,char);
static char *months[] = {
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
};
char *ftndate(t)
time_t t;
{
static char buf[32];
struct tm *ptm;
ptm=localtime(&t);
sprintf(buf,"%02d %s %02d %02d:%02d:%02d",ptm->tm_mday,
months[ptm->tm_mon],ptm->tm_year%100,
ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
return buf;
}
FILE *ftnmsghdr(fmsg,pkt,route,flavor)
ftnmsg *fmsg;
FILE *pkt;
faddr *route;
char flavor;
{
if (route == NULL) route=fmsg->to;
pkt=openpkt(pkt,route,flavor);
if (pkt == NULL) return NULL;
iwrite(MSGTYPE, pkt);
#ifndef USE_REAL_BINARY_FROM
if (fmsg->area)
iwrite(bestaka_s(fmsg->to)->node,pkt);
else
#endif
iwrite(fmsg->from->node,pkt);
iwrite(fmsg->to->node, pkt);
#ifndef USE_REAL_BINARY_FROM
if (fmsg->area)
iwrite(bestaka_s(fmsg->to)->net,pkt);
else
#endif
iwrite(fmsg->from->net, pkt);
iwrite(fmsg->to->net, pkt);
iwrite(fmsg->flags, pkt);
iwrite(0, pkt);
awrite(ftndate(fmsg->date),pkt);
awrite(fmsg->to->name?fmsg->to->name:"Sysop", pkt);
awrite(fmsg->from->name?fmsg->from->name:"Sysop",pkt);
awrite(fmsg->subj?fmsg->subj:"<none>",pkt);
if (fmsg->area)
{
fprintf(pkt,"AREA:%s\r",fmsg->area);
}
else
{
if (fmsg->to->point)
fprintf(pkt,"\1TOPT %u\r",fmsg->to->point);
if (fmsg->from->point)
fprintf(pkt,"\1FMPT %u\r",fmsg->from->point);
#ifndef FORCEINTL
if (fmsg->to->zone != fmsg->from->zone)
#endif
fprintf(pkt,"\1INTL %u:%u/%u %u:%u/%u\r",
fmsg->to->zone,
fmsg->to->net,
fmsg->to->node,
fmsg->from->zone,
fmsg->from->net,
fmsg->from->node
);
}
if (fmsg->msgid_s)
fprintf(pkt,"\1MSGID: %s\r",fmsg->msgid_s);
else if (fmsg->msgid_a)
fprintf(pkt,"\1MSGID: %s %08lx\r",
fmsg->msgid_a,
fmsg->msgid_n);
if (fmsg->reply_s)
fprintf(pkt,"\1REPLY: %s\r",fmsg->reply_s);
else if (fmsg->reply_a)
fprintf(pkt,"\1REPLY: %s %08lx\r",
fmsg->reply_a,
fmsg->reply_n);
if (ferror(pkt)) return NULL;
else return pkt;
}
void tidy_ftnmsg(tmsg)
ftnmsg *tmsg;
{
if (tmsg == NULL) return;
tmsg->flags=0;
if (tmsg->to) tidy_faddr(tmsg->to); tmsg->to=NULL;
if (tmsg->from) tidy_faddr(tmsg->from); tmsg->from=NULL;
if (tmsg->subj) free(tmsg->subj); tmsg->subj=NULL;
if (tmsg->msgid_s) free(tmsg->msgid_s); tmsg->msgid_s=NULL;
if (tmsg->msgid_a) free(tmsg->msgid_a); tmsg->msgid_a=NULL;
if (tmsg->reply_s) free(tmsg->reply_s); tmsg->reply_s=NULL;
if (tmsg->reply_a) free(tmsg->reply_a); tmsg->reply_a=NULL;
if (tmsg->origin) free(tmsg->origin); tmsg->origin=NULL;
if (tmsg->area) free(tmsg->area); tmsg->area=NULL;
free(tmsg);
}
|