You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Geoffrey Young <ge...@modperlcookbook.org> on 2002/12/06 16:28:10 UTC

[PATCH 2.0] $r->as_string patch

hi all...

   I don't know how folks have lived without $r->as_string for as long as they have, but I 
couldn't, so here's a patch.  the only thing that seemed strange as the addition of 
sv_str_header in RequestUtil.h, but I didn't see another place for generic utility 
functions like that and apr_table_do is rather funky.

lemme know if I have to send it as an attachment (or just a +1 and I'll commit :)

   the only

--Geoff

Index: Changes
===================================================================
RCS file: /home/cvspublic/modperl-2.0/Changes,v
retrieving revision 1.78
diff -u -r1.78 Changes
--- Changes	6 Dec 2002 13:09:15 -0000	1.78
+++ Changes	6 Dec 2002 15:22:25 -0000
@@ -10,6 +10,8 @@

  =item 1.99_08-dev

+add $r->as_string [Geoffrey Young]
+
  add backcompat vars: $Apache::Server::CWD and
  $Apache::Server::AddPerlVersion [Stas Bekman]

Index: t/response/TestAPI/rutil.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/t/response/TestAPI/rutil.pm,v
retrieving revision 1.3
diff -u -r1.3 rutil.pm
--- t/response/TestAPI/rutil.pm	11 Apr 2002 11:08:43 -0000	1.3
+++ t/response/TestAPI/rutil.pm	6 Dec 2002 15:22:26 -0000
@@ -30,7 +30,7 @@
  sub handler {
      my $r = shift;

-    plan $r, tests => 17;
+    plan $r, tests => 18;

      ok $r->default_type;

@@ -53,6 +53,11 @@
      }

      ok $r->is_initial_req;
+
+    # test for the request_line, status_ling, and few
+    # headers that should always be there
+    ok $r->as_string =~
+      m!GET /TestAPI::rutil.*Host:.*200 OK.*Content-Type:!s;

      Apache::OK;
  }
Index: xs/Apache/RequestUtil/Apache__RequestUtil.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/Apache/RequestUtil/Apache__RequestUtil.h,v
retrieving revision 1.12
diff -u -r1.12 Apache__RequestUtil.h
--- xs/Apache/RequestUtil/Apache__RequestUtil.h	5 Dec 2001 19:00:29 -0000	1.12
+++ xs/Apache/RequestUtil/Apache__RequestUtil.h	6 Dec 2002 15:22:26 -0000
@@ -214,3 +214,33 @@

      return dcfg->location;
  }
+
+static int sv_str_header(void *arg, const char *k, const char *v)
+{
+    SV *sv = (SV*)arg;
+    sv_catpvf(sv, "%s: %s\n", k, v);
+    return 1;
+}
+
+static MP_INLINE
+SV *mpxs_Apache__RequestRec_as_string(pTHX_ request_rec *r)
+{
+    SV *retval = newSVpv(r->the_request, 0);
+
+    sv_catpvn(retval, "\n", 1);
+
+    apr_table_do((int (*) (void *, const char *, const char *))
+                  sv_str_header, (void *) retval, r->headers_in, NULL);
+
+    sv_catpvf(retval, "\n%s %s\n", r->protocol, r->status_line);
+
+    apr_table_do((int (*) (void *, const char *, const char *))
+                  sv_str_header, (void *) retval, r->headers_out, NULL);
+    apr_table_do((int (*) (void *, const char *, const char *))
+                  sv_str_header, (void *) retval, r->err_headers_out, NULL);
+
+    sv_catpvn(retval, "\n", 1);
+
+    return retval;
+}
+
Index: xs/maps/modperl_functions.map
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/maps/modperl_functions.map,v
retrieving revision 1.45
diff -u -r1.45 modperl_functions.map
--- xs/maps/modperl_functions.map	5 Sep 2002 01:48:40 -0000	1.45
+++ xs/maps/modperl_functions.map	6 Dec 2002 15:22:26 -0000
@@ -18,6 +18,7 @@
   mpxs_Apache__RequestRec_set_handlers
   mpxs_Apache__RequestRec_get_handlers
   mpxs_Apache__RequestRec_location
+ mpxs_Apache__RequestRec_as_string
   mpxs_Apache__RequestRec_pnotes | | r, key=Nullsv, val=Nullsv
   modperl_config_insert_request | | \
    r, lines, path=r->filename, override=OR_AUTHCFG | add_config
Index: xs/tables/current/ModPerl/FunctionTable.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v
retrieving revision 1.86
diff -u -r1.86 FunctionTable.pm
--- xs/tables/current/ModPerl/FunctionTable.pm	21 Oct 2002 17:58:40 -0000	1.86
+++ xs/tables/current/ModPerl/FunctionTable.pm	6 Dec 2002 15:22:26 -0000
@@ -6242,7 +6242,21 @@
          'name' => 'func'
        }
      ]
-  }
+  },
+  {
+    'return_type' => 'SV *',
+    'name' => 'mpxs_Apache__RequestRec_as_string',
+    'args' => [
+      {
+        'type' => 'PerlInterpreter *',
+        'name' => 'my_perl'
+      },
+      {
+        'type' => 'request_rec *',
+        'name' => 'r'
+      }
+    ]
+  },
  ];




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [PATCH 2.0] $r->as_string patch

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> 
> 
> Geoffrey Young wrote:
> 
>> hi all...
>>
>>   I don't know how folks have lived without $r->as_string for as long 
>> as they have, but I couldn't, so here's a patch.  the only thing that 
>> seemed strange as the addition of sv_str_header in RequestUtil.h, but 
>> I didn't see another place for generic utility functions like that and 
>> apr_table_do is rather funky.
> 
> 
> I moved that sv_str_header to modperl_sv_str_header in modperl_util.c, 
> which seems a bit better.  here's a new patch.

+1

Go Geoff!

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Re: [PATCH 2.0] $r->as_string patch

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Geoffrey Young wrote:
> hi all...
> 
>   I don't know how folks have lived without $r->as_string for as long as 
> they have, but I couldn't, so here's a patch.  the only thing that 
> seemed strange as the addition of sv_str_header in RequestUtil.h, but I 
> didn't see another place for generic utility functions like that and 
> apr_table_do is rather funky.

I moved that sv_str_header to modperl_sv_str_header in modperl_util.c, which seems a bit 
better.  here's a new patch.

--Geoff

Index: Changes
===================================================================
RCS file: /home/cvspublic/modperl-2.0/Changes,v
retrieving revision 1.78
diff -u -r1.78 Changes
--- Changes	6 Dec 2002 13:09:15 -0000	1.78
+++ Changes	6 Dec 2002 15:57:08 -0000
@@ -10,6 +10,8 @@

  =item 1.99_08-dev

+add $r->as_string [Geoffrey Young]
+
  add backcompat vars: $Apache::Server::CWD and
  $Apache::Server::AddPerlVersion [Stas Bekman]

Index: src/modules/perl/modperl_util.c
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_util.c,v
retrieving revision 1.48
diff -u -r1.48 modperl_util.c
--- src/modules/perl/modperl_util.c	1 Jul 2002 05:15:28 -0000	1.48
+++ src/modules/perl/modperl_util.c	6 Dec 2002 15:57:08 -0000
@@ -614,3 +614,11 @@
                      GvNAME(gv), GvNAMELEN(gv), G_DISCARD);
      return rv;
  }
+
+int modperl_sv_str_header(void *arg, const char *k, const char *v)
+{
+    SV *sv = (SV*)arg;
+    sv_catpvf(sv, "%s: %s\n", k, v);
+    return 1;
+}
+
Index: src/modules/perl/modperl_util.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/src/modules/perl/modperl_util.h,v
retrieving revision 1.35
diff -u -r1.35 modperl_util.h
--- src/modules/perl/modperl_util.h	21 Jun 2002 00:44:24 -0000	1.35
+++ src/modules/perl/modperl_util.h	6 Dec 2002 15:57:08 -0000
@@ -119,4 +119,6 @@

  SV *modperl_perl_gensym(pTHX_ char *pack);

+int modperl_sv_str_header(void *arg, const char *k, const char *v);
+
  #endif /* MODPERL_UTIL_H */
Index: t/response/TestAPI/rutil.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/t/response/TestAPI/rutil.pm,v
retrieving revision 1.3
diff -u -r1.3 rutil.pm
--- t/response/TestAPI/rutil.pm	11 Apr 2002 11:08:43 -0000	1.3
+++ t/response/TestAPI/rutil.pm	6 Dec 2002 15:57:09 -0000
@@ -30,7 +30,7 @@
  sub handler {
      my $r = shift;

-    plan $r, tests => 17;
+    plan $r, tests => 18;

      ok $r->default_type;

@@ -53,6 +53,11 @@
      }

      ok $r->is_initial_req;
+
+    # test for the request_line, status_ling, and few
+    # headers that should always be there
+    ok $r->as_string =~
+        m!GET /TestAPI::rutil.*Host:.*200 OK.*Content-Type:!s;

      Apache::OK;
  }
Index: xs/Apache/RequestUtil/Apache__RequestUtil.h
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/Apache/RequestUtil/Apache__RequestUtil.h,v
retrieving revision 1.12
diff -u -r1.12 Apache__RequestUtil.h
--- xs/Apache/RequestUtil/Apache__RequestUtil.h	5 Dec 2001 19:00:29 -0000	1.12
+++ xs/Apache/RequestUtil/Apache__RequestUtil.h	6 Dec 2002 15:57:09 -0000
@@ -214,3 +214,26 @@

      return dcfg->location;
  }
+
+static MP_INLINE
+SV *mpxs_Apache__RequestRec_as_string(pTHX_ request_rec *r)
+{
+    SV *retval = newSVpv(r->the_request, 0);
+
+    sv_catpvn(retval, "\n", 1);
+
+    apr_table_do((int (*) (void *, const char *, const char *))
+                  modperl_sv_str_header, (void *) retval, r->headers_in, NULL);
+
+    sv_catpvf(retval, "\n%s %s\n", r->protocol, r->status_line);
+
+    apr_table_do((int (*) (void *, const char *, const char *))
+                  modperl_sv_str_header, (void *) retval, r->headers_out, NULL);
+    apr_table_do((int (*) (void *, const char *, const char *))
+                  modperl_sv_str_header, (void *) retval, r->err_headers_out, NULL);
+
+    sv_catpvn(retval, "\n", 1);
+
+    return retval;
+}
+
Index: xs/maps/modperl_functions.map
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/maps/modperl_functions.map,v
retrieving revision 1.45
diff -u -r1.45 modperl_functions.map
--- xs/maps/modperl_functions.map	5 Sep 2002 01:48:40 -0000	1.45
+++ xs/maps/modperl_functions.map	6 Dec 2002 15:57:09 -0000
@@ -18,6 +18,7 @@
   mpxs_Apache__RequestRec_set_handlers
   mpxs_Apache__RequestRec_get_handlers
   mpxs_Apache__RequestRec_location
+ mpxs_Apache__RequestRec_as_string
   mpxs_Apache__RequestRec_pnotes | | r, key=Nullsv, val=Nullsv
   modperl_config_insert_request | | \
    r, lines, path=r->filename, override=OR_AUTHCFG | add_config
Index: xs/tables/current/ModPerl/FunctionTable.pm
===================================================================
RCS file: /home/cvspublic/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v
retrieving revision 1.86
diff -u -r1.86 FunctionTable.pm
--- xs/tables/current/ModPerl/FunctionTable.pm	21 Oct 2002 17:58:40 -0000	1.86
+++ xs/tables/current/ModPerl/FunctionTable.pm	6 Dec 2002 15:57:09 -0000
@@ -6242,7 +6242,21 @@
          'name' => 'func'
        }
      ]
-  }
+  },
+  {
+    'return_type' => 'SV *',
+    'name' => 'mpxs_Apache__RequestRec_as_string',
+    'args' => [
+      {
+        'type' => 'PerlInterpreter *',
+        'name' => 'my_perl'
+      },
+      {
+        'type' => 'request_rec *',
+        'name' => 'r'
+      }
+    ]
+  },
  ];







---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org