[PATCH] Add vty command for setting Access control classes

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Peter Stuge peter at stuge.se
Thu Jul 25 16:18:14 UTC 2013


Peter Stuge wrote:
> >     if (',' == *p)
> >       p++;
> 
> Here it should actually also throw parse error if there is any other
> character than comma or end-of-input:

And there was an off-by-one error for the upper bound of a range.

I think I've caught all the issues in this version of the file. :)


//Peter
-------------- next part --------------
#include <stdio.h>

#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif /* MIN */
#ifndef MAX
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif /* MAX */

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof (a) / sizeof (a)[0])
#endif /* ARRAY_SIZE */

int main(int argc,const char *argv[]) {
  int i,val[16];
  int a,b,n1,n2;
  const char *p;

  if(argc<2) {
    fprintf(stderr,"usage: %s int[-int][,...]\n",*argv);
    return 1;
  }

  for(i=0;i<ARRAY_SIZE(val);i++)
    val[i]=0;

  p = argv[1];
  do {
    switch (sscanf(p, "%d%n-%d%n", &a, &n1, &b, &n2)) {
    case 0:
      fprintf(stderr, "invalid input at '%.5s'\n", p);
      return 2;
    case -1:
      perror("sscanf");
      return 3;
    case 1:
      if (a < ARRAY_SIZE(val))
        val[a] = 1;
      p += n1;
      break;
    case 2:
      b = MIN(MAX(a, b), ARRAY_SIZE(val) - 1);
      for (i = MIN(a, b); i <= b; i++)
        val[i] = 1;
      p += n2;
      break;
    }
    if (',' == *p)
      p++;
    else if (*p) {
      fprintf(stderr, "invalid input at '%.5s'\n", p);
      return 4;
    }
  } while (*p);

  for (i = 0; i < ARRAY_SIZE(val); i++)
    printf("val[%d]=%d\n", i, val[i]);

  return 0;
}


More information about the OpenBSC mailing list