2014-01-28 03:54:29 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Dmitry Timoshkov
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "taskschd.h"
|
2014-04-07 06:14:33 +02:00
|
|
|
#include "schrpc.h"
|
2014-01-28 03:54:29 +01:00
|
|
|
#include "taskschd_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(taskschd);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ITaskFolderCollection ITaskFolderCollection_iface;
|
|
|
|
LONG ref;
|
2014-01-28 03:54:41 +01:00
|
|
|
WCHAR *path;
|
2014-04-07 06:14:33 +02:00
|
|
|
TASK_NAMES list;
|
|
|
|
DWORD count;
|
2014-01-28 03:54:29 +01:00
|
|
|
} TaskFolderCollection;
|
|
|
|
|
2014-01-28 03:54:48 +01:00
|
|
|
static HRESULT NewEnum_create(TaskFolderCollection *folders, IUnknown **obj);
|
|
|
|
|
2014-01-28 03:54:29 +01:00
|
|
|
static inline TaskFolderCollection *impl_from_ITaskFolderCollection(ITaskFolderCollection *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, TaskFolderCollection, ITaskFolderCollection_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI folders_AddRef(ITaskFolderCollection *iface)
|
|
|
|
{
|
|
|
|
TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
|
|
|
|
return InterlockedIncrement(&folders->ref);
|
|
|
|
}
|
|
|
|
|
2014-04-07 06:14:33 +02:00
|
|
|
static void free_list(LPWSTR *list, DWORD count)
|
2014-01-28 03:54:41 +01:00
|
|
|
{
|
|
|
|
LONG i;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2014-04-07 06:14:33 +02:00
|
|
|
MIDL_user_free(list[i]);
|
2014-01-28 03:54:41 +01:00
|
|
|
|
2014-04-07 06:14:33 +02:00
|
|
|
MIDL_user_free(list);
|
2014-01-28 03:54:41 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 03:54:29 +01:00
|
|
|
static ULONG WINAPI folders_Release(ITaskFolderCollection *iface)
|
|
|
|
{
|
|
|
|
TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&folders->ref);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
TRACE("destroying %p\n", iface);
|
2014-01-28 03:54:41 +01:00
|
|
|
free_list(folders->list, folders->count);
|
|
|
|
heap_free(folders->path);
|
2014-01-28 03:54:36 +01:00
|
|
|
heap_free(folders);
|
2014-01-28 03:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI folders_QueryInterface(ITaskFolderCollection *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (!riid || !obj) return E_INVALIDARG;
|
|
|
|
|
|
|
|
TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_ITaskFolderCollection) ||
|
|
|
|
IsEqualGUID(riid, &IID_IDispatch) ||
|
|
|
|
IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
ITaskFolderCollection_AddRef(iface);
|
|
|
|
*obj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("interface %s is not implemented\n", debugstr_guid(riid));
|
2014-02-05 07:09:11 +01:00
|
|
|
*obj = NULL;
|
2014-01-28 03:54:29 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI folders_GetTypeInfoCount(ITaskFolderCollection *iface, UINT *count)
|
|
|
|
{
|
|
|
|
FIXME("%p,%p: stub\n", iface, count);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI folders_GetTypeInfo(ITaskFolderCollection *iface, UINT index, LCID lcid, ITypeInfo **info)
|
|
|
|
{
|
2022-02-18 09:17:22 +01:00
|
|
|
FIXME("%p,%u,%lu,%p: stub\n", iface, index, lcid, info);
|
2014-01-28 03:54:29 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI folders_GetIDsOfNames(ITaskFolderCollection *iface, REFIID riid, LPOLESTR *names,
|
|
|
|
UINT count, LCID lcid, DISPID *dispid)
|
|
|
|
{
|
2022-02-18 09:17:22 +01:00
|
|
|
FIXME("%p,%s,%p,%u,%lu,%p: stub\n", iface, debugstr_guid(riid), names, count, lcid, dispid);
|
2014-01-28 03:54:29 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI folders_Invoke(ITaskFolderCollection *iface, DISPID dispid, REFIID riid, LCID lcid, WORD flags,
|
|
|
|
DISPPARAMS *params, VARIANT *result, EXCEPINFO *excepinfo, UINT *argerr)
|
|
|
|
{
|
2022-02-18 09:17:22 +01:00
|
|
|
FIXME("%p,%ld,%s,%04lx,%04x,%p,%p,%p,%p: stub\n", iface, dispid, debugstr_guid(riid), lcid, flags,
|
2014-01-28 03:54:29 +01:00
|
|
|
params, result, excepinfo, argerr);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI folders_get_Count(ITaskFolderCollection *iface, LONG *count)
|
|
|
|
{
|
2014-01-28 03:54:45 +01:00
|
|
|
TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
|
|
|
|
|
|
|
|
TRACE("%p,%p\n", iface, count);
|
|
|
|
|
|
|
|
if (!count) return E_POINTER;
|
|
|
|
|
|
|
|
*count = folders->count;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG get_var_int(const VARIANT *var)
|
|
|
|
{
|
|
|
|
switch(V_VT(var))
|
|
|
|
{
|
|
|
|
case VT_I1:
|
|
|
|
case VT_UI1:
|
|
|
|
return V_UI1(var);
|
|
|
|
|
|
|
|
case VT_I2:
|
|
|
|
case VT_UI2:
|
|
|
|
return V_UI2(var);
|
|
|
|
|
|
|
|
case VT_I4:
|
|
|
|
case VT_UI4:
|
|
|
|
return V_UI4(var);
|
|
|
|
|
|
|
|
case VT_I8:
|
|
|
|
case VT_UI8:
|
|
|
|
return V_UI8(var);
|
|
|
|
|
|
|
|
case VT_INT:
|
|
|
|
case VT_UINT:
|
|
|
|
return V_UINT(var);
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unsupported variant type %d\n", V_VT(var));
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-28 03:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI folders_get_Item(ITaskFolderCollection *iface, VARIANT index, ITaskFolder **folder)
|
|
|
|
{
|
2014-01-28 03:54:45 +01:00
|
|
|
TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
|
|
|
|
LONG idx;
|
|
|
|
|
|
|
|
TRACE("%p,%s,%p\n", iface, debugstr_variant(&index), folder);
|
|
|
|
|
|
|
|
if (!folder) return E_POINTER;
|
|
|
|
|
|
|
|
if (V_VT(&index) == VT_BSTR)
|
|
|
|
return TaskFolder_create(folders->path, V_BSTR(&index), folder, FALSE);
|
|
|
|
|
|
|
|
idx = get_var_int(&index);
|
|
|
|
/* collections are 1 based */
|
|
|
|
if (idx < 1 || idx > folders->count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return TaskFolder_create(folders->path, folders->list[idx - 1], folder, FALSE);
|
2014-01-28 03:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI folders_get__NewEnum(ITaskFolderCollection *iface, IUnknown **penum)
|
|
|
|
{
|
2014-01-28 03:54:48 +01:00
|
|
|
TaskFolderCollection *folders = impl_from_ITaskFolderCollection(iface);
|
|
|
|
|
|
|
|
TRACE("%p,%p\n", iface, penum);
|
|
|
|
|
|
|
|
if (!penum) return E_POINTER;
|
|
|
|
|
|
|
|
return NewEnum_create(folders, penum);
|
2014-01-28 03:54:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const ITaskFolderCollectionVtbl TaskFolderCollection_vtbl =
|
|
|
|
{
|
|
|
|
folders_QueryInterface,
|
|
|
|
folders_AddRef,
|
|
|
|
folders_Release,
|
|
|
|
folders_GetTypeInfoCount,
|
|
|
|
folders_GetTypeInfo,
|
|
|
|
folders_GetIDsOfNames,
|
|
|
|
folders_Invoke,
|
|
|
|
folders_get_Count,
|
|
|
|
folders_get_Item,
|
|
|
|
folders_get__NewEnum
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT TaskFolderCollection_create(const WCHAR *path, ITaskFolderCollection **obj)
|
|
|
|
{
|
|
|
|
TaskFolderCollection *folders;
|
2014-01-28 03:54:41 +01:00
|
|
|
HRESULT hr;
|
2014-04-07 06:14:33 +02:00
|
|
|
TASK_NAMES list;
|
|
|
|
DWORD start_index, count;
|
2014-01-28 03:54:41 +01:00
|
|
|
|
2014-04-07 06:14:33 +02:00
|
|
|
start_index = 0;
|
|
|
|
list = NULL;
|
|
|
|
hr = SchRpcEnumFolders(path, 0, &start_index, 0, &count, &list);
|
|
|
|
if (hr != S_OK) return hr;
|
2014-01-28 03:54:29 +01:00
|
|
|
|
2014-01-28 03:54:36 +01:00
|
|
|
folders = heap_alloc(sizeof(*folders));
|
2014-01-28 03:54:41 +01:00
|
|
|
if (!folders)
|
|
|
|
{
|
|
|
|
free_list(list, count);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2014-01-28 03:54:29 +01:00
|
|
|
|
|
|
|
folders->ITaskFolderCollection_iface.lpVtbl = &TaskFolderCollection_vtbl;
|
|
|
|
folders->ref = 1;
|
2017-12-01 12:01:50 +01:00
|
|
|
if (!(folders->path = heap_strdupW(path)))
|
|
|
|
{
|
|
|
|
heap_free(folders);
|
2017-12-23 08:51:17 +01:00
|
|
|
free_list(list, count);
|
2017-12-01 12:01:50 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2014-01-28 03:54:41 +01:00
|
|
|
folders->count = count;
|
|
|
|
folders->list = list;
|
2014-01-28 03:54:29 +01:00
|
|
|
*obj = &folders->ITaskFolderCollection_iface;
|
|
|
|
|
|
|
|
TRACE("created %p\n", *obj);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2014-01-28 03:54:48 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
IEnumVARIANT IEnumVARIANT_iface;
|
|
|
|
LONG ref, pos;
|
|
|
|
TaskFolderCollection *folders;
|
|
|
|
} EnumVARIANT;
|
|
|
|
|
|
|
|
static inline EnumVARIANT *impl_from_IEnumVARIANT(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, EnumVARIANT, IEnumVARIANT_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enumvar_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **obj)
|
|
|
|
{
|
|
|
|
if (!riid || !obj) return E_INVALIDARG;
|
|
|
|
|
|
|
|
TRACE("%p,%s,%p\n", iface, debugstr_guid(riid), obj);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IEnumVARIANT) ||
|
|
|
|
IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
|
|
|
IEnumVARIANT_AddRef(iface);
|
|
|
|
*obj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME("interface %s is not implemented\n", debugstr_guid(riid));
|
2014-02-05 07:09:11 +01:00
|
|
|
*obj = NULL;
|
2014-01-28 03:54:48 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enumvar_AddRef(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
|
|
|
|
return InterlockedIncrement(&enumvar->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enumvar_Release(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&enumvar->ref);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
|
|
|
TRACE("destroying %p\n", iface);
|
|
|
|
ITaskFolderCollection_Release(&enumvar->folders->ITaskFolderCollection_iface);
|
|
|
|
heap_free(enumvar);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enumvar_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *var, ULONG *fetched)
|
|
|
|
{
|
|
|
|
EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
|
|
|
|
LONG i;
|
|
|
|
|
2022-02-18 09:17:22 +01:00
|
|
|
TRACE("%p,%lu,%p,%p\n", iface, celt, var, fetched);
|
2014-01-28 03:54:48 +01:00
|
|
|
|
|
|
|
for (i = 0; i < celt && enumvar->pos < enumvar->folders->count; i++)
|
|
|
|
{
|
|
|
|
ITaskFolder *folder;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = TaskFolder_create(enumvar->folders->path, enumvar->folders->list[enumvar->pos++], &folder, FALSE);
|
|
|
|
if (hr) return hr;
|
|
|
|
|
|
|
|
if (!var)
|
|
|
|
{
|
|
|
|
ITaskFolder_Release(folder);
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
V_VT(&var[i]) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(&var[i]) = (IDispatch *)folder;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fetched) *fetched = i;
|
|
|
|
|
|
|
|
return i == celt ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enumvar_Skip(IEnumVARIANT *iface, ULONG celt)
|
|
|
|
{
|
|
|
|
EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
|
|
|
|
|
2022-02-18 09:17:22 +01:00
|
|
|
TRACE("%p,%lu\n", iface, celt);
|
2014-01-28 03:54:48 +01:00
|
|
|
|
|
|
|
enumvar->pos += celt;
|
|
|
|
|
|
|
|
if (enumvar->pos > enumvar->folders->count)
|
|
|
|
{
|
|
|
|
enumvar->pos = enumvar->folders->count;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enumvar_Reset(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
|
|
|
|
|
|
|
|
TRACE("%p\n", iface);
|
|
|
|
|
|
|
|
enumvar->pos = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enumvar_Clone(IEnumVARIANT *iface, IEnumVARIANT **penum)
|
|
|
|
{
|
2014-01-28 03:54:52 +01:00
|
|
|
EnumVARIANT *enumvar = impl_from_IEnumVARIANT(iface);
|
|
|
|
|
|
|
|
TRACE("%p,%p\n", iface, penum);
|
|
|
|
|
|
|
|
return NewEnum_create(enumvar->folders, (IUnknown **)penum);
|
2014-01-28 03:54:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IEnumVARIANTVtbl EnumVARIANT_vtbl =
|
|
|
|
{
|
|
|
|
enumvar_QueryInterface,
|
|
|
|
enumvar_AddRef,
|
|
|
|
enumvar_Release,
|
|
|
|
enumvar_Next,
|
|
|
|
enumvar_Skip,
|
|
|
|
enumvar_Reset,
|
|
|
|
enumvar_Clone
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT NewEnum_create(TaskFolderCollection *folders, IUnknown **obj)
|
|
|
|
{
|
|
|
|
EnumVARIANT *enumvar;
|
|
|
|
|
|
|
|
enumvar = heap_alloc(sizeof(*enumvar));
|
|
|
|
if (!enumvar) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
enumvar->IEnumVARIANT_iface.lpVtbl = &EnumVARIANT_vtbl;
|
|
|
|
enumvar->ref = 1;
|
|
|
|
enumvar->pos = 0;
|
|
|
|
enumvar->folders = folders;
|
|
|
|
ITaskFolderCollection_AddRef(&folders->ITaskFolderCollection_iface);
|
|
|
|
|
|
|
|
*obj = (IUnknown *)&enumvar->IEnumVARIANT_iface;
|
|
|
|
|
|
|
|
TRACE("created %p\n", *obj);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|