nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 2002, 2008, 2009, 2011, 2012 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or (at 00008 // your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #include <lib/ac/limits.h> 00020 00021 #include <lib/space/protocols/slurp.h> 00022 #include <lib/symtab.h> 00023 00024 00025 space_protocols_slurp::~space_protocols_slurp() 00026 { 00027 } 00028 00029 00030 space_protocols_slurp::space_protocols_slurp(const rcstring &a_filename) : 00031 space_protocols(a_filename) 00032 { 00033 } 00034 00035 00036 space_protocols_slurp::pointer 00037 space_protocols_slurp::create(const rcstring &a_filename) 00038 { 00039 return pointer(new space_protocols_slurp(a_filename)); 00040 } 00041 00042 00043 void 00044 space_protocols_slurp::process(const record::pointer &rp) 00045 { 00046 // check the name 00047 { 00048 by_name_t::iterator bnit = by_name.find(rp->get_name()); 00049 if (bnit != by_name.end()) 00050 { 00051 error 00052 ( 00053 rp->get_source_location(), 00054 "duplicate %s protocol name...", 00055 rp->get_name().quote_c().c_str() 00056 ); 00057 error 00058 ( 00059 bnit->second->get_source_location(), 00060 "... here is the first use of the %s protocol name", 00061 bnit->second->get_name().quote_c().c_str() 00062 ); 00063 } 00064 else 00065 { 00066 by_name.insert(by_name_t::value_type(rp->get_name(), rp)); 00067 } 00068 } 00069 00070 // 00071 // Check the number 00072 // 00073 long value = rp->get_number_binary(); 00074 by_number_t::iterator nit = by_number.find(value); 00075 if (nit != by_number.end()) 00076 { 00077 error 00078 ( 00079 rp->get_source_location(), 00080 "duplicate %s protocol number...", 00081 rp->get_number().quote_c().c_str() 00082 ); 00083 error 00084 ( 00085 nit->second->get_source_location(), 00086 "...here is the first %s protocol number", 00087 nit->second->get_number().quote_c().c_str() 00088 ); 00089 } 00090 else 00091 { 00092 by_number.insert(by_number_t::value_type(value, rp)); 00093 } 00094 00095 // 00096 // Check the aliases 00097 // 00098 const record::aliases_t &aliases = rp->get_aliases(); 00099 for 00100 ( 00101 record::aliases_t::const_iterator it = aliases.begin(); 00102 it != aliases.end(); 00103 ++it 00104 ) 00105 { 00106 by_name_t::iterator bnit = by_name.find(*it); 00107 if (bnit != by_name.end()) 00108 { 00109 error 00110 ( 00111 rp->get_source_location(), 00112 "duplicate %s protocol name...", 00113 rp->get_name().quote_c().c_str() 00114 ); 00115 error 00116 ( 00117 bnit->second->get_source_location(), 00118 "... here is the first use of the %s protocol name", 00119 bnit->second->get_name().quote_c().c_str() 00120 ); 00121 } 00122 else 00123 { 00124 by_name.insert(by_name_t::value_type(*it, rp)); 00125 } 00126 } 00127 } 00128 00129 00130 void 00131 space_protocols_slurp::read_and_process(void) 00132 { 00133 for (;;) 00134 { 00135 space_protocols::record::pointer rp = get(); 00136 if (!rp) 00137 break; 00138 process(rp); 00139 } 00140 close(); 00141 } 00142 00143 00144 space_protocols::record::pointer 00145 space_protocols_slurp::query_by_name(const rcstring &key) 00146 const 00147 { 00148 by_name_t::const_iterator it = by_name.find(key); 00149 if (it == by_name.end()) 00150 return record::pointer(); 00151 return it->second; 00152 } 00153 00154 00155 space_protocols::record::pointer 00156 space_protocols_slurp::query_by_number(const rcstring &key) 00157 const 00158 { 00159 long value = 0; 00160 if (!key.to_long(value)) 00161 return record::pointer(); 00162 if (value < INT_MIN || value > INT_MAX) 00163 return record::pointer(); 00164 return query_by_number(int(value)); 00165 } 00166 00167 00168 space_protocols::record::pointer 00169 space_protocols_slurp::query_by_number(int key) 00170 const 00171 { 00172 if (key < 0 || key >= 256) 00173 return record::pointer(); 00174 by_number_t::const_iterator it = by_number.find(key); 00175 if (it == by_number.end()) 00176 return record::pointer(); 00177 return it->second; 00178 } 00179 00180 00181 // vim: set ts=8 sw=4 et :