Avoid use of deprecated Xml_node methods

Issue #3755
This commit is contained in:
Norman Feske
2020-05-06 19:06:25 +02:00
parent d22b95ded3
commit be65c4acd2
16 changed files with 196 additions and 212 deletions

View File

@ -276,16 +276,14 @@ struct Audio_out::Main
Main(Genode::Env &env) : env(env)
{
char dev[32] = { 'h', 'w', 0 };
try {
config.xml().attribute("alsa_device").value(dev, sizeof(dev));
} catch (...) { }
typedef Genode::String<32> Dev;
Dev const dev = config.xml().attribute_value("alsa_device", Dev("hw"));
/* init ALSA */
int err = audio_drv_init(dev);
int err = audio_drv_init(dev.string());
if (err) {
if (err == -1) {
Genode::error("could not open ALSA device ", Genode::Cstring(dev));
Genode::error("could not open ALSA device ", dev);
} else {
Genode::error("could not initialize driver error ", err);
}

View File

@ -59,49 +59,40 @@ struct Main
using namespace Genode;
log("--- Raspberry Pi GPIO driver ---");
Xml_node const config = config_rom.xml();
/*
* Check configuration for async events detect
*/
unsigned int async = 0;
try {
config_rom.xml().attribute("async_events").value(&async);
} catch (...) { }
unsigned int async = config.attribute_value("async_events", 0U);
driver.set_async_events(async>0);
/*
* Check for common GPIO configuration
*/
Gpio::process_config(config_rom.xml(), driver);
Gpio::process_config(config, driver);
/*
* Check configuration for specific function
*/
try {
Xml_node gpio_node = config_rom.xml().sub_node("gpio");
if (!config.has_sub_node("gpio"))
warning("no GPIO config");
for (;; gpio_node = gpio_node.next("gpio")) {
unsigned num = 0;
unsigned function = 0;
config_rom.xml().for_each_sub_node("gpio", [&] (Xml_node const &gpio_node) {
try {
gpio_node.attribute("num").value(&num);
gpio_node.attribute("function").value(&function);
unsigned const num = gpio_node.attribute_value("num", 0U);
unsigned const function = gpio_node.attribute_value("function", 0U);
switch(function){
case 0: driver.set_func(num, Gpio::Reg::FSEL_ALT0); break;
case 1: driver.set_func(num, Gpio::Reg::FSEL_ALT1); break;
case 2: driver.set_func(num, Gpio::Reg::FSEL_ALT2); break;
case 3: driver.set_func(num, Gpio::Reg::FSEL_ALT3); break;
case 4: driver.set_func(num, Gpio::Reg::FSEL_ALT4); break;
case 5: driver.set_func(num, Gpio::Reg::FSEL_ALT5); break;
default: warning("wrong pin function, ignore node");
}
} catch(Xml_node::Nonexistent_attribute) {
warning("missing attribute, ignore node");
}
if (gpio_node.last("gpio")) break;
switch(function){
case 0: driver.set_func(num, Gpio::Reg::FSEL_ALT0); break;
case 1: driver.set_func(num, Gpio::Reg::FSEL_ALT1); break;
case 2: driver.set_func(num, Gpio::Reg::FSEL_ALT2); break;
case 3: driver.set_func(num, Gpio::Reg::FSEL_ALT3); break;
case 4: driver.set_func(num, Gpio::Reg::FSEL_ALT4); break;
case 5: driver.set_func(num, Gpio::Reg::FSEL_ALT5); break;
default: warning("wrong pin function, ignore node");
}
} catch (Xml_node::Nonexistent_sub_node) { warning("no GPIO config"); }
});
/*
* Announce service

View File

@ -113,7 +113,11 @@ class Linux_session_component : public Nic::Session_component
/* get tap device from config */
try {
Genode::Xml_node nic_node = _config_rom.xml().sub_node("nic");
nic_node.attribute("tap").value(ifr.ifr_name, sizeof(ifr.ifr_name));
nic_node.attribute("tap").with_raw_value([&] (char const *ptr, size_t len) {
len = Genode::min(len, sizeof(ifr.ifr_name) - 1);
Genode::memcpy(ifr.ifr_name, ptr, len);
ifr.ifr_name[len] = 0;
});
Genode::log("using tap device \"", Genode::Cstring(ifr.ifr_name), "\"");
} catch (...) {
/* use tap0 if no config has been provided */
@ -212,20 +216,20 @@ class Linux_session_component : public Nic::Session_component
_config_rom(env, "config"),
_tap_fd(_setup_tap_fd()), _rx_thread(env, _tap_fd, _packet_stream_dispatcher)
{
/* fall back to fake MAC address (unicast, locally managed) */
_mac_addr.addr[0] = 0x02;
_mac_addr.addr[1] = 0x00;
_mac_addr.addr[2] = 0x00;
_mac_addr.addr[3] = 0x00;
_mac_addr.addr[4] = 0x00;
_mac_addr.addr[5] = 0x01;
/* try using configured MAC address */
try {
Genode::Xml_node nic_config = _config_rom.xml().sub_node("nic");
nic_config.attribute("mac").value(&_mac_addr);
_mac_addr = nic_config.attribute_value("mac", _mac_addr);
Genode::log("Using configured MAC address ", _mac_addr);
} catch (...) {
/* fall back to fake MAC address (unicast, locally managed) */
_mac_addr.addr[0] = 0x02;
_mac_addr.addr[1] = 0x00;
_mac_addr.addr[2] = 0x00;
_mac_addr.addr[3] = 0x00;
_mac_addr.addr[4] = 0x00;
_mac_addr.addr[5] = 0x01;
}
} catch (...) { }
_rx_thread.start();
}

View File

@ -55,21 +55,20 @@ class Server::Gem_session_component : public Cadence_gem
{
Nic::Mac_address mac_addr;
/* fall back to fake MAC address (unicast, locally managed) */
mac_addr.addr[0] = 0x02;
mac_addr.addr[1] = 0x00;
mac_addr.addr[2] = 0x00;
mac_addr.addr[3] = 0x00;
mac_addr.addr[4] = 0x00;
mac_addr.addr[5] = 0x01;
/* try using configured MAC address */
try {
Genode::Xml_node nic_config = _config_rom.xml().sub_node("nic");
nic_config.attribute("mac").value(&mac_addr);
} catch (...) {
/* fall back to fake MAC address (unicast, locally managed) */
mac_addr.addr[0] = 0x02;
mac_addr.addr[1] = 0x00;
mac_addr.addr[2] = 0x00;
mac_addr.addr[3] = 0x00;
mac_addr.addr[4] = 0x00;
mac_addr.addr[5] = 0x01;
}
Genode::log("Using MAC address ", mac_addr);
mac_addr = nic_config.attribute_value("mac", mac_addr);
Genode::log("Using configured MAC address ", mac_addr);
} catch (...) { }
/* set mac address */
mac_address(mac_addr);

View File

@ -413,53 +413,43 @@ class Lx_fs::Root : public Root_component<Session_component>
char const *root_dir = ".";
bool writeable = false;
enum { ROOT_MAX_LEN = 256 };
char root[ROOT_MAX_LEN];
root[0] = 0;
Session_label const label = label_from_args(args);
Session_policy const policy(label, _config.xml());
Session_label const label = label_from_args(args);
try {
Session_policy policy(label, _config.xml());
/*
* Determine directory that is used as root directory of
* the session.
*/
try {
policy.attribute("root").value(root, sizeof(root));
/*
* Make sure the root path is specified with a
* leading path delimiter. For performing the
* lookup, we remove all leading slashes.
*/
if (root[0] != '/') {
Genode::error("Root directory must start with / but is \"",
Genode::Cstring(root), "\"");
throw Service_denied();
}
for (root_dir = root; *root_dir == '/'; ++root_dir) ;
/* sanitize possibly empty root_dir to current directory */
if (*root_dir == 0)
root_dir = ".";
} catch (Xml_node::Nonexistent_attribute) {
Genode::error("missing \"root\" attribute in policy definition");
throw Service_denied();
}
/*
* Determine if write access is permitted for the session.
*/
writeable = policy.attribute_value("writeable", false) &&
writeable_from_args(args);
if (!policy.has_attribute("root")) {
Genode::error("missing \"root\" attribute in policy definition");
throw Service_denied();
}
catch (Session_policy::No_policy_defined) {
Genode::error("invalid session request, no matching policy");
throw Genode::Service_denied();
/*
* Determine directory that is used as root directory of
* the session.
*/
typedef String<256> Root;
Root const root = policy.attribute_value("root", Root());
/*
* Make sure the root path is specified with a
* leading path delimiter. For performing the
* lookup, we remove all leading slashes.
*/
if (root.string()[0] != '/') {
Genode::error("Root directory must start with / but is \"", root, "\"");
throw Service_denied();
}
for (root_dir = root.string(); *root_dir == '/'; ++root_dir) ;
/* sanitize possibly empty root_dir to current directory */
if (*root_dir == 0)
root_dir = ".";
/*
* Determine if write access is permitted for the session.
*/
writeable = policy.attribute_value("writeable", false) &&
writeable_from_args(args);
size_t ram_quota =
Arg_string::find_arg(args, "ram_quota" ).ulong_value(0);
size_t tx_buf_size =
@ -486,7 +476,7 @@ class Lx_fs::Root : public Root_component<Session_component>
Session_component(tx_buf_size, _env, root_dir, writeable, *md_alloc());
}
catch (Lookup_failed) {
Genode::error("session root directory \"", Genode::Cstring(root), "\" "
Genode::error("session root directory \"", root, "\" "
"does not exist");
throw Service_denied();
}

View File

@ -68,10 +68,8 @@ struct Main
Genode::Attached_rom_dataspace config { env, "config" };
verbose = config.xml().attribute_value("verbose", false);
config.xml().attribute("expect").value(line, sizeof(line));
expect = Line(line);
config.xml().attribute("send").value(line, sizeof(line));
send = Line(line);
expect = config.xml().attribute_value("expect", Line());
send = config.xml().attribute_value("send", Line());
} catch (...) { warning("No config data available"); }
}
};