commit afdd86a: [Minor] Allow ucl emitters to output rspamd_text

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Oct 15 10:49:06 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-10-15 11:31:35 +0100
URL: https://github.com/rspamd/rspamd/commit/afdd86ad9be24f1b4843b9f4d990b13590d8a4a6

[Minor] Allow ucl emitters to output rspamd_text

---
 contrib/libucl/lua_ucl.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/contrib/libucl/lua_ucl.c b/contrib/libucl/lua_ucl.c
index 4e5eb9452..f2d4f24d6 100644
--- a/contrib/libucl/lua_ucl.c
+++ b/contrib/libucl/lua_ucl.c
@@ -82,6 +82,11 @@ static ucl_object_t* ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_f
 
 static void *ucl_null;
 
+struct _rspamd_lua_text {
+	const char *start;
+	unsigned int len;
+	unsigned int flags;
+};
 
 enum lua_ucl_push_flags {
 	LUA_UCL_DEFAULT_FLAGS = 0,
@@ -501,6 +506,14 @@ ucl_object_lua_fromelt (lua_State *L, int idx, ucl_string_flags_t flags)
 		if (lua_topointer (L, idx) == ucl_null) {
 			obj = ucl_object_typed_new (UCL_NULL);
 		}
+		else {
+			/* Assume it is a text like object */
+			struct _rspamd_lua_text *t = lua_touserdata (L, idx);
+
+			if (t) {
+				obj = ucl_object_fromstring_common(t->start, t->len, 0);
+			}
+		}
 		break;
 	case LUA_TTABLE:
 	case LUA_TFUNCTION:
@@ -834,12 +847,6 @@ lua_ucl_parser_parse_string (lua_State *L)
 	return ret;
 }
 
-struct _rspamd_lua_text {
-	const char *start;
-	unsigned int len;
-	unsigned int flags;
-};
-
 /***
  * @method parser:parse_text(input)
  * Parse UCL object from text object (Rspamd specific).
@@ -1440,10 +1447,11 @@ lua_ucl_to_format (lua_State *L)
 				format = UCL_EMIT_YAML;
 			}
 			else if (strcasecmp (strtype, "config") == 0 ||
-				strcasecmp (strtype, "ucl") == 0) {
+					 strcasecmp (strtype, "ucl") == 0) {
 				format = UCL_EMIT_CONFIG;
 			}
-			else if (strcasecmp (strtype, "msgpack") == 0) {
+			else if (strcasecmp (strtype, "msgpack") == 0 ||
+					 strcasecmp (strtype, "messagepack") == 0) {
 				format = UCL_EMIT_MSGPACK;
 			}
 		}


More information about the Commits mailing list