diff --git a/repos/base-nova/src/test/nova/main.cc b/repos/base-nova/src/test/nova/main.cc index 2c2c85fd7e..b38929f13a 100644 --- a/repos/base-nova/src/test/nova/main.cc +++ b/repos/base-nova/src/test/nova/main.cc @@ -649,13 +649,14 @@ Main::Main(Env &env) : env(env) { log("testing base-nova platform"); - try { + { Attached_rom_dataspace config(env, "config"); - config.xml().attribute("check_pat").value(check_pat); - } catch (...) { - Genode::error("no check_pat attribute found"); - env.parent().exit(-__LINE__); - return; + if (!config.xml().has_attribute("check_pat")) { + Genode::error("no check_pat attribute found"); + env.parent().exit(-__LINE__); + return; + } + check_pat = config.xml().attribute_value("check_pat", check_pat); } Thread * myself = Thread::myself(); diff --git a/repos/base/include/util/xml_node.h b/repos/base/include/util/xml_node.h index 1f7c13c216..782b42e825 100644 --- a/repos/base/include/util/xml_node.h +++ b/repos/base/include/util/xml_node.h @@ -93,7 +93,7 @@ class Genode::Xml_attribute explicit Xml_attribute(Token t) : _tokens(t) { if (_tokens.name.type() != Token::IDENT) - throw Nonexistent_attribute(); + throw Invalid_syntax(); if (!_tokens.valid()) throw Invalid_syntax(); @@ -110,8 +110,7 @@ class Genode::Xml_attribute ** Exception types ** *********************/ - class Invalid_syntax : public Exception { }; - class Nonexistent_attribute : public Exception { }; + class Invalid_syntax : public Exception { }; typedef String<64> Name; @@ -121,7 +120,7 @@ class Genode::Xml_attribute /** * Return true if attribute has specified type */ - bool has_type(char const *type) { + bool has_type(char const *type) const { return strlen(type) == _tokens.name.len() && strcmp(type, _tokens.name.start(), _tokens.name.len()) == 0; } @@ -221,9 +220,7 @@ class Genode::Xml_node ** Exception types ** *********************/ - typedef Genode::Exception Exception; - typedef Xml_attribute::Nonexistent_attribute Nonexistent_attribute; - typedef Xml_attribute::Invalid_syntax Invalid_syntax; + typedef Xml_attribute::Invalid_syntax Invalid_syntax; class Nonexistent_sub_node : public Exception { }; @@ -885,41 +882,6 @@ class Genode::Xml_node for_each_sub_node(nullptr, fn); } - /** - * Return Nth attribute of XML node - * - * \param idx attribute index, - * first attribute has index 0 - * \throw Nonexistent_attribute no such attribute exists - * \return XML attribute - */ - Xml_attribute attribute(unsigned idx) const - { - Xml_attribute attr = _tags.start.attribute(); - for (unsigned i = 0; i < idx; i++) - attr = Xml_attribute(attr._next_token()); - - return attr; - } - - /** - * Return attribute of specified type - * - * \param type name of attribute type - * \throw Nonexistent_attribute no such attribute exists - * \return XML attribute - */ - Xml_attribute attribute(char const *type) const - { - for (Xml_attribute attr = _tags.start.attribute(); ;) { - if (attr.has_type(type)) - return attr; - - attr = Xml_attribute(attr._next_token()); - } - throw Nonexistent_attribute(); - } - /** * Read attribute value from XML node * diff --git a/repos/base/src/test/xml_node/test.cc b/repos/base/src/test/xml_node/test.cc index 4d26d66147..2963aaa380 100644 --- a/repos/base/src/test/xml_node/test.cc +++ b/repos/base/src/test/xml_node/test.cc @@ -243,11 +243,8 @@ struct Formatted_xml_attribute */ static void print_xml_attr_info(Output &output, Xml_node node, int indent = 0) { - try { - for (Xml_node::Attribute a = node.attribute(0U); ; a = a.next()) - print(output, Formatted_xml_attribute(a, indent), "\n"); - - } catch (Xml_node::Nonexistent_attribute) { } + node.for_each_attribute([&] (Xml_attribute const &a) { + print(output, Formatted_xml_attribute(a, indent), "\n"); }); } diff --git a/repos/dde_linux/src/driver/usb_net/main.cc b/repos/dde_linux/src/driver/usb_net/main.cc index 35bcc34ddd..8ae8a8d458 100644 --- a/repos/dde_linux/src/driver/usb_net/main.cc +++ b/repos/dde_linux/src/driver/usb_net/main.cc @@ -90,15 +90,12 @@ struct Main usb_config = config_rom.xml().attribute_value("configuration", 0ul); /* retrieve possible MAC */ - try { - Nic::Mac_address mac; - Xml_node::Attribute mac_node = config_rom.xml().attribute("mac"); - mac_node.value(mac); + use_mac_address = config_rom.xml().has_attribute("mac"); + if (use_mac_address) { + auto const mac = config_rom.xml().attribute_value("mac", Nic::Mac_address{}); mac.copy(mac_address); use_mac_address = true; log("Trying to use configured mac: ", mac); - } catch (...) { - use_mac_address = false; } } }; diff --git a/repos/dde_linux/src/lib/vfs/lxip/vfs.cc b/repos/dde_linux/src/lib/vfs/lxip/vfs.cc index 2e6b43fe42..ca993f9bb6 100644 --- a/repos/dde_linux/src/lib/vfs/lxip/vfs.cc +++ b/repos/dde_linux/src/lib/vfs/lxip/vfs.cc @@ -1619,34 +1619,31 @@ class Vfs::Lxip_file_system : public Vfs::File_system, return; } - try { + Addr ip_addr = config.attribute_value("ip_addr", Addr()); + Addr netmask = config.attribute_value("netmask", Addr()); + Addr gateway = config.attribute_value("gateway", Addr()); + Addr nameserver = config.attribute_value("nameserver", Addr()); - Addr ip_addr = config.attribute_value("ip_addr", Addr()); - Addr netmask = config.attribute_value("netmask", Addr()); - Addr gateway = config.attribute_value("gateway", Addr()); - Addr nameserver = config.attribute_value("nameserver", Addr()); + if (ip_addr == "") { + warning("Missing \"ip_addr\" attribute. Ignoring network interface config."); + return; + } else if (netmask == "") { + warning("Missing \"netmask\" attribute. Ignoring network interface config."); + return; + } - if (ip_addr == "") { - warning("Missing \"ip_addr\" attribute. Ignoring network interface config."); - throw Genode::Xml_node::Nonexistent_attribute(); - } else if (netmask == "") { - warning("Missing \"netmask\" attribute. Ignoring network interface config."); - throw Genode::Xml_node::Nonexistent_attribute(); - } + log("static network interface: ip_addr=",ip_addr," netmask=",netmask); - log("static network interface: ip_addr=",ip_addr," netmask=",netmask); + genode_socket_config address_config = { + .dhcp = false, + .ip_addr = ip_addr.string(), + .netmask = netmask.string(), + .gateway = gateway.string(), + .nameserver = nameserver.string(), + }; - genode_socket_config address_config = { - .dhcp = false, - .ip_addr = ip_addr.string(), - .netmask = netmask.string(), - .gateway = gateway.string(), - .nameserver = nameserver.string(), - }; - - genode_socket_config_address(&address_config); - } catch (...) { } - } + genode_socket_config_address(&address_config); + } /************************* diff --git a/repos/gems/include/gems/xml_anchor.h b/repos/gems/include/gems/xml_anchor.h index 6884f3227e..b3b558dbf6 100644 --- a/repos/gems/include/gems/xml_anchor.h +++ b/repos/gems/include/gems/xml_anchor.h @@ -54,10 +54,10 @@ class Anchor if (!node.has_attribute(attr)) return; - Xml_node::Attribute const anchor = node.attribute(attr); + auto const v = node.attribute_value(attr, Genode::String<16>()); for (Value const *value = _values; value->value; value++) { - if (anchor.has_value(value->value)) { + if (v == value->value) { horizontal = value->horizontal; vertical = value->vertical; return; diff --git a/repos/gems/src/app/backdrop/main.cc b/repos/gems/src/app/backdrop/main.cc index 2ad069192f..4ded5d1767 100644 --- a/repos/gems/src/app/backdrop/main.cc +++ b/repos/gems/src/app/backdrop/main.cc @@ -169,6 +169,8 @@ static Surface_base::Area calc_scaled_size(Xml_node operation, if (!operation.has_attribute(attr)) return image_size; + auto const value = operation.attribute_value("scale", String<16>()); + /* prevent division by zero, below */ if (image_size.count() == 0) return image_size; @@ -176,14 +178,13 @@ static Surface_base::Area calc_scaled_size(Xml_node operation, /* * Determine scale ratio (in 16.16 fixpoint format) */ - unsigned const ratio = - operation.attribute(attr).has_value("fit") ? - min((mode_size.w << 16) / image_size.w, - (mode_size.h << 16) / image_size.h) : - operation.attribute(attr).has_value("zoom") ? - max((mode_size.w << 16) / image_size.w, - (mode_size.h << 16) / image_size.h) : - 1 << 16; + unsigned const ratio = (value == "fit") + ? min((mode_size.w << 16) / image_size.w, + (mode_size.h << 16) / image_size.h) + : (value == "zoom") + ? max((mode_size.w << 16) / image_size.w, + (mode_size.h << 16) / image_size.h) + : 1 << 16; /* * We add 0.5 (1 << 15) to round instead of truncating the fractional diff --git a/repos/gems/src/app/decorator/config.h b/repos/gems/src/app/decorator/config.h index 771e4d00fb..311ac1bc18 100644 --- a/repos/gems/src/app/decorator/config.h +++ b/repos/gems/src/app/decorator/config.h @@ -219,11 +219,9 @@ class Decorator::Config if (node.has_type("maximizer")) type = Window_control::TYPE_MAXIMIZER; if (node.has_type("minimizer")) type = Window_control::TYPE_MINIMIZER; - if (node.has_attribute("align")) { - Genode::Xml_attribute attr = node.attribute("align"); - if (attr.has_value("left")) align = Window_control::ALIGN_LEFT; - if (attr.has_value("right")) align = Window_control::ALIGN_RIGHT; - } + auto const align_attr = node.attribute_value("align", Genode::String<16>()); + if (align_attr == "left") align = Window_control::ALIGN_LEFT; + if (align_attr == "right") align = Window_control::ALIGN_RIGHT; _window_controls[_num_window_controls++] = new (_alloc) Window_control(type, align); diff --git a/repos/gems/src/app/depot_autopilot/child.cc b/repos/gems/src/app/depot_autopilot/child.cc index 721436fcb7..7dbe6201be 100644 --- a/repos/gems/src/app/depot_autopilot/child.cc +++ b/repos/gems/src/app/depot_autopilot/child.cc @@ -1121,19 +1121,15 @@ Log_event::~Log_event() Log_prefix Log_event::_init_log_prefix(Xml_node const &xml) { - if (!xml.has_attribute("log_prefix")) + auto const log_prefix = xml.attribute_value("log_prefix", Log_prefix { }); + if (log_prefix.length() <= 1) return Log_prefix { }; - char buf[Log_prefix::size()]; - size_t buf_str_size { 0 }; - xml.attribute("log_prefix").with_raw_value([&] (char const *src_ptr, size_t src_size) { + char buf[Log_prefix::size()] { }; /* mutable buffer for filter operation */ + memcpy(buf, log_prefix.string(), log_prefix.length()); + size_t const filtered_len = pattern_filters.apply_to(buf, log_prefix.length()); - size_t const cpy_size = min(src_size, sizeof(buf) - 1); - memcpy(buf, src_ptr, cpy_size); - buf[cpy_size] = 0; - buf_str_size = pattern_filters.apply_to(buf, cpy_size + 1); - }); - return Cstring { buf, buf_str_size }; + return Log_prefix { Cstring { buf, filtered_len } }; } diff --git a/repos/gems/src/app/mixer_gui_qt/main_window.cpp b/repos/gems/src/app/mixer_gui_qt/main_window.cpp index aa6de5eb0f..7b99627d01 100644 --- a/repos/gems/src/app/mixer_gui_qt/main_window.cpp +++ b/repos/gems/src/app/mixer_gui_qt/main_window.cpp @@ -442,18 +442,16 @@ Main_window::Main_window(Genode::Env &env) using namespace Genode; - Attached_rom_dataspace config(env, "config"); - try { - Xml_node config_node = config.xml(); - _verbose = config_node.attribute("verbose").has_value("yes"); - } catch (...) { _verbose = false; } - - try { - Xml_node node = config.xml().sub_node("default"); - _default_out_volume = node.attribute_value("out_volume", 0); - _default_volume = node.attribute_value("volume", 0); - _default_muted = node.attribute_value("muted", 1); - } catch (...) { Genode::warning("no node found, fallback is 'muted=1'"); } + Attached_rom_dataspace const config(env, "config"); + _verbose = config.xml().attribute_value("verbose", false); + config.xml().with_sub_node("default", + [&] (Xml_node const &node) { + _default_out_volume = node.attribute_value("out_volume", 0L); + _default_volume = node.attribute_value("volume", 0L); + _default_muted = node.attribute_value("muted", 1L); + }, + [&] { warning("no node found, fallback is 'muted=1'"); } + ); } diff --git a/repos/gems/src/app/nano3d/main.cc b/repos/gems/src/app/nano3d/main.cc index 47a43969d0..d67e48cc77 100644 --- a/repos/gems/src/app/nano3d/main.cc +++ b/repos/gems/src/app/nano3d/main.cc @@ -86,17 +86,15 @@ class Scene : public Nano3d::Scene { _config.update(); - try { - _shape = SHAPE_DODECAHEDRON; - if (_config.xml().attribute("shape").has_value("cube")) - _shape = SHAPE_CUBE; - } catch (...) { } + using Value = Genode::String<32>; - try { - _painter = PAINTER_TEXTURED; - if (_config.xml().attribute("painter").has_value("shaded")) - _painter = PAINTER_SHADED; - } catch (...) { } + _shape = SHAPE_DODECAHEDRON; + if (_config.xml().attribute_value("shape", Value()) == "cube") + _shape = SHAPE_CUBE; + + _painter = PAINTER_TEXTURED; + if (_config.xml().attribute_value("painter", Value()) == "shaded") + _painter = PAINTER_SHADED; } Genode::Signal_handler _config_handler; diff --git a/repos/gems/src/app/sculpt_manager/model/wifi_connection.h b/repos/gems/src/app/sculpt_manager/model/wifi_connection.h index 505c4ffc34..85be215b2a 100644 --- a/repos/gems/src/app/sculpt_manager/model/wifi_connection.h +++ b/repos/gems/src/app/sculpt_manager/model/wifi_connection.h @@ -33,30 +33,32 @@ struct Sculpt::Wifi_connection /** * Create 'Wifi_connection' object from 'state' report */ - static Wifi_connection from_xml(Xml_node node) + static Wifi_connection from_xml(Xml_node const &node) { - bool const connected = - node.has_sub_node("accesspoint") && - node.sub_node("accesspoint").attribute("state").has_value("connected"); - bool const connecting = - node.has_sub_node("accesspoint") && - node.sub_node("accesspoint").attribute("state").has_value("connecting"); - bool const auth_failed = - node.has_sub_node("accesspoint") && - node.sub_node("accesspoint").attribute_value("auth_failure", false); + Wifi_connection result { }; - if (!connected && !connecting) - return { .state = DISCONNECTED, - .auth_failed = auth_failed, - .bssid = Access_point::Bssid{}, - .ssid = Access_point::Bssid{} }; + bool connected = false; + bool connecting = false; + bool auth_failed = false; - Xml_node const ap = node.sub_node("accesspoint"); + node.with_optional_sub_node("accesspoint", [&] (Xml_node const &ap) { + connected = (ap.attribute_value("state", String<32>()) == "connected"); + connecting = (ap.attribute_value("state", String<32>()) == "connecting"); + auth_failed = ap.attribute_value("auth_failed", false); - return { .state = connected ? CONNECTED : CONNECTING, - .auth_failed = false, - .bssid = ap.attribute_value("bssid", Access_point::Bssid()), - .ssid = ap.attribute_value("ssid", Access_point::Ssid()) }; + if (!connected && !connecting) + result = { .state = DISCONNECTED, + .auth_failed = auth_failed, + .bssid = Access_point::Bssid{}, + .ssid = Access_point::Bssid{} }; + + else + result = { .state = connected ? CONNECTED : CONNECTING, + .auth_failed = false, + .bssid = ap.attribute_value("bssid", Access_point::Bssid()), + .ssid = ap.attribute_value("ssid", Access_point::Ssid()) }; + }); + return result; } static Wifi_connection disconnected_wifi_connection() diff --git a/repos/gems/src/app/tresor_tester/main.cc b/repos/gems/src/app/tresor_tester/main.cc index d5cec58e0c..2d419cd2f7 100644 --- a/repos/gems/src/app/tresor_tester/main.cc +++ b/repos/gems/src/app/tresor_tester/main.cc @@ -216,15 +216,16 @@ struct Tresor_tester::Request_node : Noncopyable Operation read_op_attr(Xml_node const &node) { ASSERT(node.has_attribute("op")); - if (node.attribute("op").has_value("read")) return Operation::READ; - if (node.attribute("op").has_value("write")) return Operation::WRITE; - if (node.attribute("op").has_value("sync")) return Operation::SYNC; - if (node.attribute("op").has_value("create_snapshot")) return Operation::CREATE_SNAPSHOT; - if (node.attribute("op").has_value("discard_snapshot")) return Operation::DISCARD_SNAPSHOT; - if (node.attribute("op").has_value("extend_ft")) return Operation::EXTEND_FREE_TREE; - if (node.attribute("op").has_value("extend_vbd")) return Operation::EXTEND_VBD; - if (node.attribute("op").has_value("rekey")) return Operation::REKEY; - if (node.attribute("op").has_value("deinitialize")) return Operation::DEINITIALIZE; + auto const value = node.attribute_value("op", String<32>()); + if (value == "read") return Operation::READ; + if (value == "write") return Operation::WRITE; + if (value == "sync") return Operation::SYNC; + if (value == "create_snapshot") return Operation::CREATE_SNAPSHOT; + if (value == "discard_snapshot") return Operation::DISCARD_SNAPSHOT; + if (value == "extend_ft") return Operation::EXTEND_FREE_TREE; + if (value == "extend_vbd") return Operation::EXTEND_VBD; + if (value == "rekey") return Operation::REKEY; + if (value == "deinitialize") return Operation::DEINITIALIZE; ASSERT_NEVER_REACHED; } diff --git a/repos/gems/src/server/gui_fader/main.cc b/repos/gems/src/server/gui_fader/main.cc index 8ec72db4b3..b0386043b4 100644 --- a/repos/gems/src/server/gui_fader/main.cc +++ b/repos/gems/src/server/gui_fader/main.cc @@ -500,11 +500,9 @@ void Gui_fader::Main::handle_config_update() { config.update(); - Genode::Xml_node config_xml = config.xml(); + Genode::Xml_node const config_xml = config.xml(); - unsigned new_alpha = alpha; - if (config_xml.has_attribute("alpha")) - config_xml.attribute("alpha").value(new_alpha); + unsigned const new_alpha = config_xml.attribute_value("alpha", 255u); fade_in_steps = config_xml.attribute_value("fade_in_steps", 20U); fade_out_steps = config_xml.attribute_value("fade_out_steps", 50U); diff --git a/repos/gems/src/server/wm/gui.h b/repos/gems/src/server/wm/gui.h index a08f9a2d82..101265fd81 100644 --- a/repos/gems/src/server/wm/gui.h +++ b/repos/gems/src/server/wm/gui.h @@ -1191,18 +1191,11 @@ class Wm::Gui::Root : public Genode::Rpc_object Genode::Xml_node policy = Genode::Session_policy(session_label, _config.xml()); - char const *role_attr = "role"; - if (policy.has_attribute(role_attr)) { + auto const value = policy.attribute_value("role", String<16>()); - if (policy.attribute(role_attr).has_value("layouter")) - role = ROLE_LAYOUTER; - - if (policy.attribute(role_attr).has_value("decorator")) - role = ROLE_DECORATOR; - - if (policy.attribute(role_attr).has_value("direct")) - role = ROLE_DIRECT; - } + if (value == "layouter") role = ROLE_LAYOUTER; + if (value == "decorator") role = ROLE_DECORATOR; + if (value == "direct") role = ROLE_DIRECT; } catch (...) { } diff --git a/repos/gems/src/server/wm/main.cc b/repos/gems/src/server/wm/main.cc index 69836b7c01..82d0fdbd49 100644 --- a/repos/gems/src/server/wm/main.cc +++ b/repos/gems/src/server/wm/main.cc @@ -68,24 +68,21 @@ struct Wm::Main : Pointer::Tracker void handle_focus_update() { - try { - focus_rom.update(); - if (!focus_rom.valid()) - return; + focus_rom.update(); - unsigned win_id = 0; + focus_rom.xml().with_optional_sub_node("window", [&] (Xml_node const &window) { - Xml_node(focus_rom.local_addr()).sub_node("window") - .attribute("id").value(win_id); + unsigned const win_id = window.attribute_value("id", 0u); if (win_id) { - Gui::Session_capability session_cap = - gui_root.lookup_gui_session(win_id); + try { + Gui::Session_capability session_cap = + gui_root.lookup_gui_session(win_id); - focus_gui_session.focus(session_cap); + focus_gui_session.focus(session_cap); + } catch (...) { } } - - } catch (...) { } + }); } Genode::Signal_handler
focus_handler = { diff --git a/repos/libports/include/libc/args.h b/repos/libports/include/libc/args.h index d76ea51155..11b6de211c 100644 --- a/repos/libports/include/libc/args.h +++ b/repos/libports/include/libc/args.h @@ -26,6 +26,13 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char using Genode::Xml_node; using Genode::Xml_attribute; + auto with_raw_attr = [] (Xml_node const &node, auto const attr_name, auto const &fn) + { + node.for_each_attribute([&] (Xml_attribute const &attr) { + if (attr.has_type(attr_name)) + attr.with_raw_value(fn); }); + }; + env.config([&] (Xml_node const &node) { int envc = 0; @@ -62,9 +69,7 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char /* insert an argument */ if (node.has_type("arg")) { - - Xml_attribute attr = node.attribute("value"); - attr.with_raw_value([&] (char const *start, size_t length) { + with_raw_attr(node, "value", [&] (char const *start, size_t length) { size_t const size = length + 1; /* for null termination */ @@ -72,7 +77,6 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char Genode::copy_cstring(argv[arg_i], start, size); }); - ++arg_i; } else @@ -87,17 +91,15 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char check_attr(node, "key"); check_attr(node, "value"); - Xml_attribute const key = node.attribute("key"); - Xml_attribute const value = node.attribute("value"); - using namespace Genode; /* * An environment variable has the form =, followed * by a terminating zero. */ - size_t const var_size = key .value_size() + 1 - + value.value_size() + 1; + size_t var_size = 1 + 1; + with_raw_attr(node, "key", [&] (char const *, size_t l) { var_size += l; }); + with_raw_attr(node, "value", [&] (char const *, size_t l) { var_size += l; }); envp[env_i] = (char*)malloc(var_size); @@ -116,19 +118,18 @@ static void populate_args_and_env(Libc::Env &env, int &argc, char **&argv, char pos += len; }; - key.with_raw_value([&] (char const *start, size_t length) { + with_raw_attr(node, "key", [&] (char const *start, size_t length) { append(start, length); }); append("=", 1); - value.with_raw_value([&] (char const *start, size_t length) { + with_raw_attr(node, "value", [&] (char const *start, size_t length) { append(start, length); }); ++env_i; } catch (Xml_node::Nonexistent_sub_node) { } - catch (Xml_node::Nonexistent_attribute) { } }); /* argv and envp are both NULL terminated */ diff --git a/repos/libports/src/lib/gcov/libc/libc.cc b/repos/libports/src/lib/gcov/libc/libc.cc index 6be25bd825..99567f7340 100644 --- a/repos/libports/src/lib/gcov/libc/libc.cc +++ b/repos/libports/src/lib/gcov/libc/libc.cc @@ -290,10 +290,9 @@ extern "C" FILE *fopen(const char *path, const char *mode) seek_offset); }); - gcov_env->fs.close(annotate_file_handle); + gcov_env->fs.close(annotate_file_handle); } catch (Xml_node::Nonexistent_sub_node) { } - catch (Xml_attribute::Nonexistent_attribute) { } return &gcov_env->file; } diff --git a/repos/libports/src/test/libc_vfs/main.cc b/repos/libports/src/test/libc_vfs/main.cc index 7a3ecff8fb..2224c2f4ac 100644 --- a/repos/libports/src/test/libc_vfs/main.cc +++ b/repos/libports/src/test/libc_vfs/main.cc @@ -41,30 +41,21 @@ struct Test_failed : Genode::Exception { }; } -static void test_write_read(Genode::Xml_node node) +static void test_write_read(Genode::Xml_node const &config) { - size_t rounds = 4; + size_t rounds = 4u; size_t size = 4*1024*1024; size_t buffer_size = 32*1024; - try { - Genode::Xml_node config = node.sub_node("write-read"); + config.with_optional_sub_node("write-read", [&] (Genode::Xml_node const &node) { + using Num_bytes = Genode::Number_of_bytes; + rounds = node.attribute_value("rounds", rounds); + size = node.attribute_value("size", Num_bytes{size}); + buffer_size = node.attribute_value("buffer_size", Num_bytes{buffer_size}); + }); - rounds = config.attribute_value("rounds", rounds); - - Genode::Number_of_bytes n { }; - try { - config.attribute("size").value(n); - size = n; - } catch (...) { } - try { - config.attribute("buffer_size").value(n); - buffer_size = n; - } catch (...) { } - } catch (...) { } - - void *buf = malloc(buffer_size); - char const *file_name = "write_read.tst"; + void * const buf = malloc(buffer_size); + char const * const file_name = "write_read.tst"; printf("write-read test: %zu rounds of %zu MiB (buffer size %zu)\n", rounds, size/(1024*1024), buffer_size); @@ -112,9 +103,8 @@ static void test(Genode::Xml_node node) unsigned int iterations = 1; - try { - node.sub_node("iterations").attribute("value").value(iterations); - } catch(...) { } + node.with_optional_sub_node("iterations", [&] (Genode::Xml_node const &iter) { + iterations = iter.attribute_value("value", iterations); }); for (unsigned int i = 0; i < iterations; i++) { diff --git a/repos/libports/src/test/lwip/udp/server/main.cc b/repos/libports/src/test/lwip/udp/server/main.cc index 87e5e16d91..f5e5e77952 100644 --- a/repos/libports/src/test/lwip/udp/server/main.cc +++ b/repos/libports/src/test/lwip/udp/server/main.cc @@ -30,8 +30,6 @@ struct Send_failed : Genode::Exception { }; struct Receive_failed : Genode::Exception { }; struct Bind_failed : Genode::Exception { }; -struct Read_port_attr_failed : Genode::Exception { }; - static void test(Libc::Env & env) { @@ -42,12 +40,9 @@ static void test(Libc::Env & env) } /* read server port */ unsigned port = 0; - env.config([&] (Xml_node config_node) { - try { config_node.attribute("port").value(port); } - catch (...) { - throw Read_port_attr_failed(); - } - }); + env.config([&] (Xml_node const &config_node) { + port = config_node.attribute_value("port", 0u); }); + /* create server socket address */ struct sockaddr_in in_addr; in_addr.sin_family = AF_INET; diff --git a/repos/os/include/vfs/dir_file_system.h b/repos/os/include/vfs/dir_file_system.h index f0df74a4ae..b36078fde5 100644 --- a/repos/os/include/vfs/dir_file_system.h +++ b/repos/os/include/vfs/dir_file_system.h @@ -394,18 +394,7 @@ class Vfs::Dir_file_system : public File_system continue; } - Genode::error("failed to create <", sub_node.type(), "> VFS node"); - try { - for (unsigned i = 0; i < 16; ++i) { - - Xml_attribute const attr = sub_node.attribute(i); - - String<64> value { }; - attr.value(value); - - Genode::error("\t", attr.name(), "=\"", value, "\""); - } - } catch (Xml_node::Nonexistent_attribute) { } + Genode::error("failed to create VFS node: ", sub_node); } } diff --git a/repos/os/src/app/sequence/main.cc b/repos/os/src/app/sequence/main.cc index 148ec96ba6..cdb1fbfe7a 100644 --- a/repos/os/src/app/sequence/main.cc +++ b/repos/os/src/app/sequence/main.cc @@ -40,12 +40,10 @@ struct Sequence::Child : Genode::Child_policy Binary_name _start_binary() { - Binary_name name; - try { - _start_node.sub_node("binary").attribute("name").value(name); - return name != "" ? name : _name; - } - catch (...) { return _name; } + Binary_name name = _name; + _start_node.with_optional_sub_node("binary", [&] (Xml_node const &binary) { + name = binary.attribute_value("name", _name); }); + return name; } Binary_name const _binary_name = _start_binary(); diff --git a/repos/os/src/server/dynamic_rom/main.cc b/repos/os/src/server/dynamic_rom/main.cc index 008b0af5b2..8f532caf2f 100644 --- a/repos/os/src/server/dynamic_rom/main.cc +++ b/repos/os/src/server/dynamic_rom/main.cc @@ -205,9 +205,9 @@ class Dynamic_rom::Root : public Genode::Root_component { /* lookup ROM module in config */ for (unsigned i = 0; i < _config_node.num_sub_nodes(); i++) { - Xml_node node = _config_node.sub_node(i); - if (node.has_attribute("name") - && node.attribute("name").has_value(name.string())) + Xml_node const node = _config_node.sub_node(i); + + if (node.attribute_value("name", Genode::String<64>()) == name) return node; } throw Nonexistent_rom_module(); diff --git a/repos/os/src/server/nic_router/xml_node.h b/repos/os/src/server/nic_router/xml_node.h index 63fea7e3b1..cfc4ae793e 100644 --- a/repos/os/src/server/nic_router/xml_node.h +++ b/repos/os/src/server/nic_router/xml_node.h @@ -25,14 +25,13 @@ namespace Genode { char const *name, uint64_t const default_sec); - template - void xml_node_with_attribute(Xml_node const node, + void xml_node_with_attribute(Xml_node const &node, char const *name, - FUNC && func) + auto const &fn) { - if (node.has_attribute(name)) { - func(node.attribute(name)); - } + node.for_each_attribute([&] (Xml_attribute const &attr) { + if (attr.has_type(name)) + fn(attr); }); } } diff --git a/repos/os/src/server/nitpicker/global_keys.cc b/repos/os/src/server/nitpicker/global_keys.cc index e318cfec5b..9f9fc560c9 100644 --- a/repos/os/src/server/nitpicker/global_keys.cc +++ b/repos/os/src/server/nitpicker/global_keys.cc @@ -63,7 +63,7 @@ void Global_keys::apply_config(Xml_node config, Session_list &session_list) /* assign policy to matching client session */ for (Gui_session *s = session_list.first(); s; s = s->next()) - if (node.attribute("label").has_value(s->label().string())) + if (node.attribute_value("label", String<128>()) == s->label().string()) policy->client(s); } diff --git a/repos/os/src/server/part_block/main.cc b/repos/os/src/server/part_block/main.cc index 0bdb0085e3..d8ae04ebe1 100644 --- a/repos/os/src/server/part_block/main.cc +++ b/repos/os/src/server/part_block/main.cc @@ -327,16 +327,17 @@ class Block::Main : Rpc_object>, /* sessions are not writeable by default */ writeable = policy.attribute_value("writeable", false); - } catch (Xml_node::Nonexistent_attribute) { - error("policy does not define partition number for for '", - label, "'"); - throw Service_denied(); } catch (Session_policy::No_policy_defined) { error("rejecting session request, no matching policy for '", label, "'"); throw Service_denied(); } + if (num == -1) { + error("policy does not define partition number for for '", label, "'"); + throw Service_denied(); + } + if (!_partition_table.partition_valid(num)) { error("Partition ", num, " unavailable for '", label, "'"); throw Service_denied(); diff --git a/repos/os/src/test/trace/main.cc b/repos/os/src/test/trace/main.cc index d7d036765f..2878a4cb33 100644 --- a/repos/os/src/test/trace/main.cc +++ b/repos/os/src/test/trace/main.cc @@ -195,7 +195,8 @@ struct Test_tracing Constructible test_monitor { }; - typedef Genode::String<64> String; + using String = Genode::String<64>; + String policy_label { }; String policy_module { }; String policy_thread { }; @@ -210,12 +211,13 @@ struct Test_tracing log("test Tracing"); - try { - Xml_node policy = config.xml().sub_node("trace_policy"); - policy.attribute("label").value(policy_label); - policy.attribute("module").value(policy_module); - policy.attribute("thread").value(policy_thread); + config.xml().with_optional_sub_node("trace_policy", [&] (Xml_node const &policy) { + policy_label = policy.attribute_value("label", String()); + policy_module = policy.attribute_value("module", String()); + policy_thread = policy.attribute_value("thread", String()); + }); + try { Rom_connection policy_rom(env, policy_module.string()); policy_module_rom_ds = policy_rom.dataspace();