1 //  $Id$
2 // Copyright (c) 2001,2002                        RIPE NCC
3 //
4 // All Rights Reserved
5 //
6 // Permission to use, copy, modify, and distribute this software and its
7 // documentation for any purpose and without fee is hereby granted,
8 // provided that the above copyright notice appear in all copies and that
9 // both that copyright notice and this permission notice appear in
10 // supporting documentation, and that the name of the author not be
11 // used in advertising or publicity pertaining to distribution of the
12 // software without specific, written prior permission.
13 //
14 // THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15 // ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
16 // AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
17 // DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
18 // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 //
21 //
22 //  Copyright (c) 1994 by the University of Southern California
23 //  All rights reserved.
24 //
25 //    Permission is hereby granted, free of charge, to any person obtaining a copy
26 //    of this software and associated documentation files (the "Software"), to deal
27 //    in the Software without restriction, including without limitation the rights
28 //    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29 //    copies of the Software, and to permit persons to whom the Software is
30 //    furnished to do so, subject to the following conditions:
31 //
32 //    The above copyright notice and this permission notice shall be included in
33 //    all copies or substantial portions of the Software.
34 //
35 //    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 //    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 //    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 //    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 //    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 //    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
41 //    THE SOFTWARE.
42 //
43 //  Questions concerning this software should be directed to
44 //  irrtoolset@cs.usc.edu.
45 //
46 //  Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>
47 
48 #include "config.h"
49 #include "irrutil/debug.hh"
50 #include "community.hh"
51 #include <iostream>
52 #include "rpsl/rpsl_item.hh"
53 
54 using namespace std;
55 
addCommunity(Item * item)56 void CommunitySet::addCommunity(Item *item) {
57    if (typeid(*item) == typeid(ItemINT))
58       add(((ItemINT *)item)->i);
59    else
60       if (typeid(*item) == typeid(ItemWORD))
61 	 if (!strcasecmp(((ItemWORD *)item)->word, "no_advertise"))
62 	    add(COMMUNITY_NO_ADVERTISE);
63 	 else if (!strcasecmp(((ItemWORD *)item)->word, "no_export"))
64 	    add(COMMUNITY_NO_EXPORT);
65 	 else if (!strcasecmp(((ItemWORD *)item)->word,"no_export_subconfed"))
66 	    add(COMMUNITY_NO_EXPORT_SUBCONFED);
67 	 else
68 	    add(COMMUNITY_INTERNET);
69       else
70 	 if (typeid(*item) == typeid(ItemList)) {
71 	    int high = ((ItemINT *) ((ItemList *) item)->head())->i;
72 	    int low  = ((ItemINT *) ((ItemList *) item)->tail())->i;
73 	    add((high << 16) + low);
74 	 } else
75 	    cerr << "Warning: Ignoring non-community value " << *item << endl;
76 }
77 
operator <<(ostream & os,CommunitySet & cs)78 ostream& operator<<(ostream &os, CommunitySet& cs) {
79    for (Pix p = cs.first(); p;) {
80       community_print(os, cs(p));
81       cs.next(p);
82       if (p)
83 	 os << ", ";
84    }
85    return os;
86 }
87