mountmgr.sys: Ensure unixlib function tables and enum stay in sync.
[wine.git] / dlls / activeds / pathname.c
blob8142e47e244a7b1c52c346903a7fa4c9efe9f6ee
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/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(activeds);
35 #include "initguid.h"
36 DEFINE_GUID(CLSID_Pathname,0x080d0d78,0xf421,0x11d0,0xa3,0x6e,0x00,0xc0,0x4f,0xb9,0x50,0xdc);
38 typedef struct
40 IADsPathname IADsPathname_iface;
41 LONG ref;
42 BSTR provider, server, dn;
43 } Pathname;
45 static inline Pathname *impl_from_IADsPathname(IADsPathname *iface)
47 return CONTAINING_RECORD(iface, Pathname, IADsPathname_iface);
50 static HRESULT WINAPI path_QueryInterface(IADsPathname *iface, REFIID riid, void **obj)
52 TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
54 if (!riid || !obj) return E_INVALIDARG;
56 if (IsEqualGUID(riid, &IID_IUnknown) ||
57 IsEqualGUID(riid, &IID_IDispatch) ||
58 IsEqualGUID(riid, &IID_IADsPathname))
60 IADsPathname_AddRef(iface);
61 *obj = iface;
62 return S_OK;
65 FIXME("interface %s is not implemented\n", debugstr_guid(riid));
66 return E_NOINTERFACE;
69 static ULONG WINAPI path_AddRef(IADsPathname *iface)
71 Pathname *path = impl_from_IADsPathname(iface);
72 return InterlockedIncrement(&path->ref);
75 static ULONG WINAPI path_Release(IADsPathname *iface)
77 Pathname *path = impl_from_IADsPathname(iface);
78 LONG ref = InterlockedDecrement(&path->ref);
80 if (!ref)
82 TRACE("destroying %p\n", iface);
83 SysFreeString(path->provider);
84 SysFreeString(path->server);
85 SysFreeString(path->dn);
86 free(path);
89 return ref;
92 static HRESULT WINAPI path_GetTypeInfoCount(IADsPathname *iface, UINT *count)
94 FIXME("%p,%p: stub\n", iface, count);
95 return E_NOTIMPL;
98 static HRESULT WINAPI path_GetTypeInfo(IADsPathname *iface, UINT index, LCID lcid, ITypeInfo **info)
100 FIXME("%p,%u,%#lx,%p: stub\n", iface, index, lcid, info);
101 return E_NOTIMPL;
104 static HRESULT WINAPI path_GetIDsOfNames(IADsPathname *iface, REFIID riid, LPOLESTR *names,
105 UINT count, LCID lcid, DISPID *dispid)
107 FIXME("%p,%s,%p,%u,%lu,%p: stub\n", iface, debugstr_guid(riid), names, count, lcid, dispid);
108 return E_NOTIMPL;
111 static HRESULT WINAPI path_Invoke(IADsPathname *iface, DISPID dispid, REFIID riid, LCID lcid, WORD flags,
112 DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *argerr)
114 FIXME("%p,%ld,%s,%04lx,%04x,%p,%p,%p,%p: stub\n", iface, dispid, debugstr_guid(riid), lcid, flags,
115 params, result, excepinfo, argerr);
116 return E_NOTIMPL;
119 static HRESULT parse_path(BSTR path, BSTR *provider, BSTR *server, BSTR *dn)
121 WCHAR *p, *p_server;
122 int server_len;
124 *provider = NULL;
125 *server = NULL;
126 *dn = NULL;
128 if (wcsnicmp(path, L"LDAP:", 5) != 0)
129 return E_ADS_BAD_PATHNAME;
131 *provider = SysAllocStringLen(path, 4);
132 if (!*provider) return E_OUTOFMEMORY;
134 p = path + 5;
135 if (!*p) return S_OK;
137 if (*p++ != '/' || *p++ != '/' || !*p)
139 SysFreeString(*provider);
140 return E_ADS_BAD_PATHNAME;
143 p_server = p;
144 server_len = 0;
145 while (*p && *p != '/')
147 p++;
148 server_len++;
150 if (server_len == 0)
152 SysFreeString(*provider);
153 return E_ADS_BAD_PATHNAME;
156 *server = SysAllocStringLen(p_server, server_len);
157 if (!*server)
159 SysFreeString(*provider);
160 return E_OUTOFMEMORY;
163 if (!*p) return S_OK;
165 if (*p++ != '/' || !*p)
167 SysFreeString(*provider);
168 SysFreeString(*server);
169 return E_ADS_BAD_PATHNAME;
172 *dn = SysAllocString(p);
173 if (!*dn)
175 SysFreeString(*provider);
176 SysFreeString(*server);
177 return E_OUTOFMEMORY;
180 return S_OK;
183 static HRESULT WINAPI path_Set(IADsPathname *iface, BSTR adspath, LONG type)
185 Pathname *path = impl_from_IADsPathname(iface);
186 HRESULT hr;
187 BSTR provider, server, dn;
189 TRACE("%p,%s,%ld\n", iface, debugstr_w(adspath), type);
191 if (!adspath) return E_INVALIDARG;
193 if (type == ADS_SETTYPE_PROVIDER)
195 SysFreeString(path->provider);
196 path->provider = SysAllocString(adspath);
197 return path->provider ? S_OK : E_OUTOFMEMORY;
200 if (type == ADS_SETTYPE_SERVER)
202 SysFreeString(path->server);
203 path->server = SysAllocString(adspath);
204 return path->server ? S_OK : E_OUTOFMEMORY;
207 if (type == ADS_SETTYPE_DN)
209 SysFreeString(path->dn);
210 path->dn = SysAllocString(adspath);
211 return path->dn ? S_OK : E_OUTOFMEMORY;
214 if (type != ADS_SETTYPE_FULL)
216 FIXME("type %ld not implemented\n", type);
217 return E_INVALIDARG;
220 hr = parse_path(adspath, &provider, &server, &dn);
221 if (hr == S_OK)
223 SysFreeString(path->provider);
224 SysFreeString(path->server);
225 SysFreeString(path->dn);
227 path->provider = provider;
228 path->server = server;
229 path->dn = dn;
231 return hr;
234 static HRESULT WINAPI path_SetDisplayType(IADsPathname *iface, LONG type)
236 FIXME("%p,%ld: stub\n", iface, type);
237 return E_NOTIMPL;
240 static HRESULT WINAPI path_Retrieve(IADsPathname *iface, LONG type, BSTR *adspath)
242 Pathname *path = impl_from_IADsPathname(iface);
243 int len;
245 TRACE("%p,%ld,%p\n", iface, type, adspath);
247 if (!adspath) return E_INVALIDARG;
249 switch (type)
251 default:
252 FIXME("type %ld not implemented\n", type);
253 /* fall through */
255 case ADS_FORMAT_X500:
256 len = wcslen(path->provider) + 3;
257 if (path->server) len += wcslen(path->server) + 1;
258 if (path->dn) len += wcslen(path->dn);
260 *adspath = SysAllocStringLen(NULL, len);
261 if (!*adspath) break;
263 wcscpy(*adspath, path->provider);
264 wcscat(*adspath, L"://");
265 if (path->server)
267 wcscat(*adspath, path->server);
268 wcscat(*adspath, L"/");
270 if (path->dn) wcscat(*adspath, path->dn);
271 break;
273 case ADS_FORMAT_PROVIDER:
274 *adspath = SysAllocString(path->provider);
275 break;
277 case ADS_FORMAT_SERVER:
278 *adspath = path->provider ? SysAllocString(path->server) : SysAllocStringLen(NULL, 0);
279 break;
281 case ADS_FORMAT_X500_DN:
282 *adspath = path->dn ? SysAllocString(path->dn) : SysAllocStringLen(NULL, 0);
283 break;
285 case ADS_FORMAT_LEAF:
286 if (!path->dn)
287 *adspath = SysAllocStringLen(NULL, 0);
288 else
290 WCHAR *p = wcschr(path->dn, ',');
291 *adspath = p ? SysAllocStringLen(path->dn, p - path->dn) : SysAllocString(path->dn);
293 break;
296 TRACE("=> %s\n", debugstr_w(*adspath));
297 return *adspath ? S_OK : E_OUTOFMEMORY;
300 static HRESULT WINAPI path_GetNumElements(IADsPathname *iface, LONG *count)
302 Pathname *path = impl_from_IADsPathname(iface);
303 WCHAR *p;
305 TRACE("%p,%p\n", iface, count);
307 if (!count) return E_INVALIDARG;
309 *count = 0;
311 p = path->dn;
312 while (p)
314 *count += 1;
315 p = wcschr(p, ',');
316 if (p) p++;
319 return S_OK;
322 static HRESULT WINAPI path_GetElement(IADsPathname *iface, LONG index, BSTR *element)
324 Pathname *path = impl_from_IADsPathname(iface);
325 HRESULT hr;
326 WCHAR *p, *end;
327 LONG count;
329 TRACE("%p,%ld,%p\n", iface, index, element);
331 if (!element) return E_INVALIDARG;
333 count = 0;
334 hr = HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
336 p = path->dn;
337 while (p)
339 end = wcschr(p, ',');
341 if (index == count)
343 *element = end ? SysAllocStringLen(p, end - p) : SysAllocString(p);
344 hr = *element ? S_OK : E_OUTOFMEMORY;
345 break;
348 p = end ? end + 1 : NULL;
349 count++;
352 return hr;
355 static HRESULT WINAPI path_AddLeafElement(IADsPathname *iface, BSTR element)
357 FIXME("%p,%s: stub\n", iface, debugstr_w(element));
358 return E_NOTIMPL;
361 static HRESULT WINAPI path_RemoveLeafElement(IADsPathname *iface)
363 FIXME("%p: stub\n", iface);
364 return E_NOTIMPL;
367 static HRESULT WINAPI path_CopyPath(IADsPathname *iface, IDispatch **path)
369 FIXME("%p,%p: stub\n", iface, path);
370 return E_NOTIMPL;
373 static HRESULT WINAPI path_GetEscapedElement(IADsPathname *iface, LONG reserved, BSTR element, BSTR *str)
375 FIXME("%p,%ld,%s,%p: stub\n", iface, reserved, debugstr_w(element), str);
376 return E_NOTIMPL;
379 static HRESULT WINAPI path_get_EscapedMode(IADsPathname *iface, LONG *mode)
381 FIXME("%p,%p: stub\n", iface, mode);
382 return E_NOTIMPL;
385 static HRESULT WINAPI path_put_EscapedMode(IADsPathname *iface, LONG mode)
387 FIXME("%p,%ld: stub\n", iface, mode);
388 return E_NOTIMPL;
391 static const IADsPathnameVtbl IADsPathname_vtbl =
393 path_QueryInterface,
394 path_AddRef,
395 path_Release,
396 path_GetTypeInfoCount,
397 path_GetTypeInfo,
398 path_GetIDsOfNames,
399 path_Invoke,
400 path_Set,
401 path_SetDisplayType,
402 path_Retrieve,
403 path_GetNumElements,
404 path_GetElement,
405 path_AddLeafElement,
406 path_RemoveLeafElement,
407 path_CopyPath,
408 path_GetEscapedElement,
409 path_get_EscapedMode,
410 path_put_EscapedMode
413 static HRESULT Pathname_create(REFIID riid, void **obj)
415 Pathname *path;
416 HRESULT hr;
418 path = malloc(sizeof(*path));
419 if (!path) return E_OUTOFMEMORY;
421 path->IADsPathname_iface.lpVtbl = &IADsPathname_vtbl;
422 path->ref = 1;
423 path->provider = SysAllocString(L"LDAP");
424 path->server = NULL;
425 path->dn = NULL;
427 hr = IADsPathname_QueryInterface(&path->IADsPathname_iface, riid, obj);
428 IADsPathname_Release(&path->IADsPathname_iface);
430 return hr;
433 static const struct class_info
435 const CLSID *clsid;
436 HRESULT (*constructor)(REFIID, void **);
437 } class_info[] =
439 { &CLSID_Pathname, Pathname_create }
442 typedef struct
444 IClassFactory IClassFactory_iface;
445 LONG ref;
446 const struct class_info *info;
447 } class_factory;
449 static inline class_factory *impl_from_IClassFactory(IClassFactory *iface)
451 return CONTAINING_RECORD(iface, class_factory, IClassFactory_iface);
454 static HRESULT WINAPI factory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *obj)
456 TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
458 if (!riid || !obj) return E_INVALIDARG;
460 if (IsEqualIID(riid, &IID_IUnknown) ||
461 IsEqualIID(riid, &IID_IClassFactory))
463 IClassFactory_AddRef(iface);
464 *obj = iface;
465 return S_OK;
468 *obj = NULL;
469 FIXME("interface %s is not implemented\n", debugstr_guid(riid));
470 return E_NOINTERFACE;
473 static ULONG WINAPI factory_AddRef(IClassFactory *iface)
475 class_factory *factory = impl_from_IClassFactory(iface);
476 ULONG ref = InterlockedIncrement(&factory->ref);
478 TRACE("(%p) ref %lu\n", iface, ref);
480 return ref;
483 static ULONG WINAPI factory_Release(IClassFactory *iface)
485 class_factory *factory = impl_from_IClassFactory(iface);
486 ULONG ref = InterlockedDecrement(&factory->ref);
488 TRACE("(%p) ref %lu\n", iface, ref);
490 if (!ref)
491 free(factory);
493 return ref;
496 static HRESULT WINAPI factory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **obj)
498 class_factory *factory = impl_from_IClassFactory(iface);
500 TRACE("%p,%s,%p\n", outer, debugstr_guid(riid), obj);
502 if (!riid || !obj) return E_INVALIDARG;
504 *obj = NULL;
505 if (outer) return CLASS_E_NOAGGREGATION;
507 return factory->info->constructor(riid, obj);
510 static HRESULT WINAPI factory_LockServer(IClassFactory *iface, BOOL lock)
512 FIXME("%p,%d: stub\n", iface, lock);
513 return S_OK;
516 static const struct IClassFactoryVtbl factory_vtbl =
518 factory_QueryInterface,
519 factory_AddRef,
520 factory_Release,
521 factory_CreateInstance,
522 factory_LockServer
525 static HRESULT factory_constructor(const struct class_info *info, REFIID riid, void **obj)
527 class_factory *factory;
528 HRESULT hr;
530 factory = malloc(sizeof(*factory));
531 if (!factory) return E_OUTOFMEMORY;
533 factory->IClassFactory_iface.lpVtbl = &factory_vtbl;
534 factory->ref = 1;
535 factory->info = info;
537 hr = IClassFactory_QueryInterface(&factory->IClassFactory_iface, riid, obj);
538 IClassFactory_Release(&factory->IClassFactory_iface);
540 return hr;
543 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID *obj)
545 int i;
547 TRACE("%s,%s,%p\n", debugstr_guid(clsid), debugstr_guid(iid), obj);
549 if (!clsid || !iid || !obj) return E_INVALIDARG;
551 *obj = NULL;
553 for (i = 0; i < ARRAY_SIZE(class_info); i++)
555 if (IsEqualCLSID(class_info[i].clsid, clsid))
556 return factory_constructor(&class_info[i], iid, obj);
559 FIXME("class %s/%s is not implemented\n", debugstr_guid(clsid), debugstr_guid(iid));
560 return CLASS_E_CLASSNOTAVAILABLE;