|
| 1 | +// Copyright (c) 2015 |
| 2 | +// Author: Chrono Law |
| 3 | +#include "NdgTestInit.hpp" |
| 4 | + |
| 5 | +auto ndg_test_module = NdgTestInit::module(); |
| 6 | + |
| 7 | +/* |
| 8 | +#include <iostream> |
| 9 | +
|
| 10 | +#include "NgxAll.hpp" |
| 11 | +
|
| 12 | +struct NdgTestConf final |
| 13 | +{ |
| 14 | + ngx_flag_t enabled = NgxUnsetValue::get(); |
| 15 | +}; |
| 16 | +
|
| 17 | +static void *create(ngx_conf_t* cf); |
| 18 | +static char *merge(ngx_conf_t *cf, void *parent, void *child); |
| 19 | +
|
| 20 | +static ngx_command_t ndg_test_cmds[] = |
| 21 | +{ |
| 22 | + { |
| 23 | + ngx_string("ndg_test"), |
| 24 | + NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
| 25 | + ngx_conf_set_flag_slot, |
| 26 | + NGX_HTTP_LOC_CONF_OFFSET, |
| 27 | + offsetof(NdgTestConf, enabled), |
| 28 | + nullptr |
| 29 | + }, |
| 30 | +
|
| 31 | + ngx_null_command |
| 32 | +}; |
| 33 | +
|
| 34 | +static ngx_int_t init(ngx_conf_t* cf); |
| 35 | +static ngx_int_t handler(ngx_http_request_t *r); |
| 36 | +
|
| 37 | +static ngx_http_module_t ndg_test_ctx = |
| 38 | +{ |
| 39 | + nullptr, |
| 40 | + init, |
| 41 | + nullptr, |
| 42 | + nullptr, |
| 43 | + nullptr, |
| 44 | + nullptr, |
| 45 | + create, |
| 46 | + nullptr,//merge |
| 47 | +}; |
| 48 | +
|
| 49 | +ngx_module_t ndg_test_module = |
| 50 | +{ |
| 51 | + NGX_MODULE_V1, |
| 52 | + &ndg_test_ctx, |
| 53 | + ndg_test_cmds, |
| 54 | + NGX_HTTP_MODULE, |
| 55 | + nullptr, // init master |
| 56 | + nullptr, // init module |
| 57 | + nullptr, // init process |
| 58 | + nullptr, // init thread |
| 59 | + nullptr, // exit thread |
| 60 | + nullptr, // exit process |
| 61 | + nullptr, // exit master |
| 62 | + NGX_MODULE_V1_PADDING |
| 63 | +}; |
| 64 | +
|
| 65 | +static void* create(ngx_conf_t* cf) |
| 66 | +{ |
| 67 | + return NgxPool(cf).alloc<NdgTestConf>(); |
| 68 | +} |
| 69 | +
|
| 70 | +static char *merge(ngx_conf_t *cf, void *parent, void *child) |
| 71 | +{ |
| 72 | + boost::ignore_unused(cf); |
| 73 | +
|
| 74 | + auto prev = reinterpret_cast<NdgTestConf*>(parent); |
| 75 | + auto conf = reinterpret_cast<NdgTestConf*>(child); |
| 76 | +
|
| 77 | + NgxValue::merge(conf->enabled, prev->enabled, 1); |
| 78 | +
|
| 79 | + return NGX_CONF_OK; |
| 80 | +} |
| 81 | +
|
| 82 | +static ngx_int_t init(ngx_conf_t* cf) |
| 83 | +{ |
| 84 | + auto cmcf = reinterpret_cast<ngx_http_core_main_conf_t*>( |
| 85 | + ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module)); |
| 86 | +
|
| 87 | + NgxArray<ngx_http_handler_pt> arr( |
| 88 | + cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers); |
| 89 | +
|
| 90 | + arr.push(handler); |
| 91 | +
|
| 92 | + return NGX_OK; |
| 93 | +} |
| 94 | +
|
| 95 | +static ngx_int_t handler(ngx_http_request_t *r) |
| 96 | +{ |
| 97 | + auto cf = reinterpret_cast<NdgTestConf*>( |
| 98 | + ngx_http_get_module_loc_conf(r, ndg_test_module)); |
| 99 | +
|
| 100 | + NgxLogError(r).print("hello c++"); |
| 101 | +
|
| 102 | + if (cf->enabled) |
| 103 | + { |
| 104 | + std::cout << "hello nginx" << std::endl; |
| 105 | + } |
| 106 | + else |
| 107 | + { |
| 108 | + std::cout << "hello disabled" << std::endl; |
| 109 | + } |
| 110 | +
|
| 111 | +
|
| 112 | + return NGX_DECLINED; |
| 113 | +} |
| 114 | +*/ |
| 115 | + |
0 commit comments