1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
|
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
static MP_INLINE
int mpxs_Apache2__RequestRec_push_handlers(pTHX_ request_rec *r,
const char *name,
SV *sv)
{
return modperl_handler_perl_add_handlers(aTHX_
r, NULL, r->server, r->pool,
name, sv,
MP_HANDLER_ACTION_PUSH);
}
static MP_INLINE
int mpxs_Apache2__RequestRec_set_handlers(pTHX_ request_rec *r,
const char *name,
SV *sv)
{
return modperl_handler_perl_add_handlers(aTHX_
r, NULL, r->server, r->pool,
name, sv,
MP_HANDLER_ACTION_SET);
}
static MP_INLINE
SV *mpxs_Apache2__RequestRec_get_handlers(pTHX_ request_rec *r,
const char *name)
{
MpAV **handp =
modperl_handler_get_handlers(r, NULL, r->server,
r->pool, name,
MP_HANDLER_ACTION_GET);
return modperl_handler_perl_get_handlers(aTHX_ handp, r->pool);
}
/*
* XXX: these three should be part of the apache api
* for protocol module helpers
*/
static MP_INLINE
SV *mpxs_Apache2__RequestRec_new(pTHX_ SV *classname,
conn_rec *c,
SV *base_pool_sv)
{
apr_pool_t *p, *base_pool;
request_rec *r;
server_rec *s = c->base_server;
SV *r_sv;
/* see: httpd-2.0/server/protocol.c:ap_read_request */
if (base_pool_sv) {
base_pool = mp_xs_sv2_APR__Pool(base_pool_sv);
}
else {
base_pool = c->pool;
}
apr_pool_create(&p, base_pool);
r = apr_pcalloc(p, sizeof(request_rec));
r->pool = p;
r->connection = c;
r->server = s;
r->request_time = apr_time_now();
r->user = NULL;
r->ap_auth_type = NULL;
r->allowed_methods = ap_make_method_list(p, 1);
r->headers_in = apr_table_make(p, 1);
r->subprocess_env = apr_table_make(r->pool, 1);
r->headers_out = apr_table_make(p, 1);
r->err_headers_out = apr_table_make(p, 1);
r->notes = apr_table_make(p, 1);
r->request_config = ap_create_request_config(p);
r->proto_output_filters = c->output_filters;
r->output_filters = r->proto_output_filters;
r->proto_input_filters = c->input_filters;
r->input_filters = r->proto_input_filters;
ap_run_create_request(r);
r->per_dir_config = s->lookup_defaults;
r->sent_bodyct = 0;
r->read_length = 0;
r->read_body = REQUEST_NO_BODY;
r->status = HTTP_OK;
r->the_request = "UNKNOWN";
r->hostname = s->server_hostname;
r->method = "GET";
r->method_number = M_GET;
r->uri = "/";
r->filename = (char *)ap_server_root_relative(p, r->uri);
r->assbackwards = 1;
r->protocol = "UNKNOWN";
r_sv = sv_setref_pv(newSV(0), "Apache2::RequestRec", (void*)r);
if (base_pool_sv) {
mpxs_add_pool_magic(r_sv, base_pool_sv);
}
return r_sv;
}
static MP_INLINE
request_rec *mpxs_Apache2__RequestUtil_request(pTHX_ SV *classname, SV *svr)
{
/* ignore classname */
return modperl_global_request(aTHX_ svr);
}
static MP_INLINE
int mpxs_Apache2__RequestRec_location_merge(request_rec *r,
char *location)
{
apr_pool_t *p = r->pool;
server_rec *s = r->server;
core_server_config *sconf = ap_get_module_config(s->module_config,
&core_module);
ap_conf_vector_t **sec = (ap_conf_vector_t **)sconf->sec_url->elts;
int num_sec = sconf->sec_url->nelts;
int i;
for (i=0; i<num_sec; i++) {
core_dir_config *entry =
(core_dir_config *)ap_get_module_config(sec[i],
&core_module);
if (strEQ(entry->d, location)) {
r->per_dir_config =
ap_merge_per_dir_configs(p, s->lookup_defaults, sec[i]);
return 1;
}
}
return 0;
}
static MP_INLINE
void mpxs_Apache2__RequestRec_set_basic_credentials(request_rec *r,
char *username,
char *password)
{
char encoded[1024];
int elen;
char *auth_value, *auth_cat;
auth_cat = apr_pstrcat(r->pool,
username, ":", password, NULL);
elen = apr_base64_encode(encoded, auth_cat, strlen(auth_cat));
encoded[elen] = '\0';
auth_value = apr_pstrcat(r->pool, "Basic ", encoded, NULL);
apr_table_setn(r->headers_in, "Authorization", auth_value);
}
static MP_INLINE
int mpxs_Apache2__RequestRec_no_cache(pTHX_ request_rec *r, SV *flag)
{
int retval = r->no_cache;
if (flag) {
r->no_cache = (int)SvIV(flag);
}
if (r->no_cache) {
apr_table_setn(r->headers_out, "Pragma", "no-cache");
apr_table_setn(r->headers_out, "Cache-control", "no-cache");
}
else if (flag) { /* only unset if $r->no_cache(0) */
apr_table_unset(r->headers_out, "Pragma");
apr_table_unset(r->headers_out, "Cache-control");
}
return retval;
}
static MP_INLINE
SV *mpxs_Apache2__RequestRec_pnotes(pTHX_ request_rec *r, SV *key, SV *val)
{
MP_dRCFG;
if (!rcfg) {
return &PL_sv_undef;
}
return modperl_pnotes(aTHX_ &rcfg->pnotes, key, val, r->pool);
}
static MP_INLINE
void mpxs_Apache2__RequestRec_pnotes_kill(pTHX_ request_rec *r)
{
MP_dRCFG;
if (!rcfg) {
return;
}
modperl_pnotes_kill(&rcfg->pnotes);
}
#define mpxs_Apache2__RequestRec_dir_config(r, key, sv_val) \
modperl_dir_config(aTHX_ r, r->server, key, sv_val)
#define mpxs_Apache2__RequestRec_slurp_filename(r, tainted) \
modperl_slurp_filename(aTHX_ r, tainted)
static MP_INLINE
char *mpxs_Apache2__RequestRec_location(request_rec *r)
{
MP_dDCFG;
return dcfg->location;
}
typedef struct {
PerlInterpreter *perl;
SV *sv;
} sv_str_header_t;
static int sv_str_header(void *arg, const char *k, const char *v)
{
sv_str_header_t *svh = (sv_str_header_t *)arg;
dTHXa(svh->perl);
Perl_sv_catpvf(aTHX_ svh->sv, "%s: %s\n", k, v);
return 1;
}
static MP_INLINE
SV *mpxs_Apache2__RequestRec_as_string(pTHX_ request_rec *r)
{
sv_str_header_t svh;
#ifdef USE_ITHREADS
svh.perl = aTHX;
#endif
svh.sv = newSVpv(r->the_request, 0);
sv_catpvn(svh.sv, "\n", 1);
apr_table_do((int (*) (void *, const char *, const char *))
sv_str_header, (void *) &svh, r->headers_in, NULL);
Perl_sv_catpvf(aTHX_ svh.sv, "\n%s %s\n", r->protocol, r->status_line);
apr_table_do((int (*) (void *, const char *, const char *))
sv_str_header, (void *) &svh, r->headers_out, NULL);
apr_table_do((int (*) (void *, const char *, const char *))
sv_str_header, (void *) &svh, r->err_headers_out, NULL);
sv_catpvn(svh.sv, "\n", 1);
return svh.sv;
}
static MP_INLINE
int mpxs_Apache2__RequestRec_is_perl_option_enabled(pTHX_ request_rec *r,
const char *name)
{
return modperl_config_is_perl_option_enabled(aTHX_ r, r->server, name);
}
static MP_INLINE
void mpxs_Apache2__RequestRec_add_config(pTHX_ request_rec *r, SV *lines,
int override, char *path,
int override_options)
{
const char *errmsg = modperl_config_insert_request(aTHX_ r, lines,
override, path,
override_options);
if (errmsg) {
Perl_croak(aTHX_ "$r->add_config() has failed: %s", errmsg);
}
}
/* in order to ensure that s->document_root doesn't get corrupted by
* modperl users setting its value, restore the original value at the
* end of each request */
struct mp_docroot_info {
const char **docroot;
const char *original;
};
static apr_status_t restore_docroot(void *data)
{
struct mp_docroot_info *di = (struct mp_docroot_info *)data;
*di->docroot = di->original;
return APR_SUCCESS;
}
static MP_INLINE
const char *mpxs_Apache2__RequestRec_document_root(pTHX_ request_rec *r,
SV *new_root)
{
const char *retval = ap_document_root(r);
if (new_root) {
struct mp_docroot_info *di;
core_server_config *conf;
MP_CROAK_IF_THREADS_STARTED("setting $r->document_root");
conf = ap_get_module_config(r->server->module_config,
&core_module);
di = apr_palloc(r->pool, sizeof *di);
di->docroot = &conf->ap_document_root;
di->original = conf->ap_document_root;
apr_pool_cleanup_register(r->pool, di, restore_docroot,
restore_docroot);
conf->ap_document_root = apr_pstrdup(r->pool, SvPV_nolen(new_root));
}
return retval;
}
static apr_status_t child_terminate(void *data) {
apr_pool_t *pool = (apr_pool_t *)data;
/* On the first pass, re-register so we end up last */
if (data) {
apr_pool_cleanup_register(pool, NULL, child_terminate,
apr_pool_cleanup_null);
}
else {
exit(0);
}
return APR_SUCCESS;
}
static MP_INLINE
void mpxs_Apache2__RequestRec_child_terminate(pTHX_ request_rec *r)
{
MP_CROAK_IF_THREADED_MPM("$r->child_terminate")
apr_pool_cleanup_register(r->pool, r->pool, child_terminate,
apr_pool_cleanup_null);
}
static MP_INLINE
apr_status_t mpxs_ap_register_auth_provider(pTHX_ I32 items, SV **MARK, SV **SP)
{
apr_pool_t *pool;
const char *provider_group;
const char *provider_name;
const char *provider_version;
SV *callback1;
SV *callback2 = NULL;
int type;
if (items != 7)
Perl_croak(aTHX_ "pool, provider_group, provider_name, "
"provider_version, callback1, callback2, type");
if (SvROK(*MARK) && sv_derived_from(*MARK, "APR::Pool")) {
IV tmp = SvIV((SV*)SvRV(*MARK));
if (tmp == 0) {
Perl_croak(aTHX_ "invalid pool object (already destroyed?)");
}
pool = INT2PTR(APR__Pool, tmp);
}
else {
Perl_croak(aTHX_ SvROK(*MARK) ?
"pool is not of type APR::Pool" :
"pool is not a blessed reference");
}
MARK++;
provider_group = (const char *)SvPV_nolen(*MARK);
MARK++;
provider_name = (const char *)SvPV_nolen(*MARK);
MARK++;
provider_version = (const char *)SvPV_nolen(*MARK);
MARK++;
callback1 = newSVsv(*MARK);
MARK++;
callback2 = NULL;
if (SvROK(*MARK)) {
callback2 = newSVsv(*MARK);
}
MARK++;
type = (int)SvIV(*MARK);
return modperl_register_auth_provider(pool, provider_group, provider_name,
provider_version, callback1,
callback2, type);
}
/*
* Local Variables:
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
|