home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 400-499 / ff473.lzh / CNewsSrc / cnews_src.lzh / relay / hdrdefs.c < prev    next >
C/C++ Source or Header  |  1990-12-22  |  5KB  |  164 lines

  1. /* :ts=4
  2.  * Usenet header definitions (see ARPA Internet RFCs 1036 nee 850 & 822;
  3.  *    for a second opinion, see The Hideous Name by Pike & Weinberger).
  4.  *
  5.  * Headers are parsed and modified and copied in one pass.
  6.  * Nevertheless, the code is in pieces: hdrdefs.c, hdrcommon.c,
  7.  * hdrparse.c, hdrmunge.c.
  8.  *
  9.  *    $Log$
  10.  */
  11.  
  12. #include <stdio.h>
  13. #ifdef unix
  14. # include <sys/types.h>
  15. #endif /* unix */
  16. #include "libc.h"
  17. #include "news.h"
  18. #include "headers.h"
  19. #include "hdrint.h"            /* may define "CONST" or REALSTDC */
  20. #ifdef REALSTDC
  21. # include <stddef.h>        /* defines offsetof */
  22. #endif                        /* REALSTDC */
  23.  
  24. #if 0
  25. #ifndef offsetof
  26. #define offsetof(type, mem) ((char *)&((type *)NULL)->mem - (char *)NULL)
  27. #endif
  28. #endif
  29.  
  30. /* "mandatory" headers (also From:, Date:) */
  31. static CONST char msgnm[] =    "Message-ID:";    /* for rejection */
  32. static CONST char ngsnm[] =    "Newsgroups:";    /* filing, clone for Xref */
  33. static CONST char pathnm[] =    "Path:";    /* rejection, extend (damn) */
  34. static CONST char subjnm[] =    "Subject:";    /* for ctl. msgs. */
  35.  
  36. /* optional headers */
  37. static CONST char appnm[] =    "Approved:";    /* for mod. groups */
  38. static CONST char ctlnm[] =    "Control:";    /* ctl. msg.; NCMP */
  39. static CONST char etctlnm[] = "Also-Control:";    /* hybrid ctl. msg.; NCMP */
  40. static CONST char expnm[] =    "Expires:";    /* for history */
  41. static CONST char distrnm[] =    "Distribution:";    /* for transmission */
  42. static CONST char sendnm[] =    "Sender:";    /* for mod. groups */
  43. static CONST char xrefnm[] =    "Xref:";    /* to *replace* (damn!)*/
  44.  
  45. /* obsolete "useful" headers */
  46. static CONST char artnm[] =    "Article-I.D.:";    /* obs. Message-ID: */
  47.  
  48. /* obsolete useless headers: delete them all on contact */
  49. static CONST char datercvnm[] = "Date-Received:";
  50. static CONST char rcvnm[] =    "Received:";    /* obsolete Date-Received: */
  51. static CONST char postnm[] =    "Posted:";    /* obsolete Date: */
  52. static CONST char postversnm[] = "Posting-Version:";
  53. static CONST char rlyversnm[] = "Relay-Version:";
  54. static CONST char illobjnm[] = "Illegal-Object:";    /* zmailer bitching */
  55.  
  56. static CONST struct hdrdef msghdr = {
  57.     msgnm, STRLEN(msgnm), offsetof(struct headers, h_msgid) };
  58. static CONST struct hdrdef ngshdr = {
  59.     ngsnm, STRLEN(ngsnm), offsetof(struct headers, h_ngs) };
  60. CONST struct hdrdef pathhdr = {
  61.     pathnm, STRLEN(pathnm), offsetof(struct headers, h_path) };
  62. static CONST struct hdrdef subjhdr = {
  63.     subjnm, STRLEN(subjnm), offsetof(struct headers, h_subj) };
  64.  
  65. static CONST struct hdrdef apphdr = {
  66.     appnm, STRLEN(appnm), offsetof(struct headers, h_approved) };
  67. static CONST struct hdrdef ctlhdr = {                    /* NCMP */
  68.     ctlnm, STRLEN(ctlnm), offsetof(struct headers, h_ctlcmd) };    /* NCMP */
  69. static CONST struct hdrdef etctlhdr = {                    /* NCMP */
  70.     etctlnm, STRLEN(etctlnm), offsetof(struct headers,h_etctlcmd) };/*NCMP*/
  71. static CONST struct hdrdef exphdr = {
  72.     expnm, STRLEN(expnm), offsetof(struct headers, h_expiry) };
  73. static CONST struct hdrdef distrhdr = {
  74.     distrnm, STRLEN(distrnm), offsetof(struct headers, h_distr) };
  75. static CONST struct hdrdef sendhdr = {
  76.     sendnm, STRLEN(sendnm), offsetof(struct headers, h_sender) };
  77. CONST struct hdrdef xrefhdr = { xrefnm, STRLEN(xrefnm), -1 };
  78.  
  79. static CONST struct hdrdef arthdr = {
  80.     artnm, STRLEN(artnm), offsetof(struct headers, h_artid) };
  81.  
  82. static CONST struct hdrdef datrcvhdr = { datercvnm, STRLEN(datercvnm), -1 };
  83. static CONST struct hdrdef rcvhdr = { rcvnm, STRLEN(rcvnm), -1 };
  84. static CONST struct hdrdef psthdr = { postnm, STRLEN(postnm), -1 };
  85. static CONST struct hdrdef pstvrshdr = { postversnm, STRLEN(postversnm),-1};
  86. static CONST struct hdrdef rlyvrshdr = { rlyversnm, STRLEN(rlyversnm), -1 };
  87. static CONST struct hdrdef illobjhdr = { illobjnm, STRLEN(illobjnm), -1 };
  88.  
  89.     /* these are parsed into a struct headers */
  90. CONST struct hdrdef *parsehdrs[] = {
  91.     &msghdr,
  92.     &arthdr,        /* obsolete */
  93.     &ngshdr,
  94.     &pathhdr,        /* modified by hdrmunge.c (emithdr()) */
  95.     &subjhdr,
  96.     /* start optional headers */
  97.     &apphdr,
  98.     &ctlhdr,        /* NCMP */
  99.     &etctlhdr,        /* NCMP */
  100.     &distrhdr,
  101.     &exphdr,
  102.     &sendhdr,
  103.     NULL
  104. };
  105. /*
  106.  * the following noxious headers are deleted on contact because neighbours
  107.  * still send them and they are big.  in an ideal world, they wouldn't be
  108.  * sent and thus we wouldn't need to delete them.
  109.  * It is tempting to delete Article-I.D.: too, but it may be too soon for that.
  110.  */
  111. CONST struct hdrdef *hdrvilest[] = {
  112.     &xrefhdr,        /* regenerated by fileart() if needed */
  113.     &datrcvhdr,
  114.     &rcvhdr,
  115.     &psthdr,
  116.     &pstvrshdr,
  117.     &rlyvrshdr,
  118.     &illobjhdr,
  119.     NULL,
  120. };
  121.  
  122. boolean headdebug = NO;
  123.  
  124. void
  125. hdrdebug(state)
  126. int state;
  127. {
  128.     headdebug = state;
  129. }
  130.  
  131. void
  132. hdrinit(hdrs)            /* zero all elements of hdrs */
  133. register struct headers *hdrs;
  134. {
  135.     hdrs->h_subj = NULL;
  136.     hdrs->h_ngs = NULL;
  137.     hdrs->h_distr = NULL;
  138.     hdrs->h_ctlcmd = NULL;        /* NCMP */
  139.     hdrs->h_etctlcmd = NULL;    /* NCMP */
  140.     hdrs->h_approved = NULL;
  141.     hdrs->h_msgid = NULL;
  142.     hdrs->h_artid = NULL;
  143.     hdrs->h_expiry = NULL;
  144.     hdrs->h_path = NULL;
  145.     hdrs->h_sender = NULL;
  146. }
  147.  
  148. void
  149. freeheaders(hdrs)        /* free (assumed) malloced storage */
  150. register struct headers *hdrs;
  151. {
  152.     nnfree(&hdrs->h_subj);
  153.     nnfree(&hdrs->h_ngs);
  154.     nnfree(&hdrs->h_distr);
  155.     nnfree(&hdrs->h_ctlcmd);    /* NCMP */
  156.     nnfree(&hdrs->h_etctlcmd);    /* NCMP */
  157.     nnfree(&hdrs->h_approved);
  158.     nnfree(&hdrs->h_msgid);
  159.     nnfree(&hdrs->h_artid);
  160.     nnfree(&hdrs->h_expiry);
  161.     nnfree(&hdrs->h_path);
  162.     nnfree(&hdrs->h_sender);
  163. }
  164.