2008-07-09 Esteban Sanchez <estebans@artica.es>

* pandora_strutils.[cc,h]: Added strUnicodeToAnsi().

        * modules/pandora_module_logevent.cc, pandora_windows_service.[cc,h],
        windows/pandora_wmi.h: Tabs and blankspace style correction.

        * windows/pandora_wmi.cc: Convert result in getEventList() to ANSI,
        which was causing some BADXML errors on server. Tabs and blankspace 
        style correction.

        * bin/PandoraAgent.exe: Updated to last commit.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@946 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
esanchezm 2008-07-09 12:46:22 +00:00
parent 8e9b10cdc2
commit 654405d451
9 changed files with 423 additions and 373 deletions

View File

@ -1,3 +1,16 @@
2008-07-09 Esteban Sanchez <estebans@artica.es>
* pandora_strutils.[cc,h]: Added strUnicodeToAnsi().
* modules/pandora_module_logevent.cc, pandora_windows_service.[cc,h],
windows/pandora_wmi.h: Tabs and blankspace style correction.
* windows/pandora_wmi.cc: Convert result in getEventList() to ANSI,
which was causing some BADXML errors on server. Tabs and blankspace
style correction.
* bin/PandoraAgent.exe: Updated to last commit.
2008-06-11 Esteban Sanchez <estebans@artica.es> 2008-06-11 Esteban Sanchez <estebans@artica.es>
* bin/PandoraAgent.exe: Updated to commit, fixed an error when * bin/PandoraAgent.exe: Updated to commit, fixed an error when

View File

@ -56,6 +56,41 @@ Pandora_Strutils::trim (const string str) {
return result; return result;
} }
/**
* Convert an unicode string to a ANSI string.
*
* @param s String to convert
*
* @return String converted into ANSI code
*/
LPSTR
Pandora_Strutils::strUnicodeToAnsi (LPCWSTR s) {
if (s == NULL)
return NULL;
int cw = lstrlenW (s);
if (cw == 0) {
CHAR *psz = new CHAR[1];
*psz='\0';
return psz;
}
int cc = WideCharToMultiByte (CP_ACP,0, s, cw, NULL, 0, NULL, NULL);
if (cc==0)
return NULL;
CHAR *psz = new CHAR[cc+1];
cc = WideCharToMultiByte (CP_ACP, 0, s, cw, psz, cc, NULL, NULL);
if (cc == 0) {
delete[] psz;
return NULL;
}
psz[cc]='\0';
return psz;
}
/** /**
* Transform an integer variable into a string. * Transform an integer variable into a string.
* *

View File

@ -43,6 +43,8 @@ namespace Pandora_Strutils {
string trim (const string str); string trim (const string str);
LPSTR strUnicodeToAnsi (LPCWSTR s);
string inttostr (const int i); string inttostr (const int i);
string longtostr (const long i); string longtostr (const long i);
string longtohex (const long i); string longtohex (const long i);

View File

@ -52,7 +52,6 @@ Pandora_Windows_Service::Pandora_Windows_Service (const char * svc_name,
const char * svc_display_name, const char * svc_display_name,
const char * svc_description) const char * svc_description)
: Windows_Service (svc_name, svc_display_name, svc_description) { : Windows_Service (svc_name, svc_display_name, svc_description) {
this->setInitFunction ((void (Windows_Service::*) ()) this->setInitFunction ((void (Windows_Service::*) ())
&Pandora_Windows_Service::pandora_init); &Pandora_Windows_Service::pandora_init);
this->setRunFunction ((void (Windows_Service::*) ()) this->setRunFunction ((void (Windows_Service::*) ())

View File

@ -392,7 +392,9 @@ Pandora_Wmi::getEventList (string source, string type, string pattern, int inter
CDhInitialize init; CDhInitialize init;
CDispPtr wmi_svc, quickfixes; CDispPtr wmi_svc, quickfixes;
char *value = NULL; char *value = NULL;
WCHAR *unicode_value;
string event, limit, message, query, timestamp; string event, limit, message, query, timestamp;
char *encode;
limit = getTimestampLimit (interval); limit = getTimestampLimit (interval);
if (limit.empty()) { if (limit.empty()) {
@ -423,9 +425,10 @@ Pandora_Wmi::getEventList (string source, string type, string pattern, int inter
dhFreeString (value); dhFreeString (value);
// Message // Message
dhGetValue (L"%s", &value, quickfix, dhGetValue (L"%S", &unicode_value, quickfix,
L".Message"); L".Message");
message = value; value = Pandora_Strutils::strUnicodeToAnsi (unicode_value);
message = Pandora_Strutils::trim (value);
dhFreeString (value); dhFreeString (value);
// LIKE is not always available, we have to filter ourselves // LIKE is not always available, we have to filter ourselves
@ -438,8 +441,6 @@ Pandora_Wmi::getEventList (string source, string type, string pattern, int inter
} catch (string errstr) { } catch (string errstr) {
pandoraDebug ("Pandora_Wmi::getEventList: error: %s", errstr.c_str ()); pandoraDebug ("Pandora_Wmi::getEventList: error: %s", errstr.c_str ());
} }
return;
} }
/** /**
@ -492,12 +493,15 @@ Pandora_Wmi::getTimestampLimit (int interval) {
return string (limit_str); return string (limit_str);
} }
/* /**
* Converts a date in WMI format to SYSTEMTIME format. * Converts a date in WMI format to SYSTEMTIME format.
*
* @param wmi_date Date in WMI format
* @param system_time Output system time variable
*/ */
void void
Pandora_Wmi::convertWMIDate (string wmi_date, SYSTEMTIME *system_time) { Pandora_Wmi::convertWMIDate (string wmi_date, SYSTEMTIME *system_time)
{
system_time->wYear = atoi (wmi_date.substr (0, 4).c_str()); system_time->wYear = atoi (wmi_date.substr (0, 4).c_str());
system_time->wMonth = atoi (wmi_date.substr (4, 2).c_str()); system_time->wMonth = atoi (wmi_date.substr (4, 2).c_str());
system_time->wDay = atoi (wmi_date.substr (6, 2).c_str()); system_time->wDay = atoi (wmi_date.substr (6, 2).c_str());

View File

@ -50,9 +50,6 @@ namespace Pandora_Wmi {
void getEventList (string source, string type, string pattern, int interval, list<string> &event_list); void getEventList (string source, string type, string pattern, int interval, list<string> &event_list);
string getTimestampLimit (int interval); string getTimestampLimit (int interval);
void convertWMIDate (string wmi_date, SYSTEMTIME *system_time); void convertWMIDate (string wmi_date, SYSTEMTIME *system_time);
}; };
#endif #endif