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
28 #include "wine/debug.h"
29 #include "wbemprox_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
35 IWbemLocator IWbemLocator_iface
;
39 static inline wbem_locator
*impl_from_IWbemLocator( IWbemLocator
*iface
)
41 return CONTAINING_RECORD(iface
, wbem_locator
, IWbemLocator_iface
);
44 static ULONG WINAPI
wbem_locator_AddRef(
47 wbem_locator
*wl
= impl_from_IWbemLocator( iface
);
48 return InterlockedIncrement( &wl
->refs
);
51 static ULONG WINAPI
wbem_locator_Release(
54 wbem_locator
*wl
= impl_from_IWbemLocator( iface
);
55 LONG refs
= InterlockedDecrement( &wl
->refs
);
58 TRACE("destroying %p\n", wl
);
64 static HRESULT WINAPI
wbem_locator_QueryInterface(
69 wbem_locator
*This
= impl_from_IWbemLocator( iface
);
71 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
73 if ( IsEqualGUID( riid
, &IID_IWbemLocator
) ||
74 IsEqualGUID( riid
, &IID_IUnknown
) )
80 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
83 IWbemLocator_AddRef( iface
);
87 static BOOL
is_local_machine( const WCHAR
*server
)
89 WCHAR buffer
[MAX_COMPUTERNAME_LENGTH
+ 1];
90 DWORD len
= ARRAY_SIZE( buffer
);
92 if (!server
|| !wcscmp( server
, L
"." ) || !wcsicmp( server
, L
"localhost" )) return TRUE
;
93 if (GetComputerNameW( buffer
, &len
) && !wcsicmp( server
, buffer
)) return TRUE
;
97 static HRESULT
parse_resource( const WCHAR
*resource
, WCHAR
**server
, WCHAR
**namespace )
99 HRESULT hr
= WBEM_E_INVALID_NAMESPACE
;
106 if (*p
== '\\' || *p
== '/')
109 if (*p
== '\\' || *p
== '/') p
++;
110 if (!*p
) return WBEM_E_INVALID_NAMESPACE
;
111 if (*p
== '\\' || *p
== '/') return WBEM_E_INVALID_PARAMETER
;
113 while (*q
&& *q
!= '\\' && *q
!= '/') q
++;
114 if (!*q
) return WBEM_E_INVALID_NAMESPACE
;
116 if (!(*server
= malloc( (len
+ 1) * sizeof(WCHAR
) )))
121 memcpy( *server
, p
, len
* sizeof(WCHAR
) );
127 while (*q
&& *q
!= '\\' && *q
!= '/') q
++;
129 if (len
>= ARRAY_SIZE( L
"root" ) - 1 && wcsnicmp( L
"root", p
, len
)) goto done
;
137 if (!(*namespace = malloc( (len
+ 1) * sizeof(WCHAR
) ))) hr
= E_OUTOFMEMORY
;
140 memcpy( *namespace, q
, len
* sizeof(WCHAR
) );
141 (*namespace)[len
] = 0;
154 static HRESULT WINAPI
wbem_locator_ConnectServer(
156 const BSTR NetworkResource
,
161 const BSTR Authority
,
162 IWbemContext
*context
,
163 IWbemServices
**ppNamespace
)
166 WCHAR
*server
, *namespace;
168 TRACE( "%p, %s, %s, %s, %s, %#lx, %s, %p, %p)\n", iface
, debugstr_w(NetworkResource
), debugstr_w(User
),
169 debugstr_w(Password
), debugstr_w(Locale
), SecurityFlags
, debugstr_w(Authority
), context
, ppNamespace
);
171 hr
= parse_resource( NetworkResource
, &server
, &namespace );
172 if (hr
!= S_OK
) return hr
;
174 if (!is_local_machine( server
))
176 FIXME("remote computer not supported\n");
179 return WBEM_E_TRANSPORT_FAILURE
;
181 if (User
|| Password
|| Authority
)
182 FIXME("authentication not supported\n");
184 FIXME("specific locale not supported\n");
186 FIXME("unsupported flags\n");
188 hr
= WbemServices_create( namespace, context
, (void **)ppNamespace
);
192 return WBEM_NO_ERROR
;
197 static const IWbemLocatorVtbl wbem_locator_vtbl
=
199 wbem_locator_QueryInterface
,
201 wbem_locator_Release
,
202 wbem_locator_ConnectServer
205 HRESULT
WbemLocator_create( LPVOID
*ppObj
, REFIID riid
)
209 TRACE("(%p)\n", ppObj
);
211 if ( !IsEqualGUID( riid
, &IID_IWbemLocator
) &&
212 !IsEqualGUID( riid
, &IID_IUnknown
) )
213 return E_NOINTERFACE
;
215 if (!(wl
= malloc( sizeof(*wl
) ))) return E_OUTOFMEMORY
;
217 wl
->IWbemLocator_iface
.lpVtbl
= &wbem_locator_vtbl
;
220 *ppObj
= &wl
->IWbemLocator_iface
;
222 TRACE("returning iface %p\n", *ppObj
);