1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| ngx_int_t ngx_add_module(ngx_conf_t *cf, ngx_str_t *file, ngx_module_t *module, char **order) { void *rv; ngx_uint_t i, m, before; ngx_core_module_t *core_module;
if (cf->cycle->modules_n >= ngx_max_module) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "too many modules loaded"); return NGX_ERROR; }
if (module->version != nginx_version) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "module \"%V\" version %ui instead of %ui", file, module->version, (ngx_uint_t) nginx_version); return NGX_ERROR; }
if (ngx_strcmp(module->signature, NGX_MODULE_SIGNATURE) != 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "module \"%V\" is not binary compatible", file); return NGX_ERROR; }
for (m = 0; cf->cycle->modules[m]; m++) { if (ngx_strcmp(cf->cycle->modules[m]->name, module->name) == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "module \"%s\" is already loaded", module->name); return NGX_ERROR; } }
if (module->index == NGX_MODULE_UNSET_INDEX) { module->index = ngx_module_index(cf->cycle);
if (module->index >= ngx_max_module) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "too many modules loaded"); return NGX_ERROR; } }
before = cf->cycle->modules_n;
if (order) { for (i = 0; order[i]; i++) { if (ngx_strcmp(order[i], module->name) == 0) { i++; break; } }
for ( ; order[i]; i++) {
#if 0 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cf->log, 0, "module: %s before %s", module->name, order[i]); #endif
for (m = 0; m < before; m++) { if (ngx_strcmp(cf->cycle->modules[m]->name, order[i]) == 0) {
ngx_log_debug3(NGX_LOG_DEBUG_CORE, cf->log, 0, "module: %s before %s:%i", module->name, order[i], m);
before = m; break; } } } }
if (before != cf->cycle->modules_n) { ngx_memmove(&cf->cycle->modules[before + 1], &cf->cycle->modules[before], (cf->cycle->modules_n - before) * sizeof(ngx_module_t *)); }
cf->cycle->modules[before] = module; cf->cycle->modules_n++;
if (module->type == NGX_CORE_MODULE) {
core_module = module->ctx;
if (core_module->create_conf) { rv = core_module->create_conf(cf->cycle); if (rv == NULL) { return NGX_ERROR; }
cf->cycle->conf_ctx[module->index] = rv; } }
return NGX_OK; }
|