Merge branch 'master' of baracus-vpn:~/git/uhub
Conflicts: src/adc/message.c
This commit is contained in:
commit
c3ba8d52ee
@ -31,7 +31,9 @@ EXO_TEST(adc_message_parse_1, {
|
|||||||
|
|
||||||
EXO_TEST(adc_message_parse_2, {
|
EXO_TEST(adc_message_parse_2, {
|
||||||
struct adc_message* msg = adc_msg_create(test_string2);
|
struct adc_message* msg = adc_msg_create(test_string2);
|
||||||
return msg == NULL;
|
int ok = (msg != NULL);
|
||||||
|
adc_msg_free(msg);
|
||||||
|
return ok;
|
||||||
});
|
});
|
||||||
|
|
||||||
EXO_TEST(adc_message_parse_3, {
|
EXO_TEST(adc_message_parse_3, {
|
||||||
|
@ -747,14 +747,14 @@ int adc_msg_add_named_argument_string(struct adc_message* cmd, const char prefix
|
|||||||
|
|
||||||
int adc_msg_add_named_argument_int(struct adc_message* cmd, const char prefix[2], int num)
|
int adc_msg_add_named_argument_int(struct adc_message* cmd, const char prefix[2], int num)
|
||||||
{
|
{
|
||||||
char* s = uhub_itoa(num);
|
const char* s = uhub_itoa(num);
|
||||||
int ret = adc_msg_add_named_argument(cmd, prefix, s);
|
int ret = adc_msg_add_named_argument(cmd, prefix, s);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int adc_msg_add_named_argument_uint64(struct adc_message* cmd, const char prefix[2], uint64_t num)
|
int adc_msg_add_named_argument_uint64(struct adc_message* cmd, const char prefix[2], uint64_t num)
|
||||||
{
|
{
|
||||||
char* s = uhub_ulltoa(num);
|
const char* s = uhub_ulltoa(num);
|
||||||
int ret = adc_msg_add_named_argument(cmd, prefix, s);
|
int ret = adc_msg_add_named_argument(cmd, prefix, s);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -185,18 +185,10 @@ static int acl_parse_line(char* line, int line_count, void* ptr_data)
|
|||||||
pos[0] = 0;
|
pos[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
line = strip_white_space(line);
|
||||||
if (!*line)
|
if (!*line)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
LOG_DEBUG("acl_parse_line(): '%s'", line);
|
|
||||||
line = strip_white_space(line);
|
|
||||||
|
|
||||||
if (!*line)
|
|
||||||
{
|
|
||||||
LOG_FATAL("ACL parse error on line %d", line_count);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_DEBUG("acl_parse_line: '%s'", line);
|
LOG_DEBUG("acl_parse_line: '%s'", line);
|
||||||
|
|
||||||
ACL_ADD_USER("bot", handle->users, cred_bot);
|
ACL_ADD_USER("bot", handle->users, cred_bot);
|
||||||
|
@ -290,7 +290,7 @@ static int command_version(struct hub_info* hub, struct hub_user* user, struct h
|
|||||||
static int command_myip(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
|
static int command_myip(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd)
|
||||||
{
|
{
|
||||||
char tmp[128];
|
char tmp[128];
|
||||||
snprintf(tmp, 128, "Your address is \"%s\"", net_con_get_peer_address(user->connection));
|
snprintf(tmp, 128, "Your address is \"%s\"", user_get_address(user));
|
||||||
return command_status(hub, user, cmd, tmp);
|
return command_status(hub, user, cmd, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ static int command_getip(struct hub_info* hub, struct hub_user* user, struct hub
|
|||||||
if (!target)
|
if (!target)
|
||||||
return command_status_user_not_found(hub, user, cmd, nick);
|
return command_status_user_not_found(hub, user, cmd, nick);
|
||||||
|
|
||||||
snprintf(tmp, 128, "%s has address \"%s\"", nick, net_con_get_peer_address(user->connection));
|
snprintf(tmp, 128, "%s has address \"%s\"", nick, user_get_address(user));
|
||||||
return command_status(hub, user, cmd, tmp);
|
return command_status(hub, user, cmd, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ static int command_whoip(struct hub_info* hub, struct hub_user* user, struct hub
|
|||||||
{
|
{
|
||||||
strcat(buffer, u->id.nick);
|
strcat(buffer, u->id.nick);
|
||||||
strcat(buffer, " (");
|
strcat(buffer, " (");
|
||||||
strcat(buffer, net_con_get_peer_address(u->connection));
|
strcat(buffer, user_get_address(u));
|
||||||
strcat(buffer, ")\n");
|
strcat(buffer, ")\n");
|
||||||
u = (struct hub_user*) list_get_next(users);
|
u = (struct hub_user*) list_get_next(users);
|
||||||
}
|
}
|
||||||
|
@ -1047,7 +1047,7 @@ void hub_logout_log(struct hub_info* hub, struct hub_user* user)
|
|||||||
loginfo->time = time(NULL);
|
loginfo->time = time(NULL);
|
||||||
strcpy(loginfo->cid, user->id.cid);
|
strcpy(loginfo->cid, user->id.cid);
|
||||||
strcpy(loginfo->nick, user->id.nick);
|
strcpy(loginfo->nick, user->id.nick);
|
||||||
memcpy(&loginfo->addr, &user->connection->ipaddr, sizeof(struct ip_addr_encap));
|
memcpy(&loginfo->addr, &user->id.addr, sizeof(struct ip_addr_encap));
|
||||||
loginfo->reason = user->quit_reason;
|
loginfo->reason = user->quit_reason;
|
||||||
|
|
||||||
list_append(hub->logout_info, loginfo);
|
list_append(hub->logout_info, loginfo);
|
||||||
|
@ -22,26 +22,26 @@
|
|||||||
static void log_user_login(struct hub_user* u)
|
static void log_user_login(struct hub_user* u)
|
||||||
{
|
{
|
||||||
const char* cred = get_user_credential_string(u->credentials);
|
const char* cred = get_user_credential_string(u->credentials);
|
||||||
const char* addr = net_con_get_peer_address(u->connection);
|
const char* addr = user_get_address(u);
|
||||||
LOG_USER("LoginOK %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, cred, u->user_agent);
|
LOG_USER("LoginOK %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, cred, u->user_agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log_user_login_error(struct hub_user* u, enum status_message msg)
|
static void log_user_login_error(struct hub_user* u, enum status_message msg)
|
||||||
{
|
{
|
||||||
const char* addr = net_con_get_peer_address(u->connection);
|
const char* addr = user_get_address(u);
|
||||||
const char* message = hub_get_status_message_log(u->hub, msg);
|
const char* message = hub_get_status_message_log(u->hub, msg);
|
||||||
LOG_USER("LoginError %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message, u->user_agent);
|
LOG_USER("LoginError %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message, u->user_agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log_user_logout(struct hub_user* u, const char* message)
|
static void log_user_logout(struct hub_user* u, const char* message)
|
||||||
{
|
{
|
||||||
const char* addr = net_con_get_peer_address(u->connection);
|
const char* addr = user_get_address(u);
|
||||||
LOG_USER("Logout %s/%s %s \"%s\" (%s)", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message);
|
LOG_USER("Logout %s/%s %s \"%s\" (%s)", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log_user_nick_change(struct hub_user* u, const char* nick)
|
static void log_user_nick_change(struct hub_user* u, const char* nick)
|
||||||
{
|
{
|
||||||
const char* addr = net_con_get_peer_address(u->connection);
|
const char* addr = user_get_address(u);
|
||||||
LOG_USER("NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
|
LOG_USER("NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ static int check_required_login_flags(struct hub_info* hub, struct hub_user* use
|
|||||||
*/
|
*/
|
||||||
int check_network(struct hub_info* hub, struct hub_user* user, struct adc_message* cmd)
|
int check_network(struct hub_info* hub, struct hub_user* user, struct adc_message* cmd)
|
||||||
{
|
{
|
||||||
const char* address = net_con_get_peer_address(user->connection);
|
const char* address = user_get_address(user);
|
||||||
|
|
||||||
/* Check for NAT override address */
|
/* Check for NAT override address */
|
||||||
if (acl_is_ip_nat_override(hub->acl, address))
|
if (acl_is_ip_nat_override(hub->acl, address))
|
||||||
|
@ -187,6 +187,14 @@ void net_event(struct net_connection* con, int event, void *arg)
|
|||||||
struct hub_user* user = (struct hub_user*) arg;
|
struct hub_user* user = (struct hub_user*) arg;
|
||||||
int flag_close = 0;
|
int flag_close = 0;
|
||||||
|
|
||||||
|
if (event == NET_EVENT_DESTROYED)
|
||||||
|
{
|
||||||
|
printf("NET_EVENT_DESTROYED\n");
|
||||||
|
hub_free(user->connection);
|
||||||
|
user->connection = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_SENDQ
|
#ifdef DEBUG_SENDQ
|
||||||
LOG_TRACE("net_event() : fd=%d, ev=%d, arg=%p", fd, (int) event, arg);
|
LOG_TRACE("net_event() : fd=%d, ev=%d, arg=%p", fd, (int) event, arg);
|
||||||
#endif
|
#endif
|
||||||
|
@ -197,7 +197,7 @@ int route_info_message(struct hub_info* hub, struct hub_user* u)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct adc_message* cmd = adc_msg_copy(u->info);
|
struct adc_message* cmd = adc_msg_copy(u->info);
|
||||||
const char* address = net_con_get_peer_address(u->connection);
|
const char* address = user_get_address(u);
|
||||||
struct hub_user* user = 0;
|
struct hub_user* user = 0;
|
||||||
|
|
||||||
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);
|
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);
|
||||||
|
@ -51,9 +51,11 @@ struct hub_user* user_create(struct hub_info* hub, int sd, struct ip_addr_encap*
|
|||||||
user->recv_queue = hub_recvq_create();
|
user->recv_queue = hub_recvq_create();
|
||||||
|
|
||||||
user->connection = (struct net_connection*) hub_malloc(sizeof(struct net_connection));
|
user->connection = (struct net_connection*) hub_malloc(sizeof(struct net_connection));
|
||||||
net_con_initialize(user->connection, sd, addr, net_event, user, NET_EVENT_READ);
|
net_con_initialize(user->connection, sd, net_event, user, NET_EVENT_READ);
|
||||||
net_con_set_timeout(user->connection, TIMEOUT_CONNECTED);
|
net_con_set_timeout(user->connection, TIMEOUT_CONNECTED);
|
||||||
|
|
||||||
|
memcpy(&user->id.addr, addr, sizeof(struct ip_addr_encap));
|
||||||
|
|
||||||
user_set_state(user, state_protocol);
|
user_set_state(user, state_protocol);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
@ -344,4 +346,7 @@ const char* user_get_quit_reason_string(enum user_quit_reason reason)
|
|||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* user_get_address(struct hub_user* user)
|
||||||
|
{
|
||||||
|
return ip_convert_to_string(&user->id.addr);
|
||||||
|
}
|
||||||
|
@ -79,6 +79,7 @@ struct hub_user_info
|
|||||||
sid_t sid; /** session ID */
|
sid_t sid; /** session ID */
|
||||||
char cid[MAX_CID_LEN+1]; /** global client ID */
|
char cid[MAX_CID_LEN+1]; /** global client ID */
|
||||||
char nick[MAX_NICK_LEN+1]; /** User's nick name */
|
char nick[MAX_NICK_LEN+1]; /** User's nick name */
|
||||||
|
struct ip_addr_encap addr; /** User's IP address */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -209,6 +210,8 @@ extern void user_support_add(struct hub_user* user, int fourcc);
|
|||||||
*/
|
*/
|
||||||
extern void user_support_remove(struct hub_user* user, int fourcc);
|
extern void user_support_remove(struct hub_user* user, int fourcc);
|
||||||
|
|
||||||
|
extern const char* user_get_address(struct hub_user* user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the nat override flag for a user, this allows users on the same
|
* Sets the nat override flag for a user, this allows users on the same
|
||||||
* subnet as a natted hub to spoof their IP in order to use active mode
|
* subnet as a natted hub to spoof their IP in order to use active mode
|
||||||
|
@ -221,7 +221,7 @@ size_t uman_get_user_by_addr(struct hub_info* hub, struct linked_list* users, st
|
|||||||
struct hub_user* user = (struct hub_user*) list_get_first(hub->users->list); /* iterate users - only on incoming INF msg */
|
struct hub_user* user = (struct hub_user*) list_get_first(hub->users->list); /* iterate users - only on incoming INF msg */
|
||||||
while (user)
|
while (user)
|
||||||
{
|
{
|
||||||
if (ip_in_range(&user->connection->ipaddr, range))
|
if (ip_in_range(&user->id.addr, range))
|
||||||
{
|
{
|
||||||
list_append(users, user);
|
list_append(users, user);
|
||||||
num++;
|
num++;
|
||||||
|
@ -71,6 +71,8 @@ static void net_con_event(int fd, short ev, void *arg);
|
|||||||
|
|
||||||
void net_con_set(struct net_connection* con)
|
void net_con_set(struct net_connection* con)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
int ev = 0;
|
int ev = 0;
|
||||||
if (net_con_flag_get(con, NET_WANT_READ | NET_WANT_SSL_READ)) ev |= EV_READ;
|
if (net_con_flag_get(con, NET_WANT_READ | NET_WANT_SSL_READ)) ev |= EV_READ;
|
||||||
if (net_con_flag_get(con, NET_WANT_WRITE | NET_WANT_SSL_WRITE)) ev |= EV_WRITE;
|
if (net_con_flag_get(con, NET_WANT_WRITE | NET_WANT_SSL_WRITE)) ev |= EV_WRITE;
|
||||||
@ -80,6 +82,9 @@ void net_con_set(struct net_connection* con)
|
|||||||
net_con_flag_set(con, NET_INITIALIZED);
|
net_con_flag_set(con, NET_INITIALIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CALLBACK(CON, EVENTS) \
|
||||||
|
if (CON->callback) \
|
||||||
|
CON->callback(con, EVENTS, CON->ptr);
|
||||||
|
|
||||||
static void net_con_event(int fd, short ev, void *arg)
|
static void net_con_event(int fd, short ev, void *arg)
|
||||||
{
|
{
|
||||||
@ -92,7 +97,7 @@ static void net_con_event(int fd, short ev, void *arg)
|
|||||||
if (!con->ssl)
|
if (!con->ssl)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
con->callback(con, events, con->ptr);
|
CALLBACK(con, events);
|
||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -105,29 +110,29 @@ static void net_con_event(int fd, short ev, void *arg)
|
|||||||
if (net_con_flag_get(con, NET_WANT_SSL_ACCEPT))
|
if (net_con_flag_get(con, NET_WANT_SSL_ACCEPT))
|
||||||
{
|
{
|
||||||
if (net_con_ssl_accept(con) < 0)
|
if (net_con_ssl_accept(con) < 0)
|
||||||
con->callback(con, NET_EVENT_SOCKERROR, con->ptr);
|
CALLBACK(con, NET_EVENT_SOCKERROR);
|
||||||
}
|
}
|
||||||
else if (net_con_flag_get(con, NET_WANT_SSL_CONNECT))
|
else if (net_con_flag_get(con, NET_WANT_SSL_CONNECT))
|
||||||
{
|
{
|
||||||
if (net_con_ssl_connect(con) < 0)
|
if (net_con_ssl_connect(con) < 0)
|
||||||
con->callback(con, NET_EVENT_SOCKERROR, con->ptr);
|
CALLBACK(con, NET_EVENT_SOCKERROR);
|
||||||
}
|
}
|
||||||
else if (ev == EV_READ && net_con_flag_get(con, NET_WANT_SSL_READ))
|
else if (ev == EV_READ && net_con_flag_get(con, NET_WANT_SSL_READ))
|
||||||
{
|
{
|
||||||
con->callback(con, NET_EVENT_WRITE, con->ptr);
|
CALLBACK(con, NET_EVENT_WRITE);
|
||||||
}
|
}
|
||||||
else if (ev == EV_WRITE && net_con_flag_get(con, NET_WANT_SSL_WRITE))
|
else if (ev == EV_WRITE && net_con_flag_get(con, NET_WANT_SSL_WRITE))
|
||||||
{
|
{
|
||||||
con->callback(con, events & NET_EVENT_READ, con->ptr);
|
CALLBACK(con, events & NET_EVENT_READ);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
con->callback(con, events, con->ptr);
|
CALLBACK((con, events);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
con->callback(con, events, con->ptr);
|
CALLBACK(con, events);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -135,8 +140,8 @@ static void net_con_event(int fd, short ev, void *arg)
|
|||||||
|
|
||||||
if (net_con_flag_get(con, NET_CLEANUP))
|
if (net_con_flag_get(con, NET_CLEANUP))
|
||||||
{
|
{
|
||||||
printf("SHOULD SCHEDULE SHUTTING DOWN SOCKET.");
|
|
||||||
net_con_flag_unset(con, NET_INITIALIZED);
|
net_con_flag_unset(con, NET_INITIALIZED);
|
||||||
|
CALLBACK(con, NET_EVENT_DESTROYED);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -144,13 +149,10 @@ static void net_con_event(int fd, short ev, void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* net_con_get_peer_address(struct net_connection* con)
|
void net_con_initialize(struct net_connection* con, int sd, net_connection_cb callback, const void* ptr, int ev)
|
||||||
{
|
{
|
||||||
return ip_convert_to_string(&con->ipaddr);
|
uhub_assert(con);
|
||||||
}
|
|
||||||
|
|
||||||
void net_con_initialize(struct net_connection* con, int sd, struct ip_addr_encap* addr, net_connection_cb callback, const void* ptr, int ev)
|
|
||||||
{
|
|
||||||
int events = net_con_convert_to_libevent_mask(ev);
|
int events = net_con_convert_to_libevent_mask(ev);
|
||||||
if (ev & NET_EVENT_READ) net_con_flag_set(con, NET_WANT_READ);
|
if (ev & NET_EVENT_READ) net_con_flag_set(con, NET_WANT_READ);
|
||||||
if (ev & NET_EVENT_WRITE) net_con_flag_set(con, NET_WANT_WRITE);
|
if (ev & NET_EVENT_WRITE) net_con_flag_set(con, NET_WANT_WRITE);
|
||||||
@ -162,12 +164,6 @@ void net_con_initialize(struct net_connection* con, int sd, struct ip_addr_encap
|
|||||||
con->last_send = time(0);
|
con->last_send = time(0);
|
||||||
con->last_recv = con->last_send;
|
con->last_recv = con->last_send;
|
||||||
|
|
||||||
/** IP address of peer */
|
|
||||||
if (addr)
|
|
||||||
{
|
|
||||||
memcpy(&con->ipaddr, addr, sizeof(struct ip_addr_encap));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ev)
|
if (ev)
|
||||||
{
|
{
|
||||||
event_set(&con->event, con->sd, events, net_con_event, con);
|
event_set(&con->event, con->sd, events, net_con_event, con);
|
||||||
@ -188,6 +184,8 @@ void net_con_initialize(struct net_connection* con, int sd, struct ip_addr_encap
|
|||||||
|
|
||||||
void net_con_update(struct net_connection* con, int ev)
|
void net_con_update(struct net_connection* con, int ev)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
if (ev & NET_EVENT_READ)
|
if (ev & NET_EVENT_READ)
|
||||||
net_con_flag_set(con, NET_EVENT_READ);
|
net_con_flag_set(con, NET_EVENT_READ);
|
||||||
else
|
else
|
||||||
@ -206,6 +204,8 @@ void net_con_update(struct net_connection* con, int ev)
|
|||||||
|
|
||||||
void net_con_close(struct net_connection* con)
|
void net_con_close(struct net_connection* con)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
if (net_con_flag_get(con, NET_CLEANUP))
|
if (net_con_flag_get(con, NET_CLEANUP))
|
||||||
{
|
{
|
||||||
LOG_INFO("Running net_con_close, but we already have closed...");
|
LOG_INFO("Running net_con_close, but we already have closed...");
|
||||||
@ -214,7 +214,8 @@ void net_con_close(struct net_connection* con)
|
|||||||
|
|
||||||
if (net_con_flag_get(con, NET_PROCESSING_BUSY))
|
if (net_con_flag_get(con, NET_PROCESSING_BUSY))
|
||||||
{
|
{
|
||||||
LOG_INFO("Trying to close socket while processing it, will need to post a message about it...");
|
LOG_INFO("Trying to close socket while processing it");
|
||||||
|
net_con_flag_set(con, NET_CLEANUP);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +235,8 @@ void net_con_close(struct net_connection* con)
|
|||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
static int handle_openssl_error(struct net_connection* con, int ret)
|
static int handle_openssl_error(struct net_connection* con, int ret)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
int error = SSL_get_error(con->ssl, ret);
|
int error = SSL_get_error(con->ssl, ret);
|
||||||
switch (error)
|
switch (error)
|
||||||
{
|
{
|
||||||
@ -290,6 +293,8 @@ static int handle_openssl_error(struct net_connection* con, int ret)
|
|||||||
|
|
||||||
ssize_t net_con_send(struct net_connection* con, const void* buf, size_t len)
|
ssize_t net_con_send(struct net_connection* con, const void* buf, size_t len)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
if (!con->ssl)
|
if (!con->ssl)
|
||||||
{
|
{
|
||||||
@ -342,6 +347,8 @@ ssize_t net_con_send(struct net_connection* con, const void* buf, size_t len)
|
|||||||
|
|
||||||
ssize_t net_con_recv(struct net_connection* con, void* buf, size_t len)
|
ssize_t net_con_recv(struct net_connection* con, void* buf, size_t len)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
if (!con->ssl)
|
if (!con->ssl)
|
||||||
{
|
{
|
||||||
@ -387,6 +394,8 @@ ssize_t net_con_recv(struct net_connection* con, void* buf, size_t len)
|
|||||||
|
|
||||||
void net_con_set_timeout(struct net_connection* con, int seconds)
|
void net_con_set_timeout(struct net_connection* con, int seconds)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
struct timeval timeout = { seconds, 0 };
|
struct timeval timeout = { seconds, 0 };
|
||||||
net_con_clear_timeout(con);
|
net_con_clear_timeout(con);
|
||||||
|
|
||||||
@ -397,6 +406,8 @@ void net_con_set_timeout(struct net_connection* con, int seconds)
|
|||||||
|
|
||||||
void net_con_clear_timeout(struct net_connection* con)
|
void net_con_clear_timeout(struct net_connection* con)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
if (net_con_flag_get(con, NET_TIMER_ENABLED))
|
if (net_con_flag_get(con, NET_TIMER_ENABLED))
|
||||||
{
|
{
|
||||||
evtimer_del(&con->timeout);
|
evtimer_del(&con->timeout);
|
||||||
@ -408,6 +419,8 @@ void net_con_clear_timeout(struct net_connection* con)
|
|||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
ssize_t net_con_ssl_accept(struct net_connection* con)
|
ssize_t net_con_ssl_accept(struct net_connection* con)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
net_con_flag_set(con, NET_WANT_SSL_ACCEPT);
|
net_con_flag_set(con, NET_WANT_SSL_ACCEPT);
|
||||||
ssize_t ret = SSL_accept(con->ssl);
|
ssize_t ret = SSL_accept(con->ssl);
|
||||||
#ifdef NETWORK_DUMP_DEBUG
|
#ifdef NETWORK_DUMP_DEBUG
|
||||||
@ -427,6 +440,8 @@ ssize_t net_con_ssl_accept(struct net_connection* con)
|
|||||||
|
|
||||||
ssize_t net_con_ssl_connect(struct net_connection* con)
|
ssize_t net_con_ssl_connect(struct net_connection* con)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
net_con_flag_set(con, NET_WANT_SSL_CONNECT);
|
net_con_flag_set(con, NET_WANT_SSL_CONNECT);
|
||||||
ssize_t ret = SSL_connect(con->ssl);
|
ssize_t ret = SSL_connect(con->ssl);
|
||||||
#ifdef NETWORK_DUMP_DEBUG
|
#ifdef NETWORK_DUMP_DEBUG
|
||||||
@ -446,6 +461,8 @@ ssize_t net_con_ssl_connect(struct net_connection* con)
|
|||||||
|
|
||||||
ssize_t net_con_ssl_handshake(struct net_connection* con, int ssl_mode)
|
ssize_t net_con_ssl_handshake(struct net_connection* con, int ssl_mode)
|
||||||
{
|
{
|
||||||
|
uhub_assert(con);
|
||||||
|
|
||||||
if (ssl_mode == NET_CON_SSL_MODE_SERVER)
|
if (ssl_mode == NET_CON_SSL_MODE_SERVER)
|
||||||
{
|
{
|
||||||
con->ssl = SSL_new(g_hub->ssl_ctx);
|
con->ssl = SSL_new(g_hub->ssl_ctx);
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#define NET_EVENT_WRITE 0x0004
|
#define NET_EVENT_WRITE 0x0004
|
||||||
#define NET_EVENT_SOCKERROR 0x1000 /* Socket error, closed */
|
#define NET_EVENT_SOCKERROR 0x1000 /* Socket error, closed */
|
||||||
#define NET_EVENT_CLOSED 0x2000 /* Socket closed */
|
#define NET_EVENT_CLOSED 0x2000 /* Socket closed */
|
||||||
|
#define NET_EVENT_DESTROYED 0x4000 /* Struct is invalid and can be cleaned up */
|
||||||
|
|
||||||
struct net_connection;
|
struct net_connection;
|
||||||
struct net_timer;
|
struct net_timer;
|
||||||
@ -54,7 +55,6 @@ struct net_connection
|
|||||||
net_connection_cb callback; /** Callback function */
|
net_connection_cb callback; /** Callback function */
|
||||||
struct event event; /** libevent struct for read/write events */
|
struct event event; /** libevent struct for read/write events */
|
||||||
struct event timeout; /** Used for internal timeout handling */
|
struct event timeout; /** Used for internal timeout handling */
|
||||||
struct ip_addr_encap ipaddr; /** IP address of peer */
|
|
||||||
time_t last_recv; /** Timestamp for last recv() */
|
time_t last_recv; /** Timestamp for last recv() */
|
||||||
time_t last_send; /** Timestamp for last send() */
|
time_t last_send; /** Timestamp for last send() */
|
||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
@ -63,8 +63,15 @@ struct net_connection
|
|||||||
#endif /* SSL_SUPPORT */
|
#endif /* SSL_SUPPORT */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void net_con_initialize(struct net_connection* con, int sd, struct ip_addr_encap*, net_connection_cb callback, const void* ptr, int events);
|
extern void net_con_initialize(struct net_connection* con, int sd, net_connection_cb callback, const void* ptr, int events);
|
||||||
extern void net_con_update(struct net_connection* con, int events);
|
extern void net_con_update(struct net_connection* con, int events);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the connection.
|
||||||
|
* This will ensure a connection is closed properly and will generate a NET_EVENT_DESTROYED event which indicates
|
||||||
|
* that the con can safely be deleted (or set to NULL)
|
||||||
|
* NOTE: Do not dele
|
||||||
|
*/
|
||||||
extern void net_con_close(struct net_connection* con);
|
extern void net_con_close(struct net_connection* con);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,12 +100,6 @@ extern ssize_t net_con_recv(struct net_connection* con, void* buf, size_t len);
|
|||||||
extern void net_con_set_timeout(struct net_connection* con, int seconds);
|
extern void net_con_set_timeout(struct net_connection* con, int seconds);
|
||||||
extern void net_con_clear_timeout(struct net_connection* con);
|
extern void net_con_clear_timeout(struct net_connection* con);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of the ipaddr member.
|
|
||||||
* NOTE: Static buffer.
|
|
||||||
*/
|
|
||||||
extern const char* net_con_get_peer_address(struct net_connection* con);
|
|
||||||
|
|
||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
/**
|
/**
|
||||||
* Start SSL_accept()
|
* Start SSL_accept()
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
#ifndef HAVE_UHUB_SYSTEM_H
|
#ifndef HAVE_UHUB_SYSTEM_H
|
||||||
#define HAVE_UHUB_SYSTEM_H
|
#define HAVE_UHUB_SYSTEM_H
|
||||||
|
|
||||||
|
#define _FILE_OFFSET_BITS 64
|
||||||
|
|
||||||
#if USE_REGPARM && __GNUC__ >= 3
|
#if USE_REGPARM && __GNUC__ >= 3
|
||||||
#define REGPRM1 __attribute__((regparm(1)))
|
#define REGPRM1 __attribute__((regparm(1)))
|
||||||
#define REGPRM2 __attribute__((regparm(2)))
|
#define REGPRM2 __attribute__((regparm(2)))
|
||||||
|
@ -80,8 +80,18 @@ static void timer_callback(struct net_timer* t, void* arg)
|
|||||||
static void event_callback(struct net_connection* con, int events, void *arg)
|
static void event_callback(struct net_connection* con, int events, void *arg)
|
||||||
{
|
{
|
||||||
struct ADC_client* client = (struct ADC_client*) arg;
|
struct ADC_client* client = (struct ADC_client*) arg;
|
||||||
|
|
||||||
|
if (events == NET_EVENT_DESTROYED)
|
||||||
|
{
|
||||||
|
printf("NET_EVENT_DESTROYED\n");
|
||||||
|
hub_free(client->con);
|
||||||
|
client->con = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (events == NET_EVENT_SOCKERROR || events == NET_EVENT_CLOSED)
|
if (events == NET_EVENT_SOCKERROR || events == NET_EVENT_CLOSED)
|
||||||
{
|
{
|
||||||
|
printf("NET_EVENT_SOCKERROR || NET_EVENT_CLOSED\n");
|
||||||
client->callback(client, ADC_CLIENT_DISCONNECTED, 0);
|
client->callback(client, ADC_CLIENT_DISCONNECTED, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -343,12 +353,13 @@ void ADC_client_destroy(struct ADC_client* client)
|
|||||||
{
|
{
|
||||||
ADC_client_disconnect(client);
|
ADC_client_disconnect(client);
|
||||||
net_timer_shutdown(client->timer);
|
net_timer_shutdown(client->timer);
|
||||||
|
hub_free(client->timer);
|
||||||
|
adc_msg_free(client->info);
|
||||||
hub_free(client->nick);
|
hub_free(client->nick);
|
||||||
hub_free(client->desc);
|
hub_free(client->desc);
|
||||||
hub_free(client->hub_address);
|
hub_free(client->hub_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ADC_client_connect(struct ADC_client* client, const char* address)
|
int ADC_client_connect(struct ADC_client* client, const char* address)
|
||||||
{
|
{
|
||||||
if (!client->hub_address)
|
if (!client->hub_address)
|
||||||
@ -391,8 +402,6 @@ static void ADC_client_on_connected(struct ADC_client* client)
|
|||||||
static void ADC_client_on_disconnected(struct ADC_client* client)
|
static void ADC_client_on_disconnected(struct ADC_client* client)
|
||||||
{
|
{
|
||||||
net_con_close(client->con);
|
net_con_close(client->con);
|
||||||
hub_free(client->con);
|
|
||||||
client->con = 0;
|
|
||||||
ADC_client_set_state(client, ps_none);
|
ADC_client_set_state(client, ps_none);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +413,7 @@ static void ADC_client_on_login(struct ADC_client* client)
|
|||||||
|
|
||||||
void ADC_client_disconnect(struct ADC_client* client)
|
void ADC_client_disconnect(struct ADC_client* client)
|
||||||
{
|
{
|
||||||
if (client->con->sd != -1)
|
if (client->con && client->con->sd != -1)
|
||||||
{
|
{
|
||||||
net_con_close(client->con);
|
net_con_close(client->con);
|
||||||
}
|
}
|
||||||
|
@ -46,10 +46,13 @@ char* strip_white_space(char* string)
|
|||||||
{
|
{
|
||||||
char* pos;
|
char* pos;
|
||||||
|
|
||||||
|
if (!string)
|
||||||
|
return "";
|
||||||
|
|
||||||
while (string[0] && is_white_space(string[0])) string++;
|
while (string[0] && is_white_space(string[0])) string++;
|
||||||
|
|
||||||
if (!*string)
|
if (!*string)
|
||||||
return 0;
|
return string;
|
||||||
|
|
||||||
/* Strip appending whitespace */
|
/* Strip appending whitespace */
|
||||||
pos = &string[strlen(string)-1];
|
pos = &string[strlen(string)-1];
|
||||||
|
Loading…
Reference in New Issue
Block a user