[WBEMPROX] Sync with Wine Staging 1.9.4. CORE-10912
[reactos.git] / reactos / dll / win32 / wbemprox / builtin.c
index aa33523..aac49b9 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "wbemprox_private.h"
 
+#include <winuser.h>
 #include <wingdi.h>
 #include <winsock2.h>
 #include <ws2tcpip.h>
@@ -42,6 +43,8 @@ static const WCHAR class_compsysproductW[] =
     {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m','P','r','o','d','u','c','t',0};
 static const WCHAR class_datafileW[] =
     {'C','I','M','_','D','a','t','a','F','i','l','e',0};
+static const WCHAR class_desktopmonitorW[] =
+    {'W','i','n','3','2','_','D','e','s','k','t','o','p','M','o','n','i','t','o','r',0};
 static const WCHAR class_directoryW[] =
     {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
 static const WCHAR class_diskdriveW[] =
@@ -65,8 +68,6 @@ static const WCHAR class_physicalmediaW[] =
     {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
 static const WCHAR class_physicalmemoryW[] =
     {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
-static const WCHAR class_qualifiersW[] =
-    {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
 static const WCHAR class_printerW[] =
     {'W','i','n','3','2','_','P','r','i','n','t','e','r',0};
 static const WCHAR class_process_getowner_outW[] =
@@ -76,6 +77,8 @@ static const WCHAR class_processorW[] =
     {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
 static const WCHAR class_processor2W[] =
     {'C','I','M','_','P','r','o','c','e','s','s','o','r',0};
+static const WCHAR class_qualifiersW[] =
+    {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
 static const WCHAR class_sidW[] =
     {'W','i','n','3','2','_','S','I','D',0};
 static const WCHAR class_sounddeviceW[] =
@@ -145,12 +148,16 @@ static const WCHAR prop_currentverticalresW[] =
     {'C','u','r','r','e','n','t','V','e','r','t','i','c','a','l','R','e','s','o','l','u','t','i','o','n',0};
 static const WCHAR prop_datawidthW[] =
     {'D','a','t','a','W','i','d','t','h',0};
+static const WCHAR prop_defaultipgatewayW[] =
+    {'D','e','f','a','u','l','t','I','P','G','a','t','e','w','a','y',0};
 static const WCHAR prop_defaultvalueW[] =
     {'D','e','f','a','u','l','t','V','a','l','u','e',0};
 static const WCHAR prop_descriptionW[] =
     {'D','e','s','c','r','i','p','t','i','o','n',0};
 static const WCHAR prop_deviceidW[] =
     {'D','e','v','i','c','e','I','d',0};
+static const WCHAR prop_dhcpenabledW[] =
+    {'D','H','C','P','E','n','a','b','l','e','d',0};
 static const WCHAR prop_directionW[] =
     {'D','i','r','e','c','t','i','o','n',0};
 static const WCHAR prop_displaynameW[] =
@@ -159,6 +166,8 @@ static const WCHAR prop_diskindexW[] =
     {'D','i','s','k','I','n','d','e','x',0};
 static const WCHAR prop_dnshostnameW[] =
     {'D','N','S','H','o','s','t','N','a','m','e',0};
+static const WCHAR prop_dnsserversearchorderW[] =
+    {'D','N','S','S','e','r','v','e','r','S','e','a','r','c','h','O','r','d','e','r',0};
 static const WCHAR prop_domainW[] =
     {'D','o','m','a','i','n',0};
 static const WCHAR prop_domainroleW[] =
@@ -249,6 +258,8 @@ static const WCHAR prop_parameterW[] =
     {'P','a','r','a','m','e','t','e','r',0};
 static const WCHAR prop_physicaladapterW[] =
     {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
+static const WCHAR prop_pixelsperxlogicalinchW[] =
+    {'P','i','x','e','l','s','P','e','r','X','L','o','g','i','c','a','l','I','n','c','h',0};
 static const WCHAR prop_pnpdeviceidW[] =
     {'P','N','P','D','e','v','i','c','e','I','D',0};
 static const WCHAR prop_pprocessidW[] =
@@ -277,6 +288,8 @@ static const WCHAR prop_servicepackminorW[] =
     {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
 static const WCHAR prop_servicetypeW[] =
     {'S','e','r','v','i','c','e','T','y','p','e',0};
+static const WCHAR prop_settingidW[] =
+    {'S','e','t','t','i','n','g','I','D',0};
 static const WCHAR prop_smbiosbiosversionW[] =
     {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
 static const WCHAR prop_startmodeW[] =
@@ -327,6 +340,8 @@ static const WCHAR prop_videoarchitectureW[] =
     {'V','i','d','e','o','A','r','c','h','i','t','e','c','t','u','r','e',0};
 static const WCHAR prop_videomemorytypeW[] =
     {'V','i','d','e','o','M','e','m','o','r','y','T','y','p','e',0};
+static const WCHAR prop_videomodedescriptionW[] =
+    {'V','i','d','e','o','M','o','d','e','D','e','s','c','r','i','p','t','i','o','n',0};
 static const WCHAR prop_videoprocessorW[] =
     {'V','i','d','e','o','P','r','o','c','e','s','s','o','r',0};
 static const WCHAR prop_volumenameW[] =
@@ -352,6 +367,7 @@ static const struct column col_bios[] =
     { prop_descriptionW,        CIM_STRING },
     { prop_identificationcodeW, CIM_STRING },
     { prop_manufacturerW,       CIM_STRING },
+    { prop_nameW,               CIM_STRING },
     { prop_releasedateW,        CIM_DATETIME },
     { prop_serialnumberW,       CIM_STRING },
     { prop_smbiosbiosversionW,  CIM_STRING },
@@ -388,6 +404,10 @@ static const struct column col_datafile[] =
     { prop_nameW,    CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
     { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
 };
+static const struct column col_desktopmonitor[] =
+{
+    { prop_pixelsperxlogicalinchW, CIM_UINT32 }
+};
 static const struct column col_directory[] =
 {
     { prop_accessmaskW, CIM_UINT32 },
@@ -444,11 +464,16 @@ static const struct column col_networkadapter[] =
 };
 static const struct column col_networkadapterconfig[] =
 {
-    { prop_dnshostnameW,        CIM_STRING|COL_FLAG_DYNAMIC },
-    { prop_indexW,              CIM_UINT32|COL_FLAG_KEY, VT_I4 },
-    { prop_ipconnectionmetricW, CIM_UINT32, VT_I4 },
-    { prop_ipenabledW,          CIM_BOOLEAN },
-    { prop_macaddressW,         CIM_STRING|COL_FLAG_DYNAMIC }
+    { prop_defaultipgatewayW,     CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
+    { prop_descriptionW,          CIM_STRING|COL_FLAG_DYNAMIC },
+    { prop_dhcpenabledW,          CIM_BOOLEAN },
+    { prop_dnshostnameW,          CIM_STRING|COL_FLAG_DYNAMIC },
+    { prop_dnsserversearchorderW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
+    { prop_indexW,                CIM_UINT32|COL_FLAG_KEY, VT_I4 },
+    { prop_ipconnectionmetricW,   CIM_UINT32, VT_I4 },
+    { prop_ipenabledW,            CIM_BOOLEAN },
+    { prop_macaddressW,           CIM_STRING|COL_FLAG_DYNAMIC },
+    { prop_settingidW,            CIM_STRING|COL_FLAG_DYNAMIC }
 };
 static const struct column col_os[] =
 {
@@ -617,6 +642,7 @@ static const struct column col_videocontroller[] =
     { prop_pnpdeviceidW,          CIM_STRING|COL_FLAG_DYNAMIC },
     { prop_videoarchitectureW,    CIM_UINT16, VT_I4 },
     { prop_videomemorytypeW,      CIM_UINT16, VT_I4 },
+    { prop_videomodedescriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
     { prop_videoprocessorW,       CIM_STRING|COL_FLAG_DYNAMIC }
 };
 
@@ -632,6 +658,8 @@ static const WCHAR bios_descriptionW[] =
     {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
 static const WCHAR bios_manufacturerW[] =
     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
+static const WCHAR bios_nameW[] =
+    {'W','I','N','E',' ','B','I','O','S',0};
 static const WCHAR bios_releasedateW[] =
     {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
 static const WCHAR bios_serialnumberW[] =
@@ -735,6 +763,7 @@ struct record_bios
     const WCHAR *description;
     const WCHAR *identificationcode;
     const WCHAR *manufacturer;
+    const WCHAR *name;
     const WCHAR *releasedate;
     const WCHAR *serialnumber;
     const WCHAR *smbiosbiosversion;
@@ -771,6 +800,10 @@ struct record_datafile
     const WCHAR *name;
     const WCHAR *version;
 };
+struct record_desktopmonitor
+{
+    UINT32       pixelsperxlogicalinch;
+};
 struct record_directory
 {
     UINT32       accessmask;
@@ -827,11 +860,16 @@ struct record_networkadapter
 };
 struct record_networkadapterconfig
 {
-    const WCHAR *dnshostname;
-    UINT32       index;
-    UINT32       ipconnectionmetric;
-    int          ipenabled;
-    const WCHAR *mac_address;
+    const struct array *defaultipgateway;
+    const WCHAR        *description;
+    int                 dhcpenabled;
+    const WCHAR        *dnshostname;
+    const struct array *dnsserversearchorder;
+    UINT32              index;
+    UINT32              ipconnectionmetric;
+    int                 ipenabled;
+    const WCHAR        *mac_address;
+    const WCHAR        *settingid;
 };
 struct record_operatingsystem
 {
@@ -1000,6 +1038,7 @@ struct record_videocontroller
     const WCHAR *pnpdevice_id;
     UINT16       videoarchitecture;
     UINT16       videomemorytype;
+    const WCHAR *videomodedescription;
     const WCHAR *videoprocessor;
 };
 #include "poppack.h"
@@ -1010,7 +1049,7 @@ static const struct record_baseboard data_baseboard[] =
 };
 static const struct record_bios data_bios[] =
 {
-    { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
+    { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_nameW, bios_releasedateW, bios_serialnumberW,
       bios_smbiosbiosversionW, bios_versionW }
 };
 static const struct record_computersystemproduct data_compsysproduct[] =
@@ -1142,7 +1181,7 @@ static enum fill_status fill_cdromdrive( struct table *table, const struct expr
 
     if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
 
-    for (i = 0; i < sizeof(drives); i++)
+    for (i = 0; i < 26; i++)
     {
         if (drives & (1 << i))
         {
@@ -1564,7 +1603,7 @@ static enum fill_status fill_datafile( struct table *table, const struct expr *c
 
     dirstack = alloc_dirstack(2);
 
-    for (i = 0; i < sizeof(drives); i++)
+    for (i = 0; i < 26; i++)
     {
         if (!(drives & (1 << i))) continue;
 
@@ -1640,6 +1679,35 @@ done:
     return status;
 }
 
+static UINT32 get_pixelsperxlogicalinch(void)
+{
+    HDC hdc = GetDC( NULL );
+    UINT32 ret;
+
+    if (!hdc) return 96;
+    ret = GetDeviceCaps( hdc, LOGPIXELSX );
+    ReleaseDC( NULL, hdc );
+    return ret;
+}
+
+static enum fill_status fill_desktopmonitor( struct table *table, const struct expr *cond )
+{
+    struct record_desktopmonitor *rec;
+    enum fill_status status = FILL_STATUS_UNFILTERED;
+    UINT row = 0;
+
+    if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
+
+    rec = (struct record_desktopmonitor *)table->data;
+    rec->pixelsperxlogicalinch = get_pixelsperxlogicalinch();
+
+    if (match_row( table, row, cond, &status )) row++;
+
+    TRACE("created %u rows\n", row);
+    table->num_rows = row;
+    return status;
+}
+
 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
 {
     static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
@@ -1656,7 +1724,7 @@ static enum fill_status fill_directory( struct table *table, const struct expr *
 
     dirstack = alloc_dirstack(2);
 
-    for (i = 0; i < sizeof(drives); i++)
+    for (i = 0; i < 26; i++)
     {
         if (!(drives & (1 << i))) continue;
 
@@ -1768,7 +1836,7 @@ static enum fill_status fill_diskdrive( struct table *table, const struct expr *
 
     if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
 
-    for (i = 0; i < sizeof(drives); i++)
+    for (i = 0; i < 26; i++)
     {
         if (drives & (1 << i))
         {
@@ -1832,7 +1900,7 @@ static enum fill_status fill_diskpartition( struct table *table, const struct ex
 
     if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
 
-    for (i = 0; i < sizeof(drives); i++)
+    for (i = 0; i < 26; i++)
     {
         if (drives & (1 << i))
         {
@@ -1899,7 +1967,7 @@ static enum fill_status fill_logicaldisk( struct table *table, const struct expr
 
     if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
 
-    for (i = 0; i < sizeof(drives); i++)
+    for (i = 0; i < 26; i++)
     {
         if (drives & (1 << i))
         {
@@ -2047,6 +2115,82 @@ static WCHAR *get_dnshostname( IP_ADAPTER_UNICAST_ADDRESS *addr )
                       0, NI_NAMEREQD )) return NULL;
     return heap_strdupW( buf );
 }
+static struct array *get_defaultipgateway( IP_ADAPTER_GATEWAY_ADDRESS *list )
+{
+    IP_ADAPTER_GATEWAY_ADDRESS *gateway;
+    struct array *ret;
+    ULONG buflen, i = 0, count = 0;
+    WCHAR **ptr, buf[54]; /* max IPv6 address length */
+
+    if (!list) return NULL;
+    for (gateway = list; gateway; gateway = gateway->Next) count++;
+
+    if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
+    if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
+    {
+        heap_free( ret );
+        return NULL;
+    }
+    for (gateway = list; gateway; gateway = gateway->Next)
+    {
+        buflen = sizeof(buf)/sizeof(buf[0]);
+        if (WSAAddressToStringW( gateway->Address.lpSockaddr, gateway->Address.iSockaddrLength,
+                                 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
+        {
+            for (; i > 0; i--) heap_free( ptr[i - 1] );
+            heap_free( ptr );
+            heap_free( ret );
+            return NULL;
+        }
+    }
+    ret->count = count;
+    ret->ptr   = ptr;
+    return ret;
+}
+static struct array *get_dnsserversearchorder( IP_ADAPTER_DNS_SERVER_ADDRESS *list )
+{
+    IP_ADAPTER_DNS_SERVER_ADDRESS *server;
+    struct array *ret;
+    ULONG buflen, i = 0, count = 0;
+    WCHAR **ptr, *p, buf[54]; /* max IPv6 address length */
+
+    if (!list) return NULL;
+    for (server = list; server; server = server->Next) count++;
+
+    if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
+    if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
+    {
+        heap_free( ret );
+        return NULL;
+    }
+    for (server = list; server; server = server->Next)
+    {
+        buflen = sizeof(buf)/sizeof(buf[0]);
+        if (WSAAddressToStringW( server->Address.lpSockaddr, server->Address.iSockaddrLength,
+                                 NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
+        {
+            for (; i > 0; i--) heap_free( ptr[i - 1] );
+            heap_free( ptr );
+            heap_free( ret );
+            return NULL;
+        }
+        if ((p = strrchrW( ptr[i - 1], ':' ))) *p = 0;
+    }
+    ret->count = count;
+    ret->ptr   = ptr;
+    return ret;
+}
+static WCHAR *get_settingid( UINT32 index )
+{
+    GUID guid;
+    WCHAR *ret, *str;
+    memset( &guid, 0, sizeof(guid) );
+    guid.Data1 = index;
+    UuidToStringW( &guid, &str );
+    ret = heap_strdupW( str );
+    RpcStringFreeW( &str );
+    return ret;
+}
 
 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
 {
@@ -2056,11 +2200,11 @@ static enum fill_status fill_networkadapterconfig( struct table *table, const st
     DWORD size = 0, ret;
     enum fill_status status = FILL_STATUS_UNFILTERED;
 
-    ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
+    ret = GetAdaptersAddresses( AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, NULL, &size );
     if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
 
     if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
-    if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
+    if (GetAdaptersAddresses( AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, buffer, &size ))
     {
         heap_free( buffer );
         return FILL_STATUS_FAILED;
@@ -2079,11 +2223,16 @@ static enum fill_status fill_networkadapterconfig( struct table *table, const st
         if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
 
         rec = (struct record_networkadapterconfig *)(table->data + offset);
-        rec->dnshostname        = get_dnshostname( aa->FirstUnicastAddress );
-        rec->index              = aa->u.s.IfIndex;
-        rec->ipconnectionmetric = 20;
-        rec->ipenabled          = -1;
-        rec->mac_address        = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
+        rec->defaultipgateway     = get_defaultipgateway( aa->FirstGatewayAddress );
+        rec->description          = heap_strdupW( aa->Description );
+        rec->dhcpenabled          = -1;
+        rec->dnshostname          = get_dnshostname( aa->FirstUnicastAddress );
+        rec->dnsserversearchorder = get_dnsserversearchorder( aa->FirstDnsServerAddress );
+        rec->index                = aa->u.s.IfIndex;
+        rec->ipconnectionmetric   = 20;
+        rec->ipenabled            = -1;
+        rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
+        rec->settingid            = get_settingid( rec->index );
         if (!match_row( table, row, cond, &status ))
         {
             free_row_values( table, row );
@@ -2778,16 +2927,16 @@ static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
 
 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
 {
-
+    static const WCHAR fmtW[] = {'%','u',' ','x',' ','%','u',' ','x',' ','%','I','6','4','u',' ','c','o','l','o','r','s',0};
     struct record_videocontroller *rec;
     HRESULT hr;
     IDXGIFactory *factory = NULL;
     IDXGIAdapter *adapter = NULL;
     DXGI_ADAPTER_DESC desc;
-    UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
+    UINT row = 0, hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
     const WCHAR *name = videocontroller_deviceidW;
     enum fill_status status = FILL_STATUS_UNFILTERED;
-    UINT row = 0;
+    WCHAR mode[44];
 
     if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
 
@@ -2823,6 +2972,8 @@ done:
     rec->pnpdevice_id          = get_pnpdeviceid( &desc );
     rec->videoarchitecture     = 2; /* Unknown */
     rec->videomemorytype       = 2; /* Unknown */
+    wsprintfW( mode, fmtW, hres, vres, (UINT64)1 << rec->current_bitsperpixel );
+    rec->videomodedescription  = heap_strdupW( mode );
     rec->videoprocessor        = heap_strdupW( name );
     if (!match_row( table, row, cond, &status )) free_row_values( table, row );
     else row++;
@@ -2845,6 +2996,7 @@ static struct table builtin_classes[] =
     { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
     { class_compsysproductW, SIZEOF(col_compsysproduct), col_compsysproduct, SIZEOF(data_compsysproduct), 0, (BYTE *)data_compsysproduct },
     { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
+    { class_desktopmonitorW, SIZEOF(col_desktopmonitor), col_desktopmonitor, 0, 0, NULL, fill_desktopmonitor },
     { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
     { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, 0, 0, NULL, fill_diskdrive },
     { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },