From 55325a6e780b121f93d35076e4226521ca13ef12 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sat, 19 Oct 2019 17:23:00 -0500 Subject: hscript: Implement UserIcon parsing --- hscript/user.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'hscript') 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 #include #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 { -- cgit v1.2.3-60-g2f50