Removed ADC_UDP_OPERATION code as it is not used or needed. on_kick is also gone.

This commit is contained in:
Jan Vidar Krey 2009-05-16 03:14:20 +02:00
parent 953db2dcbc
commit 548867de10
7 changed files with 24 additions and 219 deletions

156
src/hub.c
View File

@ -39,10 +39,6 @@ int hub_handle_message(struct hub_info* hub, struct user* u, const char* line, s
case ADC_CMD_HSUP: ret = hub_handle_support(hub, u, cmd); break;
case ADC_CMD_HPAS: ret = hub_handle_password(hub, u, cmd); break;
case ADC_CMD_BINF: ret = hub_handle_info(hub, u, cmd); break;
#ifdef ADC_UDP_OPERATION
case ADC_CMD_HCHK: ret = hub_handle_autocheck(hub, u, cmd); break;
#endif
case ADC_CMD_DINF:
case ADC_CMD_EINF:
case ADC_CMD_FINF:
@ -206,51 +202,6 @@ int hub_handle_chat_message(struct hub_info* hub, struct user* u, struct adc_mes
return ret;
}
int on_kick(struct user* u, struct adc_message* cmd)
{
hub_log(log_error, "on_kick() not implemented");
return -1;
}
#ifdef ADC_UDP_OPERATION
int hub_handle_autocheck(struct user* u, struct adc_message* cmd)
{
char* port_str = adc_msg_get_argument(cmd, 0);
char* token = adc_msg_get_argument(cmd, 1);
int port = 0;
if (!port_str || !token || strlen(token) != 4)
{
hub_free(port_str);
hub_free(token);
return -1;
}
port = uhub_atoi(port_str);
if (port == 0 || port > 65535)
{
hub_free(port_str);
hub_free(token);
return -1;
}
hub_send_autocheck(u, port, token);
hub_free(port_str);
hub_free(token);
return 0;
}
#endif
#ifdef ADC_UDP_OPERATION
void hub_send_autocheck(struct user* u, uint16_t port, const char* token)
{
}
#endif
void hub_send_support(struct hub_info* hub, struct user* u)
{
if (user_is_connecting(u) || user_is_logged_in(u))
@ -266,7 +217,7 @@ void hub_send_sid(struct hub_info* hub, struct user* u)
if (user_is_connecting(u))
{
command = adc_msg_construct(ADC_CMD_ISID, 10);
u->id.sid = user_manager_get_free_sid(hub);
u->id.sid = uman_get_free_sid(hub);
adc_msg_add_argument(command, (const char*) sid_to_string(u->id.sid));
route_to_user(u, command);
adc_msg_free(command);
@ -410,7 +361,7 @@ static void hub_event_dispatcher(void* callback_data, struct event_data* message
case UHUB_EVENT_USER_QUIT:
{
user_manager_remove(hub, (struct user*) message->ptr);
uman_remove(hub, (struct user*) message->ptr);
send_quit_message((struct user*) message->ptr);
on_logout_user(hub, (struct user*) message->ptr);
user_schedule_destroy((struct user*) message->ptr);
@ -434,12 +385,9 @@ static void hub_event_dispatcher(void* callback_data, struct event_data* message
struct hub_info* hub_start_service(struct hub_config* config)
{
struct hub_info* hub = 0;
int server_tcp, ret, ipv6_supported, af;
#ifdef ADC_UDP_OPERATION
int server_udp;
#endif
struct sockaddr_storage addr;
socklen_t sockaddr_size;
int server_tcp, ret, ipv6_supported, af;
char address_buf[INET6_ADDRSTRLEN+1];
hub = hub_malloc_zero(sizeof(struct hub_info));
@ -497,66 +445,24 @@ struct hub_info* hub_start_service(struct hub_config* config)
return 0;
}
#ifdef ADC_UDP_OPERATION
server_udp = net_socket_create(af, SOCK_DGRAM, IPPROTO_UDP);
if (server_udp == -1)
{
event_base_free(hub->evbase);
hub_free(hub);
return 0;
}
#endif
ret = net_set_reuseaddress(server_tcp, 1);
if (ret == -1)
{
event_base_free(hub->evbase);
hub_free(hub);
net_close(server_tcp);
#ifdef ADC_UDP_OPERATION
net_close(server_udp);
#endif
return 0;
}
#ifdef ADC_UDP_OPERATION
ret = net_set_reuseaddress(server_udp, 1);
if (ret == -1)
{
event_base_free(hub->evbase);
hub_free(hub);
net_close(server_tcp);
net_close(server_udp);
return 0;
}
#endif
ret = net_set_nonblocking(server_tcp, 1);
if (ret == -1)
{
event_base_free(hub->evbase);
hub_free(hub);
net_close(server_tcp);
#ifdef ADC_UDP_OPERATION
net_close(server_udp);
#endif
return 0;
}
#ifdef ADC_UDP_OPERATION
ret = net_set_nonblocking(server_udp, 1);
if (ret == -1)
{
event_base_free(hub->evbase);
hub_free(hub);
net_close(server_tcp);
net_close(server_udp);
return 0;
}
#endif
ret = net_bind(server_tcp, (struct sockaddr*) &addr, sockaddr_size);
if (ret == -1)
{
@ -564,25 +470,9 @@ struct hub_info* hub_start_service(struct hub_config* config)
event_base_free(hub->evbase);
hub_free(hub);
net_close(server_tcp);
#ifdef ADC_UDP_OPERATION
net_close(server_udp);
#endif
return 0;
}
#ifdef ADC_UDP_OPERATION
ret = net_bind(server_udp, (struct sockaddr*) &addr, sockaddr_size);
if (ret == -1)
{
hub_log(log_fatal, "hub_start_service(): Unable to bind to UDP local address. errno=%d, str=%s", net_error(), net_error_string(net_error()));
event_base_free(hub->evbase);
hub_free(hub);
net_close(server_tcp);
net_close(server_udp);
return 0;
}
#endif
ret = net_listen(server_tcp, SERVER_BACKLOG);
if (ret == -1)
{
@ -590,26 +480,17 @@ struct hub_info* hub_start_service(struct hub_config* config)
event_base_free(hub->evbase);
hub_free(hub);
net_close(server_tcp);
#ifdef ADC_UDP_OPERATION
net_close(server_udp);
#endif
return 0;
}
hub->fd_tcp = server_tcp;
#ifdef ADC_UDP_OPERATION
hub->fd_udp = server_udp;
#endif
hub->config = config;
hub->users = NULL;
if (user_manager_init(hub) == -1)
if (uman_init(hub) == -1)
{
hub_free(hub);
net_close(server_tcp);
#ifdef ADC_UDP_OPERATION
net_close(server_udp);
#endif
return 0;
}
@ -617,36 +498,17 @@ struct hub_info* hub_start_service(struct hub_config* config)
event_base_set(hub->evbase, &hub->ev_accept);
if (event_add(&hub->ev_accept, NULL) == -1)
{
user_manager_shutdown(hub);
uman_shutdown(hub);
hub_free(hub);
net_close(server_tcp);
#ifdef ADC_UDP_OPERATION
net_close(server_udp);
#endif
return 0;
}
#ifdef ADC_UDP_OPERATION
event_set(&hub->ev_datagram, hub->fd_udp, EV_READ | EV_PERSIST, net_on_packet, hub);
event_base_set(hub->evbase, &hub->ev_datagram);
if (event_add(&hub->ev_datagram, NULL) == -1)
{
user_manager_shutdown(hub);
hub_free(hub);
net_close(server_tcp);
net_close(server_udp);
return 0;
}
#endif
if (event_queue_initialize(&hub->queue, hub_event_dispatcher, (void*) hub) == -1)
{
user_manager_shutdown(hub);
uman_shutdown(hub);
hub_free(hub);
net_close(server_tcp);
#ifdef ADC_UDP_OPERATION
net_close(server_udp);
#endif
return 0;
}
@ -662,12 +524,8 @@ void hub_shutdown_service(struct hub_info* hub)
event_queue_shutdown(hub->queue);
event_del(&hub->ev_accept);
#ifdef ADC_UDP_OPERATION
event_del(&hub->ev_datagram);
net_close(hub->fd_udp);
#endif
net_close(hub->fd_tcp);
user_manager_shutdown(hub);
uman_shutdown(hub);
hub->status = hub_status_stopped;
event_base_free(hub->evbase);
hub_free(hub);

View File

@ -82,14 +82,8 @@ struct hub_stats
struct hub_info
{
int fd_tcp;
#ifdef ADC_UDP_OPERATION
int fd_udp;
#endif
struct event ev_accept;
struct event ev_timer;
#ifdef ADC_UDP_OPERATION
struct event ev_datagram;
#endif
struct hub_stats stats;
struct event_queue* queue;
struct event_base* evbase;
@ -150,20 +144,6 @@ extern int hub_handle_info_check_nick(struct hub_info* hub, struct user* u, str
*/
extern int hub_handle_info_check_cid(struct hub_info* hub, struct user* u, struct adc_message* cmd);
/**
* Can only be used by administrators or operators.
*
* @return 0 on success, -1 on error
*/
extern int hub_handle_kick(struct hub_info* hub, struct user* u, struct adc_message* cmd);
#ifdef ADC_UDP_OPERATION
/**
* Handle incoming autocheck message.
*/
extern int hub_handle_autocheck(struct hub_info* hub, struct user* u, struct adc_message* cmd);
#endif
/**
* Send the support line for the hub to a particular user.
* Only used during the initial handshake.
@ -212,15 +192,6 @@ extern void hub_send_password_challenge(struct hub_info* hub, struct user* u);
*/
extern void hub_send_status(struct hub_info*, struct user* user, enum status_message msg, enum msg_status_level level);
#ifdef ADC_UDP_OPERATION
/**
* Send an autocheck message to a user.
* This is basically a UDP message. The user's client can then determine
* if UDP communication works by either hole punching or configuring UPnP.
*/
extern void hub_send_autocheck(struct hub_info* hub, struct user* u, uint16_t port, const char* token);
#endif
/**
* Allocates memory, initializes the hub based on the configuration,
* and returns a hub handle.

View File

@ -57,7 +57,7 @@ void on_login_success(struct hub_info* hub, struct user* u)
/* Mark as being in the normal state, and add user to the user list */
user_set_state(u, state_normal);
user_manager_add(hub, u);
uman_add(hub, u);
/* Print log message */
log_user_login(u);

View File

@ -317,19 +317,3 @@ void net_on_accept(int server_fd, short ev, void *arg)
}
}
#ifdef ADC_UDP_OPERATION
extern void net_on_packet(int fd, short ev, void *arg)
{
static char buffer[1024] = {0,};
// struct hub_info* hub = (struct hub_info*) arg;
// struct user* user = 0;
ssize_t size;
struct sockaddr_storage from;
socklen_t fromlen;
size = recvfrom(fd, buffer, 1024, 0, (struct sockaddr*) &from, &fromlen);
// FIXME: A plugin should handle this!
hub_log(log_info, "Datagram [%s] (%d bytes)", buffer, (int) size);
}
#endif

View File

@ -40,13 +40,5 @@ extern void net_on_read_timeout(int fd, short ev, void* arg);
*/
extern void net_on_accept(int fd, short ev, void *arg);
#ifdef ADC_UDP_OPERATION
/**
* Network callback to receive incoming UDP datagram.
*/
extern void net_on_packet(int fd, short ev, void *arg);
#endif
#endif /* HAVE_UHUB_NET_EVENT_H */

View File

@ -21,7 +21,7 @@
/*
* This callback function is used to clear user objects from the userlist.
* Should only be used in user_manager_shutdown().
* Should only be used in uman_shutdown().
*/
static void clear_user_list_callback(void* ptr)
{
@ -39,7 +39,7 @@ static void clear_user_list_callback(void* ptr)
}
void user_manager_update_stats(struct hub_info* hub)
void uman_update_stats(struct hub_info* hub)
{
const int factor = TIMEOUT_STATS;
struct net_statistics* total;
@ -57,7 +57,7 @@ void user_manager_update_stats(struct hub_info* hub)
}
void user_manager_print_stats(struct hub_info* hub)
void uman_print_stats(struct hub_info* hub)
{
hub_log(log_info, "Statistics users=%zu (peak_users=%zu), net_tx=%d KB/s, net_rx=%d KB/s (peak_tx=%d KB/s, peak_rx=%d KB/s)",
hub->users->count,
@ -73,7 +73,7 @@ static void timer_statistics(int fd, short ev, void *arg)
{
struct hub_info* hub = (struct hub_info*) arg;
struct timeval timeout = { TIMEOUT_STATS, 0 };
user_manager_update_stats(hub);
uman_update_stats(hub);
evtimer_set(&hub->ev_timer, timer_statistics, hub);
event_base_set(hub->evbase, &hub->ev_timer);
evtimer_add(&hub->ev_timer, &timeout);
@ -81,7 +81,7 @@ static void timer_statistics(int fd, short ev, void *arg)
#endif
int user_manager_init(struct hub_info* hub)
int uman_init(struct hub_info* hub)
{
struct user_manager* users = NULL;
#ifdef USERMANAGER_TIMER
@ -114,7 +114,7 @@ int user_manager_init(struct hub_info* hub)
}
int user_manager_shutdown(struct hub_info* hub)
int uman_shutdown(struct hub_info* hub)
{
if (!hub || !hub->users)
return -1;
@ -135,7 +135,7 @@ int user_manager_shutdown(struct hub_info* hub)
}
int user_manager_add(struct hub_info* hub, struct user* user)
int uman_add(struct hub_info* hub, struct user* user)
{
if (!hub || !user)
return -1;
@ -154,7 +154,7 @@ int user_manager_add(struct hub_info* hub, struct user* user)
return 0;
}
int user_manager_remove(struct hub_info* hub, struct user* user)
int uman_remove(struct hub_info* hub, struct user* user)
{
if (!hub || !user)
return -1;
@ -249,7 +249,7 @@ void send_quit_message(struct user* leaving)
}
sid_t user_manager_get_free_sid(struct hub_info* hub)
sid_t uman_get_free_sid(struct hub_info* hub)
{
#if 0
struct user* user;

View File

@ -34,7 +34,7 @@ struct user_manager
* Initializes the user manager.
* @return 0 on success, or -1 if error (out of memory).
*/
extern int user_manager_init(struct hub_info* hub);
extern int uman_init(struct hub_info* hub);
/**
* Shuts down the user manager.
@ -42,13 +42,13 @@ extern int user_manager_init(struct hub_info* hub);
*
* @return 0 on success, or -1 in an error occured (hub is invalid).
*/
extern int user_manager_shutdown(struct hub_info* hub);
extern int uman_shutdown(struct hub_info* hub);
/**
* Generate statistics for logfiles.
*/
extern void user_manager_update_stats(struct hub_info* hub);
extern void user_manager_print_stats(struct hub_info* hub);
extern void uman_update_stats(struct hub_info* hub);
extern void uman_print_stats(struct hub_info* hub);
/**
* Add a user to the user manager.
@ -56,7 +56,7 @@ extern void user_manager_print_stats(struct hub_info* hub);
* @param hub The hub to add the user to
* @param user The user to be added to the hub.
*/
extern int user_manager_add(struct hub_info* hub, struct user* user);
extern int uman_add(struct hub_info* hub, struct user* user);
/**
* Remove a user from the user manager.
@ -65,12 +65,12 @@ extern int user_manager_add(struct hub_info* hub, struct user* user);
*
* @return 0 if successfully removed, -1 if error.
*/
extern int user_manager_remove(struct hub_info* hub, struct user* user);
extern int uman_remove(struct hub_info* hub, struct user* user);
/**
* Returns and allocates an unused session ID (SID).
*/
extern sid_t user_manager_get_free_sid(struct hub_info* hub);
extern sid_t uman_get_free_sid(struct hub_info* hub);
/**
* Lookup a user based on the session ID (SID).