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:
DokanSetFileAttributesW(const SString& cachePath) :
DokanSetFileAttributesW(const SString& cachePath, const NTSTATUS& ret) :
CEvent(EventLevel::Debug),
_cachePath(cachePath)
_cachePath(cachePath),
_ret(ret)
{
}
@@ -503,16 +504,17 @@ public:
private:
const SString _cachePath;
const NTSTATUS _ret;
public:
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
{
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)
{
// TODO Implement rolling/max size and timestamp
FilePath logPath("logs\\siadrive.log");
logPath.MakeAbsolute();
FilePath(logPath).RemoveFileName().CreateDirectory();
if (eventData.GetEventLevel() <= GetEventLevel())
{
// TODO Implement rolling/max size and timestamp
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::stringstream ss;
ss << std::put_time(std::localtime(&now), "%F %T ");
std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::stringstream ss;
ss << std::put_time(std::localtime(&now), "%F %T ");
FILE* logFile;
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());
fclose(logFile);
}
FILE* logFile;
if (fopen_s(&logFile, SString::ToUtf8(static_cast<SString>(logPath)).c_str(), "a+") == 0)
{
std::string msg = SString::ToUtf8(ss.str() + eventData.GetSingleLineMessage() + "\n");
fwrite(&msg[0], 1, msg.length(), logFile);
fclose(logFile);
}
}
}

View File

@@ -1,8 +1,96 @@
#include <siacurl.h>
#include <curl/curl.h>
#include <eventsystem.h>
#include <siaapi.h>
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()
{
SetHostConfig({ L"localhost", 9980, L""});
@@ -109,6 +197,7 @@ SiaCurlError CSiaCurl::_Get(const SString& path, const HttpParameters& parameter
SString result;
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SiaCurlBegin(false, url)));
const CURLcode res = curl_easy_perform(curlHandle);
long httpCode = 0;
@@ -116,6 +205,7 @@ SiaCurlError CSiaCurl::_Get(const SString& path, const HttpParameters& parameter
SiaCurlError ret = ProcessResponse(res, httpCode, result, response);
curl_easy_cleanup(curlHandle);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SiaCurlEnd(false, url, res, ret)));
return ret;
}
@@ -200,6 +290,7 @@ SiaCurlError CSiaCurl::Post(const SString& path, const HttpParameters& parameter
SString result;
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &result);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SiaCurlBegin(true, ConstructPath(path))));
const CURLcode res = curl_easy_perform(curlHandle);
long httpCode = 0;
@@ -207,6 +298,8 @@ SiaCurlError CSiaCurl::Post(const SString& path, const HttpParameters& parameter
ret = ProcessResponse(res, httpCode, result, response);
curl_easy_cleanup(curlHandle);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(SiaCurlEnd(false, ConstructPath(path), res, 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;
@@ -700,10 +697,7 @@ private:
::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;
}
@@ -1161,7 +1155,6 @@ private:
NTSTATUS ret = STATUS_SUCCESS;
FilePath filePath(GetCacheLocation(), fileName);
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanSetFileAttributesW(filePath)));
if (!::SetFileAttributes(&filePath[0], fileAttributes))
{
@@ -1169,6 +1162,7 @@ private:
ret = DokanNtStatusFromWin32(error);
}
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DokanSetFileAttributesW(filePath, ret)));
return ret;
}