summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2010-04-06 11:56:04 -0400
committerDan Winship <danw@gnome.org>2010-04-09 19:51:33 -0400
commit6ce2bb5d1e4dfc1429567cc6d2b5232f421af2b3 (patch)
treeee48fb7fc93af32368ff0a71c7851276bf24f4ba
parent50e363db0243cd94acd45e67f93983312a90eb1c (diff)
downloadlibsoup-6ce2bb5d1e4dfc1429567cc6d2b5232f421af2b3.tar.gz
Add macros for checking character classes. Eg, soup_char_is_token()
Move the existing URI character class table from soup-uri.c to soup-misc.c, and update for that. Also add soup_char_is_token(), to determine if a character can be used in a token or not.
-rw-r--r--libsoup/soup-misc.c59
-rw-r--r--libsoup/soup-misc.h15
-rw-r--r--libsoup/soup-uri.c29
3 files changed, 77 insertions, 26 deletions
diff --git a/libsoup/soup-misc.c b/libsoup/soup-misc.c
index 5e99476f..9a9740b2 100644
--- a/libsoup/soup-misc.c
+++ b/libsoup/soup-misc.c
@@ -164,3 +164,62 @@ soup_add_timeout (GMainContext *async_context,
g_source_unref (source);
return source;
}
+
+/* 00 URI_UNRESERVED
+ * 01 URI_PCT_ENCODED
+ * 02 URI_GEN_DELIMS
+ * 04 URI_SUB_DELIMS
+ * 08 HTTP_SEPARATOR
+ * 10 HTTP_CTL
+ */
+const char soup_char_attributes[] = {
+ /* 0x00 - 0x07 */
+ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+ /* 0x08 - 0x0f */
+ 0x11, 0x19, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+ /* 0x10 - 0x17 */
+ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+ /* 0x18 - 0x1f */
+ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
+ /* !"#$%&' */
+ 0x09, 0x04, 0x09, 0x02, 0x04, 0x01, 0x04, 0x04,
+ /* ()*+,-./ */
+ 0x0c, 0x0c, 0x04, 0x04, 0x0c, 0x00, 0x00, 0x0a,
+ /* 01234567 */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* 89:;<=>? */
+ 0x00, 0x00, 0x0a, 0x0c, 0x09, 0x0a, 0x09, 0x0a,
+ /* @ABCDEFG */
+ 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* HIJKLMNO */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* PQRSTUVW */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* XYZ[\]^_ */
+ 0x00, 0x00, 0x00, 0x0a, 0x09, 0x0a, 0x01, 0x00,
+ /* `abcdefg */
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* hijklmno */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* pqrstuvw */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* xyz{|}~ */
+ 0x00, 0x00, 0x00, 0x09, 0x01, 0x09, 0x00, 0x11,
+ /* 0x80 - 0xFF */
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
+};
diff --git a/libsoup/soup-misc.h b/libsoup/soup-misc.h
index 8802340b..9e7f00d0 100644
--- a/libsoup/soup-misc.h
+++ b/libsoup/soup-misc.h
@@ -35,6 +35,21 @@ gboolean soup_str_case_equal (gconstpointer v1,
#define _SOUP_ATOMIC_INTERN_STRING(variable, value) ((const char *)(g_atomic_pointer_get (&(variable)) ? (variable) : (g_atomic_pointer_set (&(variable), (gpointer)g_intern_static_string (value)), (variable))))
+/* character classes */
+
+extern const char soup_char_attributes[];
+#define SOUP_CHAR_URI_PERCENT_ENCODED 0x01
+#define SOUP_CHAR_URI_GEN_DELIMS 0x02
+#define SOUP_CHAR_URI_SUB_DELIMS 0x04
+#define SOUP_CHAR_HTTP_SEPARATOR 0x08
+#define SOUP_CHAR_HTTP_CTL 0x10
+
+#define soup_char_is_uri_percent_encoded(ch) (soup_char_attributes[(guchar)ch] & SOUP_CHAR_URI_PERCENT_ENCODED)
+#define soup_char_is_uri_gen_delims(ch) (soup_char_attributes[(guchar)ch] & SOUP_CHAR_URI_GEN_DELIMS)
+#define soup_char_is_uri_sub_delims(ch) (soup_char_attributes[(guchar)ch] & SOUP_CHAR_URI_SUB_DELIMS)
+#define soup_char_is_uri_unreserved(ch) (!(soup_char_attributes[(guchar)ch] & (SOUP_CHAR_URI_PERCENT_ENCODED | SOUP_CHAR_URI_GEN_DELIMS | SOUP_CHAR_URI_SUB_DELIMS)))
+#define soup_char_is_token(ch) (!(soup_char_attributes[(guchar)ch] & (SOUP_CHAR_HTTP_SEPARATOR | SOUP_CHAR_HTTP_CTL)))
+
/* SSL stuff */
extern const gboolean soup_ssl_supported;
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index d82fe294..792c6dc2 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -559,37 +559,14 @@ soup_uri_free (SoupURI *uri)
g_slice_free (SoupURI, uri);
}
-/* From RFC 3986 */
-#define SOUP_URI_UNRESERVED 0
-#define SOUP_URI_PCT_ENCODED 1
-#define SOUP_URI_GEN_DELIMS 2
-#define SOUP_URI_SUB_DELIMS 4
-static const char uri_encoded_char[] = {
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x00 - 0x0f */
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x10 - 0x1f */
- 1, 4, 1, 2, 4, 1, 4, 4, 4, 4, 4, 4, 4, 0, 0, 2, /* !"#$%&'()*+,-./ */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 1, 4, 1, 2, /* 0123456789:;<=>? */
- 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 2, 1, 0, /* PQRSTUVWXYZ[\]^_ */
- 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* `abcdefghijklmno */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, /* pqrstuvwxyz{|}~ */
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
-};
-
static void
append_uri_encoded (GString *str, const char *in, const char *extra_enc_chars)
{
const unsigned char *s = (const unsigned char *)in;
while (*s) {
- if ((uri_encoded_char[*s] & (SOUP_URI_PCT_ENCODED | SOUP_URI_GEN_DELIMS)) ||
+ if (soup_char_is_uri_percent_encoded (*s) ||
+ soup_char_is_uri_gen_delims (*s) ||
(extra_enc_chars && strchr (extra_enc_chars, *s)))
g_string_append_printf (str, "%%%02X", (int)*s++);
else
@@ -689,7 +666,7 @@ uri_normalized_copy (const char *part, int length,
}
c = HEXCHAR (s);
- if (uri_encoded_char[c] == SOUP_URI_UNRESERVED ||
+ if (soup_char_is_uri_unreserved (c) ||
(unescape_extra && strchr (unescape_extra, c))) {
*d++ = c;
s += 2;