Pagina Principale   Moduli   Lista dei namespaces   Gerarchia delle classi   Lista in ordine alfabetico   Lista dei composti   Lista dei files   Membri dei namespaces   Membri dei composti   Membri dei files   Esempi  

/home/fbassi/devel/projects/reti/NameServer/NameServer_i.cc

Vai alla documentazione di questo file.
00001 /*
00002  *    FBFS Distributed Object Repository
00003  *    Copyright (C) 2001 Francesco V. Bassi
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
00008  *    (at 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
00013  *    GNU 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, write to the Free Software
00017  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00025 #include "NameServer_i.h"
00026 
00027 #include <fstream.h>
00028 
00029 using namespace fbfs;
00030 using namespace utils;
00031 
00032 fbfs::NameServer_i::NameServer_i(Prefs &p, const CORBA::ORB_ptr &o) : prefs(p), orb(o) {
00033     string rulefile = p.get("rulefile","nameserver-rules");
00034 
00035     ifstream::ifstream s;
00036     s.open(rulefile.c_str());
00037     char buf[80];
00038     while(!s.eof()) {
00039         s.getline(buf,80);
00040         string s(buf);
00041         if(s.find("#")==0 || s.length() < 3)
00042             continue;
00043         int level = 0;
00044         while(s[level++]==' ');
00045         level--;
00046         string line = s.substr(level,s.length()-level);
00047         int i;
00048         i = line.find(" ");
00049         string command = line.substr(0,i);
00050         line = line.substr(i+1,line.length()-i-1);
00051         i = line.find(" ");
00052         string arg = line.substr(0,i);
00053 
00054         Rule r(level, command, arg);
00055         rules.push_back(r);
00056     };
00057 };
00058     
00059 char *fbfs::NameServer_i::lookup(const Security &cert, const Obj_id &id)
00060             throw(NotFound, SecurityException, InternalError) {
00061     string name(id.name);
00062     string result;
00063     int level = 0;
00064     bool go_deeper = true;
00065     bool exit_now = false;
00066     vector<Rule>::iterator i;
00067     for(i=rules.begin(); i != rules.end(); i++) {
00068         if(i->level <= level || go_deeper) {
00069             level = i->level;
00070             switch( i->eval(name, result, orb) ) {
00071                 case Rule::FALSE:
00072                     go_deeper = false;
00073                     break;
00074                 case Rule::TRUE:
00075                     go_deeper = true;
00076                     break;
00077                 case Rule::OK:
00078                     return CORBA::string_dup(result.c_str());
00079                     break;
00080                 case Rule::NOTFOUND:
00081                     throw NotFound();
00082             };
00083         };
00084         if(exit_now)
00085             break;
00086     };
00087     throw NotFound();
00088 };

Generato il Thu Feb 15 13:24:56 2001 per A Simple Distributed Object Repository with CORBA & C++. da doxygen1.2.3 scritto da Dimitri van Heesch, © 1997-2000