]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: move url escaping to a common place
authorJosh Durgin <josh.durgin@inktank.com>
Thu, 24 Oct 2013 15:37:25 +0000 (08:37 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Fri, 1 Nov 2013 23:17:30 +0000 (16:17 -0700)
This is useful outside of the s3 interface. Rename url_escape()
url_encode() for consistency with the exsting common url_decode()
function. This is in preparation for the next commit, which needs
to escape url-unsafe characters in another place.

Backport: dumpling
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
(cherry picked from commit dd308cd481b368f90a64220847b91fc233d92a59)

src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_rest_s3.cc

index 28a99b504d2c81c03d04adbe19e4e4684771829d..fb204c75d941a0c876c307aef1b12efcca9d3594 100644 (file)
@@ -708,6 +708,59 @@ bool url_decode(string& src_str, string& dest_str)
   return true;
 }
 
+static void escape_char(char c, string& dst)
+{
+  char buf[16];
+  snprintf(buf, sizeof(buf), "%%%.2X", (unsigned int)c);
+  dst.append(buf);
+}
+
+static bool char_needs_url_encoding(char c)
+{
+  if (c < 0x20 || c >= 0x7f)
+    return true;
+
+  switch (c) {
+    case 0x20:
+    case 0x22:
+    case 0x23:
+    case 0x25:
+    case 0x26:
+    case 0x2B:
+    case 0x2C:
+    case 0x2F:
+    case 0x3A:
+    case 0x3B:
+    case 0x3C:
+    case 0x3E:
+    case 0x3D:
+    case 0x3F:
+    case 0x40:
+    case 0x5B:
+    case 0x5D:
+    case 0x5C:
+    case 0x5E:
+    case 0x60:
+    case 0x7B:
+    case 0x7D:
+      return true;
+  }
+  return false;
+}
+
+void url_encode(const string& src, string& dst)
+{
+  const char *p = src.c_str();
+  for (unsigned i = 0; i < src.size(); i++, p++) {
+    if (char_needs_url_encoding(*p)) {
+      escape_char(*p, dst);
+      continue;
+    }
+
+    dst.append(p, 1);
+  }
+}
+
 string rgw_trim_whitespace(const string& src)
 {
   if (src.empty()) {
index eb5fe76e6cb6458f30c22a28bf4187aeefe1383e..3368e9756154df446eaff2afa2e2a9cd5cbfa3f1 100644 (file)
@@ -1233,6 +1233,7 @@ extern bool verify_object_permission(struct req_state *s, int perm);
 /** Convert an input URL into a sane object name
  * by converting %-escaped strings into characters, etc*/
 extern bool url_decode(string& src_str, string& dest_str);
+extern void url_encode(const string& src, string& dst);
 
 extern void calc_hmac_sha1(const char *key, int key_len,
                           const char *msg, int msg_len, char *dest);
index 913866e3996e714a9483fbc024e37f343c74d644..cdf802b130499d55d3b5f1baccf2589d2c355c69 100644 (file)
@@ -1085,59 +1085,6 @@ int RGWPostObj_ObjStore_S3::get_data(bufferlist& bl)
   return bl.length();
 }
 
-static void escape_char(char c, string& dst)
-{
-  char buf[16];
-  snprintf(buf, sizeof(buf), "%%%.2X", (unsigned int)c);
-  dst.append(buf);
-}
-
-static bool char_needs_url_encoding(char c)
-{
-  if (c < 0x20 || c >= 0x7f)
-    return true;
-
-  switch (c) {
-    case 0x20:
-    case 0x22:
-    case 0x23:
-    case 0x25:
-    case 0x26:
-    case 0x2B:
-    case 0x2C:
-    case 0x2F:
-    case 0x3A:
-    case 0x3B:
-    case 0x3C:
-    case 0x3E:
-    case 0x3D:
-    case 0x3F:
-    case 0x40:
-    case 0x5B:
-    case 0x5D:
-    case 0x5C:
-    case 0x5E:
-    case 0x60:
-    case 0x7B:
-    case 0x7D:
-      return true;
-  }
-  return false;
-}
-
-static void url_escape(const string& src, string& dst)
-{
-  const char *p = src.c_str();
-  for (unsigned i = 0; i < src.size(); i++, p++) {
-    if (char_needs_url_encoding(*p)) {
-      escape_char(*p, dst);
-      continue;
-    }
-
-    dst.append(p, 1);
-  }
-}
-
 void RGWPostObj_ObjStore_S3::send_response()
 {
   if (ret == 0 && parts.count("success_action_redirect")) {
@@ -1154,11 +1101,10 @@ void RGWPostObj_ObjStore_S3::send_response()
 
     string etag_url;
 
-    url_escape(s->bucket_name, bucket);
-    url_escape(s->object_str, key);
-    url_escape(etag_str, etag_url);
+    url_encode(s->bucket_name, bucket);
+    url_encode(s->object_str, key);
+    url_encode(etag_str, etag_url);
 
-    
     redirect.append("?bucket=");
     redirect.append(bucket);
     redirect.append("&key=");