patch [1/2]: expose more data from conn_rec, request_rec
"Matthew Kent" <[email protected]> Thu, 21 Jun 2007 00:41:17 -0700 (PDT)
| Newsgroups | gmane.comp.apache.mod-ruby |
|---|---|
| Message-ID | <[email protected]> |
------=_20070621004117_21486 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable [this the right place to submit these? the dev links off the main page seem down] Adds read access to a few more values in the conn_rec and request_rec structures. Things that mod_perl provides, nothing new. Tested against trunk on httpd 2.2.4/apache 1.3.37 --=20 Matthew Kent <[email protected]> http://magoazul.com ------=_20070621004117_21486 Content-Type: text/x-patch; name="mod_ruby-r132-additions.patch" Content-Disposition: attachment; filename="mod_ruby-r132-additions.patch" Content-Transfer-Encoding: quoted-printable diff -urN mod_ruby/trunk/apachelib.c mod_ruby-1.2.6/apachelib.c --- mod_ruby/trunk/apachelib.c 2007-06-17 00:52:30.000000000 -0700 +++ mod_ruby-1.2.6/apachelib.c 2007-06-17 01:11:58.000000000 -0700 @@ -389,6 +389,15 @@ 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 + /* Policy constants for setup_client_block() */ rb_define_const(rb_mApache, "REQUEST_NO_BODY", INT2NUM(REQUEST_NO_BODY)); diff -urN mod_ruby/trunk/connection.c mod_ruby-1.2.6/connection.c --- mod_ruby/trunk/connection.c 2007-06-17 00:52:30.000000000 -0700 +++ mod_ruby-1.2.6/connection.c 2007-06-17 01:23:09.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/trunk/request.c mod_ruby-1.2.6/request.c --- mod_ruby/trunk/request.c 2007-06-17 00:52:30.000000000 -0700 +++ mod_ruby-1.2.6/request.c 2007-06-16 18:53:23.000000000 -0700 @@ -1049,6 +1063,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; @@ -2180,6 +2203,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", ------=_20070621004117_21486--