2 * Copyright 2009 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
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
31 #include "wbemprox_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
37 IWbemLocator IWbemLocator_iface
;
41 static inline wbem_locator
*impl_from_IWbemLocator( IWbemLocator
*iface
)
43 return CONTAINING_RECORD(iface
, wbem_locator
, IWbemLocator_iface
);
46 static ULONG WINAPI
wbem_locator_AddRef(
49 wbem_locator
*wl
= impl_from_IWbemLocator( iface
);
50 return InterlockedIncrement( &wl
->refs
);
53 static ULONG WINAPI
wbem_locator_Release(
56 wbem_locator
*wl
= impl_from_IWbemLocator( iface
);
57 LONG refs
= InterlockedDecrement( &wl
->refs
);
60 TRACE("destroying %p\n", wl
);
66 static HRESULT WINAPI
wbem_locator_QueryInterface(
71 wbem_locator
*This
= impl_from_IWbemLocator( iface
);
73 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
75 if ( IsEqualGUID( riid
, &IID_IWbemLocator
) ||
76 IsEqualGUID( riid
, &IID_IUnknown
) )
82 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
85 IWbemLocator_AddRef( iface
);
89 static BOOL
is_local_machine( const WCHAR
*server
)
91 static const WCHAR dotW
[] = {'.',0};
92 WCHAR buffer
[MAX_COMPUTERNAME_LENGTH
+ 1];
93 DWORD len
= sizeof(buffer
) / sizeof(buffer
[0]);
95 if (!server
|| !strcmpW( server
, dotW
)) return TRUE
;
96 if (GetComputerNameW( buffer
, &len
) && !strcmpiW( server
, buffer
)) return TRUE
;
100 static HRESULT
parse_resource( const WCHAR
*resource
, WCHAR
**server
, WCHAR
**namespace )
102 static const WCHAR rootW
[] = {'R','O','O','T'};
103 static const WCHAR cimv2W
[] = {'C','I','M','V','2'};
104 static const WCHAR defaultW
[] = {'D','E','F','A','U','L','T'};
105 HRESULT hr
= WBEM_E_INVALID_NAMESPACE
;
112 if (*p
== '\\' || *p
== '/')
115 if (*p
== '\\' || *p
== '/') p
++;
116 if (!*p
) return WBEM_E_INVALID_NAMESPACE
;
117 if (*p
== '\\' || *p
== '/') return WBEM_E_INVALID_PARAMETER
;
119 while (*q
&& *q
!= '\\' && *q
!= '/') q
++;
120 if (!*q
) return WBEM_E_INVALID_NAMESPACE
;
122 if (!(*server
= heap_alloc( (len
+ 1) * sizeof(WCHAR
) )))
127 memcpy( *server
, p
, len
* sizeof(WCHAR
) );
133 while (*q
&& *q
!= '\\' && *q
!= '/') q
++;
135 if (len
>= sizeof(rootW
) / sizeof(rootW
[0]) && memicmpW( rootW
, p
, len
)) goto done
;
143 if ((len
!= sizeof(cimv2W
) / sizeof(cimv2W
[0]) || memicmpW( q
, cimv2W
, len
)) &&
144 (len
!= sizeof(defaultW
) / sizeof(defaultW
[0]) || memicmpW( q
, defaultW
, len
)))
146 if (!(*namespace = heap_alloc( (len
+ 1) * sizeof(WCHAR
) ))) hr
= E_OUTOFMEMORY
;
149 memcpy( *namespace, p
, len
* sizeof(WCHAR
) );
150 (*namespace)[len
] = 0;
157 heap_free( *server
);
158 heap_free( *namespace );
163 static HRESULT WINAPI
wbem_locator_ConnectServer(
165 const BSTR NetworkResource
,
170 const BSTR Authority
,
172 IWbemServices
**ppNamespace
)
175 WCHAR
*server
, *namespace;
177 TRACE("%p, %s, %s, %s, %s, 0x%08x, %s, %p, %p)\n", iface
, debugstr_w(NetworkResource
), debugstr_w(User
),
178 debugstr_w(Password
), debugstr_w(Locale
), SecurityFlags
, debugstr_w(Authority
), pCtx
, ppNamespace
);
180 hr
= parse_resource( NetworkResource
, &server
, &namespace );
181 if (hr
!= S_OK
) return hr
;
183 if (!is_local_machine( server
))
185 FIXME("remote computer not supported\n");
187 heap_free( namespace );
188 return WBEM_E_TRANSPORT_FAILURE
;
190 if (User
|| Password
|| Authority
)
191 FIXME("authentication not supported\n");
193 FIXME("specific locale not supported\n");
195 FIXME("unsupported flags\n");
197 hr
= WbemServices_create( namespace, (void **)ppNamespace
);
198 heap_free( namespace );
201 return WBEM_NO_ERROR
;
203 return WBEM_E_FAILED
;
206 static const IWbemLocatorVtbl wbem_locator_vtbl
=
208 wbem_locator_QueryInterface
,
210 wbem_locator_Release
,
211 wbem_locator_ConnectServer
214 HRESULT
WbemLocator_create( LPVOID
*ppObj
)
218 TRACE("(%p)\n", ppObj
);
220 wl
= heap_alloc( sizeof(*wl
) );
221 if (!wl
) return E_OUTOFMEMORY
;
223 wl
->IWbemLocator_iface
.lpVtbl
= &wbem_locator_vtbl
;
226 *ppObj
= &wl
->IWbemLocator_iface
;
228 TRACE("returning iface %p\n", *ppObj
);