about summary refs log tree commit homepage
path: root/ext/unicorn_http/global_variables.h
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-08-02 13:39:21 -0700
committerEric Wong <normalperson@yhbt.net>2009-08-09 01:24:30 -0700
commitca3fd8acb4bc3f5125a9f0f281951fb8f03778e5 (patch)
tree42752ea26cf989d9a8d02d750a87aff0d15dc1d8 /ext/unicorn_http/global_variables.h
parente1d67bef994587ba77e1a3575773755b2b5e1558 (diff)
downloadunicorn-ca3fd8acb4bc3f5125a9f0f281951fb8f03778e5.tar.gz
More tightly integrate the C/Ruby portions with C/Ragel to avoid
the confusing the flow.  Split out some files into hopefully
logical areas so it's easier to focus on more
interesting/volatile code.
Diffstat (limited to 'ext/unicorn_http/global_variables.h')
-rw-r--r--ext/unicorn_http/global_variables.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/ext/unicorn_http/global_variables.h b/ext/unicorn_http/global_variables.h
new file mode 100644
index 0000000..1091909
--- /dev/null
+++ b/ext/unicorn_http/global_variables.h
@@ -0,0 +1,57 @@
+#ifndef global_variables_h
+#define global_variables_h
+static VALUE mUnicorn;
+static VALUE cHttpParser;
+static VALUE eHttpParserError;
+static VALUE sym_http_body;
+
+static VALUE g_rack_url_scheme;
+static VALUE g_request_method;
+static VALUE g_request_uri;
+static VALUE g_fragment;
+static VALUE g_query_string;
+static VALUE g_http_version;
+static VALUE g_request_path;
+static VALUE g_path_info;
+static VALUE g_server_name;
+static VALUE g_server_port;
+static VALUE g_server_protocol;
+static VALUE g_server_protocol_value;
+static VALUE g_http_host;
+static VALUE g_http_x_forwarded_proto;
+static VALUE g_port_80;
+static VALUE g_port_443;
+static VALUE g_localhost;
+static VALUE g_http;
+
+/** Defines common length and error messages for input length validation. */
+#define DEF_MAX_LENGTH(N, length) \
+  static const size_t MAX_##N##_LENGTH = length; \
+  static const char * const MAX_##N##_LENGTH_ERR = \
+    "HTTP element " # N  " is longer than the " # length " allowed length."
+
+/**
+ * Validates the max length of given input and throws an HttpParserError
+ * exception if over.
+ */
+#define VALIDATE_MAX_LENGTH(len, N) do { \
+  if (len > MAX_##N##_LENGTH) \
+    rb_raise(eHttpParserError, MAX_##N##_LENGTH_ERR); \
+} while (0)
+
+/** Defines global strings in the init method. */
+#define DEF_GLOBAL(N, val) do { \
+  g_##N = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \
+  rb_global_variable(&g_##N); \
+} while (0)
+
+/* Defines the maximum allowed lengths for various input elements.*/
+DEF_MAX_LENGTH(FIELD_NAME, 256);
+DEF_MAX_LENGTH(FIELD_VALUE, 80 * 1024);
+DEF_MAX_LENGTH(REQUEST_URI, 1024 * 12);
+DEF_MAX_LENGTH(FRAGMENT, 1024); /* Don't know if this length is specified somewhere or not */
+DEF_MAX_LENGTH(REQUEST_PATH, 1024);
+DEF_MAX_LENGTH(QUERY_STRING, (1024 * 10));
+DEF_MAX_LENGTH(HEADER, (1024 * (80 + 32)));
+
+#endif /* global_variables_h */