Permalink
Browse files

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
Thanks, Matthew Kent.
  • Loading branch information...
1 parent f68e971 commit ce4d096f284a7c882a5709bb13a0b9e424e22807 shugo committed Jul 31, 2007
Showing with 353 additions and 24 deletions.
  1. +4 −0 Makefile.in
  2. +28 −0 apachelib.c
  3. +10 −0 apachelib.h
  4. +36 −0 connection.c
  5. +58 −0 error.c
  6. +74 −23 mod_ruby.c
  7. +14 −0 mod_ruby.h
  8. +32 −0 request.c
  9. +17 −1 ruby_config.c
  10. +3 −0 ruby_config.h
  11. +77 −0 uri.c
View
4 Makefile.in
@@ -98,6 +98,8 @@ OBJS = mod_ruby.@OBJEXT@ \
paramtable.@OBJEXT@ \
multival.@OBJEXT@ \
bucket.@OBJEXT@ \
+ uri.@OBJEXT@ \
+ error.@OBJEXT@ \
apache_request.@OBJEXT@ \
apache_multipart_buffer.@OBJEXT@ \
apache_cookie.@OBJEXT@
@@ -183,6 +185,8 @@ cookie.@OBJEXT@: cookie.c mod_ruby.h apachelib.h
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
apache_request.@OBJEXT@: apache_request.c mod_ruby.h apache_request.h
apache_multipart_buffer.@OBJEXT@: apache_multipart_buffer.c mod_ruby.h apache_request.h apache_multipart_buffer.h
View
28 apachelib.c
@@ -389,6 +389,32 @@ void rb_init_apache()
rb_define_const(rb_mApache, "REMOTE_DOUBLE_REV",
INT2NUM(REMOTE_DOUBLE_REV));
+#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 @@ void rb_init_apache()
#ifdef APACHE2
rb_init_apache_bucket();
#endif
+ rb_init_apache_uri();
+ rb_init_apache_error();
}
/*
View
10 apachelib.h
@@ -80,6 +80,16 @@ extern VALUE rb_cApacheBucket;
void rb_init_apache_bucket();
#endif
+/* 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 ------------------------------ */
extern VALUE rb_eApacheRequestError;
View
36 connection.c
@@ -36,6 +36,13 @@ VALUE rb_apache_connection_new(conn_rec *conn)
}
DEFINE_BOOL_ATTR_READER(connection_aborted, conn_rec, aborted);
+/* in APACHE1: -1 fatal error, 0 undecided, 1 yes
+ * 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_reverse);
+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_logname);
@@ -124,12 +131,39 @@ static VALUE connection_remote_port(VALUE self)
#endif
}
+#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 = rb_define_class_under(rb_mApache, "Connection", 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 @@ void rb_init_apache_connection()
connection_local_host, 0);
rb_define_method(rb_cApacheConnection, "local_port",
connection_local_port, 0);
+ rb_define_method(rb_cApacheConnection, "notes",
+ connection_notes, 0);
}
/* vim: set filetype=c ts=8 sw=4 : */
View
58 error.c
@@ -0,0 +1,58 @@
+/*
+ * $Id$
+ * Copyright (C) 2001 Shugo Maeda <shugo@modruby.net>
+ * 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 the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * 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 == 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 = 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=c ts=8 sw=4 : */
View
97 mod_ruby.c
@@ -198,6 +198,10 @@ static const command_rec ruby_cmds[] = {
"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, NULL, OR_ALL,
+ "set log handler object"),
+#endif
AP_INIT_TAKE1("RubyHeaderParserHandler", ruby_cmd_header_parser_handler,
NULL, OR_ALL,
"set header parser object"),
@@ -220,6 +224,7 @@ static const command_rec ruby_cmds[] = {
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*);
static void ruby_register_hooks(pool *p)
{
@@ -233,6 +238,9 @@ static void ruby_register_hooks(pool *p)
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_MIDDLE);
+#ifdef APACHE2
+ ap_hook_error_log(ruby_error_log_handler, NULL, NULL, APR_HOOK_MIDDLE);
+#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 @@ static request_rec *fake_request_rec(server_rec *s, pool *p, char *hook)
return r;
}
-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);
#ifdef APACHE2
static void ruby_child_init(pool *p, server_rec *s)
@@ -916,7 +924,7 @@ static void ruby_child_init(server_rec *s, pool *p)
r = fake_request_rec(s, p, "RubyChildInitHandler");
conf = 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);
}
@@ -1115,10 +1123,14 @@ static void per_request_init(request_rec *r)
ruby_dir_config *dconf;
if (r->request_config) {
- rconf = apr_palloc(r->pool, sizeof(ruby_request_config));
- rconf->saved_env = save_env(r->pool);
- rconf->request_object = Qnil;
- ap_set_module_config(r->request_config, &ruby_module, rconf);
+ rconf = get_request_config(r);
+ /* may already have request object from successive handler calls */
+ if (rconf == NULL || NIL_P(rconf->request_object)) {
+ rconf = apr_palloc(r->pool, sizeof(ruby_request_config));
+ rconf->saved_env = save_env(r->pool);
+ rconf->request_object = Qnil;
+ ap_set_module_config(r->request_config, &ruby_module, rconf);
+ }
}
dconf = get_dir_config(r);
sconf = get_server_config(r->server);
@@ -1184,20 +1196,27 @@ static void per_request_cleanup(request_rec *r, int flush)
typedef struct handler_0_arg {
request_rec *r;
char *handler;
+ error_log_data *err;
ID mid;
} handler_0_arg_t;
static VALUE ruby_handler_0(void *arg)
{
handler_0_arg_t *ha = (handler_0_arg_t *) arg;
request_rec *r = ha->r;
+ error_log_data *err = ha->err;
char *handler = ha->handler;
ID mid = ha->mid;
VALUE ret;
int state;
- ret = rb_protect_funcall(rb_eval_string(handler), mid, &state,
- 1, rb_request);
+ if (err) {
+ ret = rb_protect_funcall(rb_eval_string(handler), mid, &state,
+ 2, rb_request, rb_apache_error_new(r, err));
+ } else {
+ ret = rb_protect_funcall(rb_eval_string(handler), mid, &state,
+ 1, rb_request);
+ }
if (state) {
if (state == TAG_RAISE &&
rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
@@ -1222,6 +1241,7 @@ static VALUE ruby_handler_0(void *arg)
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 @@ static void *ruby_handler_internal(handler_internal_arg_t *iarg)
{
request_rec *r = iarg->r;
array_header *handlers_arr = iarg->handlers_arr;
+ error_log_data *err = iarg->err;
ID mid = iarg->mid;
int run_all = iarg->run_all;
int flush = iarg->flush;
@@ -1259,6 +1280,7 @@ static void *ruby_handler_internal(handler_internal_arg_t *iarg)
for (i = 0; i < handlers_len; i++) {
arg.r = r;
arg.handler = handlers[i];
+ arg.err = err;
arg.mid = mid;
ap_soft_timeout("call ruby handler", r);
timeout = sconf->timeout;
@@ -1289,8 +1311,9 @@ static void *ruby_handler_internal(handler_internal_arg_t *iarg)
}
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;
@@ -1300,6 +1323,7 @@ static int ruby_handler(request_rec *r,
arg = apr_palloc(r->pool, sizeof(handler_internal_arg_t));
arg->r = r;
arg->handlers_arr = handlers_arr;
+ arg->err = error;
arg->mid = mid;
arg->run_all = run_all;
arg->flush = flush;
@@ -1340,7 +1364,7 @@ static int ruby_object_handler(request_rec *r)
}
#endif
dconf = get_dir_config(r);
- retval = ruby_handler(r, dconf->ruby_handler, rb_intern("handler"), 0, 1);
+ retval = ruby_handler(r, dconf->ruby_handler, NULL, rb_intern("handler"), 0, 1);
#ifdef APACHE2
if (retval == DECLINED && r->finfo.filetype == APR_DIR)
r->handler = DIR_MAGIC_TYPE;
@@ -1352,7 +1376,7 @@ static int ruby_trans_handler(request_rec *r)
{
ruby_dir_config *dconf = get_dir_config(r);
- return ruby_handler(r, dconf->ruby_trans_handler,
+ return ruby_handler(r, dconf->ruby_trans_handler, NULL,
rb_intern("translate_uri"), 0, 0);
}
@@ -1362,7 +1386,7 @@ static int ruby_authen_handler(request_rec *r)
int retval;
if (dconf->ruby_authen_handler == NULL) return DECLINED;
- retval = ruby_handler(r, dconf->ruby_authen_handler,
+ retval = ruby_handler(r, dconf->ruby_authen_handler, NULL,
rb_intern("authenticate"), 0, 0);
return retval;
}
@@ -1371,15 +1395,15 @@ static int ruby_authz_handler(request_rec *r)
{
ruby_dir_config *dconf = get_dir_config(r);
- return ruby_handler(r, dconf->ruby_authz_handler,
+ return ruby_handler(r, dconf->ruby_authz_handler, NULL,
rb_intern("authorize"), 0, 0);
}
static int ruby_access_handler(request_rec *r)
{
ruby_dir_config *dconf = get_dir_config(r);
- return ruby_handler(r, dconf->ruby_access_handler,
+ return ruby_handler(r, dconf->ruby_access_handler, NULL,
rb_intern("check_access"), 1, 0);
}
@@ -1388,7 +1412,7 @@ static int ruby_type_handler(request_rec *r)
ruby_dir_config *dconf = get_dir_config(r);
if (dconf->ruby_type_handler == 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);
}
@@ -1397,7 +1421,7 @@ static int ruby_fixup_handler(request_rec *r)
ruby_dir_config *dconf = get_dir_config(r);
if (dconf->ruby_fixup_handler == 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);
}
@@ -1406,7 +1430,7 @@ static int ruby_log_handler(request_rec *r)
ruby_dir_config *dconf = get_dir_config(r);
if (dconf->ruby_log_handler == 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);
}
@@ -1418,13 +1442,13 @@ static int ruby_header_parser_handler(request_rec *r)
if (dconf->ruby_init_handler &&
ap_table_get(r->notes, "ruby_init_ran") == NULL) {
- retval = ruby_handler(r, dconf->ruby_init_handler,
+ retval = ruby_handler(r, dconf->ruby_init_handler, NULL,
rb_intern("init"), 1, 0);
if (retval != OK && retval != DECLINED)
return retval;
}
if (dconf->ruby_header_parser_handler == 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 @@ static APR_CLEANUP_RETURN_TYPE ruby_cleanup_handler(void *data)
request_rec *r = (request_rec *) data;
ruby_dir_config *dconf = get_dir_config(r);
- 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 @@ static int ruby_post_read_request_handler(request_rec *r)
apr_pool_cleanup_null);
if (dconf->ruby_init_handler) {
- retval = ruby_handler(r, dconf->ruby_init_handler,
+ retval = ruby_handler(r, dconf->ruby_init_handler, NULL,
rb_intern("init"), 1, 0);
apr_table_set(r->notes, "ruby_init_ran", "true");
if (retval != OK && retval != 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);
}
+#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_pool_t *pool, const char *error) {
+ ruby_dir_config *dconf;
+ error_log_data *e;
+
+ /* only interested in errors produced as the result of requests.
+ *
+ * [this handler is called multiple times during startup but since this is
+ * prior to config stage, we'll ignore them] */
+ if (r == NULL) return;
+
+ dconf = get_dir_config(r);
+ if (dconf->ruby_error_log_handler == NULL) return;
+
+ e = apr_palloc(r->pool, sizeof(error_log_data));
+ e->file = file;
+ e->line = line;
+ e->level = level;
+ e->status = status;
+ e->error = error;
+
+ ruby_handler((request_rec *) r, dconf->ruby_error_log_handler, e,
+ rb_intern("log_error"), 1, 0);
+ return;
+}
+#endif
+
/*
* Local variables:
* mode: C
View
14 mod_ruby.h
@@ -83,6 +83,7 @@
#include "apr_tables.h"
#define ap_pool apr_pool_t
+#define uri_components apr_uri_t
typedef apr_pool_t pool;
typedef apr_array_header_t array_header;
@@ -193,6 +194,7 @@ typedef struct {
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 @@ typedef struct {
VALUE request_object;
} ruby_request_config;
+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;
+
#define MR_DEFAULT_TIMEOUT 0
#define MR_DEFAULT_SAFE_LEVEL 1
#define MR_DEFAULT_RESTRICT_DIRECTIVES 0
View
32 request.c
@@ -56,6 +56,7 @@ typedef struct request_data {
VALUE subprocess_env;
VALUE notes;
VALUE finfo;
+ VALUE parsed_uri;
VALUE attributes;
VALUE error_message;
VALUE exception;
@@ -106,6 +107,10 @@ static VALUE fname(VALUE self, VALUE val) \
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)
static void request_mark(request_data *data)
{
@@ -119,6 +124,7 @@ static void request_mark(request_data *data)
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 @@ static VALUE apache_request_new(request_rec *r)
data->subprocess_env = Qnil;
data->notes = Qnil;
data->finfo = Qnil;
+ data->parsed_uri = Qnil;
data->attributes = Qnil;
data->error_message = Qnil;
data->exception = Qnil;
@@ -605,6 +612,8 @@ REQUEST_INT_ATTR_WRITER(request_set_status, status);
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 @@ static VALUE request_finfo(VALUE self)
return data->finfo;
}
+static VALUE request_parsed_uri(VALUE self)
+{
+ request_data *data;
+
+ data = get_request_data(self);
+ if (NIL_P(data->parsed_uri)) {
+ data->parsed_uri = 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 @@ static VALUE request_default_type(VALUE self)
return type ? rb_tainted_str_new2(type) : Qnil;
}
+static VALUE request_default_port(VALUE self)
+{
+ request_data *data;
+
+ data = 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 @@ void rb_init_apache_request()
rb_define_method(rb_cApacheRequest, "allowed=", request_set_allowed, 1);
rb_define_method(rb_cApacheRequest, "the_request",
request_the_request, 0);
+ rb_define_method(rb_cApacheRequest, "assbackwards?", request_get_assbackwards, 0);
+ rb_define_method(rb_cApacheRequest, "assbackwards=", request_set_assbackwards, 1);
rb_define_method(rb_cApacheRequest, "header_only?", request_header_only, 0);
rb_define_method(rb_cApacheRequest, "args", request_get_args, 0);
rb_define_method(rb_cApacheRequest, "args=", request_set_args, 1);
@@ -2160,6 +2190,7 @@ void rb_init_apache_request()
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 @@ void rb_init_apache_request()
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",
View
18 ruby_config.c
@@ -109,6 +109,9 @@ void *ruby_create_dir_config(pool *p, char *dirname)
conf->ruby_type_handler = NULL;
conf->ruby_fixup_handler = NULL;
conf->ruby_log_handler = NULL;
+#ifdef APACHE2
+ conf->ruby_error_log_handler = NULL;
+#endif
conf->ruby_header_parser_handler = NULL;
conf->ruby_post_read_request_handler = NULL;
conf->ruby_init_handler = NULL;
@@ -164,7 +167,11 @@ void *ruby_merge_dir_config(pool *p, void *basev, void *addv)
merge_handlers(p, base->ruby_fixup_handler, add->ruby_fixup_handler);
new->ruby_log_handler =
merge_handlers(p, base->ruby_log_handler, add->ruby_log_handler);
- new->ruby_header_parser_handler =
+#ifdef APACHE2
+ new->ruby_error_log_handler =
+ merge_handlers(p, base->ruby_error_log_handler, add->ruby_error_log_handler);
+#endif
+ new->ruby_header_parser_handler =
merge_handlers(p, base->ruby_header_parser_handler,
add->ruby_header_parser_handler);
new->ruby_post_read_request_handler =
@@ -472,6 +479,15 @@ const char *ruby_cmd_log_handler(cmd_parms *cmd, void *conf, const char *arg)
return NULL;
}
+#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_handler, arg);
+ return NULL;
+}
+#endif
+
const char *ruby_cmd_header_parser_handler(cmd_parms *cmd,
void *conf, const char *arg)
{
View
3 ruby_config.h
@@ -53,6 +53,9 @@ const char *ruby_cmd_access_handler(cmd_parms*, void*, const char*);
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*);
View
77 uri.c
@@ -0,0 +1,77 @@
+/*
+ * $Id$
+ * Copyright (C) 2001 Shugo Maeda <shugo@modruby.net>
+ * 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 the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "mod_ruby.h"
+#include "apachelib.h"
+
+VALUE rb_cApacheUri;
+
+VALUE rb_apache_uri_new(uri_components *uri)
+{
+ if (uri == 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_initialized);
+DEFINE_BOOL_ATTR_READER(uri_dns_looked_up, uri_components, dns_looked_up);
+DEFINE_BOOL_ATTR_READER(uri_dns_resolved, uri_components, dns_resolved);
+
+/*
+ * struct hostent *hostent; defined but unused by apr-util or apache at present
+ */
+
+void rb_init_apache_uri()
+{
+ rb_cApacheUri = rb_define_class_under(rb_mApache, "Uri", rb_cObject);
+ 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=c ts=8 sw=4 : */

0 comments on commit ce4d096

Please sign in to comment.