mach 2004/01/31 11:28:32
Modified: . AxKit.xs MANIFEST
lib/Apache/AxKit Provider.pm
t/conf extra.last.conf.in
Added: lib/Apache/AxKit/Provider POST.pm
t/htdocs/style/provider 01.xsl
t/provider 01post.t
Log:
Fix for get_strref being called twice.
Revision Changes Path
1.7 +13 -16 xml-axkit/AxKit.xs
Index: AxKit.xs
===================================================================
RCS file: /home/cvs/xml-axkit/AxKit.xs,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AxKit.xs 5 Jun 2002 23:59:19 -0000 1.6
+++ AxKit.xs 31 Jan 2004 19:28:32 -0000 1.7
@@ -373,26 +373,22 @@
ret = -1;
error_str = newSVpv("", 0);
-
xmlInitParser();
xmlDoValidityCheckingDefaultValue = 0;
xmlSubstituteEntitiesDefaultValue = 0;
xmlLoadExtDtdDefaultValue = 0;
- read_length = read_perl(ioref, buffer, 4);
- if (read_length > 0) {
- ctxt = xmlCreatePushParserCtxt(axkitSAXHandler,
- NULL, buffer, read_length, "filename");
- ctxt->userData = (void*)&results;
-
- while(read_length = read_perl(ioref, buffer, BUFSIZE)) {
- xmlParseChunk(ctxt, buffer, read_length, 0);
- }
- ret = xmlParseChunk(ctxt, buffer, 0, 1);
-
- xmlFreeParserCtxt(ctxt);
- }
+ read_length = 0;
+ ctxt = xmlCreatePushParserCtxt(axkitSAXHandler,
+ &results, buffer, read_length,
"filename");
+
+ while(read_length = read_perl(ioref, buffer, BUFSIZE)) {
+ xmlParseChunk(ctxt, buffer, read_length, 0);
+ }
+ ret = xmlParseChunk(ctxt, buffer, 0, 1);
+
+ xmlFreeParserCtxt(ctxt);
sv_2mortal(error_str);
@@ -406,11 +402,12 @@
STRLEN len;
croak("xmlParse returned error: %d, %s", ret, SvPV(error_str,
len));
}
-
+
return_array = newAV();
av_push(return_array, newRV_noinc((SV*)results.xml_stylesheet));
av_push(return_array, newSVpv(results.start_element, 0));
av_push(return_array, newRV_noinc((SV*)results.start_attribs));
+
if (results.dtd != NULL) {
av_push(return_array, newSVpv(results.dtd, 0));
1.21 +3 -1 xml-axkit/MANIFEST
Index: MANIFEST
===================================================================
RCS file: /home/cvs/xml-axkit/MANIFEST,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- MANIFEST 19 Oct 2003 16:09:36 -0000 1.20
+++ MANIFEST 31 Jan 2004 19:28:32 -0000 1.21
@@ -157,6 +157,7 @@
lib/Apache/AxKit/Provider/FileWrite.pm
lib/Apache/AxKit/Provider/Filter.pm
lib/Apache/AxKit/Provider/Scalar.pm
+lib/Apache/AxKit/Provider/POST.pm
lib/Apache/AxKit/StyleChooser/Cookie.pm
lib/Apache/AxKit/StyleChooser/FileSuffix.pm
lib/Apache/AxKit/StyleChooser/PathInfo.pm
@@ -208,5 +209,6 @@
t/htdocs/uri/axkit/subrequest.xml
t/htdocs/style/uri/axkit/01.xsl
t/htdocs/style/uri/axkit/subrequest.xsl
-
+t/provider/01post.t
+t/htdocs/style/provider/01.xsl
typemap
1.19 +139 -84 xml-axkit/lib/Apache/AxKit/Provider.pm
Index: Provider.pm
===================================================================
RCS file: /home/cvs/xml-axkit/lib/Apache/AxKit/Provider.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Provider.pm 3 Oct 2003 18:38:38 -0000 1.18
+++ Provider.pm 31 Jan 2004 19:28:32 -0000 1.19
@@ -5,6 +5,7 @@
use Apache::AxKit::Exception;
use Apache::Constants qw(OK DECLINED);
+use AxKit;
# use vars qw/$COUNT/;
@@ -130,6 +131,7 @@
);
}
+
sub get_dom {
my $self = shift;
require Apache::AxKit::LibXMLSupport;
@@ -142,21 +144,33 @@
$XML::LibXML::read_cb, $XML::LibXML::close_cb);
Apache::AxKit::LibXMLSupport->reset($parser);
+ my $r = $self->apache_request();
+
my $xml_doc;
- eval {
- my $fh = $self->get_fh();
- AxKit::Debug(8, "Provider::get_dom/parse_fh($fh, ",
$self->{apache}->uri(), ")");
- $xml_doc = $parser->parse_fh($fh, $self->{apache}->uri());
- };
- if ($@) {
- use bytes;
- my $xmlstring = ${$self->get_strref()};
- AxKit::Debug(8, "Provider::get_dom/parse_string($xmlstring, ",
$self->{apache}->uri(), ")");
- $xml_doc = $parser->parse_string($xmlstring, $self->{apache}->uri())
||
+ my $str;
+ if($str = $r->pnotes('xml_string')) {
+ use bytes;
+ AxKit::Debug(8, "Provider::get_dom/parse_string($str, ",
$self->{apache}->uri(), ")");
+ $xml_doc = $parser->parse_string($str, $self->{apache}->uri()) ||
throw Apache::AxKit::Exception::Error(
-text => "XML::LibXML->parse_string returned nothing!"
);
- }
+ } else {
+ eval {
+ my $fh = $self->get_fh();
+ AxKit::Debug(8, "Provider::get_dom/parse_fh($fh, ",
$self->{apache}->uri(), ")");
+ $xml_doc = $parser->parse_fh($fh,
$self->{apache}->uri());
+ };
+ if ($@) {
+ use bytes;
+ my $xmlstring = ${$self->get_strref()};
+ AxKit::Debug(8,
"Provider::get_dom/parse_string($xmlstring, ", $self->{apache}->uri(), ")");
+ $xml_doc = $parser->parse_string($xmlstring,
$self->{apache}->uri()) ||
+ throw Apache::AxKit::Exception::Error(
+ -text => "XML::LibXML->parse_string
returned nothing!"
+ );
+ }
+ }
return $xml_doc;
}
@@ -228,9 +242,7 @@
undef $pref_style;
}
- my $xml_styles = [];
- my $vals = [];
-
+ my @styles;
my $key = $self->key();
# need to extract the following from the XML file:
@@ -238,68 +250,25 @@
# DTD filename
# Root element name (including namespace)
# use three element array @$vals
+
+ my ($doctype, $dtd, $root, $xml_styles) = $self->get_xml_info( $media,
$pref_style );
+
+ $xml_styles = [] if $AxKit::Cfg->IgnoreStylePI();
+
+ foreach my $style (@$xml_styles) {
+ $style->{title} ||= '#default';
+ }
+
+ # Let GetMatchingProcessors to process the @$styles array
+ {
+ local $^W; # suppress "Use of uninitialized value" warnings
+ AxKit::Debug(4, "Calling GetMatchingProcessors with ($media,
$pref_style, $doctype, $dtd, $root)");
+ }
- if (defined &Apache::AxKit::Provider::xs_get_styles_fh) {
- AxKit::Debug(2, "using XS get_styles (libxml2)");
- my ($xs_styles, $doctype, $dtd, $root) =
- $self->xs_get_styles($media, $pref_style);
- @$xml_styles = @$xs_styles unless $AxKit::Cfg->IgnoreStylePI();
- @$vals = ($doctype, $dtd, $root);
- }
- else {
- require XML::Parser;
-
- AxKit::Debug(4, "get_styles: creating XML::Parser");
-
- my $handlers = {
- Start => \&parse_start,
- Doctype => \&parse_dtd,
- $AxKit::Cfg->IgnoreStylePI() ? () : (Proc => \&parse_pi),
- };
-
- my $xml_parser = XML::Parser->new(
- Namespaces => 1,
- ErrorContext => 2,
- Handlers => $handlers,
- );
+ @styles = $AxKit::Cfg->GetMatchingProcessors($media, $pref_style,
$doctype, $dtd, $root, $xml_styles, $self);
- my $to_parse;
- eval {
- $to_parse = $self->get_fh();
- };
- if ($@) {
- $to_parse = ${ $self->get_strref(); };
- }
-
- AxKit::Debug(4, "get_styles: calling XML::Parser->parse('$key')");
- $xml_parser->parse(
- $to_parse,
- XMLStyle_preferred => $pref_style,
- XMLStyle_media => $media,
- XMLStyle_style => $xml_styles,
- XMLStyle_vals => $vals,
- XMLStyle_style_screen => [],
- );
-
- AxKit::Debug(4, "get_styles: parse returned successfully");
- }
-
- foreach my $style (@$xml_styles) {
- $style->{title} ||= '#default';
- }
-
- # Let GetMatchingProcessors to process the @$styles array
- {
- local $^W; # suppress "Use of uninitialized value" warnings
- AxKit::Debug(4, "Calling GetMatchingProcessors with ($media,
$pref_style, $vals->[0], $vals->[1], $vals->[2])");
- }
- my @styles = $AxKit::Cfg->GetMatchingProcessors($media,
- $pref_style, @$vals[0 .. 2], $xml_styles, $self);
-
if ([EMAIL PROTECTED]) {
- throw Apache::AxKit::Exception::Declined(
- reason => "No styles defined for '$key'"
- );
+ throw Apache::AxKit::Exception::Declined( reason => "No styles
defined for '$key'" );
}
# get mime-type => module mapping
@@ -331,20 +300,105 @@
return [EMAIL PROTECTED];
}
+sub get_xml_info{
+ my ($self, $media, $pref_style ) = @_;
+
+ # This is where the sniffing of the xml content happens.
+
+ my $r = $self->apache_request();
+ my @ret;
+ eval{
+ my $fh = $self->get_fh();
+ my $pos = eval { tell $fh; };
+ if($@) {
+ # fh is not seekable, thus we must slurp file at this
point.
+ undef $@;
+ local($/) = undef;
+ my $string = <$fh>;
+ $r->pnotes('xml_string', $string);
+ @ret = parse_xml_info( $r, undef, \$string, $media,
$pref_style);
+ } else {
+ # seekable.
+ @ret = parse_xml_info( $r, $fh, undef, $media,
$pref_style);
+ seek $fh, 0, $pos;
+ }
+ };
+ if($@) {
+ my $str_ref = $self->get_strref();
+ $r->pnotes('xml_string', ${$str_ref});
+ @ret = parse_xml_info( $r, undef, $str_ref, $media,
$pref_style);
+ }
+ return @ret;
+}
+
+sub parse_xml_info{
+ my ($r, $fh, $str_ref, $media, $pref_style) = @_;
+
+ if ($pref_style eq '#default') {
+ undef $pref_style;
+ }
+
+ my $xml_styles = [];
+ my $vals = [];
+ my @styles;
+
+ if (defined &Apache::AxKit::Provider::xs_get_styles_fh) {
+ AxKit::Debug(2, "using XS get_styles (libxml2)");
+ my ($xs_styles, $doctype, $dtd, $root) = xs_get_styles($r, $fh,
$str_ref, $media, $pref_style);
+ @$xml_styles = @$xs_styles unless $AxKit::Cfg->IgnoreStylePI();
+ @$vals = ($doctype, $dtd, $root);
+ }
+ else {
+ require XML::Parser;
+
+ AxKit::Debug(4, "get_styles: creating XML::Parser");
+
+ my $handlers = {
+ Start => \&parse_start,
+ Doctype => \&parse_dtd,
+ $AxKit::Cfg->IgnoreStylePI() ? () : (Proc =>
\&parse_pi),
+ };
+
+ my $xml_parser = XML::Parser->new(
+ Namespaces => 1,
+ ErrorContext => 2,
+ Handlers => $handlers,
+ );
+
+ my $to_parse = $fh || ${$str_ref};
+ #eval {
+ # $to_parse = $provider->get_fh();
+ #};
+ #if ($@) {
+ # $to_parse = ${ $provider->get_strref(); };
+ #}
+
+ AxKit::Debug(4, "get_styles: calling XML::Parser->parse()");
+ $xml_parser->parse(
+ $to_parse,
+ XMLStyle_preferred => $pref_style,
+ XMLStyle_media => $media,
+ XMLStyle_style => $xml_styles,
+ XMLStyle_vals => $vals,
+ XMLStyle_style_screen => [],
+ );
+
+ AxKit::Debug(4, "get_styles: parse returned successfully");
+ }
+
+ return (@$vals, $xml_styles);
+}
+
sub xs_get_styles {
- my $self = shift;
- my ($media, $pref_style) = @_;
+ my ($r, $fh, $strref, $media, $pref_style) = @_;
my $bits;
- eval {
- my $fh = $self->get_fh();
+ if(defined($fh)) {
AxKit::Debug(4, "calling xs_get_styles_fh()");
- $bits = xs_get_styles_fh($self->apache_request, $fh);
- };
- if ($@) {
- my $strref = $self->get_strref();
+ $bits = xs_get_styles_fh($r, $fh);
+ } else {
AxKit::Debug(4, "calling xs_get_styles_str()");
- $bits = xs_get_styles_str($self->apache_request, $$strref);
+ $bits = xs_get_styles_str($r, $$strref);
}
my @xml_stylesheet = @{$bits->[0]};
@@ -366,7 +420,7 @@
XMLStyle_style_screen => [],
XMLStyle_preferred => $pref_style,
XMLStyle_media => $media,
- };
+ };
foreach my $pi (@xml_stylesheet) {
parse_pi($e, "xml-stylesheet", $pi);
@@ -536,6 +590,7 @@
}
}
}
+
1;
__END__
1.2 +132 -0 xml-axkit/lib/Apache/AxKit/Provider/POST.pm
1.8 +8 -0 xml-axkit/t/conf/extra.last.conf.in
Index: extra.last.conf.in
===================================================================
RCS file: /home/cvs/xml-axkit/t/conf/extra.last.conf.in,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- extra.last.conf.in 19 Oct 2003 16:09:36 -0000 1.7
+++ extra.last.conf.in 31 Jan 2004 19:28:32 -0000 1.8
@@ -135,3 +135,11 @@
AxAddProcessor text/xsl /style/uri/axkit/subrequest.xsl
</Location>
+<Location "/provider/post">
+ Sethandler axkit
+ AxResetProcessors
+ AxContentProvider Apache::AxKit::Provider::POST
+ AxAddRootProcessor text/xsl /style/provider/01.xsl root
+</Location>
+
+
1.2 +9 -0 xml-axkit/t/htdocs/style/provider/01.xsl
1.2 +20 -0 xml-axkit/t/provider/01post.t