mirror of
https://github.com/znc/znc.git
synced 2026-07-02 16:02:02 +02:00
Remove some code duplications and move functions into classes
This removes ReadFile(), WriteFile(), ReadLine(), Lower() and Upper() from Utils.h and adds CFile::ReadFile(). The biggest part of this patch fixes modules to use CFile and CString instead of these global functions. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1311 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
+19
-9
@@ -101,15 +101,17 @@ public:
|
||||
CString sFile;
|
||||
if (DecryptMessages(sFile))
|
||||
{
|
||||
CString sLine;
|
||||
CString::size_type iPos = 0;
|
||||
while (ReadLine(sFile, sLine, iPos))
|
||||
{
|
||||
VCString vsLines;
|
||||
VCString::iterator it;
|
||||
|
||||
sFile.Split("\n", vsLines);
|
||||
|
||||
for (it = vsLines.begin(); it != vsLines.end(); it++) {
|
||||
CString sLine(*it);
|
||||
sLine.Trim();
|
||||
AddMessage(sLine);
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
m_sPassword = "";
|
||||
CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt Messages");
|
||||
return(false);
|
||||
@@ -132,8 +134,12 @@ public:
|
||||
CString sPath = GetPath();
|
||||
if (!sPath.empty())
|
||||
{
|
||||
WriteFile(sPath, sFile);
|
||||
chmod(sPath.c_str(), 0600);
|
||||
CFile File(sPath);
|
||||
if (File.Open(O_WRONLY | O_CREAT | O_TRUNC, 0600)) {
|
||||
File.Chmod(0600);
|
||||
File.Write(sFile);
|
||||
}
|
||||
File.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,12 +385,16 @@ private:
|
||||
CString sFile;
|
||||
sBuffer = "";
|
||||
|
||||
if ((sMessages.empty()) || (!ReadFile(sMessages, sFile)))
|
||||
CFile File(sMessages);
|
||||
|
||||
if (sMessages.empty() || !File.Open(O_RDONLY) || !File.ReadFile(sFile))
|
||||
{
|
||||
PutModule("Unable to find buffer");
|
||||
return(true); // gonna be successful here
|
||||
}
|
||||
|
||||
File.Close();
|
||||
|
||||
if (!sFile.empty())
|
||||
{
|
||||
CBlowfish c(m_sPassword, BF_DECRYPT);
|
||||
|
||||
Reference in New Issue
Block a user