home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / MN321SRC.ZIP / upcont.c < prev    next >
C/C++ Source or Header  |  2004-07-16  |  5KB  |  167 lines

  1. /* $Id: upcont.c,v 1.6 2004/07/15 17:44:02 ozzmosis Exp $ */
  2.  
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. #include "makenl.h"
  7. #include "upcont.h"
  8. #include "fts5.h"
  9.  
  10. #ifdef MALLOC_DEBUG
  11. #include "rmalloc.h"
  12. #endif
  13.  
  14. #ifdef DMALLOC
  15. #include "dmalloc.h"
  16. #endif
  17.  
  18. /* *INDENT-OFF* */
  19. /* Don't indent this array, keep it this way (you could try what indent
  20.    makes of it. It is not really fun, its just funny */
  21. static int OnTop[] = {
  22. /* LEVEL_TOP   --> */ LEVEL_TOP,
  23. /* LEVEL_ZONE  --> */ LEVEL_TOP,
  24. /* LEVEL_REGION--> */ LEVEL_ZONE,
  25. /* LEVEL_HOST  --> */ LEVEL_REGION,
  26. /* LEVEL_HUB   --> */ LEVEL_HOST,
  27. /* LEVEL_NODE  --> */ LEVEL_TOP,   /* Nodes may be anywhere */
  28. /* LEVEL_OGATE --> */ LEVEL_HOST,
  29. /* LEVEL_PRIVATE-> */ LEVEL_HOST,
  30. /* LEVEL_HOLD  --> */ LEVEL_TOP,   /* Hold and down nodes may be anywhere */
  31. /* LEVEL_DOWN  --> */ LEVEL_TOP,
  32. /* LEVEL_POINT --> */ LEVEL_HUB,   /* Hubs and nodes may have points */
  33. };
  34. /* *INDENT-ON* */
  35.  
  36.  
  37. static char Node[] = "Node\0";
  38. static char PVT[] = ",PVT";
  39. static char PhoneNoHolder[MAXPHONE];
  40. static char PointPhoneNoHolder[MAXPHONE];
  41.  
  42. int
  43. UpdateContext(int level, int num, int makenum, int *ctxnum, int *ctxlevel,
  44.               int maketype)
  45. {
  46.     const char *leveltxt;
  47.     const char *makeleveltxt;
  48.  
  49.     if (makenum)
  50.     {
  51.         if ((level >= maketype - 1)
  52.             && (maketype == LEVEL_NODE || maketype == level)
  53.             && makenum == num)
  54.             goto out;
  55.         if (level == LEVEL_POINT)
  56.             leveltxt = "Point";
  57.         else if (level >= LEVEL_NODE)
  58.             leveltxt = Node;
  59.         else
  60.             leveltxt = Levels[level];
  61.         if (maketype >= LEVEL_NODE)
  62.             makeleveltxt = Node;
  63.         else
  64.             makeleveltxt = Levels[maketype];
  65.         sprintf(ErrorMessage, "Expected \"%s %d\", got \"%s %d\"",
  66.                 makeleveltxt, makenum, leveltxt, num);
  67.         return 2;
  68.     }
  69.     if (maketype > level)
  70.     {
  71.         sprintf(ErrorMessage, "Unexpected \"%s\" statement in %s file",
  72.                 Levels[level], LevelsSimple[maketype]);
  73.         return 2;
  74.     }
  75.     if (level == maketype && maketype != LEVEL_NODE)
  76.     {
  77.         sprintf(ErrorMessage, "Multiple \"%s\" statememts",
  78.                 (maketype > LEVEL_HUB) ? "Node" : Levels[maketype]);
  79.         return 2;
  80.     }
  81.     switch (level)
  82.     {
  83.     case LEVEL_POINT:
  84.         if (*ctxlevel > LEVEL_NODE) /* Catch private, hold and down nodes
  85.                                        with points */
  86.         {
  87.             sprintf(ErrorMessage, "%s nodes may not have points\n",
  88.                     Levels[*ctxlevel]);
  89.             return 1;
  90.         }
  91.         switch (PointLevel)
  92.         {
  93.         case 0:                /* OK */
  94.             break;
  95.         case -2:               /* NONE */
  96.             strcpy(ErrorMessage, "Points not allowed in this list");
  97.             return 1;
  98.         case -3:               /* HIDE */
  99.             FTS5Phone = "-Unpublished-";
  100.             break;
  101.         default:               /* some level - currently only LEVEL_NODE
  102.                                    possible */
  103.             if (PointPhoneNoHolder[0] == 0)
  104.             {
  105.                 strcpy(ErrorMessage,
  106.                        "No phone number translation available");
  107.                 return 1;
  108.             }
  109.             if (!strcmp(FTS5Phone, "-Unpublished-"))
  110.                 FTS5Phone = PointPhoneNoHolder;
  111.         }
  112.         goto check_level;
  113.     case LEVEL_PRIVATE:
  114.         switch (PrivateLevel)
  115.         {
  116.         case 0:                /* OK */
  117.             break;
  118.         case -2:               /* NONE */
  119.             strcpy(ErrorMessage,
  120.                    "Private nodes not allowed in this network");
  121.             return 1;
  122.         default:
  123.             if (PhoneNoHolder[0] == 0)
  124.             {
  125.                 strcpy(ErrorMessage,
  126.                        "No phone number translation available");
  127.                 return 1;
  128.             }
  129.             FTS5Phone = PhoneNoHolder;
  130.             if (FTS5Flags[0] != 0)
  131.                 strcat(FTS5Flags, PVT);
  132.             else
  133.                 FTS5Flags = PVT + 1;
  134.             return 0;
  135.         }
  136.         /* FALLTHROUGH */
  137.     case LEVEL_REGION:
  138.     case LEVEL_HOST:
  139.     case LEVEL_HUB:
  140.     case LEVEL_OGATE:
  141.     case LEVEL_NODE:
  142.     case LEVEL_DOWN:
  143.     case LEVEL_HOLD:
  144.       check_level:
  145.         if (OnTop[level] > *ctxlevel)
  146.         {
  147.             sprintf(ErrorMessage, "\"%s\" not allowed in a %s",
  148.                     Levels[level], LevelsSimple[*ctxlevel]);
  149.             if (level > LEVEL_HOST)
  150.                 return 1;
  151.             else
  152.                 return 2;
  153.         }
  154.       out:
  155.         if (level <= PrivateLevel)
  156.             strcpy(PhoneNoHolder, FTS5Phone);
  157.         if (level <= PointLevel)
  158.             strcpy(PointPhoneNoHolder, FTS5Phone);
  159.         if (level < LEVEL_POINT) /* Points don't start a context... */
  160.         {
  161.             *ctxnum = num;
  162.             *ctxlevel = level;
  163.         }
  164.     }
  165.     return 0;
  166. }
  167.