From d1a755597ca2bd57a5a64b9815e583ff7ae68948 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Thu, 23 Jun 2011 15:26:08 -0700 Subject: [PATCH] librgw: eliminate globals Signed-off-by: Colin McCabe --- src/Makefile.am | 6 ++++++ src/rgw/librgw.cc | 2 +- src/rgw/rgw_acl.cc | 21 +++++++++------------ src/rgw/rgw_acl.h | 4 ++-- src/rgw/rgw_aclparser.cc | 12 +++++------- src/rgw/rgw_common.cc | 2 +- src/rgw/rgw_common.h | 1 + src/rgw/rgw_xml.cc | 1 - src/test/librgw.cc | 2 -- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b24db2a21397c..8e5d607ecb832 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -185,6 +185,12 @@ test_librados_build_LDADD = -lpthread -lm $(CRYPTO_LIBS) $(EXTRALIBS) test_librados_build_CXXFLAGS = $(AM_CXXFLAGS) bin_DEBUGPROGRAMS += test_librados_build +test_librgw_build_SOURCES = test/test_libcommon_build.cc $(libcommon_files) \ + $(librados_SOURCES) $(librgw_la_SOURCES) +test_librgw_build_LDADD = -lexpat -lpthread -lm $(CRYPTO_LIBS) $(EXTRALIBS) +test_librgw_build_CXXFLAGS = $(AM_CXXFLAGS) +bin_DEBUGPROGRAMS += test_librgw_build + ########## BUILT_SOURCES = lib_LTLIBRARIES = diff --git a/src/rgw/librgw.cc b/src/rgw/librgw.cc index 0ec6331cfe8aa..5f5bad9579039 100644 --- a/src/rgw/librgw.cc +++ b/src/rgw/librgw.cc @@ -128,5 +128,5 @@ void librgw_free_bin(librgw_t rgw, char *bin) void librgw_shutdown(librgw_t rgw) { - common_init_finish(rgw); + common_destroy_context(rgw); } diff --git a/src/rgw/rgw_acl.cc b/src/rgw/rgw_acl.cc index 0189d347eadb4..31a73ec641073 100644 --- a/src/rgw/rgw_acl.cc +++ b/src/rgw/rgw_acl.cc @@ -245,21 +245,18 @@ bool ACLGrant::xml_end(const char *el) { acl_name = (ACLDisplayName *)acl_grantee->find_first("DisplayName"); if (acl_name) name = acl_name->get_data(); - RGW_LOG(15) << "[" << *acl_grantee << ", " << permission << ", " << id << ", " << "]" << dendl; break; case ACL_TYPE_GROUP: acl_uri = (ACLURI *)acl_grantee->find_first("URI"); if (!acl_uri) return false; uri = acl_uri->get_data(); - RGW_LOG(15) << "[" << *acl_grantee << ", " << permission << ", " << uri << "]" << dendl; break; case ACL_TYPE_EMAIL_USER: acl_email = (ACLEmail *)acl_grantee->find_first("EmailAddress"); if (!acl_email) return false; email = acl_email->get_data(); - RGW_LOG(15) << "[" << *acl_grantee << ", " << permission << ", " << email << "]" << dendl; break; default: // unknown user type @@ -309,16 +306,16 @@ bool RGWAccessControlList::xml_end(const char *el) { return true; } -int RGWAccessControlList::get_perm(string& id, int perm_mask) { - RGW_LOG(5) << "Searching permissions for uid=" << id << " mask=" << perm_mask << dendl; +int RGWAccessControlList::get_perm(CephContext *cct, string& id, int perm_mask) { + ldout(cct, 5) << "Searching permissions for uid=" << id << " mask=" << perm_mask << dendl; if (!user_map_initialized) init_user_map(); map::iterator iter = acl_user_map.find(id); if (iter != acl_user_map.end()) { - RGW_LOG(5) << "Found permission: " << iter->second << dendl; + LRGW_LOG(cct, 5) << "Found permission: " << iter->second << dendl; return iter->second & perm_mask; } - RGW_LOG(5) << "Permissions for user not found" << dendl; + LRGW_LOG(cct, 5) << "Permissions for user not found" << dendl; return 0; } @@ -380,8 +377,8 @@ bool RGWAccessControlPolicy::xml_end(const char *el) { return true; } -int RGWAccessControlPolicy::get_perm(string& id, int perm_mask) { - int perm = acl.get_perm(id, perm_mask); +int RGWAccessControlPolicy::get_perm(CephContext *cct, string& id, int perm_mask) { + int perm = acl.get_perm(cct, id, perm_mask); if (perm == perm_mask) return perm; @@ -396,15 +393,15 @@ int RGWAccessControlPolicy::get_perm(string& id, int perm_mask) { /* should we continue looking up? */ if ((perm & perm_mask) != perm_mask) { - perm |= acl.get_perm(rgw_uri_all_users, perm_mask); + perm |= acl.get_perm(cct, rgw_uri_all_users, perm_mask); if (id.compare(RGW_USER_ANON_ID)) { /* this is not the anonymous user */ - perm |= acl.get_perm(rgw_uri_auth_users, perm_mask); + perm |= acl.get_perm(cct, rgw_uri_auth_users, perm_mask); } } - RGW_LOG(5) << "Getting permissions id=" << id << " owner=" << owner << " perm=" << perm << dendl; + LRGW_LOG(cct, 5) << "Getting permissions id=" << id << " owner=" << owner << " perm=" << perm << dendl; return perm; } diff --git a/src/rgw/rgw_acl.h b/src/rgw/rgw_acl.h index 73ed11927ba66..424d8487b735d 100644 --- a/src/rgw/rgw_acl.h +++ b/src/rgw/rgw_acl.h @@ -188,7 +188,7 @@ public: ~RGWAccessControlList(); bool xml_end(const char *el); - int get_perm(string& id, int perm_mask); + int get_perm(CephContext *cct, string& id, int perm_mask); void encode(bufferlist& bl) const { __u8 struct_v = 1; ::encode(struct_v, bl); @@ -274,7 +274,7 @@ public: bool xml_end(const char *el); - int get_perm(string& id, int perm_mask); + int get_perm(CephContext *cct, string& id, int perm_mask); void encode(bufferlist& bl) const { __u8 struct_v = 1; diff --git a/src/rgw/rgw_aclparser.cc b/src/rgw/rgw_aclparser.cc index 54f8c73d191e6..bfae7023ca281 100644 --- a/src/rgw/rgw_aclparser.cc +++ b/src/rgw/rgw_aclparser.cc @@ -1,14 +1,12 @@ #include -#include -#include - +#include "common/ceph_context.h" #include "include/types.h" +#include "rgw/rgw_acl.h" -#include "rgw_acl.h" +#include +#include -using namespace std; - int main(int argc, char **argv) { RGWACLXMLParser parser; @@ -38,7 +36,7 @@ int main(int argc, char **argv) { if (policy) { string id="79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be"; - cout << hex << policy->get_perm(id, RGW_PERM_ALL) << dec << endl; + cout << hex << policy->get_perm(g_ceph_context, id, RGW_PERM_ALL) << dec << endl; policy->to_xml(cout); } diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index de0073d27fd9c..2fe42d285c212 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -216,7 +216,7 @@ bool verify_permission(RGWAccessControlPolicy *policy, string& uid, int user_per if (!policy) return false; - int acl_perm = policy->get_perm(uid, perm) & user_perm_mask; + int acl_perm = policy->get_perm(g_ceph_context, uid, perm) & user_perm_mask; return (perm == acl_perm); } diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index c498395509edf..5e038e5323de3 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -51,6 +51,7 @@ extern string rgw_root_bucket; #define RGW_LOG_BEGIN "RADOS S3 Gateway:" #define RGW_LOG(x) pdout(x, g_conf->rgw_log) +#define LRGW_LOG(cct, x) lpdout(cct, x, cct->_conf->rgw_log) #define RGW_FORMAT_XML 1 #define RGW_FORMAT_JSON 2 diff --git a/src/rgw/rgw_xml.cc b/src/rgw/rgw_xml.cc index 7a64690737b17..c96e91bbe677a 100644 --- a/src/rgw/rgw_xml.cc +++ b/src/rgw/rgw_xml.cc @@ -194,7 +194,6 @@ bool RGWXMLParser::init() { p = XML_ParserCreate(NULL); if (!p) { - RGW_LOG(10) << "RGWXMLParser::init(): ERROR allocating memory" << dendl; return false; } XML_SetElementHandler(p, ::xml_start, ::xml_end); diff --git a/src/test/librgw.cc b/src/test/librgw.cc index 24aa52c709bbd..5a360a7b4100b 100644 --- a/src/test/librgw.cc +++ b/src/test/librgw.cc @@ -18,7 +18,6 @@ #include -/* static const char SAMPLE_XML_1[] = \ "\n\ \n\ @@ -102,4 +101,3 @@ TEST(LibRGW, RoundTrip) { librgw_shutdown(rgw); } -*/ -- 2.39.5