joes        2004/06/28 14:58:15

  Modified:    .        CHANGES
               glue/perl/t/response/TestApReq request.pm
               glue/perl/xsbuilder/Apache/Request Apache__Request.h
                        Request_pod
               glue/perl/xsbuilder/Apache/Upload Apache__Upload.h Upload_pm
                        Upload_pod
               glue/perl/xsbuilder/maps apreq_functions.map apreq_types.map
  Removed:     glue/perl/xsbuilder/maps apache_types.map apr_types.map
  Log:
    $upload->info returns a proper APR::Table object now, however this
    may break Win32 port, which now may need to link Upload.dll against APR.lib.
    Also implemented $upload->size, $upload->fh, and $upload->type.
  
  Revision  Changes    Path
  1.45      +5 -0      httpd-apreq-2/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/CHANGES,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- CHANGES   26 Jun 2004 01:36:24 -0000      1.44
  +++ CHANGES   28 Jun 2004 21:58:15 -0000      1.45
  @@ -3,6 +3,11 @@
   
   @section v2_04_dev Changes with libapreq2-2.04-dev
   
  +
  +- Perl API [joes]
  +  $upload->info returns a proper APR::Table object now. Also implemented
  +  $upload->size, $upload->fh, and $upload->type.
  +
   - C API [Jean-Fran�ois Meesse]
     mfd parser fails to parse CRLF-terminated files when the terminating
     boundary string is at the start of a new bucket.  This is reportedly
  
  
  
  1.12      +1 -0      httpd-apreq-2/glue/perl/t/response/TestApReq/request.pm
  
  Index: request.pm
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/response/TestApReq/request.pm,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- request.pm        26 Jun 2004 21:35:10 -0000      1.11
  +++ request.pm        28 Jun 2004 21:58:15 -0000      1.12
  @@ -44,6 +44,7 @@
       elsif ($test eq 'fh_read') {
           my $upload = $req->upload(($req->upload)[0]);
           my $fh = $upload->fh;
  +        return unless $upload->info->{"Content-Type"} eq $upload->type;
           $r->print(<$fh>);
       }
   
  
  
  
  1.30      +9 -0      
httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h
  
  Index: Apache__Request.h
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Apache__Request.h,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- Apache__Request.h 14 Jun 2004 02:02:23 -0000      1.29
  +++ Apache__Request.h 28 Jun 2004 21:58:15 -0000      1.30
  @@ -93,6 +93,15 @@
           else if (strcasecmp(attr, "MAX_BRIGADE") == 0) {
               apreq_env_max_brigade(req->env, (apr_ssize_t)apreq_atoi64f(val));
           }
  +        else if (strcasecmp(attr, "DISABLE_UPLOADS") == 0) {
  +            ;
  +        }
  +        else if (strcasecmp(attr, "UPLOAD_HOOK") == 0) {
  +            ;
  +        }
  +        else if (strcasecmp(attr, "HOOK_DATA") == 0) {
  +            ;
  +        }
           else {
               Perl_warn(aTHX_ "Apache::Request::config: "
                         "Unrecognized attribute %s", attr);
  
  
  
  1.15      +15 -15    
httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Request_pod
  
  Index: Request_pod
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Request_pod,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Request_pod       27 Jun 2004 18:07:35 -0000      1.14
  +++ Request_pod       28 Jun 2004 21:58:15 -0000      1.15
  @@ -31,7 +31,7 @@
   
   =back
   
  -=head2 new  
  +=head2 C<new>  
   
   creates a new C<Apache::Request> object with an environment object $r:
   
  @@ -44,18 +44,18 @@
   
   =over 4
   
  -=item POST_MAX, MAX_BODY
  +=item C<POST_MAX>, C<MAX_BODY>
   
   Limit the size of POST data (in bytes).
   
  -=item DISABLE_UPLOADS [TODO]
  +=item C<DISABLE_UPLOADS> [TODO]
   
   Disable file uploads.
   
  -=item TEMP_DIR
  +=item C<TEMP_DIR>
   
   Sets the directory where upload files are spooled.  On a *nix-like
  -that supports link(2), the TEMP_DIR should be located on the same
  +that supports I<link(2)>, the TEMP_DIR should be located on the same
   file system as the final destination file:
   
    use Apache::Upload;
  @@ -65,12 +65,12 @@
   
   For more details on C<link>, see the L<Apache:Upload> manpage.
   
  -=item HOOK_DATA (requires L<Apache::Upload>)
  +=item C<HOOK_DATA> (requires C<Apache::Upload>)
   
   Extra configuration info passed to an upload hook.
   See the description for the next item, C<UPLOAD_HOOK>.
   
  -=item UPLOAD_HOOK (requires L<Apache::Upload>)
  +=item C<UPLOAD_HOOK> (requires C<Apache::Upload>)
   
   Sets up a callback to run whenever file upload data is read. This
   can be used to provide an upload progress meter during file uploads.
  @@ -89,7 +89,7 @@
   
   =back
   
  -=head2 C<instance> [DEPRECATED]
  +=head2 C<instance($r)> [DEPRECATED]
   
   The default (and only) behavior of I<Apache::Request> is to intelligently
   cache B<POST> data for the duration of the request.  Thus there is no longer
  @@ -100,7 +100,7 @@
   However an C<instance()> method is aliased to C<new()> in this release
   to ease the pain of porting from 1.X to 2.X.
   
  -=head2 C<param>
  +=head2 C<param([$name])>
   
   Get the request parameters (using case-insensitive keys) by
   mimicing the OO interface of C<CGI::param>.
  @@ -130,14 +130,14 @@
   the "foo" param.
   
   
  -=head2 parms, params [DEPRECATED]
  +=head2 C<parms>, C<params> [DEPRECATED]
   
   The functionality of these functions is assumed by C<param>,
   so they are no longer necessary.  Aliases to C<param> are
   provided in this release for backwards compatibility,
   however they may be removed from a future release.
   
  -=head2 args
  +=head2 C<args([$name])>
   
   Returns an I<Apache::Request::Table> object containing the query-string 
   parameters of the I<Apache::Request> object.
  @@ -149,7 +149,7 @@
   
      my $arg = $req->args($name);
   
  -=head2 body
  +=head2 C<body([$name])>
   
   Returns an I<Apache::Request::Table> object containing the POST data 
   parameters of the I<Apache::Request> object.
  @@ -162,7 +162,7 @@
      my $param = $req->body($name);
   
   
  -=head2 upload (requires Apache::Upload)
  +=head2 C<upload([$name])> (requires Apache::Upload)
   
   With no arguments, this returns an I<Apache::Upload::Table> object in 
   scalar context, or the names of all I<Apache::Upload> objects in
  @@ -190,7 +190,7 @@
        }
   
   
  -=head1 CHANGES in Apache::Request API from 1.X to 2.X
  +=head1 API CHANGES from 1.X to 2.X
   
   =over 4
   
  @@ -210,7 +210,7 @@
   
   =head1 SEE ALSO
   
  -Apache::Cookie(3), Apache::Upload(3), APR::Table(3)
  +L<Apache::Cookie>, L<Apache::Upload>, L<APR::Table>
   
   =head1 CREDITS
   
  
  
  
  1.7       +28 -0     
httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h
  
  Index: Apache__Upload.h
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Apache__Upload.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Apache__Upload.h  27 Jun 2004 22:13:02 -0000      1.6
  +++ Apache__Upload.h  28 Jun 2004 21:58:15 -0000      1.7
  @@ -18,6 +18,10 @@
   /* avoid namespace collisions from perl's XSUB.h */
   #include "modperl_perl_unembed.h"
   
  +/* XXX modperl_* dependency for T_HASHOBJ support */
  +#include "modperl_common_util.h"
  +
  +
   /* Temporary work-around for missing apr_perlio.h file.
    * #include "apr_perlio.h" 
    */
  @@ -141,6 +145,7 @@
   APREQ_XS_DEFINE_GET(upload_table, UPLOAD_TABLE, param, UPLOAD_PKG, 1);
   APREQ_XS_DEFINE_ENV(upload);
   
  +
   APR_INLINE
   static XS(apreq_xs_upload_link)
   {
  @@ -257,6 +262,29 @@
           Perl_croak(aTHX_ "$upload->size: can't get brigade length");
       }
       XSRETURN_IV((IV)len);
  +}
  +static XS(apreq_xs_upload_type)
  +{
  +    dXSARGS;
  +    apreq_param_t *upload;
  +    const char *ct, *sc;
  +    STRLEN len;
  +
  +    if (items != 1 || !SvROK(ST(0)))
  +        Perl_croak(aTHX_ "Usage: $upload->type()");
  +
  +    upload = apreq_xs_sv2param(ST(0));
  +    ct = apr_table_get(upload->info, "Content-Type");
  +    if (ct == NULL)
  +        Perl_croak(aTHX_ "$upload->type: can't find Content-Type header");
  +    
  +    if ((sc = strchr(ct, ';')))
  +        len = sc - ct;
  +    else
  +        len = strlen(ct);
  +
  +    ST(0) = sv_2mortal(newSVpvn(ct,len));
  +    XSRETURN(1);
   }
   
   static APR_OPTIONAL_FN_TYPE(apr_perlio_apr_file_to_glob) *f2g;
  
  
  
  1.4       +1 -0      httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Upload_pm
  
  Index: Upload_pm
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Upload_pm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Upload_pm 26 Jun 2004 03:25:10 -0000      1.3
  +++ Upload_pm 28 Jun 2004 21:58:15 -0000      1.4
  @@ -3,6 +3,7 @@
   use APR::Bucket;
   use APR::Brigade;
   use APR::PerlIO;
  +use Apache::Request;
   
   package Apache::Upload::Table;
   push our(@ISA), "APR::Table";
  
  
  
  1.2       +70 -26    
httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Upload_pod
  
  Index: Upload_pod
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Upload/Upload_pod,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Upload_pod        19 Jun 2004 15:38:18 -0000      1.1
  +++ Upload_pod        28 Jun 2004 21:58:15 -0000      1.2
  @@ -1,3 +1,22 @@
  +=head1 NAME 
  +
  +Apache::Upload - Methods for dealing with file uploads.
  +
  +=head1 SYNOPSIS
  +
  +    use Apache::Upload;
  +
  +    my $req = Apache::Request->new($r);  # $r is an Apache::RequestRec
  +    my $upload_table = $req->upload;
  +    my $upload = $req->upload("file_field"); # same as 
$upload_table->{file_field}
  +    my $size = $upload->size;
  +    $upload->slurp(my $file_contents);
  +    my $fh = $upload->fh;
  +    print while <$fh>;
  +
  +=head1 DESCRIPTION
  +
  +
   =head1 Apache::Upload METHODS
   
   =head2 name
  @@ -12,66 +31,91 @@
   
       my $filename = $upload->filename;
   
  -=head2 bb [replaces fh]
  +=head2 C<fh>
  +
  +Create an I<APR::PerlIO> filehandle from which the upload's contents 
  +may be read.
   
  -The APR::Brigade containing the contents of the uploaded file.
  +=head2 C<bb([$new_brigade])>
   
  -=head2 size [TODO]
  +Returns an I<APR::Brigade> which represents the upload's contents.
  +Passing an optional I<APR::Brigade> argument will reassign the 
  +brigade, which effectively replaces the original contents of the 
  +upload.
   
  -The size of the file in bytes:
  +=head2 C<size()>
  +
  +The size of the upload in bytes:
   
       my $size = $upload->size;
   
  -=head2 info
  +=head2 C<info([$table])>
   
   The additional header information for the uploaded file.
  -Returns a hash reference tied to the I<Apache::Table> class.
  -An optional I<key> argument can be passed to return the value of 
  -a given header rather than a hash reference.  Examples:
  +Returns a hash reference tied to the I<APR::Table> class.
  +An optional C<$table> argument can be passed to reassign
  +the upload's internal (apr_table_t) info table to the one
  +C<$table> represents.
  +
  +Examples:
   
       my $info = $upload->info;
       while (my($key, $val) = each %$info) {
        ...
       }
   
  -    my $val = $upload->info("Content-type");
  +    # fetch upload's Content-Type header
  +    my $type = $upload->info->{"Content-type"};
   
  -=head2 type [TODO]
  +    #reassign table
  +    $upload->info($apr_table_object);
   
  -Returns the I<Content-Type> for the given I<Apache::Upload> object:
  +=head2 C<type()>
   
  -    my $type = $upload->type;
  -    #same as
  -    my $type = $upload->info("Content-Type");
  +Returns the MIME type of the given I<Apache::Upload> object.
   
  -=head2 tempname [XXX- Does this mesh with brigade API?]
  +    my $type = $upload->type;
   
  -Provides the name of the spool file. This method is reserved for
  -debugging purposes, and is possibly subject to change in a future
  -version of Apache::Request.
  +    #same as
  +    my $type = $upload->info->{"Content-Type"};
  +    $type =~ s/;.*$//ms;
   
  -=head2 link
  +=head2 C<link()>
   
   To avoid recopying the upload's internal tempfile brigade on a 
   *nix-like system, I<link> will create a hard link to it:
   
  -  my $upload = $apr->upload('file');
  +  my $upload = $req->upload('file');
     $upload->link("/path/to/newfile") or
         die sprintf "link from '%s' failed: $!", $upload->tempname;
   
  -Typically the new name must lie on the same file system as the
  -brigade's tempfile. Check your system's link(2) manpage for details.
  +Typically the new name must lie on the same device and partition 
  +as the brigade's tempfile.  If this or any other reason prevents
  +the OS from linking the files, C<link()> will instead 
  +copy the temporary file to the specified location.
   
  -=head2 slurp
  +=head2 C<slurp($contents)>
   
   Reads the full contents of a file upload into the scalar argument.
  -The return value is currently an APR status code (0 on success, error 
otherwise),
  -but this may change in a future release (to bring this function
  -in line with similar read-type functions in mp2).
  +The return value is currently an I<APR> status code (0 on success, 
  +error otherwise), but this may change in a future release (to bring 
  +this function in line with similar read-type functions in mp2).
   
     # print out the upload file
     my $contents;
     print $contents if $upload->slurp($contents) == 0;
  +
  +
  +=head1 API CHANGES from v1.X to v2.X
  +
  +C<tempname> has been removed from the API.
  +C<info($header)> is replaced by C<info($table)>.
  +C<type()> returns only the MIME-type portion of the Content-Type header.
  +
  +=head1 SEE ALSO
  +
  +L<Apache::Cookie>, L<Apache::Upload>, L<APR::Table>
  +
   
   
   =head1 MISSING DOCS
  
  
  
  1.22      +1 -0      
httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_functions.map
  
  Index: apreq_functions.map
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_functions.map,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- apreq_functions.map       27 Jun 2004 18:07:35 -0000      1.21
  +++ apreq_functions.map       28 Jun 2004 21:58:15 -0000      1.22
  @@ -29,6 +29,7 @@
    DEFINE_slurp                    | apreq_xs_upload_slurp |
    DEFINE_size                     | apreq_xs_upload_size |
    DEFINE_fh                       | apreq_xs_upload_fh |
  + DEFINE_type                     | apreq_xs_upload_type |
   
   MODULE=Apache::Upload PACKAGE=Apache::Upload::Table 
PREFIX=Apache__Upload__Table_
    DEFINE_get     | apreq_xs_upload_table_get |
  
  
  
  1.5       +8 -2      httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_types.map
  
  Index: apreq_types.map
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/maps/apreq_types.map,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- apreq_types.map   24 Jun 2003 22:27:44 -0000      1.4
  +++ apreq_types.map   28 Jun 2004 21:58:15 -0000      1.5
  @@ -2,11 +2,17 @@
   const apr_size_t | UV
   apr_size_t | UV
   struct SV  | SV
  +apr_status_t | IV
  +const char *  | PV
  +char * | PV
  +void | VOID
  +void * | PTR
  +const void * | PTR
   
   #data structure stuff
  -struct apr_pool_t           | APR::Pool
  +struct apr_pool_t           | APR::Pool | T_POOLOBJ
   struct apr_array_header_t   | APR::ArrayHeader
  -struct apr_table_t          | APR::Table
  +struct apr_table_t          | APR::Table | T_HASHOBJ
   struct apr_bucket_brigade   | APR::Brigade
   #apr_table_entry_t           | APR::TableEntry
   #struct apr_hash_t           | APR::Hash
  
  
  

Reply via email to