~ubuntu-branches/ubuntu/trusty/kvirc/trusty-proposed

« back to all changes in this revision

Viewing changes to src/modules/dcc/utils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : utils.cpp
4
 
//   Creation date : Tue Jul 23 02:54:44 2002 GMT by Szymon Stefanek
5
 
//
6
 
//   This file is part of the KVirc irc client distribution
7
 
//   Copyright (C) 2002-2008 Szymon Stefanek (pragma at kvirc dot net)
8
 
//
9
 
//   This program is FREE software. You can redistribute it and/or
10
 
//   modify it under the terms of the GNU General Public License
11
 
//   as published by the Free Software Foundation; either version 2
12
 
//   of the License, or (at your opinion) any later version.
13
 
//
14
 
//   This program is distributed in the HOPE that it will be USEFUL,
15
 
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
 
//   See the GNU General Public License for more details.
18
 
//
19
 
//   You should have received a copy of the GNU General Public License
20
 
//   along with this program. If not, write to the Free Software Foundation,
21
 
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 
//
23
 
//=============================================================================
24
 
 
25
 
#define _UTILS_CPP_
26
 
 
27
 
#include "utils.h"
28
 
 
29
 
#include "kvi_options.h"
30
 
#include "kvi_locale.h"
31
 
#include "kvi_netutils.h"
32
 
#include "kvi_ircsocket.h"
33
 
#include "kvi_irclink.h"
34
 
#include "kvi_qstring.h"
35
 
 
36
 
/*
37
 
bool dcc_module_get_listen_ip_address(KviCommand *c,KviConsole * pConsole,QString &szListenIp)
38
 
{
39
 
        //
40
 
        // Find an interface suitable for listening....
41
 
        // Either from user options or from the current connection...
42
 
        //
43
 
 
44
 
        if(KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault))
45
 
        {
46
 
                KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).trimmed();
47
 
                if(!KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).isEmpty())
48
 
                {
49
 
                        if(kvi_isValidStringIp(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()))
50
 
                        {
51
 
                                if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),"0.0.0.0"))
52
 
                                {
53
 
                                        // Try to find the first available IPv4 interface
54
 
                                        if(!kvi_getLocalHostAddress(szListenIp))
55
 
                                        {
56
 
                                                if(c)c->warning(__tr2qs_ctx("Can't retrieve a suitable local IPV4 address","dcc"),
57
 
                                                                KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data());
58
 
                                                return false;
59
 
                                        }
60
 
                                } else {
61
 
                                        szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface);
62
 
                                }
63
 
                                return true;
64
 
                        }
65
 
#ifdef COMPILE_IPV6_SUPPORT
66
 
                        if(kvi_isValidStringIPv6(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()))
67
 
                        {
68
 
                                szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface);
69
 
                        } else {
70
 
#endif
71
 
                                if(!kvi_getInterfaceAddress(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data(),szListenIp))
72
 
                                {
73
 
                                        KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false;
74
 
                                        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"),
75
 
                                                        KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data());
76
 
                                        return false;
77
 
                                }
78
 
#ifdef COMPILE_IPV6_SUPPORT
79
 
                        }
80
 
#endif
81
 
                        return true;
82
 
                } else {
83
 
                        // the option was empty.. disable it
84
 
                        KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false;
85
 
                }
86
 
        }
87
 
 
88
 
        if(pConsole)
89
 
        {
90
 
                if(pConsole->isConnected())
91
 
                {
92
 
                        //#warning "The IPV6 choice is not OK here.... and maybe allow to bind to specified ports"
93
 
                        pConsole->socket()->getLocalHostIp(szListenIp,pConsole->isIPv6Connection());
94
 
                } else {
95
 
                        szListenIp = "0.0.0.0"; // huh ? :)
96
 
                }
97
 
        } else {
98
 
                szListenIp = "0.0.0.0";
99
 
        }
100
 
 
101
 
        return true;
102
 
}
103
 
*/
104
 
 
105
 
bool dcc_kvs_get_listen_ip_address(KviKvsModuleCommandCall *c,KviConsole * pConsole,QString &szListenIp)
106
 
{
107
 
        //
108
 
        // Find an interface suitable for listening....
109
 
        // Either from user options or from the current connection...
110
 
        //
111
 
 
112
 
        if(KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault))
113
 
        {
114
 
                KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).trimmed();
115
 
                if(!KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).isEmpty())
116
 
                {
117
 
                        if(KviNetUtils::isValidStringIp(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()))
118
 
                        {
119
 
                                if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),"0.0.0.0"))
120
 
                                {
121
 
                                        // Try to find the first available IPv4 interface
122
 
                                        if(!kvi_getLocalHostAddress(szListenIp))
123
 
                                        {
124
 
                                                if(c)c->warning(__tr2qs_ctx("Can't retrieve a suitable local IPV4 address","dcc"),
125
 
                                                                KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data());
126
 
                                                return false;
127
 
                                        }
128
 
                                } else {
129
 
                                        szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface);
130
 
                                }
131
 
                                return true;
132
 
                        }
133
 
#ifdef COMPILE_IPV6_SUPPORT
134
 
                        if(KviNetUtils::isValidStringIPv6(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()))
135
 
                        {
136
 
                                szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface);
137
 
                        } else {
138
 
#endif
139
 
                                if(!KviNetUtils::getInterfaceAddress(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),szListenIp))
140
 
                                {
141
 
                                        KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false;
142
 
                                        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"),
143
 
                                                        KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data());
144
 
                                        return false;
145
 
                                }
146
 
#ifdef COMPILE_IPV6_SUPPORT
147
 
                        }
148
 
#endif
149
 
                        return true;
150
 
                } else {
151
 
                        // the option was empty.. disable it
152
 
                        KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false;
153
 
                }
154
 
        }
155
 
 
156
 
        if(pConsole)
157
 
        {
158
 
                if(pConsole->isConnected())
159
 
                {
160
 
                        //#warning "The IPV6 choice is not OK here.... and maybe allow to bind to specified ports"
161
 
                        pConsole->connection()->link()->socket()->getLocalHostIp(szListenIp,pConsole->isIPv6Connection());
162
 
                } else {
163
 
                        szListenIp = "0.0.0.0"; // huh ? :)
164
 
                }
165
 
        } else {
166
 
                szListenIp = "0.0.0.0";
167
 
        }
168
 
 
169
 
        return true;
170
 
}