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:
psychon
2008-12-30 13:05:04 +00:00
parent fdb451a908
commit b7f38c4d4a
7 changed files with 86 additions and 112 deletions
+19 -9
View File
@@ -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);
+7 -4
View File
@@ -169,10 +169,13 @@ public:
{
EmailST tmp;
tmp.sUidl = (char *)CMD5(m_sMailBuffer.substr(0, 255));
CString sLine;
CString::size_type iPos = 0;
while (::ReadLine(m_sMailBuffer, sLine, iPos))
{
VCString vsLines;
VCString::iterator it;
m_sMailBuffer.Split("\n", vsLines);
for (it = vsLines.begin(); it != vsLines.end(); it++) {
CString sLine(*it);
sLine.Trim();
if (sLine.empty())
break; // out of the headers
+33 -16
View File
@@ -103,10 +103,13 @@ public:
if (!pChan->GetBuffer().empty())
return(true); // reloaded a module probably in this case, so just verify we can decrypt the file
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();
pChan->AddBuffer(sLine);
}
@@ -150,8 +153,12 @@ public:
CString sPath = GetPath(vChans[a]->GetName());
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();
}
}
}
@@ -172,10 +179,13 @@ public:
CString sFile;
if (DecryptChannel(sArgs, 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();
PutModule("[" + sLine + "]");
}
@@ -200,10 +210,13 @@ public:
PutUser(":***!znc@znc.in PRIVMSG " + sChan + " :Buffer Playback...");
if (DecryptChannel(sChan, 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();
PutUser(sLine);
}
@@ -213,7 +226,7 @@ public:
CString GetPath(const CString & sChannel)
{
CString sBuffer = m_pUser->GetUserName() + Lower(sChannel);
CString sBuffer = m_pUser->GetUserName() + sChannel.AsLower();
CString sRet = GetSavePath();
sRet += "/" + CBlowfish::MD5(sBuffer, true);
return(sRet);
@@ -289,9 +302,13 @@ private:
CString sFile;
sBuffer = "";
if ((sChannel.empty()) || (!ReadFile(sChannel, sFile)))
CFile File(sChannel);
if (sChannel.empty() || !File.Open(O_RDONLY) || !File.ReadFile(sFile))
return(true); // gonna be successful here
File.Close();
if (!sFile.empty())
{
CBlowfish c(m_sPassword, BF_DECRYPT);
+2 -2
View File
@@ -70,7 +70,7 @@ public:
for (unsigned int a = 0; a < m_vsSources.size(); a++) {
const CWatchSource& WatchSource = m_vsSources[a];
if (sSource.AsLower().WildCmp(Lower(WatchSource.GetSource()))) {
if (sSource.AsLower().WildCmp(WatchSource.GetSource().AsLower())) {
if (WatchSource.IsNegated()) {
return false;
} else {
@@ -80,7 +80,7 @@ public:
}
}
return (bGoodSource && Nick.GetHostMask().AsLower().WildCmp(Lower(m_sHostMask))) && sText.AsLower().WildCmp(Lower(m_sPattern));
return (bGoodSource && Nick.GetHostMask().AsLower().WildCmp(m_sHostMask.AsLower())) && sText.AsLower().WildCmp(m_sPattern.AsLower());
}
bool operator ==(const CWatchEntry& WatchEntry) {