|
7 | 7 | #include <nxt_main.h>
|
8 | 8 | #include <nxt_conf.h>
|
9 | 9 | #include <nxt_cert.h>
|
| 10 | +#include <nxt_script.h> |
10 | 11 | #include <nxt_router.h>
|
11 | 12 | #include <nxt_http.h>
|
12 | 13 | #include <nxt_sockaddr.h>
|
@@ -226,6 +227,13 @@ static nxt_int_t nxt_conf_vldt_cgroup_path(nxt_conf_validation_t *vldt,
|
226 | 227 | nxt_conf_value_t *value, void *data);
|
227 | 228 | #endif
|
228 | 229 |
|
| 230 | +#if (NXT_HAVE_NJS) |
| 231 | +static nxt_int_t nxt_conf_vldt_js_module(nxt_conf_validation_t *vldt, |
| 232 | + nxt_conf_value_t *value, void *data); |
| 233 | +static nxt_int_t nxt_conf_vldt_js_module_element(nxt_conf_validation_t *vldt, |
| 234 | + nxt_conf_value_t *value); |
| 235 | +#endif |
| 236 | + |
229 | 237 |
|
230 | 238 | static nxt_conf_vldt_object_t nxt_conf_vldt_setting_members[];
|
231 | 239 | static nxt_conf_vldt_object_t nxt_conf_vldt_http_members[];
|
@@ -297,6 +305,12 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_setting_members[] = {
|
297 | 305 | .type = NXT_CONF_VLDT_OBJECT,
|
298 | 306 | .validator = nxt_conf_vldt_object,
|
299 | 307 | .u.members = nxt_conf_vldt_http_members,
|
| 308 | +#if (NXT_HAVE_NJS) |
| 309 | + }, { |
| 310 | + .name = nxt_string("js_module"), |
| 311 | + .type = NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY, |
| 312 | + .validator = nxt_conf_vldt_js_module, |
| 313 | +#endif |
300 | 314 | },
|
301 | 315 |
|
302 | 316 | NXT_CONF_VLDT_END
|
@@ -1306,35 +1320,26 @@ nxt_conf_validate(nxt_conf_validation_t *vldt)
|
1306 | 1320 |
|
1307 | 1321 | vldt->tstr_state = nxt_tstr_state_new(vldt->pool, 1);
|
1308 | 1322 | if (nxt_slow_path(vldt->tstr_state == NULL)) {
|
1309 |
| - ret = NXT_ERROR; |
1310 |
| - goto fail; |
| 1323 | + return NXT_ERROR; |
1311 | 1324 | }
|
1312 | 1325 |
|
1313 | 1326 | ret = nxt_conf_vldt_type(vldt, NULL, vldt->conf, NXT_CONF_VLDT_OBJECT);
|
1314 | 1327 | if (ret != NXT_OK) {
|
1315 |
| - goto fail; |
| 1328 | + return ret; |
1316 | 1329 | }
|
1317 | 1330 |
|
1318 | 1331 | ret = nxt_conf_vldt_object(vldt, vldt->conf, nxt_conf_vldt_root_members);
|
1319 | 1332 | if (ret != NXT_OK) {
|
1320 |
| - goto fail; |
| 1333 | + return ret; |
1321 | 1334 | }
|
1322 | 1335 |
|
1323 | 1336 | ret = nxt_tstr_state_done(vldt->tstr_state, error);
|
1324 | 1337 | if (ret != NXT_OK) {
|
1325 | 1338 | ret = nxt_conf_vldt_error(vldt, "%s", error);
|
1326 |
| - goto fail; |
| 1339 | + return ret; |
1327 | 1340 | }
|
1328 | 1341 |
|
1329 |
| - nxt_tstr_state_release(vldt->tstr_state); |
1330 |
| - |
1331 | 1342 | return NXT_OK;
|
1332 |
| - |
1333 |
| -fail: |
1334 |
| - |
1335 |
| - nxt_tstr_state_release(vldt->tstr_state); |
1336 |
| - |
1337 |
| - return ret; |
1338 | 1343 | }
|
1339 | 1344 |
|
1340 | 1345 |
|
@@ -3241,6 +3246,49 @@ nxt_conf_vldt_server_weight(nxt_conf_validation_t *vldt,
|
3241 | 3246 | }
|
3242 | 3247 |
|
3243 | 3248 |
|
| 3249 | +#if (NXT_HAVE_NJS) |
| 3250 | + |
| 3251 | +static nxt_int_t |
| 3252 | +nxt_conf_vldt_js_module(nxt_conf_validation_t *vldt, nxt_conf_value_t *value, |
| 3253 | + void *data) |
| 3254 | +{ |
| 3255 | + if (nxt_conf_type(value) == NXT_CONF_ARRAY) { |
| 3256 | + return nxt_conf_vldt_array_iterator(vldt, value, |
| 3257 | + &nxt_conf_vldt_js_module_element); |
| 3258 | + } |
| 3259 | + |
| 3260 | + /* NXT_CONF_STRING */ |
| 3261 | + |
| 3262 | + return nxt_conf_vldt_js_module_element(vldt, value); |
| 3263 | +} |
| 3264 | + |
| 3265 | + |
| 3266 | +static nxt_int_t |
| 3267 | +nxt_conf_vldt_js_module_element(nxt_conf_validation_t *vldt, |
| 3268 | + nxt_conf_value_t *value) |
| 3269 | +{ |
| 3270 | + nxt_str_t name; |
| 3271 | + nxt_conf_value_t *module; |
| 3272 | + |
| 3273 | + if (nxt_conf_type(value) != NXT_CONF_STRING) { |
| 3274 | + return nxt_conf_vldt_error(vldt, "The \"js_module\" array must " |
| 3275 | + "contain only string values."); |
| 3276 | + } |
| 3277 | + |
| 3278 | + nxt_conf_get_string(value, &name); |
| 3279 | + |
| 3280 | + module = nxt_script_info_get(&name); |
| 3281 | + if (module == NULL) { |
| 3282 | + return nxt_conf_vldt_error(vldt, "JS module \"%V\" is not found.", |
| 3283 | + &name); |
| 3284 | + } |
| 3285 | + |
| 3286 | + return NXT_OK; |
| 3287 | +} |
| 3288 | + |
| 3289 | +#endif |
| 3290 | + |
| 3291 | + |
3244 | 3292 | typedef struct {
|
3245 | 3293 | nxt_str_t path;
|
3246 | 3294 | nxt_str_t format;
|
|
0 commit comments