00001 // Certificate implementation -*- C++ -*- 00002 00003 // $Id: api_certbase.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_CERTBASE_H_ 00032 #define _API_CERTBASE_H_ 00033 00034 #include <coconut_config.h> 00035 #include <string> 00036 #include <database> 00037 #include <api_debug.h> 00038 00039 namespace coco { 00040 00041 class work_node; 00042 00043 class certificate_base; 00044 00046 00054 class certificate 00055 { 00056 private: 00058 certificate_base* _c; 00059 00060 public: 00062 certificate() : _c(NULL) {} 00063 private: 00067 certificate(certificate_base* __c) : _c(__c) {} 00068 public: 00072 certificate(const certificate_base& __c); 00077 certificate(const certificate& __c); 00078 00080 ~certificate(); 00081 00084 std::string get_contents() const; 00086 const certificate_base* get_base() const; 00087 00090 bool verify(const work_node& _x) const; 00091 00095 certificate& operator=(const certificate& _c); 00096 00098 bool operator==(const certificate& _c) const; 00099 bool operator!=(const certificate& _c) const; 00100 00101 friend std::ostream& operator<< (std::ostream& o, const certificate& t); 00102 friend class certificate_base; 00103 friend class ie_return_type; 00104 }; 00105 00107 00112 inline std::ostream& operator<< (std::ostream& o, const certificate& t) 00113 { 00114 o << t.get_contents() << std::endl; 00115 return o; 00116 } 00117 00119 00124 class certificate_base 00125 { 00126 protected: 00128 std::string _contents; 00129 00130 public: 00132 certificate_base() : _contents() {} 00134 certificate_base(const std::string& c) : _contents(c) {} 00136 certificate_base(const char* c) : _contents(std::string(c)) {} 00138 certificate_base(const certificate_base& __c) : _contents(__c._contents) 00139 { 00140 #if DEBUG_CERTIFICATE 00141 std::cerr << "Called certificate_base copy constructor" << std::endl; 00142 #endif 00143 } 00144 00146 virtual certificate_base* new_copy() const PURE_VIRTUAL 00147 00149 virtual void destroy_copy(certificate_base* __c) const PURE_VIRTUAL 00150 00152 virtual ~certificate_base() {} 00153 00156 certificate make_certificate(const std::string& c) 00157 { 00158 certificate_base* __tmp(new_copy()); 00159 __tmp->_contents = c; 00160 return certificate(__tmp); 00161 } 00162 00165 virtual std::string get_contents() const { return _contents; } 00166 00169 virtual bool verify(const work_node& _x) const 00170 { return false; } 00171 00173 virtual bool operator==(const certificate_base& _c) const PURE_VIRTUAL 00174 virtual bool operator!=(const certificate_base& _c) const PURE_VIRTUAL 00175 }; 00176 00177 } // namespace coco 00178 00179 #endif /* _API_CERTBASE_H_ */