Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ConfigLoader.cpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * ConfigLoader.cpp
4  *
5  */
6 
7 /************************************************************
8  -----BEGIN PGP SIGNED MESSAGE-----
9  Hash: SHA1
10 
11  * OPEN TRANSACTIONS
12  *
13  * Financial Cryptography and Digital Cash
14  * Library, Protocol, API, Server, CLI, GUI
15  *
16  * -- Anonymous Numbered Accounts.
17  * -- Untraceable Digital Cash.
18  * -- Triple-Signed Receipts.
19  * -- Cheques, Vouchers, Transfers, Inboxes.
20  * -- Basket Currencies, Markets, Payment Plans.
21  * -- Signed, XML, Ricardian-style Contracts.
22  * -- Scripted smart contracts.
23  *
24  * Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
25  *
26  * EMAIL:
28  *
29  * BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
30  *
31  * KEY FINGERPRINT (PGP Key in license file):
32  * 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
33  *
34  * OFFICIAL PROJECT WIKI(s):
35  * https://github.com/FellowTraveler/Moneychanger
36  * https://github.com/FellowTraveler/Open-Transactions/wiki
37  *
38  * WEBSITE:
39  * http://www.OpenTransactions.org/
40  *
41  * Components and licensing:
42  * -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
43  * -- otlib.........A class library.......LICENSE:...LAGPLv3
44  * -- otapi.........A client API..........LICENSE:...LAGPLv3
45  * -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
46  * -- otserver......Server Application....LICENSE:....AGPLv3
47  * Github.com/FellowTraveler/Open-Transactions/wiki/Components
48  *
49  * All of the above OT components were designed and written by
50  * Fellow Traveler, with the exception of Moneychanger, which
51  * was contracted out to Vicky C ([email protected]).
52  * The open-source community has since actively contributed.
53  *
54  * -----------------------------------------------------
55  *
56  * LICENSE:
57  * This program is free software: you can redistribute it
58  * and/or modify it under the terms of the GNU Affero
59  * General Public License as published by the Free Software
60  * Foundation, either version 3 of the License, or (at your
61  * option) any later version.
62  *
63  * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
64  * section 7: (This paragraph applies only to the LAGPLv3
65  * components listed above.) If you modify this Program, or
66  * any covered work, by linking or combining it with other
67  * code, such other code is not for that reason alone subject
68  * to any of the requirements of the GNU Affero GPL version 3.
69  * (==> This means if you are only using the OT API, then you
70  * don't have to open-source your code--only your changes to
71  * Open-Transactions itself must be open source. Similar to
72  * LGPLv3, except it applies to software-as-a-service, not
73  * just to distributing binaries.)
74  *
75  * Extra WAIVER for OpenSSL, Lucre, and all other libraries
76  * used by Open Transactions: This program is released under
77  * the AGPL with the additional exemption that compiling,
78  * linking, and/or using OpenSSL is allowed. The same is true
79  * for any other open source libraries included in this
80  * project: complete waiver from the AGPL is hereby granted to
81  * compile, link, and/or use them with Open-Transactions,
82  * according to their own terms, as long as the rest of the
83  * Open-Transactions terms remain respected, with regard to
84  * the Open-Transactions code itself.
85  *
86  * Lucre License:
87  * This code is also "dual-license", meaning that Ben Lau-
88  * rie's license must also be included and respected, since
89  * the code for Lucre is also included with Open Transactions.
90  * See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
91  * The Laurie requirements are light, but if there is any
92  * problem with his license, simply remove the Lucre code.
93  * Although there are no other blind token algorithms in Open
94  * Transactions (yet. credlib is coming), the other functions
95  * will continue to operate.
96  * See Lucre on Github: https://github.com/benlaurie/lucre
97  * -----------------------------------------------------
98  * You should have received a copy of the GNU Affero General
99  * Public License along with this program. If not, see:
100  * http://www.gnu.org/licenses/
101  *
102  * If you would like to use this software outside of the free
103  * software license, please contact FellowTraveler.
104  * (Unfortunately many will run anonymously and untraceably,
105  * so who could really stop them?)
106  *
107  * DISCLAIMER:
108  * This program is distributed in the hope that it will be
109  * useful, but WITHOUT ANY WARRANTY; without even the implied
110  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
111  * PURPOSE. See the GNU Affero General Public License for
112  * more details.
113 
114  -----BEGIN PGP SIGNATURE-----
115  Version: GnuPG v1.4.9 (Darwin)
116 
117  iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
118  vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
119  KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
120  aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
121  LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
122  sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
123  oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
124  TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
125  x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
126  nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
127  M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
128  kamH0Y/n11lCvo1oQxM+
129  =uSzz
130  -----END PGP SIGNATURE-----
131 **************************************************************/
132 
133 #include "ConfigLoader.hpp"
134 #include "ServerSettings.hpp"
135 #include <opentxs/core/OTString.hpp>
139 #include <opentxs/core/OTLog.hpp>
141 #include <cstdint>
142 
143 #define SERVER_WALLET_FILENAME "notaryServer.xml"
144 #define SERVER_MASTER_KEY_TIMEOUT_DEFAULT -1
145 #define SERVER_USE_SYSTEM_KEYRING false
146 
147 namespace opentxs
148 {
149 
150 bool ConfigLoader::load(OTString& walletFilename)
151 {
152  const char* szFunc = "ConfigLoader::load()";
153 
154  // Setup Config File
155  OTString strConfigFolder, strConfigFilename;
156 
158  OT_FAIL;
159  }
160 
161  // Create Config Object (OTSettings)
162  OTString strConfigFilePath = "";
163  if (!OTDataFolder::GetConfigFilePath(strConfigFilePath)) {
164  OT_FAIL;
165  }
166  OTSettings* p_Config = new OTSettings(strConfigFilePath);
167 
168  // First Load, Create new fresh config file if failed loading.
169  if (!p_Config->Load()) {
171  0, "%s: Note: Unable to Load Config. Creating a new file: %s\n",
172  szFunc, strConfigFilename.Get());
173  if (!p_Config->Reset()) return false;
174  if (!p_Config->Save()) return false;
175  }
176 
177  if (!p_Config->Reset()) return false;
178 
179  // Second Load, Throw Assert if Failed loading.
180  if (!p_Config->Load()) {
181  OTLog::vError(0, "%s: Error: Unable to load config file: %s It should "
182  "exist, as we just saved it!\n",
183  szFunc, strConfigFilename.Get());
184  OT_FAIL;
185  }
186 
187  // LOG LEVEL
188  {
189  bool bIsNewKey;
190  int64_t lValue;
191  p_Config->CheckSet_long("logging", "log_level", 0, lValue, bIsNewKey);
192  OTLog::SetLogLevel(static_cast<int32_t>(lValue));
193  }
194 
195  // WALLET
196 
197  // WALLET FILENAME
198  //
199  // Clean and Set
200  {
201  bool bIsNewKey;
202  OTString strValue;
203  p_Config->CheckSet_str("wallet", "wallet_filename",
204  SERVER_WALLET_FILENAME, strValue, bIsNewKey);
205  walletFilename.Set(strValue);
206  OTLog::vOutput(0, "Using Wallet: %s\n", strValue.Get());
207  }
208 
209  // CRON
210  {
211  const char* szComment = ";; CRON (regular events like market trades "
212  "and smart contract clauses)\n";
213 
214  bool b_SectionExist;
215  p_Config->CheckSetSection("cron", szComment, b_SectionExist);
216  }
217 
218  {
219  const char* szComment = "; refill_trans_number is the count of "
220  "transaction numbers cron will grab for "
221  "itself,\n"
222  "; whenever its supply is getting low. If it "
223  "ever drops below 20% of this count\n"
224  "; while in the middle of processing, it will "
225  "put a WARNING into your server log.\n";
226 
227  bool bIsNewKey;
228  int64_t lValue;
229  p_Config->CheckSet_long("cron", "refill_trans_number", 500, lValue,
230  bIsNewKey, szComment);
231  OTCron::SetCronRefillAmount(static_cast<int32_t>(lValue));
232  }
233 
234  {
235  const char* szComment = "; ms_between_cron_beats is the number of "
236  "milliseconds before Cron processes\n"
237  "; (all the trades, all the smart contracts, "
238  "etc every 10 seconds.)\n";
239 
240  bool bIsNewKey;
241  int64_t lValue;
242  p_Config->CheckSet_long("cron", "ms_between_cron_beats", 10000, lValue,
243  bIsNewKey, szComment);
244  OTCron::SetCronMsBetweenProcess(static_cast<int32_t>(lValue));
245  }
246 
247  {
248  const char* szComment = "; max_items_per_nym is the number of cron "
249  "items (such as market offers or payment\n"
250  "; plans) that any given Nym is allowed to "
251  "have live and active at the same time.\n";
252 
253  bool bIsNewKey;
254  int64_t lValue;
255  p_Config->CheckSet_long("cron", "max_items_per_nym", 10, lValue,
256  bIsNewKey, szComment);
257  OTCron::SetCronMaxItemsPerNym(static_cast<int32_t>(lValue));
258  }
259 
260  // HEARTBEAT
261 
262  {
263  const char* szComment = ";; HEARTBEAT\n";
264 
265  bool bSectionExist;
266  p_Config->CheckSetSection("heartbeat", szComment, bSectionExist);
267  }
268 
269  {
270  const char* szComment = "; no_requests is the number of client "
271  "requests the server processes per "
272  "heartbeat.\n";
273 
274  bool bIsNewKey;
275  int64_t lValue;
276  p_Config->CheckSet_long("heartbeat", "no_requests", 10, lValue,
277  bIsNewKey, szComment);
278  ServerSettings::SetHeartbeatNoRequests(static_cast<int32_t>(lValue));
279  }
280 
281  {
282  const char* szComment = "; ms_between_beats is the number of "
283  "milliseconds between each heartbeat.\n";
284 
285  bool bIsNewKey;
286  int64_t lValue;
287  p_Config->CheckSet_long("heartbeat", "ms_between_beats", 100, lValue,
288  bIsNewKey, szComment);
290  static_cast<int32_t>(lValue));
291  }
292 
293  // PERMISSIONS
294 
295  {
296  const char* szComment = ";; PERMISSIONS\n"
297  ";; You can deactivate server functions here "
298  "by setting them to false.\n"
299  ";; (Even if you do, override_nym_id will "
300  "STILL be able to do those functions.)\n";
301 
302  bool bSectionExists;
303  p_Config->CheckSetSection("permissions", szComment, bSectionExists);
304  }
305 
306  {
307  OTString strValue;
308  const char* szValue;
309 
310  std::string stdstrValue = ServerSettings::GetOverrideNymID();
311  szValue = stdstrValue.c_str();
312 
313  bool bIsNewKey;
314 
315  if (nullptr == szValue)
316  p_Config->CheckSet_str("permissions", "override_nym_id", nullptr,
317  strValue, bIsNewKey);
318  else
319  p_Config->CheckSet_str("permissions", "override_nym_id", szValue,
320  strValue, bIsNewKey);
321 
323  }
324 
325  // MARKETS
326 
327  {
328  const char* szComment = "; minimum_scale is the smallest allowed "
329  "power-of-ten for the scale, for any market.\n"
330  "; (1oz, 10oz, 100oz, 1000oz.)\n";
331 
332  bool bIsNewKey;
333  int64_t lValue;
334  p_Config->CheckSet_long("markets", "minimum_scale",
336  bIsNewKey, szComment);
338  }
339 
340  // SECURITY (beginnings of..)
341 
342  // Master Key Timeout
343  {
344  const char* szComment =
345  "; master_key_timeout is how int64_t the master key will be in "
346  "memory until a thread wipes it out.\n"
347  "; 0 : means you have to type your password EVERY time OT uses a "
348  "private key. (Even multiple times in a single function.)\n"
349  "; 300 : means you only have to type it once per 5 minutes.\n"
350  "; -1 : means you only type it once PER RUN (popular for "
351  "servers.)\n";
352 
353  bool bIsNewKey;
354  int64_t lValue;
355  p_Config->CheckSet_long("security", "master_key_timeout",
357  bIsNewKey, szComment);
358  OTCachedKey::It()->SetTimeoutSeconds(static_cast<int32_t>(lValue));
359  }
360 
361  // Use System Keyring
362  {
363  bool bIsNewKey;
364  bool bValue;
365  p_Config->CheckSet_bool("security", "use_system_keyring",
366  SERVER_USE_SYSTEM_KEYRING, bValue, bIsNewKey);
367  OTCachedKey::It()->UseSystemKeyring(bValue);
368 
369 #if defined(OT_KEYRING_FLATFILE)
370  // Is there a password folder? (There shouldn't be, but we allow it...)
371  //
372  if (bValue) {
373  bool bIsNewKey2;
374  OTString strValue;
375  p_Config->CheckSet_str("security", "password_folder",
376  SERVER_PASSWORD_FOLDER, strValue,
377  bIsNewKey2);
378  if (strValue.Exists()) {
379  OTKeyring::FlatFile_SetPasswordFolder(strValue.Get());
380  OTLog::vOutput(0, " Using server password folder: %s\n",
381  strValue.Get());
382  }
383  }
384 #endif
385  }
386 
387  // (#defined right above this function.)
388  //
389 
390  p_Config->SetOption_bool("permissions", "admin_usage_credits",
392  p_Config->SetOption_bool("permissions", "admin_server_locked",
394  p_Config->SetOption_bool("permissions", "cmd_usage_credits",
396  p_Config->SetOption_bool("permissions", "cmd_issue_asset",
398  p_Config->SetOption_bool("permissions", "cmd_get_contract",
400  p_Config->SetOption_bool("permissions", "cmd_check_server_id",
402  p_Config->SetOption_bool("permissions", "cmd_create_user_acct",
404  p_Config->SetOption_bool("permissions", "cmd_del_user_acct",
406  p_Config->SetOption_bool("permissions", "cmd_check_user",
408  p_Config->SetOption_bool("permissions", "cmd_get_request",
410  p_Config->SetOption_bool("permissions", "cmd_get_trans_num",
412  p_Config->SetOption_bool("permissions", "cmd_send_message",
414  p_Config->SetOption_bool("permissions", "cmd_get_nymbox",
416  p_Config->SetOption_bool("permissions", "cmd_process_nymbox",
418  p_Config->SetOption_bool("permissions", "cmd_create_asset_acct",
420  p_Config->SetOption_bool("permissions", "cmd_del_asset_acct",
422  p_Config->SetOption_bool("permissions", "cmd_get_acct",
424  p_Config->SetOption_bool("permissions", "cmd_get_inbox",
426  p_Config->SetOption_bool("permissions", "cmd_get_outbox",
428  p_Config->SetOption_bool("permissions", "cmd_process_inbox",
430  p_Config->SetOption_bool("permissions", "cmd_issue_basket",
432  p_Config->SetOption_bool("permissions", "transact_exchange_basket",
434  p_Config->SetOption_bool("permissions", "cmd_notarize_transaction",
436  p_Config->SetOption_bool("permissions", "transact_process_inbox",
438  p_Config->SetOption_bool("permissions", "transact_transfer",
440  p_Config->SetOption_bool("permissions", "transact_withdrawal",
442  p_Config->SetOption_bool("permissions", "transact_deposit",
444  p_Config->SetOption_bool("permissions", "transact_withdraw_voucher",
446  p_Config->SetOption_bool("permissions", "transact_pay_dividend",
448  p_Config->SetOption_bool("permissions", "transact_deposit_cheque",
450  p_Config->SetOption_bool("permissions", "cmd_get_mint",
452  p_Config->SetOption_bool("permissions", "transact_withdraw_cash",
454  p_Config->SetOption_bool("permissions", "transact_deposit_cash",
456  p_Config->SetOption_bool("permissions", "cmd_get_market_list",
458  p_Config->SetOption_bool("permissions", "cmd_get_market_offers",
460  p_Config->SetOption_bool("permissions", "cmd_get_market_recent_trades",
462  p_Config->SetOption_bool("permissions", "cmd_get_nym_market_offers",
464  p_Config->SetOption_bool("permissions", "transact_market_offer",
466  p_Config->SetOption_bool("permissions", "transact_payment_plan",
468  p_Config->SetOption_bool("permissions", "transact_cancel_cron_item",
470  p_Config->SetOption_bool("permissions", "transact_smart_contract",
472  p_Config->SetOption_bool("permissions", "cmd_trigger_clause",
474 
475  // Done Loading... Lets save any changes...
476  if (!p_Config->Save()) {
477  OTLog::vError("%s: Error! Unable to save updated Config!!!\n", szFunc);
478  OT_FAIL;
479  }
480 
481  // Finsihed Saving... now lets cleanup!
482  if (!p_Config->Reset()) return false;
483 
484  if (nullptr != p_Config) delete p_Config;
485  p_Config = nullptr;
486 
487  return true;
488 }
489 
490 } // namespace opentxs
static EXPORT void vError(const char *szError,...)
Definition: OTLog.cpp:800
static void SetCronRefillAmount(int32_t nAmount)
Definition: OTCron.hpp:209
static void SetHeartbeatNoRequests(int32_t value)
static bool __transact_withdraw_cash
static EXPORT bool GetConfigFilePath(OTString &strConfigFilePath)
static bool __cmd_create_asset_acct
static const std::string & GetOverrideNymID()
static EXPORT bool SetLogLevel(const int32_t &nLogLevel)
Definition: OTLog.cpp:443
static void SetCronMaxItemsPerNym(int32_t nMax)
Definition: OTCron.hpp:217
static bool __transact_market_offer
static bool __transact_cancel_cron_item
static EXPORT bool IsInitialized()
EXPORT bool Exists() const
Definition: OTString.cpp:1035
static EXPORT std::shared_ptr< OTCachedKey > It(OTIdentifier *pIdentifier=nullptr)
static bool load(OTString &walletFilename)
static void SetHeartbeatMsBetweenBeats(int32_t value)
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
static int64_t GetMinMarketScale()
static bool __transact_smart_contract
static void SetCronMsBetweenProcess(int32_t lMS)
Definition: OTCron.hpp:200
static bool __transact_process_inbox
static bool __cmd_get_nym_market_offers
EXPORT bool Reset()
Definition: OTSettings.cpp:297
#define OT_FAIL
Definition: Assert.hpp:139
#define SERVER_USE_SYSTEM_KEYRING
static bool __transact_exchange_basket
EXPORT bool CheckSet_str(const OTString &strSection, const OTString &strKey, const OTString &strDefault, OTString &out_strResult, bool &out_bIsNew, const OTString &strComment="")
Definition: OTSettings.cpp:664
EXPORT const char * Get() const
Definition: OTString.cpp:1045
static bool __transact_withdraw_voucher
EXPORT bool SetOption_bool(const OTString &strSection, const OTString &strKey, bool &bVariableName)
Definition: OTSettings.cpp:809
static void SetMinMarketScale(int64_t value)
EXPORT bool CheckSet_long(const OTString &strSection, const OTString &strKey, const int64_t &lDefault, int64_t &out_lResult, bool &out_bIsNew, const OTString &strComment="")
Definition: OTSettings.cpp:722
static bool __transact_deposit_cash
#define SERVER_WALLET_FILENAME
static bool __cmd_create_user_acct
static bool __transact_deposit_cheque
EXPORT bool CheckSetSection(const OTString &strSection, const OTString &strComment, bool &out_bIsNewSection)
Definition: OTSettings.cpp:628
static bool __transact_payment_plan
#define SERVER_MASTER_KEY_TIMEOUT_DEFAULT
static void SetOverrideNymID(const std::string &id)
#define SERVER_PASSWORD_FOLDER
Definition: OTServer.cpp:184
static bool __cmd_get_market_offers
static bool __transact_pay_dividend
static bool __cmd_notarize_transaction
static EXPORT void vOutput(int32_t nVerbosity, const char *szOutput,...)
Definition: OTLog.cpp:768
EXPORT bool CheckSet_bool(const OTString &strSection, const OTString &strKey, const bool &bDefault, bool &out_bResult, bool &out_bIsNew, const OTString &strComment="")
Definition: OTSettings.cpp:766
static bool __cmd_get_market_recent_trades