home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / submit / t-tracecheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  2.3 KB  |  115 lines

  1. /* t-tracecheck: small wrap around to test checking of traces */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/submit/RCS/t-tracecheck.c,v 6.0 1991/12/18 20:28:02 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/submit/RCS/t-tracecheck.c,v 6.0 1991/12/18 20:28:02 jpo Rel $
  9.  *
  10.  * $Log: t-tracecheck.c,v $
  11.  * Revision 6.0  1991/12/18  20:28:02  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "head.h"
  19. #include "q.h"
  20. #include "prm.h"
  21. #include "dr.h"
  22.  
  23. #define MAX_TRACE_HOPS  15
  24.  
  25. static int inTraceList (tp, list)
  26. Trace    *tp, *list;
  27. {
  28.     int    retval = NOTOK;
  29.  
  30.     while (retval == NOTOK && list != NULL) {
  31.         if (trace_equ(tp, list) == 0)
  32.             retval = OK;
  33.         else
  34.             list = list -> trace_next;
  35.     }
  36.     return retval;
  37. }
  38.  
  39. static void addToTraceList(this, to)
  40. Trace    *this, **to;
  41. {
  42.     Trace    *next;
  43.     if (this == NULL)
  44.         return;
  45.     next = this -> trace_next;
  46.     this -> trace_next = NULL;
  47.     trace_add(to, trace_dup(this));
  48.     this -> trace_next = next;
  49. }
  50.       
  51.  
  52. void tracecheck_mgt (qp)
  53. Q_struct    *qp;
  54. {
  55.     register Trace    *tp;
  56.     Trace        *list = NULL;
  57.     int        nhops = 0;
  58.     char        buf[BUFSIZ];
  59.     PP_DBG (("submit/tracecheck_mgt (qp)"));
  60.  
  61.     for (tp = qp->trace; tp; tp = tp -> trace_next) {
  62.         /* -- too many hops -- */
  63.  
  64.         if (++nhops > MAX_TRACE_HOPS) {
  65.             (void) sprintf (buf,
  66.                 "%s%s %d",
  67.                 "This Message has travelled a long time, ",
  68.                 "there are too many Trace hops", nhops);
  69. /*            message_failure (DRR_UNABLE_TO_TRANSFER,
  70.                      DRD_LOOP_DETECTED, buf);*/
  71.             if (list != NULL) trace_free(list);
  72.             return;
  73.         }
  74.  
  75.         if (tp -> trace_mta != NULLCP) {
  76.             /* can only check against those with mta specified */
  77.             if (inTraceList(tp, list) == OK) {
  78.                 (void) sprintf (buf, "%s%s",
  79.                         "A Loop has been detected in the Trace ",
  80.                         "field for this Message");
  81. /*                message_failure (DRR_UNABLE_TO_TRANSFER,
  82.                          DRD_LOOP_DETECTED, buf);*/
  83.                 if (list != NULL) trace_free(list);
  84.                 return;
  85.             } else
  86.                 addToTraceList(tp, &list);
  87.         }
  88.     }
  89.     if (list != NULL) trace_free (list);
  90. }
  91.  
  92. main (argc, argv)
  93. int  argc;
  94. char **argv;
  95. {
  96.     struct prm_vars    prm;
  97.     Q_struct    que;
  98.     ADDR        *sender = NULL;
  99.     ADDR        *recips = NULL;
  100.     int         rcount;
  101.     if (argc < 2) {
  102.         printf("usage : %s msg", argv[0]);
  103.         exit(0);
  104.     }
  105.     sys_init(argv[0]);
  106.  
  107.     if (rp_isbad(rd_msg(argv[1],&prm,&que,&sender,&recips,&rcount))) {
  108.         printf("rd_msg err: '%s'",argv[1]);
  109.         rd_end();
  110.         exit(0);
  111.     }
  112.     tracecheck_mgt (&que);
  113.     rd_end();
  114. }
  115.