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.seHolger Hans Peter Freyther wrote:
> > > + # Barred rach access control classes
> > > + self.vty.verify("rach access-control-class 0 barred", [''])
> > > + self.vty.verify("rach access-control-class 1 barred", [''])
> > > + self.vty.verify("rach access-control-class 2 barred", [''])
> >
> > what happened to the code that I sent for parsing ranges and not just
> > a single class digit?
>
> can you re-send your patch/diff for that? I can help with the test
> case for that.
I didn't make an actual patch, I only wrote and sent the range/list
parsing code, since Alex wrote that it would get used it if I sent it.
I'm attaching a cleaned-up version with all functionality moved to
an actual function and now also featuring input validation not just
for characters but also their meaning. Out-of-range list/range
numbers are no longer silently ignored but cause an error.
What's the best way to proceed? I suppose I could send a patch to
add this function somewhere - maybe libosmocore? It should obviously
log instead of sending to stderr then.
//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 parse_range_list(const char *str, int *val, size_t n_val) {
int i, ret = 0;
unsigned int a, b;
int n1, n2;
while (*str) {
switch (sscanf(str, "%u%n-%u%n", &a, &n1, &b, &n2)) {
case -1:
perror("sscanf");
return -1;
case 0:
goto invalid;
case 1:
if (a >= n_val)
goto invalid;
val[a] = 1;
ret++;
str += n1;
break;
case 2:
if (a >= n_val || b >= n_val)
goto invalid;
for (i = MIN(a, b); i <= MAX(a, b); i++) {
val[i] = 1;
ret++;
}
str += n2;
break;
}
if (',' == *str)
str++;
else if (*str)
goto invalid;
}
return ret;
invalid:
fprintf(stderr, "invalid input at '%.5s'\n", str);
return -1;
}
int main(int argc,const char *argv[]) {
int i, val[16];
if (argc < 2) {
fprintf(stderr, "usage: %s int[-int][,...]\n", *argv);
return 1;
}
memset(val, 0, sizeof val);
i = parse_range_list(argv[1], val, ARRAY_SIZE(val));
if (-1 == i)
return 2;
printf("parse_range_list() returns %d\n", i);
for (i = 0; i < ARRAY_SIZE(val); i++)
printf("val[%d]=%d\n", i, val[i]);
return 0;
}