Browse Source

scheme.plugin: Add id field

Serj Kalichev 3 years ago
parent
commit
383dec6770
5 changed files with 28 additions and 0 deletions
  1. 2 0
      bin/klishd/sch.c
  2. 2 0
      klish.xsd
  3. 4 0
      klish/kplugin.h
  4. 1 0
      klish/kscheme/iplugin.c
  5. 19 0
      klish/kscheme/kplugin.c

+ 2 - 0
bin/klishd/sch.c

@@ -4,12 +4,14 @@ ischeme_t sch = {
 
   PLUGIN {
    .name = "plugin1",
+   .id = "id1",
    .file = "file1",
    .global = "true",
   },
 
   PLUGIN {
    .name = "plugin2",
+   .id = "id2",
    .file = "file2",
    .global = "false",
   },

+ 2 - 0
klish.xsd

@@ -480,6 +480,7 @@
 *
 * name - Plugin name. If "file" attribute is not specified then plugin's
 *	filename is autogenerated as "klish-plugin-<name>.so".
+* [id] - Internal plugin name. Can be the same as "name".
 * [file] - File name if standard autogenerated filename (using "name" field)
 *	is not appropriate.
 * [global] - A boolean RTLD_GLOBAL flag for dlopen()
@@ -490,6 +491,7 @@
 		<xs:simpleContent>
 			<xs:extension base="xs:string">
 				<xs:attribute name="name" type="xs:string" use="required"/>
+				<xs:attribute name="id" type="xs:string" use="optional"/>
 				<xs:attribute name="file" type="xs:string" use="optional"/>
 				<xs:attribute name="global" type="xs:boolean" use="optional" default="false"/>
 			</xs:extension>

+ 4 - 0
klish/kplugin.h

@@ -12,6 +12,7 @@ typedef struct kplugin_s kplugin_t;
 
 typedef struct iplugin_s {
 	char *name;
+	char *id;
 	char *file;
 	char *global;
 	char *script;
@@ -23,6 +24,7 @@ typedef enum {
 	KPLUGIN_ERROR_INTERNAL,
 	KPLUGIN_ERROR_ALLOC,
 	KPLUGIN_ERROR_ATTR_NAME,
+	KPLUGIN_ERROR_ATTR_ID,
 	KPLUGIN_ERROR_ATTR_FILE,
 	KPLUGIN_ERROR_ATTR_GLOBAL,
 	KPLUGIN_ERROR_SCRIPT,
@@ -42,6 +44,8 @@ const char *kplugin_strerror(kplugin_error_e error);
 
 const char *kplugin_name(const kplugin_t *plugin);
 bool_t kplugin_set_name(kplugin_t *plugin, const char *name);
+const char *kplugin_id(const kplugin_t *plugin);
+bool_t kplugin_set_id(kplugin_t *plugin, const char *id);
 const char *kplugin_file(const kplugin_t *plugin);
 bool_t kplugin_set_file(kplugin_t *plugin, const char *file);
 bool_t kplugin_global(const kplugin_t *plugin);

+ 1 - 0
klish/kscheme/iplugin.c

@@ -19,6 +19,7 @@ char *iplugin_to_text(const iplugin_t *iplugin, int level)
 	faux_str_free(tmp);
 
 	attr2ctext(&str, "name", iplugin->name, level + 1);
+	attr2ctext(&str, "id", iplugin->id, level + 1);
 	attr2ctext(&str, "file", iplugin->file, level + 1);
 	attr2ctext(&str, "global", iplugin->global, level + 1);
 

+ 19 - 0
klish/kscheme/kplugin.c

@@ -13,6 +13,7 @@
 
 struct kplugin_s {
 	char *name;
+	char *id;
 	char *file;
 	bool_t global;
 	char *script;
@@ -25,6 +26,10 @@ struct kplugin_s {
 KGET_STR(plugin, name);
 KSET_STR_ONCE(plugin, name);
 
+// ID
+KGET_STR(plugin, id);
+KSET_STR(plugin, id);
+
 // File
 KGET_STR(plugin, file);
 KSET_STR(plugin, file);
@@ -49,6 +54,7 @@ static kplugin_t *kplugin_new_empty(void)
 
 	// Initialize
 	plugin->name = NULL;
+	plugin->id = NULL;
 	plugin->file = NULL;
 	plugin->global = BOOL_FALSE;
 	plugin->script = NULL;
@@ -87,6 +93,7 @@ void kplugin_free(kplugin_t *plugin)
 		return;
 
 	faux_str_free(plugin->name);
+	faux_str_free(plugin->id);
 	faux_str_free(plugin->file);
 	faux_str_free(plugin->script);
 
@@ -111,6 +118,9 @@ const char *kplugin_strerror(kplugin_error_e error)
 	case KPLUGIN_ERROR_ATTR_NAME:
 		str = "Illegal 'name' attribute";
 		break;
+	case KPLUGIN_ERROR_ATTR_ID:
+		str = "Illegal 'id' attribute";
+		break;
 	case KPLUGIN_ERROR_ATTR_FILE:
 		str = "Illegal 'file' attribute";
 		break;
@@ -144,6 +154,15 @@ bool_t kplugin_parse(kplugin_t *plugin, const iplugin_t *info, kplugin_error_e *
 		}
 	}
 
+	// ID
+	if (!faux_str_is_empty(info->id)) {
+		if (!kplugin_set_id(plugin, info->id)) {
+			if (error)
+				*error = KPLUGIN_ERROR_ATTR_ID;
+			return BOOL_FALSE;
+		}
+	}
+
 	// File
 	if (!faux_str_is_empty(info->file)) {
 		if (!kplugin_set_file(plugin, info->file)) {