ReactOS 0.4.16-dev-2332-g4cba65d
irotp.c
Go to the documentation of this file.
1/*
2 * Running Object Table
3 *
4 * Copyright 2007 Robert Shearman
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdarg.h>
22#include <string.h>
23
24#include "winerror.h"
25#include "windef.h"
26#include "winbase.h"
27
28#include "irot.h"
29
30#include "wine/list.h"
31#include "wine/debug.h"
32
34
35/* define the structure of the running object table elements */
37{
38 struct list entry;
39 InterfaceData *object; /* marshaled running object*/
40 InterfaceData *moniker; /* marshaled moniker that identifies this object */
41 MonikerComparisonData *moniker_data; /* moniker comparison data that identifies this object */
42 DWORD cookie; /* cookie identifying this object */
45};
46
48
51{
54 0, 0, { (DWORD_PTR)(__FILE__ ": csRunningObjectTable") }
55};
56static CRITICAL_SECTION csRunningObjectTable = { &critsect_debug, -1, 0, 0, 0, 0 };
57
58static LONG last_cookie = 1;
59
60static inline void rot_entry_release(struct rot_entry *rot_entry)
61{
63 {
68 }
69}
70
72 IrotHandle h,
74 const InterfaceData *obj,
75 const InterfaceData *mk,
76 const FILETIME *time,
77 DWORD grfFlags,
78 IrotCookie *cookie,
79 IrotContextHandle *ctxt_handle)
80{
81 struct rot_entry *rot_entry;
82 struct rot_entry *existing_rot_entry;
83 HRESULT hr;
84
85 if (grfFlags & ~(ROTFLAGS_REGISTRATIONKEEPSALIVE|ROTFLAGS_ALLOWANYCLIENT))
86 {
87 WINE_ERR("Invalid grfFlags: 0x%08lx\n", grfFlags & ~(ROTFLAGS_REGISTRATIONKEEPSALIVE|ROTFLAGS_ALLOWANYCLIENT));
88 return E_INVALIDARG;
89 }
90
91 if (!(rot_entry = calloc(1, sizeof(*rot_entry))))
92 return E_OUTOFMEMORY;
93
94 rot_entry->refs = 1;
95 rot_entry->object = malloc(FIELD_OFFSET(InterfaceData, abData[obj->ulCntData]));
96 if (!rot_entry->object)
97 {
99 return E_OUTOFMEMORY;
100 }
101 rot_entry->object->ulCntData = obj->ulCntData;
102 memcpy(&rot_entry->object->abData, obj->abData, obj->ulCntData);
103
105
106 rot_entry->moniker = malloc(FIELD_OFFSET(InterfaceData, abData[mk->ulCntData]));
107 if (!rot_entry->moniker)
108 {
110 return E_OUTOFMEMORY;
111 }
112 rot_entry->moniker->ulCntData = mk->ulCntData;
113 memcpy(&rot_entry->moniker->abData, mk->abData, mk->ulCntData);
114
115 if (!(rot_entry->moniker_data = malloc(FIELD_OFFSET(MonikerComparisonData, abData[data->ulCntData]))))
116 {
118 return E_OUTOFMEMORY;
119 }
120 rot_entry->moniker_data->ulCntData = data->ulCntData;
121 memcpy(&rot_entry->moniker_data->abData, data->abData, data->ulCntData);
122
124
125 hr = S_OK;
126
127 LIST_FOR_EACH_ENTRY(existing_rot_entry, &RunningObjectTable, struct rot_entry, entry)
128 {
129 if ((existing_rot_entry->moniker_data->ulCntData == data->ulCntData) &&
130 !memcmp(&data->abData, &existing_rot_entry->moniker_data->abData, data->ulCntData))
131 {
133 WINE_TRACE("moniker already registered with cookie %ld\n", existing_rot_entry->cookie);
134 break;
135 }
136 }
137
139
141
142 /* gives a registration identifier to the registered object*/
145
146 return hr;
147}
148
150 IrotHandle h,
151 IrotCookie cookie,
152 IrotContextHandle *ctxt_handle,
153 PInterfaceData *obj,
154 PInterfaceData *mk)
155{
156 struct rot_entry *rot_entry;
157
158 WINE_TRACE("%ld\n", cookie);
159
162 {
163 if (rot_entry->cookie == cookie)
164 {
165 HRESULT hr = S_OK;
166
169
170 *obj = MIDL_user_allocate(FIELD_OFFSET(InterfaceData, abData[rot_entry->object->ulCntData]));
171 *mk = MIDL_user_allocate(FIELD_OFFSET(InterfaceData, abData[rot_entry->moniker->ulCntData]));
172 if (*obj && *mk)
173 {
174 (*obj)->ulCntData = rot_entry->object->ulCntData;
175 memcpy((*obj)->abData, rot_entry->object->abData, (*obj)->ulCntData);
176 (*mk)->ulCntData = rot_entry->moniker->ulCntData;
177 memcpy((*mk)->abData, rot_entry->moniker->abData, (*mk)->ulCntData);
178 }
179 else
180 {
182 MIDL_user_free(*mk);
184 }
185
187 *ctxt_handle = NULL;
188 return hr;
189 }
190 }
192
193 return E_INVALIDARG;
194}
195
197 IrotHandle h,
199{
200 const struct rot_entry *rot_entry;
202
203 WINE_TRACE("\n");
204
206
208 {
209 if ((rot_entry->moniker_data->ulCntData == data->ulCntData) &&
210 !memcmp(&data->abData, &rot_entry->moniker_data->abData, data->ulCntData))
211 {
212 hr = S_OK;
213 break;
214 }
215 }
217
218 return hr;
219}
220
222 IrotHandle h,
224 PInterfaceData *obj,
225 IrotCookie *cookie)
226{
227 const struct rot_entry *rot_entry;
228
229 WINE_TRACE("%p\n", moniker_data);
230
231 *cookie = 0;
232
234
236 {
237 HRESULT hr = S_OK;
240 {
241 *obj = MIDL_user_allocate(FIELD_OFFSET(InterfaceData, abData[rot_entry->object->ulCntData]));
242 if (*obj)
243 {
244 (*obj)->ulCntData = rot_entry->object->ulCntData;
245 memcpy((*obj)->abData, rot_entry->object->abData, (*obj)->ulCntData);
246
248 }
249 else
251
253
254 return hr;
255 }
256 }
257
259
260 return MK_E_UNAVAILABLE;
261}
262
264 IrotHandle h,
265 IrotCookie cookie,
266 const FILETIME *last_modified_time)
267{
268 struct rot_entry *rot_entry;
269
270 WINE_TRACE("%ld %p\n", cookie, last_modified_time);
271
274 {
275 if (rot_entry->cookie == cookie)
276 {
277 rot_entry->last_modified = *last_modified_time;
279 return S_OK;
280 }
281 }
283
284 return E_INVALIDARG;
285}
286
288 IrotHandle h,
290 FILETIME *time)
291{
292 const struct rot_entry *rot_entry;
294
295 WINE_TRACE("%p\n", moniker_data);
296
297 memset(time, 0, sizeof(*time));
298
301 {
304 {
306 hr = S_OK;
307 break;
308 }
309 }
311
312 return hr;
313}
314
316 IrotHandle h,
317 PInterfaceList *list)
318{
319 const struct rot_entry *rot_entry;
320 HRESULT hr = S_OK;
321 ULONG moniker_count = 0;
322 ULONG i = 0;
323
324 WINE_TRACE("\n");
325
327
329 moniker_count++;
330
331 *list = MIDL_user_allocate(FIELD_OFFSET(InterfaceList, interfaces[moniker_count]));
332 if (*list)
333 {
334 (*list)->size = moniker_count;
336 {
337 (*list)->interfaces[i] = MIDL_user_allocate(FIELD_OFFSET(InterfaceData, abData[rot_entry->moniker->ulCntData]));
338 if (!(*list)->interfaces[i])
339 {
340 ULONG end = i - 1;
341 for (i = 0; i < end; i++)
342 MIDL_user_free((*list)->interfaces[i]);
345 break;
346 }
347 (*list)->interfaces[i]->ulCntData = rot_entry->moniker->ulCntData;
348 memcpy((*list)->interfaces[i]->abData, rot_entry->moniker->abData, rot_entry->moniker->ulCntData);
349 i++;
350 }
351 }
352 else
354
356
357 return hr;
358}
359
361{
367}
368
370{
371 return I_RpcAllocate(size);
372}
373
375{
376 I_RpcFree(p);
377}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
Definition: list.h:37
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define __cdecl
Definition: corecrt.h:121
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint end
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLfloat GLfloat p
Definition: glext.h:8902
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define S_OK
Definition: intsafe.h:52
HRESULT __cdecl IrotRevoke(IrotHandle h, IrotCookie cookie, IrotContextHandle *ctxt_handle, PInterfaceData *obj, PInterfaceData *mk)
Definition: irotp.c:149
HRESULT __cdecl IrotEnumRunning(IrotHandle h, PInterfaceList *list)
Definition: irotp.c:315
HRESULT __cdecl IrotGetObject(IrotHandle h, const MonikerComparisonData *moniker_data, PInterfaceData *obj, IrotCookie *cookie)
Definition: irotp.c:221
static CRITICAL_SECTION_DEBUG critsect_debug
Definition: irotp.c:50
HRESULT __cdecl IrotRegister(IrotHandle h, const MonikerComparisonData *data, const InterfaceData *obj, const InterfaceData *mk, const FILETIME *time, DWORD grfFlags, IrotCookie *cookie, IrotContextHandle *ctxt_handle)
Definition: irotp.c:71
HRESULT __cdecl IrotIsRunning(IrotHandle h, const MonikerComparisonData *data)
Definition: irotp.c:196
void *__RPC_USER MIDL_user_allocate(SIZE_T size)
Definition: irotp.c:369
void __RPC_USER IrotContextHandle_rundown(IrotContextHandle ctxt_handle)
Definition: irotp.c:360
static struct list RunningObjectTable
Definition: irotp.c:47
static CRITICAL_SECTION csRunningObjectTable
Definition: irotp.c:49
static LONG last_cookie
Definition: irotp.c:58
HRESULT __cdecl IrotGetTimeOfLastChange(IrotHandle h, const MonikerComparisonData *moniker_data, FILETIME *time)
Definition: irotp.c:287
HRESULT __cdecl IrotNoteChangeTime(IrotHandle h, IrotCookie cookie, const FILETIME *last_modified_time)
Definition: irotp.c:263
static void rot_entry_release(struct rot_entry *rot_entry)
Definition: irotp.c:60
void __RPC_USER MIDL_user_free(void *p)
Definition: irotp.c:374
uint32_t entry
Definition: isohybrid.c:63
__u16 time
Definition: mkdosfs.c:8
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
long LONG
Definition: pedump.c:60
#define calloc
Definition: rosglue.h:14
void WINAPI I_RpcFree(void *Object)
Definition: rpcrt4_main.c:755
void *WINAPI I_RpcAllocate(unsigned int Size)
Definition: rpcrt4_main.c:747
#define __RPC_USER
Definition: rpc.h:61
#define WINE_TRACE
Definition: debug.h:363
#define WINE_ERR
Definition: debug.h:380
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
Definition: cookie.c:34
Definition: irotp.c:37
LONG refs
Definition: irotp.c:44
IrotContextHandle ctxt_handle
Definition: moniker.c:61
struct list entry
Definition: irotp.c:38
InterfaceData * object
Definition: irotp.c:39
MonikerComparisonData * moniker_data
Definition: irotp.c:41
DWORD cookie
Definition: irotp.c:42
InterfaceData * moniker
Definition: irotp.c:40
FILETIME last_modified
Definition: irotp.c:43
#define LIST_INIT(head)
Definition: queue.h:197
#define DWORD_PTR
Definition: treelist.c:76
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
_In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList
Definition: usbdlib.h:181
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define S_FALSE
Definition: winerror.h:3451
#define MK_E_UNAVAILABLE
Definition: winerror.h:3894
#define MK_S_MONIKERALREADYREGISTERED
Definition: winerror.h:3901