patch [2/2]: expose request_rec->parsed_uri
"Matthew Kent" <[email protected]> Thu, 21 Jun 2007 00:50:11 -0700 (PDT)
| Newsgroups | gmane.comp.apache.mod-ruby |
|---|---|
| Message-ID | <[email protected]> |
------=_20070621005011_31159 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Provides read access to the parsed_uri data from r->parsed_uri. Nothing fancy :) Tested against trunk on httpd 2.2.4/apache 1.3.37 Willing to provide doc patches for either one of these submissions. --=20 Matthew Kent <[email protected]> http://magoazul.com ------=_20070621005011_31159 Content-Type: text/x-patch; name="mod_ruby-r132-uri.patch" Content-Disposition: attachment; filename="mod_ruby-r132-uri.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 @@ -425,6 +434,7 @@ #ifdef APACHE2 rb_init_apache_bucket(); #endif + rb_init_apache_uri(); } =20 /* diff -urN mod_ruby/trunk/apachelib.h mod_ruby-1.2.6/apachelib.h --- mod_ruby/trunk/apachelib.h 2007-06-17 00:52:30.000000000 -0700 +++ mod_ruby-1.2.6/apachelib.h 2007-06-17 01:20:53.000000000 -0700 @@ -80,6 +80,11 @@ 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); + /* --- Libapreq Extensions ------------------------------ */ =20 extern VALUE rb_eApacheRequestError; diff -urN mod_ruby/trunk/Makefile.in mod_ruby-1.2.6/Makefile.in --- mod_ruby/trunk/Makefile.in 2007-06-17 00:52:30.000000000 -0700 +++ mod_ruby-1.2.6/Makefile.in 2007-06-16 15:20:53.000000000 -0700 @@ -98,6 +98,7 @@ paramtable.@OBJEXT@ \ multival.@OBJEXT@ \ bucket.@OBJEXT@ \ + uri.@OBJEXT@ \ apache_request.@OBJEXT@ \ apache_multipart_buffer.@OBJEXT@ \ apache_cookie.@OBJEXT@ @@ -183,6 +184,7 @@ 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 =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/trunk/mod_ruby.h mod_ruby-1.2.6/mod_ruby.h --- mod_ruby/trunk/mod_ruby.h 2007-06-17 00:52:30.000000000 -0700 +++ mod_ruby-1.2.6/mod_ruby.h 2007-06-17 00:06:34.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; 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 @@ -56,6 +56,7 @@ VALUE subprocess_env; VALUE notes; VALUE finfo; + VALUE parsed_uri; VALUE attributes; VALUE error_message; VALUE exception; @@ -119,6 +120,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 +184,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; @@ -876,6 +879,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; @@ -2160,6 +2182,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); diff -urN mod_ruby/trunk/uri.c mod_ruby-1.2.6/uri.c --- mod_ruby/trunk/uri.c 1969-12-31 16:00:00.000000000 -0800 +++ mod_ruby-1.2.6/uri.c 2007-06-17 00:18:20.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 : */ ------=_20070621005011_31159--