Moved the ipaddr object into the connection object.

This commit is contained in:
Jan Vidar Krey 2009-08-03 18:14:34 +02:00
parent 27c71a75ee
commit 4e43746c1b
11 changed files with 24 additions and 45 deletions

View File

@ -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)
{
char tmp[128];
snprintf(tmp, 128, "Your address is \"%s\"", ip_convert_to_string(&user->net.ipaddr));
snprintf(tmp, 128, "Your address is \"%s\"", ip_convert_to_string(&user->net.connection.ipaddr));
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)
return command_status_user_not_found(hub, user, cmd, nick);
snprintf(tmp, 128, "%s has address \"%s\"", nick, ip_convert_to_string(&target->net.ipaddr));
snprintf(tmp, 128, "%s has address \"%s\"", nick, ip_convert_to_string(&target->net.connection.ipaddr));
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, " (");
strcat(buffer, ip_convert_to_string(&u->net.ipaddr));
strcat(buffer, ip_convert_to_string(&u->net.connection.ipaddr));
strcat(buffer, ")\n");
u = (struct hub_user*) list_get_next(users);
}

View File

@ -1034,7 +1034,7 @@ void hub_logout_log(struct hub_info* hub, struct hub_user* user)
loginfo->time = time(NULL);
strcpy(loginfo->cid, user->id.cid);
strcpy(loginfo->nick, user->id.nick);
memcpy(&loginfo->addr, &user->net.ipaddr, sizeof(struct ip_addr_encap));
memcpy(&loginfo->addr, &user->net.connection.ipaddr, sizeof(struct ip_addr_encap));
loginfo->reason = user->quit_reason;
list_append(hub->logout_info, loginfo);

View File

@ -22,26 +22,26 @@
static void log_user_login(struct hub_user* u)
{
const char* cred = get_user_credential_string(u->credentials);
const char* addr = ip_convert_to_string(&u->net.ipaddr);
const char* addr = ip_convert_to_string(&u->net.connection.ipaddr);
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)
{
const char* addr = ip_convert_to_string(&u->net.ipaddr);
const char* addr = ip_convert_to_string(&u->net.connection.ipaddr);
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);
}
static void log_user_logout(struct hub_user* u, const char* message)
{
const char* addr = ip_convert_to_string(&u->net.ipaddr);
const char* addr = ip_convert_to_string(&u->net.connection.ipaddr);
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)
{
const char* addr = ip_convert_to_string(&u->net.ipaddr);
const char* addr = ip_convert_to_string(&u->net.connection.ipaddr);
LOG_USER("NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
}

View File

@ -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)
{
const char* address = ip_convert_to_string(&user->net.ipaddr);
const char* address = ip_convert_to_string(&user->net.connection.ipaddr);
/* Check for NAT override address */
if (acl_is_ip_nat_override(hub->acl, address))

View File

@ -256,7 +256,7 @@ void net_on_accept(int server_fd, short ev, void *arg)
continue;
}
user = user_create(hub, fd);
user = user_create(hub, fd, &ipaddr);
if (!user)
{
LOG_ERROR("Unable to create user after socket accepted. Out of memory?");
@ -264,9 +264,6 @@ void net_on_accept(int server_fd, short ev, void *arg)
break;
}
/* Store IP address in user object */
memcpy(&user->net.ipaddr, &ipaddr, sizeof(ipaddr));
#ifdef SSL_SUPPORT
net_con_ssl_accept(&user->net.connection);
#endif

View File

@ -197,7 +197,7 @@ int route_info_message(struct hub_info* hub, struct hub_user* u)
else
{
struct adc_message* cmd = adc_msg_copy(u->info);
const char* address = ip_convert_to_string(&u->net.ipaddr);
const char* address = ip_convert_to_string(&u->net.connection.ipaddr);
struct hub_user* user = 0;
adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR);

View File

@ -35,7 +35,7 @@ static const char* user_log_str(struct hub_user* user)
}
#endif
struct hub_user* user_create(struct hub_info* hub, int sd)
struct hub_user* user_create(struct hub_info* hub, int sd, struct ip_addr_encap* addr)
{
struct hub_user* user = NULL;
@ -50,7 +50,7 @@ struct hub_user* user_create(struct hub_info* hub, int sd)
user->net.send_queue = hub_sendq_create();
user->net.recv_queue = hub_recvq_create();
net_con_initialize(&user->net.connection, sd, user, EV_READ);
net_con_initialize(&user->net.connection, sd, addr, user, EV_READ);
evtimer_set(&user->net.timeout, net_event, user);
event_base_set(hub->evbase, &user->net.timeout);
@ -335,16 +335,6 @@ void user_net_io_want_read(struct hub_user* user)
net_con_update(&user->net.connection, EV_READ);
}
void user_reset_last_write(struct hub_user* user)
{
user->net.tm_last_write = time(NULL);
}
void user_reset_last_read(struct hub_user* user)
{
user->net.tm_last_read = time(NULL);
}
void user_set_timeout(struct hub_user* user, int seconds)
{
#ifdef DEBUG_SENDQ

View File

@ -104,9 +104,6 @@ struct hub_user_net_io
struct hub_recvq* recv_queue;
struct hub_sendq* send_queue;
time_t tm_connected; /** time when user connected */
time_t tm_last_read; /** time the user last received something from the hub */
time_t tm_last_write; /** time the user last sent something to the hub */
struct ip_addr_encap ipaddr; /** IP address of connected user */
};
struct hub_user
@ -136,7 +133,7 @@ struct hub_user
* @param sd socket descriptor associated with the user
* @return User object or NULL if not enough memory is available.
*/
extern struct hub_user* user_create(struct hub_info* hub, int sd);
extern struct hub_user* user_create(struct hub_info* hub, int sd, struct ip_addr_encap* addr);
/**
* Delete a user.
@ -276,18 +273,6 @@ extern void user_net_io_want_read(struct hub_user* user);
*/
extern void user_set_timeout(struct hub_user* user, int seconds);
/**
* Reset the last-write timer.
*/
extern void user_reset_last_write(struct hub_user* user);
/**
* Reset the last-write timer.
*/
extern void user_reset_last_read(struct hub_user* user);
#endif /* HAVE_UHUB_USER_H */

View File

@ -223,7 +223,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 */
while (user)
{
if (ip_in_range(&user->net.ipaddr, range))
if (ip_in_range(&user->net.connection.ipaddr, range))
{
list_append(users, user);
num++;

View File

@ -82,7 +82,7 @@ static void net_con_event(int fd, short ev, void *arg)
#endif
}
void net_con_initialize(struct net_connection* con, int sd, const void* ptr, int events)
void net_con_initialize(struct net_connection* con, int sd, struct ip_addr_encap* addr, const void* ptr, int events)
{
LOG_DEBUG("net_con_initialize: sd=%d, ptr=%p", sd, ptr);
con->sd = sd;
@ -90,6 +90,12 @@ void net_con_initialize(struct net_connection* con, int sd, const void* ptr, int
con->last_send = time(0);
con->last_recv = con->last_send;
/** IP address of peer */
if (addr)
{
memcpy(&con->ipaddr, addr, sizeof(struct ip_addr_encap));
}
if (events & EV_READ) net_con_flag_set(con, NET_WANT_READ);
if (events & EV_WRITE) net_con_flag_set(con, NET_WANT_WRITE);

View File

@ -28,6 +28,7 @@ struct net_connection
unsigned int flags; /** Connection flags */
void* ptr; /** data pointer */
struct event event; /** libevent struct for read/write events */
struct ip_addr_encap ipaddr; /** IP address of peer */
time_t last_recv; /** Timestamp for last recv() */
time_t last_send; /** Timestamp for last send() */
#ifdef SSL_SUPPORT
@ -37,7 +38,7 @@ struct net_connection
#endif /* SSL_SUPPORT */
};
extern void net_con_initialize(struct net_connection* con, int sd, const void* ptr, int events);
extern void net_con_initialize(struct net_connection* con, int sd, struct ip_addr_encap*, const void* ptr, int events);
extern void net_con_update(struct net_connection* con, int events);
extern void net_con_close(struct net_connection* con);