extern struct rspamadm_command confighelp_command;
extern struct rspamadm_command statconvert_command;
extern struct rspamadm_command fuzzyconvert_command;
-extern struct rspamadm_command grep_command;
extern struct rspamadm_command signtool_command;
extern struct rspamadm_command lua_command;
extern struct rspamadm_command dkim_keygen_command;
&confighelp_command,
&statconvert_command,
&fuzzyconvert_command,
- &grep_command,
&signtool_command,
&lua_command,
&dkim_keygen_command,
gint i, err_idx, ret;
GString *tb;
- lua_rawgeti (L, LUA_REGISTRYINDEX, table_idx);
-
lua_pushcfunction (L, &rspamd_lua_traceback);
err_idx = lua_gettop (L);
/* Function */
+ lua_rawgeti (L, LUA_REGISTRYINDEX, table_idx);
lua_pushstring (L, "handler");
- lua_gettable (L, -1);
+ lua_gettable (L, -2);
/* Args */
lua_createtable (L, argc + 1, 0);
lua_rawseti (L, -2, i); /* Starting from zero ! */
}
- if ((ret = lua_pcall (L, 2, 0, err_idx)) != 0) {
+ if ((ret = lua_pcall (L, 1, 0, err_idx)) != 0) {
tb = lua_touserdata (L, -1);
msg_err ("call to rspamadm lua script %s failed (%d): %v", cmd->name,
ret, tb);
gint err_idx, ret;
GString *tb;
- lua_rawgeti (L, LUA_REGISTRYINDEX, table_idx);
-
- lua_pushcfunction (L, &rspamd_lua_traceback);
- err_idx = lua_gettop (L);
+ if (full_help) {
+ lua_pushcfunction (L, &rspamd_lua_traceback);
+ err_idx = lua_gettop (L);
- /* Function */
- lua_pushstring (L, "handler");
- lua_gettable (L, -1);
+ lua_rawgeti (L, LUA_REGISTRYINDEX, table_idx);
+ /* Function */
+ lua_pushstring (L, "handler");
+ lua_gettable (L, -2);
- /* Args */
- lua_createtable (L, 2, 0);
- lua_pushstring (L, cmd->name);
- lua_rawseti (L, -2, 0); /* Starting from zero ! */
+ /* Args */
+ lua_createtable (L, 2, 0);
+ lua_pushstring (L, cmd->name);
+ lua_rawseti (L, -2, 0); /* Starting from zero ! */
- if (full_help) {
lua_pushstring (L, "--help");
lua_rawseti (L, -2, 1);
- }
- else {
- lua_pushstring (L, "--usage");
- lua_rawseti (L, -2, 1);
- }
- if ((ret = lua_pcall (L, 2, 0, err_idx)) != 0) {
- tb = lua_touserdata (L, -1);
- msg_err ("call to rspamadm lua script %s failed (%d): %v", cmd->name,
- ret, tb);
+ if ((ret = lua_pcall (L, 1, 0, err_idx)) != 0) {
+ tb = lua_touserdata (L, -1);
+ msg_err ("call to rspamadm lua script %s failed (%d): %v", cmd->name,
+ ret, tb);
- if (tb) {
- g_string_free (tb, TRUE);
- }
+ if (tb) {
+ g_string_free (tb, TRUE);
+ }
- lua_settop (L, 0);
+ lua_settop (L, 0);
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
+ }
+ }
+ else {
+ lua_rawgeti (L, LUA_REGISTRYINDEX, table_idx);
+ lua_pushstring (L, "description");
+ lua_gettable (L, -2);
+
+ if (lua_isstring (L, -1)) {
+ printf (" %-18s %-60s\n", cmd->name, lua_tostring (L, -1));
+ }
+ else {
+ printf (" %-18s %-60s\n", cmd->name, "no description available");
+ }
}
lua_settop (L, 0);
lua_gettable (L, -2);
}
else {
+ msg_err ("bad return type in %s: %s", path,
+ lua_typename (L, lua_type (L, -1)));
continue; /* Something goes wrong, huh */
}
lua_cmd->flags |= RSPAMADM_FLAG_LUA;
lua_cmd->run = rspamadm_lua_command_run;
lua_cmd->help = rspamadm_lua_command_help;
+
+ g_ptr_array_add (dest, lua_cmd);
}
}
}
static void
rspamadm_version (void)
{
- printf ("Rspamadm %s\n", RVERSION);
+ rspamd_printf ("Rspamadm %s\n", RVERSION);
}
static void
gchar *help_str;
help_str = g_option_context_get_help (context, TRUE, NULL);
- printf ("%s", help_str);
+ rspamd_printf ("%s", help_str);
}
static void
const struct rspamadm_command *cmd;
guint i;
- printf ("Rspamadm %s\n", RVERSION);
- printf ("Usage: rspamadm [global_options] command [command_options]\n");
- printf ("\nAvailable commands:\n");
+ rspamd_printf ("Rspamadm %s\n", RVERSION);
+ rspamd_printf ("Usage: rspamadm [global_options] command [command_options]\n");
+ rspamd_printf ("\nAvailable commands:\n");
PTR_ARRAY_FOREACH (all_commands, i, cmd) {
if (!(cmd->flags & RSPAMADM_FLAG_NOHELP)) {
- printf (" %-18s %-60s\n", cmd->name, cmd->help (FALSE, cmd));
+ rspamd_printf (" %-18s %-60s\n", cmd->name, cmd->help (FALSE, cmd));
}
-
- cmd ++;
}
}
const struct rspamadm_command *cmd;
GPtrArray *all_commands = (GPtrArray *)command->command_data;
- printf ("Rspamadm %s\n", RVERSION);
- printf ("Usage: rspamadm [global_options] command [command_options]\n\n");
+ rspamd_printf ("Rspamadm %s\n", RVERSION);
+ rspamd_printf ("Usage: rspamadm [global_options] command [command_options]\n\n");
if (argc <= 1) {
cmd_name = "help";
}
else {
cmd_name = argv[1];
- printf ("Showing help for %s command\n\n", cmd_name);
+ rspamd_printf ("Showing help for %s command\n\n", cmd_name);
}
cmd = rspamadm_search_command (cmd_name, all_commands);
if (strcmp (cmd_name, "help") == 0) {
guint i;
- printf ("Available commands:\n");
+ rspamd_printf ("Available commands:\n");
PTR_ARRAY_FOREACH (all_commands, i, cmd) {
if (!(cmd->flags & RSPAMADM_FLAG_NOHELP)) {
}
else {
if (!(cmd->flags & RSPAMADM_FLAG_LUA)) {
- printf ("%s\n", cmd->help (TRUE, cmd));
+ rspamd_printf ("%s\n", cmd->help (TRUE, cmd));
}
else {
/* Just call lua subr */
return TRUE;
}
+static gint
+rspamdadm_commands_sort_func (gconstpointer a, gconstpointer b)
+{
+ const struct rspamadm_command *cmda = *((struct rspamadm_command const **)a),
+ *cmdb = *((struct rspamadm_command const **)b);
+
+ return strcmp (cmda->name, cmdb->name);
+}
+
gint
main (gint argc, gchar **argv, gchar **env)
{
lua_setglobal (L, "rspamadm");
rspamadm_fill_lua_commands (L, all_commands);
+ g_ptr_array_sort (all_commands, rspamdadm_commands_sort_func);
g_strfreev (nargv);