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

8
.gitignore vendored
View File

@ -7,3 +7,11 @@ uhub-admin
adcrush adcrush
uhub uhub
revision.h* revision.h*
build-stamp
debian/files
debian/uhub.debhelper.log
debian/uhub.postinst.debhelper
debian/uhub.postrm.debhelper
debian/uhub.prerm.debhelper
debian/uhub.substvars
uhub-passwd

View File

@ -355,7 +355,5 @@ dist-clean:
@rm -rf $(all_OBJECTS) *~ core @rm -rf $(all_OBJECTS) *~ core
clean: clean:
@rm -rf $(libuhub_OBJECTS) *~ core $(uhub_BINARY) $(admin_BINARY) $(autotest_BINARY) $(adcrush_BINARY) $(all_OBJECTS) $(all_plugins) autotest.c revision.h revision.h.tmp && \ @rm -rf $(libuhub_OBJECTS) *~ core $(uhub_BINARY) $(uhub-passwd_BINARY) $(admin_BINARY) $(autotest_BINARY) $(adcrush_BINARY) $(all_OBJECTS) $(all_plugins) autotest.c revision.h revision.h.tmp && \
echo $(MSG_CLEAN) echo $(MSG_CLEAN)

2
README
View File

@ -4,5 +4,5 @@ For the official documentation, bugs and other information, please visit:
http://www.uhub.org/ http://www.uhub.org/
For a list of compatible ADC clients, see: For a list of compatible ADC clients, see:
http://www.adcportal.com/wiki/index.php/ADC_Software_List#Client_Software http://en.wikipedia.org/wiki/Advanced_Direct_Connect#Client_software

4
debian/changelog vendored
View File

@ -2,13 +2,13 @@ uhub (0.3.2-1) unstable; urgency=low
* Updated upstream version. * Updated upstream version.
-- Jan Vidar Krey <janvidar@extatic.org> Mon 30 May 2010 18:00:00 +0200 -- Jan Vidar Krey <janvidar@extatic.org> Mon, 30 May 2010 18:00:00 +0200
uhub (0.3.1-1) unstable; urgency=low uhub (0.3.1-1) unstable; urgency=low
* Updated version number. * Updated version number.
-- Jan Vidar Krey <janvidar@extatic.org> Mon 04 Apr 2010 16:44:21 +0200 -- Jan Vidar Krey <janvidar@extatic.org> Mon, 04 Apr 2010 16:44:21 +0200
uhub (0.3.0-2) unstable; urgency=low uhub (0.3.0-2) unstable; urgency=low

View File

@ -1,13 +1,13 @@
= Architecture of uHub = = Architecture of uHub =
uHub is single threaded and handles network and timer events using the uHub is single-threaded and handles network and timer events using the
libevent library. libevent library.
For each state there is a read event (and sometimes a write event) and timeout For each state there is a read event (and sometimes a write event) and timeout
event in case an expected read (or write) event does not occur. event in case an expected read (or write) event does not occur.
== Protocol overview == == Protocol overview ==
uHub use "speak" the ADC protocol, which works in short as follows: uHub "speaks" the ADC protocol, which works in short as follows:
(C = client, S = server aka uHub). (C = client, S = server aka uHub).
C: HSUP ADBASE C: HSUP ADBASE

View File

@ -1,7 +1,7 @@
How to compile: How to compile:
--------------- ---------------
See the official compiling howto: http://www.extatic.org/uhub/compile.html See the official compiling howto: http://www.uhub.org/compile.php
Prerequisites Prerequisites

View File

@ -31,7 +31,7 @@ The hub should send a packet containing the token back:
'IECH {token} {host:port}', aswell as the same message via TCP. 'IECH {token} {host:port}', aswell as the same message via TCP.
If the client receives the message via UDP, it should now be able to determine the type of NAT. If the client receives the message via UDP, it should now be able to determine the type of NAT.
If the client receives the message via TCP only it knows it has a firewall blocking icomming communication. If the client receives the message via TCP only it knows it has a firewall blocking incomming communication.
If the client does not receive the message, it should assume a firewall is blocking all UDP communication, If the client does not receive the message, it should assume a firewall is blocking all UDP communication,
and resume in passive mode. and resume in passive mode.

View File

@ -186,7 +186,10 @@ static enum command_parse_status command_extract_arguments(struct command_base*
if (!token || !*token) 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; break;
} }
@ -284,7 +287,7 @@ static enum command_parse_status command_extract_arguments(struct command_base*
{ {
hub_free(data); hub_free(data);
data = NULL; data = NULL;
return cmd_status_arg_number; status = cmd_status_arg_number;
} }
break; break;
@ -387,10 +390,13 @@ void command_get_syntax(struct command_handle* handler, struct cbuffer* buf)
{ {
for (n = 0; n < strlen(handler->args); n++) 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]) switch (handler->args[n])
{ {
case '?': cbuf_append(buf, "["); opt = 1; continue; case '?': opt = 1; continue;
case 'n': cbuf_append(buf, "<nick>"); break; case 'n': cbuf_append(buf, "<nick>"); break;
case 'u': cbuf_append(buf, "<user>"); break; case 'u': cbuf_append(buf, "<user>"); break;
case 'i': cbuf_append(buf, "<cid>"); 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; case 'N': cbuf_append(buf, "<number>"); break;
} }
if (opt) if (opt)
{ opt++;
cbuf_append(buf, "]");
opt = 0;
}
} }
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("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("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("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("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("reload", 6, "", auth_cred_admin, command_reload, "Reload configuration files." );
ADD_COMMAND("shutdown", 8, "", auth_cred_admin, command_shutdown_hub, "Shutdown hub." ); 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." */ const char* message; /**<<< "The complete message." */
char* prefix; /**<<< "The prefix extracted from the 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." */ enum command_parse_status status; /**<<< "Status of the hub_command." */
command_handler handler; /**<<< "The function handler to call in order to invoke this 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." */ 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; 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) static struct hub_user* convert_user_type(struct plugin_user* user)
{ {
struct hub_user* huser = (struct hub_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) 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; struct uhub_plugin;
extern struct plugin_callback_data* plugin_callback_data_create(); 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_register_callback_functions(struct plugin_handle* plugin);
extern void plugin_unregister_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; struct plugin_hub_internals* internals = (struct plugin_hub_internals*) plugin->internals;
LOG_PLUGIN("plugin_close: \"%s\"", plugin->filename); 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); hub_free(internals);
plugin->internals = NULL; 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) void plugin_unload(struct plugin_handle* plugin)
{ {
struct plugin_hub_internals* internals = get_internals(plugin); struct plugin_hub_internals* internals = get_internals(plugin);
plugin_unregister_callback_functions(plugin);
internals->unregister(plugin); internals->unregister(plugin);
plugin_unregister_callback_functions(plugin);
plugin_close(plugin->handle); plugin_close(plugin->handle);
hub_free(plugin); hub_free(plugin);
} }

View File

@ -114,13 +114,6 @@ int net_destroy()
return -1; 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) static void net_error_out(int fd, const char* func)
{ {
int err = net_error(); int err = net_error();

View File

@ -51,8 +51,6 @@ extern int net_initialize();
*/ */
extern int net_destroy(); extern int net_destroy();
extern struct event_base* net_get_evbase();
/** /**
* @return the number of sockets currrently being monitored. * @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; struct net_backend_select* backend = (struct net_backend_select*) data;
tval.tv_sec = ms / 1000; 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->rfds);
FD_ZERO(&backend->wfds); 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 struct plugin_command_handle
{ {
void* internal_handle; /**<<< "Internal used by the hub only" */ void* internal_handle; /**<<< "Internal used by the hub only" */
struct plugin_handle* handle; /**<<< "The plugin handle this is associated with" */ 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." */ const char* prefix; /**<<< "Command prefix, for instance 'help' would be the prefix for the !help command." */
size_t length; /**<<< "Length of the prefix" */ size_t length; /**<<< "Length of the prefix" */
const char* args; /**<<< "Argument codes" */ const char* args; /**<<< "Argument codes" */
enum auth_credentials cred; /**<<< "Minimum access level for the command" */ enum auth_credentials cred; /**<<< "Minimum access level for the command" */
plugin_command_handler handler; /**<<< "Function pointer for the command" */ plugin_command_handler handler; /**<<< "Function pointer for the command" */
const char* description; /**<<< "Description for the command" */ const char* description; /**<<< "Description for the command" */
const char* origin; /**<<< "Name of plugin where the command originated." */ const char* origin; /**<<< "Name of plugin where the command originated." */
}; };
#define PLUGIN_COMMAND_INITIALIZE(PTR, HANDLE, PREFIX, ARGS, CRED, CALLBACK, DESC) \ #define PLUGIN_COMMAND_INITIALIZE(PTR, HANDLE, PREFIX, ARGS, CRED, CALLBACK, DESC) \