MEDIUM: actions: Add standard return code for the action API
Action function can return 3 status:
- error if the action encounter fatal error (like out of memory)
- yield if the action must terminate his work later
- continue in other cases
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 3c70357..f797042 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -1231,9 +1231,15 @@
}
else {
/* Custom keywords. */
- if (rule->action_ptr && !rule->action_ptr(rule, s->be, s->sess, s)) {
- s->current_rule = rule;
- goto missing_data;
+ if (rule->action_ptr) {
+ switch (rule->action_ptr(rule, s->be, s->sess, s)) {
+ case ACT_RET_ERR:
+ case ACT_RET_CONT:
+ break;
+ case ACT_RET_YIELD:
+ s->current_rule = rule;
+ goto missing_data;
+ }
}
/* accept */
@@ -1356,10 +1362,16 @@
}
else {
/* Custom keywords. */
- if (rule->action_ptr && !rule->action_ptr(rule, s->be, s->sess, s)) {
- channel_dont_close(rep);
- s->current_rule = rule;
- return 0;
+ if (rule->action_ptr) {
+ switch (rule->action_ptr(rule, s->be, s->sess, s)) {
+ case ACT_RET_ERR:
+ case ACT_RET_CONT:
+ break;
+ case ACT_RET_YIELD:
+ channel_dont_close(rep);
+ s->current_rule = rule;
+ return 0;
+ }
}
/* accept */
@@ -1441,7 +1453,19 @@
else {
/* Custom keywords. */
if (rule->action_ptr) {
- rule->action_ptr(rule, sess->fe, sess, NULL);
+ switch (rule->action_ptr(rule, sess->fe, sess, NULL)) {
+ case ACT_RET_YIELD:
+ /* yield is not allowed at this point. If this return code is
+ * used it is a bug, so I prefer to abort the process.
+ */
+ send_log(sess->fe, LOG_WARNING,
+ "Internal error: yield not allowed with tcp-request connection actions.");
+ case ACT_RET_CONT:
+ break;
+ case ACT_RET_ERR:
+ result = 0;
+ break;
+ }
if (rule->action == ACT_ACTION_CONT)
continue;
}