소스 검색

Use named udata 'sysrepo' instead private one

Serj Kalichev 11 달 전
부모
커밋
453f2f85ba
2개의 변경된 파일37개의 추가작업 그리고 13개의 파일을 삭제
  1. 3 0
      src/klish_plugin_sysrepo.h
  2. 34 13
      src/plugin.c

+ 3 - 0
src/klish_plugin_sysrepo.h

@@ -195,6 +195,9 @@ size_t num_of_keys(const struct lysc_node *node);
 C_DECL_END
 
 
+// Name of named klish's udata
+#define SRP_UDATA_NAME "sysrepo"
+
 // Plugin's user-data structure
 typedef struct {
 	faux_argv_t *path; // Current data hierarchy path ('edit' operation)

+ 34 - 13
src/plugin.c

@@ -26,14 +26,30 @@ static int kplugin_sysrepo_init_session(kcontext_t *context);
 static int kplugin_sysrepo_fini_session(kcontext_t *context);
 
 
+static bool_t free_udata(void *data)
+{
+	srp_udata_t *udata = (srp_udata_t *)data;
+
+	assert(udata);
+	if (udata->path)
+		faux_argv_free(udata->path);
+	faux_free(udata);
+
+	return BOOL_TRUE;
+}
+
+
 int kplugin_sysrepo_init(kcontext_t *context)
 {
 	kplugin_t *plugin = NULL;
 	srp_udata_t *udata = NULL;
+	kscheme_t *scheme = NULL;
 
 	assert(context);
 	plugin = kcontext_plugin(context);
 	assert(plugin);
+	scheme = kcontext_scheme(context);
+	assert(scheme);
 
 	// Symbols
 
@@ -130,7 +146,8 @@ int kplugin_sysrepo_init(kcontext_t *context)
 	pline_opts_init(&udata->opts);
 	pline_opts_parse(kplugin_conf(plugin), &udata->opts);
 
-	kplugin_set_udata(plugin, udata);
+	if (!kscheme_named_udata_new(scheme, SRP_UDATA_NAME, udata, free_udata))
+		syslog(LOG_ERR, "Can't create name udata \"%s\"", SRP_UDATA_NAME);
 
 	// Logging
 	ly_log_options(LY_LOSTORE);
@@ -140,19 +157,23 @@ int kplugin_sysrepo_init(kcontext_t *context)
 
 
 int kplugin_sysrepo_fini(kcontext_t *context)
+{
+	context = context;
+
+	return 0;
+}
+
+
+srp_udata_t *srp_udata(kcontext_t *context)
 {
 	srp_udata_t *udata = NULL;
 
 	assert(context);
 
-	// Free plugin's user-data
-	udata = (srp_udata_t *)kcontext_udata(context);
+	udata = (srp_udata_t *)kcontext_named_udata(context, SRP_UDATA_NAME);
 	assert(udata);
-	if (udata->path)
-		faux_argv_free(udata->path);
-	faux_free(udata);
 
-	return 0;
+	return udata;
 }
 
 
@@ -162,7 +183,7 @@ pline_opts_t *srp_udata_opts(kcontext_t *context)
 
 	assert(context);
 
-	udata = (srp_udata_t *)kcontext_udata(context);
+	udata = srp_udata(context);
 	assert(udata);
 
 	return &udata->opts;
@@ -175,7 +196,7 @@ faux_argv_t *srp_udata_path(kcontext_t *context)
 
 	assert(context);
 
-	udata = (srp_udata_t *)kcontext_udata(context);
+	udata = srp_udata(context);
 	assert(udata);
 
 	return udata->path;
@@ -188,7 +209,7 @@ void srp_udata_set_path(kcontext_t *context, faux_argv_t *path)
 
 	assert(context);
 
-	udata = (srp_udata_t *)kcontext_udata(context);
+	udata = srp_udata(context);
 	assert(udata);
 	if (udata->path)
 		faux_argv_free(udata->path);
@@ -202,7 +223,7 @@ sr_session_ctx_t *srp_udata_sr_sess(kcontext_t *context)
 
 	assert(context);
 
-	udata = (srp_udata_t *)kcontext_udata(context);
+	udata = srp_udata(context);
 	assert(udata);
 
 	return udata->sr_sess;
@@ -216,7 +237,7 @@ static int kplugin_sysrepo_init_session(kcontext_t *context)
 
 	assert(context);
 
-	udata = (srp_udata_t *)kcontext_udata(context);
+	udata = srp_udata(context);
 	assert(udata);
 
 	// Remote user name
@@ -255,7 +276,7 @@ static int kplugin_sysrepo_fini_session(kcontext_t *context)
 
 	assert(context);
 
-	udata = (srp_udata_t *)kcontext_udata(context);
+	udata = srp_udata(context);
 	assert(udata);
 
 	// Remote user name