Changeset bf6e9b4 in nscp for modules/CheckEventLog


Ignore:
Timestamp:
02/02/08 13:54:12 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
52215d7
Parents:
5ac88c0a
Message:

2008-02-02 MickeM

  • Might have fixed the "missing eventlog messages" problem.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/CheckEventLog/CheckEventLog.cpp

    r5ac88c0a rbf6e9b4  
    2828#include <utils.h> 
    2929#include <error.hpp> 
     30#include <map> 
    3031 
    3132CheckEventLog gCheckEventLog; 
     
    5657  return false; 
    5758} 
    58  
    5959 
    6060 
     
    225225      p += len+1; 
    226226    } 
    227     std::wstring ret = error::format::message::from_module(get_dll(), eventID(), dwArgs); 
     227 
     228/* 
     229    TCHAR **_sz = (TCHAR**)GlobalAlloc(GPTR, (pevlr_->NumStrings)*sizeof(TCHAR *)); 
     230    register UINT z; 
     231    TCHAR* p = reinterpret_cast<TCHAR*>(reinterpret_cast<LPBYTE>(pevlr_) + pevlr_->StringOffset); 
     232    for(unsigned int z = 0; z < pevlr_->NumStrings; z++) { 
     233      DWORD len = wcslen(p); 
     234      _sz[z] = (TCHAR *)GlobalAlloc(GPTR, (len+1) * sizeof(TCHAR)); 
     235      wcscpy_s(_sz[z], len, p); 
     236      p += len+1; 
     237    } 
     238*/ 
     239    std::wstring ret; 
     240    strEx::splitList dlls = strEx::splitEx(get_dll(), _T(";")); 
     241    for (strEx::splitList::const_iterator cit = dlls.begin(); cit != dlls.end(); ++cit) { 
     242      //std::wstring msg = error::format::message::from_module((*cit), eventID(), _sz); 
     243      std::wstring msg = error::format::message::from_module((*cit), eventID(), dwArgs); 
     244      if (msg.empty()) { 
     245        msg = error::format::message::from_module((*cit), pevlr_->EventID, dwArgs); 
     246      } 
     247      strEx::replace(msg, _T("\n"), _T(" ")); 
     248      strEx::replace(msg, _T("\t"), _T(" ")); 
     249      std::string::size_type pos = msg.find_last_not_of(_T("\n\t ")); 
     250      if (pos != std::string::npos) { 
     251        msg = msg.substr(0,pos); 
     252      } 
     253      if (!msg.empty()) { 
     254        if (!ret.empty()) 
     255          ret += _T(", "); 
     256        ret += msg; 
     257      } 
     258    } 
    228259    delete [] dwArgs; 
    229     std::string::size_type pos = ret.find_last_not_of(_T("\n\t\m")); 
    230     if (pos != std::string::npos) { 
    231       ret = ret.substr(0,pos-1); 
    232     } 
    233260    return ret; 
    234261  } 
     
    274301  } 
    275302}; 
     303/* 
     304return (pevlr_->EventID&0xffff); 
     305} 
     306inline DWORD severity() const { 
     307return (pevlr_->EventID>>30); 
     308*/ 
     309class uniq_eventlog_record { 
     310  DWORD ID; 
     311  WORD type; 
     312  WORD category; 
     313public: 
     314  uniq_eventlog_record(EVENTLOGRECORD *pevlr) : ID(pevlr->EventID&0xffff), type(pevlr->EventType), category(pevlr->EventCategory) {} 
     315  bool operator< (const uniq_eventlog_record &other) const {  
     316    return (ID < other.ID) || ((ID==other.ID)&&(type < other.type)) || (ID==other.ID&&type==other.type)&&(category < other.category); 
     317  } 
     318  std::wstring to_string() const { 
     319    return _T("id=") + strEx::itos(ID) + _T("type=") + strEx::itos(type) + _T("category=") + strEx::itos(category); 
     320  } 
     321}; 
     322typedef std::map<uniq_eventlog_record,bool> uniq_eventlog_map; 
    276323 
    277324 
     
    332379  bool bFilterNew = false; 
    333380  bool bShowDescriptions = false; 
     381  bool unique = false; 
    334382  unsigned int truncate = 0; 
    335383  std::wstring syntax; 
     
    338386  const int filter_normal = 3; 
    339387  const int filter_compat = 3; 
    340   NSC_DEBUG_MSG_STD(_T("000") + message) ; 
    341388 
    342389  try { 
     
    344391      MAP_OPTIONS_NUMERIC_ALL(query, _T("")) 
    345392      MAP_OPTIONS_STR2INT(_T("truncate"), truncate) 
     393      MAP_OPTIONS_BOOL_TRUE(_T("unique"), unique) 
    346394      MAP_OPTIONS_BOOL_TRUE(_T("descriptions"), bShowDescriptions) 
    347395      MAP_OPTIONS_PUSH(_T("file"), files) 
     
    402450      return NSCAPI::returnUNKNOWN; 
    403451    } 
     452    uniq_eventlog_map uniq_records; 
    404453 
    405454    //DWORD dwThisRecord; 
     
    464513          match = true; 
    465514        } 
     515        if (match&&unique) { 
     516          uniq_eventlog_record record = pevlr; 
     517          uniq_eventlog_map::const_iterator cit = uniq_records.find(record); 
     518          if (cit != uniq_records.end()) { 
     519            match = false; 
     520          } 
     521          else 
     522            uniq_records[record] = true; 
     523        } 
    466524 
    467525        if (match) { 
Note: See TracChangeset for help on using the changeset viewer.