File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / mpd / src / vars.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Jul 22 08:44:29 2013 UTC (10 years, 11 months ago) by misho
Branches: mpd, MAIN
CVS tags: v5_8p7, v5_8p1_cross, v5_8p1, v5_8, v5_7p0, v5_7, v5_6, HEAD
5.7

    1: 
    2: /*
    3:  * vars.c
    4:  *
    5:  * Written by Archie Cobbs <archie@freebsd.org>
    6:  * Copyright (c) 1995-1999 Whistle Communications, Inc. All rights reserved.
    7:  * See ``COPYRIGHT.whistle''
    8:  */
    9: 
   10: #include "ppp.h"
   11: #include "console.h"
   12: 
   13: /*
   14:  * DEFINITIONS
   15:  */
   16: 
   17:   #define ENABLE	1
   18:   #define DISABLE	2
   19:   #define ACCEPT	3
   20:   #define DENY		4
   21: 
   22:   #define NO_SCOLD	0x100
   23: 
   24: /*
   25:  * INTERNAL FUNCTIONS
   26:  */
   27: 
   28:   static void	Do(int which, int ac, char *av[], Options o, ConfInfo list);
   29:   static int	FindOpt(ConfInfo list, const char *name);
   30: 
   31: /*
   32:  * OptStat()
   33:  */
   34: 
   35: void
   36: OptStat(Context ctx, Options opt, ConfInfo list)
   37: {
   38:     int		k, peered = 0;
   39: 
   40:     for (k = 0; list[k].name; k++) {
   41: 	if (list[k].peered) {
   42: 	    peered=1;
   43: 	    break;
   44: 	}
   45:     }
   46: 
   47:     if (peered)
   48: 	Printf("\t\t\tSelf\t\tPeer\r\n");
   49:     for (k = 0; list[k].name; k++) {
   50: 	ConfInfo	const c = &list[k];
   51: 
   52: 	Printf("\t%-10s\t%s",
   53:     	    c->name, Enabled(opt, c->option) ? "enable" : "disable");
   54: 	if (c->peered)
   55:     	    Printf("\t\t%s", Acceptable(opt, c->option) ? "accept" : "deny");
   56: 	Printf("\r\n");
   57:     }
   58: }
   59: 
   60: /*
   61:  * NoCommand()
   62:  */
   63: 
   64: void
   65: NoCommand(int ac, char *av[], Options opt, ConfInfo list)
   66: {
   67:   Do(DISABLE, ac, av, opt, list);
   68:   Do(DENY | NO_SCOLD, ac, av, opt, list);
   69: }
   70: 
   71: /*
   72:  * YesCommand()
   73:  */
   74: 
   75: void
   76: YesCommand(int ac, char *av[], Options opt, ConfInfo list)
   77: {
   78:   Do(ENABLE, ac, av, opt, list);
   79:   Do(ACCEPT | NO_SCOLD, ac, av, opt, list);
   80: }
   81: 
   82: /*
   83:  * EnableCommand()
   84:  */
   85: 
   86: void
   87: EnableCommand(int ac, char *av[], Options opt, ConfInfo list)
   88: {
   89:   Do(ENABLE, ac, av, opt, list);
   90: }
   91: 
   92: /*
   93:  * DisableCommand()
   94:  */
   95: 
   96: void
   97: DisableCommand(int ac, char *av[], Options opt, ConfInfo list)
   98: {
   99:   Do(DISABLE, ac, av, opt, list);
  100: }
  101: 
  102: /*
  103:  * AcceptCommand()
  104:  */
  105: 
  106: void
  107: AcceptCommand(int ac, char *av[], Options opt, ConfInfo list)
  108: {
  109:   Do(ACCEPT, ac, av, opt, list);
  110: }
  111: 
  112: /*
  113:  * DenyCommand()
  114:  */
  115: 
  116: void
  117: DenyCommand(int ac, char *av[], Options opt, ConfInfo list)
  118: {
  119:   Do(DENY, ac, av, opt, list);
  120: }
  121: 
  122: /*
  123:  * Do()
  124:  */
  125: 
  126: static void
  127: Do(int which, int ac, char *av[], Options opt, ConfInfo list)
  128: {
  129:   const int	scold = !(which & NO_SCOLD);
  130: 
  131:   which &= ~NO_SCOLD;
  132:   for ( ; ac > 0; av++, ac--)
  133:   {
  134:     const int	index = FindOpt(list, *av);
  135: 
  136:     switch (index)
  137:     {
  138:       case -1:
  139: 	Log(LG_ERR, ("option \"%s\" unknown", *av));
  140: 	break;
  141:       case -2:
  142: 	Log(LG_ERR, ("option \"%s\" ambiguous", *av));
  143: 	break;
  144:       default:
  145: 	{
  146: 	  ConfInfo	const c = &list[index];
  147: 
  148: 	  switch (which)
  149: 	  {
  150: 	    case ENABLE:
  151: 	      Enable(opt, c->option);
  152: 	      break;
  153: 	    case DISABLE:
  154: 	      Disable(opt, c->option);
  155: 	      break;
  156: 	    case ACCEPT:
  157: 	      if (!c->peered)
  158: 	      {
  159: 		if (scold)
  160: 		  Log(LG_ERR, ("'%s %s' is not applicable",
  161: 		    "accept", c->name));
  162: 	      }
  163: 	      else
  164: 		Accept(opt, c->option);
  165: 	      break;
  166: 	    case DENY:
  167: 	      if (!c->peered)
  168: 	      {
  169: 		if (scold)
  170: 		  Log(LG_ERR, ("'%s %s' is not applicable", "deny", c->name));
  171: 	      }
  172: 	      else
  173: 		Deny(opt, c->option);
  174: 	      break;
  175: 	    default:
  176: 	      assert(0);
  177: 	  }
  178: 	}
  179: 	break;
  180:     }
  181:   }
  182: }
  183: 
  184: /*
  185:  * FindOpt()
  186:  *
  187:  * Returns index of option, -1 if not found, -2 if ambiguous
  188:  */
  189: 
  190: static int
  191: FindOpt(ConfInfo list, const char *name)
  192: {
  193:     int		k, found = -1;
  194: 
  195:     for (k = 0; list[k].name; k++) {
  196: 	if (strncasecmp(list[k].name, name, strlen(name)) == 0) {
  197:     	    if (found == -1)
  198: 		found = k;
  199:     	    else {
  200: 		found = -2;		/* ambiguous */
  201:     		break;
  202: 	    }
  203: 	}
  204:     }
  205:     return(found);
  206: }
  207: 
  208: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>