[interchange-cvs] interchange - heins modified 8 files

interchange-cvs at icdevgroup.org interchange-cvs at icdevgroup.org
Sun Mar 22 19:32:31 UTC 2009


User:      heins
Date:      2009-03-22 19:32:31 GMT
Modified:  .        WHATSNEW-5.7
Modified:  lib/Vend CharSet.pm Config.pm Dispatch.pm File.pm Server.pm
Modified:           Util.pm
Modified:  lib/Vend/Table GDBM.pm
Log:
* Add environment variable MINIVEND_DISABLE_UTF8 which allows us to
  skip the Encode module entirely.

  Since "no encoding" does not remove the tie from regexes to Encode,
  but only disables it, you can't use that method. You have to literally
  not include Encode in the module namespace. This environment variable
  prevents require/import of the module if it is set true.

  It also adds a Global UTF8 directive that would normally not be, but could
  be, set by the user. This disables UTF8 with "no encoding", which should avoid
  some of the Perl UTF8 insanity but still won't avoid a potential "require" or
  "dofile" on a simple regex.

* Change Vend::CharSet away from the quasi-object style of programming
  (i.e. Module->routine()), since this module is only used internally.
  This will improve performance if/when a large number of CGI parameters
  are passed.

* Pass data to be encoded by Vend::CharSet by reference. While the
  Encode module inexplicably won't operate on references, at least we
  can avoid slinging hundred-megabyte files by value for what ends up
  being a no-op. Should you have to decode the data, it will still be
  slow but it will be limited to that eventuality, not every uploaded
  file.

Revision  Changes    Path
2.36                 interchange/WHATSNEW-5.7


rev 2.36, prev_rev 2.35
Index: WHATSNEW-5.7
===================================================================
RCS file: /var/cvs/interchange/WHATSNEW-5.7,v
retrieving revision 2.35
retrieving revision 2.36
diff -u -r2.35 -r2.36
--- WHATSNEW-5.7	22 Mar 2009 14:13:52 -0000	2.35
+++ WHATSNEW-5.7	22 Mar 2009 19:32:31 -0000	2.36
@@ -21,6 +21,31 @@
   table and field will work as well as a simple field in the same table
   as the item.
 
+* Add environment variable MINIVEND_DISABLE_UTF8 which allows us to
+  skip the Encode module entirely.
+
+  Since "no encoding" does not remove the tie from regexes to Encode,
+  but only disables it, you can't use that method. You have to literally
+  not include Encode in the module namespace. This environment variable
+  prevents require/import of the module if it is set true.
+
+  It also adds a Global UTF8 directive that would normally not be, but could
+  be, set by the user. This disables UTF8 with "no encoding", which should avoid
+  some of the Perl UTF8 insanity but still won't avoid a potential "require" or
+  "dofile" on a simple regex.
+
+* Change Vend::CharSet away from the quasi-object style of programming
+  (i.e. Module->routine()), since this module is only used internally.
+  This will improve performance if/when a large number of CGI parameters
+  are passed.
+
+* Pass data to be encoded by Vend::CharSet by reference. While the
+  Encode module inexplicably won't operate on references, at least we
+  can avoid slinging hundred-megabyte files by value for what ends up
+  being a no-op. Should you have to decode the data, it will still be
+  slow but it will be limited to that eventuality, not every uploaded
+  file.
+
 * Fixed rare bug that caused requests to / URL with a query string to fail, e.g.:
 
   http://hostname/?somevar=1



2.11                 interchange/lib/Vend/CharSet.pm


rev 2.11, prev_rev 2.10
Index: CharSet.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/CharSet.pm,v
retrieving revision 2.10
retrieving revision 2.11
diff -u -r2.10 -r2.11
--- CharSet.pm	26 Sep 2008 15:38:17 -0000	2.10
+++ CharSet.pm	22 Mar 2009 19:32:31 -0000	2.11
@@ -1,6 +1,6 @@
 # Vend::CharSet - utility methods for handling character encoding
 #
-# $Id: CharSet.pm,v 2.10 2008-09-26 15:38:17 jon Exp $
+# $Id: CharSet.pm,v 2.11 2009-03-22 19:32:31 mheins Exp $
 #
 # Copyright (C) 2008 Interchange Development Group
 # Copyright (C) 2008 Sonny Cook <sonny at endpoint.com>
@@ -22,28 +22,40 @@
 
 package Vend::CharSet;
 
+ at ISA = qw( Exporter );
+
+ at EXPORT_OK = qw(
+				decode_urlencode
+				default_charset
+				to_internal 
+				utf8_safe_regex_workaround
+				);
+
 use strict;
 
-use Encode qw( decode resolve_alias is_utf8 );
+unless( $ENV{MINIVEND_DISABLE_UTF8} ) {
+	require Encode;
+	import Encode qw( decode resolve_alias is_utf8 );
+}
 
 sub decode_urlencode {
-	my ($class, $octets, $encoding) = (@_);
+	my ($octets, $encoding) = (@_);
 
 #::logDebug("decode_urlencode--octets: $octets, encoding: $encoding");
 
-	$octets =~ tr/+/ /;
-	$octets =~ s/%([0-9a-fA-F][0-9a-fA-F])/chr(hex $1)/ge;
+	$$octets =~ tr/+/ /;
+	$$octets =~ s/%([0-9a-fA-F][0-9a-fA-F])/chr(hex $1)/ge;
 
-	return $octets unless $encoding and $class->validate_encoding($encoding);
+	return $octets unless $encoding and $Global::UTF8 and validate_encoding($encoding);
 
-	my $string = $class->to_internal($encoding, $octets);
+	to_internal($encoding, $octets);
 
 #::logDebug("decoded string: " . display_chars($string)) if $string;
-	return $string;
+	return $octets;
 }
 
 sub to_internal {
-	my ($class, $encoding, $octets) = @_;
+	my ($encoding, $octets) = @_;
 
 #::logDebug("to_internal - no encoding specified"),
     return $octets unless $encoding;
@@ -51,16 +63,16 @@
     return $octets if is_utf8($octets);
 
 #::logDebug("to_internal - converting octets from $encoding to internal");
-	my $string = eval {	decode($encoding, $octets, Encode::FB_CROAK) };
+	$$octets = eval {	decode($encoding, $$octets, Encode::FB_CROAK) };
 	if ($@) {
 		::logError("Unable to properly decode <%s> with encoding %s: %s", display_chars($octets), $encoding, $@);
 		return;
 	}
-	return $string;
+	return $octets;
 }
 
 sub validate_encoding {
-	my ($class, $encoding) = @_;
+	my ($encoding) = @_;
 	return resolve_alias($encoding);
 }
 
@@ -72,7 +84,7 @@
 # This is a workaround for the problem with UTF-8 regular expressions
 # implicitly trying to require UTF-8
 sub utf8_safe_regex_workaround {
-    my ($class, $compartment) = @_;
+    my ($compartment) = @_;
 
     $_ = 'workaround for the workaround';
     s/\p{SpacePerl}+$//;



2.243                interchange/lib/Vend/Config.pm


rev 2.243, prev_rev 2.242
Index: Config.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Config.pm,v
retrieving revision 2.242
retrieving revision 2.243
diff -u -r2.242 -r2.243
--- Config.pm	16 Mar 2009 10:06:12 -0000	2.242
+++ Config.pm	22 Mar 2009 19:32:31 -0000	2.243
@@ -1,6 +1,6 @@
 # Vend::Config - Configure Interchange
 #
-# $Id: Config.pm,v 2.242 2009-03-16 10:06:12 pajamian Exp $
+# $Id: Config.pm,v 2.243 2009-03-22 19:32:31 mheins Exp $
 #
 # Copyright (C) 2002-2009 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -54,7 +54,7 @@
 use Vend::Data;
 use Vend::Cron;
 
-$VERSION = substr(q$Revision: 2.242 $, 10);
+$VERSION = substr(q$Revision: 2.243 $, 10);
 
 my %CDname;
 my %CPname;
@@ -514,6 +514,7 @@
 	['SubCatalog',		 'catalog',     	 ''],
 	['AutoVariable',	 'autovar',     	 'UrlJoiner'],
 	['XHTML',			 'yesno',	     	 'No'],
+	['UTF8',			 'yesno',	     	 $ENV{MINIVEND_DISABLE_UTF8} ? 'No' : 'Yes'],
 	['External',		 'yesno',	     	 'No'],
 	['ExternalFile',	 'root_dir',	     "$Global::RunDir/external.structure"],
 	['ExternalExport',	 undef,				 'Global::Catalog=Catalog'],



1.109                interchange/lib/Vend/Dispatch.pm


rev 1.109, prev_rev 1.108
Index: Dispatch.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Dispatch.pm,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -r1.108 -r1.109
--- Dispatch.pm	16 Mar 2009 10:06:12 -0000	1.108
+++ Dispatch.pm	22 Mar 2009 19:32:31 -0000	1.109
@@ -1,6 +1,6 @@
 # Vend::Dispatch - Handle Interchange page requests
 #
-# $Id: Dispatch.pm,v 1.108 2009-03-16 10:06:12 pajamian Exp $
+# $Id: Dispatch.pm,v 1.109 2009-03-22 19:32:31 mheins Exp $
 #
 # Copyright (C) 2002-2009 Interchange Development Group
 # Copyright (C) 2002 Mike Heins <mike at perusion.net>
@@ -26,7 +26,7 @@
 package Vend::Dispatch;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 1.108 $, 10);
+$VERSION = substr(q$Revision: 1.109 $, 10);
 
 use POSIX qw(strftime);
 use Vend::Util;
@@ -1221,12 +1221,19 @@
 }
 
 my %source_keys_hide;
+
+sub disable_encoding {
+	no encoding;
+}
+
 sub dispatch {
 	my($http) = @_;
 	$H = $http;
 
 	adjust_cgi();
 
+	$Global::UTF8 or disable_encoding();
+
 	## If returns false then was a 404 no catalog or a delivered image
 	open_cat() or return 1;
 



2.30                 interchange/lib/Vend/File.pm


rev 2.30, prev_rev 2.29
Index: File.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/File.pm,v
retrieving revision 2.29
retrieving revision 2.30
diff -u -r2.29 -r2.30
--- File.pm	10 Nov 2008 05:52:57 -0000	2.29
+++ File.pm	22 Mar 2009 19:32:31 -0000	2.30
@@ -1,6 +1,6 @@
 # Vend::File - Interchange file functions
 #
-# $Id: File.pm,v 2.29 2008-11-10 05:52:57 jon Exp $
+# $Id: File.pm,v 2.30 2009-03-22 19:32:31 mheins Exp $
 # 
 # Copyright (C) 2002-2008 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -50,13 +50,18 @@
 use Config;
 use Fcntl;
 use Errno;
-use Encode qw( is_utf8 );
+
+unless( $ENV{MINIVEND_DISABLE_UTF8} ) {
+	require Encode;
+	import Encode qw( is_utf8 );
+}
+
 use Vend::Util;
 use File::Path;
 use File::Copy;
 use subs qw(logError logGlobal);
 use vars qw($VERSION @EXPORT @EXPORT_OK $errstr);
-$VERSION = substr(q$Revision: 2.29 $, 10);
+$VERSION = substr(q$Revision: 2.30 $, 10);
 
 sub writefile {
     my($file, $data, $opt) = @_;



2.103                interchange/lib/Vend/Server.pm


rev 2.103, prev_rev 2.102
Index: Server.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Server.pm,v
retrieving revision 2.102
retrieving revision 2.103
diff -u -r2.102 -r2.103
--- Server.pm	20 Mar 2009 22:15:56 -0000	2.102
+++ Server.pm	22 Mar 2009 19:32:31 -0000	2.103
@@ -1,6 +1,6 @@
 # Vend::Server - Listen for Interchange CGI requests as a background server
 #
-# $Id: Server.pm,v 2.102 2009-03-20 22:15:56 markj Exp $
+# $Id: Server.pm,v 2.103 2009-03-22 19:32:31 mheins Exp $
 #
 # Copyright (C) 2002-2009 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -26,12 +26,12 @@
 package Vend::Server;
 
 use vars qw($VERSION);
-$VERSION = substr(q$Revision: 2.102 $, 10);
+$VERSION = substr(q$Revision: 2.103 $, 10);
 
 use Cwd;
 use POSIX qw(setsid strftime);
 use Vend::Util;
-use Vend::CharSet;
+use Vend::CharSet qw/ to_internal decode_urlencode default_charset /;
 use Fcntl;
 use Errno qw/:POSIX/;
 use Config;
@@ -336,7 +336,7 @@
 		$charset = $2;
 	}
 	else {
-		$charset = Vend::CharSet->default_charset();
+		$charset = default_charset();
 	}
 
 	$CGI::values{mv_form_charset} = $charset;
@@ -384,10 +384,12 @@
 
 #::logDebug("incoming --> $key");
 		$key = $::IV->{$key} if defined $::IV->{$key};
-		$key = Vend::CharSet->decode_urlencode($key, $charset);
+
+		Vend::CharSet::decode_urlencode(\$key, $charset);
+
 #::logDebug("mapping  --> $key");
 		if ($key) {
-			$value = Vend::CharSet->decode_urlencode($value, $charset);
+			decode_urlencode(\$value, $charset);
 			# Handle multiple keys
 			if(defined $CGI::values{$key} and ! defined $::SV{$key}) {
 				$CGI::values{$key} = "$CGI::values{$key}\0$value";
@@ -463,10 +465,10 @@
 			my ($charset) = $header{'Content-Type'} =~ / charset="?([-a-zA-Z0-9]+)"?/;
 
 			$content_type ||= 'text/plain';
-			$charset ||= Vend::CharSet->default_charset();
+			$charset ||= default_charset();
 
 			if ($content_type =~ m{^text/}i) {
-				$data = Vend::CharSet->to_internal($charset, $data);
+				$charset and $Global::UTF8 and Vend::CharSet::to_internal($charset, \$data);
 			}
 
 			if($filename) {
@@ -544,9 +546,8 @@
     my ($s, $body) = @_;
 #show_times("begin response send") if $Global::ShowTimes;
 
-	# Safe kludge: duplicate Vend::CharSet->default_charset method here
+	# Safe kludge: duplicate Vend::CharSet::default_charset method here
 	# so that $Document->send() will work from within Safe
-	#my $response_charset = Vend::CharSet->default_charset();
 	my $c = $Global::Selector{$CGI::script_name};
 	my $response_charset = $c->{Variable}{MV_HTTP_CHARSET} || $Global::Variable->{MV_HTTP_CHARSET} || 'iso8859-1';
 



2.124                interchange/lib/Vend/Util.pm


rev 2.124, prev_rev 2.123
Index: Util.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Util.pm,v
retrieving revision 2.123
retrieving revision 2.124
diff -u -r2.123 -r2.124
--- Util.pm	10 Feb 2009 15:06:54 -0000	2.123
+++ Util.pm	22 Mar 2009 19:32:31 -0000	2.124
@@ -1,6 +1,6 @@
 # Vend::Util - Interchange utility functions
 #
-# $Id: Util.pm,v 2.123 2009-02-10 15:06:54 thunder Exp $
+# $Id: Util.pm,v 2.124 2009-03-22 19:32:31 mheins Exp $
 # 
 # Copyright (C) 2002-2008 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -93,7 +93,7 @@
 use Vend::File;
 use subs qw(logError logGlobal);
 use vars qw($VERSION @EXPORT @EXPORT_OK);
-$VERSION = substr(q$Revision: 2.123 $, 10);
+$VERSION = substr(q$Revision: 2.124 $, 10);
 
 my $Eval_routine;
 my $Eval_routine_file;
@@ -598,7 +598,12 @@
 	$Keysub = sub {
 					@_ = time() unless @_;
 					$Md->reset();
-					$Md->add(map encode_utf8($_), @_);
+					if($Global::UTF8) {
+						$Md->add(map encode_utf8($_), @_);
+					}
+					else {
+						$Md->add(@_);
+					}
 					$Md->hexdigest();
 				};
 }



2.20                 interchange/lib/Vend/Table/GDBM.pm


rev 2.20, prev_rev 2.19
Index: GDBM.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Table/GDBM.pm,v
retrieving revision 2.19
retrieving revision 2.20
diff -u -r2.19 -r2.20
--- GDBM.pm	19 Apr 2008 14:38:14 -0000	2.19
+++ GDBM.pm	22 Mar 2009 19:32:31 -0000	2.20
@@ -1,6 +1,6 @@
 # Vend::Table::GDBM - Access an Interchange table stored in a GDBM file
 #
-# $Id: GDBM.pm,v 2.19 2008-04-19 14:38:14 jon Exp $
+# $Id: GDBM.pm,v 2.20 2009-03-22 19:32:31 mheins Exp $
 #
 # Copyright (C) 2002-2008 Interchange Development Group
 # Copyright (C) 1996-2002 Red Hat, Inc.
@@ -28,10 +28,14 @@
 use vars qw($VERSION @ISA);
 use GDBM_File;
 use Vend::Table::Common;
-use Encode qw(encode decode);
+
+unless( $ENV{MINIVEND_DISABLE_UTF8} ) {
+	require Encode;
+	import Encode qw( decode encode );
+}
 
 @ISA = qw(Vend::Table::Common);
-$VERSION = substr(q$Revision: 2.19 $, 10);
+$VERSION = substr(q$Revision: 2.20 $, 10);
 
 sub new {
 	my ($class, $obj) = @_;







More information about the interchange-cvs mailing list