20 #include <znc/zncconfig.h>
31 static inline void SetFdCloseOnExec(
int fd)
33 int flags = fcntl(fd, F_GETFD, 0);
37 fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
40 static const char g_HexDigits[] =
"0123456789abcdef";
69 static bool GetNumInput(
const CString& sPrompt,
unsigned int& uRet,
unsigned int uMin = 0,
unsigned int uMax = ~0,
unsigned int uDefault = ~0);
73 unsigned long long iTime = 0;
74 gettimeofday(&tv, NULL);
75 iTime = (
unsigned long long) tv.tv_sec * 1000;
76 iTime += ((
unsigned long long) tv.tv_usec / 1000);
139 class CTable :
protected std::vector<std::vector<CString> > {
186 using std::vector<std::vector<CString> >::size;
189 using std::vector<std::vector<CString> >::empty;
191 unsigned int GetColumnIndex(
const CString& sName)
const;
200 #include <openssl/aes.h>
201 #include <openssl/blowfish.h>
202 #include <openssl/md5.h>
215 static unsigned char *
MD5(
const unsigned char *input, u_int ilen);
221 void Crypt(
unsigned char *input,
unsigned char *output, u_int ibytes);
224 unsigned char *
Crypt(
unsigned char *input, u_int ibytes);
228 unsigned char *m_ivec;
230 int m_iEncrypt, m_num;
240 template<
typename K,
typename V =
bool>
262 void AddItem(
const K& Item,
unsigned int uTTL) {
281 void AddItem(
const K& Item,
const V& Val,
unsigned int uTTL) {
310 return &it->second.second;
351 typedef std::pair<unsigned long long, V>
value;
352 typedef typename std::map<K, value>::iterator
iterator;
419 if (&CopyFrom !=
this) {
426 m_pType = CopyFrom.m_pType;
427 m_puCount = CopyFrom.m_puCount;
441 operator bool()
const {
450 return (m_pType == NULL);
459 if (pRawPtr != m_pType) {
464 m_puCount =
new unsigned int(1);
491 unsigned int GetCount()
const {
return (m_puCount) ? *m_puCount : 0; }
495 unsigned int* m_puCount;
void Release()
Releases the underlying raw pointer and cleans up if we were the last reference to said pointer...
Definition: Utils.h:474
bool operator==(T *lhs, const CSmartPtr< T > &rhs)
Definition: Utils.h:499
void Cleanup()
Cycles through the queue removing all of the stale entries.
Definition: Utils.h:325
bool HasItem(const K &Item)
Performs a Cleanup() and then checks to see if your item exists.
Definition: Utils.h:295
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:253
V * GetItem(const K &Item)
Performs a Cleanup() and returns a pointer to the object, or NULL.
Definition: Utils.h:305
EType m_eType
Definition: Utils.h:110
static CString GetSaltedHashPass(CString &sSalt)
does Blowfish w/64 bit feedback, no padding
Definition: Utils.h:204
unsigned int GetTTL() const
Definition: Utils.h:348
void Crypt(unsigned char *input, unsigned char *output, u_int ibytes)
output must be the same size as input
CSmartPtr< T > & Attach(T *pRawPtr)
Attach to a given raw pointer, it will Release() the current raw pointer and assign the new one...
Definition: Utils.h:458
std::map< CString, CString::size_type > m_msuWidths
Definition: Utils.h:195
virtual ~CTable()
Definition: Utils.h:142
bool IsNull() const
Check to see if the underlying raw pointer is null.
Definition: Utils.h:449
void SetTTL(unsigned int u)
Definition: Utils.h:345
static unsigned long long GetMillTime()
Definition: Utils.h:71
static void SetMessageTags(CString &sLine, const MCString &mssTags)
std::vector< CString > m_vsHeaders
Definition: Utils.h:194
static void PrintStatus(bool bSuccess, const CString &sMessage="")
static CString GetIP(unsigned long addr)
EType GetType() const
Definition: Utils.h:107
std::set< CString > SCString
Definition: ZNCString.h:34
static unsigned long GetLongIP(const CString &sIP)
CSmartPtr()
Standard constructor, points to nothing.
Definition: Utils.h:368
virtual ~CException()
Definition: Utils.h:105
static bool GetNumInput(const CString &sPrompt, unsigned int &uRet, unsigned int uMin=0, unsigned int uMax=~0, unsigned int uDefault=~0)
static const CString sDefaultHash
Definition: Utils.h:58
static MCString GetMessageTags(const CString &sLine)
CException(EType e)
Definition: Utils.h:102
static CString FormatTime(time_t t, const CString &sFormat, const CString &sTZ)
String class that is used inside ZNC.
Definition: ZNCString.h:67
bool AddColumn(const CString &sName)
Adds a new column to the table.
This is a standard reference counting pointer. Be careful not to have two of these point to the same ...
Definition: Utils.h:363
T * GetPtr() const
Definition: Utils.h:490
CSmartPtr(const CSmartPtr< T > &CopyFrom)
Copy constructor, will copy the raw pointer and counter locations and increment the reference counter...
Definition: Utils.h:388
virtual ~TCacheMap()
Definition: Utils.h:247
bool GetLine(unsigned int uIdx, CString &sLine) const
Get a line of the table's output.
static CString SaltedSHA256Hash(const CString &sPass, const CString &sSalt)
bool RemItem(const K &Item)
Removes a specific item from the cache.
Definition: Utils.h:318
T & operator*() const
Definition: Utils.h:403
static CString FormatServerTime(const timeval &tv)
static SCString GetTimezones()
~CSmartPtr()
Destructor will Release() the raw pointer and delete it if this was the last reference.
Definition: Utils.h:398
static bool GetBoolInput(const CString &sPrompt, bool bDefault)
std::map< K, value > m_mItems
Map of cached items.
Definition: Utils.h:353
CSmartPtr< T > & operator=(T *pRawPtr)
Attach() to a raw pointer.
Definition: Utils.h:411
static void PrintAction(const CString &sMessage)
static void PrintError(const CString &sMessage)
T * operator->() const
Definition: Utils.h:404
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:271
A dictionary for strings.
Definition: ZNCString.h:538
static CString GetPass(const CString &sPrompt)
std::pair< unsigned long long, V > value
Definition: Utils.h:351
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:262
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:281
static unsigned char * MD5(const unsigned char *input, u_int ilen)
output must be freed
void Clear()
Completely clear the table.
Insert an object with a time-to-live and check later if it still exists.
Definition: Utils.h:241
unsigned int m_uTTL
Default time-to-live duration.
Definition: Utils.h:354
TCacheMap(unsigned int uTTL=5000)
Definition: Utils.h:243
void Clear()
Clear all entries.
Definition: Utils.h:340
CBlowfish(const CString &sPassword, int iEncrypt, const CString &sIvec="")
CTable()
Definition: Utils.h:141
unsigned int GetCount() const
Definition: Utils.h:491
std::map< CString, value >::iterator iterator
Definition: Utils.h:352
EType
Definition: Utils.h:97
Generate a grid-like output from a given input.
Definition: Utils.h:139
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="")
CString::size_type GetColumnWidth(unsigned int uIdx) const
Return the width of the given column.
CSmartPtr(T *pRawPtr)
Attach to an existing raw pointer, be CAREFUL not to have more than one CSmartPtr attach to the same ...
Definition: Utils.h:377
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.