2 * Copyright 2012 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
33 HRESULT
create_view( const struct property
*proplist
, const WCHAR
*class,
34 const struct expr
*cond
, struct view
**ret
)
36 struct view
*view
= heap_alloc( sizeof(struct view
) );
38 if (!view
) return E_OUTOFMEMORY
;
39 view
->proplist
= proplist
;
40 view
->table
= grab_table( class );
48 void destroy_view( struct view
*view
)
51 if (view
->table
) release_table( view
->table
);
52 heap_free( view
->result
);
56 static BOOL
eval_like( const WCHAR
*lstr
, const WCHAR
*rstr
)
58 const WCHAR
*p
= lstr
, *q
= rstr
;
64 while (*q
== '%') q
++;
66 while (*p
&& *q
&& toupperW( *p
) == toupperW( *q
)) { p
++; q
++; };
67 if (!*p
&& !*q
) return TRUE
;
69 if (*q
!= '%' && toupperW( *p
++ ) != toupperW( *q
++ )) return FALSE
;
74 static HRESULT
eval_strcmp( UINT op
, const WCHAR
*lstr
, const WCHAR
*rstr
, LONGLONG
*val
)
84 *val
= !strcmpW( lstr
, rstr
);
87 *val
= strcmpW( lstr
, rstr
) > 0;
90 *val
= strcmpW( lstr
, rstr
) < 0;
93 *val
= strcmpW( lstr
, rstr
) <= 0;
96 *val
= strcmpW( lstr
, rstr
) >= 0;
99 *val
= strcmpW( lstr
, rstr
);
102 *val
= eval_like( lstr
, rstr
);
105 ERR("unhandled operator %u\n", op
);
106 return WBEM_E_INVALID_QUERY
;
111 static BOOL
is_int( CIMTYPE type
)
129 static inline BOOL
is_strcmp( const struct complex_expr
*expr
, UINT ltype
, UINT rtype
)
131 if ((ltype
== CIM_STRING
|| is_int( ltype
)) && expr
->left
->type
== EXPR_PROPVAL
&&
132 expr
->right
->type
== EXPR_SVAL
) return TRUE
;
133 else if ((rtype
== CIM_STRING
|| is_int( rtype
)) && expr
->right
->type
== EXPR_PROPVAL
&&
134 expr
->left
->type
== EXPR_SVAL
) return TRUE
;
138 static inline BOOL
is_boolcmp( const struct complex_expr
*expr
, UINT ltype
, UINT rtype
)
140 if (ltype
== CIM_BOOLEAN
&& expr
->left
->type
== EXPR_PROPVAL
&&
141 (expr
->right
->type
== EXPR_SVAL
|| expr
->right
->type
== EXPR_BVAL
)) return TRUE
;
142 else if (rtype
== CIM_BOOLEAN
&& expr
->right
->type
== EXPR_PROPVAL
&&
143 (expr
->left
->type
== EXPR_SVAL
|| expr
->left
->type
== EXPR_BVAL
)) return TRUE
;
147 static HRESULT
eval_boolcmp( UINT op
, LONGLONG lval
, LONGLONG rval
, UINT ltype
, UINT rtype
, LONGLONG
*val
)
149 static const WCHAR trueW
[] = {'T','r','u','e',0};
151 if (ltype
== CIM_STRING
) lval
= !strcmpiW( (const WCHAR
*)(INT_PTR
)lval
, trueW
) ? -1 : 0;
152 else if (rtype
== CIM_STRING
) rval
= !strcmpiW( (const WCHAR
*)(INT_PTR
)rval
, trueW
) ? -1 : 0;
157 *val
= (lval
== rval
);
160 *val
= (lval
!= rval
);
163 ERR("unhandled operator %u\n", op
);
164 return WBEM_E_INVALID_QUERY
;
169 static UINT
resolve_type( UINT left
, UINT right
)
197 if (right
== CIM_STRING
) return CIM_STRING
;
201 if (right
== CIM_BOOLEAN
) return CIM_BOOLEAN
;
210 static const WCHAR
*format_int( WCHAR
*buf
, CIMTYPE type
, LONGLONG val
)
212 static const WCHAR fmt_signedW
[] = {'%','d',0};
213 static const WCHAR fmt_unsignedW
[] = {'%','u',0};
214 static const WCHAR fmt_signed64W
[] = {'%','I','6','4','d',0};
215 static const WCHAR fmt_unsigned64W
[] = {'%','I','6','4','u',0};
222 sprintfW( buf
, fmt_signedW
, val
);
228 sprintfW( buf
, fmt_unsignedW
, val
);
232 wsprintfW( buf
, fmt_signed64W
, val
);
236 wsprintfW( buf
, fmt_unsigned64W
, val
);
240 ERR( "unhandled type %u\n", type
);
245 static HRESULT
eval_binary( const struct table
*table
, UINT row
, const struct complex_expr
*expr
,
246 LONGLONG
*val
, UINT
*type
)
252 lret
= eval_cond( table
, row
, expr
->left
, &lval
, <ype
);
253 rret
= eval_cond( table
, row
, expr
->right
, &rval
, &rtype
);
254 if (lret
!= S_OK
|| rret
!= S_OK
) return WBEM_E_INVALID_QUERY
;
256 *type
= resolve_type( ltype
, rtype
);
258 if (is_boolcmp( expr
, ltype
, rtype
))
259 return eval_boolcmp( expr
->op
, lval
, rval
, ltype
, rtype
, val
);
261 if (is_strcmp( expr
, ltype
, rtype
))
263 const WCHAR
*lstr
, *rstr
;
264 WCHAR lbuf
[21], rbuf
[21];
266 if (is_int( ltype
)) lstr
= format_int( lbuf
, ltype
, lval
);
267 else lstr
= (const WCHAR
*)(INT_PTR
)lval
;
269 if (is_int( rtype
)) rstr
= format_int( rbuf
, rtype
, rval
);
270 else rstr
= (const WCHAR
*)(INT_PTR
)rval
;
272 return eval_strcmp( expr
->op
, lstr
, rstr
, val
);
277 *val
= (lval
== rval
);
280 *val
= (lval
&& rval
);
283 *val
= (lval
|| rval
);
286 *val
= (lval
> rval
);
289 *val
= (lval
< rval
);
292 *val
= (lval
<= rval
);
295 *val
= (lval
>= rval
);
298 *val
= (lval
!= rval
);
301 ERR("unhandled operator %u\n", expr
->op
);
302 return WBEM_E_INVALID_QUERY
;
307 static HRESULT
eval_unary( const struct table
*table
, UINT row
, const struct complex_expr
*expr
,
308 LONGLONG
*val
, UINT
*type
)
315 if (expr
->op
== OP_NOT
)
317 hr
= eval_cond( table
, row
, expr
->left
, &lval
, type
);
324 hr
= get_column_index( table
, expr
->left
->u
.propval
->name
, &column
);
328 hr
= get_value( table
, row
, column
, &lval
);
341 ERR("unknown operator %u\n", expr
->op
);
342 return WBEM_E_INVALID_QUERY
;
345 *type
= table
->columns
[column
].type
& CIM_TYPE_MASK
;
349 static HRESULT
eval_propval( const struct table
*table
, UINT row
, const struct property
*propval
,
350 LONGLONG
*val
, UINT
*type
)
356 hr
= get_column_index( table
, propval
->name
, &column
);
360 *type
= table
->columns
[column
].type
& CIM_TYPE_MASK
;
361 return get_value( table
, row
, column
, val
);
364 HRESULT
eval_cond( const struct table
*table
, UINT row
, const struct expr
*cond
, LONGLONG
*val
, UINT
*type
)
375 return eval_binary( table
, row
, &cond
->u
.expr
, val
, type
);
378 return eval_unary( table
, row
, &cond
->u
.expr
, val
, type
);
381 return eval_propval( table
, row
, cond
->u
.propval
, val
, type
);
384 *val
= (INT_PTR
)cond
->u
.sval
;
399 ERR("invalid expression type\n");
402 return WBEM_E_INVALID_QUERY
;
405 HRESULT
execute_view( struct view
*view
)
409 if (!view
->table
) return S_OK
;
410 if (view
->table
->fill
)
412 clear_table( view
->table
);
413 view
->table
->fill( view
->table
, view
->cond
);
415 if (!view
->table
->num_rows
) return S_OK
;
417 len
= min( view
->table
->num_rows
, 16 );
418 if (!(view
->result
= heap_alloc( len
* sizeof(UINT
) ))) return E_OUTOFMEMORY
;
420 for (i
= 0; i
< view
->table
->num_rows
; i
++)
430 if (!(tmp
= heap_realloc( view
->result
, len
* sizeof(UINT
) ))) return E_OUTOFMEMORY
;
433 if ((hr
= eval_cond( view
->table
, i
, view
->cond
, &val
, &type
)) != S_OK
) return hr
;
434 if (val
) view
->result
[j
++] = i
;
440 struct query
*create_query(void)
444 if (!(query
= heap_alloc( sizeof(*query
) ))) return NULL
;
445 list_init( &query
->mem
);
450 void free_query( struct query
*query
)
452 struct list
*mem
, *next
;
455 destroy_view( query
->view
);
456 LIST_FOR_EACH_SAFE( mem
, next
, &query
->mem
) { heap_free( mem
); }
460 struct query
*addref_query( struct query
*query
)
462 InterlockedIncrement( &query
->refs
);
466 void release_query( struct query
*query
)
468 if (!InterlockedDecrement( &query
->refs
)) free_query( query
);
471 HRESULT
exec_query( const WCHAR
*str
, IEnumWbemClassObject
**result
)
477 if (!(query
= create_query())) return E_OUTOFMEMORY
;
478 hr
= parse_query( str
, &query
->view
, &query
->mem
);
479 if (hr
!= S_OK
) goto done
;
480 hr
= execute_view( query
->view
);
481 if (hr
!= S_OK
) goto done
;
482 hr
= EnumWbemClassObject_create( query
, (void **)result
);
485 release_query( query
);
489 BOOL
is_selected_prop( const struct view
*view
, const WCHAR
*name
)
491 const struct property
*prop
= view
->proplist
;
493 if (!prop
) return TRUE
;
496 if (!strcmpiW( prop
->name
, name
)) return TRUE
;
502 static BOOL
is_system_prop( const WCHAR
*name
)
504 return (name
[0] == '_' && name
[1] == '_');
507 static BSTR
build_servername( const struct view
*view
)
509 WCHAR server
[MAX_COMPUTERNAME_LENGTH
+ 1], *p
;
510 DWORD len
= ARRAY_SIZE( server
);
512 if (view
->proplist
) return NULL
;
514 if (!(GetComputerNameW( server
, &len
))) return NULL
;
515 for (p
= server
; *p
; p
++) *p
= toupperW( *p
);
516 return SysAllocString( server
);
519 static BSTR
build_classname( const struct view
*view
)
521 return SysAllocString( view
->table
->name
);
524 static BSTR
build_namespace( const struct view
*view
)
526 static const WCHAR cimv2W
[] = {'R','O','O','T','\\','C','I','M','V','2',0};
528 if (view
->proplist
) return NULL
;
529 return SysAllocString( cimv2W
);
532 static BSTR
build_proplist( const struct view
*view
, UINT index
, UINT count
, UINT
*len
)
534 static const WCHAR fmtW
[] = {'%','s','=','%','s',0};
535 UINT i
, j
, offset
, row
= view
->result
[index
];
536 BSTR
*values
, ret
= NULL
;
538 if (!(values
= heap_alloc( count
* sizeof(BSTR
) ))) return NULL
;
541 for (i
= 0; i
< view
->table
->num_cols
; i
++)
543 if (view
->table
->columns
[i
].type
& COL_FLAG_KEY
)
545 const WCHAR
*name
= view
->table
->columns
[i
].name
;
547 values
[j
] = get_value_bstr( view
->table
, row
, i
);
548 *len
+= strlenW( fmtW
) + strlenW( name
) + strlenW( values
[j
] );
552 if ((ret
= SysAllocStringLen( NULL
, *len
)))
555 for (i
= 0; i
< view
->table
->num_cols
; i
++)
557 if (view
->table
->columns
[i
].type
& COL_FLAG_KEY
)
559 const WCHAR
*name
= view
->table
->columns
[i
].name
;
561 offset
+= sprintfW( ret
+ offset
, fmtW
, name
, values
[j
] );
562 if (j
< count
- 1) ret
[offset
++] = ',';
567 for (i
= 0; i
< count
; i
++) SysFreeString( values
[i
] );
572 static UINT
count_key_columns( const struct view
*view
)
574 UINT i
, num_keys
= 0;
576 for (i
= 0; i
< view
->table
->num_cols
; i
++)
578 if (view
->table
->columns
[i
].type
& COL_FLAG_KEY
) num_keys
++;
583 static BSTR
build_relpath( const struct view
*view
, UINT index
, const WCHAR
*name
)
585 static const WCHAR fmtW
[] = {'%','s','.','%','s',0};
586 BSTR
class, proplist
, ret
= NULL
;
589 if (view
->proplist
) return NULL
;
591 if (!(class = build_classname( view
))) return NULL
;
592 if (!(num_keys
= count_key_columns( view
))) return class;
593 if (!(proplist
= build_proplist( view
, index
, num_keys
, &len
))) goto done
;
595 len
+= strlenW( fmtW
) + SysStringLen( class );
596 if (!(ret
= SysAllocStringLen( NULL
, len
))) goto done
;
597 sprintfW( ret
, fmtW
, class, proplist
);
600 SysFreeString( class );
601 SysFreeString( proplist
);
605 static BSTR
build_path( const struct view
*view
, UINT index
, const WCHAR
*name
)
607 static const WCHAR fmtW
[] = {'\\','\\','%','s','\\','%','s',':','%','s',0};
608 BSTR server
, namespace = NULL
, relpath
= NULL
, ret
= NULL
;
611 if (view
->proplist
) return NULL
;
613 if (!(server
= build_servername( view
))) return NULL
;
614 if (!(namespace = build_namespace( view
))) goto done
;
615 if (!(relpath
= build_relpath( view
, index
, name
))) goto done
;
617 len
= strlenW( fmtW
) + SysStringLen( server
) + SysStringLen( namespace ) + SysStringLen( relpath
);
618 if (!(ret
= SysAllocStringLen( NULL
, len
))) goto done
;
619 sprintfW( ret
, fmtW
, server
, namespace, relpath
);
622 SysFreeString( server
);
623 SysFreeString( namespace );
624 SysFreeString( relpath
);
628 BOOL
is_method( const struct table
*table
, UINT column
)
630 return table
->columns
[column
].type
& COL_FLAG_METHOD
;
633 static UINT
count_properties( const struct view
*view
)
635 UINT i
, num_props
= 0;
637 for (i
= 0; i
< view
->table
->num_cols
; i
++)
639 if (!is_method( view
->table
, i
)) num_props
++;
644 static UINT
count_selected_properties( const struct view
*view
)
646 const struct property
*prop
= view
->proplist
;
649 if (!prop
) return count_properties( view
);
652 while ((prop
= prop
->next
)) count
++;
656 static HRESULT
get_system_propval( const struct view
*view
, UINT index
, const WCHAR
*name
,
657 VARIANT
*ret
, CIMTYPE
*type
, LONG
*flavor
)
659 static const WCHAR classW
[] = {'_','_','C','L','A','S','S',0};
660 static const WCHAR genusW
[] = {'_','_','G','E','N','U','S',0};
661 static const WCHAR pathW
[] = {'_','_','P','A','T','H',0};
662 static const WCHAR namespaceW
[] = {'_','_','N','A','M','E','S','P','A','C','E',0};
663 static const WCHAR propcountW
[] = {'_','_','P','R','O','P','E','R','T','Y','_','C','O','U','N','T',0};
664 static const WCHAR relpathW
[] = {'_','_','R','E','L','P','A','T','H',0};
665 static const WCHAR serverW
[] = {'_','_','S','E','R','V','E','R',0};
667 if (flavor
) *flavor
= WBEM_FLAVOR_ORIGIN_SYSTEM
;
669 if (!strcmpiW( name
, classW
))
673 V_VT( ret
) = VT_BSTR
;
674 V_BSTR( ret
) = build_classname( view
);
676 if (type
) *type
= CIM_STRING
;
679 if (!strcmpiW( name
, genusW
))
684 V_I4( ret
) = WBEM_GENUS_INSTANCE
; /* FIXME */
686 if (type
) *type
= CIM_SINT32
;
689 else if (!strcmpiW( name
, namespaceW
))
693 V_VT( ret
) = VT_BSTR
;
694 V_BSTR( ret
) = build_namespace( view
);
696 if (type
) *type
= CIM_STRING
;
699 else if (!strcmpiW( name
, pathW
))
703 V_VT( ret
) = VT_BSTR
;
704 V_BSTR( ret
) = build_path( view
, index
, name
);
706 if (type
) *type
= CIM_STRING
;
709 if (!strcmpiW( name
, propcountW
))
714 V_I4( ret
) = count_selected_properties( view
);
716 if (type
) *type
= CIM_SINT32
;
719 else if (!strcmpiW( name
, relpathW
))
723 V_VT( ret
) = VT_BSTR
;
724 V_BSTR( ret
) = build_relpath( view
, index
, name
);
726 if (type
) *type
= CIM_STRING
;
729 else if (!strcmpiW( name
, serverW
))
733 V_VT( ret
) = VT_BSTR
;
734 V_BSTR( ret
) = build_servername( view
);
736 if (type
) *type
= CIM_STRING
;
739 FIXME("system property %s not implemented\n", debugstr_w(name
));
740 return WBEM_E_NOT_FOUND
;
743 VARTYPE
to_vartype( CIMTYPE type
)
747 case CIM_BOOLEAN
: return VT_BOOL
;
749 case CIM_DATETIME
: return VT_BSTR
;
750 case CIM_SINT8
: return VT_I1
;
751 case CIM_UINT8
: return VT_UI1
;
752 case CIM_SINT16
: return VT_I2
;
753 case CIM_UINT16
: return VT_UI2
;
754 case CIM_SINT32
: return VT_I4
;
755 case CIM_UINT32
: return VT_UI4
;
756 case CIM_SINT64
: return VT_I8
;
757 case CIM_UINT64
: return VT_UI8
;
759 ERR("unhandled type %u\n", type
);
765 SAFEARRAY
*to_safearray( const struct array
*array
, CIMTYPE type
)
768 UINT size
= get_type_size( type
);
769 VARTYPE vartype
= to_vartype( type
);
772 if (!array
|| !(ret
= SafeArrayCreateVector( vartype
, 0, array
->count
))) return NULL
;
774 for (i
= 0; i
< array
->count
; i
++)
776 void *ptr
= (char *)array
->ptr
+ i
* size
;
777 if (vartype
== VT_BSTR
)
779 BSTR str
= SysAllocString( *(const WCHAR
**)ptr
);
780 if (!str
|| SafeArrayPutElement( ret
, &i
, str
) != S_OK
)
782 SysFreeString( str
);
783 SafeArrayDestroy( ret
);
786 SysFreeString( str
);
788 else if (SafeArrayPutElement( ret
, &i
, ptr
) != S_OK
)
790 SafeArrayDestroy( ret
);
797 void set_variant( VARTYPE type
, LONGLONG val
, void *val_ptr
, VARIANT
*ret
)
802 V_ARRAY( ret
) = val_ptr
;
811 V_BSTR( ret
) = val_ptr
;
834 ERR("unhandled variant type %u\n", type
);
840 HRESULT
get_propval( const struct view
*view
, UINT index
, const WCHAR
*name
, VARIANT
*ret
,
841 CIMTYPE
*type
, LONG
*flavor
)
846 void *val_ptr
= NULL
;
849 if (is_system_prop( name
)) return get_system_propval( view
, index
, name
, ret
, type
, flavor
);
850 if (!view
->count
|| !is_selected_prop( view
, name
)) return WBEM_E_NOT_FOUND
;
852 hr
= get_column_index( view
->table
, name
, &column
);
853 if (hr
!= S_OK
|| is_method( view
->table
, column
)) return WBEM_E_NOT_FOUND
;
855 row
= view
->result
[index
];
856 hr
= get_value( view
->table
, row
, column
, &val
);
857 if (hr
!= S_OK
) return hr
;
859 if (type
) *type
= view
->table
->columns
[column
].type
& COL_TYPE_MASK
;
860 if (flavor
) *flavor
= 0;
862 if (!ret
) return S_OK
;
864 vartype
= view
->table
->columns
[column
].vartype
;
865 if (view
->table
->columns
[column
].type
& CIM_FLAG_ARRAY
)
867 CIMTYPE basetype
= view
->table
->columns
[column
].type
& CIM_TYPE_MASK
;
869 val_ptr
= to_safearray( (const struct array
*)(INT_PTR
)val
, basetype
);
870 if (!val_ptr
) vartype
= VT_NULL
;
871 else if (!vartype
) vartype
= to_vartype( basetype
) | VT_ARRAY
;
872 set_variant( vartype
, val
, val_ptr
, ret
);
876 switch (view
->table
->columns
[column
].type
& COL_TYPE_MASK
)
879 if (!vartype
) vartype
= VT_BOOL
;
886 val_ptr
= SysAllocString( (const WCHAR
*)(INT_PTR
)val
);
892 if (!vartype
) vartype
= VT_I1
;
895 if (!vartype
) vartype
= VT_UI1
;
898 if (!vartype
) vartype
= VT_I2
;
901 if (!vartype
) vartype
= VT_UI2
;
904 if (!vartype
) vartype
= VT_I4
;
907 if (!vartype
) vartype
= VT_UI4
;
911 val_ptr
= get_value_bstr( view
->table
, row
, column
);
915 val_ptr
= get_value_bstr( view
->table
, row
, column
);
918 ERR("unhandled column type %u\n", view
->table
->columns
[column
].type
);
919 return WBEM_E_FAILED
;
922 set_variant( vartype
, val
, val_ptr
, ret
);
926 static CIMTYPE
to_cimtype( VARTYPE type
)
930 case VT_BOOL
: return CIM_BOOLEAN
;
931 case VT_BSTR
: return CIM_STRING
;
932 case VT_I1
: return CIM_SINT8
;
933 case VT_UI1
: return CIM_UINT8
;
934 case VT_I2
: return CIM_SINT16
;
935 case VT_UI2
: return CIM_UINT16
;
936 case VT_I4
: return CIM_SINT32
;
937 case VT_UI4
: return CIM_UINT32
;
938 case VT_I8
: return CIM_SINT64
;
939 case VT_UI8
: return CIM_UINT64
;
941 ERR("unhandled type %u\n", type
);
947 static struct array
*to_array( VARIANT
*var
, CIMTYPE
*type
)
955 if (SafeArrayGetVartype( V_ARRAY( var
), &vartype
) != S_OK
) return NULL
;
956 if (!(basetype
= to_cimtype( vartype
))) return NULL
;
957 if (SafeArrayGetUBound( V_ARRAY( var
), 1, &bound
) != S_OK
) return NULL
;
958 if (!(ret
= heap_alloc( sizeof(struct array
) ))) return NULL
;
960 ret
->count
= bound
+ 1;
961 size
= get_type_size( basetype
);
962 if (!(ret
->ptr
= heap_alloc_zero( ret
->count
* size
)))
967 for (i
= 0; i
< ret
->count
; i
++)
969 void *ptr
= (char *)ret
->ptr
+ i
* size
;
970 if (vartype
== VT_BSTR
)
973 if (SafeArrayGetElement( V_ARRAY( var
), &i
, &str
) != S_OK
)
975 destroy_array( ret
, basetype
);
978 *(WCHAR
**)ptr
= heap_strdupW( str
);
979 SysFreeString( str
);
982 destroy_array( ret
, basetype
);
986 else if (SafeArrayGetElement( V_ARRAY( var
), &i
, ptr
) != S_OK
)
988 destroy_array( ret
, basetype
);
992 *type
= basetype
| CIM_FLAG_ARRAY
;
996 HRESULT
to_longlong( VARIANT
*var
, LONGLONG
*val
, CIMTYPE
*type
)
1003 if (V_VT( var
) & VT_ARRAY
)
1005 *val
= (INT_PTR
)to_array( var
, type
);
1006 if (!*val
) return E_OUTOFMEMORY
;
1009 switch (V_VT( var
))
1012 *val
= V_BOOL( var
);
1013 *type
= CIM_BOOLEAN
;
1016 *val
= (INT_PTR
)heap_strdupW( V_BSTR( var
) );
1017 if (!*val
) return E_OUTOFMEMORY
;
1025 *val
= V_UI2( var
);
1033 *val
= V_UI4( var
);
1040 ERR("unhandled type %u\n", V_VT( var
));
1041 return WBEM_E_FAILED
;
1046 HRESULT
put_propval( const struct view
*view
, UINT index
, const WCHAR
*name
, VARIANT
*var
, CIMTYPE type
)
1049 UINT column
, row
= view
->result
[index
];
1052 hr
= get_column_index( view
->table
, name
, &column
);
1055 FIXME("no support for creating new properties\n");
1056 return WBEM_E_FAILED
;
1058 if (is_method( view
->table
, column
) || !(view
->table
->columns
[column
].type
& COL_FLAG_DYNAMIC
))
1059 return WBEM_E_FAILED
;
1061 hr
= to_longlong( var
, &val
, &type
);
1062 if (hr
!= S_OK
) return hr
;
1064 return set_value( view
->table
, row
, column
, val
, type
);
1067 HRESULT
get_properties( const struct view
*view
, LONG flags
, SAFEARRAY
**props
)
1071 UINT i
, num_props
= count_selected_properties( view
);
1074 if (!(sa
= SafeArrayCreateVector( VT_BSTR
, 0, num_props
))) return E_OUTOFMEMORY
;
1076 for (i
= 0, j
= 0; i
< view
->table
->num_cols
; i
++)
1080 if (is_method( view
->table
, i
)) continue;
1081 if (!is_selected_prop( view
, view
->table
->columns
[i
].name
)) continue;
1083 is_system
= is_system_prop( view
->table
->columns
[i
].name
);
1084 if ((flags
& WBEM_FLAG_NONSYSTEM_ONLY
) && is_system
) continue;
1085 else if ((flags
& WBEM_FLAG_SYSTEM_ONLY
) && !is_system
) continue;
1087 str
= SysAllocString( view
->table
->columns
[i
].name
);
1088 if (!str
|| SafeArrayPutElement( sa
, &j
, str
) != S_OK
)
1090 SysFreeString( str
);
1091 SafeArrayDestroy( sa
);
1092 return E_OUTOFMEMORY
;
1094 SysFreeString( str
);