diff --git a/buildconf/default.ini b/buildconf/default.ini index 609b961e..9de065c8 100644 --- a/buildconf/default.ini +++ b/buildconf/default.ini @@ -20,6 +20,7 @@ pcre = auto debug = false unbit = false xml_implementation = libxml2 +yaml_implementation = auto plugins = bin_name = uwsgi plugin_dir = . diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 32d3f855..0a8c55c9 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -404,6 +404,13 @@ class uConf(object): if self.get('yaml'): self.cflags.append("-DUWSGI_YAML") self.gcc_list.append('yaml') + if self.get('yaml_implementation') == 'libyaml': + self.cflags.append("-DUWSGI_LIBYAML") + self.libs.append('-lyaml') + if self.get('yaml_implementation') == 'auto': + if os.path.exists('/usr/include/yaml.h') or os.path.exists('/usr/local/include/yaml.h'): + self.cflags.append("-DUWSGI_LIBYAML") + self.libs.append('-lyaml') if self.get('json'): if self.get('json') == 'auto': diff --git a/werkzeug.yml b/werkzeug.yml index 210e7d9d..3eac4a11 100644 --- a/werkzeug.yml +++ b/werkzeug.yml @@ -9,6 +9,7 @@ uwsgi: master: 1 processes: 8 # the number of processes memory-report: 1 + show-config: true # now a psgi app via plugin app2: @@ -19,3 +20,4 @@ app2: processes: 8 # the number of processes memory-report: 1 psgi: test.psgi + show-config: true diff --git a/yaml.c b/yaml.c index a7696dc8..693533f6 100644 --- a/yaml.c +++ b/yaml.c @@ -4,6 +4,8 @@ extern struct uwsgi_server uwsgi; + +#ifndef UWSGI_LIBYAML /* yaml file must be read ALL into memory. This memory must not be freed for all the server lifecycle @@ -83,23 +85,19 @@ char *yaml_get_line(char *yaml, off_t size) { return NULL; } +#else +#include +#endif void uwsgi_yaml_config(char *file, char *magic_table[]) { int len = 0; char *yaml; - int depth; - int current_depth = 0; int in_uwsgi_section = 0; - char *yaml_line; - - char *section = ""; - char *key; - char *val; - - int lines = 1; + char *key = NULL; + char *val = NULL; char *section_asked = "uwsgi"; char *colon; @@ -123,6 +121,76 @@ void uwsgi_yaml_config(char *file, char *magic_table[]) { yaml = uwsgi_open_and_read(file, &len, 1, magic_table); +#ifdef UWSGI_LIBYAML + yaml_parser_t parser; + yaml_token_t token; + int status = 0; + int parsing = 1; + + if(!yaml_parser_initialize(&parser)) { + uwsgi_log("unable to initialize YAML parser (libyaml)\n"); + exit(1); + } + + yaml_parser_set_input_string(&parser, (const unsigned char *)yaml, (size_t) len-1); + + while(parsing) { + yaml_parser_scan(&parser, &token); + switch(token.type) { + case YAML_STREAM_END_TOKEN: + parsing = 0; + break; + case YAML_KEY_TOKEN: + status = 1; + break; + case YAML_VALUE_TOKEN: + status = 2; + break; + case YAML_BLOCK_MAPPING_START_TOKEN: + if (!in_uwsgi_section) { + if (key) { + if (!strcmp(section_asked, key)) { + in_uwsgi_section = 1; + } + } + } + break; + case YAML_BLOCK_END_TOKEN: + if (in_uwsgi_section) { + parsing = 0; + break; + } + break; + case YAML_SCALAR_TOKEN: + if (status == 1) { + key = (char *) token.data.scalar.value; + } + else if (status == 2) { + val = (char *) token.data.scalar.value; + if (key && val && in_uwsgi_section) { + add_exported_option(key, val, 0); + } + status = 0; + } + else { + uwsgi_log("unsupported YAML token in %s block\n", section_asked); + parsing = 0; + break; + } + break; + default: + status = 0; + } + } + +#else + int depth; + int current_depth = 0; + int lines = 1; + char *yaml_line; + char *section = ""; + + while(len) { yaml_line = yaml_get_line(yaml, len); if (yaml_line == NULL) { @@ -184,6 +252,7 @@ next: yaml += (yaml_line - yaml); } +#endif }