Implement IsTokenRestricted.
[wine] / dlls / dxdiagn / container.c
1 /* 
2  * IDxDiagContainer Implementation
3  * 
4  * Copyright 2004 Raphael Junqueira
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "config.h"
23 #include "dxdiag_private.h"
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
28
29 /* IDxDiagContainer IUnknown parts follow: */
30 HRESULT WINAPI IDxDiagContainerImpl_QueryInterface(PDXDIAGCONTAINER iface, REFIID riid, LPVOID *ppobj)
31 {
32     IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
33
34     if (IsEqualGUID(riid, &IID_IUnknown)
35         || IsEqualGUID(riid, &IID_IDxDiagContainer)) {
36         IDxDiagContainerImpl_AddRef(iface);
37         *ppobj = This;
38         return S_OK;
39     }
40
41     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
42     return E_NOINTERFACE;
43 }
44
45 ULONG WINAPI IDxDiagContainerImpl_AddRef(PDXDIAGCONTAINER iface) {
46     IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
47     ULONG refCount = InterlockedIncrement(&This->ref);
48
49     TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
50
51     DXDIAGN_LockModule();
52
53     return refCount;
54 }
55
56 ULONG WINAPI IDxDiagContainerImpl_Release(PDXDIAGCONTAINER iface) {
57     IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
58     ULONG refCount = InterlockedDecrement(&This->ref);
59
60     TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
61
62     if (!refCount) {
63         HeapFree(GetProcessHeap(), 0, This);
64     }
65
66     DXDIAGN_UnlockModule();
67     
68     return refCount;
69 }
70
71 /* IDxDiagContainer Interface follow: */
72 HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfChildContainers(PDXDIAGCONTAINER iface, DWORD* pdwCount) {
73   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
74   TRACE("(%p)\n", iface);
75   if (NULL == pdwCount) {
76     return E_INVALIDARG;
77   }
78   *pdwCount = This->nSubContainers;
79   return S_OK;
80 }
81
82 HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer) {
83   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
84   IDxDiagContainerImpl_SubContainer* p = NULL;
85   DWORD i = 0;
86   
87   TRACE("(%p, %lu, %s, %lu)\n", iface, dwIndex, debugstr_w(pwszContainer), cchContainer);
88
89   if (NULL == pwszContainer) {
90     return E_INVALIDARG;
91   }
92   if (256 > cchContainer) {
93     return DXDIAG_E_INSUFFICIENT_BUFFER;
94   }
95   
96   p = This->subContainers;
97   while (NULL != p) {
98     if (dwIndex == i) {  
99       if (cchContainer <= strlenW(p->contName)) {
100         return DXDIAG_E_INSUFFICIENT_BUFFER;
101       }
102       lstrcpynW(pwszContainer, p->contName, cchContainer);
103       return S_OK;
104     }
105     p = p->next;
106     ++i;
107   }  
108   return E_INVALIDARG;
109 }
110
111 HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER iface, LPCWSTR pwszContainer, IDxDiagContainer** ppInstance) {
112   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
113   IDxDiagContainerImpl_SubContainer* p = NULL;
114
115   FIXME("(%p, %s, %p)\n", iface, debugstr_w(pwszContainer), ppInstance);
116
117   if (NULL == ppInstance || NULL == pwszContainer) {
118     return E_INVALIDARG;
119   }
120
121   p = This->subContainers;
122   while (NULL != p) {
123     if (0 == lstrcmpW(p->contName, pwszContainer)) {      
124       IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)p->pCont, &IID_IDxDiagContainer, (void**) ppInstance);
125       /*TRACE"(%p) returns %p\n", iface, *ppInstance);*/
126       return S_OK;
127     }
128     p = p->next;
129   }
130
131   return E_INVALIDARG;
132 }
133
134 HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfProps(PDXDIAGCONTAINER iface, DWORD* pdwCount) {
135   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
136   TRACE("(%p)\n", iface);
137   if (NULL == pdwCount) {
138     return E_INVALIDARG;
139   }
140   *pdwCount = This->nProperties;
141   return S_OK;
142 }
143
144 HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszPropName, DWORD cchPropName) {
145   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
146   IDxDiagContainerImpl_Property* p = NULL;
147   DWORD i = 0;
148   
149   FIXME("(%p, %lu, %s, %lu)\n", iface, dwIndex, debugstr_w(pwszPropName), cchPropName);
150
151   if (NULL == pwszPropName) {
152     return E_INVALIDARG;
153   }
154   if (256 > cchPropName) {
155     return DXDIAG_E_INSUFFICIENT_BUFFER;
156   }
157   
158   p = This->properties;
159   while (NULL != p) {
160     if (dwIndex == i) {  
161       if (cchPropName <= lstrlenW(p->vName)) {
162         return DXDIAG_E_INSUFFICIENT_BUFFER;
163       }
164       lstrcpynW(pwszPropName, p->vName, cchPropName);
165       return S_OK;
166     }
167     p = p->next;
168     ++i;
169   }  
170   return E_INVALIDARG;
171 }
172
173 HRESULT WINAPI IDxDiagContainerImpl_GetProp(PDXDIAGCONTAINER iface, LPCWSTR pwszPropName, VARIANT* pvarProp) {
174   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
175   IDxDiagContainerImpl_Property* p = NULL;
176   FIXME("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pvarProp);
177
178   if (NULL == pvarProp || NULL == pwszPropName) {
179     return E_INVALIDARG;
180   }
181
182   p = This->properties;
183   while (NULL != p) {
184     if (0 == lstrcmpW(p->vName, pwszPropName)) {      
185       VariantCopy(pvarProp, &p->v);
186       return S_OK;
187     }
188     p = p->next;
189   }
190   return S_OK;
191 }
192
193 HRESULT WINAPI IDxDiagContainerImpl_AddProp(PDXDIAGCONTAINER iface, LPCWSTR pwszPropName, VARIANT* pVarProp) {
194   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
195   IDxDiagContainerImpl_Property* p = NULL;
196   IDxDiagContainerImpl_Property* pNew = NULL;
197
198   FIXME("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pVarProp);
199
200   if (NULL == pVarProp || NULL == pwszPropName) {
201     return E_INVALIDARG;
202   }
203
204   pNew =  HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl_Property));
205   if (NULL == pNew) {
206     return E_OUTOFMEMORY;
207   }
208   VariantInit(&pNew->v);
209   VariantCopy(&pNew->v, pVarProp);
210   pNew->vName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lstrlenW(pwszPropName) * sizeof(WCHAR));
211   lstrcpyW(pNew->vName, pwszPropName);
212   pNew->next = NULL;
213
214   p = This->properties;
215   if (NULL == p) {
216     This->properties = pNew;
217   } else {
218     while (NULL != p->next) {
219       p = p->next;
220     }
221     p->next = pNew;
222   }
223   ++This->nProperties;
224   return S_OK;
225 }
226
227 HRESULT WINAPI IDxDiagContainerImpl_AddChildContainer(PDXDIAGCONTAINER iface, LPCWSTR pszContName, PDXDIAGCONTAINER pSubCont) {
228   IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
229   IDxDiagContainerImpl_SubContainer* p = NULL;
230   IDxDiagContainerImpl_SubContainer* pNew = NULL;
231
232   FIXME("(%p, %s, %p)\n", iface, debugstr_w(pszContName), pSubCont);
233
234   if (NULL == pSubCont || NULL == pszContName) {
235     return E_INVALIDARG;
236   }
237
238   pNew =  HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl_SubContainer));
239   if (NULL == pNew) {
240     return E_OUTOFMEMORY;
241   }
242   pNew->pCont = pSubCont;
243   pNew->contName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lstrlenW(pszContName) * sizeof(WCHAR));
244   lstrcpyW(pNew->contName, pszContName);
245   pNew->next = NULL;
246
247   p = This->subContainers;
248   if (NULL == p) {
249     This->subContainers = pNew;
250   } else {
251     while (NULL != p->next) {
252       p = p->next;
253     }
254     p->next = pNew;
255   }
256   ++This->nSubContainers;
257   return S_OK;
258 }
259
260 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl =
261 {
262     IDxDiagContainerImpl_QueryInterface,
263     IDxDiagContainerImpl_AddRef,
264     IDxDiagContainerImpl_Release,
265     IDxDiagContainerImpl_GetNumberOfChildContainers,
266     IDxDiagContainerImpl_EnumChildContainerNames,
267     IDxDiagContainerImpl_GetChildContainer,
268     IDxDiagContainerImpl_GetNumberOfProps,
269     IDxDiagContainerImpl_EnumPropNames,
270     IDxDiagContainerImpl_GetProp
271 };
272
273
274 HRESULT DXDiag_CreateDXDiagContainer(REFIID riid, LPVOID *ppobj) {
275   IDxDiagContainerImpl* container;
276
277   TRACE("(%p, %p)\n", debugstr_guid(riid), ppobj);
278   
279   container = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl));
280   if (NULL == container) {
281     *ppobj = NULL;
282     return E_OUTOFMEMORY;
283   }
284   container->lpVtbl = &DxDiagContainer_Vtbl;
285   container->ref = 0; /* will be inited with QueryInterface */
286   return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)container, riid, ppobj);
287 }