modules/up/src/rpsl/rpsl/schema_rpsl.cc

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. addClass
  2. initializeBase
  3. initializeFromFile
  4. initializeFromString
  5. initialize

   1 //  $Id: schema_rpsl.cc,v 1.18 2001/06/01 19:03:57 engin Exp $
   2 //
   3 //  Copyright (c) 1994 by the University of Southern California
   4 //  All rights reserved.
   5 //
   6 //  Permission to use, copy, modify, and distribute this software and its
   7 //  documentation in source and binary forms for lawful non-commercial
   8 //  purposes and without fee is hereby granted, provided that the above
   9 //  copyright notice appear in all copies and that both the copyright
  10 //  notice and this permission notice appear in supporting documentation,
  11 //  and that any documentation, advertising materials, and other materials
  12 //  related to such distribution and use acknowledge that the software was
  13 //  developed by the University of Southern California, Information
  14 //  Sciences Institute. The name of the USC may not be used to endorse or
  15 //  promote products derived from this software without specific prior
  16 //  written permission.
  17 //
  18 //  THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY
  19 //  REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY
  20 //  PURPOSE.  THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  21 //  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  22 //  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
  23 //  TITLE, AND NON-INFRINGEMENT.
  24 //
  25 //  IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
  26 //  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT, TORT,
  27 //  OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH, THE USE
  28 //  OR PERFORMANCE OF THIS SOFTWARE.
  29 //
  30 //  Questions concerning this software should be directed to 
  31 //  ratoolset@isi.edu.
  32 //
  33 //  Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
  34 
  35 #include "config.h"
  36 
  37 #include <fstream.h>
  38 #include <cstring>
  39 #include "gnu/std.h"
  40 
  41 #include "schema.hh"
  42 #include "object.hh"
  43 #include "rpsl.y.hh"
  44 #include "rptype.hh"
  45 
  46 #define NO          0
  47 #define PRS         1
  48 #define MAN         1
  49 #define SNG         1
  50 #define HDN         1
  51 #define KEY         1
  52 #define IDX         1
  53 #define OBS         1
  54 
  55 
  56 char Schema::dictionary_text[] = "";
  57 
  58 #define CMN_ATTRS "
  59 attr:  notify           syntax(email),                                         optional,  multiple
  60 attr:  remarks                                                                 optional,  multiple
  61 attr:  source           syntax(special,source),                                mandatory, single,   internal
  62 attr:  changed          syntax(special, changed),                              mandatory,  multiple
  63 attr:  delete                                                                  optional,  single, deleted
  64 attr:  override                                                                optional,  single"
  65 
  66 static char base_text[] = "class: dictionary        
  67 attr:  dictionary       syntax(rpsl_word),                                     mandatory, single,   key
  68 attr:  rp-attribute     syntax(special,rp-attribute),                          optional,  multiple
  69 attr:  typedef          syntax(special,typedef),                               optional,  multiple
  70 attr:  protocol         syntax(special,protocol),                              optional,  multiple            
  71 attr:  notify           syntax(email),                                         optional,  multiple
  72 attr:  remarks                                                                 optional,  multiple
  73 attr:  source           syntax(rpsl_word),                                     mandatory, single,   internal
  74 attr:  integrity        syntax(rpsl_word),                                     optional, single,   internal
  75 attr:  changed          optional,  multiple
  76 attr:  deleted                                                                 optional,  single, deleted  
  77 attr:  descr                                                                   mandatory, single 
  78 attr:  mnt-by           syntax(list of rpsl_word),                             mandatory, multiple, lookup
  79 attr:  tech-c                                                                  mandatory, multiple, lookup
  80 attr:  admin-c                                                                 optional,  multiple, lookup
  81 
  82 dictionary: rpsl
  83 descr:   rpsl dictionary
  84 admin-c: Cengiz Alaettinoglu
  85 tech-c: Cengiz Alaettinoglu
  86 mnt-by: MNT-CENGIZ
  87 changed: cengiz@isi.edu 19980324
  88 source: RPS-WG
  89 typedef: ListOfIPv4Prefix list of Address_Prefix
  90 typedef: Date integer[19000000,20000000]
  91 typedef: as_number-as_set_name union as_number, as_set_name
  92 typedef: ListOfas_number list of as_number
  93 typedef: ListOfas_number-as_set_name list of as_number-as_set_name
  94 typedef: ListOfas_set_name  list of as_set_name
  95 typedef: ListOfroute_set_name  list[1 : 65535] of route_set_name
  96 typedef: as_number-as_set_name-route_set_name-IPv4Prefix
  97          union as_number, as_set_name, route_set_name, Address_Prefix
  98 typedef: ListOfas_number-as_set_name-route_set_name-IPv4Prefix
  99          list of as_number-as_set_name-route_set_name-IPv4Prefix
 100 typedef: ListOfrpsl_word List of rpsl_word
 101 typedef: listofrpsl_word_non_empty list[1 : 65535] of rpsl_word
 102 rp-attribute: # preference, smaller values represent higher preferences
 103               pref
 104               operator=(integer[0, 65535])  
 105 rp-attribute: # BGP multi_exit_discriminator attribute
 106               med    
 107               operator=(union integer[0, 65535], enum[igp_cost])
 108               # to set med to the IGP metric: med = igp_cost;
 109               #operator=(enum[igp_cost])
 110 rp-attribute: # BGP destination preference attribute (dpa)
 111               dpa    
 112               operator=(integer[0, 65535])  
 113 rp-attribute: # BGP aspath attribute
 114               aspath
 115               # prepends AS numbers from last to first order
 116               prepend(as_number, ...)
 117 typedef:      # a community value in RPSL is either
 118               #  - a 4 byte integer
 119               #  - internet, no_export, no_advertise (see RFC-1997)
 120               community_elm union
 121               integer[1, 4294967295],
 122               enum[internet, no_export, no_advertise]
 123 typedef:      # list of community values { 40, no_export, 3561:70}
 124               community_list
 125               list of community_elm
 126 rp-attribute: # BGP community attribute
 127               community 
 128               # set to a list of communities
 129               operator=(community_list)
 130               # order independent equality comparison
 131               operator==(community_list)    
 132               # append community values                              
 133               operator.=(community_list)
 134               append(community_elm, ...)
 135               # delete community values
 136               delete(community_elm, ...)
 137               # a filter: true if one of community values is contained
 138               contains(community_elm, ...)
 139               # shortcut to contains: community(no_export, {3561,70})
 140               operator()(community_elm, ...)
 141 rp-attribute: # next hop router in a static route
 142               next-hop 
 143               operator=(ipv4_address)       # a router address
 144               operator=(enum[self])         # router's own address
 145 rp-attribute: # cost of a static route
 146               cost 
 147               operator=(integer[0, 65535])
 148 protocol: BGP4
 149           # as number of the peer router
 150           MANDATORY asno(as_number)
 151           # enable flap damping
 152           OPTIONAL flap_damp()        
 153           OPTIONAL flap_damp(integer[0,65535],# penalty per flap
 154                              integer[0,65535],# penalty value for supression
 155                              integer[0,65535],# penalty value for reuse
 156                              integer[0,65535],# halflife in secs when up
 157                              integer[0,65535],# halflife in secs when down
 158                              integer[0,65535])# maximum penalty
 159 protocol: OSPF
 160 protocol: RIP
 161 protocol: IGRP
 162 protocol: IS-IS
 163 protocol: STATIC
 164 protocol: RIPng
 165 protocol: DVMRP
 166 protocol: PIM-DM
 167 protocol: PIM-SM
 168 protocol: CBT
 169 protocol: MOSPF
 170 ";
 171 
 172 static char classes_text[] = "class: mntner
 173 attr:  mntner           syntax(rpsl_word),                                     mandatory, single,   key
 174 attr:  upd-to           syntax(email),                                         mandatory, multiple
 175 attr:  auth                                                                    mandatory, multiple
 176 attr:  mnt-nfy          syntax(email),                                         optional,  multiple                   " CMN_ATTRS "
 177 attr:  descr                                                                   mandatory, multiple 
 178 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory, multiple, lookup
 179 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 180 attr:  tech-c           syntax(special,nichdl),                                optional,  multiple, lookup
 181 attr:  referral-by      syntax(rpsl_word),                                     mandatory, single 
 182 attr:  auth-override    syntax(integer),                                       optional, single
 183 
 184 class: person
 185 attr:  person           syntax(special,person),                                mandatory, single,   lookup
 186 attr:  nic-hdl          syntax(special,nichdl),                                mandatory, single,   key
 187 attr:  address                                                                 mandatory, multiple
 188 attr:  phone            syntax(special,phone),                                 mandatory, multiple
 189 attr:  fax-no           syntax(special,phone),                                 optional,  multiple
 190 attr:  e-mail           syntax(email),                                         optional,  multiple, lookup           " CMN_ATTRS "
 191 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple, lookup
 192 
 193 class: role
 194 attr:  role             syntax(special,person),                                mandatory, single,   lookup
 195 attr:  nic-hdl          syntax(special,nichdl),                                mandatory, single,   key
 196 attr:  address                                                                 mandatory, multiple
 197 attr:  phone            syntax(special,phone),                                 optional, multiple
 198 attr:  fax-no           syntax(special,phone),                                 optional,  multiple
 199 attr:  e-mail           syntax(email),                                         mandatory, multiple, lookup
 200 attr:  trouble                                                                 optional,  multiple                   " CMN_ATTRS "
 201 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple, lookup
 202 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 203 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 204 
 205 class: route
 206 attr:  route            syntax(address_prefix),                                mandatory, single,   key, lookup
 207 attr:  origin           syntax(as_number),                                     mandatory, single,   key, lookup
 208 attr:  member-of        syntax(ListOfroute_set_name),                          optional,  multiple, lookup
 209 attr:  inject           syntax(special, inject),                               optional,  multiple
 210 attr:  components       syntax(special, components),                           optional,  single
 211 attr:  aggr-bndry       syntax(special, aggr-bndry),                           optional,  single
 212 attr:  aggr-mtd         syntax(special, aggr-mtd),                             optional,  single
 213 attr:  export-comps     syntax(special, filter),                               optional,  single
 214 attr:  holes            syntax(ListOfIPv4Prefix),                              optional,  multiple                   " CMN_ATTRS "
 215 attr:  descr                                                                   mandatory, multiple 
 216 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory, multiple, lookup
 217 attr:  cross-nfy        syntax(special,nichdl),                                optional,  multiple
 218 attr:  cross-mnt        syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple
 219 attr:  mnt-routes       syntax(rpsl_word),                                       optional,  multiple
 220 attr:  mnt-lower        syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple
 221 
 222 class: route-set
 223 attr:  route-set        syntax(route_set_name),                                mandatory, single,   key
 224 attr:  members          syntax(special, rs-members),                           optional,  multiple, lookup 
 225 attr:  mbrs-by-ref      syntax(list [1 : 65535] of rpsl_Word),                             optional,  multiple, lookup           " CMN_ATTRS "
 226 attr:  descr                                                                   mandatory, multiple 
 227 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory, multiple, lookup
 228 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 229 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 230 
 231 class: as-set
 232 attr:  as-set           syntax(as_set_name),                                   mandatory, single,   key
 233 attr:  members          syntax(list [1 : 65535] of union as_number, as_set_name),          optional,  multiple, lookup     
 234 attr:  mbrs-by-ref      syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple, lookup           " CMN_ATTRS "
 235 attr:  descr                                                                   mandatory, multiple 
 236 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory, multiple, lookup
 237 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 238 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 239 
 240 class: rtr-set
 241 attr:  rtr-set        syntax(rtr_set_name),                                       mandatory, single,   key
 242 attr:  members        syntax(list [1 : 65535] of union rtr_set_name, dns_name, ipv4_address), optional,  multiple, lookup 
 243 attr:  mbrs-by-ref    syntax(list [1 : 65535] of rpsl_Word),                                      optional,  multiple, lookup           " CMN_ATTRS "
 244 attr:  descr                                                                      mandatory, multiple 
 245 attr:  mnt-by         syntax(list [1 : 65535] of rpsl_word),                                      mandatory, multiple, lookup
 246 attr:  admin-c        syntax(special,nichdl),                                     mandatory, multiple, lookup
 247 attr:  tech-c         syntax(special,nichdl),                                     mandatory, multiple, lookup
 248 
 249 class: peering-set
 250 attr:  peering-set    syntax(peering_set_name),                                   mandatory, single,   key
 251 attr:  peering        syntax(special, peering),                                   mandatory, multiple                   " CMN_ATTRS "
 252 attr:  descr                                                                      mandatory, multiple 
 253 attr:  mnt-by         syntax(list [1 : 65535] of rpsl_word),                                      mandatory, multiple, lookup
 254 attr:  admin-c        syntax(special,nichdl),                                     mandatory, multiple, lookup
 255 attr:  tech-c         syntax(special,nichdl),                                     mandatory, multiple, lookup
 256 
 257 class: filter-set
 258 attr:  filter-set       syntax(filter_set_name),                               mandatory, single,   key
 259 attr:  filter           syntax(special, filter),                               mandatory, single                       " CMN_ATTRS "
 260 attr:  descr                                                                   mandatory, multiple 
 261 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory, multiple, lookup
 262 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 263 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 264 
 265 class: aut-num
 266 attr:  aut-num          syntax(as_number),                                     mandatory, single,   key
 267 attr:  as-name          syntax(rpsl_word),                                     mandatory, single,   lookup
 268 attr:  member-of        syntax(List [1 : 65535] Of AS_set_name),                           optional,  multiple, lookup
 269 attr:  import           syntax(special,import),                                optional,  multiple
 270 attr:  export           syntax(special,export),                                optional,  multiple
 271 attr:  default          syntax(special,default),                               optional,  multiple                   " CMN_ATTRS "
 272 attr:  descr                                                                   mandatory, multiple 
 273 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory, multiple, lookup
 274 attr:  mnt-routes       syntax(rpsl_word),                           optional,  multiple, lookup
 275 attr:  mnt-lower        syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple
 276 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 277 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 278 attr:  cross-nfy        syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple
 279 attr:  cross-mnt        syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple
 280 
 281 class: inet-rtr
 282 attr:  inet-rtr         syntax(dns_name),                                      mandatory, single,   key
 283 attr:  alias            syntax(dns_name),                                      optional,  multiple, lookup
 284 attr:  local-as         syntax(as_number),                                     mandatory, single,   lookup
 285 attr:  ifaddr           syntax(special,ifaddr),                                mandatory, multiple
 286 attr:  peer             syntax(special,peer),                                  optional,  multiple                   " CMN_ATTRS "
 287 attr:  member-of        syntax(List Of rtr_set_name),                          optional,  multiple, lookup
 288 attr:  descr                                                                   optional,  multiple 
 289 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory, multiple, lookup
 290 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 291 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 292 
 293 class: inetnum
 294 attr:  inetnum          syntax(range of ipv4_address),                         mandatory, single,   key
 295 attr:  netname          syntax(rpsl_word),                                     mandatory, single,   lookup
 296 attr:  country          syntax(special, country),                              mandatory, multiple
 297 attr:  rev-srv          syntax(list [1 : 65535] of union dns_name, rpsl_word),   optional,  multiple, lookup
 298 attr:  status           syntax(special,status_inet),                           mandatory, single
 299 attr:  mnt-routes       syntax(rpsl_word),                           optional, multiple 
 300 attr:  mnt-lower        syntax(list [1 : 65535] of rpsl_word),                               optional,  multiple                   " CMN_ATTRS "
 301 attr:  descr                                                                   mandatory, multiple 
 302 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory,  multiple, lookup
 303 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 304 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 305 
 306 class: inet6num
 307 attr:  inet6num          syntax(ipv6_prefix),                                  mandatory, single,   key
 308 attr:  netname           syntax(rpsl_word),                                    mandatory, single,   lookup
 309 attr:  country           syntax(special, country),                             mandatory, multiple
 310 attr:  rev-srv           syntax(list [1 : 65535] of union dns_name, rpsl_word),  optional,  multiple, lookup
 311 attr:  status                                                                  optional, generated, single
 312 attr:  mnt-lower        syntax(list [1 : 65535] of rpsl_word),                               optional,  multiple                   " CMN_ATTRS "
 313 attr:  descr                                                                   mandatory, multiple 
 314 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory,  multiple, lookup
 315 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 316 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 317 
 318 class: domain
 319 attr:  domain           syntax(union dns_name, rpsl_word),                     mandatory, single,   key
 320 attr:  sub-dom          syntax(list [1 : 65535] of union dns_name, rpsl_word),  optional,  multiple, lookup
 321 attr:  dom-net                                                                 optional,  multiple
 322 attr:  zone-c          syntax(special,nichdl),                                 mandatory, multiple, lookup
 323 attr:  nserver         syntax(list [1 : 65535] of union dns_name, rpsl_word),   optional,  multiple, lookup
 324 attr:  refer           syntax(special, refer),    optional, single
 325 attr:  mnt-lower        syntax(list [1 : 65535] of rpsl_word),                               optional,  multiple                   " CMN_ATTRS "
 326 attr:  descr                                                                   mandatory, multiple 
 327 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             optional,  multiple, lookup
 328 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 329 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 330 
 331 class: limerick
 332 attr:  limerick                                                                mandatory, single,   key
 333 attr:  text                                                                    mandatory, multiple
 334 attr:  author          syntax(special,nichdl),                                 mandatory, multiple, lookup           " CMN_ATTRS "
 335 attr:  descr                                                                   optional,  multiple 
 336 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory, multiple, lookup
 337 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 338 
 339 class: as-block
 340 attr:  as-block         syntax(union as_number, range of as_number),           mandatory, single,   key
 341 attr:  mnt-lower        syntax(list [1 : 65535] of rpsl_word),                               optional,  multiple                   " CMN_ATTRS "
 342 attr:  descr                                                                   optional, multiple 
 343 attr:  mnt-by           syntax(list [1 : 65535] of rpsl_word),                             mandatory,  multiple, lookup
 344 attr:  admin-c          syntax(special,nichdl),                                mandatory, multiple, lookup
 345 attr:  tech-c           syntax(special,nichdl),                                mandatory, multiple, lookup
 346 
 347 class: key-cert
 348 attr:  key-cert       mandatory, single,    key,        syntax(keycrtname)
 349 attr:  method         generated, optional, single,      syntax(rpsl_word)
 350 attr:  owner          generated, optional, multiple
 351 attr:  fingerpr       generated, optional, single
 352 attr:  certif         mandatory, multiple                        " CMN_ATTRS "
 353 attr:  mnt-by         mandatory, multiple, lookup,      syntax(list [1 : 65535] of rpsl_word)
 354 ";
 355 
 356 void Schema::addClass(AttrClass *clss) {
     /* [<][>][^][v][top][bottom][index][help] */
 357    classes[lastClass++] = clss;
 358 }
 359 
 360 void Schema::initializeBase() {
     /* [<][>][^][v][top][bottom][index][help] */
 361    static bool initializeBaseDone = false;
 362    if (initializeBaseDone)
 363       return;
 364    initializeBaseDone = true;
 365 
 366    AttrClass *classClass = new AttrClass(strdup("class"));
 367    AttrClass *clss = NULL;
 368 
 369    addClass(classClass);
 370    classClass->addAttr(new AttrAttr(strdup("class"), ATTR_GENERIC, 
 371                                     RPType::newRPType("rpsl_word"),
 372                                     AttrAttr::LOOKUP));
 373    classClass->addAttr(new AttrAttr(strdup("attr"), ATTR_ATTR,    
 374                                     (RPType *) NULL, 
 375                                     AttrAttr::MULTIVALUED));
 376 
 377    dictionary = initializeFromString(base_text, "dictionary");
 378 }
 379 
 380 List<Object> *Schema::initializeFromFile(char *filename) {
     /* [<][>][^][v][top][bottom][index][help] */
 381    Object *o;
 382    const AttrAttr *attr;
 383    char *class_name;
 384    bool code = true;
 385    List<Object> *result = new List<Object>;
 386    AttrClass *clss = NULL;
 387 
 388    initializeBase();
 389 
 390    ifstream in(filename);
 391    if (!in)
 392       return result;
 393 
 394    while (in) {
 395       o = new Object;
 396       code = o->read(in);
 397       if (! code) {
 398          delete o;
 399          continue;
 400       }
 401 
 402       code = o->scan();
 403       if (o->has_error)
 404          delete o;
 405       else {
 406          if (! strcasecmp(o->type->name, "class")) {
 407             AttrGenericIterator<ItemWORD> cname(o, "class");
 408             AttrIterator<AttrAttr>  attrItr(o, "attr");
 409             char *name = cname.first()->word;
 410 
 411             addClass(clss = new AttrClass(strdup(name)));
 412             clss->object = o;
 413             //cerr << "Reading "<< name << " class definition..." << endl;
 414             
 415             for (attr = attrItr.first(); attr; attr = attrItr.next())
 416                clss->addAttr((AttrAttr *) attr);
 417 
 418          } 
 419 
 420          result->append(o);
 421       }
 422    }
 423 
 424    return result;
 425 }
 426 
 427 Object *Schema::initializeFromString(char *class_text, char *lookFor) {
     /* [<][>][^][v][top][bottom][index][help] */
 428    Object *o;
 429    const AttrAttr *attr;
 430    char *class_name;
 431    Object *result = (Object *) NULL;
 432    AttrClass *clss = NULL;
 433    int count = 0;
 434 
 435    initializeBase();
 436 
 437    do {
 438       count++;
 439       o = new Object;
 440       if (count == 2 && ! dictionary)
 441          dictionary = o;
 442 
 443       o->scan(class_text, strlen(class_text));
 444 
 445       if (o->has_error)
 446          delete o;
 447       else {
 448          if (!strcasecmp(o->type->name, "class")) {
 449             AttrGenericIterator<ItemWORD> cname(o, "class");
 450             AttrIterator<AttrAttr>  attrItr(o, "attr");
 451             char *name = cname.first()->word;
 452 
 453             addClass(clss = new AttrClass(strdup(name)));
 454             clss->object = o;
 455             // cerr << "Reading "<< name << " class definition..." << endl;
 456 
 457             for (attr = attrItr.first(); attr; attr = attrItr.next())
 458                clss->addAttr((AttrAttr *) attr);
 459 
 460             //delete o;
 461          }
 462 
 463          if (lookFor && ! strcasecmp(o->type->name, lookFor))
 464             result = o;
 465       }
 466 
 467       class_text = strstr(class_text, "\n\n");
 468       if (class_text)
 469          class_text += 2;
 470    } while (class_text);
 471 
 472    return result;
 473 }
 474 
 475 void Schema::initialize() {
     /* [<][>][^][v][top][bottom][index][help] */
 476    initializeBase();
 477    initializeFromString(classes_text);
 478 }
 479 
 480 static RPSLKeyword rpsl_keywords[] = {
 481    RPSLKeyword("true",     KEYW_TRUE,     1),
 482    RPSLKeyword("false",    KEYW_FALSE,    1),
 483    RPSLKeyword("action",   KEYW_ACTION,   1),
 484    RPSLKeyword("accept",   KEYW_ACCEPT,   1),
 485    RPSLKeyword("announce", KEYW_ANNOUNCE, 1),
 486    RPSLKeyword("from",     KEYW_FROM,     1),
 487    RPSLKeyword("to",       KEYW_TO,       1),
 488    RPSLKeyword("at",       KEYW_AT,       1),
 489    RPSLKeyword("any",      KEYW_ANY,      1),
 490    RPSLKeyword("protocol", KEYW_PROTOCOL, 1),
 491    RPSLKeyword("into",     KEYW_INTO,     1),
 492    RPSLKeyword("refine",   KEYW_REFINE,   1),
 493    RPSLKeyword("except",   KEYW_EXCEPT,   1),
 494    RPSLKeyword("static",   KEYW_STATIC,   1),
 495    RPSLKeyword("networks", KEYW_NETWORKS, 1),
 496    RPSLKeyword("masklen",  KEYW_MASKLEN,  1),
 497    RPSLKeyword("peeras",   KEYW_PEERAS,   1),
 498 
 499    RPSLKeyword("atomic",   KEYW_ATOMIC,   1),
 500    RPSLKeyword("inbound",  KEYW_INBOUND,  1),
 501    RPSLKeyword("outbound", KEYW_OUTBOUND, 1),
 502 
 503    RPSLKeyword("or",       OP_OR ,        1),
 504    RPSLKeyword("and",      OP_AND,        1),
 505    RPSLKeyword("not",      OP_NOT,        1),
 506 
 507    RPSLKeyword("union",        KEYW_UNION,        1),
 508    RPSLKeyword("range",        KEYW_RANGE,        1),
 509    RPSLKeyword("list",         KEYW_LIST,         1),
 510    RPSLKeyword("of",           KEYW_OF,           1),
 511    RPSLKeyword("operator",     KEYW_OPERATOR,     1),
 512    RPSLKeyword("upon",         KEYW_UPON,         1),
 513    RPSLKeyword("have-components", KEYW_HAVE_COMPONENTS, 1),
 514    RPSLKeyword("exclude",      KEYW_EXCLUDE,      1),
 515 
 516    RPSLKeyword("syntax",       KEYW_SYNTAX,       1),
 517    RPSLKeyword("special",      KEYW_SPECIAL,      1),
 518    RPSLKeyword("optional",     KEYW_OPTIONAL,     1),
 519    RPSLKeyword("mandatory",    KEYW_MANDATORY,    1),
 520    RPSLKeyword("internal",     KEYW_INTERNAL,     1),
 521    RPSLKeyword("single",       KEYW_SINGLEVALUED, 1),
 522    RPSLKeyword("multiple",     KEYW_MULTIVALUED,  1),
 523    RPSLKeyword("lookup",       KEYW_LOOKUP,       1),
 524    RPSLKeyword("key",          KEYW_KEY,          1),
 525    RPSLKeyword("deleted",      KEYW_DELETED,      1),
 526    RPSLKeyword("generated",    KEYW_GENERATED,    1),
 527    RPSLKeyword("none",         KEYW_NONE,         1),
 528    RPSLKeyword("mail-from",    KEYW_MAILFROM,     1),
 529    RPSLKeyword("crypt-pw",     KEYW_CRYPTPW,      1),
 530    RPSLKeyword("assigned",     KEYW_ASSIGNED,     1),
 531    RPSLKeyword("allocated",    KEYW_ALLOCATED,    1),
 532    RPSLKeyword("PA",           KEYW_PA,           1),
 533    RPSLKeyword("PI",           KEYW_PI,           1),
 534    RPSLKeyword("unspecified",  KEYW_UNSPECIFIED,  1),
 535    RPSLKeyword("ext",          KEYW_EXT,          1),
 536    RPSLKeyword("simple",       KEYW_SIMPLE,       1),
 537    RPSLKeyword("ripe",         KEYW_RIPE,         1),
 538    RPSLKeyword("internic",     KEYW_INTERNIC,     1),
 539    RPSLKeyword("clientaddress",KEYW_CLIENTADDRESS,1),
 540    RPSLKeyword(NULL,       0,             0)
 541 };
 542 
 543 static RPSLKeyword rpsl_rules[] = {
 544    RPSLKeyword("changed",           ATTR_CHANGED,           1),
 545    RPSLKeyword("import",            ATTR_IMPORT,            1),
 546    RPSLKeyword("export",            ATTR_EXPORT,            1),
 547    RPSLKeyword("default",           ATTR_DEFAULT,           1),
 548    RPSLKeyword("ifaddr",            ATTR_IFADDR,            1),
 549    RPSLKeyword("peer",              ATTR_PEER,              1),
 550    RPSLKeyword("rp-attribute",      ATTR_RP_ATTR,           1),
 551    RPSLKeyword("typedef",           ATTR_TYPEDEF,           1),
 552    RPSLKeyword("protocol",          ATTR_PROTOCOL,          1),
 553    RPSLKeyword("filter",            ATTR_FILTER,            1),
 554    RPSLKeyword("peering",           ATTR_PEERING,           1),
 555    RPSLKeyword("blobs",             ATTR_BLOBS,             1),
 556    RPSLKeyword("mnt-routes",        ATTR_MNT_ROUTES,        1),
 557    RPSLKeyword("components",        ATTR_COMPONENTS,        1),
 558    RPSLKeyword("inject",            ATTR_INJECT,            1),
 559    RPSLKeyword("aggr-mtd",          ATTR_AGGR_MTD,          1),
 560    RPSLKeyword("aggr-bndry",        ATTR_AGGR_BNDRY,        1),
 561    RPSLKeyword("rs-members",        ATTR_RS_MEMBERS,        1),
 562    RPSLKeyword("nichdl",            ATTR_NICHDL,            1),
 563    RPSLKeyword("auth",              ATTR_AUTH,              1),
 564    RPSLKeyword("status_inet",       ATTR_STATUS_INET,       1),
 565    RPSLKeyword("phone",             ATTR_PHONE,             1),
 566    RPSLKeyword("source",            ATTR_SOURCE,            1),
 567    RPSLKeyword("refer",             ATTR_REFER,             1),
 568    RPSLKeyword("country",           ATTR_COUNTRY,           1),
 569    RPSLKeyword("person",            ATTR_PERSON,            1),
 570    RPSLKeyword(NULL, 0,                                     1)
 571 };
 572 
 573 Schema schema(rpsl_keywords, rpsl_rules);

/* [<][>][^][v][top][bottom][index][help] */