From d8fd2ada1711c08481036834e5132845926e9639 Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Thu, 2 Feb 2023 21:36:58 +1100
Subject: [PATCH] use existing name checker

---
 src/lib66/exec/ssexec_disable.c | 14 ++------------
 src/lib66/exec/ssexec_enable.c  | 14 ++------------
 2 files changed, 4 insertions(+), 24 deletions(-)

diff --git a/src/lib66/exec/ssexec_disable.c b/src/lib66/exec/ssexec_disable.c
index 0a8ec0b2..3a5549ad 100644
--- a/src/lib66/exec/ssexec_disable.c
+++ b/src/lib66/exec/ssexec_disable.c
@@ -29,17 +29,7 @@
 #include <66/service.h>
 #include <66/graph.h>
 #include <66/resolve.h>
-
-static void check_identifier(char const *name)
-{
-    log_flow() ;
-
-    int logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ;
-    if (logname > 0) log_die(LOG_EXIT_USER,"service: ",name,": ends with reserved suffix -log") ;
-    if (!memcmp(name,SS_MASTER+1,6)) log_die(LOG_EXIT_USER,"service: ",name,": starts with reserved prefix Master") ;
-    if (!strcmp(name,SS_SERVICE)) log_die(LOG_EXIT_USER,"service as service name is a reserved name") ;
-    if (!strcmp(name,"service@")) log_die(LOG_EXIT_USER,"service@ as service name is a reserved name") ;
-}
+#include <66/utils.h>
 
 int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
 {
@@ -104,7 +94,7 @@ int ssexec_disable(int argc, char const *const *argv, ssexec_t *info)
         log_die(LOG_EXIT_USER, "services selection is not available -- try to parse it first") ;
 
     for (; n < argc ; n++) {
-        check_identifier(argv[n]) ;
+        name_isvalid(argv[n]) ;
         service_enable_disable(&graph, info->base.s, argv[n], 0) ;
 
         if (!sastr_add_string(&sa, argv[n]))
diff --git a/src/lib66/exec/ssexec_enable.c b/src/lib66/exec/ssexec_enable.c
index a8a03d1e..72fb3f95 100644
--- a/src/lib66/exec/ssexec_enable.c
+++ b/src/lib66/exec/ssexec_enable.c
@@ -30,17 +30,7 @@
 #include <66/config.h>
 #include <66/state.h>
 #include <66/resolve.h>
-
-static void check_identifier(char const *name)
-{
-    log_flow() ;
-
-    int logname = get_rstrlen_until(name,SS_LOG_SUFFIX) ;
-    if (logname > 0) log_die(LOG_EXIT_USER,"service: ",name,": ends with reserved suffix -log") ;
-    if (!memcmp(name,SS_MASTER+1,6)) log_die(LOG_EXIT_USER,"service: ",name,": starts with reserved prefix Master") ;
-    if (!strcmp(name,SS_SERVICE)) log_die(LOG_EXIT_USER,"service as service name is a reserved name") ;
-    if (!strcmp(name,"service@")) log_die(LOG_EXIT_USER,"service@ as service name is a reserved name") ;
-}
+#include <66/utils.h>
 
 static void parse_it(char const *name, uint8_t force, uint8_t conf, ssexec_t *info)
 {
@@ -131,7 +121,7 @@ int ssexec_enable(int argc, char const *const *argv, ssexec_t *info)
         log_usage(info->usage, "\n", info->help) ;
 
     for(; n < argc ; n++) {
-        check_identifier(argv[n]) ;
+        name_isvalid(argv[n]) ;
         parse_it(argv[n], force, conf, info) ;
     }
 
-- 
GitLab