Пример #1
0
static void
ngx_http_lua_req_body_post_read(ngx_http_request_t *r)
{
    ngx_http_lua_ctx_t  *ctx;

    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
            "lua req body post read");

    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
    ctx->req_read_body_done = 1;

#if defined(nginx_version) && nginx_version >= 8011
    r->main->count--;
#endif

    if (ctx->waiting_more_body) {
        ctx->waiting_more_body = 0;

        if (ctx->entered_content_phase) {
            ngx_http_lua_wev_handler(r);

        } else {
            ngx_http_core_run_phases(r);
        }
    }
}
static void
ngx_http_form_input_post_read(ngx_http_request_t *r)
{
    ngx_http_form_input_ctx_t     *ctx;

    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                   "http form_input post read request body");

    ctx = ngx_http_get_module_ctx(r, ngx_http_form_input_module);

    ctx->done = 1;

#if defined(nginx_version) && nginx_version >= 8011
    dd("count--");
    r->main->count--;
#endif

    dd("waiting more body: %d", (int) ctx->waiting_more_body);

    /* waiting_more_body my rewrite phase handler */
    if (ctx->waiting_more_body) {
        ctx->waiting_more_body = 0;

        ngx_http_core_run_phases(r);
    }
}
static void
ngx_http_srcache_post_read_body(ngx_http_request_t *r)
{
    ngx_http_srcache_ctx_t  *ctx;

    ctx = ngx_http_get_module_ctx(r, ngx_http_srcache_filter_module);

    dd("post read: ctx=%p", ctx);

    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                   "srcache post read for the access phase: wait:%ud c:%ud",
                   (unsigned) ctx->waiting_request_body, r->main->count);

    r->write_event_handler = ngx_http_core_run_phases;

#if defined(nginx_version) && nginx_version >= 8011
    r->main->count--;
#endif

    dd("c:%u", r->main->count);

    if (ctx->waiting_request_body) {
        ctx->request_body_done = 1;
        ctx->waiting_request_body = 0;
        ngx_http_core_run_phases(r);
    }
}
Пример #4
0
static void
ngx_http_modsecurity_body_handler(ngx_http_request_t *r)
{
    ngx_http_modsecurity_ctx_t    *ctx;
    ngx_int_t                      rc;

    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "modSecurity: body handler");

    ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity);

    if (ngx_http_modsecurity_load_request_body(r) != NGX_OK) {
        return ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
    }

    rc = ngx_http_modsecurity_status(r, modsecProcessRequestBody(ctx->req));

    if (rc != NGX_DECLINED) {
        return ngx_http_finalize_request(r, rc);
    }

    if (ngx_http_modsecurity_save_request_body(r) != NGX_OK
            || ngx_http_modsecurity_save_headers_in(r) != NGX_OK ) {

        return ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
    }

    r->phase_handler++;
    ngx_http_core_run_phases(r);
    ngx_http_finalize_request(r, NGX_DONE);
}
/* ngx_http_core_run_phases会遍历所有的phase,然后调用它的checker进行处理,phase处理过程中的错误处理,校验等都是在checker中完成的,不同phase的checker的逻辑是不同,但是返回值的意义是相同的,如果checker的返回值时NGX_OK表示请求处理完毕,否则会进入下一个handler继续处理。接下来看一下phase的checker */
static void
ngx_http_gettoken_wake_request(ngx_http_request_t *r)
{
    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http_gettoken: Waking authentication request \"%V\"",
        &r->request_line);
    ngx_http_core_run_phases(r);
}
static void
ngx_http_limit_req_delay(ngx_http_request_t *r)
{
    ngx_event_t  *wev;

    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                   "limit_req delay");

    wev = r->connection->write;

    if (wev->delayed) {

        if (ngx_handle_write_event(wev, 0) != NGX_OK) {
            ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
        }

        return;
    }

    if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
        return;
    }

    r->read_event_handler = ngx_http_block_reading;
    r->write_event_handler = ngx_http_core_run_phases;

    ngx_http_core_run_phases(r);
}
Пример #7
0
/**
 * Function to reset processing cycle if input data are not yet available.
 *
 * @param[in] r   the nginx request object
 */
static void ngxib_post_handler(ngx_http_request_t *r)
{
    ngxib_req_ctx *ctx = ngx_http_get_module_ctx(r, ngx_ironbee_module);
    if (ctx->body_wait) {
        ib_log_debug_tx(ctx->tx, "Waiting for more input body data.");
        ctx->body_wait = 0;
        ngx_http_core_run_phases(r);
    }
}
Пример #8
0
/**
 * Function to reset processing cycle if input data are not yet available.
 *
 * @param[in] r   the nginx request object
 */
static void ngxib_post_handler(ngx_http_request_t *r)
{
    ngxib_req_ctx *ctx = ngx_http_get_module_ctx(r, ngx_ironbee_module);
    if (ctx->body_wait) {
        ngx_log_error(NGX_LOG_DEBUG, r->connection->log, 0,
                      "Waiting for more input body data");
        ctx->body_wait = 0;
        ngx_http_core_run_phases(r);
    }
}
Пример #9
0
void
ngx_http_lua_sleep_handler(ngx_event_t *ev)
{
    ngx_connection_t        *c;
    ngx_http_request_t      *r;
    ngx_http_lua_ctx_t      *ctx;
    ngx_http_log_ctx_t      *log_ctx;
    ngx_http_lua_co_ctx_t   *coctx;

    coctx = ev->data;

    r = coctx->data;
    c = r->connection;

    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);

    if (ctx == NULL) {
        return;
    }

    log_ctx = c->log->data;
    log_ctx->current_request = r;

    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
                   "lua sleep handler: \"%V?%V\"", &r->uri, &r->args);

    if (!coctx->sleep.timedout) {
        dd("reach lua sleep event handler without timeout!");
        return;
    }

    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
                   "lua sleep timer expired: \"%V?%V\"", &r->uri, &r->args);

    if (coctx->sleep.timer_set) {
        dd("deleting timer for lua_sleep");
        ngx_del_timer(&coctx->sleep);
    }

    ctx->cur_co_ctx = coctx;

    if (ctx->entered_content_phase) {
        (void) ngx_http_lua_sleep_resume(r);

    } else {
        ctx->resume_handler = ngx_http_lua_sleep_resume;
        ngx_http_core_run_phases(r);
    }

    ngx_http_run_posted_requests(c);
}
/* 读取请求报文体完毕后的回调函数 */
void
ngx_http_modsecurity_request_read(ngx_http_request_t *r)
{
    ngx_http_modsecurity_ctx_t *ctx;

    ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity_module);

#if defined(nginx_version) && nginx_version >= 8011
    r->main->count--;
#endif

    if (ctx->waiting_more_body)
    {
        ctx->waiting_more_body = 0;        /* 清除标识 */
        ngx_http_core_run_phases(r);       /* 继续handler处理 */
    }
}
Пример #11
0
void 
ngx_http_php_zend_uthread_resume(ngx_http_request_t *r)
{
    ngx_php_request = r;

    ngx_http_php_ctx_t *ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

    ngx_php_debug("ctx: %p", ctx);

    if (ctx == NULL) {
        
    }

    zend_try {
        zval *closure;
        zval *func_next;
        zval *func_valid;
        zval retval;

        closure = ctx->generator_closure;

        MAKE_STD_ZVAL(func_valid);
        ZVAL_STRING(func_next, "next", 1);
        call_user_function(NULL, &(closure), func_next, &retval, 0, NULL TSRMLS_CC);
        zval_ptr_dtor(&func_next);

        MAKE_STD_ZVAL(func_valid);
        ZVAL_STRING(func_valid, "valid", 1);
        call_user_function(NULL, &(closure), func_valid, &retval, 0, NULL TSRMLS_CC);
        zval_ptr_dtor(&func_valid);

        ngx_php_debug("r:%p, closure:%p, retval:%d", r, closure, Z_TYPE(retval));

        if (Z_TYPE(retval) == IS_BOOL && Z_BVAL(retval)) {
            ctx->phase_status = NGX_AGAIN;
        }else {
            ctx->phase_status = NGX_OK;
            ngx_http_core_run_phases(r);
            efree(ctx->generator_closure);
            ctx->generator_closure = NULL;
        }

    }zend_catch {

    }zend_end_try();
}
static void ngx_http_form_input_post_read(ngx_http_request_t *r)
{
    ngx_captcha_access_filter_ctx_t     *ctx = NULL;

    r->read_event_handler = ngx_http_request_empty_handler;

    ctx = ngx_http_get_module_ctx(r, ngx_captcha_access_filter_module);
    ctx->done = 1;

#if defined(nginx_version) && nginx_version >= 8011
    r->main->count--;
#endif

    /* waiting_more_body my rewrite phase handler */
    if (ctx->waiting_more_body) {
        ctx->waiting_more_body = 0;
        ngx_http_core_run_phases(r);
    }
}
/* post read callback for rewrite and access phases */
void
ngx_http_lua_generic_phase_post_read(ngx_http_request_t *r)
{
    ngx_http_lua_ctx_t  *ctx;

    r->read_event_handler = ngx_http_request_empty_handler;

    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);

    ctx->read_body_done = 1;

#if defined(nginx_version) && nginx_version >= 8011
    r->main->count--;
#endif

    if (ctx->waiting_more_body) {
        ctx->waiting_more_body = 0;
        ngx_http_core_run_phases(r);
    }
}
static void
ngx_http_chunkin_post_read(ngx_http_request_t *r)
{
    ngx_http_chunkin_ctx_t          *ctx;

    dd("post read");

    dd_check_read_event_handler(r);
    dd_check_write_event_handler(r);

    r->read_event_handler = ngx_http_block_reading;

    ctx = ngx_http_get_module_ctx(r, ngx_http_chunkin_filter_module);

    ctx->done = 1;

    if (ctx->waiting_more_body) {
        ctx->waiting_more_body = 0;
        ngx_http_core_run_phases(r);
    }
}
Пример #15
0
void
ngx_http_lua_sleep_handler(ngx_event_t *ev)
{
    ngx_connection_t        *c;
    ngx_http_request_t      *r;
    ngx_http_lua_ctx_t      *ctx;
    ngx_http_log_ctx_t      *log_ctx;
    ngx_http_lua_co_ctx_t   *coctx;

    coctx = ev->data;

    r = coctx->data;
    c = r->connection;

    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);

    if (ctx == NULL) {
        return;
    }

    log_ctx = c->log->data;
    log_ctx->current_request = r;

    coctx->cleanup = NULL;

    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
                   "lua sleep timer expired: \"%V?%V\"", &r->uri, &r->args);

    ctx->cur_co_ctx = coctx;

    if (ctx->entered_content_phase) {
        (void) ngx_http_lua_sleep_resume(r);

    } else {
        ctx->resume_handler = ngx_http_lua_sleep_resume;
        ngx_http_core_run_phases(r);
    }

    ngx_http_run_posted_requests(c);
}
Пример #16
0
void 
ngx_http_php_zend_uthread_exit(ngx_http_request_t *r)
{
    ngx_http_php_ctx_t *ctx;

    ngx_php_request = r;

    ctx = ngx_http_get_module_ctx(r, ngx_http_php_module);

    if (ctx == NULL) {

    }

    if (ctx->generator_closure) {
        //ngx_http_php_zend_uthread_resume(r);
        ctx->phase_status = NGX_OK;
        ngx_http_core_run_phases(r);
        efree(ctx->generator_closure);
        ctx->generator_closure = NULL;
    }

}
Пример #17
0
static void
ngx_http_lua_req_body_post_read(ngx_http_request_t *r)
{
    ngx_http_lua_ctx_t      *ctx;
    ngx_http_lua_co_ctx_t   *coctx;

    ngx_http_lua_loc_conf_t             *llcf;

    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                   "lua req body post read, c:%ud", r->main->count);

    ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);

    if (ctx->waiting_more_body) {
        ctx->waiting_more_body = 0;

        coctx = ctx->downstream;
        ctx->cur_co_ctx = coctx;

        coctx->cleanup = NULL;

        llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);

        if (llcf->check_client_abort) {
            r->read_event_handler = ngx_http_lua_rd_check_broken_connection;

        } else {
            r->read_event_handler = ngx_http_block_reading;
        }

        if (ctx->entered_content_phase) {
            (void) ngx_http_lua_read_body_resume(r);

        } else {
            ctx->resume_handler = ngx_http_lua_read_body_resume;
            ngx_http_core_run_phases(r);
        }
    }
}