Command arguments handling + cleanups
Fix bug #185 - Args of !commands lost/damaged. All string arguments were incorrectly freed after being added to the argument list for a command. Instead this fix makes sure it is properly copied into a new string, and by doing so this requires a new API for dealing with hub command arguments in a type safe manner, and also allows for each argument to be cleaned up properly when the command is no longer needed. This also fixes issues with parse errors for certain types, and optional arguments (previously it was impossible to tell the difference for an integer with value 0 or if no integer was given). All arguments can now be accessed through the new functions hub_command_arg_reset() and hub_command_arg_next(). These functions are also exposed to plug-ins. The argument type notations for 'n' has changed to mean nick (string), and 'u' is used for a user (struct hub_user - must be online).
This commit is contained in:
@@ -106,6 +106,8 @@ struct plugin_funcs
|
||||
};
|
||||
|
||||
struct plugin_command_handle;
|
||||
struct plugin_command;
|
||||
struct plugin_command_arg_data;
|
||||
|
||||
typedef int (*hfunc_send_message)(struct plugin_handle*, struct plugin_user* user, const char* message);
|
||||
typedef int (*hfunc_send_status)(struct plugin_handle*, struct plugin_user* to, int code, const char* message);
|
||||
@@ -113,6 +115,9 @@ typedef int (*hfunc_user_disconnect)(struct plugin_handle*, struct plugin_user*
|
||||
typedef int (*hfunc_command_add)(struct plugin_handle*, struct plugin_command_handle*);
|
||||
typedef int (*hfunc_command_del)(struct plugin_handle*, struct plugin_command_handle*);
|
||||
|
||||
typedef size_t (*hfunc_command_arg_reset)(struct plugin_handle*, struct plugin_command*);
|
||||
typedef struct plugin_command_arg_data* (*hfunc_command_arg_next)(struct plugin_handle*, struct plugin_command*, enum plugin_command_arg_type);
|
||||
|
||||
/**
|
||||
* These are functions created and initialized by the hub and which can be used
|
||||
* by plugins to access functionality internal to the hub.
|
||||
@@ -124,9 +129,10 @@ struct plugin_hub_funcs
|
||||
hfunc_user_disconnect user_disconnect;
|
||||
hfunc_command_add command_add;
|
||||
hfunc_command_del command_del;
|
||||
hfunc_command_arg_reset command_arg_reset;
|
||||
hfunc_command_arg_next command_arg_next;
|
||||
};
|
||||
|
||||
|
||||
struct plugin_handle
|
||||
{
|
||||
struct uhub_plugin* handle; /* Must NOT be modified by the plugin */
|
||||
|
||||
Reference in New Issue
Block a user