mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / activeds / pathname.c
blobfbc7984f2e451ab71fa95e9f3a3818f548fb6a49
1 /*
2 * Copyright 2020 Dmitry Timoshkov
4 * This file contains only stubs to get the printui.dll up and running
5 * activeds.dll is much much more than this
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "iads.h"
29 #include "adserr.h"
31 #include "wine/heap.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(activeds);
36 #include "initguid.h"
37 DEFINE_GUID(CLSID_Pathname,0x080d0d78,0xf421,0x11d0,0xa3,0x6e,0x00,0xc0,0x4f,0xb9,0x50,0xdc);
39 typedef struct
41 IADsPathname IADsPathname_iface;
42 LONG ref;
43 BSTR provider, server, dn;
44 } Pathname;
46 static inline Pathname *impl_from_IADsPathname(IADsPathname *iface)
48 return CONTAINING_RECORD(iface, Pathname, IADsPathname_iface);
51 static HRESULT WINAPI path_QueryInterface(IADsPathname *iface, REFIID riid, void **obj)
53 TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
55 if (!riid || !obj) return E_INVALIDARG;
57 if (IsEqualGUID(riid, &IID_IUnknown) ||
58 IsEqualGUID(riid, &IID_IDispatch) ||
59 IsEqualGUID(riid, &IID_IADsPathname))
61 IADsPathname_AddRef(iface);
62 *obj = iface;
63 return S_OK;
66 FIXME("interface %s is not implemented\n", debugstr_guid(riid));
67 return E_NOINTERFACE;
70 static ULONG WINAPI path_AddRef(IADsPathname *iface)
72 Pathname *path = impl_from_IADsPathname(iface);
73 return InterlockedIncrement(&path->ref);
76 static ULONG WINAPI path_Release(IADsPathname *iface)
78 Pathname *path = impl_from_IADsPathname(iface);
79 LONG ref = InterlockedDecrement(&path->ref);
81 if (!ref)
83 TRACE("destroying %p\n", iface);
84 SysFreeString(path->provider);
85 SysFreeString(path->server);
86 SysFreeString(path->dn);
87 heap_free(path);
90 return ref;
93 static HRESULT WINAPI path_GetTypeInfoCount(IADsPathname *iface, UINT *count)
95 FIXME("%p,%p: stub\n", iface, count);
96 return E_NOTIMPL;
99 static HRESULT WINAPI path_GetTypeInfo(IADsPathname *iface, UINT index, LCID lcid, ITypeInfo **info)
101 FIXME("%p,%u,%#x,%p: stub\n", iface, index, lcid, info);
102 return E_NOTIMPL;
105 static HRESULT WINAPI path_GetIDsOfNames(IADsPathname *iface, REFIID riid, LPOLESTR *names,
106 UINT count, LCID lcid, DISPID *dispid)
108 FIXME("%p,%s,%p,%u,%u,%p: stub\n", iface, debugstr_guid(riid), names, count, lcid, dispid);
109 return E_NOTIMPL;
112 static HRESULT WINAPI path_Invoke(IADsPathname *iface, DISPID dispid, REFIID riid, LCID lcid, WORD flags,
113 DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *argerr)
115 FIXME("%p,%d,%s,%04x,%04x,%p,%p,%p,%p: stub\n", iface, dispid, debugstr_guid(riid), lcid, flags,
116 params, result, excepinfo, argerr);
117 return E_NOTIMPL;
120 static HRESULT parse_path(BSTR path, BSTR *provider, BSTR *server, BSTR *dn)
122 WCHAR *p, *p_server;
123 int server_len;
125 *provider = NULL;
126 *server = NULL;
127 *dn = NULL;
129 if (wcsnicmp(path, L"LDAP:", 5) != 0)
130 return E_ADS_BAD_PATHNAME;
132 *provider = SysAllocStringLen(path, 4);
133 if (!*provider) return E_OUTOFMEMORY;
135 p = path + 5;
136 if (!*p) return S_OK;
138 if (*p++ != '/' || *p++ != '/' || !*p)
139 return E_ADS_BAD_PATHNAME;
141 p_server = p;
142 server_len = 0;
143 while (*p && *p != '/')
145 p++;
146 server_len++;
148 if (server_len == 0) return E_ADS_BAD_PATHNAME;
150 *server = SysAllocStringLen(p_server, server_len);
151 if (!*server)
153 SysFreeString(*provider);
154 return E_OUTOFMEMORY;
157 if (!*p) return S_OK;
159 if (*p++ != '/' || !*p)
161 SysFreeString(*provider);
162 SysFreeString(*server);
163 return E_ADS_BAD_PATHNAME;
166 *dn = SysAllocString(p);
167 if (!*dn)
169 SysFreeString(*provider);
170 SysFreeString(*server);
171 return E_OUTOFMEMORY;
174 return S_OK;
177 static HRESULT WINAPI path_Set(IADsPathname *iface, BSTR adspath, LONG type)
179 Pathname *path = impl_from_IADsPathname(iface);
180 HRESULT hr;
181 BSTR provider, server, dn;
183 TRACE("%p,%s,%d\n", iface, debugstr_w(adspath), type);
185 if (!adspath) return E_INVALIDARG;
187 if (type == ADS_SETTYPE_PROVIDER)
189 SysFreeString(path->provider);
190 path->provider = SysAllocString(adspath);
191 return path->provider ? S_OK : E_OUTOFMEMORY;
194 if (type == ADS_SETTYPE_SERVER)
196 SysFreeString(path->server);
197 path->server = SysAllocString(adspath);
198 return path->server ? S_OK : E_OUTOFMEMORY;
201 if (type == ADS_SETTYPE_DN)
203 SysFreeString(path->dn);
204 path->dn = SysAllocString(adspath);
205 return path->dn ? S_OK : E_OUTOFMEMORY;
208 if (type != ADS_SETTYPE_FULL)
210 FIXME("type %d not implemented\n", type);
211 return E_INVALIDARG;
214 hr = parse_path(adspath, &provider, &server, &dn);
215 if (hr == S_OK)
217 SysFreeString(path->provider);
218 SysFreeString(path->server);
219 SysFreeString(path->dn);
221 path->provider = provider;
222 path->server = server;
223 path->dn = dn;
225 return hr;
228 static HRESULT WINAPI path_SetDisplayType(IADsPathname *iface, LONG type)
230 FIXME("%p,%d: stub\n", iface, type);
231 return E_NOTIMPL;
234 static HRESULT WINAPI path_Retrieve(IADsPathname *iface, LONG type, BSTR *adspath)
236 Pathname *path = impl_from_IADsPathname(iface);
237 int len;
239 TRACE("%p,%d,%p\n", iface, type, adspath);
241 if (!adspath) return E_INVALIDARG;
243 switch (type)
245 default:
246 FIXME("type %d not implemented\n", type);
247 /* fall through */
249 case ADS_FORMAT_X500:
250 len = wcslen(path->provider) + 3;
251 if (path->server) len += wcslen(path->server) + 1;
252 if (path->dn) len += wcslen(path->dn);
254 *adspath = SysAllocStringLen(NULL, len);
255 if (!*adspath) break;
257 wcscpy(*adspath, path->provider);
258 wcscat(*adspath, L"://");
259 if (path->server)
261 wcscat(*adspath, path->server);
262 wcscat(*adspath, L"/");
264 if (path->dn) wcscat(*adspath, path->dn);
265 break;
267 case ADS_FORMAT_PROVIDER:
268 *adspath = SysAllocString(path->provider);
269 break;
271 case ADS_FORMAT_SERVER:
272 *adspath = path->provider ? SysAllocString(path->server) : SysAllocStringLen(NULL, 0);
273 break;
275 case ADS_FORMAT_X500_DN:
276 *adspath = path->dn ? SysAllocString(path->dn) : SysAllocStringLen(NULL, 0);
277 break;
279 case ADS_FORMAT_LEAF:
280 if (!path->dn)
281 *adspath = SysAllocStringLen(NULL, 0);
282 else
284 WCHAR *p = wcschr(path->dn, ',');
285 *adspath = p ? SysAllocStringLen(path->dn, p - path->dn) : SysAllocString(path->dn);
287 break;
290 TRACE("=> %s\n", debugstr_w(*adspath));
291 return *adspath ? S_OK : E_OUTOFMEMORY;
294 static HRESULT WINAPI path_GetNumElements(IADsPathname *iface, LONG *count)
296 Pathname *path = impl_from_IADsPathname(iface);
297 WCHAR *p;
299 TRACE("%p,%p\n", iface, count);
301 if (!count) return E_INVALIDARG;
303 *count = 0;
305 p = path->dn;
306 while (p)
308 *count += 1;
309 p = wcschr(p, ',');
310 if (p) p++;
313 return S_OK;
316 static HRESULT WINAPI path_GetElement(IADsPathname *iface, LONG index, BSTR *element)
318 Pathname *path = impl_from_IADsPathname(iface);
319 HRESULT hr;
320 WCHAR *p, *end;
321 LONG count;
323 TRACE("%p,%d,%p\n", iface, index, element);
325 if (!element) return E_INVALIDARG;
327 count = 0;
328 hr = HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
330 p = path->dn;
331 while (p)
333 end = wcschr(p, ',');
335 if (index == count)
337 *element = end ? SysAllocStringLen(p, end - p) : SysAllocString(p);
338 hr = *element ? S_OK : E_OUTOFMEMORY;
339 break;
342 p = end ? end + 1 : NULL;
343 count++;
346 return hr;
349 static HRESULT WINAPI path_AddLeafElement(IADsPathname *iface, BSTR element)
351 FIXME("%p,%s: stub\n", iface, debugstr_w(element));
352 return E_NOTIMPL;
355 static HRESULT WINAPI path_RemoveLeafElement(IADsPathname *iface)
357 FIXME("%p: stub\n", iface);
358 return E_NOTIMPL;
361 static HRESULT WINAPI path_CopyPath(IADsPathname *iface, IDispatch **path)
363 FIXME("%p,%p: stub\n", iface, path);
364 return E_NOTIMPL;
367 static HRESULT WINAPI path_GetEscapedElement(IADsPathname *iface, LONG reserved, BSTR element, BSTR *str)
369 FIXME("%p,%d,%s,%p: stub\n", iface, reserved, debugstr_w(element), str);
370 return E_NOTIMPL;
373 static HRESULT WINAPI path_get_EscapedMode(IADsPathname *iface, LONG *mode)
375 FIXME("%p,%p: stub\n", iface, mode);
376 return E_NOTIMPL;
379 static HRESULT WINAPI path_put_EscapedMode(IADsPathname *iface, LONG mode)
381 FIXME("%p,%d: stub\n", iface, mode);
382 return E_NOTIMPL;
385 static const IADsPathnameVtbl IADsPathname_vtbl =
387 path_QueryInterface,
388 path_AddRef,
389 path_Release,
390 path_GetTypeInfoCount,
391 path_GetTypeInfo,
392 path_GetIDsOfNames,
393 path_Invoke,
394 path_Set,
395 path_SetDisplayType,
396 path_Retrieve,
397 path_GetNumElements,
398 path_GetElement,
399 path_AddLeafElement,
400 path_RemoveLeafElement,
401 path_CopyPath,
402 path_GetEscapedElement,
403 path_get_EscapedMode,
404 path_put_EscapedMode
407 static HRESULT Pathname_create(REFIID riid, void **obj)
409 Pathname *path;
410 HRESULT hr;
412 path = heap_alloc(sizeof(*path));
413 if (!path) return E_OUTOFMEMORY;
415 path->IADsPathname_iface.lpVtbl = &IADsPathname_vtbl;
416 path->ref = 1;
417 path->provider = SysAllocString(L"LDAP");
418 path->server = NULL;
419 path->dn = NULL;
421 hr = IADsPathname_QueryInterface(&path->IADsPathname_iface, riid, obj);
422 IADsPathname_Release(&path->IADsPathname_iface);
424 return hr;
427 static const struct class_info
429 const CLSID *clsid;
430 HRESULT (*constructor)(REFIID, void **);
431 } class_info[] =
433 { &CLSID_Pathname, Pathname_create }
436 typedef struct
438 IClassFactory IClassFactory_iface;
439 LONG ref;
440 const struct class_info *info;
441 } class_factory;
443 static inline class_factory *impl_from_IClassFactory(IClassFactory *iface)
445 return CONTAINING_RECORD(iface, class_factory, IClassFactory_iface);
448 static HRESULT WINAPI factory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *obj)
450 TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
452 if (!riid || !obj) return E_INVALIDARG;
454 if (IsEqualIID(riid, &IID_IUnknown) ||
455 IsEqualIID(riid, &IID_IClassFactory))
457 IClassFactory_AddRef(iface);
458 *obj = iface;
459 return S_OK;
462 *obj = NULL;
463 FIXME("interface %s is not implemented\n", debugstr_guid(riid));
464 return E_NOINTERFACE;
467 static ULONG WINAPI factory_AddRef(IClassFactory *iface)
469 class_factory *factory = impl_from_IClassFactory(iface);
470 ULONG ref = InterlockedIncrement(&factory->ref);
472 TRACE("(%p) ref %u\n", iface, ref);
474 return ref;
477 static ULONG WINAPI factory_Release(IClassFactory *iface)
479 class_factory *factory = impl_from_IClassFactory(iface);
480 ULONG ref = InterlockedDecrement(&factory->ref);
482 TRACE("(%p) ref %u\n", iface, ref);
484 if (!ref)
485 heap_free(factory);
487 return ref;
490 static HRESULT WINAPI factory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **obj)
492 class_factory *factory = impl_from_IClassFactory(iface);
494 TRACE("%p,%s,%p\n", outer, debugstr_guid(riid), obj);
496 if (!riid || !obj) return E_INVALIDARG;
498 *obj = NULL;
499 if (outer) return CLASS_E_NOAGGREGATION;
501 return factory->info->constructor(riid, obj);
504 static HRESULT WINAPI factory_LockServer(IClassFactory *iface, BOOL lock)
506 FIXME("%p,%d: stub\n", iface, lock);
507 return S_OK;
510 static const struct IClassFactoryVtbl factory_vtbl =
512 factory_QueryInterface,
513 factory_AddRef,
514 factory_Release,
515 factory_CreateInstance,
516 factory_LockServer
519 static HRESULT factory_constructor(const struct class_info *info, REFIID riid, void **obj)
521 class_factory *factory;
522 HRESULT hr;
524 factory = heap_alloc(sizeof(*factory));
525 if (!factory) return E_OUTOFMEMORY;
527 factory->IClassFactory_iface.lpVtbl = &factory_vtbl;
528 factory->ref = 1;
529 factory->info = info;
531 hr = IClassFactory_QueryInterface(&factory->IClassFactory_iface, riid, obj);
532 IClassFactory_Release(&factory->IClassFactory_iface);
534 return hr;
537 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *obj)
539 int i;
541 TRACE("%s,%s,%p\n", debugstr_guid(clsid), debugstr_guid(iid), obj);
543 if (!clsid || !iid || !obj) return E_INVALIDARG;
545 *obj = NULL;
547 for (i = 0; i < ARRAY_SIZE(class_info); i++)
549 if (IsEqualCLSID(class_info[i].clsid, clsid))
550 return factory_constructor(&class_info[i], iid, obj);
553 FIXME("class %s/%s is not implemented\n", debugstr_guid(clsid), debugstr_guid(iid));
554 return CLASS_E_CLASSNOTAVAILABLE;