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/space/protocols/slurp.h> 00020 #include <lib/space/services/slurp.h> 00021 00022 00023 space_services_slurp::~space_services_slurp() 00024 { 00025 } 00026 00027 00028 space_services_slurp::space_services_slurp( 00029 const rcstring &a_filename, 00030 const space_protocols_slurp::pointer &a_protocols 00031 ) : 00032 space_services(a_filename), 00033 protocols(a_protocols) 00034 { 00035 } 00036 00037 00038 space_services_slurp::pointer 00039 space_services_slurp::create(const rcstring &a_filename, 00040 const space_protocols_slurp::pointer &a_protocols) 00041 { 00042 return pointer(new space_services_slurp(a_filename, a_protocols)); 00043 } 00044 00045 00046 void 00047 space_services_slurp::process(const record::pointer &rp) 00048 { 00049 // 00050 // Check the name 00051 // 00052 { 00053 rcstring tmp = rp->get_name() + "/" + rp->get_protocol(); 00054 by_name_t::iterator it = by_name.find(tmp); 00055 if (it != by_name.end()) 00056 { 00057 error 00058 ( 00059 rp->get_source_location(), 00060 "duplicate %s service name...", 00061 tmp.quote_c().c_str() 00062 ); 00063 error 00064 ( 00065 it->second->get_source_location(), 00066 "... here is the first %s service name", 00067 tmp.quote_c().c_str() 00068 ); 00069 } 00070 else 00071 { 00072 by_name.insert(by_name_t::value_type(tmp, rp)); 00073 } 00074 } 00075 00076 // 00077 // Check the number 00078 // 00079 { 00080 rcstring tmp = rp->get_port() + "/" + rp->get_protocol(); 00081 by_number_t::iterator it = by_number.find(tmp); 00082 if (it != by_number.end()) 00083 { 00084 error 00085 ( 00086 rp->get_source_location(), 00087 "duplicate %s service number...", 00088 tmp.c_str() 00089 ); 00090 error 00091 ( 00092 it->second->get_source_location(), 00093 "... here is the first %s service number", 00094 tmp.c_str() 00095 ); 00096 } 00097 else 00098 { 00099 by_number.insert(by_number_t::value_type(tmp, rp)); 00100 } 00101 } 00102 00103 // 00104 // Check the protocol. 00105 // 00106 if (!protocols->query_by_name(rp->get_protocol())) 00107 { 00108 error 00109 ( 00110 rp->get_source_location(), 00111 "protocol %s is not defined in the protocols map", 00112 rp->get_protocol().quote_c().c_str() 00113 ); 00114 } 00115 00116 // 00117 // Check the aliases 00118 // 00119 const record::aliases_t &aliases = rp->get_aliases(); 00120 for 00121 ( 00122 record::aliases_t::const_iterator it = aliases.begin(); 00123 it != aliases.end(); 00124 ++it 00125 ) 00126 { 00127 rcstring tmp = *it + "/" + rp->get_protocol(); 00128 by_name_t::iterator bnit = by_name.find(tmp); 00129 if (bnit != by_name.end()) 00130 { 00131 error 00132 ( 00133 rp->get_source_location(), 00134 "duplicate %s service name...", 00135 tmp.quote_c().c_str() 00136 ); 00137 error 00138 ( 00139 bnit->second->get_source_location(), 00140 "... here is the first %s service name", 00141 tmp.quote_c().c_str() 00142 ); 00143 } 00144 else 00145 { 00146 by_number.insert(by_number_t::value_type(tmp, rp)); 00147 } 00148 } 00149 } 00150 00151 00152 void 00153 space_services_slurp::read_and_process(void) 00154 { 00155 for (;;) 00156 { 00157 space_services::record::pointer rp = get(); 00158 if (!rp) 00159 break; 00160 process(rp); 00161 } 00162 close(); 00163 } 00164 00165 00166 // vim: set ts=8 sw=4 et :