Re: [tkined] Syntax (sub-)ranges patch?? [LONG]

Michael J. Long (mjlong@Summa4.COM)
Fri, 26 Sep 1997 11:41:54 -0400

Juergen Schoenwaelder wrote:
>
> "Michael J. Long" <mjlong@Summa4.COM> said:

[...snip...]

> I was trying to say that I am not adding this feature unless I find
> time to write a complete new parser. The exception to this rule are
> patches written by someone else that fit into the code without
> breaking something. Once again, I am not interested to make these
> patches myself.

I'm sorry, I misread what you had written before.

[...snip...]

> There are no patches as far as I know. Having no knowledge about
> parsers is actually an advantage if you look at the CMU derived MIB
> parser. (People with compiler construction background risk serious
> health problems when looking at this code. :-)

Now, I may be misreading again but...

Are you implying that CMU parser contains the code to interpret
sub-ranges?? I looked at parser.c in cmu-snmp-linux-3.3-src.tar.gz
and I see the following lines:
if (*ntype == LEFTPAREN){
level = 1;
/* don't record any constraints for now */
while(level > 0){
*ntype = get_token(fp, ntoken);
if (*ntype == LEFTPAREN)
level++;
if (*ntype == RIGHTPAREN)
level--;
}
*ntype = get_token(fp, ntoken);
} else if (*ntype == LEFTBRACKET) {
/* if there is an enumeration list, parse it */

Is there somewhere else that contains the code to parse sub-ranges??

I am assuming there is not and I have looked into what it would
(at least) take to add this bit of functionality. Please review
this list and tell me if I have missed anything:
1 create a new struct (Tnm_MibRange) to hold sub-range
information
typedef struct Tnm_MibRange {
int min; /* The min. value for this sub-range. */
int max; /* The max. value for this sub-range. */
struct Tnm_MibRange *nextPtr;
} Tnm_MibRange;
e.g., for a syntax of ( 1..12 ), the structure would
be:
+----------+
| min = 1 |
| max = 12 |
+----------+
| nextPtr |---> NULL
+----------+
for a syntax of ( 5 ):
+---------+
| min = 5 |
| max = 5 |
+---------+
| nextPtr |---> NULL
+---------+
for a syntax of ( 1..19 | 30..50 ):
+----------+ +----------+
| min = 1 | +-->| min = 30 |
| max = 19 | | | max = 50 |
+----------+ | +----------+
| nextPtr |--+ | nextPtr |---> NULL
+----------+ +----------+

2 Alter Tnm_MibTC to allow for either an enum or
range (they seem to be mutually exclusive):
typedef struct Tnm_MibTC {
char *name;
char *fileName;
char *moduleName;
short syntax;
char *displayHint;
Restriction restriction; /* Can be ENUMERATION or
RANGE (or NONE) */
void *restrictList; /* The list of restrictions. */
struct Tnm_MibTC *nextPtr;
} Tnm_MibTC;

Restriction would be defined as follows:
/* I can't remember if this syntax is correct */
typedef enum {
NONE = 0,
ENUMERATION,
RANGE
} Restriction;

It would be necessary to cast restrictList depending on
the type of restriction defined.

3 Add keywords to allow for easier processing of sub-ranges:
... /* After SEMICOLON?? */
{ "..", UPTO, 0 },
{ "|", OR, 0 },
...
4 Create a procedure (ReadRange) to perform for ranges
what ReadIntEnums performs for enums. I have yet to
think deeply about this one, but it will be a very
complex procedure that will create Tnm_MibRange structs.
It will also involve a considerable amount of range
checking. It need to make sure that the ranges given
are:
- within the valid range of its parent type
e.g., see RFC 1902, section 13.3
(does ReadIntEnums do this??)
- not overlapping each other (within one list
of Tnm_MibRange)
e.g., see RFC 1902, section 13.1 and 13.2
In addition to this, ReadIntEnums would:
- convert hex and binary String to ints for storage
- add new Tnm_MibRange in order in linked list
e.g., the syntax ( 30..50 | 1..19 ) would be
the exact same as ( 1..19 | 30..50 )

5 Add ReadRange to ParseFile (in tnmMibParser.c, line
823) and ParseObjectType (in tnmMibParser.c, line 1926).
Why is code dup'ped in two places?? The first for
non-INTEGER types and the latter for INTEGER types??

6 #define QUOTEVALUE, much like QUOTESTRING is defined,
and edit ReadKeyword (in tnmMibParser.c, line 2187) to
handle QUOTEVALUE just as it does QUOTESTRING. See
RFC 1902, section 13.1 for details (particularly the
definition of hexString and binString).

7 Fix all the code that will break because of item 2.

8 Add range and size options to tcl mib:
- add to MibCmd in tnmMibTcl.c, line 76
- create C procedures Tnm_MibGetRange and
Tnm_MibGetSize in tnmMibQuery.c

9 Ranges would be the list item at index 3 just like
enums are today (in the return from the mib syntax
command). The output would be something like:
{ {1..19} {25} {30..50} }
for a syntax of ( 1..19 | 25 | 30..50 ).

10 Fix all the code broken by item 9. The code is
written to assume that index 4 is an enumeration.
All I could find on this one was snmp.tcl and
sbrowser.cgi, is there more (in the scotty code)??

Well, that's all I could find at this time. If you know of
more areas that need attention, please let me know.

[...sig snipped...]

Michael J. Long

-- 
* Michael J. Long * #include <disclaimer.h>
*   Summa Four    * Work: mjlong@Summa4.COM
* Manchester, NH  * Play: mjlong@mindspring.com
--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.