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

📄 ngx_http_ssi_filter_module.c

📁 Nginx是一个高性能的HTTP和反向代理服务器
💻 C
📖 第 1 页 / 共 5 页
字号:
        b = cl->buf;    }#endif    rc = ngx_http_next_body_filter(r, ctx->out);    if (ctx->busy == NULL) {        ctx->busy = ctx->out;    } else {        for (cl = ctx->busy; cl->next; cl = cl->next) { /* void */ }        cl->next = ctx->out;    }    ctx->out = NULL;    ctx->last_out = &ctx->out;    while (ctx->busy) {        cl = ctx->busy;        b = cl->buf;        if (ngx_buf_size(b) != 0) {            break;        }#if (NGX_HAVE_WRITE_ZEROCOPY)        if (b->zerocopy_busy) {            break;        }#endif        if (b->shadow) {            b->shadow->pos = b->shadow->last;        }        ctx->busy = cl->next;        if (ngx_buf_in_memory(b) || b->in_file) {            /* add data bufs only to the free buf chain */            cl->next = ctx->free;            ctx->free = cl;        }    }    if (ctx->in || ctx->buf) {        r->buffered |= NGX_HTTP_SSI_BUFFERED;    } else {        r->buffered &= ~NGX_HTTP_SSI_BUFFERED;    }    return rc;}static ngx_int_tngx_http_ssi_parse(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx){    u_char                *p, *value, *last, *copy_end, ch;    size_t                 looked;    ngx_http_ssi_state_e   state;    state = ctx->state;    looked = ctx->looked;    last = ctx->buf->last;    copy_end = ctx->copy_end;    for (p = ctx->pos; p < last; p++) {        ch = *p;        if (state == ssi_start_state) {            /* the tight loop */            for ( ;; ) {                if (ch == '<') {                    copy_end = p;                    looked = 1;                    state = ssi_tag_state;                    goto tag_started;                }                if (++p == last) {                    break;                }                ch = *p;            }            ctx->state = state;            ctx->pos = p;            ctx->looked = looked;            ctx->copy_end = p;            if (ctx->copy_start == NULL) {                ctx->copy_start = ctx->buf->pos;            }            return NGX_AGAIN;        tag_started:            continue;        }        switch (state) {        case ssi_start_state:            break;        case ssi_tag_state:            switch (ch) {            case '!':                looked = 2;                state = ssi_comment0_state;                break;            case '<':                copy_end = p;                break;            default:                copy_end = p;                looked = 0;                state = ssi_start_state;                break;            }            break;        case ssi_comment0_state:            switch (ch) {            case '-':                looked = 3;                state = ssi_comment1_state;                break;            case '<':                copy_end = p;                looked = 1;                state = ssi_tag_state;                break;            default:                copy_end = p;                looked = 0;                state = ssi_start_state;                break;            }            break;        case ssi_comment1_state:            switch (ch) {            case '-':                looked = 4;                state = ssi_sharp_state;                break;            case '<':                copy_end = p;                looked = 1;                state = ssi_tag_state;                break;            default:                copy_end = p;                looked = 0;                state = ssi_start_state;                break;            }            break;        case ssi_sharp_state:            switch (ch) {            case '#':                if (p - ctx->pos < 4) {                    ctx->saved = 0;                }                looked = 0;                state = ssi_precommand_state;                break;            case '<':                copy_end = p;                looked = 1;                state = ssi_tag_state;                break;            default:                copy_end = p;                looked = 0;                state = ssi_start_state;                break;            }            break;        case ssi_precommand_state:            switch (ch) {            case ' ':            case CR:            case LF:            case '\t':                break;            default:                ctx->command.len = 1;                ctx->command.data = ngx_palloc(r->pool,                                               NGX_HTTP_SSI_COMMAND_LEN);                if (ctx->command.data == NULL) {                    return NGX_ERROR;                }                ctx->command.data[0] = ch;                ctx->key = 0;                ctx->key = ngx_hash(ctx->key, ch);                ctx->params.nelts = 0;                state = ssi_command_state;                break;            }            break;        case ssi_command_state:            switch (ch) {            case ' ':            case CR:            case LF:            case '\t':                state = ssi_preparam_state;                break;            case '-':                state = ssi_comment_end0_state;                break;            default:                if (ctx->command.len == NGX_HTTP_SSI_COMMAND_LEN) {                    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                  "the \"%V%c...\" SSI command is too long",                                  &ctx->command, ch);                    state = ssi_error_state;                    break;                }                ctx->command.data[ctx->command.len++] = ch;                ctx->key = ngx_hash(ctx->key, ch);            }            break;        case ssi_preparam_state:            switch (ch) {            case ' ':            case CR:            case LF:            case '\t':                break;            case '-':                state = ssi_comment_end0_state;                break;            default:                ctx->param = ngx_array_push(&ctx->params);                if (ctx->param == NULL) {                    return NGX_ERROR;                }                ctx->param->key.len = 1;                ctx->param->key.data = ngx_palloc(r->pool,                                                  NGX_HTTP_SSI_PARAM_LEN);                if (ctx->param->key.data == NULL) {                    return NGX_ERROR;                }                ctx->param->key.data[0] = ch;                ctx->param->value.len = 0;                if (ctx->value_buf == NULL) {                    ctx->param->value.data = ngx_palloc(r->pool,                                                        ctx->value_len);                    if (ctx->param->value.data == NULL) {                        return NGX_ERROR;                    }                } else {                    ctx->param->value.data = ctx->value_buf;                }                state = ssi_param_state;                break;            }            break;        case ssi_param_state:            switch (ch) {            case ' ':            case CR:            case LF:            case '\t':                state = ssi_preequal_state;                break;            case '=':                state = ssi_prevalue_state;                break;            case '-':                state = ssi_error_end0_state;                ctx->param->key.data[ctx->param->key.len++] = ch;                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                              "invalid \"%V\" parameter in \"%V\" SSI command",                              &ctx->param->key, &ctx->command);                break;            default:                if (ctx->param->key.len == NGX_HTTP_SSI_PARAM_LEN) {                    state = ssi_error_state;                    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                  "too long \"%V%c...\" parameter in "                                  "\"%V\" SSI command",                                  &ctx->param->key, ch, &ctx->command);                    break;                }                ctx->param->key.data[ctx->param->key.len++] = ch;            }            break;        case ssi_preequal_state:            switch (ch) {            case ' ':            case CR:            case LF:            case '\t':                break;            case '=':                state = ssi_prevalue_state;                break;            default:                if (ch == '-') {                    state = ssi_error_end0_state;                } else {                    state = ssi_error_state;                }                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                              "unexpected \"%c\" symbol after \"%V\" "                              "parameter in \"%V\" SSI command",                              ch, &ctx->param->key, &ctx->command);                break;            }            break;        case ssi_prevalue_state:            switch (ch) {            case ' ':            case CR:            case LF:            case '\t':                break;            case '"':                state = ssi_double_quoted_value_state;                break;            case '\'':                state = ssi_quoted_value_state;                break;            default:                if (ch == '-') {                    state = ssi_error_end0_state;                } else {                    state = ssi_error_state;                }                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                              "unexpected \"%c\" symbol before value of "                              "\"%V\" parameter in \"%V\" SSI command",                              ch, &ctx->param->key, &ctx->command);                break;            }            break;        case ssi_double_quoted_value_state:            switch (ch) {            case '"':                state = ssi_postparam_state;                break;            case '\\':                ctx->saved_state = ssi_double_quoted_value_state;                state = ssi_quoted_symbol_state;                /* fall through */            default:                if (ctx->param->value.len == ctx->value_len) {                    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                  "too long \"%V%c...\" value of \"%V\" "                                  "parameter in \"%V\" SSI command",                                  &ctx->param->value, ch, &ctx->param->key,                                  &ctx->command);                    state = ssi_error_state;                    break;                }                ctx->param->value.data[ctx->param->value.len++] = ch;            }            break;        case ssi_quoted_value_state:            switch (ch) {            case '\'':                state = ssi_postparam_state;                break;            case '\\':                ctx->saved_state = ssi_quoted_value_state;                state = ssi_quoted_symbol_state;                /* fall through */            default:                if (ctx->param->value.len == ctx->value_len) {                    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                  "too long \"%V%c...\" value of \"%V\" "                                  "parameter in \"%V\" SSI command",                                  &ctx->param->value, ch, &ctx->param->key,                                  &ctx->command);                    state = ssi_error_state;                    break;                }                ctx->param->value.data[ctx->param->value.len++] = ch;            }            break;        case ssi_quoted_symbol_state:            state = ctx->saved_state;            ctx->param->value.data[ctx->param->value.len++] = ch;            break;        case ssi_postparam_state:            if (ctx->param->value.len + 1 < ctx->value_len / 2) {

⌨️ 快捷键说明

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