]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Formatter.cc: use common/escape.h
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 1 Aug 2011 18:14:55 +0000 (11:14 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 1 Aug 2011 18:24:04 +0000 (11:24 -0700)
* Rename rgw/rgw_escape.h to common/escape.h

* Use escape.h in common/Formatter.cc

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/Makefile.am
src/common/Formatter.cc
src/common/Formatter.h
src/common/escape.c [new file with mode: 0644]
src/common/escape.h [new file with mode: 0644]
src/os/FileStore.cc
src/rgw/rgw_escape.c [deleted file]
src/rgw/rgw_escape.h [deleted file]
src/rgw/rgw_formats.cc
src/test/escape.cc [new file with mode: 0644]
src/test/rgw_escape.cc [deleted file]

index e269d6dab8675f0d173842b357483d73c16e720e..06431e36b86ba7f5d575875f2b500291248ea82b 100644 (file)
@@ -320,7 +320,6 @@ my_radosgw_src = \
        rgw/rgw_formats.cc \
        rgw/rgw_log.cc \
        rgw/rgw_multi.cc \
-       rgw/rgw_escape.c \
        rgw/rgw_env.cc
 
 my_radosgw_ldadd = \
@@ -503,11 +502,11 @@ unittest_mime_LDADD = ${UNITTEST_LDADD} $(LIBGLOBAL_LDA)
 unittest_mime_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
 check_PROGRAMS += unittest_mime
 
-unittest_rgw_escape_SOURCES = test/rgw_escape.cc rgw/rgw_escape.c
-unittest_rgw_escape_LDFLAGS = -pthread ${AM_LDFLAGS}
-unittest_rgw_escape_LDADD = ${UNITTEST_LDADD} $(LIBGLOBAL_LDA)
-unittest_rgw_escape_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
-check_PROGRAMS += unittest_rgw_escape
+unittest_escape_SOURCES = test/escape.cc
+unittest_escape_LDFLAGS = -pthread ${AM_LDFLAGS}
+unittest_escape_LDADD = ${UNITTEST_LDADD} $(LIBGLOBAL_LDA)
+unittest_escape_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS}
+check_PROGRAMS += unittest_escape
 
 unittest_strtol_SOURCES = test/strtol.cc
 unittest_strtol_LDFLAGS = -pthread ${AM_LDFLAGS}
@@ -705,6 +704,7 @@ libcommon_files = \
        common/perf_counters.cc \
        common/admin_socket.cc \
        common/admin_socket_client.cc \
+       common/escape.c \
        common/Clock.cc \
        common/Timer.cc \
        common/Finisher.cc \
@@ -894,6 +894,7 @@ noinst_HEADERS = \
        common/compiler_extensions.h\
        common/debug.h\
        common/dout.h\
+       common/escape.h\
        common/version.h\
        common/hex.h\
        common/entity_name.h\
@@ -1217,7 +1218,6 @@ noinst_HEADERS = \
        rgw/rgw_rest_os.h\
        rgw/rgw_rest_s3.h\
        rgw/rgw_user.h\
-       rgw/rgw_escape.h\
        sample.ceph.conf\
        tools/common.h\
        tools/gui.h\
index 44f659667d33c63b9348d038efac64b7a8e8207c..5aaa63d7cf95ad3c2e8a9b035c7b373ebe6c9251 100644 (file)
@@ -1,14 +1,28 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
 
 #define LARGE_SIZE 8192
 
-#include <stdarg.h>
-#include <stdio.h>
-#include <inttypes.h>
-
-#include <iostream>
-
 #include "assert.h"
 #include "Formatter.h"
+#include "common/escape.h"
+
+#include <inttypes.h>
+#include <iostream>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
 
 // -----------------------
 namespace ceph {
@@ -52,36 +66,11 @@ void JSONFormatter::print_comma(formatter_stack_entry_d& entry)
 
 void JSONFormatter::print_quoted_string(const char *s)
 {
-  m_ss << '\"';
-  while (*s) {
-    if (*s == '\\')
-      m_ss << "\\";
-    else if (*s == '\"')
-      m_ss << "\\\"";
-    else if (*s < 32) {
-      // do a few common control characters
-      switch (*s) {
-      case '\n':
-       m_ss << "\\n";
-       break;
-      case '\r':
-       m_ss << "\\r";
-       break;
-      case '\t':
-       m_ss << "\\t";
-       break;
-      default:
-       {
-         // otherwise...
-         char s[10];
-         sprintf(s, "\\u%04x", (int)*s);
-       }
-      }
-    } else
-      m_ss << *s;
-    s++;
-  }
-  m_ss << '\"';
+  int len = escape_json_attr_len(s);
+  char *escaped = (char*)malloc(len);
+  escape_json_attr(s, escaped);
+  m_ss << '\"' << escaped << '\"';
+  free(escaped);
 }
 
 void JSONFormatter::print_name(const char *name)
index 598e86824e9edd93e2dcffa36df81962ffccbd37..fe746370d1b805e14130a841e9ffe4a38c9ff579 100644 (file)
@@ -1,10 +1,13 @@
 #ifndef CEPH_FORMATTER_H
 #define CEPH_FORMATTER_H
 
+#include <inttypes.h>
+#include <iostream>
+#include <list>
 #include <ostream>
 #include <sstream>
+#include <stdarg.h>
 #include <string>
-#include <list>
 
 namespace ceph {
 
diff --git a/src/common/escape.c b/src/common/escape.c
new file mode 100644 (file)
index 0000000..cb4076b
--- /dev/null
@@ -0,0 +1,207 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "common/escape.h"
+
+#include <stdio.h>
+#include <string.h>
+
+/*
+ * Some functions for escaping RGW responses
+ */
+
+/* Static string length */
+#define SSTRL(x) ((sizeof(x)/sizeof(x[0])) - 1)
+
+#define LESS_THAN_XESCAPE              "&lt;"
+#define AMPERSAND_XESCAPE              "&amp;"
+#define GREATER_THAN_XESCAPE           "&gt;"
+#define SGL_QUOTE_XESCAPE              "&apos;"
+#define DBL_QUOTE_XESCAPE              "&quot;"
+
+int escape_xml_attr_len(const char *buf)
+{
+       const char *b;
+       int ret = 0;
+       for (b = buf; *b; ++b) {
+               unsigned char c = *b;
+               switch (c) {
+               case '<':
+                       ret += SSTRL(LESS_THAN_XESCAPE);
+                       break;
+               case '&':
+                       ret += SSTRL(AMPERSAND_XESCAPE);
+                       break;
+               case '>':
+                       ret += SSTRL(GREATER_THAN_XESCAPE);
+                       break;
+               case '\'':
+                       ret += SSTRL(SGL_QUOTE_XESCAPE);
+                       break;
+               case '"':
+                       ret += SSTRL(DBL_QUOTE_XESCAPE);
+                       break;
+               default:
+                       // Escape control characters.
+                       if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) ||
+                                   (c == 0x7f)) {
+                               ret += 6;
+                       }
+                       else {
+                               ret++;
+                       }
+               }
+       }
+       // leave room for null terminator
+       ret++;
+       return ret;
+}
+
+void escape_xml_attr(const char *buf, char *out)
+{
+       char *o = out;
+       const char *b;
+       for (b = buf; *b; ++b) {
+               unsigned char c = *b;
+               switch (c) {
+               case '<':
+                       memcpy(o, LESS_THAN_XESCAPE, SSTRL(LESS_THAN_XESCAPE));
+                       o += SSTRL(LESS_THAN_XESCAPE);
+                       break;
+               case '&':
+                       memcpy(o, AMPERSAND_XESCAPE, SSTRL(AMPERSAND_XESCAPE));
+                       o += SSTRL(AMPERSAND_XESCAPE);
+                       break;
+               case '>':
+                       memcpy(o, GREATER_THAN_XESCAPE, SSTRL(GREATER_THAN_XESCAPE));
+                       o += SSTRL(GREATER_THAN_XESCAPE);
+                       break;
+               case '\'':
+                       memcpy(o, SGL_QUOTE_XESCAPE, SSTRL(SGL_QUOTE_XESCAPE));
+                       o += SSTRL(SGL_QUOTE_XESCAPE);
+                       break;
+               case '"':
+                       memcpy(o, DBL_QUOTE_XESCAPE, SSTRL(DBL_QUOTE_XESCAPE));
+                       o += SSTRL(DBL_QUOTE_XESCAPE);
+                       break;
+               default:
+                       // Escape control characters.
+                       if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) ||
+                                   (c == 0x7f)) {
+                               sprintf(o, "&#x%02x;", c);
+                               o += 6;
+                       }
+                       else {
+                               *o++ = c;
+                       }
+                       break;
+               }
+       }
+       // null terminator
+       *o = '\0';
+}
+
+#define SGL_QUOTE_JESCAPE "\\'"
+#define DBL_QUOTE_JESCAPE "\\\""
+#define BACKSLASH_JESCAPE "\\\\"
+#define SLASH_JESCAPE "\\/"
+#define TAB_JESCAPE "\\t"
+#define NEWLINE_JESCAPE "\\n"
+
+int escape_json_attr_len(const char *buf)
+{
+       const char *b;
+       int ret = 0;
+       for (b = buf; *b; ++b) {
+               unsigned char c = *b;
+               switch (c) {
+               case '\'':
+                       ret += SSTRL(SGL_QUOTE_JESCAPE);
+                       break;
+               case '"':
+                       ret += SSTRL(DBL_QUOTE_JESCAPE);
+                       break;
+               case '\\':
+                       ret += SSTRL(BACKSLASH_JESCAPE);
+                       break;
+               case '/':
+                       ret += SSTRL(SLASH_JESCAPE);
+                       break;
+               case '\t':
+                       ret += SSTRL(TAB_JESCAPE);
+                       break;
+               case '\n':
+                       ret += SSTRL(NEWLINE_JESCAPE);
+                       break;
+               default:
+                       // Escape control characters.
+                       if ((c < 0x20) || (c == 0x7f)) {
+                               ret += 5;
+                       }
+                       else {
+                               ret++;
+                       }
+               }
+       }
+       // leave room for null terminator
+       ret++;
+       return ret;
+}
+
+void escape_json_attr(const char *buf, char *out)
+{
+       char *o = out;
+       const char *b;
+       for (b = buf; *b; ++b) {
+               unsigned char c = *b;
+               switch (c) {
+               case '\'':
+                       memcpy(o, SGL_QUOTE_JESCAPE, SSTRL(SGL_QUOTE_JESCAPE));
+                       o += SSTRL(SGL_QUOTE_JESCAPE);
+                       break;
+               case '"':
+                       memcpy(o, DBL_QUOTE_JESCAPE, SSTRL(DBL_QUOTE_JESCAPE));
+                       o += SSTRL(DBL_QUOTE_JESCAPE);
+                       break;
+               case '\\':
+                       memcpy(o, BACKSLASH_JESCAPE, SSTRL(BACKSLASH_JESCAPE));
+                       o += SSTRL(BACKSLASH_JESCAPE);
+                       break;
+               case '/':
+                       memcpy(o, SLASH_JESCAPE, SSTRL(SLASH_JESCAPE));
+                       o += SSTRL(SLASH_JESCAPE);
+                       break;
+               case '\t':
+                       memcpy(o, TAB_JESCAPE, SSTRL(TAB_JESCAPE));
+                       o += SSTRL(TAB_JESCAPE);
+                       break;
+               case '\n':
+                       memcpy(o, NEWLINE_JESCAPE, SSTRL(NEWLINE_JESCAPE));
+                       o += SSTRL(NEWLINE_JESCAPE);
+                       break;
+               default:
+                       // Escape control characters.
+                       if ((c < 0x20) || (c == 0x7f)) {
+                               sprintf(o, "\\%04x", c);
+                               o += 5;
+                       }
+                       else {
+                               *o++ = c;
+                       }
+                       break;
+               }
+       }
+       // null terminator
+       *o = '\0';
+}
diff --git a/src/common/escape.h b/src/common/escape.h
new file mode 100644 (file)
index 0000000..31aa5ac
--- /dev/null
@@ -0,0 +1,52 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#ifndef CEPH_RGW_ESCAPE_H
+#define CEPH_RGW_ESCAPE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Returns the length of a buffer that would be needed to escape 'buf'
+ * as an XML attrribute
+ */
+int escape_xml_attr_len(const char *buf);
+
+/* Escapes 'buf' as an XML attribute. Assumes that 'out' is at least long
+ * enough to fit the output. You can find out the required length by calling
+ * escape_xml_attr_len first.
+ */
+void escape_xml_attr(const char *buf, char *out);
+
+/* Returns the length of a buffer that would be needed to escape 'buf'
+ * as an JSON attrribute
+ */
+int escape_json_attr_len(const char *buf);
+
+/* Escapes 'buf' as an JSON attribute. Assumes that 'out' is at least long
+ * enough to fit the output. You can find out the required length by calling
+ * escape_json_attr_len first.
+ */
+void escape_json_attr(const char *buf, char *out);
+
+/* Note: we escape control characters. Although the XML spec doesn't actually
+ * require this, Amazon does it in their XML responses.
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index d3ddfa26ba5f8102f45b35cad7cfc055000ffab5..005fa359b76640cb697f0e192a041b9beb2574d3 100644 (file)
@@ -12,8 +12,6 @@
  * 
  */
 
-
-
 #include "FileStore.h"
 #include "common/BackTrace.h"
 #include "include/types.h"
diff --git a/src/rgw/rgw_escape.c b/src/rgw/rgw_escape.c
deleted file mode 100644 (file)
index aa19720..0000000
+++ /dev/null
@@ -1,207 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2011 New Dream Network
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-
-#include "rgw/rgw_escape.h"
-
-#include <stdio.h>
-#include <string.h>
-
-/*
- * Some functions for escaping RGW responses
- */
-
-/* Static string length */
-#define SSTRL(x) ((sizeof(x)/sizeof(x[0])) - 1)
-
-#define LESS_THAN_XESCAPE              "&lt;"
-#define AMPERSAND_XESCAPE              "&amp;"
-#define GREATER_THAN_XESCAPE           "&gt;"
-#define SGL_QUOTE_XESCAPE              "&apos;"
-#define DBL_QUOTE_XESCAPE              "&quot;"
-
-int escape_xml_attr_len(const char *buf)
-{
-       const char *b;
-       int ret = 0;
-       for (b = buf; *b; ++b) {
-               unsigned char c = *b;
-               switch (c) {
-               case '<':
-                       ret += SSTRL(LESS_THAN_XESCAPE);
-                       break;
-               case '&':
-                       ret += SSTRL(AMPERSAND_XESCAPE);
-                       break;
-               case '>':
-                       ret += SSTRL(GREATER_THAN_XESCAPE);
-                       break;
-               case '\'':
-                       ret += SSTRL(SGL_QUOTE_XESCAPE);
-                       break;
-               case '"':
-                       ret += SSTRL(DBL_QUOTE_XESCAPE);
-                       break;
-               default:
-                       // Escape control characters.
-                       if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) ||
-                                   (c == 0x7f)) {
-                               ret += 6;
-                       }
-                       else {
-                               ret++;
-                       }
-               }
-       }
-       // leave room for null terminator
-       ret++;
-       return ret;
-}
-
-void escape_xml_attr(const char *buf, char *out)
-{
-       char *o = out;
-       const char *b;
-       for (b = buf; *b; ++b) {
-               unsigned char c = *b;
-               switch (c) {
-               case '<':
-                       memcpy(o, LESS_THAN_XESCAPE, SSTRL(LESS_THAN_XESCAPE));
-                       o += SSTRL(LESS_THAN_XESCAPE);
-                       break;
-               case '&':
-                       memcpy(o, AMPERSAND_XESCAPE, SSTRL(AMPERSAND_XESCAPE));
-                       o += SSTRL(AMPERSAND_XESCAPE);
-                       break;
-               case '>':
-                       memcpy(o, GREATER_THAN_XESCAPE, SSTRL(GREATER_THAN_XESCAPE));
-                       o += SSTRL(GREATER_THAN_XESCAPE);
-                       break;
-               case '\'':
-                       memcpy(o, SGL_QUOTE_XESCAPE, SSTRL(SGL_QUOTE_XESCAPE));
-                       o += SSTRL(SGL_QUOTE_XESCAPE);
-                       break;
-               case '"':
-                       memcpy(o, DBL_QUOTE_XESCAPE, SSTRL(DBL_QUOTE_XESCAPE));
-                       o += SSTRL(DBL_QUOTE_XESCAPE);
-                       break;
-               default:
-                       // Escape control characters.
-                       if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) ||
-                                   (c == 0x7f)) {
-                               sprintf(o, "&#x%02x;", c);
-                               o += 6;
-                       }
-                       else {
-                               *o++ = c;
-                       }
-                       break;
-               }
-       }
-       // null terminator
-       *o = '\0';
-}
-
-#define SGL_QUOTE_JESCAPE "\\'"
-#define DBL_QUOTE_JESCAPE "\\\""
-#define BACKSLASH_JESCAPE "\\\\"
-#define SLASH_JESCAPE "\\/"
-#define TAB_JESCAPE "\\t"
-#define NEWLINE_JESCAPE "\\n"
-
-int escape_json_attr_len(const char *buf)
-{
-       const char *b;
-       int ret = 0;
-       for (b = buf; *b; ++b) {
-               unsigned char c = *b;
-               switch (c) {
-               case '\'':
-                       ret += SSTRL(SGL_QUOTE_JESCAPE);
-                       break;
-               case '"':
-                       ret += SSTRL(DBL_QUOTE_JESCAPE);
-                       break;
-               case '\\':
-                       ret += SSTRL(BACKSLASH_JESCAPE);
-                       break;
-               case '/':
-                       ret += SSTRL(SLASH_JESCAPE);
-                       break;
-               case '\t':
-                       ret += SSTRL(TAB_JESCAPE);
-                       break;
-               case '\n':
-                       ret += SSTRL(NEWLINE_JESCAPE);
-                       break;
-               default:
-                       // Escape control characters.
-                       if ((c < 0x20) || (c == 0x7f)) {
-                               ret += 5;
-                       }
-                       else {
-                               ret++;
-                       }
-               }
-       }
-       // leave room for null terminator
-       ret++;
-       return ret;
-}
-
-void escape_json_attr(const char *buf, char *out)
-{
-       char *o = out;
-       const char *b;
-       for (b = buf; *b; ++b) {
-               unsigned char c = *b;
-               switch (c) {
-               case '\'':
-                       memcpy(o, SGL_QUOTE_JESCAPE, SSTRL(SGL_QUOTE_JESCAPE));
-                       o += SSTRL(SGL_QUOTE_JESCAPE);
-                       break;
-               case '"':
-                       memcpy(o, DBL_QUOTE_JESCAPE, SSTRL(DBL_QUOTE_JESCAPE));
-                       o += SSTRL(DBL_QUOTE_JESCAPE);
-                       break;
-               case '\\':
-                       memcpy(o, BACKSLASH_JESCAPE, SSTRL(BACKSLASH_JESCAPE));
-                       o += SSTRL(BACKSLASH_JESCAPE);
-                       break;
-               case '/':
-                       memcpy(o, SLASH_JESCAPE, SSTRL(SLASH_JESCAPE));
-                       o += SSTRL(SLASH_JESCAPE);
-                       break;
-               case '\t':
-                       memcpy(o, TAB_JESCAPE, SSTRL(TAB_JESCAPE));
-                       o += SSTRL(TAB_JESCAPE);
-                       break;
-               case '\n':
-                       memcpy(o, NEWLINE_JESCAPE, SSTRL(NEWLINE_JESCAPE));
-                       o += SSTRL(NEWLINE_JESCAPE);
-                       break;
-               default:
-                       // Escape control characters.
-                       if ((c < 0x20) || (c == 0x7f)) {
-                               sprintf(o, "\\%04x", c);
-                               o += 5;
-                       }
-                       else {
-                               *o++ = c;
-                       }
-                       break;
-               }
-       }
-       // null terminator
-       *o = '\0';
-}
diff --git a/src/rgw/rgw_escape.h b/src/rgw/rgw_escape.h
deleted file mode 100644 (file)
index 31aa5ac..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2011 New Dream Network
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-
-#ifndef CEPH_RGW_ESCAPE_H
-#define CEPH_RGW_ESCAPE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Returns the length of a buffer that would be needed to escape 'buf'
- * as an XML attrribute
- */
-int escape_xml_attr_len(const char *buf);
-
-/* Escapes 'buf' as an XML attribute. Assumes that 'out' is at least long
- * enough to fit the output. You can find out the required length by calling
- * escape_xml_attr_len first.
- */
-void escape_xml_attr(const char *buf, char *out);
-
-/* Returns the length of a buffer that would be needed to escape 'buf'
- * as an JSON attrribute
- */
-int escape_json_attr_len(const char *buf);
-
-/* Escapes 'buf' as an JSON attribute. Assumes that 'out' is at least long
- * enough to fit the output. You can find out the required length by calling
- * escape_json_attr_len first.
- */
-void escape_json_attr(const char *buf, char *out);
-
-/* Note: we escape control characters. Although the XML spec doesn't actually
- * require this, Amazon does it in their XML responses.
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
index 76befad774825b7fd4e02ab82440c926fd0c308a..276425cd8e72de462174f92023bce03637c67410 100644 (file)
@@ -1,6 +1,20 @@
-#include "rgw_escape.h"
-#include "rgw_common.h"
-#include "rgw_formats.h"
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "common/escape.h"
+#include "rgw/rgw_common.h"
+#include "rgw/rgw_formats.h"
 
 /* Plain */
 void RGWFormatter_Plain::formatter_init()
diff --git a/src/test/escape.cc b/src/test/escape.cc
new file mode 100644 (file)
index 0000000..f494e9a
--- /dev/null
@@ -0,0 +1,95 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 New Dream Network
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+#include "common/escape.h"
+#include "gtest/gtest.h"
+#include <stdint.h>
+
+static std::string escape_xml_attrs(const char *str)
+{
+  int len = escape_xml_attr_len(str);
+  char out[len];
+  escape_xml_attr(str, out);
+  return out;
+}
+
+TEST(EscapeXml, PassThrough) {
+  ASSERT_EQ(escape_xml_attrs("simplicity itself"), "simplicity itself");
+  ASSERT_EQ(escape_xml_attrs(""), "");
+  ASSERT_EQ(escape_xml_attrs("simple examples please!"), "simple examples please!");
+}
+
+TEST(EscapeXml, EntityRefs1) {
+  ASSERT_EQ(escape_xml_attrs("The \"scare quotes\""), "The &quot;scare quotes&quot;");
+  ASSERT_EQ(escape_xml_attrs("I <3 XML"), "I &lt;3 XML");
+  ASSERT_EQ(escape_xml_attrs("Some 'single' \"quotes\" here"),
+           "Some &apos;single&apos; &quot;quotes&quot; here");
+}
+
+TEST(EscapeXml, ControlChars) {
+  uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
+  ASSERT_EQ(escape_xml_attrs((char*)cc1), "&#x01;&#x02;&#x03;");
+
+  uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
+  ASSERT_EQ(escape_xml_attrs((char*)cc2), "abc&#x7f;");
+}
+
+TEST(EscapeXml, Utf8) {
+  uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
+  ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
+
+  uint8_t cc2[] = { 0x3c, 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x3e, 0x0a, 0x0 };
+  uint8_t cc2_out[] = { 0x26, 0x6c, 0x74, 0x3b, 0xe6, 0xb1, 0x89, 0xe5,
+                       0xad, 0x97, 0x26, 0x67, 0x74, 0x3b, 0x0a, 0x0 };
+  ASSERT_EQ(escape_xml_attrs((const char*)cc2), (const char*)cc2_out);
+}
+
+static std::string escape_json_attrs(const char *str)
+{
+  int len = escape_json_attr_len(str);
+  char out[len];
+  escape_json_attr(str, out);
+  return out;
+}
+
+TEST(EscapeJson, PassThrough) {
+  ASSERT_EQ(escape_json_attrs("simplicity itself"), "simplicity itself");
+  ASSERT_EQ(escape_json_attrs(""), "");
+  ASSERT_EQ(escape_json_attrs("simple examples please!"), "simple examples please!");
+}
+
+TEST(EscapeJson, Escapes1) {
+  ASSERT_EQ(escape_json_attrs("The \"scare quotes\""),
+                            "The \\\"scare quotes\\\"");
+  ASSERT_EQ(escape_json_attrs("I <3 JSON"), "I <3 JSON");
+  ASSERT_EQ(escape_json_attrs(
+      "JSON calls a slash / backslash a solidus / reverse solidus"),
+      "JSON calls a slash \\/ backslash a solidus \\/ reverse solidus");
+  ASSERT_EQ(escape_json_attrs("Some 'single' \"quotes\" here"),
+      "Some \\'single\\' \\\"quotes\\\" here");
+  ASSERT_EQ(escape_json_attrs("tabs\tand\tnewlines\n, oh my"),
+      "tabs\\tand\\tnewlines\\n, oh my");
+}
+
+TEST(EscapeJson, ControlChars) {
+  uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
+  ASSERT_EQ(escape_json_attrs((char*)cc1), "\\0001\\0002\\0003");
+
+  uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
+  ASSERT_EQ(escape_json_attrs((char*)cc2), "abc\\007f");
+}
+
+TEST(EscapeJson, Utf8) {
+  uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
+  ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
+}
diff --git a/src/test/rgw_escape.cc b/src/test/rgw_escape.cc
deleted file mode 100644 (file)
index 16eb261..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2011 New Dream Network
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software
- * Foundation.  See file COPYING.
- *
- */
-#include "rgw/rgw_escape.h"
-#include "gtest/gtest.h"
-#include <stdint.h>
-
-static std::string escape_xml_attrs(const char *str)
-{
-  int len = escape_xml_attr_len(str);
-  char out[len];
-  escape_xml_attr(str, out);
-  return out;
-}
-
-TEST(EscapeXml, PassThrough) {
-  ASSERT_EQ(escape_xml_attrs("simplicity itself"), "simplicity itself");
-  ASSERT_EQ(escape_xml_attrs(""), "");
-  ASSERT_EQ(escape_xml_attrs("simple examples please!"), "simple examples please!");
-}
-
-TEST(EscapeXml, EntityRefs1) {
-  ASSERT_EQ(escape_xml_attrs("The \"scare quotes\""), "The &quot;scare quotes&quot;");
-  ASSERT_EQ(escape_xml_attrs("I <3 XML"), "I &lt;3 XML");
-  ASSERT_EQ(escape_xml_attrs("Some 'single' \"quotes\" here"),
-           "Some &apos;single&apos; &quot;quotes&quot; here");
-}
-
-TEST(EscapeXml, ControlChars) {
-  uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
-  ASSERT_EQ(escape_xml_attrs((char*)cc1), "&#x01;&#x02;&#x03;");
-
-  uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
-  ASSERT_EQ(escape_xml_attrs((char*)cc2), "abc&#x7f;");
-}
-
-TEST(EscapeXml, Utf8) {
-  uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
-  ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
-
-  uint8_t cc2[] = { 0x3c, 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x3e, 0x0a, 0x0 };
-  uint8_t cc2_out[] = { 0x26, 0x6c, 0x74, 0x3b, 0xe6, 0xb1, 0x89, 0xe5,
-                       0xad, 0x97, 0x26, 0x67, 0x74, 0x3b, 0x0a, 0x0 };
-  ASSERT_EQ(escape_xml_attrs((const char*)cc2), (const char*)cc2_out);
-}
-
-static std::string escape_json_attrs(const char *str)
-{
-  int len = escape_json_attr_len(str);
-  char out[len];
-  escape_json_attr(str, out);
-  return out;
-}
-
-TEST(EscapeJson, PassThrough) {
-  ASSERT_EQ(escape_json_attrs("simplicity itself"), "simplicity itself");
-  ASSERT_EQ(escape_json_attrs(""), "");
-  ASSERT_EQ(escape_json_attrs("simple examples please!"), "simple examples please!");
-}
-
-TEST(EscapeJson, Escapes1) {
-  ASSERT_EQ(escape_json_attrs("The \"scare quotes\""),
-                            "The \\\"scare quotes\\\"");
-  ASSERT_EQ(escape_json_attrs("I <3 JSON"), "I <3 JSON");
-  ASSERT_EQ(escape_json_attrs(
-      "JSON calls a slash / backslash a solidus / reverse solidus"),
-      "JSON calls a slash \\/ backslash a solidus \\/ reverse solidus");
-  ASSERT_EQ(escape_json_attrs("Some 'single' \"quotes\" here"),
-      "Some \\'single\\' \\\"quotes\\\" here");
-  ASSERT_EQ(escape_json_attrs("tabs\tand\tnewlines\n, oh my"),
-      "tabs\\tand\\tnewlines\\n, oh my");
-}
-
-TEST(EscapeJson, ControlChars) {
-  uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
-  ASSERT_EQ(escape_json_attrs((char*)cc1), "\\0001\\0002\\0003");
-
-  uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
-  ASSERT_EQ(escape_json_attrs((char*)cc2), "abc\\007f");
-}
-
-TEST(EscapeJson, Utf8) {
-  uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
-  ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
-}