Commit Graph

47 Commits

Author SHA1 Message Date
Kevin Easton
6cf30d8ce1 Make finalize_server_connect() static
It is only called within server.c.
2019-01-16 23:26:39 +11:00
Kevin Easton
95b57cc3cc Correctly handle reconnection after finalize_server_connect() fails
finalize_server_connect() can fail for SSL connections, because SSL_connect() can fail.  Without this change, the client won't
try to reconnect after an initial SSL connection failure - it'll just wait forever.

Reported by g0z, thanks!
2019-01-16 17:13:29 +11:00
Kevin Easton
3800e4b099 Replace get_server_flag() with get_server_umode()
This function gets the status of a single umode flag identified by umode char rather than
internal server flag number.

This also lets us remove all the USER_MODE* constants because they're no longer required.

Invert the sense of the +w check in e_wall() - we only echo our OPERWALL if we're *not* +w,
because if we are +w then the server will echo it back to us anyway.
2017-12-07 00:23:43 +11:00
Kevin Easton
1769c03951 Replace set_server_flag() with update_server_umode() and remove get_possible_umodes()
The idea here is not to expose the internal server implementation for storing umodes,
but instead have callers just work in terms of umode characters.

The 'possible umodes' have always been the same for all servers anyway.  We just assume
that [a-zA-Z] is the bounding set.
2017-12-06 23:30:24 +11:00
Kevin Easton
305cfe2afb Move reinstate_user_modes() and update_user_mode() from funny.c to server.c and parse.c
Move these functions where they belong.
2017-12-06 22:13:34 +11:00
Kevin Easton
7642e741b9 Switch to using NULL server.ssl_fd to mark new SSL connection instead of NULL server.ctx
server.ctx is now allocated once for each server on first connection, then reused for subsequent connections.

server.ctx wasn't being cleared when the server was closed (as server.ssl_fd is), so this was causing
reconnection to fail until try_connect() got called.

This also removes the last uses of the CHK_* macros in ssl.h, so remove them.
2017-12-03 02:16:39 +11:00
Kevin Easton
7b817dd9d2 Correctly handle zero value error return from SSL_write() 2017-12-03 01:09:06 +11:00
Kevin Easton
abc9dbdf9e Use SSL_free() when closing an SSL server connection
This avoids leaking memory.

Also change to always call SSL_shutdown() regardless of whether a QUIT message was sent.  No
need to call SSL_shutdown() from write_to_server(), close_server() will do it for us.

Remove "Closing SSL connection" message.
2017-12-03 01:06:53 +11:00
Kevin Easton
5d131bcf01 Add SSL version and cipher to SSL connect message
Similar to what EPIC5 does.
2017-12-03 00:13:47 +11:00
gdinit
bac141898b Correct spelling of some client messages, comments and function names 2017-10-20 14:57:17 +11:00
Kevin Easton
f7de661f2f Use L suffixed constant to match type of server.flags / server.flags2 field in (get|set)_server_flag()
Also squash return value of get_server_flag() to 1 / 0.
2017-08-22 23:16:43 +10:00
Kevin Easton
73148fa4a4 Remove unused server flags CLOSE_PENDING and CLOSING_SERVER, rename LOGGED_IN to SF_LOGGED_IN
CLOSING_SERVER was never referenced outside of server.h where it's defined, and CLOSE_PENDING was cleared
but never set by any code.

Rename LOGGED_IN to namespace it (in anticipation of other flag variables in the server struct being
consolidated into a set of server flags).

Also put correct parantheses around the definition of SF_LOGGED_IN.
2017-07-19 07:57:52 +10:00
Kevin Easton
0fea2b97a4 Remove exported function create_server_list()
The guts of this function doesn't need to be in server.c - it only uses extern server functions so it
makes sense just to move it into the body of function_servers(), the only caller.

That means it's no longer accessible for loadable modules, but it isn't much use for them anyway.  They
can always directly access the server list if they need that info.

(Requires rolling the module table version).
2017-07-17 12:59:49 +10:00
Kevin Easton
d2e576a774 Fix $myservers(1) to only return registered server refnums
When $myservers() is called with an argument of 1 it is supposed to only return the refnums of servers
that are registered (ie. those which it is legal to send a command to).  This is the way EPIC works, and
it was always intended to work this way in BX too.

Also fix the warning about a NULL itsname - we use our name for the server if it isn't registered yet.

Remove the slightly bogus use of strncat() while we're here, by removing the temporary stack buffer and
just directly creating the result string with m_s3cat().
2017-07-17 12:48:28 +10:00
Kevin Easton
cd9c358eed Fix CHANGE_NICK_ON_KILL feature
Remove the 'resend_only' flag option to fudge_nickname().  The only caller passing it was the CHANGE_NICK_ON_KILL
feature, and in that case it was the wrong thing too (and stopped that function from working at all).

Some other minor cleanups in fudge_nickname() while we're there.
2017-07-15 23:29:14 +10:00
Kevin Easton
0a16ab16ac Introduce strbegins() macro and replace all open-coded instances
This test is done quite a bit across the tree, and the open-coded variants make it easy to have an
accidental mismatch between the length of the prefix being tested and the length actually passed to
strncmp().

This fixes an issue of that type comparing the server version against the prefix "u2.10", where the old
code used an incorrect length of 4.
2017-06-06 23:47:10 +10:00
Kevin Easton
2fa0bf818a Replace uses of HAVE_SSL with HAVE_LIBSSL
autoconf's AC_CHECK_LIB automatically sets HAVE_LIBSSL, whereas HAVE_SSL has to be set manually.

This prepares us to remove some code from configure.
2017-03-17 00:07:38 +11:00
Kevin Easton
04cf832604 Change send_msg_to_channels() to remove 'channels' argument and always use PRIVMSG
The 'channels' argument was unnecessary because the channel list passed to it would
always be from get_server_channels(server) anyway.

Changing the message argument from a protocol message format string to a plain payload
string for PRIVMSG means printf-escaping of the argument is avoided in the caller.
This simplifies the callers and means we can remove the last use of quote_it().

This change also switches set_server_away() to use send_msg_to_channels() instead of
open-coding the equivalent, which simplifies that function a lot.

We are changing the signature of a function exported to modules here; however none
of the in-tree modules use this function so it should be OK.
2016-10-13 01:36:19 +11:00
Kevin Easton
58588946e0 Simplify send_to_server functions by adding server parameter to vsend_to_server() 2016-10-02 22:44:06 +11:00
Kevin Easton
ce3fd79652 Global spelling fix s/recieve/receive/ across codebase
This includes some user-visible messages and help files, so if anyone has
hooked them with /ON WINDOW their hooks will need updating.
2015-10-04 09:06:38 +11:00
Kevin Easton
8cc9684c76 Ensure close_server() clears the who/ison/userhost queues for the right server
close_server() should call clear_server_queues() on the server that's being
closed, not from_server.  This also lets us remove a few other calls to
clear_server_queues() that are right next to calls to close_server().
2015-09-07 16:34:41 +10:00
Kevin Easton
bc94fbe64a Remove a strange old piece of code apparently for detecting a server gone to lunch
This code appears to be some kind of backstop so that the client will notice
a server connection that's died because of a network interruption.  Checking
errno that was last set christ-knows-where is not the right way to do this,
though.

The normal write to the server for the lag check should eventually see the
host/net unreachable error if this happens.
2015-06-13 22:35:03 +10:00
Kevin Easton
b0951d44dd Simplify and make static reconnect_server() function 2015-06-13 22:30:44 +10:00
Kevin Easton
6dbc712046 Rework and improve the scheduling of the server lag check
Previously the server lag check was run by update_clock() if the number of
seconds since client startup was a multiple of 20 (unless it had already been
done this second).  This meant that if update_clock() was not being called
frequently (eg. if your IRC connection was very quiet), it might go a long
time between lag checks.

This commit adds a /set LAG_CHECK_INTERVAL (defaulting to 30).  For each
server, a lag check ping is scheduled for every LAG_CHECK_INTERVAL seconds
after the connection is finalised/registered.  Setting this value to 0
disables the lag check pings entirely.

The old code set the lag to 'unknown' immediately after sending out a ping,
which meant that it was quite unpredictable how long the lag value would
stay around for.  The new code only sets this once the current lag value
has become stale (ie. a ping reply is overdue based on the current lag
value).  If your lag is staying the same or reducing, you shouldn't see
the [Lag ??] at all.
2015-06-12 15:54:43 +10:00
Kevin Easton
c0c7cdbdcc Rework the calculation of the select timeout in io() to be based on absolute wake time
An absolute wake time is now calculated and updated by set_server_bits(),
TimerTimeout() and tclTimerTimeout().  This is then used to calculate the actual
select() timeout, instead of having those functions calculate a relative timeout
value themselves.  This significantly simplifies those functions, since the
underlying values tend to be recorded as absolute times.

It also allows us to disentangle tclTimeTimeout from TimerTimeout(), and move the
responsibility for calculating the QUEUE_SENDS wake time from TimerTimeout() to
set_server_bits() where it belongs.

The QUEUE_SENDS and CONNECT_DELAY wake up times will also now be correctly
calculated, based on the last sent time and connect time respectively.
2015-06-07 00:03:09 +10:00
Kevin Easton
f1c27a4f64 Switch server->connect_time from time_t to struct timeval
This means that settings like CONNECT_DELAY and CONNECT_TIMEOUT are compared
against the current time with sub-second resolution.  With the old way, the
delays could be up to a second longer than asked for, which had the effect of
almost doubling the default CONNECT_DELAY value of 1.
2015-05-13 23:17:18 +10:00
Kevin Easton
0f8280ed51 Prevent indefinite wait if CONNECT_DELAY is set to zero
set_server_bits() now returns -1 for "no timeout", so 0 is a legitimate
return value.

io() should only update real_timeout from server_timeout if server_timeout
is not -1 (real_timeout == -1 ends up meaning "wait indefinitely").

Note that if you set CONNECT_DELAY to zero you get a lag check ping sent off
first thing in the server connection, this should be fixed.
2015-05-12 22:39:30 +10:00
Kevin Easton
9f7cf6b6c2 Alter the way PINGs for /sping and lag check are used.
We now send PING <server> :<server> for /spings, and
PING LAG!<cookie>.<tv_sec>.<tv_usec> :<server> for lag checks.  The cookie is
set randomly at server connect time, and means that clients connected to the
same bouncer shouldn't act on each other's lag checks.

We can now remove in_sping entirely - previously it would get out of synch if
you disconnected with a sping in progress.
2015-05-04 00:13:08 +10:00
Kevin Easton
3b99834e00 Partially revert r456.
An snprintf() call that creates IRC protocol messages must use 
(MAX_PROTOCOL_SIZE + 1) as 'n' rather than the buffer size.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@461 13b04d17-f746-0410-82c6-800466cd88b0
2013-11-13 09:57:15 +00:00
Tim Cava
317b84ee9d Convert sprintf calls to snprintf. From pvaldes.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@456 13b04d17-f746-0410-82c6-800466cd88b0
2013-11-11 21:29:00 +00:00
Tim Cava
112b38ac7a Revert the last commit. It accidentally had autogenerated files in it.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@432 13b04d17-f746-0410-82c6-800466cd88b0
2013-11-07 03:00:24 +00:00
Tim Cava
276fd24258 Use snprintf rather than sprintf. From pvaldes.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@431 13b04d17-f746-0410-82c6-800466cd88b0
2013-11-07 02:41:16 +00:00
Tim Cava
a3ab6659fc Refactor vsend_to_server() with help from caf.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@410 13b04d17-f746-0410-82c6-800466cd88b0
2013-10-26 00:49:30 +00:00
Tim Cava
e4e8a1358a Use strlcpy, rather than strmcpy, in show_server_map().
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@327 13b04d17-f746-0410-82c6-800466cd88b0
2013-08-15 10:41:00 +00:00
Tim Cava
72cf367e45 Use strlcpy, rather than strmcpy, in accept_server_nickname().
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@326 13b04d17-f746-0410-82c6-800466cd88b0
2013-08-15 10:35:43 +00:00
Tim Cava
68c3df7c6c Use strlcpy, rather than strmcpy, in set_server_nickname().
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@325 13b04d17-f746-0410-82c6-800466cd88b0
2013-08-15 10:28:56 +00:00
Tim Cava
e070369079 Make the namelen passed to getsockname() a socklen_t everywhere.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@280 13b04d17-f746-0410-82c6-800466cd88b0
2013-07-14 03:26:00 +00:00
Tim Cava
80cfa9c5d8 Make the namelen passed to getpeername() a socklen_t everywhere.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@279 13b04d17-f746-0410-82c6-800466cd88b0
2013-07-14 03:18:47 +00:00
Tim Cava
27ed98a03d Make the addrlen passed to my_accept() a socklen_t everywhere.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@278 13b04d17-f746-0410-82c6-800466cd88b0
2013-07-14 03:09:16 +00:00
Kevin Easton
1541299fa1 Merge infrastructure for SASL authentication support from flashback.
This includes all of the underlying support, but doesn't hook it up to the
/SERVER command yet, so it's not useable at this point.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@216 13b04d17-f746-0410-82c6-800466cd88b0
2012-12-30 02:22:56 +00:00
Tim Cava
416fcda578 Fix QUIT messages with SSL connections.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@212 13b04d17-f746-0410-82c6-800466cd88b0
2012-09-20 02:36:48 +00:00
Kevin Easton
5222ce2f1d Move window_check_servers() call out of loop, otherwise the client does a
huge amount of work on each keystroke if you have a long server list and
start it up disconnected (-N).


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@150 13b04d17-f746-0410-82c6-800466cd88b0
2012-02-10 12:38:08 +00:00
Kevin Easton
d1e13bc526 Show correct message ("Remote end closed connection") when we get EOF
on a socket.

I also added a wrapper function around strerror() for dgets_errno, since
we did the same thing in a few places.  This all needs to be cleaned up
a little - the -1 value we use could in theory clash with an actual
errno error number.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@104 13b04d17-f746-0410-82c6-800466cd88b0
2010-09-30 13:26:06 +00:00
Kevin Easton
789ed916cd Backport changes from epic5 to make recv_nick, sent_nick and sent_body
per-server, and apply new version of do_oops from flewid (the BX2 version). 

This means that /oops, "/query .", "/query ,", "/msg ." and "/msg ," are now
per-server, along with the $. $, and $B aliases.



git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@87 13b04d17-f746-0410-82c6-800466cd88b0
2010-06-26 08:18:34 +00:00
Kevin Easton
eb13453e50 Fix snprintf() call in /QUIT to make glibc2.9 happy.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@67 13b04d17-f746-0410-82c6-800466cd88b0
2009-09-08 13:22:27 +00:00
Kevin Easton
533c3dbcbf Turn on SVN keyword replacement for $Date$, $Author$, $Revision$, $Id$ for all
*.c and *.h files.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/branches/ircii-pana-1.1@3 13b04d17-f746-0410-82c6-800466cd88b0
2008-02-25 09:49:14 +00:00
Kevin Easton
28febcfea9 Initial import of the ircii-pana-1.1-final source tree.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/tags/ircii-pana-1.1-final@1 13b04d17-f746-0410-82c6-800466cd88b0
2008-02-25 09:25:32 +00:00