patch: add error log handler, expose parsed_uri and more
"Matthew Kent" <[email protected]> Sun, 29 Jul 2007 17:15:52 -0700 (PDT)
| Newsgroups | gmane.comp.apache.mod-ruby |
|---|---|
| Message-ID | <[email protected]> |
------=_20070729171552_39090 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Bigger patch now that includes the last couple I sent to the list and add= s a RubyErrorLogHandler hook for APACHE2 which can be used to log per request errors with log_error(request obj, error obj) eg: a request which results in a 404 invokes the log_error handler provid= ing e.file -> core.c e.line -> 3631 e.level -> 3 e.status -> 0 e.errstr -> File does not exist: /home/mkent/work/httpd224/htdocs/home Ruby errors in log_error get written to disk properly since they don't happen in a per request context. And since ap_hook_error_log is called at the end of the code that writes to ErrorLog, you'll always have a copy of the error even if the hook somehow fails. Seems to work fine here in testing (apache benched it to death with hundreds of thousands of requests). Tested with apache 1.3.37 as well. Willing to break these patches out into series and do documentation if there's interest in this. --=20 Matthew Kent <[email protected]> http://magoazul.com ------=_20070729171552_39090 Content-Type: text/x-patch; name="mod_ruby-r133-additions_complete.patch" Content-Disposition: attachment; filename="mod_ruby-r133-additions_complete.patch" Content-Transfer-Encoding: quoted-printable does the following: - expose more useful constants - expose parsed uri data - adds a per request error log hook - exposes a few more useful data points in core httpd structs mkent@ diff -urN mod_ruby_orig/apachelib.c mod_ruby/apachelib.c --- mod_ruby_orig/apachelib.c 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/apachelib.c 2007-07-25 23:16:37.000000000 -0700 @@ -389,6 +389,32 @@ rb_define_const(rb_mApache, "REMOTE_DOUBLE_REV", INT2NUM(REMOTE_DOUBLE_REV)); =20 +#ifdef APACHE2 + rb_define_const(rb_mApache, "AP_CONN_UNKNOWN", + INT2NUM(AP_CONN_UNKNOWN)); + rb_define_const(rb_mApache, "AP_CONN_CLOSE", + INT2NUM(AP_CONN_CLOSE)); + rb_define_const(rb_mApache, "AP_CONN_KEEPALIVE", + INT2NUM(AP_CONN_KEEPALIVE)); +#endif + + rb_define_const(rb_mApache, "APLOG_EMERG", + INT2NUM(APLOG_EMERG)); + rb_define_const(rb_mApache, "APLOG_ALERT", + INT2NUM(APLOG_ALERT)); + rb_define_const(rb_mApache, "APLOG_CRIT", + INT2NUM(APLOG_CRIT)); + rb_define_const(rb_mApache, "APLOG_ERR", + INT2NUM(APLOG_ERR)); + rb_define_const(rb_mApache, "APLOG_WARNING", + INT2NUM(APLOG_WARNING)); + rb_define_const(rb_mApache, "APLOG_NOTICE", + INT2NUM(APLOG_NOTICE)); + rb_define_const(rb_mApache, "APLOG_INFO", + INT2NUM(APLOG_INFO)); + rb_define_const(rb_mApache, "APLOG_DEBUG", + INT2NUM(APLOG_DEBUG)); + /* Policy constants for setup_client_block() */ rb_define_const(rb_mApache, "REQUEST_NO_BODY", INT2NUM(REQUEST_NO_BODY)); @@ -425,6 +451,8 @@ #ifdef APACHE2 rb_init_apache_bucket(); #endif + rb_init_apache_uri(); + rb_init_apache_error(); } =20 /* diff -urN mod_ruby_orig/apachelib.h mod_ruby/apachelib.h --- mod_ruby_orig/apachelib.h 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/apachelib.h 2007-07-25 23:16:37.000000000 -0700 @@ -80,6 +80,16 @@ void rb_init_apache_bucket(); #endif =20 +/* uri.c */ +extern VALUE rb_cApacheUri; +void rb_init_apache_uri(); +VALUE rb_apache_uri_new(uri_components *uri); + +/* error.c */ +extern VALUE rb_cApacheError; +void rb_init_apache_error(); +VALUE rb_apache_error_new(request_rec *r, error_log_data *error); + /* --- Libapreq Extensions ------------------------------ */ =20 extern VALUE rb_eApacheRequestError; diff -urN mod_ruby_orig/connection.c mod_ruby/connection.c --- mod_ruby_orig/connection.c 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/connection.c 2007-07-25 23:16:37.000000000 -0700 @@ -36,6 +36,13 @@ } =20 DEFINE_BOOL_ATTR_READER(connection_aborted, conn_rec, aborted); +/* in APACHE1: -1 fatal error, 0 undecided, 1 yes=20 + * APACHE2: 0 AP_CONN_UNKNOWN, 1 AP_CONN_CLOSE, 2 AP_CONN_KEEPALIVE + * fun... */ +DEFINE_INT_ATTR_READER(connection_keepalive, conn_rec, keepalive); +/* -1 yes/failure, 0 not yet, 1 yes/success */ +DEFINE_INT_ATTR_READER(connection_double_reverse, conn_rec, double_rever= se); +DEFINE_INT_ATTR_READER(connection_keepalives, conn_rec, keepalives); DEFINE_STRING_ATTR_READER(connection_remote_ip, conn_rec, remote_ip); DEFINE_STRING_ATTR_READER(connection_remote_host, conn_rec, remote_host)= ; DEFINE_STRING_ATTR_READER(connection_remote_logname, conn_rec, remote_lo= gname); @@ -124,12 +131,39 @@ #endif } =20 +#ifdef APACHE2 +static VALUE connection_notes(VALUE self) +{ + conn_rec *conn; + + Data_Get_Struct(self, conn_rec, conn); + if (conn->notes) { + return rb_apache_table_new(conn->notes); + } + else { + return Qnil; + } +} +#else +static VALUE connection_notes(VALUE self) +{ + rb_notimplement(); + return Qnil; +} +#endif + void rb_init_apache_connection() { rb_cApacheConnection =3D rb_define_class_under(rb_mApache, "Connecti= on", rb_cObject); rb_undef_method(CLASS_OF(rb_cApacheConnection), "new"); rb_define_method(rb_cApacheConnection, "aborted?", connection_aborted, 0); + rb_define_method(rb_cApacheConnection, "keepalive", + connection_keepalive, 0); + rb_define_method(rb_cApacheConnection, "double_reverse", + connection_double_reverse, 0); + rb_define_method(rb_cApacheConnection, "keepalives", + connection_keepalives, 0); rb_define_method(rb_cApacheConnection, "remote_ip", connection_remote_ip, 0); rb_define_method(rb_cApacheConnection, "remote_host", @@ -150,6 +184,8 @@ connection_local_host, 0); rb_define_method(rb_cApacheConnection, "local_port", connection_local_port, 0); + rb_define_method(rb_cApacheConnection, "notes", + connection_notes, 0); } =20 /* vim: set filetype=3Dc ts=3D8 sw=3D4 : */ diff -urN mod_ruby_orig/error.c mod_ruby/error.c --- mod_ruby_orig/error.c 1969-12-31 16:00:00.000000000 -0800 +++ mod_ruby/error.c 2007-07-25 23:27:49.000000000 -0700 @@ -0,0 +1,58 @@ +/* + * $Id$ + * Copyright (C) 2001 Shugo Maeda <[email protected]> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in th= e + * documentation and/or other materials provided with the distributio= n. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' A= ND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PU= RPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIA= BLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUE= NTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOO= DS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S= TRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY= WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY O= F + * SUCH DAMAGE. + */ + +#include "mod_ruby.h" +#include "apachelib.h" + +VALUE rb_cApacheError; + +VALUE rb_apache_error_new(request_rec *r, error_log_data *error) +{ + if (error =3D=3D NULL) + return Qnil; + return Data_Wrap_Struct(rb_cApacheError, NULL, NULL, error); +} + +DEFINE_STRING_ATTR_READER(error_file, error_log_data, file); +DEFINE_INT_ATTR_READER(error_line, error_log_data, line); +DEFINE_INT_ATTR_READER(error_level, error_log_data, level); +DEFINE_INT_ATTR_READER(error_status, error_log_data, status); +DEFINE_STRING_ATTR_READER(error_string, error_log_data, error); + +void rb_init_apache_error() +{ + rb_cApacheError =3D rb_define_class_under(rb_mApache, "ErrorLogItem"= , rb_cObject); + rb_define_method(rb_cApacheError, "file", error_file, 0); + rb_define_method(rb_cApacheError, "line", error_line, 0); + rb_define_method(rb_cApacheError, "level", error_level, 0); + rb_define_method(rb_cApacheError, "status", error_status, 0); + rb_define_method(rb_cApacheError, "errstr", error_string, 0); + rb_define_method(rb_cApacheError, "msg", error_string, 0); + rb_define_method(rb_cApacheError, "string", error_string, 0); +} + +/* vim: set filetype=3Dc ts=3D8 sw=3D4 : */ diff -urN mod_ruby_orig/Makefile.in mod_ruby/Makefile.in --- mod_ruby_orig/Makefile.in 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/Makefile.in 2007-07-25 23:16:37.000000000 -0700 @@ -98,6 +98,8 @@ paramtable.@OBJEXT@ \ multival.@OBJEXT@ \ bucket.@OBJEXT@ \ + uri.@OBJEXT@ \ + error.@OBJEXT@ \ apache_request.@OBJEXT@ \ apache_multipart_buffer.@OBJEXT@ \ apache_cookie.@OBJEXT@ @@ -183,6 +185,8 @@ paramtable.@OBJEXT@: paramtable.c mod_ruby.h apachelib.h multival.@OBJEXT@: multival.c mod_ruby.h apachelib.h bucket.@OBJEXT@: bucket.c mod_ruby.h apachelib.h +uri.@OBJEXT@: uri.c mod_ruby.h apachelib.h +error.@OBJEXT@: error.c mod_ruby.h apachelib.h =20 apache_request.@OBJEXT@: apache_request.c mod_ruby.h apache_request.h apache_multipart_buffer.@OBJEXT@: apache_multipart_buffer.c mod_ruby.h a= pache_request.h apache_multipart_buffer.h diff -urN mod_ruby_orig/mod_ruby.c mod_ruby/mod_ruby.c --- mod_ruby_orig/mod_ruby.c 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/mod_ruby.c 2007-07-29 15:43:25.000000000 -0700 @@ -198,6 +198,10 @@ "set fixup handler object"), AP_INIT_TAKE1("RubyLogHandler", ruby_cmd_log_handler, NULL, OR_ALL, "set log handler object"), +#ifdef APACHE2 + AP_INIT_TAKE1("RubyErrorLogHandler", ruby_cmd_error_log_handler, NUL= L, OR_ALL, + "set log handler object"), +#endif AP_INIT_TAKE1("RubyHeaderParserHandler", ruby_cmd_header_parser_hand= ler, NULL, OR_ALL, "set header parser object"), @@ -220,6 +224,7 @@ =20 static int ruby_startup(pool*, pool*, pool*, server_rec*); static void ruby_child_init(pool*, server_rec*); +static void ruby_error_log_handler(const char*, int, int, apr_status_t, = const server_rec*, const request_rec*, pool*, const char*); =20 static void ruby_register_hooks(pool *p) { @@ -233,6 +238,9 @@ ap_hook_type_checker(ruby_type_handler, NULL, NULL, APR_HOOK_MIDDLE)= ; ap_hook_fixups(ruby_fixup_handler, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_log_transaction(ruby_log_handler, NULL, NULL, APR_HOOK_MIDDL= E); +#ifdef APACHE2 + ap_hook_error_log(ruby_error_log_handler, NULL, NULL, APR_HOOK_MIDDL= E); +#endif ap_hook_child_init(ruby_child_init, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_post_read_request(ruby_post_read_request_handler, NULL, NULL, APR_HOOK_MIDDLE); @@ -851,7 +859,7 @@ return r; } =20 -static int ruby_handler(request_rec *, array_header *, ID, int, int); +static int ruby_handler(request_rec *, array_header *, error_log_data *,= ID, int, int); =20 #ifdef APACHE2 static void ruby_child_init(pool *p, server_rec *s) @@ -916,7 +924,7 @@ =20 r =3D fake_request_rec(s, p, "RubyChildInitHandler"); conf =3D get_server_config(r->server); - ruby_handler(r, conf->ruby_child_init_handler, + ruby_handler(r, conf->ruby_child_init_handler, NULL, rb_intern("child_init"), 0, 0); } =20 @@ -1115,10 +1123,14 @@ ruby_dir_config *dconf; =20 if (r->request_config) { - rconf =3D apr_palloc(r->pool, sizeof(ruby_request_config)); - rconf->saved_env =3D save_env(r->pool); - rconf->request_object =3D Qnil; - ap_set_module_config(r->request_config, &ruby_module, rconf); + rconf =3D get_request_config(r); + /* may already have request object from successive handler calls= */ + if (rconf =3D=3D NULL || NIL_P(rconf->request_object)) { + rconf =3D apr_palloc(r->pool, sizeof(ruby_request_config)); + rconf->saved_env =3D save_env(r->pool); + rconf->request_object =3D Qnil; + ap_set_module_config(r->request_config, &ruby_module, rconf)= ; + } } dconf =3D get_dir_config(r); sconf =3D get_server_config(r->server); @@ -1184,6 +1196,7 @@ typedef struct handler_0_arg { request_rec *r; char *handler; + error_log_data *err; ID mid; } handler_0_arg_t; =20 @@ -1191,13 +1204,19 @@ { handler_0_arg_t *ha =3D (handler_0_arg_t *) arg; request_rec *r =3D ha->r; + error_log_data *err =3D ha->err; char *handler =3D ha->handler; ID mid =3D ha->mid; VALUE ret; int state; =20 - ret =3D rb_protect_funcall(rb_eval_string(handler), mid, &state, - 1, rb_request); + if (err) { + ret =3D rb_protect_funcall(rb_eval_string(handler), mid, &state, + 2, rb_request, rb_apache_error_new(r, err)); + } else { + ret =3D rb_protect_funcall(rb_eval_string(handler), mid, &state, + 1, rb_request); + } if (state) { if (state =3D=3D TAG_RAISE && rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) { @@ -1222,6 +1241,7 @@ typedef struct handler_internal_arg { request_rec *r; array_header *handlers_arr; + error_log_data *err; ID mid; int run_all; int flush; @@ -1232,6 +1252,7 @@ { request_rec *r =3D iarg->r; array_header *handlers_arr =3D iarg->handlers_arr; + error_log_data *err =3D iarg->err; ID mid =3D iarg->mid; int run_all =3D iarg->run_all; int flush =3D iarg->flush; @@ -1259,6 +1280,7 @@ for (i =3D 0; i < handlers_len; i++) { arg.r =3D r; arg.handler =3D handlers[i]; + arg.err =3D err; arg.mid =3D mid; ap_soft_timeout("call ruby handler", r); timeout =3D sconf->timeout; @@ -1289,8 +1311,9 @@ } =20 static int ruby_handler(request_rec *r, - array_header *handlers_arr, ID mid, - int run_all, int flush) + array_header *handlers_arr, + error_log_data *error, + ID mid, int run_all, int flush) { handler_internal_arg_t *arg; =20 @@ -1300,6 +1323,7 @@ arg =3D apr_palloc(r->pool, sizeof(handler_internal_arg_t)); arg->r =3D r; arg->handlers_arr =3D handlers_arr; + arg->err =3D error; arg->mid =3D mid; arg->run_all =3D run_all; arg->flush =3D flush; @@ -1340,7 +1364,7 @@ } #endif dconf =3D get_dir_config(r); - retval =3D ruby_handler(r, dconf->ruby_handler, rb_intern("handler")= , 0, 1); + retval =3D ruby_handler(r, dconf->ruby_handler, NULL, rb_intern("han= dler"), 0, 1); #ifdef APACHE2 if (retval =3D=3D DECLINED && r->finfo.filetype =3D=3D APR_DIR) r->handler =3D DIR_MAGIC_TYPE; @@ -1352,7 +1376,7 @@ { ruby_dir_config *dconf =3D get_dir_config(r); =20 - return ruby_handler(r, dconf->ruby_trans_handler, + return ruby_handler(r, dconf->ruby_trans_handler, NULL, rb_intern("translate_uri"), 0, 0); } =20 @@ -1362,7 +1386,7 @@ int retval; =20 if (dconf->ruby_authen_handler =3D=3D NULL) return DECLINED; - retval =3D ruby_handler(r, dconf->ruby_authen_handler, + retval =3D ruby_handler(r, dconf->ruby_authen_handler, NULL, rb_intern("authenticate"), 0, 0); return retval; } @@ -1371,7 +1395,7 @@ { ruby_dir_config *dconf =3D get_dir_config(r); =20 - return ruby_handler(r, dconf->ruby_authz_handler, + return ruby_handler(r, dconf->ruby_authz_handler, NULL, rb_intern("authorize"), 0, 0); } =20 @@ -1379,7 +1403,7 @@ { ruby_dir_config *dconf =3D get_dir_config(r); =20 - return ruby_handler(r, dconf->ruby_access_handler, + return ruby_handler(r, dconf->ruby_access_handler, NULL, rb_intern("check_access"), 1, 0); } =20 @@ -1388,7 +1412,7 @@ ruby_dir_config *dconf =3D get_dir_config(r); =20 if (dconf->ruby_type_handler =3D=3D NULL) return DECLINED; - return ruby_handler(r, dconf->ruby_type_handler, + return ruby_handler(r, dconf->ruby_type_handler, NULL, rb_intern("find_types"), 0, 0); } =20 @@ -1397,7 +1421,7 @@ ruby_dir_config *dconf =3D get_dir_config(r); =20 if (dconf->ruby_fixup_handler =3D=3D NULL) return DECLINED; - return ruby_handler(r, dconf->ruby_fixup_handler, + return ruby_handler(r, dconf->ruby_fixup_handler, NULL, rb_intern("fixup"), 1, 0); } =20 @@ -1406,7 +1430,7 @@ ruby_dir_config *dconf =3D get_dir_config(r); =20 if (dconf->ruby_log_handler =3D=3D NULL) return DECLINED; - return ruby_handler(r, dconf->ruby_log_handler, + return ruby_handler(r, dconf->ruby_log_handler, NULL, rb_intern("log_transaction"), 1, 0); } =20 @@ -1418,13 +1442,13 @@ =20 if (dconf->ruby_init_handler && ap_table_get(r->notes, "ruby_init_ran") =3D=3D NULL) { - retval =3D ruby_handler(r, dconf->ruby_init_handler, + retval =3D ruby_handler(r, dconf->ruby_init_handler, NULL, rb_intern("init"), 1, 0); if (retval !=3D OK && retval !=3D DECLINED) return retval; } if (dconf->ruby_header_parser_handler =3D=3D NULL) return DECLINED; - return ruby_handler(r, dconf->ruby_header_parser_handler, + return ruby_handler(r, dconf->ruby_header_parser_handler, NULL, rb_intern("header_parse"), 1, 0); } #endif @@ -1434,7 +1458,7 @@ request_rec *r =3D (request_rec *) data; ruby_dir_config *dconf =3D get_dir_config(r); =20 - ruby_handler(r, dconf->ruby_cleanup_handler, + ruby_handler(r, dconf->ruby_cleanup_handler, NULL, rb_intern("cleanup"), 1, 0); APR_CLEANUP_RETURN_SUCCESS(); } @@ -1448,16 +1472,43 @@ apr_pool_cleanup_null); =20 if (dconf->ruby_init_handler) { - retval =3D ruby_handler(r, dconf->ruby_init_handler, + retval =3D ruby_handler(r, dconf->ruby_init_handler, NULL, rb_intern("init"), 1, 0); apr_table_set(r->notes, "ruby_init_ran", "true"); if (retval !=3D OK && retval !=3D DECLINED) return retval; } - return ruby_handler(r, dconf->ruby_post_read_request_handler, + return ruby_handler(r, dconf->ruby_post_read_request_handler, NULL, rb_intern("post_read_request"), 1, 0); } =20 +#ifdef APACHE2 +static void ruby_error_log_handler(const char *file, int line, int level= , apr_status_t status, const server_rec *s, const request_rec *r, apr_poo= l_t *pool, const char *error) { + ruby_dir_config *dconf; + error_log_data *e; +=20 + /* only interested in errors produced as the result of requests. + *=20 + * [this handler is called multiple times during startup but since t= his is + * prior to config stage, we'll ignore them] */ + if (r =3D=3D NULL) return; + + dconf =3D get_dir_config(r); + if (dconf->ruby_error_log_handler =3D=3D NULL) return; + =20 + e =3D apr_palloc(r->pool, sizeof(error_log_data)); + e->file =3D file; + e->line =3D line; + e->level =3D level; + e->status =3D status; + e->error =3D error; + + ruby_handler((request_rec *) r, dconf->ruby_error_log_handler, e, + rb_intern("log_error"), 1, 0); + return; +} +#endif + /* * Local variables: * mode: C diff -urN mod_ruby_orig/mod_ruby.h mod_ruby/mod_ruby.h --- mod_ruby_orig/mod_ruby.h 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/mod_ruby.h 2007-07-29 16:12:06.000000000 -0700 @@ -83,6 +83,7 @@ #include "apr_tables.h" =20 #define ap_pool apr_pool_t +#define uri_components apr_uri_t =20 typedef apr_pool_t pool; typedef apr_array_header_t array_header; @@ -193,6 +194,7 @@ array_header *ruby_type_handler; array_header *ruby_fixup_handler; array_header *ruby_log_handler; + array_header *ruby_error_log_handler; array_header *ruby_header_parser_handler; array_header *ruby_post_read_request_handler; array_header *ruby_init_handler; @@ -210,6 +212,18 @@ VALUE request_object; } ruby_request_config; =20 +typedef struct { + const char *file; + int line; + int level; +#ifdef APACHE2 + apr_status_t status; +#else + int status; +#endif + const char *error; +} error_log_data; + =20 #define MR_DEFAULT_TIMEOUT 0 #define MR_DEFAULT_SAFE_LEVEL 1 #define MR_DEFAULT_RESTRICT_DIRECTIVES 0 diff -urN mod_ruby_orig/request.c mod_ruby/request.c --- mod_ruby_orig/request.c 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/request.c 2007-07-25 23:16:37.000000000 -0700 @@ -56,6 +56,7 @@ VALUE subprocess_env; VALUE notes; VALUE finfo; + VALUE parsed_uri; VALUE attributes; VALUE error_message; VALUE exception; @@ -106,6 +107,10 @@ DEFINE_INT_ATTR_READER(fname, request_data, request->member) #define REQUEST_INT_ATTR_WRITER(fname, member) \ DEFINE_INT_ATTR_WRITER(fname, request_data, request->member) +#define REQUEST_BOOL_ATTR_READER(fname, member) \ + DEFINE_BOOL_ATTR_READER(fname, request_data, request->member) +#define REQUEST_BOOL_ATTR_WRITER(fname, member) \ + DEFINE_BOOL_ATTR_WRITER(fname, request_data, request->member) =20 static void request_mark(request_data *data) { @@ -119,6 +124,7 @@ rb_gc_mark(data->subprocess_env); rb_gc_mark(data->notes); rb_gc_mark(data->finfo); + rb_gc_mark(data->parsed_uri); rb_gc_mark(data->attributes); rb_gc_mark(data->error_message); rb_gc_mark(data->exception); @@ -182,6 +188,7 @@ data->subprocess_env =3D Qnil; data->notes =3D Qnil; data->finfo =3D Qnil; + data->parsed_uri =3D Qnil; data->attributes =3D Qnil; data->error_message =3D Qnil; data->exception =3D Qnil; @@ -605,6 +612,8 @@ REQUEST_STRING_ATTR_READER(request_get_status_line, status_line); REQUEST_STRING_ATTR_WRITER(request_set_status_line, status_line); REQUEST_STRING_ATTR_READER(request_the_request, the_request); +REQUEST_BOOL_ATTR_READER(request_get_assbackwards, assbackwards); +REQUEST_BOOL_ATTR_WRITER(request_set_assbackwards, assbackwards); REQUEST_STRING_ATTR_READER(request_request_method, method); REQUEST_INT_ATTR_READER(request_method_number, method_number); REQUEST_INT_ATTR_READER(request_get_allowed, allowed); @@ -876,6 +885,17 @@ return data->finfo; } =20 +static VALUE request_parsed_uri(VALUE self) +{ + request_data *data; + =20 + data =3D get_request_data(self); + if (NIL_P(data->parsed_uri)) { + data->parsed_uri =3D rb_apache_uri_new(&data->request->parsed_uri)= ; + } + return data->parsed_uri; +} + static VALUE request_attributes(VALUE self) { request_data *data; @@ -1049,6 +1069,14 @@ return type ? rb_tainted_str_new2(type) : Qnil; } =20 +static VALUE request_default_port(VALUE self) +{ + request_data *data; + + data =3D get_request_data(self); + return INT2NUM(ap_default_port(data->request)); +} + static VALUE request_remote_host(int argc, VALUE *argv, VALUE self) { request_data *data; @@ -2135,6 +2163,8 @@ rb_define_method(rb_cApacheRequest, "allowed=3D", request_set_allowe= d, 1); rb_define_method(rb_cApacheRequest, "the_request", request_the_request, 0); + rb_define_method(rb_cApacheRequest, "assbackwards?", request_get_ass= backwards, 0); + rb_define_method(rb_cApacheRequest, "assbackwards=3D", request_set_a= ssbackwards, 1); rb_define_method(rb_cApacheRequest, "header_only?", request_header_o= nly, 0); rb_define_method(rb_cApacheRequest, "args", request_get_args, 0); rb_define_method(rb_cApacheRequest, "args=3D", request_set_args, 1); @@ -2160,6 +2190,7 @@ request_subprocess_env, 0); rb_define_method(rb_cApacheRequest, "notes", request_notes, 0); rb_define_method(rb_cApacheRequest, "finfo", request_finfo, 0); + rb_define_method(rb_cApacheRequest, "parsed_uri", request_parsed_uri= , 0); rb_define_method(rb_cApacheRequest, "attributes", request_attributes= , 0); rb_define_method(rb_cApacheRequest, "setup_client_block", request_setup_client_block, -1); @@ -2180,6 +2211,7 @@ request_allow_overrides, 0); rb_define_method(rb_cApacheRequest, "default_type", request_default_type, 0); + rb_define_method(rb_cApacheRequest, "default_port", request_default_= port, 0); rb_define_method(rb_cApacheRequest, "remote_host", request_remote_host, -1); rb_define_method(rb_cApacheRequest, "remote_logname", diff -urN mod_ruby_orig/ruby_config.c mod_ruby/ruby_config.c --- mod_ruby_orig/ruby_config.c 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/ruby_config.c 2007-07-25 23:16:37.000000000 -0700 @@ -109,6 +109,9 @@ conf->ruby_type_handler =3D NULL; conf->ruby_fixup_handler =3D NULL; conf->ruby_log_handler =3D NULL; +#ifdef APACHE2 + conf->ruby_error_log_handler =3D NULL; +#endif conf->ruby_header_parser_handler =3D NULL; conf->ruby_post_read_request_handler =3D NULL; conf->ruby_init_handler =3D NULL; @@ -164,7 +167,11 @@ merge_handlers(p, base->ruby_fixup_handler, add->ruby_fixup_handler); new->ruby_log_handler =3D merge_handlers(p, base->ruby_log_handler, add->ruby_log_handler); - new->ruby_header_parser_handler =3D +#ifdef APACHE2 + new->ruby_error_log_handler =3D + merge_handlers(p, base->ruby_error_log_handler, add->ruby_error_log_han= dler); +#endif + new->ruby_header_parser_handler =3D merge_handlers(p, base->ruby_header_parser_handler, add->ruby_header_parser_handler); new->ruby_post_read_request_handler =3D @@ -472,6 +479,15 @@ return NULL; } =20 +#ifdef APACHE2 +const char *ruby_cmd_error_log_handler(cmd_parms *cmd, void *conf, const= char *arg) +{ + check_restrict_directives(cmd, conf) + push_handler(cmd->pool, ((ruby_dir_config *) conf)->ruby_error_log_h= andler, arg); + return NULL; +} +#endif + const char *ruby_cmd_header_parser_handler(cmd_parms *cmd, void *conf, const char *arg) { diff -urN mod_ruby_orig/ruby_config.h mod_ruby/ruby_config.h --- mod_ruby_orig/ruby_config.h 2007-07-22 20:52:47.000000000 -0700 +++ mod_ruby/ruby_config.h 2007-07-25 23:16:37.000000000 -0700 @@ -53,6 +53,9 @@ const char *ruby_cmd_type_handler(cmd_parms*, void*, const char*); const char *ruby_cmd_fixup_handler(cmd_parms*, void*, const char*); const char *ruby_cmd_log_handler(cmd_parms*, void*, const char*); +#ifdef APACHE2 +const char *ruby_cmd_error_log_handler(cmd_parms*, void*, const char*); +#endif const char *ruby_cmd_header_parser_handler(cmd_parms*, void*, const char= *); const char *ruby_cmd_post_read_request_handler(cmd_parms*, void*, const = char*); const char *ruby_cmd_init_handler(cmd_parms*, void*, const char*); diff -urN mod_ruby_orig/uri.c mod_ruby/uri.c --- mod_ruby_orig/uri.c 1969-12-31 16:00:00.000000000 -0800 +++ mod_ruby/uri.c 2007-07-25 23:16:37.000000000 -0700 @@ -0,0 +1,77 @@ +/* + * $Id$ + * Copyright (C) 2001 Shugo Maeda <[email protected]> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in th= e + * documentation and/or other materials provided with the distributio= n. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' A= ND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PU= RPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIA= BLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUE= NTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOO= DS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, S= TRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY= WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY O= F + * SUCH DAMAGE. + */ + +#include "mod_ruby.h" +#include "apachelib.h" + +VALUE rb_cApacheUri; + +VALUE rb_apache_uri_new(uri_components *uri) +{ + if (uri =3D=3D NULL) + return Qnil; + return Data_Wrap_Struct(rb_cApacheUri, NULL, NULL, uri); +} + +DEFINE_STRING_ATTR_READER(uri_scheme, uri_components, scheme); +DEFINE_STRING_ATTR_READER(uri_hostinfo, uri_components, hostinfo); +DEFINE_STRING_ATTR_READER(uri_user, uri_components, user); +DEFINE_STRING_ATTR_READER(uri_password, uri_components, password); +DEFINE_STRING_ATTR_READER(uri_hostname, uri_components, hostname); +DEFINE_STRING_ATTR_READER(uri_port_str, uri_components, port_str); +DEFINE_STRING_ATTR_READER(uri_path, uri_components, path); +DEFINE_STRING_ATTR_READER(uri_query, uri_components, query); +DEFINE_STRING_ATTR_READER(uri_fragment, uri_components, fragment); +DEFINE_INT_ATTR_READER(uri_port, uri_components, port); +DEFINE_BOOL_ATTR_READER(uri_is_initialized, uri_components, is_initializ= ed); +DEFINE_BOOL_ATTR_READER(uri_dns_looked_up, uri_components, dns_looked_up= ); +DEFINE_BOOL_ATTR_READER(uri_dns_resolved, uri_components, dns_resolved); + +/*=20 + * struct hostent *hostent; defined but unused by apr-util or apache at = present + */ + +void rb_init_apache_uri() +{ + rb_cApacheUri =3D rb_define_class_under(rb_mApache, "Uri", rb_cObjec= t); + rb_define_method(rb_cApacheUri, "scheme", uri_scheme, 0); + rb_define_method(rb_cApacheUri, "hostinfo", uri_hostinfo, 0); + rb_define_method(rb_cApacheUri, "user", uri_user, 0); + rb_define_method(rb_cApacheUri, "password", uri_password, 0); + rb_define_method(rb_cApacheUri, "hostname", uri_hostname, 0); + rb_define_method(rb_cApacheUri, "port_str", uri_port_str, 0); + rb_define_method(rb_cApacheUri, "path", uri_path, 0); + rb_define_method(rb_cApacheUri, "query", uri_query, 0); + rb_define_method(rb_cApacheUri, "fragment", uri_fragment, 0); + rb_define_method(rb_cApacheUri, "port", uri_port, 0); + rb_define_method(rb_cApacheUri, "is_initialized", uri_is_initialized= , 0); + rb_define_method(rb_cApacheUri, "initialized?", uri_is_initialized, = 0); + rb_define_method(rb_cApacheUri, "dns_looked_up?", uri_dns_looked_up,= 0); + rb_define_method(rb_cApacheUri, "dns_resolved?", uri_dns_resolved, 0= ); +} + +/* vim: set filetype=3Dc ts=3D8 sw=3D4 : */ ------=_20070729171552_39090--