[angel] rewrite parser, changing syntax (similar to main config)

personal/stbuehler/wip
Stefan Bühler 9 years ago
parent 84325a5a06
commit dfaab291d9
  1. 2
      include/lighttpd/angel_plugin.h
  2. 1296
      src/angel/angel_config_parser.rl
  3. 46
      src/angel/angel_plugin.c
  4. 2
      src/angel/angel_plugin_core.c
  5. 26
      tests/base.py

@ -78,7 +78,7 @@ LI_API void li_plugins_clear(liServer *srv);
LI_API void li_plugins_config_clean(liServer *srv);
LI_API gboolean li_plugins_config_load(liServer *srv, const gchar *filename);
LI_API void li_plugins_handle_item(liServer *srv, GString *itemname, liValue *hash);
LI_API gboolean li_plugins_handle_item(liServer *srv, GString *itemname, liValue *hash);
/* "core" is a reserved module name for interal use */
LI_API gboolean li_plugins_load_module(liServer *srv, const gchar *name);

File diff suppressed because it is too large Load Diff

@ -201,7 +201,7 @@ gboolean li_plugins_config_load(liServer *srv, const gchar *filename) {
return TRUE;
}
void li_plugins_handle_item(liServer *srv, GString *itemname, liValue *hash) {
gboolean li_plugins_handle_item(liServer *srv, GString *itemname, liValue *hash) {
liPlugins *ps = &srv->plugins;
server_item *si;
@ -219,24 +219,36 @@ void li_plugins_handle_item(liServer *srv, GString *itemname, liValue *hash) {
WARNING(srv, "Unknown item '%s' - perhaps you forgot to load the module? (ignored)", itemname->str);
} else {
liValue **optlist = g_slice_alloc0(sizeof(liValue*) * si->option_count);
GHashTableIter opti;
gpointer k, v;
guint i;
gboolean valid = TRUE;
/* find options and assign them by id */
g_hash_table_iter_init(&opti, hash->data.hash);
while (g_hash_table_iter_next(&opti, &k, &v)) {
const gchar *optkey = ((GString*) k)->str;
hash = li_value_get_single_argument(hash);
if (LI_VALUE_LIST != li_value_type(hash)) {
ERROR(srv, "invalid type '%s' of parameter list", li_value_type_string(hash));
return FALSE;
}
LI_VALUE_FOREACH(entry, hash)
liValue *entryKey = li_value_list_at(entry, 0);
liValue *entryValue = li_value_list_at(entry, 1);
GString *entryKeyStr;
if (LI_VALUE_STRING != li_value_type(entryKey)) {
ERROR(srv, "invalid key of type %s", li_value_type_string(entryKey));
return FALSE;
}
entryKeyStr = entryKey->data.string; /* keys are either NONE or STRING */
for (i = 0; i < si->option_count; i++) {
if (0 == g_strcmp0(si->p_item->options[i].name, optkey)) break;
if (0 == g_strcmp0(si->p_item->options[i].name, entryKeyStr->str)) break;
}
if (i == si->option_count) {
WARNING(srv, "Unknown option '%s' in item '%s' (ignored)", optkey, itemname->str);
ERROR(srv, "Unknown option '%s' in item '%s'", entryKeyStr->str, itemname->str);
return FALSE;
} else {
optlist[i] = v;
optlist[i] = entryValue;
}
}
LI_VALUE_END_FOREACH()
/* validate options */
for (i = 0; i < si->option_count; i++) {
@ -244,24 +256,24 @@ void li_plugins_handle_item(liServer *srv, GString *itemname, liValue *hash) {
if (0 != (pi->flags & LI_PLUGIN_ITEM_OPTION_MANDATORY)) {
if (!optlist[i]) {
ERROR(srv, "Missing mandatory option '%s' in item '%s'", pi->name, itemname->str);
valid = FALSE;
return FALSE;
}
}
if (pi->type != LI_VALUE_NONE && optlist[i] && optlist[i]->type != pi->type) {
/* TODO: convert from string if possible */
ERROR(srv, "Invalid value type of option '%s' in item '%s', got '%s' but expected '%s'",
pi->name, itemname->str, li_value_type_string(optlist[i]), li_valuetype_string(pi->type));
valid = FALSE;
return FALSE;
}
}
if (valid) {
g_assert(si->p_item->handle_parse_item);
si->p_item->handle_parse_item(srv, si->p, optlist);
}
g_assert(si->p_item->handle_parse_item);
si->p_item->handle_parse_item(srv, si->p, optlist);
g_slice_free1(sizeof(liValue*) * si->option_count, optlist);
}
return TRUE;
}
static gboolean plugins_activate_module(liServer *srv, server_module *sm) {

@ -273,7 +273,7 @@ static const liPluginItemOption core_listen_options[] = {
static const liPluginItem core_items[] = {
{ "instance", core_instance_parse, core_instance_options },
{ "allow-listen", core_listen_parse, core_listen_options },
{ "allow_listen", core_listen_parse, core_listen_options },
{ NULL, NULL, NULL }
};

@ -446,27 +446,27 @@ if request.is_handled {{
if Env.valgrind_leak != "":
suppressions = ', "--suppressions=' + Env.valgrind_leak + '"'
valgrindconfig = """
env ( "G_SLICE=always-malloc", "G_DEBUG=gc-friendly,fatal-criticals,resident-modules" );
wrapper ("{valgrind}", "--leak-check=full", "--show-reachable=yes", "--leak-resolution=high" {suppressions} );
"env" => [ "G_SLICE=always-malloc", "G_DEBUG=gc-friendly,fatal-criticals,resident-modules" ],
"wrapper" => [ "{valgrind}", "--leak-check=full", "--show-reachable=yes", "--leak-resolution=high" {suppressions} ],
""".format(valgrind = Env.valgrind, suppressions = suppressions)
elif Env.valgrind:
valgrindconfig = """
env ( "G_SLICE=always-malloc", "G_DEBUG=gc-friendly,fatal-criticals,resident-modules" );
wrapper ("{valgrind}" );
"env" => [ "G_SLICE=always-malloc", "G_DEBUG=gc-friendly,fatal-criticals,resident-modules" ],
"wrapper" => [ "{valgrind}" ],
""".format(valgrind = Env.valgrind)
Env.angelconf = self.PrepareFile("conf/angel.conf", """
instance {{
binary "{Env.worker}";
config "{Env.lighttpdconf}";
modules "{Env.plugindir}";
copy-env ("PATH");
instance [
"binary" => "{Env.worker}",
"config" => "{Env.lighttpdconf}",
"modules" => "{Env.plugindir}",
"copy-env" => [ "PATH" ],
{valgrindconfig}
}}
];
allow-listen {{ ip "127.0.0.2:{Env.port}"; }}
allow-listen {{ ip "127.0.0.2:{gnutlsport}"; }}
allow-listen {{ ip "127.0.0.2:{opensslport}"; }}
allow_listen [ "ip" => "127.0.0.2:{Env.port}", ];
allow_listen [ "ip" => "127.0.0.2:{gnutlsport}", ];
allow_listen [ "ip" => "127.0.0.2:{opensslport}", ];
""".format(Env = Env, gnutlsport = Env.port+1, opensslport = Env.port + 2, valgrindconfig = valgrindconfig))
print >> Env.log, "[Done] Preparing tests"

Loading…
Cancel
Save