diff --git a/src/bip.c b/src/bip.c index b25bd9c..2309946 100644 --- a/src/bip.c +++ b/src/bip.c @@ -1571,9 +1571,6 @@ void adm_list_users(struct link_client *ic) hash_iterator_t it; hash_iterator_t lit; char buf[RET_STR_LEN + 1]; - connection_t *c; - - c = CONN(ic); bip_notify(ic, "-- User list"); for (hash_it_init(&_bip->users, &it); hash_it_item(&it); @@ -1621,9 +1618,6 @@ void adm_list_networks(struct link_client *ic) { hash_iterator_t it; char buf[RET_STR_LEN + 1]; - connection_t *c; - - c = CONN(ic); bip_notify(ic, "-- Network list (* means SSL):"); for (hash_it_init(&_bip->networks, &it); hash_it_item(&it); @@ -1670,9 +1664,7 @@ noroom: void adm_list_connections(struct link_client *ic, struct bipuser *bu) { hash_iterator_t it; - connection_t *c; - c = CONN(ic); if (!bu) { bip_notify(ic, "-- Your connections:"); bu = LINK(ic)->user; diff --git a/src/connection.c b/src/connection.c index c793e18..7eb2294 100644 --- a/src/connection.c +++ b/src/connection.c @@ -16,6 +16,8 @@ #include #include "connection.h" +void (*on_new_connection)() = NULL; + extern int errno; #ifdef HAVE_LIBSSL static int ssl_initialized = 0; @@ -23,7 +25,7 @@ static SSL_CTX *sslctx = NULL; static int ssl_cx_idx; static BIO *errbio = NULL; extern char *conf_ssl_certfile; -static int SSLize(connection_t *cn, int *nc); +static int SSLize(connection_t *cn); static SSL_CTX *SSL_init_context(void); /* SSH like trust management */ int link_add_untrusted(void *ls, X509 *cert); @@ -31,7 +33,7 @@ int link_add_untrusted(void *ls, X509 *cert); static int connection_timedout(connection_t *cn); static int socket_set_nonblock(int s); -static void connection_connected(connection_t *c); +static void connection_tcp_connected(connection_t *c); struct connecting_data { @@ -151,7 +153,9 @@ static void connect_trynext(connection_t *cn) connecting_data_free(cn->connecting_data); cn->connecting_data = NULL; cn->connected = cn->ssl ? CONN_NEED_SSLIZE : CONN_OK; - connection_connected(cn); + connection_tcp_connected(cn); + if (on_new_connection) + on_new_connection(); return; } @@ -617,7 +621,7 @@ static int check_event_read(fd_set *fds, connection_t *cn) return 1; } -static void connection_connected(connection_t *c) +static void connection_tcp_connected(connection_t *c) { if (c->localip) free(c->localip); @@ -629,7 +633,7 @@ static void connection_connected(connection_t *c) c->remoteport = connection_remoteport(c); } -static int check_event_write(fd_set *fds, connection_t *cn, int *nc) +static int check_event_write(fd_set *fds, connection_t *cn) { if (cn_is_in_error(cn)) { mylog(LOG_ERROR, "Error on fd %d (state %d)", @@ -673,6 +677,9 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc) cn->handle); return connection_timedout(cn); } else if (err == EISCONN || err == 0) { + connection_tcp_connected(cn); + if (on_new_connection) + on_new_connection(); #ifdef HAVE_LIBSSL if (cn->ssl) { cn->connected = CONN_NEED_SSLIZE; @@ -680,8 +687,6 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc) } #endif cn->connected = CONN_OK; - connection_connected(cn); - *nc = 1; mylog(LOG_DEBUG, "fd:%d Connection established !", cn->handle); return 1; @@ -700,7 +705,7 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc) #ifdef HAVE_LIBSSL if (cn->connected == CONN_NEED_SSLIZE) { - if (SSLize(cn, nc)) + if (SSLize(cn)) return connection_timedout(cn); return 0; } @@ -761,7 +766,7 @@ int cn_want_write(connection_t *cn) return !list_is_empty(cn->outgoing); } -list_t *wait_event(list_t *cn_list, int *msec, int *nc) +list_t *wait_event(list_t *cn_list, int *msec) { fd_set fds_read, fds_write, fds_except; int maxfd = -1, err; @@ -769,7 +774,6 @@ list_t *wait_event(list_t *cn_list, int *msec, int *nc) list_iterator_t it; struct timeval tv; struct timeval btv, etv; - *nc = 0; cn_newdata = list_new(list_ptr_cmp); FD_ZERO(&fds_read); @@ -873,7 +877,7 @@ list_t *wait_event(list_t *cn_list, int *msec, int *nc) list_add_first_uniq(cn_newdata, cn); continue; } - if (check_event_write(&fds_write, cn, nc)) { + if (check_event_write(&fds_write, cn)) { if (cn_is_in_error(cn)) toadd = 1; } @@ -1324,7 +1328,7 @@ static int bip_ssl_verify_callback(int preverify_ok, X509_STORE_CTX *ctx) return result; } -static int SSLize(connection_t *cn, int *nc) +static int SSLize(connection_t *cn) { int err, err2; @@ -1363,8 +1367,6 @@ static int SSLize(connection_t *cn, int *nc) mylog(LOG_DEBUG, "Negociated ciphers: %s", buf); cn->connected = CONN_OK; - connection_connected(cn); - *nc = 1; return 0; } diff --git a/src/connection.h b/src/connection.h index 5fa7d2e..ebb5b14 100644 --- a/src/connection.h +++ b/src/connection.h @@ -102,7 +102,7 @@ void write_line(connection_t *cn, char *line); void write_lines(connection_t *cn, list_t *lines); void write_line_fast(connection_t *cn, char *line); list_t *read_lines(connection_t *cn, int *error); -list_t *wait_event(list_t *cn_list, int *msec, int *nc); +list_t *wait_event(list_t *cn_list, int *msec); int cn_is_connected(connection_t *cn); int cn_is_listening(connection_t *cn); diff --git a/src/irc.c b/src/irc.c index 98744ea..caa5c6f 100644 --- a/src/irc.c +++ b/src/irc.c @@ -51,7 +51,7 @@ static void ls_set_nick(struct link_server *ircs, char *nick); #ifdef HAVE_OIDENTD #define OIDENTD_FILENAME ".oidentd.conf" -void oidentd_dump(bip_t *bip); +void oidentd_dump(void); #endif void irc_client_free(struct link_client *cli); @@ -326,8 +326,6 @@ static int irc_315(struct link_server *server, struct line *l) link->who_client, link->who_client->who_count); } } - l = NULL; /* keep gcc happy */ - return OK_COPY_WHO; } @@ -1474,8 +1472,6 @@ static int irc_368(struct link_server *server, struct line *l) link->who_client, link->who_client->who_count); } } - l = NULL; /* keep gcc happy */ - return OK_COPY_WHO; } @@ -2196,7 +2192,7 @@ connection_t *irc_server_connect(struct link *link) list_add_last(&_bip->conn_list, conn); #ifdef HAVE_OIDENTD - oidentd_dump(_bip); + oidentd_dump(); #endif irc_server_startup(ls); return conn; @@ -2237,13 +2233,14 @@ void irc_server_shutdown(struct link_server *s) #define BIP_OIDENTD_END "## END OF AUTOGENERATED STUFF ##\n" #define BIP_OIDENTD_END_LENGTH strlen(BIP_OIDENTD_END) -void oidentd_dump(bip_t *bip) +void oidentd_dump(void) { list_iterator_t it; FILE *f; char *bipstart = NULL, *bipend = NULL; struct stat stats; char tag_written = 0; + bip_t *bip = _bip; if (stat(bip->oidentdpath, &stats) == -1) { if (errno == ENOENT && (f = fopen(bip->oidentdpath, "w+"))) { @@ -2512,6 +2509,8 @@ prot_err: } } +extern void (*on_new_connection)(); + /* * The main loop * inc is the incoming connection, clientl list a list of client struct that @@ -2521,6 +2520,10 @@ void irc_main(bip_t *bip) { int timeleft = 1000; +#ifdef HAVE_OIDENTD + on_new_connection = oidentd_dump; +#endif + if (bip->reloading_client) { char *l; @@ -2548,13 +2551,8 @@ void irc_main(bip_t *bip) bip_tick(bip); } - int nc; /* Da main loop */ - list_t *ready = wait_event(&bip->conn_list, &timeleft, &nc); -#ifdef HAVE_OIDENTD - if (nc) - oidentd_dump(bip); -#endif + list_t *ready = wait_event(&bip->conn_list, &timeleft); while ((conn = list_remove_first(ready))) bip_on_event(bip, conn); list_free(ready); diff --git a/src/log.c b/src/log.c index 2d788f8..269c6cb 100644 --- a/src/log.c +++ b/src/log.c @@ -655,14 +655,12 @@ void log_ping_timeout(log_t *logdata) void log_connected(log_t *logdata) { - logstore_t *store; hash_iterator_t hi; snprintf(logdata->buffer, LOGLINE_MAXLEN, "%s -!- Connected to" " server...", timestamp()); for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi); hash_it_next(&hi)) { - store = hash_it_item(&hi); log_write(logdata, hash_it_key(&hi), logdata->buffer); } }