Commit Graph

514 Commits

Author SHA1 Message Date
Kevin Easton
3d353f5a48 Remove dead store to a variable 2017-02-11 22:42:32 +11:00
Kevin Easton
95ad004ff0 Remove unused function is_ignored() 2017-02-08 23:56:36 +11:00
Kevin Easton
ce92ddc8fc Fix typo in unused function is_ignored() 2017-02-05 00:09:51 +11:00
Kevin Easton
bbaeca3bc3 Allow INVITE and WALLOP floods to trigger auto-ignore
Previously, INVITE and WALLOP were tracked for flooding, but if the flood triggered then the auto-ignore
didn't happen.  As far as I can tell, this was just an oversight.
2017-01-25 17:12:38 +11:00
Kevin Easton
27b2f3e939 Change ignore_type() arguments to (const char *, size_t)
This just changes the arguments to match the strncmp() calls in the function.
2017-01-21 14:23:57 +11:00
Kevin Easton
69296c2c5a Switch *_FLOOD constants to sequential rather than bits and add flood type lookup table
Using sequential constants for *_FLOOD constants means that we can use a simple lookup table to convert them
into text for display and IGNORE_* constants.
2017-01-21 14:17:42 +11:00
Kevin Easton
81ddf52909 Introduce an enum flood_type for the *_FLOOD constants
This allows the debugger to show the decoded constant name.
2017-01-19 17:10:32 +11:00
Kevin Easton
fef98f43ba Separate notion of _FLOOD constant from the flags stored in the Flooding struct
This adds a FLOOD_FLAG() macro to convert a _FLOOD constant to the appropriate flag.  For now this just
casts the argument to unsigned int.

Rename Flooding.type to Flooding.flags and change it to unsigned int, to reflect that it's a bitfield of
flags for multiple flooding types.
2017-01-18 17:03:06 +11:00
Kevin Easton
78dbdea441 Remove 'type' argument of flood_prot()
All callers of flood_prot() were supplying { get_flood_types(flood_type), flood_type } as the second and third arguments,
except one that supplied { get_flood_types(CTCP_FLOOD), CTCP_ACTION_FLOOD }.

Hardwiring this logic in to flood_prot() lets us remove the 'type' argument without changing the behaviour.
2017-01-18 00:11:49 +11:00
Kevin Easton
657acd8985 Remove dead store to currmatch in do_hook() 2017-01-03 00:12:23 +11:00
Kevin Easton
89a5417a11 Use %d sprintf() format for 'int' arguments rather than %u 2017-01-02 15:16:13 +11:00
Kevin Easton
a047eba6da Simplify unnecessarily complex condition
!match || (match && ...) is exactly equivalent to !match || ...
2017-01-02 15:09:21 +11:00
Kevin Easton
00ae33b67f Clean up formatting in function_sar() and function_msar(), remove redundant test
The test for !search in function_msar() wasn't necessary because it is assigned from a pointer
that was just tested for NULL above.
2017-01-02 00:47:43 +11:00
Kevin Easton
8975ba93dd Change $indextoword() so that the return value numbers the words from 0 rather than 1
This aligns the function with the documentation and what EPIC4/5 do. I couldn't find any example of an existing
script that actually called this function, so hopefully no-one is relying on the old behaviour.
2017-01-01 23:33:25 +11:00
Kevin Easton
678adbdd40 Rework and simplify $remw() implementation
This replaces calls to alloca() followed by two strcpy()s with a single
call to memmove(), and removes a confusing for/break structure.

The function should behave exactly as it did before.
2016-12-14 23:39:31 +11:00
Kevin Easton
908e6cdf00 Remove doubled-up identical fset_string_var() calls 2016-12-07 23:53:14 +11:00
Kevin Easton
21a12c004b Correct issue where flood detection could become unreliable
The static 'pos' variable in check_flooding() would not stay in sync with the number of entries in
flood_list after clean_flood_list() was called.  This meant that check_flooding() would always end up
removing all previous entries if it tried to add a new one.

Fix this by removing the tracking of number of flood_list entries, and just removing stale ones (older
than /SET FLOOD_RATE).
2016-11-26 00:08:59 +11:00
Kevin Easton
966f1c6c27 Apply correct casts to check_ext_mail and check_ext_mail_status
As always, the funcion pointers should be cast to the correct type before calling them, rather
than calling them with the wrong type and trying to cast the result.  Fixes a warning compiling
mail.c on 64 bit architectures, and this might well have caused a crash when using the qmail plugin
on those architectures too.
2016-11-03 00:57:03 +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
b462cf0001 Simplify show_version()
Re-order the code to squash two copies of the formatting code into one.
2016-10-18 23:54:46 +11:00
Kevin Easton
0a90a9d9db Minor cleanups in commands2.c
Remove some unused expressions after comma operators.

parm.termid is an array so it is pointless to compare it to NULL.
2016-10-18 23:46:43 +11:00
Kevin Easton
c2d6a184a3 Act on channel mode lock as half-op
There's no reason you shouldn't be able to use modelock as a half-op.

Also a few other minor cleanups in this function - eg. use my_send_to_server()
with the passed server number instead of implicitly using from_server.
2016-10-18 23:32:23 +11:00
Kevin Easton
da1618d393 Constify pointer return value of find_command() 2016-10-16 00:45:41 +11:00
Kevin Easton
c6ec1f4098 Reformat and remove some unnecessary tests in parse_line()
Remove some unnecessary tests for !line: next_expr(&line, ...) can't set line to NULL.

Fixes some whitespace breakage.
2016-10-15 11:59:39 +11:00
Kevin Easton
9a2792345f Fix crash and memory leak in $aliasctl(COMMAND MATCH)
glob_commands() would run off the end of the irc_command array if given a match that matched
the last command.  It also leaked memory because it used m_s3cat() to construct the string,
then passed that to m_strdup().

This fixes these problems by reworking glob_commands(), and at the same time removes the use
of alloca() and wild_match() by using strncmp() instead to match the start of a string.  Move
glob_commands() to alias.c and make it static since it's only used for aliasctl().

Change the 'name' argument of find_command() and find_dll_command() to const char * at the same
time, so that glob_commands()'s prefix argument can be const char * too.
2016-10-15 00:41:34 +11:00
Kevin Easton
dec7caafd0 Change 'name' argument of find_fixed_array_item() to const char * 2016-10-15 00:17:31 +11:00
Kevin Easton
a7f2462395 Fix memory leaks and format string issues in CDCC
cdcc_numpacks is unsigned, so %u should be used instead of %d.

Fix some memory leaks in /CDCC PLIST and /CDCC NOTICE where malloc_sprintf() was called
and the string never freed.
2016-10-14 00:56:03 +11:00
Kevin Easton
6948d91f6b Simplify unnecessary tests in CDCC
!password || (password && x) can be simplified to !password || x.

There's no need to check if a string is equal to the destination before
copying it there: might as well just copy it.
2016-10-14 00:34:26 +11:00
Kevin Easton
eb4b2a29d6 Remove unused function quote_it()
This function is no longer needed.  It was problematic anyway because it didn't have a way for
the caller to specify the destination buffer size.
2016-10-13 01:44:29 +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
08e3c99720 Remove use of quote_it() from LameKick() and masskick()
The use of quote_it() is unnecessary - we can just directly use my_send_to_server()
to construct the message.

Preparation to remove quote_it() entirely.
2016-10-09 23:22:18 +11:00
Kevin Easton
0fd11b3d75 Ensure masskick(), massban(), unban(), ban() and remove_bans() send command to correct server
These commands use prepare_command() to find a channel to act on, which returns the server to use.
The code should then use my_send_to_server() to ensure that it sends the command to that server -
these functions were using send_to_server() which sends to 'from_server', which means that they
could send the commands to the wrong place, for example if they were called from a hook on a
different server.

This patch was created with the following coccinelle script:

// Detects pairing preprare_command() with send_to_server() (which uses from_server)

@prepare3@
identifier s;
local idexpression c;
expression E1, E2, E3, E4, E5;
@@

(
if ((c = prepare_command(&s,...)) != NULL && ...)
{
<...
(
- send_to_server(E1);
+ my_send_to_server(s, E1);
|
- send_to_server(E1,E2);
+ my_send_to_server(s, E1, E2);
|
- send_to_server(E1,E2,E3);
+ my_send_to_server(s, E1, E2, E3);
|
- send_to_server(E1,E2,E3,E4);
+ my_send_to_server(s, E1, E2, E3, E4);
|
- send_to_server(E1,E2,E3,E4,E5);
+ my_send_to_server(s, E1, E2, E3, E4, E5);
)
...>
}
|
if ((c = prepare_command(&s,...)) == NULL || ...) { ... return ...; }
{
<...
(
- send_to_server(E1);
+ my_send_to_server(s, E1);
|
- send_to_server(E1,E2);
+ my_send_to_server(s, E1, E2);
|
- send_to_server(E1,E2,E3);
+ my_send_to_server(s, E1, E2, E3);
|
- send_to_server(E1,E2,E3,E4);
+ my_send_to_server(s, E1, E2, E3, E4);
|
- send_to_server(E1,E2,E3,E4,E5);
+ my_send_to_server(s, E1, E2, E3, E4, E5);
)
...>
}
)
2016-10-08 00:12:47 +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
729b029385 Code and comment cleanups to the Karll array functions
There should be no behavioural change.
2016-10-01 01:37:27 +10:00
Kevin Easton
e2b351b9ce Remove unnecessary NULL checks in expr.c
The first is unnecessary because after_expand() never returns NULL, and the 'rest' pointer has been
dereferenced multiple times anyway.

The second is unnecessary because parse_number(&ptr) cannot set ptr to NULL.
2016-09-30 23:44:15 +10:00