]> git-server-git.apps.pok.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>
Thu, 24 Oct 2013 15:58:48 +0000 (08:58 -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>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_rest_s3.cc

index 0b2d003599220a054d9050477fa017091a0458d3..e51b08889cb96278bce4eba09837aafcd861cc43 100644 (file)
@@ -705,6 +705,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 b3d39e57c2d0c0129556358faa7f9cc024e3bb73..a7ef250b7d8d345a70689ae53e5267727f7c3e7d 100644 (file)
@@ -1257,6 +1257,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 8ea21d452e6f5f24b41c222cda4ec6640f07b780..12bd377d8a0647a6391ebce4e4fede041abdeaea 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_str, bucket);
-    url_escape(s->object_str, key);
-    url_escape(etag_str, etag_url);
+    url_encode(s->bucket_name_str, bucket);
+    url_encode(s->object_str, key);
+    url_encode(etag_str, etag_url);
 
-    
     redirect.append("?bucket=");
     redirect.append(bucket);
     redirect.append("&key=");