]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common: Change cleanbin() to use base64 encoding, update ceph-objectstore-tool
authorDavid Zafman <dzafman@redhat.com>
Tue, 30 Aug 2016 17:56:06 +0000 (10:56 -0700)
committerDavid Zafman <dzafman@redhat.com>
Tue, 8 Nov 2016 23:16:52 +0000 (15:16 -0800)
Signed-off-by: David Zafman <dzafman@redhat.com>
src/common/util.cc
src/include/util.h
src/tools/ceph_objectstore_tool.cc

index 5ab1e441a30b6fd7411b9f21bc47f68aeb173f91..73b457ff5419c8bfd09bfc2c7a2226daecb2fdd4 100644 (file)
@@ -268,25 +268,38 @@ void dump_services(Formatter* f, const map<string, list<int> >& services, const
   f->close_section();
 }
 
-// Convert non-printable characters to '\###'
-void cleanbin(string &str)
+
+// If non-printable characters found then convert bufferlist to
+// base64 encoded string indicating whether it did.
+string cleanbin(bufferlist &bl, bool &base64)
 {
-  bool cleaned = false;
-  string clean;
-
-  for (string::iterator it = str.begin(); it != str.end(); ++it) {
-    if (!isprint(*it)) {
-      clean.push_back('\\');
-      clean.push_back('0' + ((*it >> 6) & 7));
-      clean.push_back('0' + ((*it >> 3) & 7));
-      clean.push_back('0' + (*it & 7));
-      cleaned = true;
-    } else {
-      clean.push_back(*it);
-    }
+  bufferlist::iterator it;
+  for (it = bl.begin(); it != bl.end(); ++it) {
+    if (iscntrl(*it))
+      break;
+  }
+  if (it == bl.end()) {
+    base64 = false;
+    string result(bl.c_str(), bl.length());
+    return result;
   }
 
-  if (cleaned)
-    str = clean;
-  return;
+  bufferlist b64;
+  bl.encode_base64(b64);
+  string encoded(b64.c_str(), b64.length());
+  base64 = true;
+  return encoded;
+}
+
+// If non-printable characters found then convert to "Base64:" followed by
+// base64 encoding
+string cleanbin(string &str)
+{
+  bool base64;
+  bufferlist bl;
+  bl.append(str);
+  string result = cleanbin(bl, base64);
+  if (base64)
+    result = "Base64:" + result;
+  return result;
 }
index 6a85f1b894a17fe45560797376308cf63f972df1..b152c1130df9455684fcd4a82285bbfc705fb873 100644 (file)
@@ -82,5 +82,6 @@ void collect_sys_info(map<string, string> *m, CephContext *cct);
 /// @param type the service type of given @p services, for example @p osd or @p mon.
 void dump_services(Formatter* f, const map<string, list<int> >& services, const char* type);
 
-void cleanbin(string &str);
+string cleanbin(bufferlist &bl, bool &b64);
+string cleanbin(string &str);
 #endif /* CEPH_UTIL_H */
index b120fadc5960c372b53c0d0f4c066bf46039ff8c..e2636d202f43fe10f8609090703bc863383baabb 100644 (file)
@@ -1522,7 +1522,7 @@ int do_list_attrs(ObjectStore *store, coll_t coll, ghobject_t &ghobj)
   for (map<string,bufferptr>::iterator i = aset.begin();i != aset.end(); ++i) {
     string key(i->first);
     if (outistty)
-      cleanbin(key);
+      key = cleanbin(key);
     cout << key << std::endl;
   }
   return 0;
@@ -1543,7 +1543,7 @@ int do_list_omap(ObjectStore *store, coll_t coll, ghobject_t &ghobj)
     for (map<string,bufferlist>::iterator i = oset.begin();i != oset.end(); ++i) {
       string key(i->first);
       if (outistty)
-        cleanbin(key);
+        key = cleanbin(key);
       cout << key << std::endl;
     }
   }
@@ -1649,7 +1649,7 @@ int do_get_attr(ObjectStore *store, coll_t coll, ghobject_t &ghobj, string key)
 
   string value(bp.c_str(), bp.length());
   if (outistty) {
-    cleanbin(value);
+    value = cleanbin(value);
     value.push_back('\n');
   }
   cout << value;
@@ -1725,7 +1725,7 @@ int do_get_omap(ObjectStore *store, coll_t coll, ghobject_t &ghobj, string key)
   bufferlist bl = out.begin()->second;
   string value(bl.c_str(), bl.length());
   if (outistty) {
-    cleanbin(value);
+    value = cleanbin(value);
     value.push_back('\n');
   }
   cout << value;
@@ -1796,7 +1796,7 @@ int do_get_omaphdr(ObjectStore *store, coll_t coll, ghobject_t &ghobj)
 
   string header(hdrbl.c_str(), hdrbl.length());
   if (outistty) {
-    cleanbin(header);
+    header = cleanbin(header);
     header.push_back('\n');
   }
   cout << header;