Commit Graph

676 Commits

Author SHA1 Message Date
Kevin Easton
1fbafddc59 UNBAN <nick> can use cached whowas info to unset bans
The use of the whowas cache in userhost_unban() would never work, because it was passing 'args' as the channel
name which also included the window number.

Rework this substantially, including using lookup_channel() and set_display_target() in place of prepare_command().
2017-02-25 00:34:58 +11:00
Kevin Easton
3a5a489f25 Add option to check_whowas_nick_buffer() to scan all channels in whowas list
Passing NULL channel lets you scan the full whowas list, which is useful for functions not tied to a channel
like ignore.
2017-02-22 23:03:17 +11:00
Kevin Easton
2363ea709d Remove unused 'unlink' argument from check_whowas_nick_buffer()
Every caller was passing 0 for unlink, so remove it.  This simplifies the function.

Also change the nick and channel arguments to const char *.
2017-02-22 22:28:17 +11:00
Kevin Easton
0c721de2a5 Remove dead code and clean up convert_output_format_raw()
The second branch of if (str) ... else if (str) is dead code, remove it.  Also remove the if() entirely because
the while condition covers it exactly anyway.

Move the static variables used only in this function to function scope.

Change color_mod to const static and remove unneeded variable c_mod.

Move the increment of cparse_recurse to after the point where we bail.

None of this should have any user-visible impact.
2017-02-18 01:04:39 +11:00
Kevin Easton
61ff399b3d Remove superfluous test for current_window
It is always non-NULL, and we dereference it unconditionally anyway.
2017-02-18 00:32:23 +11:00
Kevin Easton
5574ff043b Replace an alloca() call with new_malloc() / new_free()
This also cleans up the code here a bit.
2017-02-18 00:00:45 +11:00
Kevin Easton
e5b2a65fe2 Remove pointless NULL test and unreachable return
There is no point testing ptr for NULL - we dereference it anyway, this function can't be called with a
NULL pointer for the first argument.
2017-02-17 21:55:11 +11:00
Kevin Easton
a0e8bd5742 Cast pid_t to long for fprintf()
pid_t is defined by POSIX to be a signed integer type, so the %u format is wrong.

Cast to long and print with %ld - it is unlikely that any real-world system has pid_t bigger than long.
2017-02-17 16:50:41 +11:00
Kevin Easton
686344314f Unsetting CMDCHARS sets it back to the default
Previously you could unset CMDCHARS and the effect would be to treat it like it was set to DEFAULT_CMDCHARS,
except that some code was missing the fallback (eg. ignore_last_nick()) which would make it crash.

Instead of having the fallback everywhere, just make it so that you can't unset the variable - if you try, it
sets it to DEFAULT_CMDCHARS.  This reflects what the behaviour has always been, it just makes it explicit to
the user and the bonus is we don't have the test it for NULL everywhere.
2017-02-16 23:42:52 +11:00
Kevin Easton
debfebf3a7 Fix a double-free bug when a window on an alternate screen queries an exec process
The 'free_it' variable was only initialised to zero at the start of the function, so when non-main screens
were processed in the later iterations of the loop, it could keep a value of 1 from the previous iteration.

We don't actually need a free_it variable at all - just use a NULL value of ptr_free to indicate that there
is nothing to free (and passing a NULL to new_free() is a no-op).

This also simplifies a test because ptr is always non-NULL (strip_ansi() never returns NULL).
2017-02-16 23:12:38 +11:00
Kevin Easton
790cb771ed Use 127.0.0.1 for wserv socket, which fixes /WINDOW CREATE with IPv6
If wserv is told to connect to "localhost" it might try to connect to ::1, which won't work because
the wserv socket is AF_INET only.

So explicitly bind the socket and make the connection to "127.0.0.1" instead.
2017-02-16 22:06:32 +11:00
Kevin Easton
1f062fb7de Remove unnecessary repeated check
tmp has already been tested in the previous line.
2017-02-12 23:55:16 +11:00
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