home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Unix System Administration Handbook 1997 October
/
usah_oct97.iso
/
news
/
cnews.tar
/
relay
/
hdrdefs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-17
|
4KB
|
152 lines
/*
* Usenet header definitions (see ARPA Internet RFCs 1036 nee 850 & 822;
* for a second opinion, see The Hideous Name by Pike & Weinberger).
*
* Headers are parsed and modified and copied in one pass.
* Nevertheless, the code is in pieces: hdrdefs.c, hdrparse.c, hdrmunge.c.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h> /* must define offsetof */
#include <sys/types.h>
#include "libc.h"
#include "news.h"
#include "headers.h"
#include "hdrint.h"
/* required headers */
static char msgnm[] = "Message-ID:"; /* rejection of dup.s */
static char ngsnm[] = "Newsgroups:"; /* filing, clone for Xref */
static char pathnm[] = "Path:"; /* rejection, extend (damn) */
static char subjnm[] = "Subject:"; /* for ctl. msgs. */
static char datenm[] = "Date:"; /* rejection of stale art.s */
static char fromnm[] = "From:"; /* only required; no use */
/* optional headers */
static char appnm[] = "Approved:"; /* mod. groups */
static char ctlnm[] = "Control:"; /* ctl. msg.; NCMP */
static char etctlnm[] = "Also-Control:"; /* hybrid ctl. msg.; NCMP */
static char expnm[] = "Expires:"; /* history */
static char distrnm[] = "Distribution:"; /* transmission */
static char sendnm[] = "Sender:"; /* mod. groups */
static char xrefnm[] = "Xref:"; /* to *replace* (damn!)*/
/* obsolete "useful" headers */
static char artnm[] = "Article-I.D.:"; /* obs. Message-ID: */
static struct hdrdef msghdr = {
msgnm, STRLEN(msgnm), offsetof(struct headers, h_msgid) };
static struct hdrdef ngshdr = {
ngsnm, STRLEN(ngsnm), offsetof(struct headers, h_ngs) };
struct hdrdef pathhdr = {
pathnm, STRLEN(pathnm), offsetof(struct headers, h_path) };
static struct hdrdef subjhdr = {
subjnm, STRLEN(subjnm), offsetof(struct headers, h_subj) };
static struct hdrdef datehdr = {
datenm, STRLEN(datenm), offsetof(struct headers, h_date) };
static struct hdrdef fromhdr = {
fromnm, STRLEN(fromnm), offsetof(struct headers, h_from) };
static struct hdrdef apphdr = {
appnm, STRLEN(appnm), offsetof(struct headers, h_approved) };
static struct hdrdef ctlhdr = { /* NCMP */
ctlnm, STRLEN(ctlnm), offsetof(struct headers, h_ctlcmd) }; /* NCMP */
static struct hdrdef etctlhdr = { /* NCMP */
etctlnm, STRLEN(etctlnm), offsetof(struct headers, h_etctlcmd) }; /* NCMP */
static struct hdrdef exphdr = {
expnm, STRLEN(expnm), offsetof(struct headers, h_expiry) };
static struct hdrdef distrhdr = {
distrnm, STRLEN(distrnm), offsetof(struct headers, h_distr) };
static struct hdrdef sendhdr = {
sendnm, STRLEN(sendnm), offsetof(struct headers, h_sender) };
struct hdrdef xrefhdr = {
xrefnm, STRLEN(xrefnm), offsetof(struct headers, h_xref) };
static struct hdrdef arthdr = {
artnm, STRLEN(artnm), offsetof(struct headers, h_artid) };
/* these are parsed into a struct headers */
/* putting opthdrs first makes some broken compilers happier */
hdrlist opthdrs = {
&arthdr, /* obsolete */
&apphdr,
&ctlhdr, /* NCMP */
&etctlhdr, /* NCMP */
&distrhdr,
&exphdr,
&sendhdr,
&xrefhdr, /* for -b only */
NULL
};
hdrlist reqdhdrs = {
&msghdr,
&ngshdr,
&pathhdr, /* modified by hdrmunge.c (emithdr()) */
&subjhdr,
&datehdr,
&fromhdr,
NULL
};
/*
* the following headers are deleted on contact because neighbours
* still send them. in an ideal world, they wouldn't be
* sent and thus we wouldn't need to delete them.
*/
hdrlist hdrvilest = {
&xrefhdr, /* regenerated by fileart() if needed */
NULL,
};
boolean headdebug = NO;
void
hdrdebug(state)
int state;
{
headdebug = state;
}
void
hdrinit(hdrs) /* zero all elements of hdrs */
register struct headers *hdrs;
{
hdrs->h_subj = NULL;
hdrs->h_ngs = NULL;
hdrs->h_distr = NULL;
hdrs->h_ctlcmd = NULL; /* NCMP */
hdrs->h_etctlcmd = NULL; /* NCMP */
hdrs->h_approved = NULL;
hdrs->h_msgid = NULL;
hdrs->h_artid = NULL;
hdrs->h_expiry = NULL;
hdrs->h_path = NULL;
hdrs->h_sender = NULL;
hdrs->h_from = NULL;
hdrs->h_date = NULL;
hdrs->h_xref = NULL;
}
void
freeheaders(hdrs) /* free (assumed) malloced storage */
register struct headers *hdrs;
{
nnfree(&hdrs->h_subj);
nnfree(&hdrs->h_ngs);
nnfree(&hdrs->h_distr);
nnfree(&hdrs->h_ctlcmd); /* NCMP */
nnfree(&hdrs->h_etctlcmd); /* NCMP */
nnfree(&hdrs->h_approved);
nnfree(&hdrs->h_msgid);
nnfree(&hdrs->h_artid);
nnfree(&hdrs->h_expiry);
nnfree(&hdrs->h_path);
nnfree(&hdrs->h_sender);
nnfree(&hdrs->h_from);
nnfree(&hdrs->h_date);
nnfree(&hdrs->h_xref);
}