# # # patch "cmd_policy.cc" # from [5f5db2161539493e77190e965adb7b08cb30ace9] # to [590363a44896e8e6a84ce26b96e40dbdacafc072] # # patch "lua_hooks.hh" # from [5a4ca50e4f51c3094ee78c3b3abefbd4fcfa100f] # to [a9a96d4e75128cfc2b2e57810b7ef9152d6a15ad] # # patch "policies/base_policy.cc" # from [bd4d5d8b816f72573927c8b3181fcb318cb7cd1f] # to [daaf24d8ed1627929a264e8a687e62e83b0807ad] # # patch "policies/base_policy.hh" # from [a39d323843f43fa9f449d4af360e3bd1afed9944] # to [84e52ef58478b40d3f33f5c58871b8e97cc45c89] # # patch "policies/branch.cc" # from [5b6b0d65bf8419f2961f228f9e3cc42ade0ba9f4] # to [2f714e3b01abd133ed7e01e13630ee755ec9b6d0] # ============================================================ --- cmd_policy.cc 5f5db2161539493e77190e965adb7b08cb30ace9 +++ cmd_policy.cc 590363a44896e8e6a84ce26b96e40dbdacafc072 @@ -75,7 +75,7 @@ CMD(create_project, "create_project", "" bp.set_delegation(project_name, policies::delegation::create(app, signers)); - policies::base_policy::write(bp); + policies::base_policy::write(app.lua, bp); } CMD(create_subpolicy, "create_subpolicy", "", CMD_REF(policy), ============================================================ --- lua_hooks.hh 5a4ca50e4f51c3094ee78c3b3abefbd4fcfa100f +++ lua_hooks.hh a9a96d4e75128cfc2b2e57810b7ef9152d6a15ad @@ -78,6 +78,7 @@ public: bool hook_get_projects(std::map & project_definitions); + bool hook_write_projects(std::map const & project_definitions); // network hooks ============================================================ --- policies/base_policy.cc bd4d5d8b816f72573927c8b3181fcb318cb7cd1f +++ policies/base_policy.cc daaf24d8ed1627929a264e8a687e62e83b0807ad @@ -35,6 +35,7 @@ namespace policies { { return _empty; } + void base_policy::load(database & db, options const & opts, lua_hooks & lua) { typedef map > override_map; @@ -61,6 +62,22 @@ namespace policies { } } } + + void base_policy::write(lua_hooks & lua, policy const & pol) + { + map hm; + + policy::del_map const & delegations = pol.list_delegations(); + for (policy::del_map::const_iterator d = delegations.begin(); + d != delegations.end(); ++d) + { + string s; + d->second.serialize(s); + hm.insert(make_pair(d->first, data(s, origin::internal))); + } + + lua.hook_write_projects(hm); + } } // Local Variables: ============================================================ --- policies/base_policy.hh a39d323843f43fa9f449d4af360e3bd1afed9944 +++ policies/base_policy.hh 84e52ef58478b40d3f33f5c58871b8e97cc45c89 @@ -29,7 +29,7 @@ namespace policies { inline bool outdated() const { return false; } // Use lua hooks to write out the given policy. - static void write(policy const & pol); + static void write(lua_hooks & lua, policy const & pol); }; } ============================================================ --- policies/branch.cc 5b6b0d65bf8419f2961f228f9e3cc42ade0ba9f4 +++ policies/branch.cc 2f714e3b01abd133ed7e01e13630ee755ec9b6d0 @@ -12,9 +12,19 @@ #include "policies/branch.hh" #include "app_state.hh" +#include "basic_io.hh" #include "lazy_rng.hh" #include "transforms.hh" +using std::string; + +namespace basic_io { + namespace syms { + static symbol branch_uid("branch_uid"); + static symbol key("key"); + } +} + namespace { branch_uid generate_uid(app_state & app) { @@ -45,6 +55,47 @@ namespace policies { { return signers; } + + void branch::serialize(std::string & out) const + { + basic_io::printer p; + basic_io::stanza s; + + s.push_str_pair(basic_io::syms::branch_uid, uid()); + for (std::set::const_iterator k = signers.begin(); + k != signers.end(); ++k) + { + s.push_str_pair(basic_io::syms::key, (*k)()); + } + + p.print_stanza(s); + out = p.buf; + } + void branch::deserialize(std::string const & in) + { + basic_io::input_source s(in, "branch"); + basic_io::tokenizer t(s); + basic_io::parser p(t); + while (p.symp()) + { + if (p.symp(basic_io::syms::branch_uid)) + { + p.sym(); + string u; + p.str(u); + uid = branch_uid(u, origin::internal); + } + else if (p.symp(basic_io::syms::key)) + { + p.sym(); + string k; + p.str(k); + signers.insert(external_key_name(k, origin::internal)); + } + else + break; + } + } } // Local Variables: