20 #include <znc/zncconfig.h> 31 static inline void SetFdCloseOnExec(
int fd) {
32 int flags = fcntl(fd, F_GETFD, 0);
33 if (flags < 0)
return;
35 fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
38 static const char g_HexDigits[] =
"0123456789abcdef";
71 unsigned int uMin = 0,
unsigned int uMax = ~0,
72 unsigned int uDefault = ~0);
172 class CTable :
protected std::vector<std::vector<CString>> {
208 size_type uRowIdx = ~0);
229 using std::vector<std::vector<CString>>::size;
232 using std::vector<std::vector<CString>>::empty;
235 unsigned int GetColumnIndex(
const CString& sName)
const;
245 #include <openssl/aes.h> 246 #include <openssl/blowfish.h> 247 #include <openssl/md5.h> 264 static unsigned char*
MD5(
const unsigned char* input,
unsigned int ilen);
270 void Crypt(
unsigned char* input,
unsigned char* output,
271 unsigned int ibytes);
274 unsigned char*
Crypt(
unsigned char* input,
unsigned int ibytes);
278 unsigned char* m_ivec;
280 int m_iEncrypt, m_num;
290 template <
typename K,
typename V =
bool>
323 void AddItem(
const K& Item,
const V& Val,
unsigned int uTTL) {
352 if (it ==
m_mItems.end())
return nullptr;
353 return &it->second.second;
388 std::map<K, V> mItems;
390 mItems[it.first] = it.second.second;
402 typedef std::pair<unsigned long long, V>
value;
403 typedef typename std::map<K, value>::iterator
iterator;
409 #endif // !ZNC_UTILS_H EType GetType() const
Definition: Utils.h:124
std::map< K, V > GetItems()
Returns all entries.
Definition: Utils.h:386
void Cleanup()
Cycles through the queue removing all of the stale entries.
Definition: Utils.h:366
bool HasItem(const K &Item)
Performs a Cleanup() and then checks to see if your item exists.
Definition: Utils.h:339
void Crypt(unsigned char *input, unsigned char *output, unsigned int ibytes)
output must be the same size as input
static void PrintMessage(const CString &sMessage, bool bStrong=false)
void AddItem(const K &Item)
This function adds an item to the cache using the default time-to-live value.
Definition: Utils.h:301
V * GetItem(const K &Item)
Performs a Cleanup() and returns a pointer to the object, or nullptr.
Definition: Utils.h:349
EStyle eStyle
Definition: Utils.h:241
unsigned int GetTTL() const
Definition: Utils.h:399
EType m_eType
Definition: Utils.h:128
static bool CheckCIDR(const CString &sIP, const CString &sRange)
CIDR notation checker, e.g.
does Blowfish w/64 bit feedback, no padding
Definition: Utils.h:249
std::map< CString, CString::size_type > m_msuWidths
Definition: Utils.h:240
virtual ~CTable()
Definition: Utils.h:176
static CString AskSaltedHashPassForConfig()
Asks password from stdin, with confirmation.
void SetTTL(unsigned int u)
Definition: Utils.h:396
static unsigned long long GetMillTime()
static void SetMessageTags(CString &sLine, const MCString &mssTags)
EStyle
Definition: Utils.h:174
std::vector< CString > m_vsHeaders
Definition: Utils.h:238
static void PrintStatus(bool bSuccess, const CString &sMessage="")
static CString GetIP(unsigned long addr)
std::set< CString > SCString
Definition: ZNCString.h:35
static unsigned long GetLongIP(const CString &sIP)
virtual ~CException()
Definition: Utils.h:122
static bool GetNumInput(const CString &sPrompt, unsigned int &uRet, unsigned int uMin=0, unsigned int uMax=~0, unsigned int uDefault=~0)
CBlowfish & operator=(const CBlowfish &)=default
CString::size_type GetColumnWidth(unsigned int uIdx) const
Return the width of the given column.
static SCString GetEncodings()
static MCString GetMessageTags(const CString &sLine)
CException(EType e)
Definition: Utils.h:121
static CString FormatTime(time_t t, const CString &sFormat, const CString &sTZ)
String class that is used inside ZNC.
Definition: ZNCString.h:68
bool AddColumn(const CString &sName)
Adds a new column to the table.
bool GetLine(unsigned int uIdx, CString &sLine) const
Get a line of the table's output.
virtual ~TCacheMap()
Definition: Utils.h:295
static CString SaltedSHA256Hash(const CString &sPass, const CString &sSalt)
bool RemItem(const K &Item)
Removes a specific item from the cache.
Definition: Utils.h:361
static CString FormatServerTime(const timeval &tv)
static CString SaltedHash(const CString &sPass, const CString &sSalt)
static SCString GetTimezones()
static bool GetBoolInput(const CString &sPrompt, bool bDefault)
std::map< K, value > m_mItems
Map of cached items.
Definition: Utils.h:405
static void PrintAction(const CString &sMessage)
static void PrintError(const CString &sMessage)
void AddItem(const K &Item, const V &Val)
This function adds an item to the cache using the default time-to-live value.
Definition: Utils.h:315
bool SetStyle(EStyle eNewStyle)
Selects the output style of the table.
A dictionary for strings.
Definition: ZNCString.h:595
static CString GetPass(const CString &sPrompt)
std::pair< unsigned long long, V > value
Definition: Utils.h:402
void AddItem(const K &Item, unsigned int uTTL)
This function adds an item to the cache using a custom time-to-live value.
Definition: Utils.h:308
static CString CTime(time_t t, const CString &sTZ)
void AddItem(const K &Item, const V &Val, unsigned int uTTL)
This function adds an item to the cache using a custom time-to-live value.
Definition: Utils.h:323
void Clear()
Completely clear the table.
Insert an object with a time-to-live and check later if it still exists.
Definition: Utils.h:291
static unsigned char * MD5(const unsigned char *input, unsigned int ilen)
output must be freed
unsigned int m_uTTL
Default time-to-live duration.
Definition: Utils.h:406
static timeval ParseServerTime(const CString &sTime)
TCacheMap(unsigned int uTTL=5000)
Definition: Utils.h:293
void Clear()
Clear all entries.
Definition: Utils.h:381
CBlowfish(const CString &sPassword, int iEncrypt, const CString &sIvec="")
CTable()
Definition: Utils.h:175
std::map< CString, value >::iterator iterator
Definition: Utils.h:403
EType
Definition: Utils.h:119
Generate a grid-like or list-like output from a given input.
Definition: Utils.h:172
size_type AddRow()
Adds a new row to the table.
static void GenerateCert(FILE *pOut, const CString &sHost="")
static CString SaltedMD5Hash(const CString &sPass, const CString &sSalt)
static bool GetInput(const CString &sPrompt, CString &sRet, const CString &sDefault="", const CString &sHint="")
static void PrintPrompt(const CString &sMessage)
bool SetCell(const CString &sColumn, const CString &sValue, size_type uRowIdx=~0)
Sets a given cell in the table to a value.