You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Rob Lambden <Ro...@itinsideout.com> on 2003/02/04 17:24:03 UTC

Apache::Registry incompatible with CGI ?

Hi,

I have written a request handler in Perl.  I recently changed some code
in this to convert
from using CGI within mod_perl to using Apache::Registry.  The old code
was ...

  $DB->{ApacheReq} = shift;
  :
  $DB->{Page} = CGI::new();
  :

The new code is ...

  :
  $DB->{ApacheReq}= Apache::Request->new(shift);
  :
  $DB->SetupPageArguments();
  :
  sub SetupPageArguments()
  {
  my ($DB, $nLoop, @Query, $Key, $Value);

    $DB=shift;
    @{$DB->{Page}->{'.parameters'}}=$DB->{ApacheReq}->param();

    for($nLoop=0; $nLoop<=$#{$DB->{Page}->{'.parameters'}}; $nLoop++)
    {
 
if(!defined($DB->{ApacheReq}->param($DB->{Page}->{'.parameters'}[$nLoop]
)))
      {
        $DB->{Page}->{$DB->{Page}->{'.parameters'}[$nLoop]}[0]='';
      }
      else
      {
 
@{$DB->{Page}->{$DB->{Page}->{'.parameters'}[$nLoop]}}=$DB->{ApacheReq}-
>param($DB->{Page}->{'.parameters'}[$nLoop]);
      }
    }
  }


My handler then referes to the '.parameters' field and the arrays of
values.  For most posts 
this works fine.  However, when I send a large block of data in with the
request I have found 
that portions of the middle are left out.  Putting the old code back
means that the whole of the 
text is seen.

I am using a client program written in C++ to send the requests in.  All
requests are sent as a 
multipart message, with each form field having one part within the
message.  On the particular 
instance I have been looking at the overall content size for the request
(excluding the header) 
in my application is set to 21555.  (I have not set the flag to limit
post size as you can see 
from the above).  The end of the request appears as ...

:
:
:
function NewProductExtension(Id, ExtensionId, Description, MinRequired,
MaxRequired, Visible, WarnLessThan, WarnGreaterThan, LessThanWarning,
GreaterThanWarning, Width, Units)\n{\n  new ProductExtension(Id,
ExtensionId, Description, MinRequired, MaxRequired, Visible,
WarnLessThan, WarnGreaterTha<*********>ion CheckProductExtensions()
{
var nLoop;
var Rc=new String('');

  for(nLoop=0; nLoop<Products.length; nLoop++)
  {
    if(Products[nLoop].ExtensionCount>Products[nLoop].Extensions.length)
    {
      Rc=Rc+(Products[nLoop].ProductId+',');
    }
  }
  Rc=Rc.substr(0, Rc.length-1);
  return(Rc);
}

where <*********> denotes the portion that is missing (about 100 lines
or so)


I also sometimes see spurious data added after the request.

My server is running linux 2.4.18 on a two-way Intel box.  I have Apache
1.3.26 / mod_perl 1.27
I downloaded Apache::Registry from CPAN and I have version 2.01.  My C
compiler is gcc 2.96

I have not been able to run a LAN trace to see what's being sent, but
since it is OK with CGI I 
assume that I am sending what my client says I'm sending.

Unfortunately I do not understand how the C / Perl and XS files all
stitch together so my attempts 
to look at the code have not been fruitful.

I have adopted some code that works neatly under the Apache::Registry
but will have to be fudged to work with CGI so I am keen to get this
working.

Can anyone help ?

Rob Lambden

Re: Apache::Registry incompatible with CGI ?

Posted by Perrin Harkins <pe...@elem.com>.
Rob Lambden wrote:
>   sub SetupPageArguments()
>   {
>   my ($DB, $nLoop, @Query, $Key, $Value);
> 
>     $DB=shift;
>     @{$DB->{Page}->{'.parameters'}}=$DB->{ApacheReq}->param();
> 
>     for($nLoop=0; $nLoop<=$#{$DB->{Page}->{'.parameters'}}; $nLoop++)
>     {
>  
> if(!defined($DB->{ApacheReq}->param($DB->{Page}->{'.parameters'}[$nLoop]
> )))
>       {
>         $DB->{Page}->{$DB->{Page}->{'.parameters'}[$nLoop]}[0]='';
>       }
>       else
>       {
>  
> @{$DB->{Page}->{$DB->{Page}->{'.parameters'}[$nLoop]}}=$DB->{ApacheReq}-
> 
>>param($DB->{Page}->{'.parameters'}[$nLoop]);
> 
>       }
>     }

What's the purpose of that loop?  Is it just to copy the data out of 
Apache::Request/CGI?  I would do something a little more compact, like this:

my @keys = $DB->{ApacheReq}->param();
my %param_hash = map { $_, [ $DB->{ApacheReq}->param($_) ] } @keys;
$DB->{Page} = \%param_hash;
$DB->{Page}->{'.parameters'} = \@keys;

> However, when I send a large block of data in with the
> request I have found 
> that portions of the middle are left out.  Putting the old code back
> means that the whole of the 
> text is seen.

Have you tried debugging the individual parameters to see exactly which 
ones(s) are getting munged?  Print them out in both versions and compare 
them to see where the data is being lost.

- Perrin


Re: Apache::Registry incompatible with CGI ?

Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,

On Tue, 4 Feb 2003, Rob Lambden wrote:

> I have written a request handler in Perl.  I recently changed some code
> in this to convert from using CGI within mod_perl to using Apache::Registry.

It's generally best to write handlers.  If you have written a handler,
in general I think you should stay with it.

The Apache::Registry handler is really a kludge to get legacy scripts
going and it isn't intended that you would use it for new code.  There
are lots of things to think about (including traps for the unwary:),
and a great deal of documentation in the mod_perl Guide to help you.

73,
Ged.