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 / hdrparse.c < prev    next >
C/C++ Source or Header  |  1990-05-28  |  2KB  |  92 lines

  1. /* :ts=4
  2.  * Usenet header parsing and remembering.
  3.  *
  4.  *    $Log$
  5.  */
  6.  
  7. #include <stdio.h>
  8. #ifdef unix
  9. # include <sys/types.h>
  10. #endif /* unix */
  11. #include "libc.h"
  12. #include "news.h"
  13. #include "control.h"
  14. #include "case.h"
  15. #include "fileart.h"
  16. #include "headers.h"
  17. #include "hdrint.h"
  18.  
  19. /*
  20.  * Parse (assumed) RFC822/850/1036 header in "line" (ishdr(line) can
  21.  * verify this) into "hdrs" using hdrlst set of keywords by retaining the
  22.  * value of any matching keyword.  Keyword matching is case-insensitive.
  23.  * If the keyword in "line" matches one in hdrlst, store the value in
  24.  * *malloc'ed memory* (N.B.) pointed to by a member of "hdrs".
  25.  * freeheader() will free this memory.
  26.  */
  27. void
  28. hdrparse(hdrs, line, hdrlst)
  29. register struct headers *hdrs;
  30. char *line;
  31. hdrlist hdrlst;                /* headers of positive utility */
  32. {
  33.     register struct hdrdef **hpp;
  34.     register char *hackline = hackhybrid(line);
  35.  
  36.     for (hpp = hdrlst; *hpp != NULL; hpp++) {
  37.         register CONST char *hdrnm = (*hpp)->hdrnm;
  38.  
  39.         if (CISTREQN(hackline, hdrnm, (int)(*hpp)->hdrlen) &&
  40.             (*hpp)->hdroff >= 0)    /* paranoia */
  41.             break;
  42.     }
  43.     if (*hpp != NULL) {
  44.         register char **ptrp = (char **)((char *)hdrs+(*hpp)->hdroff);
  45.  
  46.         nnfree(ptrp);        /* free prev. value in this article */
  47.         *ptrp = strsave(skipsp(&hackline[(*hpp)->hdrlen]));
  48.         if (*ptrp != NULL)
  49.             trim(*ptrp);        /* cut trailing \n */
  50.     }
  51.     free(hackline);
  52. }
  53.  
  54. /*
  55.  * default missing header values
  56.  *
  57.  * If strsave ever returns NULL on failure, instead of exiting,
  58.  * then the strsave calls need to check for failure.
  59.  *
  60.  * An article lacking a Message-ID: but possessing an (obsolete)
  61.  * Article-I.D.: gets the transformed Article-I.D. as its Message-ID:.
  62.  *
  63.  * We support control message *backwards* compatibility: if no Control:
  64.  * header exists and the newsgroup matches all.all.ctl, use the Subject:
  65.  * as the control message.  Ugh.
  66.  */
  67. void
  68. hdrdeflt(hdrs)
  69. register struct headers *hdrs;
  70. {
  71.     if (hdrs->h_ngs == NULL)
  72.         hdrs->h_ngs = strsave(JUNK);
  73.     if (hdrs->h_distr == NULL)
  74.         hdrs->h_distr = strsave(DEFDIST);
  75.  
  76.     if (hdrs->h_msgid == NULL && hdrs->h_artid != NULL)
  77.         hdrs->h_msgid = str3save("<", hdrs->h_artid, ">");
  78.     if (hdrs->h_msgid == NULL || hdrs->h_msgid[0] == '\0') {
  79.         nnfree(&hdrs->h_msgid);
  80.         hdrs->h_msgid = strsave(DEFMSGID);
  81.     }
  82.  
  83.     if (hdrs->h_expiry == NULL || hdrs->h_expiry[0] == '\0') {
  84.         nnfree(&hdrs->h_expiry);
  85.         hdrs->h_expiry = strsave(DEFEXP);
  86.     }
  87.  
  88.     if (hdrs->h_subj == NULL)
  89.         hdrs->h_subj = strsave("");
  90.     hackoldctl(hdrs);                /* NCMP */
  91. }
  92.