1 #ifndef global_variables_h
2 #define global_variables_h
4 static VALUE cHttpParser
;
5 static VALUE eHttpParserError
;
7 static VALUE g_rack_url_scheme
;
8 static VALUE g_request_method
;
9 static VALUE g_request_uri
;
10 static VALUE g_fragment
;
11 static VALUE g_query_string
;
12 static VALUE g_http_version
;
13 static VALUE g_request_path
;
14 static VALUE g_path_info
;
15 static VALUE g_server_name
;
16 static VALUE g_server_port
;
17 static VALUE g_server_protocol
;
18 static VALUE g_http_host
;
19 static VALUE g_http_x_forwarded_proto
;
20 static VALUE g_http_transfer_encoding
;
21 static VALUE g_content_length
;
22 static VALUE g_http_trailer
;
23 static VALUE g_http_connection
;
24 static VALUE g_port_80
;
25 static VALUE g_port_443
;
26 static VALUE g_localhost
;
28 static VALUE g_http_09
;
29 static VALUE g_http_10
;
30 static VALUE g_http_11
;
34 /** Defines common length and error messages for input length validation. */
35 #define DEF_MAX_LENGTH(N, length) \
36 static const size_t MAX_##N##_LENGTH = length; \
37 static const char * const MAX_##N##_LENGTH_ERR = \
38 "HTTP element " # N " is longer than the " # length " allowed length."
41 * Validates the max length of given input and throws an HttpParserError
44 #define VALIDATE_MAX_LENGTH(len, N) do { \
45 if (len > MAX_##N##_LENGTH) \
46 rb_raise(eHttpParserError, MAX_##N##_LENGTH_ERR); \
49 /** Defines global strings in the init method. */
50 #define DEF_GLOBAL(N, val) do { \
51 g_##N = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \
52 rb_global_variable(&g_##N); \
55 /* Defines the maximum allowed lengths for various input elements.*/
56 DEF_MAX_LENGTH(FIELD_NAME
, 256);
57 DEF_MAX_LENGTH(FIELD_VALUE
, 80 * 1024);
58 DEF_MAX_LENGTH(REQUEST_URI
, 1024 * 12);
59 DEF_MAX_LENGTH(FRAGMENT
, 1024); /* Don't know if this length is specified somewhere or not */
60 DEF_MAX_LENGTH(REQUEST_PATH
, 1024);
61 DEF_MAX_LENGTH(QUERY_STRING
, (1024 * 10));
62 DEF_MAX_LENGTH(HEADER
, (1024 * (80 + 32)));
64 void init_globals(void)
66 DEF_GLOBAL(rack_url_scheme
, "rack.url_scheme");
67 DEF_GLOBAL(request_method
, "REQUEST_METHOD");
68 DEF_GLOBAL(request_uri
, "REQUEST_URI");
69 DEF_GLOBAL(fragment
, "FRAGMENT");
70 DEF_GLOBAL(query_string
, "QUERY_STRING");
71 DEF_GLOBAL(http_version
, "HTTP_VERSION");
72 DEF_GLOBAL(request_path
, "REQUEST_PATH");
73 DEF_GLOBAL(path_info
, "PATH_INFO");
74 DEF_GLOBAL(server_name
, "SERVER_NAME");
75 DEF_GLOBAL(server_port
, "SERVER_PORT");
76 DEF_GLOBAL(server_protocol
, "SERVER_PROTOCOL");
77 DEF_GLOBAL(http_x_forwarded_proto
, "HTTP_X_FORWARDED_PROTO");
78 DEF_GLOBAL(port_80
, "80");
79 DEF_GLOBAL(port_443
, "443");
80 DEF_GLOBAL(localhost
, "localhost");
81 DEF_GLOBAL(http
, "http");
82 DEF_GLOBAL(http_11
, "HTTP/1.1");
83 DEF_GLOBAL(http_10
, "HTTP/1.0");
84 DEF_GLOBAL(http_09
, "HTTP/0.9");
85 DEF_GLOBAL(GET
, "GET");
86 DEF_GLOBAL(HEAD
, "HEAD");
91 #endif /* global_variables_h */