LCOV - code coverage report
Current view: top level - home/build/openresty-1.13.6.1/build/ngx_lua-0.10.11/src - ngx_http_lua_phase.c (source / functions) Hit Total Coverage
Test: coverage ngix Lines: 4 55 7.3 %
Date: 2020-03-03 04:25:50 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : 
       2             : /*
       3             :  * Copyright (C) Yichun Zhang (agentzh)
       4             :  */
       5             : 
       6             : 
       7             : #ifndef DDEBUG
       8             : #define DDEBUG 0
       9             : #endif
      10             : #include "ddebug.h"
      11             : 
      12             : 
      13             : #include "ngx_http_lua_phase.h"
      14             : #include "ngx_http_lua_util.h"
      15             : #include "ngx_http_lua_ctx.h"
      16             : 
      17             : 
      18             : static int ngx_http_lua_ngx_get_phase(lua_State *L);
      19             : 
      20             : 
      21             : static int
      22           0 : ngx_http_lua_ngx_get_phase(lua_State *L)
      23             : {
      24             :     ngx_http_request_t          *r;
      25             :     ngx_http_lua_ctx_t          *ctx;
      26             : 
      27           0 :     r = ngx_http_lua_get_req(L);
      28             : 
      29             :     /* If we have no request object, assume we are called from the "init"
      30             :      * phase. */
      31             : 
      32           0 :     if (r == NULL) {
      33           0 :         lua_pushliteral(L, "init");
      34           0 :         return 1;
      35             :     }
      36             : 
      37           0 :     ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
      38           0 :     if (ctx == NULL) {
      39           0 :         return luaL_error(L, "no request ctx found");
      40             :     }
      41             : 
      42           0 :     switch (ctx->context) {
      43           0 :     case NGX_HTTP_LUA_CONTEXT_INIT_WORKER:
      44           0 :         lua_pushliteral(L, "init_worker");
      45           0 :         break;
      46             : 
      47           0 :     case NGX_HTTP_LUA_CONTEXT_SET:
      48           0 :         lua_pushliteral(L, "set");
      49           0 :         break;
      50             : 
      51           0 :     case NGX_HTTP_LUA_CONTEXT_REWRITE:
      52           0 :         lua_pushliteral(L, "rewrite");
      53           0 :         break;
      54             : 
      55           0 :     case NGX_HTTP_LUA_CONTEXT_ACCESS:
      56           0 :         lua_pushliteral(L, "access");
      57           0 :         break;
      58             : 
      59           0 :     case NGX_HTTP_LUA_CONTEXT_CONTENT:
      60           0 :         lua_pushliteral(L, "content");
      61           0 :         break;
      62             : 
      63           0 :     case NGX_HTTP_LUA_CONTEXT_LOG:
      64           0 :         lua_pushliteral(L, "log");
      65           0 :         break;
      66             : 
      67           0 :     case NGX_HTTP_LUA_CONTEXT_HEADER_FILTER:
      68           0 :         lua_pushliteral(L, "header_filter");
      69           0 :         break;
      70             : 
      71           0 :     case NGX_HTTP_LUA_CONTEXT_BODY_FILTER:
      72           0 :         lua_pushliteral(L, "body_filter");
      73           0 :         break;
      74             : 
      75           0 :     case NGX_HTTP_LUA_CONTEXT_TIMER:
      76           0 :         lua_pushliteral(L, "timer");
      77           0 :         break;
      78             : 
      79           0 :     case NGX_HTTP_LUA_CONTEXT_BALANCER:
      80           0 :         lua_pushliteral(L, "balancer");
      81           0 :         break;
      82             : 
      83           0 :     case NGX_HTTP_LUA_CONTEXT_SSL_CERT:
      84           0 :         lua_pushliteral(L, "ssl_cert");
      85           0 :         break;
      86             : 
      87           0 :     case NGX_HTTP_LUA_CONTEXT_SSL_SESS_STORE:
      88           0 :         lua_pushliteral(L, "ssl_session_store");
      89           0 :         break;
      90             : 
      91           0 :     case NGX_HTTP_LUA_CONTEXT_SSL_SESS_FETCH:
      92           0 :         lua_pushliteral(L, "ssl_session_fetch");
      93           0 :         break;
      94             : 
      95           0 :     default:
      96           0 :         return luaL_error(L, "unknown phase: %#x", (int) ctx->context);
      97             :     }
      98             : 
      99           0 :     return 1;
     100             : }
     101             : 
     102             : 
     103             : void
     104          18 : ngx_http_lua_inject_phase_api(lua_State *L)
     105             : {
     106          18 :     lua_pushcfunction(L, ngx_http_lua_ngx_get_phase);
     107          18 :     lua_setfield(L, -2, "get_phase");
     108          18 : }
     109             : 
     110             : /* vi:set ft=c ts=4 sw=4 et fdm=marker: */

Generated by: LCOV version 1.13