From 658b1f85f5e3b1a2699cbb008a739d32b5f87685 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Wed, 22 Feb 2017 18:18:08 +0300 Subject: [PATCH] FS-10060 [mod_v8] Add startup scripts support. --- .gitignore | 5 +- conf/curl/autoload_configs/v8.conf.xml | 2 + conf/insideout/autoload_configs/v8.conf.xml | 2 + conf/vanilla/autoload_configs/v8.conf.xml | 2 + .../mod_v8/conf/autoload_configs/v8.conf.xml | 2 + src/mod/languages/mod_v8/mod_v8.cpp | 53 +++++++++++++------ src/mod/languages/mod_v8/mod_v8.h | 1 + 7 files changed, 51 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index ccbebdd2be..d7e6933822 100644 --- a/.gitignore +++ b/.gitignore @@ -239,4 +239,7 @@ libs/libpng/ libs/zlib/ libs/libav/ -libs/libx264/ \ No newline at end of file +libs/libx264/ + +Win32/*.msi +x64/*.msi \ No newline at end of file diff --git a/conf/curl/autoload_configs/v8.conf.xml b/conf/curl/autoload_configs/v8.conf.xml index 4f1e5f64f7..67c1f1ca06 100644 --- a/conf/curl/autoload_configs/v8.conf.xml +++ b/conf/curl/autoload_configs/v8.conf.xml @@ -1,5 +1,7 @@ + + diff --git a/conf/insideout/autoload_configs/v8.conf.xml b/conf/insideout/autoload_configs/v8.conf.xml index 4f1e5f64f7..67c1f1ca06 100644 --- a/conf/insideout/autoload_configs/v8.conf.xml +++ b/conf/insideout/autoload_configs/v8.conf.xml @@ -1,5 +1,7 @@ + + diff --git a/conf/vanilla/autoload_configs/v8.conf.xml b/conf/vanilla/autoload_configs/v8.conf.xml index 4f1e5f64f7..67c1f1ca06 100644 --- a/conf/vanilla/autoload_configs/v8.conf.xml +++ b/conf/vanilla/autoload_configs/v8.conf.xml @@ -1,5 +1,7 @@ + + diff --git a/src/mod/languages/mod_v8/conf/autoload_configs/v8.conf.xml b/src/mod/languages/mod_v8/conf/autoload_configs/v8.conf.xml index 4f1e5f64f7..67c1f1ca06 100644 --- a/src/mod/languages/mod_v8/conf/autoload_configs/v8.conf.xml +++ b/src/mod/languages/mod_v8/conf/autoload_configs/v8.conf.xml @@ -1,5 +1,7 @@ + + diff --git a/src/mod/languages/mod_v8/mod_v8.cpp b/src/mod/languages/mod_v8/mod_v8.cpp index fe2ff65de3..d0e5cc4abc 100644 --- a/src/mod/languages/mod_v8/mod_v8.cpp +++ b/src/mod/languages/mod_v8/mod_v8.cpp @@ -276,7 +276,35 @@ static switch_status_t load_modules(void) switch_core_hash_init(&module_manager.load_hash); if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) { - switch_xml_t mods, ld, settings, param, hook; + switch_xml_t mods, ld; + + if ((mods = switch_xml_child(cfg, "modules"))) { + for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) { + const char *val = switch_xml_attr_soft(ld, "module"); + if (!zstr(val) && strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); + continue; + } + v8_load_module(SWITCH_GLOBAL_dirs.mod_dir, val); + count++; + } + } + switch_xml_free(xml); + + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Open of %s failed\n", cf); + } + + return SWITCH_STATUS_SUCCESS; +} + +static void load_configuration(void) +{ + const char *cf = "v8.conf"; + switch_xml_t cfg, xml; + + if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) { + switch_xml_t settings, param, hook; if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { @@ -292,6 +320,11 @@ static switch_status_t load_modules(void) switch_xml_bind_search_function(v8_fetch, switch_xml_parse_section_string(val), NULL); } } + else if (!strcmp(var, "startup-script")) { + if (val) { + v8_thread_launch(val); + } + } } for (hook = switch_xml_child(settings, "hook"); hook; hook = hook->next) { @@ -326,24 +359,12 @@ static switch_status_t load_modules(void) } } - if ((mods = switch_xml_child(cfg, "modules"))) { - for (ld = switch_xml_child(mods, "load"); ld; ld = ld->next) { - const char *val = switch_xml_attr_soft(ld, "module"); - if (!zstr(val) && strchr(val, '.') && !strstr(val, ext) && !strstr(val, EXT)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Invalid extension for %s\n", val); - continue; - } - v8_load_module(SWITCH_GLOBAL_dirs.mod_dir, val); - count++; - } - } switch_xml_free(xml); - } else { + } + else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Open of %s failed\n", cf); } - - return SWITCH_STATUS_SUCCESS; } static int env_init(JSMain *js) @@ -1007,6 +1028,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_v8_load) SWITCH_ADD_JSON_API(json_api_interface, "jsjson", "JSON JS Gateway", json_function, ""); + load_configuration(); + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_NOUNLOAD; } diff --git a/src/mod/languages/mod_v8/mod_v8.h b/src/mod/languages/mod_v8/mod_v8.h index 6d5c75c881..0af8e17e0a 100644 --- a/src/mod/languages/mod_v8/mod_v8.h +++ b/src/mod/languages/mod_v8/mod_v8.h @@ -86,6 +86,7 @@ void v8_remove_event_handler(void *event_handler); static switch_xml_t v8_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params, void *user_data); static void v8_event_handler(switch_event_t *event); +void v8_thread_launch(const char *text); #endif /* MOD_V8_H */