⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nginx.xs

📁 Nginx是一个高性能的HTTP和反向代理服务器
💻 XS
📖 第 1 页 / 共 2 页
字号:
    if (ctx->filename.data) {        goto done;    }    if (ngx_http_map_uri_to_path(r, &ctx->filename, &root, 0) == NULL) {        XSRETURN_UNDEF;    }    ctx->filename.len--;    sv_setpv(PL_statname, (char *) ctx->filename.data);    done:    ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len);    ST(0) = TARG;voidprint(r, ...)    CODE:    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);    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) && SvPOK(sv)) {            p = (u_char *) SvPV(sv, len);            if (len == 0) {                XSRETURN_EMPTY;            }            b = ngx_calloc_buf(r->pool);            if (b == NULL) {                XSRETURN_EMPTY;            }            b->memory = 1;            b->pos = p;            b->last = p + len;            b->start = p;            b->end = b->last;            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                           "$r->print: read-only SV: %z", len);            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);        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                       "$r->print: copy SV: %z", len);        size += len;    }    if (size == 0) {        XSRETURN_EMPTY;    }    b = ngx_create_temp_buf(r->pool, size);    if (b == NULL) {        XSRETURN_EMPTY;    }    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:    (void) ngx_http_perl_output(r, b);voidsendfile(r, filename, offset = -1, bytes = 0)    CODE:    ngx_http_request_t        *r;    char                      *filename;    int                        offset;    size_t                     bytes;    ngx_str_t                  path;    ngx_buf_t                 *b;    ngx_open_file_info_t       of;    ngx_http_core_loc_conf_t  *clcf;    ngx_http_perl_set_request(r);    filename = SvPV_nolen(ST(1));    if (filename == NULL) {        croak("sendfile(): NULL filename");    }    offset = items < 3 ? -1 : SvIV(ST(2));    bytes = items < 4 ? 0 : SvIV(ST(3));    b = ngx_calloc_buf(r->pool);    if (b == NULL) {        XSRETURN_EMPTY;    }    b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t));    if (b->file == NULL) {        XSRETURN_EMPTY;    }    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);    of.test_dir = 0;    of.valid = clcf->open_file_cache_valid;    of.min_uses = clcf->open_file_cache_min_uses;    of.errors = clcf->open_file_cache_errors;    of.events = clcf->open_file_cache_events;    path.len = ngx_strlen(filename);    path.data = ngx_pcalloc(r->pool, path.len + 1);    if (path.data == NULL) {        XSRETURN_EMPTY;    }    (void) ngx_cpystrn(path.data, filename, path.len + 1);    if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)        != NGX_OK)    {        if (of.err == 0) {            XSRETURN_EMPTY;        }        ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,                      ngx_open_file_n " \"%s\" failed", filename);        XSRETURN_EMPTY;    }    if (offset == -1) {        offset = 0;    }    if (bytes == 0) {        bytes = of.size - offset;    }    b->in_file = 1;    b->file_pos = offset;    b->file_last = offset + bytes;    b->file->fd = of.fd;    b->file->log = r->connection->log;    (void) ngx_http_perl_output(r, b);voidflush(r)    CODE:    ngx_http_request_t  *r;    ngx_buf_t           *b;    ngx_http_perl_set_request(r);    b = ngx_calloc_buf(r->pool);    if (b == NULL) {        XSRETURN_EMPTY;    }    b->flush = 1;    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush");    (void) ngx_http_perl_output(r, b);    XSRETURN_EMPTY;voidinternal_redirect(r, uri)    CODE:    ngx_http_request_t   *r;    SV                   *uri;    ngx_uint_t            i;    ngx_http_perl_ctx_t  *ctx;    ngx_http_perl_set_request(r);    uri = ST(1);    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;        }    }voidallow_ranges(r)    CODE:    ngx_http_request_t  *r;    ngx_http_perl_set_request(r);    r->allow_ranges = 1;voidunescape(r, text, type = 0)    CODE:    dXSTARG;    ngx_http_request_t  *r;    SV                  *text;    int                  type;    u_char              *p, *dst, *src;    STRLEN               len;    ngx_http_perl_set_request(r);    text = ST(1);    src = (u_char *) SvPV(text, len);    p = ngx_palloc(r->pool, len + 1);    if (p == NULL) {        XSRETURN_UNDEF;    }    dst = p;    type = items < 3 ? 0 : SvIV(ST(2));    ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type);    *dst = '\0';    ngx_http_perl_set_targ(p, dst - p);    ST(0) = TARG;voidvariable(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;    ngx_http_perl_var_t        *v;    ngx_http_perl_ctx_t        *ctx;    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;    #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    vv = ngx_http_get_variable(r, &var, hash, 1);    if (vv == NULL) {        XSRETURN_UNDEF;    }    if (vv->not_found) {        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);                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;            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_cacheable = 0;        vv->not_found = 0;        vv->data = val.data;        XSRETURN_UNDEF;    }    ngx_http_perl_set_targ(vv->data, vv->len);    done:    ST(0) = TARG;voidsleep(r, sleep, next)    CODE:    ngx_http_request_t   *r;    ngx_msec_t            sleep;    ngx_http_perl_ctx_t  *ctx;    ngx_http_perl_set_request(r);    sleep = (ngx_msec_t) SvIV(ST(1));    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "perl sleep: %M", sleep);    ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);    ctx->next = SvRV(ST(2));    ngx_add_timer(r->connection->write, sleep);    r->write_event_handler = ngx_http_perl_sleep_handler;voidlog_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);    ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -