This commit is contained in:
Jan Vidar Krey
2012-04-19 23:17:39 +02:00
16 changed files with 72 additions and 63 deletions

View File

@@ -186,7 +186,10 @@ static enum command_parse_status command_extract_arguments(struct command_base*
if (!token || !*token)
{
status = (arg_code == '?' ? cmd_status_ok : cmd_status_missing_args);
if (arg_code == '?' || opt == 1)
status = cmd_status_ok;
else
status = cmd_status_missing_args;
break;
}
@@ -284,7 +287,7 @@ static enum command_parse_status command_extract_arguments(struct command_base*
{
hub_free(data);
data = NULL;
return cmd_status_arg_number;
status = cmd_status_arg_number;
}
break;
@@ -387,10 +390,13 @@ void command_get_syntax(struct command_handle* handler, struct cbuffer* buf)
{
for (n = 0; n < strlen(handler->args); n++)
{
if (n > 0 && !opt) cbuf_append(buf, " ");
if (n > 0)
cbuf_append(buf, " ");
if (opt)
cbuf_append(buf, "[");
switch (handler->args[n])
{
case '?': cbuf_append(buf, "["); opt = 1; continue;
case '?': opt = 1; continue;
case 'n': cbuf_append(buf, "<nick>"); break;
case 'u': cbuf_append(buf, "<user>"); break;
case 'i': cbuf_append(buf, "<cid>"); break;
@@ -403,11 +409,10 @@ void command_get_syntax(struct command_handle* handler, struct cbuffer* buf)
case 'N': cbuf_append(buf, "<number>"); break;
}
if (opt)
{
cbuf_append(buf, "]");
opt = 0;
}
opt++;
}
while (opt--)
cbuf_append(buf, "]");
}
}
@@ -858,7 +863,7 @@ void commands_builtin_add(struct command_base* cbase)
ADD_COMMAND("getip", 5, "u", auth_cred_operator, command_getip, "Show IP address for a user" );
ADD_COMMAND("help", 4, "?c",auth_cred_guest, command_help, "Show this help message." );
ADD_COMMAND("kick", 4, "u", auth_cred_operator, command_kick, "Kick a user" );
ADD_COMMAND("log", 3, "?m", auth_cred_operator, command_log, "Display log" ); // fail
ADD_COMMAND("log", 3, "?m",auth_cred_operator, command_log, "Display log" ); // fail
ADD_COMMAND("myip", 4, "", auth_cred_guest, command_myip, "Show your own IP." );
ADD_COMMAND("reload", 6, "", auth_cred_admin, command_reload, "Reload configuration files." );
ADD_COMMAND("shutdown", 8, "", auth_cred_admin, command_shutdown_hub, "Shutdown hub." );

View File

@@ -83,7 +83,7 @@ struct hub_command
{
const char* message; /**<<< "The complete message." */
char* prefix; /**<<< "The prefix extracted from the message." */
struct linked_list* args; /**<<< "List of all parsed arguments from the message. Type depends on expectations." */
struct linked_list* args; /**<<< "List of arguments of type struct hub_command_arg_data. Parsed from message." */
enum command_parse_status status; /**<<< "Status of the hub_command." */
command_handler handler; /**<<< "The function handler to call in order to invoke this command." */
const struct hub_user* user; /**<<< "The user who invoked this command." */

View File

@@ -54,26 +54,6 @@ static int plugin_command_dispatch(struct command_base* cbase, struct hub_user*
return 0;
}
struct plugin_callback_data* plugin_callback_data_create()
{
struct plugin_callback_data* data = (struct plugin_callback_data*) hub_malloc_zero(sizeof(struct plugin_callback_data));
LOG_PLUGIN("plugin_callback_data_create()");
data->commands = list_create();
return data;
}
void plugin_callback_data_destroy(struct plugin_callback_data* data)
{
LOG_PLUGIN("plugin_callback_data_destroy()");
if (data->commands)
{
uhub_assert(list_size(data->commands) == 0);
list_destroy(data->commands);
}
hub_free(data);
}
static struct hub_user* convert_user_type(struct plugin_user* user)
{
struct hub_user* huser = (struct hub_user*) user;
@@ -229,3 +209,30 @@ void plugin_register_callback_functions(struct plugin_handle* handle)
void plugin_unregister_callback_functions(struct plugin_handle* handle)
{
}
struct plugin_callback_data* plugin_callback_data_create()
{
struct plugin_callback_data* data = (struct plugin_callback_data*) hub_malloc_zero(sizeof(struct plugin_callback_data));
LOG_PLUGIN("plugin_callback_data_create()");
data->commands = list_create();
return data;
}
void plugin_callback_data_destroy(struct plugin_handle* plugin, struct plugin_callback_data* data)
{
LOG_PLUGIN("plugin_callback_data_destroy()");
if (data->commands)
{
// delete commands not deleted by the plugin itself:
struct plugin_command_handle* cmd = list_get_first(data->commands);
while (cmd)
{
cbfunc_command_del(plugin, cmd);
list_remove(data->commands, cmd);
cmd = list_get_next(data->commands);
}
list_destroy(data->commands);
}
hub_free(data);
}

View File

@@ -24,9 +24,9 @@ struct plugin_handle;
struct uhub_plugin;
extern struct plugin_callback_data* plugin_callback_data_create();
extern void plugin_callback_data_destroy(struct plugin_callback_data* data);
extern void plugin_callback_data_destroy(struct plugin_handle* plugin, struct plugin_callback_data* data);
extern void plugin_register_callback_functions(struct plugin_handle* plugin);
extern void plugin_unregister_callback_functions(struct plugin_handle* plugin);
#endif /* HAVE_UHUB_PLUGIN_CALLBACK_H */
#endif /* HAVE_UHUB_PLUGIN_CALLBACK_H */

View File

@@ -76,7 +76,7 @@ void plugin_close(struct uhub_plugin* plugin)
struct plugin_hub_internals* internals = (struct plugin_hub_internals*) plugin->internals;
LOG_PLUGIN("plugin_close: \"%s\"", plugin->filename);
plugin_callback_data_destroy(internals->callback_data);
plugin_callback_data_destroy(plugin->handle, internals->callback_data);
hub_free(internals);
plugin->internals = NULL;
@@ -162,8 +162,8 @@ struct plugin_handle* plugin_load(const char* filename, const char* config, stru
void plugin_unload(struct plugin_handle* plugin)
{
struct plugin_hub_internals* internals = get_internals(plugin);
plugin_unregister_callback_functions(plugin);
internals->unregister(plugin);
plugin_unregister_callback_functions(plugin);
plugin_close(plugin->handle);
hub_free(plugin);
}

View File

@@ -114,13 +114,6 @@ int net_destroy()
return -1;
}
#ifdef USE_LIBEVENT
struct event_base* net_get_evbase()
{
return net_evbase;
}
#endif
static void net_error_out(int fd, const char* func)
{
int err = net_error();

View File

@@ -51,8 +51,6 @@ extern int net_initialize();
*/
extern int net_destroy();
extern struct event_base* net_get_evbase();
/**
* @return the number of sockets currrently being monitored.
*/

View File

@@ -55,7 +55,7 @@ int net_backend_poll_select(struct net_backend* data, int ms)
struct net_backend_select* backend = (struct net_backend_select*) data;
tval.tv_sec = ms / 1000;
tval.tv_usec = ((ms % 1000) * 1000); // FIXME: correct?
tval.tv_usec = (ms % 1000) * 1000;
FD_ZERO(&backend->rfds);
FD_ZERO(&backend->wfds);

View File

@@ -52,15 +52,15 @@ typedef int (*plugin_command_handler)(struct plugin_handle*, struct plugin_user*
struct plugin_command_handle
{
void* internal_handle; /**<<< "Internal used by the hub only" */
struct plugin_handle* handle; /**<<< "The plugin handle this is associated with" */
const char* prefix; /**<<< "Command prefix, for instance 'help' would be the prefix for the !help command." */
size_t length; /**<<< "Length of the prefix" */
const char* args; /**<<< "Argument codes" */
enum auth_credentials cred; /**<<< "Minimum access level for the command" */
plugin_command_handler handler; /**<<< "Function pointer for the command" */
const char* description; /**<<< "Description for the command" */
const char* origin; /**<<< "Name of plugin where the command originated." */
void* internal_handle; /**<<< "Internal used by the hub only" */
struct plugin_handle* handle; /**<<< "The plugin handle this is associated with" */
const char* prefix; /**<<< "Command prefix, for instance 'help' would be the prefix for the !help command." */
size_t length; /**<<< "Length of the prefix" */
const char* args; /**<<< "Argument codes" */
enum auth_credentials cred; /**<<< "Minimum access level for the command" */
plugin_command_handler handler; /**<<< "Function pointer for the command" */
const char* description; /**<<< "Description for the command" */
const char* origin; /**<<< "Name of plugin where the command originated." */
};
#define PLUGIN_COMMAND_INITIALIZE(PTR, HANDLE, PREFIX, ARGS, CRED, CALLBACK, DESC) \