From 4ae5746e709ed0c32b35e2c37f854053133b7acf Mon Sep 17 00:00:00 2001 From: imaginos Date: Sat, 14 May 2005 08:19:10 +0000 Subject: [PATCH] make perl hash map, update to use new getpermstr git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@290 726aef4b-f618-498e-8847-2d620e286838 --- modules/modperl.cpp | 55 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/modules/modperl.cpp b/modules/modperl.cpp index 24a37845..3072953b 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -65,6 +65,43 @@ private: EType m_eType; }; + +#define CSTR( a ) a.c_str(), a.length() + +class CPerlHash : public map< CString, PString > +{ +public: + + HV *GetHash() + { + HV *pHash = newHV(); + for( CPerlHash::iterator it = this->begin(); it != this->end(); it++ ) + { + SV *pSV = NULL; + switch( it->second.GetType() ) + { + case PString::NUM: + pSV = newSVnv( it->second.ToDouble() ); + break; + case PString::INT: + pSV = newSViv( it->second.ToLongLong() ); + break; + case PString::UINT: + case PString::BOOL: + pSV = newSVuv( it->second.ToULongLong() ); + break; + case PString::STRING: + default: + pSV = newSVpv( CSTR( it->second ) ); + break; + } + hv_store( pHash, CSTR( it->first ), pSV, 0); + } + + return( pHash ); + } +}; + typedef vector< PString > VPString; class CModPerl; @@ -496,8 +533,6 @@ XS(XS_ZNC_PutModNotice) } } -#define STR( a ) a, strlen( a ) -#define CSTR( a ) a.c_str(), a.length() XS(XS_ZNC_GetNicks) { @@ -520,17 +555,13 @@ XS(XS_ZNC_GetNicks) for( map< CString,CNick* >::const_iterator it = mscNicks.begin(); it != mscNicks.end(); it++ ) { - HV *Hash = newHV(); CNick & cNick = *(it->second); - hv_store( Hash, STR( "Nick" ), newSVpv( CSTR( cNick.GetNick() ) ), 0); - hv_store( Hash, STR( "Ident" ), newSVpv( CSTR( cNick.GetIdent() ) ), 0); - hv_store( Hash, STR( "Host" ), newSVpv( CSTR( cNick.GetHost() ) ), 0); - if ( cNick.IsOp() ) - hv_store( Hash, STR( "IsOp" ), newSVpv( STR( "1" ) ), 0); - if( cNick.IsVoice() ) - hv_store( Hash, STR( "IsVoice" ), newSVpv( STR( "1" ) ), 0); - - XPUSHs( sv_2mortal( newRV( (SV *)Hash ) ) ); + CPerlHash cHash; + cHash["Nick"] = cNick.GetNick(); + cHash["Ident"] = cNick.GetIdent(); + cHash["Host"] = cNick.GetHost(); + cHash["Perms"] = cNick.GetPermStr(); + XPUSHs( sv_2mortal( newRV( (SV *)cHash.GetHash() ) ) ); } } PUTBACK;