20#include <znc/zncconfig.h>
31static 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);
38static const char g_HexDigits[] =
"0123456789abcdef";
72 unsigned int uMin = 0,
unsigned int uMax = ~0,
73 unsigned int uDefault = ~0);
173class CTable :
protected std::vector<std::vector<CString>> {
209 size_type uRowIdx = ~0);
230 using std::vector<std::vector<CString>>::size;
233 using std::vector<std::vector<CString>>::empty;
236 unsigned int GetColumnIndex(
const CString& sName)
const;
246#include <openssl/aes.h>
247#include <openssl/blowfish.h>
248#include <openssl/md5.h>
265 static unsigned char*
MD5(
const unsigned char* input,
unsigned int ilen);
271 void Crypt(
unsigned char* input,
unsigned char* output,
272 unsigned int ibytes);
275 unsigned char*
Crypt(
unsigned char* input,
unsigned int ibytes);
279 unsigned char* m_ivec;
281 int m_iEncrypt, m_num;
291template <
typename K,
typename V =
bool>
324 void AddItem(
const K& Item,
const V& Val,
unsigned int uTTL) {
353 if (it ==
m_mItems.end())
return nullptr;
354 return &it->second.second;
389 std::map<K, V> mItems;
391 mItems[it.first] = it.second.second;
403 typedef std::pair<unsigned long long, V>
value;
404 typedef typename std::map<K, value>::iterator
iterator;
std::set< CString > SCString
Definition ZNCString.h:37
does Blowfish w/64 bit feedback, no padding
Definition Utils.h:250
CBlowfish(const CBlowfish &)=default
void Crypt(unsigned char *input, unsigned char *output, unsigned int ibytes)
output must be the same size as input
static unsigned char * MD5(const unsigned char *input, unsigned int ilen)
output must be freed
CBlowfish(const CString &sPassword, int iEncrypt, const CString &sIvec="")
unsigned char * Crypt(unsigned char *input, unsigned int ibytes)
must free result
CBlowfish & operator=(const CBlowfish &)=default
static CString MD5(const CString &sInput, bool bHexEncode=false)
returns an md5 of the CString (not hex encoded)
CString Crypt(const CString &sData)
EType GetType() const
Definition Utils.h:125
virtual ~CException()
Definition Utils.h:123
EType
Definition Utils.h:120
@ EX_Shutdown
Definition Utils.h:120
@ EX_Restart
Definition Utils.h:120
EType m_eType
Definition Utils.h:129
CException(EType e)
Definition Utils.h:122
String class that is used inside ZNC.
Definition ZNCString.h:68
Generate a grid-like or list-like output from a given input.
Definition Utils.h:173
bool AddColumn(const CString &sName)
Adds a new column to the table.
std::map< CString, CString::size_type > m_msuWidths
Definition Utils.h:241
EStyle eStyle
Definition Utils.h:242
std::vector< CString > m_vsHeaders
Definition Utils.h:239
virtual ~CTable()
Definition Utils.h:177
bool SetStyle(EStyle eNewStyle)
Selects the output style of the table.
bool SetCell(const CString &sColumn, const CString &sValue, size_type uRowIdx=~0)
Sets a given cell in the table to a value.
bool GetLine(unsigned int uIdx, CString &sLine) const
Get a line of the table's output.
CString::size_type GetColumnWidth(unsigned int uIdx) const
Return the width of the given column.
EStyle
Definition Utils.h:175
@ GridStyle
Definition Utils.h:175
@ ListStyle
Definition Utils.h:175
size_type AddRow()
Adds a new row to the table.
CTable()
Definition Utils.h:176
void Clear()
Completely clear the table.
static SCString GetEncodings()
static bool CheckCIDR(const CString &sIP, const CString &sRange)
CIDR notation checker, e.g.
static CString FormatTime(time_t t, const CString &sFormat, const CString &sTZ)
static CString GetHostName()
static CString GetIP(unsigned long addr)
static CString GetPass(const CString &sPrompt)
static CString SaltedMD5Hash(const CString &sPass, const CString &sSalt)
static unsigned long GetLongIP(const CString &sIP)
static CString FormatServerTime(const timeval &tv)
static void PrintError(const CString &sMessage)
static CString SaltedSHA256Hash(const CString &sPass, const CString &sSalt)
static CString CTime(time_t t, const CString &sTZ)
static CString AskSaltedHashPassForConfig()
Asks password from stdin, with confirmation.
static void PrintPrompt(const CString &sMessage)
static CString SaltedHash(const CString &sPass, const CString &sSalt)
static bool GetNumInput(const CString &sPrompt, unsigned int &uRet, unsigned int uMin=0, unsigned int uMax=~0, unsigned int uDefault=~0)
static SCString GetTimezones()
static void SetMessageTags(CString &sLine, const MCString &mssTags)
static CString FormatTime(const timeval &tv, const CString &sFormat, const CString &sTZ)
Supports an additional format specifier for formatting sub-second values:
static void PrintStatus(bool bSuccess, const CString &sMessage="")
static MCString GetMessageTags(const CString &sLine)
static bool GetBoolInput(const CString &sPrompt, bool *pbDefault=nullptr)
static bool GetInput(const CString &sPrompt, CString &sRet, const CString &sDefault="", const CString &sHint="")
static void GenerateCert(FILE *pOut)
static void PrintAction(const CString &sMessage)
static unsigned long long GetMillTime()
static bool GetBoolInput(const CString &sPrompt, bool bDefault)
static void PrintMessage(const CString &sMessage, bool bStrong=false)
static timeval ParseServerTime(const CString &sTime)
A dictionary for strings.
Definition ZNCString.h:595
Insert an object with a time-to-live and check later if it still exists.
Definition Utils.h:292
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:309
bool HasItem(const K &Item)
Performs a Cleanup() and then checks to see if your item exists.
Definition Utils.h:340
unsigned int m_uTTL
Default time-to-live duration.
Definition Utils.h:407
void Cleanup()
Cycles through the queue removing all of the stale entries.
Definition Utils.h:367
std::map< K, value >::iterator iterator
Definition Utils.h:404
bool RemItem(const K &Item)
Removes a specific item from the cache.
Definition Utils.h:362
void AddItem(const K &Item)
This function adds an item to the cache using the default time-to-live value.
Definition Utils.h:302
unsigned int GetTTL() const
Definition Utils.h:400
std::map< K, V > GetItems()
Returns all entries.
Definition Utils.h:387
std::map< K, value > m_mItems
Map of cached items.
Definition Utils.h:406
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:324
void Clear()
Clear all entries.
Definition Utils.h:382
virtual ~TCacheMap()
Definition Utils.h:296
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:316
void SetTTL(unsigned int u)
Definition Utils.h:397
std::pair< unsigned long long, V > value
Definition Utils.h:403
TCacheMap(unsigned int uTTL=5000)
Definition Utils.h:294
V * GetItem(const K &Item)
Performs a Cleanup() and returns a pointer to the object, or nullptr.
Definition Utils.h:350