You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by do...@hyperreal.org on 1998/07/18 16:44:18 UTC

cvs commit: modperl/t/net/perl util.pl

dougm       98/07/18 07:44:18

  Modified:    .        Changes MANIFEST Makefile.PL ToDo
                        apache-modlist.html
               src/modules/perl URI.xs
  Added:       Util     .cvsignore Makefile.PL Util.pm
               src/modules/perl Util.xs
               t/modules util.t
               t/net/perl util.pl
  Log:
  added Apache::Util module (enable with PERL_UTIL_API=1 or EVERYTHING=1)
  
  Revision  Changes    Path
  1.80      +2 -0      modperl/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /export/home/cvs/modperl/Changes,v
  retrieving revision 1.79
  retrieving revision 1.80
  diff -u -r1.79 -r1.80
  --- Changes	1998/07/17 21:00:01	1.79
  +++ Changes	1998/07/18 14:44:12	1.80
  @@ -8,6 +8,8 @@
   
   =item 1.13_01-dev
   
  +added Apache::Util module (enable with PERL_UTIL_API=1 or EVERYTHING=1)
  +
   only break out of the write loop if rwrite() returns -1 and
   r->connection->aborted, otherwise continue  
   
  
  
  
  1.27      +5 -0      modperl/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  RCS file: /export/home/cvs/modperl/MANIFEST,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- MANIFEST	1998/07/17 20:48:35	1.26
  +++ MANIFEST	1998/07/18 14:44:12	1.27
  @@ -7,6 +7,8 @@
   Log/Log.pm
   URI/Makefile.PL
   URI/URI.pm
  +Util/Makefile.PL
  +Util/Util.pm
   CREDITS
   INSTALL
   INSTALL.apaci
  @@ -63,6 +65,7 @@
   src/modules/perl/ModuleConfig.xs
   src/modules/perl/Log.xs
   src/modules/perl/URI.xs
  +src/modules/perl/Util.xs
   src/modules/perl/Tie.xs
   src/modules/perl/ldopts
   src/modules/perl/mod_perl.c
  @@ -91,6 +94,7 @@
   t/modules/httpdconf.t
   t/modules/log.t
   t/modules/uri.t
  +t/modules/util.t
   t/modules/psections.t
   t/modules/perlrun.t
   t/modules/include.t
  @@ -116,6 +120,7 @@
   t/internal/tie.t
   t/net/perl/log.pl
   t/net/perl/uri.pl
  +t/net/perl/util.pl
   t/net/perl/file_upload.cgi
   t/net/perl/tie_table.pl
   t/net/perl/qredirect.pl
  
  
  
  1.67      +6 -4      modperl/Makefile.PL
  
  Index: Makefile.PL
  ===================================================================
  RCS file: /export/home/cvs/modperl/Makefile.PL,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- Makefile.PL	1998/07/17 20:48:35	1.66
  +++ Makefile.PL	1998/07/18 14:44:12	1.67
  @@ -150,6 +150,7 @@
   $PERL_TIE_TABLES = 0;
   $PERL_LOG_API = 0;
   $PERL_URI_API = 0;
  +$PERL_UTIL_API = 0;
   my %experimental = map { $_,1 } qw{
   PERL_GET_SET_HANDLERS
   PERL_MARK_WHERE
  @@ -193,6 +194,7 @@
      PERL_TIE_TABLES
      PERL_LOG_API
      PERL_URI_API
  +   PERL_UTIL_API
   };
   
   $callback_alias{PERL_INIT} = "PERL_HEADER_PARSER";
  @@ -269,7 +271,7 @@
   
   if($EVERYTHING) {
       @callback_hooks{qw(PERL_STACKED_HANDLERS PERL_METHOD_HANDLERS)} = (1) x 2;
  -    for(qw(ALL_HOOKS PERL_SSI PERL_SECTIONS PERL_TIE_TABLES PERL_DIRECTIVE_HANDLERS PERL_LOG_API PERL_URI_API)) {
  +    for(qw(ALL_HOOKS PERL_SSI PERL_SECTIONS PERL_TIE_TABLES PERL_DIRECTIVE_HANDLERS PERL_LOG_API PERL_URI_API PERL_UTIL_API)) {
          $$_ = 1;
       }
   }
  @@ -284,7 +286,7 @@
   
   if($DYNAMIC) {
       $PERL_DIRECTIVE_HANDLERS = $PERL_TIE_TABLES = 
  -	$PERL_LOG_API = $PERL_URI_API = 1;
  +	$PERL_LOG_API = $PERL_URI_API = $PERL_UTIL_API = 1;
   }
   
   my @xs_modules = qw(Apache Apache::Constants);
  @@ -358,7 +360,7 @@
   	    $USE_APACI = $USE_DSO = 0;
   	    
   	}
  -	for (qw(PERL_LOG_API PERL_URI_API)) {
  +	for (qw(PERL_LOG_API PERL_URI_API PERL_UTIL_API)) {
   	    if(($mmn < MMN_130) and $$_) { #1.3.0
   		$$_ = 0;
   		$cant_hook{$_} = "(need 1.3.0 or higher)";
  @@ -503,7 +505,7 @@
       $callback_hooks{PERL_TIE_TABLES} = 1;
   }
   
  -for (qw(Log URI)) {
  +for (qw(Log URI Util)) {
       my $s = "PERL_".uc($_)."_API";
       if($$s) {
   	push @xs_modules, "Apache::$_";
  
  
  
  1.46      +0 -2      modperl/ToDo
  
  Index: ToDo
  ===================================================================
  RCS file: /export/home/cvs/modperl/ToDo,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- ToDo	1998/07/17 20:48:35	1.45
  +++ ToDo	1998/07/18 14:44:13	1.46
  @@ -233,8 +233,6 @@
   - should Apache::Registry use filename instead of vhost_name+uri?
                 Ben Laurie <be...@algroup.co.uk>
   
  -- Apache::Util: functions from apache's util*.c files
  -
   - apache.pm: use apache '1.3b3';
   
   - have Apache::Status hunt for AUTOLOADing 
  
  
  
  1.28      +3 -2      modperl/apache-modlist.html
  
  Index: apache-modlist.html
  ===================================================================
  RCS file: /export/home/cvs/modperl/apache-modlist.html,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- apache-modlist.html	1998/07/17 20:48:35	1.27
  +++ apache-modlist.html	1998/07/18 14:44:13	1.28
  @@ -2,12 +2,13 @@
   <head>
   <title>The Apache/Perl Module List</title>
   <!-- Changed by: Gerald Richter, 17-Jul-1998 -->
  +<!-- Changed by: Doug MacEachern, 18-Jul-1998 -->
   </head>
   <body>
   <h1>The Apache/Perl Module List</h1>
   
   Maintained by <a href="mailto:dougm@pobox.com">Doug MacEachern</a>,
  -<br><i> $Revision: 1.27 $ $Date: 1998/07/17 20:48:35 $</i>
  +<br><i> $Revision: 1.28 $ $Date: 1998/07/18 14:44:13 $</i>
   
   <h3>Contents</h3>
   <a href="#intro">Introduction</a><br>
  @@ -179,7 +180,7 @@
   Sfio		cmcO	Interface to r-&gt;connection-&gt;client-&gt;sf* DOUGM
   Tie		bmcO	Tie interfaces to Apache structures 	APML
   URI		bmfO	URI component parsing and unparsing	APML
  -Util		cmcf	Interface to Apache's util*.c functions	APML
  +Util		bmcf	Interface to Apache's util*.c functions	APML
   
   * Development and Debug tools
   Debug		Rmpf	mod_perl debugging utilities		APML
  
  
  
  1.1                  modperl/Util/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  Makefile
  pm_to_blib
  
  
  
  1.1                  modperl/Util/Makefile.PL
  
  Index: Makefile.PL
  ===================================================================
  use ExtUtils::MakeMaker;
  # See lib/ExtUtils/MakeMaker.pm for details of how to influence
  # the contents of the Makefile that is written.
  
  use ExtUtils::testlib;
  use lib qw(../blib/lib ../blib/arch);
  
  use Apache::src ();
  my $src = Apache::src->new;
  
  WriteMakefile(
      'NAME'	=> 'Apache::Util',
      'VERSION_FROM' => 'Util.pm', # finds $VERSION
      'LIBS'	=> [''],   # e.g., '-lm' 
      'DEFINE'	=> '',     # e.g., '-DHAVE_SOMETHING' 
      'INC'	=> $src->inc,     # e.g., '-I/usr/include/other' 
      'TYPEMAPS'  => $src->typemaps,
  );
  
  
  
  1.1                  modperl/Util/Util.pm
  
  Index: Util.pm
  ===================================================================
  package Apache::Util;
  
  use strict;
  use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
  
  use Exporter ();
  use DynaLoader ();
  
  @ISA = qw(Exporter DynaLoader);
  @EXPORT_OK = qw(escape_html escape_uri);
  %EXPORT_TAGS = (all => \@EXPORT_OK);
  $VERSION = '0.01';
  
  if($ENV{MOD_PERL}) {
      bootstrap Apache::Util $VERSION;
  }
  
  1;
  __END__
  
  
  =head1 NAME
  
  Apache::Util - Interface to Apache C util functions
  
  =head1 SYNOPSIS
  
    use Apache::Util qw(:all);
  
  =head1 DESCRIPTION
  
  This module provides a Perl interface to some of the C utility functions
  available in Perl.  The same functionality is avaliable in libwww-perl, but
  the C versions are faster:
  
      use Benchmark;
      timethese(1000, {
          C => sub { my $esc = Apache::Util::escape_html($html) },
          Perl => sub { my $esc = HTML::Entities::encode($html) },
      });  
  
      Benchmark: timing 1000 iterations of C, Perl...
              C:  0 secs ( 0.17 usr  0.00 sys =  0.17 cpu)
           Perl: 15 secs (15.06 usr  0.04 sys = 15.10 cpu) 
  
      use Benchmark;
      timethese(10000, {
          C => sub { my $esc = Apache::Util::escape_uri($uri) },
          Perl => sub { my $esc = URI::Escape::uri_escape($uri) },
      }); 
  
      Benchmark: timing 10000 iterations of C, Perl...
              C:  0 secs ( 0.55 usr  0.01 sys =  0.56 cpu)
           Perl:  2 secs ( 1.78 usr  0.01 sys =  1.79 cpu) 
  
  =head1 FUNCTIONS
  
  =over 4
  
  =item escape_html
  
  This routine replaces unsafe characters in $string with their entity
  representation.
  
   my $esc = Apache::Util::escape_html($html);
  
  =item escape_uri
  
  This function replaces all unsafe characters in the $string with their
  escape sequence and returns the result.
  
   my $esc = Apache::Util::escape_uri($uri);
  
  =back
  
  =head1 AUTHOR
  
  Doug MacEachern
  
  =head1 SEE ALSO
  
  perl(1).
  
  =cut
  
  
  
  1.2       +1 -0      modperl/src/modules/perl/URI.xs
  
  Index: URI.xs
  ===================================================================
  RCS file: /export/home/cvs/modperl/src/modules/perl/URI.xs,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- URI.xs	1998/07/17 20:48:41	1.1
  +++ URI.xs	1998/07/18 14:44:16	1.2
  @@ -77,6 +77,7 @@
       Apache::URI uri
   
       CODE:
  +    RETVAL = Nullsv;
   
       if(uri->path_info) {
   	int uri_len = strlen(uri->uri.path);
  
  
  
  1.1                  modperl/src/modules/perl/Util.xs
  
  Index: Util.xs
  ===================================================================
  #ifdef MOD_PERL
  #include "mod_perl.h"
  #else
  #include "modules/perl/mod_perl.h"
  #endif 
  
  #define TIME_NOW time(NULL)
  #define DEFAULT_TIME_FORMAT "%a, %d %b %Y %H:%M:%S %Z"
   
  static pool *util_pool(void)
  {
      request_rec *r = NULL;
  
      if((r = perl_request_rec(NULL)))
          return r->pool;
      else
          return perl_get_startup_pool();
      return NULL;
  }
  
  MODULE = Apache::Util		PACKAGE = Apache::Util		
  
  PROTOTYPES: DISABLE
  
  BOOT:
      items = items; /*avoid warning*/
                                           
  char *
  escape_uri(segment)
      const char *segment
  
      CODE:
      RETVAL = ap_os_escape_path(util_pool(), segment, TRUE);
  
      OUTPUT:
      RETVAL
  
  char *
  escape_html(s)
      const char *s
  
      CODE:
      RETVAL = escape_html(util_pool(),s);
  
      OUTPUT:
      RETVAL
  
  char *
  ht_time(t=TIME_NOW, fmt=DEFAULT_TIME_FORMAT, gmt=TRUE)
      time_t t
      const char *fmt
      int gmt
  
      CODE:
      RETVAL = ap_ht_time(util_pool(), t, fmt, gmt);
  
      OUTPUT:
      RETVAL
  
  
  
  1.1                  modperl/t/modules/util.t
  
  Index: util.t
  ===================================================================
  
  use Apache::test;
  
  print fetch "http://$net::httpserver$net::perldir/util.pl";
  
  
  
  
  1.1                  modperl/t/net/perl/util.pl
  
  Index: util.pl
  ===================================================================
  use strict;
  use Apache::test;
  $|++;
  my $i = 0;
  
  my $r = shift;
  $r->send_http_header('text/plain');
  
  eval {
      require Apache::Util;
      require HTML::Entities;
      require URI::Escape;
      require HTTP::Date;
  };
  if($@) {
      print "$@\n";
      print "1..0\n";
      return;
  }
  
  my $html = <<EOF;
  <html>
  <head>
  <title>Testing Escape</title>
  </head>
  <body>
  ok
  </body>
  </html>
  EOF
  
  print "1..3\n";
  
  my $esc = Apache::Util::escape_html($html);
  #print $esc;
  
  my $esc_2 = HTML::Entities::encode($html);
  
  #print $esc_2;
  test ++$i, $esc eq $esc_2;
  
  =pod
  use Benchmark;
  timethese(1000, {
      C => sub { my $esc = Apache::Util::escape_html($html) },
      Perl => sub { my $esc = HTML::Entities::encode($html) },
  });
  =cut
  
  my $uri = "http://www.apache.org/docs/mod/mod_proxy.html?has some spaces";
  
  my $C = Apache::Util::escape_uri($uri);
  my $Perl = URI::Escape::uri_escape($uri);
  
  print "C = $C\n";
  print "Perl = $Perl\n";
  
  test ++$i, lc($C) eq lc($Perl); 
  
  =pod
  use Benchmark;
  timethese(10000, {
      C => sub { my $esc = Apache::Util::escape_uri($uri) },
      Perl => sub { my $esc = URI::Escape::uri_escape($uri) },
  });  
  =cut
  
  $C = Apache::Util::ht_time();
  $Perl = HTTP::Date::time2str();
  my $builtin = scalar gmtime;
  
  print "C = $C\n";
  print "Perl = $Perl\n";
  print "builtin = $builtin\n";
  
  test ++$i, lc($C) eq lc($Perl); 
  
  =pod
  use Benchmark;
  timethese(10000, {
      C => sub { my $d = Apache::Util::ht_time() },
      Perl => sub { my $d = HTTP::Date::time2str() },
      Perl_builtin => sub { my $d = scalar gmtime },
  });  
  =cut