Sync with trunk r58740.
[reactos.git] / dll / win32 / mapi32 / prop.c
1 /*
2 * Property functions
3 *
4 * Copyright 2004 Jon Griffiths
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 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #include <stdarg.h>
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 //#include "winerror.h"
32 //#include "winternl.h"
33 //#include "objbase.h"
34 #include <shlwapi.h>
35 #include <wine/list.h>
36 #include <wine/debug.h>
37 #include <wine/unicode.h>
38 #include <mapival.h>
39
40 WINE_DEFAULT_DEBUG_CHANNEL(mapi);
41
42 BOOL WINAPI FBadRglpszA(LPSTR*,ULONG);
43
44 /* Internal: Check if a property value array is invalid */
45 static inline ULONG PROP_BadArray(LPSPropValue lpProp, size_t elemSize)
46 {
47 return IsBadReadPtr(lpProp->Value.MVi.lpi, lpProp->Value.MVi.cValues * elemSize);
48 }
49
50 /*************************************************************************
51 * PropCopyMore@16 (MAPI32.76)
52 *
53 * Copy a property value.
54 *
55 * PARAMS
56 * lpDest [O] Destination for the copied value
57 * lpSrc [I] Property value to copy to lpDest
58 * lpMore [I] Linked memory allocation function (pass MAPIAllocateMore())
59 * lpOrig [I] Original allocation to which memory will be linked
60 *
61 * RETURNS
62 * Success: S_OK. lpDest contains a deep copy of lpSrc.
63 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
64 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
65 *
66 * NOTES
67 * Any elements within the property returned should not be individually
68 * freed, as they will be freed when lpOrig is.
69 */
70 SCODE WINAPI PropCopyMore(LPSPropValue lpDest, LPSPropValue lpSrc,
71 ALLOCATEMORE *lpMore, LPVOID lpOrig)
72 {
73 ULONG ulLen, i;
74 SCODE scode = S_OK;
75
76 TRACE("(%p,%p,%p,%p)\n", lpDest, lpSrc, lpMore, lpOrig);
77
78 if (!lpDest || IsBadWritePtr(lpDest, sizeof(SPropValue)) ||
79 FBadProp(lpSrc) || !lpMore)
80 return MAPI_E_INVALID_PARAMETER;
81
82 /* Shallow copy first, this is sufficient for properties without pointers */
83 *lpDest = *lpSrc;
84
85 switch (PROP_TYPE(lpSrc->ulPropTag))
86 {
87 case PT_CLSID:
88 scode = lpMore(sizeof(GUID), lpOrig, (LPVOID*)&lpDest->Value.lpguid);
89 if (SUCCEEDED(scode))
90 *lpDest->Value.lpguid = *lpSrc->Value.lpguid;
91 break;
92 case PT_STRING8:
93 ulLen = lstrlenA(lpSrc->Value.lpszA) + 1u;
94 scode = lpMore(ulLen, lpOrig, (LPVOID*)&lpDest->Value.lpszA);
95 if (SUCCEEDED(scode))
96 memcpy(lpDest->Value.lpszA, lpSrc->Value.lpszA, ulLen);
97 break;
98 case PT_UNICODE:
99 ulLen = (strlenW(lpSrc->Value.lpszW) + 1u) * sizeof(WCHAR);
100 scode = lpMore(ulLen, lpOrig, (LPVOID*)&lpDest->Value.lpszW);
101 if (SUCCEEDED(scode))
102 memcpy(lpDest->Value.lpszW, lpSrc->Value.lpszW, ulLen);
103 break;
104 case PT_BINARY:
105 scode = lpMore(lpSrc->Value.bin.cb, lpOrig, (LPVOID*)&lpDest->Value.bin.lpb);
106 if (SUCCEEDED(scode))
107 memcpy(lpDest->Value.bin.lpb, lpSrc->Value.bin.lpb, lpSrc->Value.bin.cb);
108 break;
109 default:
110 if (lpSrc->ulPropTag & MV_FLAG)
111 {
112 ulLen = UlPropSize(lpSrc);
113
114 if (PROP_TYPE(lpSrc->ulPropTag) == PT_MV_STRING8 ||
115 PROP_TYPE(lpSrc->ulPropTag) == PT_MV_UNICODE)
116 {
117 /* UlPropSize doesn't account for the string pointers */
118 ulLen += lpSrc->Value.MVszA.cValues * sizeof(char*);
119 }
120 else if (PROP_TYPE(lpSrc->ulPropTag) == PT_MV_BINARY)
121 {
122 /* UlPropSize doesn't account for the SBinary structs */
123 ulLen += lpSrc->Value.MVbin.cValues * sizeof(SBinary);
124 }
125
126 lpDest->Value.MVi.cValues = lpSrc->Value.MVi.cValues;
127 scode = lpMore(ulLen, lpOrig, (LPVOID*)&lpDest->Value.MVi.lpi);
128 if (FAILED(scode))
129 break;
130
131 /* Note that we could allocate the memory for each value in a
132 * multi-value property separately, however if an allocation failed
133 * we would be left with a bunch of allocated memory, which (while
134 * not really leaked) is unusable until lpOrig is freed. So for
135 * strings and binary arrays we make a single allocation for all
136 * of the data. This is consistent since individual elements can't
137 * be freed anyway.
138 */
139
140 switch (PROP_TYPE(lpSrc->ulPropTag))
141 {
142 case PT_MV_STRING8:
143 {
144 char *lpNextStr = (char*)(lpDest->Value.MVszA.lppszA +
145 lpDest->Value.MVszA.cValues);
146
147 for (i = 0; i < lpSrc->Value.MVszA.cValues; i++)
148 {
149 ULONG ulStrLen = lstrlenA(lpSrc->Value.MVszA.lppszA[i]) + 1u;
150
151 lpDest->Value.MVszA.lppszA[i] = lpNextStr;
152 memcpy(lpNextStr, lpSrc->Value.MVszA.lppszA[i], ulStrLen);
153 lpNextStr += ulStrLen;
154 }
155 break;
156 }
157 case PT_MV_UNICODE:
158 {
159 WCHAR *lpNextStr = (WCHAR*)(lpDest->Value.MVszW.lppszW +
160 lpDest->Value.MVszW.cValues);
161
162 for (i = 0; i < lpSrc->Value.MVszW.cValues; i++)
163 {
164 ULONG ulStrLen = strlenW(lpSrc->Value.MVszW.lppszW[i]) + 1u;
165
166 lpDest->Value.MVszW.lppszW[i] = lpNextStr;
167 memcpy(lpNextStr, lpSrc->Value.MVszW.lppszW[i], ulStrLen * sizeof(WCHAR));
168 lpNextStr += ulStrLen;
169 }
170 break;
171 }
172 case PT_MV_BINARY:
173 {
174 LPBYTE lpNext = (LPBYTE)(lpDest->Value.MVbin.lpbin +
175 lpDest->Value.MVbin.cValues);
176
177 for (i = 0; i < lpSrc->Value.MVszW.cValues; i++)
178 {
179 lpDest->Value.MVbin.lpbin[i].cb = lpSrc->Value.MVbin.lpbin[i].cb;
180 lpDest->Value.MVbin.lpbin[i].lpb = lpNext;
181 memcpy(lpNext, lpSrc->Value.MVbin.lpbin[i].lpb, lpDest->Value.MVbin.lpbin[i].cb);
182 lpNext += lpDest->Value.MVbin.lpbin[i].cb;
183 }
184 break;
185 }
186 default:
187 /* No embedded pointers, just copy the data over */
188 memcpy(lpDest->Value.MVi.lpi, lpSrc->Value.MVi.lpi, ulLen);
189 break;
190 }
191 break;
192 }
193 }
194 return scode;
195 }
196
197 /*************************************************************************
198 * UlPropSize@4 (MAPI32.77)
199 *
200 * Determine the size of a property in bytes.
201 *
202 * PARAMS
203 * lpProp [I] Property to determine the size of
204 *
205 * RETURNS
206 * Success: The size of the value in lpProp.
207 * Failure: 0, if a multi-value (array) property is invalid or the type of lpProp
208 * is unknown.
209 *
210 * NOTES
211 * - The size returned does not include the size of the SPropValue struct
212 * or the size of the array of pointers for multi-valued properties that
213 * contain pointers (such as PT_MV_STRING8 or PT-MV_UNICODE).
214 * - MSDN incorrectly states that this function returns MAPI_E_CALL_FAILED if
215 * lpProp is invalid. In reality no checking is performed and this function
216 * will crash if passed an invalid property, or return 0 if the property
217 * type is PT_OBJECT or is unknown.
218 */
219 ULONG WINAPI UlPropSize(LPSPropValue lpProp)
220 {
221 ULONG ulRet = 1u, i;
222
223 TRACE("(%p)\n", lpProp);
224
225 switch (PROP_TYPE(lpProp->ulPropTag))
226 {
227 case PT_MV_I2: ulRet = lpProp->Value.MVi.cValues;
228 case PT_BOOLEAN:
229 case PT_I2: ulRet *= sizeof(USHORT);
230 break;
231 case PT_MV_I4: ulRet = lpProp->Value.MVl.cValues;
232 case PT_ERROR:
233 case PT_I4: ulRet *= sizeof(LONG);
234 break;
235 case PT_MV_I8: ulRet = lpProp->Value.MVli.cValues;
236 case PT_I8: ulRet *= sizeof(LONG64);
237 break;
238 case PT_MV_R4: ulRet = lpProp->Value.MVflt.cValues;
239 case PT_R4: ulRet *= sizeof(float);
240 break;
241 case PT_MV_APPTIME:
242 case PT_MV_R8: ulRet = lpProp->Value.MVdbl.cValues;
243 case PT_APPTIME:
244 case PT_R8: ulRet *= sizeof(double);
245 break;
246 case PT_MV_CURRENCY: ulRet = lpProp->Value.MVcur.cValues;
247 case PT_CURRENCY: ulRet *= sizeof(CY);
248 break;
249 case PT_MV_SYSTIME: ulRet = lpProp->Value.MVft.cValues;
250 case PT_SYSTIME: ulRet *= sizeof(FILETIME);
251 break;
252 case PT_MV_CLSID: ulRet = lpProp->Value.MVguid.cValues;
253 case PT_CLSID: ulRet *= sizeof(GUID);
254 break;
255 case PT_MV_STRING8: ulRet = 0u;
256 for (i = 0; i < lpProp->Value.MVszA.cValues; i++)
257 ulRet += (lstrlenA(lpProp->Value.MVszA.lppszA[i]) + 1u);
258 break;
259 case PT_STRING8: ulRet = lstrlenA(lpProp->Value.lpszA) + 1u;
260 break;
261 case PT_MV_UNICODE: ulRet = 0u;
262 for (i = 0; i < lpProp->Value.MVszW.cValues; i++)
263 ulRet += (strlenW(lpProp->Value.MVszW.lppszW[i]) + 1u);
264 ulRet *= sizeof(WCHAR);
265 break;
266 case PT_UNICODE: ulRet = (lstrlenW(lpProp->Value.lpszW) + 1u) * sizeof(WCHAR);
267 break;
268 case PT_MV_BINARY: ulRet = 0u;
269 for (i = 0; i < lpProp->Value.MVbin.cValues; i++)
270 ulRet += lpProp->Value.MVbin.lpbin[i].cb;
271 break;
272 case PT_BINARY: ulRet = lpProp->Value.bin.cb;
273 break;
274 case PT_OBJECT:
275 default: ulRet = 0u;
276 break;
277 }
278
279 return ulRet;
280 }
281
282 /*************************************************************************
283 * FPropContainsProp@12 (MAPI32.78)
284 *
285 * Find a property with a given property tag in a property array.
286 *
287 * PARAMS
288 * lpHaystack [I] Property to match to
289 * lpNeedle [I] Property to find in lpHaystack
290 * ulFuzzy [I] Flags controlling match type and strictness (FL_* flags from "mapidefs.h")
291 *
292 * RETURNS
293 * TRUE, if lpNeedle matches lpHaystack according to the criteria of ulFuzzy.
294 *
295 * NOTES
296 * Only property types of PT_STRING8 and PT_BINARY are handled by this function.
297 */
298 BOOL WINAPI FPropContainsProp(LPSPropValue lpHaystack, LPSPropValue lpNeedle, ULONG ulFuzzy)
299 {
300 TRACE("(%p,%p,0x%08x)\n", lpHaystack, lpNeedle, ulFuzzy);
301
302 if (FBadProp(lpHaystack) || FBadProp(lpNeedle) ||
303 PROP_TYPE(lpHaystack->ulPropTag) != PROP_TYPE(lpNeedle->ulPropTag))
304 return FALSE;
305
306 /* FIXME: Do later versions support Unicode as well? */
307
308 if (PROP_TYPE(lpHaystack->ulPropTag) == PT_STRING8)
309 {
310 DWORD dwFlags = 0, dwNeedleLen, dwHaystackLen;
311
312 if (ulFuzzy & FL_IGNORECASE)
313 dwFlags |= NORM_IGNORECASE;
314 if (ulFuzzy & FL_IGNORENONSPACE)
315 dwFlags |= NORM_IGNORENONSPACE;
316 if (ulFuzzy & FL_LOOSE)
317 dwFlags |= (NORM_IGNORECASE|NORM_IGNORENONSPACE|NORM_IGNORESYMBOLS);
318
319 dwNeedleLen = lstrlenA(lpNeedle->Value.lpszA);
320 dwHaystackLen = lstrlenA(lpHaystack->Value.lpszA);
321
322 if ((ulFuzzy & (FL_SUBSTRING|FL_PREFIX)) == FL_PREFIX)
323 {
324 if (dwNeedleLen <= dwHaystackLen &&
325 CompareStringA(LOCALE_USER_DEFAULT, dwFlags,
326 lpHaystack->Value.lpszA, dwNeedleLen,
327 lpNeedle->Value.lpszA, dwNeedleLen) == CSTR_EQUAL)
328 return TRUE; /* needle is a prefix of haystack */
329 }
330 else if ((ulFuzzy & (FL_SUBSTRING|FL_PREFIX)) == FL_SUBSTRING)
331 {
332 LPSTR (WINAPI *pStrChrFn)(LPCSTR,WORD) = StrChrA;
333 LPSTR lpStr = lpHaystack->Value.lpszA;
334
335 if (dwFlags & NORM_IGNORECASE)
336 pStrChrFn = StrChrIA;
337
338 while ((lpStr = pStrChrFn(lpStr, *lpNeedle->Value.lpszA)) != NULL)
339 {
340 dwHaystackLen -= (lpStr - lpHaystack->Value.lpszA);
341 if (dwNeedleLen <= dwHaystackLen &&
342 CompareStringA(LOCALE_USER_DEFAULT, dwFlags,
343 lpStr, dwNeedleLen,
344 lpNeedle->Value.lpszA, dwNeedleLen) == CSTR_EQUAL)
345 return TRUE; /* needle is a substring of haystack */
346 lpStr++;
347 }
348 }
349 else if (CompareStringA(LOCALE_USER_DEFAULT, dwFlags,
350 lpHaystack->Value.lpszA, dwHaystackLen,
351 lpNeedle->Value.lpszA, dwNeedleLen) == CSTR_EQUAL)
352 return TRUE; /* full string match */
353 }
354 else if (PROP_TYPE(lpHaystack->ulPropTag) == PT_BINARY)
355 {
356 if ((ulFuzzy & (FL_SUBSTRING|FL_PREFIX)) == FL_PREFIX)
357 {
358 if (lpNeedle->Value.bin.cb <= lpHaystack->Value.bin.cb &&
359 !memcmp(lpNeedle->Value.bin.lpb, lpHaystack->Value.bin.lpb,
360 lpNeedle->Value.bin.cb))
361 return TRUE; /* needle is a prefix of haystack */
362 }
363 else if ((ulFuzzy & (FL_SUBSTRING|FL_PREFIX)) == FL_SUBSTRING)
364 {
365 ULONG ulLen = lpHaystack->Value.bin.cb;
366 LPBYTE lpb = lpHaystack->Value.bin.lpb;
367
368 while ((lpb = memchr(lpb, *lpNeedle->Value.bin.lpb, ulLen)) != NULL)
369 {
370 ulLen = lpHaystack->Value.bin.cb - (lpb - lpHaystack->Value.bin.lpb);
371 if (lpNeedle->Value.bin.cb <= ulLen &&
372 !memcmp(lpNeedle->Value.bin.lpb, lpb, lpNeedle->Value.bin.cb))
373 return TRUE; /* needle is a substring of haystack */
374 lpb++;
375 }
376 }
377 else if (!LPropCompareProp(lpHaystack, lpNeedle))
378 return TRUE; /* needle is an exact match with haystack */
379
380 }
381 return FALSE;
382 }
383
384 /*************************************************************************
385 * FPropCompareProp@12 (MAPI32.79)
386 *
387 * Compare two properties.
388 *
389 * PARAMS
390 * lpPropLeft [I] Left hand property to compare to lpPropRight
391 * ulOp [I] Comparison operator (RELOP_* enum from "mapidefs.h")
392 * lpPropRight [I] Right hand property to compare to lpPropLeft
393 *
394 * RETURNS
395 * TRUE, if the comparison is true, FALSE otherwise.
396 */
397 BOOL WINAPI FPropCompareProp(LPSPropValue lpPropLeft, ULONG ulOp, LPSPropValue lpPropRight)
398 {
399 LONG iCmp;
400
401 TRACE("(%p,%d,%p)\n", lpPropLeft, ulOp, lpPropRight);
402
403 if (ulOp > RELOP_RE || FBadProp(lpPropLeft) || FBadProp(lpPropRight))
404 return FALSE;
405
406 if (ulOp == RELOP_RE)
407 {
408 FIXME("Comparison operator RELOP_RE not yet implemented!\n");
409 return FALSE;
410 }
411
412 iCmp = LPropCompareProp(lpPropLeft, lpPropRight);
413
414 switch (ulOp)
415 {
416 case RELOP_LT: return iCmp < 0 ? TRUE : FALSE;
417 case RELOP_LE: return iCmp <= 0 ? TRUE : FALSE;
418 case RELOP_GT: return iCmp > 0 ? TRUE : FALSE;
419 case RELOP_GE: return iCmp >= 0 ? TRUE : FALSE;
420 case RELOP_EQ: return iCmp == 0 ? TRUE : FALSE;
421 case RELOP_NE: return iCmp != 0 ? TRUE : FALSE;
422 }
423 return FALSE;
424 }
425
426 /*************************************************************************
427 * LPropCompareProp@8 (MAPI32.80)
428 *
429 * Compare two properties.
430 *
431 * PARAMS
432 * lpPropLeft [I] Left hand property to compare to lpPropRight
433 * lpPropRight [I] Right hand property to compare to lpPropLeft
434 *
435 * RETURNS
436 * An integer less than, equal to or greater than 0, indicating that
437 * lpszStr is less than, the same, or greater than lpszComp.
438 */
439 LONG WINAPI LPropCompareProp(LPSPropValue lpPropLeft, LPSPropValue lpPropRight)
440 {
441 LONG iRet;
442
443 TRACE("(%p->0x%08x,%p->0x%08x)\n", lpPropLeft, lpPropLeft->ulPropTag,
444 lpPropRight, lpPropRight->ulPropTag);
445
446 /* If the properties are not the same, sort by property type */
447 if (PROP_TYPE(lpPropLeft->ulPropTag) != PROP_TYPE(lpPropRight->ulPropTag))
448 return (LONG)PROP_TYPE(lpPropLeft->ulPropTag) - (LONG)PROP_TYPE(lpPropRight->ulPropTag);
449
450 switch (PROP_TYPE(lpPropLeft->ulPropTag))
451 {
452 case PT_UNSPECIFIED:
453 case PT_NULL:
454 return 0; /* NULLs are equal */
455 case PT_I2:
456 return lpPropLeft->Value.i - lpPropRight->Value.i;
457 case PT_I4:
458 return lpPropLeft->Value.l - lpPropRight->Value.l;
459 case PT_I8:
460 if (lpPropLeft->Value.li.QuadPart > lpPropRight->Value.li.QuadPart)
461 return 1;
462 if (lpPropLeft->Value.li.QuadPart == lpPropRight->Value.li.QuadPart)
463 return 0;
464 return -1;
465 case PT_R4:
466 if (lpPropLeft->Value.flt > lpPropRight->Value.flt)
467 return 1;
468 if (lpPropLeft->Value.flt == lpPropRight->Value.flt)
469 return 0;
470 return -1;
471 case PT_APPTIME:
472 case PT_R8:
473 if (lpPropLeft->Value.dbl > lpPropRight->Value.dbl)
474 return 1;
475 if (lpPropLeft->Value.dbl == lpPropRight->Value.dbl)
476 return 0;
477 return -1;
478 case PT_CURRENCY:
479 if (lpPropLeft->Value.cur.int64 > lpPropRight->Value.cur.int64)
480 return 1;
481 if (lpPropLeft->Value.cur.int64 == lpPropRight->Value.cur.int64)
482 return 0;
483 return -1;
484 case PT_SYSTIME:
485 return CompareFileTime(&lpPropLeft->Value.ft, &lpPropRight->Value.ft);
486 case PT_BOOLEAN:
487 return (lpPropLeft->Value.b ? 1 : 0) - (lpPropRight->Value.b ? 1 : 0);
488 case PT_BINARY:
489 if (lpPropLeft->Value.bin.cb == lpPropRight->Value.bin.cb)
490 iRet = memcmp(lpPropLeft->Value.bin.lpb, lpPropRight->Value.bin.lpb,
491 lpPropLeft->Value.bin.cb);
492 else
493 {
494 iRet = memcmp(lpPropLeft->Value.bin.lpb, lpPropRight->Value.bin.lpb,
495 min(lpPropLeft->Value.bin.cb, lpPropRight->Value.bin.cb));
496
497 if (!iRet)
498 iRet = lpPropLeft->Value.bin.cb - lpPropRight->Value.bin.cb;
499 }
500 return iRet;
501 case PT_STRING8:
502 return lstrcmpA(lpPropLeft->Value.lpszA, lpPropRight->Value.lpszA);
503 case PT_UNICODE:
504 return strcmpW(lpPropLeft->Value.lpszW, lpPropRight->Value.lpszW);
505 case PT_ERROR:
506 if (lpPropLeft->Value.err > lpPropRight->Value.err)
507 return 1;
508 if (lpPropLeft->Value.err == lpPropRight->Value.err)
509 return 0;
510 return -1;
511 case PT_CLSID:
512 return memcmp(lpPropLeft->Value.lpguid, lpPropRight->Value.lpguid,
513 sizeof(GUID));
514 }
515 FIXME("Unhandled property type %d\n", PROP_TYPE(lpPropLeft->ulPropTag));
516 return 0;
517 }
518
519 /*************************************************************************
520 * HrGetOneProp@8 (MAPI32.135)
521 *
522 * Get a property value from an IMAPIProp object.
523 *
524 * PARAMS
525 * lpIProp [I] IMAPIProp object to get the property value in
526 * ulPropTag [I] Property tag of the property to get
527 * lppProp [O] Destination for the returned property
528 *
529 * RETURNS
530 * Success: S_OK. *lppProp contains the property value requested.
531 * Failure: MAPI_E_NOT_FOUND, if no property value has the tag given by ulPropTag.
532 */
533 HRESULT WINAPI HrGetOneProp(LPMAPIPROP lpIProp, ULONG ulPropTag, LPSPropValue *lppProp)
534 {
535 SPropTagArray pta;
536 ULONG ulCount;
537 HRESULT hRet;
538
539 TRACE("(%p,%d,%p)\n", lpIProp, ulPropTag, lppProp);
540
541 pta.cValues = 1u;
542 pta.aulPropTag[0] = ulPropTag;
543 hRet = IMAPIProp_GetProps(lpIProp, &pta, 0u, &ulCount, lppProp);
544 if (hRet == MAPI_W_ERRORS_RETURNED)
545 {
546 MAPIFreeBuffer(*lppProp);
547 *lppProp = NULL;
548 hRet = MAPI_E_NOT_FOUND;
549 }
550 return hRet;
551 }
552
553 /*************************************************************************
554 * HrSetOneProp@8 (MAPI32.136)
555 *
556 * Set a property value in an IMAPIProp object.
557 *
558 * PARAMS
559 * lpIProp [I] IMAPIProp object to set the property value in
560 * lpProp [I] Property value to set
561 *
562 * RETURNS
563 * Success: S_OK. The value in lpProp is set in lpIProp.
564 * Failure: An error result from IMAPIProp_SetProps().
565 */
566 HRESULT WINAPI HrSetOneProp(LPMAPIPROP lpIProp, LPSPropValue lpProp)
567 {
568 TRACE("(%p,%p)\n", lpIProp, lpProp);
569
570 return IMAPIProp_SetProps(lpIProp, 1u, lpProp, NULL);
571 }
572
573 /*************************************************************************
574 * FPropExists@8 (MAPI32.137)
575 *
576 * Find a property with a given property tag in an IMAPIProp object.
577 *
578 * PARAMS
579 * lpIProp [I] IMAPIProp object to find the property tag in
580 * ulPropTag [I] Property tag to find
581 *
582 * RETURNS
583 * TRUE, if ulPropTag matches a property held in lpIProp,
584 * FALSE, otherwise.
585 *
586 * NOTES
587 * if ulPropTag has a property type of PT_UNSPECIFIED, then only the property
588 * Ids need to match for a successful match to occur.
589 */
590 BOOL WINAPI FPropExists(LPMAPIPROP lpIProp, ULONG ulPropTag)
591 {
592 BOOL bRet = FALSE;
593
594 TRACE("(%p,%d)\n", lpIProp, ulPropTag);
595
596 if (lpIProp)
597 {
598 LPSPropTagArray lpTags;
599 ULONG i;
600
601 if (FAILED(IMAPIProp_GetPropList(lpIProp, 0u, &lpTags)))
602 return FALSE;
603
604 for (i = 0; i < lpTags->cValues; i++)
605 {
606 if (!FBadPropTag(lpTags->aulPropTag[i]) &&
607 (lpTags->aulPropTag[i] == ulPropTag ||
608 (PROP_TYPE(ulPropTag) == PT_UNSPECIFIED &&
609 PROP_ID(lpTags->aulPropTag[i]) == lpTags->aulPropTag[i])))
610 {
611 bRet = TRUE;
612 break;
613 }
614 }
615 MAPIFreeBuffer(lpTags);
616 }
617 return bRet;
618 }
619
620 /*************************************************************************
621 * PpropFindProp@12 (MAPI32.138)
622 *
623 * Find a property with a given property tag in a property array.
624 *
625 * PARAMS
626 * lpProps [I] Property array to search
627 * cValues [I] Number of properties in lpProps
628 * ulPropTag [I] Property tag to find
629 *
630 * RETURNS
631 * A pointer to the matching property, or NULL if none was found.
632 *
633 * NOTES
634 * if ulPropTag has a property type of PT_UNSPECIFIED, then only the property
635 * Ids need to match for a successful match to occur.
636 */
637 LPSPropValue WINAPI PpropFindProp(LPSPropValue lpProps, ULONG cValues, ULONG ulPropTag)
638 {
639 TRACE("(%p,%d,%d)\n", lpProps, cValues, ulPropTag);
640
641 if (lpProps && cValues)
642 {
643 ULONG i;
644 for (i = 0; i < cValues; i++)
645 {
646 if (!FBadPropTag(lpProps[i].ulPropTag) &&
647 (lpProps[i].ulPropTag == ulPropTag ||
648 (PROP_TYPE(ulPropTag) == PT_UNSPECIFIED &&
649 PROP_ID(lpProps[i].ulPropTag) == PROP_ID(ulPropTag))))
650 return &lpProps[i];
651 }
652 }
653 return NULL;
654 }
655
656 /*************************************************************************
657 * FreePadrlist@4 (MAPI32.139)
658 *
659 * Free the memory used by an address book list.
660 *
661 * PARAMS
662 * lpAddrs [I] Address book list to free
663 *
664 * RETURNS
665 * Nothing.
666 */
667 VOID WINAPI FreePadrlist(LPADRLIST lpAddrs)
668 {
669 TRACE("(%p)\n", lpAddrs);
670
671 /* Structures are binary compatible; use the same implementation */
672 FreeProws((LPSRowSet)lpAddrs);
673 }
674
675 /*************************************************************************
676 * FreeProws@4 (MAPI32.140)
677 *
678 * Free the memory used by a row set.
679 *
680 * PARAMS
681 * lpRowSet [I] Row set to free
682 *
683 * RETURNS
684 * Nothing.
685 */
686 VOID WINAPI FreeProws(LPSRowSet lpRowSet)
687 {
688 TRACE("(%p)\n", lpRowSet);
689
690 if (lpRowSet)
691 {
692 ULONG i;
693
694 for (i = 0; i < lpRowSet->cRows; i++)
695 MAPIFreeBuffer(lpRowSet->aRow[i].lpProps);
696
697 MAPIFreeBuffer(lpRowSet);
698 }
699 }
700
701 /*************************************************************************
702 * ScCountProps@12 (MAPI32.170)
703 *
704 * Validate and determine the length of an array of properties.
705 *
706 * PARAMS
707 * iCount [I] Length of the lpProps array
708 * lpProps [I] Array of properties to validate/size
709 * pcBytes [O] If non-NULL, destination for the size of the property array
710 *
711 * RETURNS
712 * Success: S_OK. If pcBytes is non-NULL, it contains the size of the propery array.
713 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid or validation
714 * of the property array fails.
715 */
716 SCODE WINAPI ScCountProps(INT iCount, LPSPropValue lpProps, ULONG *pcBytes)
717 {
718 ULONG i, ulCount = iCount, ulBytes = 0;
719
720 TRACE("(%d,%p,%p)\n", iCount, lpProps, pcBytes);
721
722 if (iCount <= 0 || !lpProps ||
723 IsBadReadPtr(lpProps, iCount * sizeof(SPropValue)))
724 return MAPI_E_INVALID_PARAMETER;
725
726 for (i = 0; i < ulCount; i++)
727 {
728 ULONG ulPropSize = 0;
729
730 if (FBadProp(&lpProps[i]) || lpProps[i].ulPropTag == PROP_ID_NULL ||
731 lpProps[i].ulPropTag == PROP_ID_INVALID)
732 return MAPI_E_INVALID_PARAMETER;
733
734 if (PROP_TYPE(lpProps[i].ulPropTag) != PT_OBJECT)
735 {
736 ulPropSize = UlPropSize(&lpProps[i]);
737 if (!ulPropSize)
738 return MAPI_E_INVALID_PARAMETER;
739 }
740
741 switch (PROP_TYPE(lpProps[i].ulPropTag))
742 {
743 case PT_STRING8:
744 case PT_UNICODE:
745 case PT_CLSID:
746 case PT_BINARY:
747 case PT_MV_I2:
748 case PT_MV_I4:
749 case PT_MV_I8:
750 case PT_MV_R4:
751 case PT_MV_R8:
752 case PT_MV_CURRENCY:
753 case PT_MV_SYSTIME:
754 case PT_MV_APPTIME:
755 ulPropSize += sizeof(SPropValue);
756 break;
757 case PT_MV_CLSID:
758 ulPropSize += lpProps[i].Value.MVszA.cValues * sizeof(char*) + sizeof(SPropValue);
759 break;
760 case PT_MV_STRING8:
761 case PT_MV_UNICODE:
762 ulPropSize += lpProps[i].Value.MVszA.cValues * sizeof(char*) + sizeof(SPropValue);
763 break;
764 case PT_MV_BINARY:
765 ulPropSize += lpProps[i].Value.MVbin.cValues * sizeof(SBinary) + sizeof(SPropValue);
766 break;
767 default:
768 ulPropSize = sizeof(SPropValue);
769 break;
770 }
771 ulBytes += ulPropSize;
772 }
773 if (pcBytes)
774 *pcBytes = ulBytes;
775
776 return S_OK;
777 }
778
779 /*************************************************************************
780 * ScCopyProps@16 (MAPI32.171)
781 *
782 * Copy an array of property values into a buffer suited for serialisation.
783 *
784 * PARAMS
785 * cValues [I] Number of properties in lpProps
786 * lpProps [I] Property array to copy
787 * lpDst [O] Destination for the serialised data
788 * lpCount [O] If non-NULL, destination for the number of bytes of data written to lpDst
789 *
790 * RETURNS
791 * Success: S_OK. lpDst contains the serialised data from lpProps.
792 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
793 *
794 * NOTES
795 * The resulting property value array is stored in a contiguous block starting at lpDst.
796 */
797 SCODE WINAPI ScCopyProps(int cValues, LPSPropValue lpProps, LPVOID lpDst, ULONG *lpCount)
798 {
799 LPSPropValue lpDest = (LPSPropValue)lpDst;
800 char *lpDataDest = (char *)(lpDest + cValues);
801 ULONG ulLen, i;
802 int iter;
803
804 TRACE("(%d,%p,%p,%p)\n", cValues, lpProps, lpDst, lpCount);
805
806 if (!lpProps || cValues < 0 || !lpDest)
807 return MAPI_E_INVALID_PARAMETER;
808
809 memcpy(lpDst, lpProps, cValues * sizeof(SPropValue));
810
811 for (iter = 0; iter < cValues; iter++)
812 {
813 switch (PROP_TYPE(lpProps->ulPropTag))
814 {
815 case PT_CLSID:
816 lpDest->Value.lpguid = (LPGUID)lpDataDest;
817 *lpDest->Value.lpguid = *lpProps->Value.lpguid;
818 lpDataDest += sizeof(GUID);
819 break;
820 case PT_STRING8:
821 ulLen = lstrlenA(lpProps->Value.lpszA) + 1u;
822 lpDest->Value.lpszA = lpDataDest;
823 memcpy(lpDest->Value.lpszA, lpProps->Value.lpszA, ulLen);
824 lpDataDest += ulLen;
825 break;
826 case PT_UNICODE:
827 ulLen = (strlenW(lpProps->Value.lpszW) + 1u) * sizeof(WCHAR);
828 lpDest->Value.lpszW = (LPWSTR)lpDataDest;
829 memcpy(lpDest->Value.lpszW, lpProps->Value.lpszW, ulLen);
830 lpDataDest += ulLen;
831 break;
832 case PT_BINARY:
833 lpDest->Value.bin.lpb = (LPBYTE)lpDataDest;
834 memcpy(lpDest->Value.bin.lpb, lpProps->Value.bin.lpb, lpProps->Value.bin.cb);
835 lpDataDest += lpProps->Value.bin.cb;
836 break;
837 default:
838 if (lpProps->ulPropTag & MV_FLAG)
839 {
840 lpDest->Value.MVi.cValues = lpProps->Value.MVi.cValues;
841 /* Note: Assignment uses lppszA but covers all cases by union aliasing */
842 lpDest->Value.MVszA.lppszA = (char**)lpDataDest;
843
844 switch (PROP_TYPE(lpProps->ulPropTag))
845 {
846 case PT_MV_STRING8:
847 {
848 lpDataDest += lpProps->Value.MVszA.cValues * sizeof(char *);
849
850 for (i = 0; i < lpProps->Value.MVszA.cValues; i++)
851 {
852 ULONG ulStrLen = lstrlenA(lpProps->Value.MVszA.lppszA[i]) + 1u;
853
854 lpDest->Value.MVszA.lppszA[i] = lpDataDest;
855 memcpy(lpDataDest, lpProps->Value.MVszA.lppszA[i], ulStrLen);
856 lpDataDest += ulStrLen;
857 }
858 break;
859 }
860 case PT_MV_UNICODE:
861 {
862 lpDataDest += lpProps->Value.MVszW.cValues * sizeof(WCHAR *);
863
864 for (i = 0; i < lpProps->Value.MVszW.cValues; i++)
865 {
866 ULONG ulStrLen = (strlenW(lpProps->Value.MVszW.lppszW[i]) + 1u) * sizeof(WCHAR);
867
868 lpDest->Value.MVszW.lppszW[i] = (LPWSTR)lpDataDest;
869 memcpy(lpDataDest, lpProps->Value.MVszW.lppszW[i], ulStrLen);
870 lpDataDest += ulStrLen;
871 }
872 break;
873 }
874 case PT_MV_BINARY:
875 {
876 lpDataDest += lpProps->Value.MVszW.cValues * sizeof(SBinary);
877
878 for (i = 0; i < lpProps->Value.MVszW.cValues; i++)
879 {
880 lpDest->Value.MVbin.lpbin[i].cb = lpProps->Value.MVbin.lpbin[i].cb;
881 lpDest->Value.MVbin.lpbin[i].lpb = (LPBYTE)lpDataDest;
882 memcpy(lpDataDest, lpProps->Value.MVbin.lpbin[i].lpb, lpDest->Value.MVbin.lpbin[i].cb);
883 lpDataDest += lpDest->Value.MVbin.lpbin[i].cb;
884 }
885 break;
886 }
887 default:
888 /* No embedded pointers, just copy the data over */
889 ulLen = UlPropSize(lpProps);
890 memcpy(lpDest->Value.MVi.lpi, lpProps->Value.MVi.lpi, ulLen);
891 lpDataDest += ulLen;
892 break;
893 }
894 break;
895 }
896 }
897 lpDest++;
898 lpProps++;
899 }
900 if (lpCount)
901 *lpCount = lpDataDest - (char *)lpDst;
902
903 return S_OK;
904 }
905
906 /*************************************************************************
907 * ScRelocProps@20 (MAPI32.172)
908 *
909 * Relocate the pointers in an array of property values after it has been copied.
910 *
911 * PARAMS
912 * cValues [I] Number of properties in lpProps
913 * lpProps [O] Property array to relocate the pointers in.
914 * lpOld [I] Position where the data was copied from
915 * lpNew [I] Position where the data was copied to
916 * lpCount [O] If non-NULL, destination for the number of bytes of data at lpDst
917 *
918 * RETURNS
919 * Success: S_OK. Any pointers in lpProps are relocated.
920 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
921 *
922 * NOTES
923 * MSDN states that this function can be used for serialisation by passing
924 * NULL as either lpOld or lpNew, thus converting any pointers in lpProps
925 * between offsets and pointers. This does not work in native (it crashes),
926 * and cannot be made to work in Wine because the original interface design
927 * is deficient. The only use left for this function is to remap pointers
928 * in a contiguous property array that has been copied with memcpy() to
929 * another memory location.
930 */
931 SCODE WINAPI ScRelocProps(int cValues, LPSPropValue lpProps, LPVOID lpOld,
932 LPVOID lpNew, ULONG *lpCount)
933 {
934 static const BOOL bBadPtr = TRUE; /* Windows bug - Assumes source is bad */
935 LPSPropValue lpDest = lpProps;
936 ULONG ulCount = cValues * sizeof(SPropValue);
937 ULONG ulLen, i;
938 int iter;
939
940 TRACE("(%d,%p,%p,%p,%p)\n", cValues, lpProps, lpOld, lpNew, lpCount);
941
942 if (!lpProps || cValues < 0 || !lpOld || !lpNew)
943 return MAPI_E_INVALID_PARAMETER;
944
945 /* The reason native doesn't work as MSDN states is that it assumes that
946 * the lpProps pointer contains valid pointers. This is obviously not
947 * true if the array is being read back from serialisation (the pointers
948 * are just offsets). Native can't actually work converting the pointers to
949 * offsets either, because it converts any array pointers to offsets then
950 * _dereferences the offset_ in order to convert the array elements!
951 *
952 * The code below would handle both cases except that the design of this
953 * function makes it impossible to know when the pointers in lpProps are
954 * valid. If both lpOld and lpNew are non-NULL, native reads the pointers
955 * after converting them, so we must do the same. It seems this
956 * functionality was never tested by MS.
957 */
958
959 #define RELOC_PTR(p) (((char*)(p)) - (char*)lpOld + (char*)lpNew)
960
961 for (iter = 0; iter < cValues; iter++)
962 {
963 switch (PROP_TYPE(lpDest->ulPropTag))
964 {
965 case PT_CLSID:
966 lpDest->Value.lpguid = (LPGUID)RELOC_PTR(lpDest->Value.lpguid);
967 ulCount += sizeof(GUID);
968 break;
969 case PT_STRING8:
970 ulLen = bBadPtr ? 0 : lstrlenA(lpDest->Value.lpszA) + 1u;
971 lpDest->Value.lpszA = RELOC_PTR(lpDest->Value.lpszA);
972 if (bBadPtr)
973 ulLen = lstrlenA(lpDest->Value.lpszA) + 1u;
974 ulCount += ulLen;
975 break;
976 case PT_UNICODE:
977 ulLen = bBadPtr ? 0 : (lstrlenW(lpDest->Value.lpszW) + 1u) * sizeof(WCHAR);
978 lpDest->Value.lpszW = (LPWSTR)RELOC_PTR(lpDest->Value.lpszW);
979 if (bBadPtr)
980 ulLen = (strlenW(lpDest->Value.lpszW) + 1u) * sizeof(WCHAR);
981 ulCount += ulLen;
982 break;
983 case PT_BINARY:
984 lpDest->Value.bin.lpb = (LPBYTE)RELOC_PTR(lpDest->Value.bin.lpb);
985 ulCount += lpDest->Value.bin.cb;
986 break;
987 default:
988 if (lpDest->ulPropTag & MV_FLAG)
989 {
990 /* Since we have to access the array elements, don't map the
991 * array unless it is invalid (otherwise, map it at the end)
992 */
993 if (bBadPtr)
994 lpDest->Value.MVszA.lppszA = (LPSTR*)RELOC_PTR(lpDest->Value.MVszA.lppszA);
995
996 switch (PROP_TYPE(lpProps->ulPropTag))
997 {
998 case PT_MV_STRING8:
999 {
1000 ulCount += lpDest->Value.MVszA.cValues * sizeof(char *);
1001
1002 for (i = 0; i < lpDest->Value.MVszA.cValues; i++)
1003 {
1004 ULONG ulStrLen = bBadPtr ? 0 : lstrlenA(lpDest->Value.MVszA.lppszA[i]) + 1u;
1005
1006 lpDest->Value.MVszA.lppszA[i] = RELOC_PTR(lpDest->Value.MVszA.lppszA[i]);
1007 if (bBadPtr)
1008 ulStrLen = lstrlenA(lpDest->Value.MVszA.lppszA[i]) + 1u;
1009 ulCount += ulStrLen;
1010 }
1011 break;
1012 }
1013 case PT_MV_UNICODE:
1014 {
1015 ulCount += lpDest->Value.MVszW.cValues * sizeof(WCHAR *);
1016
1017 for (i = 0; i < lpDest->Value.MVszW.cValues; i++)
1018 {
1019 ULONG ulStrLen = bBadPtr ? 0 : (strlenW(lpDest->Value.MVszW.lppszW[i]) + 1u) * sizeof(WCHAR);
1020
1021 lpDest->Value.MVszW.lppszW[i] = (LPWSTR)RELOC_PTR(lpDest->Value.MVszW.lppszW[i]);
1022 if (bBadPtr)
1023 ulStrLen = (strlenW(lpDest->Value.MVszW.lppszW[i]) + 1u) * sizeof(WCHAR);
1024 ulCount += ulStrLen;
1025 }
1026 break;
1027 }
1028 case PT_MV_BINARY:
1029 {
1030 ulCount += lpDest->Value.MVszW.cValues * sizeof(SBinary);
1031
1032 for (i = 0; i < lpDest->Value.MVszW.cValues; i++)
1033 {
1034 lpDest->Value.MVbin.lpbin[i].lpb = (LPBYTE)RELOC_PTR(lpDest->Value.MVbin.lpbin[i].lpb);
1035 ulCount += lpDest->Value.MVbin.lpbin[i].cb;
1036 }
1037 break;
1038 }
1039 default:
1040 ulCount += UlPropSize(lpDest);
1041 break;
1042 }
1043 if (!bBadPtr)
1044 lpDest->Value.MVszA.lppszA = (LPSTR*)RELOC_PTR(lpDest->Value.MVszA.lppszA);
1045 break;
1046 }
1047 }
1048 lpDest++;
1049 }
1050 if (lpCount)
1051 *lpCount = ulCount;
1052
1053 return S_OK;
1054 }
1055
1056 /*************************************************************************
1057 * LpValFindProp@12 (MAPI32.173)
1058 *
1059 * Find a property with a given property id in a property array.
1060 *
1061 * PARAMS
1062 * ulPropTag [I] Property tag containing property id to find
1063 * cValues [I] Number of properties in lpProps
1064 * lpProps [I] Property array to search
1065 *
1066 * RETURNS
1067 * A pointer to the matching property, or NULL if none was found.
1068 *
1069 * NOTES
1070 * This function matches only on the property id and does not care if the
1071 * property types differ.
1072 */
1073 LPSPropValue WINAPI LpValFindProp(ULONG ulPropTag, ULONG cValues, LPSPropValue lpProps)
1074 {
1075 TRACE("(%d,%d,%p)\n", ulPropTag, cValues, lpProps);
1076
1077 if (lpProps && cValues)
1078 {
1079 ULONG i;
1080 for (i = 0; i < cValues; i++)
1081 {
1082 if (PROP_ID(ulPropTag) == PROP_ID(lpProps[i].ulPropTag))
1083 return &lpProps[i];
1084 }
1085 }
1086 return NULL;
1087 }
1088
1089 /*************************************************************************
1090 * ScDupPropset@16 (MAPI32.174)
1091 *
1092 * Duplicate a property value array into a contiguous block of memory.
1093 *
1094 * PARAMS
1095 * cValues [I] Number of properties in lpProps
1096 * lpProps [I] Property array to duplicate
1097 * lpAlloc [I] Memory allocation function, use MAPIAllocateBuffer()
1098 * lpNewProp [O] Destination for the newly duplicated property value array
1099 *
1100 * RETURNS
1101 * Success: S_OK. *lpNewProp contains the duplicated array.
1102 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
1103 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
1104 */
1105 SCODE WINAPI ScDupPropset(int cValues, LPSPropValue lpProps,
1106 LPALLOCATEBUFFER lpAlloc, LPSPropValue *lpNewProp)
1107 {
1108 ULONG ulCount;
1109 SCODE sc;
1110
1111 TRACE("(%d,%p,%p,%p)\n", cValues, lpProps, lpAlloc, lpNewProp);
1112
1113 sc = ScCountProps(cValues, lpProps, &ulCount);
1114 if (SUCCEEDED(sc))
1115 {
1116 sc = lpAlloc(ulCount, (LPVOID*)lpNewProp);
1117 if (SUCCEEDED(sc))
1118 sc = ScCopyProps(cValues, lpProps, *lpNewProp, &ulCount);
1119 }
1120 return sc;
1121 }
1122
1123 /*************************************************************************
1124 * FBadRglpszA@8 (MAPI32.175)
1125 *
1126 * Determine if an array of strings is invalid
1127 *
1128 * PARAMS
1129 * lppszStrs [I] Array of strings to check
1130 * ulCount [I] Number of strings in lppszStrs
1131 *
1132 * RETURNS
1133 * TRUE, if lppszStrs is invalid, FALSE otherwise.
1134 */
1135 BOOL WINAPI FBadRglpszA(LPSTR *lppszStrs, ULONG ulCount)
1136 {
1137 ULONG i;
1138
1139 TRACE("(%p,%d)\n", lppszStrs, ulCount);
1140
1141 if (!ulCount)
1142 return FALSE;
1143
1144 if (!lppszStrs || IsBadReadPtr(lppszStrs, ulCount * sizeof(LPWSTR)))
1145 return TRUE;
1146
1147 for (i = 0; i < ulCount; i++)
1148 {
1149 if (!lppszStrs[i] || IsBadStringPtrA(lppszStrs[i], -1))
1150 return TRUE;
1151 }
1152 return FALSE;
1153 }
1154
1155 /*************************************************************************
1156 * FBadRglpszW@8 (MAPI32.176)
1157 *
1158 * See FBadRglpszA.
1159 */
1160 BOOL WINAPI FBadRglpszW(LPWSTR *lppszStrs, ULONG ulCount)
1161 {
1162 ULONG i;
1163
1164 TRACE("(%p,%d)\n", lppszStrs, ulCount);
1165
1166 if (!ulCount)
1167 return FALSE;
1168
1169 if (!lppszStrs || IsBadReadPtr(lppszStrs, ulCount * sizeof(LPWSTR)))
1170 return TRUE;
1171
1172 for (i = 0; i < ulCount; i++)
1173 {
1174 if (!lppszStrs[i] || IsBadStringPtrW(lppszStrs[i], -1))
1175 return TRUE;
1176 }
1177 return FALSE;
1178 }
1179
1180 /*************************************************************************
1181 * FBadRowSet@4 (MAPI32.177)
1182 *
1183 * Determine if a row is invalid
1184 *
1185 * PARAMS
1186 * lpRow [I] Row to check
1187 *
1188 * RETURNS
1189 * TRUE, if lpRow is invalid, FALSE otherwise.
1190 */
1191 BOOL WINAPI FBadRowSet(LPSRowSet lpRowSet)
1192 {
1193 ULONG i;
1194 TRACE("(%p)\n", lpRowSet);
1195
1196 if (!lpRowSet || IsBadReadPtr(lpRowSet, CbSRowSet(lpRowSet)))
1197 return TRUE;
1198
1199 for (i = 0; i < lpRowSet->cRows; i++)
1200 {
1201 if (FBadRow(&lpRowSet->aRow[i]))
1202 return TRUE;
1203 }
1204 return FALSE;
1205 }
1206
1207 /*************************************************************************
1208 * FBadPropTag@4 (MAPI32.179)
1209 *
1210 * Determine if a property tag is invalid
1211 *
1212 * PARAMS
1213 * ulPropTag [I] Property tag to check
1214 *
1215 * RETURNS
1216 * TRUE, if ulPropTag is invalid, FALSE otherwise.
1217 */
1218 ULONG WINAPI FBadPropTag(ULONG ulPropTag)
1219 {
1220 TRACE("(0x%08x)\n", ulPropTag);
1221
1222 switch (ulPropTag & (~MV_FLAG & PROP_TYPE_MASK))
1223 {
1224 case PT_UNSPECIFIED:
1225 case PT_NULL:
1226 case PT_I2:
1227 case PT_LONG:
1228 case PT_R4:
1229 case PT_DOUBLE:
1230 case PT_CURRENCY:
1231 case PT_APPTIME:
1232 case PT_ERROR:
1233 case PT_BOOLEAN:
1234 case PT_OBJECT:
1235 case PT_I8:
1236 case PT_STRING8:
1237 case PT_UNICODE:
1238 case PT_SYSTIME:
1239 case PT_CLSID:
1240 case PT_BINARY:
1241 return FALSE;
1242 }
1243 return TRUE;
1244 }
1245
1246 /*************************************************************************
1247 * FBadRow@4 (MAPI32.180)
1248 *
1249 * Determine if a row is invalid
1250 *
1251 * PARAMS
1252 * lpRow [I] Row to check
1253 *
1254 * RETURNS
1255 * TRUE, if lpRow is invalid, FALSE otherwise.
1256 */
1257 ULONG WINAPI FBadRow(LPSRow lpRow)
1258 {
1259 ULONG i;
1260 TRACE("(%p)\n", lpRow);
1261
1262 if (!lpRow || IsBadReadPtr(lpRow, sizeof(SRow)) || !lpRow->lpProps ||
1263 IsBadReadPtr(lpRow->lpProps, lpRow->cValues * sizeof(SPropValue)))
1264 return TRUE;
1265
1266 for (i = 0; i < lpRow->cValues; i++)
1267 {
1268 if (FBadProp(&lpRow->lpProps[i]))
1269 return TRUE;
1270 }
1271 return FALSE;
1272 }
1273
1274 /*************************************************************************
1275 * FBadProp@4 (MAPI32.181)
1276 *
1277 * Determine if a property is invalid
1278 *
1279 * PARAMS
1280 * lpProp [I] Property to check
1281 *
1282 * RETURNS
1283 * TRUE, if lpProp is invalid, FALSE otherwise.
1284 */
1285 ULONG WINAPI FBadProp(LPSPropValue lpProp)
1286 {
1287 if (!lpProp || IsBadReadPtr(lpProp, sizeof(SPropValue)) ||
1288 FBadPropTag(lpProp->ulPropTag))
1289 return TRUE;
1290
1291 switch (PROP_TYPE(lpProp->ulPropTag))
1292 {
1293 /* Single value properties containing pointers */
1294 case PT_STRING8:
1295 if (!lpProp->Value.lpszA || IsBadStringPtrA(lpProp->Value.lpszA, -1))
1296 return TRUE;
1297 break;
1298 case PT_UNICODE:
1299 if (!lpProp->Value.lpszW || IsBadStringPtrW(lpProp->Value.lpszW, -1))
1300 return TRUE;
1301 break;
1302 case PT_BINARY:
1303 if (IsBadReadPtr(lpProp->Value.bin.lpb, lpProp->Value.bin.cb))
1304 return TRUE;
1305 break;
1306 case PT_CLSID:
1307 if (IsBadReadPtr(lpProp->Value.lpguid, sizeof(GUID)))
1308 return TRUE;
1309 break;
1310
1311 /* Multiple value properties (arrays) containing no pointers */
1312 case PT_MV_I2:
1313 return PROP_BadArray(lpProp, sizeof(SHORT));
1314 case PT_MV_LONG:
1315 return PROP_BadArray(lpProp, sizeof(LONG));
1316 case PT_MV_LONGLONG:
1317 return PROP_BadArray(lpProp, sizeof(LONG64));
1318 case PT_MV_FLOAT:
1319 return PROP_BadArray(lpProp, sizeof(float));
1320 case PT_MV_SYSTIME:
1321 return PROP_BadArray(lpProp, sizeof(FILETIME));
1322 case PT_MV_APPTIME:
1323 case PT_MV_DOUBLE:
1324 return PROP_BadArray(lpProp, sizeof(double));
1325 case PT_MV_CURRENCY:
1326 return PROP_BadArray(lpProp, sizeof(CY));
1327 case PT_MV_CLSID:
1328 return PROP_BadArray(lpProp, sizeof(GUID));
1329
1330 /* Multiple value properties containing pointers */
1331 case PT_MV_STRING8:
1332 return FBadRglpszA(lpProp->Value.MVszA.lppszA,
1333 lpProp->Value.MVszA.cValues);
1334 case PT_MV_UNICODE:
1335 return FBadRglpszW(lpProp->Value.MVszW.lppszW,
1336 lpProp->Value.MVszW.cValues);
1337 case PT_MV_BINARY:
1338 return FBadEntryList(&lpProp->Value.MVbin);
1339 }
1340 return FALSE;
1341 }
1342
1343 /*************************************************************************
1344 * FBadColumnSet@4 (MAPI32.182)
1345 *
1346 * Determine if an array of property tags is invalid
1347 *
1348 * PARAMS
1349 * lpCols [I] Property tag array to check
1350 *
1351 * RETURNS
1352 * TRUE, if lpCols is invalid, FALSE otherwise.
1353 */
1354 ULONG WINAPI FBadColumnSet(LPSPropTagArray lpCols)
1355 {
1356 ULONG ulRet = FALSE, i;
1357
1358 TRACE("(%p)\n", lpCols);
1359
1360 if (!lpCols || IsBadReadPtr(lpCols, CbSPropTagArray(lpCols)))
1361 ulRet = TRUE;
1362 else
1363 {
1364 for (i = 0; i < lpCols->cValues; i++)
1365 {
1366 if ((lpCols->aulPropTag[i] & PROP_TYPE_MASK) == PT_ERROR ||
1367 FBadPropTag(lpCols->aulPropTag[i]))
1368 {
1369 ulRet = TRUE;
1370 break;
1371 }
1372 }
1373 }
1374 TRACE("Returning %s\n", ulRet ? "TRUE" : "FALSE");
1375 return ulRet;
1376 }
1377
1378
1379 /**************************************************************************
1380 * IMAPIProp {MAPI32}
1381 *
1382 * The default Mapi interface for manipulating object properties.
1383 *
1384 * DESCRIPTION
1385 * This object provides an interface to an objects properties. It is exposed
1386 * by several types of Mapi objects in order to simplify the querying and
1387 * modification of properties.
1388 *
1389 * METHODS
1390 */
1391
1392 /* A single property in a property data collection */
1393 typedef struct
1394 {
1395 struct list entry;
1396 ULONG ulAccess; /* The property value access level */
1397 LPSPropValue value; /* The property value */
1398 } IPropDataItem, *LPIPropDataItem;
1399
1400 /* The main property data collection structure */
1401 typedef struct
1402 {
1403 const IPropDataVtbl *lpVtbl;
1404 LONG lRef; /* Reference count */
1405 ALLOCATEBUFFER *lpAlloc; /* Memory allocation routine */
1406 ALLOCATEMORE *lpMore; /* Linked memory allocation routine */
1407 FREEBUFFER *lpFree; /* Memory free routine */
1408 ULONG ulObjAccess; /* Object access level */
1409 ULONG ulNumValues; /* Number of items in values list */
1410 struct list values; /* List of property values */
1411 CRITICAL_SECTION cs; /* Lock for thread safety */
1412 } IPropDataImpl;
1413
1414 /* Internal - Get a property value, assumes lock is held */
1415 static IPropDataItem *IMAPIPROP_GetValue(IPropDataImpl *This, ULONG ulPropTag)
1416 {
1417 struct list *cursor;
1418
1419 LIST_FOR_EACH(cursor, &This->values)
1420 {
1421 LPIPropDataItem current = LIST_ENTRY(cursor, IPropDataItem, entry);
1422 /* Note that propery types don't have to match, just Id's */
1423 if (PROP_ID(current->value->ulPropTag) == PROP_ID(ulPropTag))
1424 return current;
1425 }
1426 return NULL;
1427 }
1428
1429 /* Internal - Add a new property value, assumes lock is held */
1430 static IPropDataItem *IMAPIPROP_AddValue(IPropDataImpl *This,
1431 LPSPropValue lpProp)
1432 {
1433 LPVOID lpMem;
1434 LPIPropDataItem lpNew;
1435 HRESULT hRet;
1436
1437 hRet = This->lpAlloc(sizeof(IPropDataItem), &lpMem);
1438
1439 if (SUCCEEDED(hRet))
1440 {
1441 lpNew = lpMem;
1442 lpNew->ulAccess = IPROP_READWRITE;
1443
1444 /* Allocate the value separately so we can update it easily */
1445 lpMem = NULL;
1446 hRet = This->lpAlloc(sizeof(SPropValue), &lpMem);
1447 if (SUCCEEDED(hRet))
1448 {
1449 lpNew->value = lpMem;
1450
1451 hRet = PropCopyMore(lpNew->value, lpProp, This->lpMore, lpMem);
1452 if (SUCCEEDED(hRet))
1453 {
1454 list_add_tail(&This->values, &lpNew->entry);
1455 This->ulNumValues++;
1456 return lpNew;
1457 }
1458 This->lpFree(lpNew->value);
1459 }
1460 This->lpFree(lpNew);
1461 }
1462 return NULL;
1463 }
1464
1465 /* Internal - Lock an IPropData object */
1466 static inline void IMAPIPROP_Lock(IPropDataImpl *This)
1467 {
1468 EnterCriticalSection(&This->cs);
1469 }
1470
1471 /* Internal - Unlock an IPropData object */
1472 static inline void IMAPIPROP_Unlock(IPropDataImpl *This)
1473 {
1474 LeaveCriticalSection(&This->cs);
1475 }
1476
1477 /* This one seems to be missing from mapidefs.h */
1478 #define CbNewSPropProblemArray(c) \
1479 (offsetof(SPropProblemArray,aProblem)+(c)*sizeof(SPropProblem))
1480
1481 /**************************************************************************
1482 * IMAPIProp_QueryInterface {MAPI32}
1483 *
1484 * Inherited method from the IUnknown Interface.
1485 * See IUnknown_QueryInterface.
1486 *
1487 * NOTES
1488 * This object exposes the following interfaces:
1489 * - IUnknown() : The default interface for all COM-Objects.
1490 * - IMAPIProp() : The default Mapi interface for manipulating object properties.
1491 */
1492 static inline HRESULT IMAPIProp_fnQueryInterface(LPMAPIPROP iface, REFIID riid, LPVOID *ppvObj)
1493 {
1494 IPropDataImpl *This = (IPropDataImpl*)iface;
1495
1496 TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppvObj);
1497
1498 if (!ppvObj || !riid)
1499 return MAPI_E_INVALID_PARAMETER;
1500
1501 *ppvObj = NULL;
1502
1503 if(IsEqualIID(riid, &IID_IUnknown) ||
1504 IsEqualIID(riid, &IID_IMAPIProp) ||
1505 IsEqualIID(riid, &IID_IMAPIPropData))
1506 {
1507 *ppvObj = This;
1508 IPropData_AddRef(iface);
1509 TRACE("returning %p\n", *ppvObj);
1510 return S_OK;
1511 }
1512
1513 TRACE("returning E_NOINTERFACE\n");
1514 return MAPI_E_INTERFACE_NOT_SUPPORTED;
1515 }
1516
1517 /**************************************************************************
1518 * IMAPIProp_AddRef {MAPI32}
1519 *
1520 * Inherited method from the IUnknown Interface.
1521 * See IUnknown_AddRef.
1522 */
1523 static inline ULONG IMAPIProp_fnAddRef(LPMAPIPROP iface)
1524 {
1525 IPropDataImpl *This = (IPropDataImpl*)iface;
1526
1527 TRACE("(%p)->(count before=%u)\n", This, This->lRef);
1528
1529 return InterlockedIncrement(&This->lRef);
1530 }
1531
1532 /**************************************************************************
1533 * IMAPIProp_Release {MAPI32}
1534 *
1535 * Inherited method from the IUnknown Interface.
1536 * See IUnknown_Release.
1537 */
1538 static inline ULONG IMAPIProp_fnRelease(LPMAPIPROP iface)
1539 {
1540 IPropDataImpl *This = (IPropDataImpl*)iface;
1541 LONG lRef;
1542
1543 TRACE("(%p)->(count before=%u)\n", This, This->lRef);
1544
1545 lRef = InterlockedDecrement(&This->lRef);
1546 if (!lRef)
1547 {
1548 TRACE("Destroying IPropData (%p)\n",This);
1549
1550 /* Note: No need to lock, since no other thread is referencing iface */
1551 while (!list_empty(&This->values))
1552 {
1553 struct list *head = list_head(&This->values);
1554 LPIPropDataItem current = LIST_ENTRY(head, IPropDataItem, entry);
1555 list_remove(head);
1556 This->lpFree(current->value);
1557 This->lpFree(current);
1558 }
1559 This->cs.DebugInfo->Spare[0] = 0;
1560 DeleteCriticalSection(&This->cs);
1561 This->lpFree(This);
1562 }
1563 return (ULONG)lRef;
1564 }
1565
1566 /**************************************************************************
1567 * IMAPIProp_GetLastError {MAPI32}
1568 *
1569 * Get information about the last error that occurred in an IMAPIProp object.
1570 *
1571 * PARAMS
1572 * iface [I] IMAPIProp object that experienced the error
1573 * hRes [I] Result of the call that returned an error
1574 * ulFlags [I] 0=return Ascii strings, MAPI_UNICODE=return Unicode strings
1575 * lppError [O] Destination for detailed error information
1576 *
1577 * RETURNS
1578 * Success: S_OK. *lppError contains details about the last error.
1579 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
1580 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
1581 *
1582 * NOTES
1583 * - If this function succeeds, the returned information in *lppError must be
1584 * freed using MAPIFreeBuffer() once the caller is finished with it.
1585 * - It is possible for this function to succeed and set *lppError to NULL,
1586 * if there is no further information to report about hRes.
1587 */
1588 static inline HRESULT
1589 IMAPIProp_fnGetLastError(LPMAPIPROP iface, HRESULT hRes,
1590 ULONG ulFlags, LPMAPIERROR *lppError)
1591 {
1592 TRACE("(%p,0x%08X,0x%08X,%p)\n", iface, hRes, ulFlags, lppError);
1593
1594 if (!lppError || SUCCEEDED(hRes) || (ulFlags & ~MAPI_UNICODE))
1595 return MAPI_E_INVALID_PARAMETER;
1596
1597 *lppError = NULL;
1598 return S_OK;
1599 }
1600
1601 /**************************************************************************
1602 * IMAPIProp_SaveChanges {MAPI32}
1603 *
1604 * Update any changes made to a transactional IMAPIProp object.
1605 *
1606 * PARAMS
1607 * iface [I] IMAPIProp object to update
1608 * ulFlags [I] Flags controlling the update.
1609 *
1610 * RETURNS
1611 * Success: S_OK. Any outstanding changes are committed to the object.
1612 * Failure: An HRESULT error code describing the error.
1613 */
1614 static inline HRESULT
1615 IMAPIProp_fnSaveChanges(LPMAPIPROP iface, ULONG ulFlags)
1616 {
1617 TRACE("(%p,0x%08X)\n", iface, ulFlags);
1618
1619 /* Since this object is not transacted we do not need to implement this */
1620 /* FIXME: Should we set the access levels to clean? */
1621 return S_OK;
1622 }
1623
1624 /**************************************************************************
1625 * IMAPIProp_GetProps {MAPI32}
1626 *
1627 * Get property values from an IMAPIProp object.
1628 *
1629 * PARAMS
1630 * iface [I] IMAPIProp object to get the property values from
1631 * lpTags [I] Property tage of property values to be retrieved
1632 * ulFlags [I] Return 0=Ascii MAPI_UNICODE=Unicode strings for
1633 * unspecified types
1634 * lpCount [O] Destination for number of properties returned
1635 * lppProps [O] Destination for returned property values
1636 *
1637 * RETURNS
1638 * Success: S_OK. *lppProps and *lpCount are updated.
1639 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1640 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
1641 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
1642 * successfully.
1643 * NOTES
1644 * - If MAPI_W_ERRORS_RETURNED is returned, any properties that could not be
1645 * retrieved from iface are present in lppProps with their type
1646 * changed to PT_ERROR and Id unchanged.
1647 */
1648 static inline HRESULT
1649 IMAPIProp_fnGetProps(LPMAPIPROP iface, LPSPropTagArray lpTags,
1650 ULONG ulFlags, ULONG *lpCount, LPSPropValue *lppProps)
1651 {
1652 ULONG i;
1653 HRESULT hRet = S_OK;
1654 IPropDataImpl *This = (IPropDataImpl*)iface;
1655
1656 TRACE("(%p,%p,0x%08x,%p,%p) stub\n", iface, lpTags, ulFlags,
1657 lpCount, lppProps);
1658
1659 if (!iface || ulFlags & ~MAPI_UNICODE || !lpTags || *lpCount || !lppProps)
1660 return MAPI_E_INVALID_PARAMETER;
1661
1662 FIXME("semi-stub, flags not supported\n");
1663
1664 *lpCount = lpTags->cValues;
1665 *lppProps = NULL;
1666
1667 if (*lpCount)
1668 {
1669 hRet = MAPIAllocateBuffer(*lpCount * sizeof(SPropValue), (LPVOID*)lppProps);
1670 if (FAILED(hRet))
1671 return hRet;
1672
1673 IMAPIPROP_Lock(This);
1674
1675 for (i = 0; i < lpTags->cValues; i++)
1676 {
1677 HRESULT hRetTmp = E_INVALIDARG;
1678 LPIPropDataItem item;
1679
1680 item = IMAPIPROP_GetValue(This, lpTags->aulPropTag[i]);
1681
1682 if (item)
1683 hRetTmp = PropCopyMore(&(*lppProps)[i], item->value,
1684 This->lpMore, *lppProps);
1685 if (FAILED(hRetTmp))
1686 {
1687 hRet = MAPI_W_ERRORS_RETURNED;
1688 (*lppProps)[i].ulPropTag =
1689 CHANGE_PROP_TYPE(lpTags->aulPropTag[i], PT_ERROR);
1690 }
1691 }
1692
1693 IMAPIPROP_Unlock(This);
1694 }
1695 return hRet;
1696 }
1697
1698 /**************************************************************************
1699 * MAPIProp_GetPropList {MAPI32}
1700 *
1701 * Get the list of property tags for all values in an IMAPIProp object.
1702 *
1703 * PARAMS
1704 * iface [I] IMAPIProp object to get the property tag list from
1705 * ulFlags [I] Return 0=Ascii MAPI_UNICODE=Unicode strings for
1706 * unspecified types
1707 * lppTags [O] Destination for the retrieved property tag list
1708 *
1709 * RETURNS
1710 * Success: S_OK. *lppTags contains the tags for all available properties.
1711 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1712 * MAPI_E_BAD_CHARWIDTH, if Ascii or Unicode strings are requested
1713 * and that type of string is not supported.
1714 */
1715 static inline HRESULT
1716 IMAPIProp_fnGetPropList(LPMAPIPROP iface, ULONG ulFlags,
1717 LPSPropTagArray *lppTags)
1718 {
1719 IPropDataImpl *This = (IPropDataImpl*)iface;
1720 ULONG i;
1721 HRESULT hRet;
1722
1723 TRACE("(%p,0x%08x,%p) stub\n", iface, ulFlags, lppTags);
1724
1725 if (!iface || ulFlags & ~MAPI_UNICODE || !lppTags)
1726 return MAPI_E_INVALID_PARAMETER;
1727
1728 FIXME("semi-stub, flags not supported\n");
1729
1730 *lppTags = NULL;
1731
1732 IMAPIPROP_Lock(This);
1733
1734 hRet = MAPIAllocateBuffer(CbNewSPropTagArray(This->ulNumValues),
1735 (LPVOID*)lppTags);
1736 if (SUCCEEDED(hRet))
1737 {
1738 struct list *cursor;
1739
1740 i = 0;
1741 LIST_FOR_EACH(cursor, &This->values)
1742 {
1743 LPIPropDataItem current = LIST_ENTRY(cursor, IPropDataItem, entry);
1744 (*lppTags)->aulPropTag[i] = current->value->ulPropTag;
1745 i++;
1746 }
1747 (*lppTags)->cValues = This->ulNumValues;
1748 }
1749
1750 IMAPIPROP_Unlock(This);
1751 return hRet;
1752 }
1753
1754 /**************************************************************************
1755 * IMAPIProp_OpenProperty {MAPI32}
1756 *
1757 * Not documented at this time.
1758 *
1759 * RETURNS
1760 * An HRESULT success/failure code.
1761 */
1762 static inline HRESULT
1763 IMAPIProp_fnOpenProperty(LPMAPIPROP iface, ULONG ulPropTag, LPCIID iid,
1764 ULONG ulOpts, ULONG ulFlags, LPUNKNOWN *lpUnk)
1765 {
1766 FIXME("(%p,%u,%s,%u,0x%08x,%p) stub\n", iface, ulPropTag,
1767 debugstr_guid(iid), ulOpts, ulFlags, lpUnk);
1768 return MAPI_E_NO_SUPPORT;
1769 }
1770
1771
1772 /**************************************************************************
1773 * IMAPIProp_SetProps {MAPI32}
1774 *
1775 * Add or edit the property values in an IMAPIProp object.
1776 *
1777 * PARAMS
1778 * iface [I] IMAPIProp object to get the property tag list from
1779 * ulValues [I] Number of properties in lpProps
1780 * lpProps [I] Property values to set
1781 * lppProbs [O] Optional destination for any problems that occurred
1782 *
1783 * RETURNS
1784 * Success: S_OK. The properties in lpProps are added to iface if they don't
1785 * exist, or changed to the values in lpProps if they do
1786 * Failure: An HRESULT error code describing the error
1787 */
1788 static inline HRESULT
1789 IMAPIProp_fnSetProps(LPMAPIPROP iface, ULONG ulValues,
1790 LPSPropValue lpProps, LPSPropProblemArray *lppProbs)
1791 {
1792 IPropDataImpl *This = (IPropDataImpl*)iface;
1793 HRESULT hRet = S_OK;
1794 ULONG i;
1795
1796 TRACE("(%p,%u,%p,%p)\n", iface, ulValues, lpProps, lppProbs);
1797
1798 if (!iface || !lpProps)
1799 return MAPI_E_INVALID_PARAMETER;
1800
1801 for (i = 0; i < ulValues; i++)
1802 {
1803 if (FBadProp(&lpProps[i]) ||
1804 PROP_TYPE(lpProps[i].ulPropTag) == PT_OBJECT ||
1805 PROP_TYPE(lpProps[i].ulPropTag) == PT_NULL)
1806 return MAPI_E_INVALID_PARAMETER;
1807 }
1808
1809 IMAPIPROP_Lock(This);
1810
1811 /* FIXME: Under what circumstances is lpProbs created? */
1812 for (i = 0; i < ulValues; i++)
1813 {
1814 LPIPropDataItem item = IMAPIPROP_GetValue(This, lpProps[i].ulPropTag);
1815
1816 if (item)
1817 {
1818 HRESULT hRetTmp;
1819 LPVOID lpMem = NULL;
1820
1821 /* Found, so update the existing value */
1822 if (item->value->ulPropTag != lpProps[i].ulPropTag)
1823 FIXME("semi-stub, overwriting type (not coercing)\n");
1824
1825 hRetTmp = This->lpAlloc(sizeof(SPropValue), &lpMem);
1826 if (SUCCEEDED(hRetTmp))
1827 {
1828 hRetTmp = PropCopyMore(lpMem, &lpProps[i], This->lpMore, lpMem);
1829 if (SUCCEEDED(hRetTmp))
1830 {
1831 This->lpFree(item->value);
1832 item->value = lpMem;
1833 continue;
1834 }
1835 This->lpFree(lpMem);
1836 }
1837 hRet = hRetTmp;
1838 }
1839 else
1840 {
1841 /* Add new value */
1842 if (!IMAPIPROP_AddValue(This, &lpProps[i]))
1843 hRet = MAPI_E_NOT_ENOUGH_MEMORY;
1844 }
1845 }
1846
1847 IMAPIPROP_Unlock(This);
1848 return hRet;
1849 }
1850
1851 /**************************************************************************
1852 * IMAPIProp_DeleteProps {MAPI32}
1853 *
1854 * Delete one or more property values from an IMAPIProp object.
1855 *
1856 * PARAMS
1857 * iface [I] IMAPIProp object to remove property values from.
1858 * lpTags [I] Collection of property Id's to remove from iface.
1859 * lppProbs [O] Destination for problems encountered, if any.
1860 *
1861 * RETURNS
1862 * Success: S_OK. Any properties in iface matching property Id's in lpTags have
1863 * been deleted. If lppProbs is non-NULL it contains details of any
1864 * errors that occurred.
1865 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1866 * E_ACCESSDENIED, if this object was created using CreateIProp() and
1867 * a subsequent call to IPropData_SetObjAcess() was made specifying
1868 * IPROP_READONLY as the access type.
1869 *
1870 * NOTES
1871 * - lppProbs will not be populated for cases where a property Id is present
1872 * in lpTags but not in iface.
1873 * - lppProbs should be deleted with MAPIFreeBuffer() if returned.
1874 */
1875 static inline HRESULT
1876 IMAPIProp_fnDeleteProps(LPMAPIPROP iface, LPSPropTagArray lpTags,
1877 LPSPropProblemArray *lppProbs)
1878 {
1879 IPropDataImpl *This = (IPropDataImpl*)iface;
1880 ULONG i, numProbs = 0;
1881 HRESULT hRet = S_OK;
1882
1883 TRACE("(%p,%p,%p)\n", iface, lpTags, lppProbs);
1884
1885 if (!iface || !lpTags)
1886 return MAPI_E_INVALID_PARAMETER;
1887
1888 if (lppProbs)
1889 *lppProbs = NULL;
1890
1891 for (i = 0; i < lpTags->cValues; i++)
1892 {
1893 if (FBadPropTag(lpTags->aulPropTag[i]) ||
1894 PROP_TYPE(lpTags->aulPropTag[i]) == PT_OBJECT ||
1895 PROP_TYPE(lpTags->aulPropTag[i]) == PT_NULL)
1896 return MAPI_E_INVALID_PARAMETER;
1897 }
1898
1899 IMAPIPROP_Lock(This);
1900
1901 if (This->ulObjAccess != IPROP_READWRITE)
1902 {
1903 IMAPIPROP_Unlock(This);
1904 return E_ACCESSDENIED;
1905 }
1906
1907 for (i = 0; i < lpTags->cValues; i++)
1908 {
1909 LPIPropDataItem item = IMAPIPROP_GetValue(This, lpTags->aulPropTag[i]);
1910
1911 if (item)
1912 {
1913 if (item->ulAccess & IPROP_READWRITE)
1914 {
1915 /* Everything hunky-dory, remove the item */
1916 list_remove(&item->entry);
1917 This->lpFree(item->value); /* Also frees value pointers */
1918 This->lpFree(item);
1919 This->ulNumValues--;
1920 }
1921 else if (lppProbs)
1922 {
1923 /* Can't write the value. Create/populate problems array */
1924 if (!*lppProbs)
1925 {
1926 /* Create problems array */
1927 ULONG ulSize = CbNewSPropProblemArray(lpTags->cValues - i);
1928 HRESULT hRetTmp = MAPIAllocateBuffer(ulSize, (LPVOID*)lppProbs);
1929 if (FAILED(hRetTmp))
1930 hRet = hRetTmp;
1931 }
1932 if (*lppProbs)
1933 {
1934 LPSPropProblem lpProb = &(*lppProbs)->aProblem[numProbs];
1935 lpProb->ulIndex = i;
1936 lpProb->ulPropTag = lpTags->aulPropTag[i];
1937 lpProb->scode = E_ACCESSDENIED;
1938 numProbs++;
1939 }
1940 }
1941 }
1942 }
1943 if (lppProbs && *lppProbs)
1944 (*lppProbs)->cProblem = numProbs;
1945
1946 IMAPIPROP_Unlock(This);
1947 return hRet;
1948 }
1949
1950
1951 /**************************************************************************
1952 * IMAPIProp_CopyTo {MAPI32}
1953 *
1954 * Not documented at this time.
1955 *
1956 * RETURNS
1957 * An HRESULT success/failure code.
1958 */
1959 static inline HRESULT
1960 IMAPIProp_fnCopyTo(LPMAPIPROP iface, ULONG niids, LPCIID lpiidExcl,
1961 LPSPropTagArray lpPropsExcl, ULONG ulParam,
1962 LPMAPIPROGRESS lpIProgress, LPCIID lpIfaceIid, LPVOID lpDstObj,
1963 ULONG ulFlags, LPSPropProblemArray *lppProbs)
1964 {
1965 FIXME("(%p,%u,%p,%p,%x,%p,%s,%p,0x%08X,%p) stub\n", iface, niids,
1966 lpiidExcl, lpPropsExcl, ulParam, lpIProgress,
1967 debugstr_guid(lpIfaceIid), lpDstObj, ulFlags, lppProbs);
1968 return MAPI_E_NO_SUPPORT;
1969 }
1970
1971 /**************************************************************************
1972 * IMAPIProp_CopyProps {MAPI32}
1973 *
1974 * Not documented at this time.
1975 *
1976 * RETURNS
1977 * An HRESULT success/failure code.
1978 */
1979 static inline HRESULT
1980 IMAPIProp_fnCopyProps(LPMAPIPROP iface, LPSPropTagArray lpInclProps,
1981 ULONG ulParam, LPMAPIPROGRESS lpIProgress, LPCIID lpIface,
1982 LPVOID lpDstObj, ULONG ulFlags,
1983 LPSPropProblemArray *lppProbs)
1984 {
1985 FIXME("(%p,%p,%x,%p,%s,%p,0x%08X,%p) stub\n", iface, lpInclProps,
1986 ulParam, lpIProgress, debugstr_guid(lpIface), lpDstObj, ulFlags,
1987 lppProbs);
1988 return MAPI_E_NO_SUPPORT;
1989 }
1990
1991 /**************************************************************************
1992 * IMAPIProp_GetNamesFromIDs {MAPI32}
1993 *
1994 * Get the names of properties from their identifiers.
1995 *
1996 * PARAMS
1997 * iface [I] IMAPIProp object to operate on
1998 * lppPropTags [I/O] Property identifiers to get the names for, or NULL to
1999 * get all names
2000 * iid [I] Property set identifier, or NULL
2001 * ulFlags [I] MAPI_NO_IDS=Don't return numeric named properties,
2002 * or MAPI_NO_STRINGS=Don't return strings
2003 * lpCount [O] Destination for number of properties returned
2004 * lpppNames [O] Destination for returned names
2005 *
2006 * RETURNS
2007 * Success: S_OK. *lppPropTags and lpppNames contain the returned
2008 * name/identifiers.
2009 * Failure: MAPI_E_NO_SUPPORT, if the object does not support named properties,
2010 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
2011 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
2012 * successfully.
2013 */
2014 static inline HRESULT
2015 IMAPIProp_fnGetNamesFromIDs(LPMAPIPROP iface, LPSPropTagArray *lppPropTags,
2016 LPGUID iid, ULONG ulFlags, ULONG *lpCount,
2017 LPMAPINAMEID **lpppNames)
2018 {
2019 FIXME("(%p,%p,%s,0x%08X,%p,%p) stub\n", iface, lppPropTags,
2020 debugstr_guid(iid), ulFlags, lpCount, lpppNames);
2021 return MAPI_E_NO_SUPPORT;
2022 }
2023
2024 /**************************************************************************
2025 * IMAPIProp_GetIDsFromNames {MAPI32}
2026 *
2027 * Get property identifiers associated with one or more named properties.
2028 *
2029 * PARAMS
2030 * iface [I] IMAPIProp object to operate on
2031 * ulNames [I] Number of names in lppNames
2032 * lppNames [I] Names to query or create, or NULL to query all names
2033 * ulFlags [I] Pass MAPI_CREATE to create new named properties
2034 * lppPropTags [O] Destination for queried or created property identifiers
2035 *
2036 * RETURNS
2037 * Success: S_OK. *lppPropTags contains the property tags created or requested.
2038 * Failure: MAPI_E_NO_SUPPORT, if the object does not support named properties,
2039 * MAPI_E_TOO_BIG, if the object cannot process the number of
2040 * properties involved.
2041 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
2042 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
2043 * successfully.
2044 */
2045 static inline HRESULT
2046 IMAPIProp_fnGetIDsFromNames(LPMAPIPROP iface, ULONG ulNames,
2047 LPMAPINAMEID *lppNames, ULONG ulFlags,
2048 LPSPropTagArray *lppPropTags)
2049 {
2050 FIXME("(%p,%d,%p,0x%08X,%p) stub\n",
2051 iface, ulNames, lppNames, ulFlags, lppPropTags);
2052 return MAPI_E_NO_SUPPORT;
2053 }
2054
2055 /**************************************************************************
2056 * IPropData {MAPI32}
2057 *
2058 * A default Mapi interface to provide manipulation of object properties.
2059 *
2060 * DESCRIPTION
2061 * This object provides a default interface suitable in some cases as an
2062 * implementation of the IMAPIProp interface (which has no default
2063 * implementation). In addition to the IMAPIProp() methods inherited, this
2064 * interface allows read/write control over access to the object and its
2065 * individual properties.
2066 *
2067 * To obtain the default implementation of this interface from Mapi, call
2068 * CreateIProp().
2069 *
2070 * METHODS
2071 */
2072
2073 /**************************************************************************
2074 * IPropData_QueryInterface {MAPI32}
2075 *
2076 * Inherited method from the IMAPIProp Interface.
2077 * See IMAPIProp_QueryInterface.
2078 */
2079 static HRESULT WINAPI
2080 IPropData_fnQueryInterface(LPPROPDATA iface, REFIID riid, LPVOID *ppvObj)
2081 {
2082 return IMAPIProp_fnQueryInterface((LPMAPIPROP)iface, riid, ppvObj);
2083 }
2084
2085 /**************************************************************************
2086 * IPropData_AddRef {MAPI32}
2087 *
2088 * Inherited method from the IMAPIProp Interface.
2089 * See IMAPIProp_AddRef.
2090 */
2091 static ULONG WINAPI
2092 IPropData_fnAddRef(LPPROPDATA iface)
2093 {
2094 return IMAPIProp_fnAddRef((LPMAPIPROP)iface);
2095 }
2096
2097 /**************************************************************************
2098 * IPropData_Release {MAPI32}
2099 *
2100 * Inherited method from the IMAPIProp Interface.
2101 * See IMAPIProp_Release.
2102 */
2103 static ULONG WINAPI
2104 IPropData_fnRelease(LPPROPDATA iface)
2105 {
2106 return IMAPIProp_fnRelease((LPMAPIPROP)iface);
2107 }
2108
2109 /**************************************************************************
2110 * IPropData_GetLastError {MAPI32}
2111 *
2112 * Inherited method from the IMAPIProp Interface.
2113 * See IMAPIProp_GetLastError.
2114 */
2115 static HRESULT WINAPI
2116 IPropData_fnGetLastError(LPPROPDATA iface, HRESULT hRes, ULONG ulFlags,
2117 LPMAPIERROR *lppError)
2118 {
2119 return IMAPIProp_fnGetLastError((LPMAPIPROP)iface, hRes, ulFlags, lppError);
2120 }
2121
2122 /**************************************************************************
2123 * IPropData_SaveChanges {MAPI32}
2124 *
2125 * Inherited method from the IMAPIProp Interface.
2126 * See IMAPIProp_SaveChanges.
2127 */
2128 static HRESULT WINAPI
2129 IPropData_fnSaveChanges(LPPROPDATA iface, ULONG ulFlags)
2130 {
2131 return IMAPIProp_fnSaveChanges((LPMAPIPROP)iface, ulFlags);
2132 }
2133
2134 /**************************************************************************
2135 * IPropData_GetProps {MAPI32}
2136 *
2137 * Inherited method from the IMAPIProp Interface.
2138 * See IMAPIProp_GetProps.
2139 */
2140 static HRESULT WINAPI
2141 IPropData_fnGetProps(LPPROPDATA iface, LPSPropTagArray lpPropTags,
2142 ULONG ulFlags, ULONG *lpCount, LPSPropValue *lppProps)
2143 {
2144 return IMAPIProp_fnGetProps((LPMAPIPROP)iface, lpPropTags, ulFlags,
2145 lpCount, lppProps);
2146 }
2147
2148 /**************************************************************************
2149 * IPropData_GetPropList {MAPI32}
2150 *
2151 * Inherited method from the IMAPIProp Interface.
2152 * See IMAPIProp_GetPropList.
2153 */
2154 static HRESULT WINAPI
2155 IPropData_fnGetPropList(LPPROPDATA iface, ULONG ulFlags,
2156 LPSPropTagArray *lppPropTags)
2157 {
2158 return IMAPIProp_fnGetPropList((LPMAPIPROP)iface, ulFlags, lppPropTags);
2159 }
2160
2161 /**************************************************************************
2162 * IPropData_OpenProperty {MAPI32}
2163 *
2164 * Inherited method from the IMAPIProp Interface.
2165 * See IMAPIProp_OpenProperty.
2166 */
2167 static HRESULT WINAPI
2168 IPropData_fnOpenProperty(LPPROPDATA iface, ULONG ulPropTag, LPCIID iid,
2169 ULONG ulOpts, ULONG ulFlags, LPUNKNOWN *lpUnk)
2170 {
2171 return IMAPIProp_fnOpenProperty((LPMAPIPROP)iface, ulPropTag, iid,
2172 ulOpts, ulFlags, lpUnk);
2173 }
2174
2175 /**************************************************************************
2176 * IPropData_SetProps {MAPI32}
2177 *
2178 * Inherited method from the IMAPIProp Interface.
2179 * See IMAPIProp_SetProps.
2180 */
2181 static HRESULT WINAPI
2182 IPropData_fnSetProps(LPPROPDATA iface, ULONG cValues, LPSPropValue lpProps,
2183 LPSPropProblemArray *lppProbs)
2184 {
2185 return IMAPIProp_fnSetProps((LPMAPIPROP)iface, cValues, lpProps, lppProbs);
2186 }
2187
2188 /**************************************************************************
2189 * IPropData_DeleteProps {MAPI32}
2190 *
2191 * Inherited method from the IMAPIProp Interface.
2192 * See IMAPIProp_DeleteProps.
2193 */
2194 static HRESULT WINAPI
2195 IPropData_fnDeleteProps(LPPROPDATA iface, LPSPropTagArray lpPropTags,
2196 LPSPropProblemArray *lppProbs)
2197 {
2198 return IMAPIProp_fnDeleteProps((LPMAPIPROP)iface, lpPropTags, lppProbs);
2199 }
2200
2201 /**************************************************************************
2202 * IPropData_CopyTo {MAPI32}
2203 *
2204 * Inherited method from the IMAPIProp Interface.
2205 * See IMAPIProp_CopyTo.
2206 */
2207 static HRESULT WINAPI
2208 IPropData_fnCopyTo(LPPROPDATA iface, ULONG ciidExclude, LPCIID lpIid,
2209 LPSPropTagArray lpProps, ULONG ulParam,
2210 LPMAPIPROGRESS lpProgress, LPCIID lpIface, LPVOID lpDst,
2211 ULONG ulFlags, LPSPropProblemArray *lppProbs)
2212 {
2213 return IMAPIProp_fnCopyTo((LPMAPIPROP)iface, ciidExclude, lpIid, lpProps,
2214 ulParam, lpProgress, lpIface, lpDst,
2215 ulFlags, lppProbs);
2216 }
2217
2218 /**************************************************************************
2219 * IPropData_CopyProps {MAPI32}
2220 *
2221 * Inherited method from the IMAPIProp Interface.
2222 * See IMAPIProp_CopyProps.
2223 */
2224 static HRESULT WINAPI
2225 IPropData_fnCopyProps(LPPROPDATA iface, LPSPropTagArray lpProps,
2226 ULONG ulParam, LPMAPIPROGRESS lpProgress, LPCIID lpIface,
2227 LPVOID lpDst, ULONG ulFlags, LPSPropProblemArray *lppProbs)
2228 {
2229 return IMAPIProp_fnCopyProps((LPMAPIPROP)iface, lpProps, ulParam,
2230 lpProgress, lpIface, lpDst, ulFlags, lppProbs);
2231 }
2232
2233 /**************************************************************************
2234 * IPropData_GetNamesFromIDs {MAPI32}
2235 *
2236 * Inherited method from the IMAPIProp Interface.
2237 * See IMAPIProp_GetNamesFromIDs.
2238 */
2239 static HRESULT WINAPI
2240 IPropData_fnGetNamesFromIDs(LPPROPDATA iface, LPSPropTagArray *lppPropTags,
2241 LPGUID iid, ULONG ulFlags, ULONG *lpCount,
2242 LPMAPINAMEID **lpppNames)
2243 {
2244 return IMAPIProp_fnGetNamesFromIDs((LPMAPIPROP)iface, lppPropTags, iid,
2245 ulFlags, lpCount, lpppNames);
2246 }
2247
2248 /**************************************************************************
2249 * IPropData_GetIDsFromNames {MAPI32}
2250 *
2251 * Inherited method from the IMAPIProp Interface.
2252 * See IMAPIProp_GetIDsFromNames.
2253 */
2254 static HRESULT WINAPI
2255 IPropData_fnGetIDsFromNames(LPPROPDATA iface, ULONG ulNames,
2256 LPMAPINAMEID *lppNames, ULONG ulFlags,
2257 LPSPropTagArray *lppPropTags)
2258 {
2259 return IMAPIProp_fnGetIDsFromNames((LPMAPIPROP)iface, ulNames, lppNames,
2260 ulFlags, lppPropTags);
2261 }
2262
2263 /**************************************************************************
2264 * IPropData_HrSetObjAccess {MAPI32}
2265 *
2266 * Set the access level of an IPropData object.
2267 *
2268 * PARAMS
2269 * iface [I] IPropData object to set the access on
2270 * ulAccess [I] Either IPROP_READONLY or IPROP_READWRITE for read or
2271 * read/write access respectively.
2272 *
2273 * RETURNS
2274 * Success: S_OK. The objects access level is changed.
2275 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
2276 */
2277 static HRESULT WINAPI
2278 IPropData_fnHrSetObjAccess(LPPROPDATA iface, ULONG ulAccess)
2279 {
2280 IPropDataImpl *This = (IPropDataImpl*)iface;
2281
2282 TRACE("(%p,%x)\n", iface, ulAccess);
2283
2284 if (!iface || ulAccess < IPROP_READONLY || ulAccess > IPROP_READWRITE)
2285 return MAPI_E_INVALID_PARAMETER;
2286
2287 IMAPIPROP_Lock(This);
2288
2289 This->ulObjAccess = ulAccess;
2290
2291 IMAPIPROP_Unlock(This);
2292 return S_OK;
2293 }
2294
2295 /* Internal - determine if an access value is bad */
2296 static inline BOOL PROP_IsBadAccess(ULONG ulAccess)
2297 {
2298 switch (ulAccess)
2299 {
2300 case IPROP_READONLY|IPROP_CLEAN:
2301 case IPROP_READONLY|IPROP_DIRTY:
2302 case IPROP_READWRITE|IPROP_CLEAN:
2303 case IPROP_READWRITE|IPROP_DIRTY:
2304 return FALSE;
2305 }
2306 return TRUE;
2307 }
2308
2309 /**************************************************************************
2310 * IPropData_HrSetPropAccess {MAPI32}
2311 *
2312 * Set the access levels for a group of property values in an IPropData object.
2313 *
2314 * PARAMS
2315 * iface [I] IPropData object to set access levels in.
2316 * lpTags [I] List of property Id's to set access for.
2317 * lpAccess [O] Access level for each property in lpTags.
2318 *
2319 * RETURNS
2320 * Success: S_OK. The access level of each property value in lpTags that is
2321 * present in iface is changed.
2322 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
2323 *
2324 * NOTES
2325 * - Each access level in lpAccess must contain at least one of IPROP_READONLY
2326 * or IPROP_READWRITE, but not both, and also IPROP_CLEAN or IPROP_DIRTY,
2327 * but not both. No other bits should be set.
2328 * - If a property Id in lpTags is not present in iface, it is ignored.
2329 */
2330 static HRESULT WINAPI
2331 IPropData_fnHrSetPropAccess(LPPROPDATA iface, LPSPropTagArray lpTags,
2332 ULONG *lpAccess)
2333 {
2334 IPropDataImpl *This = (IPropDataImpl*)iface;
2335
2336 ULONG i;
2337
2338 TRACE("(%p,%p,%p)\n", iface, lpTags, lpAccess);
2339
2340 if (!iface || !lpTags || !lpAccess)
2341 return MAPI_E_INVALID_PARAMETER;
2342
2343 for (i = 0; i < lpTags->cValues; i++)
2344 {
2345 if (FBadPropTag(lpTags->aulPropTag[i]) || PROP_IsBadAccess(lpAccess[i]))
2346 return MAPI_E_INVALID_PARAMETER;
2347 }
2348
2349 IMAPIPROP_Lock(This);
2350
2351 for (i = 0; i < lpTags->cValues; i++)
2352 {
2353 LPIPropDataItem item = IMAPIPROP_GetValue(This, lpTags->aulPropTag[i]);
2354
2355 if (item)
2356 item->ulAccess = lpAccess[i];
2357 }
2358
2359 IMAPIPROP_Unlock(This);
2360 return S_OK;
2361 }
2362
2363 /**************************************************************************
2364 * IPropData_HrGetPropAccess {MAPI32}
2365 *
2366 * Get the access levels for a group of property values in an IPropData object.
2367 *
2368 * PARAMS
2369 * iface [I] IPropData object to get access levels from.
2370 * lppTags [O] Destination for the list of property Id's in iface.
2371 * lppAccess [O] Destination for access level for each property in lppTags.
2372 *
2373 * RETURNS
2374 * Success: S_OK. lppTags and lppAccess contain the property Id's and the
2375 * Access level of each property value in iface.
2376 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid, or
2377 * MAPI_E_NOT_ENOUGH_MEMORY if memory allocation fails.
2378 *
2379 * NOTES
2380 * - *lppTags and *lppAccess should be freed with MAPIFreeBuffer() by the caller.
2381 */
2382 static HRESULT WINAPI
2383 IPropData_fnHrGetPropAccess(LPPROPDATA iface, LPSPropTagArray *lppTags,
2384 ULONG **lppAccess)
2385 {
2386 IPropDataImpl *This = (IPropDataImpl*)iface;
2387 LPVOID lpMem;
2388 HRESULT hRet;
2389 ULONG i;
2390
2391 TRACE("(%p,%p,%p) stub\n", iface, lppTags, lppAccess);
2392
2393 if (!iface || !lppTags || !lppAccess)
2394 return MAPI_E_INVALID_PARAMETER;
2395
2396 *lppTags = NULL;
2397 *lppAccess = NULL;
2398
2399 IMAPIPROP_Lock(This);
2400
2401 hRet = This->lpAlloc(CbNewSPropTagArray(This->ulNumValues), &lpMem);
2402 if (SUCCEEDED(hRet))
2403 {
2404 *lppTags = lpMem;
2405
2406 hRet = This->lpAlloc(This->ulNumValues * sizeof(ULONG), &lpMem);
2407 if (SUCCEEDED(hRet))
2408 {
2409 struct list *cursor;
2410
2411 *lppAccess = lpMem;
2412 (*lppTags)->cValues = This->ulNumValues;
2413
2414 i = 0;
2415 LIST_FOR_EACH(cursor, &This->values)
2416 {
2417 LPIPropDataItem item = LIST_ENTRY(cursor, IPropDataItem, entry);
2418 (*lppTags)->aulPropTag[i] = item->value->ulPropTag;
2419 (*lppAccess)[i] = item->ulAccess;
2420 i++;
2421 }
2422 IMAPIPROP_Unlock(This);
2423 return S_OK;
2424 }
2425 This->lpFree(*lppTags);
2426 *lppTags = 0;
2427 }
2428 IMAPIPROP_Unlock(This);
2429 return MAPI_E_NOT_ENOUGH_MEMORY;
2430 }
2431
2432 /**************************************************************************
2433 * IPropData_HrAddObjProps {MAPI32}
2434 *
2435 * Not documented at this time.
2436 *
2437 * RETURNS
2438 * An HRESULT success/failure code.
2439 */
2440 static HRESULT WINAPI
2441 IPropData_fnHrAddObjProps(LPPROPDATA iface, LPSPropTagArray lpTags,
2442 LPSPropProblemArray *lppProbs)
2443 {
2444 #if 0
2445 ULONG i;
2446 HRESULT hRet;
2447 LPSPropValue lpValues;
2448 #endif
2449
2450 FIXME("(%p,%p,%p) stub\n", iface, lpTags, lppProbs);
2451
2452 if (!iface || !lpTags)
2453 return MAPI_E_INVALID_PARAMETER;
2454
2455 /* FIXME: Below is the obvious implementation, adding all the properties
2456 * in lpTags to the object. However, it doesn't appear that this
2457 * is what this function does.
2458 */
2459 return S_OK;
2460 #if 0
2461 if (!lpTags->cValues)
2462 return S_OK;
2463
2464 lpValues = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2465 lpTags->cValues * sizeof(SPropValue));
2466 if (!lpValues)
2467 return MAPI_E_NOT_ENOUGH_MEMORY;
2468
2469 for (i = 0; i < lpTags->cValues; i++)
2470 lpValues[i].ulPropTag = lpTags->aulPropTag[i];
2471
2472 hRet = IPropData_SetProps(iface, lpTags->cValues, lpValues, lppProbs);
2473 HeapFree(GetProcessHeap(), 0, lpValues);
2474 return hRet;
2475 #endif
2476 }
2477
2478 static const IPropDataVtbl IPropDataImpl_vtbl =
2479 {
2480 IPropData_fnQueryInterface,
2481 IPropData_fnAddRef,
2482 IPropData_fnRelease,
2483 IPropData_fnGetLastError,
2484 IPropData_fnSaveChanges,
2485 IPropData_fnGetProps,
2486 IPropData_fnGetPropList,
2487 IPropData_fnOpenProperty,
2488 IPropData_fnSetProps,
2489 IPropData_fnDeleteProps,
2490 IPropData_fnCopyTo,
2491 IPropData_fnCopyProps,
2492 IPropData_fnGetNamesFromIDs,
2493 IPropData_fnGetIDsFromNames,
2494 IPropData_fnHrSetObjAccess,
2495 IPropData_fnHrSetPropAccess,
2496 IPropData_fnHrGetPropAccess,
2497 IPropData_fnHrAddObjProps
2498 };
2499
2500 /*************************************************************************
2501 * CreateIProp@24 (MAPI32.60)
2502 *
2503 * Create an IPropData object.
2504 *
2505 * PARAMS
2506 * iid [I] GUID of the object to create. Use &IID_IMAPIPropData or NULL
2507 * lpAlloc [I] Memory allocation function. Use MAPIAllocateBuffer()
2508 * lpMore [I] Linked memory allocation function. Use MAPIAllocateMore()
2509 * lpFree [I] Memory free function. Use MAPIFreeBuffer()
2510 * lpReserved [I] Reserved, set to NULL
2511 * lppPropData [O] Destination for created IPropData object
2512 *
2513 * RETURNS
2514 * Success: S_OK. *lppPropData contains the newly created object.
2515 * Failure: MAPI_E_INTERFACE_NOT_SUPPORTED, if iid is non-NULL and not supported,
2516 * MAPI_E_INVALID_PARAMETER, if any parameter is invalid
2517 */
2518 SCODE WINAPI CreateIProp(LPCIID iid, ALLOCATEBUFFER *lpAlloc,
2519 ALLOCATEMORE *lpMore, FREEBUFFER *lpFree,
2520 LPVOID lpReserved, LPPROPDATA *lppPropData)
2521 {
2522 IPropDataImpl *lpPropData;
2523 SCODE scode;
2524
2525 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_guid(iid), lpAlloc, lpMore, lpFree,
2526 lpReserved, lppPropData);
2527
2528 if (lppPropData)
2529 *lppPropData = NULL;
2530
2531 if (iid && !IsEqualGUID(iid, &IID_IMAPIPropData))
2532 return MAPI_E_INTERFACE_NOT_SUPPORTED;
2533
2534 if (!lpAlloc || !lpMore || !lpFree || lpReserved || !lppPropData)
2535 return MAPI_E_INVALID_PARAMETER;
2536
2537 scode = lpAlloc(sizeof(IPropDataImpl), (LPVOID*)&lpPropData);
2538
2539 if (SUCCEEDED(scode))
2540 {
2541 lpPropData->lpVtbl = &IPropDataImpl_vtbl;
2542 lpPropData->lRef = 1;
2543 lpPropData->lpAlloc = lpAlloc;
2544 lpPropData->lpMore = lpMore;
2545 lpPropData->lpFree = lpFree;
2546 lpPropData->ulObjAccess = IPROP_READWRITE;
2547 lpPropData->ulNumValues = 0;
2548 list_init(&lpPropData->values);
2549 InitializeCriticalSection(&lpPropData->cs);
2550 lpPropData->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IPropDataImpl.cs");
2551 *lppPropData = (LPPROPDATA)lpPropData;
2552 }
2553 return scode;
2554 }