static int hlua_smp2lua_str(lua_State *L, struct sample *smp);
static int hlua_lua2smp(lua_State *L, int ud, struct sample *smp);
+#define SEND_ERR(__be, __fmt, __args...) \
+ do { \
+ send_log(__be, LOG_ERR, __fmt, ## __args); \
+ if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)) \
+ Alert(__fmt, ## __args); \
+ } while (0)
+
/* Used to check an Lua function type in the stack. It creates and
* returns a reference of the function. This function throws an
* error if the rgument is not a "function".
/* finished with error. */
case HLUA_E_ERRMSG:
- send_log(NULL, LOG_ERR, "Lua task: %s.\n", lua_tostring(hlua->T, -1));
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua task: %s.\n", lua_tostring(hlua->T, -1));
+ SEND_ERR(NULL, "Lua task: %s.\n", lua_tostring(hlua->T, -1));
hlua_ctx_destroy(hlua);
task_delete(task);
task_free(task);
case HLUA_E_ERR:
default:
- send_log(NULL, LOG_ERR, "Lua task: unknown error.\n");
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua task: unknown error.\n");
+ SEND_ERR(NULL, "Lua task: unknown error.\n");
hlua_ctx_destroy(hlua);
task_delete(task);
task_free(task);
* Lua initialization cause 5% performances loss.
*/
if (!stream->hlua.T && !hlua_ctx_init(&stream->hlua, stream->task)) {
- send_log(stream->be, LOG_ERR, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua converter '%s': can't initialize Lua context.\n", fcn->name);
+ SEND_ERR(stream->be, "Lua converter '%s': can't initialize Lua context.\n", fcn->name);
return 0;
}
if (!HLUA_IS_RUNNING(&stream->hlua)) {
/* Check stack available size. */
if (!lua_checkstack(stream->hlua.T, 1)) {
- send_log(stream->be, LOG_ERR, "Lua converter '%s': full stack.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua converter '%s': full stack.\n", fcn->name);
+ SEND_ERR(stream->be, "Lua converter '%s': full stack.\n", fcn->name);
return 0;
}
/* convert input sample and pust-it in the stack. */
if (!lua_checkstack(stream->hlua.T, 1)) {
- send_log(stream->be, LOG_ERR, "Lua converter '%s': full stack.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua converter '%s': full stack.\n", fcn->name);
+ SEND_ERR(stream->be, "Lua converter '%s': full stack.\n", fcn->name);
return 0;
}
hlua_smp2lua(stream->hlua.T, smp);
if (arg_p) {
for (; arg_p->type != ARGT_STOP; arg_p++) {
if (!lua_checkstack(stream->hlua.T, 1)) {
- send_log(stream->be, LOG_ERR, "Lua converter '%s': full stack.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua converter '%s': full stack.\n", fcn->name);
+ SEND_ERR(stream->be, "Lua converter '%s': full stack.\n", fcn->name);
return 0;
}
hlua_arg2lua(stream->hlua.T, arg_p);
/* yield. */
case HLUA_E_AGAIN:
- send_log(stream->be, LOG_ERR, "Lua converter '%s': cannot use yielded functions.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua converter '%s': cannot use yielded functions.\n", fcn->name);
+ SEND_ERR(stream->be, "Lua converter '%s': cannot use yielded functions.\n", fcn->name);
return 0;
/* finished with error. */
case HLUA_E_ERRMSG:
/* Display log. */
- send_log(stream->be, LOG_ERR, "Lua converter '%s': %s.\n", fcn->name, lua_tostring(stream->hlua.T, -1));
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua converter '%s': %s.\n", fcn->name, lua_tostring(stream->hlua.T, -1));
+ SEND_ERR(stream->be, "Lua converter '%s': %s.\n",
+ fcn->name, lua_tostring(stream->hlua.T, -1));
lua_pop(stream->hlua.T, 1);
return 0;
case HLUA_E_ERR:
/* Display log. */
- send_log(stream->be, LOG_ERR, "Lua converter '%s' returns an unknown error.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua converter '%s' returns an unknown error.\n", fcn->name);
+ SEND_ERR(stream->be, "Lua converter '%s' returns an unknown error.\n", fcn->name);
default:
return 0;
* Lua initialization cause 5% performances loss.
*/
if (!stream->hlua.T && !hlua_ctx_init(&stream->hlua, stream->task)) {
- send_log(stream->be, LOG_ERR, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
+ SEND_ERR(stream->be, "Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
return 0;
}
if (!HLUA_IS_RUNNING(&stream->hlua)) {
/* Check stack available size. */
if (!lua_checkstack(stream->hlua.T, 2)) {
- send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': full stack.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua sample-fetch '%s': full stack.\n", fcn->name);
+ SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
return 0;
}
/* push arguments in the stack. */
if (!hlua_txn_new(stream->hlua.T, stream, smp->px)) {
- send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': full stack.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua sample-fetch '%s': full stack.\n", fcn->name);
+ SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
return 0;
}
stream->hlua.nargs = 1;
for (; arg_p && arg_p->type != ARGT_STOP; arg_p++) {
/* Check stack available size. */
if (!lua_checkstack(stream->hlua.T, 1)) {
- send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': full stack.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua sample-fetch '%s': full stack.\n", fcn->name);
+ SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
return 0;
}
if (!lua_checkstack(stream->hlua.T, 1)) {
- send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': full stack.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua sample-fetch '%s': full stack.\n", fcn->name);
+ SEND_ERR(smp->px, "Lua sample-fetch '%s': full stack.\n", fcn->name);
return 0;
}
hlua_arg2lua(stream->hlua.T, arg_p);
/* yield. */
case HLUA_E_AGAIN:
- send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': cannot use yielded functions.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua sample-fetch '%s': cannot use yielded functions.\n", fcn->name);
+ SEND_ERR(smp->px, "Lua sample-fetch '%s': cannot use yielded functions.\n", fcn->name);
return 0;
/* finished with error. */
case HLUA_E_ERRMSG:
/* Display log. */
- send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s': %s.\n", fcn->name, lua_tostring(stream->hlua.T, -1));
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua sample-fetch '%s': %s.\n", fcn->name, lua_tostring(stream->hlua.T, -1));
+ SEND_ERR(smp->px, "Lua sample-fetch '%s': %s.\n",
+ fcn->name, lua_tostring(stream->hlua.T, -1));
lua_pop(stream->hlua.T, 1);
return 0;
case HLUA_E_ERR:
/* Display log. */
- send_log(smp->px, LOG_ERR, "Lua sample-fetch '%s' returns an unknown error.\n", fcn->name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua sample-fetch '%s': returns an unknown error.\n", fcn->name);
+ SEND_ERR(smp->px, "Lua sample-fetch '%s' returns an unknown error.\n", fcn->name);
default:
return 0;
case ACT_F_HTTP_REQ: analyzer = AN_REQ_HTTP_PROCESS_FE; break;
case ACT_F_HTTP_RES: analyzer = AN_RES_HTTP_PROCESS_BE; break;
default:
- send_log(px, LOG_ERR, "Lua: internal error while execute action.\n");
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua: internal error while execute action.\n");
+ SEND_ERR(px, "Lua: internal error while execute action.\n");
return ACT_RET_CONT;
}
* Lua initialization cause 5% performances loss.
*/
if (!s->hlua.T && !hlua_ctx_init(&s->hlua, s->task)) {
- send_log(px, LOG_ERR, "Lua action '%s': can't initialize Lua context.\n",
+ SEND_ERR(px, "Lua action '%s': can't initialize Lua context.\n",
rule->arg.hlua_rule->fcn.name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua action '%s': can't initialize Lua context.\n",
- rule->arg.hlua_rule->fcn.name);
return ACT_RET_CONT;
}
if (!HLUA_IS_RUNNING(&s->hlua)) {
/* Check stack available size. */
if (!lua_checkstack(s->hlua.T, 1)) {
- send_log(px, LOG_ERR, "Lua function '%s': full stack.\n",
+ SEND_ERR(px, "Lua function '%s': full stack.\n",
rule->arg.hlua_rule->fcn.name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua function '%s': full stack.\n",
- rule->arg.hlua_rule->fcn.name);
return ACT_RET_CONT;
}
/* Create and and push object stream in the stack. */
if (!hlua_txn_new(s->hlua.T, s, px)) {
- send_log(px, LOG_ERR, "Lua function '%s': full stack.\n",
+ SEND_ERR(px, "Lua function '%s': full stack.\n",
rule->arg.hlua_rule->fcn.name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua function '%s': full stack.\n",
- rule->arg.hlua_rule->fcn.name);
return ACT_RET_CONT;
}
s->hlua.nargs = 1;
/* push keywords in the stack. */
for (arg = rule->arg.hlua_rule->args; arg && *arg; arg++) {
if (!lua_checkstack(s->hlua.T, 1)) {
- send_log(px, LOG_ERR, "Lua function '%s': full stack.\n",
+ SEND_ERR(px, "Lua function '%s': full stack.\n",
rule->arg.hlua_rule->fcn.name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua function '%s': full stack.\n",
- rule->arg.hlua_rule->fcn.name);
return ACT_RET_CONT;
}
lua_pushstring(s->hlua.T, *arg);
/* finished with error. */
case HLUA_E_ERRMSG:
/* Display log. */
- send_log(px, LOG_ERR, "Lua function '%s': %s.\n",
+ SEND_ERR(px, "Lua function '%s': %s.\n",
rule->arg.hlua_rule->fcn.name, lua_tostring(s->hlua.T, -1));
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua function '%s': %s.\n",
- rule->arg.hlua_rule->fcn.name, lua_tostring(s->hlua.T, -1));
lua_pop(s->hlua.T, 1);
return ACT_RET_CONT;
case HLUA_E_ERR:
/* Display log. */
- send_log(px, LOG_ERR, "Lua function '%s' return an unknown error.\n",
+ SEND_ERR(px, "Lua function '%s' return an unknown error.\n",
rule->arg.hlua_rule->fcn.name);
- if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
- Alert("Lua function '%s' return an unknown error.\n",
- rule->arg.hlua_rule->fcn.name);
default:
return ACT_RET_CONT;