netstat: Initial implementation.
[wine] / dlls / wmiutils / path.c
1 /*
2  * Copyright 2012 Hans Leidekker for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define COBJMACROS
20
21 #include "config.h"
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "ole2.h"
27 #include "wbemcli.h"
28 #include "wmiutils.h"
29
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32 #include "wmiutils_private.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(wmiutils);
35
36 struct path
37 {
38     IWbemPath IWbemPath_iface;
39     LONG refs;
40     WCHAR *text;
41     int len;
42 };
43
44 static inline struct path *impl_from_IWbemPath( IWbemPath *iface )
45 {
46     return CONTAINING_RECORD(iface, struct path, IWbemPath_iface);
47 }
48
49 static ULONG WINAPI path_AddRef(
50     IWbemPath *iface )
51 {
52     struct path *path = impl_from_IWbemPath( iface );
53     return InterlockedIncrement( &path->refs );
54 }
55
56 static ULONG WINAPI path_Release(
57     IWbemPath *iface )
58 {
59     struct path *path = impl_from_IWbemPath( iface );
60     LONG refs = InterlockedDecrement( &path->refs );
61     if (!refs)
62     {
63         TRACE("destroying %p\n", path);
64         HeapFree( GetProcessHeap(), 0, path->text );
65         HeapFree( GetProcessHeap(), 0, path );
66     }
67     return refs;
68 }
69
70 static HRESULT WINAPI path_QueryInterface(
71     IWbemPath *iface,
72     REFIID riid,
73     void **ppvObject )
74 {
75     struct path *path = impl_from_IWbemPath( iface );
76
77     TRACE("%p, %s, %p\n", path, debugstr_guid( riid ), ppvObject );
78
79     if ( IsEqualGUID( riid, &IID_IWbemPath ) ||
80          IsEqualGUID( riid, &IID_IUnknown ) )
81     {
82         *ppvObject = iface;
83     }
84     else
85     {
86         FIXME("interface %s not implemented\n", debugstr_guid(riid));
87         return E_NOINTERFACE;
88     }
89     IWbemPath_AddRef( iface );
90     return S_OK;
91 }
92
93 static HRESULT WINAPI path_SetText(
94     IWbemPath *iface,
95     ULONG uMode,
96     LPCWSTR pszPath)
97 {
98     struct path *path = impl_from_IWbemPath( iface );
99     int len;
100
101     TRACE("%p, %u, %s\n", iface, uMode, debugstr_w(pszPath));
102
103     if (uMode) FIXME("igoring mode %u\n", uMode);
104
105     len = strlenW( pszPath );
106     if (!(path->text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) )))
107         return E_OUTOFMEMORY;
108
109     strcpyW( path->text, pszPath );
110     path->len = len;
111     return S_OK;
112 }
113
114 static HRESULT WINAPI path_GetText(
115     IWbemPath *iface,
116     LONG lFlags,
117     ULONG *puBufferLength,
118     LPWSTR pszText)
119 {
120     struct path *path = impl_from_IWbemPath( iface );
121
122     TRACE("%p, 0x%x, %p, %p\n", iface, lFlags, puBufferLength, pszText);
123
124     if (lFlags != WBEMPATH_GET_ORIGINAL)
125     {
126         FIXME("flags 0x%x not supported\n", lFlags);
127         return WBEM_E_INVALID_PARAMETER;
128     }
129     if (*puBufferLength < path->len + 1)
130     {
131         *puBufferLength = path->len + 1;
132         return S_OK;
133     }
134     if (pszText) strcpyW( pszText, path->text );
135     *puBufferLength = path->len + 1;
136     return S_OK;
137 }
138
139 static HRESULT WINAPI path_GetInfo(
140     IWbemPath *iface,
141     ULONG uRequestedInfo,
142     ULONGLONG *puResponse)
143 {
144     FIXME("%p, %d, %p\n", iface, uRequestedInfo, puResponse);
145     return E_NOTIMPL;
146 }
147
148 static HRESULT WINAPI path_SetServer(
149     IWbemPath *iface,
150     LPCWSTR Name)
151 {
152     FIXME("%p, %s\n", iface, debugstr_w(Name));
153     return E_NOTIMPL;
154 }
155
156 static HRESULT WINAPI path_GetServer(
157     IWbemPath *iface,
158     ULONG *puNameBufLength,
159     LPWSTR pName)
160 {
161     FIXME("%p, %p, %p\n", iface, puNameBufLength, pName);
162     return E_NOTIMPL;
163 }
164
165 static HRESULT WINAPI path_GetNamespaceCount(
166     IWbemPath *iface,
167     ULONG *puCount)
168 {
169     FIXME("%p, %p\n", iface, puCount);
170     return E_NOTIMPL;
171 }
172
173 static HRESULT WINAPI path_SetNamespaceAt(
174     IWbemPath *iface,
175     ULONG uIndex,
176     LPCWSTR pszName)
177 {
178     FIXME("%p, %u, %s\n", iface, uIndex, debugstr_w(pszName));
179     return E_NOTIMPL;
180 }
181
182 static HRESULT WINAPI path_GetNamespaceAt(
183     IWbemPath *iface,
184     ULONG uIndex,
185     ULONG *puNameBufLength,
186     LPWSTR pName)
187 {
188     FIXME("%p, %u, %p, %p\n", iface, uIndex, puNameBufLength, pName);
189     return E_NOTIMPL;
190 }
191
192 static HRESULT WINAPI path_RemoveNamespaceAt(
193     IWbemPath *iface,
194     ULONG uIndex)
195 {
196     FIXME("%p, %u\n", iface, uIndex);
197     return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI path_RemoveAllNamespaces(
201         IWbemPath *iface)
202 {
203     FIXME("%p\n", iface);
204     return E_NOTIMPL;
205 }
206
207 static HRESULT WINAPI path_GetScopeCount(
208         IWbemPath *iface,
209         ULONG *puCount)
210 {
211     FIXME("%p, %p\n", iface, puCount);
212     return E_NOTIMPL;
213 }
214
215 static HRESULT WINAPI path_SetScope(
216     IWbemPath *iface,
217     ULONG uIndex,
218     LPWSTR pszClass)
219 {
220     FIXME("%p, %u, %s\n", iface, uIndex, debugstr_w(pszClass));
221     return E_NOTIMPL;
222 }
223
224 static HRESULT WINAPI path_SetScopeFromText(
225     IWbemPath *iface,
226     ULONG uIndex,
227     LPWSTR pszText)
228 {
229     FIXME("%p, %u, %s\n", iface, uIndex, debugstr_w(pszText));
230     return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI path_GetScope(
234     IWbemPath *iface,
235     ULONG uIndex,
236     ULONG *puClassNameBufSize,
237     LPWSTR pszClass,
238     IWbemPathKeyList **pKeyList)
239 {
240     FIXME("%p, %u, %p, %p, %p\n", iface, uIndex, puClassNameBufSize, pszClass, pKeyList);
241     return E_NOTIMPL;
242 }
243
244 static HRESULT WINAPI path_GetScopeAsText(
245     IWbemPath *iface,
246     ULONG uIndex,
247     ULONG *puTextBufSize,
248     LPWSTR pszText)
249 {
250     FIXME("%p, %u, %p, %p\n", iface, uIndex, puTextBufSize, pszText);
251     return E_NOTIMPL;
252 }
253
254 static HRESULT WINAPI path_RemoveScope(
255     IWbemPath *iface,
256     ULONG uIndex)
257 {
258     FIXME("%p, %u\n", iface, uIndex);
259     return E_NOTIMPL;
260 }
261
262 static HRESULT WINAPI path_RemoveAllScopes(
263     IWbemPath *iface)
264 {
265     FIXME("%p\n", iface);
266     return E_NOTIMPL;
267 }
268
269 static HRESULT WINAPI path_SetClassName(
270     IWbemPath *iface,
271     LPCWSTR Name)
272 {
273     FIXME("%p, %s\n", iface, debugstr_w(Name));
274     return E_NOTIMPL;
275 }
276
277 static HRESULT WINAPI path_GetClassName(
278     IWbemPath *iface,
279     ULONG *puBufferLength,
280     LPWSTR pszName)
281 {
282     FIXME("%p,%p, %p\n", iface, puBufferLength, pszName);
283     return E_NOTIMPL;
284 }
285
286 static HRESULT WINAPI path_GetKeyList(
287     IWbemPath *iface,
288     IWbemPathKeyList **pOut)
289 {
290     FIXME("%p, %p\n", iface, pOut);
291     return E_NOTIMPL;
292 }
293
294 static HRESULT WINAPI path_CreateClassPart(
295     IWbemPath *iface,
296     LONG lFlags,
297     LPCWSTR Name)
298 {
299     FIXME("%p, 0x%x, %s\n", iface, lFlags, debugstr_w(Name));
300     return E_NOTIMPL;
301 }
302
303 static HRESULT WINAPI path_DeleteClassPart(
304     IWbemPath *iface,
305     LONG lFlags)
306 {
307     FIXME("%p, 0x%x\n", iface, lFlags);
308     return E_NOTIMPL;
309 }
310
311 static BOOL WINAPI path_IsRelative(
312     IWbemPath *iface,
313     LPWSTR wszMachine,
314     LPWSTR wszNamespace)
315 {
316     FIXME("%p, %s, %s\n", iface, debugstr_w(wszMachine), debugstr_w(wszNamespace));
317     return E_NOTIMPL;
318 }
319
320 static BOOL WINAPI path_IsRelativeOrChild(
321     IWbemPath *iface,
322     LPWSTR wszMachine,
323     LPWSTR wszNamespace,
324     LONG lFlags)
325 {
326     FIXME("%p, %s, %s, 0x%x\n", iface, debugstr_w(wszMachine), debugstr_w(wszNamespace), lFlags);
327     return E_NOTIMPL;
328 }
329
330 static BOOL WINAPI path_IsLocal(
331     IWbemPath *iface,
332     LPCWSTR wszMachine)
333 {
334     FIXME("%p, %s\n", iface, debugstr_w(wszMachine));
335     return E_NOTIMPL;
336 }
337
338 static BOOL WINAPI path_IsSameClassName(
339     IWbemPath *iface,
340     LPCWSTR wszClass)
341 {
342     FIXME("%p, %s\n", iface, debugstr_w(wszClass));
343     return E_NOTIMPL;
344 }
345
346 static const struct IWbemPathVtbl path_vtbl =
347 {
348     path_QueryInterface,
349     path_AddRef,
350     path_Release,
351     path_SetText,
352     path_GetText,
353     path_GetInfo,
354     path_SetServer,
355     path_GetServer,
356     path_GetNamespaceCount,
357     path_SetNamespaceAt,
358     path_GetNamespaceAt,
359     path_RemoveNamespaceAt,
360     path_RemoveAllNamespaces,
361     path_GetScopeCount,
362     path_SetScope,
363     path_SetScopeFromText,
364     path_GetScope,
365     path_GetScopeAsText,
366     path_RemoveScope,
367     path_RemoveAllScopes,
368     path_SetClassName,
369     path_GetClassName,
370     path_GetKeyList,
371     path_CreateClassPart,
372     path_DeleteClassPart,
373     path_IsRelative,
374     path_IsRelativeOrChild,
375     path_IsLocal,
376     path_IsSameClassName
377 };
378
379 HRESULT WbemPath_create( IUnknown *pUnkOuter, LPVOID *ppObj )
380 {
381     struct path *path;
382
383     TRACE("%p, %p\n", pUnkOuter, ppObj);
384
385     if (!(path = HeapAlloc( GetProcessHeap(), 0, sizeof(*path) ))) return E_OUTOFMEMORY;
386
387     path->IWbemPath_iface.lpVtbl = &path_vtbl;
388     path->refs = 1;
389
390     *ppObj = &path->IWbemPath_iface;
391
392     TRACE("returning iface %p\n", *ppObj);
393     return S_OK;
394 }