00001 // Certificate implementation -*- C++ -*- 00002 00003 // $Id: api_cert.h 631 2008-05-19 17:38:05Z mihaly $ 00004 // Copyright (C) 2001-2005 Hermann Schichl 00005 // 00006 // This file is part of the COCONUT API. This library 00007 // is free software; you can redistribute it and/or modify it under the 00008 // terms of the Library GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // Library GNU General Public License for more details. 00016 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the Library GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the Library GNU General Public License. 00025 00031 #ifndef _API_CERT_H_ 00032 #define _API_CERT_H_ 00033 00034 #include <api_certbase.h> 00035 #include <search_node.h> 00036 #include <dbtools.h> 00037 #include <db_method> 00038 00039 namespace coco { 00040 00041 inline certificate::certificate(const certificate_base& __c) 00042 { _c = __c.new_copy(); } 00043 inline certificate::certificate(const certificate& __c) 00044 { _c = __c._c->new_copy(); 00045 #if DEBUG_CERTIFICATE 00046 std::cerr << "Called certificate copy constructor" << std::endl; 00047 #endif 00048 } 00049 inline certificate::~certificate() 00050 { if(_c) delete _c; 00051 #if DEBUG_CERTIFICATE 00052 std::cerr << "Called certificate destructor" << std::endl; 00053 #endif 00054 } 00055 inline certificate& certificate::operator=(const certificate& __c) 00056 { 00057 if(_c) delete _c; 00058 _c = __c._c->new_copy(); 00059 #if DEBUG_CERTIFICATE 00060 std::cerr << "Called certificate assignment operator" << std::endl; 00061 #endif 00062 return *this; 00063 } 00064 00065 inline std::string certificate::get_contents() const 00066 { return _c->get_contents(); } 00067 inline const certificate_base* certificate::get_base() const { return _c; } 00068 00069 inline bool certificate::verify(const work_node& _x) const 00070 { return _c->verify(_x); } 00071 inline bool certificate::operator==(const certificate& _t) const 00072 { return _c->get_contents() == _t._c->get_contents() 00073 && _c->operator==(*_t._c); } 00074 inline bool certificate::operator!=(const certificate& _t) const 00075 { return _c->get_contents() != _t._c->get_contents() 00076 || _c->operator!=(*_t._c); } 00077 00079 00084 class no_certificate : public certificate_base 00085 { 00086 public: 00088 no_certificate() : certificate_base("not certified") {} 00090 no_certificate(const no_certificate& __c) : certificate_base(__c) 00091 { 00092 #if DEBUG_CERTIFICATE 00093 std::cerr << "Called no_certificate copy constructor" << std::endl; 00094 #endif 00095 } 00096 00098 virtual ~no_certificate() {} 00099 00101 no_certificate* new_copy() const 00102 { 00103 #if DEBUG_CERTIFICATE 00104 std::cerr << "Called no_certificate new_copy" << std::endl; 00105 #endif 00106 return new no_certificate(*this); 00107 } 00109 void destroy_copy(certificate_base* __c) const 00110 { delete (no_certificate*)__c; } 00111 00114 bool verify(const work_node& _x) const { return false; } 00115 00117 bool operator==(const certificate_base& _c) const 00118 { return _c.get_contents() == get_contents() && 00119 this->operator==(*(no_certificate*)&_c); } 00120 bool operator!=(const certificate_base& _c) const 00121 { return _c.get_contents() != get_contents() || 00122 this->operator!=(*(no_certificate*)&_c); } 00123 00125 bool operator==(const no_certificate& _c) const {return true; } 00126 bool operator!=(const no_certificate& _c) const {return false; } 00127 }; 00128 00130 00134 class split_certificate : public certificate_base 00135 { 00137 std::string module_name; 00138 00139 public: 00141 split_certificate() 00142 : certificate_base("split"), module_name() {} 00144 split_certificate(const std::string& mn) 00145 : certificate_base("split"), module_name(mn) {} 00147 split_certificate(const split_certificate& __c) 00148 : certificate_base(__c), module_name(__c.module_name) 00149 { 00150 #if DEBUG_CERTIFICATE 00151 std::cerr << "Called split_certificate copy constructor" << std::endl; 00152 #endif 00153 } 00154 00156 virtual ~split_certificate() {} 00157 00159 split_certificate* new_copy() const 00160 { 00161 #if DEBUG_CERTIFICATE 00162 std::cerr << "Called split_certificate new_copy" << std::endl; 00163 #endif 00164 return new split_certificate(*this); 00165 } 00167 void destroy_copy(certificate_base* __c) const 00168 { delete (split_certificate*)__c; } 00169 00172 bool verify(const work_node& _x) const { return true; } 00173 00177 std::string get_contents() const 00178 { return this->_contents+"("+module_name+")"; } 00179 00181 bool operator==(const certificate_base& _c) const 00182 { return _c.get_contents() == get_contents() && 00183 this->operator==(*(split_certificate*)&_c); } 00184 bool operator!=(const certificate_base& _c) const 00185 { return _c.get_contents() != get_contents() || 00186 this->operator!=(*(split_certificate*)&_c); } 00187 00189 bool operator==(const split_certificate& _c) const 00190 {return module_name == _c.module_name; } 00191 bool operator!=(const split_certificate& _c) const 00192 {return module_name != _c.module_name; } 00193 }; 00194 00196 00201 class compound_certificate : public certificate_base 00202 { 00203 private: 00206 bool is_verified; 00207 00208 public: 00210 compound_certificate(bool verified) 00211 : certificate_base("compound"), is_verified(verified) {} 00213 compound_certificate(const compound_certificate& __c) 00214 : certificate_base(__c), is_verified(__c.is_verified) 00215 { 00216 #if DEBUG_CERTIFICATE 00217 std::cerr << "Called compound_certificate copy constructor" << std::endl; 00218 #endif 00219 } 00220 00222 virtual ~compound_certificate() {} 00223 00225 compound_certificate* new_copy() const 00226 { 00227 #if DEBUG_CERTIFICATE 00228 std::cerr << "Called compound_certificate new_copy" << std::endl; 00229 #endif 00230 return new compound_certificate(*this); 00231 } 00233 void destroy_copy(certificate_base* __c) const 00234 { delete (compound_certificate*)__c; } 00235 00239 bool verify(const work_node& _x) const { return is_verified; } 00240 00242 bool operator==(const certificate_base& _c) const 00243 { return _c.get_contents() == get_contents() && 00244 this->operator==(*(compound_certificate*)&_c); } 00245 bool operator!=(const certificate_base& _c) const 00246 { return _c.get_contents() != get_contents() || 00247 this->operator!=(*(compound_certificate*)&_c); } 00248 00250 bool operator==(const compound_certificate& _c) const 00251 {return is_verified == _c.is_verified; } 00252 bool operator!=(const compound_certificate& _c) const 00253 {return is_verified != _c.is_verified; } 00254 }; 00255 00257 00262 class rigorous_module_certificate : public certificate_base 00263 { 00264 private: 00266 std::string module_name; 00267 00268 public: 00270 rigorous_module_certificate(const std::string& _name) 00271 : certificate_base("rigorous module"), module_name(_name) {} 00273 rigorous_module_certificate(const rigorous_module_certificate& __c) 00274 : certificate_base(__c), module_name(__c.module_name) 00275 { 00276 #if DEBUG_CERTIFICATE 00277 std::cerr << "Called rigorous_module_certificate copy constructor" << std::endl; 00278 #endif 00279 } 00280 00282 virtual ~rigorous_module_certificate() {} 00283 00285 rigorous_module_certificate* new_copy() const 00286 { 00287 #if DEBUG_CERTIFICATE 00288 std::cerr << "Called rigorous_module_certificate new_copy" << std::endl; 00289 #endif 00290 return new rigorous_module_certificate(*this); 00291 } 00293 void destroy_copy(certificate_base* __c) const 00294 { delete (rigorous_module_certificate*)__c; } 00295 00298 bool verify(const work_node& _x) const { return true; } 00299 00303 std::string get_contents() const 00304 { return this->_contents+" "+module_name; } 00305 00307 bool operator==(const certificate_base& _c) const 00308 { return _c.get_contents() == get_contents() && 00309 this->operator==(*(rigorous_module_certificate*)&_c); } 00310 bool operator!=(const certificate_base& _c) const 00311 { return _c.get_contents() != get_contents() || 00312 this->operator!=(*(rigorous_module_certificate*)&_c); } 00313 00315 bool operator==(const rigorous_module_certificate& _c) const 00316 {return module_name == _c.module_name; } 00317 bool operator!=(const rigorous_module_certificate& _c) const 00318 {return module_name != _c.module_name; } 00319 }; 00320 00321 } // namespace coco 00322 00323 #endif /* _API_CERT_H_ */