Move GUI code from C4InputValidation to C4GonfigShareware

That way, C4InputValidation can be used by C4Group as is.
stable-5.2
Günther Brammer 2009-06-17 21:43:13 +02:00
parent 7fe7e557e0
commit fb249aafcd
7 changed files with 24 additions and 32 deletions

View File

@ -46,9 +46,6 @@ namespace C4InVal
bool ValidateInt(int32_t &riVal, int32_t iMinVal, int32_t iMaxVal);
inline bool ValidateFilename(char *szFilename, size_t iMaxSize=_MAX_PATH) { return ValidateString(szFilename, VAL_Filename, iMaxSize); }
// checks for phising attacks: Return true if input contains user's webcode
bool IsConfidentialData(const char *szInput, bool fShowWarningMessage);
};
// Validation adapter: Call ValidateString on string after compiling it

View File

@ -23,6 +23,7 @@
#include <C4ConfigShareware.h>
#include <C4SecurityCertificates.h>
#include <C4Log.h>
#include <C4Gui.h>
#include <StdFile.h>
@ -484,3 +485,21 @@ void C4ConfigShareware::ClearRegistrationError()
// Reset error message(s)
RegistrationError.Clear();
}
bool C4ConfigShareware::IsConfidentialData(const char *szInput, bool fShowWarningMessage)
{
// safety
if (!szInput) return false;
// unreg users don't have confidential data
if (!Config.Registered()) return false;
// shouldn't send the webcode!
const char *szWebCode = GetRegistrationData("WebCode");
if (szWebCode && *szWebCode) if (SSearchNoCase(szInput, szWebCode))
{
if (fShowWarningMessage && ::pGUI)
::pGUI->ShowErrorMessage(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN"));
return true;
}
// all OK
return false;
}

View File

@ -53,6 +53,8 @@ class C4ConfigShareware: public C4Config
const char* GetInvalidKeyFilename();
const char* GetKeyPath();
StdStrBuf GetKeyMD5();
// checks for phising attacks: Return true if input contains user's webcode
bool IsConfidentialData(const char *szInput, bool fShowWarningMessage);
protected:
StdStrBuf RegistrationError;
bool HandleError(const char *strMessage);

View File

@ -836,7 +836,7 @@ bool C4ChatControl::ProcessInput(const char *szInput, ChatSheet *pChatSheet)
// safety
if (!szInput || !*szInput || !pChatSheet) return fResult;
// check confidential data
if (C4InVal::IsConfidentialData(szInput, true)) return fResult;
if (Config.IsConfidentialData(szInput, true)) return fResult;
// command?
if (*szInput == '/' && !SEqual2NoCase(szInput + 1, "me "))
{

View File

@ -449,7 +449,7 @@ C4GUI::Edit::InputResult MainDlg::OnChatInput(C4GUI::Edit *edt, bool fPasting, b
::MessageInput.StoreBackBuffer(szInputText);
bool fProcessed = false;
// check confidential data
if (C4InVal::IsConfidentialData(szInputText, true)) fProcessed = true;
if (Config.IsConfidentialData(szInputText, true)) fProcessed = true;
// CAUTION when implementing special commands (like /quit) here:
// those must not be executed when text is pasted, because that could crash the GUI system
// when there are additional lines to paste, but the edit field is destructed by the command

View File

@ -23,10 +23,6 @@
#include <C4Log.h>
#include <C4Config.h>
#ifdef C4ENGINE
// FIXME: One should not have to include C4Game.h for pGUI
#include <C4Game.h>
#endif
#include <cctype>
namespace C4InVal
@ -178,26 +174,4 @@ namespace C4InVal
else if (riVal > iMaxVal) { riVal = iMaxVal; return false; }
else return true;
}
bool IsConfidentialData(const char *szInput, bool fShowWarningMessage)
{
// safety
if (!szInput) return false;
#ifdef C4ENGINE
// unreg users don't have confidential data
if (!Config.Registered()) return false;
// shouldn't send the webcode!
const char *szWebCode = Config.GetRegistrationData("WebCode");
if (szWebCode && *szWebCode) if (SSearchNoCase(szInput, szWebCode))
{
if (fShowWarningMessage && ::pGUI)
::pGUI->ShowErrorMessage(LoadResStr("IDS_ERR_WARNINGYOUWERETRYINGTOSEN"));
return true;
}
#endif
// all OK
return false;
}
};

View File

@ -132,7 +132,7 @@ C4GUI::Edit::InputResult C4ChatInputDialog::OnChatInput(C4GUI::Edit *edt, bool f
// Store to back buffer
::MessageInput.StoreBackBuffer(szInputText);
// check confidential data - even for object input (script triggered), webcode should not be pasted here
if (C4InVal::IsConfidentialData(szInputText, true))
if (Config.IsConfidentialData(szInputText, true))
{
szInputText = "";
}