Skip to content

Commit a3c3a29

Browse files
committed
NJS: supported loadable modules.
1 parent 56af7bb commit a3c3a29

16 files changed

+1591
-50
lines changed

auto/sources

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ NXT_LIB_PCRE_SRCS="src/nxt_pcre.c"
124124
NXT_LIB_PCRE2_SRCS="src/nxt_pcre2.c"
125125

126126
if [ "$NXT_NJS" != "NO" ]; then
127-
NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_js.c src/nxt_http_js.c"
127+
NXT_LIB_SRCS="$NXT_LIB_SRCS src/nxt_js.c src/nxt_http_js.c src/nxt_script.c"
128128
fi
129129

130130
NXT_LIB_EPOLL_SRCS="src/nxt_epoll_engine.c"

docs/changes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ basic URI rewrite support.
3838
</para>
3939
</change>
4040

41+
<change type="feature">
42+
<para>
43+
njs loadable modules support.
44+
</para>
45+
</change>
46+
4147
<change type="feature">
4248
<para>
4349
added conditional logging of route selection for HTTP requests.

src/nxt_conf_validation.c

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <nxt_main.h>
88
#include <nxt_conf.h>
99
#include <nxt_cert.h>
10+
#include <nxt_script.h>
1011
#include <nxt_router.h>
1112
#include <nxt_http.h>
1213
#include <nxt_sockaddr.h>
@@ -226,6 +227,13 @@ static nxt_int_t nxt_conf_vldt_cgroup_path(nxt_conf_validation_t *vldt,
226227
nxt_conf_value_t *value, void *data);
227228
#endif
228229

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+
229237

230238
static nxt_conf_vldt_object_t nxt_conf_vldt_setting_members[];
231239
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[] = {
297305
.type = NXT_CONF_VLDT_OBJECT,
298306
.validator = nxt_conf_vldt_object,
299307
.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
300314
},
301315

302316
NXT_CONF_VLDT_END
@@ -1306,35 +1320,26 @@ nxt_conf_validate(nxt_conf_validation_t *vldt)
13061320

13071321
vldt->tstr_state = nxt_tstr_state_new(vldt->pool, 1);
13081322
if (nxt_slow_path(vldt->tstr_state == NULL)) {
1309-
ret = NXT_ERROR;
1310-
goto fail;
1323+
return NXT_ERROR;
13111324
}
13121325

13131326
ret = nxt_conf_vldt_type(vldt, NULL, vldt->conf, NXT_CONF_VLDT_OBJECT);
13141327
if (ret != NXT_OK) {
1315-
goto fail;
1328+
return ret;
13161329
}
13171330

13181331
ret = nxt_conf_vldt_object(vldt, vldt->conf, nxt_conf_vldt_root_members);
13191332
if (ret != NXT_OK) {
1320-
goto fail;
1333+
return ret;
13211334
}
13221335

13231336
ret = nxt_tstr_state_done(vldt->tstr_state, error);
13241337
if (ret != NXT_OK) {
13251338
ret = nxt_conf_vldt_error(vldt, "%s", error);
1326-
goto fail;
1339+
return ret;
13271340
}
13281341

1329-
nxt_tstr_state_release(vldt->tstr_state);
1330-
13311342
return NXT_OK;
1332-
1333-
fail:
1334-
1335-
nxt_tstr_state_release(vldt->tstr_state);
1336-
1337-
return ret;
13381343
}
13391344

13401345

@@ -3241,6 +3246,49 @@ nxt_conf_vldt_server_weight(nxt_conf_validation_t *vldt,
32413246
}
32423247

32433248

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+
32443292
typedef struct {
32453293
nxt_str_t path;
32463294
nxt_str_t format;

0 commit comments

Comments
 (0)