[sr-dev] git:master:7cbece0e: app_lua: print special kemi functions via rpc

Daniel-Constantin Mierla miconda at gmail.com
Fri Nov 24 19:40:18 CET 2017


Module: kamailio
Branch: master
Commit: 7cbece0e2e60f8c334bea97333b029d51e5b7e33
URL: https://github.com/kamailio/kamailio/commit/7cbece0e2e60f8c334bea97333b029d51e5b7e33

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-11-24T19:39:27+01:00

app_lua: print special kemi functions via rpc

---

Modified: src/modules/app_lua/app_lua_mod.c

---

Diff:  https://github.com/kamailio/kamailio/commit/7cbece0e2e60f8c334bea97333b029d51e5b7e33.diff
Patch: https://github.com/kamailio/kamailio/commit/7cbece0e2e60f8c334bea97333b029d51e5b7e33.patch

---

diff --git a/src/modules/app_lua/app_lua_mod.c b/src/modules/app_lua/app_lua_mod.c
index 4c431dd3ed..b4a44fab70 100644
--- a/src/modules/app_lua/app_lua_mod.c
+++ b/src/modules/app_lua/app_lua_mod.c
@@ -606,6 +606,54 @@ static void app_lua_rpc_list(rpc_t* rpc, void* ctx)
 	return;
 }
 
+/**
+ * only prototypes of special kemi exports in order to list via rpc
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_app_lua_rpc_exports[] = {
+	{ str_init("pv"), str_init("get"),
+		SR_KEMIP_STR, NULL,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("pv"), str_init("seti"),
+		SR_KEMIP_NONE, NULL,
+		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("pv"), str_init("sets"),
+		SR_KEMIP_NONE, NULL,
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("pv"), str_init("unset"),
+		SR_KEMIP_NONE, NULL,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("pv"), str_init("is_null"),
+		SR_KEMIP_BOOL, NULL,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("x"), str_init("modf"),
+		SR_KEMIP_INT, NULL,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("x"), str_init("exit"),
+		SR_KEMIP_NONE, NULL,
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("x"), str_init("drop"),
+		SR_KEMIP_NONE, NULL,
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
 
 static const char* app_lua_rpc_api_list_doc[2] = {
 	"list kemi exports to lua",
@@ -656,6 +704,22 @@ static void app_lua_rpc_api_list(rpc_t* rpc, void* ctx)
 			return;
 		}
 	}
+	for(i=0; sr_kemi_app_lua_rpc_exports[i].fname.s!=NULL; i++) {
+		ket = &sr_kemi_app_lua_rpc_exports[i];
+		if(rpc->struct_add(ih, "{", "func", &sh)<0) {
+			rpc->fault(ctx, 500, "Internal error internal structure");
+			return;
+		}
+		if(rpc->struct_add(sh, "SSSS",
+				"ret", sr_kemi_param_map_get_name(ket->rtype),
+				"module", &ket->mname,
+				"name", &ket->fname,
+				"params", sr_kemi_param_map_get_params(ket->ptypes))<0) {
+			LM_ERR("failed to add the structure with attributes (%d)\n", i);
+			rpc->fault(ctx, 500, "Internal error creating dest struct");
+			return;
+		}
+	}
 }
 
 rpc_export_t app_lua_rpc_cmds[] = {




More information about the sr-dev mailing list