From c601b5a27f74b16158adafe429faefbe573e64a2 Mon Sep 17 00:00:00 2001 From: Szymon Tomasz Stefanek Date: Sat, 1 Jan 2011 20:19:56 +0000 Subject: The big rename for modules. Still some details remaining. git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5284 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/dcc/DccUtils.cpp | 170 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 src/modules/dcc/DccUtils.cpp (limited to 'src/modules/dcc/DccUtils.cpp') diff --git a/src/modules/dcc/DccUtils.cpp b/src/modules/dcc/DccUtils.cpp new file mode 100644 index 000000000..6d794a9de --- /dev/null +++ b/src/modules/dcc/DccUtils.cpp @@ -0,0 +1,170 @@ +//============================================================================= +// +// File : DccUtils.cpp +// Creation date : Tue Jul 23 02:54:44 2002 GMT by Szymon Stefanek +// +// This file is part of the KVIrc irc client distribution +// Copyright (C) 2002-2010 Szymon Stefanek (pragma at kvirc dot net) +// +// 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 opinion) 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. +// +//============================================================================= + +#define _UTILS_CPP_ + +#include "DccUtils.h" + +#include "KviOptions.h" +#include "KviLocale.h" +#include "KviNetUtils.h" +#include "KviIrcSocket.h" +#include "KviIrcLink.h" +#include "KviQString.h" + +/* +bool dcc_module_get_listen_ip_address(KviCommand *c,KviConsoleWindow * pConsole,QString &szListenIp) +{ + // + // Find an interface suitable for listening.... + // Either from user options or from the current connection... + // + + if(KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault)) + { + KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).trimmed(); + if(!KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).isEmpty()) + { + if(kvi_isValidStringIp(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data())) + { + if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),"0.0.0.0")) + { + // Try to find the first available IPv4 interface + if(!kvi_getLocalHostAddress(szListenIp)) + { + if(c)c->warning(__tr2qs_ctx("Can't retrieve a suitable local IPV4 address","dcc"), + KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()); + return false; + } + } else { + szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface); + } + return true; + } +#ifdef COMPILE_IPV6_SUPPORT + if(kvi_isValidStringIPv6(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data())) + { + szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface); + } else { +#endif + if(!kvi_getInterfaceAddress(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data(),szListenIp)) + { + KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false; + if(c)c->warning(__tr2qs_ctx("Can't listen on default interface '%s': fix it in the options dialog, disabling the option (so the next dcc will work)","dcc"), + KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()); + return false; + } +#ifdef COMPILE_IPV6_SUPPORT + } +#endif + return true; + } else { + // the option was empty.. disable it + KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false; + } + } + + if(pConsole) + { + if(pConsole->isConnected()) + { + //#warning "The IPV6 choice is not OK here.... and maybe allow to bind to specified ports" + pConsole->socket()->getLocalHostIp(szListenIp,pConsole->isIPv6Connection()); + } else { + szListenIp = "0.0.0.0"; // huh ? :) + } + } else { + szListenIp = "0.0.0.0"; + } + + return true; +} +*/ + +bool dcc_kvs_get_listen_ip_address(KviKvsModuleCommandCall *c,KviConsoleWindow * pConsole,QString &szListenIp) +{ + // + // Find an interface suitable for listening.... + // Either from user options or from the current connection... + // + + if(KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault)) + { + KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).trimmed(); + if(!KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).isEmpty()) + { + if(KviNetUtils::isValidStringIp(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data())) + { + if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),"0.0.0.0")) + { + // Try to find the first available IPv4 interface + if(!kvi_getLocalHostAddress(szListenIp)) + { + if(c)c->warning(__tr2qs_ctx("Can't retrieve a suitable local IPV4 address","dcc"), + KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()); + return false; + } + } else { + szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface); + } + return true; + } +#ifdef COMPILE_IPV6_SUPPORT + if(KviNetUtils::isValidStringIPv6(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data())) + { + szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface); + } else { +#endif + if(!KviNetUtils::getInterfaceAddress(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),szListenIp)) + { + KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false; + if(c)c->warning(__tr2qs_ctx("Can't listen on default interface '%s': fix it in the options dialog, disabling the option (so the next dcc will work)","dcc"), + KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()); + return false; + } +#ifdef COMPILE_IPV6_SUPPORT + } +#endif + return true; + } else { + // the option was empty.. disable it + KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false; + } + } + + if(pConsole) + { + if(pConsole->isConnected()) + { + //#warning "The IPV6 choice is not OK here.... and maybe allow to bind to specified ports" + pConsole->connection()->link()->socket()->getLocalHostIp(szListenIp,pConsole->isIPv6Connection()); + } else { + szListenIp = "0.0.0.0"; // huh ? :) + } + } else { + szListenIp = "0.0.0.0"; + } + + return true; +} -- cgit v1.3.1-10-gc9f91