ddnet/src/engine/server/sql_string_helpers.h
H-M-H 3b6baaa8d3 made CSqlData const for threadfunctions and added a class for sqlstrings
CSqlData is const for threadfunctions now to avoid modification from
within the threadfunctions as these might be called several times.
Previously this was a problem as ClearString could possibily be applied
multiple times to the same string.

To solve this the class CSqlString has been added. This class takes a
const char* and copies it. Additionally a clearstring is created from
the given const char*. This enables access to the original as well as
the cleared string safe for sql-statements.

sql_string_helpers got an own source file now.

A crashbug from CSqlServer has been fixed (pointer has not been set
back to 0)
2016-05-09 23:35:23 +02:00

49 lines
939 B
C++

#ifndef ENGINE_SERVER_SQL_STRING_HELPERS_H
#define ENGINE_SERVER_SQL_STRING_HELPERS_H
namespace sqlstr
{
void FuzzyString(char *pString);
// anti SQL injection
void ClearString(char *pString, int size = 32);
void agoTimeToString(int agoTime, char agoString[]);
void getTimeStamp(char* dest, unsigned int size);
template<unsigned int size>
class CSqlString
{
public:
CSqlString() {}
CSqlString(const char* pStr)
{
str_copy(m_aString, pStr, size);
str_copy(m_aClearString, pStr, size);
ClearString(m_aClearString, sizeof(m_aClearString));
}
const char* Str() const { return m_aString; }
const char* ClrStr() const { return m_aClearString; }
CSqlString& operator = (const char* pStr)
{
str_copy(m_aString, pStr, size);
str_copy(m_aClearString, pStr, size);
ClearString(m_aClearString, sizeof(m_aClearString));
return *this;
}
private:
char m_aString[size];
char m_aClearString[size * 2 - 1];
};
}
#endif