summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-01-08 22:50:47 +0200
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2012-01-08 22:50:47 +0200
commit58002142b6dbd82b719f6389b1fe7f66d84f1a7d (patch)
treeff8a0589c886fb718b677ede86aa1ce9db5e29b3
parentf22c8c9dc67e2f4a41a8382aa9cd2fae10ac8cc3 (diff)
added proxy support to speedtest
-rwxr-xr-xserver/server/server.project4
-rw-r--r--server/server/speedtest.cpp28
-rw-r--r--server/server/speedtest.h7
3 files changed, 36 insertions, 3 deletions
diff --git a/server/server/server.project b/server/server/server.project
index 99e9406..a390dc3 100755
--- a/server/server/server.project
+++ b/server/server/server.project
@@ -21,6 +21,8 @@
<File Name="p_process.h"/>
<File Name="p_xml.cpp"/>
<File Name="p_xml.h"/>
+ <File Name="speedtest.cpp"/>
+ <File Name="speedtest.h"/>
</VirtualDirectory>
<Settings Type="Executable">
<GlobalSettings>
@@ -48,6 +50,7 @@
<Library Value="boost_filesystem"/>
<Library Value="z"/>
<Library Value="PocoFoundation"/>
+ <Library Value="curl"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./$(ProjectName)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes"/>
@@ -91,6 +94,7 @@
<![CDATA[
+
]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="">
diff --git a/server/server/speedtest.cpp b/server/server/speedtest.cpp
index 8a694b8..5c151e1 100644
--- a/server/server/speedtest.cpp
+++ b/server/server/speedtest.cpp
@@ -18,7 +18,7 @@ size_t speedtest::curl_data_callback(void *contents, size_t size, size_t nmemb,
}
-size_t speedtest::test(const char* url)
+size_t speedtest::test(const config::proxy_entry& p)
{
curl = curl_easy_init();
/* if(!curl)
@@ -26,7 +26,31 @@ size_t speedtest::test(const char* url)
memory_struct chunk;
chunk.memory = (char*)malloc(1);
chunk.size = 0;
- curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_URL, test_url.c_str());
+ curl_easy_setopt(curl, CURLOPT_PROXY, p.host.c_str());
+ char port[8];
+ snprintf(port, 7, "%d", p.port);
+ curl_easy_setopt(curl, CURLOPT_PROXYPORT, port);
+ if(!p.password.empty() && !p.login.empty())
+ curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, std::string(p.login + ":" + p.password).c_str());
+ curl_proxytype type = CURLPROXY_HTTP;
+ switch(p.type)
+ {
+ case config::HTTP:
+ type = CURLPROXY_HTTP;
+ break;
+ case config::HTTPS:
+ type = CURLPROXY_HTTP; //is it correct ?
+ curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L); //required for ssl
+ break;
+ case config::SOCKS4:
+ type = CURLPROXY_SOCKS4;
+ break;
+ case config::SOCKS5:
+ type = CURLPROXY_SOCKS5;
+ break;
+ }
+ curl_easy_setopt(curl, CURLOPT_PROXYTYPE, type);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &speedtest::curl_data_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)&chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-speedtest/0.1");
diff --git a/server/server/speedtest.h b/server/server/speedtest.h
index 58b356f..aaed918 100644
--- a/server/server/speedtest.h
+++ b/server/server/speedtest.h
@@ -6,8 +6,12 @@
class speedtest
{
public:
- size_t test(const char* url);
+ size_t test(const config::proxy_entry&);
speedtest() : curl(NULL){}
+ speedtest(const std::string& url) : curl(NULL)
+ {
+ test_url = url;
+ }
private:
struct memory_struct {
char *memory;
@@ -15,6 +19,7 @@ private:
};
static size_t curl_data_callback(void *contents, size_t size, size_t nmemb, void *userp);
boost::timer timer;
+ std::string test_url;
CURL *curl;
};