Browse Source

dbs: ischeme plugin that can deploy

Serj Kalichev 2 years ago
parent
commit
4f35b254fa
8 changed files with 83 additions and 5 deletions
  1. 9 4
      bin/klishd/klishd.c
  2. 5 0
      dbs/Makefile.am
  3. 6 0
      dbs/ischeme/Makefile.am
  4. 58 0
      dbs/ischeme/ischeme_plugin.c
  5. 2 0
      klish/iplugin.h
  6. 1 0
      klish/iptype.h
  7. 1 1
      klish/ischeme.h
  8. 1 0
      klish/iview.h

+ 9 - 4
bin/klishd/klishd.c

@@ -143,9 +143,9 @@ int main(int argc, char **argv)
 	// Scheme
 	scheme = kscheme_new();
 	{
-	char *txt = NULL;
 	kcontext_t *context = NULL;
 	bool_t prepare_retcode = BOOL_FALSE;
+	kdb_t *deploy_db = NULL;
 
 	// Load scheme
 	if (!load_all_dbs(scheme, opts->dbs, config, error)) {
@@ -161,9 +161,14 @@ int main(int argc, char **argv)
 		fprintf(stderr, "Scheme preparing errors:\n");
 		goto err;
 	}
-	txt = ischeme_deploy(scheme, 0);
-	printf("%s\n", txt);
-	faux_str_free(txt);
+
+	// Deploy (for testing purposes)
+	deploy_db = kdb_new("ischeme", NULL);
+	kdb_load_plugin(deploy_db);
+	kdb_init(deploy_db);
+	kdb_deploy_scheme(deploy_db, scheme);
+	kdb_fini(deploy_db);
+	kdb_free(deploy_db);
 goto err; // Test purposes
 	}
 

+ 5 - 0
dbs/Makefile.am

@@ -2,16 +2,21 @@ dbdir = ${pkglibdir}/@DBS_SUBDIR@
 db_LTLIBRARIES =
 
 EXTRA_DIST += \
+	dbs/ischeme/Makefile.am \
 	dbs/libxml2/Makefile.am \
 	dbs/roxml/Makefile.am \
 	dbs/expat/Makefile.am
 
+include $(top_srcdir)/dbs/ischeme/Makefile.am
+
 if WITH_LIBXML2
 include $(top_srcdir)/dbs/libxml2/Makefile.am
 endif
+
 if WITH_ROXML
 include $(top_srcdir)/dbs/roxml/Makefile.am
 endif
+
 if WITH_EXPAT
 include $(top_srcdir)/dbs/expat/Makefile.am
 endif

+ 6 - 0
dbs/ischeme/Makefile.am

@@ -0,0 +1,6 @@
+db_LTLIBRARIES += kdb-ischeme.la
+kdb_ischeme_la_SOURCES =
+kdb_ischeme_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version -module
+
+kdb_ischeme_la_SOURCES += \
+	dbs/ischeme/ischeme_plugin.c

+ 58 - 0
dbs/ischeme/ischeme_plugin.c

@@ -0,0 +1,58 @@
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <faux/faux.h>
+#include <faux/str.h>
+#include <klish/ischeme.h>
+#include <klish/kscheme.h>
+#include <klish/kdb.h>
+
+
+uint8_t kdb_ischeme_major = KDB_MAJOR;
+uint8_t kdb_ischeme_minor = KDB_MINOR;
+
+
+bool_t kdb_ischeme_deploy_scheme(kdb_t *db, const kscheme_t *scheme)
+{
+	faux_ini_t *ini = NULL;
+	const char *out_path = NULL;
+	int f = -1;
+	char *out = NULL;
+	ssize_t bytes_written = 0;
+
+	assert(db);
+	if (!db)
+		return BOOL_FALSE;
+
+	out = ischeme_deploy(scheme, 0);
+	if (!out)
+		return BOOL_FALSE;
+
+	// Get configuration info from kdb object
+	ini = kdb_ini(db);
+	if (ini)
+		out_path = faux_ini_find(ini, "DeployPath");
+
+	if (out_path)
+		f = open(out_path, O_WRONLY | O_CREAT | O_TRUNC, 00644);
+	else
+		f = STDOUT_FILENO;
+	if (f < 0) {
+		faux_str_free(out);
+		return BOOL_FALSE;
+	}
+	bytes_written = faux_write_block(f, out, strlen(out));
+	if (out_path)
+		close(f);
+	faux_str_free(out);
+	if (bytes_written < 0)
+		return BOOL_FALSE;
+
+	return BOOL_TRUE;
+}

+ 2 - 0
klish/iplugin.h

@@ -6,6 +6,8 @@
 #ifndef _klish_iplugin_h
 #define _klish_iplugin_h
 
+#include <klish/kplugin.h>
+
 typedef struct iplugin_s {
 	char *name;
 	char *id;

+ 1 - 0
klish/iptype.h

@@ -8,6 +8,7 @@
 
 #include <faux/error.h>
 #include <klish/iaction.h>
+#include <klish/kptype.h>
 
 typedef struct iptype_s {
 	char *name;

+ 1 - 1
klish/ischeme.h

@@ -10,7 +10,7 @@
 #include <klish/iptype.h>
 #include <klish/iplugin.h>
 #include <klish/iview.h>
-
+#include <klish/kscheme.h>
 
 #define VIEW_LIST .views = &(iview_t * []) {
 #define END_VIEW_LIST NULL }

+ 1 - 0
klish/iview.h

@@ -8,6 +8,7 @@
 
 #include <faux/error.h>
 #include <klish/icommand.h>
+#include <klish/kview.h>
 
 typedef struct iview_s {
 	char *name;