Author: joes
Date: Tue Feb 15 21:04:37 2005
New Revision: 153992
URL: http://svn.apache.org/viewcvs?view=rev&rev=153992
Log:
Add core table accessors for APR::Request::Param::Table and
APR::Request::Cookie::Table.
Modified:
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Cookie/Cookie.xs
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Param/Param.xs
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/apreq_xs_postperl.h
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/maps/apreq_functions.map
Modified:
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Cookie/Cookie.xs
URL:
http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Cookie/Cookie.xs?view=diff&r1=153991&r2=153992
==============================================================================
---
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Cookie/Cookie.xs
(original)
+++
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Cookie/Cookie.xs
Tue Feb 15 21:04:37 2005
@@ -16,7 +16,7 @@
return rv;
}
-static int apreq_xs_jar_values(void *data, const char *key, const char *val)
+static int apreq_xs_table_values(void *data, const char *key, const char *val)
{
struct apreq_xs_do_arg *d = (struct apreq_xs_do_arg *)data;
dTHXa(d->perl);
@@ -55,7 +55,16 @@
sv_2mortal(ST(0));
XSRETURN(1);
}
- XSRETURN_UNDEF;
+ else {
+ const apr_table_t *t;
+ apr_status_t s;
+
+ s = apreq_jar(req, &t);
+ if (s != APR_SUCCESS && !sv_derived_from(sv, error_pkg))
+ APREQ_XS_THROW_ERROR("r", s, "APR::Request::jar", error_pkg);
+
+ XSRETURN_UNDEF;
+ }
}
else {
struct apreq_xs_do_arg d = {NULL, NULL, NULL, aTHX};
@@ -77,7 +86,7 @@
if (items == 1)
apr_table_do(apreq_xs_table_keys, &d, t, NULL);
else
- apr_table_do(apreq_xs_jar_values, &d, t,
+ apr_table_do(apreq_xs_table_values, &d, t,
SvPV_nolen(ST(1)), NULL);
return;
@@ -91,6 +100,139 @@
}
}
}
+
+
+static XS(apreq_xs_table_get)
+{
+ dXSARGS;
+ const apr_table_t *t;
+ apreq_handle_t *req;
+ const char *elt_pkg = "APR::Request::Param";
+ SV *sv, *t_obj, *r_obj;
+ IV iv;
+
+ if (items == 0 || items > 2 || !SvROK(ST(0)))
+ Perl_croak(aTHX_ "Usage: APR::Request::Cookie::Table::get($req
[,$name])");
+
+ sv = ST(0);
+
+ t_obj = apreq_xs_find_obj(aTHX_ sv, "cookie");
+ iv = SvIVX(SvRV(t_obj));
+ t = INT2PTR(const apr_table_t *, iv);
+
+ r_obj = apreq_xs_find_obj(aTHX_ t_obj, "request");
+ iv = SvIVX(SvRV(r_obj));
+ req = INT2PTR(apreq_handle_t *, iv);
+
+ if (items == 2 && GIMME_V == G_SCALAR) {
+ const char *v = apr_table_get(t, SvPV_nolen(ST(1)));
+
+ if (v != NULL) {
+ ST(0) = apreq_xs_cookie2sv(aTHX_ apreq_value_to_cookie(v),
elt_pkg, r_obj);
+ sv_2mortal(ST(0));
+ XSRETURN(1);
+ }
+ else {
+ XSRETURN_UNDEF;
+ }
+ }
+ else if (GIMME_V == G_ARRAY) {
+ struct apreq_xs_do_arg d = {NULL, NULL, NULL, aTHX};
+
+ d.pkg = elt_pkg;
+ d.parent = r_obj;
+ XSprePUSH;
+ PUTBACK;
+ if (items == 1)
+ apr_table_do(apreq_xs_table_keys, &d, t, NULL);
+ else
+ apr_table_do(apreq_xs_table_values, &d, t,
+ SvPV_nolen(ST(1)), NULL);
+ }
+ else
+ XSRETURN(0);
+}
+
+static XS(apreq_xs_table_FETCH)
+{
+ dXSARGS;
+ SV *sv, *t_obj, *r_obj;
+ IV iv, idx;
+ const char *key, *pkg;
+ const char *val;
+ const apr_table_t *t;
+ const apr_array_header_t *arr;
+ apr_table_entry_t *te;
+ apreq_handle_t *req;
+
+ if (items != 2 || !SvROK(ST(0)) || !SvOK(ST(1)))
+ Perl_croak(aTHX_ "Usage: $table->FETCH($key)");
+
+ sv = ST(0);
+ t_obj = apreq_xs_find_obj(aTHX_ sv, "cookie");
+ iv = SvIVX(SvRV(t_obj));
+ t = INT2PTR(const apr_table_t *, iv);
+
+ r_obj = apreq_xs_find_obj(aTHX_ t_obj, "request");
+ iv = SvIVX(SvRV(r_obj));
+ req = INT2PTR(apreq_handle_t *, iv);
+
+ pkg = "APR::Request::Cookie";
+
+ key = SvPV_nolen(ST(1));
+ idx = SvCUR(SvRV(r_obj));
+ arr = apr_table_elts(t);
+ te = (apr_table_entry_t *)arr->elts;
+
+ if (idx > 0 && idx <= arr->nelts
+ && !strcasecmp(key, te[idx-1].key))
+ val = te[idx-1].val;
+ else
+ val = apr_table_get(t, key);
+
+ if (val != NULL) {
+ ST(0) = apreq_xs_cookie2sv(aTHX_ apreq_value_to_cookie(val), pkg,
r_obj);
+ sv_2mortal(ST(0));
+ XSRETURN(1);
+ }
+ else
+ XSRETURN_UNDEF;
+}
+
+static XS(apreq_xs_table_NEXTKEY)
+{
+ dXSARGS;
+ SV *sv, *obj;
+ IV iv, idx;
+ const apr_table_t *t;
+ const apr_array_header_t *arr;
+ apr_table_entry_t *te;
+
+ if (!SvROK(ST(0)))
+ Perl_croak(aTHX_ "Usage: $table->NEXTKEY($prev)");
+
+ sv = ST(0);
+ obj = apreq_xs_find_obj(aTHX_ sv, "param");
+ obj = SvRV(obj);
+
+ iv = SvIVX(obj);
+ t = INT2PTR(const apr_table_t *, iv);
+ arr = apr_table_elts(t);
+ te = (apr_table_entry_t *)arr->elts;
+
+ if (items == 1)
+ SvCUR(obj) = 0;
+
+ if (SvCUR(obj) >= arr->nelts) {
+ SvCUR(obj) = 0;
+ XSRETURN_UNDEF;
+ }
+ idx = SvCUR(obj)++;
+ sv = newSVpv(te[idx].key, 0);
+ ST(0) = sv_2mortal(sv);
+ XSRETURN(1);
+}
+
static XS(XS_APR__Request__Cookie_nil)
{
Modified:
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Param/Param.xs
URL:
http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Param/Param.xs?view=diff&r1=153991&r2=153992
==============================================================================
---
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Param/Param.xs
(original)
+++
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/APR/Request/Param/Param.xs
Tue Feb 15 21:04:37 2005
@@ -62,13 +62,23 @@
if (items == 2 && GIMME_V == G_SCALAR) {
- apreq_param_t *c = apreq_args_get(req, SvPV_nolen(ST(1)));
- if (c != NULL) {
- ST(0) = apreq_xs_param2sv(aTHX_ c, elt_pkg, obj);
+ apreq_param_t *p = apreq_args_get(req, SvPV_nolen(ST(1)));
+
+ if (p != NULL) {
+ ST(0) = apreq_xs_param2sv(aTHX_ p, elt_pkg, obj);
sv_2mortal(ST(0));
XSRETURN(1);
}
+ else {
+ const apr_table_t *t;
+ apr_status_t s;
+ s = apreq_args(req, &t);
+
+ if (s != APR_SUCCESS && !sv_derived_from(sv, error_pkg))
+ APREQ_XS_THROW_ERROR("r", s, "APR::Request::args", error_pkg);
+
XSRETURN_UNDEF;
+ }
}
else {
struct apreq_xs_do_arg d = {NULL, NULL, NULL, aTHX};
@@ -126,13 +136,23 @@
if (items == 2 && GIMME_V == G_SCALAR) {
- apreq_param_t *c = apreq_body_get(req, SvPV_nolen(ST(1)));
- if (c != NULL) {
- ST(0) = apreq_xs_param2sv(aTHX_ c, elt_pkg, obj);
+ apreq_param_t *p = apreq_body_get(req, SvPV_nolen(ST(1)));
+
+ if (p != NULL) {
+ ST(0) = apreq_xs_param2sv(aTHX_ p, elt_pkg, obj);
sv_2mortal(ST(0));
XSRETURN(1);
}
+ else {
+ const apr_table_t *t;
+ apr_status_t s;
+ s = apreq_body(req, &t);
+
+ if (s != APR_SUCCESS && !sv_derived_from(sv, error_pkg))
+ APREQ_XS_THROW_ERROR("r", s, "APR::Request::args", error_pkg);
+
XSRETURN_UNDEF;
+ }
}
else {
struct apreq_xs_do_arg d = {NULL, NULL, NULL, aTHX};
@@ -169,6 +189,139 @@
}
}
}
+
+
+static XS(apreq_xs_table_get)
+{
+ dXSARGS;
+ const apr_table_t *t;
+ apreq_handle_t *req;
+ const char *elt_pkg = "APR::Request::Param";
+ SV *sv, *t_obj, *r_obj;
+ IV iv;
+
+ if (items == 0 || items > 2 || !SvROK(ST(0)))
+ Perl_croak(aTHX_ "Usage: APR::Request::body($req [,$name])");
+
+ sv = ST(0);
+
+ t_obj = apreq_xs_find_obj(aTHX_ sv, "param");
+ iv = SvIVX(SvRV(t_obj));
+ t = INT2PTR(const apr_table_t *, iv);
+
+ r_obj = apreq_xs_find_obj(aTHX_ t_obj, "request");
+ iv = SvIVX(SvRV(r_obj));
+ req = INT2PTR(apreq_handle_t *, iv);
+
+ if (items == 2 && GIMME_V == G_SCALAR) {
+ const char *v = apr_table_get(t, SvPV_nolen(ST(1)));
+
+ if (v != NULL) {
+ ST(0) = apreq_xs_param2sv(aTHX_ apreq_value_to_param(v), elt_pkg,
r_obj);
+ sv_2mortal(ST(0));
+ XSRETURN(1);
+ }
+ else {
+ XSRETURN_UNDEF;
+ }
+ }
+ else if (GIMME_V == G_ARRAY) {
+ struct apreq_xs_do_arg d = {NULL, NULL, NULL, aTHX};
+
+ d.pkg = elt_pkg;
+ d.parent = r_obj;
+ XSprePUSH;
+ PUTBACK;
+ if (items == 1)
+ apr_table_do(apreq_xs_table_keys, &d, t, NULL);
+ else
+ apr_table_do(apreq_xs_table_values, &d, t,
+ SvPV_nolen(ST(1)), NULL);
+ }
+ else
+ XSRETURN(0);
+}
+
+static XS(apreq_xs_table_FETCH)
+{
+ dXSARGS;
+ SV *sv, *t_obj, *r_obj;
+ IV iv, idx;
+ const char *key, *pkg;
+ const char *val;
+ const apr_table_t *t;
+ const apr_array_header_t *arr;
+ apr_table_entry_t *te;
+ apreq_handle_t *req;
+
+ if (items != 2 || !SvROK(ST(0)) || !SvOK(ST(1)))
+ Perl_croak(aTHX_ "Usage: $table->FETCH($key)");
+
+ sv = ST(0);
+ t_obj = apreq_xs_find_obj(aTHX_ sv, "param");
+ iv = SvIVX(SvRV(t_obj));
+ t = INT2PTR(const apr_table_t *, iv);
+
+ r_obj = apreq_xs_find_obj(aTHX_ t_obj, "request");
+ iv = SvIVX(SvRV(r_obj));
+ req = INT2PTR(apreq_handle_t *, iv);
+
+ pkg = "APR::Request::Param";
+
+ key = SvPV_nolen(ST(1));
+ idx = SvCUR(SvRV(r_obj));
+ arr = apr_table_elts(t);
+ te = (apr_table_entry_t *)arr->elts;
+
+ if (idx > 0 && idx <= arr->nelts
+ && !strcasecmp(key, te[idx-1].key))
+ val = te[idx-1].val;
+ else
+ val = apr_table_get(t, key);
+
+ if (val != NULL) {
+ ST(0) = apreq_xs_param2sv(aTHX_ apreq_value_to_param(val), pkg, r_obj);
+ sv_2mortal(ST(0));
+ XSRETURN(1);
+ }
+ else
+ XSRETURN_UNDEF;
+}
+
+static XS(apreq_xs_table_NEXTKEY)
+{
+ dXSARGS;
+ SV *sv, *obj;
+ IV iv, idx;
+ const apr_table_t *t;
+ const apr_array_header_t *arr;
+ apr_table_entry_t *te;
+
+ if (!SvROK(ST(0)))
+ Perl_croak(aTHX_ "Usage: $table->NEXTKEY($prev)");
+
+ sv = ST(0);
+ obj = apreq_xs_find_obj(aTHX_ sv, "param");
+ obj = SvRV(obj);
+
+ iv = SvIVX(obj);
+ t = INT2PTR(const apr_table_t *, iv);
+ arr = apr_table_elts(t);
+ te = (apr_table_entry_t *)arr->elts;
+
+ if (items == 1)
+ SvCUR(obj) = 0;
+
+ if (SvCUR(obj) >= arr->nelts) {
+ SvCUR(obj) = 0;
+ XSRETURN_UNDEF;
+ }
+ idx = SvCUR(obj)++;
+ sv = newSVpv(te[idx].key, 0);
+ ST(0) = sv_2mortal(sv);
+ XSRETURN(1);
+}
+
static XS(XS_APR__Request__Param_nil)
{
@@ -208,3 +361,5 @@
);
newXS("APR::Request::Param::()", XS_APR__Request__Param_nil, file);
newXS("APR::Request::Param::(\"\"", XS_APR__Request__Param_value, file);
+
+
Modified:
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/apreq_xs_postperl.h
URL:
http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/apreq_xs_postperl.h?view=diff&r1=153991&r2=153992
==============================================================================
---
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/apreq_xs_postperl.h
(original)
+++
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/apreq_xs_postperl.h
Tue Feb 15 21:04:37 2005
@@ -118,6 +118,14 @@
return INT2PTR(apreq_handle_t *,iv);
}
+APR_INLINE
+static const apr_table_t *apreq_xs_get_table(pTHX_ SV *sv, const char *name)
+{
+ SV *obj = apreq_xs_find_obj(aTHX_ sv, name);
+ IV iv = SvIVX(SvRV(obj));
+ return INT2PTR(apr_table_t *,iv);
+}
+
/**
* Searches a perl object ref with apreq_xs_find_obj
* and produces a pointer to the underlying C environment.
Modified:
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/maps/apreq_functions.map
URL:
http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/maps/apreq_functions.map?view=diff&r1=153991&r2=153992
==============================================================================
---
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/maps/apreq_functions.map
(original)
+++
httpd/apreq/branches/multi-env-unstable/glue/perl/xsbuilder/maps/apreq_functions.map
Tue Feb 15 21:04:37 2005
@@ -125,6 +125,14 @@
MODULE=APR::Request::Cookie PACKAGE=APR::Request PREFIX=APR__Request_
DEFINE_jar | apreq_xs_jar |
+MODULE=APR::Request::Cookie PACKAGE=APR::Request::Cookie::Table
PREFIX=APR__Request__Cookie__Table_
+DEFINE_get | apreq_xs_table_get |
+DEFINE_FETCH | apreq_xs_table_FETCH |
+#DEFINE_new | apreq_xs_table_make |
+DEFINE_NEXTKEY | apreq_xs_table_NEXTKEY |
+DEFINE_FIRSTKEY | apreq_xs_table_NEXTKEY |
+#DEFINE_do | apreq_xs_table_do |
+
#################### APR::Request::Param stuff ####################
@@ -134,3 +142,11 @@
MODULE=APR::Request::Param PACKAGE=APR::Request PREFIX=APR__Request_
DEFINE_args | apreq_xs_args |
DEFINE_body | apreq_xs_body |
+
+MODULE=APR::Request::Param PACKAGE=APR::Request::Param::Table
PREFIX=APR__Request__Param__Table_
+DEFINE_get | apreq_xs_table_get |
+DEFINE_FETCH | apreq_xs_table_FETCH |
+#DEFINE_new | apreq_xs_table_make |
+DEFINE_NEXTKEY | apreq_xs_table_NEXTKEY |
+DEFINE_FIRSTKEY | apreq_xs_table_NEXTKEY |
+#DEFINE_do | apreq_xs_table_do |