1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
//=============================================================================
//
// File : KviProxyDataBase.cpp
// Creation date : Sat Jul 22 2000 18:23:23 by Szymon Stefanek
//
// This file is part of the KVirc irc client distribution
// Copyright (C) 2000-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.
//
//=============================================================================
#include "KviProxyDataBase.h"
#include "KviConfigurationFile.h"
#include "KviProxy.h"
KviProxyDataBase::KviProxyDataBase()
{
m_pProxyList = new KviPointerList<KviProxy>;
m_pProxyList->setAutoDelete(true);
m_pCurrentProxy = 0;
}
KviProxyDataBase::~KviProxyDataBase()
{
delete m_pProxyList;
}
void KviProxyDataBase::updateProxyIp(const char * proxy,const char * ip)
{
for(KviProxy * prx = m_pProxyList->first();prx;prx = m_pProxyList->next())
{
if(QString::compare(proxy,prx->m_szHostname,Qt::CaseInsensitive))
{
prx->m_szIp = ip;
return;
}
}
}
KviProxy * KviProxyDataBase::findProxy(const KviProxy * pProxy, bool bName)
{
for(KviProxy *p=m_pProxyList->first();p;p=m_pProxyList->next())
{
if(bName)
{
if(QString::compare(p->m_szHostname,pProxy->m_szHostname,Qt::CaseInsensitive)) return p;
} else {
if(QString::compare(p->m_szHostname,pProxy->m_szHostname,Qt::CaseInsensitive) &&
(p->m_uPort == pProxy->m_uPort) &&
(p->protocol() == pProxy->protocol()) &&
(p->isIPv6() == pProxy->isIPv6())) return p;
}
}
return 0;
}
void KviProxyDataBase::clear()
{
delete m_pProxyList;
m_pProxyList = new KviPointerList<KviProxy>;
m_pProxyList->setAutoDelete(true);
m_pCurrentProxy = 0;
}
void KviProxyDataBase::load(const QString &filename)
{
clear();
KviConfigurationFile cfg(filename,KviConfigurationFile::Read);
unsigned int nEntries = cfg.readUIntEntry("Entries",0);
for(unsigned int i=0;i<nEntries;i++)
{
KviProxy * p = new KviProxy();
KviCString tmp(KviCString::Format,"%u_Hostname",i);
p->m_szHostname = cfg.readEntry(tmp.ptr(),"proxy.example.net");
tmp.sprintf("%u_Port",i);
p->m_uPort = cfg.readUIntEntry(tmp.ptr(),7000);
tmp.sprintf("%u_Ip",i);
p->m_szIp = cfg.readEntry(tmp.ptr(),"");
tmp.sprintf("%u_User",i);
p->m_szUser = cfg.readEntry(tmp.ptr(),"");
tmp.sprintf("%u_Pass",i);
p->m_szPass = cfg.readEntry(tmp.ptr(),"");
tmp.sprintf("%u_Protocol",i);
KviCString type = cfg.readEntry(tmp.ptr(),"SOCKSv4");
p->setNamedProtocol(type.ptr());
tmp.sprintf("%u_IsIPv6",i);
p->m_bIsIPv6 = cfg.readBoolEntry(tmp.ptr(),false);
tmp.sprintf("%u_Current",i);
if(cfg.readBoolEntry(tmp.ptr(),false))m_pCurrentProxy = p;
m_pProxyList->append(p);
}
if(!m_pCurrentProxy)m_pCurrentProxy = m_pProxyList->first();
}
void KviProxyDataBase::save(const QString &filename)
{
KviConfigurationFile cfg(filename,KviConfigurationFile::Write);
cfg.clear();
cfg.writeEntry("Entries",m_pProxyList->count());
int i=0;
for(KviProxy * p=m_pProxyList->first();p;p=m_pProxyList->next())
{
KviCString tmp(KviCString::Format,"%u_Hostname",i);
cfg.writeEntry(tmp.ptr(),p->m_szHostname);
tmp.sprintf("%u_Port",i);
cfg.writeEntry(tmp.ptr(),p->m_uPort);
tmp.sprintf("%u_Ip",i);
cfg.writeEntry(tmp.ptr(),p->m_szIp);
tmp.sprintf("%u_User",i);
cfg.writeEntry(tmp.ptr(),p->m_szUser);
tmp.sprintf("%u_Pass",i);
cfg.writeEntry(tmp.ptr(),p->m_szPass);
tmp.sprintf("%u_Protocol",i);
KviCString type;
switch(p->m_protocol)
{
case KviProxy::Socks5: type = "SOCKSv5"; break;
case KviProxy::Http: type = "HTTP"; break;
default: type = "SOCKSv4"; break;
}
cfg.writeEntry(tmp.ptr(),type.ptr());
tmp.sprintf("%u_IsIPv6",i);
cfg.writeEntry(tmp.ptr(),p->m_bIsIPv6);
tmp.sprintf("%u_Current",i);
if(m_pCurrentProxy == p)cfg.writeEntry(tmp.ptr(),true);
i++;
}
}
|