Compare commits
8 Commits
history_on
...
0.3.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac5811633e | ||
|
|
b3ed3a5526 | ||
|
|
1480b7e9c0 | ||
|
|
50fde1c5c8 | ||
|
|
77faac0494 | ||
|
|
473ff0e159 | ||
|
|
62333c5f39 | ||
|
|
44860c8477 |
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
0.3.2:
|
||||
- Fixed bugs in the kqueue network backend (OSX/BSD)
|
||||
- Rewrote the configuration backend code.
|
||||
- Added support for escaping characters in the configuration files.
|
||||
- Updated the !broadcast command to send private messages instead of main chat messages.
|
||||
- Adding support for redirecting clients to other hubs when they fail to log in.
|
||||
- Fix some out of memory related crashes.
|
||||
- Fixed minor memory leaks.
|
||||
|
||||
|
||||
0.3.1:
|
||||
- Fixed bug where !getip did not work.
|
||||
- Added flood control configuration options.
|
||||
|
||||
6
debian/changelog
vendored
6
debian/changelog
vendored
@@ -1,3 +1,9 @@
|
||||
uhub (0.3.2-1) unstable; urgency=low
|
||||
|
||||
* Updated upstream version.
|
||||
|
||||
-- Jan Vidar Krey <janvidar@extatic.org> Mon 30 May 2010 18:00:00 +0200
|
||||
|
||||
uhub (0.3.1-1) unstable; urgency=low
|
||||
|
||||
* Updated version number.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Summary: High performance ADC p2p hub.
|
||||
Name: uhub
|
||||
Version: 0.3.1
|
||||
Version: 0.3.2
|
||||
Release: 3
|
||||
License: GPLv3
|
||||
Group: Networking/File transfer
|
||||
|
||||
@@ -756,7 +756,7 @@ char* adc_msg_get_argument(struct adc_message* cmd, int offset)
|
||||
else
|
||||
{
|
||||
argument = hub_strdup(&start[1]);
|
||||
if (argument && argument[strlen(argument)-1] == '\n')
|
||||
if (argument && *argument && argument[strlen(argument)-1] == '\n')
|
||||
argument[strlen(argument)-1] = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* uhub - A tiny ADC p2p connection hub
|
||||
* Copyright (C) 2007-2009, Jan Vidar Krey
|
||||
* Copyright (C) 2007-2010, Jan Vidar Krey
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -176,14 +176,10 @@ static int check_cmd_addr(const char* cmd, struct linked_list* list, char* line,
|
||||
|
||||
static int acl_parse_line(char* line, int line_count, void* ptr_data)
|
||||
{
|
||||
char* pos;
|
||||
struct acl_handle* handle = (struct acl_handle*) ptr_data;
|
||||
int ret;
|
||||
|
||||
if ((pos = strchr(line, '#')) != NULL)
|
||||
{
|
||||
pos[0] = 0;
|
||||
}
|
||||
strip_off_ini_line_comments(line, line_count);
|
||||
|
||||
line = strip_white_space(line);
|
||||
if (!*line)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* uhub - A tiny ADC p2p connection hub
|
||||
* Copyright (C) 2007-2009, Jan Vidar Krey
|
||||
* Copyright (C) 2007-2010, Jan Vidar Krey
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -412,11 +412,48 @@ static int command_whoip(struct hub_info* hub, struct hub_user* user, struct hub
|
||||
|
||||
static int command_broadcast(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
|
||||
{
|
||||
struct adc_message* command = adc_msg_construct(ADC_CMD_IMSG, strlen((cmd->message + 12)) + 6);
|
||||
adc_msg_add_argument(command, (cmd->message + 12));
|
||||
size_t offset = 12;
|
||||
#if USE_OLD_BROADCAST_STYLE
|
||||
struct adc_message* command = adc_msg_construct(ADC_CMD_IMSG, strlen((cmd->message + offset)) + 6);
|
||||
adc_msg_add_argument(command, (cmd->message + offset));
|
||||
route_to_all(hub, command);
|
||||
adc_msg_free(command);
|
||||
return 0;
|
||||
#else
|
||||
size_t message_len = strlen(cmd->message + offset);
|
||||
struct adc_message* command = 0;
|
||||
char pm_flag[7] = "PM";
|
||||
char from_sid[5];
|
||||
char buffer[128];
|
||||
size_t recipients = 0;
|
||||
|
||||
memcpy(from_sid, sid_to_string(user->id.sid), sizeof(from_sid));
|
||||
memcpy(pm_flag + 2, from_sid, sizeof(from_sid));
|
||||
|
||||
struct hub_user* target = (struct hub_user*) list_get_first(hub->users->list);
|
||||
while (target)
|
||||
{
|
||||
if (target != user)
|
||||
{
|
||||
recipients++;
|
||||
command = adc_msg_construct(ADC_CMD_DMSG, message_len + 23);
|
||||
if (!command)
|
||||
break;
|
||||
|
||||
adc_msg_add_argument(command, from_sid);
|
||||
adc_msg_add_argument(command, sid_to_string(target->id.sid));
|
||||
adc_msg_add_argument(command, (cmd->message + offset));
|
||||
adc_msg_add_argument(command, pm_flag);
|
||||
|
||||
route_to_user(hub, target, command);
|
||||
adc_msg_free(command);
|
||||
}
|
||||
target = (struct hub_user*) list_get_next(hub->users->list);
|
||||
}
|
||||
|
||||
snprintf(buffer, sizeof(buffer), "*** %s: Delivered to " PRINTF_SIZE_T " user%s", cmd->prefix, recipients, (recipients != 1 ? "s" : ""));
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int command_history(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
|
||||
|
||||
@@ -85,10 +85,7 @@ static int config_parse_line(char* line, int line_count, void* ptr_data)
|
||||
char* data;
|
||||
struct hub_config* config = (struct hub_config*) ptr_data;
|
||||
|
||||
if ((pos = strchr(line, '#')) != NULL)
|
||||
{
|
||||
pos[0] = 0;
|
||||
}
|
||||
strip_off_ini_line_comments(line, line_count);
|
||||
|
||||
if (!*line) return 0;
|
||||
|
||||
|
||||
@@ -257,9 +257,15 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc
|
||||
int relay = 1;
|
||||
int offset;
|
||||
|
||||
if (!message || !user_is_logged_in(u))
|
||||
if (!message)
|
||||
return 0;
|
||||
|
||||
if (!user_is_logged_in(u))
|
||||
{
|
||||
hub_free(message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((cmd->cache[0] == 'B') && (message[0] == '!' || message[0] == '+'))
|
||||
{
|
||||
/*
|
||||
@@ -480,11 +486,11 @@ void hub_send_flood_warning(struct hub_info* hub, struct hub_user* u, const char
|
||||
adc_msg_add_argument(msg, "110");
|
||||
adc_msg_add_argument(msg, tmp);
|
||||
hub_free(tmp);
|
||||
}
|
||||
|
||||
route_to_user(hub, u, msg);
|
||||
user_flag_set(u, flag_flood);
|
||||
adc_msg_free(msg);
|
||||
}
|
||||
}
|
||||
|
||||
static void hub_event_dispatcher(void* callback_data, struct event_data* message)
|
||||
@@ -944,7 +950,7 @@ void hub_send_status(struct hub_info* hub, struct hub_user* user, enum status_me
|
||||
struct adc_message* cmd = adc_msg_construct(ADC_CMD_ISTA, 6);
|
||||
struct adc_message* qui = adc_msg_construct(ADC_CMD_IQUI, 512);
|
||||
char code[4];
|
||||
char buf[250];
|
||||
char buf[256];
|
||||
const char* text = 0;
|
||||
const char* flag = 0;
|
||||
char* escaped_text = 0;
|
||||
|
||||
@@ -92,9 +92,10 @@ static void probe_net_event(struct net_connection* con, int events, void *arg)
|
||||
net_con_ssl_handshake(con, net_con_ssl_mode_server, probe->hub->ssl_ctx);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
probe_destroy(probe);
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,11 +79,8 @@ int net_backend_init()
|
||||
timeout_queue_initialize(&g_backend->timeout_queue, g_backend->now, 120); /* FIXME: max 120 secs! */
|
||||
g_backend->cleaner = net_cleanup_initialize(g_backend->common.max);
|
||||
|
||||
for (n = 0; n < sizeof(net_backend_init_funcs); n++)
|
||||
for (n = 0; net_backend_init_funcs[n]; n++)
|
||||
{
|
||||
if (!net_backend_init_funcs[n])
|
||||
break;
|
||||
|
||||
g_backend->data = net_backend_init_funcs[n](&g_backend->handler, &g_backend->common);
|
||||
if (g_backend->data)
|
||||
{
|
||||
|
||||
@@ -32,19 +32,29 @@ struct net_connection_kqueue
|
||||
NET_CON_STRUCT_COMMON
|
||||
struct kevent ev_r;
|
||||
struct kevent ev_w;
|
||||
int change;
|
||||
};
|
||||
|
||||
struct net_backend_kqueue
|
||||
{
|
||||
int kqfd;
|
||||
struct net_connection_kqueue** conns;
|
||||
struct kevent** changes;
|
||||
size_t nchanges;
|
||||
struct kevent* changes;
|
||||
int* change_list;
|
||||
size_t change_list_len;
|
||||
struct kevent events[KQUEUE_EVBUFFER];
|
||||
struct net_backend_common* common;
|
||||
};
|
||||
|
||||
#define CHANGE_ACTION_ADD 0x0001
|
||||
#define CHANGE_ACTION_MOD 0x0002
|
||||
#define CHANGE_ACTION_DEL 0x0004
|
||||
#define CHANGE_OP_WANT_READ 0x0100
|
||||
#define CHANGE_OP_WANT_WRITE 0x0200
|
||||
|
||||
static void net_backend_set_handlers(struct net_backend_handler* handler);
|
||||
static void add_change(struct net_backend_kqueue* backend, struct net_connection_kqueue* con, int actions);
|
||||
static size_t create_change_list(struct net_backend_kqueue* backend);
|
||||
|
||||
const char* net_backend_name_kqueue()
|
||||
{
|
||||
@@ -56,12 +66,13 @@ int net_backend_poll_kqueue(struct net_backend* data, int ms)
|
||||
int res;
|
||||
struct timespec tspec = { 0, };
|
||||
struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data;
|
||||
size_t changes;
|
||||
|
||||
tspec.tv_sec = (ms / 1000);
|
||||
tspec.tv_nsec = ((ms % 1000) * 1000000);
|
||||
|
||||
res = kevent(backend->kqfd, *backend->changes, backend->nchanges, backend->events, KQUEUE_EVBUFFER, &tspec);
|
||||
backend->nchanges = 0;
|
||||
changes = create_change_list(backend);
|
||||
res = kevent(backend->kqfd, backend->changes, changes, backend->events, KQUEUE_EVBUFFER, &tspec);
|
||||
|
||||
if (res == -1 && errno == EINTR)
|
||||
return 0;
|
||||
@@ -76,12 +87,14 @@ void net_backend_process_kqueue(struct net_backend* data, int res)
|
||||
for (n = 0; n < res; n++)
|
||||
{
|
||||
struct net_connection_kqueue* con = (struct net_connection_kqueue*) backend->events[n].udata;
|
||||
int ev = -1;
|
||||
if (con && con->sd >= 0 && backend->conns[con->sd])
|
||||
{
|
||||
int ev = 0;
|
||||
if (backend->events[n].filter == EVFILT_READ) ev = NET_EVENT_READ;
|
||||
else if (backend->events[n].filter == EVFILT_WRITE) ev = NET_EVENT_WRITE;
|
||||
if (con)
|
||||
net_con_callback((struct net_connection*) con, ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct net_connection* net_con_create_kqueue(struct net_backend* data)
|
||||
@@ -102,58 +115,37 @@ void net_con_initialize_kqueue(struct net_backend* data, struct net_connection*
|
||||
|
||||
void net_con_backend_add_kqueue(struct net_backend* data, struct net_connection* con_, int events)
|
||||
{
|
||||
unsigned short flags_r = EV_ADD;
|
||||
unsigned short flags_w = EV_ADD;
|
||||
struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data;
|
||||
struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_;
|
||||
int operation;
|
||||
|
||||
backend->conns[con->sd] = con;
|
||||
|
||||
if (events & NET_EVENT_READ)
|
||||
flags_r |= EV_ENABLE;
|
||||
else
|
||||
flags_r |= EV_DISABLE;
|
||||
operation = CHANGE_ACTION_ADD;
|
||||
|
||||
EV_SET(&con->ev_r, con->sd, EVFILT_READ, flags_r, 0, 0, con);
|
||||
backend->changes[backend->nchanges++] = &con->ev_r;
|
||||
if (events & NET_EVENT_READ)
|
||||
operation |= CHANGE_OP_WANT_READ;
|
||||
|
||||
if (events & NET_EVENT_WRITE)
|
||||
flags_w |= EV_ENABLE;
|
||||
else
|
||||
flags_w |= EV_DISABLE;
|
||||
operation |= CHANGE_OP_WANT_WRITE;
|
||||
|
||||
EV_SET(&con->ev_w, con->sd, EVFILT_WRITE, flags_w, 0, 0, con);
|
||||
backend->changes[backend->nchanges++] = &con->ev_w;
|
||||
add_change(backend, con, operation);
|
||||
}
|
||||
|
||||
void net_con_backend_mod_kqueue(struct net_backend* data, struct net_connection* con_, int events)
|
||||
{
|
||||
unsigned short flags_r = 0;
|
||||
unsigned short flags_w = 0;
|
||||
struct net_backend_kqueue* backend = (struct net_backend_kqueue*) data;
|
||||
struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_;
|
||||
|
||||
if (events & NET_EVENT_READ)
|
||||
flags_r |= EV_ENABLE;
|
||||
else
|
||||
flags_r |= EV_DISABLE;
|
||||
int operation = CHANGE_ACTION_ADD;
|
||||
|
||||
if (!(con->ev_r.flags & flags_r))
|
||||
{
|
||||
EV_SET(&con->ev_r, con->sd, EVFILT_READ, flags_r, 0, 0, con);
|
||||
backend->changes[backend->nchanges++] = &con->ev_r;
|
||||
}
|
||||
if (events & NET_EVENT_READ)
|
||||
operation |= CHANGE_OP_WANT_READ;
|
||||
|
||||
if (events & NET_EVENT_WRITE)
|
||||
flags_r |= EV_ENABLE;
|
||||
else
|
||||
flags_r |= EV_DISABLE;
|
||||
operation |= CHANGE_OP_WANT_WRITE;
|
||||
|
||||
if (!(con->ev_w.flags & flags_w))
|
||||
{
|
||||
EV_SET(&con->ev_w, con->sd, EVFILT_WRITE, flags_w, 0, 0, con);
|
||||
backend->changes[backend->nchanges++] = &con->ev_w;
|
||||
}
|
||||
add_change(backend, con, operation);
|
||||
}
|
||||
|
||||
void net_con_backend_del_kqueue(struct net_backend* data, struct net_connection* con_)
|
||||
@@ -162,11 +154,8 @@ void net_con_backend_del_kqueue(struct net_backend* data, struct net_connection*
|
||||
struct net_connection_kqueue* con = (struct net_connection_kqueue*) con_;
|
||||
|
||||
/* No need to remove it from the kqueue filter, the kqueue man page says
|
||||
it is automatically removed when the descriptor is closed. */
|
||||
EV_SET(&con->ev_r, con->sd, EVFILT_READ, EV_DELETE, 0, 0, 0);
|
||||
backend->changes[backend->nchanges++] = &con->ev_r;
|
||||
EV_SET(&con->ev_w, con->sd, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
|
||||
backend->changes[backend->nchanges++] = &con->ev_w;
|
||||
it is automatically removed when the descriptor is closed... */
|
||||
add_change(backend, con, CHANGE_ACTION_DEL);
|
||||
|
||||
// Unmap the socket descriptor.
|
||||
backend->conns[con->sd] = 0;
|
||||
@@ -178,6 +167,7 @@ void net_backend_shutdown_kqueue(struct net_backend* data)
|
||||
close(backend->kqfd);
|
||||
hub_free(backend->conns);
|
||||
hub_free(backend->changes);
|
||||
hub_free(backend->change_list);
|
||||
hub_free(backend);
|
||||
}
|
||||
|
||||
@@ -197,8 +187,8 @@ struct net_backend* net_backend_init_kqueue(struct net_backend_handler* handler,
|
||||
}
|
||||
|
||||
backend->conns = hub_malloc_zero(sizeof(struct net_connection_kqueue*) * common->max);
|
||||
backend->conns = hub_malloc_zero(sizeof(struct net_connection_kqueue*) * common->max);
|
||||
backend->changes = hub_malloc_zero(sizeof(struct kevent*) * common->max * 2);
|
||||
backend->changes = hub_malloc_zero(sizeof(struct kevent) * common->max * 2);
|
||||
backend->change_list = hub_malloc_zero(sizeof(int) * common->max);
|
||||
backend->common = common;
|
||||
|
||||
net_backend_set_handlers(handler);
|
||||
@@ -218,4 +208,71 @@ static void net_backend_set_handlers(struct net_backend_handler* handler)
|
||||
handler->con_del = net_con_backend_del_kqueue;
|
||||
}
|
||||
|
||||
static void add_change(struct net_backend_kqueue* backend, struct net_connection_kqueue* con, int actions)
|
||||
{
|
||||
if (actions && !con->change)
|
||||
{
|
||||
backend->change_list[backend->change_list_len++] = con->sd;
|
||||
con->change = actions;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t create_change_list(struct net_backend_kqueue* backend)
|
||||
{
|
||||
size_t n = 0;
|
||||
size_t changes = 0;
|
||||
int sd;
|
||||
struct net_connection_kqueue* con;
|
||||
unsigned short flags_r = 0;
|
||||
unsigned short flags_w = 0;
|
||||
|
||||
for (; n < backend->change_list_len; n++)
|
||||
{
|
||||
sd = backend->change_list[n];
|
||||
con = backend->conns[sd];
|
||||
if (con)
|
||||
{
|
||||
flags_r = 0;
|
||||
flags_w = 0;
|
||||
|
||||
if (con->change & CHANGE_ACTION_ADD)
|
||||
{
|
||||
flags_r |= EV_ADD;
|
||||
flags_w |= EV_ADD;
|
||||
}
|
||||
|
||||
if (con->change & CHANGE_OP_WANT_READ)
|
||||
flags_r |= EV_ENABLE;
|
||||
else
|
||||
flags_r |= EV_DISABLE;
|
||||
|
||||
if (con->change & CHANGE_OP_WANT_WRITE)
|
||||
flags_w |= EV_ENABLE;
|
||||
else
|
||||
flags_w |= EV_DISABLE;
|
||||
|
||||
if (con->ev_r.flags != flags_r)
|
||||
{
|
||||
EV_SET(&con->ev_r, sd, EVFILT_READ, flags_r, 0, 0, con);
|
||||
memcpy(&backend->changes[changes++], &con->ev_r, sizeof(struct kevent));
|
||||
}
|
||||
|
||||
if (con->ev_w.flags != flags_w)
|
||||
{
|
||||
EV_SET(&con->ev_w, sd, EVFILT_WRITE, flags_w, 0, 0, con);
|
||||
memcpy(&backend->changes[changes++], &con->ev_w, sizeof(struct kevent));
|
||||
}
|
||||
|
||||
con->change = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
EV_SET(&backend->changes[changes++], sd, EVFILT_READ, EV_DELETE, 0, 0, 0);
|
||||
EV_SET(&backend->changes[changes++], sd, EVFILT_READ, EV_DELETE, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
backend->change_list_len = 0;
|
||||
return changes;
|
||||
}
|
||||
|
||||
#endif /* USE_KQUEUE */
|
||||
|
||||
@@ -400,3 +400,51 @@ const char* get_timestamp(time_t now)
|
||||
sprintf(ts, "[%02d:%02d]", t->tm_hour, t->tm_min);
|
||||
return ts;
|
||||
}
|
||||
|
||||
void strip_off_ini_line_comments(char* line, int line_count)
|
||||
{
|
||||
char* p = line;
|
||||
char* out = line;
|
||||
int backslash = 0;
|
||||
|
||||
if (!*line)
|
||||
return;
|
||||
|
||||
for (; *p; p++)
|
||||
{
|
||||
if (!backslash)
|
||||
{
|
||||
if (*p == '\\')
|
||||
{
|
||||
backslash = 1;
|
||||
}
|
||||
else if (*p == '#')
|
||||
{
|
||||
*out = '\0';
|
||||
out++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = *p;
|
||||
out++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*p == '\\' || *p == '#' || *p == '\"')
|
||||
{
|
||||
*out = *p;
|
||||
out++;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_WARN("Invalid backslash escape on line %d", line_count);
|
||||
*out = *p;
|
||||
out++;
|
||||
}
|
||||
backslash = 0;
|
||||
}
|
||||
}
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
@@ -33,10 +33,12 @@ extern int is_valid_base32_char(char c);
|
||||
extern void base32_encode(const unsigned char* buffer, size_t len, char* result);
|
||||
extern void base32_decode(const char* src, unsigned char* dst, size_t len);
|
||||
extern char* strip_white_space(char* string);
|
||||
extern void strip_off_ini_line_comments(char* line, int line_count);
|
||||
|
||||
extern int file_read_lines(const char* file, void* data, file_line_handler_t handler);
|
||||
|
||||
|
||||
|
||||
extern const char* uhub_itoa(int val);
|
||||
extern const char* uhub_ulltoa(uint64_t val);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user