summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-13 09:29:53 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-13 09:29:53 -0500
commit9980c1ec905a455a028cbeb1c15fc7eda09cb78d (patch)
tree07129df7cdc9fa4b149f24a309ee750710cb936c
parent7051861708be5f2613ab92ec03bd80399a817a0c (diff)
downloadhorizon-9980c1ec905a455a028cbeb1c15fc7eda09cb78d.tar.gz
horizon-9980c1ec905a455a028cbeb1c15fc7eda09cb78d.tar.bz2
horizon-9980c1ec905a455a028cbeb1c15fc7eda09cb78d.tar.xz
horizon-9980c1ec905a455a028cbeb1c15fc7eda09cb78d.zip
hscript: Initial twiddling at NetSSID impl, add net execution
-rw-r--r--hscript/network.cc18
-rw-r--r--hscript/network.hh37
-rw-r--r--hscript/script.cc43
3 files changed, 92 insertions, 6 deletions
diff --git a/hscript/network.cc b/hscript/network.cc
index 3dc5f1e..809891f 100644
--- a/hscript/network.cc
+++ b/hscript/network.cc
@@ -220,3 +220,21 @@ bool NetAddress::validate(ScriptOptions) const {
bool NetAddress::execute(ScriptOptions) const {
return false;
}
+
+Key *NetSSID::parseFromData(const std::string &data, int lineno, int *errors,
+ int *warnings) {
+ std::string iface, ssid, passphrase;
+ return new NetSSID(lineno, iface, ssid, SecurityType::None, passphrase);
+}
+
+bool NetSSID::validate(ScriptOptions options) const {
+ /* Runner.Validate.network.netssid.Interface */
+ if(options.test(InstallEnvironment)) {
+ return false;
+ }
+ return true;
+}
+
+bool NetSSID::execute(ScriptOptions) const {
+ return false;
+}
diff --git a/hscript/network.hh b/hscript/network.hh
index 179346e..411f4b3 100644
--- a/hscript/network.hh
+++ b/hscript/network.hh
@@ -57,11 +57,11 @@ public:
/*! Retrieve the interface to which this 'netaddress' key is associated. */
const std::string iface() const { return this->_iface; }
/*! Retrieve the address type of this 'netadress' key. */
- const AddressType type() const { return this->_type; }
+ AddressType type() const { return this->_type; }
/*! Retrieve the static address, if any. */
const std::string address() const { return this->_address; }
/*! Retreive the prefix length for the static address. */
- const uint8_t prefix() const { return this->_prefix; }
+ uint8_t prefix() const { return this->_prefix; }
/*! Retrieve the gateway, if any. */
const std::string gateway() const { return this->_gw; }
@@ -73,6 +73,39 @@ class Nameserver : public Key {
};
class NetSSID : public Key {
+public:
+ /*! The type of security used by the SSID. */
+ enum SecurityType {
+ None,
+ WEP,
+ WPA
+ };
+private:
+ const std::string _iface;
+ const std::string _ssid;
+ const SecurityType _sec;
+ const std::string _pw;
+
+ NetSSID(int _line, const std::string &_if, const std::string &_s,
+ SecurityType _t, const std::string &_p) : Key(_line), _iface(_if),
+ _ssid(_s), _sec(_t), _pw(_p) {}
+public:
+ static Key *parseFromData(const std::string &data, int lineno, int *errors,
+ int *warnings);
+
+ /*! Retrieve the interface to which this 'netssid' key is associated. */
+ const std::string iface() const { return this->_iface; }
+ /*! Retrieve the named SSID for this 'netssid' key. */
+ const std::string ssid() const { return this->_ssid; }
+ /*! Retrieve the security type of this 'netssid' key. */
+ SecurityType type() const { return this->_sec; }
+ /*! Retrieve the passphrase for this 'netssid' key.
+ * @note Only valid if type() is not None.
+ */
+ const std::string passphrase() const { return this->_pw; }
+
+ bool validate(ScriptOptions) const override;
+ bool execute(ScriptOptions) const override;
};
}
diff --git a/hscript/script.cc b/hscript/script.cc
index 8afa6aa..444b6c0 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -81,6 +81,7 @@ struct Script::ScriptPrivate {
/*! Network addressing configuration */
std::vector< std::unique_ptr<Horizon::Keys::NetAddress> > addresses;
+ std::vector< std::unique_ptr<Horizon::Keys::NetSSID> > ssids;
/*! APK repositories */
std::vector< std::unique_ptr<Horizon::Keys::Repository> > repos;
@@ -161,6 +162,12 @@ struct Script::ScriptPrivate {
);
this->addresses.push_back(std::move(addr));
return true;
+ } else if(key_name == "netssid") {
+ std::unique_ptr<Keys::NetSSID> ssid(
+ dynamic_cast<Keys::NetSSID *>(key_obj)
+ );
+ this->ssids.push_back(std::move(ssid));
+ return true;
} else if(key_name == "repository") {
std::unique_ptr<Keys::Repository> repo(
dynamic_cast<Keys::Repository *>(key_obj)
@@ -383,6 +390,13 @@ bool Script::validate() const {
}
}
+ /* Runner.Validate.network.netssid */
+ for(auto &ssid : this->internal->ssids) {
+ if(!ssid->validate(this->opts)) {
+ failures++;
+ }
+ }
+
if(this->internal->repos.size() == 0) {
Keys::Repository *sys_key = dynamic_cast<Keys::Repository *>(
Horizon::Keys::Repository::parseFromData(
@@ -470,16 +484,37 @@ bool Script::execute() const {
EXECUTE_FAILURE("pre-metadata");
return false;
}
- output_step_end("pre-metadata");
- /**************** PKGDB ****************/
- output_step_start("pkgdb");
for(auto &repo : this->internal->repos) {
if(!repo->execute(opts)) {
- EXECUTE_FAILURE("pkgdb");
+ EXECUTE_FAILURE("pre-metadata");
return false;
}
}
+ output_step_end("pre-metadata");
+
+ /**************** NETWORK ****************/
+ output_step_start("net");
+ for(auto &ssid : this->internal->ssids) {
+ if(!ssid->execute(opts)) {
+ EXECUTE_FAILURE("net");
+ /* "Soft" error. Not fatal. */
+ }
+ }
+ for(auto &addr : this->internal->addresses) {
+ if(!addr->execute(opts)) {
+ EXECUTE_FAILURE("net");
+ /* "Soft" error. Not fatal. */
+ }
+ }
+ if(!this->internal->network->execute(opts)) {
+ EXECUTE_FAILURE("net");
+ return false;
+ }
+ output_step_end("net");
+
+ /**************** PKGDB ****************/
+ output_step_start("pkgdb");
/* Runner.Execute.pkginstall.APKDB */
output_info("internal", "initialising APK");