There should be no change in behaviour. Replaces a code block of the form:
if (a || b)
{
if (c && a)
{
/* one */
}
else if (b)
{
/* two */
}
}
with the simpler equivalent:
if (c && a)
{
/* one */
}
else if (b)
{
/* two */
}
Change remove_all_dcc_binds() so that it only removes DCC binds for the module supplied, as it's supposed to.
get_dcc_type() should ignore the first entry in dcc_types[] ("<none>") otherwise the client will try to
respond to DCC requests with that name.
Explicitly track the number of entries in the dcc_types[] array rather than using a NULL terminator. This
allows us to change dcc_types[] to use NULL entries to mark unused slots in the array, rather than pointers
to entries with a NULL .name element. Together, this means that the dcc_types[] array is only resized when it
actually needs to be grown and removal works correctly (without eg. prematurely marking the end of the array).
Make add_dcc_bind() fail if the requested DCC type has already been bound by a module (this still allows one
module at a time to rebind a built-in DCC type). Previously the behaviour was ill-defined in this case.
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.
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").
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.
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.
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.
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.
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.
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.
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().
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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.