r7940 - in /trunk/jabber/src: config.cpp config.h
[email protected] Wed, 20 Oct 2010 19:12:08 -0000
Newsgroups
gmane.network.licq.cvs
Message-ID
<20101020191209.0D121224B80@thejon>
Author: erijo
Date: Thu Oct 21 04:12:08 2010
New Revision: 7940
Log:
Added proxy support to config file
Modified:
trunk/jabber/src/config.cpp
trunk/jabber/src/config.h
Modified: trunk/jabber/src/config.cpp
==============================================================================
--- trunk/jabber/src/config.cpp (original)
+++ trunk/jabber/src/config.cpp Thu Oct 21 04:12:08 2010
@@ -26,39 +26,91 @@
using namespace Jabber;
+Config::Proxy::Proxy(const std::string& name) :
+ myName(name),
+ myType(TYPE_DISABLED),
+ myPort(-1)
+{
+ // Empty
+}
+
Config::Config(const std::string& filename) :
+ myFile(NULL),
myPort(-1),
myTlsPolicy(gloox::TLSOptional),
- myResource("Licq")
+ myResource("Licq"),
+ myProxy("default")
{
- Licq::IniFile file(filename);
+ myFile = new Licq::IniFile(filename);
- if (!file.loadFile()) {
- // Save default values
- file.setSection("network");
- file.set("Port", -1);
- file.set("Server", "");
- file.set("TlsPolicy", "optional");
- file.set("Resource", "Licq");
- file.writeFile();
+ if (!myFile->loadFile()) {
+ return;
}
- else {
- std::string value;
- file.setSection("network");
- file.get("Port", myPort, -1);
- file.get("Server", myServer, std::string());
+ std::string value;
+ myFile->setSection("network");
- file.get("TlsPolicy", value, "optional");
- if (value == "disabled")
- myTlsPolicy = gloox::TLSDisabled;
- else if (value == "required")
- myTlsPolicy = gloox::TLSRequired;
+ myFile->get("Server", myServer);
+ myFile->get("Port", myPort, -1);
+
+ myFile->get("TlsPolicy", value, "optional");
+ if (value == "disabled")
+ myTlsPolicy = gloox::TLSDisabled;
+ else if (value == "required")
+ myTlsPolicy = gloox::TLSRequired;
+ else
+ myTlsPolicy = gloox::TLSOptional;
+
+ if (myFile->get("Resource", value) && !value.empty())
+ myResource = value;
+
+ myFile->get("Proxy", value);
+ if (!value.empty() && myFile->setSection("proxy." + value, false))
+ {
+ myProxy.myName = value;
+
+ myFile->get("Type", value, "disabled");
+ if (value == "http")
+ myProxy.myType = Proxy::TYPE_HTTP;
else
- myTlsPolicy = gloox::TLSOptional;
+ myProxy.myType = Proxy::TYPE_DISABLED;
- if (file.get("Resource", value) && !value.empty())
- myResource = value;
+ myFile->get("Server", myProxy.myServer);
+ myFile->get("Port", myProxy.myPort, -1);
+ myFile->get("Username", myProxy.myUsername);
+ myFile->get("Password", myProxy.myPassword);
}
}
+Config::~Config()
+{
+ myFile->setSection("network");
+
+ myFile->set("Server", myServer);
+ myFile->set("Port", myPort);
+
+ if (myTlsPolicy == gloox::TLSDisabled)
+ myFile->set("TlsPolicy", "disabled");
+ else if (myTlsPolicy == gloox::TLSRequired)
+ myFile->set("TlsPolicy", "required");
+ else if (myTlsPolicy == gloox::TLSOptional)
+ myFile->set("TlsPolicy", "optional");
+
+ myFile->set("Resource", myResource);
+
+ myFile->set("Proxy", myProxy.myName);
+ myFile->setSection("proxy." + myProxy.myName);
+
+ if (myProxy.myType == Proxy::TYPE_DISABLED)
+ myFile->set("Type", "disabled");
+ else if (myProxy.myType == Proxy::TYPE_HTTP)
+ myFile->set("Type", "http");
+
+ myFile->set("Server", myProxy.myServer);
+ myFile->set("Port", myProxy.myPort);
+ myFile->set("Username", myProxy.myUsername);
+ myFile->set("Password", myProxy.myPassword);
+
+ myFile->writeFile();
+ delete myFile;
+}
Modified: trunk/jabber/src/config.h
==============================================================================
--- trunk/jabber/src/config.h (original)
+++ trunk/jabber/src/config.h Thu Oct 21 04:12:08 2010
@@ -26,25 +26,48 @@
#include <gloox/gloox.h>
#include <string>
+namespace Licq
+{
+class IniFile;
+}
+
namespace Jabber
{
class Config
{
public:
+ struct Proxy
+ {
+ Proxy(const std::string& name);
+
+ enum Type { TYPE_DISABLED, TYPE_HTTP };
+ std::string myName;
+ Type myType;
+ int myPort;
+ std::string myServer;
+ std::string myUsername;
+ std::string myPassword;
+ };
+
explicit Config(const std::string& filename);
+ ~Config();
// Network settings
int getPort() const { return myPort; }
const std::string& getServer() const { return myServer; }
gloox::TLSPolicy getTlsPolicy() const { return myTlsPolicy; }
const std::string& getResource() const { return myResource; }
+ const Proxy& getProxy() const { return myProxy; }
private:
+ Licq::IniFile* myFile;
+
int myPort;
std::string myServer;
gloox::TLSPolicy myTlsPolicy;
std::string myResource;
+ Proxy myProxy;
};
} // namespace Jabber