4 * Copyright 2004 Jon Griffiths
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.
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.
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
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
31 //#include "winerror.h"
32 //#include "winternl.h"
33 //#include "objbase.h"
35 #include <wine/list.h>
36 #include <wine/debug.h>
37 #include <wine/unicode.h>
40 WINE_DEFAULT_DEBUG_CHANNEL(mapi
);
42 BOOL WINAPI
FBadRglpszA(LPSTR
*,ULONG
);
44 /* Internal: Check if a property value array is invalid */
45 static inline ULONG
PROP_BadArray(LPSPropValue lpProp
, size_t elemSize
)
47 return IsBadReadPtr(lpProp
->Value
.MVi
.lpi
, lpProp
->Value
.MVi
.cValues
* elemSize
);
50 /*************************************************************************
51 * PropCopyMore@16 (MAPI32.76)
53 * Copy a property value.
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
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.
67 * Any elements within the property returned should not be individually
68 * freed, as they will be freed when lpOrig is.
70 SCODE WINAPI
PropCopyMore(LPSPropValue lpDest
, LPSPropValue lpSrc
,
71 ALLOCATEMORE
*lpMore
, LPVOID lpOrig
)
76 TRACE("(%p,%p,%p,%p)\n", lpDest
, lpSrc
, lpMore
, lpOrig
);
78 if (!lpDest
|| IsBadWritePtr(lpDest
, sizeof(SPropValue
)) ||
79 FBadProp(lpSrc
) || !lpMore
)
80 return MAPI_E_INVALID_PARAMETER
;
82 /* Shallow copy first, this is sufficient for properties without pointers */
85 switch (PROP_TYPE(lpSrc
->ulPropTag
))
88 scode
= lpMore(sizeof(GUID
), lpOrig
, (LPVOID
*)&lpDest
->Value
.lpguid
);
90 *lpDest
->Value
.lpguid
= *lpSrc
->Value
.lpguid
;
93 ulLen
= lstrlenA(lpSrc
->Value
.lpszA
) + 1u;
94 scode
= lpMore(ulLen
, lpOrig
, (LPVOID
*)&lpDest
->Value
.lpszA
);
96 memcpy(lpDest
->Value
.lpszA
, lpSrc
->Value
.lpszA
, ulLen
);
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
);
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
);
110 if (lpSrc
->ulPropTag
& MV_FLAG
)
112 ulLen
= UlPropSize(lpSrc
);
114 if (PROP_TYPE(lpSrc
->ulPropTag
) == PT_MV_STRING8
||
115 PROP_TYPE(lpSrc
->ulPropTag
) == PT_MV_UNICODE
)
117 /* UlPropSize doesn't account for the string pointers */
118 ulLen
+= lpSrc
->Value
.MVszA
.cValues
* sizeof(char*);
120 else if (PROP_TYPE(lpSrc
->ulPropTag
) == PT_MV_BINARY
)
122 /* UlPropSize doesn't account for the SBinary structs */
123 ulLen
+= lpSrc
->Value
.MVbin
.cValues
* sizeof(SBinary
);
126 lpDest
->Value
.MVi
.cValues
= lpSrc
->Value
.MVi
.cValues
;
127 scode
= lpMore(ulLen
, lpOrig
, (LPVOID
*)&lpDest
->Value
.MVi
.lpi
);
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
140 switch (PROP_TYPE(lpSrc
->ulPropTag
))
144 char *lpNextStr
= (char*)(lpDest
->Value
.MVszA
.lppszA
+
145 lpDest
->Value
.MVszA
.cValues
);
147 for (i
= 0; i
< lpSrc
->Value
.MVszA
.cValues
; i
++)
149 ULONG ulStrLen
= lstrlenA(lpSrc
->Value
.MVszA
.lppszA
[i
]) + 1u;
151 lpDest
->Value
.MVszA
.lppszA
[i
] = lpNextStr
;
152 memcpy(lpNextStr
, lpSrc
->Value
.MVszA
.lppszA
[i
], ulStrLen
);
153 lpNextStr
+= ulStrLen
;
159 WCHAR
*lpNextStr
= (WCHAR
*)(lpDest
->Value
.MVszW
.lppszW
+
160 lpDest
->Value
.MVszW
.cValues
);
162 for (i
= 0; i
< lpSrc
->Value
.MVszW
.cValues
; i
++)
164 ULONG ulStrLen
= strlenW(lpSrc
->Value
.MVszW
.lppszW
[i
]) + 1u;
166 lpDest
->Value
.MVszW
.lppszW
[i
] = lpNextStr
;
167 memcpy(lpNextStr
, lpSrc
->Value
.MVszW
.lppszW
[i
], ulStrLen
* sizeof(WCHAR
));
168 lpNextStr
+= ulStrLen
;
174 LPBYTE lpNext
= (LPBYTE
)(lpDest
->Value
.MVbin
.lpbin
+
175 lpDest
->Value
.MVbin
.cValues
);
177 for (i
= 0; i
< lpSrc
->Value
.MVszW
.cValues
; i
++)
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
;
187 /* No embedded pointers, just copy the data over */
188 memcpy(lpDest
->Value
.MVi
.lpi
, lpSrc
->Value
.MVi
.lpi
, ulLen
);
197 /*************************************************************************
198 * UlPropSize@4 (MAPI32.77)
200 * Determine the size of a property in bytes.
203 * lpProp [I] Property to determine the size of
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
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.
219 ULONG WINAPI
UlPropSize(LPSPropValue lpProp
)
223 TRACE("(%p)\n", lpProp
);
225 switch (PROP_TYPE(lpProp
->ulPropTag
))
227 case PT_MV_I2
: ulRet
= lpProp
->Value
.MVi
.cValues
;
230 case PT_I2
: ulRet
*= sizeof(USHORT
);
232 case PT_MV_I4
: ulRet
= lpProp
->Value
.MVl
.cValues
;
235 case PT_I4
: ulRet
*= sizeof(LONG
);
237 case PT_MV_I8
: ulRet
= lpProp
->Value
.MVli
.cValues
;
239 case PT_I8
: ulRet
*= sizeof(LONG64
);
241 case PT_MV_R4
: ulRet
= lpProp
->Value
.MVflt
.cValues
;
243 case PT_R4
: ulRet
*= sizeof(float);
246 case PT_MV_R8
: ulRet
= lpProp
->Value
.MVdbl
.cValues
;
249 case PT_R8
: ulRet
*= sizeof(double);
251 case PT_MV_CURRENCY
: ulRet
= lpProp
->Value
.MVcur
.cValues
;
253 case PT_CURRENCY
: ulRet
*= sizeof(CY
);
255 case PT_MV_SYSTIME
: ulRet
= lpProp
->Value
.MVft
.cValues
;
257 case PT_SYSTIME
: ulRet
*= sizeof(FILETIME
);
259 case PT_MV_CLSID
: ulRet
= lpProp
->Value
.MVguid
.cValues
;
261 case PT_CLSID
: ulRet
*= sizeof(GUID
);
263 case PT_MV_STRING8
: ulRet
= 0u;
264 for (i
= 0; i
< lpProp
->Value
.MVszA
.cValues
; i
++)
265 ulRet
+= (lstrlenA(lpProp
->Value
.MVszA
.lppszA
[i
]) + 1u);
267 case PT_STRING8
: ulRet
= lstrlenA(lpProp
->Value
.lpszA
) + 1u;
269 case PT_MV_UNICODE
: ulRet
= 0u;
270 for (i
= 0; i
< lpProp
->Value
.MVszW
.cValues
; i
++)
271 ulRet
+= (strlenW(lpProp
->Value
.MVszW
.lppszW
[i
]) + 1u);
272 ulRet
*= sizeof(WCHAR
);
274 case PT_UNICODE
: ulRet
= (lstrlenW(lpProp
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
276 case PT_MV_BINARY
: ulRet
= 0u;
277 for (i
= 0; i
< lpProp
->Value
.MVbin
.cValues
; i
++)
278 ulRet
+= lpProp
->Value
.MVbin
.lpbin
[i
].cb
;
280 case PT_BINARY
: ulRet
= lpProp
->Value
.bin
.cb
;
290 /*************************************************************************
291 * FPropContainsProp@12 (MAPI32.78)
293 * Find a property with a given property tag in a property array.
296 * lpHaystack [I] Property to match to
297 * lpNeedle [I] Property to find in lpHaystack
298 * ulFuzzy [I] Flags controlling match type and strictness (FL_* flags from "mapidefs.h")
301 * TRUE, if lpNeedle matches lpHaystack according to the criteria of ulFuzzy.
304 * Only property types of PT_STRING8 and PT_BINARY are handled by this function.
306 BOOL WINAPI
FPropContainsProp(LPSPropValue lpHaystack
, LPSPropValue lpNeedle
, ULONG ulFuzzy
)
308 TRACE("(%p,%p,0x%08x)\n", lpHaystack
, lpNeedle
, ulFuzzy
);
310 if (FBadProp(lpHaystack
) || FBadProp(lpNeedle
) ||
311 PROP_TYPE(lpHaystack
->ulPropTag
) != PROP_TYPE(lpNeedle
->ulPropTag
))
314 /* FIXME: Do later versions support Unicode as well? */
316 if (PROP_TYPE(lpHaystack
->ulPropTag
) == PT_STRING8
)
318 DWORD dwFlags
= 0, dwNeedleLen
, dwHaystackLen
;
320 if (ulFuzzy
& FL_IGNORECASE
)
321 dwFlags
|= NORM_IGNORECASE
;
322 if (ulFuzzy
& FL_IGNORENONSPACE
)
323 dwFlags
|= NORM_IGNORENONSPACE
;
324 if (ulFuzzy
& FL_LOOSE
)
325 dwFlags
|= (NORM_IGNORECASE
|NORM_IGNORENONSPACE
|NORM_IGNORESYMBOLS
);
327 dwNeedleLen
= lstrlenA(lpNeedle
->Value
.lpszA
);
328 dwHaystackLen
= lstrlenA(lpHaystack
->Value
.lpszA
);
330 if ((ulFuzzy
& (FL_SUBSTRING
|FL_PREFIX
)) == FL_PREFIX
)
332 if (dwNeedleLen
<= dwHaystackLen
&&
333 CompareStringA(LOCALE_USER_DEFAULT
, dwFlags
,
334 lpHaystack
->Value
.lpszA
, dwNeedleLen
,
335 lpNeedle
->Value
.lpszA
, dwNeedleLen
) == CSTR_EQUAL
)
336 return TRUE
; /* needle is a prefix of haystack */
338 else if ((ulFuzzy
& (FL_SUBSTRING
|FL_PREFIX
)) == FL_SUBSTRING
)
340 LPSTR (WINAPI
*pStrChrFn
)(LPCSTR
,WORD
) = StrChrA
;
341 LPSTR lpStr
= lpHaystack
->Value
.lpszA
;
343 if (dwFlags
& NORM_IGNORECASE
)
344 pStrChrFn
= StrChrIA
;
346 while ((lpStr
= pStrChrFn(lpStr
, *lpNeedle
->Value
.lpszA
)) != NULL
)
348 dwHaystackLen
-= (lpStr
- lpHaystack
->Value
.lpszA
);
349 if (dwNeedleLen
<= dwHaystackLen
&&
350 CompareStringA(LOCALE_USER_DEFAULT
, dwFlags
,
352 lpNeedle
->Value
.lpszA
, dwNeedleLen
) == CSTR_EQUAL
)
353 return TRUE
; /* needle is a substring of haystack */
357 else if (CompareStringA(LOCALE_USER_DEFAULT
, dwFlags
,
358 lpHaystack
->Value
.lpszA
, dwHaystackLen
,
359 lpNeedle
->Value
.lpszA
, dwNeedleLen
) == CSTR_EQUAL
)
360 return TRUE
; /* full string match */
362 else if (PROP_TYPE(lpHaystack
->ulPropTag
) == PT_BINARY
)
364 if ((ulFuzzy
& (FL_SUBSTRING
|FL_PREFIX
)) == FL_PREFIX
)
366 if (lpNeedle
->Value
.bin
.cb
<= lpHaystack
->Value
.bin
.cb
&&
367 !memcmp(lpNeedle
->Value
.bin
.lpb
, lpHaystack
->Value
.bin
.lpb
,
368 lpNeedle
->Value
.bin
.cb
))
369 return TRUE
; /* needle is a prefix of haystack */
371 else if ((ulFuzzy
& (FL_SUBSTRING
|FL_PREFIX
)) == FL_SUBSTRING
)
373 ULONG ulLen
= lpHaystack
->Value
.bin
.cb
;
374 LPBYTE lpb
= lpHaystack
->Value
.bin
.lpb
;
376 while ((lpb
= memchr(lpb
, *lpNeedle
->Value
.bin
.lpb
, ulLen
)) != NULL
)
378 ulLen
= lpHaystack
->Value
.bin
.cb
- (lpb
- lpHaystack
->Value
.bin
.lpb
);
379 if (lpNeedle
->Value
.bin
.cb
<= ulLen
&&
380 !memcmp(lpNeedle
->Value
.bin
.lpb
, lpb
, lpNeedle
->Value
.bin
.cb
))
381 return TRUE
; /* needle is a substring of haystack */
385 else if (!LPropCompareProp(lpHaystack
, lpNeedle
))
386 return TRUE
; /* needle is an exact match with haystack */
392 /*************************************************************************
393 * FPropCompareProp@12 (MAPI32.79)
395 * Compare two properties.
398 * lpPropLeft [I] Left hand property to compare to lpPropRight
399 * ulOp [I] Comparison operator (RELOP_* enum from "mapidefs.h")
400 * lpPropRight [I] Right hand property to compare to lpPropLeft
403 * TRUE, if the comparison is true, FALSE otherwise.
405 BOOL WINAPI
FPropCompareProp(LPSPropValue lpPropLeft
, ULONG ulOp
, LPSPropValue lpPropRight
)
409 TRACE("(%p,%d,%p)\n", lpPropLeft
, ulOp
, lpPropRight
);
411 if (ulOp
> RELOP_RE
|| FBadProp(lpPropLeft
) || FBadProp(lpPropRight
))
414 if (ulOp
== RELOP_RE
)
416 FIXME("Comparison operator RELOP_RE not yet implemented!\n");
420 iCmp
= LPropCompareProp(lpPropLeft
, lpPropRight
);
424 case RELOP_LT
: return iCmp
< 0;
425 case RELOP_LE
: return iCmp
<= 0;
426 case RELOP_GT
: return iCmp
> 0;
427 case RELOP_GE
: return iCmp
>= 0;
428 case RELOP_EQ
: return iCmp
== 0;
429 case RELOP_NE
: return iCmp
!= 0;
434 /*************************************************************************
435 * LPropCompareProp@8 (MAPI32.80)
437 * Compare two properties.
440 * lpPropLeft [I] Left hand property to compare to lpPropRight
441 * lpPropRight [I] Right hand property to compare to lpPropLeft
444 * An integer less than, equal to or greater than 0, indicating that
445 * lpszStr is less than, the same, or greater than lpszComp.
447 LONG WINAPI
LPropCompareProp(LPSPropValue lpPropLeft
, LPSPropValue lpPropRight
)
451 TRACE("(%p->0x%08x,%p->0x%08x)\n", lpPropLeft
, lpPropLeft
->ulPropTag
,
452 lpPropRight
, lpPropRight
->ulPropTag
);
454 /* If the properties are not the same, sort by property type */
455 if (PROP_TYPE(lpPropLeft
->ulPropTag
) != PROP_TYPE(lpPropRight
->ulPropTag
))
456 return (LONG
)PROP_TYPE(lpPropLeft
->ulPropTag
) - (LONG
)PROP_TYPE(lpPropRight
->ulPropTag
);
458 switch (PROP_TYPE(lpPropLeft
->ulPropTag
))
462 return 0; /* NULLs are equal */
464 return lpPropLeft
->Value
.i
- lpPropRight
->Value
.i
;
466 return lpPropLeft
->Value
.l
- lpPropRight
->Value
.l
;
468 if (lpPropLeft
->Value
.li
.QuadPart
> lpPropRight
->Value
.li
.QuadPart
)
470 if (lpPropLeft
->Value
.li
.QuadPart
== lpPropRight
->Value
.li
.QuadPart
)
474 if (lpPropLeft
->Value
.flt
> lpPropRight
->Value
.flt
)
476 if (lpPropLeft
->Value
.flt
== lpPropRight
->Value
.flt
)
481 if (lpPropLeft
->Value
.dbl
> lpPropRight
->Value
.dbl
)
483 if (lpPropLeft
->Value
.dbl
== lpPropRight
->Value
.dbl
)
487 if (lpPropLeft
->Value
.cur
.int64
> lpPropRight
->Value
.cur
.int64
)
489 if (lpPropLeft
->Value
.cur
.int64
== lpPropRight
->Value
.cur
.int64
)
493 return CompareFileTime(&lpPropLeft
->Value
.ft
, &lpPropRight
->Value
.ft
);
495 return (lpPropLeft
->Value
.b
? 1 : 0) - (lpPropRight
->Value
.b
? 1 : 0);
497 if (lpPropLeft
->Value
.bin
.cb
== lpPropRight
->Value
.bin
.cb
)
498 iRet
= memcmp(lpPropLeft
->Value
.bin
.lpb
, lpPropRight
->Value
.bin
.lpb
,
499 lpPropLeft
->Value
.bin
.cb
);
502 iRet
= memcmp(lpPropLeft
->Value
.bin
.lpb
, lpPropRight
->Value
.bin
.lpb
,
503 min(lpPropLeft
->Value
.bin
.cb
, lpPropRight
->Value
.bin
.cb
));
506 iRet
= lpPropLeft
->Value
.bin
.cb
- lpPropRight
->Value
.bin
.cb
;
510 return lstrcmpA(lpPropLeft
->Value
.lpszA
, lpPropRight
->Value
.lpszA
);
512 return strcmpW(lpPropLeft
->Value
.lpszW
, lpPropRight
->Value
.lpszW
);
514 if (lpPropLeft
->Value
.err
> lpPropRight
->Value
.err
)
516 if (lpPropLeft
->Value
.err
== lpPropRight
->Value
.err
)
520 return memcmp(lpPropLeft
->Value
.lpguid
, lpPropRight
->Value
.lpguid
,
523 FIXME("Unhandled property type %d\n", PROP_TYPE(lpPropLeft
->ulPropTag
));
527 /*************************************************************************
528 * HrGetOneProp@8 (MAPI32.135)
530 * Get a property value from an IMAPIProp object.
533 * lpIProp [I] IMAPIProp object to get the property value in
534 * ulPropTag [I] Property tag of the property to get
535 * lppProp [O] Destination for the returned property
538 * Success: S_OK. *lppProp contains the property value requested.
539 * Failure: MAPI_E_NOT_FOUND, if no property value has the tag given by ulPropTag.
541 HRESULT WINAPI
HrGetOneProp(LPMAPIPROP lpIProp
, ULONG ulPropTag
, LPSPropValue
*lppProp
)
547 TRACE("(%p,%d,%p)\n", lpIProp
, ulPropTag
, lppProp
);
550 pta
.aulPropTag
[0] = ulPropTag
;
551 hRet
= IMAPIProp_GetProps(lpIProp
, &pta
, 0u, &ulCount
, lppProp
);
552 if (hRet
== MAPI_W_ERRORS_RETURNED
)
554 MAPIFreeBuffer(*lppProp
);
556 hRet
= MAPI_E_NOT_FOUND
;
561 /*************************************************************************
562 * HrSetOneProp@8 (MAPI32.136)
564 * Set a property value in an IMAPIProp object.
567 * lpIProp [I] IMAPIProp object to set the property value in
568 * lpProp [I] Property value to set
571 * Success: S_OK. The value in lpProp is set in lpIProp.
572 * Failure: An error result from IMAPIProp_SetProps().
574 HRESULT WINAPI
HrSetOneProp(LPMAPIPROP lpIProp
, LPSPropValue lpProp
)
576 TRACE("(%p,%p)\n", lpIProp
, lpProp
);
578 return IMAPIProp_SetProps(lpIProp
, 1u, lpProp
, NULL
);
581 /*************************************************************************
582 * FPropExists@8 (MAPI32.137)
584 * Find a property with a given property tag in an IMAPIProp object.
587 * lpIProp [I] IMAPIProp object to find the property tag in
588 * ulPropTag [I] Property tag to find
591 * TRUE, if ulPropTag matches a property held in lpIProp,
595 * if ulPropTag has a property type of PT_UNSPECIFIED, then only the property
596 * Ids need to match for a successful match to occur.
598 BOOL WINAPI
FPropExists(LPMAPIPROP lpIProp
, ULONG ulPropTag
)
602 TRACE("(%p,%d)\n", lpIProp
, ulPropTag
);
606 LPSPropTagArray lpTags
;
609 if (FAILED(IMAPIProp_GetPropList(lpIProp
, 0u, &lpTags
)))
612 for (i
= 0; i
< lpTags
->cValues
; i
++)
614 if (!FBadPropTag(lpTags
->aulPropTag
[i
]) &&
615 (lpTags
->aulPropTag
[i
] == ulPropTag
||
616 (PROP_TYPE(ulPropTag
) == PT_UNSPECIFIED
&&
617 PROP_ID(lpTags
->aulPropTag
[i
]) == lpTags
->aulPropTag
[i
])))
623 MAPIFreeBuffer(lpTags
);
628 /*************************************************************************
629 * PpropFindProp@12 (MAPI32.138)
631 * Find a property with a given property tag in a property array.
634 * lpProps [I] Property array to search
635 * cValues [I] Number of properties in lpProps
636 * ulPropTag [I] Property tag to find
639 * A pointer to the matching property, or NULL if none was found.
642 * if ulPropTag has a property type of PT_UNSPECIFIED, then only the property
643 * Ids need to match for a successful match to occur.
645 LPSPropValue WINAPI
PpropFindProp(LPSPropValue lpProps
, ULONG cValues
, ULONG ulPropTag
)
647 TRACE("(%p,%d,%d)\n", lpProps
, cValues
, ulPropTag
);
649 if (lpProps
&& cValues
)
652 for (i
= 0; i
< cValues
; i
++)
654 if (!FBadPropTag(lpProps
[i
].ulPropTag
) &&
655 (lpProps
[i
].ulPropTag
== ulPropTag
||
656 (PROP_TYPE(ulPropTag
) == PT_UNSPECIFIED
&&
657 PROP_ID(lpProps
[i
].ulPropTag
) == PROP_ID(ulPropTag
))))
664 /*************************************************************************
665 * FreePadrlist@4 (MAPI32.139)
667 * Free the memory used by an address book list.
670 * lpAddrs [I] Address book list to free
675 VOID WINAPI
FreePadrlist(LPADRLIST lpAddrs
)
677 TRACE("(%p)\n", lpAddrs
);
679 /* Structures are binary compatible; use the same implementation */
680 FreeProws((LPSRowSet
)lpAddrs
);
683 /*************************************************************************
684 * FreeProws@4 (MAPI32.140)
686 * Free the memory used by a row set.
689 * lpRowSet [I] Row set to free
694 VOID WINAPI
FreeProws(LPSRowSet lpRowSet
)
696 TRACE("(%p)\n", lpRowSet
);
702 for (i
= 0; i
< lpRowSet
->cRows
; i
++)
703 MAPIFreeBuffer(lpRowSet
->aRow
[i
].lpProps
);
705 MAPIFreeBuffer(lpRowSet
);
709 /*************************************************************************
710 * ScCountProps@12 (MAPI32.170)
712 * Validate and determine the length of an array of properties.
715 * iCount [I] Length of the lpProps array
716 * lpProps [I] Array of properties to validate/size
717 * pcBytes [O] If non-NULL, destination for the size of the property array
720 * Success: S_OK. If pcBytes is non-NULL, it contains the size of the
722 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid or validation
723 * of the property array fails.
725 SCODE WINAPI
ScCountProps(INT iCount
, LPSPropValue lpProps
, ULONG
*pcBytes
)
727 ULONG i
, ulCount
= iCount
, ulBytes
= 0;
729 TRACE("(%d,%p,%p)\n", iCount
, lpProps
, pcBytes
);
731 if (iCount
<= 0 || !lpProps
||
732 IsBadReadPtr(lpProps
, iCount
* sizeof(SPropValue
)))
733 return MAPI_E_INVALID_PARAMETER
;
735 for (i
= 0; i
< ulCount
; i
++)
737 ULONG ulPropSize
= 0;
739 if (FBadProp(&lpProps
[i
]) || lpProps
[i
].ulPropTag
== PROP_ID_NULL
||
740 lpProps
[i
].ulPropTag
== PROP_ID_INVALID
)
741 return MAPI_E_INVALID_PARAMETER
;
743 if (PROP_TYPE(lpProps
[i
].ulPropTag
) != PT_OBJECT
)
745 ulPropSize
= UlPropSize(&lpProps
[i
]);
747 return MAPI_E_INVALID_PARAMETER
;
750 switch (PROP_TYPE(lpProps
[i
].ulPropTag
))
764 ulPropSize
+= sizeof(SPropValue
);
767 ulPropSize
+= lpProps
[i
].Value
.MVszA
.cValues
* sizeof(char*) + sizeof(SPropValue
);
771 ulPropSize
+= lpProps
[i
].Value
.MVszA
.cValues
* sizeof(char*) + sizeof(SPropValue
);
774 ulPropSize
+= lpProps
[i
].Value
.MVbin
.cValues
* sizeof(SBinary
) + sizeof(SPropValue
);
777 ulPropSize
= sizeof(SPropValue
);
780 ulBytes
+= ulPropSize
;
788 /*************************************************************************
789 * ScCopyProps@16 (MAPI32.171)
791 * Copy an array of property values into a buffer suited for serialisation.
794 * cValues [I] Number of properties in lpProps
795 * lpProps [I] Property array to copy
796 * lpDst [O] Destination for the serialised data
797 * lpCount [O] If non-NULL, destination for the number of bytes of data written to lpDst
800 * Success: S_OK. lpDst contains the serialised data from lpProps.
801 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
804 * The resulting property value array is stored in a contiguous block starting at lpDst.
806 SCODE WINAPI
ScCopyProps(int cValues
, LPSPropValue lpProps
, LPVOID lpDst
, ULONG
*lpCount
)
808 LPSPropValue lpDest
= (LPSPropValue
)lpDst
;
809 char *lpDataDest
= (char *)(lpDest
+ cValues
);
813 TRACE("(%d,%p,%p,%p)\n", cValues
, lpProps
, lpDst
, lpCount
);
815 if (!lpProps
|| cValues
< 0 || !lpDest
)
816 return MAPI_E_INVALID_PARAMETER
;
818 memcpy(lpDst
, lpProps
, cValues
* sizeof(SPropValue
));
820 for (iter
= 0; iter
< cValues
; iter
++)
822 switch (PROP_TYPE(lpProps
->ulPropTag
))
825 lpDest
->Value
.lpguid
= (LPGUID
)lpDataDest
;
826 *lpDest
->Value
.lpguid
= *lpProps
->Value
.lpguid
;
827 lpDataDest
+= sizeof(GUID
);
830 ulLen
= lstrlenA(lpProps
->Value
.lpszA
) + 1u;
831 lpDest
->Value
.lpszA
= lpDataDest
;
832 memcpy(lpDest
->Value
.lpszA
, lpProps
->Value
.lpszA
, ulLen
);
836 ulLen
= (strlenW(lpProps
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
837 lpDest
->Value
.lpszW
= (LPWSTR
)lpDataDest
;
838 memcpy(lpDest
->Value
.lpszW
, lpProps
->Value
.lpszW
, ulLen
);
842 lpDest
->Value
.bin
.lpb
= (LPBYTE
)lpDataDest
;
843 memcpy(lpDest
->Value
.bin
.lpb
, lpProps
->Value
.bin
.lpb
, lpProps
->Value
.bin
.cb
);
844 lpDataDest
+= lpProps
->Value
.bin
.cb
;
847 if (lpProps
->ulPropTag
& MV_FLAG
)
849 lpDest
->Value
.MVi
.cValues
= lpProps
->Value
.MVi
.cValues
;
850 /* Note: Assignment uses lppszA but covers all cases by union aliasing */
851 lpDest
->Value
.MVszA
.lppszA
= (char**)lpDataDest
;
853 switch (PROP_TYPE(lpProps
->ulPropTag
))
857 lpDataDest
+= lpProps
->Value
.MVszA
.cValues
* sizeof(char *);
859 for (i
= 0; i
< lpProps
->Value
.MVszA
.cValues
; i
++)
861 ULONG ulStrLen
= lstrlenA(lpProps
->Value
.MVszA
.lppszA
[i
]) + 1u;
863 lpDest
->Value
.MVszA
.lppszA
[i
] = lpDataDest
;
864 memcpy(lpDataDest
, lpProps
->Value
.MVszA
.lppszA
[i
], ulStrLen
);
865 lpDataDest
+= ulStrLen
;
871 lpDataDest
+= lpProps
->Value
.MVszW
.cValues
* sizeof(WCHAR
*);
873 for (i
= 0; i
< lpProps
->Value
.MVszW
.cValues
; i
++)
875 ULONG ulStrLen
= (strlenW(lpProps
->Value
.MVszW
.lppszW
[i
]) + 1u) * sizeof(WCHAR
);
877 lpDest
->Value
.MVszW
.lppszW
[i
] = (LPWSTR
)lpDataDest
;
878 memcpy(lpDataDest
, lpProps
->Value
.MVszW
.lppszW
[i
], ulStrLen
);
879 lpDataDest
+= ulStrLen
;
885 lpDataDest
+= lpProps
->Value
.MVszW
.cValues
* sizeof(SBinary
);
887 for (i
= 0; i
< lpProps
->Value
.MVszW
.cValues
; i
++)
889 lpDest
->Value
.MVbin
.lpbin
[i
].cb
= lpProps
->Value
.MVbin
.lpbin
[i
].cb
;
890 lpDest
->Value
.MVbin
.lpbin
[i
].lpb
= (LPBYTE
)lpDataDest
;
891 memcpy(lpDataDest
, lpProps
->Value
.MVbin
.lpbin
[i
].lpb
, lpDest
->Value
.MVbin
.lpbin
[i
].cb
);
892 lpDataDest
+= lpDest
->Value
.MVbin
.lpbin
[i
].cb
;
897 /* No embedded pointers, just copy the data over */
898 ulLen
= UlPropSize(lpProps
);
899 memcpy(lpDest
->Value
.MVi
.lpi
, lpProps
->Value
.MVi
.lpi
, ulLen
);
910 *lpCount
= lpDataDest
- (char *)lpDst
;
915 /*************************************************************************
916 * ScRelocProps@20 (MAPI32.172)
918 * Relocate the pointers in an array of property values after it has been copied.
921 * cValues [I] Number of properties in lpProps
922 * lpProps [O] Property array to relocate the pointers in.
923 * lpOld [I] Position where the data was copied from
924 * lpNew [I] Position where the data was copied to
925 * lpCount [O] If non-NULL, destination for the number of bytes of data at lpDst
928 * Success: S_OK. Any pointers in lpProps are relocated.
929 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
932 * MSDN states that this function can be used for serialisation by passing
933 * NULL as either lpOld or lpNew, thus converting any pointers in lpProps
934 * between offsets and pointers. This does not work in native (it crashes),
935 * and cannot be made to work in Wine because the original interface design
936 * is deficient. The only use left for this function is to remap pointers
937 * in a contiguous property array that has been copied with memcpy() to
938 * another memory location.
940 SCODE WINAPI
ScRelocProps(int cValues
, LPSPropValue lpProps
, LPVOID lpOld
,
941 LPVOID lpNew
, ULONG
*lpCount
)
943 static const BOOL bBadPtr
= TRUE
; /* Windows bug - Assumes source is bad */
944 LPSPropValue lpDest
= lpProps
;
945 ULONG ulCount
= cValues
* sizeof(SPropValue
);
949 TRACE("(%d,%p,%p,%p,%p)\n", cValues
, lpProps
, lpOld
, lpNew
, lpCount
);
951 if (!lpProps
|| cValues
< 0 || !lpOld
|| !lpNew
)
952 return MAPI_E_INVALID_PARAMETER
;
954 /* The reason native doesn't work as MSDN states is that it assumes that
955 * the lpProps pointer contains valid pointers. This is obviously not
956 * true if the array is being read back from serialisation (the pointers
957 * are just offsets). Native can't actually work converting the pointers to
958 * offsets either, because it converts any array pointers to offsets then
959 * _dereferences the offset_ in order to convert the array elements!
961 * The code below would handle both cases except that the design of this
962 * function makes it impossible to know when the pointers in lpProps are
963 * valid. If both lpOld and lpNew are non-NULL, native reads the pointers
964 * after converting them, so we must do the same. It seems this
965 * functionality was never tested by MS.
968 #define RELOC_PTR(p) (((char*)(p)) - (char*)lpOld + (char*)lpNew)
970 for (iter
= 0; iter
< cValues
; iter
++)
972 switch (PROP_TYPE(lpDest
->ulPropTag
))
975 lpDest
->Value
.lpguid
= (LPGUID
)RELOC_PTR(lpDest
->Value
.lpguid
);
976 ulCount
+= sizeof(GUID
);
979 ulLen
= bBadPtr
? 0 : lstrlenA(lpDest
->Value
.lpszA
) + 1u;
980 lpDest
->Value
.lpszA
= RELOC_PTR(lpDest
->Value
.lpszA
);
982 ulLen
= lstrlenA(lpDest
->Value
.lpszA
) + 1u;
986 ulLen
= bBadPtr
? 0 : (lstrlenW(lpDest
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
987 lpDest
->Value
.lpszW
= (LPWSTR
)RELOC_PTR(lpDest
->Value
.lpszW
);
989 ulLen
= (strlenW(lpDest
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
993 lpDest
->Value
.bin
.lpb
= (LPBYTE
)RELOC_PTR(lpDest
->Value
.bin
.lpb
);
994 ulCount
+= lpDest
->Value
.bin
.cb
;
997 if (lpDest
->ulPropTag
& MV_FLAG
)
999 /* Since we have to access the array elements, don't map the
1000 * array unless it is invalid (otherwise, map it at the end)
1003 lpDest
->Value
.MVszA
.lppszA
= (LPSTR
*)RELOC_PTR(lpDest
->Value
.MVszA
.lppszA
);
1005 switch (PROP_TYPE(lpProps
->ulPropTag
))
1009 ulCount
+= lpDest
->Value
.MVszA
.cValues
* sizeof(char *);
1011 for (i
= 0; i
< lpDest
->Value
.MVszA
.cValues
; i
++)
1013 ULONG ulStrLen
= bBadPtr
? 0 : lstrlenA(lpDest
->Value
.MVszA
.lppszA
[i
]) + 1u;
1015 lpDest
->Value
.MVszA
.lppszA
[i
] = RELOC_PTR(lpDest
->Value
.MVszA
.lppszA
[i
]);
1017 ulStrLen
= lstrlenA(lpDest
->Value
.MVszA
.lppszA
[i
]) + 1u;
1018 ulCount
+= ulStrLen
;
1024 ulCount
+= lpDest
->Value
.MVszW
.cValues
* sizeof(WCHAR
*);
1026 for (i
= 0; i
< lpDest
->Value
.MVszW
.cValues
; i
++)
1028 ULONG ulStrLen
= bBadPtr
? 0 : (strlenW(lpDest
->Value
.MVszW
.lppszW
[i
]) + 1u) * sizeof(WCHAR
);
1030 lpDest
->Value
.MVszW
.lppszW
[i
] = (LPWSTR
)RELOC_PTR(lpDest
->Value
.MVszW
.lppszW
[i
]);
1032 ulStrLen
= (strlenW(lpDest
->Value
.MVszW
.lppszW
[i
]) + 1u) * sizeof(WCHAR
);
1033 ulCount
+= ulStrLen
;
1039 ulCount
+= lpDest
->Value
.MVszW
.cValues
* sizeof(SBinary
);
1041 for (i
= 0; i
< lpDest
->Value
.MVszW
.cValues
; i
++)
1043 lpDest
->Value
.MVbin
.lpbin
[i
].lpb
= (LPBYTE
)RELOC_PTR(lpDest
->Value
.MVbin
.lpbin
[i
].lpb
);
1044 ulCount
+= lpDest
->Value
.MVbin
.lpbin
[i
].cb
;
1049 ulCount
+= UlPropSize(lpDest
);
1053 lpDest
->Value
.MVszA
.lppszA
= (LPSTR
*)RELOC_PTR(lpDest
->Value
.MVszA
.lppszA
);
1065 /*************************************************************************
1066 * LpValFindProp@12 (MAPI32.173)
1068 * Find a property with a given property id in a property array.
1071 * ulPropTag [I] Property tag containing property id to find
1072 * cValues [I] Number of properties in lpProps
1073 * lpProps [I] Property array to search
1076 * A pointer to the matching property, or NULL if none was found.
1079 * This function matches only on the property id and does not care if the
1080 * property types differ.
1082 LPSPropValue WINAPI
LpValFindProp(ULONG ulPropTag
, ULONG cValues
, LPSPropValue lpProps
)
1084 TRACE("(%d,%d,%p)\n", ulPropTag
, cValues
, lpProps
);
1086 if (lpProps
&& cValues
)
1089 for (i
= 0; i
< cValues
; i
++)
1091 if (PROP_ID(ulPropTag
) == PROP_ID(lpProps
[i
].ulPropTag
))
1098 /*************************************************************************
1099 * ScDupPropset@16 (MAPI32.174)
1101 * Duplicate a property value array into a contiguous block of memory.
1104 * cValues [I] Number of properties in lpProps
1105 * lpProps [I] Property array to duplicate
1106 * lpAlloc [I] Memory allocation function, use MAPIAllocateBuffer()
1107 * lpNewProp [O] Destination for the newly duplicated property value array
1110 * Success: S_OK. *lpNewProp contains the duplicated array.
1111 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
1112 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
1114 SCODE WINAPI
ScDupPropset(int cValues
, LPSPropValue lpProps
,
1115 LPALLOCATEBUFFER lpAlloc
, LPSPropValue
*lpNewProp
)
1120 TRACE("(%d,%p,%p,%p)\n", cValues
, lpProps
, lpAlloc
, lpNewProp
);
1122 sc
= ScCountProps(cValues
, lpProps
, &ulCount
);
1125 sc
= lpAlloc(ulCount
, (LPVOID
*)lpNewProp
);
1127 sc
= ScCopyProps(cValues
, lpProps
, *lpNewProp
, &ulCount
);
1132 /*************************************************************************
1133 * FBadRglpszA@8 (MAPI32.175)
1135 * Determine if an array of strings is invalid
1138 * lppszStrs [I] Array of strings to check
1139 * ulCount [I] Number of strings in lppszStrs
1142 * TRUE, if lppszStrs is invalid, FALSE otherwise.
1144 BOOL WINAPI
FBadRglpszA(LPSTR
*lppszStrs
, ULONG ulCount
)
1148 TRACE("(%p,%d)\n", lppszStrs
, ulCount
);
1153 if (!lppszStrs
|| IsBadReadPtr(lppszStrs
, ulCount
* sizeof(LPWSTR
)))
1156 for (i
= 0; i
< ulCount
; i
++)
1158 if (!lppszStrs
[i
] || IsBadStringPtrA(lppszStrs
[i
], -1))
1164 /*************************************************************************
1165 * FBadRglpszW@8 (MAPI32.176)
1169 BOOL WINAPI
FBadRglpszW(LPWSTR
*lppszStrs
, ULONG ulCount
)
1173 TRACE("(%p,%d)\n", lppszStrs
, ulCount
);
1178 if (!lppszStrs
|| IsBadReadPtr(lppszStrs
, ulCount
* sizeof(LPWSTR
)))
1181 for (i
= 0; i
< ulCount
; i
++)
1183 if (!lppszStrs
[i
] || IsBadStringPtrW(lppszStrs
[i
], -1))
1189 /*************************************************************************
1190 * FBadRowSet@4 (MAPI32.177)
1192 * Determine if a row is invalid
1195 * lpRow [I] Row to check
1198 * TRUE, if lpRow is invalid, FALSE otherwise.
1200 BOOL WINAPI
FBadRowSet(LPSRowSet lpRowSet
)
1203 TRACE("(%p)\n", lpRowSet
);
1205 if (!lpRowSet
|| IsBadReadPtr(lpRowSet
, CbSRowSet(lpRowSet
)))
1208 for (i
= 0; i
< lpRowSet
->cRows
; i
++)
1210 if (FBadRow(&lpRowSet
->aRow
[i
]))
1216 /*************************************************************************
1217 * FBadPropTag@4 (MAPI32.179)
1219 * Determine if a property tag is invalid
1222 * ulPropTag [I] Property tag to check
1225 * TRUE, if ulPropTag is invalid, FALSE otherwise.
1227 ULONG WINAPI
FBadPropTag(ULONG ulPropTag
)
1229 TRACE("(0x%08x)\n", ulPropTag
);
1231 switch (ulPropTag
& (~MV_FLAG
& PROP_TYPE_MASK
))
1233 case PT_UNSPECIFIED
:
1255 /*************************************************************************
1256 * FBadRow@4 (MAPI32.180)
1258 * Determine if a row is invalid
1261 * lpRow [I] Row to check
1264 * TRUE, if lpRow is invalid, FALSE otherwise.
1266 ULONG WINAPI
FBadRow(LPSRow lpRow
)
1269 TRACE("(%p)\n", lpRow
);
1271 if (!lpRow
|| IsBadReadPtr(lpRow
, sizeof(SRow
)) || !lpRow
->lpProps
||
1272 IsBadReadPtr(lpRow
->lpProps
, lpRow
->cValues
* sizeof(SPropValue
)))
1275 for (i
= 0; i
< lpRow
->cValues
; i
++)
1277 if (FBadProp(&lpRow
->lpProps
[i
]))
1283 /*************************************************************************
1284 * FBadProp@4 (MAPI32.181)
1286 * Determine if a property is invalid
1289 * lpProp [I] Property to check
1292 * TRUE, if lpProp is invalid, FALSE otherwise.
1294 ULONG WINAPI
FBadProp(LPSPropValue lpProp
)
1296 if (!lpProp
|| IsBadReadPtr(lpProp
, sizeof(SPropValue
)) ||
1297 FBadPropTag(lpProp
->ulPropTag
))
1300 switch (PROP_TYPE(lpProp
->ulPropTag
))
1302 /* Single value properties containing pointers */
1304 if (!lpProp
->Value
.lpszA
|| IsBadStringPtrA(lpProp
->Value
.lpszA
, -1))
1308 if (!lpProp
->Value
.lpszW
|| IsBadStringPtrW(lpProp
->Value
.lpszW
, -1))
1312 if (IsBadReadPtr(lpProp
->Value
.bin
.lpb
, lpProp
->Value
.bin
.cb
))
1316 if (IsBadReadPtr(lpProp
->Value
.lpguid
, sizeof(GUID
)))
1320 /* Multiple value properties (arrays) containing no pointers */
1322 return PROP_BadArray(lpProp
, sizeof(SHORT
));
1324 return PROP_BadArray(lpProp
, sizeof(LONG
));
1325 case PT_MV_LONGLONG
:
1326 return PROP_BadArray(lpProp
, sizeof(LONG64
));
1328 return PROP_BadArray(lpProp
, sizeof(float));
1330 return PROP_BadArray(lpProp
, sizeof(FILETIME
));
1333 return PROP_BadArray(lpProp
, sizeof(double));
1334 case PT_MV_CURRENCY
:
1335 return PROP_BadArray(lpProp
, sizeof(CY
));
1337 return PROP_BadArray(lpProp
, sizeof(GUID
));
1339 /* Multiple value properties containing pointers */
1341 return FBadRglpszA(lpProp
->Value
.MVszA
.lppszA
,
1342 lpProp
->Value
.MVszA
.cValues
);
1344 return FBadRglpszW(lpProp
->Value
.MVszW
.lppszW
,
1345 lpProp
->Value
.MVszW
.cValues
);
1347 return FBadEntryList(&lpProp
->Value
.MVbin
);
1352 /*************************************************************************
1353 * FBadColumnSet@4 (MAPI32.182)
1355 * Determine if an array of property tags is invalid
1358 * lpCols [I] Property tag array to check
1361 * TRUE, if lpCols is invalid, FALSE otherwise.
1363 ULONG WINAPI
FBadColumnSet(LPSPropTagArray lpCols
)
1365 ULONG ulRet
= FALSE
, i
;
1367 TRACE("(%p)\n", lpCols
);
1369 if (!lpCols
|| IsBadReadPtr(lpCols
, CbSPropTagArray(lpCols
)))
1373 for (i
= 0; i
< lpCols
->cValues
; i
++)
1375 if ((lpCols
->aulPropTag
[i
] & PROP_TYPE_MASK
) == PT_ERROR
||
1376 FBadPropTag(lpCols
->aulPropTag
[i
]))
1383 TRACE("Returning %s\n", ulRet
? "TRUE" : "FALSE");
1388 /**************************************************************************
1389 * IPropData {MAPI32}
1391 * A default Mapi interface to provide manipulation of object properties.
1394 * This object provides a default interface suitable in some cases as an
1395 * implementation of the IMAPIProp interface (which has no default
1396 * implementation). In addition to the IMAPIProp() methods inherited, this
1397 * interface allows read/write control over access to the object and its
1398 * individual properties.
1400 * To obtain the default implementation of this interface from Mapi, call
1406 /* A single property in a property data collection */
1410 ULONG ulAccess
; /* The property value access level */
1411 LPSPropValue value
; /* The property value */
1412 } IPropDataItem
, *LPIPropDataItem
;
1414 /* The main property data collection structure */
1417 IPropData IPropData_iface
;
1418 LONG lRef
; /* Reference count */
1419 ALLOCATEBUFFER
*lpAlloc
; /* Memory allocation routine */
1420 ALLOCATEMORE
*lpMore
; /* Linked memory allocation routine */
1421 FREEBUFFER
*lpFree
; /* Memory free routine */
1422 ULONG ulObjAccess
; /* Object access level */
1423 ULONG ulNumValues
; /* Number of items in values list */
1424 struct list values
; /* List of property values */
1425 CRITICAL_SECTION cs
; /* Lock for thread safety */
1428 static inline IPropDataImpl
*impl_from_IPropData(IPropData
*iface
)
1430 return CONTAINING_RECORD(iface
, IPropDataImpl
, IPropData_iface
);
1433 /* Internal - Get a property value, assumes lock is held */
1434 static IPropDataItem
*IMAPIPROP_GetValue(IPropDataImpl
*This
, ULONG ulPropTag
)
1436 struct list
*cursor
;
1438 LIST_FOR_EACH(cursor
, &This
->values
)
1440 LPIPropDataItem current
= LIST_ENTRY(cursor
, IPropDataItem
, entry
);
1441 /* Note that property types don't have to match, just Id's */
1442 if (PROP_ID(current
->value
->ulPropTag
) == PROP_ID(ulPropTag
))
1448 /* Internal - Add a new property value, assumes lock is held */
1449 static IPropDataItem
*IMAPIPROP_AddValue(IPropDataImpl
*This
,
1450 LPSPropValue lpProp
)
1453 LPIPropDataItem lpNew
;
1456 hRet
= This
->lpAlloc(sizeof(IPropDataItem
), &lpMem
);
1458 if (SUCCEEDED(hRet
))
1461 lpNew
->ulAccess
= IPROP_READWRITE
;
1463 /* Allocate the value separately so we can update it easily */
1465 hRet
= This
->lpAlloc(sizeof(SPropValue
), &lpMem
);
1466 if (SUCCEEDED(hRet
))
1468 lpNew
->value
= lpMem
;
1470 hRet
= PropCopyMore(lpNew
->value
, lpProp
, This
->lpMore
, lpMem
);
1471 if (SUCCEEDED(hRet
))
1473 list_add_tail(&This
->values
, &lpNew
->entry
);
1474 This
->ulNumValues
++;
1477 This
->lpFree(lpNew
->value
);
1479 This
->lpFree(lpNew
);
1484 /* Internal - Lock an IPropData object */
1485 static inline void IMAPIPROP_Lock(IPropDataImpl
*This
)
1487 EnterCriticalSection(&This
->cs
);
1490 /* Internal - Unlock an IPropData object */
1491 static inline void IMAPIPROP_Unlock(IPropDataImpl
*This
)
1493 LeaveCriticalSection(&This
->cs
);
1496 /* This one seems to be missing from mapidefs.h */
1497 #define CbNewSPropProblemArray(c) \
1498 (offsetof(SPropProblemArray,aProblem)+(c)*sizeof(SPropProblem))
1500 /**************************************************************************
1501 * IPropData_QueryInterface {MAPI32}
1503 * Inherited method from the IUnknown Interface.
1504 * See IUnknown_QueryInterface.
1506 static HRESULT WINAPI
IPropData_fnQueryInterface(LPPROPDATA iface
, REFIID riid
, LPVOID
*ppvObj
)
1508 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1510 TRACE("(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppvObj
);
1512 if (!ppvObj
|| !riid
)
1513 return MAPI_E_INVALID_PARAMETER
;
1517 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1518 IsEqualIID(riid
, &IID_IMAPIProp
) ||
1519 IsEqualIID(riid
, &IID_IMAPIPropData
))
1522 IPropData_AddRef(iface
);
1523 TRACE("returning %p\n", *ppvObj
);
1527 TRACE("returning E_NOINTERFACE\n");
1528 return MAPI_E_INTERFACE_NOT_SUPPORTED
;
1531 /**************************************************************************
1532 * IPropData_AddRef {MAPI32}
1534 * Inherited method from the IUnknown Interface.
1535 * See IUnknown_AddRef.
1537 static ULONG WINAPI
IPropData_fnAddRef(LPPROPDATA iface
)
1539 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1541 TRACE("(%p)->(count before=%u)\n", This
, This
->lRef
);
1543 return InterlockedIncrement(&This
->lRef
);
1546 /**************************************************************************
1547 * IPropData_Release {MAPI32}
1549 * Inherited method from the IUnknown Interface.
1550 * See IUnknown_Release.
1552 static ULONG WINAPI
IPropData_fnRelease(LPPROPDATA iface
)
1554 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1557 TRACE("(%p)->(count before=%u)\n", This
, This
->lRef
);
1559 lRef
= InterlockedDecrement(&This
->lRef
);
1562 TRACE("Destroying IPropData (%p)\n",This
);
1564 /* Note: No need to lock, since no other thread is referencing iface */
1565 while (!list_empty(&This
->values
))
1567 struct list
*head
= list_head(&This
->values
);
1568 LPIPropDataItem current
= LIST_ENTRY(head
, IPropDataItem
, entry
);
1570 This
->lpFree(current
->value
);
1571 This
->lpFree(current
);
1573 This
->cs
.DebugInfo
->Spare
[0] = 0;
1574 DeleteCriticalSection(&This
->cs
);
1580 /**************************************************************************
1581 * IPropData_GetLastError {MAPI32}
1583 * Get information about the last error that occurred in an IMAPIProp object.
1586 * iface [I] IMAPIProp object that experienced the error
1587 * hRes [I] Result of the call that returned an error
1588 * ulFlags [I] 0=return Ascii strings, MAPI_UNICODE=return Unicode strings
1589 * lppError [O] Destination for detailed error information
1592 * Success: S_OK. *lppError contains details about the last error.
1593 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
1594 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
1597 * - If this function succeeds, the returned information in *lppError must be
1598 * freed using MAPIFreeBuffer() once the caller is finished with it.
1599 * - It is possible for this function to succeed and set *lppError to NULL,
1600 * if there is no further information to report about hRes.
1602 static HRESULT WINAPI
IPropData_fnGetLastError(LPPROPDATA iface
, HRESULT hRes
, ULONG ulFlags
,
1603 LPMAPIERROR
*lppError
)
1605 TRACE("(%p,0x%08X,0x%08X,%p)\n", iface
, hRes
, ulFlags
, lppError
);
1607 if (!lppError
|| SUCCEEDED(hRes
) || (ulFlags
& ~MAPI_UNICODE
))
1608 return MAPI_E_INVALID_PARAMETER
;
1614 /**************************************************************************
1615 * IPropData_SaveChanges {MAPI32}
1617 * Update any changes made to a transactional IMAPIProp object.
1620 * iface [I] IMAPIProp object to update
1621 * ulFlags [I] Flags controlling the update.
1624 * Success: S_OK. Any outstanding changes are committed to the object.
1625 * Failure: An HRESULT error code describing the error.
1627 static HRESULT WINAPI
IPropData_fnSaveChanges(LPPROPDATA iface
, ULONG ulFlags
)
1629 TRACE("(%p,0x%08X)\n", iface
, ulFlags
);
1631 /* Since this object is not transacted we do not need to implement this */
1632 /* FIXME: Should we set the access levels to clean? */
1636 /**************************************************************************
1637 * IPropData_GetProps {MAPI32}
1639 * Get property values from an IMAPIProp object.
1642 * iface [I] IMAPIProp object to get the property values from
1643 * lpTags [I] Property tage of property values to be retrieved
1644 * ulFlags [I] Return 0=Ascii MAPI_UNICODE=Unicode strings for
1646 * lpCount [O] Destination for number of properties returned
1647 * lppProps [O] Destination for returned property values
1650 * Success: S_OK. *lppProps and *lpCount are updated.
1651 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1652 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
1653 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
1656 * - If MAPI_W_ERRORS_RETURNED is returned, any properties that could not be
1657 * retrieved from iface are present in lppProps with their type
1658 * changed to PT_ERROR and Id unchanged.
1660 static HRESULT WINAPI
IPropData_fnGetProps(LPPROPDATA iface
, LPSPropTagArray lpTags
, ULONG ulFlags
,
1661 ULONG
*lpCount
, LPSPropValue
*lppProps
)
1663 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1665 HRESULT hRet
= S_OK
;
1667 TRACE("(%p,%p,0x%08x,%p,%p) stub\n", iface
, lpTags
, ulFlags
,
1670 if (!iface
|| ulFlags
& ~MAPI_UNICODE
|| !lpTags
|| *lpCount
|| !lppProps
)
1671 return MAPI_E_INVALID_PARAMETER
;
1673 FIXME("semi-stub, flags not supported\n");
1675 *lpCount
= lpTags
->cValues
;
1680 hRet
= MAPIAllocateBuffer(*lpCount
* sizeof(SPropValue
), (LPVOID
*)lppProps
);
1684 IMAPIPROP_Lock(This
);
1686 for (i
= 0; i
< lpTags
->cValues
; i
++)
1688 HRESULT hRetTmp
= E_INVALIDARG
;
1689 LPIPropDataItem item
;
1691 item
= IMAPIPROP_GetValue(This
, lpTags
->aulPropTag
[i
]);
1694 hRetTmp
= PropCopyMore(&(*lppProps
)[i
], item
->value
,
1695 This
->lpMore
, *lppProps
);
1696 if (FAILED(hRetTmp
))
1698 hRet
= MAPI_W_ERRORS_RETURNED
;
1699 (*lppProps
)[i
].ulPropTag
=
1700 CHANGE_PROP_TYPE(lpTags
->aulPropTag
[i
], PT_ERROR
);
1704 IMAPIPROP_Unlock(This
);
1709 /**************************************************************************
1710 * MAPIProp_GetPropList {MAPI32}
1712 * Get the list of property tags for all values in an IMAPIProp object.
1715 * iface [I] IMAPIProp object to get the property tag list from
1716 * ulFlags [I] Return 0=Ascii MAPI_UNICODE=Unicode strings for
1718 * lppTags [O] Destination for the retrieved property tag list
1721 * Success: S_OK. *lppTags contains the tags for all available properties.
1722 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1723 * MAPI_E_BAD_CHARWIDTH, if Ascii or Unicode strings are requested
1724 * and that type of string is not supported.
1726 static HRESULT WINAPI
IPropData_fnGetPropList(LPPROPDATA iface
, ULONG ulFlags
,
1727 LPSPropTagArray
*lppTags
)
1729 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1733 TRACE("(%p,0x%08x,%p) stub\n", iface
, ulFlags
, lppTags
);
1735 if (!iface
|| ulFlags
& ~MAPI_UNICODE
|| !lppTags
)
1736 return MAPI_E_INVALID_PARAMETER
;
1738 FIXME("semi-stub, flags not supported\n");
1742 IMAPIPROP_Lock(This
);
1744 hRet
= MAPIAllocateBuffer(CbNewSPropTagArray(This
->ulNumValues
),
1746 if (SUCCEEDED(hRet
))
1748 struct list
*cursor
;
1751 LIST_FOR_EACH(cursor
, &This
->values
)
1753 LPIPropDataItem current
= LIST_ENTRY(cursor
, IPropDataItem
, entry
);
1754 (*lppTags
)->aulPropTag
[i
] = current
->value
->ulPropTag
;
1757 (*lppTags
)->cValues
= This
->ulNumValues
;
1760 IMAPIPROP_Unlock(This
);
1764 /**************************************************************************
1765 * IPropData_OpenProperty {MAPI32}
1767 * Not documented at this time.
1770 * An HRESULT success/failure code.
1772 static HRESULT WINAPI
IPropData_fnOpenProperty(LPPROPDATA iface
, ULONG ulPropTag
, LPCIID iid
,
1773 ULONG ulOpts
, ULONG ulFlags
, LPUNKNOWN
*lpUnk
)
1775 FIXME("(%p,%u,%s,%u,0x%08x,%p) stub\n", iface
, ulPropTag
,
1776 debugstr_guid(iid
), ulOpts
, ulFlags
, lpUnk
);
1777 return MAPI_E_NO_SUPPORT
;
1781 /**************************************************************************
1782 * IPropData_SetProps {MAPI32}
1784 * Add or edit the property values in an IMAPIProp object.
1787 * iface [I] IMAPIProp object to get the property tag list from
1788 * ulValues [I] Number of properties in lpProps
1789 * lpProps [I] Property values to set
1790 * lppProbs [O] Optional destination for any problems that occurred
1793 * Success: S_OK. The properties in lpProps are added to iface if they don't
1794 * exist, or changed to the values in lpProps if they do
1795 * Failure: An HRESULT error code describing the error
1797 static HRESULT WINAPI
IPropData_fnSetProps(LPPROPDATA iface
, ULONG ulValues
, LPSPropValue lpProps
,
1798 LPSPropProblemArray
*lppProbs
)
1800 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1801 HRESULT hRet
= S_OK
;
1804 TRACE("(%p,%u,%p,%p)\n", iface
, ulValues
, lpProps
, lppProbs
);
1806 if (!iface
|| !lpProps
)
1807 return MAPI_E_INVALID_PARAMETER
;
1809 for (i
= 0; i
< ulValues
; i
++)
1811 if (FBadProp(&lpProps
[i
]) ||
1812 PROP_TYPE(lpProps
[i
].ulPropTag
) == PT_OBJECT
||
1813 PROP_TYPE(lpProps
[i
].ulPropTag
) == PT_NULL
)
1814 return MAPI_E_INVALID_PARAMETER
;
1817 IMAPIPROP_Lock(This
);
1819 /* FIXME: Under what circumstances is lpProbs created? */
1820 for (i
= 0; i
< ulValues
; i
++)
1822 LPIPropDataItem item
= IMAPIPROP_GetValue(This
, lpProps
[i
].ulPropTag
);
1827 LPVOID lpMem
= NULL
;
1829 /* Found, so update the existing value */
1830 if (item
->value
->ulPropTag
!= lpProps
[i
].ulPropTag
)
1831 FIXME("semi-stub, overwriting type (not coercing)\n");
1833 hRetTmp
= This
->lpAlloc(sizeof(SPropValue
), &lpMem
);
1834 if (SUCCEEDED(hRetTmp
))
1836 hRetTmp
= PropCopyMore(lpMem
, &lpProps
[i
], This
->lpMore
, lpMem
);
1837 if (SUCCEEDED(hRetTmp
))
1839 This
->lpFree(item
->value
);
1840 item
->value
= lpMem
;
1843 This
->lpFree(lpMem
);
1850 if (!IMAPIPROP_AddValue(This
, &lpProps
[i
]))
1851 hRet
= MAPI_E_NOT_ENOUGH_MEMORY
;
1855 IMAPIPROP_Unlock(This
);
1859 /**************************************************************************
1860 * IPropData_DeleteProps {MAPI32}
1862 * Delete one or more property values from an IMAPIProp object.
1865 * iface [I] IMAPIProp object to remove property values from.
1866 * lpTags [I] Collection of property Id's to remove from iface.
1867 * lppProbs [O] Destination for problems encountered, if any.
1870 * Success: S_OK. Any properties in iface matching property Id's in lpTags have
1871 * been deleted. If lppProbs is non-NULL it contains details of any
1872 * errors that occurred.
1873 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1874 * E_ACCESSDENIED, if this object was created using CreateIProp() and
1875 * a subsequent call to IPropData_SetObjAccess() was made specifying
1876 * IPROP_READONLY as the access type.
1879 * - lppProbs will not be populated for cases where a property Id is present
1880 * in lpTags but not in iface.
1881 * - lppProbs should be deleted with MAPIFreeBuffer() if returned.
1883 static HRESULT WINAPI
IPropData_fnDeleteProps(LPPROPDATA iface
, LPSPropTagArray lpTags
,
1884 LPSPropProblemArray
*lppProbs
)
1886 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1887 ULONG i
, numProbs
= 0;
1888 HRESULT hRet
= S_OK
;
1890 TRACE("(%p,%p,%p)\n", iface
, lpTags
, lppProbs
);
1892 if (!iface
|| !lpTags
)
1893 return MAPI_E_INVALID_PARAMETER
;
1898 for (i
= 0; i
< lpTags
->cValues
; i
++)
1900 if (FBadPropTag(lpTags
->aulPropTag
[i
]) ||
1901 PROP_TYPE(lpTags
->aulPropTag
[i
]) == PT_OBJECT
||
1902 PROP_TYPE(lpTags
->aulPropTag
[i
]) == PT_NULL
)
1903 return MAPI_E_INVALID_PARAMETER
;
1906 IMAPIPROP_Lock(This
);
1908 if (This
->ulObjAccess
!= IPROP_READWRITE
)
1910 IMAPIPROP_Unlock(This
);
1911 return E_ACCESSDENIED
;
1914 for (i
= 0; i
< lpTags
->cValues
; i
++)
1916 LPIPropDataItem item
= IMAPIPROP_GetValue(This
, lpTags
->aulPropTag
[i
]);
1920 if (item
->ulAccess
& IPROP_READWRITE
)
1922 /* Everything hunky-dory, remove the item */
1923 list_remove(&item
->entry
);
1924 This
->lpFree(item
->value
); /* Also frees value pointers */
1926 This
->ulNumValues
--;
1930 /* Can't write the value. Create/populate problems array */
1933 /* Create problems array */
1934 ULONG ulSize
= CbNewSPropProblemArray(lpTags
->cValues
- i
);
1935 HRESULT hRetTmp
= MAPIAllocateBuffer(ulSize
, (LPVOID
*)lppProbs
);
1936 if (FAILED(hRetTmp
))
1941 LPSPropProblem lpProb
= &(*lppProbs
)->aProblem
[numProbs
];
1942 lpProb
->ulIndex
= i
;
1943 lpProb
->ulPropTag
= lpTags
->aulPropTag
[i
];
1944 lpProb
->scode
= E_ACCESSDENIED
;
1950 if (lppProbs
&& *lppProbs
)
1951 (*lppProbs
)->cProblem
= numProbs
;
1953 IMAPIPROP_Unlock(This
);
1958 /**************************************************************************
1959 * IPropData_CopyTo {MAPI32}
1961 * Not documented at this time.
1964 * An HRESULT success/failure code.
1966 static HRESULT WINAPI
IPropData_fnCopyTo(LPPROPDATA iface
, ULONG niids
, LPCIID lpiidExcl
,
1967 LPSPropTagArray lpPropsExcl
, ULONG ulParam
,
1968 LPMAPIPROGRESS lpIProgress
, LPCIID lpIfaceIid
,
1969 LPVOID lpDstObj
, ULONG ulFlags
,
1970 LPSPropProblemArray
*lppProbs
)
1972 FIXME("(%p,%u,%p,%p,%x,%p,%s,%p,0x%08X,%p) stub\n", iface
, niids
,
1973 lpiidExcl
, lpPropsExcl
, ulParam
, lpIProgress
,
1974 debugstr_guid(lpIfaceIid
), lpDstObj
, ulFlags
, lppProbs
);
1975 return MAPI_E_NO_SUPPORT
;
1978 /**************************************************************************
1979 * IPropData_CopyProps {MAPI32}
1981 * Not documented at this time.
1984 * An HRESULT success/failure code.
1986 static HRESULT WINAPI
IPropData_fnCopyProps(LPPROPDATA iface
, LPSPropTagArray lpInclProps
,
1987 ULONG ulParam
, LPMAPIPROGRESS lpIProgress
,
1988 LPCIID lpIface
, LPVOID lpDstObj
, ULONG ulFlags
,
1989 LPSPropProblemArray
*lppProbs
)
1991 FIXME("(%p,%p,%x,%p,%s,%p,0x%08X,%p) stub\n", iface
, lpInclProps
,
1992 ulParam
, lpIProgress
, debugstr_guid(lpIface
), lpDstObj
, ulFlags
,
1994 return MAPI_E_NO_SUPPORT
;
1997 /**************************************************************************
1998 * IPropData_GetNamesFromIDs {MAPI32}
2000 * Get the names of properties from their identifiers.
2003 * iface [I] IMAPIProp object to operate on
2004 * lppPropTags [I/O] Property identifiers to get the names for, or NULL to
2006 * iid [I] Property set identifier, or NULL
2007 * ulFlags [I] MAPI_NO_IDS=Don't return numeric named properties,
2008 * or MAPI_NO_STRINGS=Don't return strings
2009 * lpCount [O] Destination for number of properties returned
2010 * lpppNames [O] Destination for returned names
2013 * Success: S_OK. *lppPropTags and lpppNames contain the returned
2015 * Failure: MAPI_E_NO_SUPPORT, if the object does not support named properties,
2016 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
2017 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
2020 static HRESULT WINAPI
IPropData_fnGetNamesFromIDs(LPPROPDATA iface
, LPSPropTagArray
*lppPropTags
,
2021 LPGUID iid
, ULONG ulFlags
, ULONG
*lpCount
,
2022 LPMAPINAMEID
**lpppNames
)
2024 FIXME("(%p,%p,%s,0x%08X,%p,%p) stub\n", iface
, lppPropTags
,
2025 debugstr_guid(iid
), ulFlags
, lpCount
, lpppNames
);
2026 return MAPI_E_NO_SUPPORT
;
2029 /**************************************************************************
2030 * IPropData_GetIDsFromNames {MAPI32}
2032 * Get property identifiers associated with one or more named properties.
2035 * iface [I] IMAPIProp object to operate on
2036 * ulNames [I] Number of names in lppNames
2037 * lppNames [I] Names to query or create, or NULL to query all names
2038 * ulFlags [I] Pass MAPI_CREATE to create new named properties
2039 * lppPropTags [O] Destination for queried or created property identifiers
2042 * Success: S_OK. *lppPropTags contains the property tags created or requested.
2043 * Failure: MAPI_E_NO_SUPPORT, if the object does not support named properties,
2044 * MAPI_E_TOO_BIG, if the object cannot process the number of
2045 * properties involved.
2046 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
2047 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
2050 static HRESULT WINAPI
IPropData_fnGetIDsFromNames(LPPROPDATA iface
, ULONG ulNames
,
2051 LPMAPINAMEID
*lppNames
, ULONG ulFlags
,
2052 LPSPropTagArray
*lppPropTags
)
2054 FIXME("(%p,%d,%p,0x%08X,%p) stub\n",
2055 iface
, ulNames
, lppNames
, ulFlags
, lppPropTags
);
2056 return MAPI_E_NO_SUPPORT
;
2059 /**************************************************************************
2060 * IPropData_HrSetObjAccess {MAPI32}
2062 * Set the access level of an IPropData object.
2065 * iface [I] IPropData object to set the access on
2066 * ulAccess [I] Either IPROP_READONLY or IPROP_READWRITE for read or
2067 * read/write access respectively.
2070 * Success: S_OK. The objects access level is changed.
2071 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
2073 static HRESULT WINAPI
2074 IPropData_fnHrSetObjAccess(LPPROPDATA iface
, ULONG ulAccess
)
2076 IPropDataImpl
*This
= impl_from_IPropData(iface
);
2078 TRACE("(%p,%x)\n", iface
, ulAccess
);
2080 if (!iface
|| ulAccess
< IPROP_READONLY
|| ulAccess
> IPROP_READWRITE
)
2081 return MAPI_E_INVALID_PARAMETER
;
2083 IMAPIPROP_Lock(This
);
2085 This
->ulObjAccess
= ulAccess
;
2087 IMAPIPROP_Unlock(This
);
2091 /* Internal - determine if an access value is bad */
2092 static inline BOOL
PROP_IsBadAccess(ULONG ulAccess
)
2096 case IPROP_READONLY
|IPROP_CLEAN
:
2097 case IPROP_READONLY
|IPROP_DIRTY
:
2098 case IPROP_READWRITE
|IPROP_CLEAN
:
2099 case IPROP_READWRITE
|IPROP_DIRTY
:
2105 /**************************************************************************
2106 * IPropData_HrSetPropAccess {MAPI32}
2108 * Set the access levels for a group of property values in an IPropData object.
2111 * iface [I] IPropData object to set access levels in.
2112 * lpTags [I] List of property Id's to set access for.
2113 * lpAccess [O] Access level for each property in lpTags.
2116 * Success: S_OK. The access level of each property value in lpTags that is
2117 * present in iface is changed.
2118 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
2121 * - Each access level in lpAccess must contain at least one of IPROP_READONLY
2122 * or IPROP_READWRITE, but not both, and also IPROP_CLEAN or IPROP_DIRTY,
2123 * but not both. No other bits should be set.
2124 * - If a property Id in lpTags is not present in iface, it is ignored.
2126 static HRESULT WINAPI
2127 IPropData_fnHrSetPropAccess(LPPROPDATA iface
, LPSPropTagArray lpTags
,
2130 IPropDataImpl
*This
= impl_from_IPropData(iface
);
2133 TRACE("(%p,%p,%p)\n", iface
, lpTags
, lpAccess
);
2135 if (!iface
|| !lpTags
|| !lpAccess
)
2136 return MAPI_E_INVALID_PARAMETER
;
2138 for (i
= 0; i
< lpTags
->cValues
; i
++)
2140 if (FBadPropTag(lpTags
->aulPropTag
[i
]) || PROP_IsBadAccess(lpAccess
[i
]))
2141 return MAPI_E_INVALID_PARAMETER
;
2144 IMAPIPROP_Lock(This
);
2146 for (i
= 0; i
< lpTags
->cValues
; i
++)
2148 LPIPropDataItem item
= IMAPIPROP_GetValue(This
, lpTags
->aulPropTag
[i
]);
2151 item
->ulAccess
= lpAccess
[i
];
2154 IMAPIPROP_Unlock(This
);
2158 /**************************************************************************
2159 * IPropData_HrGetPropAccess {MAPI32}
2161 * Get the access levels for a group of property values in an IPropData object.
2164 * iface [I] IPropData object to get access levels from.
2165 * lppTags [O] Destination for the list of property Id's in iface.
2166 * lppAccess [O] Destination for access level for each property in lppTags.
2169 * Success: S_OK. lppTags and lppAccess contain the property Id's and the
2170 * Access level of each property value in iface.
2171 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid, or
2172 * MAPI_E_NOT_ENOUGH_MEMORY if memory allocation fails.
2175 * - *lppTags and *lppAccess should be freed with MAPIFreeBuffer() by the caller.
2177 static HRESULT WINAPI
2178 IPropData_fnHrGetPropAccess(LPPROPDATA iface
, LPSPropTagArray
*lppTags
,
2181 IPropDataImpl
*This
= impl_from_IPropData(iface
);
2186 TRACE("(%p,%p,%p) stub\n", iface
, lppTags
, lppAccess
);
2188 if (!iface
|| !lppTags
|| !lppAccess
)
2189 return MAPI_E_INVALID_PARAMETER
;
2194 IMAPIPROP_Lock(This
);
2196 hRet
= This
->lpAlloc(CbNewSPropTagArray(This
->ulNumValues
), &lpMem
);
2197 if (SUCCEEDED(hRet
))
2201 hRet
= This
->lpAlloc(This
->ulNumValues
* sizeof(ULONG
), &lpMem
);
2202 if (SUCCEEDED(hRet
))
2204 struct list
*cursor
;
2207 (*lppTags
)->cValues
= This
->ulNumValues
;
2210 LIST_FOR_EACH(cursor
, &This
->values
)
2212 LPIPropDataItem item
= LIST_ENTRY(cursor
, IPropDataItem
, entry
);
2213 (*lppTags
)->aulPropTag
[i
] = item
->value
->ulPropTag
;
2214 (*lppAccess
)[i
] = item
->ulAccess
;
2217 IMAPIPROP_Unlock(This
);
2220 This
->lpFree(*lppTags
);
2223 IMAPIPROP_Unlock(This
);
2224 return MAPI_E_NOT_ENOUGH_MEMORY
;
2227 /**************************************************************************
2228 * IPropData_HrAddObjProps {MAPI32}
2230 * Not documented at this time.
2233 * An HRESULT success/failure code.
2235 static HRESULT WINAPI
2236 IPropData_fnHrAddObjProps(LPPROPDATA iface
, LPSPropTagArray lpTags
,
2237 LPSPropProblemArray
*lppProbs
)
2242 LPSPropValue lpValues
;
2245 FIXME("(%p,%p,%p) stub\n", iface
, lpTags
, lppProbs
);
2247 if (!iface
|| !lpTags
)
2248 return MAPI_E_INVALID_PARAMETER
;
2250 /* FIXME: Below is the obvious implementation, adding all the properties
2251 * in lpTags to the object. However, it doesn't appear that this
2252 * is what this function does.
2256 if (!lpTags
->cValues
)
2259 lpValues
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2260 lpTags
->cValues
* sizeof(SPropValue
));
2262 return MAPI_E_NOT_ENOUGH_MEMORY
;
2264 for (i
= 0; i
< lpTags
->cValues
; i
++)
2265 lpValues
[i
].ulPropTag
= lpTags
->aulPropTag
[i
];
2267 hRet
= IPropData_SetProps(iface
, lpTags
->cValues
, lpValues
, lppProbs
);
2268 HeapFree(GetProcessHeap(), 0, lpValues
);
2273 static const IPropDataVtbl IPropDataImpl_vtbl
=
2275 IPropData_fnQueryInterface
,
2277 IPropData_fnRelease
,
2278 IPropData_fnGetLastError
,
2279 IPropData_fnSaveChanges
,
2280 IPropData_fnGetProps
,
2281 IPropData_fnGetPropList
,
2282 IPropData_fnOpenProperty
,
2283 IPropData_fnSetProps
,
2284 IPropData_fnDeleteProps
,
2286 IPropData_fnCopyProps
,
2287 IPropData_fnGetNamesFromIDs
,
2288 IPropData_fnGetIDsFromNames
,
2289 IPropData_fnHrSetObjAccess
,
2290 IPropData_fnHrSetPropAccess
,
2291 IPropData_fnHrGetPropAccess
,
2292 IPropData_fnHrAddObjProps
2295 /*************************************************************************
2296 * CreateIProp@24 (MAPI32.60)
2298 * Create an IPropData object.
2301 * iid [I] GUID of the object to create. Use &IID_IMAPIPropData or NULL
2302 * lpAlloc [I] Memory allocation function. Use MAPIAllocateBuffer()
2303 * lpMore [I] Linked memory allocation function. Use MAPIAllocateMore()
2304 * lpFree [I] Memory free function. Use MAPIFreeBuffer()
2305 * lpReserved [I] Reserved, set to NULL
2306 * lppPropData [O] Destination for created IPropData object
2309 * Success: S_OK. *lppPropData contains the newly created object.
2310 * Failure: MAPI_E_INTERFACE_NOT_SUPPORTED, if iid is non-NULL and not supported,
2311 * MAPI_E_INVALID_PARAMETER, if any parameter is invalid
2313 SCODE WINAPI
CreateIProp(LPCIID iid
, ALLOCATEBUFFER
*lpAlloc
,
2314 ALLOCATEMORE
*lpMore
, FREEBUFFER
*lpFree
,
2315 LPVOID lpReserved
, LPPROPDATA
*lppPropData
)
2317 IPropDataImpl
*lpPropData
;
2320 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_guid(iid
), lpAlloc
, lpMore
, lpFree
,
2321 lpReserved
, lppPropData
);
2324 *lppPropData
= NULL
;
2326 if (iid
&& !IsEqualGUID(iid
, &IID_IMAPIPropData
))
2327 return MAPI_E_INTERFACE_NOT_SUPPORTED
;
2329 if (!lpAlloc
|| !lpMore
|| !lpFree
|| lpReserved
|| !lppPropData
)
2330 return MAPI_E_INVALID_PARAMETER
;
2332 scode
= lpAlloc(sizeof(IPropDataImpl
), (LPVOID
*)&lpPropData
);
2334 if (SUCCEEDED(scode
))
2336 lpPropData
->IPropData_iface
.lpVtbl
= &IPropDataImpl_vtbl
;
2337 lpPropData
->lRef
= 1;
2338 lpPropData
->lpAlloc
= lpAlloc
;
2339 lpPropData
->lpMore
= lpMore
;
2340 lpPropData
->lpFree
= lpFree
;
2341 lpPropData
->ulObjAccess
= IPROP_READWRITE
;
2342 lpPropData
->ulNumValues
= 0;
2343 list_init(&lpPropData
->values
);
2344 InitializeCriticalSection(&lpPropData
->cs
);
2345 lpPropData
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IPropDataImpl.cs");
2346 *lppPropData
= &lpPropData
->IPropData_iface
;