diff options
author | Dmitry Volyntsev <xeioex@nginx.com> | 2021-12-09 14:38:40 +0000 |
---|---|---|
committer | Dmitry Volyntsev <xeioex@nginx.com> | 2021-12-09 14:38:40 +0000 |
commit | 5c92d6ab873f729699f8adf8862a4e4344f4b781 (patch) | |
tree | 02c83b1c28e93cbdda553f6e2b4bff78153b85a3 /nginx/ngx_http_js_module.c | |
parent | 14003a8d120b4cd91b5bb8f731e21c1c570b7dcb (diff) | |
download | njs-5c92d6ab873f729699f8adf8862a4e4344f4b781.tar.gz njs-5c92d6ab873f729699f8adf8862a4e4344f4b781.zip |
Modules: removed "js_include" directive deprecated in 0.4.0.
Diffstat (limited to 'nginx/ngx_http_js_module.c')
-rw-r--r-- | nginx/ngx_http_js_module.c | 128 |
1 files changed, 14 insertions, 114 deletions
diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c index 5e46218d..5b20a084 100644 --- a/nginx/ngx_http_js_module.c +++ b/nginx/ngx_http_js_module.c @@ -14,9 +14,6 @@ typedef struct { njs_vm_t *vm; - ngx_str_t include; - u_char *file; - ngx_uint_t line; ngx_array_t *imports; ngx_array_t *paths; } ngx_http_js_main_conf_t; @@ -216,8 +213,6 @@ static void ngx_http_js_handle_event(ngx_http_request_t *r, njs_vm_event_t vm_event, njs_value_t *args, njs_uint_t nargs); static ngx_int_t ngx_http_js_init(ngx_conf_t *cf); -static char *ngx_http_js_include(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); static char *ngx_http_js_import(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_http_js_set(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -251,13 +246,6 @@ static ngx_conf_bitmask_t ngx_http_js_ssl_protocols[] = { static ngx_command_t ngx_http_js_commands[] = { - { ngx_string("js_include"), - NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1, - ngx_http_js_include, - NGX_HTTP_MAIN_CONF_OFFSET, - offsetof(ngx_http_js_main_conf_t, include), - NULL }, - { ngx_string("js_import"), NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE13, ngx_http_js_import, @@ -3481,7 +3469,6 @@ ngx_http_js_init_main_conf(ngx_conf_t *cf, void *conf) size_t size; u_char *start, *end, *p; - ssize_t n; ngx_fd_t fd; ngx_str_t *m, file; njs_int_t rc; @@ -3489,7 +3476,6 @@ ngx_http_js_init_main_conf(ngx_conf_t *cf, void *conf) ngx_uint_t i; njs_value_t *value; njs_vm_opt_t options; - ngx_file_info_t fi; ngx_pool_cleanup_t *cln; njs_opaque_value_t lvalue, exception; ngx_http_js_import_t *import; @@ -3497,42 +3483,17 @@ ngx_http_js_init_main_conf(ngx_conf_t *cf, void *conf) static const njs_str_t line_number_key = njs_str("lineNumber"); static const njs_str_t file_name_key = njs_str("fileName"); - if (jmcf->include.len == 0 && jmcf->imports == NGX_CONF_UNSET_PTR) { + if (jmcf->imports == NGX_CONF_UNSET_PTR) { return NGX_CONF_OK; } size = 0; fd = NGX_INVALID_FILE; - if (jmcf->include.len != 0) { - file = jmcf->include; - - if (ngx_conf_full_name(cf->cycle, &file, 1) != NGX_OK) { - return NGX_CONF_ERROR; - } - - fd = ngx_open_file(file.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); - if (fd == NGX_INVALID_FILE) { - ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - ngx_open_file_n " \"%s\" failed", file.data); - return NGX_CONF_ERROR; - } - - if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - ngx_fd_info_n " \"%s\" failed", file.data); - (void) ngx_close_file(fd); - return NGX_CONF_ERROR; - } - - size = ngx_file_size(&fi); - - } else { - import = jmcf->imports->elts; - for (i = 0; i < jmcf->imports->nelts; i++) { - size += sizeof("import from '';\n") - 1 + import[i].name.len - + import[i].path.len; - } + import = jmcf->imports->elts; + for (i = 0; i < jmcf->imports->nelts; i++) { + size += sizeof("import from '';\n") - 1 + import[i].name.len + + import[i].path.len; } start = ngx_pnalloc(cf->pool, size); @@ -3544,41 +3505,14 @@ ngx_http_js_init_main_conf(ngx_conf_t *cf, void *conf) return NGX_CONF_ERROR; } - if (jmcf->include.len != 0) { - n = ngx_read_fd(fd, start, size); - - if (n == -1) { - ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - ngx_read_fd_n " \"%s\" failed", file.data); - - (void) ngx_close_file(fd); - return NGX_CONF_ERROR; - } - - if ((size_t) n != size) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - ngx_read_fd_n " has read only %z " - "of %O from \"%s\"", n, size, file.data); - - (void) ngx_close_file(fd); - return NGX_CONF_ERROR; - } - - if (ngx_close_file(fd) == NGX_FILE_ERROR) { - ngx_log_error(NGX_LOG_EMERG, cf->log, ngx_errno, - ngx_close_file_n " %s failed", file.data); - } - - } else { - p = start; - import = jmcf->imports->elts; - for (i = 0; i < jmcf->imports->nelts; i++) { - p = ngx_cpymem(p, "import ", sizeof("import ") - 1); - p = ngx_cpymem(p, import[i].name.data, import[i].name.len); - p = ngx_cpymem(p, " from '", sizeof(" from '") - 1); - p = ngx_cpymem(p, import[i].path.data, import[i].path.len); - p = ngx_cpymem(p, "';\n", sizeof("';\n") - 1); - } + p = start; + import = jmcf->imports->elts; + for (i = 0; i < jmcf->imports->nelts; i++) { + p = ngx_cpymem(p, "import ", sizeof("import ") - 1); + p = ngx_cpymem(p, import[i].name.data, import[i].name.len); + p = ngx_cpymem(p, " from '", sizeof(" from '") - 1); + p = ngx_cpymem(p, import[i].path.data, import[i].path.len); + p = ngx_cpymem(p, "';\n", sizeof("';\n") - 1); } njs_vm_opt_init(&options); @@ -3590,12 +3524,7 @@ ngx_http_js_init_main_conf(ngx_conf_t *cf, void *conf) options.argv = ngx_argv; options.argc = ngx_argc; - if (jmcf->include.len != 0) { - file = jmcf->include; - - } else { - file = ngx_cycle->conf_prefix; - } + file = ngx_cycle->conf_prefix; options.file.start = file.data; options.file.length = file.len; @@ -3665,12 +3594,6 @@ ngx_http_js_init_main_conf(ngx_conf_t *cf, void *conf) njs_value_assign(&exception, njs_vm_retval(jmcf->vm)); njs_vm_retval_string(jmcf->vm, &text); - if (jmcf->include.len != 0) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "%*s, included in %s:%ui", - text.length, text.start, jmcf->file, jmcf->line); - return NGX_CONF_ERROR; - } - value = njs_vm_object_prop(jmcf->vm, njs_value_arg(&exception), &file_name_key, &lvalue); if (value == NULL) { @@ -3720,22 +3643,6 @@ ngx_http_js_init(ngx_conf_t *cf) static char * -ngx_http_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) -{ - ngx_http_js_main_conf_t *jmcf = conf; - - if (jmcf->imports != NGX_CONF_UNSET_PTR) { - return "is incompatible with \"js_import\""; - } - - jmcf->file = cf->conf_file->file.name.data; - jmcf->line = cf->conf_file->line; - - return ngx_conf_set_str_slot(cf, cmd, conf); -} - - -static char * ngx_http_js_import(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_js_main_conf_t *jmcf = conf; @@ -3745,10 +3652,6 @@ ngx_http_js_import(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_str_t *value, name, path; ngx_http_js_import_t *import; - if (jmcf->include.len != 0) { - return "is incompatible with \"js_include\""; - } - value = cf->args->elts; from = (cf->args->nelts == 4); @@ -4011,9 +3914,6 @@ ngx_http_js_create_main_conf(ngx_conf_t *cf) * set by ngx_pcalloc(): * * conf->vm = NULL; - * conf->include = { 0, NULL }; - * conf->file = NULL; - * conf->line = 0; */ conf->paths = NGX_CONF_UNSET_PTR; |