ddnet/src/engine/server/sql_string_helpers.h

51 lines
976 B
C
Raw Normal View History

#ifndef ENGINE_SERVER_SQL_STRING_HELPERS_H
#define ENGINE_SERVER_SQL_STRING_HELPERS_H
#include <base/system.h>
namespace sqlstr
{
2016-09-25 08:41:34 +00:00
void FuzzyString(char *pString, int size);
// anti SQL injection
void ClearString(char *pString, int size = 32);
2017-03-21 10:24:44 +00:00
void AgoTimeToString(int agoTime, char *pAgoString);
2017-03-21 10:24:44 +00:00
void GetTimeStamp(char *pDest, unsigned int Size);
template<unsigned int size>
class CSqlString
{
public:
CSqlString() {}
2017-03-21 10:24:44 +00:00
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; }
2017-03-21 10:24:44 +00:00
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