瀏覽代碼

plugin-klish: Store compiled regex within ACTION's udata.

Architecturally it's right way to store such information. Previously this data
was stored within ENTRY udata. But one ENTRY can contain multiple ACTIONs. It
can be conflict.
Serj Kalichev 4 月之前
父節點
當前提交
e2794a087e
共有 3 個文件被更改,包括 14 次插入12 次删除
  1. 1 1
      klish/kcontext.h
  2. 2 2
      klish/ksession/kcontext.c
  3. 11 9
      plugins/klish/ptype_string.c

+ 1 - 1
klish/kcontext.h

@@ -116,7 +116,7 @@ int kcontext_printf(const kcontext_t *context, const char *fmt, ...);
 kparg_t *kcontext_candidate_parg(const kcontext_t *context);
 kparg_t *kcontext_candidate_parg(const kcontext_t *context);
 kentry_t *kcontext_candidate_entry(const kcontext_t *context);
 kentry_t *kcontext_candidate_entry(const kcontext_t *context);
 const char *kcontext_candidate_value(const kcontext_t *context);
 const char *kcontext_candidate_value(const kcontext_t *context);
-const kaction_t *kcontext_action(const kcontext_t *context);
+kaction_t *kcontext_action(const kcontext_t *context);
 const char *kcontext_script(const kcontext_t *context);
 const char *kcontext_script(const kcontext_t *context);
 bool_t kcontext_named_udata_new(kcontext_t *context,
 bool_t kcontext_named_udata_new(kcontext_t *context,
 	const char *name, void *data, kudata_data_free_fn free_fn);
 	const char *name, void *data, kudata_data_free_fn free_fn);

+ 2 - 2
klish/ksession/kcontext.c

@@ -230,7 +230,7 @@ const char *kcontext_candidate_value(const kcontext_t *context)
 }
 }
 
 
 
 
-const kaction_t *kcontext_action(const kcontext_t *context)
+kaction_t *kcontext_action(const kcontext_t *context)
 {
 {
 	faux_list_node_t *node = NULL;
 	faux_list_node_t *node = NULL;
 
 
@@ -242,7 +242,7 @@ const kaction_t *kcontext_action(const kcontext_t *context)
 	if (!node)
 	if (!node)
 		return NULL;
 		return NULL;
 
 
-	return (const kaction_t *)faux_list_data(node);
+	return (kaction_t *)faux_list_data(node);
 }
 }
 
 
 
 

+ 11 - 9
plugins/klish/ptype_string.c

@@ -38,16 +38,18 @@ static void klish_ptype_STRING_free(void *data)
 }
 }
 
 
 
 
-klish_ptype_STRING_t *klish_ptype_STRING_init(kentry_t *entry,
-	const char *pattern)
+klish_ptype_STRING_t *klish_ptype_STRING_init(kaction_t *action)
 {
 {
 	klish_ptype_STRING_t *udata = NULL;
 	klish_ptype_STRING_t *udata = NULL;
+	const char *pattern = NULL;
 
 
 	udata = faux_malloc(sizeof(*udata));
 	udata = faux_malloc(sizeof(*udata));
 	assert(udata);
 	assert(udata);
 	if (!udata)
 	if (!udata)
 		return NULL;
 		return NULL;
 
 
+	pattern = kaction_script(action);
+
 	if (faux_str_is_empty(pattern)) {
 	if (faux_str_is_empty(pattern)) {
 		udata->is_regex = BOOL_FALSE;
 		udata->is_regex = BOOL_FALSE;
 	} else {
 	} else {
@@ -60,27 +62,27 @@ klish_ptype_STRING_t *klish_ptype_STRING_init(kentry_t *entry,
 		}
 		}
 	}
 	}
 
 
-	kentry_set_udata(entry, udata, klish_ptype_STRING_free);
+	kaction_set_udata(action, udata, klish_ptype_STRING_free);
 
 
 	return udata;
 	return udata;
 }
 }
 
 
-/** @brief PTYPE: Arbitrary string
+
+/** @brief PTYPE: String
  */
  */
 int klish_ptype_STRING(kcontext_t *context)
 int klish_ptype_STRING(kcontext_t *context)
 {
 {
-	kentry_t *entry = NULL;
+	kaction_t *action = NULL;
 	const char *value = NULL;
 	const char *value = NULL;
 	klish_ptype_STRING_t *udata = NULL;
 	klish_ptype_STRING_t *udata = NULL;
 	size_t len = 0;
 	size_t len = 0;
 
 
-	entry = kcontext_candidate_entry(context);
+	action = kcontext_action(context);
 	value = kcontext_candidate_value(context);
 	value = kcontext_candidate_value(context);
 
 
-	udata = (klish_ptype_STRING_t *)kentry_udata(entry);
+	udata = (klish_ptype_STRING_t *)kaction_udata(action);
 	if (!udata) {
 	if (!udata) {
-		const char *pattern = kcontext_script(context);
-		udata = klish_ptype_STRING_init(entry, pattern);
+		udata = klish_ptype_STRING_init(action);
 		if (!udata)
 		if (!udata)
 			return -1;
 			return -1;
 	}
 	}