diff --git a/FileUtils.cpp b/FileUtils.cpp index 73ab3e84..5e980c4a 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -313,7 +313,7 @@ bool CFile::ReadLine(CString& sData, const CString & sDelimiter) { return true; } - if( bEOF && m_sBuffer.size() ) { + if (bEOF && m_sBuffer.size()) { sData = m_sBuffer; m_sBuffer.clear(); return true; @@ -411,14 +411,13 @@ int CExecSock::popen2(int & iReadFD, int & iWriteFD, const CString & sCommand) { } void CExecSock::close2(int iPid, int iReadFD, int iWriteFD) { - close( iReadFD ); - close( iWriteFD ); - u_int iNow = time( NULL ); - while( waitpid( iPid, NULL, WNOHANG ) == 0 ) - { - if ( ( time( NULL ) - iNow ) > 5 ) + close(iReadFD); + close(iWriteFD); + u_int iNow = time(NULL); + while (waitpid(iPid, NULL, WNOHANG) == 0) { + if ((time(NULL) - iNow) > 5) break; // giveup - usleep( 100 ); + usleep(100); } return; } diff --git a/FileUtils.h b/FileUtils.h index 802632e3..9a2b7d39 100644 --- a/FileUtils.h +++ b/FileUtils.h @@ -364,24 +364,24 @@ public: } CExecSock(const CString& sExec) : Csock() { - Execute( sExec ); + Execute(sExec); } - int Execute( const CString & sExec ) { + int Execute(const CString & sExec) { int iReadFD, iWriteFD; m_iPid = popen2(iReadFD, iWriteFD, sExec); ConnectFD(iReadFD, iWriteFD, "0.0.0.0:0"); - return( m_iPid ); + return(m_iPid); } - void Kill( int iSignal ) + void Kill(int iSignal) { - kill( m_iPid, iSignal ); + kill(m_iPid, iSignal); Close(); } virtual ~CExecSock() { close2(m_iPid, GetRSock(), GetWSock()); - SetRSock( -1 ); - SetWSock( -1 ); + SetRSock(-1); + SetWSock(-1); } int popen2(int & iReadFD, int & iWriteFD, const CString & sCommand); diff --git a/String.cpp b/String.cpp index eed9e3ae..5b92413f 100644 --- a/String.cpp +++ b/String.cpp @@ -172,8 +172,8 @@ inline unsigned char* CString::strnchr(const unsigned char* src, unsigned char c return NULL; } -int CString::CaseCmp(const CString& s, u_long uLen ) const { - if( uLen != CString::npos ) { +int CString::CaseCmp(const CString& s, u_long uLen) const { + if (uLen != CString::npos) { return strncasecmp(c_str(), s.c_str(), uLen); } return strcasecmp(c_str(), s.c_str()); @@ -1027,7 +1027,7 @@ CString& MCString::Decode(CString& sValue) { if (*pTmp != '%') { sTmp += *pTmp++; } else { - char ch = (char )strtol(((const char *)pTmp + 1), &endptr, 16); + char ch = (char) strtol(pTmp + 1, &endptr, 16); if (*endptr == ';') { sTmp += ch; pTmp = ++endptr; diff --git a/String.h b/String.h index 2e0e630c..7b49e937 100644 --- a/String.h +++ b/String.h @@ -80,7 +80,7 @@ public: virtual ~CString() {} inline unsigned char* strnchr(const unsigned char* src, unsigned char c, unsigned int iMaxBytes, unsigned char* pFill = NULL, unsigned int* piCount = NULL) const; - int CaseCmp(const CString& s, u_long uLen = CString::npos ) const; + int CaseCmp(const CString& s, u_long uLen = CString::npos) const; int StrCmp(const CString& s) const; static bool WildCmp(const CString& sWild, const CString& sString); bool WildCmp(const CString& sWild) const; diff --git a/Utils.cpp b/Utils.cpp index d5807b0e..e5a5407e 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -54,30 +54,30 @@ void CUtils::GenerateCert(FILE *pOut, bool bEncPrivKey, const CString& sHost) { X509_NAME *pName = NULL; int days = 365; - u_int iSeed = time( NULL ); - int serial = ( rand_r( &iSeed ) % 9999 ); + u_int iSeed = time(NULL); + int serial = (rand_r(&iSeed) % 9999); RSA *pRSA = RSA_generate_key(1024, 0x10001, NULL, NULL); - if( ( pKey = EVP_PKEY_new() ) ) { - if ( !EVP_PKEY_assign_RSA( pKey, pRSA ) ) { - EVP_PKEY_free( pKey ); + if ((pKey = EVP_PKEY_new())) { + if (!EVP_PKEY_assign_RSA(pKey, pRSA)) { + EVP_PKEY_free(pKey); return; } - PEM_write_RSAPrivateKey( pOut, pRSA, (bEncPrivKey ? EVP_des_ede3_cbc() : NULL), NULL, 0, NULL, NULL); + PEM_write_RSAPrivateKey(pOut, pRSA, (bEncPrivKey ? EVP_des_ede3_cbc() : NULL), NULL, 0, NULL, NULL); - if( !( pCert = X509_new() ) ) { - EVP_PKEY_free( pKey ); + if(!(pCert = X509_new())) { + EVP_PKEY_free(pKey); return; } - X509_set_version( pCert, 2 ); - ASN1_INTEGER_set( X509_get_serialNumber( pCert ), serial ); - X509_gmtime_adj( X509_get_notBefore( pCert ), 0 ); - X509_gmtime_adj( X509_get_notAfter( pCert ), (long)60*60*24*days ); - X509_set_pubkey( pCert, pKey ); + X509_set_version(pCert, 2); + ASN1_INTEGER_set(X509_get_serialNumber(pCert), serial); + X509_gmtime_adj(X509_get_notBefore(pCert), 0); + X509_gmtime_adj(X509_get_notAfter(pCert), (long)60*60*24*days); + X509_set_pubkey(pCert, pKey); - pName = X509_get_subject_name( pCert ); + pName = X509_get_subject_name(pCert); const char *pLogName = getenv("LOGNAME"); const char *pHostName = NULL; @@ -102,25 +102,25 @@ void CUtils::GenerateCert(FILE *pOut, bool bEncPrivKey, const CString& sHost) { sEmailAddr += "@"; sEmailAddr += pHostName; - X509_NAME_add_entry_by_txt( pName, "C", MBSTRING_ASC, (unsigned char *)"US", -1, -1, 0); - X509_NAME_add_entry_by_txt( pName, "ST", MBSTRING_ASC, (unsigned char *)"SomeState", -1, -1, 0); - X509_NAME_add_entry_by_txt( pName, "L", MBSTRING_ASC, (unsigned char *)"SomeCity", -1, -1, 0); - X509_NAME_add_entry_by_txt( pName, "O", MBSTRING_ASC, (unsigned char *)"SomeCompany", -1, -1, 0); - X509_NAME_add_entry_by_txt( pName, "OU", MBSTRING_ASC, (unsigned char *)pLogName, -1, -1, 0); - X509_NAME_add_entry_by_txt( pName, "CN", MBSTRING_ASC, (unsigned char *)pHostName, -1, -1, 0); - X509_NAME_add_entry_by_txt( pName, "emailAddress", MBSTRING_ASC, (unsigned char *)sEmailAddr.c_str(), -1, -1, 0); + X509_NAME_add_entry_by_txt(pName, "C", MBSTRING_ASC, (unsigned char *)"US", -1, -1, 0); + X509_NAME_add_entry_by_txt(pName, "ST", MBSTRING_ASC, (unsigned char *)"SomeState", -1, -1, 0); + X509_NAME_add_entry_by_txt(pName, "L", MBSTRING_ASC, (unsigned char *)"SomeCity", -1, -1, 0); + X509_NAME_add_entry_by_txt(pName, "O", MBSTRING_ASC, (unsigned char *)"SomeCompany", -1, -1, 0); + X509_NAME_add_entry_by_txt(pName, "OU", MBSTRING_ASC, (unsigned char *)pLogName, -1, -1, 0); + X509_NAME_add_entry_by_txt(pName, "CN", MBSTRING_ASC, (unsigned char *)pHostName, -1, -1, 0); + X509_NAME_add_entry_by_txt(pName, "emailAddress", MBSTRING_ASC, (unsigned char *)sEmailAddr.c_str(), -1, -1, 0); - X509_set_subject_name( pCert, pName ); + X509_set_subject_name(pCert, pName); - if ( !X509_sign( pCert, pKey, EVP_md5() ) ) { - X509_free( pCert ); - EVP_PKEY_free( pKey ); + if (!X509_sign(pCert, pKey, EVP_md5())) { + X509_free(pCert); + EVP_PKEY_free(pKey); return; } - PEM_write_X509( pOut, pCert ); - X509_free( pCert ); - EVP_PKEY_free( pKey ); + PEM_write_X509(pOut, pCert); + X509_free(pCert); + EVP_PKEY_free(pKey); } } #endif /* HAVE_LIBSSL */ diff --git a/main.cpp b/main.cpp index 06033de8..6431b780 100644 --- a/main.cpp +++ b/main.cpp @@ -165,12 +165,12 @@ int main(int argc, char** argv) { if (bMakePem) { CZNC* pZNC = &CZNC::Get(); pZNC->InitDirs("", sDataDir); - pZNC->WritePemFile( bEncPem ); + pZNC->WritePemFile(bEncPem); delete pZNC; return 0; } - if( bEncPem && !bMakePem ) { + if (bEncPem && !bMakePem) { CUtils::PrintError("--encrypt-pem should be used along with --makepem."); return 1; } diff --git a/modules/away.cpp b/modules/away.cpp index e69dc764..c12dc3f6 100644 --- a/modules/away.cpp +++ b/modules/away.cpp @@ -21,8 +21,8 @@ class CAway; class CAwayJob : public CTimer { public: - CAwayJob( CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription ) - : CTimer( pModule, uInterval, uCycles, sLabel, sDescription) {} + CAwayJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) + : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {} virtual ~CAwayJob() {} @@ -38,12 +38,12 @@ public: Ping(); m_bIsAway = false; m_bBootError = false; - SetAwayTime( 300 ); - AddTimer( new CAwayJob( this, 60, 0, "AwayJob", "Checks for idle and saves messages every 1 minute" ) ); + SetAwayTime(300); + AddTimer(new CAwayJob(this, 60, 0, "AwayJob", "Checks for idle and saves messages every 1 minute")); } virtual ~CAway() { - if ( !m_bBootError ) + if (!m_bBootError) SaveBufferToDisk(); } @@ -61,7 +61,7 @@ public: } if (!sMyArgs.empty()) { - m_sPassword = CBlowfish::MD5( sMyArgs ); + m_sPassword = CBlowfish::MD5(sMyArgs); } return true; @@ -69,29 +69,29 @@ public: virtual bool OnBoot() { - if ( m_sPassword.empty() ) + if (m_sPassword.empty()) { - char *pTmp = CUtils::GetPass( "Enter Encryption Key for away.so: " ); + char *pTmp = CUtils::GetPass("Enter Encryption Key for away.so: "); - if ( pTmp ) - m_sPassword = CBlowfish::MD5( pTmp ); + if (pTmp) + m_sPassword = CBlowfish::MD5(pTmp); *pTmp = 0; } - if ( !BootStrap() ) + if (!BootStrap()) { m_bBootError = true; - return( false ); + return(false); } - return( true ); + return(true); } virtual void OnIRCConnected() { - if( m_bIsAway ) - Away( true ); // reset away if we are reconnected + if(m_bIsAway) + Away(true); // reset away if we are reconnected else Back(); // ircd seems to remember your away if you killed the client and came back } @@ -99,191 +99,191 @@ public: bool BootStrap() { CString sFile; - if ( DecryptMessages( sFile ) ) + if (DecryptMessages(sFile)) { CString sLine; CString::size_type iPos = 0; - while( ReadLine( sFile, sLine, iPos ) ) + while(ReadLine(sFile, sLine, iPos)) { sLine.Trim(); - AddMessage( sLine ); + AddMessage(sLine); } } else { m_sPassword = ""; CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt Messages"); - return( false ); + return(false); } - return( true ); + return(true); } void SaveBufferToDisk() { - if ( !m_sPassword.empty() ) + if (!m_sPassword.empty()) { CString sFile = CRYPT_VERIFICATION_TOKEN; - for( u_int b = 0; b < m_vMessages.size(); b++ ) + for(u_int b = 0; b < m_vMessages.size(); b++) sFile += m_vMessages[b] + "\n"; - CBlowfish c( m_sPassword, BF_ENCRYPT ); - sFile = c.Crypt( sFile ); + CBlowfish c(m_sPassword, BF_ENCRYPT); + sFile = c.Crypt(sFile); CString sPath = GetPath(); - if ( !sPath.empty() ) + if (!sPath.empty()) { - WriteFile( sPath, sFile ); - chmod( sPath.c_str(), 0600 ); + WriteFile(sPath, sFile); + chmod(sPath.c_str(), 0600); } } } virtual void OnUserAttached() { - Back( true ); + Back(true); } virtual void OnUserDetached() { Away(); } - virtual void OnModCommand( const CString& sCommand ) + virtual void OnModCommand(const CString& sCommand) { CString sCmdName = sCommand.Token(0); - if ( sCmdName == "away" ) + if (sCmdName == "away") { CString sReason; - if( sCommand.Token( 1 ) != "-quiet" ) + if(sCommand.Token(1) != "-quiet") { - sReason = sCommand.Token( 1, true ); - PutModNotice( "You have been marked as away", "away" ); + sReason = sCommand.Token(1, true); + PutModNotice("You have been marked as away", "away"); } else - sReason = sCommand.Token( 2, true ); - Away( false, sReason ); + sReason = sCommand.Token(2, true); + Away(false, sReason); } - else if ( sCmdName == "back" ) + else if (sCmdName == "back") { - if ( ( m_vMessages.empty() ) && ( sCommand.Token( 1 ) != "-quiet" ) ) - PutModNotice( "Welcome Back!", "away" ); + if ((m_vMessages.empty()) && (sCommand.Token(1) != "-quiet")) + PutModNotice("Welcome Back!", "away"); Back(); } - else if ( sCmdName == "messages" ) + else if (sCmdName == "messages") { - for( u_int a = 0; a < m_vMessages.size(); a++ ) - PutModule( m_vMessages[a], "away" ); + for(u_int a = 0; a < m_vMessages.size(); a++) + PutModule(m_vMessages[a], "away"); } - else if ( sCmdName == "delete" ) + else if (sCmdName == "delete") { CString sWhich = sCommand.Token(1); - if ( sWhich == "all" ) + if (sWhich == "all") { - PutModNotice( "Deleted " + CString( m_vMessages.size() ) + " Messages.", "away" ); - for( u_int a = 0; a < m_vMessages.size(); a++ ) - m_vMessages.erase( m_vMessages.begin() + a-- ); + PutModNotice("Deleted " + CString(m_vMessages.size()) + " Messages.", "away"); + for(u_int a = 0; a < m_vMessages.size(); a++) + m_vMessages.erase(m_vMessages.begin() + a--); } - else if ( sWhich.empty() ) + else if (sWhich.empty()) { - PutModNotice( "USAGE: delete ", "away" ); + PutModNotice("USAGE: delete ", "away"); return; } else { - u_int iNum = atoi( sWhich.c_str() ); - if ( iNum >= m_vMessages.size() ) + u_int iNum = atoi(sWhich.c_str()); + if (iNum >= m_vMessages.size()) { - PutModNotice( "Illegal Message # Requested", "away" ); + PutModNotice("Illegal Message # Requested", "away"); return; } else { - m_vMessages.erase( m_vMessages.begin() + iNum ); - PutModNotice( "Message Erased.", "away" ); + m_vMessages.erase(m_vMessages.begin() + iNum); + PutModNotice("Message Erased.", "away"); } SaveBufferToDisk(); } } - else if ( sCmdName == "save" ) + else if (sCmdName == "save") { SaveBufferToDisk(); - PutModNotice( "Messages saved to disk.", "away" ); + PutModNotice("Messages saved to disk.", "away"); } - else if ( sCmdName == "ping" ) + else if (sCmdName == "ping") { Ping(); - if ( m_bIsAway ) + if (m_bIsAway) Back(); } - else if ( sCmdName == "pass" ) + else if (sCmdName == "pass") { - m_sPassword = sCommand.Token( 1 ); - PutModNotice( "Password Updated to [" + m_sPassword + "]" ); + m_sPassword = sCommand.Token(1); + PutModNotice("Password Updated to [" + m_sPassword + "]"); } - else if ( sCmdName == "show" ) + else if (sCmdName == "show") { map< CString, vector< CString> > msvOutput; - for( u_int a = 0; a < m_vMessages.size(); a++ ) + for(u_int a = 0; a < m_vMessages.size(); a++) { - CString sTime = m_vMessages[a].Token( 0, false, ":" ); - CString sWhom = m_vMessages[a].Token( 1, false, ":" ); - CString sMessage = m_vMessages[a].Token( 2, true, ":" ); + CString sTime = m_vMessages[a].Token(0, false, ":"); + CString sWhom = m_vMessages[a].Token(1, false, ":"); + CString sMessage = m_vMessages[a].Token(2, true, ":"); - if ( ( sTime.empty() ) || ( sWhom.empty() ) || ( sMessage.empty() ) ) + if ((sTime.empty()) || (sWhom.empty()) || (sMessage.empty())) { // illegal format - PutModule( "Corrupt message! [" + m_vMessages[a] + "]", "away" ); - m_vMessages.erase( m_vMessages.begin() + a-- ); + PutModule("Corrupt message! [" + m_vMessages[a] + "]", "away"); + m_vMessages.erase(m_vMessages.begin() + a--); continue; } - time_t iTime = strtol( sTime.c_str(), NULL, 10 ); + time_t iTime = strtol(sTime.c_str(), NULL, 10); char szFormat[64]; struct tm t; - localtime_r( &iTime, &t ); - size_t iCount = strftime( szFormat, 64, "%F %T", &t ); - if ( iCount <= 0 ) + localtime_r(&iTime, &t); + size_t iCount = strftime(szFormat, 64, "%F %T", &t); + if (iCount <= 0) { - PutModule( "Corrupt time stamp! [" + m_vMessages[a] + "]", "away" ); - m_vMessages.erase( m_vMessages.begin() + a-- ); + PutModule("Corrupt time stamp! [" + m_vMessages[a] + "]", "away"); + m_vMessages.erase(m_vMessages.begin() + a--); continue; } - CString sTmp = " " + CString( a ) + ") ["; - sTmp.append( szFormat, iCount ); + CString sTmp = " " + CString(a) + ") ["; + sTmp.append(szFormat, iCount); sTmp += "] "; sTmp += sMessage; - msvOutput[sWhom].push_back( sTmp ); + msvOutput[sWhom].push_back(sTmp); } - for( map< CString, vector< CString> >::iterator it = msvOutput.begin(); it != msvOutput.end(); it++ ) + for(map< CString, vector< CString> >::iterator it = msvOutput.begin(); it != msvOutput.end(); it++) { - PutModule( it->first, "away" ); - for( u_int a = 0; a < it->second.size(); a++ ) - PutModule( it->second[a] ); + PutModule(it->first, "away"); + for(u_int a = 0; a < it->second.size(); a++) + PutModule(it->second[a]); } - PutModule( "#--- End Messages", "away" ); - } else if ( sCmdName == "enabletimer") + PutModule("#--- End Messages", "away"); + } else if (sCmdName == "enabletimer") { SetAwayTime(300); - PutModule( "Timer set to 300 seconds" ); - } else if ( sCmdName == "disabletimer") + PutModule("Timer set to 300 seconds"); + } else if (sCmdName == "disabletimer") { SetAwayTime(0); - PutModule( "Timer disabled" ); - } else if ( sCmdName == "settimer") + PutModule("Timer disabled"); + } else if (sCmdName == "settimer") { int iSetting = sCommand.Token(1).ToInt(); SetAwayTime(iSetting); if(iSetting == 0) - PutModule( "Timer disabled" ); + PutModule("Timer disabled"); else - PutModule( "Timer set to " + CString(iSetting) + " seconds" ); + PutModule("Timer set to " + CString(iSetting) + " seconds"); - } else if ( sCmdName == "timer") + } else if (sCmdName == "timer") { - PutModule( "Current timer setting: " + CString(GetAwayTime()) + " seconds" ); + PutModule("Current timer setting: " + CString(GetAwayTime()) + " seconds"); } else { - PutModule( "Commands: away [-quiet], back [-quiet], delete , ping, show, save, enabletimer, disabletimer, settimer , timer", "away" ); + PutModule("Commands: away [-quiet], back [-quiet], delete , ping, show, save, enabletimer, disabletimer, settimer , timer", "away"); } } @@ -291,49 +291,49 @@ public: { CString sBuffer = m_pUser->GetUserName(); CString sRet = GetSavePath(); - sRet += "/.znc-away-" + CBlowfish::MD5( sBuffer, true ); - return( sRet ); + sRet += "/.znc-away-" + CBlowfish::MD5(sBuffer, true); + return(sRet); } - virtual void Away( bool bForce = false, const CString & sReason = "" ) + virtual void Away(bool bForce = false, const CString & sReason = "") { - if ( ( !m_bIsAway ) || ( bForce ) ) + if ((!m_bIsAway) || (bForce)) { - if ( !bForce ) + if (!bForce) m_sReason = sReason; - else if ( !sReason.empty() ) + else if (!sReason.empty()) m_sReason = sReason; - time_t iTime = time( NULL ); - char *pTime = ctime( &iTime ); + time_t iTime = time(NULL); + char *pTime = ctime(&iTime); CString sTime; - if ( pTime ) + if (pTime) { sTime = pTime; sTime.Trim(); } - if ( m_sReason.empty() ) + if (m_sReason.empty()) m_sReason = "away :Auto Away at " + sTime; - PutIRC( m_sReason ); + PutIRC(m_sReason); m_bIsAway = true; } } - virtual void Back( bool bUsePrivMessage = false ) + virtual void Back(bool bUsePrivMessage = false) { - PutIRC( "away" ); + PutIRC("away"); m_bIsAway = false; - if ( !m_vMessages.empty() ) + if (!m_vMessages.empty()) { - if ( bUsePrivMessage ) + if (bUsePrivMessage) { - PutModule( "Welcome Back!", "away" ); - PutModule( "You have " + CString( m_vMessages.size() ) + " messages!", "away" ); + PutModule("Welcome Back!", "away"); + PutModule("You have " + CString(m_vMessages.size()) + " messages!", "away"); } else { - PutModNotice( "Welcome Back!", "away" ); - PutModNotice( "You have " + CString( m_vMessages.size() ) + " messages!", "away" ); + PutModNotice("Welcome Back!", "away"); + PutModNotice("You have " + CString(m_vMessages.size()) + " messages!", "away"); } } m_sReason = ""; @@ -341,76 +341,76 @@ public: virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage) { - if ( m_bIsAway ) - AddMessage( time( NULL ), Nick, sMessage ); - return( CONTINUE ); + if (m_bIsAway) + AddMessage(time(NULL), Nick, sMessage); + return(CONTINUE); } virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage) { Ping(); - if( m_bIsAway ) + if(m_bIsAway) Back(); - return( CONTINUE ); + return(CONTINUE); } virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) { Ping(); - if( m_bIsAway ) + if(m_bIsAway) Back(); - return( CONTINUE ); + return(CONTINUE); } - time_t GetTimeStamp() const { return( m_iLastSentData ); } - void Ping() { m_iLastSentData = time( NULL ); } + time_t GetTimeStamp() const { return(m_iLastSentData); } + void Ping() { m_iLastSentData = time(NULL); } time_t GetAwayTime() { return m_iAutoAway; } void SetAwayTime(time_t u) { m_iAutoAway = u; } - bool IsAway() { return( m_bIsAway ); } + bool IsAway() { return(m_bIsAway); } private: CString m_sPassword; bool m_bBootError; - bool DecryptMessages( CString & sBuffer ) + bool DecryptMessages(CString & sBuffer) { CString sMessages = GetPath(); CString sFile; sBuffer = ""; - if ( ( sMessages.empty() ) || ( !ReadFile( sMessages, sFile ) ) ) + if ((sMessages.empty()) || (!ReadFile(sMessages, sFile))) { - PutModule( "Unable to find buffer" ); - return( true ); // gonna be successful here + PutModule("Unable to find buffer"); + return(true); // gonna be successful here } - if ( !sFile.empty() ) + if (!sFile.empty()) { - CBlowfish c( m_sPassword, BF_DECRYPT ); - sBuffer = c.Crypt( sFile ); + CBlowfish c(m_sPassword, BF_DECRYPT); + sBuffer = c.Crypt(sFile); - if ( sBuffer.substr( 0, strlen( CRYPT_VERIFICATION_TOKEN ) ) != CRYPT_VERIFICATION_TOKEN ) + if (sBuffer.substr(0, strlen(CRYPT_VERIFICATION_TOKEN)) != CRYPT_VERIFICATION_TOKEN) { // failed to decode :( - PutModule( "Unable to decode Encrypted messages" ); - return( false ); + PutModule("Unable to decode Encrypted messages"); + return(false); } - sBuffer.erase( 0, strlen( CRYPT_VERIFICATION_TOKEN ) ); + sBuffer.erase(0, strlen(CRYPT_VERIFICATION_TOKEN)); } - return( true ); + return(true); } - void AddMessage( time_t iTime, const CNick & Nick, CString & sMessage ) + void AddMessage(time_t iTime, const CNick & Nick, CString & sMessage) { if (m_pUser && Nick.GetNick() == m_pUser->GetIRCNick().GetNick()) return; // ignore messages from self - AddMessage( CString( iTime ) + ":" + Nick.GetNickMask() + ":" + sMessage ); + AddMessage(CString(iTime) + ":" + Nick.GetNickMask() + ":" + sMessage); } - void AddMessage( const CString & sText ) + void AddMessage(const CString & sText) { - m_vMessages.push_back( sText ); + m_vMessages.push_back(sText); } time_t m_iLastSentData; @@ -426,11 +426,11 @@ void CAwayJob::RunJob() CAway *p = (CAway *)m_pModule; p->SaveBufferToDisk(); - if ( !p->IsAway() ) + if (!p->IsAway()) { - time_t iNow = time( NULL ); + time_t iNow = time(NULL); - if ( ( iNow - p->GetTimeStamp() ) > p->GetAwayTime() && p->GetAwayTime() != 0) + if ((iNow - p->GetTimeStamp()) > p->GetAwayTime() && p->GetAwayTime() != 0) p->Away(); } } diff --git a/modules/email.cpp b/modules/email.cpp index 253aab5c..f7dfcaf8 100644 --- a/modules/email.cpp +++ b/modules/email.cpp @@ -27,8 +27,8 @@ struct EmailST class CEmailJob : public CTimer { public: - CEmailJob( CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription ) - : CTimer( pModule, uInterval, uCycles, sLabel, sDescription) {} + CEmailJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) + : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {} virtual ~CEmailJob() {} @@ -47,16 +47,16 @@ public: virtual ~CEmail() { - vector vSocks = m_pManager->FindSocksByName( "EMAIL::" + m_pUser->GetUserName() ); - for( u_int a = 0; a < vSocks.size(); a++ ) - m_pManager->DelSockByAddr( vSocks[a] ); + vector vSocks = m_pManager->FindSocksByName("EMAIL::" + m_pUser->GetUserName()); + for(u_int a = 0; a < vSocks.size(); a++) + m_pManager->DelSockByAddr(vSocks[a]); } virtual bool OnLoad(const CString & sArgs, CString& sMessage) { m_sMailPath = sArgs; StartParser(); - if ( m_pUser->IsUserAttached() ) + if (m_pUser->IsUserAttached()) StartTimer(); return true; @@ -66,37 +66,37 @@ public: { stringstream s; s << "You have " << m_ssUidls.size() << " emails."; - PutModule( s.str() ); + PutModule(s.str()); StartTimer(); } virtual void OnUserDetached() { - RemTimer( "EMAIL::" + m_pUser->GetUserName() ); + RemTimer("EMAIL::" + m_pUser->GetUserName()); } void StartTimer() { - if ( !FindTimer( "EMAIL::" + m_pUser->GetUserName() ) ) + if (!FindTimer("EMAIL::" + m_pUser->GetUserName())) { - CEmailJob *p = new CEmailJob( this, 60, 0, "EmailMonitor", "Monitors email activity" ); - AddTimer( p ); + CEmailJob *p = new CEmailJob(this, 60, 0, "EmailMonitor", "Monitors email activity"); + AddTimer(p); } } - virtual void OnModCommand( const CString& sCommand ); + virtual void OnModCommand(const CString& sCommand); void StartParser(); - void ParseEmails( const vector & vEmails ) + void ParseEmails(const vector & vEmails) { - if ( !m_bInitialized ) + if (!m_bInitialized) { m_bInitialized = true; - for( u_int a = 0; a < vEmails.size(); a++ ) - m_ssUidls.insert( vEmails[a].sUidl ); + for(u_int a = 0; a < vEmails.size(); a++) + m_ssUidls.insert(vEmails[a].sUidl); stringstream s; s << "You have " << vEmails.size() << " emails."; - PutModule( s.str() ); + PutModule(s.str()); } else { set ssUidls; @@ -106,17 +106,17 @@ public: Table.AddColumn("Size"); Table.AddColumn("Subject"); - for( u_int a = 0; a < vEmails.size(); a++ ) + for(u_int a = 0; a < vEmails.size(); a++) { - if ( m_ssUidls.find( vEmails[a].sUidl ) == m_ssUidls.end() ) + if (m_ssUidls.find(vEmails[a].sUidl) == m_ssUidls.end()) { - //PutModule( "------------------- New Email -------------------" ); + //PutModule("------------------- New Email -------------------"); Table.AddRow(); - Table.SetCell( "From", vEmails[a].sFrom.Ellipsize( 32 ) ); - Table.SetCell( "Size", CString( vEmails[a].iSize ) ); - Table.SetCell( "Subject", vEmails[a].sSubject.Ellipsize( 64 ) ); + Table.SetCell("From", vEmails[a].sFrom.Ellipsize(32)); + Table.SetCell("Size", CString(vEmails[a].iSize)); + Table.SetCell("Subject", vEmails[a].sSubject.Ellipsize(64)); } - ssUidls.insert( vEmails[a].sUidl ); + ssUidls.insert(vEmails[a].sUidl); } m_ssUidls = ssUidls; // keep the list in synch @@ -124,13 +124,13 @@ public: if (Table.size()) { unsigned int uTableIdx = 0; CString sLine; - while ( Table.GetLine( uTableIdx++, sLine ) ) { - PutModule( sLine ); + while (Table.GetLine(uTableIdx++, sLine)) { + PutModule(sLine); } stringstream s; s << "You have " << vEmails.size() << " emails."; - PutModule( s.str() ); + PutModule(s.str()); } } } @@ -145,7 +145,7 @@ private: class CEmailFolder : public Csock { public: - CEmailFolder( CEmail *pModule, const CString & sMailbox ) : Csock() + CEmailFolder(CEmail *pModule, const CString & sMailbox) : Csock() { m_pModule = pModule; m_sMailbox = sMailbox; @@ -154,18 +154,18 @@ public: virtual ~CEmailFolder() { - if ( !m_sMailBuffer.empty() ) + if (!m_sMailBuffer.empty()) ProcessMail(); // get the last one - if ( !m_vEmails.empty() ) - m_pModule->ParseEmails( m_vEmails ); + if (!m_vEmails.empty()) + m_pModule->ParseEmails(m_vEmails); } - virtual void ReadLine( const CS_STRING & sLine ) + virtual void ReadLine(const CS_STRING & sLine) { - if ( sLine.substr( 0, 5 ) == "From " ) + if (sLine.substr(0, 5) == "From ") { - if ( !m_sMailBuffer.empty() ) + if (!m_sMailBuffer.empty()) { ProcessMail(); m_sMailBuffer.clear(); @@ -177,25 +177,25 @@ public: void ProcessMail() { EmailST tmp; - tmp.sUidl = (char *)CMD5( m_sMailBuffer.substr( 0, 255 ) ); + tmp.sUidl = (char *)CMD5(m_sMailBuffer.substr(0, 255)); CString sLine; CString::size_type iPos = 0; - while( ::ReadLine( m_sMailBuffer, sLine, iPos ) ) + while(::ReadLine(m_sMailBuffer, sLine, iPos)) { sLine.Trim(); - if ( sLine.empty() ) + if (sLine.empty()) break; // out of the headers - if ( strncasecmp( sLine.c_str(), "From: ", 6 ) == 0 ) - tmp.sFrom = sLine.substr( 6, CString::npos ); - else if ( strncasecmp( sLine.c_str(), "Subject: ", 9 ) == 0 ) - tmp.sSubject = sLine.substr( 9, CString::npos ); + if (strncasecmp(sLine.c_str(), "From: ", 6) == 0) + tmp.sFrom = sLine.substr(6, CString::npos); + else if (strncasecmp(sLine.c_str(), "Subject: ", 9) == 0) + tmp.sSubject = sLine.substr(9, CString::npos); - if ( ( !tmp.sFrom.empty() ) && ( !tmp.sSubject.empty() ) ) + if ((!tmp.sFrom.empty()) && (!tmp.sSubject.empty())) break; } tmp.iSize = m_sMailBuffer.length(); - m_vEmails.push_back( tmp ); + m_vEmails.push_back(tmp); } private: CEmail *m_pModule; @@ -204,50 +204,50 @@ private: vector m_vEmails; }; -void CEmail::OnModCommand( const CString& sCommand ) +void CEmail::OnModCommand(const CString& sCommand) { - CString::size_type iPos = sCommand.find( " " ); + CString::size_type iPos = sCommand.find(" "); CString sCom, sArgs; - if ( iPos == CString::npos ) + if (iPos == CString::npos) sCom = sCommand; else { - sCom = sCommand.substr( 0, iPos ); - sArgs = sCommand.substr( iPos + 1, CString::npos ); + sCom = sCommand.substr(0, iPos); + sArgs = sCommand.substr(iPos + 1, CString::npos); } - if ( sCom == "timers" ) + if (sCom == "timers") { ListTimers(); } else - PutModule( "Error, no such command [" + sCom + "]" ); + PutModule("Error, no such command [" + sCom + "]"); } void CEmail::StartParser() { CString sParserName = "EMAIL::" + m_pUser->GetUserName(); - if ( m_pManager->FindSockByName( sParserName ) ) + if (m_pManager->FindSockByName(sParserName)) return; // one at a time sucker - CFile cFile( m_sMailPath ); - if ( ( !cFile.Exists() ) || ( cFile.GetSize() == 0 ) ) + CFile cFile(m_sMailPath); + if ((!cFile.Exists()) || (cFile.GetSize() == 0)) { m_bInitialized = true; return; // der } - if ( cFile.GetMTime() <= m_iLastCheck ) + if (cFile.GetMTime() <= m_iLastCheck) return; // only check if modified - int iFD = open( m_sMailPath.c_str(), O_RDONLY ); - if ( iFD >= 0 ) + int iFD = open(m_sMailPath.c_str(), O_RDONLY); + if (iFD >= 0) { - m_iLastCheck = time( NULL ); - CEmailFolder *p = new CEmailFolder( this, m_sMailPath ); - p->SetRSock( iFD ); - p->SetWSock( iFD ); - m_pManager->AddSock( (Csock *)p, "EMAIL::" + m_pUser->GetUserName() ); + m_iLastCheck = time(NULL); + CEmailFolder *p = new CEmailFolder(this, m_sMailPath); + p->SetRSock(iFD); + p->SetWSock(iFD); + m_pManager->AddSock((Csock *)p, "EMAIL::" + m_pUser->GetUserName()); } } diff --git a/modules/modperl.cpp b/modules/modperl.cpp index 165e47a0..4dedfcec 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -25,8 +25,8 @@ #include #include -#define NICK( a ) a.GetNickMask() -#define CHAN( a ) a.GetName() +#define NICK(a) a.GetNickMask() +#define CHAN(a) a.GetName() #define ZNCEvalCB "ZNC::COREEval" #define ZNCCallFuncCB "ZNC::CORECallFunc" #define ZNCCallTimerCB "ZNC::CORECallTimer" @@ -46,47 +46,47 @@ public: }; PString() : CString() { m_eType = STRING; } - PString( const char* c ) : CString(c) { m_eType = STRING; } - PString( const CString& s ) : CString(s) { m_eType = STRING; } - PString( int i ) : CString( i ) { m_eType = INT; } - PString( u_int i ) : CString( i ) { m_eType = UINT; } - PString( long i ) : CString( i ) { m_eType = INT; } - PString( u_long i ) : CString( i ) { m_eType = UINT; } - PString( long long i ) : CString( i ) { m_eType = INT; } - PString( unsigned long long i ) : CString( i ) { m_eType = UINT; } - PString( double i ) : CString( i ) { m_eType = NUM; } - PString( bool b ) : CString( ( b ? "1" : "0" ) ) { m_eType = BOOL; } + PString(const char* c) : CString(c) { m_eType = STRING; } + PString(const CString& s) : CString(s) { m_eType = STRING; } + PString(int i) : CString(i) { m_eType = INT; } + PString(u_int i) : CString(i) { m_eType = UINT; } + PString(long i) : CString(i) { m_eType = INT; } + PString(u_long i) : CString(i) { m_eType = UINT; } + PString(long long i) : CString(i) { m_eType = INT; } + PString(unsigned long long i) : CString(i) { m_eType = UINT; } + PString(double i) : CString(i) { m_eType = NUM; } + PString(bool b) : CString((b ? "1" : "0")) { m_eType = BOOL; } virtual ~PString() {} - EType GetType() const { return( m_eType ); } - void SetType( EType e ) { m_eType = e; } + EType GetType() const { return(m_eType); } + void SetType(EType e) { m_eType = e; } - SV * GetSV( bool bMakeMortal = true ) const + SV * GetSV(bool bMakeMortal = true) const { SV *pSV = NULL; - switch( GetType() ) + switch(GetType()) { case NUM: - pSV = newSVnv( ToDouble() ); + pSV = newSVnv(ToDouble()); break; case INT: - pSV = newSViv( ToLongLong() ); + pSV = newSViv(ToLongLong()); break; case UINT: case BOOL: - pSV = newSVuv( ToULongLong() ); + pSV = newSVuv(ToULongLong()); break; case STRING: default: - pSV = newSVpv( data(), length() ); + pSV = newSVpv(data(), length()); break; } - if ( bMakeMortal ) - pSV = sv_2mortal( pSV ); + if (bMakeMortal) + pSV = sv_2mortal(pSV); - return( pSV ); + return(pSV); } private: @@ -101,14 +101,14 @@ public: HV *GetHash() { HV *pHash = newHV(); - sv_2mortal( (SV *) pHash ); - for( CPerlHash::iterator it = this->begin(); it != this->end(); it++ ) + sv_2mortal((SV *) pHash); + for(CPerlHash::iterator it = this->begin(); it != this->end(); it++) { - SV *pSV = it->second.GetSV( false ); - hv_store( pHash, it->first.c_str(), it->first.length(), pSV, 0); + SV *pSV = it->second.GetSV(false); + hv_store(pHash, it->first.c_str(), it->first.length(), pSV, 0); } - return( pHash ); + return(pHash); } }; @@ -123,44 +123,44 @@ public: CPerlSock() : Csock() { m_iParentFD = -1; - SetSockName( ZNCSOCK ); + SetSockName(ZNCSOCK); } - CPerlSock( const CS_STRING & sHost, u_short iPort, int iTimeout = 60 ) - : Csock( sHost, iPort, iTimeout ) + CPerlSock(const CS_STRING & sHost, u_short iPort, int iTimeout = 60) + : Csock(sHost, iPort, iTimeout) { m_iParentFD = -1; - SetSockName( ZNCSOCK ); + SetSockName(ZNCSOCK); } -// # OnSockDestroy( $sockhandle ) +// # OnSockDestroy($sockhandle) virtual ~CPerlSock(); - virtual Csock *GetSockObj( const CS_STRING & sHostname, u_short iPort ); + virtual Csock *GetSockObj(const CS_STRING & sHostname, u_short iPort); - void SetParentFD( int iFD ) { m_iParentFD = iFD; } - void SetUsername( const CString & sUsername ) { m_sUsername = sUsername; } - void SetModuleName( const CString & sModuleName ) { m_sModuleName = sModuleName; } + void SetParentFD(int iFD) { m_iParentFD = iFD; } + void SetUsername(const CString & sUsername) { m_sUsername = sUsername; } + void SetModuleName(const CString & sModuleName) { m_sModuleName = sModuleName; } - const CString & GetUsername() { return( m_sUsername ); } - const CString & GetModuleName() { return( m_sModuleName ); } + const CString & GetUsername() { return(m_sUsername); } + const CString & GetModuleName() { return(m_sModuleName); } -// # OnConnect( $sockhandle, $parentsockhandle ) +// # OnConnect($sockhandle, $parentsockhandle) virtual void Connected(); -// # OnConnectionFrom( $sockhandle, $remotehost, $remoteport ) - virtual bool ConnectionFrom( const CS_STRING & sHost, u_short iPort ); -// # OnError( $sockhandle, $errno ) - virtual void SockError( int iErrno ); -// # OnConnectionRefused( $sockhandle ) +// # OnConnectionFrom($sockhandle, $remotehost, $remoteport) + virtual bool ConnectionFrom(const CS_STRING & sHost, u_short iPort); +// # OnError($sockhandle, $errno) + virtual void SockError(int iErrno); +// # OnConnectionRefused($sockhandle) virtual void ConnectionRefused(); -// # OnTimeout( $sockhandle ) +// # OnTimeout($sockhandle) virtual void Timeout(); -// # OnDisconnect( $sockhandle ) +// # OnDisconnect($sockhandle) virtual void Disconnected(); -// # OnData( $sockhandle, $bytes, $length ) - virtual void ReadData( const char *data, int len ); -// # OnReadLine( $sockhandle, $line ) - virtual void ReadLine( const CS_STRING & sLine ); +// # OnData($sockhandle, $bytes, $length) + virtual void ReadData(const char *data, int len); +// # OnReadLine($sockhandle, $line) + virtual void ReadLine(const CS_STRING & sLine); private: @@ -172,29 +172,29 @@ private: void SetupArgs() { m_vArgs.clear(); - m_vArgs.push_back( m_sModuleName ); - m_vArgs.push_back( GetRSock() ); + m_vArgs.push_back(m_sModuleName); + m_vArgs.push_back(GetRSock()); } - void AddArg( const PString & sArg ) + void AddArg(const PString & sArg) { - m_vArgs.push_back( sArg ); + m_vArgs.push_back(sArg); } - int CallBack( const PString & sFuncName ); + int CallBack(const PString & sFuncName); }; class CPerlTimer : public CTimer { public: - CPerlTimer( CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription ) - : CTimer( pModule, uInterval, uCycles, sLabel, sDescription) {} + CPerlTimer(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) + : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {} virtual ~CPerlTimer() {} - void SetFuncName( const CString & sFuncName ) { m_sFuncName = sFuncName; } - void SetUserName( const CString & sUserName ) { m_sUserName = sUserName; } - void SetModuleName( const CString & sModuleName ) { m_sModuleName = sModuleName; } + void SetFuncName(const CString & sFuncName) { m_sFuncName = sFuncName; } + void SetUserName(const CString & sUserName) { m_sUserName = sUserName; } + void SetModuleName(const CString & sModuleName) { m_sModuleName = sModuleName; } protected: virtual void RunJob(); @@ -207,7 +207,7 @@ protected: class CModPerl : public CGlobalModule { public: - GLOBALMODCONSTRUCTOR( CModPerl ) + GLOBALMODCONSTRUCTOR(CModPerl) { g_ModPerl = this; m_pPerl = NULL; @@ -216,14 +216,14 @@ public: virtual ~CModPerl() { DestroyAllSocks(); - if ( m_pPerl ) + if (m_pPerl) { const map & msUsers = CZNC::Get().GetUserMap(); - for( map::const_iterator it = msUsers.begin(); it != msUsers.end(); it++ ) + for(map::const_iterator it = msUsers.begin(); it != msUsers.end(); it++) { // need to set it on all of these m_pUser = it->second; - CBNone( "OnShutdown" ); + CBNone("OnShutdown"); m_pUser = NULL; } PerlInterpShutdown(); @@ -233,8 +233,8 @@ public: void PerlInterpShutdown() { - perl_destruct( m_pPerl ); - perl_free( m_pPerl ); + perl_destruct(m_pPerl); + perl_free(m_pPerl); m_pPerl = NULL; } @@ -242,178 +242,178 @@ public: { CString sModule, sTmp; - if ( CZNC::Get().FindModPath( "modperl.pm", sModule, sTmp) ) + if (CZNC::Get().FindModPath("modperl.pm", sModule, sTmp)) { CString sBuffer, sScript; - CFile cFile( sModule ); - if ( ( cFile.Exists() ) && ( cFile.Open( O_RDONLY ) ) ) + CFile cFile(sModule); + if ((cFile.Exists()) && (cFile.Open(O_RDONLY))) { - while( cFile.ReadLine( sBuffer ) ) + while(cFile.ReadLine(sBuffer)) sScript += sBuffer; cFile.Close(); - eval_pv( sScript.c_str(), FALSE ); + eval_pv(sScript.c_str(), FALSE); } } } virtual EModRet OnConfigLine(const CString& sName, const CString& sValue, CUser* pUser, CChan* pChan) { - if ( ( sName.CaseCmp( "loadperlmodule" ) == 0 ) && ( pUser ) ) + if ((sName.CaseCmp("loadperlmodule") == 0) && (pUser)) { m_pUser = pUser; - if( sValue.Right( 3 ) == ".pm" ) - LoadPerlMod( sValue ); + if(sValue.Right(3) == ".pm") + LoadPerlMod(sValue); else - LoadPerlMod( sValue + ".pm" ); + LoadPerlMod(sValue + ".pm"); m_pUser = NULL; - return( HALT ); + return(HALT); } - return( CONTINUE ); + return(CONTINUE); } - void DumpError( const CString & sError ) + void DumpError(const CString & sError) { CString sTmp = sError; - for( CString::size_type a = 0; a < sTmp.size(); a++ ) + for(CString::size_type a = 0; a < sTmp.size(); a++) { - if ( isspace( sTmp[a] ) ) + if (isspace(sTmp[a])) sTmp[a] = ' '; } - PutModule( sTmp ); - DEBUG_ONLY( cerr << sTmp << endl ); + PutModule(sTmp); + DEBUG_ONLY(cerr << sTmp << endl); } - CSockManager * GetSockManager() { return( m_pManager ); } - void DestroyAllSocks( const CString & sModuleName = "" ); + CSockManager * GetSockManager() { return(m_pManager); } + void DestroyAllSocks(const CString & sModuleName = ""); - CUser * GetUser( const CString & sUsername = "", bool bSetUserContext = false ) + CUser * GetUser(const CString & sUsername = "", bool bSetUserContext = false) { - if ( sUsername.empty() ) - return( m_pUser ); + if (sUsername.empty()) + return(m_pUser); - CUser *pUser = CZNC::Get().GetUser( sUsername ); - if ( bSetUserContext ) + CUser *pUser = CZNC::Get().GetUser(sUsername); + if (bSetUserContext) m_pUser = pUser; - return( pUser ); + return(pUser); } void UnSetUser() { m_pUser = NULL; } - virtual bool OnLoad( const CString & sArgs, CString & sMessage ); - virtual void OnUserAttached() { CBNone( "OnUserAttached" ); } - virtual void OnUserDetached() { CBNone( "OnUserDetached" ); } - virtual void OnIRCDisconnected() { CBNone( "OnIRCDisconnected" ); } - virtual void OnIRCConnected() { CBNone( "OnIRCConnected" ); } + virtual bool OnLoad(const CString & sArgs, CString & sMessage); + virtual void OnUserAttached() { CBNone("OnUserAttached"); } + virtual void OnUserDetached() { CBNone("OnUserDetached"); } + virtual void OnIRCDisconnected() { CBNone("OnIRCDisconnected"); } + virtual void OnIRCConnected() { CBNone("OnIRCConnected"); } virtual EModRet OnDCCUserSend(const CNick& RemoteNick, unsigned long uLongIP, unsigned short uPort, const CString& sFile, unsigned long uFileSize); virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) { - CBFour( "OnOp", NICK( OpNick ), NICK( Nick ), CHAN( Channel ), bNoChange ); + CBFour("OnOp", NICK(OpNick), NICK(Nick), CHAN(Channel), bNoChange); } virtual void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) { - CBFour( "OnDeop", NICK( OpNick ), NICK( Nick ), CHAN( Channel ), bNoChange ); + CBFour("OnDeop", NICK(OpNick), NICK(Nick), CHAN(Channel), bNoChange); } virtual void OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) { - CBFour( "OnVoice", NICK( OpNick ), NICK( Nick ), CHAN( Channel ), bNoChange ); + CBFour("OnVoice", NICK(OpNick), NICK(Nick), CHAN(Channel), bNoChange); } virtual void OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, bool bNoChange) { - CBFour( "OnDevoice", NICK( OpNick ), NICK( Nick ), CHAN( Channel ), bNoChange ); + CBFour("OnDevoice", NICK(OpNick), NICK(Nick), CHAN(Channel), bNoChange); } virtual void OnRawMode(const CNick& Nick, CChan& Channel, const CString& sModes, const CString& sArgs) { - CBFour( "OnRawMode", NICK( Nick ), CHAN( Channel ), sModes, sArgs ); + CBFour("OnRawMode", NICK(Nick), CHAN(Channel), sModes, sArgs); } - virtual EModRet OnUserRaw(CString& sLine) { return( CBSingle( "OnUserRaw", sLine ) ); } - virtual EModRet OnRaw(CString& sLine) { return( CBSingle( "OnRaw", sLine ) ); } + virtual EModRet OnUserRaw(CString& sLine) { return(CBSingle("OnUserRaw", sLine)); } + virtual EModRet OnRaw(CString& sLine) { return(CBSingle("OnRaw", sLine)); } virtual void OnModCommand(const CString& sCommand) { - if ( CBSingle( "OnModCommand", sCommand ) == 0 ) - Eval( sCommand ); + if (CBSingle("OnModCommand", sCommand) == 0) + Eval(sCommand); } - virtual void OnModNotice(const CString& sMessage) { CBSingle( "OnModNotice", sMessage ); } - virtual void OnModCTCP(const CString& sMessage) { CBSingle( "OnModCTCP", sMessage ); } + virtual void OnModNotice(const CString& sMessage) { CBSingle("OnModNotice", sMessage); } + virtual void OnModCTCP(const CString& sMessage) { CBSingle("OnModCTCP", sMessage); } virtual void OnQuit(const CNick& Nick, const CString& sMessage, const vector& vChans) { VPString vsArgs; - vsArgs.push_back( Nick.GetNickMask() ); - vsArgs.push_back( sMessage ); - for( vector::size_type a = 0; a < vChans.size(); a++ ) - vsArgs.push_back( vChans[a]->GetName() ); + vsArgs.push_back(Nick.GetNickMask()); + vsArgs.push_back(sMessage); + for(vector::size_type a = 0; a < vChans.size(); a++) + vsArgs.push_back(vChans[a]->GetName()); - CallBack( "OnQuit", vsArgs ); + CallBack("OnQuit", vsArgs); } virtual void OnNick(const CNick& Nick, const CString& sNewNick, const vector& vChans) { VPString vsArgs; - vsArgs.push_back( Nick.GetNickMask() ); - vsArgs.push_back( sNewNick ); - for( vector::size_type a = 0; a < vChans.size(); a++ ) - vsArgs.push_back( vChans[a]->GetName() ); + vsArgs.push_back(Nick.GetNickMask()); + vsArgs.push_back(sNewNick); + for(vector::size_type a = 0; a < vChans.size(); a++) + vsArgs.push_back(vChans[a]->GetName()); - CallBack( "OnNick", vsArgs ); + CallBack("OnNick", vsArgs); } virtual void OnKick(const CNick& Nick, const CString& sOpNick, CChan& Channel, const CString& sMessage) { - CBFour( "OnKick", NICK( Nick ), sOpNick, CHAN( Channel ), sMessage ); + CBFour("OnKick", NICK(Nick), sOpNick, CHAN(Channel), sMessage); } - virtual void OnJoin(const CNick& Nick, CChan& Channel) { CBDouble( "OnJoin", NICK( Nick ), CHAN( Channel ) ); } - virtual void OnPart(const CNick& Nick, CChan& Channel) { CBDouble( "OnPart", NICK( Nick ), CHAN( Channel ) ); } + virtual void OnJoin(const CNick& Nick, CChan& Channel) { CBDouble("OnJoin", NICK(Nick), CHAN(Channel)); } + virtual void OnPart(const CNick& Nick, CChan& Channel) { CBDouble("OnPart", NICK(Nick), CHAN(Channel)); } virtual EModRet OnUserCTCPReply(CString& sTarget, CString& sMessage) { - return CBDouble( "OnUserCTCPReply", sTarget, sMessage ); + return CBDouble("OnUserCTCPReply", sTarget, sMessage); } virtual EModRet OnCTCPReply(CNick& Nick, CString& sMessage) { - return CBDouble( "OnCTCPReply", NICK( Nick ), sMessage ); + return CBDouble("OnCTCPReply", NICK(Nick), sMessage); } virtual EModRet OnUserCTCP(CString& sTarget, CString& sMessage) { - return CBDouble( "OnUserCTCP", sTarget, sMessage ); + return CBDouble("OnUserCTCP", sTarget, sMessage); } virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage) { - return CBDouble( "OnPrivCTCP", NICK( Nick ), sMessage ); + return CBDouble("OnPrivCTCP", NICK(Nick), sMessage); } virtual EModRet OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage) { - return CBTriple( "OnChanCTCP", NICK( Nick ), CHAN( Channel ), sMessage ); + return CBTriple("OnChanCTCP", NICK(Nick), CHAN(Channel), sMessage); } virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) { - return CBDouble( "OnUserMsg", sTarget, sMessage ); + return CBDouble("OnUserMsg", sTarget, sMessage); } virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage) { - return CBDouble( "OnPrivMsg", NICK( Nick ), sMessage ); + return CBDouble("OnPrivMsg", NICK(Nick), sMessage); } - virtual EModRet OnChanMsg( CNick& Nick, CChan & Channel, CString & sMessage ) + virtual EModRet OnChanMsg(CNick& Nick, CChan & Channel, CString & sMessage) { - return( CBTriple( "OnChanMsg", NICK( Nick ), CHAN( Channel ), sMessage ) ); + return(CBTriple("OnChanMsg", NICK(Nick), CHAN(Channel), sMessage)); } virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage) { - return CBDouble( "OnUserNotice", sTarget, sMessage ); + return CBDouble("OnUserNotice", sTarget, sMessage); } virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage) { - return CBDouble( "OnPrivNotice", NICK( Nick ), sMessage ); + return CBDouble("OnPrivNotice", NICK(Nick), sMessage); } virtual EModRet OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage) { - return( CBTriple( "OnChanNotice", NICK( Nick ), CHAN( Channel ), sMessage ) ); + return(CBTriple("OnChanNotice", NICK(Nick), CHAN(Channel), sMessage)); } enum ECBTYPES @@ -424,84 +424,84 @@ public: CB_SOCK = 4 }; - EModRet CallBack( const PString & sHookName, const VPString & vsArgs, - ECBTYPES eCBType = CB_ONHOOK, const PString & sUsername = "" ); + EModRet CallBack(const PString & sHookName, const VPString & vsArgs, + ECBTYPES eCBType = CB_ONHOOK, const PString & sUsername = ""); - EModRet CBNone( const PString & sHookName ) + EModRet CBNone(const PString & sHookName) { VPString vsArgs; - return( CallBack( sHookName, vsArgs ) ); + return(CallBack(sHookName, vsArgs)); } template - inline EModRet CBSingle( const PString & sHookName, const A & a ) + inline EModRet CBSingle(const PString & sHookName, const A & a) { VPString vsArgs; - vsArgs.push_back( a ); - return( CallBack( sHookName, vsArgs ) ); + vsArgs.push_back(a); + return(CallBack(sHookName, vsArgs)); } template - inline EModRet CBDouble( const PString & sHookName, const A & a, const B & b ) + inline EModRet CBDouble(const PString & sHookName, const A & a, const B & b) { VPString vsArgs; - vsArgs.push_back( a ); - vsArgs.push_back( b ); - return( CallBack( sHookName, vsArgs ) ); + vsArgs.push_back(a); + vsArgs.push_back(b); + return(CallBack(sHookName, vsArgs)); } template - inline EModRet CBTriple( const PString & sHookName, const A & a, const B & b, const C & c ) + inline EModRet CBTriple(const PString & sHookName, const A & a, const B & b, const C & c) { VPString vsArgs; - vsArgs.push_back( a ); - vsArgs.push_back( b ); - vsArgs.push_back( c ); - return( CallBack( sHookName, vsArgs ) ); + vsArgs.push_back(a); + vsArgs.push_back(b); + vsArgs.push_back(c); + return(CallBack(sHookName, vsArgs)); } template - inline EModRet CBFour( const PString & sHookName, const A & a, const B & b, const C & c, const D & d ) + inline EModRet CBFour(const PString & sHookName, const A & a, const B & b, const C & c, const D & d) { VPString vsArgs; - vsArgs.push_back( a ); - vsArgs.push_back( b ); - vsArgs.push_back( c ); - vsArgs.push_back( d ); - return( CallBack( sHookName, vsArgs ) ); + vsArgs.push_back(a); + vsArgs.push_back(b); + vsArgs.push_back(c); + vsArgs.push_back(d); + return(CallBack(sHookName, vsArgs)); } - bool Eval( const CString & sScript, const CString & sFuncName = ZNCEvalCB ); + bool Eval(const CString & sScript, const CString & sFuncName = ZNCEvalCB); - virtual EModRet OnStatusCommand( const CString& sLine ) + virtual EModRet OnStatusCommand(const CString& sLine) { - CString sCommand = sLine.Token( 0 ); + CString sCommand = sLine.Token(0); - if( sCommand.CaseCmp( "loadperlmod", 11 ) == 0 || sCommand.CaseCmp( "unloadperlmod", 13 ) == 0 || sCommand.CaseCmp( "reloadperlmod", 13 ) == 0 ) + if(sCommand.CaseCmp("loadperlmod", 11) == 0 || sCommand.CaseCmp("unloadperlmod", 13) == 0 || sCommand.CaseCmp("reloadperlmod", 13) == 0) { - CString sModule = sLine.Token( 1 ); - if ( sModule.Right( 3 ) != ".pm" ) + CString sModule = sLine.Token(1); + if (sModule.Right(3) != ".pm") sModule += ".pm"; - if ( sCommand.CaseCmp( "loadperlmod", 11 ) == 0 ) - LoadPerlMod( sModule ); - else if ( sCommand.CaseCmp( "unloadperlmod", 13 ) == 0 ) - UnloadPerlMod( sModule ); + if (sCommand.CaseCmp("loadperlmod", 11) == 0) + LoadPerlMod(sModule); + else if (sCommand.CaseCmp("unloadperlmod", 13) == 0) + UnloadPerlMod(sModule); else { - UnloadPerlMod( sModule ); - LoadPerlMod( sModule ); + UnloadPerlMod(sModule); + LoadPerlMod(sModule); } - return( HALT ); + return(HALT); } - return( CONTINUE ); + return(CONTINUE); } - void LoadPerlMod( const CString & sModule ); - void UnloadPerlMod( const CString & sModule ); + void LoadPerlMod(const CString & sModule); + void UnloadPerlMod(const CString & sModule); private: PerlInterpreter *m_pPerl; }; -GLOBALMODULEDEFS( CModPerl, "Loads perl scripts as ZNC modules" ) +GLOBALMODULEDEFS(CModPerl, "Loads perl scripts as ZNC modules") @@ -510,13 +510,13 @@ GLOBALMODULEDEFS( CModPerl, "Loads perl scripts as ZNC modules" ) XS(XS_ZNC_COREAddTimer) { dXSARGS; - if ( items != 5 ) - Perl_croak( aTHX_ "Usage: COREAddTimer( modname, funcname, description, interval, cycles )" ); + if (items != 5) + Perl_croak(aTHX_ "Usage: COREAddTimer(modname, funcname, description, interval, cycles)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( ( g_ModPerl ) && ( g_ModPerl->GetUser() ) ) + if ((g_ModPerl) && (g_ModPerl->GetUser())) { CString sModName = (char *)SvPV(ST(0),PL_na); CString sFuncName = (char *)SvPV(ST(1),PL_na); @@ -525,11 +525,11 @@ XS(XS_ZNC_COREAddTimer) u_int iCycles = (u_int)SvUV(ST(4)); CString sUserName = g_ModPerl->GetUser()->GetUserName(); CString sLabel = sUserName + sModName + sFuncName; - CPerlTimer *pTimer = new CPerlTimer( g_ModPerl, iInterval, iCycles, sLabel, sDesc ); - pTimer->SetFuncName( sFuncName ); - pTimer->SetUserName( sUserName ); - pTimer->SetModuleName( sModName ); - g_ModPerl->AddTimer( pTimer ); + CPerlTimer *pTimer = new CPerlTimer(g_ModPerl, iInterval, iCycles, sLabel, sDesc); + pTimer->SetFuncName(sFuncName); + pTimer->SetUserName(sUserName); + pTimer->SetModuleName(sModName); + g_ModPerl->AddTimer(pTimer); } PUTBACK; } @@ -538,22 +538,22 @@ XS(XS_ZNC_COREAddTimer) XS(XS_ZNC_CORERemTimer) { dXSARGS; - if ( items != 2 ) - Perl_croak( aTHX_ "Usage: CORERemTimer( modname, funcname )" ); + if (items != 2) + Perl_croak(aTHX_ "Usage: CORERemTimer(modname, funcname)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( ( g_ModPerl ) && ( g_ModPerl->GetUser() ) ) + if ((g_ModPerl) && (g_ModPerl->GetUser())) { CString sModName = (char *)SvPV(ST(0),PL_na); CString sFuncName = (char *)SvPV(ST(1),PL_na); CString sUserName = g_ModPerl->GetUser()->GetUserName(); CString sLabel = sUserName + sModName + sFuncName; - CTimer *pTimer = g_ModPerl->FindTimer( sLabel ); - if ( pTimer ) + CTimer *pTimer = g_ModPerl->FindTimer(sLabel); + if (pTimer) pTimer->Stop(); else - g_ModPerl->PutModule( "Unable to find Timer!" ); + g_ModPerl->PutModule("Unable to find Timer!"); } PUTBACK; } @@ -561,23 +561,23 @@ XS(XS_ZNC_CORERemTimer) XS(XS_ZNC_COREPuts) { dXSARGS; - if ( items != 2 ) - Perl_croak( aTHX_ "Usage: COREPuts( sWHich, sLine )" ); + if (items != 2) + Perl_croak(aTHX_ "Usage: COREPuts(sWHich, sLine)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( ( g_ModPerl ) && ( g_ModPerl->GetUser() ) ) + if ((g_ModPerl) && (g_ModPerl->GetUser())) { CString sWhich = (char *)SvPV(ST(0),PL_na); CString sLine = (char *)SvPV(ST(1),PL_na); - if ( sWhich == "IRC" ) - g_ModPerl->PutIRC( sLine ); - else if ( sWhich == "Status" ) - g_ModPerl->PutStatus( sLine ); - else if ( sWhich == "User" ) - g_ModPerl->PutUser( sLine ); + if (sWhich == "IRC") + g_ModPerl->PutIRC(sLine); + else if (sWhich == "Status") + g_ModPerl->PutStatus(sLine); + else if (sWhich == "User") + g_ModPerl->PutUser(sLine); } PUTBACK; } @@ -586,16 +586,16 @@ XS(XS_ZNC_COREPuts) XS(XS_ZNC_LoadMod) { dXSARGS; - if ( items != 1 ) - Perl_croak( aTHX_ "Usage: LoadMod( module )" ); + if (items != 1) + Perl_croak(aTHX_ "Usage: LoadMod(module)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( g_ModPerl ) + if (g_ModPerl) { CString sModule = (char *)SvPV(ST(0),PL_na); - g_ModPerl->LoadPerlMod( sModule ); + g_ModPerl->LoadPerlMod(sModule); } PUTBACK; } @@ -604,16 +604,16 @@ XS(XS_ZNC_LoadMod) XS(XS_ZNC_UnloadMod) { dXSARGS; - if ( items != 1 ) - Perl_croak( aTHX_ "Usage: UnloadMod( module )" ); + if (items != 1) + Perl_croak(aTHX_ "Usage: UnloadMod(module)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( g_ModPerl ) + if (g_ModPerl) { CString sModule = (char *)SvPV(ST(0),PL_na); - g_ModPerl->UnloadPerlMod( sModule ); + g_ModPerl->UnloadPerlMod(sModule); } PUTBACK; } @@ -622,22 +622,22 @@ XS(XS_ZNC_UnloadMod) XS(XS_ZNC_COREPutModule) { dXSARGS; - if ( items != 4 ) - Perl_croak( aTHX_ "Usage: COREPutModule( sWhich sLine, sIdent, sHost )" ); + if (items != 4) + Perl_croak(aTHX_ "Usage: COREPutModule(sWhich sLine, sIdent, sHost)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( g_ModPerl ) + if (g_ModPerl) { CString sWhich = (char *)SvPV(ST(0),PL_na); CString sLine = (char *)SvPV(ST(1),PL_na); CString sIdent = (char *)SvPV(ST(2),PL_na); CString sHost = (char *)SvPV(ST(3),PL_na); - if ( sWhich == "Module" ) - g_ModPerl->PutModule( sLine, sIdent, sHost ); + if (sWhich == "Module") + g_ModPerl->PutModule(sLine, sIdent, sHost); else - g_ModPerl->PutModNotice( sLine, sIdent, sHost ); + g_ModPerl->PutModNotice(sLine, sIdent, sHost); } PUTBACK; } @@ -646,23 +646,23 @@ XS(XS_ZNC_COREPutModule) XS(XS_ZNC_GetNicks) { dXSARGS; - if ( items != 1 ) - Perl_croak( aTHX_ "Usage: GetNicks( sChan )" ); + if (items != 1) + Perl_croak(aTHX_ "Usage: GetNicks(sChan)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( ( g_ModPerl ) && ( g_ModPerl->GetUser() ) ) + if ((g_ModPerl) && (g_ModPerl->GetUser())) { CString sChan = (char *)SvPV(ST(0),PL_na); CUser * pUser = g_ModPerl->GetUser(); - CChan * pChan = pUser->FindChan( sChan ); - if ( !pChan ) - XSRETURN( 0 ); + CChan * pChan = pUser->FindChan(sChan); + if (!pChan) + XSRETURN(0); const map< CString,CNick* > & mscNicks = pChan->GetNicks(); - for( map< CString,CNick* >::const_iterator it = mscNicks.begin(); it != mscNicks.end(); it++ ) + for(map< CString,CNick* >::const_iterator it = mscNicks.begin(); it != mscNicks.end(); it++) { CNick & cNick = *(it->second); CPerlHash cHash; @@ -670,7 +670,7 @@ XS(XS_ZNC_GetNicks) cHash["Ident"] = cNick.GetIdent(); cHash["Host"] = cNick.GetHost(); cHash["Perms"] = cNick.GetPermStr(); - XPUSHs( newRV_noinc( (SV*)cHash.GetHash() ) ); + XPUSHs(newRV_noinc((SV*)cHash.GetHash())); } } PUTBACK; @@ -681,37 +681,37 @@ XS(XS_ZNC_GetString) { dXSARGS; - if ( items != 1 ) - Perl_croak( aTHX_ "Usage: GetString( sName )" ); + if (items != 1) + Perl_croak(aTHX_ "Usage: GetString(sName)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( ( g_ModPerl ) && ( g_ModPerl->GetUser() ) ) + if ((g_ModPerl) && (g_ModPerl->GetUser())) { CUser * pUser = g_ModPerl->GetUser(); PString sReturn; CString sName = (char *)SvPV(ST(0),PL_na); - if( sName == "UserName" ) sReturn = pUser->GetUserName(); - else if ( sName == "Nick" ) sReturn = pUser->GetNick(); - else if ( sName == "AltNick" ) sReturn = pUser->GetAltNick(); - else if ( sName == "Ident" ) sReturn = pUser->GetIdent(); - else if ( sName == "RealName" ) sReturn = pUser->GetRealName(); - else if ( sName == "VHost" ) sReturn = pUser->GetVHost(); - else if ( sName == "Pass" ) sReturn = pUser->GetPass(); - else if ( sName == "CurPath" ) sReturn = CZNC::Get().GetCurPath(); - else if ( sName == "DLPath" ) sReturn = pUser->GetDLPath(); - else if ( sName == "ModPath" ) sReturn = CZNC::Get().GetModPath(); - else if ( sName == "HomePath" ) sReturn = CZNC::Get().GetHomePath(); - else if ( sName == "SavePath" ) sReturn = g_ModPerl->GetSavePath(); - else if ( sName == "StatusPrefix" ) sReturn = pUser->GetStatusPrefix(); - else if ( sName == "DefaultChanModes" ) sReturn = pUser->GetDefaultChanModes(); - else if ( sName == "IRCServer" ) sReturn = pUser->GetIRCServer(); + if(sName == "UserName") sReturn = pUser->GetUserName(); + else if (sName == "Nick") sReturn = pUser->GetNick(); + else if (sName == "AltNick") sReturn = pUser->GetAltNick(); + else if (sName == "Ident") sReturn = pUser->GetIdent(); + else if (sName == "RealName") sReturn = pUser->GetRealName(); + else if (sName == "VHost") sReturn = pUser->GetVHost(); + else if (sName == "Pass") sReturn = pUser->GetPass(); + else if (sName == "CurPath") sReturn = CZNC::Get().GetCurPath(); + else if (sName == "DLPath") sReturn = pUser->GetDLPath(); + else if (sName == "ModPath") sReturn = CZNC::Get().GetModPath(); + else if (sName == "HomePath") sReturn = CZNC::Get().GetHomePath(); + else if (sName == "SavePath") sReturn = g_ModPerl->GetSavePath(); + else if (sName == "StatusPrefix") sReturn = pUser->GetStatusPrefix(); + else if (sName == "DefaultChanModes") sReturn = pUser->GetDefaultChanModes(); + else if (sName == "IRCServer") sReturn = pUser->GetIRCServer(); else - XSRETURN( 0 ); + XSRETURN(0); - XPUSHs( sReturn.GetSV() ); + XPUSHs(sReturn.GetSV()); } PUTBACK; } @@ -722,27 +722,27 @@ XS(XS_ZNC_GetString) XS(XS_ZNC_WriteSock) { dXSARGS; - if ( items != 3 ) - Perl_croak( aTHX_ "Usage: ZNC::WriteSock( sockhandle, bytes, len )" ); + if (items != 3) + Perl_croak(aTHX_ "Usage: ZNC::WriteSock(sockhandle, bytes, len)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( g_ModPerl ) + if (g_ModPerl) { PString sReturn = false; int iSockFD = SvIV(ST(0)); STRLEN iLen = SvUV(ST(2)); - if ( iLen > 0 ) + if (iLen > 0) { PString sData; STRLEN iLen2 = iLen; - sData.append( SvPV( ST(1), iLen ), iLen2 ); - CPerlSock *pSock = (CPerlSock *)MANAGER->FindSockByFD( iSockFD ); - if ( ( pSock ) && ( pSock->GetSockName() == ZNCSOCK ) ) - sReturn = pSock->Write( sData.data(), sData.length() ); + sData.append(SvPV(ST(1), iLen), iLen2); + CPerlSock *pSock = (CPerlSock *)MANAGER->FindSockByFD(iSockFD); + if ((pSock) && (pSock->GetSockName() == ZNCSOCK)) + sReturn = pSock->Write(sData.data(), sData.length()); } - XPUSHs( sReturn.GetSV() ); + XPUSHs(sReturn.GetSV()); } PUTBACK; } @@ -751,17 +751,17 @@ XS(XS_ZNC_WriteSock) XS(XS_ZNC_CloseSock) { dXSARGS; - if ( items != 1 ) - Perl_croak( aTHX_ "Usage: ZNC::CloseSock( sockhandle )" ); + if (items != 1) + Perl_croak(aTHX_ "Usage: ZNC::CloseSock(sockhandle)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( g_ModPerl ) + if (g_ModPerl) { int iSockFD = SvIV(ST(0)); - CPerlSock *pSock = (CPerlSock *)MANAGER->FindSockByFD( iSockFD ); - if ( ( pSock ) && ( pSock->GetSockName() == ZNCSOCK ) ) + CPerlSock *pSock = (CPerlSock *)MANAGER->FindSockByFD(iSockFD); + if ((pSock) && (pSock->GetSockName() == ZNCSOCK)) pSock->Close(); } PUTBACK; @@ -771,23 +771,23 @@ XS(XS_ZNC_CloseSock) XS(XS_ZNC_SetSockValue) { dXSARGS; - if ( items < 3 ) - Perl_croak( aTHX_ "Usage: ZNC::SetSockValue( sockhandle, what, value )" ); + if (items < 3) + Perl_croak(aTHX_ "Usage: ZNC::SetSockValue(sockhandle, what, value)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( g_ModPerl ) + if (g_ModPerl) { int iSockFD = SvIV(ST(0)); PString sWhat = (char *)SvPV(ST(1),PL_na); - CPerlSock *pSock = (CPerlSock *)MANAGER->FindSockByFD( iSockFD ); - if ( ( pSock ) && ( pSock->GetSockName() == ZNCSOCK ) ) + CPerlSock *pSock = (CPerlSock *)MANAGER->FindSockByFD(iSockFD); + if ((pSock) && (pSock->GetSockName() == ZNCSOCK)) { - if ( sWhat == "timeout" ) + if (sWhat == "timeout") { u_int iTimeout = SvUV(ST(2)); - pSock->SetTimeout( iTimeout ); + pSock->SetTimeout(iTimeout); } } } @@ -798,13 +798,13 @@ XS(XS_ZNC_SetSockValue) XS(XS_ZNC_COREConnect) { dXSARGS; - if ( items != 6 ) - Perl_croak( aTHX_ "Usage: ZNC::COREConnect( $modname, $host, $port, $timeout, $bEnableReadline, $bUseSSL )" ); + if (items != 6) + Perl_croak(aTHX_ "Usage: ZNC::COREConnect($modname, $host, $port, $timeout, $bEnableReadline, $bUseSSL)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( ( g_ModPerl ) && ( g_ModPerl->GetUser() ) ) + if ((g_ModPerl) && (g_ModPerl->GetUser())) { PString sReturn = -1; PString sModuleName = (char *)SvPV(ST(0),PL_na); @@ -813,17 +813,17 @@ XS(XS_ZNC_COREConnect) u_int iTimeout = SvUV(ST(3)); u_int iEnableReadline = SvUV(ST(4)); u_int iUseSSL = SvUV(ST(5)); - CPerlSock *pSock = new CPerlSock( sHostname, iPort, iTimeout ); - pSock->SetSockName( ZNCSOCK ); - pSock->SetUsername( g_ModPerl->GetUser()->GetUserName() ); - pSock->SetModuleName( sModuleName ); - if ( iEnableReadline ) + CPerlSock *pSock = new CPerlSock(sHostname, iPort, iTimeout); + pSock->SetSockName(ZNCSOCK); + pSock->SetUsername(g_ModPerl->GetUser()->GetUserName()); + pSock->SetModuleName(sModuleName); + if (iEnableReadline) pSock->EnableReadLine(); - if ( MANAGER->Connect( sHostname, iPort, ZNCSOCK, iTimeout, ( iUseSSL != 0 ), "", pSock ) ) + if (MANAGER->Connect(sHostname, iPort, ZNCSOCK, iTimeout, (iUseSSL != 0), "", pSock)) sReturn = pSock->GetRSock(); - XPUSHs( sReturn.GetSV() ); + XPUSHs(sReturn.GetSV()); } PUTBACK; } @@ -832,13 +832,13 @@ XS(XS_ZNC_COREConnect) XS(XS_ZNC_COREListen) { dXSARGS; - if ( items != 5 ) - Perl_croak( aTHX_ "Usage: ZNC::COREListen( $modname, $port, $bindhost, $bEnableReadline, $bUseSSL )" ); + if (items != 5) + Perl_croak(aTHX_ "Usage: ZNC::COREListen($modname, $port, $bindhost, $bEnableReadline, $bUseSSL)"); SP -= items; ax = (SP - PL_stack_base) + 1 ; { - if ( ( g_ModPerl ) && ( g_ModPerl->GetUser() ) ) + if ((g_ModPerl) && (g_ModPerl->GetUser())) { PString sReturn = -1; PString sModuleName = (char *)SvPV(ST(0),PL_na); @@ -848,37 +848,37 @@ XS(XS_ZNC_COREListen) u_int iUseSSL = SvUV(ST(4)); CPerlSock *pSock = new CPerlSock(); - pSock->SetSockName( ZNCSOCK ); - pSock->SetUsername( g_ModPerl->GetUser()->GetUserName() ); - pSock->SetModuleName( sModuleName ); + pSock->SetSockName(ZNCSOCK); + pSock->SetUsername(g_ModPerl->GetUser()->GetUserName()); + pSock->SetModuleName(sModuleName); - if ( iEnableReadline ) + if (iEnableReadline) pSock->EnableReadLine(); bool bContinue = true; #ifdef HAVE_LIBSSL - if ( iUseSSL != 0 ) + if (iUseSSL != 0) { - if ( CFile::Exists( CZNC::Get().GetPemLocation() ) ) - pSock->SetPemLocation( CZNC::Get().GetPemLocation() ); + if (CFile::Exists(CZNC::Get().GetPemLocation())) + pSock->SetPemLocation(CZNC::Get().GetPemLocation()); else { - g_ModPerl->PutModule( "PEM File does not exist! (looking for " + CZNC::Get().GetPemLocation() + ")" ); + g_ModPerl->PutModule("PEM File does not exist! (looking for " + CZNC::Get().GetPemLocation() + ")"); bContinue = false; } } #endif /* HAVE_LIBSSL */ - if ( bContinue ) + if (bContinue) { - if ( MANAGER->ListenHost( iPort, ZNCSOCK, sHostname, ( iUseSSL != 0 ), SOMAXCONN, pSock ) ) + if (MANAGER->ListenHost(iPort, ZNCSOCK, sHostname, (iUseSSL != 0), SOMAXCONN, pSock)) sReturn = pSock->GetRSock(); } else sReturn = -1; - XPUSHs( sReturn.GetSV() ); + XPUSHs(sReturn.GetSV()); } PUTBACK; @@ -887,92 +887,92 @@ XS(XS_ZNC_COREListen) /////////// supporting functions from within module -bool CModPerl::Eval( const CString & sScript, const CString & sFuncName ) +bool CModPerl::Eval(const CString & sScript, const CString & sFuncName) { dSP; SAVETMPS; - PUSHMARK( SP ); - XPUSHs( sv_2mortal( newSVpv( sScript.c_str(), sScript.length() ) ) ); + PUSHMARK(SP); + XPUSHs(sv_2mortal(newSVpv(sScript.c_str(), sScript.length()))); PUTBACK; SPAGAIN; - call_pv( sFuncName.c_str(), G_EVAL|G_KEEPERR|G_VOID|G_DISCARD ); + call_pv(sFuncName.c_str(), G_EVAL|G_KEEPERR|G_VOID|G_DISCARD); bool bReturn = true; - if ( SvTRUE( ERRSV ) ) + if (SvTRUE(ERRSV)) { - DumpError( SvPV( ERRSV, PL_na) ); + DumpError(SvPV(ERRSV, PL_na)); bReturn = false; } PUTBACK; FREETMPS; - return( bReturn ); + return(bReturn); } -CModPerl::EModRet CModPerl::CallBack( const PString & sHookName, const VPString & vsArgs, - ECBTYPES eCBType, const PString & sUsername ) +CModPerl::EModRet CModPerl::CallBack(const PString & sHookName, const VPString & vsArgs, + ECBTYPES eCBType, const PString & sUsername) { - if ( !m_pPerl ) - return( CONTINUE ); + if (!m_pPerl) + return(CONTINUE); dSP; SAVETMPS; - PUSHMARK( SP ); + PUSHMARK(SP); CString sFuncToCall; - if ( eCBType == CB_LOCAL ) + if (eCBType == CB_LOCAL) sFuncToCall = sHookName; else { - if ( sUsername.empty() ) + if (sUsername.empty()) { - if ( !m_pUser ) - return( CONTINUE ); + if (!m_pUser) + return(CONTINUE); - XPUSHs( PString( m_pUser->GetUserName() ).GetSV() ); + XPUSHs(PString(m_pUser->GetUserName()).GetSV()); } else - XPUSHs( sUsername.GetSV() ); - XPUSHs( sHookName.GetSV() ); - if ( eCBType == CB_ONHOOK ) + XPUSHs(sUsername.GetSV()); + XPUSHs(sHookName.GetSV()); + if (eCBType == CB_ONHOOK) sFuncToCall = ZNCCallFuncCB; - else if ( eCBType == CB_TIMER ) + else if (eCBType == CB_TIMER) sFuncToCall = ZNCCallTimerCB; else sFuncToCall = ZNCCallSockCB; } - for( VPString::size_type a = 0; a < vsArgs.size(); a++ ) - XPUSHs( vsArgs[a].GetSV() ); + for(VPString::size_type a = 0; a < vsArgs.size(); a++) + XPUSHs(vsArgs[a].GetSV()); PUTBACK; - int iCount = call_pv( sFuncToCall.c_str(), G_EVAL|G_SCALAR ); + int iCount = call_pv(sFuncToCall.c_str(), G_EVAL|G_SCALAR); SPAGAIN; int iRet = CONTINUE; - if ( SvTRUE( ERRSV ) ) + if (SvTRUE(ERRSV)) { - CString sError = SvPV( ERRSV, PL_na); - DumpError( sHookName + ": " + sError ); + CString sError = SvPV(ERRSV, PL_na); + DumpError(sHookName + ": " + sError); - if ( eCBType == CB_TIMER ) + if (eCBType == CB_TIMER) iRet = HALT; } else { - if ( iCount == 1 ) + if (iCount == 1) iRet = POPi; } PUTBACK; FREETMPS; - return( (CModPerl::EModRet)iRet ); + return((CModPerl::EModRet)iRet); } ////////////////////// Events /////////////////// @@ -980,17 +980,17 @@ CModPerl::EModRet CModPerl::CallBack( const PString & sHookName, const VPString // special case this, required for perl modules that are dynamic EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); -bool CModPerl::OnLoad( const CString & sArgs, CString & sMessage ) +bool CModPerl::OnLoad(const CString & sArgs, CString & sMessage) { m_pPerl = perl_alloc(); - perl_construct( m_pPerl ); + perl_construct(m_pPerl); const char *pArgv[] = { "", "-e", "0", "-T", "-w" }; - if ( perl_parse( m_pPerl, NULL, 2, (char **)pArgv, (char **)NULL ) != 0 ) + if (perl_parse(m_pPerl, NULL, 2, (char **)pArgv, (char **)NULL) != 0) { - perl_free( m_pPerl ); + perl_free(m_pPerl); m_pPerl = NULL; - return( false ); + return(false); } #ifdef PERL_EXIT_DESTRUCT_END @@ -998,80 +998,80 @@ bool CModPerl::OnLoad( const CString & sArgs, CString & sMessage ) #endif /* PERL_EXIT_DESTRUCT_END */ /* system functions */ - newXS( "DynaLoader::boot_DynaLoader", boot_DynaLoader, "modperl" ); - newXS( "ZNC::COREPutModule", XS_ZNC_COREPutModule, "modperl" ); - newXS( "ZNC::COREAddTimer", XS_ZNC_COREAddTimer, "modperl" ); - newXS( "ZNC::CORERemTimer", XS_ZNC_CORERemTimer, "modperl" ); - newXS( "ZNC::COREPuts", XS_ZNC_COREPuts, "modperl" ); - newXS( "ZNC::COREConnect", XS_ZNC_COREConnect, "modperl" ); - newXS( "ZNC::COREListen", XS_ZNC_COREListen, "modperl" ); + newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, "modperl"); + newXS("ZNC::COREPutModule", XS_ZNC_COREPutModule, "modperl"); + newXS("ZNC::COREAddTimer", XS_ZNC_COREAddTimer, "modperl"); + newXS("ZNC::CORERemTimer", XS_ZNC_CORERemTimer, "modperl"); + newXS("ZNC::COREPuts", XS_ZNC_COREPuts, "modperl"); + newXS("ZNC::COREConnect", XS_ZNC_COREConnect, "modperl"); + newXS("ZNC::COREListen", XS_ZNC_COREListen, "modperl"); /* user functions */ - newXS( "ZNC::GetNicks", XS_ZNC_GetNicks, "modperl" ); - newXS( "ZNC::GetString", XS_ZNC_GetString, "modperl" ); - newXS( "ZNC::LoadMod", XS_ZNC_LoadMod, "modperl" ); - newXS( "ZNC::UnloadMod", XS_ZNC_UnloadMod, "modperl" ); - newXS( "ZNC::WriteSock", XS_ZNC_WriteSock, "modperl" ); - newXS( "ZNC::CloseSock", XS_ZNC_CloseSock, "modperl" ); - newXS( "ZNC::SetSockValue", XS_ZNC_SetSockValue, "modperl" ); + newXS("ZNC::GetNicks", XS_ZNC_GetNicks, "modperl"); + newXS("ZNC::GetString", XS_ZNC_GetString, "modperl"); + newXS("ZNC::LoadMod", XS_ZNC_LoadMod, "modperl"); + newXS("ZNC::UnloadMod", XS_ZNC_UnloadMod, "modperl"); + newXS("ZNC::WriteSock", XS_ZNC_WriteSock, "modperl"); + newXS("ZNC::CloseSock", XS_ZNC_CloseSock, "modperl"); + newXS("ZNC::SetSockValue", XS_ZNC_SetSockValue, "modperl"); // this sets up the eval CB that we call from here on out. this way we can grab the error produced SetupZNCScript(); - HV *pZNCSpace = get_hv( "ZNC::", TRUE); + HV *pZNCSpace = get_hv("ZNC::", TRUE); - if ( !pZNCSpace ) - return( false ); + if (!pZNCSpace) + return(false); sv_2mortal((SV*)pZNCSpace); - newCONSTSUB( pZNCSpace, "CONTINUE", PString( CONTINUE ).GetSV() ); - newCONSTSUB( pZNCSpace, "HALT", PString( HALT ).GetSV() ); - newCONSTSUB( pZNCSpace, "HALTMODS", PString( HALTMODS ).GetSV() ); - newCONSTSUB( pZNCSpace, "HALTCORE", PString( HALTCORE ).GetSV() ); + newCONSTSUB(pZNCSpace, "CONTINUE", PString(CONTINUE).GetSV()); + newCONSTSUB(pZNCSpace, "HALT", PString(HALT).GetSV()); + newCONSTSUB(pZNCSpace, "HALTMODS", PString(HALTMODS).GetSV()); + newCONSTSUB(pZNCSpace, "HALTCORE", PString(HALTCORE).GetSV()); - return( true ); + return(true); } -void CModPerl::LoadPerlMod( const CString & sModule ) +void CModPerl::LoadPerlMod(const CString & sModule) { - if ( !m_pUser ) + if (!m_pUser) { - DEBUG_ONLY( cerr << "LoadPerlMod: No User is set!!!" << endl ); + DEBUG_ONLY(cerr << "LoadPerlMod: No User is set!!!" << endl); return; } CString sModPath, sTmp; - if ( !CZNC::Get().FindModPath(sModule, sModPath, sTmp)) - PutStatus( "No such module " + sModule ); + if (!CZNC::Get().FindModPath(sModule, sModPath, sTmp)) + PutStatus("No such module " + sModule); else { - PutStatus( "Using " + sModPath ); - Eval( "ZNC::CORELoadMod( '" + m_pUser->GetUserName() + "', '" + sModPath + "');" ); + PutStatus("Using " + sModPath); + Eval("ZNC::CORELoadMod('" + m_pUser->GetUserName() + "', '" + sModPath + "');"); } } -void CModPerl::DestroyAllSocks( const CString & sModuleName ) +void CModPerl::DestroyAllSocks(const CString & sModuleName) { - for( u_int a = 0; a < m_pManager->size(); a++ ) + for(u_int a = 0; a < m_pManager->size(); a++) { - if ( (*m_pManager)[a]->GetSockName() == ZNCSOCK ) + if ((*m_pManager)[a]->GetSockName() == ZNCSOCK) { - if ( ( sModuleName.empty() ) || ( sModuleName == ((CPerlSock *)(*m_pManager)[a])->GetModuleName() ) ) - m_pManager->DelSock( a-- ); + if ((sModuleName.empty()) || (sModuleName == ((CPerlSock *)(*m_pManager)[a])->GetModuleName())) + m_pManager->DelSock(a--); } } } -void CModPerl::UnloadPerlMod( const CString & sModule ) +void CModPerl::UnloadPerlMod(const CString & sModule) { - DestroyAllSocks( sModule ); - if ( !m_pUser ) + DestroyAllSocks(sModule); + if (!m_pUser) { - DEBUG_ONLY( cerr << "UnloadPerlMod: No User is set!!!" << endl ); + DEBUG_ONLY(cerr << "UnloadPerlMod: No User is set!!!" << endl); return; } - Eval( "ZNC::COREUnloadMod( '" + m_pUser->GetUserName() + "', '" + sModule + "');" ); + Eval("ZNC::COREUnloadMod('" + m_pUser->GetUserName() + "', '" + sModule + "');"); } @@ -1079,141 +1079,141 @@ CModPerl::EModRet CModPerl::OnDCCUserSend(const CNick& RemoteNick, unsigned long const CString& sFile, unsigned long uFileSize) { VPString vsArgs; - vsArgs.push_back( NICK( RemoteNick ) ); - vsArgs.push_back( uLongIP ); - vsArgs.push_back( uPort ); - vsArgs.push_back( sFile ); + vsArgs.push_back(NICK(RemoteNick)); + vsArgs.push_back(uLongIP); + vsArgs.push_back(uPort); + vsArgs.push_back(sFile); - return( CallBack( "OnDCCUserSend", vsArgs ) ); + return(CallBack("OnDCCUserSend", vsArgs)); } void CPerlTimer::RunJob() { - if ( !((CModPerl *)m_pModule)->GetUser( m_sUserName, true ) ) + if (!((CModPerl *)m_pModule)->GetUser(m_sUserName, true)) { Stop(); return; } VPString vArgs; - vArgs.push_back( m_sModuleName ); - if ( ((CModPerl *)m_pModule)->CallBack( m_sFuncName, vArgs, CModPerl::CB_TIMER ) != CModPerl::CONTINUE ) + vArgs.push_back(m_sModuleName); + if (((CModPerl *)m_pModule)->CallBack(m_sFuncName, vArgs, CModPerl::CB_TIMER) != CModPerl::CONTINUE) Stop(); ((CModPerl *)m_pModule)->UnSetUser(); } /////////////////////////// CPerlSock stuff //////////////////// -#define SOCKCB( a ) if ( CallBack( a ) != CModPerl::CONTINUE ) { Close(); } -int CPerlSock::CallBack( const PString & sFuncName ) +#define SOCKCB(a) if (CallBack(a) != CModPerl::CONTINUE) { Close(); } +int CPerlSock::CallBack(const PString & sFuncName) { - if ( !g_ModPerl->GetUser( m_sUsername, true ) ) + if (!g_ModPerl->GetUser(m_sUsername, true)) { Close(); - return( CModPerl::HALT ); + return(CModPerl::HALT); } - int i = g_ModPerl->CallBack( sFuncName, m_vArgs, CModPerl::CB_SOCK, m_sUsername ); + int i = g_ModPerl->CallBack(sFuncName, m_vArgs, CModPerl::CB_SOCK, m_sUsername); g_ModPerl->UnSetUser(); - return( i ); + return(i); } -// # OnConnect( $sockhandle, $parentsockhandle ) +// # OnConnect($sockhandle, $parentsockhandle) void CPerlSock::Connected() { - if ( GetType() == INBOUND ) + if (GetType() == INBOUND) { m_vArgs.clear(); - m_vArgs.push_back( m_sModuleName ); - m_vArgs.push_back( m_iParentFD ); - m_vArgs.push_back( GetRSock() ); - SOCKCB( "OnNewSock" ); + m_vArgs.push_back(m_sModuleName); + m_vArgs.push_back(m_iParentFD); + m_vArgs.push_back(GetRSock()); + SOCKCB("OnNewSock"); } SetupArgs(); - if ( GetType() == INBOUND ) - AddArg( m_iParentFD ); + if (GetType() == INBOUND) + AddArg(m_iParentFD); - SOCKCB( "OnConnect" ) + SOCKCB("OnConnect") } -// # OnConnectionFrom( $sockhandle, $remotehost, $remoteport ) -bool CPerlSock::ConnectionFrom( const CS_STRING & sHost, u_short iPort ) +// # OnConnectionFrom($sockhandle, $remotehost, $remoteport) +bool CPerlSock::ConnectionFrom(const CS_STRING & sHost, u_short iPort) { SetupArgs(); - AddArg( sHost ); - AddArg( iPort ); + AddArg(sHost); + AddArg(iPort); // special case here - if ( CallBack( "OnConnectionFrom" ) != CModPerl::CONTINUE ) - return( false ); + if (CallBack("OnConnectionFrom") != CModPerl::CONTINUE) + return(false); - return( true ); + return(true); } -// # OnError( $sockhandle, $errno ) -void CPerlSock::SockError( int iErrno ) +// # OnError($sockhandle, $errno) +void CPerlSock::SockError(int iErrno) { SetupArgs(); - AddArg( iErrno ); - SOCKCB( "OnError" ) + AddArg(iErrno); + SOCKCB("OnError") } -// # OnConnectionRefused( $sockhandle ) +// # OnConnectionRefused($sockhandle) void CPerlSock::ConnectionRefused() { SetupArgs(); - SOCKCB( "OnConnectionRefused" ) + SOCKCB("OnConnectionRefused") } -// # OnTimeout( $sockhandle ) +// # OnTimeout($sockhandle) void CPerlSock::Timeout() { SetupArgs(); - SOCKCB( "OnTimeout" ) + SOCKCB("OnTimeout") } -// # OnDisconnect( $sockhandle ) +// # OnDisconnect($sockhandle) void CPerlSock::Disconnected() { SetupArgs(); - SOCKCB( "OnDisconnect" ); + SOCKCB("OnDisconnect"); } -// # OnData( $sockhandle, $bytes, $length ) -void CPerlSock::ReadData( const char *data, int len ) +// # OnData($sockhandle, $bytes, $length) +void CPerlSock::ReadData(const char *data, int len) { SetupArgs(); PString sData; - sData.append( data, len ); - AddArg( sData ); - AddArg( len ); - SOCKCB( "OnData" ) + sData.append(data, len); + AddArg(sData); + AddArg(len); + SOCKCB("OnData") } -// # OnReadLine( $sockhandle, $line ) -void CPerlSock::ReadLine( const CS_STRING & sLine ) +// # OnReadLine($sockhandle, $line) +void CPerlSock::ReadLine(const CS_STRING & sLine) { SetupArgs(); - AddArg( sLine ); - SOCKCB( "OnReadLine" ); + AddArg(sLine); + SOCKCB("OnReadLine"); } -// # OnSockDestroy( $sockhandle ) +// # OnSockDestroy($sockhandle) CPerlSock::~CPerlSock() { SetupArgs(); - CallBack( "OnSockDestroy" ); + CallBack("OnSockDestroy"); } -Csock *CPerlSock::GetSockObj( const CS_STRING & sHostname, u_short iPort ) +Csock *CPerlSock::GetSockObj(const CS_STRING & sHostname, u_short iPort) { - CPerlSock *p = new CPerlSock( sHostname, iPort ); - p->SetParentFD( GetRSock() ); - p->SetUsername( m_sUsername ); - p->SetModuleName( m_sModuleName ); - p->SetSockName( ZNCSOCK ); - if ( HasReadLine() ) + CPerlSock *p = new CPerlSock(sHostname, iPort); + p->SetParentFD(GetRSock()); + p->SetUsername(m_sUsername); + p->SetModuleName(m_sModuleName); + p->SetSockName(ZNCSOCK); + if (HasReadLine()) p->EnableReadLine(); - return( p ); + return(p); } #endif /* HAVE_PERL */ diff --git a/modules/nickserv.cpp b/modules/nickserv.cpp index 73b5eab7..5e4ca3c4 100644 --- a/modules/nickserv.cpp +++ b/modules/nickserv.cpp @@ -29,7 +29,7 @@ public: return true; } - virtual void OnModCommand( const CString& sCommand ) + virtual void OnModCommand(const CString& sCommand) { CString sCmdName = sCommand.Token(0).AsLower(); if(sCmdName == "set") { diff --git a/modules/perform.cpp b/modules/perform.cpp index 6680cd72..25f4f9f4 100644 --- a/modules/perform.cpp +++ b/modules/perform.cpp @@ -26,7 +26,7 @@ public: return true; } - virtual void OnModCommand( const CString& sCommand ) + virtual void OnModCommand(const CString& sCommand) { CString sCmdName = sCommand.Token(0).AsLower(); if(sCmdName == "add") @@ -50,16 +50,16 @@ public: Save(); } else if(sCmdName == "del") { - u_int iNum = atoi( sCommand.Token(1, true).c_str() ); - if ( iNum > m_vPerform.size() || iNum <= 0 ) + u_int iNum = atoi(sCommand.Token(1, true).c_str()); + if (iNum > m_vPerform.size() || iNum <= 0) { - PutModule( "Illegal # Requested"); + PutModule("Illegal # Requested"); return; } else { - m_vPerform.erase( m_vPerform.begin() + iNum - 1 ); - PutModule( "Command Erased."); + m_vPerform.erase(m_vPerform.begin() + iNum - 1); + PutModule("Command Erased."); } Save(); } else if(sCmdName == "list") @@ -68,25 +68,25 @@ public: CString sExpanded; for(VCString::iterator it = m_vPerform.begin(); it != m_vPerform.end(); it++, i++) { - sExpanded = GetUser()->ExpandString( *it ); + sExpanded = GetUser()->ExpandString(*it); if(sExpanded != *it) - PutModule(CString( i ) + ": " + *it + " (" + sExpanded + ")"); + PutModule(CString(i) + ": " + *it + " (" + sExpanded + ")"); else - PutModule(CString( i ) + ": " + *it); + PutModule(CString(i) + ": " + *it); } PutModule(" -- End of List"); }else { - PutModule( "Commands: add , del , list"); + PutModule("Commands: add , del , list"); } } virtual void OnIRCConnected() { - for( VCString::iterator it = m_vPerform.begin(); + for(VCString::iterator it = m_vPerform.begin(); it != m_vPerform.end(); it++) { - PutIRC( GetUser()->ExpandString( *it ) ); + PutIRC(GetUser()->ExpandString(*it)); } } diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index 07b125d3..dd96fa44 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -30,8 +30,8 @@ class CSaveBuff; class CSaveBuffJob : public CTimer { public: - CSaveBuffJob( CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription ) - : CTimer( pModule, uInterval, uCycles, sLabel, sDescription) {} + CSaveBuffJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) + : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {} virtual ~CSaveBuffJob() {} @@ -45,12 +45,12 @@ public: MODCONSTRUCTOR(CSaveBuff) { m_bBootError = false; - // m_sPassword = CBlowfish::MD5( "" ); - AddTimer( new CSaveBuffJob( this, 60, 0, "SaveBuff", "Saves the current buffer to disk every 1 minute" ) ); + // m_sPassword = CBlowfish::MD5(""); + AddTimer(new CSaveBuffJob(this, 60, 0, "SaveBuff", "Saves the current buffer to disk every 1 minute")); } virtual ~CSaveBuff() { - if ( !m_bBootError ) + if (!m_bBootError) { SaveBufferToDisk(); } @@ -60,8 +60,8 @@ public: { if (!sArgs.empty()) { - m_sPassword = CBlowfish::MD5( sArgs ); - return( OnBoot() ); + m_sPassword = CBlowfish::MD5(sArgs); + return(OnBoot()); } return true; @@ -69,250 +69,250 @@ public: virtual bool OnBoot() { - if ( m_sPassword.empty() ) + if (m_sPassword.empty()) { - char *pTmp = CUtils::GetPass( "Enter Encryption Key for " + GetModName() + ".so" ); + char *pTmp = CUtils::GetPass("Enter Encryption Key for " + GetModName() + ".so"); - if ( pTmp ) - m_sPassword = CBlowfish::MD5( pTmp ); + if (pTmp) + m_sPassword = CBlowfish::MD5(pTmp); *pTmp = 0; } const vector& vChans = m_pUser->GetChans(); - for( u_int a = 0; a < vChans.size(); a++ ) + for(u_int a = 0; a < vChans.size(); a++) { - if ( !vChans[a]->KeepBuffer() ) + if (!vChans[a]->KeepBuffer()) continue; - if ( !BootStrap( vChans[a] ) ) + if (!BootStrap(vChans[a])) { m_bBootError = true; - return( false ); + return(false); } } return true; } - bool BootStrap( CChan *pChan ) + bool BootStrap(CChan *pChan) { CString sFile; - if ( DecryptChannel( pChan->GetName(), sFile ) ) + if (DecryptChannel(pChan->GetName(), sFile)) { - if ( !pChan->GetBuffer().empty() ) - return( true ); // reloaded a module probably in this case, so just verify we can decrypt the file + if (!pChan->GetBuffer().empty()) + return(true); // reloaded a module probably in this case, so just verify we can decrypt the file CString sLine; CString::size_type iPos = 0; - while( ReadLine( sFile, sLine, iPos ) ) + while(ReadLine(sFile, sLine, iPos)) { sLine.Trim(); - pChan->AddBuffer( sLine ); + pChan->AddBuffer(sLine); } } else { m_sPassword = ""; CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt [" + pChan->GetName() + "]"); - return( false ); + return(false); } - return( true ); + return(true); } void SaveBufferToDisk() { - if ( !m_sPassword.empty() ) + if (!m_sPassword.empty()) { const vector& vChans = m_pUser->GetChans(); - for( u_int a = 0; a < vChans.size(); a++ ) + for(u_int a = 0; a < vChans.size(); a++) { - if ( !vChans[a]->KeepBuffer() ) + if (!vChans[a]->KeepBuffer()) continue; const vector & vBuffer = vChans[a]->GetBuffer(); - if ( vBuffer.empty() ) + if (vBuffer.empty()) { - if ( !m_sPassword.empty() ) - BootStrap( vChans[a] ); + if (!m_sPassword.empty()) + BootStrap(vChans[a]); continue; } CString sFile = CRYPT_VERIFICATION_TOKEN; - for( u_int b = 0; b < vBuffer.size(); b++ ) + for(u_int b = 0; b < vBuffer.size(); b++) sFile += vBuffer[b] + "\n"; - CBlowfish c( m_sPassword, BF_ENCRYPT ); - sFile = c.Crypt( sFile ); - CString sPath = GetPath( vChans[a]->GetName() ); - if ( !sPath.empty() ) + CBlowfish c(m_sPassword, BF_ENCRYPT); + sFile = c.Crypt(sFile); + CString sPath = GetPath(vChans[a]->GetName()); + if (!sPath.empty()) { - WriteFile( sPath, sFile ); - chmod( sPath.c_str(), 0600 ); + WriteFile(sPath, sFile); + chmod(sPath.c_str(), 0600); } } } } - virtual void OnModCommand( const CString& sCommand ) + virtual void OnModCommand(const CString& sCommand) { - CString::size_type iPos = sCommand.find( " " ); + CString::size_type iPos = sCommand.find(" "); CString sCom, sArgs; - if ( iPos == CString::npos ) + if (iPos == CString::npos) sCom = sCommand; else { - sCom = sCommand.substr( 0, iPos ); - sArgs = sCommand.substr( iPos + 1, CString::npos ); + sCom = sCommand.substr(0, iPos); + sArgs = sCommand.substr(iPos + 1, CString::npos); } - if ( strcasecmp( sCom.c_str(), "setpass" ) == 0 ) + if (strcasecmp(sCom.c_str(), "setpass") == 0) { - PutModule( "Password set to [" + sArgs + "]" ); - m_sPassword = CBlowfish::MD5( sArgs ); + PutModule("Password set to [" + sArgs + "]"); + m_sPassword = CBlowfish::MD5(sArgs); - } else if ( strcasecmp( sCom.c_str(), "dumpbuff" ) == 0 ) + } else if (strcasecmp(sCom.c_str(), "dumpbuff") == 0) { CString sFile; - if ( DecryptChannel( sArgs, sFile ) ) + if (DecryptChannel(sArgs, sFile)) { CString sLine; iPos = 0; - while( ReadLine( sFile, sLine, iPos ) ) + while(ReadLine(sFile, sLine, iPos)) { sLine.Trim(); - PutModule( "[" + sLine + "]" ); + PutModule("[" + sLine + "]"); } } - PutModule( "//!-- EOF " + sArgs ); - } else if ( strcasecmp( sCom.c_str(), "replay" ) == 0 ) + PutModule("//!-- EOF " + sArgs); + } else if (strcasecmp(sCom.c_str(), "replay") == 0) { - Replay( sArgs ); - PutModule( "Replayed " + sArgs ); + Replay(sArgs); + PutModule("Replayed " + sArgs); - } else if ( strcasecmp( sCom.c_str(), "save" ) == 0 ) + } else if (strcasecmp(sCom.c_str(), "save") == 0) { SaveBufferToDisk(); - PutModule( "Done." ); + PutModule("Done."); } else - PutModule( "Unknown command [" + sCommand + "]" ); + PutModule("Unknown command [" + sCommand + "]"); } - void Replay( const CString & sChan ) + void Replay(const CString & sChan) { CString sFile; - PutUser( ":***!znc@znc.com PRIVMSG " + sChan + " :Buffer Playback..." ); - if ( DecryptChannel( sChan, sFile ) ) + PutUser(":***!znc@znc.com PRIVMSG " + sChan + " :Buffer Playback..."); + if (DecryptChannel(sChan, sFile)) { CString sLine; CString::size_type iPos = 0; - while( ReadLine( sFile, sLine, iPos ) ) + while(ReadLine(sFile, sLine, iPos)) { sLine.Trim(); - PutUser( sLine ); + PutUser(sLine); } } - PutUser( ":***!znc@znc.com PRIVMSG " + sChan + " :Playback Complete." ); + PutUser(":***!znc@znc.com PRIVMSG " + sChan + " :Playback Complete."); } - CString GetPath( const CString & sChannel ) + CString GetPath(const CString & sChannel) { - CString sBuffer = m_pUser->GetUserName() + Lower( sChannel ); + CString sBuffer = m_pUser->GetUserName() + Lower(sChannel); CString sRet = GetSavePath(); - sRet += "/" + CBlowfish::MD5( sBuffer, true ); - return( sRet ); + sRet += "/" + CBlowfish::MD5(sBuffer, true); + return(sRet); } - CString SpoofChanMsg( const CString & sChannel, const CString & sMesg ) + CString SpoofChanMsg(const CString & sChannel, const CString & sMesg) { - CString sReturn = ":*" + GetModName() + "!znc@znc.com PRIVMSG " + sChannel + " :" + CString( time( NULL ) ) + " " + sMesg; - return( sReturn ); + CString sReturn = ":*" + GetModName() + "!znc@znc.com PRIVMSG " + sChannel + " :" + CString(time(NULL)) + " " + sMesg; + return(sReturn); } virtual void OnRawMode(const CNick& cOpNick, CChan& cChannel, const CString& sModes, const CString& sArgs) { - if ( !cChannel.KeepBuffer() ) + if (!cChannel.KeepBuffer()) return; - ((CChan &)cChannel).AddBuffer( SpoofChanMsg( cChannel.GetName(), cOpNick.GetNickMask() + " MODE " + sModes + " " + sArgs ) ); + ((CChan &)cChannel).AddBuffer(SpoofChanMsg(cChannel.GetName(), cOpNick.GetNickMask() + " MODE " + sModes + " " + sArgs)); } virtual void OnQuit(const CNick& cNick, const CString& sMessage, const vector& vChans) { - for( u_int a = 0; a < vChans.size(); a++ ) + for(u_int a = 0; a < vChans.size(); a++) { - if ( !vChans[a]->KeepBuffer() ) + if (!vChans[a]->KeepBuffer()) continue; - vChans[a]->AddBuffer( SpoofChanMsg( vChans[a]->GetName(), cNick.GetNickMask() + " QUIT " + sMessage ) ); + vChans[a]->AddBuffer(SpoofChanMsg(vChans[a]->GetName(), cNick.GetNickMask() + " QUIT " + sMessage)); } - if ( cNick.GetNick().CaseCmp( m_pUser->GetNick() ) == 0 ) + if (cNick.GetNick().CaseCmp(m_pUser->GetNick()) == 0) SaveBufferToDisk(); // need to force a save here to see this! } virtual void OnNick(const CNick& cNick, const CString& sNewNick, const vector& vChans) { - for( u_int a = 0; a < vChans.size(); a++ ) + for(u_int a = 0; a < vChans.size(); a++) { - if ( !vChans[a]->KeepBuffer() ) + if (!vChans[a]->KeepBuffer()) continue; - vChans[a]->AddBuffer( SpoofChanMsg( vChans[a]->GetName(), cNick.GetNickMask() + " NICK " + sNewNick ) ); + vChans[a]->AddBuffer(SpoofChanMsg(vChans[a]->GetName(), cNick.GetNickMask() + " NICK " + sNewNick)); } } virtual void OnKick(const CNick& cNick, const CString& sOpNick, CChan& cChannel, const CString& sMessage) { - if ( !cChannel.KeepBuffer() ) + if (!cChannel.KeepBuffer()) return; - ((CChan &)cChannel).AddBuffer( SpoofChanMsg( cChannel.GetName(), sOpNick + " KICK " + cNick.GetNickMask() + " " + sMessage ) ); + ((CChan &)cChannel).AddBuffer(SpoofChanMsg(cChannel.GetName(), sOpNick + " KICK " + cNick.GetNickMask() + " " + sMessage)); } virtual void OnJoin(const CNick& cNick, CChan& cChannel) { - if ( ( cNick.GetNick().CaseCmp( m_pUser->GetNick() ) == 0 ) && ( cChannel.GetBuffer().empty() ) ) + if ((cNick.GetNick().CaseCmp(m_pUser->GetNick()) == 0) && (cChannel.GetBuffer().empty())) { - BootStrap( (CChan *)&cChannel ); - if ( !cChannel.GetBuffer().empty() ) - Replay( cChannel.GetName() ); + BootStrap((CChan *)&cChannel); + if (!cChannel.GetBuffer().empty()) + Replay(cChannel.GetName()); } - if ( !cChannel.KeepBuffer() ) + if (!cChannel.KeepBuffer()) return; - ((CChan &)cChannel).AddBuffer( SpoofChanMsg( cChannel.GetName(), cNick.GetNickMask() + " JOIN" ) ); + ((CChan &)cChannel).AddBuffer(SpoofChanMsg(cChannel.GetName(), cNick.GetNickMask() + " JOIN")); } virtual void OnPart(const CNick& cNick, CChan& cChannel) { - if ( !cChannel.KeepBuffer() ) + if (!cChannel.KeepBuffer()) return; - ((CChan &)cChannel).AddBuffer( SpoofChanMsg( cChannel.GetName(), cNick.GetNickMask() + " PART" ) ); - if ( cNick.GetNick().CaseCmp( m_pUser->GetNick() ) == 0 ) + ((CChan &)cChannel).AddBuffer(SpoofChanMsg(cChannel.GetName(), cNick.GetNickMask() + " PART")); + if (cNick.GetNick().CaseCmp(m_pUser->GetNick()) == 0) SaveBufferToDisk(); // need to force a save here to see this! } private: bool m_bBootError; CString m_sPassword; - bool DecryptChannel( const CString & sChan, CString & sBuffer ) + bool DecryptChannel(const CString & sChan, CString & sBuffer) { - CString sChannel = GetPath( sChan ); + CString sChannel = GetPath(sChan); CString sFile; sBuffer = ""; - if ( ( sChannel.empty() ) || ( !ReadFile( sChannel, sFile ) ) ) - return( true ); // gonna be successful here + if ((sChannel.empty()) || (!ReadFile(sChannel, sFile))) + return(true); // gonna be successful here - if ( !sFile.empty() ) + if (!sFile.empty()) { - CBlowfish c( m_sPassword, BF_DECRYPT ); - sBuffer = c.Crypt( sFile ); + CBlowfish c(m_sPassword, BF_DECRYPT); + sBuffer = c.Crypt(sFile); - if ( sBuffer.substr( 0, strlen( CRYPT_VERIFICATION_TOKEN ) ) != CRYPT_VERIFICATION_TOKEN ) + if (sBuffer.substr(0, strlen(CRYPT_VERIFICATION_TOKEN)) != CRYPT_VERIFICATION_TOKEN) { // failed to decode :( - PutModule( "Unable to decode Encrypted file [" + sChannel + "]" ); - return( false ); + PutModule("Unable to decode Encrypted file [" + sChannel + "]"); + return(false); } - sBuffer.erase( 0, strlen( CRYPT_VERIFICATION_TOKEN ) ); + sBuffer.erase(0, strlen(CRYPT_VERIFICATION_TOKEN)); } - return( true ); + return(true); } }; diff --git a/modules/schat.cpp b/modules/schat.cpp index 8eec81d5..e1ce2f32 100644 --- a/modules/schat.cpp +++ b/modules/schat.cpp @@ -23,12 +23,12 @@ class CSChat; class CRemMarkerJob : public CTimer { public: - CRemMarkerJob( CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, - const CString& sDescription ) - : CTimer( pModule, uInterval, uCycles, sLabel, sDescription) {} + CRemMarkerJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, + const CString& sDescription) + : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {} virtual ~CRemMarkerJob() {} - void SetNick( const CString & sNick ) + void SetNick(const CString & sNick) { m_sNick = sNick; } @@ -41,65 +41,65 @@ protected: class CSChatSock : public Csock { public: - CSChatSock( CSChat *pMod ) : Csock() + CSChatSock(CSChat *pMod) : Csock() { m_pModule = pMod; } - CSChatSock( int itimeout = 60 ) : Csock( itimeout ) + CSChatSock(int itimeout = 60) : Csock(itimeout) { m_pModule = NULL; EnableReadLine(); } - CSChatSock( const CS_STRING & sHost, u_short iPort, int iTimeout = 60 ) - : Csock( sHost, iPort, iTimeout ) + CSChatSock(const CS_STRING & sHost, u_short iPort, int iTimeout = 60) + : Csock(sHost, iPort, iTimeout) { m_pModule = NULL; EnableReadLine(); } - virtual Csock *GetSockObj( const CS_STRING & sHostname, u_short iPort ) + virtual Csock *GetSockObj(const CS_STRING & sHostname, u_short iPort) { - CSChatSock *p = new CSChatSock( sHostname, iPort ); - p->SetModule( m_pModule ); - p->SetChatNick( m_sChatNick ); - p->SetSockName( GetSockName() + "::" + m_sChatNick ); - return( p ); + CSChatSock *p = new CSChatSock(sHostname, iPort); + p->SetModule(m_pModule); + p->SetChatNick(m_sChatNick); + p->SetSockName(GetSockName() + "::" + m_sChatNick); + return(p); } - virtual bool ConnectionFrom( const CS_STRING & sHost, u_short iPort ) + virtual bool ConnectionFrom(const CS_STRING & sHost, u_short iPort) { Close(); // close the listener after the first connection - return( true ); + return(true); } virtual void Connected(); virtual void Timeout(); - void SetModule( CSChat *p ) + void SetModule(CSChat *p) { m_pModule = p; } - void SetChatNick( const CString & sNick ) + void SetChatNick(const CString & sNick) { m_sChatNick = sNick; } - const CString & GetChatNick() const { return( m_sChatNick ); } + const CString & GetChatNick() const { return(m_sChatNick); } - virtual void ReadLine( const CS_STRING & sLine ); + virtual void ReadLine(const CS_STRING & sLine); virtual void Disconnected(); - virtual void AddLine( const CString & sLine ) + virtual void AddLine(const CString & sLine) { - m_vBuffer.insert( m_vBuffer.begin(), sLine ); - if ( m_vBuffer.size() > 200 ) + m_vBuffer.insert(m_vBuffer.begin(), sLine); + if (m_vBuffer.size() > 200) m_vBuffer.pop_back(); } virtual void DumpBuffer() { - for( vector::reverse_iterator it = m_vBuffer.rbegin(); it != m_vBuffer.rend(); it++ ) - ReadLine( *it ); + for(vector::reverse_iterator it = m_vBuffer.rbegin(); it != m_vBuffer.rend(); it++) + ReadLine(*it); m_vBuffer.clear(); } @@ -116,11 +116,11 @@ public: MODCONSTRUCTOR(CSChat) {} virtual ~CSChat() { CleanSocks(); } - virtual bool OnLoad( const CString & sArgs, CString & sMessage ) + virtual bool OnLoad(const CString & sArgs, CString & sMessage) { m_sPemFile = sArgs; - if ( m_sPemFile.empty() ) + if (m_sPemFile.empty()) { m_sPemFile = CZNC::Get().GetPemLocation(); } @@ -136,10 +136,10 @@ public: virtual void OnUserAttached() { CString sName = "SCHAT::" + m_pUser->GetUserName(); - for( u_int a = 0; a < m_pManager->size(); a++ ) + for(u_int a = 0; a < m_pManager->size(); a++) { if ((*m_pManager)[a]->GetSockName() != sName.c_str() || - ((*m_pManager)[a]->GetType() == CSChatSock::LISTENER )) + ((*m_pManager)[a]->GetType() == CSChatSock::LISTENER)) continue; CSChatSock *p = (CSChatSock *)(*m_pManager)[a]; @@ -150,230 +150,230 @@ public: void CleanSocks() { CString sName = "SCHAT::" + m_pUser->GetUserName(); - for( u_int a= 0; a < m_pManager->size(); a++ ) + for(u_int a= 0; a < m_pManager->size(); a++) { if ((*m_pManager)[a]->GetSockName() == sName) m_pManager->DelSock(a--); } } - virtual EModRet OnUserRaw( CString & sLine ) + virtual EModRet OnUserRaw(CString & sLine) { - if ( sLine.CaseCmp( "schat ", 6 ) == 0 ) + if (sLine.CaseCmp("schat ", 6) == 0) { - OnModCommand( "chat " + sLine.substr(6) ); - return( HALT ); + OnModCommand("chat " + sLine.substr(6)); + return(HALT); - } else if ( sLine.CaseCmp( "schat" ) == 0 ) + } else if (sLine.CaseCmp("schat") == 0) { - PutModule( "SChat User Area ..." ); - OnModCommand( "help" ); - return( HALT ); + PutModule("SChat User Area ..."); + OnModCommand("help"); + return(HALT); } - return( CONTINUE ); + return(CONTINUE); } - virtual void OnModCommand( const CString& sCommand ) + virtual void OnModCommand(const CString& sCommand) { CString sCom, sArgs; sCom = sCommand.Token(0); sArgs = sCommand.Token(1, true); - if ( (sCom.CaseCmp("chat") == 0 ) && ( !sArgs.empty()) ) { + if ((sCom.CaseCmp("chat") == 0) && (!sArgs.empty())) { CString sSockName = "SCHAT::" + m_pUser->GetUserName(); CString sNick = "(s)" + sArgs; - for( u_int a= 0; a < m_pManager->size(); a++ ) + for(u_int a= 0; a < m_pManager->size(); a++) { - if ( (*m_pManager)[a]->GetSockName() != sSockName ) + if ((*m_pManager)[a]->GetSockName() != sSockName) continue; CSChatSock *pSock = (CSChatSock *)(*m_pManager)[a]; - if ( pSock->GetChatNick().CaseCmp(sNick.c_str()) == 0 ) + if (pSock->GetChatNick().CaseCmp(sNick.c_str()) == 0) { - PutModule( "Already Connected to [" + sArgs + "]" ); + PutModule("Already Connected to [" + sArgs + "]"); return; } } CSChatSock *pSock = new CSChatSock; - pSock->SetCipher( "HIGH" ); - pSock->SetPemLocation( m_sPemFile ); - pSock->SetModule( this ); - pSock->SetChatNick( sNick ); + pSock->SetCipher("HIGH"); + pSock->SetPemLocation(m_sPemFile); + pSock->SetModule(this); + pSock->SetChatNick(sNick); - u_short iPort = m_pManager->ListenRand( sSockName, m_pUser->GetLocalIP(), true, - SOMAXCONN, pSock, 60 ); + u_short iPort = m_pManager->ListenRand(sSockName, m_pUser->GetLocalIP(), true, + SOMAXCONN, pSock, 60); - if ( iPort == 0 ) + if (iPort == 0) { - PutModule( "Failed to start chat!" ); + PutModule("Failed to start chat!"); return; } stringstream s; s << "PRIVMSG " << sArgs << " :\001"; s << "DCC SCHAT chat "; - s << CUtils::GetLongIP( m_pUser->GetLocalIP() ); + s << CUtils::GetLongIP(m_pUser->GetLocalIP()); s << " " << iPort << "\001"; - PutIRC( s.str() ); + PutIRC(s.str()); - } else if ( sCom.CaseCmp( "list" ) == 0 ) + } else if (sCom.CaseCmp("list") == 0) { CString sName = "SCHAT::" + m_pUser->GetUserName(); CTable Table; - Table.AddColumn( "Nick" ); - Table.AddColumn( "Created" ); - Table.AddColumn( "Host" ); - Table.AddColumn( "Port" ); - Table.AddColumn( "Status" ); - Table.AddColumn( "Cipher" ); - for( u_int a= 0; a < m_pManager->size(); a++ ) + Table.AddColumn("Nick"); + Table.AddColumn("Created"); + Table.AddColumn("Host"); + Table.AddColumn("Port"); + Table.AddColumn("Status"); + Table.AddColumn("Cipher"); + for(u_int a= 0; a < m_pManager->size(); a++) { - if ( (*m_pManager)[a]->GetSockName() != sName ) + if ((*m_pManager)[a]->GetSockName() != sName) continue; Table.AddRow(); CSChatSock *pSock = (CSChatSock *)(*m_pManager)[a]; - Table.SetCell( "Nick", pSock->GetChatNick() ); + Table.SetCell("Nick", pSock->GetChatNick()); unsigned long long iStartTime = pSock->GetStartTime(); time_t iTime = iStartTime / 1000; - char *pTime = ctime( &iTime ); - if ( pTime ) + char *pTime = ctime(&iTime); + if (pTime) { CString sTime = pTime; sTime.Trim(); - Table.SetCell( "Created", sTime ); + Table.SetCell("Created", sTime); } - if ( pSock->GetType() != CSChatSock::LISTENER ) + if (pSock->GetType() != CSChatSock::LISTENER) { - Table.SetCell( "Status", "Established" ); - Table.SetCell( "Host", pSock->GetRemoteIP() ); - Table.SetCell( "Port", CString( pSock->GetRemotePort() ) ); + Table.SetCell("Status", "Established"); + Table.SetCell("Host", pSock->GetRemoteIP()); + Table.SetCell("Port", CString(pSock->GetRemotePort())); SSL_SESSION *pSession = pSock->GetSSLSession(); - if ( ( pSession ) && ( pSession->cipher ) && ( pSession->cipher->name ) ) - Table.SetCell( "Cipher", pSession->cipher->name ); + if ((pSession) && (pSession->cipher) && (pSession->cipher->name)) + Table.SetCell("Cipher", pSession->cipher->name); } else { - Table.SetCell( "Status", "Waiting" ); - Table.SetCell( "Port", CString( pSock->GetLocalPort() ) ); + Table.SetCell("Status", "Waiting"); + Table.SetCell("Port", CString(pSock->GetLocalPort())); } } - if ( Table.size() ) + if (Table.size()) { unsigned int uTableIdx = 0; CString sLine; - while ( Table.GetLine( uTableIdx++, sLine ) ) - PutModule( sLine ); + while (Table.GetLine(uTableIdx++, sLine)) + PutModule(sLine); } else - PutModule( "No SDCCs currently in session" ); + PutModule("No SDCCs currently in session"); - } else if ( sCom.CaseCmp( "close" ) == 0 ) + } else if (sCom.CaseCmp("close") == 0) { CString sName = "SCHAT::" + m_pUser->GetUserName(); - for( u_int a = 0; a < m_pManager->size(); a++ ) + for(u_int a = 0; a < m_pManager->size(); a++) { - if ( (*m_pManager)[a]->GetSockName() != sName ) + if ((*m_pManager)[a]->GetSockName() != sName) continue; CSChatSock *pSock = (CSChatSock *)(*m_pManager)[a]; - if ( sArgs.CaseCmp( "(s)", 3 ) != 0 ) + if (sArgs.CaseCmp("(s)", 3) != 0) sArgs = "(s)" + sArgs; - if ( sArgs.CaseCmp(pSock->GetChatNick()) == 0 ) + if (sArgs.CaseCmp(pSock->GetChatNick()) == 0) { pSock->Close(); return; } } - PutModule( "No Such Chat [" + sArgs + "]" ); - } else if ( sCom.CaseCmp( "showsocks" ) == 0 ) + PutModule("No Such Chat [" + sArgs + "]"); + } else if (sCom.CaseCmp("showsocks") == 0) { CTable Table; - Table.AddColumn( "SockName" ); - Table.AddColumn( "Created" ); - Table.AddColumn( "LocalIP:Port" ); - Table.AddColumn( "RemoteIP:Port" ); - Table.AddColumn( "Type" ); - Table.AddColumn( "Cipher" ); - for( u_int a = 0; a < m_pManager->size(); a++ ) + Table.AddColumn("SockName"); + Table.AddColumn("Created"); + Table.AddColumn("LocalIP:Port"); + Table.AddColumn("RemoteIP:Port"); + Table.AddColumn("Type"); + Table.AddColumn("Cipher"); + for(u_int a = 0; a < m_pManager->size(); a++) { Table.AddRow(); Csock *pSock = (*m_pManager)[a]; - Table.SetCell( "SockName", pSock->GetSockName() ); + Table.SetCell("SockName", pSock->GetSockName()); unsigned long long iStartTime = pSock->GetStartTime(); time_t iTime = iStartTime / 1000; - char *pTime = ctime( &iTime ); - if ( pTime ) + char *pTime = ctime(&iTime); + if (pTime) { CString sTime = pTime; sTime.Trim(); - Table.SetCell( "Created", sTime ); + Table.SetCell("Created", sTime); } - if ( pSock->GetType() != Csock::LISTENER ) + if (pSock->GetType() != Csock::LISTENER) { - if ( pSock->GetType() == Csock::OUTBOUND ) - Table.SetCell( "Type", "Outbound" ); + if (pSock->GetType() == Csock::OUTBOUND) + Table.SetCell("Type", "Outbound"); else - Table.SetCell( "Type", "Inbound" ); - Table.SetCell( "LocalIP:Port", pSock->GetLocalIP() + ":" + - CString( pSock->GetLocalPort() ) ); - Table.SetCell( "RemoteIP:Port", pSock->GetRemoteIP() + ":" + - CString( pSock->GetRemotePort() ) ); + Table.SetCell("Type", "Inbound"); + Table.SetCell("LocalIP:Port", pSock->GetLocalIP() + ":" + + CString(pSock->GetLocalPort())); + Table.SetCell("RemoteIP:Port", pSock->GetRemoteIP() + ":" + + CString(pSock->GetRemotePort())); SSL_SESSION *pSession = pSock->GetSSLSession(); - if ( ( pSession ) && ( pSession->cipher ) && ( pSession->cipher->name ) ) - Table.SetCell( "Cipher", pSession->cipher->name ); + if ((pSession) && (pSession->cipher) && (pSession->cipher->name)) + Table.SetCell("Cipher", pSession->cipher->name); else - Table.SetCell( "Cipher", "None" ); + Table.SetCell("Cipher", "None"); } else { - Table.SetCell( "Type", "Listener" ); - Table.SetCell( "LocalIP:Port", pSock->GetLocalIP() + - ":" + CString( pSock->GetLocalPort() ) ); - Table.SetCell( "RemoteIP:Port", "0.0.0.0:0" ); + Table.SetCell("Type", "Listener"); + Table.SetCell("LocalIP:Port", pSock->GetLocalIP() + + ":" + CString(pSock->GetLocalPort())); + Table.SetCell("RemoteIP:Port", "0.0.0.0:0"); } } - if ( Table.size() ) + if (Table.size()) { unsigned int uTableIdx = 0; CString sLine; - while ( Table.GetLine( uTableIdx++, sLine ) ) - PutModule( sLine ); + while (Table.GetLine(uTableIdx++, sLine)) + PutModule(sLine); } else - PutModule( "Error Finding Sockets" ); + PutModule("Error Finding Sockets"); - } else if ( sCom.CaseCmp( "help" ) == 0 ) + } else if (sCom.CaseCmp("help") == 0) { - PutModule( "Commands are: " ); - PutModule( " help - This text." ); - PutModule( " chat - Chat a nick." ); - PutModule( " list - List current chats." ); - PutModule( " close - Close a chat to a nick." ); - PutModule( " timers - Shows related timers." ); - PutModule( " showsocks - Shows all socket connections." ); - } else if ( sCom.CaseCmp( "timers" ) == 0 ) + PutModule("Commands are: "); + PutModule(" help - This text."); + PutModule(" chat - Chat a nick."); + PutModule(" list - List current chats."); + PutModule(" close - Close a chat to a nick."); + PutModule(" timers - Shows related timers."); + PutModule(" showsocks - Shows all socket connections."); + } else if (sCom.CaseCmp("timers") == 0) ListTimers(); else - PutModule( "Unknown command [" + sCom + "] [" + sArgs + "]" ); + PutModule("Unknown command [" + sCom + "] [" + sArgs + "]"); } - virtual EModRet OnPrivCTCP( CNick& Nick, CString& sMessage ) + virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage) { - if ( sMessage.CaseCmp("DCC SCHAT ", 10 ) == 0 ) + if (sMessage.CaseCmp("DCC SCHAT ", 10) == 0) { // chat ip port - unsigned long iIP = sMessage.Token( 3 ).ToULong(); - unsigned short iPort = sMessage.Token( 4 ).ToUShort(); + unsigned long iIP = sMessage.Token(3).ToULong(); + unsigned short iPort = sMessage.Token(4).ToUShort(); - if ( ( iIP > 0 ) && ( iPort > 0 ) ) + if ((iIP > 0) && (iPort > 0)) { pair pTmp; CString sMask; @@ -385,76 +385,76 @@ public: m_siiWaitingChats["(s)" + Nick.GetNick()] = pTmp; SendToUser(sMask, "*** Incoming DCC SCHAT, Accept ? (yes/no)"); - CRemMarkerJob *p = new CRemMarkerJob( this, 60, 1, + CRemMarkerJob *p = new CRemMarkerJob(this, 60, 1, "Remove (s)" + Nick.GetNick(), - "Removes this nicks entry for waiting DCC." ); - p->SetNick( "(s)" + Nick.GetNick() ); - AddTimer( p ); - return( HALT ); + "Removes this nicks entry for waiting DCC."); + p->SetNick("(s)" + Nick.GetNick()); + AddTimer(p); + return(HALT); } } - return( CONTINUE ); + return(CONTINUE); } - void AcceptSDCC( const CString & sNick, u_long iIP, u_short iPort ) + void AcceptSDCC(const CString & sNick, u_long iIP, u_short iPort) { - CSChatSock *p = new CSChatSock( CUtils::GetIP( iIP ), iPort, 60 ); - p->SetModule( this ); - p->SetChatNick( sNick ); + CSChatSock *p = new CSChatSock(CUtils::GetIP(iIP), iPort, 60); + p->SetModule(this); + p->SetChatNick(sNick); CString sSockName = "SCHAT::" + m_pUser->GetUserName() + "::" + sNick; - m_pManager->Connect( CUtils::GetIP( iIP ), iPort, sSockName, 60, true, m_pUser->GetLocalIP(), p ); - RemTimer( "Remove " + sNick ); // delete any associated timer to this nick + m_pManager->Connect(CUtils::GetIP(iIP), iPort, sSockName, 60, true, m_pUser->GetLocalIP(), p); + RemTimer("Remove " + sNick); // delete any associated timer to this nick } - virtual EModRet OnUserMsg( CString& sTarget, CString& sMessage ) + virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) { - if ( sTarget.Left(3) == "(s)") + if (sTarget.Left(3) == "(s)") { CString sSockName = "SCHAT::" + m_pUser->GetUserName() + "::" + sTarget; - CSChatSock *p = (CSChatSock *)m_pManager->FindSockByName( sSockName ); - if ( !p ) + CSChatSock *p = (CSChatSock *)m_pManager->FindSockByName(sSockName); + if (!p) { map< CString,pair< u_long,u_short > >::iterator it; - it = m_siiWaitingChats.find( sTarget ); + it = m_siiWaitingChats.find(sTarget); - if ( it != m_siiWaitingChats.end() ) + if (it != m_siiWaitingChats.end()) { - if ( sMessage.CaseCmp( "yes" ) != 0 ) - SendToUser( sTarget + "!" + sTarget + "@" + - CUtils::GetIP( it->second.first ), - "Refusing to accept DCC SCHAT!" ); + if (sMessage.CaseCmp("yes") != 0) + SendToUser(sTarget + "!" + sTarget + "@" + + CUtils::GetIP(it->second.first), + "Refusing to accept DCC SCHAT!"); else - AcceptSDCC( sTarget, it->second.first, it->second.second ); + AcceptSDCC(sTarget, it->second.first, it->second.second); - m_siiWaitingChats.erase( it ); - return( HALT ); + m_siiWaitingChats.erase(it); + return(HALT); } - PutModule( "No such SCHAT to [" + sTarget + "]" ); + PutModule("No such SCHAT to [" + sTarget + "]"); } else - p->Write( sMessage + "\n" ); + p->Write(sMessage + "\n"); - return( HALT ); + return(HALT); } - return( CONTINUE ); + return(CONTINUE); } - virtual void RemoveMarker( const CString & sNick ) + virtual void RemoveMarker(const CString & sNick) { - map< CString,pair< u_long,u_short > >::iterator it = m_siiWaitingChats.find( sNick ); - if ( it != m_siiWaitingChats.end() ) - m_siiWaitingChats.erase( it ); + map< CString,pair< u_long,u_short > >::iterator it = m_siiWaitingChats.find(sNick); + if (it != m_siiWaitingChats.end()) + m_siiWaitingChats.erase(it); } - void SendToUser( const CString & sFrom, const CString & sText ) + void SendToUser(const CString & sFrom, const CString & sText) { //:*schat!znc@znc.com PRIVMSG Jim : CString sSend = ":" + sFrom + " PRIVMSG " + m_pUser->GetCurNick() + " :" + sText; - PutUser( sSend ); + PutUser(sSend); } bool IsAttached() { - return( m_pUser->IsUserAttached() ); + return(m_pUser->IsUserAttached()); } private: @@ -465,54 +465,54 @@ private: //////////////////// methods //////////////// -void CSChatSock::ReadLine( const CS_STRING & sLine ) +void CSChatSock::ReadLine(const CS_STRING & sLine) { - if ( m_pModule ) + if (m_pModule) { CString sText = sLine; - if ( sText[sText.length()-1] == '\n' ) - sText.erase( sText.length()-1, 1 ); + if (sText[sText.length()-1] == '\n') + sText.erase(sText.length()-1, 1); - if ( sText[sText.length()-1] == '\r' ) - sText.erase( sText.length()-1, 1 ); + if (sText[sText.length()-1] == '\r') + sText.erase(sText.length()-1, 1); - if ( m_pModule->IsAttached() ) - m_pModule->SendToUser( m_sChatNick + "!" + m_sChatNick + "@" + GetRemoteIP(), sText ); + if (m_pModule->IsAttached()) + m_pModule->SendToUser(m_sChatNick + "!" + m_sChatNick + "@" + GetRemoteIP(), sText); else - AddLine( sText ); + AddLine(sText); } } void CSChatSock::Disconnected() { - if ( m_pModule ) - m_pModule->SendToUser( m_sChatNick + "!" + m_sChatNick + "@" + GetRemoteIP(), - "*** Disconnected." ); + if (m_pModule) + m_pModule->SendToUser(m_sChatNick + "!" + m_sChatNick + "@" + GetRemoteIP(), + "*** Disconnected."); } void CSChatSock::Connected() { - SetTimeout( 0 ); - if ( m_pModule ) - m_pModule->SendToUser( m_sChatNick + "!" + m_sChatNick + "@" + GetRemoteIP(), "*** Connected." ); + SetTimeout(0); + if (m_pModule) + m_pModule->SendToUser(m_sChatNick + "!" + m_sChatNick + "@" + GetRemoteIP(), "*** Connected."); } void CSChatSock::Timeout() { - if ( m_pModule ) + if (m_pModule) { - if ( GetType() == LISTENER ) - m_pModule->PutModule( "Timeout while waiting for [" + m_sChatNick + "]" ); + if (GetType() == LISTENER) + m_pModule->PutModule("Timeout while waiting for [" + m_sChatNick + "]"); else - m_pModule->SendToUser( m_sChatNick + "!" + m_sChatNick + "@" + GetRemoteIP(), - "*** Connection Timed out." ); + m_pModule->SendToUser(m_sChatNick + "!" + m_sChatNick + "@" + GetRemoteIP(), + "*** Connection Timed out."); } } void CRemMarkerJob::RunJob() { CSChat *p = (CSChat *)m_pModule; - p->RemoveMarker( m_sNick ); + p->RemoveMarker(m_sNick); // store buffer } diff --git a/modules/shell.cpp b/modules/shell.cpp index a7e56948..cf8e7d67 100644 --- a/modules/shell.cpp +++ b/modules/shell.cpp @@ -14,7 +14,7 @@ class CShellMod; class CShellSock : public CExecSock { public: - CShellSock(CShellMod* pShellMod, CClient* pClient, const CString& sExec) : CExecSock( sExec ) { + CShellSock(CShellMod* pShellMod, CClient* pClient, const CString& sExec) : CExecSock(sExec) { EnableReadLine(); m_pParent = pShellMod; m_pClient = pClient; diff --git a/modules/simple_away.cpp b/modules/simple_away.cpp index f9a98df4..09c595e4 100644 --- a/modules/simple_away.cpp +++ b/modules/simple_away.cpp @@ -13,8 +13,8 @@ class CSimpleAway; class CSimpleAwayJob : public CTimer { public: - CSimpleAwayJob( CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription ) - : CTimer( pModule, uInterval, uCycles, sLabel, sDescription) {} + CSimpleAwayJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription) + : CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {} virtual ~CSimpleAwayJob() {} @@ -74,14 +74,14 @@ public: StartTimer(); } - virtual void OnModCommand( const CString& sCommand ) + virtual void OnModCommand(const CString& sCommand) { CString sCmdName = sCommand.Token(0); if (sCmdName == "disabletimer") { m_iAwayWait = 0; - PutModule( "Timer disabled" ); - } else if ( sCmdName == "settimer") { + PutModule("Timer disabled"); + } else if (sCmdName == "settimer") { int iSetting = sCommand.Token(1).ToInt(); m_iAwayWait = iSetting; @@ -91,10 +91,10 @@ public: else PutModule("Timer set to " + CString(iSetting) + " seconds"); - } else if ( sCmdName == "timer") { + } else if (sCmdName == "timer") { PutModule("Current timer setting: " + CString(m_iAwayWait) + " seconds"); - } else if ( sCmdName == "reason") { + } else if (sCmdName == "reason") { CString sReason = sCommand.Token(1, true); if (!sReason.empty()) { diff --git a/modules/stickychan.cpp b/modules/stickychan.cpp index 72d49070..cfbc2e26 100644 --- a/modules/stickychan.cpp +++ b/modules/stickychan.cpp @@ -17,19 +17,19 @@ public: { } - virtual bool OnLoad( const CString& sArgs, CString& sMessage ); + virtual bool OnLoad(const CString& sArgs, CString& sMessage); - virtual EModRet OnUserPart( CString& sChannel, CString& sMessage ) + virtual EModRet OnUserPart(CString& sChannel, CString& sMessage) { - for ( MCString::iterator it = BeginNV(); it != EndNV(); it++ ) + for (MCString::iterator it = BeginNV(); it != EndNV(); it++) { - if ( sChannel.CaseCmp( it->first ) == 0 ) + if (sChannel.CaseCmp(it->first) == 0) { - CChan* pChan = m_pUser->FindChan( sChannel ); + CChan* pChan = m_pUser->FindChan(sChannel); - if ( pChan ) + if (pChan) { - pChan->JoinUser( true, "", m_pClient ); + pChan->JoinUser(true, "", m_pClient); return HALT; } } @@ -38,54 +38,54 @@ public: return CONTINUE; } - virtual void OnModCommand( const CString& sCommand ) + virtual void OnModCommand(const CString& sCommand) { CString sCmdName = sCommand.Token(0); CString sChannel = sCommand.Token(1); sChannel.MakeLower(); - if ( ( sCmdName == "stick" ) && ( !sChannel.empty() ) ) + if ((sCmdName == "stick") && (!sChannel.empty())) { - SetNV( sChannel, sCommand.Token(2) ); - PutModule( "Stuck " + sChannel ); + SetNV(sChannel, sCommand.Token(2)); + PutModule("Stuck " + sChannel); } - else if ( ( sCmdName == "unstick" ) && ( !sChannel.empty() ) ) + else if ((sCmdName == "unstick") && (!sChannel.empty())) { - MCString::iterator it = FindNV( sChannel ); - if ( it != EndNV() ) - DelNV( it ); + MCString::iterator it = FindNV(sChannel); + if (it != EndNV()) + DelNV(it); - PutModule( "UnStuck " + sChannel ); + PutModule("UnStuck " + sChannel); } - else if ( ( sCmdName == "list" ) && ( sChannel.empty() ) ) + else if ((sCmdName == "list") && (sChannel.empty())) { int i = 1; - for( MCString::iterator it = BeginNV(); it != EndNV(); it++, i++ ) + for(MCString::iterator it = BeginNV(); it != EndNV(); it++, i++) { if (it->second.empty()) - PutModule(CString( i ) + ": " + it->first); + PutModule(CString(i) + ": " + it->first); else - PutModule(CString( i ) + ": " + it->first + " (" + it->second + ")"); + PutModule(CString(i) + ": " + it->first + " (" + it->second + ")"); } PutModule(" -- End of List"); } else { - PutModule( "USAGE: [un]stick #channel [key], list" ); + PutModule("USAGE: [un]stick #channel [key], list"); } } virtual void RunJob() { - for( MCString::iterator it = BeginNV(); it != EndNV(); it++ ) + for(MCString::iterator it = BeginNV(); it != EndNV(); it++) { - if ( !m_pUser->FindChan( it->first ) ) + if (!m_pUser->FindChan(it->first)) { - CChan *pChan = new CChan( it->first, m_pUser, true ); - if ( !it->second.empty() ) - pChan->SetKey( it->second ); - m_pUser->AddChan( pChan ); - PutModule( "Joining [" + it->first + "]" ); - PutIRC( "JOIN " + it->first + ( it->second.empty() ? "" : it->second ) ); + CChan *pChan = new CChan(it->first, m_pUser, true); + if (!it->second.empty()) + pChan->SetKey(it->second); + m_pUser->AddChan(pChan); + PutModule("Joining [" + it->first + "]"); + PutIRC("JOIN " + it->first + (it->second.empty() ? "" : it->second)); } } } @@ -94,15 +94,15 @@ private: }; -static void RunTimer( CModule * pModule, CFPTimer *pTimer ) +static void RunTimer(CModule * pModule, CFPTimer *pTimer) { ((CStickyChan *)pModule)->RunJob(); } bool CStickyChan::OnLoad(const CString& sArgs, CString& sMessage) { - AddTimer( RunTimer, "StickyChanTimer", 15 ); - return( true ); + AddTimer(RunTimer, "StickyChanTimer", 15); + return(true); } MODULEDEFS(CStickyChan, "configless sticky chans, keeps you there very stickily even") diff --git a/znc.cpp b/znc.cpp index 89dea85b..9307f66e 100644 --- a/znc.cpp +++ b/znc.cpp @@ -320,7 +320,7 @@ bool CZNC::DeletePidFile() { return false; } -bool CZNC::WritePemFile( bool bEncPem ) { +bool CZNC::WritePemFile(bool bEncPem) { #ifndef HAVE_LIBSSL CUtils::PrintError("ZNC was not compiled with ssl support."); return false; @@ -1403,14 +1403,14 @@ bool CZNC::DoRehash(CString& sError) } - if( sName.CaseCmp( "GM:", 3 ) == 0 ) + if (sName.CaseCmp("GM:", 3) == 0) { // GM: prefix is a pass through to config lines for global modules CGlobalModuleConfigLine cTmp; - cTmp.m_sName = sName.substr( 3, CString::npos ); + cTmp.m_sName = sName.substr(3, CString::npos); cTmp.m_sValue = sValue; cTmp.m_pChan = pChan; cTmp.m_pUser = pUser; - lGlobalModuleConfigLine.push_back( cTmp ); + lGlobalModuleConfigLine.push_back(cTmp); } else { @@ -1492,13 +1492,13 @@ bool CZNC::DoRehash(CString& sError) } // last step, throw unhandled config items at global config - for( std::list::iterator it = lGlobalModuleConfigLine.begin(); it != lGlobalModuleConfigLine.end(); it++ ) + for (std::list::iterator it = lGlobalModuleConfigLine.begin(); it != lGlobalModuleConfigLine.end(); it++) { - if( ( pChan && pChan == it->m_pChan ) || ( pUser && pUser == it->m_pUser ) ) + if ((pChan && pChan == it->m_pChan) || (pUser && pUser == it->m_pUser)) continue; // skip unclosed user or chan - if( !GetModules().OnConfigLine( it->m_sName, it->m_sValue, it->m_pUser, it->m_pChan ) ) + if (!GetModules().OnConfigLine(it->m_sName, it->m_sValue, it->m_pUser, it->m_pChan)) { - CUtils::PrintMessage( "unhandled global module config line [GM:" + it->m_sName + "] = [" + it->m_sValue + "]" ); + CUtils::PrintMessage("unhandled global module config line [GM:" + it->m_sName + "] = [" + it->m_sValue + "]"); } } #endif diff --git a/znc.h b/znc.h index 9ca3a6ed..8f4f86a1 100644 --- a/znc.h +++ b/znc.h @@ -69,7 +69,7 @@ public: } virtual u_short ListenAllRand(const CString& sSockName, int isSSL = false, int iMaxConns = SOMAXCONN, Csock *pcSock = NULL, u_int iTimeout = 0, bool bIsIPv6 = false) { - return( ListenRand( sSockName, "", isSSL, iMaxConns, pcSock, iTimeout, bIsIPv6 ) ); + return(ListenRand(sSockName, "", isSSL, iMaxConns, pcSock, iTimeout, bIsIPv6)); } virtual bool Connect(const CString& sHostname, u_short iPort , const CString& sSockName, int iTimeout = 60, bool isSSL = false, const CString& sBindHost = "", Csock *pcSock = NULL) { @@ -145,7 +145,7 @@ public: const CString& GetUserPath() const { if (!CFile::Exists(m_sUserPath)) { CUtils::MakeDir(m_sUserPath); } return m_sUserPath; } CString GetPemLocation() const { return GetZNCPath() + "/znc.pem"; } const CString& GetConfigFile() const { return m_sConfigFile; } - bool WritePemFile( bool bEncPem = false ); + bool WritePemFile(bool bEncPem = false); const CString& GetISpoofFile() const { return m_sISpoofFile; } const CString& GetISpoofFormat() const { return m_sISpoofFormat; } const VCString& GetVHosts() const { return m_vsVHosts; } @@ -157,7 +157,7 @@ public: CUser* FindUser(const CString& sUsername); bool DeleteUser(const CString& sUsername); bool AddUser(CUser* pUser, CString& sErrorRet); - const map & GetUserMap() const { return( m_msUsers ); } + const map & GetUserMap() const { return(m_msUsers); } // Message of the Day void SetMotd(const CString& sMessage) { ClearMotd(); AddMotd(sMessage); }