Commit Graph

58 Commits

Author SHA1 Message Date
Kevin Easton
64ec300d5d Add full prototyped declarations for DCC hook function pointers 2018-02-08 16:57:41 +11:00
Kevin Easton
d7688075b6 Export dcc_chat_socketread() and dcc_send_socketread() callbacks to modules
The idea here is that if you have a module which implements a new DCC type that is essentially
a lightly-modified version of CHAT or SEND you can reuse these functions.
2017-12-20 17:36:05 +11:00
Kevin Easton
a55feeef5f Rename process_dcc_*() functions to dcc_*_socketread()
This makes it clearer what those functions really do.  It's in preparation to export them
for modules.
2017-12-20 17:11:56 +11:00
gdinit
bac141898b Correct spelling of some client messages, comments and function names 2017-10-20 14:57:17 +11:00
Kevin Easton
1bceb5ed86 Pass STXT_NOTICE flag instead of command string to functions downstream of send_text()
This uses another bit in the existing flags argument in place of the command argument, and avoids
having to re-compare against fixed strings ("PRIVMSG", "NOTICE").
2017-07-08 21:37:08 +10:00
Kevin Easton
2d0b3e728f Replace 'hook' and 'noisy' flags in functions downstream of send_text() with !(stxt_flags & STXT_QUIET)
This is in preparation for consolidating the various send_text() options into one set of consistent flags.
2017-07-07 15:19:39 +10:00
Kevin Easton
529b1e0aa0 Small cleanup of code for CTCPs over DCC CHAT 2017-06-07 00:30:12 +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
414b1cc679 Move calls to parse_offer_params() into create_dcc_int()
Every call to create_dcc_int() was preceded by a call to parse_offer_params(), and the DCC_int
is where the address/port/size produced by the latter is stored, so this refactoring makes
sense and reduces the calling function complexity/size considerably.
2016-11-03 00:45:38 +11:00
Kevin Easton
6cac0e6bb1 Truncate DCC port to unsigned short before checking for a privileged port
Checking before truncation means you can sneak a privileged port past the check.

This change also collects the various broken-out parts of a CTCP DCC offer into a struct so that
it's easier to pass them all around together.
2016-11-02 23:58:11 +11:00
Kevin Easton
23d466c4a1 Don't show DCC "Handshake failed" message twice
parse_offer_params() was being run unconditionally by check_dcc_init() even if it didn't find a
custom init_func() to call, which is the usual case.  It then gets called again by the hardwired
DCC init function, which led to the error message appearing twice.  This has check_dcc_init() only
call parse_offer_params() when its about to dispatch to a custom init func.

This also improves the message a bit (making it [host:port] rather than the other way around) and
combines the 'privileged port' message and "zero address" message together.
2016-11-02 22:19:57 +11:00
Kevin Easton
34c2a66a35 Improve accuracy of DCC LIST speed and ETA calculations
Switch from using whole-second time_t values to fractional values calculated with time_since().
2016-10-29 01:03:18 +11:00
Kevin Easton
f372e2a19b Use the same format in /DCC LIST for all waiting offers
Previously waiting (inactive) file-type offers were shown different to others, omitting the
time-since-offer.  Unify them to use the same format, which also cuts out a few lines of code.

Also tweaks the DCC_BAR_TYPE 1 format to include the DCC state (always Active) where the
completion bar would be in the DCC_BAR_TYPE 0 format.  This just looks a bit more consistent.
2016-10-29 00:21:00 +11:00
Kevin Easton
031608a4ea Replace get_bar_percent() with get_stat_format()
get_stat_format() now returns the entire cparse string, not just the completion bar portion.  This
means we don't need to call convert_output_format() twice.
2016-10-29 00:00:27 +11:00
Kevin Easton
30e1a65efb Add function dcc_type_name() to convert DCC type to corresponding name.
This conversion (which conditionally prepends 'T' to the DCC type name depending on whether
TDCC is enabled or not) was open-coded in several places.

Also removes unused extern function get_dcc_type().
2016-10-28 15:35:23 +11:00
Kevin Easton
919b76fcef Correctly show time since offer for DCC CHAT offers in /DCC LIST
s->time on the SocketList is set to the time that the chat offer will expire, so it's in the future.
This shows up as a very large positive time.  Instead, use n->lasttime as that is set to the time
when the offer is made.

Also adjust the format for non-file offers so that it all lines up properly.
2016-10-27 15:14:57 +11:00
Kevin Easton
30e3e65af7 Move translation of DCC_ACTIVE / DCC_WAIT / DCC_OFFER state to string into new function
The same expression was open-coded in several places, so collect it into one.
2016-10-27 14:54:21 +11:00
Kevin Easton
3cba15f6b4 Further cleanups in dcc_glist()
This now calculates a 'pcomplete' value for proportion of transfer complete (0.0 to 1.0).
From this we can calculate most other things easily - percent complete, ETA, and the size
of the completion bars.

User-visible change is that the DCC_BAR_TYPE 1 bar now matches the % complete for the RESUMEd
file case.
2016-10-27 00:23:35 +11:00
Kevin Easton
ed12420755 Extensive cleanups and simplifications in dcc_glist()
The only user-visible change here is that the bar displayed for DCC_BAR_TYPE 1 is now shown
as empty for a zero-length file rather than full, matching the 0.0% complete that is shown
and the bar displayed in the DCC_BAR_TYPE 0 case.
2016-10-26 23:47:24 +11:00
Kevin Easton
d8a53ab045 Correctly align formatting of /DCC LIST line for /SET DCC_BAR_TYPE 1
With DCC_BAR_TYPE 1 set, the stat line for active DCC file connections was not aligned
correctly with the header (the mm:ss field spilled into the KB/s column.)

This also simplifies things by always generating the inline bar, so the only difference
between the line printed for DCC_BAR_TYPE 0 and 1 is now the format itself.
2016-10-25 13:56:56 +11:00
Kevin Easton
09e53eb6d4 Cleanups in open_listen_port()
This fixes a few issues in this function - the socket type should be 'int' not 'socklen_t', the
error cases should close() the socket so it doesn't leak.
2016-10-21 16:37:18 +11:00
Kevin Easton
caba4c830c Length-check copies to DCC_current_transfer_buffer 2016-10-21 00:47:51 +11:00
Kevin Easton
aacc4b2282 Fix unsigned/signed comparison in process_dcc_send1()
The result of read() can be -1, and if that is compared against the unsigned result of sizeof
it will be converted to SIZE_MAX.  Cast the result of sizeof to a signed type.
2016-10-20 21:42:10 +11:00
Kevin Easton
e49dfcf11f Remove unnecessary double-sprintf() in close_dcc_file() 2016-10-19 16:48:28 +11:00
Kevin Easton
4ee14e00c2 Minor cleanup in add_userhost_to_dcc() 2015-10-29 22:17:10 +11:00
Kevin Easton
a2e8e103e0 Modularise handling of DCC offers
There's several different types of DCC offers, all of which need slightly
different handling.  Previously they were all handled by the monster function
register_dcc_type() - this breaks them out into seperate functions for handling
SEND, RESEND, CHAT and BOT offers, moves common code into static helper
functions and renames the entry point from ctcp.c to handle_dcc_offer().

This will allow adding a way for modules to register DCC offer types that
they're interested in.

This also moves rename_file() from misc.c into dcc.c, where its only user is.
2015-10-28 21:46:38 +11:00
Kevin Easton
51ecdb8d1b Re-add code for DCC CHAT autoget mistakenly removed in [be6bd5aca] 2015-10-12 17:22:52 +11:00
Kevin Easton
cfe6735ef0 Simplify find_dcc() and find_dcc_pending()
Extract the common DCC matching code into one function and simplify
it a little.
2015-10-12 16:26:23 +11:00
Kevin Easton
fe368ac875 Fix argument order for dcc_getfile_resume_start()
The last two arguments are port, then offset (as per the DCC ACCEPT CTCP
command).  We don't really use these anyway - port is passed to dcc_create()
but for pre-existing DCC entries all that did was add it to the socketinfo,
which doesn't seem to have any real effect.

Also fix dcc_create() so it passes the actual remote port to add_socketread()
(as above, this doesn't seem to have any real effect but is consistent with
the other code).
2015-10-10 22:48:26 +11:00
Kevin Easton
be6bd5aca4 Simplify and improve code around DCC auto-get / auto-rename / auto-resume
This improves the client messages - eg previously the message to tell you that
you could use /DCC RESUME never got shown due to a logic error.

It also won't try to auto-resume if the local file is already the same size or
bigger than the incoming file.
2015-10-10 00:08:00 +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
726884b0b0 Ignore DCC ACCEPT if we didn't request a DCC RESUME
Mark DCC connections that we have requested RESUME on, so that we know
whether or not to act on a DCC ACCEPT that is received.

Also fixes up a slightly wrong message in /DCC RESUME.
2015-10-04 00:44:47 +10:00
Kevin Easton
c173af3f65 Remove unused DCC_CNCT_PEND flag and always define DCC_SSL
DCC_CNCT_PEND was only ever set, not tested, so it was pointless.

There's no point only defining DCC_SSL when HAVE_SSL is defined: we can't
re-use that flag bit anyway, so might as well just define it always.

Also fixes a "flags && DCC_WAIT" that should have been "flags & DCC_WAIT".
This has no practical effect though I believe, since as far as I can tell
DCC_WAIT would always be set at that point anyway.
2015-10-03 22:10:15 +10:00
Kevin Easton
27e32a0319 Cleanup and simplify get_reason() and related functions
Rename randreason() to fread_random() to better reflect its function,
and change it to a one-pass algorithm.  Have it write into a caller-provided
buffer instead of a static buffer.  Fixes a file leak when an empty
file is given to this function.

Change freadln() so that it never returns an empty line - it only returns
0 at end-of-file now.  This simplifies its callers.

Factor out some common code from the several get_reason()-type functions,
which greatly simplifies them.
2015-06-27 00:38:40 +10:00
Kevin Easton
5f4429bf7b Removed unused variable from output_reject_ctcp()
Also remove unnecessary tests for stuff and stuff->user - these are always
non-null when the callback is called.
2015-06-25 11:45:09 +10:00
Kevin Easton
28bd7a66b6 Remove useless check for !nick from userhostbase callbacks
The userhostbase callback is always called with non-null nick.  Checking for
this is just noise which also sometimes results in odd compiler warnings.
2015-06-24 23:20:53 +10:00
Kevin Easton
4ee6c6295b Add time_until() and time_since() utility functions
Adding these in preparation for converting server->connect_time from time_t
to struct timeval.  Also converts three existing open-coded versions over to
the new functions.
2015-05-13 21:50:30 +10:00
Tim Cava
8d5882a9ef Remove a variable that is set but unused.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@492 13b04d17-f746-0410-82c6-800466cd88b0
2014-03-02 19:59:13 +00:00
Kevin Easton
55d3b28060 dcc.c: Fix mismatching format strings in get_dcc_info() and dcc_ftpcommand().
Cast time_t value to long and use %ld to print.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@469 13b04d17-f746-0410-82c6-800466cd88b0
2013-11-16 00:18:39 +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
Kevin Easton
590ae4c685 Further cleanups in dcc.c, removing unused variables and reworking dcc_exempt_save().
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@430 13b04d17-f746-0410-82c6-800466cd88b0
2013-11-06 10:35:16 +00:00
Kevin Easton
15894eb006 Some simplification / cleanup in dcc_glist().
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@429 13b04d17-f746-0410-82c6-800466cd88b0
2013-11-05 13:07:06 +00:00
Tim Cava
0b32d978f8 Actually use strlcpy.
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@352 13b04d17-f746-0410-82c6-800466cd88b0
2013-08-17 07:31:03 +00:00
Tim Cava
9a36857761 Use strlcpy, rather than strmcpy, in new_dcc_message_transmit().
git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@351 13b04d17-f746-0410-82c6-800466cd88b0
2013-08-17 07:29:02 +00:00
Kevin Easton
0b0dbf5cf7 Make the RANDOM_LOCAL_PORTS setting actually use a random port.
The code was calling random_number(65535 - 1024), but a non-zero argument
to random_number() is actually a seed to reseed the generator, and causes
random_number() to return zero.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@331 13b04d17-f746-0410-82c6-800466cd88b0
2013-08-15 15:06:21 +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