From fa9d831f9f722f28567c4997551cd6bd1d7077d3 Mon Sep 17 00:00:00 2001 From: David Steele Date: Sat, 31 Dec 2022 11:09:50 +0700 Subject: [PATCH] Move xmlNodeAttribute() to build/common/xml module. Similar to b9be4fa5, this function was not used by the core code so move it to the build module. --- src/Makefile.in | 3 ++- src/build/common/string.c | 5 +---- src/build/common/xml.c | 29 +++++++++++++++++++++++++++++ src/build/common/xml.h | 15 +++++++++++++++ src/build/help/parse.c | 1 - src/build/help/parse.h | 2 +- src/common/type/xml.c | 24 ------------------------ src/common/type/xml.h | 3 --- src/meson.build | 2 +- test/define.yaml | 3 ++- 10 files changed, 51 insertions(+), 36 deletions(-) create mode 100644 src/build/common/xml.c create mode 100644 src/build/common/xml.h diff --git a/src/Makefile.in b/src/Makefile.in index 36724aca0..ecbd30248 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -37,7 +37,6 @@ SRCS_COMMON = \ common/type/stringList.c \ common/type/variant.c \ common/type/variantList.c \ - common/type/xml.c \ common/user.c \ common/wait.c \ config/common.c \ @@ -138,6 +137,7 @@ SRCS = \ common/stat.c \ common/type/json.c \ common/type/string.c \ + common/type/xml.c \ config/config.c \ config/exec.c \ config/load.c \ @@ -213,6 +213,7 @@ pgbackrest: $(OBJS_PGBACKREST) SRCS_BUILD_CODE = \ build/common/render.c \ build/common/string.c \ + build/common/xml.c \ build/common/yaml.c \ build/config/parse.c \ build/config/render.c \ diff --git a/src/build/common/string.c b/src/build/common/string.c index 8a2f04e02..25a67d342 100644 --- a/src/build/common/string.c +++ b/src/build/common/string.c @@ -1,10 +1,7 @@ /*********************************************************************************************************************************** String Handler Extensions ***********************************************************************************************************************************/ -#include "build.auto.h" - -#include "common/debug.h" - +// Include core module #include "common/type/string.c" /**********************************************************************************************************************************/ diff --git a/src/build/common/xml.c b/src/build/common/xml.c new file mode 100644 index 000000000..b5ad1198e --- /dev/null +++ b/src/build/common/xml.c @@ -0,0 +1,29 @@ +/*********************************************************************************************************************************** +XML Handler Extensions +***********************************************************************************************************************************/ +// Include core module +#include "common/type/xml.c" + +/**********************************************************************************************************************************/ +String * +xmlNodeAttribute(const XmlNode *this, const String *name) +{ + FUNCTION_TEST_BEGIN(); + FUNCTION_TEST_PARAM(XML_NODE, this); + FUNCTION_TEST_PARAM(STRING, name); + FUNCTION_TEST_END(); + + ASSERT(this != NULL); + ASSERT(name != NULL); + + String *result = NULL; + xmlChar *const value = xmlGetProp(this->node, (unsigned char *)strZ(name)); + + if (value != NULL) + { + result = strNewZ((const char *)value); + xmlFree(value); + } + + FUNCTION_TEST_RETURN(STRING, result); +} diff --git a/src/build/common/xml.h b/src/build/common/xml.h new file mode 100644 index 000000000..6da781333 --- /dev/null +++ b/src/build/common/xml.h @@ -0,0 +1,15 @@ +/*********************************************************************************************************************************** +XML Handler Extensions +***********************************************************************************************************************************/ +#ifndef BUILD_COMMON_XML_H +#define BUILD_COMMON_XML_H + +#include "common/type/xml.h" + +/*********************************************************************************************************************************** +Node Getters/Setters +***********************************************************************************************************************************/ +// Node attribute +String *xmlNodeAttribute(const XmlNode *this, const String *name); + +#endif diff --git a/src/build/help/parse.c b/src/build/help/parse.c index d6ed16901..8055664c2 100644 --- a/src/build/help/parse.c +++ b/src/build/help/parse.c @@ -3,7 +3,6 @@ Parse Help Xml ***********************************************************************************************************************************/ #include "build.auto.h" -#include "common/type/xml.h" #include "storage/storage.h" #include "build/config/parse.h" diff --git a/src/build/help/parse.h b/src/build/help/parse.h index 2bc3b3cc6..3cab89b46 100644 --- a/src/build/help/parse.h +++ b/src/build/help/parse.h @@ -4,8 +4,8 @@ Parse Help Xml #ifndef BUILD_HELP_PARSE_H #define BUILD_HELP_PARSE_H +#include "build/common/xml.h" #include "build/config/parse.h" -#include "common/type/xml.h" /*********************************************************************************************************************************** Types diff --git a/src/common/type/xml.c b/src/common/type/xml.c index e651eca32..c83d9d84b 100644 --- a/src/common/type/xml.c +++ b/src/common/type/xml.c @@ -144,30 +144,6 @@ xmlNodeLstAdd(XmlNodeList *this, xmlNodePtr node) FUNCTION_TEST_RETURN(XML_NODE_LIST, this); } -/**********************************************************************************************************************************/ -String * -xmlNodeAttribute(const XmlNode *this, const String *name) -{ - FUNCTION_TEST_BEGIN(); - FUNCTION_TEST_PARAM(XML_NODE, this); - FUNCTION_TEST_PARAM(STRING, name); - FUNCTION_TEST_END(); - - ASSERT(this != NULL); - ASSERT(name != NULL); - - String *result = NULL; - xmlChar *value = xmlGetProp(this->node, (unsigned char *)strZ(name)); - - if (value != NULL) - { - result = strNewZ((char *)value); - xmlFree(value); - } - - FUNCTION_TEST_RETURN(STRING, result); -} - /**********************************************************************************************************************************/ String * xmlNodeContent(const XmlNode *this) diff --git a/src/common/type/xml.h b/src/common/type/xml.h index a20628eb9..f10d0f231 100644 --- a/src/common/type/xml.h +++ b/src/common/type/xml.h @@ -65,9 +65,6 @@ XmlNode *xmlNodeAdd(XmlNode *this, const String *name); /*********************************************************************************************************************************** Node Getters/Setters ***********************************************************************************************************************************/ -// Node attribute -String *xmlNodeAttribute(const XmlNode *this, const String *name); - // Node child (by name or index) XmlNode *xmlNodeChildN(const XmlNode *this, const String *name, unsigned int index, bool errorOnMissing); diff --git a/src/meson.build b/src/meson.build index ef6101411..c750f9073 100644 --- a/src/meson.build +++ b/src/meson.build @@ -55,6 +55,7 @@ src_common = files( src_build_code = [ 'build/common/render.c', 'build/common/string.c', + 'build/common/xml.c', 'build/common/yaml.c', 'build/config/parse.c', 'build/config/render.c', @@ -67,7 +68,6 @@ src_build_code = [ 'build/main.c', 'common/compress/bz2/common.c', 'common/compress/bz2/compress.c', - 'common/type/xml.c', ] build_code = executable( diff --git a/test/define.yaml b/test/define.yaml index be82d06bc..5f3560c03 100644 --- a/test/define.yaml +++ b/test/define.yaml @@ -243,7 +243,8 @@ unit: total: 1 coverage: - - common/type/xml + - build/common/xml + - common/type/xml: included # ---------------------------------------------------------------------------------------------------------------------------- - name: stat