libimcv: Port os_info (partially) to Windows
This commit is contained in:
@@ -13,9 +13,13 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* for GetTickCount64, Windows 7 */
|
||||||
|
#ifdef WIN32
|
||||||
|
# define _WIN32_WINNT 0x0601
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "imc_os_info.h"
|
#include "imc_os_info.h"
|
||||||
|
|
||||||
#include <sys/utsname.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
@@ -86,6 +90,69 @@ METHOD(imc_os_info_t, get_version, chunk_t,
|
|||||||
return this->version;
|
return this->version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
|
||||||
|
METHOD(imc_os_info_t, get_fwd_status, os_fwd_status_t,
|
||||||
|
private_imc_os_info_t *this)
|
||||||
|
{
|
||||||
|
return OS_FWD_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(imc_os_info_t, get_uptime, time_t,
|
||||||
|
private_imc_os_info_t *this)
|
||||||
|
{
|
||||||
|
return GetTickCount64() / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(imc_os_info_t, get_setting, chunk_t,
|
||||||
|
private_imc_os_info_t *this, char *name)
|
||||||
|
{
|
||||||
|
return chunk_empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(imc_os_info_t, create_package_enumerator, enumerator_t*,
|
||||||
|
private_imc_os_info_t *this)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine Windows release
|
||||||
|
*/
|
||||||
|
static bool extract_platform_info(os_type_t *type, chunk_t *name,
|
||||||
|
chunk_t *version)
|
||||||
|
{
|
||||||
|
OSVERSIONINFOEX osvie;
|
||||||
|
char buf[64];
|
||||||
|
|
||||||
|
memset(&osvie, 0, sizeof(osvie));
|
||||||
|
osvie.dwOSVersionInfoSize = sizeof(osvie);
|
||||||
|
|
||||||
|
if (!GetVersionEx((LPOSVERSIONINFO)&osvie))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
*type = OS_TYPE_WINDOWS;
|
||||||
|
if (osvie.wProductType == VER_NT_WORKSTATION)
|
||||||
|
{
|
||||||
|
*name = chunk_clone(chunk_from_str("Client"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*name = chunk_clone(chunk_from_str("Server"));
|
||||||
|
}
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%d.%d (SP %d.%d)",
|
||||||
|
osvie.dwMajorVersion, osvie.dwMinorVersion, osvie.dwBuildNumber,
|
||||||
|
osvie.wServicePackMajor, osvie.wServicePackMinor);
|
||||||
|
*version = chunk_clone(chunk_from_str(buf));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* !WIN32 */
|
||||||
|
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
METHOD(imc_os_info_t, get_fwd_status, os_fwd_status_t,
|
METHOD(imc_os_info_t, get_fwd_status, os_fwd_status_t,
|
||||||
private_imc_os_info_t *this)
|
private_imc_os_info_t *this)
|
||||||
{
|
{
|
||||||
@@ -294,15 +361,6 @@ METHOD(imc_os_info_t, create_package_enumerator, enumerator_t*,
|
|||||||
return (enumerator_t*)enumerator;
|
return (enumerator_t*)enumerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
METHOD(imc_os_info_t, destroy, void,
|
|
||||||
private_imc_os_info_t *this)
|
|
||||||
{
|
|
||||||
free(this->name.ptr);
|
|
||||||
free(this->version.ptr);
|
|
||||||
free(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define RELEASE_LSB 0
|
#define RELEASE_LSB 0
|
||||||
#define RELEASE_DEBIAN 1
|
#define RELEASE_DEBIAN 1
|
||||||
|
|
||||||
@@ -505,6 +563,16 @@ static bool extract_platform_info(os_type_t *type, chunk_t *name,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* !WIN32 */
|
||||||
|
|
||||||
|
METHOD(imc_os_info_t, destroy, void,
|
||||||
|
private_imc_os_info_t *this)
|
||||||
|
{
|
||||||
|
free(this->name.ptr);
|
||||||
|
free(this->version.ptr);
|
||||||
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See header
|
* See header
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#include "os_info.h"
|
#include "os_info.h"
|
||||||
|
|
||||||
ENUM(os_type_names, OS_TYPE_UNKNOWN, OS_TYPE_ANDROID,
|
ENUM(os_type_names, OS_TYPE_UNKNOWN, OS_TYPE_WINDOWS,
|
||||||
"Unknown",
|
"Unknown",
|
||||||
"Debian",
|
"Debian",
|
||||||
"Ubuntu",
|
"Ubuntu",
|
||||||
@@ -24,7 +24,8 @@ ENUM(os_type_names, OS_TYPE_UNKNOWN, OS_TYPE_ANDROID,
|
|||||||
"CentOS",
|
"CentOS",
|
||||||
"SUSE",
|
"SUSE",
|
||||||
"Gentoo",
|
"Gentoo",
|
||||||
"Android"
|
"Android",
|
||||||
|
"Windows",
|
||||||
);
|
);
|
||||||
|
|
||||||
ENUM(os_fwd_status_names, OS_FWD_DISABLED, OS_FWD_UNKNOWN,
|
ENUM(os_fwd_status_names, OS_FWD_DISABLED, OS_FWD_UNKNOWN,
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ enum os_type_t {
|
|||||||
OS_TYPE_SUSE,
|
OS_TYPE_SUSE,
|
||||||
OS_TYPE_GENTOO,
|
OS_TYPE_GENTOO,
|
||||||
OS_TYPE_ANDROID,
|
OS_TYPE_ANDROID,
|
||||||
|
OS_TYPE_WINDOWS,
|
||||||
OS_TYPE_ROOF
|
OS_TYPE_ROOF
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user