summaryrefslogtreecommitdiff
path: root/hscript
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-19 17:23:00 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-19 17:23:00 -0500
commit55325a6e780b121f93d35076e4226521ca13ef12 (patch)
treeb3cf5fa6131fa966e7427b8837311c8dcdc9ceaa /hscript
parentd3489c52d4ad1e5b17ce88e8b0e5142b30bb324e (diff)
downloadhorizon-55325a6e780b121f93d35076e4226521ca13ef12.tar.gz
horizon-55325a6e780b121f93d35076e4226521ca13ef12.tar.bz2
horizon-55325a6e780b121f93d35076e4226521ca13ef12.tar.xz
horizon-55325a6e780b121f93d35076e4226521ca13ef12.zip
hscript: Implement UserIcon parsing
Diffstat (limited to 'hscript')
-rw-r--r--hscript/user.cc24
1 files changed, 22 insertions, 2 deletions
diff --git a/hscript/user.cc b/hscript/user.cc
index 6081f55..04258e4 100644
--- a/hscript/user.cc
+++ b/hscript/user.cc
@@ -17,6 +17,7 @@
#include <sstream>
#include <time.h>
#include "user.hh"
+#include "util/net.hh"
#include "util/output.hh"
using namespace Horizon::Keys;
@@ -264,11 +265,30 @@ bool UserPassphrase::execute(ScriptOptions) const {
Key *UserIcon::parseFromData(const std::string &data, int lineno, int *errors,
int *warnings) {
- return nullptr;
+ /* REQ: Runner.Validate.usericon.Validity */
+ const std::string::size_type sep = data.find_first_of(' ');
+ if(sep == std::string::npos || data.length() == sep + 1) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "usericon: icon is required",
+ "expected format is: usericon [username] [path|url]");
+ return nullptr;
+ }
+
+ std::string icon_path = data.substr(sep + 1);
+ if(icon_path[0] != '/' && !is_valid_url(icon_path)) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "usericon: path must be absolute path or valid URL");
+ return nullptr;
+ }
+
+ return new UserIcon(lineno, data.substr(0, sep), icon_path);
}
bool UserIcon::validate(ScriptOptions) const {
- return false;
+ /* TODO XXX: ensure URL is accessible */
+ return true;
}
bool UserIcon::execute(ScriptOptions) const {