joes        2004/06/30 21:11:24

  Modified:    .        CHANGES STATUS
               glue/perl/t/apreq request.t
               glue/perl/t/response/TestApReq request.pm
               glue/perl/xsbuilder apreq_xs_postperl.h
               glue/perl/xsbuilder/Apache/Cookie Apache__Cookie.h Cookie_pm
               glue/perl/xsbuilder/Apache/Request Apache__Request.h
                        Request_pm
               glue/perl/xsbuilder/Apache/Upload Apache__Upload.h
               src      apreq_cookie.c
  Log:
  Add APR::Error based error-checking for param(), body(), args() upload(), and 
get().
  
  Revision  Changes    Path
  1.48      +5 -0      httpd-apreq-2/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/CHANGES,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- CHANGES   29 Jun 2004 22:45:30 -0000      1.47
  +++ CHANGES   1 Jul 2004 04:11:24 -0000       1.48
  @@ -4,6 +4,11 @@
   @section v2_04_dev Changes with libapreq2-2.04-dev
   
   - Perl API [joes]
  +  Added apreq_xs_croak for throwing APR::Error exceptions and included
  +  error-checking on $req->param, $req->args, $req->body, $req->upload, 
  +  and $jar->get.
  +
  +- Perl API [joes]
     Added $jar->status, $req->args_status and $req->body_status to report
     parsing errors. Also add $upload->tempname per user request.
   
  
  
  
  1.57      +3 -5      httpd-apreq-2/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/STATUS,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- STATUS    29 Jun 2004 18:34:48 -0000      1.56
  +++ STATUS    1 Jul 2004 04:11:24 -0000       1.57
  @@ -100,10 +100,8 @@
       - Fix build automake/libtool/autoconf build system so it works
         properly on OSX & AIX.
   
  -    - The current API does not handle failed query_string parsing
  -      adequately (apreq_request does log an error message, but 
  -      there's no status code in the struct for users to interrogate).
  -
  +    - The $jar->cookie, $req->body, and $req->param tables need
  +      support for adding and setting entries.
   
   WISH LIST:
   
  
  
  
  1.10      +2 -2      httpd-apreq-2/glue/perl/t/apreq/request.t
  
  Index: request.t
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/t/apreq/request.t,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- request.t 29 Jun 2004 22:45:30 -0000      1.9
  +++ request.t 1 Jul 2004 04:11:24 -0000       1.10
  @@ -6,7 +6,7 @@
   use Apache::TestUtil;
   use Apache::TestRequest qw(GET_BODY UPLOAD_BODY);
   
  -plan tests => 9, have_lwp;
  +plan tests => 11, have_lwp;
   
   my $location = "/TestApReq__request";
   #print GET_BODY $location;
  @@ -20,7 +20,7 @@
                "basic param");
   }
   
  -for my $test (qw/slurp bb_read fh_read tempfile/) {
  +for my $test (qw/slurp bb_read fh_read tempfile bad;query=string%%/) {
       # upload a string as a file
       my $value = 'DataUpload' x 100_000;
       my $result = UPLOAD_BODY("$location?test=$test", content => $value); 
  
  
  
  1.14      +7 -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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- request.pm        29 Jun 2004 22:45:30 -0000      1.13
  +++ request.pm        1 Jul 2004 04:11:24 -0000       1.14
  @@ -52,6 +52,13 @@
           open my $fh, "<", $upload->tempfile or die $!;
           $r->print(<$fh>);
       }
  +    elsif ($test eq 'bad') {
  +        eval {my $q = $req->args('query')};
  +        if (ref $@ eq "Apache::Request::Error") {
  +            $req->upload("HTTPUPLOAD")->slurp(my $data);
  +            $req->print($data);
  +        }
  +    }
   
       return 0;
   }
  
  
  
  1.29      +33 -14    httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_postperl.h
  
  Index: apreq_xs_postperl.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/glue/perl/xsbuilder/apreq_xs_postperl.h,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- apreq_xs_postperl.h       26 Jun 2004 05:56:17 -0000      1.28
  +++ apreq_xs_postperl.h       1 Jul 2004 04:11:24 -0000       1.29
  @@ -335,42 +335,61 @@
       const char *key = NULL;                                             \
       struct apreq_xs_do_arg d = { NULL, aTHX };                          \
       void *env;                                                          \
  +    SV *sv = ST(0);                                                     \
                                                                           \
       if (items == 0 || items > 2 || !SvROK(ST(0)))                       \
  -        Perl_croak(aTHX_ "Usage: $table->get($key)");                   \
  +        Perl_croak(aTHX_ "Usage: $object->get($key)");                  \
                                                                           \
       env = apreq_xs_##attr##_sv2env(ST(0));                              \
       d.env = env;                                                        \
       if (items == 2)                                                     \
           key = SvPV_nolen(ST(1));                                        \
                                                                           \
  +    XSprePUSH;                                                          \
       switch (GIMME_V) {                                                  \
           apreq_##type##_t *RETVAL;                                       \
                                                                           \
       case G_ARRAY:                                                       \
  -        XSprePUSH;                                                      \
           PUTBACK;                                                        \
  -        apreq_xs_##attr##_push(ST(0), &d, key);                         \
  +        apreq_xs_##attr##_push(sv, &d, key);                            \
           break;                                                          \
                                                                           \
       case G_SCALAR:                                                      \
           if (items == 1) {                                               \
  -            apr_table_t *t = apreq_xs_##attr##_sv2table(ST(0));         \
  -            if (t == NULL)                                              \
  -                XSRETURN_UNDEF;                                         \
  -            ST(0) = sv_2mortal(apreq_xs_table2sv(t,class));             \
  -            XSRETURN(1);                                                \
  +            apr_table_t *t = apreq_xs_##attr##_sv2table(sv);            \
  +            if (t != NULL)                                              \
  +                XPUSHs(sv_2mortal(apreq_xs_table2sv(t,class)));         \
  +            PUTBACK;                                                    \
  +            break;                                                      \
           }                                                               \
                                                                           \
  -        RETVAL = apreq_xs_##attr##_##type(ST(0), key);                  \
  -        if (!RETVAL || !(COND))                                         \
  -            XSRETURN_UNDEF;                                             \
  -        ST(0) = sv_2mortal(apreq_xs_##type##2sv(RETVAL,subclass));      \
  -        XSRETURN(1);                                                    \
  +        RETVAL = apreq_xs_##attr##_##type(sv, key);                     \
  +        if (RETVAL && (COND))                                           \
  +            XPUSHs(sv_2mortal(apreq_xs_##type##2sv(RETVAL,subclass)));  \
                                                                           \
       default:                                                            \
  -        XSRETURN(0);                                                    \
  +        PUTBACK;                                                        \
       }                                                                   \
  +    apreq_xs_##attr##_error_check;                                      \
  +}
  +
  +static APR_INLINE
  +void apreq_xs_croak(pTHX_ HV *data, apr_status_t rc, const char *func, 
  +                   const char *class)
  +{
  +    HV *stash = gv_stashpvn(class, strlen(class), FALSE);
  +
  +    Perl_require_pv(aTHX_ "APR/Error.pm");
  +    if (SvTRUE(ERRSV)) {
  +        Perl_croak(aTHX_ "%s", SvPV_nolen(ERRSV));   
  +    }
  +
  +    sv_setsv(ERRSV, sv_2mortal(sv_bless(newRV_noinc((SV*)data), stash)));
  +    sv_setiv(*hv_fetch(data, "rc",   2, 1), rc);
  +    sv_setpv(*hv_fetch(data, "file", 4, 1), CopFILE(PL_curcop));
  +    sv_setiv(*hv_fetch(data, "line", 4, 1), CopLINE(PL_curcop));
  +    sv_setpv(*hv_fetch(data, "func", 4, 1), func);
  +    Perl_croak(aTHX_ Nullch);
   }
   
   /** @} */
  
  
  
  1.20      +23 -0     
httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Apache__Cookie.h
  
  Index: Apache__Cookie.h
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Apache__Cookie.h,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Apache__Cookie.h  9 Jun 2004 21:02:04 -0000       1.19
  +++ Apache__Cookie.h  1 Jul 2004 04:11:24 -0000       1.20
  @@ -29,6 +29,28 @@
   APREQ_XS_DEFINE_MAKE(cookie);
   APREQ_XS_DEFINE_OBJECT(jar);
   
  +#define apreq_xs_jar_error_check   do {                                 \
  +    int n = PL_stack_sp - (PL_stack_base + ax - 1);                     \
  +    apr_status_t s;                                                     \
  +    switch (GIMME_V) {                                                  \
  +    case G_VOID:                                                        \
  +        break;                                                          \
  +    case G_SCALAR:                                                      \
  +        if (n == 1 && items == 2)                                       \
  +            break;                                                      \
  +    default:                                                            \
  +        s = apreq_xs_sv2(jar, sv)->status;                              \
  +        if (s != APR_SUCCESS) {                                         \
  +            apreq_xs_croak(aTHX_ newHV(), s, "Apache::Cookie::Jar::get",\
  +                           "Apache::Cookie::Error");                    \
  +        }                                                               \
  +    }                                                                   \
  +} while (0)
  +
  +
  +#define apreq_xs_table_error_check 
  +
  +
   /* GET macros */
   #define S2C(s)  apreq_value_to_cookie(apreq_strtoval(s))
   #define apreq_xs_jar_push(sv,d,key)   apreq_xs_push(jar,sv,d,key)
  @@ -42,6 +64,7 @@
                   S2C(apr_table_get(apreq_xs_jar_sv2table(sv),k))
   #define apreq_xs_table_cookie(sv,k) \
                   S2C(apr_table_get(apreq_xs_table_sv2table(sv),k))
  +
   
   #define TABLE_PKG   "Apache::Cookie::Table"
   #define COOKIE_PKG  "Apache::Cookie"
  
  
  
  1.16      +3 -0      httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Cookie_pm
  
  Index: Cookie_pm
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Cookie/Cookie_pm,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Cookie_pm 26 Jun 2004 03:25:10 -0000      1.15
  +++ Cookie_pm 1 Jul 2004 04:11:24 -0000       1.16
  @@ -16,6 +16,9 @@
       }
   }
   
  +package Apache::Cookie::Error;
  +push our(@ISA), "APR::Error";
  +
   package Apache::Cookie;
   
   sub jar {
  
  
  
  1.31      +73 -2     
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.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- Apache__Request.h 28 Jun 2004 21:58:15 -0000      1.30
  +++ Apache__Request.h 1 Jul 2004 04:11:24 -0000       1.31
  @@ -15,6 +15,79 @@
   */
   
   #define READ_BLOCK_SIZE (1024 * 256)
  +#define PARAM_TABLE   "Apache::Request::Table"
  +
  +#define apreq_xs_request_error_check do {                               \
  +    int n = PL_stack_sp - (PL_stack_base + ax - 1);                     \
  +    apreq_request_t *req;                                               \
  +    apr_status_t s;                                                     \
  +    switch (GIMME_V) {                                                  \
  +    case G_VOID:                                                        \
  +        break;                                                          \
  +    case G_SCALAR:                                                      \
  +        if (n == 1 && items == 2)                                       \
  +            break;                                                      \
  +    default:                                                            \
  +        req = apreq_xs_sv2(request, sv);                                \
  +        s = req->args_status;                                           \
  +        if (s == APR_SUCCESS && req->parser)                            \
  +            s = apreq_parse_request(req, NULL);                         \
  +        switch (s) {                                                    \
  +        case APR_INCOMPLETE:                                            \
  +        case APR_SUCCESS:                                               \
  +            break;                                                      \
  +        default:                                                        \
  +            apreq_xs_croak(aTHX_ newHV(), s, "Apache::Request::param",  \
  +                           "Apache::Request::Error");                   \
  +       }                                                                \
  +    }                                                                   \
  +} while (0)
  +
  +#define apreq_xs_args_error_check do {                                  \
  +    int n = PL_stack_sp - (PL_stack_base + ax - 1);                     \
  +    apreq_request_t *req;                                               \
  +    apr_status_t s;                                                     \
  +    switch (GIMME_V) {                                                  \
  +    case G_VOID:                                                        \
  +        break;                                                          \
  +    case G_SCALAR:                                                      \
  +        if (n == 1 && items == 2)                                       \
  +            break;                                                      \
  +    default:                                                            \
  +        req = apreq_xs_sv2(request, sv);                                \
  +        s = req->args_status;                                           \
  +        if (s != APR_SUCCESS)                                           \
  +            apreq_xs_croak(aTHX_ newHV(), s, "Apache::Request::args",   \
  +                           "Apache::Request::Error");                   \
  +    }                                                                   \
  +} while (0)                                                             \
  +
  +#define apreq_xs_body_error_check   do {                                \
  +    int n = PL_stack_sp - (PL_stack_base + ax - 1);                     \
  +    apreq_request_t *req;                                               \
  +    apr_status_t s;                                                     \
  +    switch (GIMME_V) {                                                  \
  +    case G_VOID:                                                        \
  +        break;                                                          \
  +    case G_SCALAR:                                                      \
  +        if (n == 1 && items == 2)                                       \
  +            break;                                                      \
  +    default:                                                            \
  +        req = apreq_xs_sv2(request, sv);                                \
  +        if (req->parser == NULL)                                        \
  +           break;                                                       \
  +        switch (s = apreq_parse_request(req,NULL)) {                    \
  +        case APR_INCOMPLETE:                                            \
  +        case APR_SUCCESS:                                               \
  +            break;                                                      \
  +        default:                                                        \
  +            apreq_xs_croak(aTHX_ newHV(), s, "Apache::Request::body",   \
  +                           "Apache::Request::Error");                   \
  +        }                                                               \
  +    }                                                                   \
  +} while (0)
  +
  +#define apreq_xs_table_error_check
   
   #define apreq_xs_param2rv(ptr, class) apreq_xs_2sv(ptr,class)
   #define apreq_xs_rv2param(sv) ((apreq_param_t *)SvIVX(SvRV(sv)))
  @@ -56,8 +129,6 @@
                        S2P(apr_table_get(apreq_xs_body_sv2table(sv),k))
   #define apreq_xs_table_param(sv,k) \
                        S2P(apr_table_get(apreq_xs_sv2table(sv),k))
  -
  -#define PARAM_TABLE   "Apache::Request::Table"
   
   APREQ_XS_DEFINE_GET(request, PARAM_TABLE, param, NULL, 1);
   APREQ_XS_DEFINE_GET(args,    PARAM_TABLE, param, NULL, 1);
  
  
  
  1.15      +5 -1      
httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Request_pm
  
  Index: Request_pm
  ===================================================================
  RCS file: 
/home/cvs/httpd-apreq-2/glue/perl/xsbuilder/Apache/Request/Request_pm,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Request_pm        29 Jun 2004 18:34:48 -0000      1.14
  +++ Request_pm        1 Jul 2004 04:11:24 -0000       1.15
  @@ -11,6 +11,10 @@
       }
   }
   
  +
  +package Apache::Request::Error;
  +push our(@ISA), "APR::Error";
  +
   package Apache::Request;
   push our(@ISA), __PACKAGE__ -> env;
   
  @@ -33,4 +37,4 @@
      my $req = shift;
      return wantarray ? ($req->args_status, $req->body_status)
                       : $req->args_status || $req->body_status;
  -}
  \ No newline at end of file
  +}
  
  
  
  1.9       +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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Apache__Upload.h  29 Jun 2004 22:45:30 -0000      1.8
  +++ Apache__Upload.h  1 Jul 2004 04:11:24 -0000       1.9
  @@ -84,6 +84,34 @@
   
   
   
  +#define apreq_xs_upload_error_check   do {                              \
  +    int n = PL_stack_sp - (PL_stack_base + ax - 1);                     \
  +    apreq_request_t *req;                                               \
  +    apr_status_t s;                                                     \
  +    switch (GIMME_V) {                                                  \
  +    case G_VOID:                                                        \
  +        break;                                                          \
  +    case G_SCALAR:                                                      \
  +        if (n == 1 && items == 2)                                       \
  +            break;                                                      \
  +    default:                                                            \
  +        req = apreq_xs_sv2(request, sv);                                \
  +        if (req->parser == NULL)                                        \
  +           break;                                                       \
  +        switch (s = apreq_parse_request(req,NULL)) {                    \
  +        case APR_INCOMPLETE:                                            \
  +        case APR_SUCCESS:                                               \
  +            break;                                                      \
  +        default:                                                        \
  +            apreq_xs_croak(aTHX_ newHV(), s, "Apache::Request::upload", \
  +                           "Apache::Request::Error");                   \
  +        }                                                               \
  +    }                                                                   \
  +} while (0)
  +
  +
  +#define apreq_xs_upload_table_error_check 
  +
   
   #define READ_BLOCK_SIZE (1024 * 256)
   #define S2P(s) (s ? apreq_value_to_param(apreq_strtoval(s)) : NULL)
  
  
  
  1.25      +1 -0      httpd-apreq-2/src/apreq_cookie.c
  
  Index: apreq_cookie.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- apreq_cookie.c    29 Jun 2004 18:34:48 -0000      1.24
  +++ apreq_cookie.c    1 Jul 2004 04:11:24 -0000       1.25
  @@ -267,6 +267,7 @@
           j = apr_palloc(p, sizeof *j);
           j->env = env;
           j->cookies = apr_table_make(p, APREQ_NELTS);
  +        j->status = APR_SUCCESS;
   
           hdr = apreq_env_cookie(env);
   
  
  
  

Reply via email to