Browse code

core: kemi - implementation of a drop() alternative

- it doesn't stop the embedded interpreter, but it can trigger the
drop() effects (e.g., dropping a branch)

Daniel-Constantin Mierla authored on 13/04/2016 22:06:05
Showing 2 changed files
... ...
@@ -67,6 +67,27 @@ sr_kemi_module_t* sr_kemi_modules_get(void)
67 67
 /**
68 68
  *
69 69
  */
70
+static run_act_ctx_t *_sr_kemi_act_ctx = NULL;
71
+
72
+/**
73
+ *
74
+ */
75
+void sr_kemi_act_ctx_set(run_act_ctx_t *ctx)
76
+{
77
+	_sr_kemi_act_ctx = ctx;
78
+}
79
+
80
+/**
81
+ *
82
+ */
83
+run_act_ctx_t* sr_kemi_act_ctx_get(void)
84
+{
85
+	return _sr_kemi_act_ctx;
86
+}
87
+
88
+/**
89
+ *
90
+ */
70 91
 static int lua_sr_kemi_dbg(sip_msg_t *msg, str *txt)
71 92
 {
72 93
 	if(txt!=NULL && txt->s!=NULL)
... ...
@@ -97,6 +118,17 @@ static int lua_sr_kemi_info(sip_msg_t *msg, str *txt)
97 97
 /**
98 98
  *
99 99
  */
100
+static int lua_sr_kemi_drop(sip_msg_t *msg)
101
+{
102
+	if(_sr_kemi_act_ctx==NULL)
103
+		return 0;
104
+	_sr_kemi_act_ctx->run_flags |= EXIT_R_F|DROP_R_F;
105
+	return 0;
106
+}
107
+
108
+/**
109
+ *
110
+ */
100 111
 static sr_kemi_t _sr_kemi_core[] = {
101 112
 	{ str_init(""), str_init("dbg"),
102 113
 		SR_KEMIP_NONE, lua_sr_kemi_dbg,
... ...
@@ -113,6 +145,11 @@ static sr_kemi_t _sr_kemi_core[] = {
113 113
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
114 114
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
115 115
 	},
116
+	{ str_init(""), str_init("drop"),
117
+		SR_KEMIP_NONE, lua_sr_kemi_drop,
118
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
119
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
120
+	},
116 121
 
117 122
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
118 123
 };
... ...
@@ -24,6 +24,7 @@
24 24
 
25 25
 #include "str.h"
26 26
 #include "parser/msg_parser.h"
27
+#include "action.h"
27 28
 
28 29
 #define SR_KEMIP_NONE	(0)		/* no type */
29 30
 #define SR_KEMIP_INT	(1<<0)	/* type integer */
... ...
@@ -107,4 +108,7 @@ int sr_kemi_cbname_list_init(void);
107 107
 int sr_kemi_cbname_lookup_name(str *name);
108 108
 str* sr_kemi_cbname_lookup_idx(int idx);
109 109
 
110
+void sr_kemi_act_ctx_set(run_act_ctx_t *ctx);
111
+run_act_ctx_t* sr_kemi_act_ctx_get(void);
112
+
110 113
 #endif