ext: fix signedness and shadow warnings
[clogger.git] / ext / clogger_ext / clogger.c
blob01269fc39d51b8a80e64a29b0bdca582eca88f9c
1 #define _BSD_SOURCE
2 #include <ruby.h>
3 #include <assert.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/time.h>
7 #include <time.h>
8 #include <errno.h>
9 #ifdef HAVE_FCNTL_H
10 # include <fcntl.h>
11 #endif
12 #include "ruby_1_9_compat.h"
14 /* in case _BSD_SOURCE doesn't give us this macro */
15 #ifndef timersub
16 # define timersub(a, b, result) \
17 do { \
18 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
19 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
20 if ((result)->tv_usec < 0) { \
21 --(result)->tv_sec; \
22 (result)->tv_usec += 1000000; \
23 } \
24 } while (0)
25 #endif
27 /* give GCC hints for better branch prediction
28 * (we layout branches so that ASCII characters are handled faster) */
29 #if defined(__GNUC__) && (__GNUC__ >= 3)
30 # define likely(x) __builtin_expect (!!(x), 1)
31 # define unlikely(x) __builtin_expect (!!(x), 0)
32 #else
33 # define unlikely(x) (x)
34 # define likely(x) (x)
35 #endif
37 enum clogger_opcode {
38 CL_OP_LITERAL = 0,
39 CL_OP_REQUEST,
40 CL_OP_RESPONSE,
41 CL_OP_SPECIAL,
42 CL_OP_EVAL,
43 CL_OP_TIME_LOCAL,
44 CL_OP_TIME_UTC,
45 CL_OP_REQUEST_TIME,
46 CL_OP_TIME,
47 CL_OP_COOKIE
50 enum clogger_special {
51 CL_SP_body_bytes_sent = 0,
52 CL_SP_status,
53 CL_SP_request,
54 CL_SP_request_length,
55 CL_SP_response_length,
56 CL_SP_ip,
57 CL_SP_pid,
58 CL_SP_request_uri
61 struct clogger {
62 VALUE app;
64 VALUE fmt_ops;
65 VALUE logger;
66 VALUE log_buf;
68 VALUE env;
69 VALUE cookies;
70 VALUE status;
71 VALUE headers;
72 VALUE body;
74 off_t body_bytes_sent;
75 struct timeval tv_start;
77 int fd;
78 int wrap_body;
79 int need_resp;
80 int reentrant; /* tri-state, -1:auto, 1/0 true/false */
83 static ID ltlt_id;
84 static ID call_id;
85 static ID each_id;
86 static ID close_id;
87 static ID to_i_id;
88 static ID to_s_id;
89 static ID size_id;
90 static ID sq_brace_id;
91 static ID new_id;
92 static VALUE cClogger;
93 static VALUE mFormat;
94 static VALUE cHeaderHash;
96 /* common hash lookup keys */
97 static VALUE g_HTTP_X_FORWARDED_FOR;
98 static VALUE g_REMOTE_ADDR;
99 static VALUE g_REQUEST_METHOD;
100 static VALUE g_PATH_INFO;
101 static VALUE g_REQUEST_URI;
102 static VALUE g_QUERY_STRING;
103 static VALUE g_HTTP_VERSION;
104 static VALUE g_rack_errors;
105 static VALUE g_rack_input;
106 static VALUE g_rack_multithread;
107 static VALUE g_dash;
108 static VALUE g_space;
109 static VALUE g_question_mark;
110 static VALUE g_rack_request_cookie_hash;
112 #define LOG_BUF_INIT_SIZE 128
114 static void init_buffers(struct clogger *c)
116 c->log_buf = rb_str_buf_new(LOG_BUF_INIT_SIZE);
119 static inline int need_escape(unsigned c)
121 assert(c <= 0xff);
122 return !!(c == '\'' || c == '"' || c <= 0x1f);
125 /* we are encoding-agnostic, clients can send us all sorts of junk */
126 static VALUE byte_xs_str(VALUE from)
128 static const char esc[] = "0123456789ABCDEF";
129 unsigned char *new_ptr;
130 unsigned char *ptr = (unsigned char *)RSTRING_PTR(from);
131 long len = RSTRING_LEN(from);
132 long new_len = len;
133 VALUE rv;
135 for (; --len >= 0; ptr++) {
136 unsigned c = *ptr;
138 if (unlikely(need_escape(c)))
139 new_len += 3; /* { '\', 'x', 'X', 'X' } */
142 len = RSTRING_LEN(from);
143 if (new_len == len)
144 return from;
146 rv = rb_str_new(0, new_len);
147 new_ptr = (unsigned char *)RSTRING_PTR(rv);
148 ptr = (unsigned char *)RSTRING_PTR(from);
149 for (; --len >= 0; ptr++) {
150 unsigned c = *ptr;
152 if (unlikely(need_escape(c))) {
153 *new_ptr++ = '\\';
154 *new_ptr++ = 'x';
155 *new_ptr++ = esc[c >> 4];
156 *new_ptr++ = esc[c & 0xf];
157 } else {
158 *new_ptr++ = c;
161 assert(RSTRING_PTR(rv)[RSTRING_LEN(rv)] == '\0');
163 return rv;
166 static VALUE byte_xs(VALUE from)
168 return byte_xs_str(rb_obj_as_string(from));
171 static void clogger_mark(void *ptr)
173 struct clogger *c = ptr;
175 rb_gc_mark(c->app);
176 rb_gc_mark(c->fmt_ops);
177 rb_gc_mark(c->logger);
178 rb_gc_mark(c->log_buf);
179 rb_gc_mark(c->env);
180 rb_gc_mark(c->cookies);
181 rb_gc_mark(c->status);
182 rb_gc_mark(c->headers);
183 rb_gc_mark(c->body);
186 static VALUE clogger_alloc(VALUE klass)
188 struct clogger *c;
190 return Data_Make_Struct(klass, struct clogger, clogger_mark, -1, c);
193 static struct clogger *clogger_get(VALUE self)
195 struct clogger *c;
197 Data_Get_Struct(self, struct clogger, c);
198 assert(c);
199 return c;
202 static VALUE obj_fileno(VALUE obj)
204 return rb_funcall(obj, rb_intern("fileno"), 0);
207 static VALUE obj_enable_sync(VALUE obj)
209 return rb_funcall(obj, rb_intern("sync="), 1, Qtrue);
212 /* only for writing to regular files, not stupid crap like NFS */
213 static void write_full(int fd, const void *buf, size_t count)
215 ssize_t r;
217 while (count > 0) {
218 r = write(fd, buf, count);
220 if ((size_t)r == count) { /* overwhelmingly likely */
221 return;
222 } else if (r > 0) {
223 count -= r;
224 buf += r;
225 } else {
226 if (errno == EINTR || errno == EAGAIN)
227 continue; /* poor souls on NFS and like: */
228 if (!errno)
229 errno = ENOSPC;
230 rb_sys_fail("write");
236 * allow us to use write_full() iff we detect a blocking file
237 * descriptor that wouldn't play nicely with Ruby threading/fibers
239 static int raw_fd(VALUE my_fileno)
241 #if defined(HAVE_FCNTL) && defined(F_GETFL) && defined(O_NONBLOCK)
242 int fd;
243 int flags;
245 if (NIL_P(my_fileno))
246 return -1;
247 fd = NUM2INT(my_fileno);
249 flags = fcntl(fd, F_GETFL);
250 if (flags < 0)
251 rb_sys_fail("fcntl");
253 return (flags & O_NONBLOCK) ? -1 : fd;
254 #else /* platforms w/o fcntl/F_GETFL/O_NONBLOCK */
255 return -1;
256 #endif /* platforms w/o fcntl/F_GETFL/O_NONBLOCK */
259 /* :nodoc: */
260 static VALUE clogger_reentrant(VALUE self)
262 return clogger_get(self)->reentrant == 0 ? Qfalse : Qtrue;
265 /* :nodoc: */
266 static VALUE clogger_wrap_body(VALUE self)
268 return clogger_get(self)->wrap_body == 0 ? Qfalse : Qtrue;
271 static void append_status(struct clogger *c)
273 char buf[sizeof("999")];
274 int nr;
275 VALUE status = c->status;
277 if (TYPE(status) != T_FIXNUM) {
278 status = rb_funcall(status, to_i_id, 0);
279 /* no way it's a valid status code (at least not HTTP/1.1) */
280 if (TYPE(status) != T_FIXNUM) {
281 rb_str_buf_append(c->log_buf, g_dash);
282 return;
286 nr = FIX2INT(status);
287 if (nr >= 100 && nr <= 999) {
288 nr = snprintf(buf, sizeof(buf), "%03d", nr);
289 assert(nr == 3);
290 rb_str_buf_cat(c->log_buf, buf, nr);
291 } else {
292 /* raise?, swap for 500? */
293 rb_str_buf_append(c->log_buf, g_dash);
297 /* this is Rack 1.0.0-compatible, won't try to parse commas in XFF */
298 static void append_ip(struct clogger *c)
300 VALUE env = c->env;
301 VALUE tmp = rb_hash_aref(env, g_HTTP_X_FORWARDED_FOR);
303 if (NIL_P(tmp)) {
304 /* can't be faked on any real server, so no escape */
305 tmp = rb_hash_aref(env, g_REMOTE_ADDR);
306 if (NIL_P(tmp))
307 tmp = g_dash;
308 } else {
309 tmp = byte_xs(tmp);
311 rb_str_buf_append(c->log_buf, tmp);
314 static void append_body_bytes_sent(struct clogger *c)
316 char buf[(sizeof(off_t) * 8) / 3 + 1];
317 const char *fmt = sizeof(off_t) == sizeof(long) ? "%ld" : "%lld";
318 int nr = snprintf(buf, sizeof(buf), fmt, c->body_bytes_sent);
320 assert(nr > 0 && nr < (int)sizeof(buf));
321 rb_str_buf_cat(c->log_buf, buf, nr);
324 static void append_tv(struct clogger *c, const VALUE *op, struct timeval *tv)
326 char buf[sizeof(".000000") + ((sizeof(tv->tv_sec) * 8) / 3)];
327 int nr;
328 char *fmt = RSTRING_PTR(op[1]);
329 int ndiv = NUM2INT(op[2]);
331 nr = snprintf(buf, sizeof(buf), fmt,
332 (int)tv->tv_sec, (int)(tv->tv_usec / ndiv));
333 assert(nr > 0 && nr < (int)sizeof(buf));
334 rb_str_buf_cat(c->log_buf, buf, nr);
337 static void append_request_time_fmt(struct clogger *c, const VALUE *op)
339 struct timeval now, d;
341 gettimeofday(&now, NULL);
342 timersub(&now, &c->tv_start, &d);
343 append_tv(c, op, &d);
346 static void append_time_fmt(struct clogger *c, const VALUE *op)
348 struct timeval now;
350 gettimeofday(&now, NULL);
351 append_tv(c, op, &now);
354 static void append_request_uri(struct clogger *c)
356 VALUE tmp;
358 tmp = rb_hash_aref(c->env, g_REQUEST_URI);
359 if (NIL_P(tmp)) {
360 tmp = rb_hash_aref(c->env, g_PATH_INFO);
361 if (!NIL_P(tmp))
362 rb_str_buf_append(c->log_buf, byte_xs(tmp));
363 tmp = rb_hash_aref(c->env, g_QUERY_STRING);
364 if (!NIL_P(tmp) && RSTRING_LEN(tmp) != 0) {
365 rb_str_buf_append(c->log_buf, g_question_mark);
366 rb_str_buf_append(c->log_buf, byte_xs(tmp));
368 } else {
369 rb_str_buf_append(c->log_buf, byte_xs(tmp));
373 static void append_request(struct clogger *c)
375 VALUE tmp;
377 /* REQUEST_METHOD doesn't need escaping, Rack::Lint governs it */
378 tmp = rb_hash_aref(c->env, g_REQUEST_METHOD);
379 if (!NIL_P(tmp))
380 rb_str_buf_append(c->log_buf, tmp);
382 rb_str_buf_append(c->log_buf, g_space);
384 append_request_uri(c);
386 /* HTTP_VERSION can be injected by malicious clients */
387 tmp = rb_hash_aref(c->env, g_HTTP_VERSION);
388 if (!NIL_P(tmp)) {
389 rb_str_buf_append(c->log_buf, g_space);
390 rb_str_buf_append(c->log_buf, byte_xs(tmp));
394 static void append_request_length(struct clogger *c)
396 VALUE tmp = rb_hash_aref(c->env, g_rack_input);
397 if (NIL_P(tmp)) {
398 rb_str_buf_append(c->log_buf, g_dash);
399 } else {
400 tmp = rb_funcall(tmp, size_id, 0);
401 rb_str_buf_append(c->log_buf, rb_funcall(tmp, to_s_id, 0));
405 static void append_time(struct clogger *c, enum clogger_opcode op, VALUE fmt)
407 /* you'd have to be a moron to use formats this big... */
408 char buf[sizeof("Saturday, November 01, 1970, 00:00:00 PM +0000")];
409 size_t nr;
410 struct tm tmp;
411 time_t t = time(NULL);
413 if (op == CL_OP_TIME_LOCAL)
414 localtime_r(&t, &tmp);
415 else if (op == CL_OP_TIME_UTC)
416 gmtime_r(&t, &tmp);
417 else
418 assert(0 && "unknown op");
420 nr = strftime(buf, sizeof(buf), RSTRING_PTR(fmt), &tmp);
421 if (nr == 0 || nr == sizeof(buf))
422 rb_str_buf_append(c->log_buf, g_dash);
423 else
424 rb_str_buf_cat(c->log_buf, buf, nr);
427 static void append_pid(struct clogger *c)
429 char buf[(sizeof(pid_t) * 8) / 3 + 1];
430 int nr = snprintf(buf, sizeof(buf), "%d", (int)getpid());
432 assert(nr > 0 && nr < (int)sizeof(buf));
433 rb_str_buf_cat(c->log_buf, buf, nr);
436 static void append_eval(struct clogger *c, VALUE str)
438 int state = -1;
439 VALUE rv = rb_eval_string_protect(RSTRING_PTR(str), &state);
441 rv = state == 0 ? rb_obj_as_string(rv) : g_dash;
442 rb_str_buf_append(c->log_buf, rv);
445 static void append_cookie(struct clogger *c, VALUE key)
447 VALUE cookie;
449 if (c->cookies == Qfalse)
450 c->cookies = rb_hash_aref(c->env, g_rack_request_cookie_hash);
452 if (NIL_P(c->cookies)) {
453 cookie = g_dash;
454 } else {
455 cookie = rb_hash_aref(c->cookies, key);
456 if (NIL_P(cookie))
457 cookie = g_dash;
459 rb_str_buf_append(c->log_buf, cookie);
462 static void append_request_env(struct clogger *c, VALUE key)
464 VALUE tmp = rb_hash_aref(c->env, key);
466 tmp = NIL_P(tmp) ? g_dash : byte_xs(tmp);
467 rb_str_buf_append(c->log_buf, tmp);
470 static void append_response(struct clogger *c, VALUE key)
472 VALUE v;
474 assert(rb_obj_is_kind_of(c->headers, cHeaderHash) && "not HeaderHash");
476 v = rb_funcall(c->headers, sq_brace_id, 1, key);
477 v = NIL_P(v) ? g_dash : byte_xs(v);
478 rb_str_buf_append(c->log_buf, v);
481 static void special_var(struct clogger *c, enum clogger_special var)
483 switch (var) {
484 case CL_SP_body_bytes_sent:
485 append_body_bytes_sent(c);
486 break;
487 case CL_SP_status:
488 append_status(c);
489 break;
490 case CL_SP_request:
491 append_request(c);
492 break;
493 case CL_SP_request_length:
494 append_request_length(c);
495 break;
496 case CL_SP_response_length:
497 if (c->body_bytes_sent == 0)
498 rb_str_buf_append(c->log_buf, g_dash);
499 else
500 append_body_bytes_sent(c);
501 break;
502 case CL_SP_ip:
503 append_ip(c);
504 break;
505 case CL_SP_pid:
506 append_pid(c);
507 break;
508 case CL_SP_request_uri:
509 append_request_uri(c);
513 static VALUE cwrite(struct clogger *c)
515 const VALUE ops = c->fmt_ops;
516 const VALUE *ary = RARRAY_PTR(ops);
517 long i = RARRAY_LEN(ops);
518 VALUE dst = c->log_buf;
520 rb_str_set_len(dst, 0);
522 for (; --i >= 0; ary++) {
523 const VALUE *op = RARRAY_PTR(*ary);
524 enum clogger_opcode opcode = FIX2INT(op[0]);
526 switch (opcode) {
527 case CL_OP_LITERAL:
528 rb_str_buf_append(dst, op[1]);
529 break;
530 case CL_OP_REQUEST:
531 append_request_env(c, op[1]);
532 break;
533 case CL_OP_RESPONSE:
534 append_response(c, op[1]);
535 break;
536 case CL_OP_SPECIAL:
537 special_var(c, FIX2INT(op[1]));
538 break;
539 case CL_OP_EVAL:
540 append_eval(c, op[1]);
541 break;
542 case CL_OP_TIME_LOCAL:
543 case CL_OP_TIME_UTC:
544 append_time(c, opcode, op[1]);
545 break;
546 case CL_OP_REQUEST_TIME:
547 append_request_time_fmt(c, op);
548 break;
549 case CL_OP_TIME:
550 append_time_fmt(c, op);
551 break;
552 case CL_OP_COOKIE:
553 append_cookie(c, op[1]);
554 break;
558 if (c->fd >= 0) {
559 write_full(c->fd, RSTRING_PTR(dst), RSTRING_LEN(dst));
560 } else {
561 VALUE logger = c->logger;
563 if (NIL_P(logger))
564 logger = rb_hash_aref(c->env, g_rack_errors);
565 rb_funcall(logger, ltlt_id, 1, dst);
568 return Qnil;
572 * call-seq:
573 * Clogger.new(app, :logger => $stderr, :format => string) => obj
575 * Creates a new Clogger object that wraps +app+. +:logger+ may
576 * be any object that responds to the "<<" method with a string argument.
578 static VALUE clogger_init(int argc, VALUE *argv, VALUE self)
580 struct clogger *c = clogger_get(self);
581 VALUE o = Qnil;
582 VALUE fmt = rb_const_get(mFormat, rb_intern("Common"));
584 rb_scan_args(argc, argv, "11", &c->app, &o);
585 c->fd = -1;
586 c->logger = Qnil;
587 c->reentrant = -1; /* auto-detect */
589 if (TYPE(o) == T_HASH) {
590 VALUE tmp;
592 c->logger = rb_hash_aref(o, ID2SYM(rb_intern("logger")));
593 if (!NIL_P(c->logger)) {
594 rb_rescue(obj_enable_sync, c->logger, 0, 0);
595 c->fd = raw_fd(rb_rescue(obj_fileno, c->logger, 0, 0));
598 tmp = rb_hash_aref(o, ID2SYM(rb_intern("format")));
599 if (!NIL_P(tmp))
600 fmt = tmp;
602 tmp = rb_hash_aref(o, ID2SYM(rb_intern("reentrant")));
603 switch (TYPE(tmp)) {
604 case T_TRUE:
605 c->reentrant = 1;
606 break;
607 case T_FALSE:
608 c->reentrant = 0;
609 case T_NIL:
610 break;
611 default:
612 rb_raise(rb_eArgError, ":reentrant must be boolean");
616 init_buffers(c);
617 c->fmt_ops = rb_funcall(self, rb_intern("compile_format"), 2, fmt, o);
619 if (Qtrue == rb_funcall(self, rb_intern("need_response_headers?"),
620 1, c->fmt_ops))
621 c->need_resp = 1;
622 if (Qtrue == rb_funcall(self, rb_intern("need_wrap_body?"),
623 1, c->fmt_ops))
624 c->wrap_body = 1;
626 return self;
629 static VALUE body_iter_i(VALUE str, VALUE memop)
631 off_t *len = (off_t *)memop;
633 str = rb_obj_as_string(str);
634 *len += RSTRING_LEN(str);
636 return rb_yield(str);
639 static VALUE wrap_each(struct clogger *c)
641 c->body_bytes_sent = 0;
642 rb_iterate(rb_each, c->body, body_iter_i, (VALUE)&c->body_bytes_sent);
644 return c->body;
648 * call-seq:
649 * clogger.each { |part| socket.write(part) }
651 * Delegates the body#each call to the underlying +body+ object
652 * while tracking the number of bytes yielded. This will log
653 * the request.
655 static VALUE clogger_each(VALUE self)
657 struct clogger *c = clogger_get(self);
659 rb_need_block();
661 return rb_ensure(wrap_each, (VALUE)c, cwrite, (VALUE)c);
665 * call-seq:
666 * clogger.close
668 * Delegates the body#close call to the underlying +body+ object.
669 * This is only used when Clogger is wrapping the +body+ of a Rack
670 * response and should be automatically called by the web server.
672 static VALUE clogger_close(VALUE self)
674 struct clogger *c = clogger_get(self);
676 if (rb_respond_to(c->body, close_id))
677 return rb_funcall(c->body, close_id, 0);
678 return Qnil;
681 /* :nodoc: */
682 static VALUE clogger_fileno(VALUE self)
684 struct clogger *c = clogger_get(self);
686 return c->fd < 0 ? Qnil : INT2NUM(c->fd);
689 static VALUE ccall(struct clogger *c, VALUE env)
691 VALUE rv;
693 gettimeofday(&c->tv_start, NULL);
694 c->env = env;
695 c->cookies = Qfalse;
696 rv = rb_funcall(c->app, call_id, 1, env);
697 if (TYPE(rv) == T_ARRAY && RARRAY_LEN(rv) == 3) {
698 VALUE *tmp = RARRAY_PTR(rv);
700 c->status = tmp[0];
701 c->headers = tmp[1];
702 c->body = tmp[2];
704 rv = rb_ary_new4(3, tmp);
705 if (c->need_resp &&
706 ! rb_obj_is_kind_of(tmp[1], cHeaderHash)) {
707 c->headers = rb_funcall(cHeaderHash, new_id, 1, tmp[1]);
708 rb_ary_store(rv, 1, c->headers);
710 } else {
711 volatile VALUE tmp = rb_inspect(rv);
713 c->status = INT2FIX(500);
714 c->headers = c->body = rb_ary_new();
715 cwrite(c);
716 rb_raise(rb_eTypeError,
717 "app response not a 3 element Array: %s",
718 RSTRING_PTR(tmp));
721 return rv;
725 * call-seq:
726 * clogger.call(env) => [ status, headers, body ]
728 * calls the wrapped Rack application with +env+, returns the
729 * [status, headers, body ] tuplet required by Rack.
731 static VALUE clogger_call(VALUE self, VALUE env)
733 struct clogger *c = clogger_get(self);
734 VALUE rv;
736 env = rb_check_convert_type(env, T_HASH, "Hash", "to_hash");
738 if (c->wrap_body) {
739 if (c->reentrant < 0) {
740 VALUE tmp = rb_hash_aref(env, g_rack_multithread);
741 c->reentrant = Qfalse == tmp ? 0 : 1;
743 if (c->reentrant) {
744 self = rb_obj_dup(self);
745 c = clogger_get(self);
748 rv = ccall(c, env);
749 assert(!OBJ_FROZEN(rv) && "frozen response array");
750 rb_ary_store(rv, 2, self);
752 return rv;
755 rv = ccall(c, env);
756 cwrite(c);
758 return rv;
761 /* :nodoc */
762 static VALUE clogger_init_copy(VALUE clone, VALUE orig)
764 struct clogger *a = clogger_get(orig);
765 struct clogger *b = clogger_get(clone);
767 memcpy(b, a, sizeof(struct clogger));
768 init_buffers(b);
770 return clone;
773 #define CONST_GLOBAL_STR2(var, val) do { \
774 g_##var = rb_obj_freeze(rb_str_new(val, sizeof(val) - 1)); \
775 rb_global_variable(&g_##var); \
776 } while (0)
778 #define CONST_GLOBAL_STR(val) CONST_GLOBAL_STR2(val, #val)
780 void Init_clogger_ext(void)
782 VALUE tmp;
784 ltlt_id = rb_intern("<<");
785 call_id = rb_intern("call");
786 each_id = rb_intern("each");
787 close_id = rb_intern("close");
788 to_i_id = rb_intern("to_i");
789 to_s_id = rb_intern("to_s");
790 size_id = rb_intern("size");
791 sq_brace_id = rb_intern("[]");
792 new_id = rb_intern("new");
793 cClogger = rb_define_class("Clogger", rb_cObject);
794 mFormat = rb_define_module_under(cClogger, "Format");
795 rb_define_alloc_func(cClogger, clogger_alloc);
796 rb_define_method(cClogger, "initialize", clogger_init, -1);
797 rb_define_method(cClogger, "initialize_copy", clogger_init_copy, 1);
798 rb_define_method(cClogger, "call", clogger_call, 1);
799 rb_define_method(cClogger, "each", clogger_each, 0);
800 rb_define_method(cClogger, "close", clogger_close, 0);
801 rb_define_method(cClogger, "fileno", clogger_fileno, 0);
802 rb_define_method(cClogger, "wrap_body?", clogger_wrap_body, 0);
803 rb_define_method(cClogger, "reentrant?", clogger_reentrant, 0);
804 CONST_GLOBAL_STR(REMOTE_ADDR);
805 CONST_GLOBAL_STR(HTTP_X_FORWARDED_FOR);
806 CONST_GLOBAL_STR(REQUEST_METHOD);
807 CONST_GLOBAL_STR(PATH_INFO);
808 CONST_GLOBAL_STR(QUERY_STRING);
809 CONST_GLOBAL_STR(REQUEST_URI);
810 CONST_GLOBAL_STR(HTTP_VERSION);
811 CONST_GLOBAL_STR2(rack_errors, "rack.errors");
812 CONST_GLOBAL_STR2(rack_input, "rack.input");
813 CONST_GLOBAL_STR2(rack_multithread, "rack.multithread");
814 CONST_GLOBAL_STR2(dash, "-");
815 CONST_GLOBAL_STR2(space, " ");
816 CONST_GLOBAL_STR2(question_mark, "?");
817 CONST_GLOBAL_STR2(rack_request_cookie_hash, "rack.request.cookie_hash");
819 tmp = rb_const_get(rb_cObject, rb_intern("Rack"));
820 tmp = rb_const_get(tmp, rb_intern("Utils"));
821 cHeaderHash = rb_const_get(tmp, rb_intern("HeaderHash"));