## modules/up/src/rpsl/rpsl/schema.cc

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

## FUNCTIONS

This source file includes following functions.

1. Schema
2. searchClass
3. printClassStats
4. searchKeyword
5. searchAttrSyntax
6. searchTypedef
7. searchProtocol
8. searchRPAttr
9. searchSource
10. searchCountry
11. validNICHandle

       1 //  $Id: schema.cc,v 1.3 2001/05/23 12:37:28 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 <cstring>
      38 #include <cstdio>
      39 #include "gnu/std.h"
      40
      41 #include "object.hh"
      42 #include "schema.hh"
      43
      44 Schema::~Schema()  {
         /* [<][>][^][v][top][bottom][index][help] */
      45    //   if (dictionary)
      46    //   delete dictionary;
      47 }
      48
      49 AttrClass* Schema::searchClass(const char *name) {
         /* [<][>][^][v][top][bottom][index][help] */
      50    for (int i = 0; i < lastClass; ++i)
      51       if (!strcasecmp(name, classes[i]->name)) {
      52          classes[i]->touch();
      53          classes[i]->reset();
      54          return classes[i];
      55       }
      56
      57    return NULL;
      58 }
      59
      60 void Schema::printClassStats() {
         /* [<][>][^][v][top][bottom][index][help] */
      61    for (int i = 0; i < lastClass; ++i)
      62       cout << classes[i]->name << " " << classes[i]->ref_cnt << "\n";
      63 }
      64
      65 int Schema::searchKeyword(const char *word) { // return token_id or -1
         /* [<][>][^][v][top][bottom][index][help] */
      66    for (int i = 0; keywords[i]._name; i++)
      67       if (!strcasecmp(keywords[i]._name, word)) {
      68          if (!is_context_active || keywords[i].is_reserved)
      69             return keywords[i].token_id;
      70          else
      71             break;
      72       }
      73
      74    return -1;
      75 }
      76
      77 int Schema::searchAttrSyntax(const char *word) { // return token_id or -1
         /* [<][>][^][v][top][bottom][index][help] */
      78    for (int i = 0; attrSyntax[i]._name; i++)
      79       if (!strcasecmp(attrSyntax[i]._name, word)) {
      80          if (!is_context_active || attrSyntax[i].is_reserved)
      81             return attrSyntax[i].token_id;
      82          else
      83             break;
      84       }
      85
      86    return -1;
      87 }
      88
      89 RPType* Schema::searchTypedef(const char *name) {
         /* [<][>][^][v][top][bottom][index][help] */
      90    AttrIterator<AttrTypedef> itr(dictionary, "typedef");
      91    const AttrTypedef *tdef;
      92
      93    for (tdef = itr.first(); tdef; tdef = itr.next())
      94       if (! strcasecmp(tdef->name, name))
      95          return tdef->type;
      96
      97    return NULL;
      98 }
      99
     100 const AttrProtocol* Schema::searchProtocol(const char *name) {
         /* [<][>][^][v][top][bottom][index][help] */
     101    AttrIterator<AttrProtocol> itr(dictionary, "protocol");
     102    const AttrProtocol *prot;
     103
     104    for (prot = itr.first(); prot; prot = itr.next())
     105       if (! strcasecmp(prot->name, name))
     106          return prot;
     107
     108    return (AttrProtocol *) NULL;
     109 }
     110
     111 const AttrRPAttr *Schema::searchRPAttr(const char *word) {
         /* [<][>][^][v][top][bottom][index][help] */
     112    // return token_id or -1
     113    if (!dictionary)
     114       return NULL;
     115
     116    AttrIterator<AttrRPAttr> itr(dictionary, "rp-attribute");
     117    const AttrRPAttr *attr;
     118
     119    for (attr = itr.first(); attr; attr = itr.next())
     120       if (!strcasecmp(attr->name, word))
     121          return attr;
     122
     123    return (AttrRPAttr *) NULL;
     124 }
     125
     126 int Schema::searchSource(const char *name) { // return 0 or 1
         /* [<][>][^][v][top][bottom][index][help] */
     127    int i = 0;
     128    while(sources[i]){
     129      if(strcasecmp(sources[i++],name) == 0){
     130        return 1;
     131      }
     132    }
     133    return 0;
     134 }
     135
     136 int Schema::searchCountry(const char *name) { // return 0 or 1
         /* [<][>][^][v][top][bottom][index][help] */
     137    int i = 0;
     138    while(countries[i]){
     139      if(strcasecmp(countries[i++],name) == 0){
     140        return 1;
     141      }
     142    }
     143    return 0;
     144 }
     145
     146 int Schema::validNICHandle(const char *name) { // return 0 or 1
         /* [<][>][^][v][top][bottom][index][help] */
     147    int i = 0;
     148    if(!strchr(name,'-') || strncasecmp(name,"AUTO-",strlen("AUTO-")) == 0){
     149       return 1;
     150    }else{
     151      i = 0;
     152      while(nicsuffixes[i]){
     153        if(strcasecmp(nicsuffixes[i++],strchr(name,'-')+1) == 0){
     154          return 1;
     155        }
     156      }
     157      i = 0;
     158      while(sources[i]){
     159        if(strcasecmp(sources[i++],strchr(name,'-')+1) == 0){
     160          return 1;
     161        }
     162      }
     163      i = 0;
     164      while(countries[i]){
     165        if(strcasecmp(countries[i++],strchr(name,'-')+1) == 0){
     166          return 1;
     167        }
     168      }
     169
     170    }
     171    return 0;
     172 }
     173
     174

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