本文整理汇总了C++中dd函数的典型用法代码示例。如果您正苦于以下问题:C++ dd函数的具体用法?C++ dd怎么用?C++ dd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ngx_http_lua_timer_handler
static void
ngx_http_lua_timer_handler(ngx_event_t *ev)
{
int n;
lua_State *L;
ngx_int_t rc;
ngx_connection_t *c = NULL;
ngx_http_request_t *r = NULL;
ngx_http_lua_ctx_t *ctx;
ngx_http_cleanup_t *cln;
ngx_pool_cleanup_t *pcln;
ngx_http_lua_timer_ctx_t tctx;
ngx_http_lua_main_conf_t *lmcf;
ngx_http_core_loc_conf_t *clcf;
ngx_http_lua_timer_log_ctx_t *logctx;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
"lua ngx.timer expired");
ngx_memcpy(&tctx, ev->data, sizeof(ngx_http_lua_timer_ctx_t));
ngx_free(ev);
ev = NULL;
lmcf = tctx.lmcf;
lmcf->pending_timers--;
if (lmcf->running_timers >= lmcf->max_running_timers) {
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
"%i lua_max_running_timers are not enough",
lmcf->max_running_timers);
goto failed;
}
c = ngx_http_lua_create_fake_connection(tctx.pool);
if (c == NULL) {
goto failed;
}
logctx = ngx_palloc(c->pool, sizeof(ngx_http_lua_timer_log_ctx_t));
if (logctx == NULL) {
goto failed;
}
logctx->connection = c;
c->log->handler = ngx_http_lua_log_timer_error;
c->log->data = logctx;
c->listening = tctx.listening;
c->addr_text = tctx.client_addr_text;
r = ngx_http_lua_create_fake_request(c);
if (r == NULL) {
goto failed;
}
r->main_conf = tctx.main_conf;
r->srv_conf = tctx.srv_conf;
r->loc_conf = tctx.loc_conf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
#if defined(nginx_version) && nginx_version >= 1003014
ngx_http_set_connection_log(r->connection, clcf->error_log);
#else
c->log->file = clcf->error_log->file;
if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
c->log->log_level = clcf->error_log->log_level;
}
#endif
dd("lmcf: %p", lmcf);
ctx = ngx_http_lua_create_ctx(r);
if (ctx == NULL) {
goto failed;
}
if (tctx.vm_state) {
ctx->vm_state = tctx.vm_state;
pcln = ngx_pool_cleanup_add(r->pool, 0);
if (pcln == NULL) {
goto failed;
}
pcln->handler = ngx_http_lua_cleanup_vm;
pcln->data = tctx.vm_state;
}
ctx->cur_co_ctx = &ctx->entry_co_ctx;
L = ngx_http_lua_get_lua_vm(r, ctx);
//.........这里部分代码省略.........
开发者ID:adamonduty,项目名称:lua-nginx-module,代码行数:101,代码来源:ngx_http_lua_timer.c
示例2: ngx_http_lua_socket_resolve_handler
static void
ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
{
ngx_http_request_t *r;
ngx_connection_t *c;
ngx_http_upstream_resolved_t *ur;
ngx_http_lua_ctx_t *lctx;
lua_State *L;
ngx_http_lua_socket_udp_upstream_t *u;
u_char *p;
size_t len;
#if defined(nginx_version) && nginx_version >= 1005008
socklen_t socklen;
struct sockaddr *sockaddr;
#else
struct sockaddr_in *sin;
#endif
ngx_uint_t i;
unsigned waiting;
u = ctx->data;
r = u->request;
c = r->connection;
ur = u->resolved;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
"lua udp socket resolve handler");
lctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (lctx == NULL) {
return;
}
lctx->cur_co_ctx = u->co_ctx;
u->co_ctx->cleanup = NULL;
L = lctx->cur_co_ctx->co;
dd("setting socket_ready to 1");
waiting = u->waiting;
if (ctx->state) {
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"lua udp socket resolver error: %s (waiting: %d)",
ngx_resolver_strerror(ctx->state), (int) u->waiting);
lua_pushnil(L);
lua_pushlstring(L, (char *) ctx->name.data, ctx->name.len);
lua_pushfstring(L, " could not be resolved (%d: %s)",
(int) ctx->state,
ngx_resolver_strerror(ctx->state));
lua_concat(L, 2);
#if 1
ngx_resolve_name_done(ctx);
ur->ctx = NULL;
#endif
u->prepare_retvals = ngx_http_lua_socket_error_retval_handler;
ngx_http_lua_socket_udp_handle_error(r, u,
NGX_HTTP_LUA_SOCKET_FT_RESOLVER);
if (waiting) {
ngx_http_run_posted_requests(c);
}
return;
}
ur->naddrs = ctx->naddrs;
ur->addrs = ctx->addrs;
#if (NGX_DEBUG)
{
# if defined(nginx_version) && nginx_version >= 1005008
u_char text[NGX_SOCKADDR_STRLEN];
ngx_str_t addr;
# else
in_addr_t addr;
# endif
ngx_uint_t i;
# if defined(nginx_version) && nginx_version >= 1005008
addr.data = text;
for (i = 0; i < ctx->naddrs; i++) {
addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen,
text, NGX_SOCKADDR_STRLEN, 0);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"name was resolved to %V", &addr);
}
# else
for (i = 0; i < ctx->naddrs; i++) {
dd("addr i: %d %p", (int) i, &ctx->addrs[i]);
addr = ntohl(ctx->addrs[i]);
//.........这里部分代码省略.........
开发者ID:coderxh,项目名称:lua-nginx-module,代码行数:101,代码来源:ngx_http_lua_socket_udp.c
示例3: ngx_http_lua_socket_udp_receive
static int
ngx_http_lua_socket_udp_receive(lua_State *L)
{
ngx_http_request_t *r;
ngx_http_lua_socket_udp_upstream_t *u;
ngx_int_t rc;
ngx_http_lua_ctx_t *ctx;
ngx_http_lua_co_ctx_t *coctx;
size_t size;
int nargs;
ngx_http_lua_loc_conf_t *llcf;
nargs = lua_gettop(L);
if (nargs != 1 && nargs != 2) {
return luaL_error(L, "expecting 1 or 2 arguments "
"(including the object), but got %d", nargs);
}
r = ngx_http_lua_get_req(L);
if (r == NULL) {
return luaL_error(L, "no request found");
}
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua udp socket calling receive() method");
luaL_checktype(L, 1, LUA_TTABLE);
lua_rawgeti(L, 1, SOCKET_CTX_INDEX);
u = lua_touserdata(L, -1);
lua_pop(L, 1);
if (u == NULL || u->udp_connection.connection == NULL) {
llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
if (llcf->log_socket_errors) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"attempt to receive data on a closed socket: u:%p, "
"c:%p", u, u ? u->udp_connection.connection : NULL);
}
lua_pushnil(L);
lua_pushliteral(L, "closed");
return 2;
}
if (u->request != r) {
return luaL_error(L, "bad request");
}
if (u->ft_type) {
u->ft_type = 0;
}
#if 1
if (u->waiting) {
lua_pushnil(L);
lua_pushliteral(L, "socket busy");
return 2;
}
#endif
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua udp socket read timeout: %M", u->read_timeout);
size = (size_t) luaL_optnumber(L, 2, UDP_MAX_DATAGRAM_SIZE);
size = ngx_min(size, UDP_MAX_DATAGRAM_SIZE);
u->recv_buf_size = size;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua udp socket receive buffer size: %uz", u->recv_buf_size);
rc = ngx_http_lua_socket_udp_read(r, u);
if (rc == NGX_ERROR) {
dd("read failed: %d", (int) u->ft_type);
rc = ngx_http_lua_socket_udp_receive_retval_handler(r, u, L);
dd("udp receive retval returned: %d", (int) rc);
return rc;
}
if (rc == NGX_OK) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua udp socket receive done in a single run");
return ngx_http_lua_socket_udp_receive_retval_handler(r, u, L);
}
/* n == NGX_AGAIN */
u->read_event_handler = ngx_http_lua_socket_udp_read_handler;
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (ctx == NULL) {
return luaL_error(L, "no request ctx found");
}
coctx = ctx->cur_co_ctx;
//.........这里部分代码省略.........
开发者ID:coderxh,项目名称:lua-nginx-module,代码行数:101,代码来源:ngx_http_lua_socket_udp.c
示例4: ngx_http_lua_ngx_req_set_body_file
static int
ngx_http_lua_ngx_req_set_body_file(lua_State *L)
{
u_char *p;
ngx_http_request_t *r;
int n;
ngx_http_request_body_t *rb;
ngx_temp_file_t *tf;
ngx_buf_t *b;
ngx_str_t name;
ngx_int_t rc;
int clean;
ngx_open_file_info_t of;
ngx_str_t key, value;
ngx_pool_cleanup_t *cln;
ngx_pool_cleanup_file_t *clnf;
ngx_err_t err;
ngx_chain_t *cl;
ngx_buf_tag_t tag;
n = lua_gettop(L);
if (n != 1 && n != 2) {
return luaL_error(L, "expecting 1 or 2 arguments but seen %d", n);
}
p = (u_char *) luaL_checklstring(L, 1, &name.len);
lua_pushlightuserdata(L, &ngx_http_lua_request_key);
lua_rawget(L, LUA_GLOBALSINDEX);
r = lua_touserdata(L, -1);
lua_pop(L, 1);
if (r == NULL) {
return luaL_error(L, "request object not found");
}
if (r->discard_body) {
return luaL_error(L, "request body already discarded asynchronously");
}
if (r->request_body == NULL) {
return luaL_error(L, "request body not read yet");
}
name.data = ngx_palloc(r->pool, name.len + 1);
if (name.data == NULL) {
return luaL_error(L, "out of memory");
}
ngx_memcpy(name.data, p, name.len);
name.data[name.len] = '\0';
if (n == 2) {
luaL_checktype(L, 2, LUA_TBOOLEAN);
clean = lua_toboolean(L, 2);
} else {
clean = 0;
}
dd("clean: %d", (int) clean);
rb = r->request_body;
/* clean up existing r->request_body->bufs (if any) */
tag = (ngx_buf_tag_t) &ngx_http_lua_module;
if (rb->bufs) {
dd("XXX reusing buf");
for (cl = rb->bufs; cl; cl = cl->next) {
if (cl->buf->tag == tag && cl->buf->temporary) {
dd("free old request body buffer: size:%d",
(int) ngx_buf_size(cl->buf));
ngx_pfree(r->pool, cl->buf->start);
cl->buf->tag = (ngx_buf_tag_t) NULL;
cl->buf->temporary = 0;
}
}
rb->bufs->next = NULL;
b = rb->bufs->buf;
ngx_memzero(b, sizeof(ngx_buf_t));
b->tag = tag;
} else {
dd("XXX creating new buf");
rb->bufs = ngx_alloc_chain_link(r->pool);
if (rb->bufs == NULL) {
return luaL_error(L, "out of memory");
}
rb->bufs->next = NULL;
//.........这里部分代码省略.........
开发者ID:08opt,项目名称:tengine,代码行数:101,代码来源:ngx_http_lua_req_body.c
示例5: getProperty
/// Do one iteration.
bool LevenbergMarquardtMDMinimizer::iterate()
{
const bool debug = getProperty("Debug");
const double muMax = getProperty("MuMax");
const double absError = getProperty("AbsError");
if ( !m_leastSquares )
{
throw std::runtime_error("Cost function isn't set up.");
}
size_t n = m_leastSquares->nParams();
if ( n == 0 )
{
m_errorString = "No parameters to fit.";
g_log.warning() << m_errorString << std::endl;
return false;
}
if ( m_mu > muMax )
{
//m_errorString = "Failed to converge, maximum mu reached";
//g_log.warning() << m_errorString << std::endl;
return false;
}
// calculate the first and second derivatives of the cost function.
if (m_mu == 0.0)
{// first time calculate everything
m_F = m_leastSquares->valDerivHessian();
}
else if (m_rho > 0)
{// last iteration was good: calculate new m_der and m_hessian, dont't recalculate m_F
m_leastSquares->valDerivHessian(false);
}
// else if m_rho < 0 last iteration was bad: reuse m_der and m_hessian
// Calculate damping to hessian
if (m_mu == 0) // first iteration or accidental zero
{
m_mu = m_tau;
m_nu = 2.0;
}
if (debug)
{
g_log.warning() << "===========================================================" << std::endl;
g_log.warning() << "mu=" << m_mu << std::endl << std::endl;
}
if (m_D.empty())
{
m_D.resize(n);
}
// copy the hessian
GSLMatrix H( m_leastSquares->getHessian() );
GSLVector dd( m_leastSquares->getDeriv() );
// scaling factors
std::vector<double> sf(n);
for(size_t i = 0; i < n; ++i)
{
double d = fabs(dd.get(i));
if (m_D[i] > d) d = m_D[i];
m_D[i] = d;
double tmp = H.get(i,i) + m_mu * d;
H.set(i,i,tmp);
sf[i] = sqrt( tmp );
if ( tmp == 0.0 )
{
m_errorString = "Singular matrix.";
g_log.warning() << m_errorString << std::endl;
return false;
}
}
// apply scaling
for(size_t i = 0; i < n; ++i)
{
double d = dd.get(i);
dd.set( i, d / sf[i] );
for(size_t j = i; j < n; ++j)
{
const double f = sf[i] * sf[j];
double tmp = H.get(i,j);
H.set(i,j,tmp/f);
if ( i != j )
{
tmp = H.get(j,i);
H.set(j,i,tmp/f);
}
}
}
if (debug && m_rho > 0)
{
g_log.warning() << "Hessian:\n" << H ;
//.........这里部分代码省略.........
开发者ID:AlistairMills,项目名称:mantid,代码行数:101,代码来源:LevenbergMarquardtMDMinimizer.cpp
示例6: ngx_http_lua_ngx_req_set_body_data
static int
ngx_http_lua_ngx_req_set_body_data(lua_State *L)
{
ngx_http_request_t *r;
int n;
ngx_http_request_body_t *rb;
ngx_temp_file_t *tf;
ngx_buf_t *b;
ngx_str_t body, key, value;
#if 1
ngx_int_t rc;
#endif
ngx_chain_t *cl;
ngx_buf_tag_t tag;
n = lua_gettop(L);
if (n != 1) {
return luaL_error(L, "expecting 1 arguments but seen %d", n);
}
body.data = (u_char *) luaL_checklstring(L, 1, &body.len);
lua_pushlightuserdata(L, &ngx_http_lua_request_key);
lua_rawget(L, LUA_GLOBALSINDEX);
r = lua_touserdata(L, -1);
lua_pop(L, 1);
if (r == NULL) {
return luaL_error(L, "request object not found");
}
if (r->discard_body) {
return luaL_error(L, "request body already discarded asynchronously");
}
if (r->request_body == NULL) {
return luaL_error(L, "request body not read yet");
}
rb = r->request_body;
tag = (ngx_buf_tag_t) &ngx_http_lua_module;
tf = rb->temp_file;
if (tf) {
if (tf->file.fd != NGX_INVALID_FILE) {
dd("cleaning temp file %.*s", (int) tf->file.name.len,
tf->file.name.data);
ngx_http_lua_pool_cleanup_file(r->pool, tf->file.fd);
tf->file.fd = NGX_INVALID_FILE;
dd("temp file cleaned: %.*s", (int) tf->file.name.len,
tf->file.name.data);
}
rb->temp_file = NULL;
}
if (body.len == 0) {
if (rb->bufs) {
for (cl = rb->bufs; cl; cl = cl->next) {
if (cl->buf->tag == tag && cl->buf->temporary) {
dd("free old request body buffer: size:%d",
(int) ngx_buf_size(cl->buf));
ngx_pfree(r->pool, cl->buf->start);
cl->buf->tag = (ngx_buf_tag_t) NULL;
cl->buf->temporary = 0;
}
}
}
rb->bufs = NULL;
rb->buf = NULL;
dd("request body is set to empty string");
goto set_header;
}
if (rb->bufs) {
for (cl = rb->bufs; cl; cl = cl->next) {
if (cl->buf->tag == tag && cl->buf->temporary) {
dd("free old request body buffer: size:%d",
(int) ngx_buf_size(cl->buf));
ngx_pfree(r->pool, cl->buf->start);
cl->buf->tag = (ngx_buf_tag_t) NULL;
cl->buf->temporary = 0;
}
}
rb->bufs->next = NULL;
//.........这里部分代码省略.........
开发者ID:08opt,项目名称:tengine,代码行数:101,代码来源:ngx_http_lua_req_body.c
示例7: ngx_http_lua_ngx_req_read_body
static int
ngx_http_lua_ngx_req_read_body(lua_State *L)
{
ngx_http_request_t *r;
int n;
ngx_int_t rc;
ngx_http_lua_ctx_t *ctx;
ngx_http_lua_co_ctx_t *coctx;
n = lua_gettop(L);
if (n != 0) {
return luaL_error(L, "expecting 0 arguments but seen %d", n);
}
lua_pushlightuserdata(L, &ngx_http_lua_request_key);
lua_rawget(L, LUA_GLOBALSINDEX);
r = lua_touserdata(L, -1);
lua_pop(L, 1);
if (r == NULL) {
return luaL_error(L, "request object not found");
}
r->request_body_in_single_buf = 1;
r->request_body_in_persistent_file = 1;
r->request_body_in_clean_file = 1;
#if 1
if (r->request_body_in_file_only) {
r->request_body_file_log_level = 0;
}
#endif
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
if (ctx == NULL) {
return luaL_error(L, "no ctx found");
}
ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
| NGX_HTTP_LUA_CONTEXT_ACCESS
| NGX_HTTP_LUA_CONTEXT_CONTENT);
coctx = ctx->cur_co_ctx;
if (coctx == NULL) {
return luaL_error(L, "no co ctx found");
}
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua start to read buffered request body");
rc = ngx_http_read_client_request_body(r, ngx_http_lua_req_body_post_read);
#if (nginx_version < 1002006) || \
(nginx_version >= 1003000 && nginx_version < 1003009)
r->main->count--;
#endif
if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
ctx->exit_code = rc;
ctx->exited = 1;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http read client request body returned error code %i, "
"exitting now", rc);
return lua_yield(L, 0);
}
#if (nginx_version >= 1002006 && nginx_version < 1003000) || \
nginx_version >= 1003009
r->main->count--;
dd("decrement r->main->count: %d", (int) r->main->count);
#endif
if (rc == NGX_AGAIN) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua read buffered request body requires I/O "
"interruptions");
ctx->waiting_more_body = 1;
ctx->req_body_reader_co_ctx = coctx;
coctx->cleanup = ngx_http_lua_req_body_cleanup;
coctx->data = r;
return lua_yield(L, 0);
}
/* rc == NGX_OK */
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua has read buffered request body in a single run");
return 0;
}
开发者ID:08opt,项目名称:tengine,代码行数:96,代码来源:ngx_http_lua_req_body.c
示例8: urandweighted
uint32 urandweighted(size_t count, double const* chances)
{
std::discrete_distribution<uint32> dd(chances, chances + count);
return dd(SFMTEngine::Instance());
}
开发者ID:Carbenium,项目名称:TrinityCore,代码行数:5,代码来源:Random.cpp
示例9: ngx_http_lua_ngx_location_capture_multi
//.........这里部分代码省略.........
sr_headers_len = nsubreqs * sizeof(ngx_http_headers_out_t *);
sr_bodies_len = nsubreqs * sizeof(ngx_str_t);
p = ngx_pcalloc(r->pool, sr_statuses_len + sr_headers_len +
sr_bodies_len);
if (p == NULL) {
return luaL_error(L, "out of memory");
}
coctx->sr_statuses = (void *) p;
p += sr_statuses_len;
coctx->sr_headers = (void *) p;
p += sr_headers_len;
coctx->sr_bodies = (void *) p;
coctx->nsubreqs = nsubreqs;
coctx->done = 0;
coctx->waiting = 0;
extra_vars = NULL;
for (index = 0; index < nsubreqs; index++) {
coctx->waiting++;
lua_rawgeti(L, 1, index + 1);
if (lua_isnil(L, -1)) {
return luaL_error(L, "only array-like tables are allowed");
}
dd("queries query: top %d", lua_gettop(L));
if (lua_type(L, -1) != LUA_TTABLE) {
return luaL_error(L, "the query argument %d is not a table, "
"but a %s",
index, lua_typename(L, lua_type(L, -1)));
}
nargs = lua_objlen(L, -1);
if (nargs != 1 && nargs != 2) {
return luaL_error(L, "query argument %d expecting one or "
"two arguments", index);
}
lua_rawgeti(L, 2, 1); /* queries query uri */
dd("queries query uri: %d", lua_gettop(L));
dd("first arg in first query: %s", lua_typename(L, lua_type(L, -1)));
body = NULL;
extra_args.data = NULL;
extra_args.len = 0;
if (extra_vars != NULL) {
/* flush out existing elements in the array */
extra_vars->nelts = 0;
}
vars_action = 0;
开发者ID:deba12,项目名称:lua-nginx-module,代码行数:66,代码来源:ngx_http_lua_subrequest.c
示例10: ngx_http_lua_rewrite_handler
ngx_int_t
ngx_http_lua_rewrite_handler(ngx_http_request_t *r)
{
ngx_http_lua_loc_conf_t *llcf;
ngx_http_lua_ctx_t *ctx;
ngx_int_t rc;
ngx_http_lua_main_conf_t *lmcf;
/* XXX we need to take into account ngx_rewrite's location dump */
if (r->uri_changed) {
return NGX_DECLINED;
}
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua rewrite handler, uri:\"%V\" c:%ud", &r->uri,
r->main->count);
lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
if (!lmcf->postponed_to_rewrite_phase_end) {
ngx_http_core_main_conf_t *cmcf;
ngx_http_phase_handler_t tmp;
ngx_http_phase_handler_t *ph;
ngx_http_phase_handler_t *cur_ph;
ngx_http_phase_handler_t *last_ph;
lmcf->postponed_to_rewrite_phase_end = 1;
cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
ph = cmcf->phase_engine.handlers;
cur_ph = &ph[r->phase_handler];
last_ph = &ph[cur_ph->next - 1];
#if 0
if (cur_ph == last_ph) {
dd("XXX our handler is already the last rewrite phase handler");
}
#endif
if (cur_ph < last_ph) {
dd("swaping the contents of cur_ph and last_ph...");
tmp = *cur_ph;
memmove(cur_ph, cur_ph + 1,
(last_ph - cur_ph) * sizeof (ngx_http_phase_handler_t));
*last_ph = tmp;
r->phase_handler--; /* redo the current ph */
return NGX_DECLINED;
}
}
llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
if (llcf->rewrite_handler == NULL) {
dd("no rewrite handler found");
return NGX_DECLINED;
}
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
dd("ctx = %p", ctx);
if (ctx == NULL) {
ctx = ngx_http_lua_create_ctx(r);
if (ctx == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
}
dd("entered? %d", (int) ctx->entered_rewrite_phase);
if (ctx->entered_rewrite_phase) {
dd("rewriteby: calling wev handler");
rc = ctx->resume_handler(r);
dd("rewriteby: wev handler returns %d", (int) rc);
if (rc == NGX_OK) {
rc = NGX_DECLINED;
}
if (rc == NGX_DECLINED) {
if (r->header_sent) {
dd("header already sent");
/* response header was already generated in access_by_lua*,
* so it is no longer safe to proceed to later phases
* which may generate responses again */
if (!ctx->eof) {
dd("eof not yet sent");
rc = ngx_http_lua_send_chain_link(r, ctx, NULL
/* indicate last_buf */);
if (rc == NGX_ERROR || rc > NGX_OK) {
return rc;
//.........这里部分代码省略.........
开发者ID:itpp16,项目名称:lua-nginx-module,代码行数:101,代码来源:ngx_http_lua_rewriteby.c
示例11: ngx_http_modsecurity_body_filter
ngx_int_t
ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
int buffer_fully_loadead = 0;
ngx_chain_t *chain = in;
ngx_http_modsecurity_ctx_t *ctx = NULL;
#ifdef MODSECURITY_SANITY_CHECKS
ngx_list_part_t *part = &r->headers_out.headers.part;
ngx_table_elt_t *data = part->elts;
ngx_uint_t i = 0;
#endif
if (in == NULL) {
return ngx_http_next_body_filter(r, in);
}
ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity);
dd("body filter, recovering ctx: %p", ctx);
if (ctx == NULL) {
return ngx_http_next_body_filter(r, in);
}
#ifdef MODSECURITY_SANITY_CHECKS
#if 0
dd("dumping stored ctx headers");
for (i = 0; i < ctx->sanity_headers_out->nelts; i++)
{
ngx_http_modsecurity_header_t *vals = ctx->sanity_headers_out->elts;
ngx_str_t *s2 = &vals[i].name, *s3 = &vals[i].value;
dd(" dump[%d]: name = '%.*s', value = '%.*s'", (int)i,
(int)s2->len, (char*)s2->data,
(int)s3->len, (char*)s3->data);
}
#endif
/*
* Identify if there is a header that was not inspected by ModSecurity.
*/
int worth_to_fail = 0;
for (i = 0; ; i++)
{
int found = 0;
ngx_uint_t j = 0;
ngx_table_elt_t *s1;
ngx_http_modsecurity_header_t *vals;
if (i >= part->nelts)
{
if (part->next == NULL) {
break;
}
part = part->next;
data = part->elts;
i = 0;
}
vals = ctx->sanity_headers_out->elts;
s1 = &data[i];
/*
* Headers that were inspected by ModSecurity.
*/
while (j < ctx->sanity_headers_out->nelts)
{
ngx_str_t *s2 = &vals[j].name;
ngx_str_t *s3 = &vals[j].value;
if (s1->key.len == s2->len && ngx_strncmp(s1->key.data, s2->data, s1->key.len) == 0)
{
if (s1->value.len == s3->len && ngx_strncmp(s1->value.data, s3->data, s1->value.len) == 0)
{
found = 1;
break;
}
}
j++;
}
if (!found) {
dd("header: `%.*s' with value: `%.*s' was not inspected by ModSecurity",
(int) s1->key.len,
(const char *) s1->key.data,
(int) s1->value.len,
(const char *) s1->value.data);
worth_to_fail++;
}
}
if (worth_to_fail)
{
dd("%d header(s) were not inspected by ModSecurity, so exiting", worth_to_fail);
return ngx_http_filter_finalize_request(r,
&ngx_http_modsecurity, NGX_HTTP_INTERNAL_SERVER_ERROR);
}
#endif
for (; chain != NULL; chain = chain->next)
{
//.........这里部分代码省略.........
开发者ID:nginx-modules,项目名称:ModSecurity-nginx,代码行数:101,代码来源:ngx_http_modsecurity_body_filter.c
示例12: ngx_http_lua_rewrite_by_chunk
static ngx_int_t
ngx_http_lua_rewrite_by_chunk(lua_State *L, ngx_http_request_t *r)
{
int co_ref;
lua_State *co;
ngx_int_t rc;
ngx_connection_t *c;
ngx_http_lua_ctx_t *ctx;
ngx_http_cleanup_t *cln;
ngx_http_lua_loc_conf_t *llcf;
/* {{{ new coroutine to handle request */
co = ngx_http_lua_new_thread(r, L, &co_ref);
if (co == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"lua: failed to create new coroutine to handle request");
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
/* move code closure to new coroutine */
lua_xmove(L, co, 1);
/* set closure's env table to new coroutine's globals table */
ngx_http_lua_get_globals_table(co);
lua_setfenv(co, -2);
/* save nginx request in coroutine globals table */
ngx_http_lua_set_req(co, r);
/* {{{ initialize request context */
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
dd("ctx = %p", ctx);
if (ctx == NULL) {
return NGX_ERROR;
}
ngx_http_lua_reset_ctx(r, L, ctx);
ctx->entered_rewrite_phase = 1;
ctx->cur_co_ctx = &ctx->entry_co_ctx;
ctx->cur_co_ctx->co = co;
ctx->cur_co_ctx->co_ref = co_ref;
#ifdef NGX_LUA_USE_ASSERT
ctx->cur_co_ctx->co_top = 1;
#endif
/* }}} */
/* {{{ register request cleanup hooks */
if (ctx->cleanup == NULL) {
cln = ngx_http_cleanup_add(r, 0);
if (cln == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
cln->handler = ngx_http_lua_request_cleanup_handler;
cln->data = ctx;
ctx->cleanup = &cln->handler;
}
/* }}} */
ctx->context = NGX_HTTP_LUA_CONTEXT_REWRITE;
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;
}
rc = ngx_http_lua_run_thread(L, r, ctx, 0);
if (rc == NGX_ERROR || rc > NGX_OK) {
return rc;
}
c = r->connection;
if (rc == NGX_AGAIN) {
rc = ngx_http_lua_run_posted_threads(c, L, r, ctx);
} else if (rc == NGX_DONE) {
ngx_http_lua_finalize_request(r, NGX_DONE);
rc = ngx_http_lua_run_posted_threads(c, L, r, ctx);
}
if (rc == NGX_OK || rc == NGX_DECLINED) {
if (r->header_sent) {
dd("header already sent");
/* response header was already generated in access_by_lua*,
* so it is no longer safe to proceed to later phases
//.........这里部分代码省略.........
开发者ID:itpp16,项目名称:lua-nginx-module,代码行数:101,代码来源:ngx_http_lua_rewriteby.c
示例13: ngx_http_lua_ngx_timer_at
//.........这里部分代码省略.........
}
/* to work around the -1 check in ngx_worker_process_cycle: */
lmcf->watcher->fd = (ngx_socket_t) -2;
lmcf->watcher->idle = 1;
lmcf->watcher->read->handler = ngx_http_lua_abort_pending_timers;
lmcf->watcher->data = lmcf;
}
vm = ngx_http_lua_get_lua_vm(r, ctx);
co = lua_newthread(vm);
/* L stack: time func [args] thread */
ngx_http_lua_probe_user_coroutine_create(r, L, co);
lua_createtable(co, 0, 0); /* the new globals table */
/* co stack: global_tb */
lua_createtable(co, 0, 1); /* the metatable */
ngx_http_lua_get_globals_table(co);
lua_setfield(co, -2, "__index");
lua_setmetatable(co, -2);
/* co stack: global_tb */
ngx_http_lua_set_globals_table(co);
/* co stack: <empty> */
dd("stack top: %d", lua_gettop(L));
lua_xmove(vm, L, 1); /* move coroutine from main thread to L */
/* L stack: time func [args] thread */
/* vm stack: empty */
lua_pushvalue(L, 2); /* copy entry function to top of L*/
/* L stack: time func [args] thread func */
lua_xmove(L, co, 1); /* move entry function from L to co */
/* L stack: time func [args] thread */
/* co stack: func */
ngx_http_lua_get_globals_table(co);
lua_setfenv(co, -2);
/* co stack: func */
lua_pushlightuserdata(L, &ngx_http_lua_coroutines_key);
lua_rawget(L, LUA_REGISTRYINDEX);
/* L stack: time func [args] thread corountines */
lua_pushvalue(L, -2);
/* L stack: time func [args] thread coroutines thread */
co_ref = luaL_ref(L, -2);
lua_pop(L, 1);
开发者ID:adamonduty,项目名称:lua-nginx-module,代码行数:66,代码来源:ngx_http_lua_timer.c
示例14: ngx_http_lua_abort_pending_timers
static void
ngx_http_lua_abort_pending_timers(ngx_event_t *ev)
{
ngx_int_t i, n;
ngx_event_t **events;
ngx_connection_t *c, *saved_c = NULL;
ngx_rbtree_node_t *cur, *prev, *next, *sentinel, *temp;
ngx_http_lua_timer_ctx_t *tctx;
ngx_http_lua_main_conf_t *lmcf;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
"lua abort pending timers");
c = ev->data;
lmcf = c->data;
dd("lua connection fd: %d", (int) c->fd);
if (!c->close) {
return;
}
c->read->closed = 1;
c->write->closed = 1;
/* we temporarily use a valid fd (0) to make ngx_free_connection happy */
c->fd = 0;
if (ngx_cycle->files) {
saved_c = ngx_cycle->files[0];
}
ngx_free_connection(c);
c->fd = (ngx_socket_t) -1;
if (ngx_cycle->files) {
ngx_cycle->files[0] = saved_c;
}
if (lmcf->pending_timers == 0) {
return;
}
/* expire pending timers immediately */
sentinel = ngx_event_timer_rbtree.sentinel;
cur = ngx_event_timer_rbtree.root;
/* XXX nginx does not guarentee the parent of root is meaningful,
* so we temporarily override it to simplify tree traversal. */
temp = cur->parent;
cur->parent = NULL;
prev = NULL;
events = ngx_pcalloc(ngx_cycle->pool,
lmcf->pending_timers * sizeof(ngx_event_t));
if (events == NULL) {
return;
}
n = 0;
dd("root: %p, root parent: %p, sentinel: %p", cur, cur->parent, sentinel);
while (n < lmcf->pending_timers) {
if (cur == sentinel || cur == NULL) {
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
"lua pending timer counter got out of sync: %i",
lmcf->pending_timers);
break;
}
dd("prev: %p, cur: %p, cur parent: %p, cur left: %p, cur right: %p",
prev, cur, cur->parent, cur->left, cur->right);
if (prev == cur->parent) {
/* neither of the children has been accessed yet */
next = cur->left;
if (next == sentinel) {
ev = (ngx_event_t *)
((char *) cur - offsetof(ngx_event_t, timer));
if (ev->handler == ngx_http_lua_timer_handler) {
dd("found node: %p", cur);
events[n++] = ev;
}
next = (cur->right != sentinel) ? cur->right : cur->parent;
}
} else if (prev == cur->left) {
/* just accessed the left child */
ev = (ngx_event_t *)
((char *) cur - offsetof(ngx_event_t, timer));
//.........这里部分代码省略.........
开发者ID:adamonduty,项目名称:lua-nginx-module,代码行数:101,代码来源:ngx_http_lua_timer.c
示例15: ngx_http_srcache_fetch_subrequest
static ngx_int_t
ngx_http_srcache_fetch_subrequest(ngx_http_request_t *r,
ngx_http_srcache_loc_conf_t *conf, ngx_http_srcache_ctx_t *ctx)
{
ngx_http_srcache_ctx_t *sr_ctx;
ngx_http_post_subrequest_t *psr;
ngx_str_t args;
ngx_uint_t flags = 0;
ngx_http_request_t *sr;
ngx_int_t rc;
ngx_http_srcache_parsed_request_t *parsed_sr;
dd_enter();
parsed_sr = ngx_palloc(r->pool, sizeof(ngx_http_srcache_parsed_request_t));
if (parsed_sr == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
parsed_sr->method = conf->fetch->method;
parsed_sr->method_name = conf->fetch->method_name;
parsed_sr->request_body = NULL;
parsed_sr->content_length_n = -1;
if (ngx_http_complex_value(r, &conf->fetch->location,
&parsed_sr->location) != NGX_OK)
{
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (parsed_sr->location.len == 0) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (ngx_http_complex_value(r, &conf->fetch->args, &parsed_sr->args)
!= NGX_OK)
{
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
args.data = NULL;
args.len = 0;
if (ngx_http_parse_unsafe_uri(r, &parsed_sr->location, &args, &flags)
!= NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (args.len > 0 && parsed_sr->args.len == 0) {
parsed_sr->args = args;
}
sr_ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_ctx_t));
if (sr_ctx == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
sr_ctx->in_fetch_subrequest = 1;
psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t));
if (psr == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
psr->handler = ngx_http_srcache_fetch_post_subrequest;
psr->data = sr_ctx;
dd("firing the fetch subrequest");
dd("fetch location: %.*s", (int) parsed_sr->location.len,
parsed_sr->location.data);
dd("fetch args: %.*s", (int) parsed_sr->args.len,
parsed_sr->args.data);
rc = ngx_http_subrequest(r, &parsed_sr->location, &parsed_sr->args,
&sr, psr, flags);
if (rc != NGX_OK) {
return NGX_ERROR;
}
rc = ngx_http_srcache_adjust_subrequest(sr, parsed_sr);
if (rc != NGX_OK) {
return NGX_ERROR;
}
ngx_http_set_ctx(sr, sr_ctx, ngx_http_srcache_filter_module);
ctx->fetch_sr = sr;
return NGX_OK;
}
开发者ID:zhuomingliang,项目名称:srcache-nginx-module,代码行数:96,代码来源:ngx_http_srcache_fetch.c
示例16: ngx_http_lua_post_subrequest
ngx_int_t
ngx_http_lua_post_subrequest(ngx_http_request_t *r, void *data, ngx_int_t rc)
{
ngx_http_request_t *pr;
ngx_http_lua_ctx_t *pr_ctx;
ngx_http_lua_ctx_t *ctx; /* subrequest ctx */
ngx_http_lua_co_ctx_t *pr_coctx;
size_t len;
ngx_str_t *body_str;
u_char *p;
ngx_chain_t *cl;
ngx_http_lua_post_subrequest_data_t *psr_data = data;
ctx = psr_data->ctx;
if (ctx->run_post_subrequest) {
return NGX_OK;
}
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua run post subrequest handler: rc:%d", rc);
ctx->run_post_subrequest = 1;
pr = r->parent;
pr_ctx = ngx_http_get_module_ctx(pr, ngx_http_lua_module);
if (pr_ctx == NULL) {
return NGX_ERROR;
}
pr_coctx = psr_data->pr_co_ctx;
pr_coctx->waiting--;
if (pr_coctx->waiting == 0) {
pr_coctx->done = 1;
}
if (pr_ctx->entered_content_phase) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"lua restoring write event handler");
pr->write_event_handler = ngx_http_lua_content_wev_handler;
}
dd("status rc = %d", (int) rc);
dd("status headers_out.status = %d", (int) r->headers_out.status);
dd("uri: %.*s", (int) r->uri.len, r->uri.data);
/* capture subrequest response status */
if (rc == NGX_ERROR) {
pr_coctx->sr_statuses[ctx->index] = NGX_HTTP_INTERNAL_SERVER_ERROR;
} else if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
pr_coctx->sr_statuses[ctx->index] = rc;
} else {
pr_coctx->sr_statuses[ctx->index] = r->headers_out.status;
}
if (pr_coctx->sr_statuses[ctx->index] == 0) {
pr_coctx->sr_statuses[ctx->index] = NGX_HTTP_OK;
}
dd("pr_coctx status: %d", (int) pr_coctx->sr_statuses[ctx->index]);
/* copy subrequest response headers */
pr_coctx->sr_headers[ctx->index] = &r->headers_out;
/* copy subrequest response body */
body_str = &pr_coctx->sr_bodies[ctx->index];
len = 0;
for (cl = ctx->body; cl; cl = cl->next) {
/* ignore all non-memory buffers */
len += cl->buf->last - cl->buf->pos;
}
body_str->len = len;
if (len == 0) {
body_str->data = NULL;
} else {
p = ngx_palloc(r->pool, len);
if (p == NULL) {
|
请发表评论