diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index da30b06a7e..9c7b848b72 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,15 @@ +2006-11-24 Esteban Sánchez + + * pandora_strutils.h, pandora_strutils.cc: Added strtoulong() to + convert a string into a unsigned long integer. + + * wmi/pandora_wmi.h, pandora_wmi.cc: Modified getDisgkFreeSpace() to + return a unsigned long integer. Used srttoulong() to transform the + free disk into a log instead of an integer, that caused a negative + value of free disk space when the amount was in the order of GB. + + * bin/PandoraAgent.exe: Updated to new commit. + 2006-11-21 Esteban Sánchez * pandora_windows_service.cc: Changed the debug option of the diff --git a/pandora_agents/win32/bin/PandoraAgent.exe b/pandora_agents/win32/bin/PandoraAgent.exe index d0399fcf47..0fcd885fcb 100755 Binary files a/pandora_agents/win32/bin/PandoraAgent.exe and b/pandora_agents/win32/bin/PandoraAgent.exe differ diff --git a/pandora_agents/win32/pandora_strutils.cc b/pandora_agents/win32/pandora_strutils.cc index b401de9280..95a2c585b0 100644 --- a/pandora_agents/win32/pandora_strutils.cc +++ b/pandora_agents/win32/pandora_strutils.cc @@ -119,6 +119,28 @@ Pandora_Strutils::strtoint (const string str) { return result; } +/** + * Tranform a string into a long integer. + * + * @param str String to convert. + * + * @return The long integer value of the string. + * + * @exception Invalid_Conversion throwed if the string has non- + * decimal values. + */ +unsigned long +Pandora_Strutils::strtoulong (const string str) { + unsigned long result; + + if (! std::sscanf (str.c_str (), "%uld", &result)) { + throw Invalid_Conversion (); + } + printf ("%s - %u\n", str.c_str (), result); + + return result; +} + /** * Replace every occurence of a pattern in a string with other substring. * diff --git a/pandora_agents/win32/pandora_strutils.h b/pandora_agents/win32/pandora_strutils.h index 79e2c73cc2..98e8dc83b6 100644 --- a/pandora_agents/win32/pandora_strutils.h +++ b/pandora_agents/win32/pandora_strutils.h @@ -41,15 +41,16 @@ namespace Pandora_Strutils { */ class Invalid_Conversion : Pandora_Strutils::String_Exception {}; - string trim (const string str); + string trim (const string str); - string inttostr (const int i); - string longtostr (const long i); - string longtohex (const long i); + string inttostr (const int i); + string longtostr (const long i); + string longtohex (const long i); - int strtoint (const string str); + int strtoint (const string str); + unsigned long strtoulong (const string str); - string strreplace (string in, string pattern, string rep); + string strreplace (string in, string pattern, string rep); void stringtok (list &l, string const &s, diff --git a/pandora_agents/win32/windows/pandora_wmi.cc b/pandora_agents/win32/windows/pandora_wmi.cc index bb53e0940a..bd986fb8cb 100644 --- a/pandora_agents/win32/windows/pandora_wmi.cc +++ b/pandora_agents/win32/windows/pandora_wmi.cc @@ -153,12 +153,12 @@ Pandora_Wmi::isServiceRunning (string service_name) { * @exception Pandora_Wmi_Exception Throwd if an error occured when reading * from WMI database. */ -long +unsigned long Pandora_Wmi::getDiskFreeSpace (string disk_id) { CDhInitialize init; CDispPtr wmi_svc, quickfixes; string id, space_str; - int space; + unsigned long space; struct QFix { CDhStringA id, free_space; @@ -185,7 +185,7 @@ Pandora_Wmi::getDiskFreeSpace (string disk_id) { space_str = fix.free_space; try { - space = Pandora_Strutils::strtoint (space_str); + space = Pandora_Strutils::strtoulong (space_str); } catch (Pandora_Exception e) { throw Pandora_Wmi_Exception (); } diff --git a/pandora_agents/win32/windows/pandora_wmi.h b/pandora_agents/win32/windows/pandora_wmi.h index 8700715919..f4b43cf51c 100644 --- a/pandora_agents/win32/windows/pandora_wmi.h +++ b/pandora_agents/win32/windows/pandora_wmi.h @@ -38,15 +38,15 @@ namespace Pandora_Wmi { */ class Pandora_Wmi_Exception : public Pandora_Exception { }; - int isProcessRunning (string process_name); - int isServiceRunning (string service_name); - long getDiskFreeSpace (string disk_id); - int getCpuUsagePercentage (int cpu_id); - long getFreememory (); - string getOSName (); - string getOSVersion (); - string getOSBuild (); - string getSystemName (); + int isProcessRunning (string process_name); + int isServiceRunning (string service_name); + unsigned long getDiskFreeSpace (string disk_id); + int getCpuUsagePercentage (int cpu_id); + long getFreememory (); + string getOSName (); + string getOSVersion (); + string getOSBuild (); + string getSystemName (); }; #endif