summaryrefslogtreecommitdiff
path: root/hscript/meta.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-08 19:55:53 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-08 19:55:53 -0500
commit5b0d0916b27f271fc12a8c0c6b595e11673d306d (patch)
treed8d2f3413caac49c1410c539b43be4630924666b /hscript/meta.cc
parent57307442c5d707591dfc4d5e7671364fa564fa5c (diff)
downloadhorizon-5b0d0916b27f271fc12a8c0c6b595e11673d306d.tar.gz
horizon-5b0d0916b27f271fc12a8c0c6b595e11673d306d.tar.bz2
horizon-5b0d0916b27f271fc12a8c0c6b595e11673d306d.tar.xz
horizon-5b0d0916b27f271fc12a8c0c6b595e11673d306d.zip
hscript: Implement 'hostname' parsing; add rest of existing manual tests
Diffstat (limited to 'hscript/meta.cc')
-rw-r--r--hscript/meta.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/hscript/meta.cc b/hscript/meta.cc
new file mode 100644
index 0000000..83c6269
--- /dev/null
+++ b/hscript/meta.cc
@@ -0,0 +1,41 @@
+/*
+ * metadata.cc - Implementation of the Key classes for system metadata
+ * libhscript, the HorizonScript library for
+ * Project Horizon
+ *
+ * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved.
+ * This code is licensed under the AGPL 3.0 license, as noted in the
+ * LICENSE-code file in the root directory of this repository.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+#include <regex>
+#include "meta.hh"
+#include "util/output.hh"
+
+using namespace Horizon::Keys;
+
+Key *Hostname::parseFromData(const std::string data, int lineno, int *errors,
+ int *warnings) {
+ std::regex valid_re("[A-Za-z0-9.]*");
+ bool valid = std::regex_match(data, valid_re);
+ if(!valid) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "hostname: expected machine or DNS name",
+ "'" + data + "' is not a valid hostname");
+ return nullptr;
+ }
+ return new Hostname(lineno, data);
+}
+
+bool Hostname::validate() const {
+ /* Validate that the name is a valid machine or DNS name */
+ return false;
+}
+
+bool Hostname::execute() const {
+ /* Write the hostname to /etc/hostname in the target environment. */
+ return false;
+}