2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) Igor Sysoev
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2006-11-28 21:20:34 +08:00
|
|
|
#define PERL_NO_GET_CONTEXT
|
|
|
|
|
2006-01-16 22:56:53 +08:00
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
|
|
|
#include <ngx_http.h>
|
|
|
|
#include <ngx_http_perl_module.h>
|
|
|
|
|
2006-01-25 00:08:27 +08:00
|
|
|
#include "XSUB.h"
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
#define ngx_http_perl_set_request(r) \
|
|
|
|
r = INT2PTR(ngx_http_request_t *, SvIV((SV *) SvRV(ST(0))))
|
|
|
|
|
|
|
|
|
|
|
|
#define ngx_http_perl_set_targ(p, len, z) \
|
|
|
|
\
|
|
|
|
sv_upgrade(TARG, SVt_PV); \
|
|
|
|
SvPOK_on(TARG); \
|
|
|
|
SvPV_set(TARG, (char *) p); \
|
|
|
|
SvLEN_set(TARG, len + z); \
|
|
|
|
SvCUR_set(TARG, len); \
|
|
|
|
SvFAKE_on(TARG); \
|
|
|
|
SvREADONLY_on(TARG); \
|
|
|
|
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
static ngx_int_t
|
|
|
|
ngx_http_perl_sv2str(pTHX_ ngx_http_request_t *r, ngx_str_t *s, SV *sv)
|
|
|
|
{
|
|
|
|
u_char *p;
|
|
|
|
STRLEN len;
|
|
|
|
|
|
|
|
if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
|
|
|
|
sv = SvRV(sv);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (u_char *) SvPV(sv, len);
|
|
|
|
|
|
|
|
s->len = len;
|
|
|
|
|
|
|
|
if (SvREADONLY(sv)) {
|
|
|
|
s->data = p;
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->data = ngx_palloc(r->pool, len);
|
|
|
|
if (s->data == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_memcpy(s->data, p, len);
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
|
|
|
ngx_http_perl_output(ngx_http_request_t *r, ngx_buf_t *b)
|
|
|
|
{
|
2006-02-23 03:41:39 +08:00
|
|
|
ngx_chain_t out;
|
|
|
|
#if (NGX_HTTP_SSI)
|
|
|
|
ngx_chain_t *cl;
|
2006-01-16 22:56:53 +08:00
|
|
|
ngx_http_perl_ctx_t *ctx;
|
|
|
|
|
|
|
|
ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
|
|
|
|
|
|
|
|
if (ctx->ssi) {
|
|
|
|
cl = ngx_alloc_chain_link(r->pool);
|
|
|
|
if (cl == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
cl->buf = b;
|
|
|
|
cl->next = NULL;
|
|
|
|
*ctx->ssi->last_out = cl;
|
|
|
|
ctx->ssi->last_out = &cl->next;
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
2006-02-23 03:41:39 +08:00
|
|
|
#endif
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
out.buf = b;
|
|
|
|
out.next = NULL;
|
|
|
|
|
|
|
|
return ngx_http_output_filter(r, &out);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MODULE = nginx PACKAGE = nginx
|
|
|
|
|
|
|
|
|
2006-12-13 21:49:56 +08:00
|
|
|
void
|
|
|
|
status(r, code)
|
|
|
|
CODE:
|
|
|
|
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
r->headers_out.status = SvIV(ST(1));
|
|
|
|
|
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"perl status: %d", r->headers_out.status);
|
|
|
|
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-01-16 22:56:53 +08:00
|
|
|
send_http_header(r, ...)
|
2006-04-14 17:53:38 +08:00
|
|
|
CODE:
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_request_t *r;
|
|
|
|
SV *sv;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
if (r->headers_out.status == 0) {
|
|
|
|
r->headers_out.status = NGX_HTTP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (items != 1) {
|
|
|
|
sv = ST(1);
|
|
|
|
|
|
|
|
if (ngx_http_perl_sv2str(aTHX_ r, &r->headers_out.content_type, sv)
|
|
|
|
!= NGX_OK)
|
|
|
|
{
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
2007-09-01 02:47:25 +08:00
|
|
|
r->headers_out.content_type_len = r->headers_out.content_type.len;
|
|
|
|
|
2006-01-16 22:56:53 +08:00
|
|
|
} else {
|
2006-08-14 23:09:38 +08:00
|
|
|
if (ngx_http_set_content_type(r) != NGX_OK) {
|
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
(void) ngx_http_send_header(r);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-01-16 22:56:53 +08:00
|
|
|
header_only(r)
|
|
|
|
CODE:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
sv_upgrade(TARG, SVt_IV);
|
|
|
|
sv_setiv(TARG, r->header_only);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
|
|
|
uri(r)
|
|
|
|
CODE:
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
ngx_http_perl_set_targ(r->uri.data, r->uri.len, 0);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
|
|
|
args(r)
|
2006-01-16 22:56:53 +08:00
|
|
|
CODE:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
ngx_http_perl_set_targ(r->args.data, r->args.len, 0);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-04-05 21:40:54 +08:00
|
|
|
request_method(r)
|
|
|
|
CODE:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
2006-04-05 21:40:54 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
ngx_http_perl_set_targ(r->method_name.data, r->method_name.len, 0);
|
2006-04-05 21:40:54 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-04-05 21:40:54 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-04-05 21:40:54 +08:00
|
|
|
remote_addr(r)
|
|
|
|
CODE:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
ngx_http_perl_set_targ(r->connection->addr_text.data,
|
|
|
|
r->connection->addr_text.len, 1);
|
2006-04-05 21:40:54 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-04-05 21:40:54 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-01-16 22:56:53 +08:00
|
|
|
header_in(r, key)
|
2006-04-14 17:53:38 +08:00
|
|
|
CODE:
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
2006-07-28 23:16:17 +08:00
|
|
|
ngx_http_request_t *r;
|
|
|
|
SV *key;
|
|
|
|
u_char *p, *lowcase_key, *cookie;
|
|
|
|
STRLEN len;
|
|
|
|
ssize_t size;
|
|
|
|
ngx_uint_t i, n, hash;
|
|
|
|
ngx_list_part_t *part;
|
|
|
|
ngx_table_elt_t *h, **ph;
|
|
|
|
ngx_http_header_t *hh;
|
|
|
|
ngx_http_core_main_conf_t *cmcf;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
key = ST(1);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PV) {
|
|
|
|
key = SvRV(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (u_char *) SvPV(key, len);
|
|
|
|
|
2006-07-28 23:16:17 +08:00
|
|
|
/* look up hashed headers */
|
|
|
|
|
|
|
|
lowcase_key = ngx_palloc(r->pool, len);
|
|
|
|
if (lowcase_key == NULL) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
hash = 0;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
lowcase_key[i] = ngx_tolower(p[i]);
|
|
|
|
hash = ngx_hash(hash, lowcase_key[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
|
|
|
|
|
|
|
|
hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len);
|
|
|
|
|
|
|
|
if (hh) {
|
|
|
|
if (hh->offset) {
|
|
|
|
|
|
|
|
ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset);
|
|
|
|
|
|
|
|
if (*ph) {
|
|
|
|
ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len, 0);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cookie */
|
|
|
|
|
|
|
|
n = r->headers_in.cookies.nelts;
|
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
ph = r->headers_in.cookies.elts;
|
|
|
|
|
|
|
|
if (n == 1) {
|
|
|
|
ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len, 0);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = - (ssize_t) (sizeof("; ") - 1);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
size += ph[i]->value.len + sizeof("; ") - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cookie = ngx_palloc(r->pool, size);
|
|
|
|
if (cookie == NULL) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = cookie;
|
|
|
|
|
|
|
|
for (i = 0; /* void */ ; i++) {
|
|
|
|
p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len);
|
|
|
|
|
|
|
|
if (i == n - 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p++ = ';'; *p++ = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_http_perl_set_targ(cookie, size, 0);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iterate over all headers */
|
|
|
|
|
2006-01-16 22:56:53 +08:00
|
|
|
part = &r->headers_in.headers.part;
|
2006-07-28 23:16:17 +08:00
|
|
|
h = part->elts;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
for (i = 0; /* void */ ; i++) {
|
|
|
|
|
|
|
|
if (i >= part->nelts) {
|
|
|
|
if (part->next == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
part = part->next;
|
2006-07-28 23:16:17 +08:00
|
|
|
h = part->elts;
|
2006-01-16 22:56:53 +08:00
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
2006-07-28 23:16:17 +08:00
|
|
|
if (len != h[i].key.len
|
|
|
|
|| ngx_strcasecmp(p, h[i].key.data) != 0)
|
2006-01-16 22:56:53 +08:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-07-28 23:16:17 +08:00
|
|
|
ngx_http_perl_set_targ(h[i].value.data, h[i].value.len, 0);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
2006-08-30 18:39:17 +08:00
|
|
|
void
|
|
|
|
has_request_body(r, next)
|
|
|
|
CODE:
|
|
|
|
|
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
ngx_http_perl_ctx_t *ctx;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
if (r->headers_in.content_length_n <= 0) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
|
2006-12-13 04:57:48 +08:00
|
|
|
ctx->next = SvRV(ST(1));
|
2006-08-30 18:39:17 +08:00
|
|
|
|
|
|
|
r->request_body_in_single_buf = 1;
|
|
|
|
r->request_body_in_persistent_file = 1;
|
2007-01-25 16:45:04 +08:00
|
|
|
r->request_body_in_clean_file = 1;
|
2006-08-30 18:39:17 +08:00
|
|
|
|
|
|
|
if (r->request_body_in_file_only) {
|
|
|
|
r->request_body_file_log_level = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_http_read_client_request_body(r, ngx_http_perl_handle_request);
|
|
|
|
|
|
|
|
sv_upgrade(TARG, SVt_IV);
|
|
|
|
sv_setiv(TARG, 1);
|
|
|
|
|
|
|
|
ST(0) = TARG;
|
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-04-07 22:08:04 +08:00
|
|
|
request_body(r)
|
|
|
|
CODE:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
size_t len;
|
2006-04-07 22:08:04 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
2006-04-07 22:08:04 +08:00
|
|
|
|
2006-12-22 21:05:07 +08:00
|
|
|
if (r->request_body == NULL
|
|
|
|
|| r->request_body->temp_file
|
|
|
|
|| r->request_body->bufs == NULL)
|
|
|
|
{
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_UNDEF;
|
2006-04-07 22:08:04 +08:00
|
|
|
}
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
len = r->request_body->bufs->buf->last - r->request_body->bufs->buf->pos;
|
|
|
|
|
2006-04-07 22:08:04 +08:00
|
|
|
if (len == 0) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_targ(r->request_body->bufs->buf->pos, len, 0);
|
|
|
|
|
|
|
|
ST(0) = TARG;
|
2006-04-07 22:08:04 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
request_body_file(r)
|
|
|
|
CODE:
|
|
|
|
|
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
2006-12-22 21:05:07 +08:00
|
|
|
if (r->request_body == NULL || r->request_body->temp_file == NULL) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_UNDEF;
|
2006-04-07 22:08:04 +08:00
|
|
|
}
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_targ(r->request_body->temp_file->file.name.data,
|
|
|
|
r->request_body->temp_file->file.name.len, 1);
|
2006-04-07 22:08:04 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-04-07 22:08:04 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
|
2007-08-06 23:38:08 +08:00
|
|
|
void
|
|
|
|
discard_request_body(r)
|
|
|
|
CODE:
|
|
|
|
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
ngx_http_discard_request_body(r);
|
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-01-16 22:56:53 +08:00
|
|
|
header_out(r, key, value)
|
2006-04-14 17:53:38 +08:00
|
|
|
CODE:
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_request_t *r;
|
|
|
|
SV *key;
|
|
|
|
SV *value;
|
|
|
|
ngx_table_elt_t *header;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
key = ST(1);
|
|
|
|
value = ST(2);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
header = ngx_list_push(&r->headers_out.headers);
|
|
|
|
if (header == NULL) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
header->hash = 1;
|
|
|
|
|
|
|
|
if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ngx_http_perl_sv2str(aTHX_ r, &header->value, value) != NGX_OK) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (header->key.len == sizeof("Content-Length") - 1
|
|
|
|
&& ngx_strncasecmp(header->key.data, "Content-Length",
|
2006-10-05 23:05:47 +08:00
|
|
|
sizeof("Content-Length") - 1) == 0)
|
2006-01-16 22:56:53 +08:00
|
|
|
{
|
2006-10-05 23:05:47 +08:00
|
|
|
r->headers_out.content_length_n = (off_t) SvIV(value);
|
2006-01-16 22:56:53 +08:00
|
|
|
r->headers_out.content_length = header;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-01-16 22:56:53 +08:00
|
|
|
filename(r)
|
2006-04-14 17:53:38 +08:00
|
|
|
CODE:
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
2006-10-12 21:56:16 +08:00
|
|
|
size_t root;
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_request_t *r;
|
2006-01-16 22:56:53 +08:00
|
|
|
ngx_http_perl_ctx_t *ctx;
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
|
2006-04-14 17:53:38 +08:00
|
|
|
if (ctx->filename.data) {
|
2006-01-16 22:56:53 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-10-12 21:56:16 +08:00
|
|
|
if (ngx_http_map_uri_to_path(r, &ctx->filename, &root, 0) == NULL) {
|
2006-01-16 22:56:53 +08:00
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ctx->filename.len--;
|
|
|
|
sv_setpv(PL_statname, (char *) ctx->filename.data);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
done:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len, 1);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-01-16 22:56:53 +08:00
|
|
|
print(r, ...)
|
|
|
|
CODE:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_request_t *r;
|
|
|
|
SV *sv;
|
|
|
|
int i;
|
|
|
|
u_char *p;
|
|
|
|
size_t size;
|
|
|
|
STRLEN len;
|
|
|
|
ngx_buf_t *b;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
if (items == 2) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* do zero copy for prolate single read-only SV:
|
|
|
|
* $r->print("some text\n");
|
|
|
|
*/
|
|
|
|
|
|
|
|
sv = ST(1);
|
|
|
|
|
|
|
|
if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
|
|
|
|
sv = SvRV(sv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SvREADONLY(sv)) {
|
|
|
|
|
|
|
|
p = (u_char *) SvPV(sv, len);
|
|
|
|
|
|
|
|
if (len == 0) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b = ngx_calloc_buf(r->pool);
|
|
|
|
if (b == NULL) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b->memory = 1;
|
|
|
|
b->pos = p;
|
|
|
|
b->last = p + len;
|
|
|
|
b->start = p;
|
|
|
|
b->end = b->last;
|
|
|
|
|
2006-01-18 04:04:32 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"$r->print: read-only SV: %z", len);
|
|
|
|
|
2006-01-16 22:56:53 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
|
|
|
|
for (i = 1; i < items; i++) {
|
|
|
|
|
|
|
|
sv = ST(i);
|
|
|
|
|
|
|
|
if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
|
|
|
|
sv = SvRV(sv);
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) SvPV(sv, len);
|
|
|
|
|
2006-01-18 04:04:32 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"$r->print: copy SV: %z", len);
|
|
|
|
|
2006-01-16 22:56:53 +08:00
|
|
|
size += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == 0) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b = ngx_create_temp_buf(r->pool, size);
|
|
|
|
if (b == NULL) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i < items; i++) {
|
|
|
|
sv = ST(i);
|
|
|
|
|
|
|
|
if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) {
|
|
|
|
sv = SvRV(sv);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (u_char *) SvPV(sv, len);
|
|
|
|
b->last = ngx_cpymem(b->last, p, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
(void) ngx_http_perl_output(r, b);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-02-16 23:26:46 +08:00
|
|
|
sendfile(r, filename, offset = -1, bytes = 0)
|
2006-04-14 17:53:38 +08:00
|
|
|
CODE:
|
|
|
|
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
char *filename;
|
2006-02-16 23:26:46 +08:00
|
|
|
int offset;
|
|
|
|
size_t bytes;
|
2006-01-16 22:56:53 +08:00
|
|
|
ngx_fd_t fd;
|
|
|
|
ngx_buf_t *b;
|
|
|
|
ngx_file_info_t fi;
|
|
|
|
ngx_pool_cleanup_t *cln;
|
|
|
|
ngx_pool_cleanup_file_t *clnf;
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
filename = SvPV_nolen(ST(1));
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
if (filename == NULL) {
|
|
|
|
croak("sendfile(): NULL filename");
|
|
|
|
}
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
offset = items < 3 ? -1 : SvIV(ST(2));
|
|
|
|
bytes = items < 4 ? 0 : SvIV(ST(3));
|
|
|
|
|
2006-01-16 22:56:53 +08:00
|
|
|
b = ngx_calloc_buf(r->pool);
|
|
|
|
if (b == NULL) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));
|
|
|
|
if (b->file == NULL) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_pool_cleanup_file_t));
|
|
|
|
if (cln == NULL) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
2007-01-19 04:48:03 +08:00
|
|
|
fd = ngx_open_file((u_char *) filename, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
if (fd == NGX_INVALID_FILE) {
|
|
|
|
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
|
|
|
|
ngx_open_file_n " \"%s\" failed", filename);
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
2006-02-16 23:26:46 +08:00
|
|
|
if (offset == -1) {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bytes == 0) {
|
|
|
|
if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
|
|
|
|
ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
|
|
|
|
ngx_fd_info_n " \"%s\" failed", filename);
|
|
|
|
|
|
|
|
if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
|
|
ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno,
|
|
|
|
ngx_close_file_n " \"%s\" failed", filename);
|
|
|
|
}
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
2006-02-16 23:26:46 +08:00
|
|
|
bytes = ngx_file_size(&fi) - offset;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cln->handler = ngx_pool_cleanup_file;
|
|
|
|
clnf = cln->data;
|
|
|
|
|
|
|
|
clnf->fd = fd;
|
|
|
|
clnf->name = (u_char *) "";
|
|
|
|
clnf->log = r->pool->log;
|
|
|
|
|
|
|
|
b->in_file = 1;
|
2006-02-16 23:26:46 +08:00
|
|
|
|
|
|
|
b->file_pos = offset;
|
|
|
|
b->file_last = offset + bytes;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
b->file->fd = fd;
|
|
|
|
b->file->log = r->connection->log;
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
(void) ngx_http_perl_output(r, b);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2007-04-21 15:43:23 +08:00
|
|
|
flush(r)
|
2006-04-14 17:53:38 +08:00
|
|
|
CODE:
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_request_t *r;
|
|
|
|
ngx_buf_t *b;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
b = ngx_calloc_buf(r->pool);
|
|
|
|
if (b == NULL) {
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
b->flush = 1;
|
|
|
|
|
2007-04-21 15:43:23 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush");
|
2006-01-18 04:04:32 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
(void) ngx_http_perl_output(r, b);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
XSRETURN_EMPTY;
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
internal_redirect(r, uri)
|
2006-04-14 17:53:38 +08:00
|
|
|
CODE:
|
2006-01-16 22:56:53 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_request_t *r;
|
|
|
|
SV *uri;
|
2006-01-16 22:56:53 +08:00
|
|
|
ngx_uint_t i;
|
|
|
|
ngx_http_perl_ctx_t *ctx;
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
uri = ST(1);
|
2006-01-16 22:56:53 +08:00
|
|
|
|
|
|
|
ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
|
|
|
|
|
|
|
|
if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) {
|
|
|
|
XSRETURN_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < ctx->redirect_uri.len; i++) {
|
|
|
|
if (ctx->redirect_uri.data[i] == '?') {
|
|
|
|
|
|
|
|
ctx->redirect_args.len = ctx->redirect_uri.len - (i + 1);
|
|
|
|
ctx->redirect_args.data = &ctx->redirect_uri.data[i + 1];
|
|
|
|
ctx->redirect_uri.len = i;
|
|
|
|
|
|
|
|
XSRETURN_EMPTY;
|
|
|
|
}
|
|
|
|
}
|
2006-01-18 04:04:32 +08:00
|
|
|
|
|
|
|
|
2006-10-25 21:56:32 +08:00
|
|
|
void
|
|
|
|
allow_ranges(r)
|
|
|
|
CODE:
|
|
|
|
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
r->allow_ranges = 1;
|
|
|
|
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
void
|
2006-01-18 04:04:32 +08:00
|
|
|
unescape(r, text, type = 0)
|
2006-04-14 17:53:38 +08:00
|
|
|
CODE:
|
2006-01-18 04:04:32 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
SV *text;
|
|
|
|
int type;
|
|
|
|
u_char *p, *dst, *src;
|
|
|
|
STRLEN len;
|
2006-01-18 04:04:32 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_request(r);
|
2006-01-18 04:04:32 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
text = ST(1);
|
2006-01-18 04:04:32 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
src = (u_char *) SvPV(text, len);
|
2006-01-18 04:04:32 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
p = ngx_palloc(r->pool, len + 1);
|
2006-01-18 04:04:32 +08:00
|
|
|
if (p == NULL) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst = p;
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
type = items < 3 ? 0 : SvIV(ST(2));
|
|
|
|
|
|
|
|
ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type);
|
2006-01-18 04:04:32 +08:00
|
|
|
*dst = '\0';
|
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ngx_http_perl_set_targ(p, dst - p, 1);
|
2006-01-18 04:04:32 +08:00
|
|
|
|
2006-04-14 17:53:38 +08:00
|
|
|
ST(0) = TARG;
|
2006-10-31 22:46:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
variable(r, name, value = NULL)
|
|
|
|
CODE:
|
|
|
|
|
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
SV *name, *value;
|
|
|
|
u_char *p, *lowcase;
|
|
|
|
STRLEN len;
|
|
|
|
ngx_str_t var, val;
|
|
|
|
ngx_uint_t i, hash;
|
2006-12-13 06:06:03 +08:00
|
|
|
ngx_http_perl_var_t *v;
|
|
|
|
ngx_http_perl_ctx_t *ctx;
|
2006-10-31 22:46:48 +08:00
|
|
|
ngx_http_variable_value_t *vv;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
name = ST(1);
|
|
|
|
|
|
|
|
if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) {
|
|
|
|
name = SvRV(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (items == 2) {
|
|
|
|
value = NULL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
value = ST(2);
|
|
|
|
|
|
|
|
if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) {
|
|
|
|
value = SvRV(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (u_char *) SvPV(name, len);
|
|
|
|
|
|
|
|
lowcase = ngx_palloc(r->pool, len);
|
|
|
|
if (lowcase == NULL) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
hash = 0;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
lowcase[i] = ngx_tolower(p[i]);
|
|
|
|
hash = ngx_hash(hash, lowcase[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var.len = len;
|
|
|
|
var.data = lowcase;
|
|
|
|
|
2006-12-13 06:06:03 +08:00
|
|
|
#if (NGX_LOG_DEBUG)
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"perl variable: \"%V\"=\"%V\"", &var, &val);
|
|
|
|
} else {
|
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"perl variable: \"%V\"", &var);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-10-31 22:46:48 +08:00
|
|
|
vv = ngx_http_get_variable(r, &var, hash, 1);
|
|
|
|
if (vv == NULL) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vv->not_found) {
|
2006-12-13 06:06:03 +08:00
|
|
|
|
|
|
|
ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
|
|
|
|
|
|
|
|
if (ctx->variables) {
|
|
|
|
|
|
|
|
v = ctx->variables->elts;
|
|
|
|
for (i = 0; i < ctx->variables->nelts; i++) {
|
|
|
|
|
|
|
|
if (hash != v[i].hash
|
|
|
|
|| len != v[i].name.len
|
|
|
|
|| ngx_strncmp(lowcase, v[i].name.data, len) != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
v[i].value = val;
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_http_perl_set_targ(v[i].value.data, v[i].value.len, 0);
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
if (ctx->variables == NULL) {
|
|
|
|
ctx->variables = ngx_array_create(r->pool, 1,
|
|
|
|
sizeof(ngx_http_perl_var_t));
|
|
|
|
if (ctx->variables == NULL) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v = ngx_array_push(ctx->variables);
|
|
|
|
if (v == NULL) {
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
v->hash = hash;
|
|
|
|
v->name.len = len;
|
|
|
|
v->name.data = lowcase;
|
|
|
|
v->value = val;
|
|
|
|
|
2006-10-31 22:46:48 +08:00
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
|
|
"variable \"%V\" not found", &var);
|
|
|
|
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
vv->len = val.len;
|
|
|
|
vv->valid = 1;
|
|
|
|
vv->no_cachable = 0;
|
|
|
|
vv->not_found = 0;
|
|
|
|
vv->data = val.data;
|
|
|
|
|
|
|
|
XSRETURN_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_http_perl_set_targ(vv->data, vv->len, 0);
|
|
|
|
|
2006-12-13 06:06:03 +08:00
|
|
|
done:
|
|
|
|
|
2006-10-31 22:46:48 +08:00
|
|
|
ST(0) = TARG;
|
2006-12-13 03:33:13 +08:00
|
|
|
|
|
|
|
|
2006-12-13 04:59:24 +08:00
|
|
|
void
|
|
|
|
sleep(r, sleep, next)
|
|
|
|
CODE:
|
|
|
|
|
|
|
|
dXSTARG;
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
ngx_http_perl_ctx_t *ctx;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
|
|
|
|
|
|
|
|
ctx->sleep = SvIV(ST(1));
|
|
|
|
ctx->next = SvRV(ST(2));
|
|
|
|
|
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
|
"perl sleep: %d", ctx->sleep);
|
|
|
|
|
|
|
|
|
2006-12-13 03:33:13 +08:00
|
|
|
void
|
|
|
|
log_error(r, err, msg)
|
|
|
|
CODE:
|
|
|
|
|
|
|
|
ngx_http_request_t *r;
|
|
|
|
SV *err, *msg;
|
|
|
|
u_char *p;
|
|
|
|
STRLEN len;
|
|
|
|
ngx_err_t e;
|
|
|
|
|
|
|
|
ngx_http_perl_set_request(r);
|
|
|
|
|
|
|
|
err = ST(1);
|
|
|
|
|
|
|
|
if (SvROK(err) && SvTYPE(SvRV(err)) == SVt_PV) {
|
|
|
|
err = SvRV(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
e = SvIV(err);
|
|
|
|
|
|
|
|
msg = ST(2);
|
|
|
|
|
|
|
|
if (SvROK(msg) && SvTYPE(SvRV(msg)) == SVt_PV) {
|
|
|
|
msg = SvRV(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = (u_char *) SvPV(msg, len);
|
|
|
|
|
2006-12-13 04:58:41 +08:00
|
|
|
ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p);
|