Changeset 548
- Timestamp:
- 05/04/06 11:44:39 (3 years ago)
- Files:
-
- nepenthes/branches/nepenthes-experimental/modules/log-irc/IrcDialogue.cpp (modified) (5 diffs)
- nepenthes/branches/nepenthes-experimental/modules/log-irc/log-irc.conf.dist (modified) (1 diff)
- nepenthes/branches/nepenthes-experimental/modules/log-irc/log-irc.cpp (modified) (2 diffs)
- nepenthes/branches/nepenthes-experimental/modules/log-irc/log-irc.hpp (modified) (2 diffs)
- nepenthes/branches/nepenthes-experimental/nepenthes-core/include/LogManager.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nepenthes/branches/nepenthes-experimental/modules/log-irc/IrcDialogue.cpp
r547 r548 31 31 #include <ctype.h> 32 32 #include <string> 33 #include <string.h> 33 34 #include <vector> 34 35 … … 262 263 responseMessage += target; 263 264 264 if( string(message) == "!version")265 if(!strcmp(message, "!version")) 265 266 { 266 267 responseMessage += " :nepenthes v" VERSION " compiled on [" __DATE__ " " __TIME__ "] with " MY_COMPILER " " __VERSION__ "\r\n"; 267 268 m_Socket->doRespond((char *) responseMessage.data(), responseMessage.size()); 268 269 } 269 270 } 271 272 273 // TODO: add on-connect cmd to auth at nickserv 270 else if(!strncmp(message, "!pattern ", 9)) 271 { 272 m_LogIrc->setLogPattern(message + 9); 273 274 responseMessage += " :Updated log pattern to \"" + string(message + 9) + "\"\r\n"; 275 m_Socket->doRespond((char *) responseMessage.data(), responseMessage.size()); 276 } 277 else if(!strcmp(message, "!help") && m_NickName == target) 278 { 279 static const char * helpLines[] = 280 { 281 " :nepenthes v" VERSION " log-irc control interface\r\n", 282 " : !version - print detailed version information\r\n", 283 " : !pattern <logtags> - set log pattern for this log-irc instance\r\n", 284 " : !help - display this help message\r\n", 285 " : \r\n", 286 " : <http://nepenthes.mwcollect.org/>\r\n", 287 }; 288 289 for(uint32_t i = 0; i < sizeof(helpLines) / sizeof(char *); ++i) 290 { 291 string responseLine = responseMessage + helpLines[i]; 292 m_Socket->doRespond((char *) responseLine.data(), responseLine.size()); 293 } 294 } 295 } 296 274 297 275 298 void IrcDialogue::loggedOn() 276 299 { 300 m_LogIrc->setDialogue(this); 301 277 302 if(m_LoggedOn) 278 303 return; 279 280 try281 {282 string connectCommand = m_LogIrc->getConnectCommand();304 305 string connectCommand = m_LogIrc->getConnectCommand(); 306 307 if(!connectCommand.empty()) 283 308 m_Socket->doRespond((char *) connectCommand.data(), connectCommand.size()); 284 }285 catch(...)286 { // no connect command was specified287 }288 309 289 310 string joinCommand = "JOIN " + m_LogIrc->getIrcChannel() + " " + m_LogIrc->getIrcChannelPass() + "\r\n"; … … 334 355 335 356 336 // TODO: format, translate337 338 357 struct FlagMapping 339 358 { 340 int32_t m_LogFlag;359 int32_t m_LogFlag; 341 360 char *m_ColorFlag; 342 361 }; … … 346 365 { 347 366 l_crit, 348 "\x03\x34" // helles rot367 "\x03\x34" // light red 349 368 }, 350 369 { 351 370 l_warn, 352 "\x03\x36" // lila371 "\x03\x36" // purple 353 372 }, 354 373 { 355 374 l_debug, 356 "\x03\x31\x33" // pink375 "\x03\x31\x33" // pink 357 376 }, 358 377 { 359 378 l_info, 360 "\x03\x39" // helles gruen379 "\x03\x39" // light green 361 380 }, 362 {381 { 363 382 l_spam, 364 "\x03\x31\x34" // d unkel grau365 } 383 "\x03\x31\x34" // dark grey 384 }, 366 385 }; 367 386 368 387 369 // TODO: parse log tags from configuration 370 388 // oxff: made dynamic log tag pattern 371 389 void IrcDialogue::logIrc(uint32_t mask, const char *message) 372 390 { 373 if ( 374 ((mask & l_dl || mask & l_sub) && mask & l_mgr && !(mask & l_spam) ) || 375 (mask & l_warn || mask & l_crit) 376 ) 391 if(m_LogIrc->logMaskMatches(mask)) 377 392 { 378 393 if (strlen(message) > 450) 379 394 return; 380 string line ="PRIVMSG "; 381 line += m_LogIrc->getIrcChannel(); 382 line += " :"; 383 395 396 string line ="PRIVMSG " + m_LogIrc->getIrcChannel() + " :"; 384 397 uint32_t i=0; 385 398 386 for (i=0; i<sizeof(colors)/sizeof(struct FlagMapping);i++)387 { 388 if (mask & colors[i].m_LogFlag)399 for (i=0; i < sizeof(colors) / sizeof(struct FlagMapping); ++i) 400 { 401 if(mask & colors[i].m_LogFlag) 389 402 { 390 403 line += colors[i].m_ColorFlag; 404 break; 391 405 } 392 406 } … … 394 408 line += message; 395 409 396 m_Socket->doRespond((char *) line.c_str(), line.size());410 m_Socket->doRespond((char *) line.data(), line.size()); 397 411 } 398 412 } nepenthes/branches/nepenthes-experimental/modules/log-irc/log-irc.conf.dist
r547 r548 33 33 // has to be one IRC command NOT terminated with \r\n 34 34 // connect-command = "PRIVMSG NickServ :IDENTIFY mypassword"; 35 36 // set the initial log tag pattern, like on cmdline; defaults sane 37 // pattern = "crit,warn,down"; 35 38 }; 36 39 }; nepenthes/branches/nepenthes-experimental/modules/log-irc/log-irc.cpp
r547 r548 140 140 m_IrcChannelPass= m_Config->getValString("log-irc.irc.channel.pass"); 141 141 142 } catch ( ... ) 142 } 143 catch ( ... ) 143 144 { 144 145 logCrit("Error setting needed vars, check your config\n"); 145 146 return false; 146 147 } 148 149 try 150 { 151 setLogPattern(m_Config->getValString("log-irc.tag-pattern")); 152 } 153 catch (...) 154 { 155 m_LogPatternNumeric = 0; 156 } 157 158 try 159 { 160 m_ConnectCommand = string(m_Config->getValString("log-irc.irc.connect-command")) + "\r\n"; 161 } 162 catch (...) 163 { 164 } 165 147 166 m_State = LIRC_NULL; 148 167 doStart(); … … 287 306 { 288 307 if (m_IrcDialogue != NULL) 289 {290 308 m_IrcDialogue->logIrc(mask, message); 309 } 310 311 string LogIrc::getTorServer() 312 { 313 return m_TorServer; 314 } 315 316 string LogIrc::getIrcServer() 317 { 318 return m_IrcServer; 319 } 320 321 uint32_t LogIrc::getIrcIP() 322 { 323 return m_IrcIP; 324 } 325 326 uint16_t LogIrc::getIrcPort() 327 { 328 return m_IrcPort; 329 } 330 331 string LogIrc::getIrcPass() 332 { 333 return m_IrcPass; 334 } 335 336 string LogIrc::getIrcNick() 337 { 338 return m_IrcNick; 339 } 340 341 string LogIrc::getIrcIdent() 342 { 343 return m_IrcIdent; 344 } 345 346 string LogIrc::getIrcUserInfo() 347 { 348 return m_IrcUserInfo; 349 } 350 351 string LogIrc::getIrcChannel() 352 { 353 return m_IrcChannel; 354 } 355 356 string LogIrc::getIrcChannelPass() 357 { 358 return m_IrcChannelPass; 359 } 360 361 string LogIrc::getIrcUserModes() 362 { 363 return m_IrcUserModes; 364 } 365 366 string LogIrc::getConnectCommand() 367 { 368 return m_ConnectCommand; 369 } 370 371 372 bool LogIrc::logMaskMatches(uint32_t mask) 373 { 374 if(!m_LogPatternNumeric) 375 { 376 // copied from common's original code 377 return ((mask & l_dl || mask & l_sub) && mask & l_mgr && !(mask & l_spam)) || (mask & l_warn || mask & l_crit); 291 378 } 292 } 293 294 string LogIrc::getTorServer() 295 { 296 return m_TorServer; 297 } 298 299 string LogIrc::getIrcServer() 300 { 301 return m_IrcServer; 302 } 303 304 uint32_t LogIrc::getIrcIP() 305 { 306 return m_IrcIP; 307 } 308 309 uint16_t LogIrc::getIrcPort() 310 { 311 return m_IrcPort; 312 } 313 314 string LogIrc::getIrcPass() 315 { 316 return m_IrcPass; 317 } 318 319 string LogIrc::getIrcNick() 320 { 321 return m_IrcNick; 322 } 323 324 string LogIrc::getIrcIdent() 325 { 326 return m_IrcIdent; 327 } 328 329 string LogIrc::getIrcUserInfo() 330 { 331 return m_IrcUserInfo; 332 } 333 334 string LogIrc::getIrcChannel() 335 { 336 return m_IrcChannel; 337 } 338 339 string LogIrc::getIrcChannelPass() 340 { 341 return m_IrcChannelPass; 342 } 343 344 string LogIrc::getIrcUserModes() 345 { 346 return m_IrcUserModes; 347 } 348 349 string LogIrc::getConnectCommand() 350 { 351 string connectCommand = m_Config->getValString("log-irc.irc.connect-command"); 352 353 if(connectCommand.empty()) 354 throw (void *) 0; 355 356 return connectCommand + "\r\n"; 357 } 358 379 else 380 { 381 return (mask & m_LogPatternNumeric); 382 } 383 } 384 385 void LogIrc::setLogPattern(const char * patternString) 386 { 387 // this code just plain sucks, does not detect wrong pattern names... 388 m_LogPatternNumeric = g_Nepenthes->getLogMgr()->parseTagString(patternString); 389 } 359 390 360 391 void LogIrc::setDialogue(IrcDialogue *dia) nepenthes/branches/nepenthes-experimental/modules/log-irc/log-irc.hpp
r547 r548 89 89 string getIrcServer(); 90 90 91 //! throws exception if no command was specified92 91 string getConnectCommand(); 93 92 94 93 95 94 void setDialogue(IrcDialogue *); 95 96 bool logMaskMatches(uint32_t mask); 97 void setLogPattern(const char * patternString); 96 98 97 99 bool useTor(); 98 99 protected: 100 100 101 private: 101 102 log_irc_state m_State; 102 103 … … 123 124 string m_IrcChannel; 124 125 string m_IrcChannelPass; 126 127 uint32_t m_LogPatternNumeric; 128 129 string m_ConnectCommand; 125 130 126 131 IrcDialogue *m_IrcDialogue; nepenthes/branches/nepenthes-experimental/nepenthes-core/include/LogManager.hpp
r375 r548 60 60 const char *getTagName(uint32_t bit); 61 61 uint32_t getTagId(const char *tag); 62 uint32_t parseTagString(const char *tagString);62 virtual uint32_t parseTagString(const char *tagString); 63 63 void setColor(bool setting); 64 64 bool getColorSetting();
