Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTString.cpp
Go to the documentation of this file.
1 /************************************************************
2  *
3  * OTString.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 "stdafx.hpp"
134 
135 #include "OTString.hpp"
136 #include "OTContract.hpp"
137 #include "OTLog.hpp"
138 #include "crypto/OTPassword.hpp"
139 #include "OTPseudonym.hpp"
140 #include "crypto/OTSignature.hpp"
141 #include "util/StringUtils.hpp"
142 
143 #if !(defined(_WIN32) || defined(TARGET_OS_IPHONE) || defined(ANDROID))
144 #include <wordexp.h>
145 #endif
146 
147 namespace opentxs
148 {
149 
150 std::ostream& operator<<(std::ostream& os, const OTString& obj)
151 {
152  os << obj.Get();
153  return os;
154 }
155 
156 /*
157  int32_t vsnprintf(char* str, size_t size, const char* format, va_list ap);
158 
159  Upon successful return, these functions return the number of characters
160  printed (not including the trailing '\0' used to end output to
161  strings). The functions snprintf() and vsnprintf() do not write more
162  than size bytes (including the trailing '\0'). If the output was trun-
163  cated due to this limit then the return value is the number of charac-
164  ters (not including the trailing '\0') which would have been written to
165  the final string if enough space had been available. Thus, a return
166  value of size or more means that the output was truncated. (See also
167  below under NOTES.) If an output error is encountered, a negative
168  value is returned.
169 
170  -- Therefore if size was 500, and it printed 100 characters (indices 0..99),
171  then it will return 100, even though the actual bytes used are 101 (indices
172  0..100),
173  with the null terminator stored in the 101st byte (at index 100.) size (500)
174  is not <= nsize (100) so we never enter the 'if' block in vformat.
175 
176  -- vsnprintf does not write more than size bytes, INCLUDING the null
177  terminator.
178  So this is actually the buffer size we are giving it (not the fmt string
179  size.)
180 
181  -- If output was truncated then the return value is the number of characters
182  which
183  WOULD have been written, IF space had been available (NOT including the null
184  terminator.) So if size is 80, but the final output would have been 90 in
185  length
186  (without terminator--91 with terminator), then it will return 90.
187 
188  */
189 
190 // static
191 bool OTString::vformat(const char* fmt, va_list* pvl, std::string& str_Output)
192 {
193  OT_ASSERT(nullptr != fmt);
194  OT_ASSERT(nullptr != pvl);
195 
196  int32_t size = 0;
197  int32_t nsize = 0;
198  char* buffer = nullptr;
199  va_list args;
200 
201 #ifdef _WIN32
202  va_list args_2 = *pvl; // windows only.
203 
204  args = *pvl;
205  size = _vscprintf(fmt, args) + 1;
206 #else
207  va_copy(args, *pvl);
208  size = 512;
209 #endif
210 
211  buffer = new char[size + 100];
212  OT_ASSERT(nullptr != buffer);
213  OTPassword::zeroMemory(buffer, size + 100);
214 
215 #ifdef _WIN32
216  nsize = vsnprintf_s(buffer, size, size, fmt, args_2);
217 #else
218  nsize = vsnprintf(buffer, size, fmt, args);
219  va_end(args);
220 #endif
221 
222  OT_ASSERT(nsize >= 0);
223 
224  // fail -- delete buffer and try again
225  // If nsize was 1024 bytes, then that would mean that it printed 1024
226  // characters,
227  // even though the actual string must be 1025 in length (to have room for
228  // the null
229  // terminator.)
230  // If size, the ACTUAL buffer, was 1024 (that is, if size <= nsize) then
231  // size would
232  // LACK the necessary space to store the 1025th byte containing the null
233  // terminator.
234  // Therefore we are forced to delete the buffer and make one that is
235  // nsize+1, so that
236  // it will be 1025 bytes and thus have the necessary space for the
237  // terminator
238  //
239  if (size <= nsize) {
240  size = nsize + 1;
241  delete[] buffer;
242  buffer = new char[size + 100];
243  OT_ASSERT(nullptr != buffer);
244  OTPassword::zeroMemory(buffer, size + 100);
245 
246 #ifdef _WIN32
247  nsize = vsnprintf_s(buffer, size, size, fmt, *pvl);
248  va_end(args);
249  va_end(args_2);
250 #else
251  nsize = vsnprintf(buffer, size, fmt, *pvl);
252 #endif
253 
254  OT_ASSERT(nsize >= 0);
255  }
256  OT_ASSERT(size > nsize);
257 
258  str_Output = buffer;
259  delete[] buffer;
260  buffer = nullptr;
261  return true;
262 }
263 
264 // I've greped the code for strnlen, it seems like that we are not using it.
265 // This is not the correct solution for strnlen being insecure on windows.
266 // The correct solution is to us the 'strnlen_s' function on windows.
267 
268 //#ifndef __linux__
269 // extern "C" {
270 // size_t strnlen(const char* s, size_t max)
271 // {
272 // register const char *p;
273 // for(p = s; *p && max--; ++p);
274 // return(p - s);
275 // }
276 //}
277 //#endif
278 
279 // TODO Make sure I follow this advice.
280 
281 /*
282 
283 
284 It is not wise to use the ANSI standard strcpy function because of the
285 possibility of
286 unchecked buffer overflows. The better strncpy function has the problem that it
287 does not
288 properly terminate the string. The following strlcpy and strlcat functions are
289 simple
290 implementations that manage the problems of their original ANSI ancestors.
291 
292 // #include <string.h>
293 
294 size_t strlcpy(char* d, const char* s, size_t bufsize)
295 {
296  size_t len;
297  size_t ret;
298 
299  if (!d || !s) return 0;
300  len = strlen(s);
301  ret = len;
302  if (bufsize <= 0) return 0;
303  if (len >= bufsize) len = bufsize-1;
304  memcpy(d, s, len);
305  d[len] = 0;
306 
307  return ret;
308 }
309 
310 size_t strlcat(char* d, const char* s, size_t bufsize)
311 {
312  size_t len1;
313  size_t len2;
314  size_t ret;
315 
316  if (!d || !s || bufsize <= 0) return 0;
317 
318  len1 = strlen(d);
319  len2 = strlen(s);
320  ret = len1 + len2;
321  if (len1+len2 >= bufsize)
322  {
323  len2 = bufsize - (len1+1);
324  }
325  if (len2 > 0)
326  {
327  memcpy(d+len1, s, len2);
328  d[len1+len2] = 0;
329  }
330  return ret;
331 }
332  */
333 
334 // TODO: Security: should change OTString to use size_t and MAX_SIZE instead of
335 // whatever it uses now. Safer.
336 
337 /*
338  WINDOWS:
339 errno_t strcpy_s(char* strDestination,
340  size_t numberOfElements, // MAX SIZE of destination.
341  const char *strSource);
342 
343  UNIX:
344  size_t strlcpy(char * restrict dst,
345  const char* restrict src,
346  size_t size); // MAX SIZE of destination.
347 
348  extern "C" size_t strnlen(const char* s, size_t max); // Moved the definition
349 of this function to OTPassword.cpp
350  */
351 
352 // static
353 bool OTString::safe_strcpy(char* dest, const char* src, size_t dest_size,
354  bool bZeroSource) // if true, initializes
355  // the source buffer to
356  // zero after the
357  // copying is done.
358 {
359  // Make sure they don't overlap.
360  //
361  OT_ASSERT_MSG(false == ((src > dest) && (src < (dest + dest_size))),
362  "ASSERT: safe_strcpy: Unexpected memory overlap.\n");
363 
364  const size_t src_length = OTString::safe_strlen(src, MAX_STRING_LENGTH);
365 
366  OT_ASSERT_MSG(dest_size > src_length, "OTString::safe_strcpy: ASSERT: "
367  "src_length must be less than "
368  "dest_size.\n");
369 
370 #ifdef _WIN32
371  bool bSuccess = (0 == strcpy_s(dest, dest_size, src));
372 #else
373  size_t src_cpy_length = strlcpy(dest, src, dest_size);
374  bool bSuccess = (src_length == src_cpy_length);
375 #endif
376 
377  // Notice: we don't zero out the source unless we were successful (AND
378  // unless we were asked to.)
379  //
380  if (bSuccess && bZeroSource)
381  OTPassword::zeroMemory(const_cast<char*>(src),
382  static_cast<uint32_t>(src_length));
383 
384  return bSuccess;
385 }
386 
387 // static
388 size_t OTString::safe_strlen(const char* s, size_t max)
389 {
390  OT_ASSERT_MSG(max <= MAX_STRING_LENGTH, "OT_String::safe_strlen: ASSERT: "
391  "max length passed in is longer "
392  "than allowed.\n");
393 
394  return strnlen(s, max);
395 }
396 
397 // static
398 std::string& OTString::trim(std::string& str)
399 {
400  std::string whitespaces(" \t\f\v\n\r");
401 
402  size_t found = str.find_first_not_of(whitespaces);
403 
404  if (found != std::string::npos) {
405  str.erase(0, found);
406  }
407 
408  found = str.find_last_not_of(whitespaces);
409 
410  if (found != std::string::npos) {
411  str.erase(found + 1);
412  }
413 
414  // otErr << "(DEBUGGING OTString.cpp) CONTRACT HAS BEEN TRIMMED!!!
415  // RESULT: \n\n***BEGIN TRIM DATA:%s******END TRIM DATA\n\n",
416  // str.c_str()); // todo temp remove
417  return str;
418 }
419 
420 std::string OTString::replace_chars(const std::string& str,
421  const std::string& charsFrom,
422  const char& charTo)
423 {
424  std::string l_str(str);
425  size_t found;
426 
427  found = str.find_first_of(charsFrom);
428  while (found != std::string::npos) {
429  l_str[found] = charTo;
430  found = str.find_first_of(charsFrom, found + 1);
431  }
432  return l_str;
433 }
434 
435 #ifdef _WIN32
436 
437 std::wstring OTString::s2ws(const std::string& s)
438 {
439  int32_t len;
440  int32_t slength = (int32_t)s.length() + 1;
441  len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
442  std::wstring r(len, L'\0');
443  MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, &r[0], len);
444  return r;
445 }
446 
447 std::string OTString::ws2s(const std::wstring& s)
448 {
449  int32_t len;
450  int32_t slength = (int32_t)s.length() + 1;
451  len = WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
452  std::string r(len, '\0');
453  WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, &r[0], len, 0, 0);
454  return r;
455 }
456 
457 #endif
458 
459 // ------ I cannot vouch for these top four functions, I wrote them so long ago.
460 // ------ But they can't hurt and I don't think they're being used anyway so I
461 // left them in for now.
462 
463 bool OTString::operator>(const OTString& s2) const
464 {
465  if (s2.length_ == 0) {
466  return (true);
467  }
468  if (length_ == 0) {
469  return (false);
470  }
471  if (strcmp(data_, s2.data_) <= 0) {
472  return (false);
473  }
474  return (true);
475 }
476 
477 bool OTString::operator<(const OTString& s2) const
478 {
479  if (length_ == 0) {
480  return (true);
481  }
482  if (s2.length_ == 0) {
483  return (false);
484  }
485  if (strcmp(data_, s2.data_) >= 0) {
486  return (false);
487  }
488  return (true);
489 }
490 
491 bool OTString::operator<=(const OTString& s2) const
492 {
493  if (length_ == 0) {
494  return (true);
495  }
496  if (s2.length_ == 0) {
497  return (false);
498  }
499  if (strcmp(data_, s2.data_) > 0) {
500  return (false);
501  }
502  return (true);
503 }
504 
505 bool OTString::operator>=(const OTString& s2) const
506 {
507  if (s2.length_ == 0) {
508  return (true);
509  }
510  if (length_ == 0) {
511  return (false);
512  }
513  if (strcmp(data_, s2.data_) < 0) {
514  return (false);
515  }
516  return (true);
517 }
518 
519 void fwrite_string(std::ostream& ofs, const char* str)
520 {
521  char* pchar;
522 
523  pchar = (char*)str;
524 
525  if (str)
526  while (*pchar) {
527  if (*pchar != '\r') ofs << *pchar;
528  pchar++;
529  }
530 }
531 
532 /*
533 void fwrite_string(FILE* fl, const char* str)
534 {
535  char * pchar;
536 
537  pchar = (char *)str;
538 
539  if(str)
540  while(*pchar) {
541  if(*pchar != '\r')
542  fputc(*pchar, fl);
543  pchar++;
544  }
545 }
546 */
547 
548 // Note: UNIX-only (for now.)
549 //
551  std::map<std::string, std::string>& mapOutput) const
552 {
553 #if !(defined(_WIN32) || defined(TARGET_OS_IPHONE) || defined(ANDROID))
554  // fabcy-pansy parser that allows for multiple level of quotes nesting and
555  // escaped quotes
556  if (!Exists()) return true;
557 
558  wordexp_t exp_result;
559 
560  exp_result.we_wordc = 0;
561  exp_result.we_wordv = nullptr;
562  exp_result.we_offs = 0;
563 
564  if (wordexp(Get(), &exp_result, 0)) // non-zero == failure.
565  {
566  otErr << "OTString::TokenizeIntoKeyValuePairs: Error calling wordexp() "
567  "(to expand user-defined script args.)\nData: " << *this
568  << "\n";
569  // wordfree(&exp_result);
570  return false;
571  }
572 
573  if ((exp_result.we_wordc > 0) && (nullptr != exp_result.we_wordv)) {
574  // wordexp tokenizes by space (as well as expands, which is why I'm
575  // using it.)
576  // Therefore we need to iterate through the tokens, and create a single
577  // string
578  // with spaces between the tokens.
579  //
580  for (uint32_t i = 0;
581  (i < (exp_result.we_wordc - 1)) &&
582  (exp_result.we_wordv[i] != nullptr) &&
583  (exp_result.we_wordv[i + 1] !=
584  nullptr); // odd man out. Only PAIRS of strings are processed!
585  i += 2) {
586  const std::string str_key = exp_result.we_wordv[i];
587  const std::string str_val = exp_result.we_wordv[i + 1];
588 
589  otInfo << __FUNCTION__ << ":Parsed: " << str_key << " = " << str_val
590  << "\n";
591  mapOutput.insert(
592  std::pair<std::string, std::string>(str_key, str_val));
593  }
594 
595  wordfree(&exp_result);
596  }
597 
598  return true;
599 #else
600  // simple parser that allows for one level of quotes nesting but no escaped
601  // quotes
602  if (!Exists()) return true;
603 
604  const char* txt = Get();
605  std::string buf = txt;
606  for (int32_t i = 0; txt[i] != 0;) {
607  while (txt[i] == ' ') i++;
608  int32_t k = i;
609  int32_t k2 = i;
610  if (txt[i] == '\'' || txt[i] == '"') {
611  // quoted string
612  char quote = txt[i++];
613  k = i;
614  while (txt[i] != quote && txt[i] != 0) i++;
615  if (txt[i] != quote) {
616  otErr << __FUNCTION__ << ": Unmatched quotes in: " << txt
617  << "\n";
618  return false;
619  }
620  k2 = i;
621  i++;
622  }
623  else {
624  while (txt[i] != ' ' && txt[i] != 0) i++;
625  k2 = i;
626  }
627  const std::string key = buf.substr(k, k2 - k);
628 
629  while (txt[i] == ' ') i++;
630  int32_t v = i;
631  int32_t v2 = i;
632  if (txt[i] == '\'' || txt[i] == '"') {
633  // quoted string
634  char quote = txt[i++];
635  v = i;
636  while (txt[i] != quote && txt[i] != 0) i++;
637  if (txt[i] != quote) {
638  otErr << __FUNCTION__ << ": Unmatched quotes in: " << txt
639  << "\n";
640  return false;
641  }
642  v2 = i;
643  i++;
644  }
645  else {
646  while (txt[i] != ' ' && txt[i] != 0) i++;
647  v2 = i;
648  }
649  const std::string value = buf.substr(v, v2 - v);
650 
651  if (key.length() != 0 && value.length() != 0) {
652  otInfo << __FUNCTION__ << ":Parsed: " << key << " = " << value
653  << "\n";
654  mapOutput.insert(std::pair<std::string, std::string>(key, value));
655  }
656  }
657  return true;
658 #endif
659 }
660 
661 // static
662 uint64_t OTString::StringToUlong(const std::string& strNumber)
663 {
664  if (strNumber.size() == 0) return 0;
665 
666  uint64_t v = 0;
667  size_t i = 0;
668 
669  for (; i < strNumber.size(); ++i) {
670  if (strNumber[i] < '0' || strNumber[i] > '9') break;
671  v = ((v * 10) + (strNumber[i] - '0'));
672  }
673  return ((0 == v) ? 0 : v);
674 }
675 
676 // static
677 int64_t OTString::StringToLong(const std::string& strNumber)
678 {
679  if (strNumber.size() == 0) return 0;
680 
681  int64_t v = 0;
682  size_t i = 0;
683 
684  char sign = (strNumber[0] == '-' || strNumber[0] == '+')
685  ? (++i, strNumber[0])
686  : '+';
687 
688  for (; i < strNumber.size(); ++i) {
689  if (strNumber[i] < '0' || strNumber[i] > '9') break;
690  v = ((v * 10) + (strNumber[i] - '0'));
691  }
692  return ((0 == v) ? 0 : ((sign == '-') ? -v : v));
693 }
694 
695 uint64_t OTString::ToUlong() const
696 {
697  const std::string str_number(Get());
698 
699  return OTString::StringToUlong(str_number);
700 }
701 
702 int64_t OTString::ToLong() const
703 {
704  const std::string str_number(Get());
705 
706  return OTString::StringToLong(str_number);
707 }
708 
709 /*
710  int64_t OTString::StringToLong(const std::string& strNumber)
711  {
712  char* end;
713  int64_t lNumber = strtol(strNumber.c_str(), &end, 10);
714 
715  if (!*end) return lNumber;
716  else
717  {
718  otErr << "Conversion error (str to int64_t), non-convertible part:
719  %s",end);
720  OT_FAIL;
721  return -1;
722  }
723  }
724  */
725 //
726 /*
727  WCHAR szPassword[MAX_PATH];
728 
729  // Retrieve the password
730  if (GetPasswordFromUser(szPassword, MAX_PATH))
731 
732  UsePassword(szPassword); // <===========
733 
734  // WINDOWS MEMORY ZEROING CODE:
735  SecureZeroMemory(szPassword, sizeof(szPassword));
736 
737 
738  // NEED to get linux / etc versions as well, and use them in OTString
739  // as well as anywhere that std::string is used! Todo security!
740  // Can probably write a custom deallocator for the std::string and then
741  // zero it out similarly.
742  */
743 
745 {
746  if (nullptr != data_) {
748  }
749 }
750 
752 {
753  if (nullptr != data_) {
754  // for security purposes.
755  //
757  // memset(data_, 0, length_);
758  delete[] data_;
759  }
760  data_ = nullptr;
761  position_ = 0;
762  length_ = 0;
763 }
764 
766 {
767  Release_String();
768 
769  // no need to use ot_super here, since OTString is a "base class."
770 }
771 
772 // ***** Construction -- Destruction *****
773 
775 {
776  Release_String();
777 }
778 
780 {
781  length_ = 0;
782  position_ = 0;
783  data_ = nullptr;
784 }
785 
787  : length_(0)
788  , position_(0)
789  , data_(nullptr)
790 {
791  // Initialize();
792 }
793 
794 // This constructor gets the string version of the ID passed in,
795 // and sets that string on this object. (For when you need a string
796 // version of an ID.)
798  : length_(0)
799  , position_(0)
800  , data_(nullptr)
801 {
802  // Initialize();
803 
804  if (theValue.GetSize() > 0) theValue.GetString(*this);
805 }
806 
808  : length_(0)
809  , position_(0)
810  , data_(nullptr)
811 {
812  // Initialize();
813 
814  (const_cast<OTContract&>(theValue)).SaveContractRaw(*this);
815 }
816 
817 // This version base64-DECODES the ascii-armored string passed in,
818 // and then sets the decoded plaintext string onto this object.
820  : length_(0)
821  , position_(0)
822  , data_(nullptr)
823 {
824  // Initialize();
825 
826  if (strValue.Exists()) strValue.GetString(*this);
827 }
828 
829 // This version base64-DECODES the ascii-armored signature that's passed in,
830 // and then sets the decoded plaintext signature onto this object.
831 // You would only do this when the signature, decoded, is normally in ASII
832 // form. Actually, that is regularly NOT the case--signatures are usually in
833 // binary form.
834 // But Lucre signatures, as used in this library, ARE in text form, so I
835 // provided this constructor to easily base64-decode them to prepare for
836 // loading into a bio and then a Lucre object.
838  : length_(0)
839  , position_(0)
840  , data_(nullptr)
841 {
842  // Initialize();
843 
844  if (strValue.Exists()) strValue.GetString(*this);
845 }
846 
848  : length_(0)
849  , position_(0)
850  , data_(nullptr)
851 {
852  // Initialize();
853 
854  theValue.SavePseudonym(*this);
855 }
856 
857 OTString::OTString(const OTString& strValue)
858  : length_(0)
859  , position_(0)
860  , data_(nullptr)
861 {
862  // Initialize();
863  LowLevelSetStr(strValue);
864 }
865 
866 OTString::OTString(const char* new_string)
867  : length_(0)
868  , position_(0)
869  , data_(nullptr)
870 {
871  // Initialize();
872  LowLevelSet(new_string, 0);
873 }
874 
875 OTString::OTString(const char* new_string, size_t sizeLength)
876  : length_(0)
877  , position_(0)
878  , data_(nullptr)
879 {
880  // Initialize();
881  LowLevelSet(new_string, static_cast<uint32_t>(sizeLength));
882 }
883 
884 OTString::OTString(const std::string& new_string)
885  : length_(0)
886  , position_(0)
887  , data_(nullptr)
888 {
889  // Initialize();
890  LowLevelSet(new_string.c_str(), static_cast<uint32_t>(new_string.length()));
891 }
892 
893 void OTString::LowLevelSetStr(const OTString& strBuf)
894 {
895  OT_ASSERT(nullptr == data_); // otherwise memory leak.
896 
897  if (strBuf.Exists()) {
898  length_ = (MAX_STRING_LENGTH > strBuf.length_)
899  ? strBuf.length_
900  : (MAX_STRING_LENGTH - 1);
901 
903  "ASSERT: OTString::LowLevelSetStr: Exceeded "
904  "MAX_STRING_LENGTH! (String would not have fully fit "
905  "anyway--it would have been truncated here, potentially "
906  "causing data corruption.)"); // 10 being a buffer.
907 
908  data_ = str_dup2(strBuf.data_, length_);
909  }
910 }
911 
912 // if nEnforcedMaxLength is 10, then it will actually enforce a string at 9
913 // length.
914 // That is, up through index 8 (9th byte) instead of index 9 (10th byte.) This
915 // is because
916 // we are assuming the buffer has no more room than 10 bytes, and thus index 9
917 // (10th byte)
918 // MUST be reserved for the null terminating '\0'. Therefore, if the string is
919 // actually 10
920 // bytes int64_t, necessitating an 11th byte for the null terminator, then you
921 // should pass 11
922 // here, aka OTString::GetLength()+1. That way the entire string will fit.
923 //
924 void OTString::LowLevelSet(const char* new_string, uint32_t nEnforcedMaxLength)
925 {
926  OT_ASSERT(nullptr == data_); // otherwise memory leak.
927 
928  if (nullptr != new_string) {
929  uint32_t nLength =
930  (nEnforcedMaxLength > 0)
931  ? static_cast<uint32_t>(OTString::safe_strlen(
932  new_string, static_cast<size_t>(nEnforcedMaxLength)))
933  : static_cast<uint32_t>(OTString::safe_strlen(
934  new_string, static_cast<size_t>(MAX_STRING_LENGTH -
935  1))); // room for \0
936 
937  // don't bother allocating memory for a 0 length string.
938  if (0 == nLength) return;
939 
940  OT_ASSERT_MSG(nLength < (MAX_STRING_LENGTH - 10),
941  "ASSERT: OTString::LowLevelSet: Exceeded "
942  "MAX_STRING_LENGTH! (String would not have fully fit "
943  "anyway--it would have been truncated here, potentially "
944  "causing data corruption.)"); // 10 being a buffer.
945 
946  // Add null terminator to source string JUST IN CASE...
947  // Update: this is const, so we can't change it. However, the strnlen
948  // above will only have
949  // worked if there was a null terminator, since otherwise we would have
950  // hit the above ASSERT.
951  // Therefore we should be safe enough without it here...
952  //
953  // new_string[nLength] = '\0';
954 
955  data_ = str_dup2(new_string, nLength);
956 
957  if (nullptr != data_)
958  length_ = nLength;
959  else
960  length_ = 0;
961  }
962 }
963 
964 // The source is probably NOT null-terminated.
965 // Size must be exact (not a max.)
966 //
967 bool OTString::MemSet(const char* pMem, uint32_t theSize) // if theSize is 10...
968 {
969  Release();
970  // -------------------
971  if ((nullptr == pMem) || (theSize < 1)) return true;
972 
973  char* str_new = new char[theSize + 1]; // then we allocate 11
974  OT_ASSERT(nullptr != str_new);
975  // -------------------
976  OTPassword::zeroMemory(str_new, theSize + 1);
977 
978  // void * OTPassword::safe_memcpy(void* dest,
979  // uint32_t dest_size,
980  // const
981  // void * src,
982  // uint32_t src_length,
983  // bool bZeroSource)
984 
985  OTPassword::safe_memcpy(static_cast<void*>(str_new), theSize + 1, pMem,
986  theSize);
987  // memcpy(static_cast<void*>(str_new), pMem, theSize); // then we copy 10
988  // bytes
989 
990  // todo optimize: This is probably superfluous due to the zeroMemory above.
991  // Then again, we might want to remove that, and then keep this.
992  str_new[theSize] = '\0'; // add null-terminator. (I deliberately made this
993  // buffer 1 byte larger so I could put the 0 at the
994  // end.) Here the index[10] is the 11th byte, since
995  // we're counting from 0.
996 
997  // Calculate the length (in case there was a null terminator in the
998  // middle...)
999  // This way we're guaranteed to have the correct length.
1000  //
1001  uint32_t nLength = static_cast<uint32_t>(
1002  OTString::safe_strlen(str_new, static_cast<size_t>(theSize)));
1003  str_new[nLength] = '\0'; // This SHOULD be superfluous as well...
1004 
1005  length_ = nLength; // the length doesn't count the 0.
1006  data_ = str_new;
1007 
1008  return true;
1009 }
1010 
1012 {
1013  if (this != &rhs) // Compare addresses.
1014  swap(rhs); // Only swap if they are different objects.
1015  return *this;
1016 }
1017 
1019 {
1020  std::swap(length_, rhs.length_);
1021  std::swap(position_, rhs.position_);
1022  std::swap(data_, rhs.data_);
1023 }
1024 
1025 bool OTString::At(uint32_t lIndex, char& c) const
1026 {
1027  if (lIndex < length_) {
1028  c = data_[lIndex];
1029  return true;
1030  }
1031  else
1032  return false;
1033 }
1034 
1035 bool OTString::Exists(void) const
1036 {
1037  return (nullptr != data_) ? true : false;
1038 }
1039 
1040 uint32_t OTString::GetLength(void) const
1041 {
1042  return length_;
1043 }
1044 
1045 const char* OTString::Get(void) const
1046 {
1047  return (nullptr != data_) ? const_cast<const char*>(data_) : "";
1048 }
1049 
1050 // new_string MUST be at least nEnforcedMaxLength in size if nEnforcedMaxLength
1051 // is passed in at all.
1052 // That's because this function forces the null terminator at that length of the
1053 // string minus 1.
1054 
1055 void OTString::Set(const char* new_string, uint32_t nEnforcedMaxLength)
1056 {
1057  if (new_string == data_) // Already the same string.
1058  return;
1059 
1060  Release();
1061 
1062  if (nullptr == new_string) return;
1063 
1064  LowLevelSet(new_string, nEnforcedMaxLength);
1065 }
1066 
1067 void OTString::Set(const OTString& strBuf)
1068 {
1069  if (this == &strBuf) // Already the same string.
1070  return;
1071 
1072  Release();
1073 
1074  LowLevelSetStr(strBuf);
1075 }
1076 
1077 bool OTString::operator==(const OTString& s2) const
1078 {
1079  // If they are not the same length, return false
1080  if (length_ != s2.length_) {
1081  return (false);
1082  }
1083 
1084  // At this point we know they are at least the same length.
1085  // Next--are they both 0? If they are both 0, return true
1086  if (length_ == 0 && s2.length_ == 0) {
1087  return (true);
1088  }
1089 
1090  // At this point we have 2 identical-length strings.
1091  // Now we call strcmp and convert it to true or false.
1092  if (strcmp(data_, s2.data_) ==
1093  0) { // TODO security: use a replacement for strcmp.
1094  return (true);
1095  }
1096  return (false);
1097 }
1098 
1099 // ***** Operations *****
1100 
1101 // Compare is simple. True if they match, False if they don't match.
1102 bool OTString::Compare(const char* strCompare) const
1103 {
1104  if (nullptr == data_ || nullptr == strCompare) {
1105  return false;
1106  }
1107 
1108  char* s1 = data_;
1109  char* s2 = (char*)strCompare;
1110 
1111  for (; *s1 && *s2; s1++, s2++)
1112  if (*s1 != *s2) return false;
1113 
1114  if (*s1 != *s2) return false;
1115 
1116  return true;
1117 }
1118 
1119 bool OTString::Compare(const OTString& strCompare) const
1120 {
1121  if (nullptr == data_ || !strCompare.Exists()) {
1122  return false;
1123  }
1124 
1125  char* s1 = data_;
1126  const char* s2 = strCompare.Get();
1127 
1128  for (; *s1 && *s1 != ' '; s1++, s2++)
1129  if (*s1 != *s2) return false;
1130 
1131  return true;
1132 }
1133 
1134 // Contains is like compare. True if the substring is there, false if not.
1135 // I was going to return the position but then I realized I never needed it.
1136 // Should be easy to modify if the need arises.
1137 bool OTString::Contains(const char* strCompare) const
1138 {
1139  if (nullptr == data_ || nullptr == strCompare) {
1140  return false;
1141  }
1142 
1143  if (strstr(data_, strCompare)) return true;
1144 
1145  return false;
1146 }
1147 
1148 bool OTString::Contains(const OTString& strCompare) const
1149 {
1150  if (nullptr == data_ || !strCompare.Exists()) {
1151  return false;
1152  }
1153 
1154  if (strstr(data_, strCompare.Get())) return true;
1155 
1156  return false;
1157 }
1158 
1159 void OTString::OTfgets(std::istream& ifs)
1160 {
1161  std::stringbuf sb;
1162  ifs.get(sb); // delimiter defaults to '\n'
1163 
1164  if (ifs.good()) {
1165  const std::string str_output = sb.str();
1166 
1167  Set(str_output.c_str());
1168  }
1169 }
1170 
1172 {
1173  if (data_ == nullptr) {
1174  return;
1175  }
1176 
1177  for (char* s1 = data_; *s1; s1++) {
1178  *s1 = static_cast<char>(tolower(*s1));
1179  }
1180 }
1181 
1183 {
1184  if (data_ == nullptr) {
1185  return;
1186  }
1187 
1188  for (char* s1 = data_; *s1; s1++) {
1189  *s1 = static_cast<char>(toupper(*s1));
1190  }
1191 }
1192 
1193 void OTString::Truncate(uint32_t lAt)
1194 {
1195  OTString strTruncated;
1196 
1197  strTruncated.Set(Get(), lAt);
1198 
1199  Set(strTruncated);
1200 }
1201 
1202 // If this string starts with -----BEGIN OT ARMORED...
1203 // Then this function will load it up into an OTASCIIArmor (removing
1204 // the bookends) and then decode it back into this string. This code
1205 // has been repeated around so I'm doing this as a refactoring exercise.
1206 //
1207 // Return value: true == There is a string in here that is not armored.
1208 // (Whether I actually HAD to unarmor it or not... it's
1209 // unarmored now.)
1210 // false == There was some error or the string is empty.
1211 //
1212 bool OTString::DecodeIfArmored(bool bEscapedIsAllowed)
1213 {
1214  if (!Exists()) return false;
1215 
1216  bool bArmoredAndALSOescaped = false; // "- -----BEGIN OT ARMORED"
1217  bool bArmoredButNOTescaped = false; // "-----BEGIN OT ARMORED"
1218 
1219  if (Contains(OT_BEGIN_ARMORED_escaped)) // check this one first...
1220  {
1221  bArmoredAndALSOescaped = true;
1222 
1223  if (!bEscapedIsAllowed) {
1224  otErr << __FUNCTION__ << ": Armored and escaped value passed in, "
1225  "but escaped are forbidden here. "
1226  "(Returning.)\n";
1227  return false;
1228  }
1229  }
1230  else if (Contains(OT_BEGIN_ARMORED)) {
1231  bArmoredButNOTescaped = true;
1232  }
1233 
1234  const bool bArmored = (bArmoredAndALSOescaped || bArmoredButNOTescaped);
1235 
1236  // Whether the string is armored or not, (-----BEGIN OT ARMORED)
1237  // either way, we'll end up with the decoded version in this variable:
1238  //
1239  std::string str_Trim;
1240 
1241  if (bArmored) // it's armored, we have to decode it first.
1242  {
1243  OTASCIIArmor ascTemp;
1244  if (false ==
1245  (ascTemp.LoadFromString(
1246  *this, bArmoredAndALSOescaped, // if it IS escaped or not, this
1247  // variable will be true or false
1248  // to show it.
1249  // The below szOverride sub-string determines where the content
1250  // starts, when loading.
1251  OT_BEGIN_ARMORED))) // Default is: "-----BEGIN"
1252  // We're doing this: "-----BEGIN OT ARMORED" (Should worked for
1253  // escaped as well, here.)
1254  {
1255  otErr << __FUNCTION__ << ": Error loading string contents from "
1256  "ascii-armored encoding. "
1257  "Contents: \n" << Get() << "\n";
1258  return false;
1259  }
1260  else // success loading the actual contents out of the ascii-armored
1261  // version.
1262  {
1263  OTString strTemp(ascTemp); // <=== ascii-decoded here.
1264  std::string str_temp(strTemp.Get(), strTemp.GetLength());
1265  str_Trim = OTString::trim(
1266  str_temp); // This is the std::string for the trim process.
1267  }
1268  }
1269  else {
1270  std::string str_temp(Get(), GetLength());
1271  str_Trim = OTString::trim(str_temp); // This is the std::string for the
1272  // trim process. (Wasn't armored,
1273  // so here we use it as passed in.)
1274  }
1275 
1276  // At this point, str_Trim contains the actual contents, whether they
1277  // were originally ascii-armored OR NOT. (And they are also now trimmed,
1278  // either way.)
1279 
1280  Release();
1281 
1282  if (str_Trim.size() > 0) Set(str_Trim.c_str());
1283 
1284  return Exists();
1285 }
1286 
1287 /*
1288  char *str_dup2(const char* str, int32_t length)
1289  {
1290  char *str_new;
1291  str_new = new char [length + 1];
1292  strncpy(str_new, str, length);
1293  str_new[length] = 0;
1294  return str_new;
1295  }
1296  */
1297 
1298 // inline bool vformat(const char* fmt, va_list vl, std::string& str_output)
1299 //{
1300 // int32_t size = 512;
1301 // char * buffer = new char[size];
1302 // buffer[0] = '\0';
1303 //
1304 // int32_t nsize = vsnprintf(buffer,size,fmt,vl);
1305 //
1306 // //fail -- delete buffer and try again
1307 // if(size <= nsize)
1308 // {
1309 // delete buffer; buffer = nullptr;
1310 // buffer = new char[nsize+1]; //+1 for /0
1311 // nsize = vsnprintf(buffer,nsize,fmt,vl);
1312 // }
1313 //
1314 // str_output = buffer;
1315 // delete buffer;
1316 // return true;
1317 //}
1318 
1319 void OTString::Format(const char* fmt, ...)
1320 {
1321  va_list vl;
1322  va_start(vl, fmt);
1323 
1324  std::string str_output;
1325 
1326  const bool bSuccess = OTString::vformat(fmt, &vl, str_output);
1327 
1328  va_end(vl);
1329 
1330  if (bSuccess) Set(str_output.c_str());
1331 }
1332 
1333 // append a string at the end of the current buffer.
1334 void OTString::Concatenate(const char* fmt, ...)
1335 {
1336  va_list vl;
1337  va_start(vl, fmt);
1338 
1339  std::string str_output;
1340 
1341  const bool bSuccess = OTString::vformat(fmt, &vl, str_output);
1342 
1343  va_end(vl);
1344 
1345  if (bSuccess) {
1346  const OTString strConcat(str_output);
1347 
1348  Concatenate(strConcat);
1349  }
1350 }
1351 
1352 // append a string at the end of the current buffer.
1353 void OTString::Concatenate(const OTString& strBuf)
1354 {
1355  std::string str_output;
1356 
1357  if ((length_ > 0) && (nullptr != data_)) str_output += data_;
1358 
1359  if (strBuf.Exists() && (strBuf.GetLength() > 0)) str_output += strBuf.Get();
1360 
1361  Set(str_output.c_str());
1362 }
1363 
1364 void OTString::WriteToFile(std::ostream& ofs) const
1365 {
1366  fwrite_string(ofs, data_);
1367 }
1368 
1369 /*
1370 void OTString::WriteToFile(FILE* fl) const
1371 {
1372  if (fl != nullptr)
1373  fwrite_string(fl, data_);
1374 }
1375 */
1376 
1377 // true == there are more lines to read.
1378 // false == this is the last line. Like EOF.
1379 //
1380 bool OTString::sgets(char* szBuffer, uint32_t nBufSize)
1381 {
1382  if (nullptr == szBuffer) {
1383  return false;
1384  }
1385 
1386  if (position_ >= length_) return false;
1387 
1388  uint32_t lIndex = 0;
1389  char* pChar = (char*)(data_ + position_);
1390 
1391  // while *pChar isn't at the end of the source string,
1392  // and lIndex hasn't reached the end of the destination buffer,
1393  //
1394  while (0 != *pChar && (position_ < length_) &&
1395  lIndex < (nBufSize - 1)) // the -1 leaves room for a forced null
1396  // terminator.
1397  {
1398  // If the current character isn't a newline, then copy it...
1399  if ('\n' != *pChar) {
1400  szBuffer[lIndex] = *pChar;
1401  lIndex++; // increment the buffer
1402  position_++; // increment the string's internal memory of where it
1403  // stopped.
1404  pChar++; // increment this for convenience (could calcuate from
1405  // position)
1406  }
1407  // Until we reach a newline...
1408  else {
1409  // IT'S A NEWLINE!
1410 
1411  szBuffer[lIndex] =
1412  0; // destination buffer, this is the end of the line for him.
1413  position_++; // This still moves past the newline, so the next
1414  // call will get the next
1415  // string.
1416  // lIndex does NOT increment here because we reach the end of this
1417  // string.
1418  // neither does pChar. These local variables go away since we are
1419  // returning.
1420 
1421  if (0 == *(pChar + 1))
1422  return false;
1423  else
1424  return true; // there was more to read, but we stopped at the
1425  // newline.
1426  }
1427  }
1428 
1429  // Need to add the nullptr terminator.
1430  szBuffer[lIndex] = 0;
1431 
1432  // We reached the end of the string.
1433  // EOF. So we return false to tell the caller not to bother calling again.
1434  if (0 == *pChar) {
1435  return false;
1436  }
1437 
1438  // Obviously if *pChar isn't at the end, then there was more to read,
1439  // but the buffer was full, so we return true.
1440  return true;
1441 }
1442 
1444 {
1445  char answer;
1446 
1447  if (position_ >= length_) {
1448  return EOF;
1449  }
1450  answer = (char)(*(data_ + position_));
1451 
1452  ++position_;
1453 
1454  return answer;
1455 }
1456 
1458 {
1459  if (position_ > 0) {
1460  --position_;
1461  }
1462 }
1463 
1465 {
1466  position_ = 0;
1467 }
1468 
1469 } // namespace opentxs
void Truncate(uint32_t index)
Definition: OTString.cpp:1193
EXPORT OTString & operator=(OTString rhs)
Definition: OTString.cpp:1011
uint32_t length_
Definition: OTString.hpp:275
static EXPORT int64_t StringToLong(const std::string &number)
Definition: OTString.cpp:677
std::ostream & operator<<(std::ostream &os, const OTIdentifier &obj)
static EXPORT uint64_t StringToUlong(const std::string &number)
Definition: OTString.cpp:662
const char * OT_BEGIN_ARMORED_escaped
size_t strlcpy(char *dst, const char *src, size_t siz)
static EXPORT bool safe_strcpy(char *dest, const char *src, size_t destSize, bool zeroSource=false)
Definition: OTString.cpp:353
void ConvertToUpperCase() const
Definition: OTString.cpp:1182
EXPORT int64_t ToLong() const
Definition: OTString.cpp:702
EXPORT OTString()
Definition: OTString.cpp:786
EXPORT void zeroMemory()
Definition: OTPassword.cpp:281
EXPORT void OTfgets(std::istream &ofs)
Definition: OTString.cpp:1159
#define MAX_STRING_LENGTH
Definition: OTString.hpp:147
EXPORT uint32_t GetLength() const
Definition: OTString.cpp:1040
char * str_dup2(const char *str, uint32_t length)
EXPORT void Concatenate(const char *arg,...)
Definition: OTString.cpp:1334
bool operator<(const OTString &rhs) const
Definition: OTString.cpp:477
void fwrite_string(std::ostream &ofs, const char *str)
Definition: OTString.cpp:519
EXPORT bool DecodeIfArmored(bool escapedIsAllowed=true)
Definition: OTString.cpp:1212
EXPORT bool Exists() const
Definition: OTString.cpp:1035
static EXPORT bool LoadFromString(OTASCIIArmor &ascArmor, const OTString &strInput, std::string str_bookend="-----BEGIN")
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
EXPORT bool Compare(const char *compare) const
Definition: OTString.cpp:1102
static size_t safe_strlen(const char *s, size_t max)
Definition: OTString.cpp:388
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
uint32_t position_
Definition: OTString.hpp:276
EXPORT bool TokenizeIntoKeyValuePairs(Map &map) const
Definition: OTString.cpp:550
void Release_String()
Definition: OTString.cpp:751
bool sgets(char *buffer, uint32_t size)
Definition: OTString.cpp:1380
bool operator>=(const OTString &rhs) const
Definition: OTString.cpp:505
#define OT_ASSERT(x)
Definition: Assert.hpp:150
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
OTLOG_IMPORT OTLogStream otInfo
EXPORT bool At(uint32_t index, char &c) const
Definition: OTString.cpp:1025
EXPORT bool SavePseudonym()
EXPORT const char * Get() const
Definition: OTString.cpp:1045
OTLOG_IMPORT OTLogStream otErr
EXPORT bool operator==(const OTString &rhs) const
Definition: OTString.cpp:1077
EXPORT void zeroMemory() const
Definition: OTString.cpp:744
bool operator<=(const OTString &rhs) const
Definition: OTString.cpp:491
EXPORT void GetString(OTString &theStr) const
EXPORT uint64_t ToUlong() const
Definition: OTString.cpp:695
EXPORT bool Contains(const char *compare) const
Definition: OTString.cpp:1137
static EXPORT std::string & trim(std::string &str)
Definition: OTString.cpp:398
EXPORT bool GetString(OTString &theData, bool bLineBreaks=true) const
bool operator>(const OTString &rhs) const
Definition: OTString.cpp:463
virtual EXPORT ~OTString()
Definition: OTString.cpp:774
static EXPORT void * safe_memcpy(void *dest, uint32_t dsize, const void *src, uint32_t ssize, bool zeroSource=false)
Definition: OTPassword.cpp:357
EXPORT bool MemSet(const char *mem, uint32_t size)
Definition: OTString.cpp:967
static bool vformat(const char *fmt, std::va_list *pvl, std::string &s)
Definition: OTString.cpp:191
virtual EXPORT void Release()
Definition: OTString.cpp:765
uint32_t GetSize() const
Definition: OTData.hpp:174
void WriteToFile(std::ostream &ofs) const
Definition: OTString.cpp:1364
const char * OT_BEGIN_ARMORED
static EXPORT std::string replace_chars(const std::string &str, const std::string &charsFrom, const char &charTo)
Definition: OTString.cpp:420
void swap(OTString &rhs)
Definition: OTString.cpp:1018
void ConvertToLowerCase() const
Definition: OTString.cpp:1171