Browse Source

kxml: Deafault plugin functions for dbs

Serj Kalichev 2 years ago
parent
commit
fa16f7e267

+ 10 - 13
dbs/expat/expat_plugin.c

@@ -15,21 +15,18 @@ uint8_t kdb_expat_major = KDB_MAJOR;
 uint8_t kdb_expat_minor = KDB_MINOR;
 
 
-bool_t kdb_expat_load_scheme(kdb_t *db, kscheme_t *scheme)
+bool_t kdb_expat_init(kdb_t *db)
 {
-	faux_ini_t *ini = NULL;
-	faux_error_t *error = NULL;
-	const char *xml_path = NULL;
+	return kxml_plugin_init(db);
+}
 
-	assert(db);
-	if (!db)
-		return BOOL_FALSE;
+bool_t kdb_expat_fini(kdb_t *db)
+{
+	return kxml_plugin_fini(db);
+}
 
-	// Get configuration info from kdb object
-	ini = kdb_ini(db);
-	if (ini)
-		xml_path = faux_ini_find(ini, "XMLPath");
-	error = kdb_error(db);
 
-	return kxml_load_scheme(scheme, xml_path, error);
+bool_t kdb_expat_load_scheme(kdb_t *db, kscheme_t *scheme)
+{
+	return kxml_plugin_load_scheme(db, scheme);
 }

+ 10 - 13
dbs/libxml2/libxml2_plugin.c

@@ -15,21 +15,18 @@ uint8_t kdb_libxml2_major = KDB_MAJOR;
 uint8_t kdb_libxml2_minor = KDB_MINOR;
 
 
-bool_t kdb_libxml2_load_scheme(kdb_t *db, kscheme_t *scheme)
+bool_t kdb_libxml2_init(kdb_t *db)
 {
-	faux_ini_t *ini = NULL;
-	faux_error_t *error = NULL;
-	const char *xml_path = NULL;
+	return kxml_plugin_init(db);
+}
 
-	assert(db);
-	if (!db)
-		return BOOL_FALSE;
+bool_t kdb_libxml2_fini(kdb_t *db)
+{
+	return kxml_plugin_fini(db);
+}
 
-	// Get configuration info from kdb object
-	ini = kdb_ini(db);
-	if (ini)
-		xml_path = faux_ini_find(ini, "XMLPath");
-	error = kdb_error(db);
 
-	return kxml_load_scheme(scheme, xml_path, error);
+bool_t kdb_libxml2_load_scheme(kdb_t *db, kscheme_t *scheme)
+{
+	return kxml_plugin_load_scheme(db, scheme);
 }

+ 10 - 13
dbs/roxml/roxml_plugin.c

@@ -15,21 +15,18 @@ uint8_t kdb_roxml_major = KDB_MAJOR;
 uint8_t kdb_roxml_minor = KDB_MINOR;
 
 
-bool_t kdb_roxml_load_scheme(kdb_t *db, kscheme_t *scheme)
+bool_t kdb_roxml_init(kdb_t *db)
 {
-	faux_ini_t *ini = NULL;
-	faux_error_t *error = NULL;
-	const char *xml_path = NULL;
+	return kxml_plugin_init(db);
+}
 
-	assert(db);
-	if (!db)
-		return BOOL_FALSE;
+bool_t kdb_roxml_fini(kdb_t *db)
+{
+	return kxml_plugin_fini(db);
+}
 
-	// Get configuration info from kdb object
-	ini = kdb_ini(db);
-	if (ini)
-		xml_path = faux_ini_find(ini, "XMLPath");
-	error = kdb_error(db);
 
-	return kxml_load_scheme(scheme, xml_path, error);
+bool_t kdb_roxml_load_scheme(kdb_t *db, kscheme_t *scheme)
+{
+	return kxml_plugin_load_scheme(db, scheme);
 }

+ 8 - 0
klish/kxml.h

@@ -10,6 +10,7 @@
 
 #include <faux/faux.h>
 #include <klish/kscheme.h>
+#include <klish/kdb.h>
 
 /** @brief XML document (opaque type).
  *
@@ -122,4 +123,11 @@ bool_t kxml_load_scheme(kscheme_t *scheme, const char *xml_path,
 	faux_error_t *error);
 
 
+/** @brief Typical XML parser functions
+ */
+bool_t kxml_plugin_init(kdb_t *db);
+bool_t kxml_plugin_fini(kdb_t *db);
+bool_t kxml_plugin_load_scheme(kdb_t *db, kscheme_t *scheme);
+
+
 #endif // _klish_kxml_h

+ 3 - 2
klish/xml-helper/Makefile.am

@@ -1,5 +1,6 @@
 lib_LTLIBRARIES += libklish-helper-xml.la
-libklish_helper_xml_la_SOURCES = \
-	klish/xml-helper/load.c
 libklish_helper_xml_la_CFLAGS = $(AM_CFLAGS) -fPIC
 libklish_helper_xml_la_LDFLAGS = -static
+libklish_helper_xml_la_SOURCES = \
+	klish/xml-helper/load.c \
+	klish/xml-helper/plugin.c

+ 47 - 0
klish/xml-helper/plugin.c

@@ -0,0 +1,47 @@
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <assert.h>
+
+#include <faux/faux.h>
+#include <faux/str.h>
+#include <faux/error.h>
+#include <klish/kxml.h>
+#include <klish/kscheme.h>
+#include <klish/kdb.h>
+
+
+bool_t kxml_plugin_init(kdb_t *db)
+{
+	db = db; // Happy compiler
+
+	return kxml_doc_start();
+}
+
+
+bool_t kxml_plugin_fini(kdb_t *db)
+{
+	db = db; // Happy compiler
+
+	return kxml_doc_stop();
+}
+
+
+bool_t kxml_plugin_load_scheme(kdb_t *db, kscheme_t *scheme)
+{
+	faux_ini_t *ini = NULL;
+	faux_error_t *error = NULL;
+	const char *xml_path = NULL;
+
+	assert(db);
+	if (!db)
+		return BOOL_FALSE;
+
+	// Get configuration info from kdb object
+	ini = kdb_ini(db);
+	if (ini)
+		xml_path = faux_ini_find(ini, "XMLPath");
+	error = kdb_error(db);
+
+	return kxml_load_scheme(scheme, xml_path, error);
+}