summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/CurrencyRates/Forex.vcxproj1
-rw-r--r--protocols/CurrencyRates/Forex.vcxproj.filters3
-rw-r--r--protocols/CurrencyRates/docs/Utility/cbrf.xml110
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp77
-rw-r--r--protocols/CurrencyRates/src/CurrencyRatesProviders.cpp2
5 files changed, 193 insertions, 0 deletions
diff --git a/protocols/CurrencyRates/Forex.vcxproj b/protocols/CurrencyRates/Forex.vcxproj
index f65c410009..e833771ab7 100644
--- a/protocols/CurrencyRates/Forex.vcxproj
+++ b/protocols/CurrencyRates/Forex.vcxproj
@@ -31,6 +31,7 @@
<ClCompile Include="src\CurrencyRateChart.cpp" />
<ClCompile Include="src\CurrencyRateInfoDlg.cpp" />
<ClCompile Include="src\CurrencyRatesProviderBase.cpp" />
+ <ClCompile Include="src\CurrencyRatesProviderCbrf.cpp" />
<ClCompile Include="src\CurrencyRatesProviderCurrencyConverter.cpp" />
<ClCompile Include="src\CurrencyRatesProviderExchangeRates.cpp" />
<ClCompile Include="src\CurrencyRatesProviders.cpp" />
diff --git a/protocols/CurrencyRates/Forex.vcxproj.filters b/protocols/CurrencyRates/Forex.vcxproj.filters
index f01423621c..7f9353f2b7 100644
--- a/protocols/CurrencyRates/Forex.vcxproj.filters
+++ b/protocols/CurrencyRates/Forex.vcxproj.filters
@@ -59,6 +59,9 @@
<ClCompile Include="src\CurrencyRatesProviderExchangeRates.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\CurrencyRatesProviderCbrf.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Chart.h">
diff --git a/protocols/CurrencyRates/docs/Utility/cbrf.xml b/protocols/CurrencyRates/docs/Utility/cbrf.xml
new file mode 100644
index 0000000000..d5cdc15aae
--- /dev/null
+++ b/protocols/CurrencyRates/docs/Utility/cbrf.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<Provider>
+ <name>Russian Central Bank Rates API</name>
+ <ref>https://www.cbr-xml-daily.ru/</ref>
+ <url>https://www.cbr-xml-daily.ru/latest.js</url>
+
+<section>
+ <name>Currencies</name>
+ <currencyrate>
+ <id>AMD</id><symbol>AMD</symbol><description>Armenian Dram (AMD)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>ANG</id><symbol>ANG</symbol><description>Netherlands Antillean Gulden (ANG)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>AUD</id><symbol>AUD</symbol><description>Australian Dollar (AUD)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>BGN</id><symbol>BGN</symbol><description>Bulgarian Lev (BGN)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>BRL</id><symbol>BRL</symbol><description>Brazilian Real (BRL)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>BYN</id><symbol>BYN</symbol><description>Belarusian Ruble (BYN)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>CAD</id><symbol>CAD</symbol><description>Canadian Dollar (CAD)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>CHF</id><symbol>CHF</symbol><description>Swiss Franc (CHF)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>CNY</id><symbol>CNY</symbol><description>Chinese Yuan (CNY)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>DKK</id><symbol>DKK</symbol><description>Danish Krone (DKK)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>EGP</id><symbol>EGP</symbol><description>Egyptian Pound (EGP)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>EUR</id><symbol>EUR</symbol><description>Euro (EUR)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>GBP</id><symbol>GBP</symbol><description>British Pound (GBP)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>GEL</id><symbol>GEL</symbol><description>Georgian Lari (GEL)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>HUF</id><symbol>HUF</symbol><description>Hungarian Forint (HUF)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>INR</id><symbol>INR</symbol><description>Indian Rupee (INR)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>JPY</id><symbol>JPY</symbol><description>Japanese Yen (JPY)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>KGS</id><symbol>KGS</symbol><description>Kyrgystani Som (KGS)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>KRW</id><symbol>KRW</symbol><description>South Korean Won (KRW)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>KZT</id><symbol>KZT</symbol><description>Kazakhstani Tenge (KZT)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>NOK</id><symbol>NOK</symbol><description>Norwegian Krone (NOK)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>NZD</id><symbol>NZD</symbol><description>New Zealand Dollar (NZD)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>PLN</id><symbol>PLN</symbol><description>Polish Zloty (PLN)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>RUB</id><symbol>RUB</symbol><description>Russian Ruble (RUB)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>SEK</id><symbol>SEK</symbol><description>Swedish Krona (SEK)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>THB</id><symbol>THB</symbol><description>Thai Baht (THB)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>TJS</id><symbol>TJS</symbol><description>Tajikistani Somoni (TJS)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>TMT</id><symbol>TMT</symbol><description>Turkmenistani Manat (TMT)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>TRY</id><symbol>TRY</symbol><description>Turkish Lira (TRY)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>UAH</id><symbol>UAH</symbol><description>Ukrainian Hryvnia (UAH)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>USD</id><symbol>USD</symbol><description>United States Dollar (USD)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>UZS</id><symbol>UZS</symbol><description>Uzbekistani Som (UZS)</description>
+ </currencyrate>
+ <currencyrate>
+ <id>ZAR</id><symbol>ZAR</symbol><description>South African Rand (ZAR)</description>
+ </currencyrate>
+</section>
+</Provider> \ No newline at end of file
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp
new file mode 100644
index 0000000000..ed7a94bb3a
--- /dev/null
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviderCbrf.cpp
@@ -0,0 +1,77 @@
+#include "stdafx.h"
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// CCurrencyRatesProviderExchangeRates implementation
+
+class CCurrencyRatesProviderCbrf : public CCurrencyRatesProviderBase
+{
+ std::map<CMStringA, double> m_lastRates;
+
+ double GetRate(const CMStringA &id1, const CMStringA &id2) const
+ {
+ if (!id1.IsEmpty() && !id2.IsEmpty()) {
+ auto r1 = m_lastRates.find(id1), r2 = m_lastRates.find(id2);
+ if (r1 != m_lastRates.end() && r2 != m_lastRates.end())
+ return r2->second / r1->second;
+ }
+
+ return 0.0;
+ }
+
+public:
+ CCurrencyRatesProviderCbrf()
+ {}
+
+ void RefreshCurrencyRates(TContacts &anContacts) override
+ {
+ CHTTPSession http;
+ if (true == http.OpenURL(GetURL())) {
+ CMStringW sHTML;
+ if (true == http.ReadResponce(sHTML)) {
+ JSONNode root = JSONNode::parse(_T2A(sHTML));
+ if (!root)
+ return;
+
+ auto rates = root["rates"];
+ if (!rates)
+ return;
+
+ auto &qs = GetSection();
+
+ m_lastRates.clear();
+ for (auto &it : qs.GetCurrencyRates()) {
+ CMStringA id = it.GetID();
+ m_lastRates[id] = (id == "RUB") ? 1.0 : rates[id].as_float();
+ }
+ }
+ }
+
+ for (auto &hContact : anContacts) {
+ double rate = GetRate(g_plugin.getMStringA(hContact, DB_STR_FROM_ID), g_plugin.getMStringA(hContact, DB_STR_TO_ID));
+ if (rate != 0.0) {
+ WriteContactRate(hContact, rate);
+ continue;
+ }
+ SetContactStatus(hContact, ID_STATUS_NA);
+ }
+ }
+
+ double Convert(double dAmount, const CCurrencyRate &from, const CCurrencyRate &to) const override
+ {
+ CMStringA id1 = from.GetID(), id2 = to.GetID();
+ return dAmount * GetRate(id1, id2);
+ }
+
+ wchar_t* GetXmlFilename() const override
+ {
+ return L"cbrf.xml";
+ }
+};
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Module entry point
+
+void InitCbrf()
+{
+ g_apProviders.push(new CCurrencyRatesProviderCbrf());
+}
diff --git a/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp b/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp
index 70d9979b06..5aa6dac52e 100644
--- a/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp
+++ b/protocols/CurrencyRates/src/CurrencyRatesProviders.cpp
@@ -3,6 +3,7 @@
#define LAST_RUN_VERSION "LastRunVersion"
void InitCC();
+void InitCbrf();
void InitExchangeRates();
TCurrencyRatesProviders g_apProviders;
@@ -14,6 +15,7 @@ CCurrencyRatesProviderBase *g_pCurrentProvider = nullptr;
void InitProviders()
{
InitCC();
+ InitCbrf();
InitExchangeRates();
g_pCurrentProvider = FindProvider(g_plugin.getMStringW(DB_STR_PROVIDER));