Re: Apache::Config module

2000-06-29 Thread Nathan Wiger

> NW] In any case, I have several questions:
> NW]
> NW] 1. Does a module like this exist anywhere? 
> 
> You may want to take a look at AppConfig module. It does provide
> generic capability to parse various kinds of config file. But I'll
> be a happy user to have more spesific Apache related in this regard.

Yeah, I checked out AppConfig, and I actually emailed the author about
modifying it a little so I could use it as a base class possibly for
Apache::Config. Unfortunately, I haven't heard anything back yet.
AppConfig would be a great base class, the only problem is that:

# it handles comments like this

 # but not like this

that's the only sticking point to not being able to extend AppConfig.
Hopefully I'll hear something back from him. The fix is just the
addition of a \s* to a regexp.

> Apache::Config will be sufficient, IMHO, as later someone might
> write another module, say Apache::Config::Deploy, that syncronize
> the configuration of some httpds across some networks.

Not bad - I like the idea for an extension.

I'll keep plugging away on it then, hopefully the author of AppConfig
will get back to me as that would help save some work, but regardless
the parsing of the httpd.conf is not really that hard in and of itself.
I'll use the name Apache::Config unless I hear otherwise.

Thanks again to everyone who responded for their input!

-Nate



Re: Apache::Config module

2000-06-29 Thread Nathan Wiger

James-

You and are are saying the same thing, just with different terminology.
I agree completely. :-)

-Nate

James G Smith wrote:
> 
> Nathan Wiger <[EMAIL PROTECTED]> wrote:
> >
> >  UseCanonicalName   On# = 1
> >  UseCanonicalName   Off   # = 0
> >  #UseCanonicalName  On# = undef (commented out)
> >
> >That way, the logic in your script/module/whatever can set a default
> >value:
> >
> >   if ( ! defined($conf->{usecanonicalname}) ) {
> >  # not specified, set default(s)
> >   } elsif ( ! $conf->{usecanonicalname} ) {
> >  # explicitly turned off
> >   } else {
> >  # explicitly turned on
> >   }
> 
> I think I would prefer it not exist in the hash if it is commented out in the
> config file (the same as not existing in the config file).  Then
> 
>   UseCanonicalName   On# = 1
>   UseCanonicalName   Off   # = 0
>   UseCanonicalName # = undef
>   #UseCanonicalName  On# = non-existant (commented out)
> 
> Otherwise, we can't distinguish between the last two possibilities.
> --
> James Smith <[EMAIL PROTECTED]>, 979-862-3725
> Texas A&M CIS Operating Systems Group, Unix



Re: Browser Sniffing

2000-06-29 Thread Gunther Birznieks


At 09:06 AM 6/30/00 +0700, Edwin Pratomo wrote:
>Ask Bjoern Hansen wrote:
> >
> > On Thu, 29 Jun 2000, Drew Taylor wrote:
> >
> > > I'm hoping it's been done already, because the user-agent strings are
> > > terribly inconsistent...
> >
> > I needed something like that once and ended up with this:
> >
> > sub UA {
> >   my $ua = shift;
> >   my $n = "";
> >   my $v = "";
>
>
>this doesn't seem to be aware of either WAP browsers or the emulators.
>A typical usage of this is to return WML pages if the request comes from
>a WAP browser, otherwise return html pages.
>
>Regards,
>Edwin.

That is a different method.

The fact is that you can't really easily tell if a browser is WAP or not 
from the useragent because there are new ones coming out every day... every 
phone and potentially every gateway is a user agent (the gateway may add 
its own details since it is the client that is actually going to the web 
server).

It is part of the HTTP standard to negotiate content. So if a WAP browser 
can't digest HTML, then text/html will not be among the content types that 
it accepts I suspect.

I would be interested if anyone else has checked this out. I tend to just 
check a use_wap=on variable in our latest scripts and turn on WML 
generation for that. Although I know it's a kludge, I haven't really minded 
because I figure every WML site will end up having an index.wml file as a 
frontpage which will navigate the user to the full cgi-bin URL.

The reality is that no user in their right mind would ever type in a full 
cgi-bin URL on one of those silly WAP phones. I have one and I got carpal 
tunnel typing www.extropia.com/cgi-bin/DemoStuff/WebCalendar...bla bla bla

Later,
Gunther

__
Gunther Birznieks ([EMAIL PROTECTED])
eXtropia - The Web Technology Company
http://www.extropia.com/




Re: Browser Sniffing

2000-06-29 Thread Edwin Pratomo

Ask Bjoern Hansen wrote:
>
> On Thu, 29 Jun 2000, Drew Taylor wrote:
>
> > I'm hoping it's been done already, because the user-agent strings are
> > terribly inconsistent...
>
> I needed something like that once and ended up with this:
>
> sub UA {
>   my $ua = shift;
>   my $n = "";
>   my $v = "";


this doesn't seem to be aware of either WAP browsers or the emulators.
A typical usage of this is to return WML pages if the request comes from
a WAP browser, otherwise return html pages.

Regards,
Edwin.



Re: Browser Sniffing

2000-06-29 Thread brian moseley

On Fri, 30 Jun 2000, Gunther Birznieks wrote:

> So two CPAN submissions, one under Apache::* and another
> under CGI::* or maybe under LWP (I prefer CGI::*
> though)...

i vote HTTP!




Re: Browser Sniffing

2000-06-29 Thread brian moseley

On Fri, 30 Jun 2000, Gunther Birznieks wrote:

> There are too many modules (even 1 is too many... ;))
> under the Apache::* moniker that actually can be used in
> generic CGI programs.

yeah, i'm thinking the same thing about Apache::Session!




Re: Browser Sniffing

2000-06-29 Thread Scott Alexander

Looking at this,  I'm tempted to do a similar thing.  My thought was 
to take the code and then twist it slightly to put the information into 
a database.  ie when I create a new session,  grab the information 
about browser etc.

Would save me a bit if it were already a completed apache:: 
module but if not.  I'll do it probably within the next three weeks.

Scott
On 29 Jun 2000, at 16:35, Drew Taylor wrote:
> Next question, what if this was turned into a proper Apache module and
> run as the PerlFixupHandler. It could put the sniffer results into
> $r->notes entries, which could then be used where ever needed. I'll
> assume it would just return DECLINED so the standard handlers will be
> run.





Re: Browser Sniffing

2000-06-29 Thread Gunther Birznieks

Would you mind please submitting this as a standard NON-Apache CPAN module?

There are too many modules (even 1 is too many... ;)) under the Apache::* 
moniker that actually can be used in generic CGI programs.

The fixuphandler sounds interesting, but I would prefer if that were a 
wrapper around another module that generically is designed to check the 
user agent regardless of mod_perl, PerlEx, Win32Perl, CGI/Perl. FastCGI, 
whatever...

So two CPAN submissions, one under Apache::* and another under CGI::* or 
maybe under LWP (I prefer CGI::* though)...

Later,
Gunther "Module Naming Nazi" Birznieks

At 04:35 PM 6/29/00 -0400, Drew Taylor wrote:
>Ask Bjoern Hansen wrote:
> >
> > On Thu, 29 Jun 2000, Drew Taylor wrote:
> >
> > > I'm hoping it's been done already, because the user-agent strings are
> > > terribly inconsistent...
> >
> > I needed something like that once and ended up with this:
>
>Cool! I ripped off the browser & version code. It seemed much more
>conprehensive than mine. :-)
>
>Next question, what if this was turned into a proper Apache module and
>run as the PerlFixupHandler. It could put the sniffer results into
>$r->notes entries, which could then be used where ever needed. I'll
>assume it would just return DECLINED so the standard handlers will be
>run.
>
>Does this sound like a useful project? I think I could probably squeeze
>it in within a few days, using Ask's and my code.
>
>--
>Drew Taylor
>Vialogix Communications, Inc.
>501 N. College Street
>Charlotte, NC 28202
>704 370 0550
>http://www.vialogix.com/

__
Gunther Birznieks ([EMAIL PROTECTED])
eXtropia - The Web Technology Company
http://www.extropia.com/




Re: getting data posted to site

2000-06-29 Thread Roger Espel Llima

Scott Alexander wrote:
> I'm trying to get the data that is posted from the browser durring a 
> request.
> 
> if ($r->method ne 'GET')
> {
>   $r->read($buffer,$r->header_in('Content-Length'));
>   #proccess data...
> }

There's a higher-level method for that, $r->content; I'd do something
like this:

if ($r->method eq 'POST' &&
$r->header_in('Content-type') =~ m!^application/x-www-form-urlencoded!)
{
  my $data = $r->content;
  # process data ...
}

Although you should seriously consider using a higher-level interface,
such as Apache::Request (downloadable from mod_perl's ftp server under
the name "libapreq"), or CGI.pm.

-- 
Roger Espel Llima, [EMAIL PROTECTED]
http://www.iagora.com/~espel/index.html



Re: global variables in mod_perl

2000-06-29 Thread Casey Bristow


 seems to me, that the script is working as it should.. you are just 
 hitting several different instances of the script.. one for each 
 apache child process.. try starting apache with the -X flag.
 './httpd -X' .. this will cause apache to run in single process mode.

 hope this helps.

On Thu, 29 Jun 2000, Tomas Zeman wrote:

> Hi all, 
> 
> I am new to mod_perl and i have one problem
> 
> I want to rewrite this simple script from fastcgi to
> mdo_perl
> -
> use FCGI;
> $cnt = 0;
> while (FCGI::Accept)
> {
>print "Content-type:text/html\n\n";
>print $cnt++;
> }
> -
> 
> This script writes (when i relaod it) 1,2,3,4,5,...
> and $cnt is "global variable"
> 
> in mod_perl
> I created My.pm package
> ---
> package My;
> 
> use strict;
> use Apache::Constants qw(:common);
> 
> # I try both global variable possibilites
> use vars qw($cnt1);
> $My::cnt2 = 1;
> 
> my $cnt1 = 1;
> 
> sub increment{
>  $My::cnt2++;
>  $cnt++;
>  print "$cnt1";
>  print $My::cnt2;
> }
> 1;
> ---
> 
> I have this module in starup.pl and start it when
> apache start
> 
> I also have a script when i use My.pm module
> ---
> #!/usr/bin/perl -w
> 
> use strict;
> use Apache::Registry;
> use My;
> 
> print "Content-type:text/html\n\n";
> 
> 
> $rr = Myy->increment();
> print "$rr"; 
> ---
> 
> This script writes 1,1,1,2,2,2,3,3,3,2,2,3,4,2,1 .
> randomly !!
> 
> Can anybody help me, where is the problem ?
> 
> 
> Thanks a lot
> Tomas Zeman
> 
> 
> 
> __
> Do You Yahoo!?
> Get Yahoo! Mail - Free email you can access from anywhere!
> http://mail.yahoo.com/
> 

-- 

 -Casey






Re: global variables in mod_perl

2000-06-29 Thread Richard Dice

> I am new to mod_perl and i have one problem
.
.
.
> This script writes 1,1,1,2,2,2,3,3,3,2,2,3,4,2,1 .
> randomly !!

Global variables are your problem.  The thing is, each global has a 
value that is persistent... IN ANY GIVEN APACHE CHILD PROCESS!

So, your increments are working, but you are randomly hitting different
child processes each time you access your web server.

The solution to this problem depends on what your goal is with this
program.

Cheers,
Richard

-- 

 Richard Dice * Personal 514 816 9568 * Fax 514 816 9569
 ShadNet Creator * http://shadnet.shad.ca/ * [EMAIL PROTECTED]
 Occasional Writer, HotWired * http://www.hotwired.com/webmonkey/
 "squeeze the world 'til it's small enough to join us heel to toe"
 - jesus jones



global variables in mod_perl

2000-06-29 Thread Tomas Zeman

Hi all, 

I am new to mod_perl and i have one problem

I want to rewrite this simple script from fastcgi to
mdo_perl
-
use FCGI;
$cnt = 0;
while (FCGI::Accept)
{
   print "Content-type:text/html\n\n";
   print $cnt++;
}
-

This script writes (when i relaod it) 1,2,3,4,5,...
and $cnt is "global variable"

in mod_perl
I created My.pm package
---
package My;

use strict;
use Apache::Constants qw(:common);

# I try both global variable possibilites
use vars qw($cnt1);
$My::cnt2 = 1;

my $cnt1 = 1;

sub increment{
 $My::cnt2++;
 $cnt++;
 print "$cnt1";
 print $My::cnt2;
}
1;
---

I have this module in starup.pl and start it when
apache start

I also have a script when i use My.pm module
---
#!/usr/bin/perl -w

use strict;
use Apache::Registry;
use My;

print "Content-type:text/html\n\n";


$rr = Myy->increment();
print "$rr"; 
---

This script writes 1,1,1,2,2,2,3,3,3,2,2,3,4,2,1 .
randomly !!

Can anybody help me, where is the problem ?


Thanks a lot
Tomas Zeman



__
Do You Yahoo!?
Get Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/



Re: mod_perl socket problem

2000-06-29 Thread Rob Tanner



--On Wednesday, June 28, 2000 4:35 PM +0200 ubr
<[EMAIL PROTECTED]> wrote:

> Hello mailinglist, i have a problem...
>
> I wrote a mod_perl-script running on an Apache-Server which has
> to receive a GIF-File from a NT-Server via a IO::Socket. (see code below)
> On the NT-side there is a JAVA-programm.
>
> Here some information about the used software:
> (A) my workstation:
>Linux 2.2.13
>Apache/1.3.9 (Unix)  (SuSE/Linux) PHP/3.0.12 mod_perl/1.21
>perl, version 5.005_03
> (B) production server:
>Linux 2.2.7
>Apache/1.3.6 (Unix)  (SuSE/Linux) PHP/3.0.7 mod_perl/1.19
>perl, version 5.005_02
> (C) test-server:
>Linux 2.2.5
>Apache/1.3.4 (Unix)  (SuSE/Linux) PHP/3.0.7 mod_perl/1.18
>perl, version 5.005_02
>
> I developed and tested the script on my workstation (A) and it worked.
> Moving to the production server (B)  or another test-server (C)  the
> mod_perl-script  seems to crash without a sigh (C) or doesn´t receive
> the whole file (B).
>

I'm not all that familiar with the various issues surrounding the earlier
releases of mod_perl, but you do notice the above trend.  Earlier versions
of mod_perl and Apache have the problem, the later do not.  Mod_perl's
current release is 1.24 and apache is 1.3.12.  Unless there's a
show-stopper bug in the most recent version of something, I like to keep up 
to date so that I don't rediscover something that has already been fixed.

> I have concentrated on the more severe problem (crashing on test-server
> C).
>
> The script cycles through the while-loop receiving a packet, sends
> a newline to the JAVA-program and writes to the IMG-Handle.
> And then after some packets it dies, just before the handshaking newline.
>
> The debugging output "GetFile: ready" does´nt appear in the logfile
> (GISLOG) and the function does´nt return to the main program (No further
> output  in GISLOG)
>

Looking at your code, one thing I think might be quite problematics is the
use of the "die" statement.  According to the eagle book, except during
apache initialization and startup, die does not necessarily behave as
advertised.  I suggest that instead you print to STDERR since apache
reopens that handle to point to error_log, and then simply return with an
SERVER_ERROR set.  That way apache handles it as apache was designed to do, 
and you won't suffer any of the possible negative consequences of "die".
That might get you a long way towards figuring out what all is going on.

And don't overlook the profuse use of "print STDERR" to write out debugging 
information to the error_log.  That one mechanism has helped me to find
more bugs than I'm even willing to admit to have had.

Hope that's helpful.

-- Rob


   _ _ _ _   __ _ _ _ _
  /\_\_\_\_\/\_\ /\_\_\_\_\_\
 /\/_/_/_/_/   /\/_/ \/_/_/_/_/_/  QUIDQUID LATINE DICTUM SIT,
/\/_/__\/_/ __/\/_//\/_/  PROFUNDUM VIDITUR
   /\/_/_/_/_/ /\_\  /\/_//\/_/
  /\/_/ \/_/  /\/_/_/\/_//\/_/ (Whatever is said in Latin
  \/_/  \/_/  \/_/_/_/_/ \/_/  appears profound)

  Rob Tanner
  McMinnville, Oregon
  [EMAIL PROTECTED]



SIGPIPE errors

2000-06-29 Thread Brent Meshier

Occasionaly, during a GET/POST, the request will be
dropped and netscape/IE returns "Document Contains No
Data".  The errors logs report:

[modperl] caught SIGPIPE in process 18311 hint: may be a
client (browser) hit STOP?
[modperl] process 18311 going to Apache::exit with
status=-2

When this happens, it will continue on for the next
three or four sequential requests.

I also will see the webpage load with:
Error: at
/usr/lib/perl5/site_perl/5.005/i686-linux/Apache/SIG.pm
line 31.

but not always during the SIGPIPE problems.

The modperl version is:
Server Version: Apache/1.3.12 (Unix) PHP/4.0.0
mod_perl/1.24
Linux 2.2.5-22smp #1 SMP Wed Jun 2 09:11:51 EDT 1999
i686 unknown
PERL version 5.005_03 built for i686-linux

(I'm running slashcode 1.0.5)
Any help would be greatly appreciated.

--Brent



Possible mod_perl or ??? bug?

2000-06-29 Thread Nathan Wiger

Hi all-

On a totally different subject, I've been experiencing problems with the
interaction between CGI::Carp and Apache::Session. I find that in a
mod_perl context, if I import CGI::Carp before I import Apache::Session,
then I run into the following error:

[Thu Jun 29 13:14:03 2000] [error]  (in cleanup) Can't use an undefined
value as a symbol reference at
/apache/perl/lib/site_perl/5.005/Apache/Session/Lock/File.pm line 109.

This happens if I use "PerlModule" in httpd.conf or "use" in the script
to import them. If you reverse the order, importing Apache::Session
before CGI::Carp, then everything's ok! This also only happens under
mod_perl - under a normal CGI context it works just fine. Strange.

The code this is referencing is this:

   sub release_all_locks  {
 my $self= shift;
 my $session = shift;
 
 flock($self->{fh}, LOCK_UN);  <<--- line 109
 
 if ($self->{opened}) {
 close $self->{fh} || die $!;
 }
 
 $self->{opened} = 0;
 $self->{read}   = 0;
 $self->{write}  = 0;
   }

So something is screwing up the $self that should be passed to
Apache::Session::Lock::File::release_all_locks() by DESTROY(). Since
this only seems to happen when these two modules play together, it's
been difficult for me to try and find what the problem is. Anyone have
any ideas or see a similar thing on their systems? My config is mod_perl
1.24 / Apache 1.3.12 / Solaris 8.

Thanks,
Nate



perldoc gateway/handler

2000-06-29 Thread Ian Mahuron


Does anyone know of a good mod_perl handler or CGI for browsing the perl
docs and various module docs?  I'd prefer to offer this functionality to my
developers on our intranet, rather then sending them off to
http://search.cpan.org

I've also been looking for a good one for system man pages.  The last one I
found had a tendency to break things.

TIA

Ian




Re: Browser Sniffing

2000-06-29 Thread Drew Taylor

Ask Bjoern Hansen wrote:
> 
> On Thu, 29 Jun 2000, Drew Taylor wrote:
> 
> > I'm hoping it's been done already, because the user-agent strings are
> > terribly inconsistent...
> 
> I needed something like that once and ended up with this:

Cool! I ripped off the browser & version code. It seemed much more
conprehensive than mine. :-)

Next question, what if this was turned into a proper Apache module and
run as the PerlFixupHandler. It could put the sniffer results into
$r->notes entries, which could then be used where ever needed. I'll
assume it would just return DECLINED so the standard handlers will be
run.

Does this sound like a useful project? I think I could probably squeeze
it in within a few days, using Ask's and my code.

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/



Re: [input] mod_perl and ISPs in the real world

2000-06-29 Thread Ask Bjoern Hansen


On Wed, 28 Jun 2000, Stas Bekman wrote:

> In the mod_perl Guide's chapter "mod_perl for ISPs" that you can read at
> http://perl.apache.org/guide/multiuser.html I go through various scenarios
> that can be deployed by ISPs who want to provide mod_perl services. The
> chapter talks about things to watch after, security issues and similar
> stuff.

I've pretty good experiences with having the user run their own daemon on
a high port and then have the frontend proxy the requests. The "backend"
daemon should be limited to a low number of concurrent childs. It doesn't
make for a $30/month solution, but if that's what you need mod_perl is
kinda out of the picture anyway.

plug: mail [EMAIL PROTECTED] if you need mod_perl hosting in Europe.


 - ask

ps. sorry about the duplicate Stas.

-- 
ask bjoern hansen - 
more than 70M impressions per day, 




getting data posted to site

2000-06-29 Thread Scott Alexander

I'm trying to get the data that is posted from the browser durring a 
request.

if ($r->method ne 'GET')
{
$r->read($buffer,$r->header_in('Content-Length'));
#proccess data...
}

The $r->read() hangs the request completely.  I ran an strace on 
httpd -X and posted the request section to 
http://mail.thefriend.com/httpd.strace.txt if that helps anyone.

Scott



Re: Browser Sniffing

2000-06-29 Thread Ask Bjoern Hansen

On Thu, 29 Jun 2000, Drew Taylor wrote:

> I'm hoping it's been done already, because the user-agent strings are
> terribly inconsistent...

I needed something like that once and ended up with this:

sub UA { 
  my $ua = shift;
  my $n = "";
  my $v = "";

  # $n is the name of the browser
  # $v the version
  $ $p the platform
  # $ua the full useragent string

  # grap the beginning of the UA string for the name
  ($n) = ($ua =~ m/^([^\/]+)\//);

  # but everything calls itself Mozilla, so let's check for a few more
  # known browsers
  $n = "msie" if m/MSIE/;
  # it's worse, these babies calls themself both MSIE and Mozilla, doh!
  $n = "webtv" if m/webtv/i;
  $n = "opera" if m/opera/i;

  # try getting the version
  ($v) = ($ua =~ m/\/((\d+)(\.\d+)?)/)[0];
  # loosen up what we match on a little and try again if we didn't get
  # a match
  ($v) = ($ua =~ m/((\d+)(\.\d+)?)/)[0] unless $v;

  # these thingies call themself Mozilla/N.Z, so let's get their real
  # version number
  ($v) = (m/MSIE ((\d+)(\.\d+)?)/) if ($n eq "msie");
  ($v) = (m/webtv\/((\d+)(\.\d+)?)/i) if ($n eq "webtv");
  ($v) = (m/opera[\s\/]((\d+)(\.\d+)?)/i) if ($n eq "opera");

  # guess the platform
  my $p = "";
  $p = "w" if $ua =~ m/win/i;
  $p = "w16" if $ua =~ m/win(dows)?\s?3\.1/i;
  $p = "w16" if $ua =~ m/win.*16(bit)?/i;
  $p = "w95" if $ua =~ m/win(dows)?\s?95/i;
  $p = "w98" if $ua =~ m/win(dows)?\s?98/i;
  $p = "wnt" if $ua =~ m/win(dows)?\s?NT/i;
  $p = "w32" if $ua =~ m/win(dows)?\s?32/i;
  $p = "x11" if $ua =~ m/X11/;
  $p = "mac" if $ua =~ m/mac/i;
  $p = "os2" if $ua =~ m/os\/2/i;
  $p = "webtv" if $n eq "webtv";

  $n = lc($n);
  die "No name for $ua?\n" unless $n;
  #return $n, $v, $p;
  return "$n-$v-$p";
}


-- 
ask bjoern hansen - 
more than 70M impressions per day, 





Re: Browser Sniffing

2000-06-29 Thread Drew Taylor

Casey Bristow wrote:
> 
>  I've also played with the idea of creating a similiar class, but have not
>  had time to really get on with it.. The best client sniffer that I have
>  found thus far is a javascript (ewww) one.. but it would rock to have this
>  functionality as an apache mod
>
>  http://developer.netscape.com:80/docs/examples/javascript/browser_type.html
Thanks for the link. It will be most useful as I improve the sniffing
code.

Here is the code I have thus far. It seems to work with IE 4+ on Mac &
windoze, NS 3+ on Mac & Windoze, and it recognizes my linux Netscape as
unix :-). It is very simplistic, but I guess something is better than
nothing.

sub BrowserPlatform {
my $self = shift;

my $agent = shift || $self->{R}->headers_in->get('User-Agent');
$agent = lc($agent);

my ($platform, $browser, $version) = ('','',0);

# browser version
if ( $agent =~ /msie (\d)/ ) { 
$version = int($1);
} elsif ($agent =~ m#^mozilla/(\d)#) {
$version = int($1)
} else {
$version = 3;
}

# check browser
if ( $agent =~ /mozilla/ && $agent !~ /msie/ ) { 
$browser = 'netscape'; 
} elsif ( $agent =~ /msie/ ) { 
$browser = 'msie'; 
} else {
$browser = 'other';
}

# check platform
if ( $agent =~ /mac/ or $agent =~ /ppc/ or $agent =~ /powerpc/) { 
$platform = 'mac'; 
} elsif ( $agent =~ /win/ ) { 
$platform = 'win'; 
} elsif ($agent =~ /linux/ or $agent =~ /sunos/) {
$platform = 'unix';
} else {
$platform = 'other';
}

print STDERR "BrowserPlatform: Browser=$browser Platform=$platform
Version=$version\n" if $DEBUG;
return ($browser, $platform, $version);
}

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/



Re: Browser Sniffing

2000-06-29 Thread Casey Bristow


 I've also played with the idea of creating a similiar class, but have not
 had time to really get on with it.. The best client sniffer that I have 
 found thus far is a javascript (ewww) one.. but it would rock to have this
 functionality as an apache mod!

 http://developer.netscape.com:80/docs/examples/javascript/browser_type.html

 I'm more than willing to help with this if you so desire.. just haven't 
 gotten around to it myself yet.

On Thu, 29 Jun 2000, Drew Taylor wrote:

> I am about to embark on a journey to find/create a brower sniffing
> module. It should get three things: 1) Browser 2) Version 3) Platform.
> Has anyone created such a beast? If I write it myself, I will be happy
> to share the code with those on the list.
> 
> I'm hoping it's been done already, because the user-agent strings are
> terribly inconsistent...
> 
> 

-- 

 -Casey






Browser Sniffing

2000-06-29 Thread Drew Taylor

I am about to embark on a journey to find/create a brower sniffing
module. It should get three things: 1) Browser 2) Version 3) Platform.
Has anyone created such a beast? If I write it myself, I will be happy
to share the code with those on the list.

I'm hoping it's been done already, because the user-agent strings are
terribly inconsistent...

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/



Re: can't properly append to file from mod_perl script

2000-06-29 Thread Stas Bekman

> On Thu, 29 Jun 2000, Stas Bekman wrote:
> 
> > When using file locking one must make sure, that if the script has been
> > stopped before the close() was called, to use an END block under Registry
> > or $r->register_cleanup() anywhere. See:
> > http://perl.apache.org/guide/debug.html#Handling_the_User_pressed_Stop_
> > http://perl.apache.org/guide/debug.html#Cleanup_Code
> > 
> > Otherwise you might get stuck with a stale lock, which will be never
> > removed unless the same process will call open() on the same filehandler.
> > And it'd be the same filehandler only if you use "open, IN ..." style, if
> > you use Symbol module or perl5.6 filehandler autovivification a new unique
> > filehandler will be created when the same code will run again.
> > 
> > So close() under mod_perl is not enough when locking is used.
> 
> Are you suggesting that more has to be done even if you use my $fh type
> opening? I'm not sure I believe you, if thats what you're suggesting - the
> second paragraph there seems to confuse things. If you use my $fh style
> opening (either the Symbol or 5.6 way) you need worry not about unlocking
> files or cleanup code for unlocking/closing files - it's all done by the
> garbage collector. (you should close your filehandles anyway though for
> the sake of cleanliness and not leaving around locks, but my point was
> merely the necessity of it).

Frank were talking about using globals. I forgot to stress this point. My
post is correct only when assuming that one uses globals.

so if you use 

  use vars ($fh)
  $fh = Symbol::gensym; # or Apache::Symbol
  open $fh, "foo" ...

it holds. Now thinking again about 5.6, I'm not sure about this:

  use vars ($fh)
  open $fh, "foo"...

is the auto-vivication of a unique filehandler works in this case? Or
only when one uses:

  open my $fh, "foo"...

if the latter is correct, my statement is incorrect regrading the perl5.6
autovivication, and only these two cases hold:

  # 1
  open IN, "foo" 

  # 2
  use vars ($fh)
  $fh = Symbol::gensym; # or Apache::Symbol
  open $fh, "foo" ...

In both you should worry to add a cleanup code.

_
Stas Bekman  JAm_pH --   Just Another mod_perl Hacker
http://stason.org/   mod_perl Guide  http://perl.apache.org/guide 
mailto:[EMAIL PROTECTED]   http://perl.org http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org






Re: can't properly append to file from mod_perl script

2000-06-29 Thread Matt Sergeant

On Thu, 29 Jun 2000, Stas Bekman wrote:

> When using file locking one must make sure, that if the script has been
> stopped before the close() was called, to use an END block under Registry
> or $r->register_cleanup() anywhere. See:
> http://perl.apache.org/guide/debug.html#Handling_the_User_pressed_Stop_
> http://perl.apache.org/guide/debug.html#Cleanup_Code
> 
> Otherwise you might get stuck with a stale lock, which will be never
> removed unless the same process will call open() on the same filehandler.
> And it'd be the same filehandler only if you use "open, IN ..." style, if
> you use Symbol module or perl5.6 filehandler autovivification a new unique
> filehandler will be created when the same code will run again.
> 
> So close() under mod_perl is not enough when locking is used.

Are you suggesting that more has to be done even if you use my $fh type
opening? I'm not sure I believe you, if thats what you're suggesting - the
second paragraph there seems to confuse things. If you use my $fh style
opening (either the Symbol or 5.6 way) you need worry not about unlocking
files or cleanup code for unlocking/closing files - it's all done by the
garbage collector. (you should close your filehandles anyway though for
the sake of cleanliness and not leaving around locks, but my point was
merely the necessity of it).

-- 


Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




use integer and CGI::Cookie

2000-06-29 Thread G.W. Haywood

Hi Stas,

Just a small point, maybe there's a place for it in the Guide?.

The following doesn't work

use integer;
use CGI::Cookie;
my $q = new CGI::Cookie( -name => ... );

because the `-' in `-name' is misinterpreted as a negative sign.

To get it to work, write

my $q = new CGI::Cookie( '-name' => ... );


Aaarrgghh.

73,
Ged.




Re: can't properly append to file from mod_perl script

2000-06-29 Thread Stas Bekman

On 29 Jun 2000, Frank D. Cringle wrote:

> Vivek Khera <[EMAIL PROTECTED]> writes:
> > > "RE" == Rob Egan <[EMAIL PROTECTED]> writes:
> > 
> > RE> CGI scripts to behave in mod_perl. All it does is capture e-mail addresses,
> > RE> and place them in a text file so we can gather them up later and drop them
> > RE> into a database. If you run the script as a regular CGI (without mod_perl
> > RE> enabled) it works great. But on the mod_perl enabled server, the script
> > RE> throws garbage into the file and overwrites previous entries if a user
> > RE> submits more than one e-mail address in a single session (i.e. they enter
> > 
> > It has nothing to do with the person quitting the browser.  It has to
> > do with your script using global variables.  Turn on "use strict" and
> > perl warnings and see what your error log says.
> > 
> > Then go to the mod perl guide and search for "sticky variables".
> 
> But since they are all global (no use of my), they won't be sticky.
> 
> There is plenty wrong with the script, although I can't specifically
> correlate the symptoms with the mistakes.  Sometimes the file is
> referred to as $results_file and in other places by its literal name.
> The 'if (-e $results_file) open ">..." else open ">>..."' code is
> unnecessary and will break if 2 processes hit the first if
> concurrently.  Just open it in append mode.  If it isn't there it will
> be created.  If you don't have write permission the open will fail.
> The locking is classically broken "# Unlock before you close" No!
> Wrong!.  Just close the file.  That has the desired side-effects of
> first flushing the buffered data and then unlocking the file.

When using file locking one must make sure, that if the script has been
stopped before the close() was called, to use an END block under Registry
or $r->register_cleanup() anywhere. See:
http://perl.apache.org/guide/debug.html#Handling_the_User_pressed_Stop_
http://perl.apache.org/guide/debug.html#Cleanup_Code

Otherwise you might get stuck with a stale lock, which will be never
removed unless the same process will call open() on the same filehandler.
And it'd be the same filehandler only if you use "open, IN ..." style, if
you use Symbol module or perl5.6 filehandler autovivification a new unique
filehandler will be created when the same code will run again.

So close() under mod_perl is not enough when locking is used.

_
Stas Bekman  JAm_pH --   Just Another mod_perl Hacker
http://stason.org/   mod_perl Guide  http://perl.apache.org/guide 
mailto:[EMAIL PROTECTED]   http://perl.org http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org





Re: can't properly append to file from mod_perl script

2000-06-29 Thread Frank D. Cringle

Vivek Khera <[EMAIL PROTECTED]> writes:
> > "RE" == Rob Egan <[EMAIL PROTECTED]> writes:
> 
> RE> CGI scripts to behave in mod_perl. All it does is capture e-mail addresses,
> RE> and place them in a text file so we can gather them up later and drop them
> RE> into a database. If you run the script as a regular CGI (without mod_perl
> RE> enabled) it works great. But on the mod_perl enabled server, the script
> RE> throws garbage into the file and overwrites previous entries if a user
> RE> submits more than one e-mail address in a single session (i.e. they enter
> 
> It has nothing to do with the person quitting the browser.  It has to
> do with your script using global variables.  Turn on "use strict" and
> perl warnings and see what your error log says.
> 
> Then go to the mod perl guide and search for "sticky variables".

But since they are all global (no use of my), they won't be sticky.

There is plenty wrong with the script, although I can't specifically
correlate the symptoms with the mistakes.  Sometimes the file is
referred to as $results_file and in other places by its literal name.
The 'if (-e $results_file) open ">..." else open ">>..."' code is
unnecessary and will break if 2 processes hit the first if
concurrently.  Just open it in append mode.  If it isn't there it will
be created.  If you don't have write permission the open will fail.
The locking is classically broken "# Unlock before you close" No!
Wrong!.  Just close the file.  That has the desired side-effects of
first flushing the buffered data and then unlocking the file.

-- 
Frank Cringle,  [EMAIL PROTECTED]
voice: (+49 2304) 467101; fax: 943357



Re: can't properly append to file from mod_perl script

2000-06-29 Thread Vivek Khera

> "RE" == Rob Egan <[EMAIL PROTECTED]> writes:

RE> CGI scripts to behave in mod_perl. All it does is capture e-mail addresses,
RE> and place them in a text file so we can gather them up later and drop them
RE> into a database. If you run the script as a regular CGI (without mod_perl
RE> enabled) it works great. But on the mod_perl enabled server, the script
RE> throws garbage into the file and overwrites previous entries if a user
RE> submits more than one e-mail address in a single session (i.e. they enter

It has nothing to do with the person quitting the browser.  It has to
do with your script using global variables.  Turn on "use strict" and
perl warnings and see what your error log says.

Then go to the mod perl guide and search for "sticky variables".

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.Khera Communications, Inc.
Internet: [EMAIL PROTECTED]   Rockville, MD   +1-301-545-6996
GPG & MIME spoken herehttp://www.khera.org/~vivek/



RE: Apache::Session

2000-06-29 Thread Kreimendahl, Chad J

We attempted something similar here, and failed.  We'd definately be
interested in seeing this implimentation.

-Original Message-
From: Jerrad Pierce [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 28, 2000 4:52 PM
To: '[EMAIL PROTECTED]'
Subject: Apache::Session


Has anybody started/interested in an imnplementation using DBD::RAM?



RE: Upgrade

2000-06-29 Thread Geoffrey Young



> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 28, 2000 4:45 PM
> To: Geoffrey Young
> Cc: [EMAIL PROTECTED]
> Subject: RE: Upgrade
> 
> 
> Looks like I'm going to have to recompile the works. I've downloaded 
> http://www.perl.com/CPAN/src/latest.tar.gz 
> and
> mod_perl-1.2.tar
> 
> When running the config on mod_perl as it is in the INSTALL file. It
> crashes out on the make. Looking like some source error with the
> ap_configtestonly function. Any suggestions?

looks like there has been some correction of this sort in 1.24_01, which can
be downloaded from
http://perl.apache.org/from-cvs/modperl/

just pick the latest one - there hasn't been any cvs action for a while...

HTH

--Geoff


> 
> 
> mod_perl.c: In function `perl_startup':
> mod_perl.c:738: `ap_configtestonly' undeclared (first use in this
> function)
> mod_perl.c:738: (Each undeclared identifier is reported only once
> mod_perl.c:738: for each function it appears in.)
> *** Error code 1
> 
> Stop in /usr/local/apache_1.3.6/src/modules/perl.
> *** Error code 1
> 
> Stop in /usr/local/apache_1.3.6/src/modules.
> *** Error code 1
> 
> Stop in /usr/local/apache_1.3.6/src.
> *** Error code 1
> 
> Stop in /usr/local/mod_perl-1.24.
> 
> 
> 
> =
> Keith W.
> 
> At the helm 
> =
> 
> 
> On Wed, 28 Jun 2000, Geoffrey Young wrote:
> 
> > as long as you have mod_so compiled into apache, you should 
> be able to add
> > mod_perl as a DSO.  you can check with httpd -l
> > 
> > the advice you will get the most from this list is to 
> recompile apache with
> > a static mod_perl and forget DSO, but DSO stability is 
> reported to have
> > improved of late so it may not give you much grief.  If you 
> really can't
> > recompile apache, DSO is for you...
> > 
> > see 
> > http://perl.apache.org/guide/install.html
> > specifically
> > 
http://perl.apache.org/guide/install.html#Build_mod_perl_as_a_DSO_inside_t
> 
> HTH
> 
> --Geoff
> 
> 
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, June 28, 2000 3:01 PM
> > To: [EMAIL PROTECTED]
> > Subject: Upgrade
> > 
> > 
> > I have to get mod_perl into a currently runnning apache 
> > server. How does
> > one go about adding mod_perl if not done at compile time?
> > 
> > Sysinfo:
> > FreeBSD 4.0-stable
> > Apache 1.3.6  - source install not ports collection.
> > 
> > 
> > 
> > =
> > Keith W.
> > 
> > At the helm 
> > =
> > 
> > 
> 



RE: Apache::Upload ?

2000-06-29 Thread Geoffrey Young



> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 28, 2000 5:46 PM
> To: Geoffrey Young
> Cc: [EMAIL PROTECTED]
> Subject: Re: Apache::Upload ?
> 
> 
> Geoffrey Young wrote:
> > 
> > the documentation in Apache::Request is pretty complete.  
> I've only tested
> > Apache::Upload and don't use it in production (because I 
> don't need to
> > support uploads) but you can start your script like this:
> > 
> > use strict;
> > my $r = Apache::Request->new(shift);
> > my $upload = $r->upload;
> > 
> > now you have an Apache::Upload object.  use the various 
> methods on $upload
> > as are in the docs.  for instance, the perldoc shows you 
> how to get back a
> > filehandle that you can use to read the file:
> > 
> > my $fh = $upload->fh;
> > my $lines = 0;
> > while(<$fh>) {
> >   ++$lines;
> >   ...
> > }
> > 
> > HTH
> > 
> > --Geoff
> > 
> > > -Original Message-
> > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, June 28, 2000 3:31 PM
> > > To: Geoffrey Young
> > > Cc: 'Casey Bristow'; [EMAIL PROTECTED]
> > > Subject: Re: Apache::Upload ?
> > >
> > >
> > > i to need an upload solution
> > >
> > > to get Apache::Request::upload in i just
> > > cpan'd it down as
> > > install Bundle::Apache
> > > there was quite a few dependencies
> > > that it needed
> > >
> > > i then restarted apache
> > >
> > > and perl-status had it in there
> > >
> > > now my question is does anyone have a example script 
> using this upload
> > > feature?
> > >
> > > i saw some snippets in perldoc Apache::Request
> > > that are quite usable
> > > but if someone has an example
> > > it would simply save me some time!
> > >
> > > thanks
> > >
> 
> hmm , ive been try for the last while based on your 
> suggestions and the
> preldoc man
> 
> here are the files ive been using
> can you tell me whats wrong?
> 
> PerlRun: `Can't locate object method "new" via package 
> "Apache::Request"
> at /home/www/perl/uploadstuff.pl line 8.

you might want to add 

use Apache::Request;

at the top of that script. 

--Geoff

> 
> is what i get
> 



RE: can't properly append to file from mod_perl script

2000-06-29 Thread Geoffrey Young

you might want to 'use strict' and see what pops up :)

additionally, you might want to read up on mod_perl_traps.pod and 
http://perl.apache.org/guide/porting.html

specifically
http://perl.apache.org/guide/porting.html#Exposing_Apache_Registry_secret


HTH

--Geoff

> -Original Message-
> From: Rob Egan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, June 28, 2000 6:38 PM
> To: [EMAIL PROTECTED]
> Subject: can't properly append to file from mod_perl script
> 
> 
> Hi,
> 
> I am relocating content from a non-mod_perl Apache site to a new
> mod_perl/1.24 enabled Apache server and I have a problems 
> getting one of the
> CGI scripts to behave in mod_perl. All it does is capture 
> e-mail addresses,
> and place them in a text file so we can gather them up later 
> and drop them
> into a database. If you run the script as a regular CGI 
> (without mod_perl
> enabled) it works great. But on the mod_perl enabled server, 
> the script
> throws garbage into the file and overwrites previous entries if a user
> submits more than one e-mail address in a single session 
> (i.e. they enter
> one address, click "Back", then enter another address). 
> However, if the user
> submits one e-mail address, then quits their browser, 
> restarts the browser
> and enters another e-mail, it works just fine. Does anybody 
> have any idea
> why this would happen? I've included the CGI script below 
> with actual URL's
> omitted (which was written by some consultant who no longer 
> works here).
> Thanks!
> 
> -Rob
> [EMAIL PROTECTED]
> 
> -begin script text
> #!/usr/local/bin/perl
> 
> $|=1;
> 
> # Enumerate the locking options for clarity...
> $LOCK_EX = 2;
> $LOCK_UN = 8;
> $results_file = "./results.csv";
> $cl = $ENV{'CONTENT_LENGTH'};
> $rqm = $ENV{'REQUEST_METHOD'};
> 
> sub lock {
>   # print "locking";
>   flock(RESULTS, $LOCK_EX);
>   # print "seeking";
>   # seeks to the end of the file in case
>   # someone got while we were waiting for the lock
>   seek(RESULTS, 0, 2);
>   # print "locked";
> }
> 
> sub unlock {
>   # print "unlocking";
>   flock(RESULTS, $LOCK_UN);
>   # print "unlocked";
> }
> 
> sub web_die {
> print "Location:  http://";
> die("\n");
> }
> 
> sub web_die_action {
> print "Location:  http://";
> die("\n");
> }
> 
> sub return_error
> {
>   local ($status, $keyword, $message) = @_;
> 
>   print "Content-type: text/html", "\n";
>   print "Status: ", $status, " ", $keyword, "\n\n";
> 
>   print < 
> Unexpected CGI Error
> 
> $keyword
> $message
> 
> 
> End_of_Error
>   exit(1);
> }
> sub write_entry
> {
>   # Lock after you open
>   &lock();
> 
>   $count = 0;
>   foreach (keys %FORM)
>   {
>$count++;
>   }
> 
>   for ($i = 0; $i < $count; $i++)
>   {
> $index = $i + 1;
> if ($FORM{"FIELD_$index"} eq "")
>  {
>   $FORM{"FIELD_$index"} = "NO ENTRY";
>  }
> $FORM{"FIELD_$index"} =~ s/\"/\"\"/g;  # 
> ...change " to ""
> $FORM{"FIELD_$index"} =~ s/\r//g;  # 
> ...kill line feeds
> $FORM{"FIELD_$index"} =~ s/\n/ /g; # 
> ...change cr to whitespace
> $FORM{"FIELD_$index"} = "\"" . 
> $FORM{"FIELD_$index"} . "\"";
> print RESULTS $FORM{"FIELD_$index"};
> print RESULTS ","
>}
>   print RESULTS "\n";
> 
>   # Unlock before you close
>   &unlock();
> 
>   close(RESULTS);
> 
>   &location;
> }
> 
> if ($rqm eq "POST")
>  {
>   read(STDIN, $buffer, $cl);
>   @pairs = split(/&/, $buffer);
>   $q = 0;
>   foreach $pair (@pairs)
>{
> $q++;
> ($name, $value) = split(/=/, $pair);
> $FORM{"FIELD_$q"} = $value;
> $FORM{"FIELD_$q"} =~ tr/+/ /;
> $FORM{"FIELD_$q"} =~ 
> s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> if ($FORM{"FIELD_$q"} eq "0-12")
>  {
>&location;
>exit(0);
>  }
>}
>  }
> elsif ($cl > 0)
>  {
>   &web_die_action;
> # Error: form results must be submitted with method POST
>  }
> 
> ###
> if (! (-e $results_file))
> {
>   if (open (RESULTS, ">results.csv"))
>   {
>   &write_entry;
>   }
>   else
>   {
>   &return_error (500, "Results Error", "Cannot 
> create results.csv to store
> entries.");
>   }
> }
> 
> else
> {
>   if (! ((-r $results_file) && (-w $results_file)) )
>   {
>   &return_error (500, "Results Error", "Cannot 
> read or write to
> results.csv.");
>   }
>   else
>   {
>   open(RESULTS, ">>results.csv") || &web_die;
>   &write_entry;
>   }
> }
> exit(0);
> sub location
> {
> print "Location:  http://";
> }
> 



does __END__ at the end save memory?

2000-06-29 Thread Vladislav Safronov

Hi, 

Does __END__ directive at the end of every mod_perl script
reduce memory used by httpd ?

Best regards,

/Vlad



multipart_buffer patch for libapreq

2000-06-29 Thread joe

Here's another patch for libapreq that should help keep 
Apache::Request from hogging memory during large file uploads.

The 2 main problems with the multipart_buffer code are

1) the loop in multipart_buffer_fill needs "optimizing".

   The my_join call (line 142 in multipart_buffer.c) mallocs
   a brand new buffer with each pass of the loop. This is BAD.

2) multipart_buffer_read (line 225 in multipart_buffer.c) mallocs 
   with each function call. 

   A large file upload calls this code repeatedly 
   (427-430 inapache_request.c), so you wind up shoving another 
   copy of the entire file into r->pool.

Here's the patch. I parsed a 50M file with it using Apache::Request,
but that's about the full extent to which it's been tested.



diff -ur libapreq-0.31/c/multipart_buffer.c libapreq-0.31-new/c/multipart_buffer.c
--- libapreq-0.31/c/multipart_buffer.c	Sat May  1 02:44:28 1999
+++ libapreq-0.31-new/c/multipart_buffer.c	Thu Jun 29 01:58:43 2000
@@ -55,111 +55,112 @@
  *
  */
 
+/* JS: 6/29/2000
+ * This should fix the memory allocation issues.
+ */
+
+
 #include "multipart_buffer.h"
 
-#define FILLUNIT (1024 * 5)
 #ifndef CRLF
 #define CRLF "\015\012"
 #endif
 #define CRLF_CRLF "\015\012\015\012"
+#define min(A, B) ((A) < (B) ? (A) : (B))
+
+#define DEBUG 0 /* 0 = off, 1 = noisy */
 
 static char *my_join(pool *p, char *one, int lenone, char *two, int lentwo)
 {
-char *res; 
-int len = lenone+lentwo;
-res = (char *)ap_palloc(p, len + 1); 
-memcpy(res, one, lenone);  
+char *res;
+res = (char *)ap_palloc(p, lenone + lentwo  + 1);
+memcpy(res, one, lenone);
 memcpy(res+lenone, two, lentwo);
+*(res+lenone+lentwo+1) = '\0';
 return res;
 }
 
-static char * 
-my_ninstr(register char *big, register char *bigend, char *little, char *lend) 
-{ 
-register char *s, *x; 
-register int first = *little; 
-register char *littleend = lend; 
- 
-if (!first && little >= littleend) {
-return big; 
-}
-if (bigend - big < littleend - little) {
-return NULL; 
-}
-bigend -= littleend - little++; 
-while (big <= bigend) { 
-	if (*big++ != first) {
-	continue; 
-	}
-	for (x=big,s=little; s < littleend; /**/ ) { 
-	if (*s++ != *x++) { 
-		s--; 
-		break; 
-	}
-	}
-	if (s >= littleend) {
-	return big-1; 
-	}
+void multipart_buffer_flush(multipart_buffer *self)
+{
+/* shifts all unread data in the buffer to the beginning of the buffer */
+
+char *ptr = self->buffer;
+while ( ptr < self->buffer + self->buffer_len) {
+	*ptr = *(ptr + self->buffer_off);
+	++ptr;
 }
-return NULL; 
-} 
+
+self->buffer_off = 0;
+}
+
 
 /*
  * This fills up our internal buffer in such a way that the
  * boundary is never split between reads
  */
-void multipart_buffer_fill(multipart_buffer *self, long bytes)
+
+int multipart_buffer_fill(multipart_buffer *self, long bytes)
 {
-int len_read, length, bytes_to_read;
-int buffer_len = self->buffer_len;
+
+int len_read=0, length, bytes_to_read, total=0;
 
 if (!self->length) {
 	return;
 }
-length = (bytes - buffer_len) + self->boundary_length + 2;
-if (self->length < length) {
-	length = self->length;
+
+bytes_to_read = min( (BUFSIZE) - self->buffer_len, min( bytes, self->length) );
+
+if ( bytes_to_read + self->buffer_off + self->buffer_len > BUFSIZE ) 
+{ /* overflow condition- need to flush stale data */
+	multipart_buffer_flush(self);
 }
-bytes_to_read = length;
+
+#if DEBUG == 1
+ap_log_rerror(MPB_ERROR,
+ 		  "[libapreq]: BUFFER_FILL: SIZE=%d, OFF=%d, LENGTH=%d", 
+ 		  bytes_to_read, self->buffer_off,
+  		  self->buffer_len);
+#endif /* DEBUG */
 
 ap_hard_timeout("multipart_buffer_fill", self->r);
+
+total = bytes_to_read;
+
 while (bytes_to_read > 0) {
-	/*XXX: we can optimize this loop*/ 
-	char *buff = (char *)ap_pcalloc(self->subp,
-	sizeof(char) * bytes_to_read + 1);
-	len_read = ap_get_client_block(self->r, buff, bytes_to_read);
+
+	char *buff = self->buffer + self->buffer_len + self->buffer_off;
+	len_read = ap_get_client_block(self->r, 
+	  buff, 
+	  bytes_to_read);
 
 	if (len_read < 0) {
 	ap_log_rerror(MPB_ERROR,
 			  "[libapreq] client dropped connection during read");
 	self->length = 0;
-	self->buffer = NULL;
 	self->buffer_len = 0;
-	return;
+	multipart_buff_flush(self);
+	return 0;
 	}
 
-	self->buffer = self->buffer ? 
-	my_join(self->r->pool, 
-		self->buffer, self->buffer_len, 
-		buff, len_read) :
-	ap_pstrndup(self->r->pool, buff, len_read);
-
-	self->total  += len_read;
 	self->buffer_len += len_read;
-	self->length -= len_read;
-	bytes_to_read-= len_read;
+	bytes_to_read -= len_read;
 
 	ap_reset_timeout(self->r);
 }
+
+self->total += total;
+self->length -= total;
+
 ap_kill_timeout(self->r);
-ap_clear_pool(self->subp);
+   
+return total;
 }
 
 char *multipart_buffer_read(multipart_buffer