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

📄 ngx_http_ssi_filter_module.c

📁 Nginx是一个高性能的HTTP和反向代理服务器
💻 C
📖 第 1 页 / 共 5 页
字号:
            ctx->copy_start = ctx->pos;            ctx->copy_end = ctx->pos;        }        b = NULL;        while (ctx->pos < ctx->buf->last) {            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                           "saved: %d state: %d", ctx->saved, ctx->state);            rc = ngx_http_ssi_parse(r, ctx);            ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                           "parse: %d, looked: %d %p-%p",                           rc, ctx->looked, ctx->copy_start, ctx->copy_end);            if (rc == NGX_ERROR) {                return rc;            }            if (ctx->copy_start != ctx->copy_end) {                if (ctx->output) {                    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                                   "saved: %d", ctx->saved);                    if (ctx->saved) {                        if (ctx->free) {                            cl = ctx->free;                            ctx->free = ctx->free->next;                            b = cl->buf;                            ngx_memzero(b, sizeof(ngx_buf_t));                        } else {                            b = ngx_calloc_buf(r->pool);                            if (b == NULL) {                                return NGX_ERROR;                            }                            cl = ngx_alloc_chain_link(r->pool);                            if (cl == NULL) {                                return NGX_ERROR;                            }                            cl->buf = b;                        }                        b->memory = 1;                        b->pos = ngx_http_ssi_string;                        b->last = ngx_http_ssi_string + ctx->saved;                        *ctx->last_out = cl;                        ctx->last_out = &cl->next;                        ctx->saved = 0;                    }                    if (ctx->free) {                        cl = ctx->free;                        ctx->free = ctx->free->next;                        b = cl->buf;                    } else {                        b = ngx_alloc_buf(r->pool);                        if (b == NULL) {                            return NGX_ERROR;                        }                        cl = ngx_alloc_chain_link(r->pool);                        if (cl == NULL) {                            return NGX_ERROR;                        }                        cl->buf = b;                    }                    ngx_memcpy(b, ctx->buf, sizeof(ngx_buf_t));                    b->pos = ctx->copy_start;                    b->last = ctx->copy_end;                    b->shadow = NULL;                    b->last_buf = 0;                    b->recycled = 0;                    if (b->in_file) {                        if (slcf->min_file_chunk < (size_t) (b->last - b->pos))                        {                            b->file_last = b->file_pos + (b->last - b->start);                            b->file_pos += b->pos - b->start;                        } else {                            b->in_file = 0;                        }                    }                    cl->next = NULL;                    *ctx->last_out = cl;                    ctx->last_out = &cl->next;                } else {                    if (ctx->block                        && ctx->saved + (ctx->copy_end - ctx->copy_start))                    {                        b = ngx_create_temp_buf(r->pool,                               ctx->saved + (ctx->copy_end - ctx->copy_start));                        if (b == NULL) {                            return NGX_ERROR;                        }                        if (ctx->saved) {                            b->last = ngx_cpymem(b->pos, ngx_http_ssi_string,                                                 ctx->saved);                        }                        b->last = ngx_cpymem(b->last, ctx->copy_start,                                             ctx->copy_end - ctx->copy_start);                        cl = ngx_alloc_chain_link(r->pool);                        if (cl == NULL) {                            return NGX_ERROR;                        }                        cl->buf = b;                        cl->next = NULL;                        b = NULL;                        mctx = ngx_http_get_module_ctx(r->main,                                                   ngx_http_ssi_filter_module);                        bl = mctx->blocks->elts;                        for (ll = &bl[mctx->blocks->nelts - 1].bufs;                             *ll;                             ll = &(*ll)->next)                        {                            /* void */                        }                        *ll = cl;                    }                    ctx->saved = 0;                }            }            if (ctx->state == ssi_start_state) {                ctx->copy_start = ctx->pos;                ctx->copy_end = ctx->pos;            } else {                ctx->copy_start = NULL;                ctx->copy_end = NULL;            }            if (rc == NGX_AGAIN) {                continue;            }            b = NULL;            if (rc == NGX_OK) {                smcf = ngx_http_get_module_main_conf(r,                                                   ngx_http_ssi_filter_module);                cmd = ngx_hash_find(&smcf->hash, ctx->key, ctx->command.data,                                    ctx->command.len);                if (cmd == NULL) {                    if (ctx->output) {                        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                      "invalid SSI command: \"%V\"",                                      &ctx->command);                        goto ssi_error;                    }                    continue;                }                if (cmd->conditional                    && (ctx->conditional == 0                        || ctx->conditional > cmd->conditional))                {                    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                  "invalid context of SSI command: \"%V\"",                                  &ctx->command);                    goto ssi_error;                }                if (!ctx->output && !cmd->block) {                    if (ctx->block) {                        /* reconstruct the SSI command text */                        len = 5 + ctx->command.len + 4;                        param = ctx->params.elts;                        for (i = 0; i < ctx->params.nelts; i++) {                            len += 1 + param[i].key.len + 2                                + param[i].value.len + 1;                        }                        b = ngx_create_temp_buf(r->pool, len);                        if (b == NULL) {                            return NGX_ERROR;                        }                        cl = ngx_alloc_chain_link(r->pool);                        if (cl == NULL) {                            return NGX_ERROR;                        }                        cl->buf = b;                        cl->next = NULL;                        *b->last++ = '<';                        *b->last++ = '!';                        *b->last++ = '-';                        *b->last++ = '-';                        *b->last++ = '#';                        b->last = ngx_cpymem(b->last, ctx->command.data,                                             ctx->command.len);                        for (i = 0; i < ctx->params.nelts; i++) {                            *b->last++ = ' ';                            b->last = ngx_cpymem(b->last, param[i].key.data,                                                 param[i].key.len);                            *b->last++ = '=';                            *b->last++ = '"';                            b->last = ngx_cpymem(b->last, param[i].value.data,                                                 param[i].value.len);                            *b->last++ = '"';                        }                        *b->last++ = ' ';                        *b->last++ = '-';                        *b->last++ = '-';                        *b->last++ = '>';                        mctx = ngx_http_get_module_ctx(r->main,                                                   ngx_http_ssi_filter_module);                        bl = mctx->blocks->elts;                        for (ll = &bl[mctx->blocks->nelts - 1].bufs;                             *ll;                             ll = &(*ll)->next)                        {                            /* void */                        }                        *ll = cl;                        b = NULL;                        continue;                    }                    if (cmd->conditional == 0) {                        continue;                    }                }                if (ctx->params.nelts > NGX_HTTP_SSI_MAX_PARAMS) {                    ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                  "too many SSI command paramters: \"%V\"",                                  &ctx->command);                    goto ssi_error;                }                ngx_memzero(params,                           (NGX_HTTP_SSI_MAX_PARAMS + 1) * sizeof(ngx_str_t *));                param = ctx->params.elts;                for (i = 0; i < ctx->params.nelts; i++) {                    for (prm = cmd->params; prm->name.len; prm++) {                        if (param[i].key.len != prm->name.len                            || ngx_strncmp(param[i].key.data, prm->name.data,                                           prm->name.len) != 0)                        {                            continue;                        }                        if (!prm->multiple) {                            if (params[prm->index]) {                                ngx_log_error(NGX_LOG_ERR,                                              r->connection->log, 0,                                              "duplicate \"%V\" parameter "                                              "in \"%V\" SSI command",                                              &param[i].key, &ctx->command);                                goto ssi_error;                            }                            params[prm->index] = &param[i].value;                            break;                        }                        for (index = prm->index; params[index]; index++) {                            /* void */                        }                        params[index] = &param[i].value;                        break;                    }                    if (prm->name.len == 0) {                        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                      "invalid parameter name: \"%V\" "                                      "in \"%V\" SSI command",                                      &param[i].key, &ctx->command);                        goto ssi_error;                    }                }                for (prm = cmd->params; prm->name.len; prm++) {                    if (prm->mandatory && params[prm->index] == 0) {                        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                                      "mandatory \"%V\" parameter is absent "                                      "in \"%V\" SSI command",                                      &prm->name, &ctx->command);                        goto ssi_error;                    }                }                if (cmd->flush) {                    if (ctx->out) {                        rc = ngx_http_ssi_output(r, ctx);                    } else {                        rc = ngx_http_next_body_filter(r, NULL);                    }                    if (rc == NGX_ERROR) {                        return NGX_ERROR;                    }                }                rc = cmd->handler(r, ctx, params);                if (rc == NGX_OK) {                    continue;                }                if (rc == NGX_DONE || rc == NGX_AGAIN || rc == NGX_ERROR) {                    return rc;                }            }            /* rc == NGX_HTTP_SSI_ERROR */    ssi_error:            if (slcf->silent_errors) {                continue;            }            if (ctx->free) {                cl = ctx->free;                ctx->free = ctx->free->next;                b = cl->buf;                ngx_memzero(b, sizeof(ngx_buf_t));            } else {                b = ngx_calloc_buf(r->pool);                if (b == NULL) {                    return NGX_ERROR;                }                cl = ngx_alloc_chain_link(r->pool);                if (cl == NULL) {                    return NGX_ERROR;                }                cl->buf = b;            }            b->memory = 1;            b->pos = ctx->errmsg.data;            b->last = ctx->errmsg.data + ctx->errmsg.len;            cl->next = NULL;            *ctx->last_out = cl;            ctx->last_out = &cl->next;            continue;        }        if (ctx->buf->last_buf || ngx_buf_in_memory(ctx->buf)) {            if (b == NULL) {                if (ctx->free) {                    cl = ctx->free;                    ctx->free = ctx->free->next;                    b = cl->buf;                    ngx_memzero(b, sizeof(ngx_buf_t));                } else {                    b = ngx_calloc_buf(r->pool);                    if (b == NULL) {                        return NGX_ERROR;                    }                    cl = ngx_alloc_chain_link(r->pool);                    if (cl == NULL) {                        return NGX_ERROR;                    }                    cl->buf = b;                }                b->sync = 1;                cl->next = NULL;                *ctx->last_out = cl;                ctx->last_out = &cl->next;            }            b->last_buf = ctx->buf->last_buf;            b->shadow = ctx->buf;            if (slcf->ignore_recycled_buffers == 0)  {                b->recycled = ctx->buf->recycled;            }        }        ctx->buf = NULL;        ctx->saved = ctx->looked;    }    if (ctx->out == NULL && ctx->busy == NULL) {        return NGX_OK;    }    return ngx_http_ssi_output(r, ctx);}static ngx_int_tngx_http_ssi_output(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx){    ngx_int_t     rc;    ngx_buf_t    *b;    ngx_chain_t  *cl;#if 1    b = NULL;    for (cl = ctx->out; cl; cl = cl->next) {        ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                       "ssi out: %p %p", cl->buf, cl->buf->pos);        if (cl->buf == b) {            ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,                          "the same buf was used in ssi");            ngx_debug_point();            return NGX_ERROR;        }

⌨️ 快捷键说明

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