00001 #ifndef _REVCONTROL_HH_
00002 #define _REVCONTROL_HH_
00003
00004 #include <vos/vos/vos.hh>
00005 #include <vos/extensions/fspersist/fspersist.hh>
00006 #include <vos/extensions/revcontrol/revdefs.hh>
00007 #include <vos/extensions/revcontrol/changelog.hh>
00008
00009 namespace VOS {
00010 class VERSIONED_API RevisionControlError : public std::runtime_error
00011 {
00012 public:
00013 RevisionControlError(const std::string& s) : std::runtime_error(s) { };
00014 };
00015
00016 class VERSIONED_API RevisionControlPersistance : public FileSystemPersistance
00017 {
00018 private:
00019 Site* site;
00020 ChangeLog* log;
00021
00022 void checkin(const char* path);
00023 void checkout(const char* path, const char* version = "");
00024 std::string readHeadRCSVersion(const std::string& path);
00025
00026 public:
00027 RevisionControlPersistance(const std::string& dbpath);
00028
00029 virtual void siteExtensionAttachedTo(Site* site);
00030
00031 virtual void post_createVobject(VobjectState& state, Vobject* requester, VobjectBase* newvobject);
00032 virtual void post_renameVobject(VobjectState& state, Vobject* requester,
00033 const std::string& oldname, const std::string& newname);
00034 virtual void post_addType(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00035 Vobject* requester, const std::string& s);
00036 virtual void post_removeType(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00037 Vobject* requester, const std::string& s);
00038 virtual void post_insertChild(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00039 Vobject* requester,
00040 int position, const std::string& contextual_name, Vobject* child);
00041 virtual void post_setChild(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00042 Vobject* requester,
00043 int position, const std::string& contextual_name, Vobject* child,
00044 const std::string& oldcontextual_name, Vobject* oldchild);
00045 virtual void post_removeChild(VobjectState& state, boost::recursive_mutex::scoped_lock& state_lock,
00046 Vobject* requester,
00047 ParentChildRelation* pcr,
00048 bool strict);
00049 virtual void post_addToACL(AccessControlState* acs, Vobject* requester, const std::string& ACLname, Vobject* id,
00050 const std::string& oldACLname);
00051 virtual void post_removeFromACL(AccessControlState* acs, Vobject* requester,
00052 const std::string& ACLname, Vobject* id);
00053 virtual void post_deleteACL(AccessControlState* acs, Vobject* requester,
00054 const std::string& policies, AccessControlList* oldacl);
00055 virtual void post_setDefaultPolicy(AccessControlState* acs, Vobject* requester,
00056 const std::string& policy,
00057 const std::string& oldpolicy);
00058
00059 virtual void wipeDatabase();
00060
00061 virtual bool storeBlock(Vobject* from, const std::string& key, const std::string& data);
00062 virtual bool getBlock(Vobject* from, const std::string& key, std::string& data);
00063 virtual bool getBlockAtVersion(Vobject* from, const std::string& key,
00064 int version, std::string& data);
00065
00066 std::string readHeadVersion(Vobject* from, const std::string& file);
00067
00068 std::string getDefaultPolicyAtVersion(Vobject* vobj, unsigned int ver);
00069 std::string getACLsAtVersion(Vobject* vobj, unsigned int ver);
00070 std::string getChildrenAtVersion(Vobject* vobj, unsigned int ver);
00071 std::string getTypesAtVersion(Vobject* vobj, unsigned int ver);
00072
00073 void findChangedVobjects(int startVer, int updateVer,
00074 std::map< std::string, std::set<std::string> >& dirty,
00075 Message* reply);
00076
00077 void handleFetchVersionRequest(Message* m);
00078 void handleCommitRequest(Message* m);
00079 void handleSetTagRequest(Message* m);
00080
00081 typedef enum { AddTag, Commit, FetchVersion} RevControlAccessType;
00082
00083 bool validateRepositoryAccess(Vobject* requester, RevControlAccessType at, std::string& message);
00084 };
00085
00086 class RevControlAccess
00087 {
00088 public:
00089 virtual ~RevControlAccess()
00090 { }
00091
00092 virtual const std::string getPolicyName() = 0;
00093
00094 virtual bool checkAddTagPermission(Vobject* requester, std::string& message) = 0;
00095 virtual bool checkCommitPermission(Vobject* requester, std::string& message) = 0;
00096 virtual bool checkFetchVersionPermission(Vobject* requester, std::string& message) = 0;
00097 };
00098
00099 class ReadOnlyRevControlAccess : public RevControlAccess
00100 {
00101 public:
00102 static ReadOnlyRevControlAccess static_;
00103
00104 virtual ~ReadOnlyRevControlAccess() { }
00105
00106 virtual const std::string getPolicyName()
00107 { return "revcontrol:read-only"; }
00108
00109 virtual bool checkAddTagPermission(Vobject* requester, std::string& message)
00110 { return false; }
00111 virtual bool checkCommitPermission(Vobject* requester, std::string& message)
00112 { return false; }
00113 virtual bool checkFetchVersionPermission(Vobject* requester, std::string& message)
00114 { return true; }
00115 };
00116
00117 class AcceptAllRevControlAccess : public RevControlAccess
00118 {
00119 public:
00120 static AcceptAllRevControlAccess static_;
00121
00122 virtual ~AcceptAllRevControlAccess() { }
00123
00124 virtual const std::string getPolicyName()
00125 { return "revcontrol:accept-all"; }
00126
00127 virtual bool checkAddTagPermission(Vobject* requester, std::string& message)
00128 { return true; }
00129 virtual bool checkCommitPermission(Vobject* requester, std::string& message)
00130 { return true; }
00131 virtual bool checkFetchVersionPermission(Vobject* requester, std::string& message)
00132 { return true; }
00133 };
00134
00135 class DenyAllRevControlAccess : public RevControlAccess
00136 {
00137 public:
00138 static DenyAllRevControlAccess static_;
00139
00140 virtual ~DenyAllRevControlAccess() { }
00141
00142 virtual const std::string getPolicyName()
00143 { return "revcontrol:deny-all"; }
00144
00145 virtual bool checkAddTagPermission(Vobject* requester, std::string& message)
00146 { return false; }
00147 virtual bool checkCommitPermission(Vobject* requester, std::string& message)
00148 { return false; }
00149 virtual bool checkFetchVersionPermission(Vobject* requester, std::string& message)
00150 { return false; }
00151 };
00152 }
00153
00154 #endif