Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTDB::StorageFS Class Reference

#include <OTStorage.hpp>

Inheritance diagram for opentxs::OTDB::StorageFS:
Collaboration diagram for opentxs::OTDB::StorageFS:

Public Member Functions

virtual bool Exists (std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
virtual int64_t FormPathString (std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
virtual ~StorageFS ()
 
bool ConfirmOrCreateFolder (const char *szFolderName, struct stat *pst=nullptr)
 
bool ConfirmFile (const char *szFileName, struct stat *pst=nullptr)
 
- Public Member Functions inherited from opentxs::OTDB::Storage
EXPORT OTPackerGetPacker (PackType ePackType=OTDB_DEFAULT_PACKER)
 
virtual ~Storage ()
 
EXPORT bool StoreString (std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
EXPORT std::string QueryString (std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
EXPORT bool StorePlainString (std::string strContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
EXPORT std::string QueryPlainString (std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
EXPORT bool StoreObject (Storable &theContents, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
EXPORT StorableQueryObject (StoredObjectType theObjectType, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
EXPORT std::string EncodeObject (Storable &theContents)
 
EXPORT StorableDecodeObject (StoredObjectType theObjectType, std::string strInput)
 
EXPORT bool EraseValueByKey (std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
EXPORT StorableCreateObject (StoredObjectType eType)
 
EXPORT StorageType GetType () const
 

Static Public Member Functions

static StorageFSInstantiate ()
 
- Static Public Member Functions inherited from opentxs::OTDB::Storage
static EXPORT StorageCreate (StorageType eStorageType, PackType ePackType)
 

Protected Member Functions

 StorageFS ()
 
int64_t ConstructAndConfirmPath (std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
int64_t ConstructAndCreatePath (std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
virtual bool onStorePackedBuffer (PackedBuffer &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
virtual bool onQueryPackedBuffer (PackedBuffer &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
virtual bool onStorePlainString (std::string &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
virtual bool onQueryPlainString (std::string &theBuffer, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
virtual bool onEraseValueByKey (std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
 
- Protected Member Functions inherited from opentxs::OTDB::Storage
 Storage ()
 
 Storage (const Storage &)
 
void SetPacker (OTPacker &thePacker)
 

Detailed Description

Definition at line 1812 of file OTStorage.hpp.

Constructor & Destructor Documentation

opentxs::OTDB::StorageFS::StorageFS ( )
protected

Definition at line 2923 of file OTStorage.cpp.

2924  : Storage()
2925 {
2926  OTString strDataPath;
2927  OTDataFolder::Get(strDataPath);
2928  m_strDataPath = strDataPath.Get();
2929 }
static EXPORT OTString Get()
opentxs::OTDB::StorageFS::~StorageFS ( )
virtual

Definition at line 2931 of file OTStorage.cpp.

2932 {
2933 }

Member Function Documentation

bool opentxs::OTDB::StorageFS::ConfirmFile ( const char *  szFileName,
struct stat *  pst = nullptr 
)

Definition at line 2530 of file OTStorage.cpp.

2531 {
2532  OTString strFilePath("");
2533  OTPaths::AppendFile(strFilePath, m_strDataPath, szFileName);
2534  return OTPaths::PathExists(strFilePath);
2535 }
static EXPORT bool AppendFile(OTString &out_strPath, const OTString &strBasePath, const OTString &strFileName)
Definition: OTPaths.cpp:1245
static EXPORT bool PathExists(const OTString &strPath)
Definition: OTPaths.cpp:802
bool opentxs::OTDB::StorageFS::ConfirmOrCreateFolder ( const char *  szFolderName,
struct stat *  pst = nullptr 
)

Definition at line 2516 of file OTStorage.cpp.

2517 {
2518  bool bConfirmOrCreateSuccess = false, bFolderAlreadyExist = false;
2519  OTString strFolderName(szFolderName);
2520  if (!OTPaths::ConfirmCreateFolder(strFolderName, bConfirmOrCreateSuccess,
2521  bFolderAlreadyExist)) {
2522  OT_FAIL;
2523  };
2524  return bConfirmOrCreateSuccess;
2525 }
#define OT_FAIL
Definition: Assert.hpp:139
static EXPORT bool ConfirmCreateFolder(const OTString &strExactPath, bool &out_Exists, bool &out_IsNew)
Definition: OTPaths.cpp:921
int64_t opentxs::OTDB::StorageFS::ConstructAndConfirmPath ( std::string &  strOutput,
std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
protected

Definition at line 2562 of file OTStorage.cpp.

2567 {
2568  return ConstructAndConfirmPathImp(false, strOutput, strFolder, oneStr,
2569  twoStr, threeStr);
2570 }
int64_t opentxs::OTDB::StorageFS::ConstructAndCreatePath ( std::string &  strOutput,
std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
protected

Definition at line 2552 of file OTStorage.cpp.

2557 {
2558  return ConstructAndConfirmPathImp(true, strOutput, strFolder, oneStr,
2559  twoStr, threeStr);
2560 }
bool opentxs::OTDB::StorageFS::Exists ( std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
virtual

Implements opentxs::OTDB::Storage.

Definition at line 2937 of file OTStorage.cpp.

2939 {
2940  std::string strOutput;
2941 
2942  return (0 < ConstructAndConfirmPath(strOutput, strFolder, oneStr, twoStr,
2943  threeStr));
2944 }
int64_t ConstructAndConfirmPath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2562
int64_t opentxs::OTDB::StorageFS::FormPathString ( std::string &  strOutput,
std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
virtual

Implements opentxs::OTDB::Storage.

Definition at line 2948 of file OTStorage.cpp.

2951 {
2952  return ConstructAndConfirmPath(strOutput, strFolder, oneStr, twoStr,
2953  threeStr);
2954 }
int64_t ConstructAndConfirmPath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2562
static StorageFS* opentxs::OTDB::StorageFS::Instantiate ( )
inlinestatic

Definition at line 1896 of file OTStorage.hpp.

1897  {
1898  return new StorageFS;
1899  }
bool opentxs::OTDB::StorageFS::onEraseValueByKey ( std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
protectedvirtual

Implements opentxs::OTDB::Storage.

Definition at line 2862 of file OTStorage.cpp.

2864 {
2865  std::string strOutput;
2866 
2867  if (0 > ConstructAndConfirmPath(strOutput, strFolder, oneStr, twoStr,
2868  threeStr)) {
2869  otErr << "Error: " << __FUNCTION__
2870  << ": Failed calling ConstructAndConfirmPath with:\n"
2871  "strOutput: " << strOutput << " | strFolder: " << strFolder
2872  << " | oneStr: " << oneStr << " | twoStr: " << twoStr
2873  << " | threeStr: " << threeStr << " \n";
2874 
2875  return false;
2876  }
2877 
2878  // TODO: Should check here to see if there is a .lock file for the target...
2879 
2880  // TODO: If not, next I should actually create a .lock file for myself right
2881  // here..
2882 
2883  // SAVE to the file here. (a blank string.)
2884  //
2885  // Here's where the serialization code would be changed to CouchDB or
2886  // whatever.
2887  // In a key/value database, szFilename is the "key" and strFinal.Get() is
2888  // the "value".
2889  //
2890  std::ofstream ofs(strOutput.c_str(), std::ios::out | std::ios::binary);
2891 
2892  if (ofs.fail()) {
2893  otErr << "Error opening file in StorageFS::onEraseValueByKey: "
2894  << strOutput << "\n";
2895  return false;
2896  }
2897 
2898  ofs.clear();
2899  ofs << "(This space intentionally left blank.)\n";
2900  bool bSuccess = ofs.good() ? true : false;
2901  ofs.close();
2902  // Note: I bet you think I should be overwriting the file 7 times here with
2903  // random data, right? Wrong: YOU need to override OTStorage and create your
2904  // own subclass, where you can override onEraseValueByKey and do that stuff
2905  // yourself. It's outside of the scope of OT.
2906 
2907  if (remove(strOutput.c_str()) != 0) {
2908  bSuccess = false;
2909  otErr << "** Failed trying to delete file: " << strOutput << " \n";
2910  }
2911  else {
2912  bSuccess = true;
2913  otInfo << "** Success deleting file: " << strOutput << " \n";
2914  }
2915 
2916  // TODO: Remove the .lock file.
2917 
2918  return bSuccess;
2919 }
int64_t ConstructAndConfirmPath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2562
OTLOG_IMPORT OTLogStream otInfo
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTDB::StorageFS::onQueryPackedBuffer ( PackedBuffer theBuffer,
std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
protectedvirtual

Implements opentxs::OTDB::Storage.

Definition at line 2730 of file OTStorage.cpp.

2733 {
2734  std::string strOutput;
2735 
2736  int64_t lRet =
2737  ConstructAndConfirmPath(strOutput, strFolder, oneStr, twoStr, threeStr);
2738 
2739  if (0 > lRet) {
2740  otErr << "StorageFS::" << __FUNCTION__ << ": Error with " << strOutput
2741  << ".\n";
2742  return false;
2743  }
2744  else if (0 == lRet) {
2745  otErr << "StorageFS::" << __FUNCTION__ << ": Failure reading from "
2746  << strOutput << ": file does not exist.\n";
2747  return false;
2748  }
2749 
2750  // READ from the file here
2751 
2752  std::ifstream fin(strOutput.c_str(), std::ios::in | std::ios::binary);
2753 
2754  if (!fin.is_open()) {
2755  otErr << __FUNCTION__ << ": Error opening file: " << strOutput << "\n";
2756  return false;
2757  }
2758 
2759  bool bSuccess = theBuffer.ReadFromIStream(fin, lRet);
2760 
2761  fin.close();
2762 
2763  return bSuccess;
2764 }
int64_t ConstructAndConfirmPath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2562
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTDB::StorageFS::onQueryPlainString ( std::string &  theBuffer,
std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
protectedvirtual

Implements opentxs::OTDB::Storage.

Definition at line 2810 of file OTStorage.cpp.

2813 {
2814  std::string strOutput;
2815 
2816  int64_t lRet =
2817  ConstructAndConfirmPath(strOutput, strFolder, oneStr, twoStr, threeStr);
2818 
2819  if (0 > lRet) {
2820  otErr << "StorageFS::" << __FUNCTION__ << ": Error with " << strOutput
2821  << ".\n";
2822  return false;
2823  }
2824  else if (0 == lRet) {
2825  otErr << "StorageFS::" << __FUNCTION__ << ": Failure reading from "
2826  << strOutput << ": file does not exist.\n";
2827  return false;
2828  }
2829 
2830  // Open the file here
2831 
2832  std::ifstream fin(strOutput.c_str(), std::ios::in | std::ios::binary);
2833 
2834  if (!fin.is_open()) {
2835  otErr << __FUNCTION__ << ": Error opening file: " << strOutput << "\n";
2836  return false;
2837  }
2838 
2839  // Read from the file as a plain string.
2840 
2841  std::stringstream buffer;
2842  buffer << fin.rdbuf();
2843 
2844  bool bSuccess = fin.good();
2845 
2846  if (bSuccess)
2847  theBuffer = buffer.str(); // here's the actual output of this function.
2848  else {
2849  theBuffer = "";
2850  return false;
2851  }
2852 
2853  bSuccess = (theBuffer.length() > 0);
2854 
2855  fin.close();
2856 
2857  return bSuccess;
2858 }
int64_t ConstructAndConfirmPath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2562
OTLOG_IMPORT OTLogStream otErr
bool opentxs::OTDB::StorageFS::onStorePackedBuffer ( PackedBuffer theBuffer,
std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
protectedvirtual

Implements opentxs::OTDB::Storage.

Definition at line 2696 of file OTStorage.cpp.

2699 {
2700  std::string strOutput;
2701 
2702  if (0 > ConstructAndCreatePath(strOutput, strFolder, oneStr, twoStr,
2703  threeStr)) {
2704  otErr << __FUNCTION__ << ": Error writing to " << strOutput << ".\n";
2705  return false;
2706  }
2707 
2708  // TODO: Should check here to see if there is a .lock file for the target...
2709 
2710  // TODO: If not, next I should actually create a .lock file for myself right
2711  // here..
2712 
2713  // SAVE to the file here
2714  std::ofstream ofs(strOutput.c_str(), std::ios::out | std::ios::binary);
2715 
2716  if (ofs.fail()) {
2717  otErr << __FUNCTION__ << ": Error opening file: " << strOutput << "\n";
2718  return false;
2719  }
2720 
2721  ofs.clear();
2722  bool bSuccess = theBuffer.WriteToOStream(ofs);
2723  ofs.close();
2724 
2725  // TODO: Remove the .lock file.
2726 
2727  return bSuccess;
2728 }
OTLOG_IMPORT OTLogStream otErr
int64_t ConstructAndCreatePath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2552
bool opentxs::OTDB::StorageFS::onStorePlainString ( std::string &  theBuffer,
std::string  strFolder,
std::string  oneStr = "",
std::string  twoStr = "",
std::string  threeStr = "" 
)
protectedvirtual

Implements opentxs::OTDB::Storage.

Definition at line 2768 of file OTStorage.cpp.

2771 {
2772  std::string strOutput;
2773 
2774  if (0 > ConstructAndCreatePath(strOutput, strFolder, oneStr, twoStr,
2775  threeStr)) {
2776  otErr << "StorageFS::" << __FUNCTION__ << ": Error writing to "
2777  << strOutput << ".\n";
2778  return false;
2779  }
2780 
2781  // TODO: Should check here to see if there is a .lock file for the target...
2782 
2783  // TODO: If not, next I should actually create a .lock file for myself right
2784  // here..
2785 
2786  // SAVE to the file here.
2787  //
2788  // Here's where the serialization code would be changed to CouchDB or
2789  // whatever.
2790  // In a key/value database, szFilename is the "key" and strFinal.Get() is
2791  // the "value".
2792  //
2793  std::ofstream ofs(strOutput.c_str(), std::ios::out | std::ios::binary);
2794 
2795  if (ofs.fail()) {
2796  otErr << __FUNCTION__ << ": Error opening file: " << strOutput << "\n";
2797  return false;
2798  }
2799 
2800  ofs.clear();
2801  ofs << theBuffer;
2802  bool bSuccess = ofs.good();
2803  ofs.close();
2804 
2805  // TODO: Remove the .lock file.
2806 
2807  return bSuccess;
2808 }
OTLOG_IMPORT OTLogStream otErr
int64_t ConstructAndCreatePath(std::string &strOutput, std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:2552

The documentation for this class was generated from the following files: