1
0
This commit is contained in:
Scott E. Graves
2017-04-05 18:01:29 -05:00
parent 871d22cb69
commit 2be0d08359
4 changed files with 119 additions and 26 deletions

View File

@@ -490,9 +490,10 @@ class SIADRIVE_DOKAN_EXPORTABLE DokanSetFileAttributesW :
public CEvent public CEvent
{ {
public: public:
DokanSetFileAttributesW(const SString& cachePath) : DokanSetFileAttributesW(const SString& cachePath, const NTSTATUS& ret) :
CEvent(EventLevel::Debug), CEvent(EventLevel::Debug),
_cachePath(cachePath) _cachePath(cachePath),
_ret(ret)
{ {
} }
@@ -503,16 +504,17 @@ public:
private: private:
const SString _cachePath; const SString _cachePath;
const NTSTATUS _ret;
public: public:
virtual std::shared_ptr<CEvent> Clone() const override virtual std::shared_ptr<CEvent> Clone() const override
{ {
return std::shared_ptr<CEvent>(new DokanSetFileAttributesW(_cachePath)); return std::shared_ptr<CEvent>(new DokanSetFileAttributesW(_cachePath, _ret));
} }
virtual SString GetSingleLineMessage() const override virtual SString GetSingleLineMessage() const override
{ {
return L"DokanSetFileAttributesW|PATH|" + _cachePath; return L"DokanSetFileAttributesW|PATH|" + _cachePath + "|RET|" + SString::FromUInt64(_ret);
} }
}; };

View File

@@ -17,19 +17,23 @@ CLoggingConsumer::~CLoggingConsumer()
void CLoggingConsumer::ProcessEvent(const CEvent& eventData) void CLoggingConsumer::ProcessEvent(const CEvent& eventData)
{ {
// TODO Implement rolling/max size and timestamp if (eventData.GetEventLevel() <= GetEventLevel())
FilePath logPath("logs\\siadrive.log"); {
logPath.MakeAbsolute(); // TODO Implement rolling/max size and timestamp
FilePath(logPath).RemoveFileName().CreateDirectory(); FilePath logPath("logs\\siadrive.log");
logPath.MakeAbsolute();
FilePath(logPath).RemoveFileName().CreateDirectory();
std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::stringstream ss; std::stringstream ss;
ss << std::put_time(std::localtime(&now), "%F %T "); ss << std::put_time(std::localtime(&now), "%F %T ");
FILE* logFile; FILE* logFile;
if (fopen_s(&logFile, SString::ToUtf8(static_cast<SString>(logPath)).c_str(), "a+") == 0) if (fopen_s(&logFile, SString::ToUtf8(static_cast<SString>(logPath)).c_str(), "a+") == 0)
{ {
fprintf_s(logFile, SString::ToUtf8(ss.str() + eventData.GetSingleLineMessage() + "\n").c_str()); std::string msg = SString::ToUtf8(ss.str() + eventData.GetSingleLineMessage() + "\n");
fclose(logFile); fwrite(&msg[0], 1, msg.length(), logFile);
} fclose(logFile);
}
}
} }

View File

@@ -1,8 +1,96 @@
#include <siacurl.h> #include <siacurl.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <eventsystem.h>
#include <siaapi.h>
using namespace Sia::Api; using namespace Sia::Api;
class SiaCurlBegin :
public CEvent
{
public:
SiaCurlBegin(const bool& isPost, const SString& url) :
CEvent(EventLevel::Debug),
_type(isPost ? "POST" : "GET"),
_url(url)
{
}
private:
SiaCurlBegin(const SString& type, const SString& url) :
CEvent(EventLevel::Debug),
_type(type),
_url(url)
{
}
public:
virtual ~SiaCurlBegin()
{
}
private:
const SString _type;
const SString _url;
public:
virtual SString GetSingleLineMessage() const override
{
return L"SiaCurlBegin|" + _type + "|URL|" + _url;
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new SiaCurlBegin(_type, _url));
}
};
class SiaCurlEnd :
public CEvent
{
public:
SiaCurlEnd(const bool& isPost, const SString& url, const CURLcode& curlCode, const SiaCurlError& siaCurlError) :
CEvent(EventLevel::Debug),
_type(isPost ? "POST" : "GET"),
_url(url),
_curlCode(curlCode),
_siaCurlError(siaCurlError)
{
}
private:
SiaCurlEnd(const SString& type, const SString& url, const CURLcode& curlCode, const SiaCurlError& siaCurlError) :
CEvent(EventLevel::Debug),
_type(type),
_url(url),
_curlCode(curlCode),
_siaCurlError(siaCurlError)
{
}
public:
virtual ~SiaCurlEnd()
{
}
private:
const SString _type;
const SString _url;
const CURLcode _curlCode;
const SiaCurlError _siaCurlError;
public:
virtual SString GetSingleLineMessage() const override
{
return L"SiaCurlEnd|" + _type + +"|URL|" + _url + "|CODE|" + SString::FromInt32(_curlCode) + "|ERROR|" + _siaCurlError.GetReason();
}
virtual std::shared_ptr<CEvent> Clone() const override
{
return std::shared_ptr<CEvent>(new SiaCurlEnd(_type, _url, _curlCode, _siaCurlError));
}
};
CSiaCurl::CSiaCurl() CSiaCurl::CSiaCurl()
{ {
SetHostConfig({ L"localhost", 9980, L""}); SetHostConfig({ L"localhost", 9980, L""});
@@ -109,6 +197,7 @@ SiaCurlError CSiaCurl::_Get(const SString& path, const HttpParameters& parameter
SString result; SString result;
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result); curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SiaCurlBegin(false, url)));
const CURLcode res = curl_easy_perform(curlHandle); const CURLcode res = curl_easy_perform(curlHandle);
long httpCode = 0; long httpCode = 0;
@@ -116,6 +205,7 @@ SiaCurlError CSiaCurl::_Get(const SString& path, const HttpParameters& parameter
SiaCurlError ret = ProcessResponse(res, httpCode, result, response); SiaCurlError ret = ProcessResponse(res, httpCode, result, response);
curl_easy_cleanup(curlHandle); curl_easy_cleanup(curlHandle);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SiaCurlEnd(false, url, res, ret)));
return ret; return ret;
} }
@@ -200,6 +290,7 @@ SiaCurlError CSiaCurl::Post(const SString& path, const HttpParameters& parameter
SString result; SString result;
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result); curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SiaCurlBegin(true, ConstructPath(path))));
const CURLcode res = curl_easy_perform(curlHandle); const CURLcode res = curl_easy_perform(curlHandle);
long httpCode = 0; long httpCode = 0;
@@ -207,6 +298,8 @@ SiaCurlError CSiaCurl::Post(const SString& path, const HttpParameters& parameter
ret = ProcessResponse(res, httpCode, result, response); ret = ProcessResponse(res, httpCode, result, response);
curl_easy_cleanup(curlHandle); curl_easy_cleanup(curlHandle);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SiaCurlEnd(false, ConstructPath(path), res, ret)));
} }
return ret; return ret;

View File

@@ -471,10 +471,7 @@ private:
} }
} }
if (ret != STATUS_SUCCESS) CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanCreateFile(cacheFilePath, fileAttributesAndFlags, creationDisposition, genericDesiredAccess, ret)));
{
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanCreateFile(cacheFilePath, fileAttributesAndFlags, creationDisposition, genericDesiredAccess, ret)));
}
} }
return ret; return ret;
@@ -700,10 +697,7 @@ private:
::CloseHandle(tempHandle); ::CloseHandle(tempHandle);
} }
if (ret != STATUS_SUCCESS) CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanGetFileInformation(openFileInfo->CacheFilePath, fileName, ret)));
{
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanGetFileInformation(openFileInfo->CacheFilePath, fileName, ret)));
}
return ret; return ret;
} }
@@ -1161,7 +1155,6 @@ private:
NTSTATUS ret = STATUS_SUCCESS; NTSTATUS ret = STATUS_SUCCESS;
FilePath filePath(GetCacheLocation(), fileName); FilePath filePath(GetCacheLocation(), fileName);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanSetFileAttributesW(filePath)));
if (!::SetFileAttributes(&filePath[0], fileAttributes)) if (!::SetFileAttributes(&filePath[0], fileAttributes))
{ {
@@ -1169,6 +1162,7 @@ private:
ret = DokanNtStatusFromWin32(error); ret = DokanNtStatusFromWin32(error);
} }
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanSetFileAttributesW(filePath, ret)));
return ret; return ret;
} }