diff options
Diffstat (limited to '')
-rw-r--r-- | src/irc/proxy/Makefile.am | 28 | ||||
-rw-r--r-- | src/irc/proxy/Makefile.in | 740 | ||||
-rw-r--r-- | src/irc/proxy/dump.c | 303 | ||||
-rw-r--r-- | src/irc/proxy/listen.c | 874 | ||||
-rw-r--r-- | src/irc/proxy/meson.build | 21 | ||||
-rw-r--r-- | src/irc/proxy/module.h | 26 | ||||
-rw-r--r-- | src/irc/proxy/proxy.c | 116 | ||||
-rw-r--r-- | src/irc/proxy/proxy.h | 36 |
8 files changed, 2144 insertions, 0 deletions
diff --git a/src/irc/proxy/Makefile.am b/src/irc/proxy/Makefile.am new file mode 100644 index 0000000..437a6dc --- /dev/null +++ b/src/irc/proxy/Makefile.am @@ -0,0 +1,28 @@ +moduledir = $(libdir)/irssi/modules +module_LTLIBRARIES = libirc_proxy.la + +AM_CPPFLAGS = \ + -I$(top_builddir) \ + $(GLIB_CFLAGS) + +libirc_proxy.a: + rm -f libirc_proxy.a + $(LN_S) .libs/libirc_proxy.a libirc_proxy.a + +libirc_proxy_la_LDFLAGS = -module -avoid-version + +libirc_proxy_la_DEPENDENCIES = libirc_proxy.a + +libirc_proxy_la_SOURCES = \ + proxy.c \ + dump.c \ + listen.c + +noinst_HEADERS = \ + module.h \ + proxy.h + +clean-generic: + rm -f libirc_proxy.a + +EXTRA_DIST = meson.build diff --git a/src/irc/proxy/Makefile.in b/src/irc/proxy/Makefile.in new file mode 100644 index 0000000..06e7ee7 --- /dev/null +++ b/src/irc/proxy/Makefile.in @@ -0,0 +1,740 @@ +# Makefile.in generated by automake 1.16.5 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2021 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/irc/proxy +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/glib-2.0.m4 \ + $(top_srcdir)/m4/glibtests.m4 $(top_srcdir)/m4/libgcrypt.m4 \ + $(top_srcdir)/m4/libotr.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/irssi-config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__installdirs = "$(DESTDIR)$(moduledir)" +LTLIBRARIES = $(module_LTLIBRARIES) +libirc_proxy_la_LIBADD = +am_libirc_proxy_la_OBJECTS = proxy.lo dump.lo listen.lo +libirc_proxy_la_OBJECTS = $(am_libirc_proxy_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +libirc_proxy_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(libirc_proxy_la_LDFLAGS) $(LDFLAGS) \ + -o $@ +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = +depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/dump.Plo ./$(DEPDIR)/listen.Plo \ + ./$(DEPDIR)/proxy.Plo +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libirc_proxy_la_SOURCES) +DIST_SOURCES = $(libirc_proxy_la_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +am__DIST_COMMON = $(srcdir)/Makefile.in \ + $(top_srcdir)/build-aux/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CHAT_MODULES = @CHAT_MODULES@ +COMMON_LIBS = @COMMON_LIBS@ +COMMON_NOUI_LIBS = @COMMON_NOUI_LIBS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ETAGS = @ETAGS@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +FILECMD = @FILECMD@ +FUZZER_LIBS = @FUZZER_LIBS@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GLIB_LIBS = @GLIB_LIBS@ +GLIB_MKENUMS = @GLIB_MKENUMS@ +GOBJECT_QUERY = @GOBJECT_QUERY@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBOTR_CFLAGS = @LIBOTR_CFLAGS@ +LIBOTR_LIBS = @LIBOTR_LIBS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OPENSSL_CFLAGS = @OPENSSL_CFLAGS@ +OPENSSL_LIBS = @OPENSSL_LIBS@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +OTR_CFLAGS = @OTR_CFLAGS@ +OTR_LDFLAGS = @OTR_LDFLAGS@ +OTR_LINK_FLAGS = @OTR_LINK_FLAGS@ +OTR_LINK_LIBS = @OTR_LINK_LIBS@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL_CFLAGS = @PERL_CFLAGS@ +PERL_EXTRA_OPTS = @PERL_EXTRA_OPTS@ +PERL_FE_LINK_LIBS = @PERL_FE_LINK_LIBS@ +PERL_LDFLAGS = @PERL_LDFLAGS@ +PERL_LINK_FLAGS = @PERL_LINK_FLAGS@ +PERL_LINK_LIBS = @PERL_LINK_LIBS@ +PERL_MM_OPT = @PERL_MM_OPT@ +PERL_MM_PARAMS = @PERL_MM_PARAMS@ +PERL_STATIC_LIBS = @PERL_STATIC_LIBS@ +PERL_USE_LIB = @PERL_USE_LIB@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +PROG_LIBS = @PROG_LIBS@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TEXTUI_LIBS = @TEXTUI_LIBS@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +installed_test_metadir = @installed_test_metadir@ +installed_testdir = @installed_testdir@ +irc_MODULES = @irc_MODULES@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +otr_module_lib = @otr_module_lib@ +otr_static_lib = @otr_static_lib@ +pdfdir = @pdfdir@ +perl_module_fe_lib = @perl_module_fe_lib@ +perl_module_lib = @perl_module_lib@ +perl_static_fe_lib = @perl_static_fe_lib@ +perl_static_lib = @perl_static_lib@ +perlpath = @perlpath@ +pkgconfigdir = @pkgconfigdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sedpath = @sedpath@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +moduledir = $(libdir)/irssi/modules +module_LTLIBRARIES = libirc_proxy.la +AM_CPPFLAGS = \ + -I$(top_builddir) \ + $(GLIB_CFLAGS) + +libirc_proxy_la_LDFLAGS = -module -avoid-version +libirc_proxy_la_DEPENDENCIES = libirc_proxy.a +libirc_proxy_la_SOURCES = \ + proxy.c \ + dump.c \ + listen.c + +noinst_HEADERS = \ + module.h \ + proxy.h + +EXTRA_DIST = meson.build +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/irc/proxy/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/irc/proxy/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +install-moduleLTLIBRARIES: $(module_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(module_LTLIBRARIES)'; test -n "$(moduledir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(moduledir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(moduledir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(moduledir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(moduledir)"; \ + } + +uninstall-moduleLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(module_LTLIBRARIES)'; test -n "$(moduledir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(moduledir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(moduledir)/$$f"; \ + done + +clean-moduleLTLIBRARIES: + -test -z "$(module_LTLIBRARIES)" || rm -f $(module_LTLIBRARIES) + @list='$(module_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +libirc_proxy.la: $(libirc_proxy_la_OBJECTS) $(libirc_proxy_la_DEPENDENCIES) $(EXTRA_libirc_proxy_la_DEPENDENCIES) + $(AM_V_CCLD)$(libirc_proxy_la_LINK) -rpath $(moduledir) $(libirc_proxy_la_OBJECTS) $(libirc_proxy_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dump.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/listen.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proxy.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(moduledir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-moduleLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/dump.Plo + -rm -f ./$(DEPDIR)/listen.Plo + -rm -f ./$(DEPDIR)/proxy.Plo + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-moduleLTLIBRARIES + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/dump.Plo + -rm -f ./$(DEPDIR)/listen.Plo + -rm -f ./$(DEPDIR)/proxy.Plo + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-moduleLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libtool clean-moduleLTLIBRARIES \ + cscopelist-am ctags ctags-am distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man \ + install-moduleLTLIBRARIES install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am \ + uninstall-moduleLTLIBRARIES + +.PRECIOUS: Makefile + + +libirc_proxy.a: + rm -f libirc_proxy.a + $(LN_S) .libs/libirc_proxy.a libirc_proxy.a + +clean-generic: + rm -f libirc_proxy.a + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/irc/proxy/dump.c b/src/irc/proxy/dump.c new file mode 100644 index 0000000..82dc1fe --- /dev/null +++ b/src/irc/proxy/dump.c @@ -0,0 +1,303 @@ +/* + dump.c : proxy plugin - output all information about irc session + + Copyright (C) 1999-2001 Timo Sirainen + + 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 <irssi/src/core/network.h> +#include <irssi/src/core/net-sendbuffer.h> +#include <irssi/src/core/settings.h> +#include <irssi/irssi-version.h> +#include <irssi/src/core/recode.h> + +#include <irssi/src/irc/core/irc-servers.h> +#include <irssi/src/irc/core/irc-channels.h> +#include <irssi/src/irc/core/irc-nicklist.h> +#include <irssi/src/irc/core/modes.h> + +void proxy_outdata(CLIENT_REC *client, const char *data, ...) +{ + va_list args; + char *str; + + g_return_if_fail(client != NULL); + g_return_if_fail(data != NULL); + + va_start(args, data); + + str = g_strdup_vprintf(data, args); + net_sendbuffer_send(client->handle, str, strlen(str)); + g_free(str); + + va_end(args); +} + +void proxy_outdata_all(IRC_SERVER_REC *server, const char *data, ...) +{ + va_list args; + GSList *tmp; + char *str; + int len; + + g_return_if_fail(server != NULL); + g_return_if_fail(data != NULL); + + va_start(args, data); + + str = g_strdup_vprintf(data, args); + len = strlen(str); + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + if (rec->connected && rec->server == server) + net_sendbuffer_send(rec->handle, str, len); + } + g_free(str); + + va_end(args); +} + +void proxy_outserver(CLIENT_REC *client, const char *data, ...) +{ + va_list args; + char *str; + + g_return_if_fail(client != NULL); + g_return_if_fail(data != NULL); + + va_start(args, data); + + str = g_strdup_vprintf(data, args); + proxy_outdata(client, ":%s!%s@proxy %s\r\n", client->nick, + settings_get_str("user_name"), str); + g_free(str); + + va_end(args); +} + +void proxy_outserver_all(IRC_SERVER_REC *server, const char *data, ...) +{ + va_list args; + GSList *tmp; + char *str; + + g_return_if_fail(server != NULL); + g_return_if_fail(data != NULL); + + va_start(args, data); + + str = g_strdup_vprintf(data, args); + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + if (rec->connected && rec->server == server) { + proxy_outdata(rec, ":%s!%s@proxy %s\r\n", rec->nick, + settings_get_str("user_name"), str); + } + } + g_free(str); + + va_end(args); +} + +void proxy_outserver_all_except(CLIENT_REC *client, const char *data, ...) +{ + va_list args; + GSList *tmp; + char *str; + + g_return_if_fail(client != NULL); + g_return_if_fail(data != NULL); + + va_start(args, data); + + str = g_strdup_vprintf(data, args); + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + if (rec->connected && rec != client && + rec->server == client->server) { + proxy_outdata(rec, ":%s!%s@proxy %s\r\n", rec->nick, + settings_get_str("user_name"), str); + } + } + g_free(str); + + va_end(args); +} + +static void create_names_start(GString *str, IRC_CHANNEL_REC *channel, + CLIENT_REC *client) +{ + g_string_printf(str, ":%s 353 %s %c %s :", + client->proxy_address, client->nick, + channel_mode_is_set(channel, 'p') ? '*' : + channel_mode_is_set(channel, 's') ? '@' : '=', + channel->name); +} + +static void dump_join(IRC_CHANNEL_REC *channel, CLIENT_REC *client) +{ + GSList *tmp, *nicks; + GString *str; + int first; + char *recoded; + + proxy_outserver(client, "JOIN %s", channel->name); + + str = g_string_new(NULL); + create_names_start(str, channel, client); + + first = TRUE; + nicks = nicklist_getnicks(CHANNEL(channel)); + for (tmp = nicks; tmp != NULL; tmp = tmp->next) { + NICK_REC *nick = tmp->data; + + if (str->len >= 500) { + g_string_append(str, "\r\n"); + proxy_outdata(client, "%s", str->str); + create_names_start(str, channel, client); + first = TRUE; + } + + if (first) + first = FALSE; + else + g_string_append_c(str, ' '); + + if (nick->prefixes[0]) + g_string_append_c(str, nick->prefixes[0]); + g_string_append(str, nick->nick); + } + g_slist_free(nicks); + + g_string_append(str, "\r\n"); + proxy_outdata(client, "%s", str->str); + g_string_free(str, TRUE); + + proxy_outdata(client, ":%s 366 %s %s :End of /NAMES list.\r\n", + client->proxy_address, client->nick, channel->name); + if (channel->topic != NULL) { + /* this is needed because the topic may be encoded into other charsets internaly */ + recoded = recode_out(SERVER(client->server), channel->topic, channel->name); + proxy_outdata(client, ":%s 332 %s %s :%s\r\n", + client->proxy_address, client->nick, + channel->name, recoded); + g_free(recoded); + if (channel->topic_time > 0) + proxy_outdata(client, ":%s 333 %s %s %s %d\r\n", + client->proxy_address, client->nick, + channel->name, channel->topic_by, channel->topic_time); + } +} + +void proxy_client_reset_nick(CLIENT_REC *client) +{ + if (client->server == NULL || + g_strcmp0(client->nick, client->server->nick) == 0) + return; + + proxy_outdata(client, ":%s!proxy NICK :%s\r\n", + client->nick, client->server->nick); + + g_free(client->nick); + client->nick = g_strdup(client->server->nick); +} + +static void proxy_dump_data_005(gpointer key, gpointer value, gpointer context) +{ + if (*(char *)value != '\0') + g_string_append_printf(context, "%s=%s ", (char *)key, (char *)value); + else + g_string_append_printf(context, "%s ", (char *)key); +} + +void proxy_dump_data(CLIENT_REC *client) +{ + GString *isupport_out, *paramstr; + char **paramlist, **tmp; + int count; + + proxy_client_reset_nick(client); + + /* welcome info */ + proxy_outdata(client, ":%s 001 %s :Welcome to the Internet Relay Network %s!%s@proxy\r\n", client->proxy_address, client->nick, client->nick, settings_get_str("user_name")); + proxy_outdata(client, ":%s 002 %s :Your host is irssi-proxy, running version %s\r\n", client->proxy_address, client->nick, PACKAGE_VERSION); + proxy_outdata(client, ":%s 003 %s :This server was created ...\r\n", client->proxy_address, client->nick); + if (client->server == NULL || !client->server->emode_known) + proxy_outdata(client, ":%s 004 %s %s %s oirw abiklmnopqstv\r\n", client->proxy_address, client->nick, client->proxy_address, PACKAGE_VERSION); + else + proxy_outdata(client, ":%s 004 %s %s %s oirw abeIiklmnopqstv\r\n", client->proxy_address, client->nick, client->proxy_address, PACKAGE_VERSION); + + if (client->server != NULL && client->server->isupport_sent) { + isupport_out = g_string_new(NULL); + g_hash_table_foreach(client->server->isupport, proxy_dump_data_005, isupport_out); + if (isupport_out->len > 0) + g_string_truncate(isupport_out, isupport_out->len-1); + + proxy_outdata(client, ":%s 005 %s ", client->proxy_address, client->nick); + + paramstr = g_string_new(NULL); + paramlist = g_strsplit(isupport_out->str, " ", -1); + count = 0; + tmp = paramlist; + + for (;; tmp++) { + if (*tmp != NULL) { + g_string_append_printf(paramstr, "%s ", *tmp); + if (++count < 15) + continue; + } + + count = 0; + if (paramstr->len > 0) + g_string_truncate(paramstr, paramstr->len-1); + g_string_append_printf(paramstr, " :are supported by this server\r\n"); + proxy_outdata(client, "%s", paramstr->str); + g_string_truncate(paramstr, 0); + g_string_printf(paramstr, ":%s 005 %s ", client->proxy_address, client->nick); + + if (*tmp == NULL || tmp[1] == NULL) + break; + } + + g_string_free(isupport_out, TRUE); + g_string_free(paramstr, TRUE); + g_strfreev(paramlist); + } + + proxy_outdata(client, ":%s 251 %s :There are 0 users and 0 invisible on 1 servers\r\n", client->proxy_address, client->nick); + proxy_outdata(client, ":%s 255 %s :I have 0 clients, 0 services and 0 servers\r\n", client->proxy_address, client->nick); + proxy_outdata(client, ":%s 422 %s :MOTD File is missing\r\n", client->proxy_address, client->nick); + + /* user mode / away status */ + if (client->server != NULL) { + if (client->server->usermode != NULL) { + proxy_outserver(client, "MODE %s :+%s", + client->server->nick, + client->server->usermode); + } + if (client->server->usermode_away) { + proxy_outdata(client, ":%s 306 %s :You have been marked as being away\r\n", + client->proxy_address, client->nick); + } + + /* Send channel joins */ + g_slist_foreach(client->server->channels, (GFunc) dump_join, client); + } +} diff --git a/src/irc/proxy/listen.c b/src/irc/proxy/listen.c new file mode 100644 index 0000000..19aba87 --- /dev/null +++ b/src/irc/proxy/listen.c @@ -0,0 +1,874 @@ +/* + listen.c : irc proxy + + Copyright (C) 1999-2001 Timo Sirainen + + 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 <irssi/src/core/signals.h> +#include <irssi/src/core/net-sendbuffer.h> +#include <irssi/src/irc/core/servers-redirect.h> +#include <irssi/src/core/levels.h> +#include <irssi/src/core/settings.h> +#include <irssi/src/core/misc.h> + +#include <irssi/src/irc/core/irc.h> +#include <irssi/src/irc/core/irc-chatnets.h> +#include <irssi/src/irc/core/irc-channels.h> + +#include <irssi/src/fe-common/core/printtext.h> /* FIXME: evil. need to do fe-proxy */ + +#include <sys/un.h> + +GSList *proxy_listens; +GSList *proxy_clients; + +static GString *next_line; +static int ignore_next; + +static int enabled = FALSE; + +static int is_all_digits(const char *s) +{ + return strspn(s, "0123456789") == strlen(s); +} + +static GIOChannel *net_listen_unix(const char *path) +{ + struct sockaddr_un sa; + int saved_errno, handle; + + g_return_val_if_fail(path != NULL, NULL); + + handle = socket(AF_UNIX, SOCK_STREAM, 0); + if (handle == -1) { + return NULL; + } + + fcntl(handle, F_SETFL, O_NONBLOCK); + + memset(&sa, '\0', sizeof sa); + sa.sun_family = AF_UNIX; + strncpy(sa.sun_path, path, sizeof sa.sun_path - 1); + if (bind(handle, (struct sockaddr *)&sa, sizeof sa) == -1) { + saved_errno = errno; + goto error_close; + } + + if (listen(handle, 1) == -1) { + saved_errno = errno; + goto error_unlink; + } + + return i_io_channel_new(handle); + +error_unlink: + unlink(sa.sun_path); +error_close: + close(handle); + errno = saved_errno; + return NULL; +} + +static GIOChannel *net_accept_unix(GIOChannel *handle) +{ + struct sockaddr_un sa; + int ret; + socklen_t addrlen; + + g_return_val_if_fail(handle != NULL, NULL); + + addrlen = sizeof sa; + ret = accept(g_io_channel_unix_get_fd(handle), (struct sockaddr *)&sa, &addrlen); + + if (ret < 0) + return NULL; + + fcntl(ret, F_SETFL, O_NONBLOCK); + return i_io_channel_new(ret); +} + +static void remove_client(CLIENT_REC *rec) +{ + g_return_if_fail(rec != NULL); + + proxy_clients = g_slist_remove(proxy_clients, rec); + rec->listen->clients = g_slist_remove(rec->listen->clients, rec); + + signal_emit("proxy client disconnected", 1, rec); + printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Client %s disconnected", rec->addr); + + g_free(rec->proxy_address); + net_sendbuffer_destroy(rec->handle, TRUE); + g_source_remove(rec->recv_tag); + g_free_not_null(rec->nick); + g_free_not_null(rec->addr); + g_free(rec); +} + +static void proxy_redirect_event(CLIENT_REC *client, const char *command, + int count, const char *arg, int remote) +{ + char *str; + + g_return_if_fail(client != NULL); + + str = g_strdup_printf("proxy %p", client); + server_redirect_event(client->server, command, count, + arg, remote, NULL, "", str, NULL); + g_free(str); +} + +static void grab_who(CLIENT_REC *client, const char *channel) +{ + GString *arg; + char **list, **tmp; + int count; + + /* /WHO a,b,c may respond with either one "a,b,c End of WHO" message + or three different "a End of WHO", "b End of WHO", .. messages */ + list = g_strsplit(channel, ",", -1); + + arg = g_string_new(channel); + + for (tmp = list, count = 0; *tmp != NULL; tmp++, count++) { + if (g_strcmp0(*tmp, "0") == 0) { + /* /who 0 displays everyone */ + **tmp = '*'; + } + + g_string_append_c(arg, ' '); + g_string_append(arg, *tmp); + } + + proxy_redirect_event(client, "who", + client->server->one_endofwho ? 1 : count, + arg->str, -1); + + g_strfreev(list); + g_string_free(arg, TRUE); +} + +static void handle_client_connect_cmd(CLIENT_REC *client, + const char *cmd, const char *args) +{ + const char *password; + + password = settings_get_str("irssiproxy_password"); + + if (g_strcmp0(cmd, "PASS") == 0) { + const char *args_pass; + + if (!client->multiplex) { + args_pass = args; + } else { + IRC_CHATNET_REC *chatnet; + char *tag; + const char *tag_end; + + if ((tag_end = strchr(args, ':')) != NULL) { + args_pass = tag_end + 1; + } else { + tag_end = args + strlen(args); + args_pass = ""; + } + + tag = g_strndup(args, tag_end - args); + chatnet = IRC_CHATNET(chatnet_find(tag)); + + if (!chatnet) { + /* an invalid network was specified */ + remove_client(client); + g_free(tag); + return; + } + + client->server = IRC_SERVER(server_find_chatnet(tag)); + g_free(client->proxy_address); + client->proxy_address = g_strdup_printf("%s.proxy", tag); + g_free(tag); + } + + if (g_strcmp0(password, args_pass) != 0) { + /* wrong password! */ + remove_client(client); + return; + } + client->pass_sent = TRUE; + } else if (g_strcmp0(cmd, "NICK") == 0) { + g_free_not_null(client->nick); + client->nick = g_strdup(args); + } else if (g_strcmp0(cmd, "USER") == 0) { + client->user_sent = TRUE; + } + + if (client->nick != NULL && client->user_sent) { + if ((*password != '\0' || client->multiplex) && !client->pass_sent) { + /* client didn't send us PASS, kill it */ + remove_client(client); + } else { + signal_emit("proxy client connected", 1, client); + printtext(client->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Client %s connected", + client->addr); + client->connected = TRUE; + proxy_dump_data(client); + } + } +} + +static void handle_client_cmd(CLIENT_REC *client, char *cmd, char *args, + const char *data) +{ + GSList *tmp; + if (!client->connected) { + handle_client_connect_cmd(client, cmd, args); + return; + } + + if (g_strcmp0(cmd, "QUIT") == 0) { + remove_client(client); + return; + } + + if (g_strcmp0(cmd, "PING") == 0) { + /* Reply to PING, if the target parameter is either + proxy_adress, our own nick or empty. */ + char *params, *origin, *target; + + params = event_get_params(args, 2, &origin, &target); + if (*target == '\0' || + g_ascii_strcasecmp(target, client->proxy_address) == 0 || + g_ascii_strcasecmp(target, client->nick) == 0) { + proxy_outdata(client, ":%s PONG %s :%s\r\n", + client->proxy_address, + client->proxy_address, origin); + g_free(params); + return; + } + g_free(params); + } + + if (g_strcmp0(cmd, "PROXY") == 0) { + if (g_ascii_strcasecmp(args, "CTCP ON") == 0) { + /* client wants all ctcps */ + client->want_ctcp = 1; + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + if (g_ascii_strcasecmp(client->listen->ircnet, rec->listen->ircnet) == 0 && + /* kludgy way to check if the clients aren't the same */ + client->recv_tag != rec->recv_tag) { + if (rec->want_ctcp == 1) + proxy_outdata(rec, ":%s NOTICE %s :Another client is now receiving CTCPs sent to %s\r\n", + rec->proxy_address, rec->nick, rec->listen->ircnet); + rec->want_ctcp = 0; + } + + } + proxy_outdata(client, ":%s NOTICE %s :You're now receiving CTCPs sent to %s\r\n", + client->proxy_address, client->nick, client->listen->ircnet); + } else if (g_ascii_strcasecmp(args, "CTCP OFF") == 0) { + /* client wants proxy to handle all ctcps */ + client->want_ctcp = 0; + proxy_outdata(client, ":%s NOTICE %s :Proxy is now handling itself CTCPs sent to %s\r\n", + client->proxy_address, client->nick, client->listen->ircnet); + } else { + signal_emit("proxy client command", 3, client, args, data); + } + return; + } + + if (client->server == NULL || !client->server->connected) { + proxy_outdata(client, ":%s NOTICE %s :Not connected to server\r\n", + client->proxy_address, client->nick); + return; + } + + /* check if the command could be redirected */ + if (g_strcmp0(cmd, "WHO") == 0) + grab_who(client, args); + else if (g_strcmp0(cmd, "WHOWAS") == 0) + proxy_redirect_event(client, "whowas", 1, args, -1); + else if (g_strcmp0(cmd, "WHOIS") == 0) { + char *p; + + /* convert dots to spaces */ + for (p = args; *p != '\0'; p++) + if (*p == ',') *p = ' '; + + proxy_redirect_event(client, "whois", 1, args, TRUE); + } else if (g_strcmp0(cmd, "ISON") == 0) + proxy_redirect_event(client, "ison", 1, args, -1); + else if (g_strcmp0(cmd, "USERHOST") == 0) + proxy_redirect_event(client, "userhost", 1, args, -1); + else if (g_strcmp0(cmd, "MODE") == 0) { + /* convert dots to spaces */ + char *slist, *str, mode, *p; + int argc; + + p = strchr(args, ' '); + if (p != NULL) *p++ = '\0'; + mode = p == NULL ? '\0' : *p; + + slist = g_strdup(args); + argc = 1; + for (p = slist; *p != '\0'; p++) { + if (*p == ',') { + *p = ' '; + argc++; + } + } + + /* get channel mode / bans / exception / invite list */ + str = g_strdup_printf("%s %s", args, slist); + switch (mode) { + case '\0': + proxy_redirect_event(client, "mode channel", argc, str, -1); + break; + case 'b': + proxy_redirect_event(client, "mode b", argc, str, -1); + break; + case 'e': + proxy_redirect_event(client, "mode e", argc, str, -1); + break; + case 'I': + proxy_redirect_event(client, "mode I", argc, str, -1); + break; + } + g_free(str); + g_free(slist); + } else if (g_strcmp0(cmd, "PRIVMSG") == 0) { + /* send the message to other clients as well */ + char *params, *target, *msg; + + params = event_get_params(args, 2 | PARAM_FLAG_GETREST, + &target, &msg); + proxy_outserver_all_except(client, "PRIVMSG %s", args); + + ignore_next = TRUE; + if (*msg != '\001' || msg[strlen(msg)-1] != '\001') { + signal_emit(server_ischannel(SERVER(client->server), target) ? + "message own_public" : "message own_private", 4, + client->server, msg, target, target); + } else if (strncmp(msg+1, "ACTION ", 7) == 0) { + /* action */ + msg[strlen(msg)-1] = '\0'; + signal_emit("message irc own_action", 3, + client->server, msg+8, target); + } else { + /* CTCP */ + char *p; + + msg[strlen(msg)-1] = '\0'; + p = strchr(msg, ' '); + if (p != NULL) *p++ = '\0'; else p = ""; + + signal_emit("message irc own_ctcp", 4, + client->server, msg+1, p, target); + } + ignore_next = FALSE; + g_free(params); + } else if (g_strcmp0(cmd, "PING") == 0) { + proxy_redirect_event(client, "ping", 1, NULL, TRUE); + } else if (g_strcmp0(cmd, "AWAY") == 0) { + /* set the away reason */ + if (args != NULL) { + g_free(client->server->away_reason); + client->server->away_reason = g_strdup(args); + } + } + + irc_send_cmd(client->server, data); +} + +static void sig_listen_client(CLIENT_REC *client) +{ + char *str, *cmd, *args; + int ret; + + g_return_if_fail(client != NULL); + + while (g_slist_find(proxy_clients, client) != NULL) { + ret = net_sendbuffer_receive_line(client->handle, &str, 1); + if (ret == -1) { + /* connection lost */ + remove_client(client); + break; + } + + if (ret == 0) + break; + + cmd = g_strdup(str); + args = strchr(cmd, ' '); + if (args != NULL) *args++ = '\0'; else args = ""; + if (*args == ':') args++; + ascii_strup(cmd); + + handle_client_cmd(client, cmd, args, str); + + g_free(cmd); + } +} + +static void sig_listen(LISTEN_REC *listen) +{ + CLIENT_REC *rec; + IPADDR ip; + NET_SENDBUF_REC *sendbuf; + GIOChannel *handle; + char host[MAX_IP_LEN]; + int port; + char *addr; + + g_return_if_fail(listen != NULL); + + /* accept connection */ + if (listen->port) { + handle = net_accept(listen->handle, &ip, &port); + if (handle == NULL) + return; + net_ip2host(&ip, host); + addr = g_strdup_printf("%s:%d", host, port); + } else { + /* no port => this is a unix socket */ + handle = net_accept_unix(listen->handle); + if (handle == NULL) + return; + addr = g_strdup("(local)"); + } + + sendbuf = net_sendbuffer_create(handle, 0); + rec = g_new0(CLIENT_REC, 1); + rec->listen = listen; + rec->handle = sendbuf; + rec->addr = addr; + if (g_strcmp0(listen->ircnet, "?") == 0) { + rec->multiplex = TRUE; + rec->proxy_address = g_strdup("multiplex.proxy"); + rec->server = NULL; + } else if (g_strcmp0(listen->ircnet, "*") == 0) { + rec->proxy_address = g_strdup("irc.proxy"); + rec->server = servers == NULL ? NULL : IRC_SERVER(servers->data); + } else { + rec->proxy_address = g_strdup_printf("%s.proxy", listen->ircnet); + rec->server = servers == NULL ? NULL : + IRC_SERVER(server_find_chatnet(listen->ircnet)); + } + rec->recv_tag = i_input_add(handle, I_INPUT_READ, (GInputFunction) sig_listen_client, rec); + + proxy_clients = g_slist_prepend(proxy_clients, rec); + listen->clients = g_slist_prepend(listen->clients, rec); + + signal_emit("proxy client connecting", 1, rec); + printtext(rec->server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: New client %s on port %s (%s)", + rec->addr, listen->port_or_path, listen->ircnet); +} + +static void sig_incoming(IRC_SERVER_REC *server, const char *line) +{ + g_return_if_fail(line != NULL); + + /* send server event to all clients */ + g_string_printf(next_line, "%s\r\n", line); +} + +static void sig_server_event(IRC_SERVER_REC *server, const char *line, + const char *nick, const char *address) +{ + GSList *tmp; + void *client; + const char *signal; + char *event, *args; + int redirected; + + g_return_if_fail(line != NULL); + if (!IS_IRC_SERVER(server)) + return; + + /* get command.. */ + event = g_strconcat("event ", line, NULL); + args = strchr(event+6, ' '); + if (args != NULL) *args++ = '\0'; else args = ""; + while (*args == ' ') args++; + ascii_strdown(event); + + signal = server_redirect_peek_signal(server, nick, event, args, &redirected); + if ((signal != NULL && strncmp(signal, "proxy ", 6) != 0) || + (signal == NULL && redirected)) { + /* we want to send this to one client (or proxy itself) only */ + /* proxy only */ + g_free(event); + return; + } + + if (signal != NULL) { + server_redirect_get_signal(server, nick, event, args); + if (sscanf(signal+6, "%p", &client) == 1) { + /* send it to specific client only */ + if (g_slist_find(proxy_clients, client) != NULL) + net_sendbuffer_send(((CLIENT_REC *) client)->handle, next_line->str, next_line->len); + g_free(event); + signal_stop(); + return; + } + } + + if (g_strcmp0(event, "event privmsg") == 0 && + strstr(args, " :\001") != NULL && + strstr(args, " :\001ACTION") == NULL) { + /* CTCP - either answer ourself or forward it to one client */ + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + if (rec->want_ctcp == 1) { + /* only CTCP for the chatnet where client is connected to will be forwarded */ + if (strstr(rec->proxy_address, server->connrec->chatnet) != NULL) { + net_sendbuffer_send(rec->handle, + next_line->str, next_line->len); + signal_stop(); + } + } + } + g_free(event); + return; + } + + if (g_strcmp0(event, "event ping") == 0 || + g_strcmp0(event, "event pong") == 0) { + /* We want to answer ourself to PINGs and CTCPs. + Also hide PONGs from clients. */ + g_free(event); + return; + } + + /* send the data to clients.. */ + proxy_outdata_all(server, "%s", next_line->str); + + g_free(event); +} + +static void event_connected(IRC_SERVER_REC *server) +{ + GSList *tmp; + const char *chatnet; + + if (!IS_IRC_SERVER(server)) + return; + + chatnet = server->connrec->chatnet; + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + if (rec->connected && rec->server == NULL && + (g_strcmp0(rec->listen->ircnet, "*") == 0 || + (chatnet != NULL && + strstr(rec->proxy_address, chatnet) == rec->proxy_address && + rec->proxy_address[strlen(chatnet)] == '.'))) { + proxy_outdata(rec, ":%s NOTICE %s :Connected to server\r\n", + rec->proxy_address, rec->nick); + rec->server = server; + proxy_client_reset_nick(rec); + } + } +} + +static void proxy_server_disconnected(CLIENT_REC *client, + IRC_SERVER_REC *server) +{ + GSList *tmp; + + proxy_outdata(client, ":%s NOTICE %s :Connection lost to server %s\r\n", + client->proxy_address, client->nick, + server->connrec->address); + + for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { + IRC_CHANNEL_REC *rec = tmp->data; + + proxy_outserver(client, "PART %s :Connection lost to server", + rec->name); + } +} + +static void sig_server_disconnected(IRC_SERVER_REC *server) +{ + GSList *tmp; + + if (!IS_IRC_SERVER(server)) + return; + + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + if (rec->connected && rec->server == server) { + proxy_server_disconnected(rec, server); + rec->server = NULL; + } + } +} + +static void event_nick(IRC_SERVER_REC *server, const char *data, + const char *orignick) +{ + GSList *tmp; + + if (!IS_IRC_SERVER(server)) + return; + + if (g_ascii_strcasecmp(orignick, server->nick) != 0) + return; + + if (*data == ':') data++; + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + if (rec->connected && rec->server == server) { + g_free(rec->nick); + rec->nick = g_strdup(data); + } + } +} + +static void sig_message_own_public(IRC_SERVER_REC *server, const char *msg, + const char *target) +{ + if (!IS_IRC_SERVER(server)) + return; + + if (!ignore_next) + proxy_outserver_all(server, "PRIVMSG %s :%s", target, msg); +} + +static void sig_message_own_private(IRC_SERVER_REC *server, const char *msg, + const char *target, const char *origtarget) +{ + if (!IS_IRC_SERVER(server)) + return; + + if (!ignore_next) + proxy_outserver_all(server, "PRIVMSG %s :%s", target, msg); +} + +static void sig_message_own_action(IRC_SERVER_REC *server, const char *msg, + const char *target) +{ + if (!IS_IRC_SERVER(server)) + return; + + if (!ignore_next) + proxy_outserver_all(server, "PRIVMSG %s :\001ACTION %s\001", target, msg); +} + +static LISTEN_REC *find_listen(const char *ircnet, int port, const char *port_or_path) +{ + GSList *tmp; + + for (tmp = proxy_listens; tmp != NULL; tmp = tmp->next) { + LISTEN_REC *rec = tmp->data; + + if ((port + ? /* a tcp port */ + rec->port == port + : /* a unix socket path */ + g_strcmp0(rec->port_or_path, port_or_path) == 0 + ) && + g_ascii_strcasecmp(rec->ircnet, ircnet) == 0) + return rec; + } + + return NULL; +} + +static void add_listen(const char *ircnet, int port, const char *port_or_path) +{ + LISTEN_REC *rec; + IPADDR ip4, ip6, *my_ip; + GIOChannel *handle; + + if (*port_or_path == '\0' || port < 0 || *ircnet == '\0') + return; + + if (port == 0) { + /* listening on a unix socket */ + handle = net_listen_unix(port_or_path); + } else { + /* bind to specific host/ip? */ + my_ip = NULL; + if (*settings_get_str("irssiproxy_bind") != '\0') { + if (net_gethostbyname(settings_get_str("irssiproxy_bind"), + &ip4, &ip6) != 0) { + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, + "Proxy: can not resolve '%s' - aborting", + settings_get_str("irssiproxy_bind")); + return; + } + + my_ip = ip6.family == 0 ? &ip4 : ip4.family == 0 || + settings_get_bool("resolve_prefer_ipv6") ? &ip6 : &ip4; + } + handle = net_listen(my_ip, &port); + } + + if (handle == NULL) { + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, + "Proxy: Listen in port %s failed: %s", + port_or_path, g_strerror(errno)); + return; + } + + rec = g_new0(LISTEN_REC, 1); + rec->handle = handle; + rec->ircnet = g_strdup(ircnet); + rec->port = port; + rec->port_or_path = g_strdup(port_or_path); + + rec->tag = i_input_add(rec->handle, I_INPUT_READ, (GInputFunction) sig_listen, rec); + + proxy_listens = g_slist_append(proxy_listens, rec); +} + +static void remove_listen(LISTEN_REC *rec) +{ + proxy_listens = g_slist_remove(proxy_listens, rec); + + while (rec->clients != NULL) + remove_client(rec->clients->data); + + /* remove unix socket because bind wants to (re)create it */ + if (rec->port == 0) + unlink(rec->port_or_path); + + net_disconnect(rec->handle); + g_source_remove(rec->tag); + g_free(rec->port_or_path); + g_free(rec->ircnet); + g_free(rec); +} + +static void read_settings(void) +{ + LISTEN_REC *rec; + GSList *remove_listens = NULL; + GSList *add_listens = NULL; + char **ports, **tmp, *ircnet, *port_or_path; + int portnum; + + remove_listens = g_slist_copy(proxy_listens); + + ports = g_strsplit(settings_get_str("irssiproxy_ports"), " ", -1); + for (tmp = ports; *tmp != NULL; tmp++) { + ircnet = *tmp; + port_or_path = strchr(ircnet, '='); + if (port_or_path == NULL) + continue; + + *port_or_path++ = '\0'; + if (is_all_digits(port_or_path)) { + portnum = atoi(port_or_path); + if (portnum <= 0) + continue; + } else { + portnum = 0; + } + + rec = find_listen(ircnet, portnum, port_or_path); + if (rec == NULL) { + rec = g_new0(LISTEN_REC, 1); + rec->ircnet = ircnet; /* borrow */ + rec->port = portnum; + rec->port_or_path = port_or_path; /* borrow */ + add_listens = g_slist_prepend(add_listens, rec); + } else { + /* remove from the list of listens to remove == keep it */ + remove_listens = g_slist_remove(remove_listens, rec); + } + } + + while (remove_listens != NULL) { + remove_listen(remove_listens->data); + remove_listens = g_slist_remove(remove_listens, remove_listens->data); + } + + while (add_listens != NULL) { + rec = add_listens->data; + add_listen(rec->ircnet, rec->port, rec->port_or_path); + add_listens = g_slist_remove(add_listens, rec); + g_free(rec); + } + + g_strfreev(ports); +} + +static void sig_dump(CLIENT_REC *client, const char *data) +{ + g_return_if_fail(client != NULL); + g_return_if_fail(data != NULL); + + proxy_outdata(client, data); +} + +void proxy_listen_init(void) +{ + if (enabled) { + return; + } + enabled = TRUE; + + next_line = g_string_new(NULL); + + proxy_clients = NULL; + proxy_listens = NULL; + read_settings(); + + signal_add("server incoming", (SIGNAL_FUNC) sig_incoming); + signal_add("server event", (SIGNAL_FUNC) sig_server_event); + signal_add("event connected", (SIGNAL_FUNC) event_connected); + signal_add("server disconnected", (SIGNAL_FUNC) sig_server_disconnected); + signal_add_first("event nick", (SIGNAL_FUNC) event_nick); + signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public); + signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private); + signal_add("message irc own_action", (SIGNAL_FUNC) sig_message_own_action); + signal_add("setup changed", (SIGNAL_FUNC) read_settings); + + signal_add("proxy client dump", (SIGNAL_FUNC) sig_dump); +} + +void proxy_listen_deinit(void) +{ + if (!enabled) { + return; + } + enabled = FALSE; + + while (proxy_listens != NULL) + remove_listen(proxy_listens->data); + g_string_free(next_line, TRUE); + + signal_remove("server incoming", (SIGNAL_FUNC) sig_incoming); + signal_remove("server event", (SIGNAL_FUNC) sig_server_event); + signal_remove("event connected", (SIGNAL_FUNC) event_connected); + signal_remove("server disconnected", (SIGNAL_FUNC) sig_server_disconnected); + signal_remove("event nick", (SIGNAL_FUNC) event_nick); + signal_remove("message own_public", (SIGNAL_FUNC) sig_message_own_public); + signal_remove("message own_private", (SIGNAL_FUNC) sig_message_own_private); + signal_remove("message irc own_action", (SIGNAL_FUNC) sig_message_own_action); + signal_remove("setup changed", (SIGNAL_FUNC) read_settings); + + signal_remove("proxy client dump", (SIGNAL_FUNC) sig_dump); +} diff --git a/src/irc/proxy/meson.build b/src/irc/proxy/meson.build new file mode 100644 index 0000000..30ac90a --- /dev/null +++ b/src/irc/proxy/meson.build @@ -0,0 +1,21 @@ +# this file is part of irssi + +shared_module('irc_proxy', + files( + 'dump.c', + 'listen.c', + 'proxy.c', + ) + + [ irssi_version_h ], + include_directories : rootinc, + implicit_include_directories : false, + name_suffix : module_suffix, + install : true, + install_dir : moduledir, + dependencies : dep, +) + +# noinst_headers = files( +# 'module.h', +# 'proxy.h', +# ) diff --git a/src/irc/proxy/module.h b/src/irc/proxy/module.h new file mode 100644 index 0000000..b6ad3a4 --- /dev/null +++ b/src/irc/proxy/module.h @@ -0,0 +1,26 @@ +#include <irssi/src/common.h> + +#define MODULE_NAME "proxy" + +#include <irssi/src/core/network.h> +#include <irssi/src/irc/core/irc.h> +#include <irssi/src/irc/core/irc-servers.h> + +#include <irssi/src/irc/proxy/proxy.h> + +extern GSList *proxy_listens; +extern GSList *proxy_clients; + +void proxy_listen_init(void); +void proxy_listen_deinit(void); + +void proxy_settings_init(void); + +void proxy_dump_data(CLIENT_REC *client); +void proxy_client_reset_nick(CLIENT_REC *client); + +void proxy_outdata(CLIENT_REC *client, const char *data, ...); +void proxy_outdata_all(IRC_SERVER_REC *server, const char *data, ...); +void proxy_outserver(CLIENT_REC *client, const char *data, ...); +void proxy_outserver_all(IRC_SERVER_REC *server, const char *data, ...); +void proxy_outserver_all_except(CLIENT_REC *client, const char *data, ...); diff --git a/src/irc/proxy/proxy.c b/src/irc/proxy/proxy.c new file mode 100644 index 0000000..d32b600 --- /dev/null +++ b/src/irc/proxy/proxy.c @@ -0,0 +1,116 @@ +/* + proxy.c : irc proxy + + Copyright (C) 1999-2001 Timo Sirainen + + 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 <irssi/src/core/signals.h> +#include <irssi/src/core/settings.h> +#include <irssi/src/core/levels.h> + +#include <irssi/src/fe-common/core/printtext.h> + +/* SYNTAX: IRSSIPROXY STATUS */ +static void cmd_irssiproxy_status(const char *data, IRC_SERVER_REC *server) +{ + GSList *tmp; + + if (!settings_get_bool("irssiproxy")) { + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy is currently disabled"); + return; + } + + + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + "Proxy: Currently connected clients: %d", + g_slist_length(proxy_clients)); + + for (tmp = proxy_clients; tmp != NULL; tmp = tmp->next) { + CLIENT_REC *rec = tmp->data; + + printtext(server, NULL, MSGLEVEL_CLIENTNOTICE, + " %s connect%s to %s (%s)", + rec->addr, + rec->connected ? "ed" : "ing", + rec->listen->port_or_path, rec->listen->ircnet); + } +} + +/* SYNTAX: IRSSIPROXY */ +static void cmd_irssiproxy(const char *data, IRC_SERVER_REC *server, void *item) +{ + if (*data == '\0') { + cmd_irssiproxy_status(data, server); + return; + } + + command_runsub("irssiproxy", data, server, item); +} + +static void irc_proxy_setup_changed(void) +{ + if (settings_get_bool("irssiproxy")) { + proxy_listen_init(); + } else { + proxy_listen_deinit(); + } +} + +void irc_proxy_init(void) +{ + settings_add_str("irssiproxy", "irssiproxy_ports", ""); + settings_add_str("irssiproxy", "irssiproxy_password", ""); + settings_add_str("irssiproxy", "irssiproxy_bind", ""); + settings_add_bool("irssiproxy", "irssiproxy", TRUE); + + if (*settings_get_str("irssiproxy_password") == '\0') { + /* no password - bad idea! */ + signal_emit("gui dialog", 2, "warning", + "Warning!! Password not specified, everyone can " + "use this proxy! Use /set irssiproxy_password " + "<password> to set it"); + } + if (*settings_get_str("irssiproxy_ports") == '\0') { + signal_emit("gui dialog", 2, "warning", + "No proxy ports specified. Use /SET " + "irssiproxy_ports <ircnet>=<port> <ircnet2>=<port2> " + "... to set them."); + } + + command_bind("irssiproxy", NULL, (SIGNAL_FUNC) cmd_irssiproxy); + command_bind("irssiproxy status", NULL, (SIGNAL_FUNC) cmd_irssiproxy_status); + + signal_add_first("setup changed", (SIGNAL_FUNC) irc_proxy_setup_changed); + + if (settings_get_bool("irssiproxy")) { + proxy_listen_init(); + } + settings_check(); + module_register("proxy", "irc"); +} + +void irc_proxy_deinit(void) +{ + proxy_listen_deinit(); +} + +void irc_proxy_abicheck(int *version) +{ + *version = IRSSI_ABI_VERSION; +} diff --git a/src/irc/proxy/proxy.h b/src/irc/proxy/proxy.h new file mode 100644 index 0000000..5b3d25f --- /dev/null +++ b/src/irc/proxy/proxy.h @@ -0,0 +1,36 @@ +#ifndef IRSSI_IRC_PROXY_PROXY_H +#define IRSSI_IRC_PROXY_PROXY_H + +#include <irssi/src/common.h> + +#include <irssi/src/core/network.h> +#include <irssi/src/irc/core/irc.h> +#include <irssi/src/irc/core/irc-servers.h> + +typedef struct { + int port; + char *port_or_path; + char *ircnet; + + int tag; + GIOChannel *handle; + + GSList *clients; + +} LISTEN_REC; + +typedef struct { + char *nick, *addr; + NET_SENDBUF_REC *handle; + int recv_tag; + char *proxy_address; + LISTEN_REC *listen; + IRC_SERVER_REC *server; + unsigned int pass_sent:1; + unsigned int user_sent:1; + unsigned int connected:1; + unsigned int want_ctcp:1; + unsigned int multiplex:1; +} CLIENT_REC; + +#endif |