summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format38
-rw-r--r--.gitignore4
-rw-r--r--.travis.yml36
-rw-r--r--Makefile.am21
-rw-r--r--NEWS63
-rw-r--r--README.md160
-rwxr-xr-xautogen.sh40
-rw-r--r--configure.ac42
-rw-r--r--docs/Makefile.am4
-rw-r--r--docs/capsicum.txt31
-rw-r--r--docs/faq.html4
-rw-r--r--docs/faq.txt124
-rw-r--r--docs/help/in/clear.in6
-rw-r--r--docs/help/in/dcc.in2
-rw-r--r--docs/help/in/list.in10
-rw-r--r--docs/help/in/network.in2
-rw-r--r--docs/help/in/statusbar.in35
-rw-r--r--docs/startup-HOWTO.html510
-rw-r--r--docs/startup-HOWTO.txt797
-rw-r--r--fuzz-support/fuzz.diff269
-rw-r--r--m4/glibtests.m428
-rw-r--r--scripts/autorejoin.pl49
-rw-r--r--scripts/mail.pl1
-rw-r--r--scripts/usercount.pl1
-rw-r--r--src/common.h3
-rw-r--r--src/core/Makefile.am15
-rw-r--r--src/core/capsicum.c508
-rw-r--r--src/core/capsicum.h15
-rw-r--r--src/core/chat-commands.c14
-rw-r--r--src/core/core.c9
-rw-r--r--src/core/ignore.c40
-rw-r--r--src/core/ignore.h17
-rw-r--r--src/core/iregex-gregex.c165
-rw-r--r--src/core/iregex-regexh.c99
-rw-r--r--src/core/iregex.h47
-rw-r--r--src/core/levels.c21
-rw-r--r--src/core/levels.h4
-rw-r--r--src/core/log.c18
-rw-r--r--src/core/log.h2
-rw-r--r--src/core/misc.c163
-rw-r--r--src/core/misc.h1
-rw-r--r--src/core/network-openssl.c80
-rw-r--r--src/core/network-openssl.h6
-rw-r--r--src/core/network.c75
-rw-r--r--src/core/network.h9
-rw-r--r--src/core/nicklist.c63
-rw-r--r--src/core/rawlog.c37
-rw-r--r--src/core/recode.c7
-rw-r--r--src/core/settings.c10
-rw-r--r--src/core/settings.h7
-rw-r--r--src/core/special-vars.c13
-rw-r--r--src/fe-common/core/Makefile.am7
-rw-r--r--src/fe-common/core/chat-completion.c14
-rw-r--r--src/fe-common/core/command-history.c233
-rw-r--r--src/fe-common/core/command-history.h19
-rw-r--r--src/fe-common/core/completion.c56
-rw-r--r--src/fe-common/core/fe-capsicum.c63
-rw-r--r--src/fe-common/core/fe-capsicum.h7
-rw-r--r--src/fe-common/core/fe-channels.c2
-rw-r--r--src/fe-common/core/fe-common-core.c9
-rw-r--r--src/fe-common/core/fe-core-commands.c14
-rw-r--r--src/fe-common/core/fe-exec.c2
-rw-r--r--src/fe-common/core/fe-ignore.c5
-rw-r--r--src/fe-common/core/fe-log.c16
-rw-r--r--src/fe-common/core/fe-server.c33
-rw-r--r--src/fe-common/core/fe-settings.c7
-rw-r--r--src/fe-common/core/fe-settings.h6
-rw-r--r--src/fe-common/core/fe-windows.c4
-rw-r--r--src/fe-common/core/formats.c58
-rw-r--r--src/fe-common/core/hilight-text.c57
-rw-r--r--src/fe-common/core/hilight-text.h12
-rw-r--r--src/fe-common/core/module-formats.c3
-rw-r--r--src/fe-common/core/module-formats.h53
-rw-r--r--src/fe-common/core/themes.c7
-rw-r--r--src/fe-common/irc/dcc/fe-dcc-get.c2
-rw-r--r--src/fe-common/irc/dcc/fe-dcc-send.c2
-rw-r--r--src/fe-common/irc/fe-ircnet.c19
-rw-r--r--src/fe-fuzz/Makefile.am4
-rw-r--r--src/fe-fuzz/irssi.c2
-rw-r--r--src/fe-text/gui-entry.c20
-rw-r--r--src/fe-text/gui-entry.h1
-rw-r--r--src/fe-text/gui-readline.c47
-rw-r--r--src/fe-text/gui-windows.c4
-rw-r--r--src/fe-text/irssi.c52
-rw-r--r--src/fe-text/mainwindows-layout.c10
-rw-r--r--src/fe-text/module-formats.c22
-rw-r--r--src/fe-text/module-formats.h7
-rw-r--r--src/fe-text/statusbar-items.c4
-rw-r--r--src/fe-text/term-terminfo.c48
-rw-r--r--src/fe-text/term.h2
-rw-r--r--src/fe-text/textbuffer-commands.c21
-rw-r--r--src/fe-text/textbuffer-view.c69
-rw-r--r--src/fe-text/textbuffer-view.h36
-rw-r--r--src/fe-text/textbuffer.c46
-rw-r--r--src/fe-text/textbuffer.h2
-rw-r--r--src/irc/core/channel-events.c10
-rw-r--r--src/irc/core/channels-query.c7
-rw-r--r--src/irc/core/irc-chatnets.c7
-rw-r--r--src/irc/core/irc-chatnets.h1
-rw-r--r--src/irc/core/irc-nicklist.c19
-rw-r--r--src/irc/core/irc-servers-setup.c22
-rw-r--r--src/irc/core/irc-servers.c5
-rw-r--r--src/irc/core/irc.c34
-rw-r--r--src/irc/core/sasl.c6
-rw-r--r--src/irc/dcc/dcc-chat.c21
-rw-r--r--src/irc/dcc/dcc-get.c19
-rw-r--r--src/irc/dcc/dcc-resume.c2
-rw-r--r--src/irc/dcc/dcc-send.c10
-rw-r--r--src/perl/Makefile.am2
-rw-r--r--src/perl/common/Expando.xs3
-rw-r--r--src/perl/textui/Statusbar.xs4
-rw-r--r--src/perl/ui/Window.xs144
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/fe-common/Makefile.am1
-rw-r--r--tests/fe-common/core/Makefile.am28
-rw-r--r--tests/fe-common/core/test-formats.c50
-rw-r--r--tests/irc/Makefile.am1
-rw-r--r--tests/irc/core/Makefile.am29
-rw-r--r--tests/irc/core/test-irc.c231
-rw-r--r--themes/Makefile.am5
-rw-r--r--themes/colorless.theme (renamed from colorless.theme)0
-rw-r--r--themes/default.theme (renamed from default.theme)0
-rw-r--r--utils/Makefile.am6
-rwxr-xr-xutils/file2header.sh (renamed from file2header.sh)0
-rw-r--r--utils/glib-tap.mk134
-rwxr-xr-xutils/irssi-version.sh (renamed from irssi-version.sh)0
-rwxr-xr-xutils/syncdocs.sh102
-rwxr-xr-xutils/syncscripts.sh39
-rwxr-xr-xutils/syntax.pl (renamed from syntax.pl)0
-rwxr-xr-xutils/tap-driver.sh652
-rwxr-xr-xutils/tap-test5
131 files changed, 5497 insertions, 935 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..1180910e
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,38 @@
+# IndentPPDirectives: AfterHash
+# SpaceInParentheses: false
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Empty
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+BinPackArguments: true
+BinPackParameters: true
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Linux
+BreakBeforeTernaryOperators: false
+ColumnLimit: 100
+IndentCaseLabels: false
+IndentWidth: 8
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+Language: Cpp
+Cpp11BracedListStyle: false
+MaxEmptyLinesToKeep: 1
+PointerAlignment: Right
+SortIncludes: true
+SpaceAfterCStyleCast: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesInCStyleCastParentheses: false
+SpacesInSquareBrackets: false
+TabWidth: 8
+UseTab: ForIndentation
diff --git a/.gitignore b/.gitignore
index 9af0c4b1..cf1cf72e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,7 +11,6 @@ config.status
configure
default-config.h
default-theme.h
-faq.txt
irssi-config
irssi-config.h
irssi-config.h.in
@@ -50,6 +49,9 @@ src/perl/*/Makefile.old
src/fe-fuzz/crash-*
src/fe-fuzz/oom-*
+tests/irc/core/test-irc
+tests/irc/core/test-irc.trs
+
*.a
*.bs
*.la
diff --git a/.travis.yml b/.travis.yml
index 804dc58c..e2b3f57c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,26 @@
sudo: false
+dist: trusty
language: perl
perl:
- - "5.20-shrplib"
- - "5.18-shrplib"
+ # ~stretch
+ - "5.24-shrplib"
+ # ~xenial
+ # - "5.22-shrplib"
+ # ~jessie
+ # - "5.20-shrplib"
+ # ~trusty
+ # - "5.18-shrplib"
- "system-perl"
env:
- - CC=clang
- - CC=gcc
+ - CC=clang UNITTESTS=false
+ - CC=gcc UNITTESTS=false
+ - CC=clang UNITTESTS=true
+matrix:
+ exclude:
+ - env: CC=clang UNITTESTS=true
+ perl: "system-perl"
+ allow_failures:
+ - env: CC=clang UNITTESTS=true
addons:
apt:
@@ -24,11 +38,12 @@ before_install:
install:
- ./configure --with-proxy --with-bot --with-perl=module --prefix=$HOME/irssi-build
- - make CFLAGS="-Wall -Werror"
+ $( $UNITTESTS && echo --enable-always-build-tests )
+ - make CFLAGS="-Wall -Werror -Werror=declaration-after-statement"
- make install
before_script:
- - cd
+ - pushd ~
- mkdir irssi-test
- echo echo automated irssi launch test > irssi-test/startup;
echo ^set settings_autosave off >> irssi-test/startup;
@@ -40,7 +55,12 @@ before_script:
- echo load perl >> irssi-test/startup
- echo load proxy >> irssi-test/startup
- echo ^quit >> irssi-test/startup
+
+script:
- irssi-build/bin/irssi --home irssi-test
- - cat irc.log.*
+ - popd
+ - if $UNITTESTS; then make -C tests -sk check; fi
-script: true
+after_script:
+ - cat ~/irc.log.*
+ - find -name test-suite.log -exec cat {} +
diff --git a/Makefile.am b/Makefile.am
index 75d502f1..ba45d8ac 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,33 +7,26 @@ CLEANFILES = default-config.h default-theme.h
@MAINTAINER_MODE_TRUE@.PHONY: irssi-version.h
default-config.h: $(srcdir)/irssi.conf
- $(srcdir)/file2header.sh $(srcdir)/irssi.conf default_config > default-config.h
+ $(srcdir)/utils/file2header.sh $(srcdir)/irssi.conf default_config > default-config.h
-default-theme.h: $(srcdir)/default.theme
- $(srcdir)/file2header.sh $(srcdir)/default.theme default_theme > default-theme.h
+default-theme.h: $(srcdir)/themes/default.theme
+ $(srcdir)/utils/file2header.sh $(srcdir)/themes/default.theme default_theme > default-theme.h
irssi-version.h:
- VERSION="$(VERSION)" $(srcdir)/irssi-version.sh $(srcdir) | \
- cmp -s - $@ || VERSION="$(VERSION)" $(srcdir)/irssi-version.sh $(srcdir) >$@
+ VERSION="$(VERSION)" $(srcdir)/utils/irssi-version.sh $(srcdir) | \
+ cmp -s - $@ || VERSION="$(VERSION)" $(srcdir)/utils/irssi-version.sh $(srcdir) >$@
-SUBDIRS = src docs scripts
+SUBDIRS = src tests docs scripts themes utils
confdir = $(sysconfdir)
conf_DATA = irssi.conf
-themedir = $(datadir)/irssi/themes
-theme_DATA = default.theme colorless.theme
-
pkginclude_HEADERS = irssi-config.h irssi-version.h
EXTRA_DIST = \
ChangeLog \
autogen.sh \
README.md \
- file2header.sh \
$(conf_DATA) \
- $(theme_DATA) \
irssi-config.in \
- irssi-icon.png \
- irssi-version.sh \
- syntax.pl
+ irssi-icon.png
diff --git a/NEWS b/NEWS
index af330804..1054bb62 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,65 @@
-v1.1-head 2017-xx-xx The Irssi team <staff@irssi.org>
+v1.1-head 2018-xx-xx The Irssi team <staff@irssi.org>
+
+v1.0.6 2018-01-07 The Irssi team <staff@irssi.org>
+ - Fix invalid memory access when reading hilight configuration
+ (#787, #788).
+ - Fix null pointer dereference when the channel topic is set
+ without specifying a sender (GL#20, GL!25).
+ - Fix return of random memory when using incomplete escape
+ codes (GL#21, GL!26).
+ - Fix heap buffer overflow when completing certain strings
+ (GL#19, GL!27).
+ - Fix return of random memory when using an incomplete
+ variable argument (GL#18, GL!28).
+
+v1.0.5 2017-10-23 The Irssi team <staff@irssi.org>
+ - Fix missing -sasl_method '' in /NETWORK (#718, #719).
+ - Fix incorrect restoration of term state when hitting SUSP
+ inside screen (#737, #733).
+ - Fix out of bounds read when compressing colour
+ sequences. Found by Hanno Böck (GL#12, GL!18).
+ - Fix use after free condition during a race condition when
+ waiting on channel sync during a rejoin (GL#13, GL!19).
+ - Fix null pointer dereference when parsing certain malformed
+ CTCP DCC messages (GL#14, GL!20).
+ - Fix crash due to null pointer dereference when failing to
+ split messages due to overlong nick or target (GL#15, GL!21).
+ - Fix out of bounds read when trying to skip a safe channel ID
+ without verifying that the ID is long enough (GL#16, GL!22).
+ - Fix return of random memory when inet_ntop failed (#769).
+ - Minor statusbar help update. By Robert Bisewski (#758,
+ #763).
+
+v1.0.4 2017-07-07 The Irssi team <staff@irssi.org>
+ - Fix null pointer dereference when parsing invalid timestamp (GL#10,
+ GL!15). Reported by Brian 'geeknik' Carpenter.
+ - Fix use-after-free condition when removing nicks from the internal
+ nicklist (GL#11, GL!16). Reported by Brian 'geeknik' Carpenter.
+ - Fix incorrect string comparison in DCC file names (#714).
+ - Fix regression in Irssi 1.0.3 where it would claim "Invalid time '-1'"
+ (#716, #722).
+ - Fix a bug when using \n to separate lines with expand_escapes (#723).
+ - Retain screen output on improper exit, to better see any error
+ messages (#287, #721).
+ - Minor help update (#729).
+
+v1.0.3 2017-06-06 The Irssi team <staff@irssi.org>
+ - Fix out of bounds read when scanning expandos (GL!11).
+ - Fix invalid memory access with quoted filenames in DCC
+ (GL#8, GL!12).
+ - Fix null-pointer dereference on DCC without address (GL#9, GL!13).
+ - Improve integer overflow handling. Originally reported by
+ oss-fuzz#525 (#706).
+ - Improve nicklist performance from O(N^2) to O(N) (#705).
+ - Fix initial screen redraw delay. By Stephen Oberholtzer
+ (#680, bdo#856201).
+ - Fix incorrect reset of true colours when resetting background. (#711).
+ - Fix missing -notls option in /SERVER. By Jari Matilainen (#117, #702).
+ - Fix minor history glitch on overcounter (#462, #685).
+ - Improved OpenSSL detection at compile time. By Rodrigo Rebello (#677).
+ - Improved NetBSD Terminfo detection. By Maya Rashish (#694, #698).
+ - Add missing syntax info for COMPLETION (#687, #688).
+ - Minor typo correction in help. By Michael Hansen (#707).
v1.0.2 2017-03-10 The Irssi team <staff@irssi.org>
- Prevent some null-pointer crashes (GL!9).
diff --git a/README.md b/README.md
index d6577fdf..0f54ccf5 100644
--- a/README.md
+++ b/README.md
@@ -1,109 +1,73 @@
-# Irssi
+# [Irssi](https://irssi.org/)
[![Build Status](https://travis-ci.org/irssi/irssi.svg?branch=master)](https://travis-ci.org/irssi/irssi)
Irssi is a modular chat client that is most commonly known for its
text mode user interface, but 80% of the code isn't text mode
-specific. We have a working but currently unmaintained GTK2 frontend
-called xirssi. Irssi comes with IRC support built in, and there are
+specific. Irssi comes with IRC support built in, and there are
third party [ICB](https://github.com/jperkin/irssi-icb),
[SILC](http://www.silcnet.org/),
[XMPP](http://cybione.org/~irssi-xmpp/) (Jabber),
-[PSYC](https://github.com/electric-blue/irssyc) and
+[PSYC](http://about.psyc.eu/Irssyc) and
[Quassel](https://github.com/phhusson/quassel-irssi) protocol modules
available.
-## Installation
-
-See the `INSTALL` file.
-
-## Features
-
-So what's so great about Irssi? Here's a list of some features I can
-think of currently:
-
- - **Optional automation** - There's lots of things Irssi does for you
- automatically that some people like and others just hate. Things like:
- nick completion, creating new window for newly joined channel, creating
- queries when msgs/notices are received or when you send a msg, closing
- queries when it's been idle for some time, etc.
-
- - **Multiserver friendy** - I think Irssi has clearly the best support
- for handling multiple server connections. You can have as many as you
- want in as many ircnets as you want. Having several connections in one
- server works too, for example when you hit the (ircnet's) 10
- channels/connection limit you can just create another connection and
- you hardly notice it. If connection to server is lost, Irssi tries to
- connect back until it's successful. Also channels you were joined
- before disconnection are restored, even if they're "temporarily
- unavailable" because of netsplits, Irssi keeps rejoining back to them.
- Also worth noticing - there's not that stupid "server is bound to this
- window, if this window gets closed the connection closes" thing that
- ircII based clients have.
-
- - **Channel automation** - You can specify what channels to join to
- immediately after connected to some server or IRC network. After joined
- to channel, Irssi can automatically request ops for you (or do
- anything, actually) from channel's bots.
-
- - **Window content saving** - Say /LAYOUT SAVE when you've put all the
- channels and queries to their correct place, and after restarting
- Irssi, the channels will be joined back into windows where they were
- saved.
-
- - **Tab completing anything** - You can complete lots of things with tab:
- nicks, commands, command -options, file names, settings, text format
- names, channels and server names. There's also an excellent /msg
- completion that works transparently with multiple IRC networks.
- Completing channel nicks is also pretty intelligent, it first goes
- through the people who have talked to you recently, then the people who
- have talked to anyone recently and only then it fallbacks to rest of
- the nicks. You can also complete a set of words you've specified, for
- example homepage<tab> changes it to your actual home page URL.
-
- - **Excellent logging** - You can log any way you want and as easily or
- hard as you want. With autologging Irssi logs everything to specified
- directory, one file per channel/nick. ircII style /WINDOW LOG ON is
- also supported. There's also the "hard way" of logging - /LOG command
- which lets you specify exactly what you wish to log and where. Log
- rotating is supported with all the different logging methods, you can
- specify how often you want it to rotate and what kind of time stamp to
- use.
-
- - **Excellent ignoring** - You can most probably ignore anything any way
- you want. Nick masks, words, regular expressions. You can add
- exceptions to ignores. You can ignore other people's replies in
- channels to nicks you have ignored. You can also specify that the
- specific ignores work only in specific channel(s).
-
- - **Lastlog and scrollback handling** - /LASTLOG command has some new
- features: -new option checks only lines that came since you last did
- /LASTLOG command, -away option checks new lines since you last went
- away. Regular expression matches work also, of course. Going to some
- wanted place at scrollback has always been hard with non-GUI clients. A
- search command that jumps around in scrollback in GUI-style is still
- missing from Irssi, but there's something that's almost as good as it.
- /LASTLOG always shows timestamps when the line was printed, even if you
- didn't have timestamps on. Now doing /SB GOTO <timestamp> jumps
- directly to the position in scrollback you wanted. Great feature when
- you want to browse a bit of the discussion what happened when someone
- said your name (as seen in awaylog) or topic was changed (/last
- -topics)
-
-## Files
-
- - The `docs/` directory contains several documents:
- - `startup-HOWTO.txt` - new users should read this
- - `manual.txt` - manual I started writing but didn't get it very far :)
- - `perl.txt` - Perl scripting help
- - `formats.txt` - How to use colors, etc. with irssi
- - `faq.txt` - Frequently Asked Questions
- - `special_vars.txt` - some predefined $variables you can use with irssi
-
-## Bugs / Suggestions
-
-See the `TODO` file, http://bugs.irssi.org and the GitHub issues if it is
-already listed in there; if not, open an issue on GitHub or send a mail to
-[staff@irssi.org](mailto:staff@irssi.org).
-
-You can also contact the Irssi developers in #irssi on freenode.
+![irssi](https://user-images.githubusercontent.com/5665186/32180643-cf127f60-bd92-11e7-8aa2-882313ce1d8e.png)
+
+## [Download information](https://irssi.org/download/)
+
+#### Development source installation
+
+```
+git clone https://github.com/irssi/irssi
+cd irssi
+./autogen.sh
+make && sudo make install
+```
+
+#### Release source installation
+
+* Download [release](https://github.com/irssi/irssi/releases)
+* [Verify](https://irssi.org/download/#release-sources) signature
+```
+tar xJf irssi-*.tar.xz
+cd irssi-*
+./configure
+make && sudo make install
+```
+
+### Requirements
+
+- [glib-2.28](https://wiki.gnome.org/Projects/GLib) or greater
+- [openssl](https://www.openssl.org/)
+- [perl-5.6](https://www.perl.org/) or greater (for perl support)
+- terminfo or ncurses (for text frontend)
+
+#### See the [INSTALL](INSTALL) file for details
+
+## [Documentation](https://irssi.org/documentation/)
+
+* [Frequently Asked Questions](https://irssi.org/documentation/faq)
+* [Startup How-To](https://irssi.org/documentation/startup)
+* Check the built-in `/HELP`, it has all the details on command syntax
+
+## [Themes](https://irssi-import.github.io/themes/)
+
+## [Scripts](http://scripts.irssi.org/)
+
+## [Modules](https://irssi.org/modules/)
+
+## [Security information](https://irssi.org/security/)
+
+Please report security issues to staff@irssi.org. Thanks!
+
+## [Bugs](https://github.com/irssi/irssi/issues) / Suggestions / [Contributing](https://irssi.org/development/)
+
+Check the GitHub issues if it is already listed in there; if not, open
+an issue on GitHub or send a mail to [staff@irssi.org](mailto:staff@irssi.org).
+
+Irssi is always looking for developers. Feel free to submit patches through
+GitHub pull requests.
+
+You can also contact the Irssi developers in
+[#irssi](https://irssi.org/support/irc/) on freenode.
diff --git a/autogen.sh b/autogen.sh
index 946f1ebb..9feb0872 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -3,21 +3,24 @@
PKG_NAME="Irssi"
-srcdir=`dirname $0`
+srcdir=`dirname "$0"`
test -z "$srcdir" && srcdir=.
+mydir=`pwd`
-if test ! -f $srcdir/configure.ac; then
- echo -n "**Error**: Directory \`$srcdir\' does not look like the"
+if test ! -f "$srcdir"/configure.ac; then
+ echo -n "**Error**: Directory \`$srcdir' does not look like the"
echo " top-level $PKG_NAME directory"
exit 1
fi
+cd "$srcdir"
+
# create help files
echo "Creating help files..."
-perl syntax.pl
+perl utils/syntax.pl
echo "Creating ChangeLog..."
-git log > $srcdir/ChangeLog
+git log > ChangeLog
if test "$?" -ne 0; then
echo "**Error**: ${PKG_NAME} Autogen must be run in a git clone, cannot proceed."
exit 1
@@ -29,19 +32,6 @@ cat docs/help/in/Makefile.am.gen|sed "s/@HELPFILES@/$files/g"|sed 's/?/\\?/g'|tr
files=`echo $files|sed 's/\.in//g'`
cat docs/help/Makefile.am.gen|sed "s/@HELPFILES@/$files/g"|sed 's/?/\\?/g'|tr '!?' '\t\n' > docs/help/Makefile.am
-# .html -> .txt with lynx or elinks
-echo "Documentation: html -> txt..."
-if type lynx >/dev/null 2>&1 ; then
- LC_ALL=en_IE.utf8 lynx -dump docs/faq.html|perl -pe 's/^ *//; if ($_ eq "\n" && $state eq "Q") { $_ = ""; } elsif (/^([QA]):/) { $state = $1 } elsif ($_ ne "\n") { $_ = " $_"; };' > docs/faq.txt
-elif type elinks >/dev/null 2>&1 ; then
- elinks -dump docs/faq.html|perl -pe 's/^ *//; if ($_ eq "\n" && $state eq "Q") { $_ = ""; } elsif (/^([QA]):/) { $state = $1 } elsif ($_ ne "\n") { $_ = " $_"; };' > docs/faq.txt
-elif type links >/dev/null 2>&1 ; then
- links -dump docs/faq.html|perl -pe 's/^ *//; if ($_ eq "\n" && $state eq "Q") { $_ = ""; } elsif (/^([QA]):/) { $state = $1 } elsif ($_ ne "\n") { $_ = " $_"; };' > docs/faq.txt
-else
- echo "**Error**: No lynx or elinks present"
- exit 1
-fi
-
if test x$NOCONFIGURE = x && test -z "$*"; then
echo "**Warning**: I am going to run \`configure' with no arguments."
echo "If you wish to pass any to it, please specify them on the"
@@ -51,17 +41,19 @@ fi
rm -f aclocal.m4
echo "Running autoreconf ..."
-autoreconf -i || exit 1
+autoreconf -i || exit $?
+
+# make sure perl hashes have correct length
+find src/perl -name '*.c' -o -name '*.xs' -exec grep -n hv_store {} + | perl -l -ne 'if (/"(\w+)",\s*(\d+)/ && $2 != length $1) { $X=1; print "Incorrect key length in $_" } END { exit $X }'
+
+cd "$mydir"
conf_flags="--enable-maintainer-mode"
if test x$NOCONFIGURE = x; then
- echo Running $srcdir/configure $conf_flags "$@" ...
- $srcdir/configure $conf_flags "$@" \
+ echo Running "$srcdir"/configure $conf_flags "$@" ...
+ "$srcdir"/configure $conf_flags "$@" \
&& echo Now type \`make\' to compile $PKG_NAME || exit 1
else
echo Skipping configure process.
fi
-
-# make sure perl hashes have correct length
-find src/perl -name *.c -o -name *.xs | xargs grep -n hv_store | perl -ne 'if (/"(\w+)",\s*(\d+)/) { print unless $2 == length $1 }'
diff --git a/configure.ac b/configure.ac
index dd5064c9..76ada09f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -158,7 +158,7 @@ AC_ARG_ENABLE(true-color,
want_truecolor=no)
AC_ARG_ENABLE(gregex,
-[ --disable-gregex Build without GRegex (fall back to regex.h)],
+[ --disable-gregex Build without GRegex (fall back to regex.h)],
if test x$enableval = xno ; then
want_gregex=no
else
@@ -166,6 +166,15 @@ AC_ARG_ENABLE(gregex,
fi,
want_gregex=yes)
+AC_ARG_WITH(capsicum,
+[ --with-capsicum Build with Capsicum support],
+ if test x$withval = xno; then
+ want_capsicum=no
+ else
+ want_capsicum=yes
+ fi,
+ want_capsicum=yes)
+
dnl **
dnl ** just some generic stuff...
dnl **
@@ -286,6 +295,8 @@ fi
LIBS="$LIBS $GLIB_LIBS"
+GLIB_TESTS
+
dnl **
dnl ** OpenSSL checks
dnl **
@@ -308,7 +319,7 @@ if test "x$want_textui" != "xno"; then
TEXTUI_NO_LIBS="$LIBS"
LIBS=
- AC_SEARCH_LIBS([setupterm], [tinfo ncursesw ncurses], [want_textui=yes], [
+ AC_SEARCH_LIBS([setupterm], [tinfo ncursesw ncurses terminfo], [want_textui=yes], [
AC_ERROR(Terminfo not found - install libncurses-dev or ncurses-devel package)
want_textui="no, Terminfo not found"
])
@@ -499,12 +510,31 @@ if test "$want_perl" != "no"; then
fi
fi
+dnl **
+dnl ** check for capsicum
+dnl **
+
+if test "x$want_capsicum" = "xyes"; then
+ AC_CHECK_LIB(c, cap_enter, [
+ AC_CHECK_LIB(nv, nvlist_create, [
+ AC_DEFINE(HAVE_CAPSICUM,, Build with Capsicum support)
+ LIBS="$LIBS -lnv"
+ ], [
+ want_capsicum="no, nvlist_create not found"
+ ])
+ ], [
+ want_capsicum="no, cap_enter not found"
+ ])
+fi
+
dnl ** check what we want to build
AM_CONDITIONAL(BUILD_TEXTUI, test "$want_textui" = "yes")
AM_CONDITIONAL(BUILD_IRSSIBOT, test "$want_irssibot" = "yes")
AM_CONDITIONAL(BUILD_IRSSIFUZZER, test "$want_irssifuzzer" = "yes")
AM_CONDITIONAL(BUILD_IRSSIPROXY, test "$want_irssiproxy" = "yes")
AM_CONDITIONAL(HAVE_PERL, test "$want_perl" != "no")
+AM_CONDITIONAL(HAVE_CAPSICUM, test "x$want_capsicum" = "xyes")
+AM_CONDITIONAL(USE_GREGEX, test "x$want_gregex" = "xyes")
# move LIBS to PROG_LIBS so they're not tried to be used when linking eg. perl libraries
PROG_LIBS=$LIBS
@@ -630,9 +660,16 @@ src/perl/ui/Makefile.PL
src/perl/textui/Makefile.PL
scripts/Makefile
scripts/examples/Makefile
+tests/Makefile
+tests/fe-common/Makefile
+tests/fe-common/core/Makefile
+tests/irc/Makefile
+tests/irc/core/Makefile
docs/Makefile
docs/help/Makefile
docs/help/in/Makefile
+utils/Makefile
+themes/Makefile
irssi-config
])
@@ -712,6 +749,7 @@ echo
echo "Building with 64bit DCC support .. : $offt_64bit"
echo "Building with true color support.. : $want_truecolor"
echo "Building with GRegex ............. : $want_gregex"
+echo "Building with Capsicum ........... : $want_capsicum"
echo
echo "If there are any problems, read the INSTALL file."
diff --git a/docs/Makefile.am b/docs/Makefile.am
index 861a2ca4..8998ffb4 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -2,6 +2,7 @@ man_MANS = \
irssi.1
doc_DATA = \
+ capsicum.txt \
design.txt \
formats.txt \
manual.txt \
@@ -10,7 +11,8 @@ doc_DATA = \
perl.txt \
signals.txt \
special_vars.txt \
- startup-HOWTO.html
+ startup-HOWTO.html \
+ startup-HOWTO.txt
EXTRA_DIST = $(doc_DATA) $(man_MANS)
diff --git a/docs/capsicum.txt b/docs/capsicum.txt
new file mode 100644
index 00000000..a3a1b8a7
--- /dev/null
+++ b/docs/capsicum.txt
@@ -0,0 +1,31 @@
+Capsicum is a lightweight OS capability and sandbox framework provided
+by FreeBSD. When built with Capsicum support - which is the default under
+FreeBSD - Irssi can enter a Capsicum capability mode (a sandbox), greatly
+limiting possible consequences of a potential security hole in Irssi
+or the libraries it depends on.
+
+To make Irssi enter capability mode on startup, add
+
+capsicum = "yes";
+awaylog_file = "~/irclogs/away.log";
+
+to your ~/.irssi/config and restart the client. Alternatively you can
+enter it "by hand", using the "/capsicum enter" command. From the security
+point of view it's strongly preferable to use the former method, to avoid
+establishing connections without the sandbox protection; the "/capsicum"
+command is only intended for experimentation, and in cases where you need
+to do something that's not possible in capability mode - run scripts,
+for example - before continuing.
+
+There is no way to leave the capability mode, apart from exiting Irssi.
+When running in capability mode, there are certain restrictions - Irssi
+won't be able to access any files outside the directory pointed to by
+capsicum_irclogs_path (which defaults to ~/irclogs/). If you change
+the path when already in capability mode it won't be effective until
+you restart Irssi. Capability mode also makes it impossible to use
+the "/save" command.
+
+Currently there is no way to use custom SSL certificates. As a workaround
+you can establish connections and enter the capability mode afterwards
+using the "/capsicum enter" command.
+
diff --git a/docs/faq.html b/docs/faq.html
index 345060dc..70e90bb5 100644
--- a/docs/faq.html
+++ b/docs/faq.html
@@ -1,4 +1,6 @@
+<base href='https://irssi.org/documentation/faq/'>
<h1>Frequently Asked Questions</h1>
+
<h3 id="q-why-doesnt-irssi-display-colors-even-when-ircii-etc-displays-them">Q: Why doesn’t irssi display colors even when ircii etc. displays them?</h3>
<p>A: They force ANSI colors even if terminal doesn’t support them. By default, irssi uses colors only if terminfo/termcap so says. The correct way to fix this would be to change your TERM environment to a value where colors work, like xterm-color or color_xterm (eg. <code>TERM=xterm-color irssi</code>). If this doesn’t help, then use the evil way of <code>/SET term_force_colors ON</code>.</p>
@@ -77,4 +79,4 @@
<h3 id="q-how-to-pronounce-irssi">Q: How to pronounce Irssi?</h3>
-<p>A: Check <a href="https://irssi.org/assets/irssi.wav">here</a></p>
+<p>A: Check <a href="/assets/irssi.wav">here</a></p> \ No newline at end of file
diff --git a/docs/faq.txt b/docs/faq.txt
new file mode 100644
index 00000000..719fbb9a
--- /dev/null
+++ b/docs/faq.txt
@@ -0,0 +1,124 @@
+ Frequently Asked Questions
+
+Q: Why doesn’t irssi display colors even when ircii etc. displays them?
+A: They force ANSI colors even if terminal doesn’t support them. By default,
+ irssi uses colors only if terminfo/termcap so says. The correct way to fix this
+ would be to change your TERM environment to a value where colors work, like
+ xterm-color or color_xterm (eg. TERM=xterm-color irssi). If this doesn’t help,
+ then use the evil way of /SET term_force_colors ON.
+
+Q: How do I easily write text to channel that starts with ‘/’ character?
+A: / /text
+
+Q: Why doesn’t irssi update my realname (or whatever) after I change it with /
+ SET realname and reconnect with /RECONNECT or /SERVER?
+A: Irssi is trying to be too smart. This will be fixed in future, but for now
+ you should use /DISCONNECT and /CONNECT.
+
+Q: I connected to some server which isn’t responding but now irssi tries to
+ connect back to it all the time! How can I stop it?
+A: Two ways. The “good way” to do it is with /DISCONNECT. Check the server tags
+ first with /SERVER without giving it any parameters, reconnections are those
+ that have tag starting with “recon” text. So most probably you’re going to do /
+ DISCONNECT recon-1. The other way is to remove all the reconnections with /
+ RMRECONNS, easier but may remove some connections you actually wanted to
+ reconnect (if you used multiple servers..).
+
+Q: How do I add seconds to timestamp?
+A: /FORMAT timestamp {timestamp %%H:%%M:%%S} - and remember to add the trailing
+ space :)
+
+Q: Why does irssi say “Irssi: Channel not fully synchronized yet, try again
+ after a while” when I try to use /BAN etc?
+A: Possibly a bug in irssi, or ircd you’re using does something that irssi
+ didn’t really notice. The new code should make this happen far less often than
+ before, but one known reason for this is when irssi doesn’t notice that you
+ were unable to join some channel. Currently however I don’t know of any such
+ events irssi doesn’t know about.
+
+ Anyway, if this does happen, do /RAWLOG SAVE ~/rawlog soon after joining to
+ channel, and either try to figure out yourself why irssi didn’t get reply to
+ WHO request, or open a Github issue with the full log included. Note that the
+ rawlog is by default only 200 lines and it may not be enough to show all needed
+ information, so you might want to do /SET rawlog_lines 1000 or so.
+
+ MODE +b still works fine though.
+
+Q: Where’s the GUI version?
+A: There was one on [1]irssi-import/xirssi but it has not been maintained for a
+ long time.
+
+Q: How do I autorejoin channels after being kicked?
+A: That’s evil and you shouldn’t do it. If you get kicked, you should stay out,
+ at least until the channel forgot you existed :) Most channels I’ve joined just
+ ban you if you autorejoin after kick. If you’re joined to channels who kick
+ people for fun, try changing channels or something.
+
+ Anyway, if you REALLY want to do that, and you understand that you’re doing
+ evilness, you can use the autorejoin.pl script that comes with irssi. You’ll
+ still need to specify the channels you wish to rejoin with /SET
+ autorejoin_channels #chan1 #chan2 ...
+
+Q: How do I announce that I’m away/back in all channels I’ve joined? Or how do
+ I change my nick when setting myself away/back?
+A: That’s even worse than autorejoin. Who could possibly care every time you
+ come and go? Many channels will kick you for using this, and I for example have
+ added several ignores so I’d never need to see these messages. Learn to use /
+ AWAY command properly and tell its existence to people who don’t know about it.
+ /WII yournick shows your away reason much better for people who actually want
+ to know if you’re there or not.
+
+Q: Why does irssi autojoin on invite by default?
+A: The setting is /SET join_auto_chans_on_invite - it’s not the same as regular
+ autojoin-on-invite, which irssi doesn’t even have. The only channels that are
+ joined on invite, are the ones you’ve added to config with /CHANNEL ADD -auto.
+ This is very useful with +i channels when you need to first send an invite
+ request to bot, or if you get accidentally kicked from channel, the kicker can
+ invite you back immediately.
+
+ I don’t see any bad side effects with this feature, so it’s ON by default. I
+ guess someone could start kicking/inviting you all the time but server
+ connection shouldn’t drop because of that, and you shouldn’t join channels
+ whose operators are that evil.
+
+Q: How to make UTF-8 support work with irssi?
+A: Make sure your terminal supports UTF-8 (for example, xterm -u8). If you use
+ screen, you may have to do screen -U. And in Irssi do /SET term_charset utf-8.
+ (for 0.8.9 and older: /SET term_type utf-8)
+
+Q: Will there be /DETACH-like feature?
+A: [2]tmux, [3]screen and [4]dtach can be used to do it just fine.
+
+Q: How do I run scripts automatically at startup?
+A: Put them into ~/.irssi/scripts/autorun/ directory. Or better would be if you
+ placed them in ~/.irssi/scripts/ and created symlinks to autorun directory (eg.
+ cd ~/.irssi/scripts/autorun/ ; ln -s ../script.pl .)
+
+Q: How do I execute commands automatically at startup?
+A: Put them into ~/.irssi/startup file, each command on its own line. The
+ preceding slash (/) is not necessary.
+
+Q: How do I easily edit existing topic?
+A: /TOPIC <tab>
+
+Q: How can I have /WHOIS replies to active window?
+A: You can disable the status window, or do /WINDOW LEVEL -CRAP in it which
+ would also make several other messages show up in active window. You can also
+ use a [5]script.
+
+Q: How do I add the active network to the statusbar
+A: Modify the window-line in statusbar section in config file to window = "{sb
+ $winref:$tag/$T{sbmode $M}}";
+
+Q: How to pronounce Irssi?
+A: Check [6]here
+
+
+ References:
+
+ [1] https://github.com/irssi-import/xirssi
+ [2] http://tmux.github.io/
+ [3] http://www.gnu.org/software/screen/screen.html
+ [4] http://dtach.sf.net/
+ [5] http://dgl.cx/irssi/hack-whois-in-current-window.pl
+ [6] https://irssi.org/assets/irssi.wav
diff --git a/docs/help/in/clear.in b/docs/help/in/clear.in
index d43830dd..3b76a7c9 100644
--- a/docs/help/in/clear.in
+++ b/docs/help/in/clear.in
@@ -12,8 +12,8 @@
%9Description:%9
- Clears the window of all text; you may use this to clear a windows that
- contains sensitive information or has rendered improperly.
+ Scrolls up the text in the window and fills the window with blank lines; you
+ may want to use this to make new text start at the top of the window again.
-%9See also:%9 REDRAW
+%9See also:%9 REDRAW, SCROLLBACK CLEAR
diff --git a/docs/help/in/dcc.in b/docs/help/in/dcc.in
index 18a77ee9..2e58c9b1 100644
--- a/docs/help/in/dcc.in
+++ b/docs/help/in/dcc.in
@@ -27,7 +27,7 @@
and file transfers.
If you are behind NAT, or if the firewall is too restrictive, you might
- want to try if using the passive parameter resolved your connection
+ want to try if using the passive parameter resolves your connection
problem.
You can send files which contain special character or spaces by enclosing
diff --git a/docs/help/in/list.in b/docs/help/in/list.in
index b796eed0..6dda79e6 100644
--- a/docs/help/in/list.in
+++ b/docs/help/in/list.in
@@ -24,11 +24,15 @@
%9Remarks:%9
- Not all networks support server-side filtering and may provide a network
+ Not all networks support server-side filtering. Some provide a network
service or service bot instead; on IRCnet, you may use the List service:
- /SQUERY List HELP
- /MSG ALIS HELP
+ /SQUERY Alis HELP
+
+ Other networks with service bots (like ChanServ) may also provide a list
+ service bot (confirm with /WHOIS ALIS):
+
+ /MSG Alis HELP
%9See also:%9 STATS, SQUERY, WHOIS
diff --git a/docs/help/in/network.in b/docs/help/in/network.in
index ba08ef69..fbdaa0b4 100644
--- a/docs/help/in/network.in
+++ b/docs/help/in/network.in
@@ -11,6 +11,7 @@
REMOVE: Removes a network from your configuration.
-nick: Specifies the nickname to use.
+ -alternate_nick Specifies the alternate nickname to use.
-user: Specifies the user identity to use.
-realname: Specifies the real name to use.
-host: Specifies the hostname to use.
@@ -36,6 +37,7 @@
-sasl_mechanism Specifies the mechanism to use for the SASL authentication.
At the moment irssi only supports the 'plain' and the
'external' mechanisms.
+ Use '' to disable the authentication.
-sasl_username Specifies the username to use during the SASL authentication.
-sasl_password Specifies the password to use during the SASL authentication.
diff --git a/docs/help/in/statusbar.in b/docs/help/in/statusbar.in
index ac475dd5..7d64b816 100644
--- a/docs/help/in/statusbar.in
+++ b/docs/help/in/statusbar.in
@@ -5,22 +5,33 @@
%9Parameters:%9
- ENABLE: Enables the statusbar.
- DISABLE: Disabled the statusbar.
+ ENABLE: Adds a statusbar to the list of statusbars.
+ DISABLE: Removes a statusbar from the list. Note that for
+ built-in statusbars they can be enabled again should the
+ user wish to add back the default statusbars.
RESET: Restores the default statusbar configuration.
- TYPE: Identifies the type of statusbar.
- PLACEMENT: Identifies the placement of the statusbar.
- POSITION: Identifies the position of the statusbar.
- VISIBLE: Identifies the visibility of the statusbar.
- ADD: Adds a statusbar into the configuration.
- REMOVE: Removes a statusbar from the configuration.
-
- The name of the statusbar; if no argument is given, the list of statusbars
- will be displayed.
+ TYPE: Sets the type of statusbar, for each split window or only
+ for the current root screen.
+ PLACEMENT: Sets the placement of the statusbar, either at the top or
+ the bottom of the screen.
+ POSITION: Sets the position of the statusbar. Represented as a
+ number, with 0 implying the first position.
+ VISIBLE: Sets the visibility of the statusbar or item. If set to
+ always it is visible on all screens, otherwise if set to
+ inactive or active then it is only visible on inactive
+ or active screens, respectively.
+ ADD: Adds an item to the specified statusbar. It can be set to
+ appear before/after another item and left/right aligned
+ to a specified position on the screen.
+ REMOVE: Removes an item from the specified statusbar.
+
+ Where name refers to the name of the statusbar; if no argument is
+ given, the entire list of statusbars will be displayed.
%9Description:%9
- Modified the attributes of the statusbar.
+ Allows adjustment of the attributes and items of a statusbar, as well
+ as where it is located and whether or not it is currently visible.
%9Examples:%9
diff --git a/docs/startup-HOWTO.html b/docs/startup-HOWTO.html
index 07a9f47c..aaf9e5fe 100644
--- a/docs/startup-HOWTO.html
+++ b/docs/startup-HOWTO.html
@@ -1,4 +1,6 @@
- <h1>Startup How-To</h1>
+<base href='https://irssi.org/documentation/startup/'>
+<h1>Startup How-To</h1>
+
<h3 id="to-new-irssi-users-not-to-new-irc-users-">To new Irssi users (not to new IRC users ..)</h3>
<p>Copyright (c) 2000-2002 by Timo Sirainen, release under <a href="http://www.gnu.org/licenses/fdl.html">GNU FDL</a> 1.1 license.</p>
@@ -6,11 +8,7 @@
<p>Index with some FAQ questions that are answered in the chapter:</p>
<ol>
- <li><a href="#for-all-the-ircii-people">For all the ircII people</a>
- <ul>
- <li>This window management is just weird, I want it exactly like ircII</li>
- </ul>
- </li>
+ <li><a href="#first-steps">First steps</a></li>
<li><a href="#basic-user-interface-usage">Basic user interface usage</a>
<ul>
<li>Split windows work in weird way</li>
@@ -50,7 +48,11 @@
</ul>
</li>
<li><a href="#proxies-and-irc-bouncers">Proxies and IRC bouncers</a></li>
- <li><a href="#irssis-settings">Irssi’s settings</a></li>
+ <li><a href="#irssis-settings">Irssi’s settings</a>
+ <ul>
+ <li><a href="#for-all-the-ircii-people">For all the ircII people</a></li>
+ </ul>
+ </li>
<li><a href="#statusbar">Statusbar</a>
<ul>
<li>I loaded a statusbar script but it’s not visible anywhere!</li>
@@ -58,169 +60,176 @@
</li>
</ol>
-<h2 id="for-all-the-ircii-people">1. For all the ircII people</h2>
+<h2 id="first-steps">1. First steps</h2>
-<p>These settings should give you pretty good defaults (the ones I use):</p>
+<p>IRC Networks are made of servers, and servers have channels. The default config has a few predefined networks, to list them:</p>
-<p>If colors don’t work, and you know you’re not going to use some weird non-VT compatible terminal (you most probably aren’t), just say:</p>
+<div><div><pre><code>/NETWORK LIST
+</code></pre></div></div>
-<pre><code> /SET term_force_colors ON
-</code></pre>
+<p>And to connect to one of those networks and join a channel:</p>
-<p>I don’t like automatic query windows, I don’t like status window, I do like msgs window where all messages go:</p>
+<div><div><pre><code>/CONNECT Freenode
+/JOIN #irssi
+</code></pre></div></div>
-<pre><code> /SET autocreate_own_query OFF
- /SET autocreate_query_level DCCMSGS
- /SET use_status_window OFF
- /SET use_msgs_window ON
-</code></pre>
+<p>To add more networks:</p>
-<p>Disable automatic window closing when <code>/PART</code>ing channel or <code>/UNQUERY</code>ing query:</p>
+<div><div><pre><code>/NETWORK ADD ExampleNet
+</code></pre></div></div>
-<pre><code> /SET autoclose_windows OFF
- /SET reuse_unused_windows ON
-</code></pre>
+<p>Then add some servers (with -auto to automatically connect):</p>
-<p>Here’s the settings that make irssi work exactly like ircII in window management (send me a note if you can think of more):</p>
+<div><div><pre><code>/SERVER ADD -auto -network ExampleNet irc.example.net
+</code></pre></div></div>
-<pre><code> /SET autocreate_own_query OFF
- /SET autocreate_query_level NONE
- /SET use_status_window OFF
- /SET use_msgs_window OFF
- /SET reuse_unused_windows ON
- /SET windows_auto_renumber OFF
+<p>Automatically join to channels after connected to server:</p>
- /SET autostick_split_windows OFF
- /SET autoclose_windows OFF
- /SET print_active_channel ON
-</code></pre>
+<div><div><pre><code>/CHANNEL ADD -auto #lounge ExampleNet
+</code></pre></div></div>
-<p>And example how to add servers:</p>
+<p>To modify existing networks (or servers, or channels) just ADD again using the same name as before. This configures a network to identify with nickserv and wait for 2 seconds before joining channels:</p>
-<p>(OFTC network, identify with nickserv and wait for 2 seconds before joining channels)</p>
+<div><div><pre><code>/NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" ExampleNet
+</code></pre></div></div>
-<pre><code> /NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" OFTC
-</code></pre>
+<p>If you have irssi 0.8.18 or higher and the irc network supports it, you can use SASL instead of nickserv, which is more reliable:</p>
-<p>(NOTE: use /IRCNET with 0.8.9 and older)</p>
+<div><div><pre><code>/NETWORK ADD -sasl_username yourname -sasl_password yourpassword -sasl_mechanism PLAIN Freenode
+</code></pre></div></div>
-<p>Then add some servers to different networks (network is already set up for them), irc.kpnqwest.fi is used by default for IRCNet but if it fails, irc.funet.fi is tried next:</p>
+<p>These commands have many more options, see their help for details:</p>
-<pre><code> /SERVER ADD -auto -network IRCnet irc.kpnqwest.fi 6667
- /SERVER ADD -network IRCnet irc.funet.fi 6667
- /SERVER ADD -auto -network efnet efnet.cs.hut.fi 6667
-</code></pre>
+<div><div><pre><code>/HELP NETWORK
+/HELP SERVER
+/HELP CHANNEL
+/HELP
+</code></pre></div></div>
-<p>Automatically join to channels after connected to server, send op request to bot after joined to efnet/#irssi:</p>
+<p>If you want lines containing your nick to hilight:</p>
-<pre><code> /CHANNEL ADD -auto #irssi IRCnet
- /CHANNEL ADD -auto -bots *!*bot@host.org -botcmd "/^msg $0 op pass" #irssi efnet
-</code></pre>
+<div><div><pre><code>/HILIGHT nick
+</code></pre></div></div>
-<p>If you want lines containing your nick to hilight:</p>
+<p>Or, for irssi 0.8.18 or higher:</p>
+
+<div><div><pre><code>/SET hilight_nick_matches_everywhere ON
+</code></pre></div></div>
+
+<p>To get beeps on private messages or highlights:</p>
+
+<div><div><pre><code>/SET beep_msg_level MSGS HILIGHT DCCMSGS
+</code></pre></div></div>
-<pre><code> /HILIGHT nick
-</code></pre>
+<p>No other irssi settings are needed (don’t enable bell_beeps), but there may be settings to change in your terminal multiplexer (screen/tmux), your terminal, or your desktop environment.</p>
<h2 id="basic-user-interface-usage">2. Basic user interface usage</h2>
<p>Windows can be scrolled up/down with PgUp and PgDown keys. If they don’t work for you, use Meta-p and Meta-n keys. For jumping to beginning or end of the buffer, use <code>/SB HOME</code> and <code>/SB END</code> commands.</p>
-<p>By default, irssi uses “hidden windows” for everything. Hidden window is created every time you <code>/JOIN</code> a channel or <code>/QUERY</code> someone. There’s several ways you can change between these windows:</p>
+<p>By default, irssi uses “hidden windows” for everything. Hidden windows are created every time you <code>/JOIN</code> a channel or <code>/QUERY</code> someone. There’s several ways you can change between these windows:</p>
-<pre><code> Meta-1, Meta-2, .. Meta-0 - Jump directly between windows 1-10
- Meta-q .. Meta-o - Jump directly between windows 11-19
- /WINDOW &lt;number&gt; - Jump to any window with specified number
- Ctrl-P, Ctrl-N - Jump to previous / next window
-</code></pre>
+<div><div><pre><code>Meta-1, Meta-2, .. Meta-0 - Jump directly between windows 1-10
+Meta-q .. Meta-o - Jump directly between windows 11-19
+/WINDOW &lt;number&gt; - Jump to any window with specified number
+Ctrl-P, Ctrl-N - Jump to previous / next window
+</code></pre></div></div>
-<p>Clearly the easiest way is to use Meta-number keys. And what is the Meta key? ESC key always works as Meta, but there’s also easier ways. ALT could work as Meta, or if you have Windows keyboard, left Windows key might work as Meta. If they don’t work directly, you’ll need to set a few X resources (NOTE: these work with both xterm and rxvt):</p>
+<p>Clearly the easiest way is to use Meta-number keys. Meta usually means the ALT key, but if that doesn’t work, you can use ESC.</p>
-<pre><code> XTerm*eightBitInput: false
+<p>Mac OS X users with ALT key issues might prefer using <a href="https://www.iterm2.com/">iTerm2</a> instead of the default terminal emulator.</p>
+
+<h3 id="alt-key-as-meta-for-xtermrxvt-users">Alt key as meta, for xterm/rxvt users</h3>
+
+<p>If you use xterm or rxvt, you may need to set a few X resources:</p>
+
+<div><div><pre><code> XTerm*eightBitInput: false
XTerm*metaSendsEscape: true
-</code></pre>
+</code></pre></div></div>
<p>With rxvt, you can also specify which key acts as Meta key. So if you want to use ALT instead of Windows key for it, use:</p>
-<pre><code> rxvt*modifier: alt
-</code></pre>
+<div><div><pre><code> rxvt*modifier: alt
+</code></pre></div></div>
<p>You could do this by changing the X key mappings:</p>
-<pre><code> xmodmap -e "keysym Alt_L = Meta_L Alt_L"
-</code></pre>
+<div><div><pre><code> xmodmap -e "keysym Alt_L = Meta_L Alt_L"
+</code></pre></div></div>
<p>And how exactly do you set these X resources? For Debian, there’s <code>/etc/X11/Xresources/xterm</code> file where you can put them and it’s read automatically when X starts. <code>~/.Xresources</code> and <code>~/.Xdefaults</code> files might also work. If you can’t get anything else to work, just copy and paste those lines to <code>~/.Xresources</code> and directly call <code>xrdb -merge ~/.Xresources</code> in some xterm. The resources affect only the new xterms you start, not existing ones.</p>
-<p>Many windows SSH clients also don’t allow usage of ALT. One excellent client that does allow is putty, you can download it from <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/"> http://www.chiark.greenend.org.uk/~sgtatham/putty/</a>.</p>
+<h3 id="split-windows-and-window-items">Split windows and window items</h3>
+
+<p><em>Note: <a href="http://quadpoint.org/articles/irssisplit/">this guide</a> might be a better introduction to window splits</em></p>
<p>Irssi also supports split windows, they’ve had some problems in past but I think they should work pretty well now :) Here’s some commands related to them:</p>
-<pre><code> /WINDOW NEW - Create new split window
- /WINDOW NEW HIDE - Create new hidden window
- /WINDOW CLOSE - Close split or hidden window
+<div><div><pre><code>/WINDOW NEW - Create new split window
+/WINDOW NEW HIDE - Create new hidden window
+/WINDOW CLOSE - Close split or hidden window
- /WINDOW HIDE [&lt;number&gt;|&lt;name&gt;] - Make the split window hidden window
- /WINDOW SHOW &lt;number&gt;|&lt;name&gt; - Make the hidden window a split window
+/WINDOW HIDE [&lt;number&gt;|&lt;name&gt;] - Make the split window hidden window
+/WINDOW SHOW &lt;number&gt;|&lt;name&gt; - Make the hidden window a split window
- /WINDOW SHRINK [&lt;lines&gt;] - Shrink the split window
- /WINDOW GROW [&lt;lines&gt;] - Grow the split window
- /WINDOW BALANCE - Balance the sizes of all split windows
-</code></pre>
+/WINDOW SHRINK [&lt;lines&gt;] - Shrink the split window
+/WINDOW GROW [&lt;lines&gt;] - Grow the split window
+/WINDOW BALANCE - Balance the sizes of all split windows
+</code></pre></div></div>
<p>By default, irssi uses “sticky windowing” for split windows. This means that windows created inside one split window cannot be moved to another split window without some effort. For example you could have following window layout:</p>
-<pre><code> Split window 1: win#1 - Status window, win#2 - Messages window
+<div><div><pre><code> Split window 1: win#1 - Status window, win#2 - Messages window
Split window 2: win#3 - IRCnet/#channel1, win#4 - IRCnet/#channel2
Split window 3: win#5 - efnet/#channel1, win#6 - efnet/#channel2
-</code></pre>
+</code></pre></div></div>
<p>When you are in win#1 and press ALT-6, irssi jumps to split window #3 and moves the efnet/#channel2 the active window.</p>
<p>With non-sticky windowing the windows don’t have any relationship with split windows, pressing ALT-6 in win#1 moves win#6 to split window 1 and sets it active, except if win#6 was already visible in some other split window irssi just changes to that split window. This it the way windows work with ircii, if you prefer it you can set it with</p>
-<pre><code> /SET autostick_split_windows OFF
-</code></pre>
+<div><div><pre><code>/SET autostick_split_windows OFF
+</code></pre></div></div>
<p>Each window can have multiple channels, queries and other “window items” inside them. If you don’t like windows at all, you disable automatic creating of them with</p>
-<pre><code> /SET autocreate_windows OFF
-</code></pre>
+<div><div><pre><code>/SET autocreate_windows OFF
+</code></pre></div></div>
<p>And if you keep all channels in one window, you most probably want the channel name printed in each line:</p>
-<pre><code> /SET print_active_channel ON
-</code></pre>
+<div><div><pre><code>/SET print_active_channel ON
+</code></pre></div></div>
<p>If you want to group only some channels or queries in one window, use</p>
-<pre><code> /JOIN -window #channel
- /QUERY -window nick
-</code></pre>
+<div><div><pre><code>/JOIN -window #channel
+/QUERY -window nick
+</code></pre></div></div>
<h2 id="server-and-channel-automation">3. Server and channel automation</h2>
<p>Irssi’s multiple IRC network support is IMHO very good - at least compared to other clients :) Even if you’re only in one IRC network you should group all your servers to be in the same IRC network as this helps with reconnecting if your primary server breaks and is probably useful in some other ways too :) For information how to actually use irssi correctly with multiple servers see the chapter 6.</p>
-<p>First you need to have your IRC network set, use <code>/NETWORK</code> command to see if it’s already there. If it isn’t, use <code>/NETWORK ADD yournetwork</code>. If you want to execute some commands automatically when you’re connected to some network, use <code>-autosendcmd</code> option. (NOTE: use /IRCNET with 0.8.9 and older.) Here’s some examples:</p>
+<p>First you need to have your IRC network set, use <code>/NETWORK</code> command to see if it’s already there. If it isn’t, use <code>/NETWORK ADD yournetwork</code>. If you want to execute some commands automatically when you’re connected to some network, use <code>-autosendcmd</code> option. Here’s some examples:</p>
-<pre><code> /NETWORK ADD -autosendcmd '^msg bot invite' IRCnet
- /NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" OFTC
-</code></pre>
+<div><div><pre><code>/NETWORK ADD -autosendcmd '^msg bot invite' IRCnet
+/NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" OFTC
+</code></pre></div></div>
<p>After that you need to add your servers. For example:</p>
-<pre><code> /SERVER ADD -auto -network IRCnet irc.kpnqwest.fi 6667
- /SERVER ADD -auto -network worknet irc.mycompany.com 6667 password
-</code></pre>
+<div><div><pre><code>/SERVER ADD -auto -network IRCnet irc.kpnqwest.fi 6667
+/SERVER ADD -auto -network worknet irc.mycompany.com 6667 password
+</code></pre></div></div>
<p>The <code>-auto</code> option specifies that this server is automatically connected at startup. You don’t need to make more than one server with <code>-auto</code> option to one IRC network, other servers are automatically connected in same network if the <code>-auto</code> server fails.</p>
<p>And finally channels:</p>
-<pre><code> /CHANNEL ADD -auto -bots *!*bot@host.org -botcmd "/^msg $0 op pass" #irssi efnet
- /CHANNEL ADD -auto #secret IRCnet password
-</code></pre>
+<div><div><pre><code>/CHANNEL ADD -auto -bots *!*user@host -botcmd "/^msg $0 op pass" #irssi efnet
+/CHANNEL ADD -auto #secret IRCnet password
+</code></pre></div></div>
<p><code>-bots</code> and <code>-botcmd</code> should be the only ones needing a bit of explaining. They’re used to send commands automatically to bot when channel is joined, usually to get ops automatically. You can specify multiple bot masks with <code>-bots</code> option separated with spaces (and remember to quote the string then). The $0 in <code>-botcmd</code> specifies the first found bot in the list. If you don’t need the bot masks (ie. the bot is always with the same nick, like chanserv) you can give only the <code>-botcmd</code> option and the command is always sent.</p>
@@ -228,9 +237,9 @@
<p>First connect to all the servers, join the channels and create the queries you want. If you want to move the windows or channels around use commands:</p>
-<pre><code> /WINDOW MOVE LEFT/RIGHT/number - move window elsewhere
- /WINDOW ITEM MOVE &lt;number&gt;|&lt;name&gt; - move channel/query to another window
-</code></pre>
+<div><div><pre><code>/WINDOW MOVE LEFT/RIGHT/number - move window elsewhere
+/WINDOW ITEM MOVE &lt;number&gt;|&lt;name&gt; - move channel/query to another window
+</code></pre></div></div>
<p>When everything looks the way you like, use <code>/LAYOUT SAVE</code> command (and <code>/SAVE</code>, if you don’t have autosaving enabled) and when you start irssi next time, irssi remembers the positions of the channels, queries and everything. This “remembering” doesn’t mean that simply using <code>/LAYOUT SAVE</code> would automatically make irssi reconnect to all servers and join all channels, you’ll need the <code>/SERVER ADD -auto</code> and <code>/CHANNEL ADD -auto</code> commands to do that.</p>
@@ -240,32 +249,32 @@
<p>By default, all the “extra messages” go to status window. This means pretty much all messages that don’t clearly belong to some channel or query. Some people like it, some don’t. If you want to remove it, use</p>
-<pre><code> /SET use_status_window OFF
-</code></pre>
+<div><div><pre><code>/SET use_status_window OFF
+</code></pre></div></div>
<p>This doesn’t have any effect until you restart irssi. If you want to remove it immediately, just <code>/WINDOW CLOSE</code> it.</p>
<p>Another common window is “messages window”, where all private messages go. By default it’s disabled and query windows are created instead. To make all private messages go to msgs window, say:</p>
-<pre><code> /SET use_msgs_window ON
- /SET autocreate_query_level DCCMSGS (or if you don't want queries to
+<div><div><pre><code>/SET use_msgs_window ON
+/SET autocreate_query_level DCCMSGS (or if you don't want queries to
dcc chats either, say NONE)
-</code></pre>
+</code></pre></div></div>
<p>use_msgs_window either doesn’t have any effect until restarting irssi. To create it immediately say:</p>
-<pre><code> /WINDOW NEW HIDE - create the window
- /WINDOW NAME (msgs) - name it to "(msgs)"
- /WINDOW LEVEL MSGS - make all private messages go to this window
- /WINDOW MOVE 1 - move it to first window
-</code></pre>
+<div><div><pre><code>/WINDOW NEW HIDE - create the window
+/WINDOW NAME (msgs) - name it to "(msgs)"
+/WINDOW LEVEL MSGS - make all private messages go to this window
+/WINDOW MOVE 1 - move it to first window
+</code></pre></div></div>
<p>Note that neither use_msgs_window nor use_status_window have any effect at all if <code>/LAYOUT SAVE</code> has been used.</p>
<p>This brings us to message levels.. What are they? All messages that irssi prints have one or more “message levels”. Most common are PUBLIC for public messages in channels, MSGS for private messages and CRAP for all sorts of messages with no real classification. You can get a whole list of levels with</p>
-<pre><code> /HELP levels
-</code></pre>
+<div><div><pre><code>/HELP levels
+</code></pre></div></div>
<p>Status window has message level <code>ALL -MSGS</code>, meaning that all messages, except private messages, without more specific place go to status window. The <code>-MSGS</code> is there so it doesn’t conflict with messages window.</p>
@@ -273,15 +282,15 @@
<p>ircii and several other clients support multiple servers by placing the connection into some window. IRSSI DOES NOT. There is no required relationship between window and server. You can connect to 10 servers and manage them all in just one window, or join channel in each one of them to one single window if you really want to. That being said, here’s how you do connect to new server without closing the old connection:</p>
-<pre><code> /CONNECT irc.server.org
-</code></pre>
+<div><div><pre><code>/CONNECT irc.server.org
+</code></pre></div></div>
<p>Instead of the <code>/SERVER</code> which disconnects the existing connection. To see list of all active connections, use <code>/SERVER</code> without any parameters. You should see a list of something like:</p>
-<pre><code> -!- IRCNet: irc.song.fi:6667 (IRCNet)
+<div><div><pre><code> -!- IRCNet: irc.song.fi:6667 (IRCNet)
-!- OFTC: irc.oftc.net:6667 (OFTC)
-!- RECON-1: 192.168.0.1:6667 () (02:59 left before reconnecting)
-</code></pre>
+</code></pre></div></div>
<p>Here you see that we’re connected to IRCNet and OFTC networks. The IRCNet at the beginning is called the “server tag” while the (IRCnet) at the end shows the IRC network. Server tag specifies unique tag to refer to the server, usually it’s the same as the IRC network. When the IRC network isn’t known it’s some part of the server name. When there’s multiple connections to same IRC network or server, irssi adds a number after the tag so there could be network, network2, network3 etc.</p>
@@ -289,63 +298,63 @@
<p>To disconnect one of the servers, or to stop irssi from reconnecting, use</p>
-<pre><code> /DISCONNECT network - disconnect server with tag "network"
- /DISCONNECT recon-1 - stop trying to reconnect to RECON-1 server
- /RMRECONNS - stop all server reconnections
+<div><div><pre><code>/DISCONNECT network - disconnect server with tag "network"
+/DISCONNECT recon-1 - stop trying to reconnect to RECON-1 server
+/RMRECONNS - stop all server reconnections
- /RECONNECT recon-1 - immediately try reconnecting back to RECON-1
- /RECONNECT ALL - immediately try reconnecting back to all
+/RECONNECT recon-1 - immediately try reconnecting back to RECON-1
+/RECONNECT ALL - immediately try reconnecting back to all
servers in reconnection queue
-</code></pre>
+</code></pre></div></div>
<p>Now that you’re connected to all your servers, you’ll have to know how to specify which one of them you want to use. One way is to have an empty window, like status or msgs window. In it, you can specify which server to set active with</p>
-<pre><code> /WINDOW SERVER tag - set server "tag" active
- Ctrl-X - set the next server in list active
-</code></pre>
+<div><div><pre><code>/WINDOW SERVER tag - set server "tag" active
+Ctrl-X - set the next server in list active
+</code></pre></div></div>
<p>When the server is active, you can use it normally. When there’s multiple connected servers, irssi adds [servertag] prefix to all messages in non-channel/query messages so you’ll know where it came from.</p>
<p>Several commands also accept <code>-servertag</code> option to specify which server it should use:</p>
-<pre><code> /MSG -tag nick message
- /JOIN -tag #channel
- /QUERY -tag nick
-</code></pre>
+<div><div><pre><code>/MSG -tag nick message
+/JOIN -tag #channel
+/QUERY -tag nick
+</code></pre></div></div>
<p><code>/MSG</code> tab completion also automatically adds the <code>-tag</code> option when nick isn’t in active server.</p>
<p>Window’s server can be made sticky. When sticky, it will never automatically change to anything else, and if server gets disconnected, the window won’t have any active server. When the server gets connected again, it is automatically set active in the window. To set the window’s server sticky use</p>
-<pre><code> /WINDOW SERVER -sticky tag
-</code></pre>
+<div><div><pre><code>/WINDOW SERVER -sticky tag
+</code></pre></div></div>
<p>This is useful if you wish to have multiple status or msgs windows, one for each server. Here’s how to do them (repeat for each server)</p>
-<pre><code> /WINDOW NEW HIDE
- /WINDOW NAME (status)
- /WINDOW LEVEL ALL -MSGS
- /WINDOW SERVER -sticky network
+<div><div><pre><code>/WINDOW NEW HIDE
+/WINDOW NAME (status)
+/WINDOW LEVEL ALL -MSGS
+/WINDOW SERVER -sticky network
- /WINDOW NEW HIDE
- /WINDOW NAME (msgs)
- /WINDOW LEVEL MSGS
- /WINDOW SERVER -sticky network
-</code></pre>
+/WINDOW NEW HIDE
+/WINDOW NAME (msgs)
+/WINDOW LEVEL MSGS
+/WINDOW SERVER -sticky network
+</code></pre></div></div>
<h2 id="lastlog-and-jumping-around-in-scrollback">7. /LASTLOG and jumping around in scrollback</h2>
<p><code>/LASTLOG</code> command can be used for searching texts in scrollback buffer. Simplest usages are</p>
-<pre><code> /LASTLOG word - print all lines with "word" in them
- /LASTLOG word 10 - print last 10 occurances of "word"
- /LASTLOG -topics - print all topic changes
-</code></pre>
+<div><div><pre><code>/LASTLOG word - print all lines with "word" in them
+/LASTLOG word 10 - print last 10 occurances of "word"
+/LASTLOG -topics - print all topic changes
+</code></pre></div></div>
<p>If there’s more than 1000 lines to be printed, irssi thinks that you probably made some mistake and won’t print them without <code>-force</code> option. If you want to save the full lastlog to file, use</p>
-<pre><code> /LASTLOG -file ~/irc.log
-</code></pre>
+<div><div><pre><code>/LASTLOG -file ~/irc.log
+</code></pre></div></div>
<p>With <code>-file</code> option you don’t need <code>-force</code> even if there’s more than 1000 lines. <code>/LASTLOG</code> has a lot of other options too, see <code>/HELP lastlog</code> for details.</p>
@@ -355,29 +364,29 @@
<p>Irssi can automatically log important messages when you’re set away (<code>/AWAY reason</code>). When you set yourself unaway (<code>/AWAY</code>), the new messages in away log are printed to screen. You can configure it with:</p>
-<pre><code> /SET awaylog_level MSGS HILIGHT - Specifies what messages to log
- /SET awaylog_file ~/.irssi/away.log - Specifies the file to use
-</code></pre>
+<div><div><pre><code>/SET awaylog_level MSGS HILIGHT - Specifies what messages to log
+/SET awaylog_file ~/.irssi/away.log - Specifies the file to use
+</code></pre></div></div>
<p>Easiest way to start logging with Irssi is to use autologging. With it Irssi logs all channels and private messages to specified directory. You can turn it on with</p>
-<pre><code> /SET autolog ON
-</code></pre>
+<div><div><pre><code>/SET autolog ON
+</code></pre></div></div>
<p>By default it logs pretty much everything execept CTCPS or CRAP (<code>/WHOIS</code> requests, etc). You can specify the logging level yourself with</p>
-<pre><code> /SET autolog_level ALL -CRAP -CLIENTCRAP -CTCPS (this is the default)
-</code></pre>
+<div><div><pre><code>/SET autolog_level ALL -CRAP -CLIENTCRAP -CTCPS (this is the default)
+</code></pre></div></div>
<p>By default irssi logs to ~/irclogs/<servertag>/<target>.log. You can change this with</target></servertag></p>
-<pre><code> /SET autolog_path ~/irclogs/$tag/$0.log (this is the default)
-</code></pre>
+<div><div><pre><code>/SET autolog_path ~/irclogs/$tag/$0.log (this is the default)
+</code></pre></div></div>
<p>The path is automatically created if it doesn’t exist. $0 specifies the target (channel/nick). You can make irssi automatically rotate the logs by adding date/time formats to the file name. The formats are in “man strftime” format. For example</p>
-<pre><code> /SET autolog_path ~/irclogs/%Y/$tag/$0.%m-%d.log
-</code></pre>
+<div><div><pre><code>/SET autolog_path ~/irclogs/%Y/$tag/$0.%m-%d.log
+</code></pre></div></div>
<p>For logging only some specific channels or nicks, see <code>/HELP log</code></p>
@@ -387,16 +396,16 @@
<p><code>/HELP bind</code> tells pretty much everything there is to know about keyboard bindings. However, there’s the problem of how to bind some non-standard keys. They might differ a bit with each terminal, so you’ll need to find out what exactly the keypress produces. Easiest way to check that would be to see what it prints in <code>cat</code>. Here’s an example for pressing F1 key:</p>
-<pre><code> [cras@hurina] ~% cat
+<div><div><pre><code> [user@host] ~% cat
^[OP
-</code></pre>
+</code></pre></div></div>
<p>So in irssi you would use <code>/BIND ^[OP /ECHO F1 pressed</code>. If you use multiple terminals which have different bindings for the key, it would be better to use eg.:</p>
-<pre><code> /BIND ^[OP key F1
- /BIND ^[11~ key F1
- /BIND F1 /ECHO F1 pressed.
-</code></pre>
+<div><div><pre><code>/BIND ^[OP key F1
+/BIND ^[11~ key F1
+/BIND F1 /ECHO F1 pressed.
+</code></pre></div></div>
<h2 id="proxies-and-irc-bouncers">10. Proxies and IRC bouncers</h2>
@@ -404,20 +413,20 @@
<p>Here’s an example: You have your bouncer (lets say, BNC or BNC-like) listening in irc.bouncer.org port 5000. You want to use it to connect to servers irc.dalnet and irc.efnet.org. First you’d need to setup the bouncer:</p>
-<pre><code> /SET use_proxy ON
- /SET proxy_address irc.bouncer.org
- /SET proxy_port 5000
+<div><div><pre><code>/SET use_proxy ON
+/SET proxy_address irc.bouncer.org
+/SET proxy_port 5000
- /SET proxy_password YOUR_BNC_PASSWORD_HERE
- /SET -clear proxy_string
- /SET proxy_string_after conn %s %d
-</code></pre>
+/SET proxy_password YOUR_BNC_PASSWORD_HERE
+/SET -clear proxy_string
+/SET proxy_string_after conn %s %d
+</code></pre></div></div>
<p>Then you’ll need to add the server connections. These are done exactly as if you’d want to connect directly to them. Nothing special about them:</p>
-<pre><code> /SERVER ADD -auto -network dalnet irc.dal.net
- /SERVER ADD -auto -network efnet irc.efnet.org
-</code></pre>
+<div><div><pre><code>/SERVER ADD -auto -network dalnet irc.dal.net
+/SERVER ADD -auto -network efnet irc.efnet.org
+</code></pre></div></div>
<p>With the proxy <code>/SET</code>s however, irssi now connects to those servers through your BNC. All server connections are made through them so you can just forget that your bouncer even exists.</p>
@@ -427,36 +436,36 @@
<p>All proxies have these settings in common:</p>
-<pre><code> /SET use_proxy ON
- /SET proxy_address &lt;Proxy host address&gt;
- /SET proxy_port &lt;Proxy port&gt;
-</code></pre>
+<div><div><pre><code>/SET use_proxy ON
+/SET proxy_address &lt;Proxy host address&gt;
+/SET proxy_port &lt;Proxy port&gt;
+</code></pre></div></div>
<p><strong>HTTP proxy</strong></p>
<p>Use these settings with HTTP proxies:</p>
-<pre><code> /SET -clear proxy_password
- /EVAL SET proxy_string CONNECT %s:%d HTTP/1.0\n\n
-</code></pre>
+<div><div><pre><code>/SET -clear proxy_password
+/EVAL SET proxy_string CONNECT %s:%d HTTP/1.0\n\n
+</code></pre></div></div>
<p><strong>BNC</strong></p>
-<pre><code> /SET proxy_password your_pass
- /SET -clear proxy_string
- /SET proxy_string_after conn %s %d
-</code></pre>
+<div><div><pre><code>/SET proxy_password your_pass
+/SET -clear proxy_string
+/SET proxy_string_after conn %s %d
+</code></pre></div></div>
<p><strong>dircproxy</strong></p>
<p>dircproxy separates the server connections by passwords. So, if you for example have network connection with password ircpass and OFTC connection with oftcpass, you would do something like this:</p>
-<pre><code> /SET -clear proxy_password
- /SET -clear proxy_string
+<div><div><pre><code>/SET -clear proxy_password
+/SET -clear proxy_string
- /SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
- /SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
-</code></pre>
+/SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
+/SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
+</code></pre></div></div>
<p>The server name and port you give isn’t used anywhere, so you can put anything you want in there.</p>
@@ -464,19 +473,17 @@
<p>psyBNC has internal support for multiple servers. However, it could be a bit annoying to use, and some people just use different users for connecting to different servers. You can manage this in a bit same way as with dircproxy, by creating fake connections:</p>
-<pre><code> /SET -clear proxy_password
- /SET -clear proxy_string
+<div><div><pre><code>/SET -clear proxy_password
+/SET -clear proxy_string
- /NETWORK ADD -user networkuser IRCnet
- /SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
- /NETWORK ADD -user oftcuser OFTC
- /SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
-</code></pre>
+/NETWORK ADD -user networkuser IRCnet
+/SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
+/NETWORK ADD -user oftcuser OFTC
+/SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
+</code></pre></div></div>
<p>So, you’ll specify the usernames with <code>/NETWORK ADD</code> command, and the user’s password with <code>/SERVER ADD</code>.</p>
-<p>(NOTE: use /IRCNET with 0.8.9 and older.)</p>
-
<p><strong>Irssi proxy</strong></p>
<p>Irssi contains it’s own proxy which you can build giving <code>\--with-proxy</code> option to configure. You’ll still need to run irssi in a screen to use it though.</p>
@@ -487,65 +494,52 @@
<p>Usage in proxy side:</p>
-<pre><code> /LOAD proxy
- /SET irssiproxy_password &lt;password&gt;
- /SET irssiproxy_ports &lt;network&gt;=&lt;port&gt; ... (eg. IRCnet=2777 efnet=2778)
-</code></pre>
+<div><div><pre><code>/LOAD proxy
+/SET irssiproxy_password &lt;password&gt;
+/SET irssiproxy_ports &lt;network&gt;=&lt;port&gt; ... (eg. IRCnet=2777 efnet=2778)
+</code></pre></div></div>
<p><strong>NOTE</strong>: you <strong>MUST</strong> add all the servers you are using to server and network lists with <code>/SERVER ADD</code> and <code>/NETWORK ADD</code>. ..Except if you really don’t want to for some reason, and you only use one server connection, you may simply set:</p>
-<pre><code> /SET irssiproxy_ports *=2777
-</code></pre>
-
-<p>The special network name <code>?</code> allows the client to select the
-network dynamically on connect (see below):</p>
-
-<pre>
-/SET irssiproxy_ports ?=2777
-</pre>
+<div><div><pre><code>/SET irssiproxy_ports *=2777
+</code></pre></div></div>
<p>Usage in client side:</p>
<p>Just connect to the irssi proxy like it is a normal server with password specified in <code>/SET irssiproxy_password</code>. For example:</p>
-<pre><code> /SERVER ADD -network IRCnet my.irssi-proxy.org 2777 secret
- /SERVER ADD -network efnet my.irssi-proxy.org 2778 secret
-</code></pre>
-
-<p>Or, if you used <code>?</code> in <code>irssiproxy_ports</code>:</p>
-
-<pre>
-/SERVER ADD -network IRCnet my.irssi-proxy.org 2777 IRCnet:secret
-/SERVER ADD -network efnet my.irssi-proxy.org 2777 efnet:secret
-</pre>
-
-<p>I.e. the network to connect to is specified as part of the password,
-separated by <code>:</code> from the actual proxy password.</p>
+<div><div><pre><code>/SERVER ADD -network IRCnet my.irssi-proxy.org 2777 secret
+/SERVER ADD -network efnet my.irssi-proxy.org 2778 secret
+</code></pre></div></div>
<p>Irssi proxy works fine with other IRC clients as well.</p>
<p><strong>SOCKS</strong></p>
-<p>Irssi can be compiled with socks support (<code>\--with-socks</code> option to configure), but I don’t really know how it works, if at all. <code>/SET proxy</code> settings don’t have anything to do with socks however.</p>
+<p>Irssi can be compiled with socks support (<code>\--with-socks</code> option to configure), which requires “dante” and routes all connections through the proxy specified in the system-wide /etc/socks.conf. This method is known to have issues in Mac OS X.</p>
+
+<p>Note that <code>/SET proxy</code> settings don’t have anything to do with socks.</p>
+
+<p>Using <a href="https://github.com/rofl0r/proxychains-ng">proxychains-ng</a> is recommended over recompiling irssi.</p>
<p><strong>Others</strong></p>
<p>IRC bouncers usually work like IRC servers, and want a password. You can give it with:</p>
-<pre><code> /SET proxy_password &lt;password&gt;
-</code></pre>
+<div><div><pre><code>/SET proxy_password &lt;password&gt;
+</code></pre></div></div>
<p>Irssi’s defaults for connect strings are</p>
-<pre><code> /SET proxy_string CONNECT %s %d
- /SET proxy_string_after
-</code></pre>
+<div><div><pre><code>/SET proxy_string CONNECT %s %d
+/SET proxy_string_after
+</code></pre></div></div>
<p>The proxy_string is sent before NICK/USER commands, the proxy_string_after is sent after them. %s and %d can be used with both of them.</p>
<h2 id="irssis-settings">11. Irssi’s settings</h2>
-<p>You probably don’t like Irssi’s default settings. I don’t like them. But I’m still convinced that they’re pretty good defaults. Here’s some of them you might want to change (the default value is shown): Also check the <a href="/documentation/settings/">Settings Documentation</a></p>
+<p>Here’s some settings you might want to change (the default value is shown): Also check the <a href="/documentation/settings/">Settings Documentation</a></p>
<p><strong>Queries</strong></p>
@@ -633,31 +627,61 @@ separated by <code>:</code> from the actual proxy password.</p>
<dd>Completion character to use.</dd>
</dl>
+<h3 id="for-all-the-ircii-people">For all the ircII people</h3>
+
+<p>I don’t like automatic query windows, I don’t like status window, I do like msgs window where all messages go:</p>
+
+<div><div><pre><code>/SET autocreate_own_query OFF
+/SET autocreate_query_level DCCMSGS
+/SET use_status_window OFF
+/SET use_msgs_window ON
+</code></pre></div></div>
+
+<p>Disable automatic window closing when <code>/PART</code>ing channel or <code>/UNQUERY</code>ing query:</p>
+
+<div><div><pre><code>/SET autoclose_windows OFF
+/SET reuse_unused_windows ON
+</code></pre></div></div>
+
+<p>Here’s the settings that make irssi work exactly like ircII in window management (send me a note if you can think of more):</p>
+
+<div><div><pre><code>/SET autocreate_own_query OFF
+/SET autocreate_query_level NONE
+/SET use_status_window OFF
+/SET use_msgs_window OFF
+/SET reuse_unused_windows ON
+/SET windows_auto_renumber OFF
+
+/SET autostick_split_windows OFF
+/SET autoclose_windows OFF
+/SET print_active_channel ON
+</code></pre></div></div>
+
<h2 id="statusbar">12. Statusbar</h2>
-<p><code>/STATUSBAR</code> displays a list of statusbars:</p>
+<p><code>/STATUSBAR</code> displays a list of the current statusbars, along with their position and visibility:</p>
-<pre><code> Name Type Placement Position Visible
+<div><div><pre><code> Name Type Placement Position Visible
window window bottom 0 always
window_inact window bottom 1 inactive
prompt root bottom 100 always
topic root top 1 always
-</code></pre>
+</code></pre></div></div>
-<p><code>/STATUSBAR &lt;name&gt;</code> prints the statusbar settings and it’s items. <code>/STATUSBAR &lt;name&gt; ENABLE|DISABLE</code> enables/disables the statusbar. <code>/STATUSBAR &lt;name&gt; RESET</code> resets the statusbar to it’s default settings, or if the statusbar was created by you, it will be removed.</p>
+<p><code>/STATUSBAR &lt;name&gt;</code> prints the statusbar settings (type, placement, position, visibility) as well as its items. <code>/STATUSBAR &lt;name&gt; ENABLE|DISABLE</code> enables/disables the statusbar. <code>/STATUSBAR &lt;name&gt; RESET</code> resets the statusbar to its default settings, or if the statusbar was created by you, it will be removed.</p>
-<p>Type can be window or root, meaning if the statusbar should be created for each split window, or just once. Placement can be top or bottom. Position is a number, the higher the value the lower in screen it is. Visible can be always, active or inactive. Active/inactive is useful only with split windows, one split window is active and the rest are inactive. These settings can be changed with:</p>
+<p>The statusbar type can be either window or root. If the type is window, then a statusbar will be created for each split window, otherwise it will be created only once. Placement can be top or bottom, which refers to the top or bottom of the screen. Position is a number, the higher the value the lower it will appear in-screen. Visible can be always, active or inactive. Active/inactive is useful only with split windows; one split window is active and the rest are inactive. To adjust these settings, the following commands are available:</p>
-<pre><code> /STATUSBAR &lt;name&gt; TYPE window|root
- /STATUSBAR &lt;name&gt; PLACEMENT top|bottom
- /STATUSBAR &lt;name&gt; POSITION &lt;num&gt;
- /STATUSBAR &lt;name&gt; VISIBLE always|active|inactive
-</code></pre>
+<div><div><pre><code>/STATUSBAR &lt;name&gt; TYPE window|root
+/STATUSBAR &lt;name&gt; PLACEMENT top|bottom
+/STATUSBAR &lt;name&gt; POSITION &lt;num&gt;
+/STATUSBAR &lt;name&gt; VISIBLE always|active|inactive
+</code></pre></div></div>
-<p>When loading a new statusbar scripts, you’ll need to also specify where you want to show it. Statusbar items can be modified with:</p>
+<p>Statusbar items can also be added or removed via command. Note that when loading new statusbar scripts that add items, you will need to specify where you want to show the item and how it is aligned. This can be accomplished using the below commands:</p>
-<pre><code> /STATUSBAR &lt;name&gt; ADD [-before | -after &lt;item&gt;] [-priority #] [-alignment left|right] &lt;item&gt;
- /STATUSBAR &lt;name&gt; REMOVE &lt;item&gt;
-</code></pre>
+<div><div><pre><code>/STATUSBAR &lt;name&gt; ADD [-before | -after &lt;item&gt;] [-priority #] [-alignment left|right] &lt;item&gt;
+/STATUSBAR &lt;name&gt; REMOVE &lt;item&gt;
+</code></pre></div></div>
-<p>The item name with statusbar scripts is usually same as the script’s name. Script’s documentation should tell if this isn’t the case. So, to add mail.pl before the window activity item (see the list with <code>/STATUSBAR</code> window), use: <code>/STATUSBAR window ADD -before act mail</code>.</p>
+<p>For statusbar scripts, the item name is usually equivalent to the script name. The documentation of the script ought to tell you if this is not the case. For example, to add mail.pl before the window activity item, use: <code>/STATUSBAR window ADD -before act mail</code>.</p> \ No newline at end of file
diff --git a/docs/startup-HOWTO.txt b/docs/startup-HOWTO.txt
new file mode 100644
index 00000000..23d7cf94
--- /dev/null
+++ b/docs/startup-HOWTO.txt
@@ -0,0 +1,797 @@
+Startup How-To
+
+To new Irssi users (not to new IRC users ..)
+
+Copyright (c) 2000-2002 by Timo Sirainen, release under [1]GNU FDL 1.1 license.
+
+Index with some FAQ questions that are answered in the chapter:
+
+ 1. First steps
+ 2. Basic user interface usage
+ □ Split windows work in weird way
+ □ How can I easily switch between windows?
+ □ But alt-1 etc. don’t work!
+ 3. Server and channel automation
+ □ How do I automatically connect to servers at startup?
+ □ How do I automatically join to channels at startup?
+ □ How do I automatically send commands to server at connect?
+ 4. Setting up windows and automatically restoring them at startup
+ 5. Status and msgs windows & message levels
+ □ I want /WHOIS to print reply to current window
+ □ I want all messages to go to one window, not create new windows
+ 6. How support for multiple servers works in irssi
+ □ I connected to some server that doesn’t respond and now irssi keeps
+ trying to reconnect to it again and again, how can I stop it??
+ □ I want to have own status and/or msgs window for each servers
+ 7. /LASTLOG and jumping around in scrollback
+ □ How can I save all texts in a window to file?
+ 8. Logging
+ 9. Changing keyboard bindings
+ □ How do I make F1 key do something?
+10. Proxies and IRC bouncers
+11. Irssi’s settings
+ □ For all the ircII people
+12. Statusbar
+ □ I loaded a statusbar script but it’s not visible anywhere!
+
+1. First steps
+
+IRC Networks are made of servers, and servers have channels. The default config
+has a few predefined networks, to list them:
+
+/NETWORK LIST
+
+And to connect to one of those networks and join a channel:
+
+/CONNECT Freenode
+/JOIN #irssi
+
+To add more networks:
+
+/NETWORK ADD ExampleNet
+
+Then add some servers (with -auto to automatically connect):
+
+/SERVER ADD -auto -network ExampleNet irc.example.net
+
+Automatically join to channels after connected to server:
+
+/CHANNEL ADD -auto #lounge ExampleNet
+
+To modify existing networks (or servers, or channels) just ADD again using the
+same name as before. This configures a network to identify with nickserv and
+wait for 2 seconds before joining channels:
+
+/NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" ExampleNet
+
+If you have irssi 0.8.18 or higher and the irc network supports it, you can use
+SASL instead of nickserv, which is more reliable:
+
+/NETWORK ADD -sasl_username yourname -sasl_password yourpassword -sasl_mechanism PLAIN Freenode
+
+These commands have many more options, see their help for details:
+
+/HELP NETWORK
+/HELP SERVER
+/HELP CHANNEL
+/HELP
+
+If you want lines containing your nick to hilight:
+
+/HILIGHT nick
+
+Or, for irssi 0.8.18 or higher:
+
+/SET hilight_nick_matches_everywhere ON
+
+To get beeps on private messages or highlights:
+
+/SET beep_msg_level MSGS HILIGHT DCCMSGS
+
+No other irssi settings are needed (don’t enable bell_beeps), but there may be
+settings to change in your terminal multiplexer (screen/tmux), your terminal,
+or your desktop environment.
+
+2. Basic user interface usage
+
+Windows can be scrolled up/down with PgUp and PgDown keys. If they don’t work
+for you, use Meta-p and Meta-n keys. For jumping to beginning or end of the
+buffer, use /SB HOME and /SB END commands.
+
+By default, irssi uses “hidden windows” for everything. Hidden windows are
+created every time you /JOIN a channel or /QUERY someone. There’s several ways
+you can change between these windows:
+
+Meta-1, Meta-2, .. Meta-0 - Jump directly between windows 1-10
+Meta-q .. Meta-o - Jump directly between windows 11-19
+/WINDOW <number> - Jump to any window with specified number
+Ctrl-P, Ctrl-N - Jump to previous / next window
+
+Clearly the easiest way is to use Meta-number keys. Meta usually means the ALT
+key, but if that doesn’t work, you can use ESC.
+
+Mac OS X users with ALT key issues might prefer using [2]iTerm2 instead of the
+default terminal emulator.
+
+Alt key as meta, for xterm/rxvt users
+
+If you use xterm or rxvt, you may need to set a few X resources:
+
+ XTerm*eightBitInput: false
+ XTerm*metaSendsEscape: true
+
+With rxvt, you can also specify which key acts as Meta key. So if you want to
+use ALT instead of Windows key for it, use:
+
+ rxvt*modifier: alt
+
+You could do this by changing the X key mappings:
+
+ xmodmap -e "keysym Alt_L = Meta_L Alt_L"
+
+And how exactly do you set these X resources? For Debian, there’s /etc/X11/
+Xresources/xterm file where you can put them and it’s read automatically when X
+starts. ~/.Xresources and ~/.Xdefaults files might also work. If you can’t get
+anything else to work, just copy and paste those lines to ~/.Xresources and
+directly call xrdb -merge ~/.Xresources in some xterm. The resources affect
+only the new xterms you start, not existing ones.
+
+Split windows and window items
+
+Note: [3]this guide might be a better introduction to window splits
+
+Irssi also supports split windows, they’ve had some problems in past but I
+think they should work pretty well now :) Here’s some commands related to them:
+
+/WINDOW NEW - Create new split window
+/WINDOW NEW HIDE - Create new hidden window
+/WINDOW CLOSE - Close split or hidden window
+
+/WINDOW HIDE [<number>|<name>] - Make the split window hidden window
+/WINDOW SHOW <number>|<name> - Make the hidden window a split window
+
+/WINDOW SHRINK [<lines>] - Shrink the split window
+/WINDOW GROW [<lines>] - Grow the split window
+/WINDOW BALANCE - Balance the sizes of all split windows
+
+By default, irssi uses “sticky windowing” for split windows. This means that
+windows created inside one split window cannot be moved to another split window
+without some effort. For example you could have following window layout:
+
+ Split window 1: win#1 - Status window, win#2 - Messages window
+ Split window 2: win#3 - IRCnet/#channel1, win#4 - IRCnet/#channel2
+ Split window 3: win#5 - efnet/#channel1, win#6 - efnet/#channel2
+
+When you are in win#1 and press ALT-6, irssi jumps to split window #3 and moves
+the efnet/#channel2 the active window.
+
+With non-sticky windowing the windows don’t have any relationship with split
+windows, pressing ALT-6 in win#1 moves win#6 to split window 1 and sets it
+active, except if win#6 was already visible in some other split window irssi
+just changes to that split window. This it the way windows work with ircii, if
+you prefer it you can set it with
+
+/SET autostick_split_windows OFF
+
+Each window can have multiple channels, queries and other “window items” inside
+them. If you don’t like windows at all, you disable automatic creating of them
+with
+
+/SET autocreate_windows OFF
+
+And if you keep all channels in one window, you most probably want the channel
+name printed in each line:
+
+/SET print_active_channel ON
+
+If you want to group only some channels or queries in one window, use
+
+/JOIN -window #channel
+/QUERY -window nick
+
+3. Server and channel automation
+
+Irssi’s multiple IRC network support is IMHO very good - at least compared to
+other clients :) Even if you’re only in one IRC network you should group all
+your servers to be in the same IRC network as this helps with reconnecting if
+your primary server breaks and is probably useful in some other ways too :) For
+information how to actually use irssi correctly with multiple servers see the
+chapter 6.
+
+First you need to have your IRC network set, use /NETWORK command to see if
+it’s already there. If it isn’t, use /NETWORK ADD yournetwork. If you want to
+execute some commands automatically when you’re connected to some network, use
+-autosendcmd option. Here’s some examples:
+
+/NETWORK ADD -autosendcmd '^msg bot invite' IRCnet
+/NETWORK ADD -autosendcmd "/^msg nickserv ident pass;wait 2000" OFTC
+
+After that you need to add your servers. For example:
+
+/SERVER ADD -auto -network IRCnet irc.kpnqwest.fi 6667
+/SERVER ADD -auto -network worknet irc.mycompany.com 6667 password
+
+The -auto option specifies that this server is automatically connected at
+startup. You don’t need to make more than one server with -auto option to one
+IRC network, other servers are automatically connected in same network if the
+-auto server fails.
+
+And finally channels:
+
+/CHANNEL ADD -auto -bots *!*user@host -botcmd "/^msg $0 op pass" #irssi efnet
+/CHANNEL ADD -auto #secret IRCnet password
+
+-bots and -botcmd should be the only ones needing a bit of explaining. They’re
+used to send commands automatically to bot when channel is joined, usually to
+get ops automatically. You can specify multiple bot masks with -bots option
+separated with spaces (and remember to quote the string then). The $0 in
+-botcmd specifies the first found bot in the list. If you don’t need the bot
+masks (ie. the bot is always with the same nick, like chanserv) you can give
+only the -botcmd option and the command is always sent.
+
+4. Setting up windows and automatically restoring them at startup
+
+First connect to all the servers, join the channels and create the queries you
+want. If you want to move the windows or channels around use commands:
+
+/WINDOW MOVE LEFT/RIGHT/number - move window elsewhere
+/WINDOW ITEM MOVE <number>|<name> - move channel/query to another window
+
+When everything looks the way you like, use /LAYOUT SAVE command (and /SAVE, if
+you don’t have autosaving enabled) and when you start irssi next time, irssi
+remembers the positions of the channels, queries and everything. This
+“remembering” doesn’t mean that simply using /LAYOUT SAVE would automatically
+make irssi reconnect to all servers and join all channels, you’ll need the /
+SERVER ADD -auto and /CHANNEL ADD -auto commands to do that.
+
+If you want to change the layout, you just rearrange the layout like you want
+it and use /LAYOUT SAVE again. If you want to remove the layout for some
+reason, use /LAYOUT RESET.
+
+5. Status and msgs windows & message levels
+
+By default, all the “extra messages” go to status window. This means pretty
+much all messages that don’t clearly belong to some channel or query. Some
+people like it, some don’t. If you want to remove it, use
+
+/SET use_status_window OFF
+
+This doesn’t have any effect until you restart irssi. If you want to remove it
+immediately, just /WINDOW CLOSE it.
+
+Another common window is “messages window”, where all private messages go. By
+default it’s disabled and query windows are created instead. To make all
+private messages go to msgs window, say:
+
+/SET use_msgs_window ON
+/SET autocreate_query_level DCCMSGS (or if you don't want queries to
+ dcc chats either, say NONE)
+
+use_msgs_window either doesn’t have any effect until restarting irssi. To
+create it immediately say:
+
+/WINDOW NEW HIDE - create the window
+/WINDOW NAME (msgs) - name it to "(msgs)"
+/WINDOW LEVEL MSGS - make all private messages go to this window
+/WINDOW MOVE 1 - move it to first window
+
+Note that neither use_msgs_window nor use_status_window have any effect at all
+if /LAYOUT SAVE has been used.
+
+This brings us to message levels.. What are they? All messages that irssi
+prints have one or more “message levels”. Most common are PUBLIC for public
+messages in channels, MSGS for private messages and CRAP for all sorts of
+messages with no real classification. You can get a whole list of levels with
+
+/HELP levels
+
+Status window has message level ALL -MSGS, meaning that all messages, except
+private messages, without more specific place go to status window. The -MSGS is
+there so it doesn’t conflict with messages window.
+
+6. How support for multiple servers works in irssi
+
+ircii and several other clients support multiple servers by placing the
+connection into some window. IRSSI DOES NOT. There is no required relationship
+between window and server. You can connect to 10 servers and manage them all in
+just one window, or join channel in each one of them to one single window if
+you really want to. That being said, here’s how you do connect to new server
+without closing the old connection:
+
+/CONNECT irc.server.org
+
+Instead of the /SERVER which disconnects the existing connection. To see list
+of all active connections, use /SERVER without any parameters. You should see a
+list of something like:
+
+ -!- IRCNet: irc.song.fi:6667 (IRCNet)
+ -!- OFTC: irc.oftc.net:6667 (OFTC)
+ -!- RECON-1: 192.168.0.1:6667 () (02:59 left before reconnecting)
+
+Here you see that we’re connected to IRCNet and OFTC networks. The IRCNet at
+the beginning is called the “server tag” while the (IRCnet) at the end shows
+the IRC network. Server tag specifies unique tag to refer to the server,
+usually it’s the same as the IRC network. When the IRC network isn’t known it’s
+some part of the server name. When there’s multiple connections to same IRC
+network or server, irssi adds a number after the tag so there could be network,
+network2, network3 etc.
+
+Server tags beginning with RECON- mean server reconnections. Above we see that
+connection to server at 192.168.0.1 wasn’t successful and irssi will try to
+connect it again in 3 minutes.
+
+To disconnect one of the servers, or to stop irssi from reconnecting, use
+
+/DISCONNECT network - disconnect server with tag "network"
+/DISCONNECT recon-1 - stop trying to reconnect to RECON-1 server
+/RMRECONNS - stop all server reconnections
+
+/RECONNECT recon-1 - immediately try reconnecting back to RECON-1
+/RECONNECT ALL - immediately try reconnecting back to all
+ servers in reconnection queue
+
+Now that you’re connected to all your servers, you’ll have to know how to
+specify which one of them you want to use. One way is to have an empty window,
+like status or msgs window. In it, you can specify which server to set active
+with
+
+/WINDOW SERVER tag - set server "tag" active
+Ctrl-X - set the next server in list active
+
+When the server is active, you can use it normally. When there’s multiple
+connected servers, irssi adds [servertag] prefix to all messages in non-channel
+/query messages so you’ll know where it came from.
+
+Several commands also accept -servertag option to specify which server it
+should use:
+
+/MSG -tag nick message
+/JOIN -tag #channel
+/QUERY -tag nick
+
+/MSG tab completion also automatically adds the -tag option when nick isn’t in
+active server.
+
+Window’s server can be made sticky. When sticky, it will never automatically
+change to anything else, and if server gets disconnected, the window won’t have
+any active server. When the server gets connected again, it is automatically
+set active in the window. To set the window’s server sticky use
+
+/WINDOW SERVER -sticky tag
+
+This is useful if you wish to have multiple status or msgs windows, one for
+each server. Here’s how to do them (repeat for each server)
+
+/WINDOW NEW HIDE
+/WINDOW NAME (status)
+/WINDOW LEVEL ALL -MSGS
+/WINDOW SERVER -sticky network
+
+/WINDOW NEW HIDE
+/WINDOW NAME (msgs)
+/WINDOW LEVEL MSGS
+/WINDOW SERVER -sticky network
+
+7. /LASTLOG and jumping around in scrollback
+
+/LASTLOG command can be used for searching texts in scrollback buffer. Simplest
+usages are
+
+/LASTLOG word - print all lines with "word" in them
+/LASTLOG word 10 - print last 10 occurances of "word"
+/LASTLOG -topics - print all topic changes
+
+If there’s more than 1000 lines to be printed, irssi thinks that you probably
+made some mistake and won’t print them without -force option. If you want to
+save the full lastlog to file, use
+
+/LASTLOG -file ~/irc.log
+
+With -file option you don’t need -force even if there’s more than 1000 lines. /
+LASTLOG has a lot of other options too, see /HELP lastlog for details.
+
+Once you’ve found the lines you were interested in, you might want to check the
+discussion around them. Irssi has /SCROLLBACK (or alias /SB) command for
+jumping around in scrollback buffer. Since /LASTLOG prints the timestamp when
+the message was originally printed, you can use /SB GOTO hh:mm to jump directly
+there. To get back to the bottom of scrollback, use /SB END command.
+
+8. Logging
+
+Irssi can automatically log important messages when you’re set away (/AWAY
+reason). When you set yourself unaway (/AWAY), the new messages in away log are
+printed to screen. You can configure it with:
+
+/SET awaylog_level MSGS HILIGHT - Specifies what messages to log
+/SET awaylog_file ~/.irssi/away.log - Specifies the file to use
+
+Easiest way to start logging with Irssi is to use autologging. With it Irssi
+logs all channels and private messages to specified directory. You can turn it
+on with
+
+/SET autolog ON
+
+By default it logs pretty much everything execept CTCPS or CRAP (/WHOIS
+requests, etc). You can specify the logging level yourself with
+
+/SET autolog_level ALL -CRAP -CLIENTCRAP -CTCPS (this is the default)
+
+By default irssi logs to ~/irclogs//.log. You can change this with
+
+/SET autolog_path ~/irclogs/$tag/$0.log (this is the default)
+
+The path is automatically created if it doesn’t exist. $0 specifies the target
+(channel/nick). You can make irssi automatically rotate the logs by adding date
+/time formats to the file name. The formats are in “man strftime” format. For
+example
+
+/SET autolog_path ~/irclogs/%Y/$tag/$0.%m-%d.log
+
+For logging only some specific channels or nicks, see /HELP log
+
+9. Changing keyboard bindings
+
+You can change any keyboard binding that terminal lets irssi know about. It
+doesn’t let irssi know everything, so for example shift-backspace can’t be
+bound unless you modify xterm resources somehow.
+
+/HELP bind tells pretty much everything there is to know about keyboard
+bindings. However, there’s the problem of how to bind some non-standard keys.
+They might differ a bit with each terminal, so you’ll need to find out what
+exactly the keypress produces. Easiest way to check that would be to see what
+it prints in cat. Here’s an example for pressing F1 key:
+
+ [user@host] ~% cat
+ ^[OP
+
+So in irssi you would use /BIND ^[OP /ECHO F1 pressed. If you use multiple
+terminals which have different bindings for the key, it would be better to use
+eg.:
+
+/BIND ^[OP key F1
+/BIND ^[11~ key F1
+/BIND F1 /ECHO F1 pressed.
+
+10. Proxies and IRC bouncers
+
+Irssi supports connecting to IRC servers via a proxy. All server connections
+are then made through it, and if you’ve set up everything properly, you don’t
+need to do any /QUOTE SERVER commands manually.
+
+Here’s an example: You have your bouncer (lets say, BNC or BNC-like) listening
+in irc.bouncer.org port 5000. You want to use it to connect to servers
+irc.dalnet and irc.efnet.org. First you’d need to setup the bouncer:
+
+/SET use_proxy ON
+/SET proxy_address irc.bouncer.org
+/SET proxy_port 5000
+
+/SET proxy_password YOUR_BNC_PASSWORD_HERE
+/SET -clear proxy_string
+/SET proxy_string_after conn %s %d
+
+Then you’ll need to add the server connections. These are done exactly as if
+you’d want to connect directly to them. Nothing special about them:
+
+/SERVER ADD -auto -network dalnet irc.dal.net
+/SERVER ADD -auto -network efnet irc.efnet.org
+
+With the proxy /SETs however, irssi now connects to those servers through your
+BNC. All server connections are made through them so you can just forget that
+your bouncer even exists.
+
+If you don’t want to use the proxy for some reason, there’s -noproxy option
+which you can give to /SERVER and /SERVER ADD commands.
+
+Proxy specific settings:
+
+All proxies have these settings in common:
+
+/SET use_proxy ON
+/SET proxy_address <Proxy host address>
+/SET proxy_port <Proxy port>
+
+HTTP proxy
+
+Use these settings with HTTP proxies:
+
+/SET -clear proxy_password
+/EVAL SET proxy_string CONNECT %s:%d HTTP/1.0\n\n
+
+BNC
+
+/SET proxy_password your_pass
+/SET -clear proxy_string
+/SET proxy_string_after conn %s %d
+
+dircproxy
+
+dircproxy separates the server connections by passwords. So, if you for example
+have network connection with password ircpass and OFTC connection with
+oftcpass, you would do something like this:
+
+/SET -clear proxy_password
+/SET -clear proxy_string
+
+/SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
+/SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
+
+The server name and port you give isn’t used anywhere, so you can put anything
+you want in there.
+
+psyBNC
+
+psyBNC has internal support for multiple servers. However, it could be a bit
+annoying to use, and some people just use different users for connecting to
+different servers. You can manage this in a bit same way as with dircproxy, by
+creating fake connections:
+
+/SET -clear proxy_password
+/SET -clear proxy_string
+
+/NETWORK ADD -user networkuser IRCnet
+/SERVER ADD -auto -network IRCnet fake.network 6667 ircpass
+/NETWORK ADD -user oftcuser OFTC
+/SERVER ADD -auto -network OFTC fake.oftc 6667 oftcpass
+
+So, you’ll specify the usernames with /NETWORK ADD command, and the user’s
+password with /SERVER ADD.
+
+Irssi proxy
+
+Irssi contains it’s own proxy which you can build giving \--with-proxy option
+to configure. You’ll still need to run irssi in a screen to use it though.
+
+Irssi proxy is a bit different than most proxies, normally proxies create a new
+connection to IRC server when you connect to it, but irssi proxy shares your
+existing IRC connection(s) to multiple clients. And even more clearly: You can
+use only one IRC server connection to IRC with as many clients as you want. Can
+anyone figure out even more easier ways to say this, so I wouldn’t need to try
+to explain this thing for minutes every time? :)
+
+Irssi proxy supports sharing multiple server connections in different ports,
+like you can share network in port 2777 and efnet in port 2778.
+
+Usage in proxy side:
+
+/LOAD proxy
+/SET irssiproxy_password <password>
+/SET irssiproxy_ports <network>=<port> ... (eg. IRCnet=2777 efnet=2778)
+
+NOTE: you MUST add all the servers you are using to server and network lists
+with /SERVER ADD and /NETWORK ADD. ..Except if you really don’t want to for
+some reason, and you only use one server connection, you may simply set:
+
+/SET irssiproxy_ports *=2777
+
+Usage in client side:
+
+Just connect to the irssi proxy like it is a normal server with password
+specified in /SET irssiproxy_password. For example:
+
+/SERVER ADD -network IRCnet my.irssi-proxy.org 2777 secret
+/SERVER ADD -network efnet my.irssi-proxy.org 2778 secret
+
+Irssi proxy works fine with other IRC clients as well.
+
+SOCKS
+
+Irssi can be compiled with socks support (\--with-socks option to configure),
+which requires “dante” and routes all connections through the proxy specified
+in the system-wide /etc/socks.conf. This method is known to have issues in Mac
+OS X.
+
+Note that /SET proxy settings don’t have anything to do with socks.
+
+Using [4]proxychains-ng is recommended over recompiling irssi.
+
+Others
+
+IRC bouncers usually work like IRC servers, and want a password. You can give
+it with:
+
+/SET proxy_password <password>
+
+Irssi’s defaults for connect strings are
+
+/SET proxy_string CONNECT %s %d
+/SET proxy_string_after
+
+The proxy_string is sent before NICK/USER commands, the proxy_string_after is
+sent after them. %s and %d can be used with both of them.
+
+11. Irssi’s settings
+
+Here’s some settings you might want to change (the default value is shown):
+Also check the [5]Settings Documentation
+
+Queries
+
+/SET autocreate_own_query ON
+ Should new query window be created when you send message to someone (with /
+ MSG).
+/SET autocreate_query_level MSGS
+ New query window should be created when receiving messages with this level.
+ MSGS, DCCMSGS and NOTICES levels work currently. You can disable this with
+ /SET -clear autocreate_query_level.
+/SET autoclose_query 0
+ Query windows can be automatically closed after certain time of inactivity.
+ Queries with unread messages aren’t closed and active window is neither
+ never closed. The value is given in seconds.
+
+Windows
+
+/SET use_msgs_window OFF
+ Create messages window at startup. All private messages go to this window.
+ This only makes sense if you’ve disabled automatic query windows. Message
+ window can also be created manually with /WINDOW LEVEL MSGS, /WINDOW NAME
+ (msgs).
+/SET use_status_window ON
+ Create status window at startup. All messages that don’t really have better
+ place go here, like all /WHOIS replies etc. Status window can also be
+ created manually with /WINDOW LEVEL ALL -MSGS, /WINDOW NAME (status).
+/SET autocreate_windows ON
+ Should we create new windows for new window items or just place everything
+ in one window
+/SET autoclose_windows ON
+ Should window be automatically closed when the last item in them is removed
+ (ie. /PART, /UNQUERY).
+/SET reuse_unused_windows OFF
+ When finding where to place new window item (channel, query) Irssi first
+ tries to use already existing empty windows. If this is set ON, new window
+ will always be created for all window items. This setting is ignored if
+ autoclose_windows is set ON.
+/SET window_auto_change OFF
+ Should Irssi automatically change to automatically created windows -
+ usually queries when someone sends you a message. To prevent accidentally
+ sending text meant to some other channel/nick, Irssi clears the input
+ buffer when changing the window. The text is still in scrollback buffer,
+ you can get it back with pressing arrow up key.
+/SET print_active_channel OFF
+ When you keep more than one channel in same window, Irssi prints the
+ messages coming to active channel as <nick> text and other channels as
+ <nick:channel> text. If this setting is set ON, the messages to active
+ channels are also printed in the latter way.
+/SET window_history OFF
+ Should command history be kept separate for each window.
+
+User information
+
+/SET nick
+ Your nick name
+/SET alternate_nick
+ Your alternate nick.
+/SET user_name
+ Your username, if you have ident enabled this doesn’t affect anything
+/SET real_name
+ Your real name.
+
+Server information
+
+/SET skip_motd OFF
+ Should we hide server’s MOTD (Message Of The Day).
+/SET server_reconnect_time 300
+ Seconds to wait before connecting to same server again. Don’t set this too
+ low since it usually doesn’t help at all - if the host is down, the few
+ extra minutes of waiting won’t hurt much.
+/SET lag_max_before_disconnect 300
+ Maximum server lag in seconds before disconnecting and trying to reconnect.
+ This happens mostly only when network breaks between you and IRC server.
+
+Appearance
+
+/SET timestamps ON
+ Show timestamps before each message.
+/SET hide_text_style OFF
+ Hide all bolds, underlines, MIRC colors, etc.
+/SET show_nickmode ON
+ Show the nick’s mode before nick in channels, ie. ops have <@nick>, voices
+ <+nick> and others < nick>
+/SET show_nickmode_empty ON
+ If the nick doesn’t have a mode, use one space. ie. ON: < nick>, OFF:
+ <nick>
+/SET show_quit_once OFF
+ Show quit message only once in some of the channel windows the nick was in
+ instead of in all windows.
+/SET lag_min_show 100
+ Show the server lag in status bar if it’s bigger than this, the unit is 1/
+ 100 of seconds (ie. the default value of 100 = 1 second).
+/SET indent 10
+ When lines are longer than screen width they have to be split to multiple
+ lines. This specifies how much space to put at the beginning of the line
+ before the text begins. This can be overridden in text formats with %|
+ format.
+/SET activity_hide_targets
+ If you don’t want to see window activity in some certain channels or
+ queries, list them here. For example #boringchannel =bot1 =bot2. If any
+ highlighted text or message for you appears in that window, this setting is
+ ignored and the activity is shown.
+
+Nick completion
+
+/SET completion_auto OFF
+ Automatically complete the nick if line begins with start of nick and the
+ completion character. Learn to use the tab-completion instead, it’s a lot
+ better ;)
+/SET completion_char :
+ Completion character to use.
+
+For all the ircII people
+
+I don’t like automatic query windows, I don’t like status window, I do like
+msgs window where all messages go:
+
+/SET autocreate_own_query OFF
+/SET autocreate_query_level DCCMSGS
+/SET use_status_window OFF
+/SET use_msgs_window ON
+
+Disable automatic window closing when /PARTing channel or /UNQUERYing query:
+
+/SET autoclose_windows OFF
+/SET reuse_unused_windows ON
+
+Here’s the settings that make irssi work exactly like ircII in window
+management (send me a note if you can think of more):
+
+/SET autocreate_own_query OFF
+/SET autocreate_query_level NONE
+/SET use_status_window OFF
+/SET use_msgs_window OFF
+/SET reuse_unused_windows ON
+/SET windows_auto_renumber OFF
+
+/SET autostick_split_windows OFF
+/SET autoclose_windows OFF
+/SET print_active_channel ON
+
+12. Statusbar
+
+/STATUSBAR displays a list of the current statusbars, along with their position
+and visibility:
+
+ Name Type Placement Position Visible
+ window window bottom 0 always
+ window_inact window bottom 1 inactive
+ prompt root bottom 100 always
+ topic root top 1 always
+
+/STATUSBAR <name> prints the statusbar settings (type, placement, position,
+visibility) as well as its items. /STATUSBAR <name> ENABLE|DISABLE enables/
+disables the statusbar. /STATUSBAR <name> RESET resets the statusbar to its
+default settings, or if the statusbar was created by you, it will be removed.
+
+The statusbar type can be either window or root. If the type is window, then a
+statusbar will be created for each split window, otherwise it will be created
+only once. Placement can be top or bottom, which refers to the top or bottom of
+the screen. Position is a number, the higher the value the lower it will appear
+in-screen. Visible can be always, active or inactive. Active/inactive is useful
+only with split windows; one split window is active and the rest are inactive.
+To adjust these settings, the following commands are available:
+
+/STATUSBAR <name> TYPE window|root
+/STATUSBAR <name> PLACEMENT top|bottom
+/STATUSBAR <name> POSITION <num>
+/STATUSBAR <name> VISIBLE always|active|inactive
+
+Statusbar items can also be added or removed via command. Note that when
+loading new statusbar scripts that add items, you will need to specify where
+you want to show the item and how it is aligned. This can be accomplished using
+the below commands:
+
+/STATUSBAR <name> ADD [-before | -after <item>] [-priority #] [-alignment left|right] <item>
+/STATUSBAR <name> REMOVE <item>
+
+For statusbar scripts, the item name is usually equivalent to the script name.
+The documentation of the script ought to tell you if this is not the case. For
+example, to add mail.pl before the window activity item, use: /STATUSBAR window
+ADD -before act mail.
+
+
+References:
+
+[1] http://www.gnu.org/licenses/fdl.html
+[2] https://www.iterm2.com/
+[3] http://quadpoint.org/articles/irssisplit/
+[4] https://github.com/rofl0r/proxychains-ng
+[5] https://irssi.org/documentation/settings/
diff --git a/fuzz-support/fuzz.diff b/fuzz-support/fuzz.diff
new file mode 100644
index 00000000..a3683493
--- /dev/null
+++ b/fuzz-support/fuzz.diff
@@ -0,0 +1,269 @@
+diff --git a/src/core/network.c b/src/core/network.c
+index 3e1b7c7..1e5324a 100644
+--- a/src/core/network.c
++++ b/src/core/network.c
+@@ -199,6 +199,10 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
+ /* Connect to named UNIX socket */
+ GIOChannel *net_connect_unix(const char *path)
+ {
++ if (strcmp(path, "/dev/stdin") == 0) {
++ return g_io_channel_new(0);
++ }
++
+ struct sockaddr_un sa;
+ int handle, ret;
+
+@@ -336,6 +340,8 @@ int net_receive(GIOChannel *handle, char *buf, int len)
+ /* Transmit data, return number of bytes sent, -1 = error */
+ int net_transmit(GIOChannel *handle, const char *data, int len)
+ {
++ return write(1, data, len);
++
+ gsize ret;
+ GIOStatus status;
+ GError *err = NULL;
+@@ -495,6 +501,7 @@ int net_host2ip(const char *host, IPADDR *ip)
+ /* Get socket error */
+ int net_geterror(GIOChannel *handle)
+ {
++ return 0;
+ int data;
+ socklen_t len = sizeof(data);
+
+diff --git a/src/core/servers-reconnect.c b/src/core/servers-reconnect.c
+index 58c9dd0..0c6ec1b 100644
+--- a/src/core/servers-reconnect.c
++++ b/src/core/servers-reconnect.c
+@@ -484,7 +484,8 @@ void servers_reconnect_init(void)
+ reconnects = NULL;
+ last_reconnect_tag = 0;
+
+- reconnect_timeout_tag = g_timeout_add(1000, (GSourceFunc) server_reconnect_timeout, NULL);
++ (void) server_reconnect_timeout;
++
+ read_settings();
+
+ signal_add("server connect failed", (SIGNAL_FUNC) sig_reconnect);
+diff --git a/src/core/settings.c b/src/core/settings.c
+index e65ceb2..f9dc678 100644
+--- a/src/core/settings.c
++++ b/src/core/settings.c
+@@ -704,7 +704,10 @@ int irssi_config_is_changed(const char *fname)
+
+ static CONFIG_REC *parse_configfile(const char *fname)
+ {
+- CONFIG_REC *config;
++ CONFIG_REC *config = config_open(NULL, -1);
++ config_parse_data(config, default_config, "internal");
++ return config;
++
+ struct stat statbuf;
+ const char *path;
+ char *str;
+@@ -871,8 +874,6 @@ void settings_init(void)
+ init_configfile();
+
+ settings_add_bool("misc", "settings_autosave", TRUE);
+- timeout_tag = g_timeout_add(SETTINGS_AUTOSAVE_TIMEOUT,
+- (GSourceFunc) sig_autosave, NULL);
+ signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+ signal_add("gui exit", (SIGNAL_FUNC) sig_autosave);
+ }
+diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c
+index 1b2ab1e..4344cd9 100644
+--- a/src/fe-common/core/fe-common-core.c
++++ b/src/fe-common/core/fe-common-core.c
+@@ -320,6 +320,8 @@ static void autoconnect_servers(void)
+ GSList *tmp, *chatnets;
+ char *str;
+
++ return;
++
+ if (autocon_server != NULL) {
+ /* connect to specified server */
+ if (autocon_password == NULL)
+@@ -390,6 +392,7 @@ static void sig_setup_changed(void)
+
+ static void autorun_startup(void)
+ {
++ return;
+ char *path;
+ GIOChannel *handle;
+ GString *buf;
+diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c
+index 2b1459b..2e518a1 100644
+--- a/src/fe-common/core/themes.c
++++ b/src/fe-common/core/themes.c
+@@ -790,9 +790,8 @@ static void theme_read_module(THEME_REC *theme, const char *module)
+ {
+ CONFIG_REC *config;
+
+- config = config_open(theme->path, -1);
+- if (config != NULL)
+- config_parse(config);
++ config = config_open(NULL, -1);
++ config_parse_data(config, default_theme, "internal");
+
+ theme_init_module(theme, module, config);
+
+@@ -987,7 +986,7 @@ static int theme_read(THEME_REC *theme, const char *path)
+ THEME_READ_REC rec;
+ char *str;
+
+- config = config_open(path, -1) ;
++ config = config_open(NULL, -1) ;
+ if (config == NULL) {
+ /* didn't exist or no access? */
+ str = g_strdup_printf("Error reading theme file %s: %s",
+@@ -997,7 +996,7 @@ static int theme_read(THEME_REC *theme, const char *path)
+ return FALSE;
+ }
+
+- if (path == NULL)
++ if (1)
+ config_parse_data(config, default_theme, "internal");
+ else
+ config_parse(config);
+@@ -1200,6 +1199,7 @@ static void module_save(const char *module, MODULE_THEME_REC *rec,
+
+ static void theme_save(THEME_REC *theme, int save_all)
+ {
++ return;
+ CONFIG_REC *config;
+ THEME_SAVE_REC data;
+ char *path;
+diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
+index 7c71edd..6bf2177 100644
+--- a/src/fe-text/gui-readline.c
++++ b/src/fe-text/gui-readline.c
+@@ -1126,7 +1126,6 @@ void gui_readline_init(void)
+ paste_timeout_id = -1;
+ paste_bracketed_mode = FALSE;
+ g_get_current_time(&last_keypress);
+- input_listen_init(STDIN_FILENO);
+
+ settings_add_bool("lookandfeel", "term_appkey_mode", TRUE);
+ settings_add_str("history", "scroll_page_count", "/2");
+diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c
+index ad79e0c..84d0c5c 100644
+--- a/src/fe-text/irssi.c
++++ b/src/fe-text/irssi.c
+@@ -314,20 +314,16 @@ int main(int argc, char **argv)
+ textui_finish_init();
+ main_loop = g_main_new(TRUE);
+
++#ifdef __AFL_HAVE_MANUAL_CONTROL
++ __AFL_INIT();
++#endif
++
++ signal_emit("command connect", 1, "/dev/stdin 6667");
++
+ /* Does the same as g_main_run(main_loop), except we
+ can call our dirty-checker after each iteration */
+ while (!quitting) {
+- term_refresh_freeze();
+ g_main_iteration(TRUE);
+- term_refresh_thaw();
+-
+- if (reload_config) {
+- /* SIGHUP received, do /RELOAD */
+- reload_config = FALSE;
+- signal_emit("command reload", 1, "");
+- }
+-
+- dirty_check();
+ }
+
+ g_main_destroy(main_loop);
+diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c
+index b2478c6..cebe260 100644
+--- a/src/fe-text/term-terminfo.c
++++ b/src/fe-text/term-terminfo.c
+@@ -29,6 +29,10 @@
+ #include <termios.h>
+ #include <stdio.h>
+
++#undef putc
++#define putc(x, y) (void) (x)
++#define fputc(x, y) (void) (x), 0
++
+ /* returns number of characters in the beginning of the buffer being a
+ a single character, or -1 if more input is needed. The character will be
+ saved in result */
+@@ -113,7 +117,8 @@ int term_init(void)
+ vcmove = FALSE; cforcemove = TRUE;
+ curs_visible = TRUE;
+
+- current_term = terminfo_core_init(stdin, stdout);
++ FILE *devnull = fopen("/dev/null", "r+");
++ current_term = terminfo_core_init(devnull, devnull);
+ if (current_term == NULL)
+ return FALSE;
+
+@@ -670,6 +675,7 @@ void term_set_input_type(int type)
+
+ void term_gets(GArray *buffer, int *line_count)
+ {
++ return;
+ int ret, i, char_len;
+
+ /* fread() doesn't work */
+diff --git a/src/fe-text/terminfo-core.c b/src/fe-text/terminfo-core.c
+index 9c9179a..6349935 100644
+--- a/src/fe-text/terminfo-core.c
++++ b/src/fe-text/terminfo-core.c
+@@ -6,6 +6,10 @@
+ # define _POSIX_VDISABLE 0
+ #endif
+
++#undef putc
++#define putc(x, y) (void) (x)
++#define fputc(x, y) (void) (x), 0
++
+ #define tput(s) tputs(s, 0, term_putchar)
+ inline static int term_putchar(int c)
+ {
+diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c
+index 4dce3fc..25fbb34 100644
+--- a/src/irc/core/irc.c
++++ b/src/irc/core/irc.c
+@@ -383,12 +383,13 @@ static void irc_parse_incoming(SERVER_REC *server)
+ signal_emit_id(signal_server_incoming, 2, server, str);
+
+ if (server->connection_lost)
+- server_disconnect(server);
++ exit(0);
+
+ count++;
+ }
+ if (ret == -1) {
+ /* connection lost */
++ exit(0);
+ server->connection_lost = TRUE;
+ server_disconnect(server);
+ }
+diff --git a/src/lib-config/write.c b/src/lib-config/write.c
+index 37e51f0..ee82726 100644
+--- a/src/lib-config/write.c
++++ b/src/lib-config/write.c
+@@ -299,6 +299,8 @@ static int config_write_block(CONFIG_REC *rec, CONFIG_NODE *node, int list, int
+
+ int config_write(CONFIG_REC *rec, const char *fname, int create_mode)
+ {
++ return 0;
++
+ int ret;
+ int fd;
+
+diff --git a/src/perl/perl-core.c b/src/perl/perl-core.c
+index 2c61df7..485fe25 100644
+--- a/src/perl/perl-core.c
++++ b/src/perl/perl-core.c
+@@ -395,6 +395,7 @@ int perl_get_api_version(void)
+
+ void perl_scripts_autorun(void)
+ {
++ return;
+ DIR *dirp;
+ struct dirent *dp;
+ struct stat statbuf;
diff --git a/m4/glibtests.m4 b/m4/glibtests.m4
new file mode 100644
index 00000000..7d5920a4
--- /dev/null
+++ b/m4/glibtests.m4
@@ -0,0 +1,28 @@
+dnl GLIB_TESTS
+dnl
+
+AC_DEFUN([GLIB_TESTS],
+[
+ AC_ARG_ENABLE(installed-tests,
+ AS_HELP_STRING([--enable-installed-tests],
+ [Enable installation of some test cases]),
+ [case ${enableval} in
+ yes) ENABLE_INSTALLED_TESTS="1" ;;
+ no) ENABLE_INSTALLED_TESTS="" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-installed-tests]) ;;
+ esac])
+ AM_CONDITIONAL([ENABLE_INSTALLED_TESTS], test "$ENABLE_INSTALLED_TESTS" = "1")
+ AC_ARG_ENABLE(always-build-tests,
+ AS_HELP_STRING([--enable-always-build-tests],
+ [Enable always building tests during 'make all']),
+ [case ${enableval} in
+ yes) ENABLE_ALWAYS_BUILD_TESTS="1" ;;
+ no) ENABLE_ALWAYS_BUILD_TESTS="" ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --enable-always-build-tests]) ;;
+ esac])
+ AM_CONDITIONAL([ENABLE_ALWAYS_BUILD_TESTS], test "$ENABLE_ALWAYS_BUILD_TESTS" = "1")
+ if test "$ENABLE_INSTALLED_TESTS" = "1"; then
+ AC_SUBST(installed_test_metadir, [${datadir}/installed-tests/]AC_PACKAGE_NAME)
+ AC_SUBST(installed_testdir, [${libexecdir}/installed-tests/]AC_PACKAGE_NAME)
+ fi
+])
diff --git a/scripts/autorejoin.pl b/scripts/autorejoin.pl
index 42c97da7..e5be21b2 100644
--- a/scripts/autorejoin.pl
+++ b/scripts/autorejoin.pl
@@ -1,6 +1,9 @@
-# automatically rejoin to channel after kick
+# automatically rejoin to channel after kicked
# delayed rejoin: Lam 28.10.2001 (lam@lac.pl)
+# /SET autorejoin_channels #channel1 #channel2 ...
+# /SET autorejoin_delay 5
+
# NOTE: I personally don't like this feature, in most channels I'm in it
# will just result as ban. You've probably misunderstood the idea of /KICK
# if you kick/get kicked all the time "just for fun" ...
@@ -9,31 +12,22 @@ use Irssi;
use Irssi::Irc;
use strict;
use vars qw($VERSION %IRSSI);
-$VERSION = "1.0.0";
+$VERSION = "1.1.0";
%IRSSI = (
authors => "Timo 'cras' Sirainen, Leszek Matok",
contact => "lam\@lac.pl",
name => "autorejoin",
- description => "Automatically rejoin to channel after being kick, after a (short) user-defined delay",
+ description => "Automatically rejoin to channel after being kicked, after a (short) user-defined delay",
license => "GPLv2",
changed => "10.3.2002 14:00"
);
-
-# How many seconds to wait before the rejoin?
-# TODO: make this a /setting
-my $delay = 5;
-
-my @tags;
-my $acttag = 0;
-
sub rejoin {
my ( $data ) = @_;
- my ( $tag, $servtag, $channel, $pass ) = split( / +/, $data );
+ my ( $servtag, $channel, $pass ) = @{$data};
my $server = Irssi::server_find_tag( $servtag );
$server->send_raw( "JOIN $channel $pass" ) if ( $server );
- Irssi::timeout_remove( $tags[$tag] );
}
sub event_rejoin_kick {
@@ -48,10 +42,31 @@ sub event_rejoin_kick {
my $rejoinchan = $chanrec->{ name } if ( $chanrec );
my $servtag = $server->{ tag };
- Irssi::print "Rejoining $rejoinchan in $delay seconds.";
- $tags[$acttag] = Irssi::timeout_add( $delay * 1000, "rejoin", "$acttag $servtag $rejoinchan $password" );
- $acttag++;
- $acttag = 0 if ( $acttag > 60 );
+ # check if we want to autorejoin this channel
+ my $chans = Irssi::settings_get_str( 'autorejoin_channels' );
+
+ if ( $chans ) {
+ my $found = 0;
+ foreach my $chan ( split( /[ ,]/, $chans ) ) {
+ if ( lc( $chan ) eq lc( $channel ) ) {
+ $found = 1;
+ last;
+ }
+ }
+ return unless $found;
+ }
+
+ my @args = ($servtag, $rejoinchan, $password);
+ my $delay = Irssi::settings_get_int( "autorejoin_delay" );
+
+ if ($delay) {
+ Irssi::print "Rejoining $rejoinchan in $delay seconds.";
+ Irssi::timeout_add_once( $delay * 1000, "rejoin", \@args );
+ } else {
+ rejoin( \@args );
+ }
}
+Irssi::settings_add_int('misc', 'autorejoin_delay', 5);
+Irssi::settings_add_str('misc', 'autorejoin_channels', '');
Irssi::signal_add( 'event kick', 'event_rejoin_kick' );
diff --git a/scripts/mail.pl b/scripts/mail.pl
index ded02120..23f99c01 100644
--- a/scripts/mail.pl
+++ b/scripts/mail.pl
@@ -6,6 +6,7 @@ $VERSION = "2.92";
contact => "tss\@iki.fi, matti\@hiljanen.com, joost\@carnique.nl, bart\@dreamflow.nl",
name => "mail",
description => "Fully customizable mail counter statusbar item with multiple mailbox and multiple Maildir support",
+ sbitems => "mail",
license => "Public Domain",
url => "http://irssi.org, http://scripts.irssi.de",
);
diff --git a/scripts/usercount.pl b/scripts/usercount.pl
index 613da1de..650f9f36 100644
--- a/scripts/usercount.pl
+++ b/scripts/usercount.pl
@@ -7,6 +7,7 @@ $VERSION = "1.19";
contact => 'dgl@dgl.cx, tss@iki.fi, georg@boerde.de',
name => 'usercount',
description => 'Adds a usercount for a channel as a statusbar item',
+ sbitems => 'usercount',
license => 'GNU GPLv2 or later',
url => 'http://irssi.dgl.cx/',
changes => 'Only show halfops if server supports them',
diff --git a/src/common.h b/src/common.h
index b6f9153e..ba5557e6 100644
--- a/src/common.h
+++ b/src/common.h
@@ -6,9 +6,10 @@
#define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
#define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
-#define IRSSI_ABI_VERSION 9
+#define IRSSI_ABI_VERSION 13
#define DEFAULT_SERVER_ADD_PORT 6667
+#define DEFAULT_SERVER_ADD_TLS_PORT 6697
#ifdef HAVE_CONFIG_H
#include "irssi-config.h"
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 10bd035a..f64d9e2e 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -7,6 +7,12 @@ AM_CPPFLAGS = \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
-DMODULEDIR=\""$(libdir)/irssi/modules"\"
+if USE_GREGEX
+regex_impl=iregex-gregex.c
+else
+regex_impl=iregex-regexh.c
+endif
+
libcore_a_SOURCES = \
args.c \
channels.c \
@@ -45,10 +51,16 @@ libcore_a_SOURCES = \
signals.c \
special-vars.c \
utf8.c \
+ $(regex_impl) \
wcwidth.c \
tls.c \
write-buffer.c
+if HAVE_CAPSICUM
+libcore_a_SOURCES += \
+ capsicum.c
+endif
+
structure_headers = \
channel-rec.h \
channel-setup-rec.h \
@@ -62,6 +74,7 @@ structure_headers = \
pkginc_coredir=$(pkgincludedir)/src/core
pkginc_core_HEADERS = \
args.h \
+ capsicum.h \
channels.h \
channels-setup.h \
commands.h \
@@ -82,6 +95,7 @@ pkginc_core_HEADERS = \
net-nonblock.h \
net-sendbuffer.h \
network.h \
+ network-openssl.h \
nick-rec.h \
nicklist.h \
nickmatch-cache.h \
@@ -97,6 +111,7 @@ pkginc_core_HEADERS = \
signals.h \
special-vars.h \
utf8.h \
+ iregex.h \
window-item-def.h \
tls.h \
write-buffer.h \
diff --git a/src/core/capsicum.c b/src/core/capsicum.c
new file mode 100644
index 00000000..568b5542
--- /dev/null
+++ b/src/core/capsicum.c
@@ -0,0 +1,508 @@
+/*
+ capsicum.c : Capsicum sandboxing support
+
+ Copyright (C) 2017 Edward Tomasz Napierala <trasz@FreeBSD.org>
+
+ This software was developed by SRI International and the University of
+ Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
+ ("CTSRD"), as part of the DARPA CRASH research programme.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "module.h"
+#include "capsicum.h"
+#include "commands.h"
+#include "log.h"
+#include "misc.h"
+#include "network.h"
+#include "network-openssl.h"
+#include "settings.h"
+#include "signals.h"
+
+#include <sys/param.h>
+#include <sys/capsicum.h>
+#include <sys/filio.h>
+#include <sys/nv.h>
+#include <sys/procdesc.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <termios.h>
+
+#define OPCODE_CONNECT 1
+#define OPCODE_GETHOSTBYNAME 2
+
+static char *irclogs_path;
+static size_t irclogs_path_len;
+static int irclogs_fd;
+static int symbiontfds[2];
+static int port_min;
+static int port_max;
+
+gboolean capsicum_enabled(void)
+{
+ u_int mode;
+ int error;
+
+ error = cap_getmode(&mode);
+ if (error != 0)
+ return FALSE;
+
+ if (mode == 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
+{
+ nvlist_t *nvl;
+ int error, saved_errno, sock;
+
+ /* Send request to the symbiont. */
+ nvl = nvlist_create(0);
+ nvlist_add_number(nvl, "opcode", OPCODE_CONNECT);
+ nvlist_add_binary(nvl, "ip", ip, sizeof(*ip));
+ nvlist_add_number(nvl, "port", port);
+ if (my_ip != NULL) {
+ /* nvlist_add_binary(3) can't handle NULL values. */
+ nvlist_add_binary(nvl, "my_ip", my_ip, sizeof(*my_ip));
+ }
+ error = nvlist_send(symbiontfds[1], nvl);
+ nvlist_destroy(nvl);
+ if (error != 0) {
+ g_warning("nvlist_send: %s", strerror(errno));
+ return -1;
+ }
+
+ /* Receive response. */
+ nvl = nvlist_recv(symbiontfds[1], 0);
+ if (nvl == NULL) {
+ g_warning("nvlist_recv: %s", strerror(errno));
+ return -1;
+ }
+ if (nvlist_exists_descriptor(nvl, "sock")) {
+ sock = nvlist_take_descriptor(nvl, "sock");
+ } else {
+ sock = -1;
+ }
+ saved_errno = nvlist_get_number(nvl, "errno");
+ nvlist_destroy(nvl);
+
+ if (sock == -1 && (port < port_min || port > port_max)) {
+ g_warning("Access restricted to ports between %d and %d "
+ "due to capability mode",
+ port_min, port_max);
+ }
+
+ errno = saved_errno;
+
+ return sock;
+}
+
+int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
+{
+ nvlist_t *nvl;
+ const IPADDR *received_ip4, *received_ip6;
+ int error, ret, saved_errno;
+
+ /* Send request to the symbiont. */
+ nvl = nvlist_create(0);
+ nvlist_add_number(nvl, "opcode", OPCODE_GETHOSTBYNAME);
+ nvlist_add_string(nvl, "addr", addr);
+ error = nvlist_send(symbiontfds[1], nvl);
+ nvlist_destroy(nvl);
+ if (error != 0) {
+ g_warning("nvlist_send: %s", strerror(errno));
+ return -1;
+ }
+
+ /* Receive response. */
+ nvl = nvlist_recv(symbiontfds[1], 0);
+ if (nvl == NULL) {
+ g_warning("nvlist_recv: %s", strerror(errno));
+ return -1;
+ }
+
+ received_ip4 = nvlist_get_binary(nvl, "ip4", NULL);
+ received_ip6 = nvlist_get_binary(nvl, "ip6", NULL);
+ memcpy(ip4, received_ip4, sizeof(*ip4));
+ memcpy(ip6, received_ip6, sizeof(*ip6));
+
+ ret = nvlist_get_number(nvl, "ret");
+ saved_errno = nvlist_get_number(nvl, "errno");
+ nvlist_destroy(nvl);
+ errno = saved_errno;
+
+ return ret;
+}
+
+int capsicum_open(const char *path, int flags, int mode)
+{
+ int fd;
+
+ /* +1 is for the slash separating irclogs_path and the rest. */
+ if (strlen(path) > irclogs_path_len + 1 &&
+ path[irclogs_path_len] == '/' &&
+ strncmp(path, irclogs_path, irclogs_path_len) == 0) {
+ fd = openat(irclogs_fd, path + irclogs_path_len + 1,
+ flags, mode);
+ } else {
+ fd = open(path, flags, mode);
+ }
+
+ if (fd < 0 && (errno == ENOTCAPABLE || errno == ECAPMODE))
+ g_warning("File system access restricted to %s "
+ "due to capability mode", irclogs_path);
+
+ return (fd);
+}
+
+int capsicum_open_wrapper(const char *path, int flags, int mode)
+{
+ if (capsicum_enabled()) {
+ return capsicum_open(path, flags, mode);
+ }
+ return open(path, flags, mode);
+}
+
+void capsicum_mkdir_with_parents(const char *path, int mode)
+{
+ char *component, *copy, *tofree;
+ int error, fd, newfd;
+
+ /* The directory already exists, nothing to do. */
+ if (strcmp(path, irclogs_path) == 0)
+ return;
+
+ /* +1 is for the slash separating irclogs_path and the rest. */
+ if (strlen(path) <= irclogs_path_len + 1 ||
+ path[irclogs_path_len] != '/' ||
+ strncmp(path, irclogs_path, irclogs_path_len) != 0) {
+ g_warning("Cannot create %s: file system access restricted "
+ "to %s due to capability mode", path, irclogs_path);
+ return;
+ }
+
+ copy = tofree = g_strdup(path + irclogs_path_len + 1);
+ fd = irclogs_fd;
+ for (;;) {
+ component = strsep(&copy, "/");
+ if (component == NULL)
+ break;
+ error = mkdirat(fd, component, mode);
+ if (error != 0 && errno != EEXIST) {
+ g_warning("cannot create %s: %s",
+ component, strerror(errno));
+ break;
+ }
+ newfd = openat(fd, component, O_DIRECTORY);
+ if (newfd < 0) {
+ g_warning("cannot open %s: %s",
+ component, strerror(errno));
+ break;
+ }
+ if (fd != irclogs_fd)
+ close(fd);
+ fd = newfd;
+ }
+ g_free(tofree);
+ if (fd != irclogs_fd)
+ close(fd);
+}
+
+void capsicum_mkdir_with_parents_wrapper(const char *path, int mode)
+{
+ if (capsicum_enabled()) {
+ capsicum_mkdir_with_parents(path, mode);
+ return;
+ }
+ g_mkdir_with_parents(path, mode);
+}
+
+nvlist_t *symbiont_connect(const nvlist_t *request)
+{
+ nvlist_t *response;
+ const IPADDR *ip, *my_ip;
+ int port, saved_errno, sock;
+
+ ip = nvlist_get_binary(request, "ip", NULL);
+ port = (int)nvlist_get_number(request, "port");
+ if (nvlist_exists(request, "my_ip"))
+ my_ip = nvlist_get_binary(request, "my_ip", NULL);
+ else
+ my_ip = NULL;
+
+ /*
+ * Check if the port is in allowed range. This is to minimize
+ * the chance of the attacker rooting another system in case of
+ * compromise.
+ */
+ if (port < port_min || port > port_max) {
+ sock = -1;
+ saved_errno = EPERM;
+ } else {
+ /* Connect. */
+ sock = net_connect_ip_handle(ip, port, my_ip);
+ saved_errno = errno;
+ }
+
+ /* Send back the socket fd. */
+ response = nvlist_create(0);
+
+ if (sock != -1)
+ nvlist_move_descriptor(response, "sock", sock);
+ nvlist_add_number(response, "errno", saved_errno);
+
+ return (response);
+}
+
+nvlist_t *symbiont_gethostbyname(const nvlist_t *request)
+{
+ nvlist_t *response;
+ IPADDR ip4, ip6;
+ const char *addr;
+ int ret, saved_errno;
+
+ addr = nvlist_get_string(request, "addr");
+
+ /* Connect. */
+ ret = net_gethostbyname(addr, &ip4, &ip6);
+ saved_errno = errno;
+
+ /* Send back the IPs. */
+ response = nvlist_create(0);
+
+ nvlist_add_number(response, "ret", ret);
+ nvlist_add_number(response, "errno", saved_errno);
+ nvlist_add_binary(response, "ip4", &ip4, sizeof(ip4));
+ nvlist_add_binary(response, "ip6", &ip6, sizeof(ip6));
+
+ return (response);
+}
+
+/*
+ * Child process, running outside the Capsicum sandbox.
+ */
+_Noreturn static void symbiont(void)
+{
+ nvlist_t *request, *response;
+ int error, opcode;
+
+ setproctitle("capsicum symbiont");
+ close(symbiontfds[1]);
+ close(0);
+ close(1);
+ close(2);
+
+ for (;;) {
+ /* Receive parameters from the main irssi process. */
+ request = nvlist_recv(symbiontfds[0], 0);
+ if (request == NULL)
+ exit(1);
+
+ opcode = nvlist_get_number(request, "opcode");
+ switch (opcode) {
+ case OPCODE_CONNECT:
+ response = symbiont_connect(request);
+ break;
+ case OPCODE_GETHOSTBYNAME:
+ response = symbiont_gethostbyname(request);
+ break;
+ default:
+ exit(1);
+ }
+
+ /* Send back the response. */
+ error = nvlist_send(symbiontfds[0], response);
+ if (error != 0)
+ exit(1);
+ nvlist_destroy(request);
+ nvlist_destroy(response);
+ }
+}
+
+static int start_symbiont(void)
+{
+ int childfd, error;
+ pid_t pid;
+
+ error = socketpair(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, symbiontfds);
+ if (error != 0) {
+ g_warning("socketpair: %s", strerror(errno));
+ return 1;
+ }
+
+ pid = pdfork(&childfd, PD_CLOEXEC);
+ if (pid < 0) {
+ g_warning("pdfork: %s", strerror(errno));
+ return 1;
+ }
+
+ if (pid > 0) {
+ close(symbiontfds[0]);
+ return 0;
+ }
+
+ symbiont();
+ /* NOTREACHED */
+}
+
+static void cmd_capsicum(const char *data, SERVER_REC *server, void *item)
+{
+ command_runsub("capsicum", data, server, item);
+}
+
+/*
+ * The main difference between this and caph_limit_stdio(3) is that this
+ * one permits TIOCSETAW, which is requred for restoring the terminal state
+ * on exit.
+ */
+static int
+limit_stdio_fd(int fd)
+{
+ cap_rights_t rights;
+ unsigned long cmds[] = { TIOCGETA, TIOCGWINSZ, TIOCSETAW, FIODTYPE };
+
+ cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_EVENT, CAP_FCNTL,
+ CAP_FSTAT, CAP_IOCTL, CAP_SEEK);
+
+ if (cap_rights_limit(fd, &rights) < 0) {
+ g_warning("cap_rights_limit(3) failed: %s", strerror(errno));
+ return (-1);
+ }
+
+ if (cap_ioctls_limit(fd, cmds, nitems(cmds)) < 0) {
+ g_warning("cap_ioctls_limit(3) failed: %s", strerror(errno));
+ return (-1);
+ }
+
+ if (cap_fcntls_limit(fd, CAP_FCNTL_GETFL) < 0) {
+ g_warning("cap_fcntls_limit(3) failed: %s", strerror(errno));
+ return (-1);
+ }
+
+ return (0);
+}
+
+static void cmd_capsicum_enter(void)
+{
+ u_int mode;
+ gboolean inited;
+ int error;
+
+ error = cap_getmode(&mode);
+ if (error == 0 && mode != 0) {
+ g_warning("Already in capability mode");
+ return;
+ }
+
+ inited = irssi_ssl_init();
+ if (!inited) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ return;
+ }
+
+ port_min = settings_get_int("capsicum_port_min");
+ port_max = settings_get_int("capsicum_port_max");
+
+ irclogs_path = convert_home(settings_get_str("capsicum_irclogs_path"));
+ irclogs_path_len = strlen(irclogs_path);
+
+ /* Strip trailing slashes, if any. */
+ while (irclogs_path_len > 0 && irclogs_path[irclogs_path_len - 1] == '/') {
+ irclogs_path[irclogs_path_len - 1] = '\0';
+ irclogs_path_len--;
+ }
+
+ g_mkdir_with_parents(irclogs_path, log_dir_create_mode);
+ irclogs_fd = open(irclogs_path, O_DIRECTORY | O_CLOEXEC);
+ if (irclogs_fd < 0) {
+ g_warning("Unable to open %s: %s", irclogs_path, strerror(errno));
+ signal_emit("capability mode failed", 1, strerror(errno));
+ return;
+ }
+
+ error = start_symbiont();
+ if (error != 0) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ return;
+ }
+
+ /*
+ * XXX: We should use pdwait(2) to wait for children. Unfortunately
+ * it's not implemented yet. Thus the workaround, to get rid
+ * of the zombies at least.
+ */
+ signal(SIGCHLD, SIG_IGN);
+
+ if (limit_stdio_fd(STDIN_FILENO) != 0 ||
+ limit_stdio_fd(STDOUT_FILENO) != 0 ||
+ limit_stdio_fd(STDERR_FILENO) != 0) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ return;
+ }
+
+ error = cap_enter();
+ if (error != 0) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ } else {
+ signal_emit("capability mode enabled", 0);
+ }
+}
+
+static void cmd_capsicum_status(void)
+{
+ u_int mode;
+ int error;
+
+ error = cap_getmode(&mode);
+ if (error != 0) {
+ signal_emit("capability mode failed", 1, strerror(errno));
+ } else if (mode == 0) {
+ signal_emit("capability mode disabled", 0);
+ } else {
+ signal_emit("capability mode enabled", 0);
+ }
+}
+
+void sig_init_finished(void)
+{
+ if (settings_get_bool("capsicum"))
+ cmd_capsicum_enter();
+}
+
+void capsicum_init(void)
+{
+ settings_add_bool("misc", "capsicum", FALSE);
+ settings_add_str("misc", "capsicum_irclogs_path", "~/irclogs");
+ settings_add_int("misc", "capsicum_port_min", 6667);
+ settings_add_int("misc", "capsicum_port_max", 9999);
+
+ signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+
+ command_bind("capsicum", NULL, (SIGNAL_FUNC) cmd_capsicum);
+ command_bind("capsicum enter", NULL, (SIGNAL_FUNC) cmd_capsicum_enter);
+ command_bind("capsicum status", NULL, (SIGNAL_FUNC) cmd_capsicum_status);
+}
+
+void capsicum_deinit(void)
+{
+ signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+
+ command_unbind("capsicum", (SIGNAL_FUNC) cmd_capsicum);
+ command_unbind("capsicum enter", (SIGNAL_FUNC) cmd_capsicum_enter);
+ command_unbind("capsicum status", (SIGNAL_FUNC) cmd_capsicum_status);
+}
diff --git a/src/core/capsicum.h b/src/core/capsicum.h
new file mode 100644
index 00000000..7d89f2aa
--- /dev/null
+++ b/src/core/capsicum.h
@@ -0,0 +1,15 @@
+#ifndef __CAPSICUM_H
+#define __CAPSICUM_H
+
+gboolean capsicum_enabled(void);
+int capsicum_net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip);
+int capsicum_net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6);
+int capsicum_open(const char *path, int flags, int mode);
+int capsicum_open_wrapper(const char *path, int flags, int mode);
+void capsicum_mkdir_with_parents(const char *path, int mode);
+void capsicum_mkdir_with_parents_wrapper(const char *path, int mode);
+
+void capsicum_init(void);
+void capsicum_deinit(void);
+
+#endif /* !__CAPSICUM_H */
diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c
index e86fdf9d..d5a133f8 100644
--- a/src/core/chat-commands.c
+++ b/src/core/chat-commands.c
@@ -149,9 +149,9 @@ static SERVER_CONNECT_REC *get_server_connect(const char *data, int *plus_addr,
return conn;
}
-/* SYNTAX: CONNECT [-4 | -6] [-ssl] [-ssl_cert <cert>] [-ssl_pkey <pkey>] [-ssl_pass <password>]
- [-ssl_verify] [-ssl_cafile <cafile>] [-ssl_capath <capath>]
- [-ssl_ciphers <list>]
+/* SYNTAX: CONNECT [-4 | -6] [-tls] [-tls_cert <cert>] [-tls_pkey <pkey>] [-tls_pass <password>]
+ [-tls_verify] [-tls_cafile <cafile>] [-tls_capath <capath>]
+ [-tls_ciphers <list>] [-tls_pinned_cert <fingerprint>] [-tls_pinned_pubkey <fingerprint>]
[-!] [-noautosendcmd]
[-noproxy] [-network <network>] [-host <hostname>]
[-rawlog <file>]
@@ -250,10 +250,10 @@ static void cmd_server(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
command_runsub("server", data, server, item);
}
-/* SYNTAX: SERVER CONNECT [-4 | -6] [-ssl] [-ssl_cert <cert>] [-ssl_pkey <pkey>]
- [-ssl_pass <password>] [-ssl_verify] [-ssl_cafile <cafile>]
- [-ssl_capath <capath>]
- [-ssl_ciphers <list>]
+/* SYNTAX: SERVER CONNECT [-4 | -6] [-tls] [-tls_cert <cert>] [-tls_pkey <pkey>]
+ [-tls_pass <password>] [-tls_verify] [-tls_cafile <cafile>]
+ [-tls_capath <capath>]
+ [-tls_ciphers <list>] [-tls_pinned_cert <fingerprint>] [-tls_pinned_pubkey <fingerprint>]
[-!] [-noautosendcmd]
[-noproxy] [-network <network>] [-host <hostname>]
[-rawlog <file>]
diff --git a/src/core/core.c b/src/core/core.c
index bf7cdd6b..506d6a13 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -29,6 +29,9 @@
#include "signals.h"
#include "settings.h"
#include "session.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "chat-protocols.h"
#include "servers.h"
@@ -235,6 +238,9 @@ void core_init(void)
commands_init();
nickmatch_cache_init();
session_init();
+#ifdef HAVE_CAPSICUM
+ capsicum_init();
+#endif
chat_protocols_init();
chatnets_init();
@@ -292,6 +298,9 @@ void core_deinit(void)
chatnets_deinit();
chat_protocols_deinit();
+#ifdef HAVE_CAPSICUM
+ capsicum_deinit();
+#endif
session_deinit();
nickmatch_cache_deinit();
commands_deinit();
diff --git a/src/core/ignore.c b/src/core/ignore.c
index d4a92e3c..cec91e6b 100644
--- a/src/core/ignore.c
+++ b/src/core/ignore.c
@@ -24,6 +24,7 @@
#include "levels.h"
#include "lib-config/iconfig.h"
#include "settings.h"
+#include "iregex.h"
#include "masks.h"
#include "servers.h"
@@ -67,13 +68,8 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text)
return FALSE;
if (rec->regexp) {
-#ifdef USE_GREGEX
return rec->preg != NULL &&
- g_regex_match(rec->preg, text, 0, NULL);
-#else
- return rec->regexp_compiled &&
- regexec(&rec->preg, text, 0, NULL, 0) == 0;
-#endif
+ i_regex_match(rec->preg, text, 0, NULL);
}
return rec->fullword ?
@@ -327,41 +323,19 @@ static void ignore_remove_config(IGNORE_REC *rec)
static void ignore_init_rec(IGNORE_REC *rec)
{
-#ifdef USE_GREGEX
if (rec->preg != NULL)
- g_regex_unref(rec->preg);
+ i_regex_unref(rec->preg);
if (rec->regexp && rec->pattern != NULL) {
GError *re_error = NULL;
- rec->preg = g_regex_new(rec->pattern, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, &re_error);
+ rec->preg = i_regex_new(rec->pattern, G_REGEX_OPTIMIZE | G_REGEX_CASELESS, 0, &re_error);
if (rec->preg == NULL) {
g_warning("Failed to compile regexp '%s': %s", rec->pattern, re_error->message);
g_error_free(re_error);
}
}
-#else
- char *errbuf;
- int errcode, errbuf_len;
-
- if (rec->regexp_compiled) regfree(&rec->preg);
- rec->regexp_compiled = FALSE;
-
- if (rec->regexp && rec->pattern != NULL) {
- errcode = regcomp(&rec->preg, rec->pattern,
- REG_EXTENDED|REG_ICASE|REG_NOSUB);
- if (errcode != 0) {
- errbuf_len = regerror(errcode, &rec->preg, 0, 0);
- errbuf = g_malloc(errbuf_len);
- regerror(errcode, &rec->preg, errbuf, errbuf_len);
- g_warning("Failed to compile regexp '%s': %s", rec->pattern, errbuf);
- g_free(errbuf);
- } else {
- rec->regexp_compiled = TRUE;
- }
- }
-#endif
}
void ignore_add_rec(IGNORE_REC *rec)
@@ -381,11 +355,7 @@ static void ignore_destroy(IGNORE_REC *rec, int send_signal)
if (send_signal)
signal_emit("ignore destroyed", 1, rec);
-#ifdef USE_GREGEX
- if (rec->preg != NULL) g_regex_unref(rec->preg);
-#else
- if (rec->regexp_compiled) regfree(&rec->preg);
-#endif
+ if (rec->preg != NULL) i_regex_unref(rec->preg);
if (rec->channels != NULL) g_strfreev(rec->channels);
g_free_not_null(rec->mask);
g_free_not_null(rec->servertag);
diff --git a/src/core/ignore.h b/src/core/ignore.h
index 80ae1d12..31171b58 100644
--- a/src/core/ignore.h
+++ b/src/core/ignore.h
@@ -1,9 +1,7 @@
#ifndef __IGNORE_H
#define __IGNORE_H
-#ifndef USE_GREGEX
-# include <regex.h>
-#endif
+#include "iregex.h"
typedef struct _IGNORE_REC IGNORE_REC;
@@ -20,12 +18,7 @@ struct _IGNORE_REC {
unsigned int regexp:1;
unsigned int fullword:1;
unsigned int replies:1; /* ignore replies to nick in channel */
-#ifdef USE_GREGEX
- GRegex *preg;
-#else
- unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */
- regex_t preg;
-#endif
+ Regex *preg;
};
extern GSList *ignores;
@@ -34,14 +27,14 @@ int ignore_check(SERVER_REC *server, const char *nick, const char *host,
const char *channel, const char *text, int level);
enum {
- IGNORE_FIND_PATTERN = 0x01, // Match the pattern
- IGNORE_FIND_NOACT = 0x02, // Exclude the targets with NOACT level
+ IGNORE_FIND_PATTERN = 0x01, /* Match the pattern */
+ IGNORE_FIND_NOACT = 0x02, /* Exclude the targets with NOACT level */
};
IGNORE_REC *ignore_find_full (const char *servertag, const char *mask, const char *pattern,
char **channels, const int flags);
-// Convenience wrappers around ignore_find_full, for compatibility purpose
+/* Convenience wrappers around ignore_find_full, for compatibility purpose */
IGNORE_REC *ignore_find(const char *servertag, const char *mask, char **channels);
IGNORE_REC *ignore_find_noact(const char *servertag, const char *mask, char **channels, int noact);
diff --git a/src/core/iregex-gregex.c b/src/core/iregex-gregex.c
new file mode 100644
index 00000000..36b4faa4
--- /dev/null
+++ b/src/core/iregex-gregex.c
@@ -0,0 +1,165 @@
+#include <string.h>
+
+#include "iregex.h"
+
+struct _MatchInfo {
+ const char *valid_string;
+ GMatchInfo *g_match_info;
+};
+
+static const gchar *
+make_valid_utf8(const gchar *text, gboolean *free_ret)
+{
+ GString *str;
+ const gchar *ptr;
+ if (g_utf8_validate(text, -1, NULL)) {
+ if (free_ret)
+ *free_ret = FALSE;
+ return text;
+ }
+
+ str = g_string_sized_new(strlen(text) + 12);
+
+ ptr = text;
+ while (*ptr) {
+ gunichar c = g_utf8_get_char_validated(ptr, -1);
+ /* the unicode is invalid */
+ if (c == (gunichar)-1 || c == (gunichar)-2) {
+ /* encode the byte into PUA-A */
+ g_string_append_unichar(str, (gunichar) (0xfff00 | (*ptr & 0xff)));
+ ptr++;
+ } else {
+ g_string_append_unichar(str, c);
+ ptr = g_utf8_next_char(ptr);
+ }
+ }
+
+ if (free_ret)
+ *free_ret = TRUE;
+ return g_string_free(str, FALSE);
+}
+
+Regex *
+i_regex_new (const gchar *pattern,
+ GRegexCompileFlags compile_options,
+ GRegexMatchFlags match_options,
+ GError **error)
+{
+ const gchar *valid_pattern;
+ gboolean free_valid_pattern;
+ Regex *ret = NULL;
+
+ valid_pattern = make_valid_utf8(pattern, &free_valid_pattern);
+ ret = g_regex_new(valid_pattern, compile_options, match_options, error);
+
+ if (free_valid_pattern)
+ g_free_not_null((gchar *)valid_pattern);
+
+ return ret;
+}
+
+void
+i_regex_unref (Regex *regex)
+{
+ g_regex_unref(regex);
+}
+
+gboolean
+i_regex_match (const Regex *regex,
+ const gchar *string,
+ GRegexMatchFlags match_options,
+ MatchInfo **match_info)
+{
+ gboolean ret;
+ gboolean free_valid_string;
+ const gchar *valid_string = make_valid_utf8(string, &free_valid_string);
+
+ if (match_info != NULL)
+ *match_info = g_new0(MatchInfo, 1);
+
+ ret = g_regex_match(regex, valid_string, match_options,
+ match_info != NULL ? &(*match_info)->g_match_info : NULL);
+
+ if (free_valid_string) {
+ if (match_info != NULL)
+ (*match_info)->valid_string = valid_string;
+ else
+ g_free_not_null((gchar *)valid_string);
+ }
+
+ return ret;
+}
+
+static gsize
+strlen_pua_oddly(const char *str)
+{
+ const gchar *ptr;
+ gsize ret = 0;
+ ptr = str;
+
+ while (*ptr) {
+ const gchar *old;
+ gunichar c = g_utf8_get_char(ptr);
+ old = ptr;
+ ptr = g_utf8_next_char(ptr);
+
+ /* it is our PUA encoded byte */
+ if ((c & 0xfff00) == 0xfff00)
+ ret++;
+ else
+ ret += ptr - old;
+ }
+
+ return ret;
+}
+
+/* new_string should be passed in here from the i_regex_match call.
+ The start_pos and end_pos will then be calculated as if they were on
+ the original string */
+gboolean
+i_match_info_fetch_pos (const MatchInfo *match_info,
+ gint match_num,
+ gint *start_pos,
+ gint *end_pos)
+{
+ gint tmp_start, tmp_end, new_start_pos;
+ gboolean ret;
+
+ if (!match_info->valid_string || (!start_pos && !end_pos))
+ return g_match_info_fetch_pos(match_info->g_match_info,
+ match_num, start_pos, end_pos);
+
+ ret = g_match_info_fetch_pos(match_info->g_match_info,
+ match_num, &tmp_start, &tmp_end);
+ if (start_pos || end_pos) {
+ const gchar *str = match_info->valid_string;
+ gchar *to_start = g_strndup(str, tmp_start);
+ new_start_pos = strlen_pua_oddly(to_start);
+ g_free_not_null(to_start);
+
+ if (start_pos)
+ *start_pos = new_start_pos;
+
+ if (end_pos) {
+ gchar *to_end = g_strndup(str + tmp_start, tmp_end - tmp_start);
+ *end_pos = new_start_pos + strlen_pua_oddly(to_end);
+ g_free_not_null(to_end);
+ }
+ }
+ return ret;
+}
+
+gboolean
+i_match_info_matches (const MatchInfo *match_info)
+{
+ g_return_val_if_fail(match_info != NULL, FALSE);
+
+ return g_match_info_matches(match_info->g_match_info);
+}
+
+void
+i_match_info_free (MatchInfo *match_info)
+{
+ g_match_info_free(match_info->g_match_info);
+ g_free(match_info);
+}
diff --git a/src/core/iregex-regexh.c b/src/core/iregex-regexh.c
new file mode 100644
index 00000000..897eb7e2
--- /dev/null
+++ b/src/core/iregex-regexh.c
@@ -0,0 +1,99 @@
+#include "iregex.h"
+
+Regex *
+i_regex_new (const gchar *pattern,
+ GRegexCompileFlags compile_options,
+ GRegexMatchFlags match_options,
+ GError **error)
+{
+ Regex *regex;
+ char *errbuf;
+ int cflags;
+ int errcode, errbuf_len;
+
+ regex = g_new0(Regex, 1);
+ cflags = REG_EXTENDED;
+ if (compile_options & G_REGEX_CASELESS)
+ cflags |= REG_ICASE;
+ if (compile_options & G_REGEX_MULTILINE)
+ cflags |= REG_NEWLINE;
+ if (match_options & G_REGEX_MATCH_NOTBOL)
+ cflags |= REG_NOTBOL;
+ if (match_options & G_REGEX_MATCH_NOTEOL)
+ cflags |= REG_NOTEOL;
+
+ errcode = regcomp(regex, pattern, cflags);
+ if (errcode != 0) {
+ errbuf_len = regerror(errcode, regex, 0, 0);
+ errbuf = g_malloc(errbuf_len);
+ regerror(errcode, regex, errbuf, errbuf_len);
+ g_set_error(error, G_REGEX_ERROR, errcode, "%s", errbuf);
+ g_free(errbuf);
+ g_free(regex);
+ return NULL;
+ } else {
+ return regex;
+ }
+}
+
+void
+i_regex_unref (Regex *regex)
+{
+ regfree(regex);
+ g_free(regex);
+}
+
+gboolean
+i_regex_match (const Regex *regex,
+ const gchar *string,
+ GRegexMatchFlags match_options,
+ MatchInfo **match_info)
+{
+ int groups;
+ int eflags;
+
+ g_return_val_if_fail(regex != NULL, FALSE);
+
+ if (match_info != NULL) {
+ groups = 1 + regex->re_nsub;
+ *match_info = g_new0(MatchInfo, groups);
+ } else {
+ groups = 0;
+ }
+
+ eflags = 0;
+ if (match_options & G_REGEX_MATCH_NOTBOL)
+ eflags |= REG_NOTBOL;
+ if (match_options & G_REGEX_MATCH_NOTEOL)
+ eflags |= REG_NOTEOL;
+
+ return regexec(regex, string, groups, groups ? *match_info : NULL, eflags) == 0;
+}
+
+gboolean
+i_match_info_fetch_pos (const MatchInfo *match_info,
+ gint match_num,
+ gint *start_pos,
+ gint *end_pos)
+{
+ if (start_pos != NULL)
+ *start_pos = match_info[match_num].rm_so;
+ if (end_pos != NULL)
+ *end_pos = match_info[match_num].rm_eo;
+
+ return TRUE;
+}
+
+gboolean
+i_match_info_matches (const MatchInfo *match_info)
+{
+ g_return_val_if_fail(match_info != NULL, FALSE);
+
+ return match_info[0].rm_so != -1;
+}
+
+void
+i_match_info_free (MatchInfo *match_info)
+{
+ g_free(match_info);
+}
diff --git a/src/core/iregex.h b/src/core/iregex.h
new file mode 100644
index 00000000..e67378d7
--- /dev/null
+++ b/src/core/iregex.h
@@ -0,0 +1,47 @@
+#ifndef __REGEX_H
+#define __REGEX_H
+
+#include "common.h"
+
+#ifdef USE_GREGEX
+
+#include <glib.h>
+typedef GRegex Regex;
+typedef struct _MatchInfo MatchInfo;
+
+#else
+
+#include <regex.h>
+typedef regex_t Regex;
+typedef regmatch_t MatchInfo;
+
+#endif
+
+gboolean
+i_match_info_matches (const MatchInfo *match_info);
+
+void
+i_match_info_free (MatchInfo *match_info);
+
+Regex *
+i_regex_new (const gchar *pattern,
+ GRegexCompileFlags compile_options,
+ GRegexMatchFlags match_options,
+ GError **error);
+
+void
+i_regex_unref (Regex *regex);
+
+gboolean
+i_regex_match (const Regex *regex,
+ const gchar *string,
+ GRegexMatchFlags match_options,
+ MatchInfo **match_info);
+
+gboolean
+i_match_info_fetch_pos (const MatchInfo *match_info,
+ gint match_num,
+ gint *start_pos,
+ gint *end_pos);
+
+#endif
diff --git a/src/core/levels.c b/src/core/levels.c
index e623c4de..eb7efcf7 100644
--- a/src/core/levels.c
+++ b/src/core/levels.c
@@ -21,6 +21,7 @@
#include "module.h"
#include "levels.h"
+/* the order of these levels must match the bits in levels.h */
static const char *levels[] = {
"CRAP",
"MSGS",
@@ -44,9 +45,6 @@ static const char *levels[] = {
"CLIENTCRAP",
"CLIENTERRORS",
"HILIGHTS",
-
- "NOHILIGHT",
- "NO_ACT",
NULL
};
@@ -63,6 +61,9 @@ int level_get(const char *level)
if (g_ascii_strcasecmp(level, "NO_ACT") == 0)
return MSGLEVEL_NO_ACT;
+ if (g_ascii_strcasecmp(level, "HIDDEN") == 0)
+ return MSGLEVEL_HIDDEN;
+
len = strlen(level);
if (len == 0) return 0;
@@ -138,17 +139,13 @@ char *bits2level(int bits)
str = g_string_new(NULL);
- if (bits & MSGLEVEL_NEVER) {
+ if (bits & MSGLEVEL_NEVER)
g_string_append(str, "NEVER ");
- bits &= ~MSGLEVEL_NEVER;
- }
- if (bits & MSGLEVEL_NO_ACT) {
+ if (bits & MSGLEVEL_NO_ACT)
g_string_append(str, "NO_ACT ");
- bits &= ~MSGLEVEL_NO_ACT;
- }
- if (bits == MSGLEVEL_ALL) {
+ if ((bits & MSGLEVEL_ALL) == MSGLEVEL_ALL) {
g_string_append(str, "ALL ");
} else {
for (n = 0; levels[n] != NULL; n++) {
@@ -156,6 +153,10 @@ char *bits2level(int bits)
g_string_append_printf(str, "%s ", levels[n]);
}
}
+
+ if (bits & MSGLEVEL_HIDDEN)
+ g_string_append(str, "HIDDEN ");
+
if (str->len > 0)
g_string_truncate(str, str->len-1);
diff --git a/src/core/levels.h b/src/core/levels.h
index 9f7e588f..b0ebafba 100644
--- a/src/core/levels.h
+++ b/src/core/levels.h
@@ -36,7 +36,9 @@ enum {
MSGLEVEL_NOHILIGHT = 0x1000000, /* Don't highlight this message */
MSGLEVEL_NO_ACT = 0x2000000, /* Don't trigger channel activity */
MSGLEVEL_NEVER = 0x4000000, /* never ignore / never log */
- MSGLEVEL_LASTLOG = 0x8000000 /* never ignore / never log */
+ MSGLEVEL_LASTLOG = 0x8000000, /* used for /lastlog */
+
+ MSGLEVEL_HIDDEN = 0x10000000 /* Hidden from view */
};
int level_get(const char *level);
diff --git a/src/core/log.c b/src/core/log.c
index 6af1effc..f7741d3d 100644
--- a/src/core/log.c
+++ b/src/core/log.c
@@ -26,6 +26,9 @@
#include "servers.h"
#include "log.h"
#include "write-buffer.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "lib-config/iconfig.h"
#include "settings.h"
@@ -33,6 +36,8 @@
#define DEFAULT_LOG_FILE_CREATE_MODE 600
GSList *logs;
+int log_file_create_mode;
+int log_dir_create_mode;
static const char *log_item_types[] = {
"target",
@@ -42,8 +47,6 @@ static const char *log_item_types[] = {
};
static char *log_timestamp;
-static int log_file_create_mode;
-static int log_dir_create_mode;
static int rotate_tag;
static int log_item_str2type(const char *type)
@@ -114,13 +117,23 @@ int log_start_logging(LOG_REC *log)
/* path may contain variables (%time, $vars),
make sure the directory is created */
dir = g_path_get_dirname(log->real_fname);
+#ifdef HAVE_CAPSICUM
+ capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
+#else
g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
}
+#ifdef HAVE_CAPSICUM
+ log->handle = log->real_fname == NULL ? -1 :
+ capsicum_open_wrapper(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
+ log_file_create_mode);
+#else
log->handle = log->real_fname == NULL ? -1 :
open(log->real_fname, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
+#endif
if (log->handle == -1) {
signal_emit("log create failed", 1, log);
log->failed = TRUE;
@@ -562,7 +575,6 @@ static void read_settings(void)
log_timestamp = g_strdup(settings_get_str("log_timestamp"));
log_file_create_mode = octal2dec(settings_get_int("log_create_mode"));
-
log_dir_create_mode = log_file_create_mode;
if (log_file_create_mode & 0400) log_dir_create_mode |= 0100;
if (log_file_create_mode & 0040) log_dir_create_mode |= 0010;
diff --git a/src/core/log.h b/src/core/log.h
index fae872c7..5a07859b 100644
--- a/src/core/log.h
+++ b/src/core/log.h
@@ -35,6 +35,8 @@ struct _LOG_REC {
};
extern GSList *logs;
+extern int log_file_create_mode;
+extern int log_dir_create_mode;
/* Create log record - you still need to call log_update() to actually add it
into log list */
diff --git a/src/core/misc.c b/src/core/misc.c
index d8437430..4e9f4bbe 100644
--- a/src/core/misc.c
+++ b/src/core/misc.c
@@ -22,10 +22,6 @@
#include "misc.h"
#include "commands.h"
-#ifndef USE_GREGEX
-# include <regex.h>
-#endif
-
typedef struct {
int condition;
GInputFunction function;
@@ -560,6 +556,9 @@ char *my_asctime(time_t t)
int len;
tm = localtime(&t);
+ if (tm == NULL)
+ return g_strdup("???");
+
str = g_strdup(asctime(tm));
len = strlen(str);
@@ -704,8 +703,11 @@ int expand_escape(const char **data)
*data += 2;
return strtol(digit, NULL, 16);
case 'c':
- /* control character (\cA = ^A) */
- (*data)++;
+ /* check for end of string */
+ if ((*data)[1] == '\0')
+ return 0;
+ /* control character (\cA = ^A) */
+ (*data)++;
return i_toupper(**data) - 64;
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
@@ -750,27 +752,73 @@ int nearest_power(int num)
return n;
}
-int parse_time_interval(const char *time, int *msecs)
+/* Parses unsigned integers from strings with decent error checking.
+ * Returns true on success, false otherwise (overflow, no valid number, etc)
+ * There's a 31 bit limit so the output can be assigned to signed positive ints */
+int parse_uint(const char *nptr, char **endptr, int base, guint *number)
+{
+ char *endptr_;
+ gulong parsed;
+
+ /* strtoul accepts whitespace and plus/minus signs, for some reason */
+ if (!i_isdigit(*nptr)) {
+ return FALSE;
+ }
+
+ errno = 0;
+ parsed = strtoul(nptr, &endptr_, base);
+
+ if (errno || endptr_ == nptr || parsed >= (1U << 31)) {
+ return FALSE;
+ }
+
+ if (endptr) {
+ *endptr = endptr_;
+ }
+
+ if (number) {
+ *number = (guint) parsed;
+ }
+
+ return TRUE;
+}
+
+static int parse_number_sign(const char *input, char **endptr, int *sign)
+{
+ int sign_ = 1;
+
+ while (i_isspace(*input))
+ input++;
+
+ if (*input == '-') {
+ sign_ = -sign_;
+ input++;
+ }
+
+ *sign = sign_;
+ *endptr = (char *) input;
+ return TRUE;
+}
+
+static int parse_time_interval_uint(const char *time, guint *msecs)
{
const char *desc;
- int number, sign, len, ret, digits;
+ guint number;
+ int len, ret, digits;
*msecs = 0;
/* max. return value is around 24 days */
- number = 0; sign = 1; ret = TRUE; digits = FALSE;
+ number = 0; ret = TRUE; digits = FALSE;
while (i_isspace(*time))
time++;
- if (*time == '-') {
- sign = -sign;
- time++;
- while (i_isspace(*time))
- time++;
- }
for (;;) {
if (i_isdigit(*time)) {
- number = number*10 + (*time - '0');
- time++;
+ char *endptr;
+ if (!parse_uint(time, &endptr, 10, &number)) {
+ return FALSE;
+ }
+ time = endptr;
digits = TRUE;
continue;
}
@@ -793,7 +841,6 @@ int parse_time_interval(const char *time, int *msecs)
if (*time != '\0')
return FALSE;
*msecs += number * 1000; /* assume seconds */
- *msecs *= sign;
return TRUE;
}
@@ -831,14 +878,14 @@ int parse_time_interval(const char *time, int *msecs)
digits = FALSE;
}
- *msecs *= sign;
return ret;
}
-int parse_size(const char *size, int *bytes)
+static int parse_size_uint(const char *size, guint *bytes)
{
const char *desc;
- int number, len;
+ guint number, multiplier, limit;
+ int len;
*bytes = 0;
@@ -846,8 +893,11 @@ int parse_size(const char *size, int *bytes)
number = 0;
while (*size != '\0') {
if (i_isdigit(*size)) {
- number = number*10 + (*size - '0');
- size++;
+ char *endptr;
+ if (!parse_uint(size, &endptr, 10, &number)) {
+ return FALSE;
+ }
+ size = endptr;
continue;
}
@@ -869,14 +919,31 @@ int parse_size(const char *size, int *bytes)
return FALSE;
}
- if (g_ascii_strncasecmp(desc, "gbytes", len) == 0)
- *bytes += number * 1024*1024*1024;
- if (g_ascii_strncasecmp(desc, "mbytes", len) == 0)
- *bytes += number * 1024*1024;
- if (g_ascii_strncasecmp(desc, "kbytes", len) == 0)
- *bytes += number * 1024;
- if (g_ascii_strncasecmp(desc, "bytes", len) == 0)
- *bytes += number;
+ multiplier = 0;
+ limit = 0;
+
+ if (g_ascii_strncasecmp(desc, "gbytes", len) == 0) {
+ multiplier = 1U << 30;
+ limit = 2U << 0;
+ }
+ if (g_ascii_strncasecmp(desc, "mbytes", len) == 0) {
+ multiplier = 1U << 20;
+ limit = 2U << 10;
+ }
+ if (g_ascii_strncasecmp(desc, "kbytes", len) == 0) {
+ multiplier = 1U << 10;
+ limit = 2U << 20;
+ }
+ if (g_ascii_strncasecmp(desc, "bytes", len) == 0) {
+ multiplier = 1;
+ limit = 2U << 30;
+ }
+
+ if (limit && number > limit) {
+ return FALSE;
+ }
+
+ *bytes += number * multiplier;
/* skip punctuation */
while (*size != '\0' && i_ispunct(*size))
@@ -886,6 +953,40 @@ int parse_size(const char *size, int *bytes)
return TRUE;
}
+int parse_size(const char *size, int *bytes)
+{
+ guint bytes_;
+ int ret;
+
+ ret = parse_size_uint(size, &bytes_);
+
+ if (bytes_ > (1U << 31)) {
+ return FALSE;
+ }
+
+ *bytes = bytes_;
+ return ret;
+}
+
+int parse_time_interval(const char *time, int *msecs)
+{
+ guint msecs_;
+ char *number;
+ int ret, sign;
+
+ parse_number_sign(time, &number, &sign);
+
+ ret = parse_time_interval_uint(number, &msecs_);
+
+ if (msecs_ > (1U << 31)) {
+ return FALSE;
+ }
+
+ *msecs = msecs_ * sign;
+ return ret;
+}
+
+
char *ascii_strup(char *str)
{
char *s;
diff --git a/src/core/misc.h b/src/core/misc.h
index 00637da0..375744db 100644
--- a/src/core/misc.h
+++ b/src/core/misc.h
@@ -71,6 +71,7 @@ int expand_escape(const char **data);
int nearest_power(int num);
/* Returns TRUE / FALSE */
+int parse_uint(const char *nptr, char **endptr, int base, guint *number);
int parse_time_interval(const char *time, int *msecs);
int parse_size(const char *size, int *bytes);
diff --git a/src/core/network-openssl.c b/src/core/network-openssl.c
index 4de3cb3c..c7ce4b43 100644
--- a/src/core/network-openssl.c
+++ b/src/core/network-openssl.c
@@ -20,6 +20,7 @@
#include "module.h"
#include "network.h"
+#include "network-openssl.h"
#include "net-sendbuffer.h"
#include "misc.h"
#include "servers.h"
@@ -44,6 +45,19 @@
#define ASN1_STRING_data(x) ASN1_STRING_get0_data(x)
#endif
+/* OpenSSL 1.1.0 also introduced some useful additions to the api */
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined (LIBRESSL_VERSION_NUMBER)
+static int X509_STORE_up_ref(X509_STORE *vfy)
+{
+ int n;
+
+ n = CRYPTO_add(&vfy->references, 1, CRYPTO_LOCK_X509_STORE);
+ g_assert(n > 1);
+
+ return (n > 1) ? 1 : 0;
+}
+#endif
+
/* ssl i/o channel object */
typedef struct
{
@@ -58,6 +72,7 @@ typedef struct
} GIOSSLChannel;
static int ssl_inited = FALSE;
+static X509_STORE *store = NULL;
static void irssi_ssl_free(GIOChannel *handle)
{
@@ -362,8 +377,10 @@ static GIOFuncs irssi_ssl_channel_funcs = {
irssi_ssl_get_flags
};
-static gboolean irssi_ssl_init(void)
+gboolean irssi_ssl_init(void)
{
+ int success;
+
#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER)
if (!OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL)) {
g_error("Could not initialize OpenSSL");
@@ -374,6 +391,20 @@ static gboolean irssi_ssl_init(void)
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
#endif
+ store = X509_STORE_new();
+ if (store == NULL) {
+ g_error("Could not initialize OpenSSL: X509_STORE_new() failed");
+ return FALSE;
+ }
+
+ success = X509_STORE_set_default_paths(store);
+ if (success == 0) {
+ g_warning("Could not load default certificates");
+ X509_STORE_free(store);
+ store = NULL;
+ /* Don't return an error; the user might have their own cafile/capath. */
+ }
+
ssl_inited = TRUE;
return TRUE;
@@ -491,9 +522,12 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
g_free(scafile);
g_free(scapath);
verify = TRUE;
- } else {
- if (!SSL_CTX_set_default_verify_paths(ctx))
- g_warning("Could not load default certificates");
+ } else if (store != NULL) {
+ /* Make sure to increment the refcount every time the store is
+ * used, that's essential not to get it free'd by OpenSSL when
+ * the SSL_CTX is destroyed. */
+ X509_STORE_up_ref(store);
+ SSL_CTX_set_cert_store(ctx, store);
}
if(!(ssl = SSL_new(ctx)))
@@ -549,9 +583,6 @@ static void set_cipher_info(TLS_REC *tls, SSL *ssl)
static void set_pubkey_info(TLS_REC *tls, X509 *cert, unsigned char *cert_fingerprint, size_t cert_fingerprint_size, unsigned char *public_key_fingerprint, size_t public_key_fingerprint_size)
{
- g_return_if_fail(tls != NULL);
- g_return_if_fail(cert != NULL);
-
EVP_PKEY *pubkey = NULL;
char *cert_fingerprint_hex = NULL;
char *public_key_fingerprint_hex = NULL;
@@ -560,13 +591,16 @@ static void set_pubkey_info(TLS_REC *tls, X509 *cert, unsigned char *cert_finger
char buffer[128];
size_t length;
+ g_return_if_fail(tls != NULL);
+ g_return_if_fail(cert != NULL);
+
pubkey = X509_get_pubkey(cert);
cert_fingerprint_hex = binary_to_hex(cert_fingerprint, cert_fingerprint_size);
tls_rec_set_certificate_fingerprint(tls, cert_fingerprint_hex);
tls_rec_set_certificate_fingerprint_algorithm(tls, "SHA256");
- // Show algorithm.
+ /* Show algorithm. */
switch (EVP_PKEY_id(pubkey)) {
case EVP_PKEY_RSA:
tls_rec_set_public_key_algorithm(tls, "RSA");
@@ -590,7 +624,7 @@ static void set_pubkey_info(TLS_REC *tls, X509 *cert, unsigned char *cert_finger
tls_rec_set_public_key_size(tls, EVP_PKEY_bits(pubkey));
tls_rec_set_public_key_fingerprint_algorithm(tls, "SHA256");
- // Read the NotBefore timestamp.
+ /* Read the NotBefore timestamp. */
bio = BIO_new(BIO_s_mem());
ASN1_TIME_print(bio, X509_get_notBefore(cert));
length = BIO_read(bio, buffer, sizeof(buffer));
@@ -598,7 +632,7 @@ static void set_pubkey_info(TLS_REC *tls, X509 *cert, unsigned char *cert_finger
BIO_free(bio);
tls_rec_set_not_before(tls, buffer);
- // Read the NotAfter timestamp.
+ /* Read the NotAfter timestamp. */
bio = BIO_new(BIO_s_mem());
ASN1_TIME_print(bio, X509_get_notAfter(cert));
length = BIO_read(bio, buffer, sizeof(buffer));
@@ -613,9 +647,6 @@ static void set_pubkey_info(TLS_REC *tls, X509 *cert, unsigned char *cert_finger
static void set_peer_cert_chain_info(TLS_REC *tls, SSL *ssl)
{
- g_return_if_fail(tls != NULL);
- g_return_if_fail(ssl != NULL);
-
int nid;
char *key = NULL;
char *value = NULL;
@@ -628,6 +659,9 @@ static void set_peer_cert_chain_info(TLS_REC *tls, SSL *ssl)
TLS_CERT_ENTRY_REC *tls_cert_entry_rec = NULL;
ASN1_STRING *data = NULL;
+ g_return_if_fail(tls != NULL);
+ g_return_if_fail(ssl != NULL);
+
chain = SSL_get_peer_cert_chain(ssl);
if (chain == NULL)
@@ -636,7 +670,7 @@ static void set_peer_cert_chain_info(TLS_REC *tls, SSL *ssl)
for (i = 0; i < sk_X509_num(chain); i++) {
cert_rec = tls_cert_create_rec();
- // Subject.
+ /* Subject. */
name = X509_get_subject_name(sk_X509_value(chain, i));
for (j = 0; j < X509_NAME_entry_count(name); j++) {
@@ -655,7 +689,7 @@ static void set_peer_cert_chain_info(TLS_REC *tls, SSL *ssl)
tls_cert_rec_append_subject_entry(cert_rec, tls_cert_entry_rec);
}
- // Issuer.
+ /* Issuer. */
name = X509_get_issuer_name(sk_X509_value(chain, i));
for (j = 0; j < X509_NAME_entry_count(name); j++) {
@@ -680,14 +714,11 @@ static void set_peer_cert_chain_info(TLS_REC *tls, SSL *ssl)
static void set_server_temporary_key_info(TLS_REC *tls, SSL *ssl)
{
- g_return_if_fail(tls != NULL);
- g_return_if_fail(ssl != NULL);
-
#ifdef SSL_get_server_tmp_key
- // Show ephemeral key information.
+ /* Show ephemeral key information. */
EVP_PKEY *ephemeral_key = NULL;
- // OPENSSL_NO_EC is for solaris 11.3 (2016), github ticket #598
+ /* OPENSSL_NO_EC is for solaris 11.3 (2016), github ticket #598 */
#ifndef OPENSSL_NO_EC
EC_KEY *ec_key = NULL;
#endif
@@ -695,6 +726,9 @@ static void set_server_temporary_key_info(TLS_REC *tls, SSL *ssl)
char *cname = NULL;
int nid;
+ g_return_if_fail(tls != NULL);
+ g_return_if_fail(ssl != NULL);
+
if (SSL_get_server_tmp_key(ssl, &ephemeral_key)) {
switch (EVP_PKEY_id(ephemeral_key)) {
case EVP_PKEY_DH:
@@ -725,7 +759,7 @@ static void set_server_temporary_key_info(TLS_REC *tls, SSL *ssl)
EVP_PKEY_free(ephemeral_key);
}
-#endif // SSL_get_server_tmp_key.
+#endif /* SSL_get_server_tmp_key. */
}
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server)
@@ -832,7 +866,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
set_peer_cert_chain_info(tls, chan->ssl);
set_server_temporary_key_info(tls, chan->ssl);
- // Emit the TLS rec.
+ /* Emit the TLS rec. */
signal_emit("tls handshake finished", 2, chan->server, tls);
ret = 1;
@@ -859,7 +893,7 @@ int irssi_ssl_handshake(GIOChannel *handle)
ret = irssi_ssl_verify(chan->ssl, chan->ctx, chan->server->connrec->address, chan->port, cert, chan->server, tls);
if (! ret) {
- // irssi_ssl_verify emits a warning itself.
+ /* irssi_ssl_verify emits a warning itself. */
goto done;
}
}
diff --git a/src/core/network-openssl.h b/src/core/network-openssl.h
new file mode 100644
index 00000000..4cd6d711
--- /dev/null
+++ b/src/core/network-openssl.h
@@ -0,0 +1,6 @@
+#ifndef __NETWORK_OPENSSL_H
+#define __NETWORK_OPENSSL_H
+
+gboolean irssi_ssl_init(void);
+
+#endif /* !__NETWORK_OPENSSL_H */
diff --git a/src/core/network.c b/src/core/network.c
index 3e1b7c70..d280b463 100644
--- a/src/core/network.c
+++ b/src/core/network.c
@@ -20,6 +20,9 @@
#include "module.h"
#include "network.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include <sys/un.h>
@@ -45,9 +48,6 @@ GIOChannel *g_io_channel_new(int handle)
return chan;
}
-/* Cygwin need this, don't know others.. */
-/*#define BLOCKING_SOCKETS 1*/
-
IPADDR ip4_any = {
AF_INET,
#if defined(IN6ADDR_ANY_INIT)
@@ -110,42 +110,7 @@ static int sin_get_port(union sockaddr_union *so)
so->sin.sin_port);
}
-/* Connect to socket */
-GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip)
-{
- IPADDR ip4, ip6, *ip;
-
- g_return_val_if_fail(addr != NULL, NULL);
-
- if (net_gethostbyname(addr, &ip4, &ip6) == -1)
- return NULL;
-
- if (my_ip == NULL) {
- /* prefer IPv4 addresses */
- ip = ip4.family != 0 ? &ip4 : &ip6;
- } else if (IPADDR_IS_V6(my_ip)) {
- /* my_ip is IPv6 address, use it if possible */
- if (ip6.family != 0)
- ip = &ip6;
- else {
- my_ip = NULL;
- ip = &ip4;
- }
- } else {
- /* my_ip is IPv4 address, use it if possible */
- if (ip4.family != 0)
- ip = &ip4;
- else {
- my_ip = NULL;
- ip = &ip6;
- }
- }
-
- return net_connect_ip(ip, port, my_ip);
-}
-
-/* Connect to socket with ip address */
-GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
+int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip)
{
union sockaddr_union so;
int handle, ret, opt = 1;
@@ -161,7 +126,7 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
handle = socket(ip->family, SOCK_STREAM, 0);
if (handle == -1)
- return NULL;
+ return -1;
/* set socket options */
fcntl(handle, F_SETFL, O_NONBLOCK);
@@ -176,7 +141,7 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
close(handle);
errno = old_errno;
- return NULL;
+ return -1;
}
}
@@ -190,9 +155,29 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
int old_errno = errno;
close(handle);
errno = old_errno;
- return NULL;
+ return -1;
}
+ return handle;
+}
+
+/* Connect to socket with ip address */
+GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
+{
+ int handle = -1;
+
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ handle = capsicum_net_connect_ip(ip, port, my_ip);
+ else
+ handle = net_connect_ip_handle(ip, port, my_ip);
+#else
+ handle = net_connect_ip_handle(ip, port, my_ip);
+#endif
+
+ if (handle == -1)
+ return (NULL);
+
return g_io_channel_new(handle);
}
@@ -383,6 +368,11 @@ int net_gethostbyname(const char *addr, IPADDR *ip4, IPADDR *ip6)
struct addrinfo hints, *ai, *ailist;
int ret, count_v4, count_v6, use_v4, use_v6;
+#ifdef HAVE_CAPSICUM
+ if (capsicum_enabled())
+ return (capsicum_net_gethostbyname(addr, ip4, ip6));
+#endif
+
g_return_val_if_fail(addr != NULL, -1);
memset(ip4, 0, sizeof(IPADDR));
@@ -462,6 +452,7 @@ int net_gethostbyaddr(IPADDR *ip, char **name)
int net_ip2host(IPADDR *ip, char *host)
{
+ host[0] = '\0';
return inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN) ? 0 : -1;
}
diff --git a/src/core/network.h b/src/core/network.h
index 8757f78c..e60f607f 100644
--- a/src/core/network.h
+++ b/src/core/network.h
@@ -33,11 +33,12 @@ extern IPADDR ip4_any;
GIOChannel *g_io_channel_new(int handle);
-/* returns 1 if IPADDRs are the same */
-int net_ip_compare(IPADDR *ip1, IPADDR *ip2);
+/* Returns 1 if IPADDRs are the same. */
+/* Deprecated since it is unused. It will be deleted in a later release. */
+int net_ip_compare(IPADDR *ip1, IPADDR *ip2) G_GNUC_DEPRECATED;
+
+int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip);
-/* Connect to socket */
-GIOChannel *net_connect(const char *addr, int port, IPADDR *my_ip) G_GNUC_DEPRECATED;
/* Connect to socket with ip address and SSL*/
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server);
/* Start TLS */
diff --git a/src/core/nicklist.c b/src/core/nicklist.c
index 770b0afc..0bc88ab8 100644
--- a/src/core/nicklist.c
+++ b/src/core/nicklist.c
@@ -54,23 +54,26 @@ static void nick_hash_add(CHANNEL_REC *channel, NICK_REC *nick)
static void nick_hash_remove(CHANNEL_REC *channel, NICK_REC *nick)
{
- NICK_REC *list;
+ NICK_REC *list, *newlist;
list = g_hash_table_lookup(channel->nicks, nick->nick);
if (list == NULL)
return;
- if (list == nick || list->next == NULL) {
- g_hash_table_remove(channel->nicks, nick->nick);
- if (list->next != NULL) {
- g_hash_table_insert(channel->nicks, nick->next->nick,
- nick->next);
- }
+ if (list == nick) {
+ newlist = nick->next;
} else {
+ newlist = list;
while (list->next != nick)
list = list->next;
list->next = nick->next;
}
+
+ g_hash_table_remove(channel->nicks, nick->nick);
+ if (newlist != NULL) {
+ g_hash_table_insert(channel->nicks, newlist->nick,
+ newlist);
+ }
}
/* Add new nick to list */
@@ -169,37 +172,39 @@ void nicklist_rename_unique(SERVER_REC *server,
static NICK_REC *nicklist_find_wildcards(CHANNEL_REC *channel,
const char *mask)
{
- GSList *nicks, *tmp;
NICK_REC *nick;
-
- nicks = nicklist_getnicks(channel);
- nick = NULL;
- for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
- nick = tmp->data;
-
- if (mask_match_address(channel->server, mask,
- nick->nick, nick->host))
- break;
+ GHashTableIter iter;
+
+ g_hash_table_iter_init(&iter, channel->nicks);
+ while (g_hash_table_iter_next(&iter, NULL, (void*)&nick)) {
+ for (; nick != NULL; nick = nick->next) {
+ if (mask_match_address(channel->server, mask,
+ nick->nick, nick->host))
+ return nick;
+ }
}
- g_slist_free(nicks);
- return tmp == NULL ? NULL : nick;
+
+ return NULL;
}
GSList *nicklist_find_multiple(CHANNEL_REC *channel, const char *mask)
{
- GSList *nicks, *tmp, *next;
+ GSList *nicks;
+ NICK_REC *nick;
+ GHashTableIter iter;
g_return_val_if_fail(IS_CHANNEL(channel), NULL);
g_return_val_if_fail(mask != NULL, NULL);
- nicks = nicklist_getnicks(channel);
- for (tmp = nicks; tmp != NULL; tmp = next) {
- NICK_REC *nick = tmp->data;
+ nicks = NULL;
- next = tmp->next;
- if (!mask_match_address(channel->server, mask,
- nick->nick, nick->host))
- nicks = g_slist_remove(nicks, tmp->data);
+ g_hash_table_iter_init(&iter, channel->nicks);
+ while (g_hash_table_iter_next(&iter, NULL, (void*)&nick)) {
+ for (; nick != NULL; nick = nick->next) {
+ if (mask_match_address(channel->server, mask,
+ nick->nick, nick->host))
+ nicks = g_slist_prepend(nicks, nick);
+ }
}
return nicks;
@@ -264,8 +269,8 @@ NICK_REC *nicklist_find_mask(CHANNEL_REC *channel, const char *mask)
static void get_nicks_hash(gpointer key, NICK_REC *rec, GSList **list)
{
while (rec != NULL) {
- *list = g_slist_append(*list, rec);
- rec = rec->next;
+ *list = g_slist_prepend(*list, rec);
+ rec = rec->next;
}
}
diff --git a/src/core/rawlog.c b/src/core/rawlog.c
index 5927e730..fdd51241 100644
--- a/src/core/rawlog.c
+++ b/src/core/rawlog.c
@@ -20,19 +20,21 @@
#include "module.h"
#include "rawlog.h"
+#include "log.h"
#include "modules.h"
#include "signals.h"
#include "commands.h"
#include "misc.h"
#include "write-buffer.h"
#include "settings.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "servers.h"
static int rawlog_lines;
static int signal_rawlog;
-static int log_file_create_mode;
-static int log_dir_create_mode;
RAWLOG_REC *rawlog_create(void)
{
@@ -127,12 +129,24 @@ void rawlog_open(RAWLOG_REC *rawlog, const char *fname)
return;
path = convert_home(fname);
+#ifdef HAVE_CAPSICUM
+ rawlog->handle = capsicum_open_wrapper(path,
+ O_WRONLY | O_APPEND | O_CREAT,
+ log_file_create_mode);
+#else
rawlog->handle = open(path, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
+#endif
+
g_free(path);
+ if (rawlog->handle == -1) {
+ g_warning("rawlog open() failed: %s", strerror(errno));
+ return;
+ }
+
rawlog_dump(rawlog, rawlog->handle);
- rawlog->logging = rawlog->handle != -1;
+ rawlog->logging = TRUE;
}
void rawlog_close(RAWLOG_REC *rawlog)
@@ -140,7 +154,7 @@ void rawlog_close(RAWLOG_REC *rawlog)
if (rawlog->logging) {
write_buffer_flush();
close(rawlog->handle);
- rawlog->logging = 0;
+ rawlog->logging = FALSE;
}
}
@@ -150,11 +164,20 @@ void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
int f;
dir = g_path_get_dirname(fname);
+#ifdef HAVE_CAPSICUM
+ capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
+#else
g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
path = convert_home(fname);
+#ifdef HAVE_CAPSICUM
+ f = capsicum_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT,
+ log_file_create_mode);
+#else
f = open(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode);
+#endif
g_free(path);
if (f < 0) {
@@ -174,12 +197,6 @@ void rawlog_set_size(int lines)
static void read_settings(void)
{
rawlog_set_size(settings_get_int("rawlog_lines"));
- log_file_create_mode = octal2dec(settings_get_int("log_create_mode"));
- log_dir_create_mode = log_file_create_mode;
- if (log_file_create_mode & 0400) log_dir_create_mode |= 0100;
- if (log_file_create_mode & 0040) log_dir_create_mode |= 0010;
- if (log_file_create_mode & 0004) log_dir_create_mode |= 0001;
-
}
static void cmd_rawlog(const char *data, SERVER_REC *server, void *item)
diff --git a/src/core/recode.c b/src/core/recode.c
index d001a46a..d3fc91e7 100644
--- a/src/core/recode.c
+++ b/src/core/recode.c
@@ -198,7 +198,12 @@ char **recode_split(const SERVER_REC *server, const char *str,
int n = 0;
char **ret;
- g_return_val_if_fail(str != NULL, NULL);
+ g_warn_if_fail(str != NULL);
+ if (str == NULL) {
+ ret = g_new(char *, 1);
+ ret[0] = NULL;
+ return ret;
+ }
if (settings_get_bool("recode")) {
to = find_conversion(server, target);
diff --git a/src/core/settings.c b/src/core/settings.c
index 4e0717cd..3ebb9e4a 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -39,6 +39,7 @@ static GString *last_errors;
static GSList *last_invalid_modules;
static int fe_initialized;
static int config_changed; /* FIXME: remove after .98 (unless needed again) */
+static unsigned int user_settings_changed;
static GHashTable *settings;
static int timeout_tag;
@@ -464,6 +465,11 @@ SETTINGS_REC *settings_get_record(const char *key)
return g_hash_table_lookup(settings, key);
}
+static void sig_init_userinfo_changed(gpointer changedp)
+{
+ user_settings_changed |= GPOINTER_TO_UINT(changedp);
+}
+
static void sig_init_finished(void)
{
fe_initialized = TRUE;
@@ -479,6 +485,8 @@ static void sig_init_finished(void)
"updated, please /SAVE");
signal_emit("setup changed", 0);
}
+
+ signal_emit("settings userinfo changed", 1, GUINT_TO_POINTER(user_settings_changed));
}
static void settings_clean_invalid_module(const char *module)
@@ -875,6 +883,7 @@ void settings_init(void)
timeout_tag = g_timeout_add(SETTINGS_AUTOSAVE_TIMEOUT,
(GSourceFunc) sig_autosave, NULL);
signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+ signal_add("irssi init userinfo changed", (SIGNAL_FUNC) sig_init_userinfo_changed);
signal_add("gui exit", (SIGNAL_FUNC) sig_autosave);
}
@@ -887,6 +896,7 @@ void settings_deinit(void)
{
g_source_remove(timeout_tag);
signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+ signal_remove("irssi init userinfo changed", (SIGNAL_FUNC) sig_init_userinfo_changed);
signal_remove("gui exit", (SIGNAL_FUNC) sig_autosave);
g_slist_foreach(last_invalid_modules, (GFunc) g_free, NULL);
diff --git a/src/core/settings.h b/src/core/settings.h
index d174f250..b67a9e44 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -30,6 +30,13 @@ typedef struct {
char **choices;
} SETTINGS_REC;
+enum {
+ USER_SETTINGS_REAL_NAME = 0x1,
+ USER_SETTINGS_USER_NAME = 0x2,
+ USER_SETTINGS_NICK = 0x4,
+ USER_SETTINGS_HOSTNAME = 0x8,
+};
+
/* macros for handling the default Irssi configuration */
#define iconfig_get_str(a, b, c) config_get_str(mainconfig, a, b, c)
#define iconfig_get_int(a, b, c) config_get_int(mainconfig, a, b, c)
diff --git a/src/core/special-vars.c b/src/core/special-vars.c
index 6ca080fc..f254c200 100644
--- a/src/core/special-vars.c
+++ b/src/core/special-vars.c
@@ -275,6 +275,8 @@ static char *get_special_value(char **cmd, SERVER_REC *server, void *item,
static int get_alignment_args(char **data, int *align, int *flags, char *pad)
{
char *str;
+ char *endptr;
+ guint align_;
*align = 0;
*flags = ALIGN_CUT|ALIGN_PAD;
@@ -295,10 +297,11 @@ static int get_alignment_args(char **data, int *align, int *flags, char *pad)
return FALSE; /* expecting number */
/* get the alignment size */
- while (i_isdigit(*str)) {
- *align = (*align) * 10 + (*str-'0');
- str++;
+ if (!parse_uint(str, &endptr, 10, &align_)) {
+ return FALSE;
}
+ str = endptr;
+ *align = align_;
/* get the pad character */
while (*str != '\0' && *str != ']') {
@@ -381,6 +384,7 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item,
}
nest_free = FALSE; nest_value = NULL;
+#if 0 /* this code is disabled due to security issues until it is fixed */
if (**cmd == '(' && (*cmd)[1] != '\0') {
/* subvariable */
int toplevel = nested_orig_cmd == NULL;
@@ -409,6 +413,9 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item,
if (toplevel) nested_orig_cmd = NULL;
}
+#else
+ if (nested_orig_cmd) nested_orig_cmd = NULL;
+#endif
if (**cmd != '{')
brackets = FALSE;
diff --git a/src/fe-common/core/Makefile.am b/src/fe-common/core/Makefile.am
index 6efff411..cf4e8ee3 100644
--- a/src/fe-common/core/Makefile.am
+++ b/src/fe-common/core/Makefile.am
@@ -38,17 +38,24 @@ libfe_common_core_a_SOURCES = \
windows-layout.c \
fe-windows.c
+if HAVE_CAPSICUM
+libfe_common_core_a_SOURCES += \
+ fe-capsicum.c
+endif
+
pkginc_fe_common_coredir=$(pkgincludedir)/src/fe-common/core
pkginc_fe_common_core_HEADERS = \
command-history.h \
chat-completion.h \
completion.h \
+ fe-capsicum.h \
fe-channels.h \
fe-common-core.h \
fe-core-commands.h \
fe-exec.h \
fe-messages.h \
fe-queries.h \
+ fe-settings.h \
fe-tls.h \
formats.h \
hilight-text.h \
diff --git a/src/fe-common/core/chat-completion.c b/src/fe-common/core/chat-completion.c
index 1f00feaf..97cd0565 100644
--- a/src/fe-common/core/chat-completion.c
+++ b/src/fe-common/core/chat-completion.c
@@ -1011,13 +1011,17 @@ static void sig_complete_target(GList **list, WINDOW_REC *window,
}
}
+static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item);
+
/* expand \n, \t and \\ */
static char *expand_escapes(const char *line, SERVER_REC *server,
WI_ITEM_REC *item)
{
char *ptr, *ret;
- int chr;
+ const char *prev;
+ int chr;
+ prev = line;
ret = ptr = g_malloc(strlen(line)+1);
for (; *line != '\0'; line++) {
if (*line != '\\') {
@@ -1036,9 +1040,11 @@ static char *expand_escapes(const char *line, SERVER_REC *server,
/* newline .. we need to send another "send text"
event to handle it (or actually the text before
the newline..) */
- if (ret != ptr) {
- *ptr = '\0';
- signal_emit("send text", 3, ret, server, item);
+ if (prev != line) {
+ char *prev_line = g_strndup(prev, (line - prev) - 1);
+ event_text(prev_line, server, item);
+ g_free(prev_line);
+ prev = line + 1;
ptr = ret;
}
} else if (chr != -1) {
diff --git a/src/fe-common/core/command-history.c b/src/fe-common/core/command-history.c
index 55474b1b..32d7adaa 100644
--- a/src/fe-common/core/command-history.c
+++ b/src/fe-common/core/command-history.c
@@ -30,10 +30,93 @@
#include "command-history.h"
/* command history */
+static GList *history_entries;
static HISTORY_REC *global_history;
static int window_history;
static GSList *histories;
+static HISTORY_ENTRY_REC *history_entry_new(HISTORY_REC *history, const char *text)
+{
+ HISTORY_ENTRY_REC *entry;
+
+ entry = g_new0(HISTORY_ENTRY_REC, 1);
+ entry->text = g_strdup(text);
+ entry->history = history;
+ entry->time = time(NULL);
+
+ return entry;
+}
+
+static void history_entry_destroy(HISTORY_ENTRY_REC *entry)
+{
+ g_free((char *)entry->text);
+ g_free(entry);
+}
+
+GList *command_history_list_last(HISTORY_REC *history)
+{
+ GList *link;
+
+ link = g_list_last(history_entries);
+ while (link != NULL && history != NULL && ((HISTORY_ENTRY_REC *)link->data)->history != history) {
+ link = link->prev;
+ }
+
+ return link;
+}
+
+GList *command_history_list_first(HISTORY_REC *history)
+{
+ GList *link;
+
+ link = history_entries;
+ while (link != NULL && history != NULL && ((HISTORY_ENTRY_REC *)link->data)->history != history) {
+ link = link->next;
+ }
+
+ return link;
+}
+
+GList *command_history_list_prev(HISTORY_REC *history, GList *pos)
+{
+ GList *link;
+
+ link = pos != NULL ? pos->prev : NULL;
+ while (link != NULL && history != NULL && ((HISTORY_ENTRY_REC *)link->data)->history != history) {
+ link = link->prev;
+ }
+
+ return link;
+}
+
+GList *command_history_list_next(HISTORY_REC *history, GList *pos)
+{
+ GList *link;
+
+ link = pos != NULL ? pos->next : NULL;
+ while (link != NULL && history != NULL && ((HISTORY_ENTRY_REC *)link->data)->history != history) {
+ link = link->next;
+ }
+
+ return link;
+}
+
+static void command_history_clear_pos_for_unlink_func(HISTORY_REC *history, GList* link)
+{
+ if (history->pos == link) {
+ history->pos = command_history_list_next(history, link);
+ history->redo = 1;
+ }
+}
+
+static void history_list_delete_link_and_destroy(GList *link)
+{
+ g_slist_foreach(histories,
+ (GFunc) command_history_clear_pos_for_unlink_func, link);
+ history_entry_destroy(link->data);
+ history_entries = g_list_delete_link(history_entries, link);
+}
+
void command_history_add(HISTORY_REC *history, const char *text)
{
GList *link;
@@ -41,21 +124,19 @@ void command_history_add(HISTORY_REC *history, const char *text)
g_return_if_fail(history != NULL);
g_return_if_fail(text != NULL);
- link = g_list_last(history->list);
- if (link != NULL && g_strcmp0(link->data, text) == 0)
- return; /* same as previous entry */
+ link = command_history_list_last(history);
+ if (link != NULL && g_strcmp0(((HISTORY_ENTRY_REC *)link->data)->text, text) == 0)
+ return; /* same as previous entry */
if (settings_get_int("max_command_history") < 1 ||
history->lines < settings_get_int("max_command_history"))
history->lines++;
else {
- link = history->list;
- g_free(link->data);
- history->list = g_list_remove_link(history->list, link);
- g_list_free_1(link);
+ link = command_history_list_first(history);
+ history_list_delete_link_and_destroy(link);
}
- history->list = g_list_append(history->list, g_strdup(text));
+ history_entries = g_list_append(history_entries, history_entry_new(history, text));
}
HISTORY_REC *command_history_find(HISTORY_REC *history)
@@ -87,6 +168,61 @@ HISTORY_REC *command_history_find_name(const char *name)
return NULL;
}
+static int history_entry_after_time_sort(const HISTORY_ENTRY_REC *a, const HISTORY_ENTRY_REC *b)
+{
+ return a->time == b->time ? 1 : a->time - b->time;
+}
+
+void command_history_load_entry(time_t history_time, HISTORY_REC *history, const char *text)
+{
+ HISTORY_ENTRY_REC *entry;
+
+ g_return_if_fail(history != NULL);
+ g_return_if_fail(text != NULL);
+
+ entry = g_new0(HISTORY_ENTRY_REC, 1);
+ entry->text = g_strdup(text);
+ entry->history = history;
+ entry->time = history_time;
+
+ history->lines++;
+
+ history_entries = g_list_insert_sorted(history_entries, entry, (GCompareFunc)history_entry_after_time_sort);
+}
+
+static int history_entry_find_func(const HISTORY_ENTRY_REC *data, const HISTORY_ENTRY_REC *user_data)
+{
+ if ((user_data->time == -1 || (data->time == user_data->time)) &&
+ (user_data->history == NULL || (data->history == user_data->history)) &&
+ g_strcmp0(data->text, user_data->text) == 0) {
+ return 0;
+ } else {
+ return -1;
+ }
+}
+
+gboolean command_history_delete_entry(time_t history_time, HISTORY_REC *history, const char *text)
+{
+ GList *link;
+ HISTORY_ENTRY_REC entry;
+
+ g_return_val_if_fail(history != NULL, FALSE);
+ g_return_val_if_fail(text != NULL, FALSE);
+
+ entry.text = text;
+ entry.history = history;
+ entry.time = history_time;
+
+ link = g_list_find_custom(history_entries, &entry, (GCompareFunc)history_entry_find_func);
+ if (link != NULL) {
+ ((HISTORY_ENTRY_REC *)link->data)->history->lines--;
+ history_list_delete_link_and_destroy(link);
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
HISTORY_REC *command_history_current(WINDOW_REC *window)
{
HISTORY_REC *rec;
@@ -104,32 +240,44 @@ HISTORY_REC *command_history_current(WINDOW_REC *window)
return global_history;
}
-const char *command_history_prev(WINDOW_REC *window, const char *text)
+static const char *command_history_prev_int(WINDOW_REC *window, const char *text, gboolean global)
{
HISTORY_REC *history;
GList *pos;
history = command_history_current(window);
pos = history->pos;
+ history->redo = 0;
if (pos != NULL) {
/* don't go past the first entry (no wrap around) */
- if (history->pos->prev != NULL)
- history->pos = history->pos->prev;
+ GList *prev = command_history_list_prev(global ? NULL : history, history->pos);
+ if (prev != NULL)
+ history->pos = prev;
} else {
- history->pos = g_list_last(history->list);
+ history->pos = command_history_list_last(global ? NULL : history);
}
if (*text != '\0' &&
- (pos == NULL || g_strcmp0(pos->data, text) != 0)) {
+ (pos == NULL || g_strcmp0(((HISTORY_ENTRY_REC *)pos->data)->text, text) != 0)) {
/* save the old entry to history */
command_history_add(history, text);
}
- return history->pos == NULL ? text : history->pos->data;
+ return history->pos == NULL ? text : ((HISTORY_ENTRY_REC *)history->pos->data)->text;
}
-const char *command_history_next(WINDOW_REC *window, const char *text)
+const char *command_history_prev(WINDOW_REC *window, const char *text)
+{
+ return command_history_prev_int(window, text, FALSE);
+}
+
+const char *command_global_history_prev(WINDOW_REC *window, const char *text)
+{
+ return command_history_prev_int(window, text, TRUE);
+}
+
+static const char *command_history_next_int(WINDOW_REC *window, const char *text, gboolean global)
{
HISTORY_REC *history;
GList *pos;
@@ -137,15 +285,43 @@ const char *command_history_next(WINDOW_REC *window, const char *text)
history = command_history_current(window);
pos = history->pos;
- if (pos != NULL)
- history->pos = history->pos->next;
+ if (!(history->redo) && pos != NULL)
+ history->pos = command_history_list_next(global ? NULL : history, history->pos);
+ history->redo = 0;
if (*text != '\0' &&
- (pos == NULL || g_strcmp0(pos->data, text) != 0)) {
+ (pos == NULL || g_strcmp0(((HISTORY_ENTRY_REC *)pos->data)->text, text) != 0)) {
/* save the old entry to history */
command_history_add(history, text);
}
- return history->pos == NULL ? "" : history->pos->data;
+ return history->pos == NULL ? "" : ((HISTORY_ENTRY_REC *)history->pos->data)->text;
+}
+
+const char *command_history_next(WINDOW_REC *window, const char *text)
+{
+ return command_history_next_int(window, text, FALSE);
+}
+
+const char *command_global_history_next(WINDOW_REC *window, const char *text)
+{
+ return command_history_next_int(window, text, TRUE);
+}
+
+const char *command_history_delete_current(WINDOW_REC *window, const char *text)
+{
+ HISTORY_REC *history;
+ GList *pos;
+
+ history = command_history_current(window);
+ pos = history->pos;
+
+ if (pos != NULL && g_strcmp0(((HISTORY_ENTRY_REC *)pos->data)->text, text) == 0) {
+ ((HISTORY_ENTRY_REC *)pos->data)->history->lines--;
+ history_list_delete_link_and_destroy(pos);
+ }
+
+ history->redo = 0;
+ return history->pos == NULL ? "" : ((HISTORY_ENTRY_REC *)history->pos->data)->text;
}
void command_history_clear_pos_func(HISTORY_REC *history, gpointer user_data)
@@ -175,12 +351,17 @@ HISTORY_REC *command_history_create(const char *name)
void command_history_clear(HISTORY_REC *history)
{
+ GList *link, *next;
+
g_return_if_fail(history != NULL);
command_history_clear_pos_func(history, NULL);
- g_list_foreach(history->list, (GFunc) g_free, NULL);
- g_list_free(history->list);
- history->list = NULL;
+ link = command_history_list_first(history);
+ while (link != NULL) {
+ next = command_history_list_next(history, link);
+ history_list_delete_link_and_destroy(link);
+ link = next;
+ }
history->lines = 0;
}
@@ -264,8 +445,8 @@ static char *special_history_func(const char *text, void *item, int *free_ret)
ret = NULL;
history = command_history_current(window);
- for (tmp = history->list; tmp != NULL; tmp = tmp->next) {
- const char *line = tmp->data;
+ for (tmp = command_history_list_first(history); tmp != NULL; tmp = command_history_list_next(history, tmp)) {
+ const char *line = ((HISTORY_ENTRY_REC *)tmp->data)->text;
if (match_wildcards(findtext, line)) {
*free_ret = TRUE;
@@ -289,6 +470,8 @@ void command_history_init(void)
special_history_func_set(special_history_func);
+ history_entries = NULL;
+
global_history = command_history_create(NULL);
read_settings();
@@ -308,4 +491,6 @@ void command_history_deinit(void)
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
command_history_destroy(global_history);
+
+ g_list_free_full(history_entries, (GDestroyNotify) history_entry_destroy);
}
diff --git a/src/fe-common/core/command-history.h b/src/fe-common/core/command-history.h
index 45126092..ed093415 100644
--- a/src/fe-common/core/command-history.h
+++ b/src/fe-common/core/command-history.h
@@ -6,12 +6,19 @@
typedef struct {
char *name;
- GList *list, *pos;
+ GList *pos;
int lines;
int refcount;
+ int redo:1;
} HISTORY_REC;
+typedef struct {
+ const char *text;
+ HISTORY_REC *history;
+ time_t time;
+} HISTORY_ENTRY_REC;
+
HISTORY_REC *command_history_find(HISTORY_REC *history);
HISTORY_REC *command_history_find_name(const char *name);
@@ -21,9 +28,19 @@ void command_history_init(void);
void command_history_deinit(void);
void command_history_add(HISTORY_REC *history, const char *text);
+void command_history_load_entry(time_t time, HISTORY_REC *history, const char *text);
+gboolean command_history_delete_entry(time_t history_time, HISTORY_REC *history, const char *text);
+
+GList *command_history_list_last(HISTORY_REC *history);
+GList *command_history_list_first(HISTORY_REC *history);
+GList *command_history_list_prev(HISTORY_REC *history, GList *pos);
+GList *command_history_list_next(HISTORY_REC *history, GList *pos);
const char *command_history_prev(WINDOW_REC *window, const char *text);
const char *command_history_next(WINDOW_REC *window, const char *text);
+const char *command_global_history_prev(WINDOW_REC *window, const char *text);
+const char *command_global_history_next(WINDOW_REC *window, const char *text);
+const char *command_history_delete_current(WINDOW_REC *window, const char *text);
void command_history_clear_pos(WINDOW_REC *window);
diff --git a/src/fe-common/core/completion.c b/src/fe-common/core/completion.c
index a97adc21..fd452e5c 100644
--- a/src/fe-common/core/completion.c
+++ b/src/fe-common/core/completion.c
@@ -137,8 +137,9 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i
int old_startpos, old_wordlen;
GString *result;
- char *word, *wordstart, *linestart, *ret;
- int continue_complete, want_space;
+ const char *cmdchars;
+ char *word, *wordstart, *linestart, *ret, *data;
+ int continue_complete, want_space, expand_escapes;
g_return_val_if_fail(line != NULL, NULL);
g_return_val_if_fail(pos != NULL, NULL);
@@ -186,12 +187,18 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i
char *old;
old = linestart;
- linestart = *linestart == '\0' ?
- g_strdup(word) :
- g_strdup_printf("%s%c%s",
- /* do not accidentally duplicate the word separator */
- line == wordstart - 1 ? "" : linestart,
- old_wordstart[-1], word);
+ /* we want to move word into linestart */
+ if (*linestart == '\0') {
+ linestart = g_strdup(word);
+ } else {
+ GString *str = g_string_new(linestart);
+ if (old_wordstart[-1] != str->str[str->len - 1]) {
+ /* do not accidentally duplicate the word separator */
+ g_string_append_c(str, old_wordstart[-1]);
+ }
+ g_string_append(str, word);
+ linestart = g_string_free(str, FALSE);
+ }
g_free(old);
g_free(word);
@@ -241,14 +248,24 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i
if (complist == NULL)
return NULL;
+ /* get the cmd char */
+ cmdchars = settings_get_str("cmdchars");
+
+ /* get the expand_escapes setting */
+ expand_escapes = settings_get_bool("expand_escapes");
+
+ /* escape if the word doesn't begin with '/' and expand_escapes are turned on */
+ data = strchr(cmdchars, *line) == NULL && expand_escapes ?
+ escape_string(complist->data) : g_strdup(complist->data);
+
/* word completed */
- *pos = startpos+strlen(complist->data);
+ *pos = startpos + strlen(data);
/* replace the word in line - we need to return
a full new line */
result = g_string_new(line);
g_string_erase(result, startpos, wordlen);
- g_string_insert(result, startpos, complist->data);
+ g_string_insert(result, startpos, data);
if (want_space) {
if (!isseparator(result->str[*pos]))
@@ -256,13 +273,17 @@ char *word_complete(WINDOW_REC *window, const char *line, int *pos, int erase, i
(*pos)++;
}
- wordlen = strlen(complist->data);
+ wordlen = strlen(data);
last_line_pos = *pos;
g_free_not_null(last_line);
last_line = g_strdup(result->str);
ret = result->str;
g_string_free(result, FALSE);
+
+ /* free the data */
+ g_free(data);
+
return ret;
}
@@ -306,6 +327,10 @@ GList *filename_complete(const char *path, const char *default_path)
g_return_val_if_fail(path != NULL, NULL);
+ if (path[0] == '\0') {
+ return NULL;
+ }
+
list = NULL;
/* get directory part of the path - expand ~/ */
@@ -335,7 +360,14 @@ GList *filename_complete(const char *path, const char *default_path)
g_free_and_null(dir);
}
- basename = g_path_get_basename(path);
+ len = strlen(path);
+ /* g_path_get_basename() returns the component before the last slash if
+ * the path ends with a directory separator, that's not what we want */
+ if (len > 0 && path[len - 1] == G_DIR_SEPARATOR) {
+ basename = g_strdup("");
+ } else {
+ basename = g_path_get_basename(path);
+ }
len = strlen(basename);
/* add all files in directory to completion list */
diff --git a/src/fe-common/core/fe-capsicum.c b/src/fe-common/core/fe-capsicum.c
new file mode 100644
index 00000000..54a43d27
--- /dev/null
+++ b/src/fe-common/core/fe-capsicum.c
@@ -0,0 +1,63 @@
+/*
+ fe-capsicum.c : irssi
+
+ Copyright (C) 2017 Edward Tomasz Napierala <trasz@FreeBSD.org>
+
+ This software was developed by SRI International and the University of
+ Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
+ ("CTSRD"), as part of the DARPA CRASH research programme.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "module.h"
+#include "fe-capsicum.h"
+#include "levels.h"
+#include "module-formats.h"
+#include "printtext.h"
+#include "signals.h"
+
+static void capability_mode_enabled(void)
+{
+
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CAPSICUM_ENABLED);
+}
+
+static void capability_mode_disabled(void)
+{
+
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CAPSICUM_DISABLED);
+}
+
+static void capability_mode_failed(gchar *msg)
+{
+
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_CAPSICUM_FAILED, msg);
+}
+
+void fe_capsicum_init(void)
+{
+
+ signal_add("capability mode enabled", (SIGNAL_FUNC) capability_mode_enabled);
+ signal_add("capability mode disabled", (SIGNAL_FUNC) capability_mode_disabled);
+ signal_add("capability mode failed", (SIGNAL_FUNC) capability_mode_failed);
+}
+
+void fe_capsicum_deinit(void)
+{
+ signal_remove("capability mode enabled", (SIGNAL_FUNC) capability_mode_enabled);
+ signal_remove("capability mode disabled", (SIGNAL_FUNC) capability_mode_disabled);
+ signal_remove("capability mode failed", (SIGNAL_FUNC) capability_mode_failed);
+}
diff --git a/src/fe-common/core/fe-capsicum.h b/src/fe-common/core/fe-capsicum.h
new file mode 100644
index 00000000..a7cb743b
--- /dev/null
+++ b/src/fe-common/core/fe-capsicum.h
@@ -0,0 +1,7 @@
+#ifndef __FE_CAPSICUM_H
+#define __FE_CAPSICUM_H
+
+void fe_capsicum_init(void);
+void fe_capsicum_deinit(void);
+
+#endif
diff --git a/src/fe-common/core/fe-channels.c b/src/fe-common/core/fe-channels.c
index 8e434ab5..5cad51a7 100644
--- a/src/fe-common/core/fe-channels.c
+++ b/src/fe-common/core/fe-channels.c
@@ -278,9 +278,9 @@ static void cmd_channel_add_modify(const char *data, gboolean add)
rec = channel_setup_find(channel, chatnet);
if (rec == NULL) {
if (add == FALSE) {
- cmd_params_free(free_arg);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_CHANSETUP_NOT_FOUND, channel, chatnet);
+ cmd_params_free(free_arg);
return;
}
diff --git a/src/fe-common/core/fe-common-core.c b/src/fe-common/core/fe-common-core.c
index 791f56d4..209c2d9e 100644
--- a/src/fe-common/core/fe-common-core.c
+++ b/src/fe-common/core/fe-common-core.c
@@ -32,6 +32,9 @@
#include "special-vars.h"
#include "fe-core-commands.h"
#include "fe-queries.h"
+#ifdef HAVE_CAPSICUM
+#include "fe-capsicum.h"
+#endif
#include "hilight-text.h"
#include "command-history.h"
#include "completion.h"
@@ -179,6 +182,9 @@ void fe_common_core_init(void)
fe_server_init();
fe_settings_init();
fe_tls_init();
+#ifdef HAVE_CAPSICUM
+ fe_capsicum_init();
+#endif
windows_init();
window_activity_init();
window_commands_init();
@@ -221,6 +227,9 @@ void fe_common_core_deinit(void)
fe_server_deinit();
fe_settings_deinit();
fe_tls_deinit();
+#ifdef HAVE_CAPSICUM
+ fe_capsicum_deinit();
+#endif
windows_deinit();
window_activity_deinit();
window_commands_deinit();
diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c
index 97a246ec..fb98cc25 100644
--- a/src/fe-common/core/fe-core-commands.c
+++ b/src/fe-common/core/fe-core-commands.c
@@ -28,6 +28,9 @@
#include "settings.h"
#include "irssi-version.h"
#include "servers.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "fe-windows.h"
#include "printtext.h"
@@ -120,6 +123,9 @@ static void cmd_cat(const char *data)
GIOChannel *handle;
GString *buf;
gsize tpos;
+#ifdef HAVE_CAPSICUM
+ int fd;
+#endif
if (!cmd_get_params(data, &free_arg, 2, &fname, &fposstr))
return;
@@ -128,7 +134,15 @@ static void cmd_cat(const char *data)
fpos = atoi(fposstr);
cmd_params_free(free_arg);
+#ifdef HAVE_CAPSICUM
+ fd = capsicum_open_wrapper(fname, O_RDONLY, 0);
+ if (fd > 0)
+ handle = g_io_channel_unix_new(fd);
+ else
+ handle = NULL;
+#else
handle = g_io_channel_new_file(fname, "r", NULL);
+#endif
g_free(fname);
if (handle == NULL) {
diff --git a/src/fe-common/core/fe-exec.c b/src/fe-common/core/fe-exec.c
index 36990866..c1739d39 100644
--- a/src/fe-common/core/fe-exec.c
+++ b/src/fe-common/core/fe-exec.c
@@ -613,7 +613,7 @@ static void sig_exec_input(PROCESS_REC *rec, const char *text)
str = g_strconcat(rec->target_nick ? "-nick " :
rec->target_channel ? "-channel " : "",
- rec->target, " ", text, NULL);
+ rec->target, " ", *text == '\0' ? " " : text, NULL);
signal_emit(rec->notice ? "command notice" : "command msg",
3, str, server, item);
g_free(str);
diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c
index 800e881d..03fd4dd2 100644
--- a/src/fe-common/core/fe-ignore.c
+++ b/src/fe-common/core/fe-ignore.c
@@ -58,13 +58,8 @@ static void ignore_print(int index, IGNORE_REC *rec)
g_string_append(options, "-regexp ");
if (rec->pattern == NULL)
g_string_append(options, "[INVALID! -pattern missing] ");
-#ifdef USE_GREGEX
else if (rec->preg == NULL)
g_string_append(options, "[INVALID!] ");
-#else
- else if (!rec->regexp_compiled)
- g_string_append(options, "[INVALID!] ");
-#endif
}
if (rec->fullword) g_string_append(options, "-full ");
if (rec->replies) g_string_append(options, "-replies ");
diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c
index 5bc5c4e1..0fed8642 100644
--- a/src/fe-common/core/fe-log.c
+++ b/src/fe-common/core/fe-log.c
@@ -30,6 +30,9 @@
#include "special-vars.h"
#include "settings.h"
#include "lib-config/iconfig.h"
+#ifdef HAVE_CAPSICUM
+#include "capsicum.h"
+#endif
#include "fe-windows.h"
#include "window-items.h"
@@ -49,8 +52,6 @@ static THEME_REC *log_theme;
static int skip_next_printtext;
static char *log_theme_name;
-static int log_dir_create_mode;
-
static char **autolog_ignore_targets;
static char *log_colorizer_strip(const char *str)
@@ -453,7 +454,11 @@ static void autolog_open(SERVER_REC *server, const char *server_tag,
log_item_add(log, LOG_ITEM_TARGET, target, server_tag);
dir = g_path_get_dirname(log->real_fname);
+#ifdef HAVE_CAPSICUM
+ capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
+#else
g_mkdir_with_parents(dir, log_dir_create_mode);
+#endif
g_free(dir);
log->temp = TRUE;
@@ -676,7 +681,6 @@ static void sig_theme_destroyed(THEME_REC *theme)
static void read_settings(void)
{
int old_autolog = autolog_level;
- int log_file_create_mode;
g_free_not_null(autolog_path);
autolog_path = g_strdup(settings_get_str("autolog_path"));
@@ -704,12 +708,6 @@ static void read_settings(void)
log_theme = log_theme_name == NULL ? NULL :
theme_load(log_theme_name);
- log_file_create_mode = octal2dec(settings_get_int("log_create_mode"));
- log_dir_create_mode = log_file_create_mode;
- if (log_file_create_mode & 0400) log_dir_create_mode |= 0100;
- if (log_file_create_mode & 0040) log_dir_create_mode |= 0010;
- if (log_file_create_mode & 0004) log_dir_create_mode |= 0001;
-
if (autolog_ignore_targets != NULL)
g_strfreev(autolog_ignore_targets);
diff --git a/src/fe-common/core/fe-server.c b/src/fe-common/core/fe-server.c
index f4c1d3ee..074a83f3 100644
--- a/src/fe-common/core/fe-server.c
+++ b/src/fe-common/core/fe-server.c
@@ -117,7 +117,18 @@ static void cmd_server_add_modify(const char *data, gboolean add)
return;
if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
- port = *portstr == '\0' ? DEFAULT_SERVER_ADD_PORT : atoi(portstr);
+
+ value = g_hash_table_lookup(optlist, "port");
+
+ if (*portstr != '\0')
+ port = atoi(portstr);
+ else if (value != NULL && *value != '\0')
+ port = atoi(value);
+ else if (g_hash_table_lookup(optlist, "tls") ||
+ g_hash_table_lookup(optlist, "ssl"))
+ port = DEFAULT_SERVER_ADD_TLS_PORT;
+ else
+ port = DEFAULT_SERVER_ADD_PORT;
chatnet = g_hash_table_lookup(optlist, "network");
@@ -125,9 +136,9 @@ static void cmd_server_add_modify(const char *data, gboolean add)
if (rec == NULL) {
if (add == FALSE) {
- cmd_params_free(free_arg);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
TXT_SETUPSERVER_NOT_FOUND, addr, port);
+ cmd_params_free(free_arg);
return;
}
@@ -139,8 +150,8 @@ static void cmd_server_add_modify(const char *data, gboolean add)
rec->address = g_strdup(addr);
rec->port = port;
} else {
- value = g_hash_table_lookup(optlist, "port");
- if (value != NULL && *value != '\0') rec->port = atoi(value);
+ if (*portstr != '\0' || g_hash_table_lookup(optlist, "port"))
+ rec->port = port;
if (*password != '\0') g_free_and_null(rec->password);
if (g_hash_table_lookup(optlist, "host")) {
@@ -154,8 +165,14 @@ static void cmd_server_add_modify(const char *data, gboolean add)
else if (g_hash_table_lookup(optlist, "4"))
rec->family = AF_INET;
- if (g_hash_table_lookup(optlist, "tls") || g_hash_table_lookup(optlist, "ssl"))
+ if (g_hash_table_lookup(optlist, "tls") || g_hash_table_lookup(optlist, "ssl")) {
rec->use_tls = TRUE;
+ }
+ else if (g_hash_table_lookup(optlist, "notls") || g_hash_table_lookup(optlist, "nossl")) {
+ rec->use_tls = FALSE;
+ /* tls_verify implies use_tls, disable it explicitly */
+ rec->tls_verify = FALSE;
+ }
value = g_hash_table_lookup(optlist, "tls_cert");
if (value == NULL)
@@ -177,6 +194,8 @@ static void cmd_server_add_modify(const char *data, gboolean add)
if (g_hash_table_lookup(optlist, "tls_verify") || g_hash_table_lookup(optlist, "ssl_verify"))
rec->tls_verify = TRUE;
+ else if (g_hash_table_lookup(optlist, "notls_verify") || g_hash_table_lookup(optlist, "nossl_verify"))
+ rec->tls_verify = FALSE;
value = g_hash_table_lookup(optlist, "tls_cafile");
if (value == NULL)
@@ -434,8 +453,8 @@ void fe_server_init(void)
command_bind_first("server", NULL, (SIGNAL_FUNC) server_command);
command_bind_first("disconnect", NULL, (SIGNAL_FUNC) server_command);
- command_set_options("server add", "4 6 !! ssl +ssl_cert +ssl_pkey +ssl_pass ssl_verify +ssl_cafile +ssl_capath +ssl_ciphers +ssl_fingerprint tls +tls_cert +tls_pkey +tls_pass tls_verify +tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert +tls_pinned_pubkey auto noauto proxy noproxy -host -port noautosendcmd");
- command_set_options("server modify", "4 6 !! ssl +ssl_cert +ssl_pkey +ssl_pass ssl_verify +ssl_cafile +ssl_capath +ssl_ciphers +ssl_fingerprint tls +tls_cert +tls_pkey +tls_pass tls_verify +tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert +tls_pinned_pubkey auto noauto proxy noproxy -host -port noautosendcmd");
+ command_set_options("server add", "4 6 !! ssl nossl +ssl_cert +ssl_pkey +ssl_pass ssl_verify nossl_verify +ssl_cafile +ssl_capath +ssl_ciphers +ssl_fingerprint tls notls +tls_cert +tls_pkey +tls_pass tls_verify notls_verify +tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert +tls_pinned_pubkey auto noauto proxy noproxy -host -port noautosendcmd");
+ command_set_options("server modify", "4 6 !! ssl nossl +ssl_cert +ssl_pkey +ssl_pass ssl_verify nossl_verify +ssl_cafile +ssl_capath +ssl_ciphers +ssl_fingerprint tls notls +tls_cert +tls_pkey +tls_pass tls_verify notls_verify +tls_cafile +tls_capath +tls_ciphers +tls_pinned_cert +tls_pinned_pubkey auto noauto proxy noproxy -host -port noautosendcmd");
signal_add("server looking", (SIGNAL_FUNC) sig_server_looking);
signal_add("server connecting", (SIGNAL_FUNC) sig_server_connecting);
diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c
index abbd45a8..de9f67a1 100644
--- a/src/fe-common/core/fe-settings.c
+++ b/src/fe-common/core/fe-settings.c
@@ -26,7 +26,7 @@
#include "misc.h"
#include "lib-config/iconfig.h"
#include "settings.h"
-
+#include "fe-settings.h"
#include "levels.h"
#include "printtext.h"
#include "keyboard.h"
@@ -41,6 +41,11 @@ static void set_print(SETTINGS_REC *rec)
g_free(value);
}
+void fe_settings_set_print(const char *key)
+{
+ set_print(settings_get_record(key));
+}
+
static void set_print_pattern(const char *pattern)
{
GSList *sets, *tmp;
diff --git a/src/fe-common/core/fe-settings.h b/src/fe-common/core/fe-settings.h
new file mode 100644
index 00000000..dd33f223
--- /dev/null
+++ b/src/fe-common/core/fe-settings.h
@@ -0,0 +1,6 @@
+#ifndef __FE_CHANNELS_H
+#define __FE_CHANNELS_H
+
+void fe_settings_set_print(const char *key);
+
+#endif
diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c
index 0afa2914..93f2e3f3 100644
--- a/src/fe-common/core/fe-windows.c
+++ b/src/fe-common/core/fe-windows.c
@@ -563,8 +563,10 @@ GSList *windows_get_sorted(void)
begin = windows_seq_begin();
while (iter != begin) {
+ WINDOW_REC *rec;
+
iter = g_sequence_iter_prev(iter);
- WINDOW_REC *rec = g_sequence_get(iter);
+ rec = g_sequence_get(iter);
sorted = g_slist_prepend(sorted, rec);
}
diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c
index 17c13a97..37db6f7c 100644
--- a/src/fe-common/core/formats.c
+++ b/src/fe-common/core/formats.c
@@ -33,6 +33,7 @@
#include "themes.h"
#include "recode.h"
#include "utf8.h"
+#include "misc.h"
static const char *format_backs = "04261537";
static const char *format_fores = "kbgcrmyw";
@@ -870,8 +871,9 @@ static const char *get_ansi_color(THEME_REC *theme, const char *str,
{
static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
const char *start;
- int fg, bg, flags, num, i;
- unsigned int num2;
+ char *endptr;
+ int fg, bg, flags, i;
+ guint num, num2;
if (*str != '[')
return str;
@@ -886,8 +888,10 @@ static const char *get_ansi_color(THEME_REC *theme, const char *str,
if (*str == '\0') return start;
if (i_isdigit(*str)) {
- num = num*10 + (*str-'0');
- continue;
+ if (!parse_uint(str, &endptr, 10, &num)) {
+ return start;
+ }
+ str = endptr;
}
if (*str != ';' && *str != 'm')
@@ -958,8 +962,12 @@ static const char *get_ansi_color(THEME_REC *theme, const char *str,
/* ANSI indexed color or RGB color */
if (*str != ';') break;
str++;
- for (num2 = 0; i_isdigit(*str); str++)
- num2 = num2*10 + (*str-'0');
+
+ if (!parse_uint(str, &endptr, 10, &num2)) {
+ return start;
+ }
+ str = endptr;
+
if (*str == '\0') return start;
switch (num2) {
@@ -1006,8 +1014,12 @@ static const char *get_ansi_color(THEME_REC *theme, const char *str,
/* indexed */
if (*str != ';') break;
str++;
- for (num2 = 0; i_isdigit(*str); str++)
- num2 = num2*10 + (*str-'0');
+
+ if (!parse_uint(str, &endptr, 10, &num2)) {
+ return start;
+ }
+ str = endptr;
+
if (*str == '\0') return start;
if (num == 38) {
@@ -1060,31 +1072,27 @@ static void get_mirc_color(const char **str, int *fg_ret, int *bg_ret)
fg = fg_ret == NULL ? -1 : *fg_ret;
bg = bg_ret == NULL ? -1 : *bg_ret;
- if (!i_isdigit(**str) && **str != ',') {
+ if (!i_isdigit(**str)) {
+ /* turn off color */
fg = -1;
bg = -1;
} else {
/* foreground color */
- if (**str != ',') {
- fg = **str-'0';
+ fg = **str-'0';
+ (*str)++;
+ if (i_isdigit(**str)) {
+ fg = fg*10 + (**str-'0');
(*str)++;
- if (i_isdigit(**str)) {
- fg = fg*10 + (**str-'0');
- (*str)++;
- }
}
- if (**str == ',') {
+
+ if ((*str)[0] == ',' && i_isdigit((*str)[1])) {
/* background color */
- if (!i_isdigit((*str)[1]))
- bg = -1;
- else {
- (*str)++;
- bg = **str-'0';
+ (*str)++;
+ bg = **str-'0';
+ (*str)++;
+ if (i_isdigit(**str)) {
+ bg = bg*10 + (**str-'0');
(*str)++;
- if (i_isdigit(**str)) {
- bg = bg*10 + (**str-'0');
- (*str)++;
- }
}
}
}
diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c
index dd38be87..b9912457 100644
--- a/src/fe-common/core/hilight-text.c
+++ b/src/fe-common/core/hilight-text.c
@@ -26,6 +26,7 @@
#include "misc.h"
#include "lib-config/iconfig.h"
#include "settings.h"
+#include "iregex.h"
#include "servers.h"
#include "channels.h"
@@ -101,14 +102,11 @@ static void hilight_destroy(HILIGHT_REC *rec)
{
g_return_if_fail(rec != NULL);
-#ifdef USE_GREGEX
- if (rec->preg != NULL) g_regex_unref(rec->preg);
-#else
- if (rec->regexp_compiled) regfree(&rec->preg);
-#endif
+ if (rec->preg != NULL) i_regex_unref(rec->preg);
if (rec->channels != NULL) g_strfreev(rec->channels);
g_free_not_null(rec->color);
g_free_not_null(rec->act_color);
+ g_free_not_null(rec->servertag);
g_free(rec->text);
g_free(rec);
}
@@ -122,19 +120,10 @@ static void hilights_destroy_all(void)
static void hilight_init_rec(HILIGHT_REC *rec)
{
-#ifdef USE_GREGEX
if (rec->preg != NULL)
- g_regex_unref(rec->preg);
+ i_regex_unref(rec->preg);
- rec->preg = g_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, NULL);
-#else
- if (rec->regexp_compiled) regfree(&rec->preg);
- if (!rec->regexp)
- rec->regexp_compiled = FALSE;
- else
- rec->regexp_compiled = regcomp(&rec->preg, rec->text,
- rec->case_sensitive ? REG_EXTENDED : (REG_EXTENDED|REG_ICASE)) == 0;
-#endif
+ rec->preg = i_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_CASELESS, 0, NULL);
}
void hilight_create(HILIGHT_REC *rec)
@@ -207,30 +196,15 @@ static gboolean hilight_match_text(HILIGHT_REC *rec, const char *text,
gboolean ret = FALSE;
if (rec->regexp) {
-#ifdef USE_GREGEX
if (rec->preg != NULL) {
- GMatchInfo *match;
-
- g_regex_match (rec->preg, text, 0, &match);
+ MatchInfo *match;
+ i_regex_match(rec->preg, text, 0, &match);
- if (g_match_info_matches(match))
- ret = g_match_info_fetch_pos(match, 0, match_beg, match_end);
+ if (i_match_info_matches(match))
+ ret = i_match_info_fetch_pos(match, 0, match_beg, match_end);
- g_match_info_free(match);
- }
-#else
- regmatch_t rmatch[1];
-
- if (rec->regexp_compiled &&
- regexec(&rec->preg, text, 1, rmatch, 0) == 0) {
- if (rmatch[0].rm_so > 0 &&
- match_beg != NULL && match_end != NULL) {
- *match_beg = rmatch[0].rm_so;
- *match_end = rmatch[0].rm_eo;
- }
- ret = TRUE;
+ i_match_info_free(match);
}
-#endif
} else {
char *match;
@@ -451,7 +425,7 @@ static void read_hilight_config(void)
CONFIG_NODE *node;
HILIGHT_REC *rec;
GSList *tmp;
- char *text, *color;
+ char *text, *color, *servertag;
hilights_destroy_all();
@@ -494,7 +468,9 @@ static void read_hilight_config(void)
rec->nickmask = config_node_get_bool(node, "mask", FALSE);
rec->fullword = config_node_get_bool(node, "fullword", FALSE);
rec->regexp = config_node_get_bool(node, "regexp", FALSE);
- rec->servertag = config_node_get_str(node, "servertag", NULL);
+ servertag = config_node_get_str(node, "servertag", NULL);
+ rec->servertag = servertag == NULL || *servertag == '\0' ? NULL :
+ g_strdup(servertag);
hilight_init_rec(rec);
node = iconfig_node_section(node, "channels", -1);
@@ -524,13 +500,8 @@ static void hilight_print(int index, HILIGHT_REC *rec)
if (rec->case_sensitive) g_string_append(options, "-matchcase ");
if (rec->regexp) {
g_string_append(options, "-regexp ");
-#ifdef USE_GREGEX
if (rec->preg == NULL)
g_string_append(options, "[INVALID!] ");
-#else
- if (!rec->regexp_compiled)
- g_string_append(options, "[INVALID!] ");
-#endif
}
if (rec->priority != 0)
diff --git a/src/fe-common/core/hilight-text.h b/src/fe-common/core/hilight-text.h
index 76beec1f..1d942f29 100644
--- a/src/fe-common/core/hilight-text.h
+++ b/src/fe-common/core/hilight-text.h
@@ -1,10 +1,7 @@
#ifndef __HILIGHT_TEXT_H
#define __HILIGHT_TEXT_H
-#ifndef USE_GREGEX
-# include <regex.h>
-#endif
-
+#include "iregex.h"
#include "formats.h"
struct _HILIGHT_REC {
@@ -24,12 +21,7 @@ struct _HILIGHT_REC {
unsigned int fullword:1; /* match `text' only for full words */
unsigned int regexp:1; /* `text' is a regular expression */
unsigned int case_sensitive:1;/* `text' must match case */
-#ifdef USE_GREGEX
- GRegex *preg;
-#else
- unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */
- regex_t preg;
-#endif
+ Regex *preg;
char *servertag;
};
diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c
index da9705be..eb0ddb61 100644
--- a/src/fe-common/core/module-formats.c
+++ b/src/fe-common/core/module-formats.c
@@ -290,6 +290,9 @@ FORMAT_REC fecommon_core_formats[] = {
{ "completion_header", "%#Key Value Auto", 0 },
{ "completion_line", "%#$[10]0 $[!40]1 $2", 3, { 0, 0, 0 } },
{ "completion_footer", "", 0 },
+ { "capsicum_enabled", "Capability mode enabled", 0 },
+ { "capsicum_disabled", "Capability mode not enabled", 0 },
+ { "capsicum_failed", "Capability mode failed: $0", 1, { 0 } },
/* ---- */
{ NULL, "TLS", 0 },
diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h
index a9ed28c5..97ac60bb 100644
--- a/src/fe-common/core/module-formats.h
+++ b/src/fe-common/core/module-formats.h
@@ -12,21 +12,21 @@ enum {
TXT_DAYCHANGE,
TXT_TALKING_WITH,
TXT_REFNUM_TOO_LOW,
- TXT_ERROR_SERVER_STICKY,
- TXT_SET_SERVER_STICKY,
+ TXT_ERROR_SERVER_STICKY,
+ TXT_SET_SERVER_STICKY,
TXT_UNSET_SERVER_STICKY,
- TXT_WINDOW_NAME_NOT_UNIQUE,
- TXT_WINDOW_LEVEL,
- TXT_WINDOW_SET_IMMORTAL,
- TXT_WINDOW_UNSET_IMMORTAL,
- TXT_WINDOW_IMMORTAL_ERROR,
+ TXT_WINDOW_NAME_NOT_UNIQUE,
+ TXT_WINDOW_LEVEL,
+ TXT_WINDOW_SET_IMMORTAL,
+ TXT_WINDOW_UNSET_IMMORTAL,
+ TXT_WINDOW_IMMORTAL_ERROR,
TXT_WINDOWLIST_HEADER,
TXT_WINDOWLIST_LINE,
TXT_WINDOWLIST_FOOTER,
TXT_WINDOWS_LAYOUT_SAVED,
TXT_WINDOWS_LAYOUT_RESET,
- TXT_WINDOW_INFO_HEADER,
- TXT_WINDOW_INFO_FOOTER,
+ TXT_WINDOW_INFO_HEADER,
+ TXT_WINDOW_INFO_FOOTER,
TXT_WINDOW_INFO_REFNUM,
TXT_WINDOW_INFO_REFNUM_STICKY,
TXT_WINDOW_INFO_NAME,
@@ -34,22 +34,22 @@ enum {
TXT_WINDOW_INFO_IMMORTAL,
TXT_WINDOW_INFO_SIZE,
TXT_WINDOW_INFO_LEVEL,
- TXT_WINDOW_INFO_SERVER,
+ TXT_WINDOW_INFO_SERVER,
TXT_WINDOW_INFO_SERVER_STICKY,
- TXT_WINDOW_INFO_THEME,
+ TXT_WINDOW_INFO_THEME,
TXT_WINDOW_INFO_BOUND_ITEMS_HEADER,
TXT_WINDOW_INFO_BOUND_ITEM,
TXT_WINDOW_INFO_BOUND_ITEMS_FOOTER,
TXT_WINDOW_INFO_ITEMS_HEADER,
TXT_WINDOW_INFO_ITEM,
- TXT_WINDOW_INFO_ITEMS_FOOTER,
+ TXT_WINDOW_INFO_ITEMS_FOOTER,
TXT_FILL_2,
TXT_LOOKING_UP,
TXT_CONNECTING,
- TXT_RECONNECTING,
- TXT_CONNECTION_ESTABLISHED,
+ TXT_RECONNECTING,
+ TXT_CONNECTION_ESTABLISHED,
TXT_CANT_CONNECT,
TXT_CONNECTION_LOST,
TXT_LAG_DISCONNECTED,
@@ -100,7 +100,7 @@ enum {
TXT_CHANSETUP_LINE,
TXT_CHANSETUP_FOOTER,
- TXT_FILL_4,
+ TXT_FILL_4,
TXT_OWN_MSG,
TXT_OWN_MSG_CHANNEL,
@@ -162,7 +162,7 @@ enum {
TXT_MODULE_HEADER,
TXT_MODULE_LINE,
- TXT_MODULE_FOOTER,
+ TXT_MODULE_FOOTER,
TXT_MODULE_ALREADY_LOADED,
TXT_MODULE_NOT_LOADED,
TXT_MODULE_LOAD_ERROR,
@@ -183,7 +183,7 @@ enum {
TXT_NOT_JOINED,
TXT_CHAN_NOT_FOUND,
TXT_CHAN_NOT_SYNCED,
- TXT_ILLEGAL_PROTO,
+ TXT_ILLEGAL_PROTO,
TXT_NOT_GOOD_IDEA,
TXT_INVALID_NUMBER,
TXT_INVALID_TIME,
@@ -232,8 +232,8 @@ enum {
TXT_FILL_14,
- TXT_UNKNOWN_CHAT_PROTOCOL,
- TXT_UNKNOWN_CHATNET,
+ TXT_UNKNOWN_CHAT_PROTOCOL,
+ TXT_UNKNOWN_CHATNET,
TXT_NOT_TOGGLE,
TXT_PERL_ERROR,
TXT_BIND_HEADER,
@@ -245,16 +245,19 @@ enum {
TXT_CONFIG_RELOADED,
TXT_CONFIG_MODIFIED,
TXT_GLIB_ERROR,
- TXT_OVERWRITE_CONFIG,
- TXT_SET_TITLE,
- TXT_SET_ITEM,
- TXT_SET_UNKNOWN,
+ TXT_OVERWRITE_CONFIG,
+ TXT_SET_TITLE,
+ TXT_SET_ITEM,
+ TXT_SET_UNKNOWN,
TXT_SET_NOT_BOOLEAN,
TXT_NO_COMPLETIONS,
- TXT_COMPLETION_REMOVED,
+ TXT_COMPLETION_REMOVED,
TXT_COMPLETION_HEADER,
- TXT_COMPLETION_LINE,
+ TXT_COMPLETION_LINE,
TXT_COMPLETION_FOOTER,
+ TXT_CAPSICUM_ENABLED,
+ TXT_CAPSICUM_DISABLED,
+ TXT_CAPSICUM_FAILED,
TLS_FILL_15,
diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c
index 2b1459be..cb1cce8f 100644
--- a/src/fe-common/core/themes.c
+++ b/src/fe-common/core/themes.c
@@ -587,7 +587,7 @@ static char *theme_format_compress_colors(THEME_REC *theme, const char *format)
/* a normal character */
g_string_append_c(str, *format);
format++;
- } else {
+ } else if (format[1] != '\0') {
/* %format */
format++;
if (IS_OLD_FORMAT(*format, last_fg, last_bg)) {
@@ -614,6 +614,11 @@ static char *theme_format_compress_colors(THEME_REC *theme, const char *format)
last_bg = '\0';
}
format++;
+ } else {
+ /* % at end of string */
+ format++;
+ g_string_append_c(str, '%');
+ g_string_append_c(str, '%');
}
}
diff --git a/src/fe-common/irc/dcc/fe-dcc-get.c b/src/fe-common/irc/dcc/fe-dcc-get.c
index 675cab65..99b6b963 100644
--- a/src/fe-common/irc/dcc/fe-dcc-get.c
+++ b/src/fe-common/irc/dcc/fe-dcc-get.c
@@ -108,7 +108,7 @@ static void dcc_error_close_not_found(const char *type, const char *nick,
g_return_if_fail(fname != NULL);
if (g_ascii_strcasecmp(type, "GET") != 0) return;
- if (fname == '\0') fname = "(ANY)";
+ if (fname == NULL || *fname == '\0') fname = "(ANY)";
printformat(NULL, NULL, MSGLEVEL_DCC,
IRCTXT_DCC_GET_NOT_FOUND, nick, fname);
}
diff --git a/src/fe-common/irc/dcc/fe-dcc-send.c b/src/fe-common/irc/dcc/fe-dcc-send.c
index 1fc43abd..7920bedc 100644
--- a/src/fe-common/irc/dcc/fe-dcc-send.c
+++ b/src/fe-common/irc/dcc/fe-dcc-send.c
@@ -108,7 +108,7 @@ static void dcc_error_close_not_found(const char *type, const char *nick,
g_return_if_fail(fname != NULL);
if (g_ascii_strcasecmp(type, "SEND") != 0) return;
- if (fname == '\0') fname = "(ANY)";
+ if (fname == NULL || *fname == '\0') fname = "(ANY)";
printformat(NULL, NULL, MSGLEVEL_DCC,
IRCTXT_DCC_SEND_NOT_FOUND, nick, fname);
}
diff --git a/src/fe-common/irc/fe-ircnet.c b/src/fe-common/irc/fe-ircnet.c
index b70a9ea7..5ae5ac05 100644
--- a/src/fe-common/irc/fe-ircnet.c
+++ b/src/fe-common/irc/fe-ircnet.c
@@ -48,6 +48,8 @@ static void cmd_network_list(void)
g_string_truncate(str, 0);
if (rec->nick != NULL)
g_string_append_printf(str, "nick: %s, ", rec->nick);
+ if (rec->alternate_nick != NULL)
+ g_string_append_printf(str, "alternate_nick: %s, ", rec->alternate_nick);
if (rec->username != NULL)
g_string_append_printf(str, "username: %s, ", rec->username);
if (rec->realname != NULL)
@@ -104,9 +106,9 @@ static void cmd_network_add_modify(const char *data, gboolean add)
rec = ircnet_find(name);
if (rec == NULL) {
if (add == FALSE) {
- cmd_params_free(free_arg);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
IRCTXT_NETWORK_NOT_FOUND, name);
+ cmd_params_free(free_arg);
return;
}
@@ -114,6 +116,7 @@ static void cmd_network_add_modify(const char *data, gboolean add)
rec->name = g_strdup(name);
} else {
if (g_hash_table_lookup(optlist, "nick")) g_free_and_null(rec->nick);
+ if (g_hash_table_lookup(optlist, "alternate_nick")) g_free_and_null(rec->alternate_nick);
if (g_hash_table_lookup(optlist, "user")) g_free_and_null(rec->username);
if (g_hash_table_lookup(optlist, "realname")) g_free_and_null(rec->realname);
if (g_hash_table_lookup(optlist, "host")) {
@@ -145,6 +148,8 @@ static void cmd_network_add_modify(const char *data, gboolean add)
value = g_hash_table_lookup(optlist, "nick");
if (value != NULL && *value != '\0') rec->nick = g_strdup(value);
+ value = g_hash_table_lookup(optlist, "alternate_nick");
+ if (value != NULL && *value != '\0') rec->alternate_nick = g_strdup(value);
value = g_hash_table_lookup(optlist, "user");
if (value != NULL && *value != '\0') rec->username = g_strdup(value);
value = g_hash_table_lookup(optlist, "realname");
@@ -163,11 +168,11 @@ static void cmd_network_add_modify(const char *data, gboolean add)
/* the validity of the parameters is checked in sig_server_setup_fill_chatnet */
value = g_hash_table_lookup(optlist, "sasl_mechanism");
- if (value != NULL && *value != '\0') rec->sasl_mechanism = g_strdup(value);
+ if (value != NULL) rec->sasl_mechanism = *value != '\0' ? g_strdup(value) : NULL;
value = g_hash_table_lookup(optlist, "sasl_username");
- if (value != NULL && *value != '\0') rec->sasl_username = g_strdup(value);
+ if (value != NULL) rec->sasl_username = *value != '\0' ? g_strdup(value) : NULL;
value = g_hash_table_lookup(optlist, "sasl_password");
- if (value != NULL && *value != '\0') rec->sasl_password = g_strdup(value);
+ if (value != NULL) rec->sasl_password = *value != '\0' ? g_strdup(value) : NULL;
ircnet_create(rec);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_NETWORK_ADDED, name);
@@ -175,7 +180,7 @@ static void cmd_network_add_modify(const char *data, gboolean add)
cmd_params_free(free_arg);
}
-/* SYNTAX: NETWORK ADD|MODIFY [-nick <nick>] [-user <user>] [-realname <name>]
+/* SYNTAX: NETWORK ADD|MODIFY [-nick <nick>] [-alternate_nick <nick>] [-user <user>] [-realname <name>]
[-host <host>] [-usermode <mode>] [-autosendcmd <cmd>]
[-querychans <count>] [-whois <count>] [-msgs <count>]
[-kicks <count>] [-modes <count>] [-cmdspeed <ms>]
@@ -228,9 +233,9 @@ void fe_ircnet_init(void)
command_bind("network remove", NULL, (SIGNAL_FUNC) cmd_network_remove);
command_set_options("network add", "-kicks -msgs -modes -whois -cmdspeed "
- "-cmdmax -nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
+ "-cmdmax -nick -alternate_nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
command_set_options("network modify", "-kicks -msgs -modes -whois -cmdspeed "
- "-cmdmax -nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
+ "-cmdmax -nick -alternate_nick -user -realname -host -autosendcmd -querychans -usermode -sasl_mechanism -sasl_username -sasl_password");
}
void fe_ircnet_deinit(void)
diff --git a/src/fe-fuzz/Makefile.am b/src/fe-fuzz/Makefile.am
index 3a547c66..c11b3dbb 100644
--- a/src/fe-fuzz/Makefile.am
+++ b/src/fe-fuzz/Makefile.am
@@ -1,7 +1,7 @@
bin_PROGRAMS = irssi-fuzz
-# Force link with clang++ for libfuzzer support
-CCLD=clang++ $(CXXFLAGS)
+# Force link with CXX for libfuzzer support
+CCLD=$(CXX) $(CXXFLAGS)
AM_CPPFLAGS = \
-I$(top_srcdir)/src \
diff --git a/src/fe-fuzz/irssi.c b/src/fe-fuzz/irssi.c
index 77892aaf..c1b2ca9b 100644
--- a/src/fe-fuzz/irssi.c
+++ b/src/fe-fuzz/irssi.c
@@ -21,7 +21,7 @@
#include "module.h"
#include "modules-load.h"
#include "levels.h"
-#include "../fe-text/module-formats.h" // need to explicitly grab from fe-text
+#include "../fe-text/module-formats.h" /* need to explicitly grab from fe-text */
#include "themes.h"
#include "core.h"
#include "fe-common-core.h"
diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c
index f05decd2..e91fcfb3 100644
--- a/src/fe-text/gui-entry.c
+++ b/src/fe-text/gui-entry.c
@@ -936,6 +936,26 @@ void gui_entry_set_pos(GUI_ENTRY_REC *entry, int pos)
gui_entry_draw(entry);
}
+void gui_entry_set_text_and_pos_bytes(GUI_ENTRY_REC *entry, const char *str, int pos_bytes)
+{
+ int pos;
+ const char *ptr;
+
+ g_return_if_fail(entry != NULL);
+
+ gui_entry_set_text(entry, str);
+
+ if (entry->utf8) {
+ g_utf8_validate(str, pos_bytes, &ptr);
+ pos = g_utf8_pointer_to_offset(str, ptr);
+ } else if (term_type == TERM_TYPE_BIG5)
+ pos = strlen_big5((const unsigned char *)str) - strlen_big5((const unsigned char *)(str + pos_bytes));
+ else
+ pos = pos_bytes;
+
+ gui_entry_set_pos(entry, pos);
+}
+
void gui_entry_move_pos(GUI_ENTRY_REC *entry, int pos)
{
g_return_if_fail(entry != NULL);
diff --git a/src/fe-text/gui-entry.h b/src/fe-text/gui-entry.h
index 8777f083..000c5f03 100644
--- a/src/fe-text/gui-entry.h
+++ b/src/fe-text/gui-entry.h
@@ -50,6 +50,7 @@ void gui_entry_set_utf8(GUI_ENTRY_REC *entry, int utf8);
void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str);
char *gui_entry_get_text(GUI_ENTRY_REC *entry);
char *gui_entry_get_text_and_pos(GUI_ENTRY_REC *entry, int *pos);
+void gui_entry_set_text_and_pos_bytes(GUI_ENTRY_REC *entry, const char *str, int pos_bytes);
void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str);
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr);
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
index 2c2eac21..b3a78396 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -530,6 +530,39 @@ static void key_forward_history(void)
g_free(line);
}
+static void key_backward_global_history(void)
+{
+ const char *text;
+ char *line;
+
+ line = gui_entry_get_text(active_entry);
+ text = command_global_history_prev(active_win, line);
+ gui_entry_set_text(active_entry, text);
+ g_free(line);
+}
+
+static void key_forward_global_history(void)
+{
+ const char *text;
+ char *line;
+
+ line = gui_entry_get_text(active_entry);
+ text = command_global_history_next(active_win, line);
+ gui_entry_set_text(active_entry, text);
+ g_free(line);
+}
+
+static void key_erase_history_entry(void)
+{
+ const char *text;
+ char *line;
+
+ line = gui_entry_get_text(active_entry);
+ text = command_history_delete_current(active_win, line);
+ gui_entry_set_text(active_entry, text);
+ g_free(line);
+}
+
static void key_beginning_of_line(void)
{
gui_entry_set_pos(active_entry, 0);
@@ -878,8 +911,7 @@ static void key_completion(int erase, int backward)
g_free(text);
if (line != NULL) {
- gui_entry_set_text(active_entry, line);
- gui_entry_set_pos(active_entry, pos);
+ gui_entry_set_text_and_pos_bytes(active_entry, line, pos);
g_free(line);
}
}
@@ -909,8 +941,7 @@ static void key_check_replaces(void)
g_free(text);
if (line != NULL) {
- gui_entry_set_text(active_entry, line);
- gui_entry_set_pos(active_entry, pos);
+ gui_entry_set_text_and_pos_bytes(active_entry, line, pos);
g_free(line);
}
}
@@ -1178,6 +1209,8 @@ void gui_readline_init(void)
key_bind("key", NULL, "meta2-5C", "cright", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;5D", "cleft", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;5C", "cright", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-1;5A", "cup", (SIGNAL_FUNC) key_combo);
+ key_bind("key", NULL, "meta2-1;5B", "cdown", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;3A", "mup", (SIGNAL_FUNC) key_combo);
key_bind("key", NULL, "meta2-1;3B", "mdown", (SIGNAL_FUNC) key_combo);
@@ -1219,6 +1252,9 @@ void gui_readline_init(void)
/* history */
key_bind("backward_history", "Go back one line in the history", "up", NULL, (SIGNAL_FUNC) key_backward_history);
key_bind("forward_history", "Go forward one line in the history", "down", NULL, (SIGNAL_FUNC) key_forward_history);
+ key_bind("backward_global_history", "Go back one line in the global history", "cup", NULL, (SIGNAL_FUNC) key_backward_global_history);
+ key_bind("forward_global_history", "Go forward one line in the global history", "cdown", NULL, (SIGNAL_FUNC) key_forward_global_history);
+ key_bind("erase_history_entry", "Erase the currently active entry from the history", NULL, NULL, (SIGNAL_FUNC) key_erase_history_entry);
/* line editing */
key_bind("backspace", "Delete the previous character", "backspace", NULL, (SIGNAL_FUNC) key_backspace);
@@ -1312,6 +1348,9 @@ void gui_readline_deinit(void)
key_unbind("backward_history", (SIGNAL_FUNC) key_backward_history);
key_unbind("forward_history", (SIGNAL_FUNC) key_forward_history);
+ key_unbind("backward_global_history", (SIGNAL_FUNC) key_backward_global_history);
+ key_unbind("forward_global_history", (SIGNAL_FUNC) key_forward_global_history);
+ key_unbind("erase_history_entry", (SIGNAL_FUNC) key_erase_history_entry);
key_unbind("backspace", (SIGNAL_FUNC) key_backspace);
key_unbind("delete_character", (SIGNAL_FUNC) key_delete_character);
diff --git a/src/fe-text/gui-windows.c b/src/fe-text/gui-windows.c
index c63c495c..34c55772 100644
--- a/src/fe-text/gui-windows.c
+++ b/src/fe-text/gui-windows.c
@@ -23,6 +23,7 @@
#include "misc.h"
#include "settings.h"
#include "special-vars.h"
+#include "levels.h"
#include "term.h"
#include "gui-entry.h"
@@ -50,6 +51,7 @@ static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window,
!settings_get_bool("indent_always"),
get_default_indent_func());
textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide"));
+ textbuffer_view_set_hidden_level(gui->view, MSGLEVEL_HIDDEN);
if (parent->active == window)
textbuffer_view_set_window(gui->view, parent->screen_win);
return gui;
@@ -204,6 +206,8 @@ void gui_windows_reset_settings(void)
WINDOW_REC *rec = tmp->data;
GUI_WINDOW_REC *gui = WINDOW_GUI(rec);
+ textbuffer_view_set_hidden_level(gui->view, MSGLEVEL_HIDDEN);
+
textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide"));
textbuffer_view_set_default_indent(gui->view,
diff --git a/src/fe-text/irssi.c b/src/fe-text/irssi.c
index b5df47c9..0288e4f1 100644
--- a/src/fe-text/irssi.c
+++ b/src/fe-text/irssi.c
@@ -31,6 +31,7 @@
#include "printtext.h"
#include "fe-common-core.h"
+#include "fe-settings.h"
#include "themes.h"
#include "term.h"
@@ -79,25 +80,8 @@ static int dirty, full_redraw;
static GMainLoop *main_loop;
int quitting;
-static const char *banner_text =
- " ___ _\n"
- "|_ _|_ _ _____(_)\n"
- " | || '_(_-<_-< |\n"
- "|___|_| /__/__/_|\n"
- "Irssi v" PACKAGE_VERSION " - http://www.irssi.org";
-
-static const char *firsttimer_text =
- "- - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"
- "Hi there! If this is your first time using Irssi, you\n"
- "might want to go to our website and read the startup\n"
- "documentation to get you going.\n\n"
- "Our community and staff are available to assist you or\n"
- "to answer any questions you may have.\n\n"
- "Use the /HELP command to get detailed information about\n"
- "the available commands.\n"
- "- - - - - - - - - - - - - - - - - - - - - - - - - - - -";
-
static int display_firsttimer = FALSE;
+static unsigned int user_settings_changed = 0;
static void sig_exit(void)
@@ -105,6 +89,11 @@ static void sig_exit(void)
quitting = TRUE;
}
+static void sig_settings_userinfo_changed(gpointer changedp)
+{
+ user_settings_changed = GPOINTER_TO_UINT(changedp);
+}
+
/* redraw irssi's screen.. */
void irssi_redraw(void)
{
@@ -161,6 +150,7 @@ static void textui_init(void)
fe_common_irc_init();
theme_register(gui_text_formats);
+ signal_add("settings userinfo changed", (SIGNAL_FUNC) sig_settings_userinfo_changed);
signal_add_last("gui exit", (SIGNAL_FUNC) sig_exit);
}
@@ -199,14 +189,26 @@ static void textui_finish_init(void)
statusbar_redraw(NULL, TRUE);
if (servers == NULL && lookup_servers == NULL) {
- printtext(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT,
- "%s", banner_text);
+ printformat(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, TXT_IRSSI_BANNER);
}
if (display_firsttimer) {
- printtext(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT,
- "%s", firsttimer_text);
+ printformat(NULL, NULL, MSGLEVEL_CRAP|MSGLEVEL_NO_ACT, TXT_WELCOME_FIRSTTIME);
}
+
+ /* see irc-servers-setup.c:init_userinfo */
+ if (user_settings_changed)
+ printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_WELCOME_INIT_SETTINGS);
+ if (user_settings_changed & USER_SETTINGS_REAL_NAME)
+ fe_settings_set_print("real_name");
+ if (user_settings_changed & USER_SETTINGS_USER_NAME)
+ fe_settings_set_print("user_name");
+ if (user_settings_changed & USER_SETTINGS_NICK)
+ fe_settings_set_print("nick");
+ if (user_settings_changed & USER_SETTINGS_HOSTNAME)
+ fe_settings_set_print("hostname");
+
+ term_environment_check();
}
static void textui_deinit(void)
@@ -222,7 +224,8 @@ static void textui_deinit(void)
fe_perl_deinit();
#endif
- dirty_check(); /* one last time to print any quit messages */
+ dirty_check(); /* one last time to print any quit messages */
+ signal_remove("settings userinfo changed", (SIGNAL_FUNC) sig_settings_userinfo_changed);
signal_remove("gui exit", (SIGNAL_FUNC) sig_exit);
lastlog_deinit();
@@ -259,12 +262,11 @@ static void check_files(void)
}
}
-
int main(int argc, char **argv)
{
static int version = 0;
static GOptionEntry options[] = {
- { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display irssi version", NULL },
+ { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display Irssi version", NULL },
{ NULL }
};
int loglev;
diff --git a/src/fe-text/mainwindows-layout.c b/src/fe-text/mainwindows-layout.c
index fae02539..acbcb6b9 100644
--- a/src/fe-text/mainwindows-layout.c
+++ b/src/fe-text/mainwindows-layout.c
@@ -23,6 +23,7 @@
#include "misc.h"
#include "lib-config/iconfig.h"
#include "settings.h"
+#include "levels.h"
#include "mainwindows.h"
#include "gui-windows.h"
@@ -41,6 +42,12 @@ static void sig_layout_window_save(WINDOW_REC *window, CONFIG_NODE *node)
iconfig_node_set_int(node, "parent", active->refnum);
}
+ if (gui->view->hidden_level != MSGLEVEL_HIDDEN) {
+ char *level = bits2level(gui->view->hidden_level);
+ iconfig_node_set_str(node, "hidelevel", level);
+ g_free(level);
+ }
+
if (gui->use_scroll)
iconfig_node_set_bool(node, "scroll", gui->scroll);
}
@@ -58,6 +65,9 @@ static void sig_layout_window_restore(WINDOW_REC *window, CONFIG_NODE *node)
if (config_node_get_bool(node, "sticky", FALSE))
gui_window_set_sticky(window);
+
+ textbuffer_view_set_hidden_level(gui->view, level2bits(config_node_get_str(node, "hidelevel", "HIDDEN"), NULL));
+
if (config_node_get_str(node, "scroll", NULL) != NULL) {
gui->use_scroll = TRUE;
gui->scroll = config_node_get_bool(node, "scroll", TRUE);
diff --git a/src/fe-text/module-formats.c b/src/fe-text/module-formats.c
index 899827c2..b8a26192 100644
--- a/src/fe-text/module-formats.c
+++ b/src/fe-text/module-formats.c
@@ -50,6 +50,7 @@ FORMAT_REC gui_text_formats[] =
{ "window_info_scroll", "%#Scroll : $0", 1, { 0 } },
{ "window_scroll", "Window scroll mode is now $0", 1, { 0 } },
{ "window_scroll_unknown", "Unknown scroll mode $0, must be ON, OFF or DEFAULT", 1, { 0 } },
+ { "window_hidelevel", "Window hidden level is now $0", 1, { 0 } },
/* ---- */
{ NULL, "Statusbars", 0 },
@@ -78,5 +79,26 @@ FORMAT_REC gui_text_formats[] =
{ "paste_warning", "Pasting $0 lines to $1. Press Ctrl-K if you wish to do this or Ctrl-C to cancel.", 2, { 1, 0 } },
{ "paste_prompt", "Hit Ctrl-K to paste, Ctrl-C to abort?", 0 },
+ /* ---- */
+ { NULL, "Welcome", 0 },
+
+ { "irssi_banner",
+ " ___ _%:"
+ "|_ _|_ _ _____(_)%:"
+ " | || '_(_-<_-< |%:"
+ "|___|_| /__/__/_|%:"
+ "Irssi v$J - http://www.irssi.org", 0 },
+ { "welcome_firsttime",
+ "- - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"
+ "Hi there! If this is your first time using Irssi, you%:"
+ "might want to go to our website and read the startup%:"
+ "documentation to get you going.%:%:"
+ "Our community and staff are available to assist you or%:"
+ "to answer any questions you may have.%:%:"
+ "Use the /HELP command to get detailed information about%:"
+ "the available commands.%:"
+ "- - - - - - - - - - - - - - - - - - - - - - - - - - - -", 0 },
+ { "welcome_init_settings", "The following settings were initialized", 0 },
+
{ NULL, NULL, 0 }
};
diff --git a/src/fe-text/module-formats.h b/src/fe-text/module-formats.h
index 3fa8c511..b753238b 100644
--- a/src/fe-text/module-formats.h
+++ b/src/fe-text/module-formats.h
@@ -26,6 +26,7 @@ enum {
TXT_WINDOW_INFO_SCROLL,
TXT_WINDOW_SCROLL,
TXT_WINDOW_SCROLL_UNKNOWN,
+ TXT_WINDOW_HIDELEVEL,
TXT_FILL_3,
@@ -52,6 +53,12 @@ enum {
TXT_PASTE_WARNING,
TXT_PASTE_PROMPT,
+ TXT_FILL_5, /* Welcome */
+
+ TXT_IRSSI_BANNER,
+ TXT_WELCOME_FIRSTTIME,
+ TXT_WELCOME_INIT_SETTINGS,
+
TXT_COUNT
};
diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c
index de4499b4..c7d6bcfb 100644
--- a/src/fe-text/statusbar-items.c
+++ b/src/fe-text/statusbar-items.c
@@ -369,8 +369,8 @@ static void item_lag(SBAR_ITEM_REC *item, int get_size_only)
last_lag_unknown = lag_unknown;
if (lag_unknown) {
- // "??)" in C becomes ']'
- // See: https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C
+ /* "??)" in C becomes ']'
+ See: https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C */
g_snprintf(str, sizeof(str), "%d (?""?)", lag / 100);
} else {
if (lag % 100 == 0)
diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c
index 3098a4e4..ba8bdcaf 100644
--- a/src/fe-text/term-terminfo.c
+++ b/src/fe-text/term-terminfo.c
@@ -102,6 +102,17 @@ static GSourceFuncs sigcont_funcs = {
.dispatch = sigcont_dispatch
};
+static void term_atexit(void)
+{
+ if (!quitting && current_term && current_term->TI_rmcup) {
+ /* Unexpected exit, avoid switching out of alternate screen
+ to keep any on-screen errors (like noperl_die()'s) */
+ current_term->TI_rmcup = NULL;
+ }
+
+ term_deinit();
+}
+
int term_init(void)
{
struct sigaction act;
@@ -140,7 +151,7 @@ int term_init(void)
term_set_input_type(TERM_TYPE_8BIT);
term_common_init();
- atexit(term_deinit);
+ atexit(term_atexit);
return TRUE;
}
@@ -618,6 +629,13 @@ void term_stop(void)
{
terminfo_stop(current_term);
kill(getpid(), SIGTSTP);
+ /* this call needs to stay here in case the TSTP was ignored,
+ because then we never see a CONT to call the restoration
+ code. On the other hand we also cannot remove the CONT
+ handler because then nothing would restore the screen when
+ Irssi is killed with TSTP/STOP from external. */
+ terminfo_cont(current_term);
+ irssi_redraw();
}
static int input_utf8(const unsigned char *buffer, int size, unichar *result)
@@ -715,3 +733,31 @@ void term_gets(GArray *buffer, int *line_count)
}
}
}
+
+static const char* term_env_warning =
+ "You seem to be running Irssi inside %2$s, but the TERM environment variable "
+ "is set to '%1$s', which can cause display glitches.\n"
+ "Consider changing TERM to '%2$s' or '%2$s-256color' instead.";
+
+void term_environment_check(void)
+{
+ const char *term, *sty, *tmux, *multiplexer;
+
+ term = g_getenv("TERM");
+ sty = g_getenv("STY");
+ tmux = g_getenv("TMUX");
+
+ multiplexer = (sty && *sty) ? "screen" :
+ (tmux && *tmux) ? "tmux" : NULL;
+
+ if (!multiplexer) {
+ return;
+ }
+
+ if (term && (g_str_has_prefix(term, "screen") ||
+ g_str_has_prefix(term, "tmux"))) {
+ return;
+ }
+
+ g_warning(term_env_warning, term, multiplexer);
+}
diff --git a/src/fe-text/term.h b/src/fe-text/term.h
index 0c7847f6..4b1e2874 100644
--- a/src/fe-text/term.h
+++ b/src/fe-text/term.h
@@ -105,4 +105,6 @@ void term_gets(GArray *buffer, int *line_count);
void term_common_init(void);
void term_common_deinit(void);
+void term_environment_check(void);
+
#endif
diff --git a/src/fe-text/textbuffer-commands.c b/src/fe-text/textbuffer-commands.c
index 648862e7..97d897f3 100644
--- a/src/fe-text/textbuffer-commands.c
+++ b/src/fe-text/textbuffer-commands.c
@@ -89,6 +89,25 @@ static void cmd_window_scroll(const char *data)
gui->scroll : settings_get_bool("scroll"));
}
+/* SYNTAX: WINDOW HIDELEVEL [<level>] */
+static void cmd_window_hidelevel(const char *data)
+{
+ GUI_WINDOW_REC *gui;
+ char *level;
+
+ g_return_if_fail(data != NULL);
+
+ gui = WINDOW_GUI(active_win);
+ textbuffer_view_set_hidden_level(gui->view,
+ combine_level(gui->view->hidden_level, data));
+ textbuffer_view_redraw(gui->view);
+ level = gui->view->hidden_level == 0 ? g_strdup("NONE") :
+ bits2level(gui->view->hidden_level);
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
+ TXT_WINDOW_HIDELEVEL, level);
+ g_free(level);
+}
+
static void cmd_scrollback(const char *data, SERVER_REC *server,
WI_ITEM_REC *item)
{
@@ -358,6 +377,7 @@ void textbuffer_commands_init(void)
{
command_bind("clear", NULL, (SIGNAL_FUNC) cmd_clear);
command_bind("window scroll", NULL, (SIGNAL_FUNC) cmd_window_scroll);
+ command_bind("window hidelevel", NULL, (SIGNAL_FUNC) cmd_window_hidelevel);
command_bind("scrollback", NULL, (SIGNAL_FUNC) cmd_scrollback);
command_bind("scrollback clear", NULL, (SIGNAL_FUNC) cmd_scrollback_clear);
command_bind("scrollback levelclear", NULL, (SIGNAL_FUNC) cmd_scrollback_levelclear);
@@ -377,6 +397,7 @@ void textbuffer_commands_deinit(void)
{
command_unbind("clear", (SIGNAL_FUNC) cmd_clear);
command_unbind("window scroll", (SIGNAL_FUNC) cmd_window_scroll);
+ command_unbind("window hidelevel", (SIGNAL_FUNC) cmd_window_hidelevel);
command_unbind("scrollback", (SIGNAL_FUNC) cmd_scrollback);
command_unbind("scrollback clear", (SIGNAL_FUNC) cmd_scrollback_clear);
command_unbind("scrollback levelclear", (SIGNAL_FUNC) cmd_scrollback_levelclear);
diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c
index 58bd36fb..b54f1c8e 100644
--- a/src/fe-text/textbuffer-view.c
+++ b/src/fe-text/textbuffer-view.c
@@ -41,9 +41,15 @@ static GSList *views;
#define view_is_bottom(view) \
((view)->ypos >= -1 && (view)->ypos < (view)->height)
-#define view_get_linecount(view, line) \
+#define view_get_linecount_hidden(view, line) \
textbuffer_view_get_line_cache(view, line)->count
+#define view_line_is_hidden(view, line) \
+ (((line)->info.level & (view)->hidden_level) != 0)
+
+#define view_get_linecount(view, line) \
+ (view_line_is_hidden(view, line) ? 0 : view_get_linecount_hidden(view, line))
+
static GSList *textbuffer_get_views(TEXT_BUFFER_REC *buffer)
{
GSList *tmp, *list;
@@ -114,7 +120,6 @@ static void update_cmd_color(unsigned char cmd, int *color)
if (cmd & LINE_COLOR_BG) {
/* set background color */
*color &= FGATTR;
- *color &= ~ATTR_FGCOLOR24;
if ((cmd & LINE_COLOR_DEFAULT) == 0)
*color |= (cmd & 0x0f) << BG_SHIFT;
else {
@@ -123,7 +128,6 @@ static void update_cmd_color(unsigned char cmd, int *color)
} else {
/* set foreground color */
*color &= BGATTR;
- *color &= ~ATTR_BGCOLOR24;
if ((cmd & LINE_COLOR_DEFAULT) == 0)
*color |= cmd & 0x0f;
else {
@@ -554,6 +558,9 @@ static void textbuffer_view_init_bottom(TEXT_BUFFER_VIEW_REC *view)
total = 0;
line = textbuffer_line_last(view->buffer);
for (; line != NULL; line = line->prev) {
+ if (view_line_is_hidden(view, line))
+ continue;
+
linecount = view_get_linecount(view, line);
if (line == view->bottom_startline) {
/* keep the old one, make sure that subline is ok */
@@ -616,6 +623,8 @@ TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer,
view->subline = view->bottom_subline;
view->bottom = TRUE;
+ view->hidden_level = 0;
+
textbuffer_view_init_ypos(view);
view->bookmarks = g_hash_table_new((GHashFunc) g_str_hash,
@@ -728,8 +737,10 @@ static void view_draw(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line,
return;
while (line != NULL && lines > 0) {
- linecount = view_line_draw(view, line, subline, ypos, lines);
- ypos += linecount; lines -= linecount;
+ if (!view_line_is_hidden(view, line)) {
+ linecount = view_line_draw(view, line, subline, ypos, lines);
+ ypos += linecount; lines -= linecount;
+ }
subline = 0;
line = line->next;
@@ -770,7 +781,12 @@ static void view_draw_bottom(TEXT_BUFFER_VIEW_REC *view, int lines)
view_draw(view, line, subline, maxline, lines, TRUE);
}
-/* Returns number of lines actually scrolled */
+/* lines: this pointer is scrolled by scrollcount screen lines
+ subline: this pointer contains the subline position
+ scrollcount: the number of lines to scroll down (negative: up)
+ draw_nonclean: whether to redraw the screen now
+
+ Returns number of lines actually scrolled */
static int view_scroll(TEXT_BUFFER_VIEW_REC *view, LINE_REC **lines,
int *subline, int scrollcount, int draw_nonclean)
{
@@ -1029,7 +1045,7 @@ static void view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
view->bottom = view_is_bottom(view);
}
- if (view->window != NULL) {
+ if (view->window != NULL && !view_line_is_hidden(view, line)) {
ypos = view->ypos+1 - view_get_linecount(view, line);
if (ypos >= 0)
subline = 0;
@@ -1044,7 +1060,7 @@ static void view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line)
}
}
- if (view->window != NULL)
+ if (view->window != NULL && !view_line_is_hidden(view, line))
term_refresh(view->window);
}
@@ -1124,6 +1140,12 @@ static int view_get_lines_height(TEXT_BUFFER_VIEW_REC *view,
return height < view->height ? height : view->height;
}
+/* line: line to remove
+ linecount: linecount of that line, to be offset when the line was in/below view
+
+ scroll the window maintaining the startline while removing line
+ if startline is removed, make the previous line the new startline
+*/
static void view_remove_line_update_startline(TEXT_BUFFER_VIEW_REC *view,
LINE_REC *line, int linecount)
{
@@ -1320,6 +1342,37 @@ LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
return g_hash_table_lookup(view->bookmarks, name);
}
+void textbuffer_view_set_hidden_level(TEXT_BUFFER_VIEW_REC *view, int level)
+{
+ g_return_if_fail(view != NULL);
+
+ if (view->hidden_level != level) {
+ if (view->empty_linecount > 0 && view->startline != NULL) {
+ int old_height, new_height;
+ LINE_REC *hidden_start;
+
+ hidden_start = view->startline;
+ while (hidden_start->prev != NULL && view_line_is_hidden(view, hidden_start->prev)) {
+ hidden_start = hidden_start->prev;
+ }
+
+ old_height = view_get_lines_height(view, hidden_start, view->subline, NULL);
+ view->hidden_level = level;
+ new_height = view_get_lines_height(view, hidden_start, view->subline, NULL);
+
+ view->empty_linecount -= new_height - old_height;
+
+ if (view->empty_linecount < 0)
+ view->empty_linecount = 0;
+ else if (view->empty_linecount > view->height)
+ view->empty_linecount = view->height;
+ } else {
+ view->hidden_level = level;
+ }
+ textbuffer_view_resize(view, view->width, view->height);
+ }
+}
+
/* Specify window where the changes in view should be drawn,
NULL disables it. */
void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view,
diff --git a/src/fe-text/textbuffer-view.h b/src/fe-text/textbuffer-view.h
index 5e7a9d0a..a670df2b 100644
--- a/src/fe-text/textbuffer-view.h
+++ b/src/fe-text/textbuffer-view.h
@@ -49,41 +49,51 @@ typedef struct {
struct _TEXT_BUFFER_VIEW_REC {
TEXT_BUFFER_REC *buffer;
- GSList *siblings; /* other views that use the same buffer */
+ /* other views that use the same buffer */
+ GSList *siblings;
TERM_WINDOW *window;
int width, height;
int default_indent;
INDENT_FUNC default_indent_func;
- unsigned int longword_noindent:1;
- unsigned int scroll:1; /* scroll down automatically when at bottom */
- unsigned int utf8:1; /* use UTF8 in this view */
- unsigned int break_wide:1; /* Break wide chars in this view */
TEXT_BUFFER_CACHE_REC *cache;
- int ypos; /* cursor position - visible area is 0..height-1 */
+ /* cursor position - visible area is 0..height-1 */
+ int ypos;
- LINE_REC *startline; /* line at the top of the screen */
- int subline; /* number of "real lines" to skip from `startline' */
+ /* line at the top of the screen */
+ LINE_REC *startline;
+ /* number of "real lines" to skip from `startline' */
+ int subline;
/* marks the bottom of the text buffer */
LINE_REC *bottom_startline;
int bottom_subline;
+ /* Bookmarks to the lines in the buffer - removed automatically
+ when the line gets removed from buffer */
+ GHashTable *bookmarks;
+
+ /* these levels should be hidden */
+ int hidden_level;
/* how many empty lines are in screen. a screenful when started
or used /CLEAR */
int empty_linecount;
+
+ unsigned int longword_noindent:1;
+ /* scroll down automatically when at bottom */
+ unsigned int scroll:1;
+ /* use UTF8 in this view */
+ unsigned int utf8:1;
+ /* Break wide chars in this view */
+ unsigned int break_wide:1;
/* window is at the bottom of the text buffer */
unsigned int bottom:1;
/* if !bottom - new text has been printed since we were at bottom */
unsigned int more_text:1;
/* Window needs a redraw */
unsigned int dirty:1;
-
- /* Bookmarks to the lines in the buffer - removed automatically
- when the line gets removed from buffer */
- GHashTable *bookmarks;
};
/* Create new view. */
@@ -143,6 +153,8 @@ void textbuffer_view_set_bookmark_bottom(TEXT_BUFFER_VIEW_REC *view,
/* Return the line for bookmark */
LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view,
const char *name);
+/* Set hidden level for view */
+void textbuffer_view_set_hidden_level(TEXT_BUFFER_VIEW_REC *view, int level);
/* Specify window where the changes in view should be drawn,
NULL disables it. */
diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c
index 3668f4c7..01cdd118 100644
--- a/src/fe-text/textbuffer.c
+++ b/src/fe-text/textbuffer.c
@@ -24,13 +24,10 @@
#include "misc.h"
#include "formats.h"
#include "utf8.h"
+#include "iregex.h"
#include "textbuffer.h"
-#ifndef USE_GREGEX
-# include <regex.h>
-#endif
-
#define TEXT_CHUNK_USABLE_SIZE (LINE_TEXT_CHUNK_SIZE-2-(int)sizeof(char*))
TEXT_BUFFER_REC *textbuffer_create(void)
@@ -233,6 +230,7 @@ LINE_REC *textbuffer_line_last(TEXT_BUFFER_REC *buffer)
return buffer->cur_line;
}
+/* returns TRUE if `search' comes on or after `line' in the buffer */
int textbuffer_line_exists_after(LINE_REC *line, LINE_REC *search)
{
while (line != NULL) {
@@ -545,11 +543,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
int before, int after,
int regexp, int fullword, int case_sensitive)
{
-#ifdef USE_GREGEX
- GRegex *preg;
-#else
- regex_t preg;
-#endif
+ Regex *preg;
LINE_REC *line, *pre_line;
GList *matches;
GString *str;
@@ -559,23 +553,14 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
g_return_val_if_fail(buffer != NULL, NULL);
g_return_val_if_fail(text != NULL, NULL);
-#ifdef USE_GREGEX
preg = NULL;
if (regexp) {
- preg = g_regex_new(text, G_REGEX_RAW | (case_sensitive ? 0 : G_REGEX_CASELESS), 0, NULL);
+ preg = i_regex_new(text, case_sensitive ? 0 : G_REGEX_CASELESS, 0, NULL);
if (preg == NULL)
return NULL;
}
-#else
- if (regexp) {
- int flags = REG_EXTENDED | REG_NOSUB |
- (case_sensitive ? 0 : REG_ICASE);
- if (regcomp(&preg, text, flags) != 0)
- return NULL;
- }
-#endif
matches = NULL; match_after = 0;
str = g_string_new(NULL);
@@ -596,11 +581,7 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
if (line_matched) {
line_matched = regexp ?
-#ifdef USE_GREGEX
- g_regex_match(preg, str->str, 0, NULL)
-#else
- regexec(&preg, str->str, 0, NULL, 0) == 0
-#endif
+ i_regex_match(preg, str->str, 0, NULL)
: match_func(str->str, text) != NULL;
}
}
@@ -610,33 +591,32 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline,
pre_line = line;
for (i = 0; i < before; i++) {
if (pre_line->prev == NULL ||
- g_list_find(matches, pre_line->prev) != NULL)
+ g_list_nth_data(matches, 0) == pre_line->prev ||
+ g_list_nth_data(matches, 1) == pre_line->prev)
break;
pre_line = pre_line->prev;
}
for (; pre_line != line; pre_line = pre_line->next)
- matches = g_list_append(matches, pre_line);
+ matches = g_list_prepend(matches, pre_line);
match_after = after;
}
if (line_matched || match_after > 0) {
/* matched */
- matches = g_list_append(matches, line);
+ matches = g_list_prepend(matches, line);
if ((!line_matched && --match_after == 0) ||
(line_matched && match_after == 0 && before > 0))
- matches = g_list_append(matches, NULL);
+ matches = g_list_prepend(matches, NULL);
}
}
-#ifdef USE_GREGEX
+ matches = g_list_reverse(matches);
+
if (preg != NULL)
- g_regex_unref(preg);
-#else
- if (regexp) regfree(&preg);
-#endif
+ i_regex_unref(preg);
g_string_free(str, TRUE);
return matches;
}
diff --git a/src/fe-text/textbuffer.h b/src/fe-text/textbuffer.h
index 303789a3..2aa22f1a 100644
--- a/src/fe-text/textbuffer.h
+++ b/src/fe-text/textbuffer.h
@@ -65,10 +65,10 @@ typedef struct {
LINE_REC *cur_line;
TEXT_CHUNK_REC *cur_text;
- unsigned int last_eol:1;
int last_fg;
int last_bg;
int last_flags;
+ unsigned int last_eol:1;
} TEXT_BUFFER_REC;
/* Create new buffer */
diff --git a/src/irc/core/channel-events.c b/src/irc/core/channel-events.c
index 6cb9b088..46bbd5fa 100644
--- a/src/irc/core/channel-events.c
+++ b/src/irc/core/channel-events.c
@@ -37,7 +37,7 @@ static void check_join_failure(IRC_SERVER_REC *server, const char *channel)
channel++; /* server didn't understand !channels */
chanrec = channel_find(SERVER(server), channel);
- if (chanrec == NULL && channel[0] == '!') {
+ if (chanrec == NULL && channel[0] == '!' && strlen(channel) > 6) {
/* it probably replied with the full !channel name,
find the channel with the short name.. */
chan2 = g_strdup_printf("!%s", channel+6);
@@ -138,7 +138,13 @@ static void channel_change_topic(IRC_SERVER_REC *server, const char *channel,
g_free_not_null(chanrec->topic_by);
chanrec->topic_by = g_strdup(setby);
- chanrec->topic_time = settime;
+ if (chanrec->topic_by == NULL) {
+ /* ensure invariant topic_time > 0 <=> topic_by != NULL.
+ this could be triggered by a topic command without sender */
+ chanrec->topic_time = 0;
+ } else {
+ chanrec->topic_time = settime;
+ }
signal_emit("channel topic changed", 1, chanrec);
}
diff --git a/src/irc/core/channels-query.c b/src/irc/core/channels-query.c
index 857ebaf0..d7dadf04 100644
--- a/src/irc/core/channels-query.c
+++ b/src/irc/core/channels-query.c
@@ -119,21 +119,22 @@ static void query_remove_all(IRC_CHANNEL_REC *channel)
int n;
rec = channel->server->chanqueries;
+ if (rec == NULL) return;
/* remove channel from query lists */
for (n = 0; n < CHANNEL_QUERIES; n++)
rec->queries[n] = g_slist_remove(rec->queries[n], channel);
rec->current_queries = g_slist_remove(rec->current_queries, channel);
- query_check(channel->server);
+ if (!channel->server->disconnected)
+ query_check(channel->server);
}
static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
{
g_return_if_fail(channel != NULL);
- if (IS_IRC_CHANNEL(channel) && !channel->server->disconnected &&
- !channel->synced)
+ if (IS_IRC_CHANNEL(channel))
query_remove_all(channel);
}
diff --git a/src/irc/core/irc-chatnets.c b/src/irc/core/irc-chatnets.c
index 0796e0cb..98ce89c3 100644
--- a/src/irc/core/irc-chatnets.c
+++ b/src/irc/core/irc-chatnets.c
@@ -43,6 +43,9 @@ static void sig_chatnet_read(IRC_CHATNET_REC *rec, CONFIG_NODE *node)
value = config_node_get_str(node, "usermode", NULL);
rec->usermode = (value != NULL && *value != '\0') ? g_strdup(value) : NULL;
+ value = config_node_get_str(node, "alternate_nick", NULL);
+ rec->alternate_nick = (value != NULL && *value != '\0') ? g_strdup(value) : NULL;
+
rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0);
rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0);
rec->max_query_chans = config_node_get_int(node, "max_query_chans", 0);
@@ -65,6 +68,9 @@ static void sig_chatnet_saved(IRC_CHATNET_REC *rec, CONFIG_NODE *node)
if (rec->usermode != NULL)
iconfig_node_set_str(node, "usermode", rec->usermode);
+ if (rec->alternate_nick != NULL)
+ iconfig_node_set_str(node, "alternate_nick", rec->alternate_nick);
+
if (rec->max_cmds_at_once > 0)
iconfig_node_set_int(node, "cmdmax", rec->max_cmds_at_once);
if (rec->cmd_queue_speed > 0)
@@ -93,6 +99,7 @@ static void sig_chatnet_destroyed(IRC_CHATNET_REC *rec)
{
if (IS_IRC_CHATNET(rec)) {
g_free(rec->usermode);
+ g_free(rec->alternate_nick);
g_free(rec->sasl_mechanism);
g_free(rec->sasl_username);
g_free(rec->sasl_password);
diff --git a/src/irc/core/irc-chatnets.h b/src/irc/core/irc-chatnets.h
index 2bb10fa9..3fd44472 100644
--- a/src/irc/core/irc-chatnets.h
+++ b/src/irc/core/irc-chatnets.h
@@ -18,6 +18,7 @@ struct _IRC_CHATNET_REC {
#include "chatnet-rec.h"
char *usermode;
+ char *alternate_nick;
char *sasl_mechanism;
char *sasl_username;
diff --git a/src/irc/core/irc-nicklist.c b/src/irc/core/irc-nicklist.c
index 1cb1f3e9..3e16db80 100644
--- a/src/irc/core/irc-nicklist.c
+++ b/src/irc/core/irc-nicklist.c
@@ -323,8 +323,9 @@ static void event_nick_invalid(IRC_SERVER_REC *server, const char *data)
static void event_nick_in_use(IRC_SERVER_REC *server, const char *data)
{
- char *str, *cmd;
+ char *str, *cmd, *params, *nick;
int n;
+ gboolean try_alternate_nick;
g_return_if_fail(data != NULL);
@@ -332,11 +333,21 @@ static void event_nick_in_use(IRC_SERVER_REC *server, const char *data)
/* Already connected, no need to handle this anymore. */
return;
}
+
+ try_alternate_nick = g_ascii_strcasecmp(server->nick, server->connrec->nick) == 0 &&
+ server->connrec->alternate_nick != NULL &&
+ g_ascii_strcasecmp(server->connrec->alternate_nick, server->nick) != 0;
+
+ params = event_get_params(data, 2, NULL, &nick);
+ if (g_ascii_strcasecmp(server->nick, nick) != 0) {
+ /* the server uses a nick different from the one we send */
+ g_free(server->nick);
+ server->nick = g_strdup(nick);
+ }
+ g_free(params);
/* nick already in use - need to change it .. */
- if (g_ascii_strcasecmp(server->nick, server->connrec->nick) == 0 &&
- server->connrec->alternate_nick != NULL &&
- g_ascii_strcasecmp(server->connrec->alternate_nick, server->nick) != 0) {
+ if (try_alternate_nick) {
/* first try, so try the alternative nick.. */
g_free(server->nick);
server->nick = g_strdup(server->connrec->alternate_nick);
diff --git a/src/irc/core/irc-servers-setup.c b/src/irc/core/irc-servers-setup.c
index f425b587..e79557ab 100644
--- a/src/irc/core/irc-servers-setup.c
+++ b/src/irc/core/irc-servers-setup.c
@@ -69,7 +69,10 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
return;
g_return_if_fail(IS_IRCNET(ircnet));
- if (ircnet->nick != NULL) g_free_and_null(conn->alternate_nick);
+ if (ircnet->alternate_nick != NULL) {
+ g_free_and_null(conn->alternate_nick);
+ conn->alternate_nick = g_strdup(ircnet->alternate_nick);
+ }
if (ircnet->usermode != NULL) {
g_free_and_null(conn->usermode);
conn->usermode = g_strdup(ircnet->usermode);
@@ -89,6 +92,8 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
/* Validate the SASL parameters filled by sig_chatnet_read() or cmd_network_add */
conn->sasl_mechanism = SASL_MECHANISM_NONE;
+ conn->sasl_username = NULL;
+ conn->sasl_password = NULL;
if (ircnet->sasl_mechanism != NULL) {
if (!g_ascii_strcasecmp(ircnet->sasl_mechanism, "plain")) {
@@ -102,9 +107,7 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
g_warning("The fields sasl_username and sasl_password are either missing or empty");
}
else if (!g_ascii_strcasecmp(ircnet->sasl_mechanism, "external")) {
- conn->sasl_mechanism = SASL_MECHANISM_EXTERNAL;
- conn->sasl_username = NULL;
- conn->sasl_password = NULL;
+ conn->sasl_mechanism = SASL_MECHANISM_EXTERNAL;
}
else
g_warning("Unsupported SASL mechanism \"%s\" selected", ircnet->sasl_mechanism);
@@ -113,14 +116,17 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn,
static void init_userinfo(void)
{
+ unsigned int changed;
const char *set, *nick, *user_name, *str;
+ changed = 0;
/* check if nick/username/realname wasn't read from setup.. */
set = settings_get_str("real_name");
if (set == NULL || *set == '\0') {
str = g_getenv("IRCNAME");
settings_set_str("real_name",
str != NULL ? str : g_get_real_name());
+ changed |= USER_SETTINGS_REAL_NAME;
}
/* username */
@@ -131,6 +137,7 @@ static void init_userinfo(void)
str != NULL ? str : g_get_user_name());
user_name = settings_get_str("user_name");
+ changed |= USER_SETTINGS_USER_NAME;
}
/* nick */
@@ -140,15 +147,20 @@ static void init_userinfo(void)
settings_set_str("nick", str != NULL ? str : user_name);
nick = settings_get_str("nick");
+ changed |= USER_SETTINGS_NICK;
}
/* host name */
set = settings_get_str("hostname");
if (set == NULL || *set == '\0') {
str = g_getenv("IRCHOST");
- if (str != NULL)
+ if (str != NULL) {
settings_set_str("hostname", str);
+ changed |= USER_SETTINGS_HOSTNAME;
+ }
}
+
+ signal_emit("irssi init userinfo changed", 1, GUINT_TO_POINTER(changed));
}
static void sig_server_setup_read(IRC_SERVER_SETUP_REC *rec, CONFIG_NODE *node)
diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c
index 3117e345..4eaab712 100644
--- a/src/irc/core/irc-servers.c
+++ b/src/irc/core/irc-servers.c
@@ -116,11 +116,14 @@ static char **split_line(const SERVER_REC *server, const char *line,
* the code much simpler. It's worth it.
*/
len -= strlen(recoded_start) + strlen(recoded_end);
+ g_warn_if_fail(len > 0);
if (len <= 0) {
/* There is no room for anything. */
g_free(recoded_start);
g_free(recoded_end);
- return NULL;
+ lines = g_new(char *, 1);
+ lines[0] = NULL;
+ return lines;
}
lines = recode_split(server, line, target, len, onspace);
diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c
index 4dce3fcf..a740b0da 100644
--- a/src/irc/core/irc.c
+++ b/src/irc/core/irc.c
@@ -40,6 +40,8 @@ static int signal_server_incoming;
# define MAX_SOCKET_READS 5
#endif
+static void strip_params_colon(char *const);
+
/* The core of the irc_send_cmd* functions. If `raw' is TRUE, the `cmd'
won't be checked at all if it's 512 bytes or not, or if it contains
line feeds or not. Use with extreme caution! */
@@ -269,8 +271,9 @@ char *event_get_params(const char *data, int count, ...)
while (count-- > 0) {
str = (char **) va_arg(args, char **);
if (count == 0 && rest) {
- /* put the rest to last parameter */
- tmp = *datad == ':' ? datad+1 : datad;
+ /* Put the rest into the last parameter. */
+ strip_params_colon(datad);
+ tmp = datad;
} else {
tmp = event_get_param(&datad);
}
@@ -281,6 +284,33 @@ char *event_get_params(const char *data, int count, ...)
return duprec;
}
+/* Given a string containing <params>, strip any colon prefixing <trailing>. */
+static void strip_params_colon(char *const params)
+{
+ char *s;
+
+ if (params == NULL) {
+ return;
+ }
+
+ s = params;
+ while (*s != '\0') {
+ if (*s == ':') {
+ memmove(s, s+1, strlen(s+1)+1);
+ return;
+ }
+
+ s = strchr(s, ' ');
+ if (s == NULL) {
+ return;
+ }
+
+ while (*s == ' ') {
+ s++;
+ }
+ }
+}
+
static void irc_server_event(IRC_SERVER_REC *server, const char *line,
const char *nick, const char *address)
{
diff --git a/src/irc/core/sasl.c b/src/irc/core/sasl.c
index 635b7dfb..2b589579 100644
--- a/src/irc/core/sasl.c
+++ b/src/irc/core/sasl.c
@@ -30,16 +30,16 @@
* Based on IRCv3 SASL Extension Specification:
* http://ircv3.net/specs/extensions/sasl-3.1.html
*/
-#define AUTHENTICATE_CHUNK_SIZE 400 // bytes
+#define AUTHENTICATE_CHUNK_SIZE 400 /* bytes */
/*
* Maximum size to allow the buffer to grow to before the next fragment comes in. Note that
* due to the way fragmentation works, the maximum message size will actually be:
* floor(AUTHENTICATE_MAX_SIZE / AUTHENTICATE_CHUNK_SIZE) + AUTHENTICATE_CHUNK_SIZE - 1
*/
-#define AUTHENTICATE_MAX_SIZE 8192 // bytes
+#define AUTHENTICATE_MAX_SIZE 8192 /* bytes */
-#define SASL_TIMEOUT (20 * 1000) // ms
+#define SASL_TIMEOUT (20 * 1000) /* ms */
static gboolean sasl_timeout(IRC_SERVER_REC *server)
{
diff --git a/src/irc/dcc/dcc-chat.c b/src/irc/dcc/dcc-chat.c
index ca90b8d8..88c577f7 100644
--- a/src/irc/dcc/dcc-chat.c
+++ b/src/irc/dcc/dcc-chat.c
@@ -66,6 +66,13 @@ CHAT_DCC_REC *dcc_chat_create(IRC_SERVER_REC *server,
dcc->id = dcc_chat_get_new_id(nick);
dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ if (dcc->module_data == NULL) {
+ /* failed to successfully init; TODO: change init_rec API */
+ g_free(dcc->id);
+ g_free(dcc);
+ return NULL;
+ }
+
return dcc;
}
@@ -471,6 +478,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
/* We are accepting a passive DCC CHAT. */
dcc_chat_passive(dcc);
}
+ cmd_params_free(free_arg);
return;
}
@@ -485,6 +493,11 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
cmd_param_error(CMDERR_NOT_CONNECTED);
dcc = dcc_chat_create(server, NULL, nick, "chat");
+ if (dcc == NULL) {
+ cmd_params_free(free_arg);
+ g_warn_if_reached();
+ return;
+ }
if (g_hash_table_lookup(optlist, "passive") == NULL) {
/* Standard DCC CHAT... let's listen for incoming connections */
@@ -627,6 +640,9 @@ static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
}
passive = paramcount == 4 && g_strcmp0(params[2], "0") == 0;
+ if (nick == NULL)
+ nick = "";
+
dcc = DCC_CHAT(dcc_find_request(DCC_CHAT_TYPE, nick, NULL));
if (dcc != NULL) {
if (dcc_is_listening(dcc)) {
@@ -658,6 +674,11 @@ static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
}
dcc = dcc_chat_create(server, chat, nick, params[0]);
+ if (dcc == NULL) {
+ g_strfreev(params);
+ g_warn_if_reached();
+ return;
+ }
dcc->target = g_strdup(target);
dcc->port = atoi(params[2]);
diff --git a/src/irc/dcc/dcc-get.c b/src/irc/dcc/dcc-get.c
index 73c1b864..cecbb076 100644
--- a/src/irc/dcc/dcc-get.c
+++ b/src/irc/dcc/dcc-get.c
@@ -43,6 +43,12 @@ GET_DCC_REC *dcc_get_create(IRC_SERVER_REC *server, CHAT_DCC_REC *chat,
dcc->fhandle = -1;
dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ if (dcc->module_data == NULL) {
+ /* failed to successfully init; TODO: change API */
+ g_free(dcc);
+ return NULL;
+ }
+
return dcc;
}
@@ -382,6 +388,8 @@ int get_file_params_count(char **params, int paramcount)
if (*params[0] == '"') {
/* quoted file name? */
for (pos = 0; pos < paramcount-3; pos++) {
+ if (strlen(params[pos]) == 0)
+ continue;
if (params[pos][strlen(params[pos])-1] == '"' &&
get_params_match(params, pos+1))
return pos+1;
@@ -428,6 +436,11 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data,
int p_id = -1;
int passive = FALSE;
+ if (addr == NULL)
+ addr = "";
+ if (nick == NULL)
+ nick = "";
+
/* SEND <file name> <address> <port> <size> [...] */
/* SEND <file name> <address> 0 <size> <id> (DCC SEND passive protocol) */
params = g_strsplit(data, " ", -1);
@@ -506,6 +519,12 @@ static void ctcp_msg_dcc_send(IRC_SERVER_REC *server, const char *data,
dcc_destroy(DCC(dcc)); /* remove the old DCC */
dcc = dcc_get_create(server, chat, nick, fname);
+ if (dcc == NULL) {
+ g_free(address);
+ g_free(fname);
+ g_warn_if_reached();
+ return;
+ }
dcc->target = g_strdup(target);
if (passive && port == 0)
diff --git a/src/irc/dcc/dcc-resume.c b/src/irc/dcc/dcc-resume.c
index 36f84ddf..ce0ac925 100644
--- a/src/irc/dcc/dcc-resume.c
+++ b/src/irc/dcc/dcc-resume.c
@@ -62,6 +62,8 @@ int get_file_params_count_resume(char **params, int paramcount)
if (*params[0] == '"') {
/* quoted file name? */
for (pos = 0; pos < paramcount-2; pos++) {
+ if (strlen(params[pos]) == 0)
+ continue;
if (params[pos][strlen(params[pos])-1] == '"' &&
get_params_match_resume(params, pos+1))
return pos+1;
diff --git a/src/irc/dcc/dcc-send.c b/src/irc/dcc/dcc-send.c
index ca29b9b9..912129b7 100644
--- a/src/irc/dcc/dcc-send.c
+++ b/src/irc/dcc/dcc-send.c
@@ -237,6 +237,12 @@ static SEND_DCC_REC *dcc_send_create(IRC_SERVER_REC *server,
dcc->queue = -1;
dcc_init_rec(DCC(dcc), server, chat, nick, arg);
+ if (dcc->module_data == NULL) {
+ /* failed to successfully init; TODO: change API */
+ g_free(dcc);
+ return NULL;
+ }
+
return dcc;
}
@@ -417,6 +423,10 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
dcc = dcc_send_create(server, chat, target, str);
g_free(str);
+ if (dcc == NULL) {
+ g_warn_if_reached();
+ return FALSE;
+ }
dcc->handle = handle;
dcc->port = port;
diff --git a/src/perl/Makefile.am b/src/perl/Makefile.am
index 427c5492..db52744e 100644
--- a/src/perl/Makefile.am
+++ b/src/perl/Makefile.am
@@ -59,7 +59,7 @@ perl-signals-list.h: $(top_srcdir)/docs/signals.txt $(srcdir)/get-signals.pl
cat $(top_srcdir)/docs/signals.txt | $(perlpath) $(srcdir)/get-signals.pl > perl-signals-list.h
irssi-core.pl.h: irssi-core.pl
- $(top_srcdir)/file2header.sh $(srcdir)/irssi-core.pl irssi_core_code > irssi-core.pl.h
+ $(top_srcdir)/utils/file2header.sh $(srcdir)/irssi-core.pl irssi_core_code > irssi-core.pl.h
common_sources = \
common/Irssi.xs \
diff --git a/src/perl/common/Expando.xs b/src/perl/common/Expando.xs
index 26800b05..84853a02 100644
--- a/src/perl/common/Expando.xs
+++ b/src/perl/common/Expando.xs
@@ -74,6 +74,7 @@ static char *perl_expando_event(PerlExpando *rec, SERVER_REC *server,
ret = NULL;
if (SvTRUE(ERRSV)) {
+ char *error;
PERL_SCRIPT_REC *script = rec->script;
(void) POPs;
@@ -85,7 +86,7 @@ static char *perl_expando_event(PerlExpando *rec, SERVER_REC *server,
script_unregister_expandos(script);
/* rec has been freed now */
- char *error = g_strdup(SvPV_nolen(ERRSV));
+ error = g_strdup(SvPV_nolen(ERRSV));
signal_emit("script error", 2, script, error);
g_free(error);
} else if (retcount > 0) {
diff --git a/src/perl/textui/Statusbar.xs b/src/perl/textui/Statusbar.xs
index 8b0e5f65..111deaa7 100644
--- a/src/perl/textui/Statusbar.xs
+++ b/src/perl/textui/Statusbar.xs
@@ -67,7 +67,7 @@ static void perl_statusbar_event(char *function, SBAR_ITEM_REC *item,
if (SvTRUE(ERRSV)) {
PERL_SCRIPT_REC *script;
- char *package;
+ char *package, *error;
package = perl_function_get_package(function);
script = perl_script_find_package(package);
@@ -78,7 +78,7 @@ static void perl_statusbar_event(char *function, SBAR_ITEM_REC *item,
script_unregister_statusbars(script);
}
- char *error = g_strdup(SvPV_nolen(ERRSV));
+ error = g_strdup(SvPV_nolen(ERRSV));
signal_emit("script error", 2, script, error);
g_free(error);
} else {
diff --git a/src/perl/ui/Window.xs b/src/perl/ui/Window.xs
index 8c994cc2..85e284bb 100644
--- a/src/perl/ui/Window.xs
+++ b/src/perl/ui/Window.xs
@@ -252,8 +252,148 @@ PREINIT:
GList *tmp;
PPCODE:
rec = command_history_current(window);
- for (tmp = rec->list; tmp != NULL; tmp = tmp->next)
- XPUSHs(sv_2mortal(new_pv(tmp->data)));
+ for (tmp = command_history_list_first(rec); tmp != NULL; tmp = command_history_list_next(rec, tmp))
+ XPUSHs(sv_2mortal(new_pv(((HISTORY_ENTRY_REC *)tmp->data)->text)));
+
+void
+window_get_history_entries(window)
+ Irssi::UI::Window window
+PREINIT:
+ HISTORY_REC *rec;
+ HISTORY_ENTRY_REC *ent;
+ WINDOW_REC *win;
+ GList *tmp;
+ GSList *stmp;
+ HV *hv;
+PPCODE:
+ rec = window == NULL ? NULL : command_history_current(window);
+ for (tmp = command_history_list_first(rec); tmp != NULL; tmp = command_history_list_next(rec, tmp)) {
+ hv = (HV*)sv_2mortal((SV*)newHV());
+ ent = tmp->data;
+ hv_store(hv, "text", 4, newSVpv(ent->text, 0), 0);
+ hv_store(hv, "time", 4, newSViv(ent->time), 0);
+ if (ent->history == command_history_current(NULL)) {
+ hv_store(hv, "history", 7, newSV(0), 0);
+ hv_store(hv, "window", 6, newSV(0), 0);
+ } else {
+ if (ent->history->name == NULL) {
+ hv_store(hv, "history", 7, newSV(0), 0);
+ for (stmp = windows; stmp != NULL; stmp = stmp->next) {
+ win = stmp->data;
+ if (win->history == ent->history) {
+ hv_store(hv, "window", 6, newSViv(win->refnum), 0);
+ break;
+ }
+ }
+ } else {
+ hv_store(hv, "history", 7, new_pv(ent->history->name), 0);
+ hv_store(hv, "window", 6, newSV(0), 0);
+ }
+ }
+ XPUSHs(sv_2mortal(newRV_inc((SV*)hv)));
+ }
+
+void
+window_load_history_entries(window, ...)
+ Irssi::UI::Window window
+PREINIT:
+ HV *hv;
+ SV **sv;
+ HISTORY_REC *history;
+ WINDOW_REC *tmp;
+ const char *text;
+ long hist_time;
+ int i;
+PPCODE:
+ for (i = 1; i < items; i++) {
+ if (!is_hvref(ST(i))) {
+ croak("Usage: Irssi::UI::Window::load_history_entries(window, hash...)");
+ }
+ hv = hvref(ST(i));
+ if (hv != NULL) {
+ tmp = NULL;
+ text = NULL;
+ hist_time = time(NULL);
+ history = command_history_current(NULL);
+
+ sv = hv_fetch(hv, "text", 4, 0);
+ if (sv != NULL) text = SvPV_nolen(*sv);
+ sv = hv_fetch(hv, "time", 4, 0);
+ if (sv != NULL && SvOK(*sv)) hist_time = SvIV(*sv);
+
+ if (window != NULL) {
+ history = command_history_current(window);
+ } else {
+ sv = hv_fetch(hv, "history", 7, 0);
+ if (sv != NULL && SvOK(*sv)) {
+ history = command_history_find_name(SvPV_nolen(*sv));
+ }
+
+ sv = hv_fetch(hv, "window", 6, 0);
+ if (sv != NULL && SvOK(*sv)) {
+ tmp = window_find_refnum(SvIV(*sv));
+ if (tmp != NULL) {
+ history = tmp->history;
+ }
+ }
+ }
+
+ if (text != NULL && history != NULL) {
+ command_history_load_entry(hist_time, history, text);
+ }
+ }
+ }
+
+void
+window_delete_history_entries(window, ...)
+ Irssi::UI::Window window
+PREINIT:
+ HV *hv;
+ SV **sv;
+ HISTORY_REC *history;
+ WINDOW_REC *tmp;
+ const char *text;
+ long hist_time;
+ int i;
+PPCODE:
+ for (i = 1; i < items; i++) {
+ if (!is_hvref(ST(i))) {
+ croak("Usage: Irssi::UI::Window::delete_history_entries(window, hash...)");
+ }
+ hv = hvref(ST(i));
+ if (hv != NULL) {
+ tmp = NULL;
+ text = NULL;
+ hist_time = -1;
+ history = command_history_current(NULL);
+
+ sv = hv_fetch(hv, "text", 4, 0);
+ if (sv != NULL) text = SvPV_nolen(*sv);
+ sv = hv_fetch(hv, "time", 4, 0);
+ if (sv != NULL && SvOK(*sv)) hist_time = SvIV(*sv);
+
+ if (window != NULL) {
+ history = command_history_current(window);
+ } else {
+ sv = hv_fetch(hv, "history", 7, 0);
+ if (sv != NULL && SvOK(*sv)) {
+ history = command_history_find_name(SvPV_nolen(*sv));
+ }
+
+ sv = hv_fetch(hv, "window", 6, 0);
+ if (sv != NULL && SvOK(*sv)) {
+ tmp = window_find_refnum(SvIV(*sv));
+ if (tmp != NULL) {
+ history = tmp->history;
+ }
+ }
+ }
+
+ if (text != NULL && history != NULL) {
+ XPUSHs(boolSV(command_history_delete_entry(hist_time, history, text)));
+ }
+ }
+ }
#*******************************
MODULE = Irssi::UI::Window PACKAGE = Irssi::Windowitem PREFIX = window_item_
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 00000000..e16d190e
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = fe-common irc
diff --git a/tests/fe-common/Makefile.am b/tests/fe-common/Makefile.am
new file mode 100644
index 00000000..52770885
--- /dev/null
+++ b/tests/fe-common/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = core
diff --git a/tests/fe-common/core/Makefile.am b/tests/fe-common/core/Makefile.am
new file mode 100644
index 00000000..070b6052
--- /dev/null
+++ b/tests/fe-common/core/Makefile.am
@@ -0,0 +1,28 @@
+include $(top_srcdir)/utils/glib-tap.mk
+
+PACKAGE_STRING=fe-common/core
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/src/core \
+ $(GLIB_CFLAGS)
+
+test_programs = test-formats
+
+test_formats_CPPFLAGS = \
+ -I$(top_srcdir)/src/fe-common/core \
+ $(AM_CPPFLAGS)
+
+test_formats_DEPENDENCIES = \
+ ../../../src/core/libcore.a \
+ ../../../src/lib-config/libirssi_config.a
+
+test_formats_LDADD = \
+ ../../../src/fe-common/core/libfe_common_core.a \
+ ../../../src/core/libcore.a \
+ ../../../src/lib-config/libirssi_config.a \
+ @GLIB_LIBS@ \
+ @OPENSSL_LIBS@
+
+test_formats_SOURCES = \
+ test-formats.c
diff --git a/tests/fe-common/core/test-formats.c b/tests/fe-common/core/test-formats.c
new file mode 100644
index 00000000..9ef23fd6
--- /dev/null
+++ b/tests/fe-common/core/test-formats.c
@@ -0,0 +1,50 @@
+#include "common.h"
+#include "formats.h"
+
+#define MAX_LENGTH 5
+
+typedef struct {
+ char const *const description;
+ char const *const input;
+ int const result[ MAX_LENGTH ];
+} format_real_length_test_case;
+
+static void test_format_real_length(const format_real_length_test_case *test);
+
+format_real_length_test_case const format_real_length_fixtures[] = {
+ {
+ .description = "",
+ .input = "%4%w ",
+ .result = { 0, 5, 5, -1 },
+ },
+};
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ g_test_init(&argc, &argv, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS(format_real_length_fixtures); i++) {
+ char *name = g_strdup_printf("/test/format_real_length/%d", i);
+ g_test_add_data_func(name, &format_real_length_fixtures[i], (GTestDataFunc)test_format_real_length);
+ g_free(name);
+ }
+
+ g_test_set_nonfatal_assertions();
+ return g_test_run();
+}
+
+static void test_format_real_length(const format_real_length_test_case *test)
+{
+ int j, len;
+
+ g_test_message("Testing format %s", test->input);
+
+ for (j = 0; test->result[j] != -1; j++) {
+ len = format_real_length(test->input, j);
+ g_assert_cmpint(len, ==, test->result[j]);
+ }
+
+ return;
+}
diff --git a/tests/irc/Makefile.am b/tests/irc/Makefile.am
new file mode 100644
index 00000000..52770885
--- /dev/null
+++ b/tests/irc/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = core
diff --git a/tests/irc/core/Makefile.am b/tests/irc/core/Makefile.am
new file mode 100644
index 00000000..ccc6aa97
--- /dev/null
+++ b/tests/irc/core/Makefile.am
@@ -0,0 +1,29 @@
+include $(top_srcdir)/utils/glib-tap.mk
+
+PACKAGE_STRING=irc/core
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/src/core \
+ -DSYSCONFDIR=\""$(sysconfdir)"\" \
+ $(GLIB_CFLAGS)
+
+test_programs = test-irc
+
+test_irc_CPPFLAGS = \
+ -I$(top_srcdir)/src/irc/core \
+ $(AM_CPPFLAGS)
+
+test_irc_DEPENDENCIES = \
+ ../../../src/core/libcore.a \
+ ../../../src/lib-config/libirssi_config.a
+
+test_irc_LDADD = \
+ ../../../src/irc/core/libirc_core.a \
+ ../../../src/core/libcore.a \
+ ../../../src/lib-config/libirssi_config.a \
+ @GLIB_LIBS@ \
+ @OPENSSL_LIBS@
+
+test_irc_SOURCES = \
+ test-irc.c
diff --git a/tests/irc/core/test-irc.c b/tests/irc/core/test-irc.c
new file mode 100644
index 00000000..c96956df
--- /dev/null
+++ b/tests/irc/core/test-irc.c
@@ -0,0 +1,231 @@
+/*
+ test-irc.c : irssi
+
+ Copyright (C) 2017 Will Storey
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <glib.h>
+#include <irc.h>
+#include <string.h>
+
+typedef struct {
+ char const *const description;
+ char const *const input;
+ char const *const input_after;
+ char const *const output;
+} event_get_param_test_case;
+
+event_get_param_test_case const event_get_param_fixtures[] = {
+ {
+ .description = "Zero parameters",
+ .input = "",
+ .input_after = "",
+ .output = "",
+ },
+ {
+ .description = "One parameter",
+ .input = "#test",
+ .input_after = "",
+ .output = "#test",
+ },
+ {
+ .description = "One parameter, trailing space",
+ .input = "#test ",
+ .input_after = "",
+ .output = "#test",
+ },
+ {
+ .description = "One parameter, more trailing space",
+ .input = "#test ",
+ .input_after = " ",
+ .output = "#test",
+ },
+ {
+ .description = "Two parameters",
+ .input = "#test +o",
+ .input_after = "+o",
+ .output = "#test",
+ },
+ {
+ .description = "Two parameters continued",
+ .input = "+o",
+ .input_after = "",
+ .output = "+o",
+ },
+ {
+ .description = "Two parameters with trailing space",
+ .input = "#test +o ",
+ .input_after = "+o ",
+ .output = "#test",
+ },
+ {
+ .description = "Two parameters with trailing space continued",
+ .input = "+o ",
+ .input_after = "",
+ .output = "+o",
+ },
+ {
+ .description = "Two parameters with inline and trailing space",
+ .input = "#test +o ",
+ .input_after = " +o ",
+ .output = "#test",
+ },
+ /* TODO: It seems not ideal that the caller has to deal with inline space.
+ */
+ {
+ .description = "Two parameters with inline and trailing space continued",
+ .input = " +o ",
+ .input_after = "+o ",
+ .output = "",
+ },
+};
+
+static void test_event_get_param(const event_get_param_test_case *test);
+
+typedef struct {
+ char const *const description;
+ char const *const input;
+ char const *const output0;
+ char const *const output1;
+} event_get_params_test_case;
+
+event_get_params_test_case const event_get_params_fixtures[] = {
+ {
+ .description = "Only a channel",
+ .input = "#test",
+ .output0 = "#test",
+ .output1 = "",
+ },
+ {
+ .description = "Only a channel with trailing space",
+ .input = "#test ",
+ .output0 = "#test",
+ .output1 = "",
+ },
+ {
+ .description = "No :<trailing>, channel mode with one parameter after channel name",
+ .input = "#test +i",
+ .output0 = "#test",
+ .output1 = "+i",
+ },
+ {
+ .description = "No :<trailing>, channel mode with two parameters after channel name",
+ .input = "#test +o tester",
+ .output0 = "#test",
+ .output1 = "+o tester",
+ },
+ {
+ .description = "No :<trailing>, channel mode with three parameters afer channel name",
+ .input = "#test +ov tester tester2",
+ .output0 = "#test",
+ .output1 = "+ov tester tester2",
+ },
+ {
+ .description = "No :<trailing>, channel mode with three parameters afer channel name, bunch of extra space",
+ .input = "#test +ov tester tester2 ",
+ .output0 = "#test",
+ .output1 = " +ov tester tester2 ",
+ },
+ {
+ .description = "Channel mode with one parameter after channel name, :<trailing> at the start of modes",
+ .input = "#test :+i",
+ .output0 = "#test",
+ .output1 = "+i",
+ },
+ {
+ .description = "Channel mode with two parameters after channel name, :<trailing> at the start of modes",
+ .input = "#test :+o tester",
+ .output0 = "#test",
+ .output1 = "+o tester",
+ },
+ {
+ .description = "Channel mode with three parameters after channel name, :<trailing> at the start of modes",
+ .input = "#test :+ov tester tester2",
+ .output0 = "#test",
+ .output1 = "+ov tester tester2",
+ },
+ {
+ .description = "Channel mode with two parameters after channel name, :<trailing> on the final parameter",
+ .input = "#test +o :tester",
+ .output0 = "#test",
+ .output1 = "+o tester",
+ },
+ {
+ .description = "Channel mode with three parameters after channel name, :<trailing> on the final parameter",
+ .input = "#test +ov tester :tester2",
+ .output0 = "#test",
+ .output1 = "+ov tester tester2",
+ },
+ {
+ .description = "Channel mode with three parameters after channel name, :<trailing> on the final parameter, also a second : present",
+ .input = "#test +ov tester :tester2 hi:there",
+ .output0 = "#test",
+ .output1 = "+ov tester tester2 hi:there",
+ },
+};
+
+static void test_event_get_params(const event_get_params_test_case *test);
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ g_test_init(&argc, &argv, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS(event_get_params_fixtures); i++) {
+ char *name = g_strdup_printf("/test/event_get_params/%d", i);
+ g_test_add_data_func(name, &event_get_params_fixtures[i], (GTestDataFunc)test_event_get_params);
+ g_free(name);
+ }
+ for (i = 0; i < G_N_ELEMENTS(event_get_param_fixtures); i++) {
+ char *name = g_strdup_printf("/test/event_get_param/%d", i);
+ g_test_add_data_func(name, &event_get_param_fixtures[i], (GTestDataFunc)test_event_get_param);
+ g_free(name);
+ }
+
+ g_test_set_nonfatal_assertions();
+ return g_test_run();
+}
+
+static void test_event_get_param(const event_get_param_test_case *test)
+{
+ char *buf, *input, *output;
+
+ input = buf = g_strdup(test->input);
+ output = event_get_param(&input);
+
+ g_assert_cmpstr(input, ==, test->input_after);
+ g_assert_cmpstr(output, ==, test->output);
+
+ g_free(buf);
+}
+
+static void test_event_get_params(const event_get_params_test_case *test)
+{
+ char *output0, *output1, *params;
+ output0 = NULL;
+ output1 = NULL;
+ params = event_get_params(test->input, 2 | PARAM_FLAG_GETREST,
+ &output0, &output1);
+
+ /* params happens to always point at the first output */
+ g_assert_cmpstr(params, ==, test->output0);
+ g_assert_cmpstr(output0, ==, test->output0);
+ g_assert_cmpstr(output1, ==, test->output1);
+
+ g_free(params);
+}
diff --git a/themes/Makefile.am b/themes/Makefile.am
new file mode 100644
index 00000000..ad0707c2
--- /dev/null
+++ b/themes/Makefile.am
@@ -0,0 +1,5 @@
+themedir = $(datadir)/irssi/themes
+theme_DATA = default.theme colorless.theme
+
+EXTRA_DIST = \
+ $(theme_DATA)
diff --git a/colorless.theme b/themes/colorless.theme
index 1b26f628..1b26f628 100644
--- a/colorless.theme
+++ b/themes/colorless.theme
diff --git a/default.theme b/themes/default.theme
index 956d7c4f..956d7c4f 100644
--- a/default.theme
+++ b/themes/default.theme
diff --git a/utils/Makefile.am b/utils/Makefile.am
new file mode 100644
index 00000000..8af5c8f7
--- /dev/null
+++ b/utils/Makefile.am
@@ -0,0 +1,6 @@
+EXTRA_DIST = \
+ file2header.sh \
+ irssi-version.sh \
+ syntax.pl \
+ tap-driver.sh \
+ tap-test
diff --git a/file2header.sh b/utils/file2header.sh
index f25ae13b..f25ae13b 100755
--- a/file2header.sh
+++ b/utils/file2header.sh
diff --git a/utils/glib-tap.mk b/utils/glib-tap.mk
new file mode 100644
index 00000000..582f6d29
--- /dev/null
+++ b/utils/glib-tap.mk
@@ -0,0 +1,134 @@
+# GLIB - Library of useful C routines
+
+TESTS_ENVIRONMENT= \
+ G_TEST_SRCDIR="$(abs_srcdir)" \
+ G_TEST_BUILDDIR="$(abs_builddir)" \
+ G_DEBUG=gc-friendly \
+ MALLOC_CHECK_=2 \
+ MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256))
+LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/utils/tap-driver.sh
+LOG_COMPILER = $(top_srcdir)/utils/tap-test
+
+NULL =
+
+# initialize variables for unconditional += appending
+BUILT_SOURCES =
+BUILT_EXTRA_DIST =
+CLEANFILES = *.log *.trs
+DISTCLEANFILES =
+MAINTAINERCLEANFILES =
+EXTRA_DIST =
+TESTS =
+
+installed_test_LTLIBRARIES =
+installed_test_PROGRAMS =
+installed_test_SCRIPTS =
+nobase_installed_test_DATA =
+
+noinst_LTLIBRARIES =
+noinst_PROGRAMS =
+noinst_SCRIPTS =
+noinst_DATA =
+
+check_LTLIBRARIES =
+check_PROGRAMS =
+check_SCRIPTS =
+check_DATA =
+
+# We support a fairly large range of possible variables. It is expected that all types of files in a test suite
+# will belong in exactly one of the following variables.
+#
+# First, we support the usual automake suffixes, but in lowercase, with the customary meaning:
+#
+# test_programs, test_scripts, test_data, test_ltlibraries
+#
+# The above are used to list files that are involved in both uninstalled and installed testing. The
+# test_programs and test_scripts are taken to be actual testcases and will be run as part of the test suite.
+# Note that _data is always used with the nobase_ automake variable name to ensure that installed test data is
+# installed in the same way as it appears in the package layout.
+#
+# In order to mark a particular file as being only for one type of testing, use 'installed' or 'uninstalled',
+# like so:
+#
+# installed_test_programs, uninstalled_test_programs
+# installed_test_scripts, uninstalled_test_scripts
+# installed_test_data, uninstalled_test_data
+# installed_test_ltlibraries, uninstalled_test_ltlibraries
+#
+# Additionally, we support 'extra' infixes for programs and scripts. This is used for support programs/scripts
+# that should not themselves be run as testcases (but exist to be used from other testcases):
+#
+# test_extra_programs, installed_test_extra_programs, uninstalled_test_extra_programs
+# test_extra_scripts, installed_test_extra_scripts, uninstalled_test_extra_scripts
+#
+# Additionally, for _scripts and _data, we support the customary dist_ prefix so that the named script or data
+# file automatically end up in the tarball.
+#
+# dist_test_scripts, dist_test_data, dist_test_extra_scripts
+# dist_installed_test_scripts, dist_installed_test_data, dist_installed_test_extra_scripts
+# dist_uninstalled_test_scripts, dist_uninstalled_test_data, dist_uninstalled_test_extra_scripts
+#
+# Note that no file is automatically disted unless it appears in one of the dist_ variables. This follows the
+# standard automake convention of not disting programs scripts or data by default.
+#
+# test_programs, test_scripts, uninstalled_test_programs and uninstalled_test_scripts (as well as their disted
+# variants) will be run as part of the in-tree 'make check'. These are all assumed to be runnable under
+# gtester. That's a bit strange for scripts, but it's possible.
+
+TESTS += $(test_programs) $(test_scripts) $(uninstalled_test_programs) $(uninstalled_test_scripts) \
+ $(dist_test_scripts) $(dist_uninstalled_test_scripts)
+
+# Note: build even the installed-only targets during 'make check' to ensure that they still work.
+# We need to do a bit of trickery here and manage disting via EXTRA_DIST instead of using dist_ prefixes to
+# prevent automake from mistreating gmake functions like $(wildcard ...) and $(addprefix ...) as if they were
+# filenames, including removing duplicate instances of the opening part before the space, eg. '$(addprefix'.
+all_test_programs = $(test_programs) $(uninstalled_test_programs) $(installed_test_programs) \
+ $(test_extra_programs) $(uninstalled_test_extra_programs) $(installed_test_extra_programs)
+all_test_scripts = $(test_scripts) $(uninstalled_test_scripts) $(installed_test_scripts) \
+ $(test_extra_scripts) $(uninstalled_test_extra_scripts) $(installed_test_extra_scripts)
+all_dist_test_scripts = $(dist_test_scripts) $(dist_uninstalled_test_scripts) $(dist_installed_test_scripts) \
+ $(dist_test_extra_scripts) $(dist_uninstalled_test_extra_scripts) $(dist_installed_test_extra_scripts)
+all_test_scripts += $(all_dist_test_scripts)
+EXTRA_DIST += $(all_dist_test_scripts)
+all_test_data = $(test_data) $(uninstalled_test_data) $(installed_test_data)
+all_dist_test_data = $(dist_test_data) $(dist_uninstalled_test_data) $(dist_installed_test_data)
+all_test_data += $(all_dist_test_data)
+EXTRA_DIST += $(all_dist_test_data)
+all_test_ltlibs = $(test_ltlibraries) $(uninstalled_test_ltlibraries) $(installed_test_ltlibraries)
+
+if ENABLE_ALWAYS_BUILD_TESTS
+noinst_LTLIBRARIES += $(all_test_ltlibs)
+noinst_PROGRAMS += $(all_test_programs)
+noinst_SCRIPTS += $(all_test_scripts)
+noinst_DATA += $(all_test_data)
+else
+check_LTLIBRARIES += $(all_test_ltlibs)
+check_PROGRAMS += $(all_test_programs)
+check_SCRIPTS += $(all_test_scripts)
+check_DATA += $(all_test_data)
+endif
+
+if ENABLE_INSTALLED_TESTS
+installed_test_PROGRAMS += $(test_programs) $(installed_test_programs) \
+ $(test_extra_programs) $(installed_test_extra_programs)
+installed_test_SCRIPTS += $(test_scripts) $(installed_test_scripts) \
+ $(test_extra_scripts) $(test_installed_extra_scripts)
+installed_test_SCRIPTS += $(dist_test_scripts) $(dist_test_extra_scripts) \
+ $(dist_installed_test_scripts) $(dist_installed_test_extra_scripts)
+nobase_installed_test_DATA += $(test_data) $(installed_test_data)
+nobase_installed_test_DATA += $(dist_test_data) $(dist_installed_test_data)
+installed_test_LTLIBRARIES += $(test_ltlibraries) $(installed_test_ltlibraries)
+installed_testcases = $(test_programs) $(installed_test_programs) \
+ $(test_scripts) $(installed_test_scripts) \
+ $(dist_test_scripts) $(dist_installed_test_scripts)
+
+installed_test_meta_DATA = $(installed_testcases:=.test)
+
+%.test: %$(EXEEXT) Makefile
+ $(AM_V_GEN) (echo '[Test]' > $@.tmp; \
+ echo 'Type=session' >> $@.tmp; \
+ echo 'Exec=$(installed_testdir)/$<' >> $@.tmp; \
+ mv $@.tmp $@)
+
+CLEANFILES += $(installed_test_meta_DATA)
+endif
diff --git a/irssi-version.sh b/utils/irssi-version.sh
index 1fc6a558..1fc6a558 100755
--- a/irssi-version.sh
+++ b/utils/irssi-version.sh
diff --git a/utils/syncdocs.sh b/utils/syncdocs.sh
new file mode 100755
index 00000000..e723edd2
--- /dev/null
+++ b/utils/syncdocs.sh
@@ -0,0 +1,102 @@
+#!/bin/sh -e
+# Run this to download FAQ and startup-HOWTO from irssi.org
+
+PKG_NAME="Irssi"
+
+site=https://irssi.org
+
+faq=$site/documentation/faq/
+howto=$site/documentation/startup/
+
+# remove everything until H1 and optionally 2 DIVs before the
+# FOOTER. May need to be adjusted as the source pages change
+pageclean_regex='s{.*(?=<h1)}{}s;
+s{\s*(</div>\s*)?(</div>\s*)?<footer.*}{}s;
+s{(<.*?)\sclass="(?:highlighter-rouge|highlight)"(.*?>)}{\1\2}g;'
+
+srcdir=`dirname "$0"`
+test -z "$srcdir" && srcdir=.
+srcdir="$srcdir"/..
+
+if test ! -f "$srcdir"/configure.ac; then
+ echo -n "**Error**: Directory \`$srcdir' does not look like the"
+ echo " top-level $PKG_NAME directory"
+ exit 1
+fi
+
+# detect downloader app
+downloader=false
+
+if type curl >/dev/null 2>&1 ; then
+ downloader="curl -Ssf"
+elif type wget >/dev/null 2>&1 ; then
+ downloader="wget -nv -O-"
+else
+ echo "**Error**: No wget or curl present"
+ echo "Install wget or curl, then run syncdocs.sh again"
+fi
+
+# detect html converter app
+converter=false
+if [ "$1" = "-any" ]; then
+ any=true
+else
+ any=false
+fi
+
+if type w3m >/dev/null 2>&1 ; then
+ converter="w3m -o display_link_number=1 -dump -T text/html"
+ any=true
+elif type lynx >/dev/null 2>&1 ; then
+ converter="lynx -dump -stdin -force_html"
+elif type elinks >/dev/null 2>&1 ; then
+ converter="elinks -dump -force-html"
+else
+ echo "**Error**: Neither w3m, nor lynx or elinks present"
+ echo "Install w3m, then run syncdocs.sh again"
+ exit 1
+fi
+
+if ! $any ; then
+ echo "**Error**: w3m not present"
+ echo "If you want to use lynx or elinks, run syncdocs.sh -any"
+ exit 1
+fi
+
+check_download() {
+ if test "$1" -ne 0 || test ! -e "$2" || test "$(wc -l "$2" | awk '{print $1}')" -le 1 ; then
+ rm -f "$2"
+ echo "... download failed ( $1 )"
+ exit 2
+ fi
+}
+
+download_it() {
+ echo "Downloading $1 from $2 ..."
+ ret=0
+ $downloader "$2" > "$3".tmp || ret=$?
+ check_download "$ret" "$3".tmp
+ perl -i -0777 -p -e "$pageclean_regex" "$3".tmp
+ perl -i -0777 -p -e 's{\A}{'"<base href='$2'>"'\n}' "$3".tmp
+ perl -i -0777 -p -e 's{<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail=".*?">\[email&#160;protected\]</a>}{user\@host}g' "$3".tmp
+ mv "$3".tmp "$3"
+}
+
+download_it "FAQ" "$faq" "$srcdir"/docs/faq.html
+download_it "Startup How-To" "$howto" "$srcdir"/docs/startup-HOWTO.html
+
+# .html -> .txt with lynx or elinks
+echo "Documentation: html -> txt..."
+
+cat "$srcdir"/docs/faq.html \
+ | LC_ALL=en_IE.utf8 $converter \
+ | perl -pe '
+ s/^ *//;
+ if ($_ eq "\n" && $state eq "Q") { $_ = ""; }
+ elsif (/^([QA]):/) { $state = $1 }
+ elsif ($_ ne "\n") { $_ = " $_"; };
+' > "$srcdir"/docs/faq.txt
+
+cat "$srcdir"/docs/startup-HOWTO.html \
+ | perl -pe "s/\\bhref=([\"\'])#.*?\\1//" \
+ | LC_ALL=en_IE.utf8 $converter > "$srcdir"/docs/startup-HOWTO.txt
diff --git a/utils/syncscripts.sh b/utils/syncscripts.sh
new file mode 100755
index 00000000..533b77cc
--- /dev/null
+++ b/utils/syncscripts.sh
@@ -0,0 +1,39 @@
+#!/bin/sh -e
+# Run this script to sync dual lived scripts from scripts.irssi.org to scripts/
+
+PKG_NAME="Irssi"
+
+scriptbase=https://scripts.irssi.org/scripts
+
+srcdir=`dirname "$0"`
+test -z "$srcdir" && srcdir=.
+srcdir="$srcdir"/..
+
+if test ! -f "$srcdir"/configure.ac; then
+ echo -n "**Error**: Directory \`$srcdir' does not look like the"
+ echo " top-level $PKG_NAME directory"
+ exit 1
+fi
+
+dl2='curl -Ssf'
+
+dl_it() {
+ echo "$1"
+ $dl2 -o "$srcdir/scripts/$1" "$scriptbase/$1"
+}
+
+for script in \
+ autoop.pl \
+ autorejoin.pl \
+ buf.pl \
+ dns.pl \
+ kills.pl \
+ mail.pl \
+ mlock.pl \
+ quitmsg.pl \
+ scriptassist.pl \
+ usercount.pl \
+ ;
+do
+ dl_it $script
+done
diff --git a/syntax.pl b/utils/syntax.pl
index 33bd12b4..33bd12b4 100755
--- a/syntax.pl
+++ b/utils/syntax.pl
diff --git a/utils/tap-driver.sh b/utils/tap-driver.sh
new file mode 100755
index 00000000..19aa531d
--- /dev/null
+++ b/utils/tap-driver.sh
@@ -0,0 +1,652 @@
+#! /bin/sh
+# Copyright (C) 2011-2013 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that program.
+
+# This file is maintained in Automake, please report
+# bugs to <bug-automake@gnu.org> or send patches to
+# <automake-patches@gnu.org>.
+
+scriptversion=2011-12-27.17; # UTC
+
+# Make unconditional expansion of undefined variables an error. This
+# helps a lot in preventing typo-related bugs.
+set -u
+
+me=tap-driver.sh
+
+fatal ()
+{
+ echo "$me: fatal: $*" >&2
+ exit 1
+}
+
+usage_error ()
+{
+ echo "$me: $*" >&2
+ print_usage >&2
+ exit 2
+}
+
+print_usage ()
+{
+ cat <<END
+Usage:
+ tap-driver.sh --test-name=NAME --log-file=PATH --trs-file=PATH
+ [--expect-failure={yes|no}] [--color-tests={yes|no}]
+ [--enable-hard-errors={yes|no}] [--ignore-exit]
+ [--diagnostic-string=STRING] [--merge|--no-merge]
+ [--comments|--no-comments] [--] TEST-COMMAND
+The \`--test-name', \`--log-file' and \`--trs-file' options are mandatory.
+END
+}
+
+# TODO: better error handling in option parsing (in particular, ensure
+# TODO: $log_file, $trs_file and $test_name are defined).
+test_name= # Used for reporting.
+log_file= # Where to save the result and output of the test script.
+trs_file= # Where to save the metadata of the test run.
+expect_failure=0
+color_tests=0
+merge=0
+ignore_exit=0
+comments=0
+diag_string='#'
+while test $# -gt 0; do
+ case $1 in
+ --help) print_usage; exit $?;;
+ --version) echo "$me $scriptversion"; exit $?;;
+ --test-name) test_name=$2; shift;;
+ --log-file) log_file=$2; shift;;
+ --trs-file) trs_file=$2; shift;;
+ --color-tests) color_tests=$2; shift;;
+ --expect-failure) expect_failure=$2; shift;;
+ --enable-hard-errors) shift;; # No-op.
+ --merge) merge=1;;
+ --no-merge) merge=0;;
+ --ignore-exit) ignore_exit=1;;
+ --comments) comments=1;;
+ --no-comments) comments=0;;
+ --diagnostic-string) diag_string=$2; shift;;
+ --) shift; break;;
+ -*) usage_error "invalid option: '$1'";;
+ esac
+ shift
+done
+
+test $# -gt 0 || usage_error "missing test command"
+
+case $expect_failure in
+ yes) expect_failure=1;;
+ *) expect_failure=0;;
+esac
+
+if test $color_tests = yes; then
+ init_colors='
+ color_map["red"]="" # Red.
+ color_map["grn"]="" # Green.
+ color_map["lgn"]="" # Light green.
+ color_map["blu"]="" # Blue.
+ color_map["mgn"]="" # Magenta.
+ color_map["std"]="" # No color.
+ color_for_result["ERROR"] = "mgn"
+ color_for_result["PASS"] = "grn"
+ color_for_result["XPASS"] = "red"
+ color_for_result["FAIL"] = "red"
+ color_for_result["XFAIL"] = "lgn"
+ color_for_result["SKIP"] = "blu"'
+else
+ init_colors=''
+fi
+
+# :; is there to work around a bug in bash 3.2 (and earlier) which
+# does not always set '$?' properly on redirection failure.
+# See the Autoconf manual for more details.
+:;{
+ (
+ # Ignore common signals (in this subshell only!), to avoid potential
+ # problems with Korn shells. Some Korn shells are known to propagate
+ # to themselves signals that have killed a child process they were
+ # waiting for; this is done at least for SIGINT (and usually only for
+ # it, in truth). Without the `trap' below, such a behaviour could
+ # cause a premature exit in the current subshell, e.g., in case the
+ # test command it runs gets terminated by a SIGINT. Thus, the awk
+ # script we are piping into would never seen the exit status it
+ # expects on its last input line (which is displayed below by the
+ # last `echo $?' statement), and would thus die reporting an internal
+ # error.
+ # For more information, see the Autoconf manual and the threads:
+ # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
+ # <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html>
+ trap : 1 3 2 13 15
+ if test $merge -gt 0; then
+ exec 2>&1
+ else
+ exec 2>&3
+ fi
+ "$@"
+ echo $?
+ ) | LC_ALL=C ${AM_TAP_AWK-awk} \
+ -v me="$me" \
+ -v test_script_name="$test_name" \
+ -v log_file="$log_file" \
+ -v trs_file="$trs_file" \
+ -v expect_failure="$expect_failure" \
+ -v merge="$merge" \
+ -v ignore_exit="$ignore_exit" \
+ -v comments="$comments" \
+ -v diag_string="$diag_string" \
+'
+# FIXME: the usages of "cat >&3" below could be optimized when using
+# FIXME: GNU awk, and/on on systems that supports /dev/fd/.
+
+# Implementation note: in what follows, `result_obj` will be an
+# associative array that (partly) simulates a TAP result object
+# from the `TAP::Parser` perl module.
+
+## ----------- ##
+## FUNCTIONS ##
+## ----------- ##
+
+function fatal(msg)
+{
+ print me ": " msg | "cat >&2"
+ exit 1
+}
+
+function abort(where)
+{
+ fatal("internal error " where)
+}
+
+# Convert a boolean to a "yes"/"no" string.
+function yn(bool)
+{
+ return bool ? "yes" : "no";
+}
+
+function add_test_result(result)
+{
+ if (!test_results_index)
+ test_results_index = 0
+ test_results_list[test_results_index] = result
+ test_results_index += 1
+ test_results_seen[result] = 1;
+}
+
+# Whether the test script should be re-run by "make recheck".
+function must_recheck()
+{
+ for (k in test_results_seen)
+ if (k != "XFAIL" && k != "PASS" && k != "SKIP")
+ return 1
+ return 0
+}
+
+# Whether the content of the log file associated to this test should
+# be copied into the "global" test-suite.log.
+function copy_in_global_log()
+{
+ for (k in test_results_seen)
+ if (k != "PASS")
+ return 1
+ return 0
+}
+
+# FIXME: this can certainly be improved ...
+function get_global_test_result()
+{
+ if ("ERROR" in test_results_seen)
+ return "ERROR"
+ if ("FAIL" in test_results_seen || "XPASS" in test_results_seen)
+ return "FAIL"
+ all_skipped = 1
+ for (k in test_results_seen)
+ if (k != "SKIP")
+ all_skipped = 0
+ if (all_skipped)
+ return "SKIP"
+ return "PASS";
+}
+
+function stringify_result_obj(result_obj)
+{
+ if (result_obj["is_unplanned"] || result_obj["number"] != testno)
+ return "ERROR"
+
+ if (plan_seen == LATE_PLAN)
+ return "ERROR"
+
+ if (result_obj["directive"] == "TODO")
+ return result_obj["is_ok"] ? "XPASS" : "XFAIL"
+
+ if (result_obj["directive"] == "SKIP")
+ return result_obj["is_ok"] ? "SKIP" : COOKED_FAIL;
+
+ if (length(result_obj["directive"]))
+ abort("in function stringify_result_obj()")
+
+ return result_obj["is_ok"] ? COOKED_PASS : COOKED_FAIL
+}
+
+function decorate_result(result)
+{
+ color_name = color_for_result[result]
+ if (color_name)
+ return color_map[color_name] "" result "" color_map["std"]
+ # If we are not using colorized output, or if we do not know how
+ # to colorize the given result, we should return it unchanged.
+ return result
+}
+
+function report(result, details)
+{
+ if (result ~ /^(X?(PASS|FAIL)|SKIP|ERROR)/)
+ {
+ msg = ": " test_script_name
+ add_test_result(result)
+ }
+ else if (result == "#")
+ {
+ msg = " " test_script_name ":"
+ }
+ else
+ {
+ abort("in function report()")
+ }
+ if (length(details))
+ msg = msg " " details
+ # Output on console might be colorized.
+ print decorate_result(result) msg
+ # Log the result in the log file too, to help debugging (this is
+ # especially true when said result is a TAP error or "Bail out!").
+ print result msg | "cat >&3";
+}
+
+function testsuite_error(error_message)
+{
+ report("ERROR", "- " error_message)
+}
+
+function handle_tap_result()
+{
+ details = result_obj["number"];
+ if (length(result_obj["description"]))
+ details = details " " result_obj["description"]
+
+ if (plan_seen == LATE_PLAN)
+ {
+ details = details " # AFTER LATE PLAN";
+ }
+ else if (result_obj["is_unplanned"])
+ {
+ details = details " # UNPLANNED";
+ }
+ else if (result_obj["number"] != testno)
+ {
+ details = sprintf("%s # OUT-OF-ORDER (expecting %d)",
+ details, testno);
+ }
+ else if (result_obj["directive"])
+ {
+ details = details " # " result_obj["directive"];
+ if (length(result_obj["explanation"]))
+ details = details " " result_obj["explanation"]
+ }
+
+ report(stringify_result_obj(result_obj), details)
+}
+
+# `skip_reason` should be empty whenever planned > 0.
+function handle_tap_plan(planned, skip_reason)
+{
+ planned += 0 # Avoid getting confused if, say, `planned` is "00"
+ if (length(skip_reason) && planned > 0)
+ abort("in function handle_tap_plan()")
+ if (plan_seen)
+ {
+ # Error, only one plan per stream is acceptable.
+ testsuite_error("multiple test plans")
+ return;
+ }
+ planned_tests = planned
+ # The TAP plan can come before or after *all* the TAP results; we speak
+ # respectively of an "early" or a "late" plan. If we see the plan line
+ # after at least one TAP result has been seen, assume we have a late
+ # plan; in this case, any further test result seen after the plan will
+ # be flagged as an error.
+ plan_seen = (testno >= 1 ? LATE_PLAN : EARLY_PLAN)
+ # If testno > 0, we have an error ("too many tests run") that will be
+ # automatically dealt with later, so do not worry about it here. If
+ # $plan_seen is true, we have an error due to a repeated plan, and that
+ # has already been dealt with above. Otherwise, we have a valid "plan
+ # with SKIP" specification, and should report it as a particular kind
+ # of SKIP result.
+ if (planned == 0 && testno == 0)
+ {
+ if (length(skip_reason))
+ skip_reason = "- " skip_reason;
+ report("SKIP", skip_reason);
+ }
+}
+
+function extract_tap_comment(line)
+{
+ if (index(line, diag_string) == 1)
+ {
+ # Strip leading `diag_string` from `line`.
+ line = substr(line, length(diag_string) + 1)
+ # And strip any leading and trailing whitespace left.
+ sub("^[ \t]*", "", line)
+ sub("[ \t]*$", "", line)
+ # Return what is left (if any).
+ return line;
+ }
+ return "";
+}
+
+# When this function is called, we know that line is a TAP result line,
+# so that it matches the (perl) RE "^(not )?ok\b".
+function setup_result_obj(line)
+{
+ # Get the result, and remove it from the line.
+ result_obj["is_ok"] = (substr(line, 1, 2) == "ok" ? 1 : 0)
+ sub("^(not )?ok[ \t]*", "", line)
+
+ # If the result has an explicit number, get it and strip it; otherwise,
+ # automatically assing the next progresive number to it.
+ if (line ~ /^[0-9]+$/ || line ~ /^[0-9]+[^a-zA-Z0-9_]/)
+ {
+ match(line, "^[0-9]+")
+ # The final `+ 0` is to normalize numbers with leading zeros.
+ result_obj["number"] = substr(line, 1, RLENGTH) + 0
+ line = substr(line, RLENGTH + 1)
+ }
+ else
+ {
+ result_obj["number"] = testno
+ }
+
+ if (plan_seen == LATE_PLAN)
+ # No further test results are acceptable after a "late" TAP plan
+ # has been seen.
+ result_obj["is_unplanned"] = 1
+ else if (plan_seen && testno > planned_tests)
+ result_obj["is_unplanned"] = 1
+ else
+ result_obj["is_unplanned"] = 0
+
+ # Strip trailing and leading whitespace.
+ sub("^[ \t]*", "", line)
+ sub("[ \t]*$", "", line)
+
+ # This will have to be corrected if we have a "TODO"/"SKIP" directive.
+ result_obj["description"] = line
+ result_obj["directive"] = ""
+ result_obj["explanation"] = ""
+
+ if (index(line, "#") == 0)
+ return # No possible directive, nothing more to do.
+
+ # Directives are case-insensitive.
+ rx = "[ \t]*#[ \t]*([tT][oO][dD][oO]|[sS][kK][iI][pP])[ \t]*"
+
+ # See whether we have the directive, and if yes, where.
+ pos = match(line, rx "$")
+ if (!pos)
+ pos = match(line, rx "[^a-zA-Z0-9_]")
+
+ # If there was no TAP directive, we have nothing more to do.
+ if (!pos)
+ return
+
+ # Let`s now see if the TAP directive has been escaped. For example:
+ # escaped: ok \# SKIP
+ # not escaped: ok \\# SKIP
+ # escaped: ok \\\\\# SKIP
+ # not escaped: ok \ # SKIP
+ if (substr(line, pos, 1) == "#")
+ {
+ bslash_count = 0
+ for (i = pos; i > 1 && substr(line, i - 1, 1) == "\\"; i--)
+ bslash_count += 1
+ if (bslash_count % 2)
+ return # Directive was escaped.
+ }
+
+ # Strip the directive and its explanation (if any) from the test
+ # description.
+ result_obj["description"] = substr(line, 1, pos - 1)
+ # Now remove the test description from the line, that has been dealt
+ # with already.
+ line = substr(line, pos)
+ # Strip the directive, and save its value (normalized to upper case).
+ sub("^[ \t]*#[ \t]*", "", line)
+ result_obj["directive"] = toupper(substr(line, 1, 4))
+ line = substr(line, 5)
+ # Now get the explanation for the directive (if any), with leading
+ # and trailing whitespace removed.
+ sub("^[ \t]*", "", line)
+ sub("[ \t]*$", "", line)
+ result_obj["explanation"] = line
+}
+
+function get_test_exit_message(status)
+{
+ if (status == 0)
+ return ""
+ if (status !~ /^[1-9][0-9]*$/)
+ abort("getting exit status")
+ if (status < 127)
+ exit_details = ""
+ else if (status == 127)
+ exit_details = " (command not found?)"
+ else if (status >= 128 && status <= 255)
+ exit_details = sprintf(" (terminated by signal %d?)", status - 128)
+ else if (status > 256 && status <= 384)
+ # We used to report an "abnormal termination" here, but some Korn
+ # shells, when a child process die due to signal number n, can leave
+ # in $? an exit status of 256+n instead of the more standard 128+n.
+ # Apparently, both behaviours are allowed by POSIX (2008), so be
+ # prepared to handle them both. See also Austing Group report ID
+ # 0000051 <http://www.austingroupbugs.net/view.php?id=51>
+ exit_details = sprintf(" (terminated by signal %d?)", status - 256)
+ else
+ # Never seen in practice.
+ exit_details = " (abnormal termination)"
+ return sprintf("exited with status %d%s", status, exit_details)
+}
+
+function write_test_results()
+{
+ print ":global-test-result: " get_global_test_result() > trs_file
+ print ":recheck: " yn(must_recheck()) > trs_file
+ print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file
+ for (i = 0; i < test_results_index; i += 1)
+ print ":test-result: " test_results_list[i] > trs_file
+ close(trs_file);
+}
+
+BEGIN {
+
+## ------- ##
+## SETUP ##
+## ------- ##
+
+'"$init_colors"'
+
+# Properly initialized once the TAP plan is seen.
+planned_tests = 0
+
+COOKED_PASS = expect_failure ? "XPASS": "PASS";
+COOKED_FAIL = expect_failure ? "XFAIL": "FAIL";
+
+# Enumeration-like constants to remember which kind of plan (if any)
+# has been seen. It is important that NO_PLAN evaluates "false" as
+# a boolean.
+NO_PLAN = 0
+EARLY_PLAN = 1
+LATE_PLAN = 2
+
+testno = 0 # Number of test results seen so far.
+bailed_out = 0 # Whether a "Bail out!" directive has been seen.
+
+# Whether the TAP plan has been seen or not, and if yes, which kind
+# it is ("early" is seen before any test result, "late" otherwise).
+plan_seen = NO_PLAN
+
+## --------- ##
+## PARSING ##
+## --------- ##
+
+is_first_read = 1
+
+while (1)
+ {
+ # Involutions required so that we are able to read the exit status
+ # from the last input line.
+ st = getline
+ if (st < 0) # I/O error.
+ fatal("I/O error while reading from input stream")
+ else if (st == 0) # End-of-input
+ {
+ if (is_first_read)
+ abort("in input loop: only one input line")
+ break
+ }
+ if (is_first_read)
+ {
+ is_first_read = 0
+ nextline = $0
+ continue
+ }
+ else
+ {
+ curline = nextline
+ nextline = $0
+ $0 = curline
+ }
+ # Copy any input line verbatim into the log file.
+ print | "cat >&3"
+ # Parsing of TAP input should stop after a "Bail out!" directive.
+ if (bailed_out)
+ continue
+
+ # TAP test result.
+ if ($0 ~ /^(not )?ok$/ || $0 ~ /^(not )?ok[^a-zA-Z0-9_]/)
+ {
+ testno += 1
+ setup_result_obj($0)
+ handle_tap_result()
+ }
+ # TAP plan (normal or "SKIP" without explanation).
+ else if ($0 ~ /^1\.\.[0-9]+[ \t]*$/)
+ {
+ # The next two lines will put the number of planned tests in $0.
+ sub("^1\\.\\.", "")
+ sub("[^0-9]*$", "")
+ handle_tap_plan($0, "")
+ continue
+ }
+ # TAP "SKIP" plan, with an explanation.
+ else if ($0 ~ /^1\.\.0+[ \t]*#/)
+ {
+ # The next lines will put the skip explanation in $0, stripping
+ # any leading and trailing whitespace. This is a little more
+ # tricky in truth, since we want to also strip a potential leading
+ # "SKIP" string from the message.
+ sub("^[^#]*#[ \t]*(SKIP[: \t][ \t]*)?", "")
+ sub("[ \t]*$", "");
+ handle_tap_plan(0, $0)
+ }
+ # "Bail out!" magic.
+ # Older versions of prove and TAP::Harness (e.g., 3.17) did not
+ # recognize a "Bail out!" directive when preceded by leading
+ # whitespace, but more modern versions (e.g., 3.23) do. So we
+ # emulate the latter, "more modern" behaviour.
+ else if ($0 ~ /^[ \t]*Bail out!/)
+ {
+ bailed_out = 1
+ # Get the bailout message (if any), with leading and trailing
+ # whitespace stripped. The message remains stored in `$0`.
+ sub("^[ \t]*Bail out![ \t]*", "");
+ sub("[ \t]*$", "");
+ # Format the error message for the
+ bailout_message = "Bail out!"
+ if (length($0))
+ bailout_message = bailout_message " " $0
+ testsuite_error(bailout_message)
+ }
+ # Maybe we have too look for dianogtic comments too.
+ else if (comments != 0)
+ {
+ comment = extract_tap_comment($0);
+ if (length(comment))
+ report("#", comment);
+ }
+ }
+
+## -------- ##
+## FINISH ##
+## -------- ##
+
+# A "Bail out!" directive should cause us to ignore any following TAP
+# error, as well as a non-zero exit status from the TAP producer.
+if (!bailed_out)
+ {
+ if (!plan_seen)
+ {
+ testsuite_error("missing test plan")
+ }
+ else if (planned_tests != testno)
+ {
+ bad_amount = testno > planned_tests ? "many" : "few"
+ testsuite_error(sprintf("too %s tests run (expected %d, got %d)",
+ bad_amount, planned_tests, testno))
+ }
+ if (!ignore_exit)
+ {
+ # Fetch exit status from the last line.
+ exit_message = get_test_exit_message(nextline)
+ if (exit_message)
+ testsuite_error(exit_message)
+ }
+ }
+
+write_test_results()
+
+exit 0
+
+} # End of "BEGIN" block.
+'
+
+# TODO: document that we consume the file descriptor 3 :-(
+} 3>"$log_file"
+
+test $? -eq 0 || fatal "I/O or internal error"
+
+# Local Variables:
+# mode: shell-script
+# sh-indentation: 2
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "scriptversion="
+# time-stamp-format: "%:y-%02m-%02d.%02H"
+# time-stamp-time-zone: "UTC"
+# time-stamp-end: "; # UTC"
+# End:
diff --git a/utils/tap-test b/utils/tap-test
new file mode 100755
index 00000000..481e333e
--- /dev/null
+++ b/utils/tap-test
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+# run a GTest in tap mode. The test binary is passed as $1
+
+$1 -k --tap