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

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

## FUNCTIONS

This source file includes following functions.

1. Attribute
2. newRPType
3. newRPType
4. newRPType
5. newRPType
6. validate
7. typeCast
8. validate
9. validate
10. validate
11. typeCast
12. validate
13. validate
14. validate
15. typeCast
16. validate
17. validate
18. typeCast
19. validate
20. validate
21. validate
22. validate
23. validate
24. validate
25. validate
26. validate
27. typeCast
28. validate
29. validate
30. validate
31. validate
32. validate
33. validate
34. typeCast
35. validate
36. validate
37. validate
38. typeCast
39. validate
40. typeCast
41. name
42. validate
43. typeCast
44. validate
45. validate

       1 //  $Id: rptype.cc,v 1.1.1.1 2000/03/10 16:32:23 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 #include <cstring>
      37 #include <cstdarg>
      38 #include <cstdio>
      39 #include <typeinfo>
      40 #include "util/List.hh"
      41
      42 class Attribute;
         /* [<][>][^][v][top][bottom][index][help] */
      43 #include "rptype.hh"
      44 #include "schema.hh"
      45
      46 extern "C" {
      47 int strcasecmp(...);
      48 }
      49
      50 ////////////////////////////// RPType ////////////////////
      51
      52 RPType *RPType::newRPType(char *name) {
      53    if (!strcasecmp(name, "integer"))
      54       return new RPTypeInt;
      55    if (!strcasecmp(name, "real"))
      56       return new RPTypeReal;
      57    if (!strcasecmp(name, "rpsl_word"))
      58       return new RPTypeWord;
      59    //   if (!strcasecmp(name, "blob"))
      60    //      return new RPTypeBlob;
      61    if (!strcasecmp(name, "as_number"))
      62       return new RPTypeASNumber;
      63    if (!strcasecmp(name, "ipv4_address"))
      64       return new RPTypeIPv4Address;
      65    if (!strcasecmp(name, "address_prefix"))
      66       return new RPTypeIPv4Prefix;
      67    if (!strcasecmp(name, "ipv6_prefix"))
      68       return new RPTypeIPv6Prefix;
      69    if (!strcasecmp(name, "address_prefix_range"))
      70       return new RPTypeIPv4PrefixRange;
      71    if (!strcasecmp(name, "connection"))
      72       return new RPTypeConnection;
      73    if (!strcasecmp(name, "dns_name"))
      74       return new RPTypeDNSName;
      75    if (!strcasecmp(name, "filter"))
      76       return new RPTypeFilter;
      77    if (!strcasecmp(name, "as_set_name"))
      78       return new RPTypeASName;
      79    if (!strcasecmp(name, "route_set_name"))
      80       return new RPTypeRSName;
      81    if (!strcasecmp(name, "rtr_set_name"))
      82       return new RPTypeRtrsName;
      83    if (!strcasecmp(name, "peering_set_name"))
      84       return new RPTypePrngName;
      85    if (!strcasecmp(name, "filter_set_name"))
      86       return new RPTypeFltrName;
      87    if (!strcasecmp(name, "string"))
      88       return new RPTypeString;
      89    if (!strcasecmp(name, "time_stamp"))
      90       return new RPTypeTimeStamp;
      91    if (!strcasecmp(name, "boolean"))
      92       return new RPTypeBoolean;
      93    if (!strcasecmp(name, "free_text"))
      94       return new RPTypeFreeText;
      95    if (!strcasecmp(name, "email"))
      96       return new RPTypeEMail;
      97 //   if(!strcasecmp(name, "nichdl"))
      98 //      return new RPTypeNICHdl;
      99    if(!strcasecmp(name, "keycrtname"))
     100       return new RPTypeKeyCrtName;
     101
     102    return schema.searchTypedef(name);
     103 }
     104
     105 RPType *RPType::newRPType(char *name, long long int min, long long int max) {
         /* [<][>][^][v][top][bottom][index][help] */
     106    if (!strcasecmp(name, "integer"))
     107       return new RPTypeInt(min, max);
     108    if (!strcasecmp(name, "real"))
     109       return new RPTypeReal(min, max);
     110
     111    return NULL;
     112 }
     113
     114 RPType *RPType::newRPType(char *name, double min, double max) {
         /* [<][>][^][v][top][bottom][index][help] */
     115    if (!strcasecmp(name, "real"))
     116       return new RPTypeReal(min, max);
     117
     118    return NULL;
     119 }
     120
     121 RPType *RPType::newRPType(char *name, List<WordNode> *words) {
         /* [<][>][^][v][top][bottom][index][help] */
     122    if (!strcasecmp(name, "enum"))
     123       return new RPTypeEnum(words);
     124
     125    return NULL;
     126 }
     127
     128 RPType *RPType::newRPType(char *name, List<RPTypeNode> *types) {
         /* [<][>][^][v][top][bottom][index][help] */
     129    if (types && !types->isEmpty())
     130       if (!strcasecmp(name, "union"))
     131          return new RPTypeUnion(types);
     132
     133    return NULL;
     134 }
     135
     136 bool RPType::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     137    return false;
     138 }
     139 Item *RPType::typeCast(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     140    return NULL;
     141 }
     142 bool RPType::validate(ItemList *list) const {
         /* [<][>][^][v][top][bottom][index][help] */
     143    if (! list->isSingleton())
     144       return false;
     145    if (validate(list->head()))
     146       return true;
     147
     148    Item *w = typeCast(list->head());
     149    if (!w)
     150       return false;
     151
     152    list->clear();
     153    list->append(w);
     154
     155    return true;
     156 }
     157
     158 ////////////////////////////// RPTypeInt ////////////////////
     159
     160 bool RPTypeInt::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     161    return (typeid(*item) == typeid(ItemINT)
     162            && min <= ((ItemINT *) item)->i
     163            && max >= ((ItemINT *) item)->i);
     164 }
     165
     166 ////////////////////////////// RPTypeReal ////////////////////
     167
     168 bool RPTypeReal::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     169    return (typeid(*item) == typeid(ItemREAL)
     170            && min <= ((ItemREAL *) item)->real
     171            && max >= ((ItemREAL *) item)->real);
     172 }
     173
     174 Item *RPTypeReal::typeCast(const Item  *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     175    if (typeid(*item) == typeid(ItemINT)
     176        && min <= ((ItemINT *) item)->i
     177        && max >= ((ItemINT *) item)->i)
     178       return new ItemREAL(((ItemINT *) item)->i);
     179
     180    return NULL;
     181 }
     182
     183 ////////////////////////////// RPTypeString ////////////////////
     184
     185 bool RPTypeString::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     186    return (typeid(*item) == typeid(ItemSTRING));
     187 }
     188
     189 ////////////////////////////// RPTypeTimeStamp ////////////////////
     190
     191 bool RPTypeTimeStamp::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     192    return (typeid(*item) == typeid(ItemTimeStamp));
     193 }
     194
     195 ////////////////////////////// RPTypeWORD ////////////////////
     196
     197 bool RPTypeWord::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     198    return (typeid(*item) == typeid(ItemWORD));
     199 }
     200 Item *RPTypeWord::typeCast(const Item  *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     201    if (typeid(*item) == typeid(ItemASNAME)){
     202       return new ItemWORD(strdup(((ItemASNAME *) item)->name));
     203    }
     204    if (typeid(*item) == typeid(ItemRSNAME))
     205       return new ItemWORD(strdup(((ItemRSNAME *) item)->name));
     206    if (typeid(*item) == typeid(ItemRTRSNAME))
     207       return new ItemWORD(strdup(((ItemRTRSNAME *) item)->name));
     208    if (typeid(*item) == typeid(ItemPRNGNAME))
     209       return new ItemWORD(strdup(((ItemPRNGNAME *) item)->name));
     210 //   if (typeid(*item) == typeid(ItemNICHDL)){
     211 //      cout << "typecasting: ItemNICHDL->ItemWORD" << endl;
     212 //      return new ItemWORD(strdup(((ItemNICHDL *) item)->nichdl));
     213 //   }
     214    if (typeid(*item) == typeid(ItemFLTRNAME))
     215       return new ItemWORD(strdup(((ItemFLTRNAME *) item)->name));
     216    if (typeid(*item) == typeid(ItemKEYCRTNAME))
     217       return new ItemWORD(strdup(((ItemKEYCRTNAME *) item)->name));
     218    if (typeid(*item) == typeid(ItemBOOLEAN))
     219       if (((ItemBOOLEAN *) item)->i)
     220          return new ItemWORD(strdup("true"));
     221       else
     222          return new ItemWORD(strdup("false"));
     223    if (typeid(*item) == typeid(ItemASNO)) {
     224       char buffer[64];
     225       sprintf(buffer, "AS%d", ((ItemASNO *) item)->asno);
     226       return new ItemWORD(strdup(buffer));
     227    }
     228
     229    return NULL;
     230 }
     231
     232 ////////////////////////////// RPTypeNICHdl ////////////////////
     233 /*
     234 bool RPTypeNICHdl::validate(const Item *item) const {
     235    if(typeid(*item) == typeid(ItemNICHDL)){
     236       cout << "Debug: RPTypeNICHdl::validate (nichdl = "<< ((ItemNICHDL *) item)->nichdl << ")" << endl;
     237    }else{
     238       cout << "Debug: RPTypeNICHdl::validate" << endl;
     239    }
     240    cout << "Debug: RPTypeNICHdl::validate " << typeid(*item).name() << " " << typeid(ItemNICHDL).name() << endl;
     241 //   return false;
     242    return (typeid(*item) == typeid(ItemNICHDL)
     243             && ((strchr(((ItemNICHDL *) item)->nichdl,'q') != NULL)
     244                || (strchr(((ItemNICHDL *) item)->nichdl,'Q') != NULL)));
     245 }
     246 */
     247 /*Item *RPTypeNICHdl::typeCast(const Item  *item) const {
     248    if (typeid(*item) == typeid(ItemWORD)){
     249       cout << "typecasting: ItemWORD -> ItemNICHDL" << endl;
     250       return new ItemNICHDL(strdup(((ItemWORD *) item)->word));
     251    }
     252    if (typeid(*item) == typeid(ItemASNAME))
     253       return new ItemNICHDL(strdup(((ItemASNAME *) item)->name));
     254    if (typeid(*item) == typeid(ItemRSNAME))
     255       return new ItemNICHDL(strdup(((ItemRSNAME *) item)->name));
     256    if (typeid(*item) == typeid(ItemRTRSNAME))
     257       return new ItemNICHDL(strdup(((ItemRTRSNAME *) item)->name));
     258    if (typeid(*item) == typeid(ItemPRNGNAME))
     259       return new ItemNICHDL(strdup(((ItemPRNGNAME *) item)->name));
     260    if (typeid(*item) == typeid(ItemFLTRNAME))
     261       return new ItemNICHDL(strdup(((ItemFLTRNAME *) item)->name));
     262    if (typeid(*item) == typeid(ItemKEYCRTNAME))
     263       return new ItemWORD(strdup(((ItemKEYCRTNAME *) item)->name));
     264    if (typeid(*item) == typeid(ItemBOOLEAN))
     265       if (((ItemBOOLEAN *) item)->i)
     266          return new ItemNICHDL(strdup("true"));
     267       else
     268          return new ItemNICHDL(strdup("false"));
     269    if (typeid(*item) == typeid(ItemASNO)) {
     270       char buffer[64];
     271       sprintf(buffer, "AS%d", ((ItemASNO *) item)->asno);
     272       return new ItemNICHDL(strdup(buffer));
     273    }
     274
     275    return NULL;
     276 }*/
     277
     278 ////////////////////////////// RPTypeKeyCrtName ////////////////////
     279
     280 bool RPTypeKeyCrtName::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     281    return (typeid(*item) == typeid(ItemKEYCRTNAME));
     282 }
     283 //Item *RPTypeKeyCrtName::typeCast(const Item  *item) const {
     284 //   if (typeid(*item) == typeid(ItemWORD))
     285 //      return new ItemKEYCRTNAME(strdup(((ItemWORD *) item)->word));
     286 //   if (typeid(*item) == typeid(ItemASNAME))
     287 //      return new ItemKEYCRTNAME(strdup(((ItemASNAME *) item)->name));
     288 //   if (typeid(*item) == typeid(ItemRSNAME))
     289 //      return new ItemKEYCRTNAME(strdup(((ItemRSNAME *) item)->name));
     290 //   if (typeid(*item) == typeid(ItemRTRSNAME))
     291 //      return new ItemKEYCRTNAME(strdup(((ItemRTRSNAME *) item)->name));
     292 //   if (typeid(*item) == typeid(ItemPRNGNAME))
     293 //      return new ItemKEYCRTNAME(strdup(((ItemPRNGNAME *) item)->name));
     294 //   if (typeid(*item) == typeid(ItemFLTRNAME))
     295 //      return new ItemKEYCRTNAME(strdup(((ItemFLTRNAME *) item)->name));
     296 //   if (typeid(*item) == typeid(ItemNICHDL))
     297 //      return new ItemKEYCRTNAME(strdup(((ItemNICHDL *) item)->nichdl));
     298 //   if (typeid(*item) == typeid(ItemBOOLEAN))
     299 //      if (((ItemBOOLEAN *) item)->i)
     300 //       return new ItemNICHDL(strdup("true"));
     301 //      else
     302 //       return new ItemNICHDL(strdup("false"));
     303 //   if (typeid(*item) == typeid(ItemASNO)) {
     304 //      char buffer[64];
     305 //      sprintf(buffer, "AS%d", ((ItemASNO *) item)->asno);
     306 //      return new ItemNICHDL(strdup(buffer));
     307 //   }
     308 //
     309 //   return NULL;
     310 //}
     311
     312 ////////////////////////////// RPTypeBlob ////////////////////
     313
     314 bool RPTypeBlob::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     315    return (typeid(*item) == typeid(ItemBLOB));
     316 }
     317
     318 Item *RPTypeBlob::typeCast(const Item  *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     319    if (typeid(*item) == typeid(ItemASNAME))
     320       return new ItemBLOB(strdup(((ItemASNAME *) item)->name));
     321    if (typeid(*item) == typeid(ItemRSNAME))
     322       return new ItemBLOB(strdup(((ItemRSNAME *) item)->name));
     323    if (typeid(*item) == typeid(ItemRTRSNAME))
     324       return new ItemBLOB(strdup(((ItemRTRSNAME *) item)->name));
     325    if (typeid(*item) == typeid(ItemPRNGNAME))
     326       return new ItemBLOB(strdup(((ItemPRNGNAME *) item)->name));
     327    if (typeid(*item) == typeid(ItemFLTRNAME))
     328       return new ItemBLOB(strdup(((ItemFLTRNAME *) item)->name));
     329   // if (typeid(*item) == typeid(ItemNICHDL))
     330   //    return new ItemBLOB(strdup(((ItemNICHDL *) item)->nichdl));
     331    if (typeid(*item) == typeid(ItemKEYCRTNAME))
     332       return new ItemBLOB(strdup(((ItemKEYCRTNAME *) item)->name));
     333    if (typeid(*item) == typeid(ItemBOOLEAN))
     334       if (((ItemBOOLEAN *) item)->i)
     335          return new ItemBLOB(strdup("true"));
     336       else
     337          return new ItemBLOB(strdup("false"));
     338    if (typeid(*item) == typeid(ItemASNO)) {
     339       char buffer[64];
     340       sprintf(buffer, "AS%d", ((ItemASNO *) item)->asno);
     341       return new ItemWORD(strdup(buffer));
     342    }
     343
     344    return NULL;
     345 }
     346
     347 ////////////////////////////// RPTypeASName ////////////////////
     348
     349 bool RPTypeASName::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     350    return (typeid(*item) == typeid(ItemASNAME));
     351 }
     352
     353 ////////////////////////////// RPTypeRSName ////////////////////
     354
     355 bool RPTypeRSName::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     356    return (typeid(*item) == typeid(ItemRSNAME));
     357 }
     358
     359 ////////////////////////////// RPTypeRTRSName ////////////////////
     360
     361 bool RPTypeRtrsName::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     362    return (typeid(*item) == typeid(ItemRTRSNAME));
     363 }
     364
     365 ////////////////////////////// RPTypePrngName ////////////////////
     366
     367 bool RPTypePrngName::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     368    return (typeid(*item) == typeid(ItemPRNGNAME));
     369 }
     370
     371 ////////////////////////////// RPTypeFltrName ////////////////////
     372
     373 bool RPTypeFltrName::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     374    return (typeid(*item) == typeid(ItemFLTRNAME));
     375 }
     376
     377 ////////////////////////////// RPTypeEMail ////////////////////
     378
     379 bool RPTypeEMail::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     380    return (typeid(*item) == typeid(ItemEMAIL));
     381 }
     382
     383 ////////////////////////////// RPTypeFreeText ////////////////////
     384
     385 bool RPTypeFreeText::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     386    return (typeid(*item) == typeid(ItemFREETEXT));
     387 }
     388
     389 ////////////////////////////// RPTypeEnum ////////////////////
     390
     391 bool RPTypeEnum::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     392    if (typeid(*item) != typeid(ItemWORD))
     393          return false;
     394
     395    for (WordNode* p = words->head(); p; p = words->next(p))
     396          if (!strcasecmp(((ItemWORD *) item)->word, p->word))
     397             return true;
     398
     399    return false;
     400 }
     401
     402 Item *RPTypeEnum::typeCast(const Item  *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     403    ItemWORD *w = NULL;
     404
     405    if (typeid(*item) == typeid(ItemASNAME))
     406       w = new ItemWORD(strdup(((ItemASNAME *) item)->name));
     407    if (typeid(*item) == typeid(ItemRSNAME))
     408       w = new ItemWORD(strdup(((ItemRSNAME *) item)->name));
     409    if (typeid(*item) == typeid(ItemRTRSNAME))
     410       w = new ItemWORD(strdup(((ItemRTRSNAME *) item)->name));
     411    if (typeid(*item) == typeid(ItemPRNGNAME))
     412       w = new ItemWORD(strdup(((ItemPRNGNAME *) item)->name));
     413    if (typeid(*item) == typeid(ItemFLTRNAME))
     414       w = new ItemWORD(strdup(((ItemFLTRNAME *) item)->name));
     415 //   if (typeid(*item) == typeid(ItemNICHDL))
     416 //      w = new ItemWORD(strdup(((ItemNICHDL *) item)->nichdl));
     417    if (typeid(*item) == typeid(ItemKEYCRTNAME))
     418       w = new ItemWORD(strdup(((ItemKEYCRTNAME *) item)->name));
     419    if (typeid(*item) == typeid(ItemBOOLEAN))
     420       if (((ItemBOOLEAN *) item)->i)
     421          w = new ItemWORD(strdup("true"));
     422       else
     423          w = new ItemWORD(strdup("false"));
     424    if (typeid(*item) == typeid(ItemASNO)) {
     425       char buffer[64];
     426       sprintf(buffer, "AS%d", ((ItemASNO *) item)->asno);
     427       w = new ItemWORD(strdup(buffer));
     428    }
     429
     430    if (w && validate(w))
     431       return w;
     432    if (w)
     433       delete w;
     434
     435    return NULL;
     436 }
     437
     438 ////////////////////////////// RPTypeBoolean ////////////////////
     439
     440 bool RPTypeBoolean::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     441    return (typeid(*item) == typeid(ItemBOOLEAN));
     442 }
     443
     444 ////////////////////////////// RPTypeASNumber ////////////////////
     445
     446 bool RPTypeASNumber::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     447    return ((typeid(*item) == typeid(ItemASNO))
     448            && ((ItemASNO *) item)->asno <= 65535);
     449 }
     450
     451 ////////////////////////////// RPTypeIPv4Address ////////////////////
     452
     453 bool RPTypeIPv4Address::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     454    return (typeid(*item) == typeid(ItemIPV4));
     455 }
     456
     457 ////////////////////////////// RPTypeIPv4Prefix ////////////////////
     458
     459 bool RPTypeIPv4Prefix::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     460    return (typeid(*item) == typeid(ItemPRFXV4));
     461 }
     462
     463 ////////////////////////////// RPTypeIPv6Prefix ////////////////////
     464
     465 bool RPTypeIPv6Prefix::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     466       return (typeid(*item) == typeid(ItemPRFXV6));
     467 }
     468
     469 ////////////////////////////// RPTypeIPv4PrefixRange ////////////////////
     470
     471 bool RPTypeIPv4PrefixRange::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     472    return (typeid(*item) == typeid(ItemPRFXV4Range));
     473 }
     474
     475 Item *RPTypeIPv4PrefixRange::typeCast(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     476    if (typeid(*item) == typeid(ItemPRFXV4))
     477       return new ItemPRFXV4Range
     478          (new PrefixRange(*((ItemPRFXV4 *) item)->prfxv4));
     479    return NULL;
     480 }
     481
     482 ////////////////////////////// RPTypeConnection ////////////////////
     483
     484 bool RPTypeConnection::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     485    return (typeid(*item) == typeid(ItemConnection));
     486 }
     487
     488 ////////////////////////////// RPTypeDNSName ////////////////////
     489
     490 bool RPTypeDNSName::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     491    return (typeid(*item) == typeid(ItemDNS));
     492 }
     493
     494 ////////////////////////////// RPTypeFilter ////////////////////
     495
     496 bool RPTypeFilter::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     497    return (typeid(*item) == typeid(ItemFilter));
     498 }
     499
     500 Item *RPTypeFilter::typeCast(const Item  *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     501    if (typeid(*item) == typeid(ItemASNAME))
     502       return new ItemFilter(new FilterASNAME(((ItemASNAME *) item)->name));
     503    if (typeid(*item) == typeid(ItemRSNAME))
     504       return new ItemFilter(new FilterRSNAME(((ItemRSNAME *) item)->name));
     505    if (typeid(*item) == typeid(ItemRTRSNAME))
     506       return new ItemFilter(new FilterRTRSNAME(((ItemRTRSNAME *) item)->name));
     507    if (typeid(*item) == typeid(ItemFLTRNAME))
     508       return new ItemFilter(new FilterFLTRNAME(((ItemFLTRNAME *) item)->name));
     509    if (typeid(*item) == typeid(ItemASNO))
     510       return new ItemFilter(new FilterASNO(((ItemASNO *) item)->asno));
     511
     512    return NULL;
     513 }
     514
     515 ////////////////////////////// RPTypeUnion ////////////////////
     516
     517 bool RPTypeUnion::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     518    for (RPTypeNode* p = types->head(); p; p = types->next(p))
     519       if (p->type->validate(item))
     520          return true;
     521
     522    return false;
     523 }
     524
     525 Item *RPTypeUnion::typeCast(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     526    Item *w;
     527    for (RPTypeNode* p = types->head(); p; p = types->next(p)) {
     528       w = p->type->typeCast(item);
     529       if (w)
     530          return w;
     531    }
     532
     533    return NULL;
     534 }
     535
     536 const char *RPTypeUnion::name() {
         /* [<][>][^][v][top][bottom][index][help] */
     537    if (!_name) {
     538       char buffer[1024];
     539       strcpy(buffer, "union ");
     540       for (RPTypeNode *n = types->head(); n; ) {
     541          strcat(buffer, n->type->name());
     542          n = types->next(n);
     543          if (n)
     544             strcat(buffer, ", ");
     545       }
     546       _name = strdup(buffer);
     547    }
     548    return _name;
     549 }
     550
     551 ////////////////////////////// RPTypeRange ////////////////////
     552
     553 bool RPTypeRange::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     554    if (typeid(*item) == typeid(ItemRange))
     555       return type->validate(((ItemRange*) item)->begin)
     556          && type->validate(((ItemRange*) item)->end)
     557          && (*((ItemRange*) item)->begin) <= (*((ItemRange*) item)->end);
     558    return false;
     559 }
     560
     561 Item *RPTypeRange::typeCast(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     562    Item *w = NULL;
     563
     564    if (type->validate(item))
     565       w = item->dup();
     566    else
     567       w = type->typeCast(item);
     568
     569    if (w)
     570       return new ItemRange(w, w->dup());
     571
     572    return NULL;
     573 }
     574
     575 ////////////////////////////// RPTypeList ////////////////////
     576
     577 bool RPTypeList::validate(const Item *item) const {
         /* [<][>][^][v][top][bottom][index][help] */
     578    if (typeid(*item) == typeid(ItemList))
     579       return validate((ItemList*) item);
     580    return false;
     581 }
     582 bool RPTypeList::validate(ItemList *l) const {
         /* [<][>][^][v][top][bottom][index][help] */
     583    Item *w;
     584
     585    if (! (min_elms <= l->size() && l->size() <= max_elms))
     586       return false;
     587
     588    for (Item *item = l->head(); item; item = l->next(item))
     589       if (! type->validate(item)) {
     590          w = type->typeCast(item);
     591          if (w) {
     592             l->insertAfter(item, w);
     593             l->remove(item);
     594             delete item;
     595             item = w;
     596          } else
     597             return false;
     598       }
     599
     600    return true;
     601 }
     602

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