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
24 #include <wine/list.h>
26 BOOL WINAPI
FBadRglpszA(LPSTR
*,ULONG
);
28 /* Internal: Check if a property value array is invalid */
29 static inline ULONG
PROP_BadArray(LPSPropValue lpProp
, size_t elemSize
)
31 return IsBadReadPtr(lpProp
->Value
.MVi
.lpi
, lpProp
->Value
.MVi
.cValues
* elemSize
);
34 /*************************************************************************
35 * PropCopyMore@16 (MAPI32.76)
37 * Copy a property value.
40 * lpDest [O] Destination for the copied value
41 * lpSrc [I] Property value to copy to lpDest
42 * lpMore [I] Linked memory allocation function (pass MAPIAllocateMore())
43 * lpOrig [I] Original allocation to which memory will be linked
46 * Success: S_OK. lpDest contains a deep copy of lpSrc.
47 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
48 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
51 * Any elements within the property returned should not be individually
52 * freed, as they will be freed when lpOrig is.
54 SCODE WINAPI
PropCopyMore(LPSPropValue lpDest
, LPSPropValue lpSrc
,
55 ALLOCATEMORE
*lpMore
, LPVOID lpOrig
)
60 TRACE("(%p,%p,%p,%p)\n", lpDest
, lpSrc
, lpMore
, lpOrig
);
62 if (!lpDest
|| IsBadWritePtr(lpDest
, sizeof(SPropValue
)) ||
63 FBadProp(lpSrc
) || !lpMore
)
64 return MAPI_E_INVALID_PARAMETER
;
66 /* Shallow copy first, this is sufficient for properties without pointers */
69 switch (PROP_TYPE(lpSrc
->ulPropTag
))
72 scode
= lpMore(sizeof(GUID
), lpOrig
, (LPVOID
*)&lpDest
->Value
.lpguid
);
74 *lpDest
->Value
.lpguid
= *lpSrc
->Value
.lpguid
;
77 ulLen
= lstrlenA(lpSrc
->Value
.lpszA
) + 1u;
78 scode
= lpMore(ulLen
, lpOrig
, (LPVOID
*)&lpDest
->Value
.lpszA
);
80 memcpy(lpDest
->Value
.lpszA
, lpSrc
->Value
.lpszA
, ulLen
);
83 ulLen
= (strlenW(lpSrc
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
84 scode
= lpMore(ulLen
, lpOrig
, (LPVOID
*)&lpDest
->Value
.lpszW
);
86 memcpy(lpDest
->Value
.lpszW
, lpSrc
->Value
.lpszW
, ulLen
);
89 scode
= lpMore(lpSrc
->Value
.bin
.cb
, lpOrig
, (LPVOID
*)&lpDest
->Value
.bin
.lpb
);
91 memcpy(lpDest
->Value
.bin
.lpb
, lpSrc
->Value
.bin
.lpb
, lpSrc
->Value
.bin
.cb
);
94 if (lpSrc
->ulPropTag
& MV_FLAG
)
96 ulLen
= UlPropSize(lpSrc
);
98 if (PROP_TYPE(lpSrc
->ulPropTag
) == PT_MV_STRING8
||
99 PROP_TYPE(lpSrc
->ulPropTag
) == PT_MV_UNICODE
)
101 /* UlPropSize doesn't account for the string pointers */
102 ulLen
+= lpSrc
->Value
.MVszA
.cValues
* sizeof(char*);
104 else if (PROP_TYPE(lpSrc
->ulPropTag
) == PT_MV_BINARY
)
106 /* UlPropSize doesn't account for the SBinary structs */
107 ulLen
+= lpSrc
->Value
.MVbin
.cValues
* sizeof(SBinary
);
110 lpDest
->Value
.MVi
.cValues
= lpSrc
->Value
.MVi
.cValues
;
111 scode
= lpMore(ulLen
, lpOrig
, (LPVOID
*)&lpDest
->Value
.MVi
.lpi
);
115 /* Note that we could allocate the memory for each value in a
116 * multi-value property separately, however if an allocation failed
117 * we would be left with a bunch of allocated memory, which (while
118 * not really leaked) is unusable until lpOrig is freed. So for
119 * strings and binary arrays we make a single allocation for all
120 * of the data. This is consistent since individual elements can't
124 switch (PROP_TYPE(lpSrc
->ulPropTag
))
128 char *lpNextStr
= (char*)(lpDest
->Value
.MVszA
.lppszA
+
129 lpDest
->Value
.MVszA
.cValues
);
131 for (i
= 0; i
< lpSrc
->Value
.MVszA
.cValues
; i
++)
133 ULONG ulStrLen
= lstrlenA(lpSrc
->Value
.MVszA
.lppszA
[i
]) + 1u;
135 lpDest
->Value
.MVszA
.lppszA
[i
] = lpNextStr
;
136 memcpy(lpNextStr
, lpSrc
->Value
.MVszA
.lppszA
[i
], ulStrLen
);
137 lpNextStr
+= ulStrLen
;
143 WCHAR
*lpNextStr
= (WCHAR
*)(lpDest
->Value
.MVszW
.lppszW
+
144 lpDest
->Value
.MVszW
.cValues
);
146 for (i
= 0; i
< lpSrc
->Value
.MVszW
.cValues
; i
++)
148 ULONG ulStrLen
= strlenW(lpSrc
->Value
.MVszW
.lppszW
[i
]) + 1u;
150 lpDest
->Value
.MVszW
.lppszW
[i
] = lpNextStr
;
151 memcpy(lpNextStr
, lpSrc
->Value
.MVszW
.lppszW
[i
], ulStrLen
* sizeof(WCHAR
));
152 lpNextStr
+= ulStrLen
;
158 LPBYTE lpNext
= (LPBYTE
)(lpDest
->Value
.MVbin
.lpbin
+
159 lpDest
->Value
.MVbin
.cValues
);
161 for (i
= 0; i
< lpSrc
->Value
.MVszW
.cValues
; i
++)
163 lpDest
->Value
.MVbin
.lpbin
[i
].cb
= lpSrc
->Value
.MVbin
.lpbin
[i
].cb
;
164 lpDest
->Value
.MVbin
.lpbin
[i
].lpb
= lpNext
;
165 memcpy(lpNext
, lpSrc
->Value
.MVbin
.lpbin
[i
].lpb
, lpDest
->Value
.MVbin
.lpbin
[i
].cb
);
166 lpNext
+= lpDest
->Value
.MVbin
.lpbin
[i
].cb
;
171 /* No embedded pointers, just copy the data over */
172 memcpy(lpDest
->Value
.MVi
.lpi
, lpSrc
->Value
.MVi
.lpi
, ulLen
);
181 /*************************************************************************
182 * UlPropSize@4 (MAPI32.77)
184 * Determine the size of a property in bytes.
187 * lpProp [I] Property to determine the size of
190 * Success: The size of the value in lpProp.
191 * Failure: 0, if a multi-value (array) property is invalid or the type of lpProp
195 * - The size returned does not include the size of the SPropValue struct
196 * or the size of the array of pointers for multi-valued properties that
197 * contain pointers (such as PT_MV_STRING8 or PT-MV_UNICODE).
198 * - MSDN incorrectly states that this function returns MAPI_E_CALL_FAILED if
199 * lpProp is invalid. In reality no checking is performed and this function
200 * will crash if passed an invalid property, or return 0 if the property
201 * type is PT_OBJECT or is unknown.
203 ULONG WINAPI
UlPropSize(LPSPropValue lpProp
)
207 TRACE("(%p)\n", lpProp
);
209 switch (PROP_TYPE(lpProp
->ulPropTag
))
211 case PT_MV_I2
: ulRet
= lpProp
->Value
.MVi
.cValues
;
214 case PT_I2
: ulRet
*= sizeof(USHORT
);
216 case PT_MV_I4
: ulRet
= lpProp
->Value
.MVl
.cValues
;
219 case PT_I4
: ulRet
*= sizeof(LONG
);
221 case PT_MV_I8
: ulRet
= lpProp
->Value
.MVli
.cValues
;
223 case PT_I8
: ulRet
*= sizeof(LONG64
);
225 case PT_MV_R4
: ulRet
= lpProp
->Value
.MVflt
.cValues
;
227 case PT_R4
: ulRet
*= sizeof(float);
230 case PT_MV_R8
: ulRet
= lpProp
->Value
.MVdbl
.cValues
;
233 case PT_R8
: ulRet
*= sizeof(double);
235 case PT_MV_CURRENCY
: ulRet
= lpProp
->Value
.MVcur
.cValues
;
237 case PT_CURRENCY
: ulRet
*= sizeof(CY
);
239 case PT_MV_SYSTIME
: ulRet
= lpProp
->Value
.MVft
.cValues
;
241 case PT_SYSTIME
: ulRet
*= sizeof(FILETIME
);
243 case PT_MV_CLSID
: ulRet
= lpProp
->Value
.MVguid
.cValues
;
245 case PT_CLSID
: ulRet
*= sizeof(GUID
);
247 case PT_MV_STRING8
: ulRet
= 0u;
248 for (i
= 0; i
< lpProp
->Value
.MVszA
.cValues
; i
++)
249 ulRet
+= (lstrlenA(lpProp
->Value
.MVszA
.lppszA
[i
]) + 1u);
251 case PT_STRING8
: ulRet
= lstrlenA(lpProp
->Value
.lpszA
) + 1u;
253 case PT_MV_UNICODE
: ulRet
= 0u;
254 for (i
= 0; i
< lpProp
->Value
.MVszW
.cValues
; i
++)
255 ulRet
+= (strlenW(lpProp
->Value
.MVszW
.lppszW
[i
]) + 1u);
256 ulRet
*= sizeof(WCHAR
);
258 case PT_UNICODE
: ulRet
= (lstrlenW(lpProp
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
260 case PT_MV_BINARY
: ulRet
= 0u;
261 for (i
= 0; i
< lpProp
->Value
.MVbin
.cValues
; i
++)
262 ulRet
+= lpProp
->Value
.MVbin
.lpbin
[i
].cb
;
264 case PT_BINARY
: ulRet
= lpProp
->Value
.bin
.cb
;
274 /*************************************************************************
275 * FPropContainsProp@12 (MAPI32.78)
277 * Find a property with a given property tag in a property array.
280 * lpHaystack [I] Property to match to
281 * lpNeedle [I] Property to find in lpHaystack
282 * ulFuzzy [I] Flags controlling match type and strictness (FL_* flags from "mapidefs.h")
285 * TRUE, if lpNeedle matches lpHaystack according to the criteria of ulFuzzy.
288 * Only property types of PT_STRING8 and PT_BINARY are handled by this function.
290 BOOL WINAPI
FPropContainsProp(LPSPropValue lpHaystack
, LPSPropValue lpNeedle
, ULONG ulFuzzy
)
292 TRACE("(%p,%p,0x%08x)\n", lpHaystack
, lpNeedle
, ulFuzzy
);
294 if (FBadProp(lpHaystack
) || FBadProp(lpNeedle
) ||
295 PROP_TYPE(lpHaystack
->ulPropTag
) != PROP_TYPE(lpNeedle
->ulPropTag
))
298 /* FIXME: Do later versions support Unicode as well? */
300 if (PROP_TYPE(lpHaystack
->ulPropTag
) == PT_STRING8
)
302 DWORD dwFlags
= 0, dwNeedleLen
, dwHaystackLen
;
304 if (ulFuzzy
& FL_IGNORECASE
)
305 dwFlags
|= NORM_IGNORECASE
;
306 if (ulFuzzy
& FL_IGNORENONSPACE
)
307 dwFlags
|= NORM_IGNORENONSPACE
;
308 if (ulFuzzy
& FL_LOOSE
)
309 dwFlags
|= (NORM_IGNORECASE
|NORM_IGNORENONSPACE
|NORM_IGNORESYMBOLS
);
311 dwNeedleLen
= lstrlenA(lpNeedle
->Value
.lpszA
);
312 dwHaystackLen
= lstrlenA(lpHaystack
->Value
.lpszA
);
314 if ((ulFuzzy
& (FL_SUBSTRING
|FL_PREFIX
)) == FL_PREFIX
)
316 if (dwNeedleLen
<= dwHaystackLen
&&
317 CompareStringA(LOCALE_USER_DEFAULT
, dwFlags
,
318 lpHaystack
->Value
.lpszA
, dwNeedleLen
,
319 lpNeedle
->Value
.lpszA
, dwNeedleLen
) == CSTR_EQUAL
)
320 return TRUE
; /* needle is a prefix of haystack */
322 else if ((ulFuzzy
& (FL_SUBSTRING
|FL_PREFIX
)) == FL_SUBSTRING
)
324 LPSTR (WINAPI
*pStrChrFn
)(LPCSTR
,WORD
) = StrChrA
;
325 LPSTR lpStr
= lpHaystack
->Value
.lpszA
;
327 if (dwFlags
& NORM_IGNORECASE
)
328 pStrChrFn
= StrChrIA
;
330 while ((lpStr
= pStrChrFn(lpStr
, *lpNeedle
->Value
.lpszA
)) != NULL
)
332 dwHaystackLen
-= (lpStr
- lpHaystack
->Value
.lpszA
);
333 if (dwNeedleLen
<= dwHaystackLen
&&
334 CompareStringA(LOCALE_USER_DEFAULT
, dwFlags
,
336 lpNeedle
->Value
.lpszA
, dwNeedleLen
) == CSTR_EQUAL
)
337 return TRUE
; /* needle is a substring of haystack */
341 else if (CompareStringA(LOCALE_USER_DEFAULT
, dwFlags
,
342 lpHaystack
->Value
.lpszA
, dwHaystackLen
,
343 lpNeedle
->Value
.lpszA
, dwNeedleLen
) == CSTR_EQUAL
)
344 return TRUE
; /* full string match */
346 else if (PROP_TYPE(lpHaystack
->ulPropTag
) == PT_BINARY
)
348 if ((ulFuzzy
& (FL_SUBSTRING
|FL_PREFIX
)) == FL_PREFIX
)
350 if (lpNeedle
->Value
.bin
.cb
<= lpHaystack
->Value
.bin
.cb
&&
351 !memcmp(lpNeedle
->Value
.bin
.lpb
, lpHaystack
->Value
.bin
.lpb
,
352 lpNeedle
->Value
.bin
.cb
))
353 return TRUE
; /* needle is a prefix of haystack */
355 else if ((ulFuzzy
& (FL_SUBSTRING
|FL_PREFIX
)) == FL_SUBSTRING
)
357 ULONG ulLen
= lpHaystack
->Value
.bin
.cb
;
358 LPBYTE lpb
= lpHaystack
->Value
.bin
.lpb
;
360 while ((lpb
= memchr(lpb
, *lpNeedle
->Value
.bin
.lpb
, ulLen
)) != NULL
)
362 ulLen
= lpHaystack
->Value
.bin
.cb
- (lpb
- lpHaystack
->Value
.bin
.lpb
);
363 if (lpNeedle
->Value
.bin
.cb
<= ulLen
&&
364 !memcmp(lpNeedle
->Value
.bin
.lpb
, lpb
, lpNeedle
->Value
.bin
.cb
))
365 return TRUE
; /* needle is a substring of haystack */
369 else if (!LPropCompareProp(lpHaystack
, lpNeedle
))
370 return TRUE
; /* needle is an exact match with haystack */
376 /*************************************************************************
377 * FPropCompareProp@12 (MAPI32.79)
379 * Compare two properties.
382 * lpPropLeft [I] Left hand property to compare to lpPropRight
383 * ulOp [I] Comparison operator (RELOP_* enum from "mapidefs.h")
384 * lpPropRight [I] Right hand property to compare to lpPropLeft
387 * TRUE, if the comparison is true, FALSE otherwise.
389 BOOL WINAPI
FPropCompareProp(LPSPropValue lpPropLeft
, ULONG ulOp
, LPSPropValue lpPropRight
)
393 TRACE("(%p,%d,%p)\n", lpPropLeft
, ulOp
, lpPropRight
);
395 if (ulOp
> RELOP_RE
|| FBadProp(lpPropLeft
) || FBadProp(lpPropRight
))
398 if (ulOp
== RELOP_RE
)
400 FIXME("Comparison operator RELOP_RE not yet implemented!\n");
404 iCmp
= LPropCompareProp(lpPropLeft
, lpPropRight
);
408 case RELOP_LT
: return iCmp
< 0;
409 case RELOP_LE
: return iCmp
<= 0;
410 case RELOP_GT
: return iCmp
> 0;
411 case RELOP_GE
: return iCmp
>= 0;
412 case RELOP_EQ
: return iCmp
== 0;
413 case RELOP_NE
: return iCmp
!= 0;
418 /*************************************************************************
419 * LPropCompareProp@8 (MAPI32.80)
421 * Compare two properties.
424 * lpPropLeft [I] Left hand property to compare to lpPropRight
425 * lpPropRight [I] Right hand property to compare to lpPropLeft
428 * An integer less than, equal to or greater than 0, indicating that
429 * lpszStr is less than, the same, or greater than lpszComp.
431 LONG WINAPI
LPropCompareProp(LPSPropValue lpPropLeft
, LPSPropValue lpPropRight
)
435 TRACE("(%p->0x%08x,%p->0x%08x)\n", lpPropLeft
, lpPropLeft
->ulPropTag
,
436 lpPropRight
, lpPropRight
->ulPropTag
);
438 /* If the properties are not the same, sort by property type */
439 if (PROP_TYPE(lpPropLeft
->ulPropTag
) != PROP_TYPE(lpPropRight
->ulPropTag
))
440 return (LONG
)PROP_TYPE(lpPropLeft
->ulPropTag
) - (LONG
)PROP_TYPE(lpPropRight
->ulPropTag
);
442 switch (PROP_TYPE(lpPropLeft
->ulPropTag
))
446 return 0; /* NULLs are equal */
448 return lpPropLeft
->Value
.i
- lpPropRight
->Value
.i
;
450 return lpPropLeft
->Value
.l
- lpPropRight
->Value
.l
;
452 if (lpPropLeft
->Value
.li
.QuadPart
> lpPropRight
->Value
.li
.QuadPart
)
454 if (lpPropLeft
->Value
.li
.QuadPart
== lpPropRight
->Value
.li
.QuadPart
)
458 if (lpPropLeft
->Value
.flt
> lpPropRight
->Value
.flt
)
460 if (lpPropLeft
->Value
.flt
== lpPropRight
->Value
.flt
)
465 if (lpPropLeft
->Value
.dbl
> lpPropRight
->Value
.dbl
)
467 if (lpPropLeft
->Value
.dbl
== lpPropRight
->Value
.dbl
)
471 if (lpPropLeft
->Value
.cur
.int64
> lpPropRight
->Value
.cur
.int64
)
473 if (lpPropLeft
->Value
.cur
.int64
== lpPropRight
->Value
.cur
.int64
)
477 return CompareFileTime(&lpPropLeft
->Value
.ft
, &lpPropRight
->Value
.ft
);
479 return (lpPropLeft
->Value
.b
? 1 : 0) - (lpPropRight
->Value
.b
? 1 : 0);
481 if (lpPropLeft
->Value
.bin
.cb
== lpPropRight
->Value
.bin
.cb
)
482 iRet
= memcmp(lpPropLeft
->Value
.bin
.lpb
, lpPropRight
->Value
.bin
.lpb
,
483 lpPropLeft
->Value
.bin
.cb
);
486 iRet
= memcmp(lpPropLeft
->Value
.bin
.lpb
, lpPropRight
->Value
.bin
.lpb
,
487 min(lpPropLeft
->Value
.bin
.cb
, lpPropRight
->Value
.bin
.cb
));
490 iRet
= lpPropLeft
->Value
.bin
.cb
- lpPropRight
->Value
.bin
.cb
;
494 return lstrcmpA(lpPropLeft
->Value
.lpszA
, lpPropRight
->Value
.lpszA
);
496 return strcmpW(lpPropLeft
->Value
.lpszW
, lpPropRight
->Value
.lpszW
);
498 if (lpPropLeft
->Value
.err
> lpPropRight
->Value
.err
)
500 if (lpPropLeft
->Value
.err
== lpPropRight
->Value
.err
)
504 return memcmp(lpPropLeft
->Value
.lpguid
, lpPropRight
->Value
.lpguid
,
507 FIXME("Unhandled property type %d\n", PROP_TYPE(lpPropLeft
->ulPropTag
));
511 /*************************************************************************
512 * HrGetOneProp@8 (MAPI32.135)
514 * Get a property value from an IMAPIProp object.
517 * lpIProp [I] IMAPIProp object to get the property value in
518 * ulPropTag [I] Property tag of the property to get
519 * lppProp [O] Destination for the returned property
522 * Success: S_OK. *lppProp contains the property value requested.
523 * Failure: MAPI_E_NOT_FOUND, if no property value has the tag given by ulPropTag.
525 HRESULT WINAPI
HrGetOneProp(LPMAPIPROP lpIProp
, ULONG ulPropTag
, LPSPropValue
*lppProp
)
531 TRACE("(%p,%d,%p)\n", lpIProp
, ulPropTag
, lppProp
);
534 pta
.aulPropTag
[0] = ulPropTag
;
535 hRet
= IMAPIProp_GetProps(lpIProp
, &pta
, 0u, &ulCount
, lppProp
);
536 if (hRet
== MAPI_W_ERRORS_RETURNED
)
538 MAPIFreeBuffer(*lppProp
);
540 hRet
= MAPI_E_NOT_FOUND
;
545 /*************************************************************************
546 * HrSetOneProp@8 (MAPI32.136)
548 * Set a property value in an IMAPIProp object.
551 * lpIProp [I] IMAPIProp object to set the property value in
552 * lpProp [I] Property value to set
555 * Success: S_OK. The value in lpProp is set in lpIProp.
556 * Failure: An error result from IMAPIProp_SetProps().
558 HRESULT WINAPI
HrSetOneProp(LPMAPIPROP lpIProp
, LPSPropValue lpProp
)
560 TRACE("(%p,%p)\n", lpIProp
, lpProp
);
562 return IMAPIProp_SetProps(lpIProp
, 1u, lpProp
, NULL
);
565 /*************************************************************************
566 * FPropExists@8 (MAPI32.137)
568 * Find a property with a given property tag in an IMAPIProp object.
571 * lpIProp [I] IMAPIProp object to find the property tag in
572 * ulPropTag [I] Property tag to find
575 * TRUE, if ulPropTag matches a property held in lpIProp,
579 * if ulPropTag has a property type of PT_UNSPECIFIED, then only the property
580 * Ids need to match for a successful match to occur.
582 BOOL WINAPI
FPropExists(LPMAPIPROP lpIProp
, ULONG ulPropTag
)
586 TRACE("(%p,%d)\n", lpIProp
, ulPropTag
);
590 LPSPropTagArray lpTags
;
593 if (FAILED(IMAPIProp_GetPropList(lpIProp
, 0u, &lpTags
)))
596 for (i
= 0; i
< lpTags
->cValues
; i
++)
598 if (!FBadPropTag(lpTags
->aulPropTag
[i
]) &&
599 (lpTags
->aulPropTag
[i
] == ulPropTag
||
600 (PROP_TYPE(ulPropTag
) == PT_UNSPECIFIED
&&
601 PROP_ID(lpTags
->aulPropTag
[i
]) == lpTags
->aulPropTag
[i
])))
607 MAPIFreeBuffer(lpTags
);
612 /*************************************************************************
613 * PpropFindProp@12 (MAPI32.138)
615 * Find a property with a given property tag in a property array.
618 * lpProps [I] Property array to search
619 * cValues [I] Number of properties in lpProps
620 * ulPropTag [I] Property tag to find
623 * A pointer to the matching property, or NULL if none was found.
626 * if ulPropTag has a property type of PT_UNSPECIFIED, then only the property
627 * Ids need to match for a successful match to occur.
629 LPSPropValue WINAPI
PpropFindProp(LPSPropValue lpProps
, ULONG cValues
, ULONG ulPropTag
)
631 TRACE("(%p,%d,%d)\n", lpProps
, cValues
, ulPropTag
);
633 if (lpProps
&& cValues
)
636 for (i
= 0; i
< cValues
; i
++)
638 if (!FBadPropTag(lpProps
[i
].ulPropTag
) &&
639 (lpProps
[i
].ulPropTag
== ulPropTag
||
640 (PROP_TYPE(ulPropTag
) == PT_UNSPECIFIED
&&
641 PROP_ID(lpProps
[i
].ulPropTag
) == PROP_ID(ulPropTag
))))
648 /*************************************************************************
649 * FreePadrlist@4 (MAPI32.139)
651 * Free the memory used by an address book list.
654 * lpAddrs [I] Address book list to free
659 VOID WINAPI
FreePadrlist(LPADRLIST lpAddrs
)
661 TRACE("(%p)\n", lpAddrs
);
663 /* Structures are binary compatible; use the same implementation */
664 FreeProws((LPSRowSet
)lpAddrs
);
667 /*************************************************************************
668 * FreeProws@4 (MAPI32.140)
670 * Free the memory used by a row set.
673 * lpRowSet [I] Row set to free
678 VOID WINAPI
FreeProws(LPSRowSet lpRowSet
)
680 TRACE("(%p)\n", lpRowSet
);
686 for (i
= 0; i
< lpRowSet
->cRows
; i
++)
687 MAPIFreeBuffer(lpRowSet
->aRow
[i
].lpProps
);
689 MAPIFreeBuffer(lpRowSet
);
693 /*************************************************************************
694 * ScCountProps@12 (MAPI32.170)
696 * Validate and determine the length of an array of properties.
699 * iCount [I] Length of the lpProps array
700 * lpProps [I] Array of properties to validate/size
701 * pcBytes [O] If non-NULL, destination for the size of the property array
704 * Success: S_OK. If pcBytes is non-NULL, it contains the size of the
706 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid or validation
707 * of the property array fails.
709 SCODE WINAPI
ScCountProps(INT iCount
, LPSPropValue lpProps
, ULONG
*pcBytes
)
711 ULONG i
, ulCount
= iCount
, ulBytes
= 0;
713 TRACE("(%d,%p,%p)\n", iCount
, lpProps
, pcBytes
);
715 if (iCount
<= 0 || !lpProps
||
716 IsBadReadPtr(lpProps
, iCount
* sizeof(SPropValue
)))
717 return MAPI_E_INVALID_PARAMETER
;
719 for (i
= 0; i
< ulCount
; i
++)
721 ULONG ulPropSize
= 0;
723 if (FBadProp(&lpProps
[i
]) || lpProps
[i
].ulPropTag
== PROP_ID_NULL
||
724 lpProps
[i
].ulPropTag
== PROP_ID_INVALID
)
725 return MAPI_E_INVALID_PARAMETER
;
727 if (PROP_TYPE(lpProps
[i
].ulPropTag
) != PT_OBJECT
)
729 ulPropSize
= UlPropSize(&lpProps
[i
]);
731 return MAPI_E_INVALID_PARAMETER
;
734 switch (PROP_TYPE(lpProps
[i
].ulPropTag
))
748 ulPropSize
+= sizeof(SPropValue
);
751 ulPropSize
+= lpProps
[i
].Value
.MVszA
.cValues
* sizeof(char*) + sizeof(SPropValue
);
755 ulPropSize
+= lpProps
[i
].Value
.MVszA
.cValues
* sizeof(char*) + sizeof(SPropValue
);
758 ulPropSize
+= lpProps
[i
].Value
.MVbin
.cValues
* sizeof(SBinary
) + sizeof(SPropValue
);
761 ulPropSize
= sizeof(SPropValue
);
764 ulBytes
+= ulPropSize
;
772 /*************************************************************************
773 * ScCopyProps@16 (MAPI32.171)
775 * Copy an array of property values into a buffer suited for serialisation.
778 * cValues [I] Number of properties in lpProps
779 * lpProps [I] Property array to copy
780 * lpDst [O] Destination for the serialised data
781 * lpCount [O] If non-NULL, destination for the number of bytes of data written to lpDst
784 * Success: S_OK. lpDst contains the serialised data from lpProps.
785 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
788 * The resulting property value array is stored in a contiguous block starting at lpDst.
790 SCODE WINAPI
ScCopyProps(int cValues
, LPSPropValue lpProps
, LPVOID lpDst
, ULONG
*lpCount
)
792 LPSPropValue lpDest
= (LPSPropValue
)lpDst
;
793 char *lpDataDest
= (char *)(lpDest
+ cValues
);
797 TRACE("(%d,%p,%p,%p)\n", cValues
, lpProps
, lpDst
, lpCount
);
799 if (!lpProps
|| cValues
< 0 || !lpDest
)
800 return MAPI_E_INVALID_PARAMETER
;
802 memcpy(lpDst
, lpProps
, cValues
* sizeof(SPropValue
));
804 for (iter
= 0; iter
< cValues
; iter
++)
806 switch (PROP_TYPE(lpProps
->ulPropTag
))
809 lpDest
->Value
.lpguid
= (LPGUID
)lpDataDest
;
810 *lpDest
->Value
.lpguid
= *lpProps
->Value
.lpguid
;
811 lpDataDest
+= sizeof(GUID
);
814 ulLen
= lstrlenA(lpProps
->Value
.lpszA
) + 1u;
815 lpDest
->Value
.lpszA
= lpDataDest
;
816 memcpy(lpDest
->Value
.lpszA
, lpProps
->Value
.lpszA
, ulLen
);
820 ulLen
= (strlenW(lpProps
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
821 lpDest
->Value
.lpszW
= (LPWSTR
)lpDataDest
;
822 memcpy(lpDest
->Value
.lpszW
, lpProps
->Value
.lpszW
, ulLen
);
826 lpDest
->Value
.bin
.lpb
= (LPBYTE
)lpDataDest
;
827 memcpy(lpDest
->Value
.bin
.lpb
, lpProps
->Value
.bin
.lpb
, lpProps
->Value
.bin
.cb
);
828 lpDataDest
+= lpProps
->Value
.bin
.cb
;
831 if (lpProps
->ulPropTag
& MV_FLAG
)
833 lpDest
->Value
.MVi
.cValues
= lpProps
->Value
.MVi
.cValues
;
834 /* Note: Assignment uses lppszA but covers all cases by union aliasing */
835 lpDest
->Value
.MVszA
.lppszA
= (char**)lpDataDest
;
837 switch (PROP_TYPE(lpProps
->ulPropTag
))
841 lpDataDest
+= lpProps
->Value
.MVszA
.cValues
* sizeof(char *);
843 for (i
= 0; i
< lpProps
->Value
.MVszA
.cValues
; i
++)
845 ULONG ulStrLen
= lstrlenA(lpProps
->Value
.MVszA
.lppszA
[i
]) + 1u;
847 lpDest
->Value
.MVszA
.lppszA
[i
] = lpDataDest
;
848 memcpy(lpDataDest
, lpProps
->Value
.MVszA
.lppszA
[i
], ulStrLen
);
849 lpDataDest
+= ulStrLen
;
855 lpDataDest
+= lpProps
->Value
.MVszW
.cValues
* sizeof(WCHAR
*);
857 for (i
= 0; i
< lpProps
->Value
.MVszW
.cValues
; i
++)
859 ULONG ulStrLen
= (strlenW(lpProps
->Value
.MVszW
.lppszW
[i
]) + 1u) * sizeof(WCHAR
);
861 lpDest
->Value
.MVszW
.lppszW
[i
] = (LPWSTR
)lpDataDest
;
862 memcpy(lpDataDest
, lpProps
->Value
.MVszW
.lppszW
[i
], ulStrLen
);
863 lpDataDest
+= ulStrLen
;
869 lpDataDest
+= lpProps
->Value
.MVszW
.cValues
* sizeof(SBinary
);
871 for (i
= 0; i
< lpProps
->Value
.MVszW
.cValues
; i
++)
873 lpDest
->Value
.MVbin
.lpbin
[i
].cb
= lpProps
->Value
.MVbin
.lpbin
[i
].cb
;
874 lpDest
->Value
.MVbin
.lpbin
[i
].lpb
= (LPBYTE
)lpDataDest
;
875 memcpy(lpDataDest
, lpProps
->Value
.MVbin
.lpbin
[i
].lpb
, lpDest
->Value
.MVbin
.lpbin
[i
].cb
);
876 lpDataDest
+= lpDest
->Value
.MVbin
.lpbin
[i
].cb
;
881 /* No embedded pointers, just copy the data over */
882 ulLen
= UlPropSize(lpProps
);
883 memcpy(lpDest
->Value
.MVi
.lpi
, lpProps
->Value
.MVi
.lpi
, ulLen
);
894 *lpCount
= lpDataDest
- (char *)lpDst
;
899 /*************************************************************************
900 * ScRelocProps@20 (MAPI32.172)
902 * Relocate the pointers in an array of property values after it has been copied.
905 * cValues [I] Number of properties in lpProps
906 * lpProps [O] Property array to relocate the pointers in.
907 * lpOld [I] Position where the data was copied from
908 * lpNew [I] Position where the data was copied to
909 * lpCount [O] If non-NULL, destination for the number of bytes of data at lpDst
912 * Success: S_OK. Any pointers in lpProps are relocated.
913 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
916 * MSDN states that this function can be used for serialisation by passing
917 * NULL as either lpOld or lpNew, thus converting any pointers in lpProps
918 * between offsets and pointers. This does not work in native (it crashes),
919 * and cannot be made to work in Wine because the original interface design
920 * is deficient. The only use left for this function is to remap pointers
921 * in a contiguous property array that has been copied with memcpy() to
922 * another memory location.
924 SCODE WINAPI
ScRelocProps(int cValues
, LPSPropValue lpProps
, LPVOID lpOld
,
925 LPVOID lpNew
, ULONG
*lpCount
)
927 static const BOOL bBadPtr
= TRUE
; /* Windows bug - Assumes source is bad */
928 LPSPropValue lpDest
= lpProps
;
929 ULONG ulCount
= cValues
* sizeof(SPropValue
);
933 TRACE("(%d,%p,%p,%p,%p)\n", cValues
, lpProps
, lpOld
, lpNew
, lpCount
);
935 if (!lpProps
|| cValues
< 0 || !lpOld
|| !lpNew
)
936 return MAPI_E_INVALID_PARAMETER
;
938 /* The reason native doesn't work as MSDN states is that it assumes that
939 * the lpProps pointer contains valid pointers. This is obviously not
940 * true if the array is being read back from serialisation (the pointers
941 * are just offsets). Native can't actually work converting the pointers to
942 * offsets either, because it converts any array pointers to offsets then
943 * _dereferences the offset_ in order to convert the array elements!
945 * The code below would handle both cases except that the design of this
946 * function makes it impossible to know when the pointers in lpProps are
947 * valid. If both lpOld and lpNew are non-NULL, native reads the pointers
948 * after converting them, so we must do the same. It seems this
949 * functionality was never tested by MS.
952 #define RELOC_PTR(p) (((char*)(p)) - (char*)lpOld + (char*)lpNew)
954 for (iter
= 0; iter
< cValues
; iter
++)
956 switch (PROP_TYPE(lpDest
->ulPropTag
))
959 lpDest
->Value
.lpguid
= (LPGUID
)RELOC_PTR(lpDest
->Value
.lpguid
);
960 ulCount
+= sizeof(GUID
);
963 ulLen
= bBadPtr
? 0 : lstrlenA(lpDest
->Value
.lpszA
) + 1u;
964 lpDest
->Value
.lpszA
= RELOC_PTR(lpDest
->Value
.lpszA
);
966 ulLen
= lstrlenA(lpDest
->Value
.lpszA
) + 1u;
970 ulLen
= bBadPtr
? 0 : (lstrlenW(lpDest
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
971 lpDest
->Value
.lpszW
= (LPWSTR
)RELOC_PTR(lpDest
->Value
.lpszW
);
973 ulLen
= (strlenW(lpDest
->Value
.lpszW
) + 1u) * sizeof(WCHAR
);
977 lpDest
->Value
.bin
.lpb
= (LPBYTE
)RELOC_PTR(lpDest
->Value
.bin
.lpb
);
978 ulCount
+= lpDest
->Value
.bin
.cb
;
981 if (lpDest
->ulPropTag
& MV_FLAG
)
983 /* Since we have to access the array elements, don't map the
984 * array unless it is invalid (otherwise, map it at the end)
987 lpDest
->Value
.MVszA
.lppszA
= (LPSTR
*)RELOC_PTR(lpDest
->Value
.MVszA
.lppszA
);
989 switch (PROP_TYPE(lpProps
->ulPropTag
))
993 ulCount
+= lpDest
->Value
.MVszA
.cValues
* sizeof(char *);
995 for (i
= 0; i
< lpDest
->Value
.MVszA
.cValues
; i
++)
997 ULONG ulStrLen
= bBadPtr
? 0 : lstrlenA(lpDest
->Value
.MVszA
.lppszA
[i
]) + 1u;
999 lpDest
->Value
.MVszA
.lppszA
[i
] = RELOC_PTR(lpDest
->Value
.MVszA
.lppszA
[i
]);
1001 ulStrLen
= lstrlenA(lpDest
->Value
.MVszA
.lppszA
[i
]) + 1u;
1002 ulCount
+= ulStrLen
;
1008 ulCount
+= lpDest
->Value
.MVszW
.cValues
* sizeof(WCHAR
*);
1010 for (i
= 0; i
< lpDest
->Value
.MVszW
.cValues
; i
++)
1012 ULONG ulStrLen
= bBadPtr
? 0 : (strlenW(lpDest
->Value
.MVszW
.lppszW
[i
]) + 1u) * sizeof(WCHAR
);
1014 lpDest
->Value
.MVszW
.lppszW
[i
] = (LPWSTR
)RELOC_PTR(lpDest
->Value
.MVszW
.lppszW
[i
]);
1016 ulStrLen
= (strlenW(lpDest
->Value
.MVszW
.lppszW
[i
]) + 1u) * sizeof(WCHAR
);
1017 ulCount
+= ulStrLen
;
1023 ulCount
+= lpDest
->Value
.MVszW
.cValues
* sizeof(SBinary
);
1025 for (i
= 0; i
< lpDest
->Value
.MVszW
.cValues
; i
++)
1027 lpDest
->Value
.MVbin
.lpbin
[i
].lpb
= (LPBYTE
)RELOC_PTR(lpDest
->Value
.MVbin
.lpbin
[i
].lpb
);
1028 ulCount
+= lpDest
->Value
.MVbin
.lpbin
[i
].cb
;
1033 ulCount
+= UlPropSize(lpDest
);
1037 lpDest
->Value
.MVszA
.lppszA
= (LPSTR
*)RELOC_PTR(lpDest
->Value
.MVszA
.lppszA
);
1049 /*************************************************************************
1050 * LpValFindProp@12 (MAPI32.173)
1052 * Find a property with a given property id in a property array.
1055 * ulPropTag [I] Property tag containing property id to find
1056 * cValues [I] Number of properties in lpProps
1057 * lpProps [I] Property array to search
1060 * A pointer to the matching property, or NULL if none was found.
1063 * This function matches only on the property id and does not care if the
1064 * property types differ.
1066 LPSPropValue WINAPI
LpValFindProp(ULONG ulPropTag
, ULONG cValues
, LPSPropValue lpProps
)
1068 TRACE("(%d,%d,%p)\n", ulPropTag
, cValues
, lpProps
);
1070 if (lpProps
&& cValues
)
1073 for (i
= 0; i
< cValues
; i
++)
1075 if (PROP_ID(ulPropTag
) == PROP_ID(lpProps
[i
].ulPropTag
))
1082 /*************************************************************************
1083 * ScDupPropset@16 (MAPI32.174)
1085 * Duplicate a property value array into a contiguous block of memory.
1088 * cValues [I] Number of properties in lpProps
1089 * lpProps [I] Property array to duplicate
1090 * lpAlloc [I] Memory allocation function, use MAPIAllocateBuffer()
1091 * lpNewProp [O] Destination for the newly duplicated property value array
1094 * Success: S_OK. *lpNewProp contains the duplicated array.
1095 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
1096 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
1098 SCODE WINAPI
ScDupPropset(int cValues
, LPSPropValue lpProps
,
1099 LPALLOCATEBUFFER lpAlloc
, LPSPropValue
*lpNewProp
)
1104 TRACE("(%d,%p,%p,%p)\n", cValues
, lpProps
, lpAlloc
, lpNewProp
);
1106 sc
= ScCountProps(cValues
, lpProps
, &ulCount
);
1109 sc
= lpAlloc(ulCount
, (LPVOID
*)lpNewProp
);
1111 sc
= ScCopyProps(cValues
, lpProps
, *lpNewProp
, &ulCount
);
1116 /*************************************************************************
1117 * FBadRglpszA@8 (MAPI32.175)
1119 * Determine if an array of strings is invalid
1122 * lppszStrs [I] Array of strings to check
1123 * ulCount [I] Number of strings in lppszStrs
1126 * TRUE, if lppszStrs is invalid, FALSE otherwise.
1128 BOOL WINAPI
FBadRglpszA(LPSTR
*lppszStrs
, ULONG ulCount
)
1132 TRACE("(%p,%d)\n", lppszStrs
, ulCount
);
1137 if (!lppszStrs
|| IsBadReadPtr(lppszStrs
, ulCount
* sizeof(LPWSTR
)))
1140 for (i
= 0; i
< ulCount
; i
++)
1142 if (!lppszStrs
[i
] || IsBadStringPtrA(lppszStrs
[i
], -1))
1148 /*************************************************************************
1149 * FBadRglpszW@8 (MAPI32.176)
1153 BOOL WINAPI
FBadRglpszW(LPWSTR
*lppszStrs
, ULONG ulCount
)
1157 TRACE("(%p,%d)\n", lppszStrs
, ulCount
);
1162 if (!lppszStrs
|| IsBadReadPtr(lppszStrs
, ulCount
* sizeof(LPWSTR
)))
1165 for (i
= 0; i
< ulCount
; i
++)
1167 if (!lppszStrs
[i
] || IsBadStringPtrW(lppszStrs
[i
], -1))
1173 /*************************************************************************
1174 * FBadRowSet@4 (MAPI32.177)
1176 * Determine if a row is invalid
1179 * lpRow [I] Row to check
1182 * TRUE, if lpRow is invalid, FALSE otherwise.
1184 BOOL WINAPI
FBadRowSet(LPSRowSet lpRowSet
)
1187 TRACE("(%p)\n", lpRowSet
);
1189 if (!lpRowSet
|| IsBadReadPtr(lpRowSet
, CbSRowSet(lpRowSet
)))
1192 for (i
= 0; i
< lpRowSet
->cRows
; i
++)
1194 if (FBadRow(&lpRowSet
->aRow
[i
]))
1200 /*************************************************************************
1201 * FBadPropTag@4 (MAPI32.179)
1203 * Determine if a property tag is invalid
1206 * ulPropTag [I] Property tag to check
1209 * TRUE, if ulPropTag is invalid, FALSE otherwise.
1211 ULONG WINAPI
FBadPropTag(ULONG ulPropTag
)
1213 TRACE("(0x%08x)\n", ulPropTag
);
1215 switch (ulPropTag
& (~MV_FLAG
& PROP_TYPE_MASK
))
1217 case PT_UNSPECIFIED
:
1239 /*************************************************************************
1240 * FBadRow@4 (MAPI32.180)
1242 * Determine if a row is invalid
1245 * lpRow [I] Row to check
1248 * TRUE, if lpRow is invalid, FALSE otherwise.
1250 ULONG WINAPI
FBadRow(LPSRow lpRow
)
1253 TRACE("(%p)\n", lpRow
);
1255 if (!lpRow
|| IsBadReadPtr(lpRow
, sizeof(SRow
)) || !lpRow
->lpProps
||
1256 IsBadReadPtr(lpRow
->lpProps
, lpRow
->cValues
* sizeof(SPropValue
)))
1259 for (i
= 0; i
< lpRow
->cValues
; i
++)
1261 if (FBadProp(&lpRow
->lpProps
[i
]))
1267 /*************************************************************************
1268 * FBadProp@4 (MAPI32.181)
1270 * Determine if a property is invalid
1273 * lpProp [I] Property to check
1276 * TRUE, if lpProp is invalid, FALSE otherwise.
1278 ULONG WINAPI
FBadProp(LPSPropValue lpProp
)
1280 if (!lpProp
|| IsBadReadPtr(lpProp
, sizeof(SPropValue
)) ||
1281 FBadPropTag(lpProp
->ulPropTag
))
1284 switch (PROP_TYPE(lpProp
->ulPropTag
))
1286 /* Single value properties containing pointers */
1288 if (!lpProp
->Value
.lpszA
|| IsBadStringPtrA(lpProp
->Value
.lpszA
, -1))
1292 if (!lpProp
->Value
.lpszW
|| IsBadStringPtrW(lpProp
->Value
.lpszW
, -1))
1296 if (IsBadReadPtr(lpProp
->Value
.bin
.lpb
, lpProp
->Value
.bin
.cb
))
1300 if (IsBadReadPtr(lpProp
->Value
.lpguid
, sizeof(GUID
)))
1304 /* Multiple value properties (arrays) containing no pointers */
1306 return PROP_BadArray(lpProp
, sizeof(SHORT
));
1308 return PROP_BadArray(lpProp
, sizeof(LONG
));
1309 case PT_MV_LONGLONG
:
1310 return PROP_BadArray(lpProp
, sizeof(LONG64
));
1312 return PROP_BadArray(lpProp
, sizeof(float));
1314 return PROP_BadArray(lpProp
, sizeof(FILETIME
));
1317 return PROP_BadArray(lpProp
, sizeof(double));
1318 case PT_MV_CURRENCY
:
1319 return PROP_BadArray(lpProp
, sizeof(CY
));
1321 return PROP_BadArray(lpProp
, sizeof(GUID
));
1323 /* Multiple value properties containing pointers */
1325 return FBadRglpszA(lpProp
->Value
.MVszA
.lppszA
,
1326 lpProp
->Value
.MVszA
.cValues
);
1328 return FBadRglpszW(lpProp
->Value
.MVszW
.lppszW
,
1329 lpProp
->Value
.MVszW
.cValues
);
1331 return FBadEntryList(&lpProp
->Value
.MVbin
);
1336 /*************************************************************************
1337 * FBadColumnSet@4 (MAPI32.182)
1339 * Determine if an array of property tags is invalid
1342 * lpCols [I] Property tag array to check
1345 * TRUE, if lpCols is invalid, FALSE otherwise.
1347 ULONG WINAPI
FBadColumnSet(LPSPropTagArray lpCols
)
1349 ULONG ulRet
= FALSE
, i
;
1351 TRACE("(%p)\n", lpCols
);
1353 if (!lpCols
|| IsBadReadPtr(lpCols
, CbSPropTagArray(lpCols
)))
1357 for (i
= 0; i
< lpCols
->cValues
; i
++)
1359 if ((lpCols
->aulPropTag
[i
] & PROP_TYPE_MASK
) == PT_ERROR
||
1360 FBadPropTag(lpCols
->aulPropTag
[i
]))
1367 TRACE("Returning %s\n", ulRet
? "TRUE" : "FALSE");
1372 /**************************************************************************
1373 * IPropData {MAPI32}
1375 * A default Mapi interface to provide manipulation of object properties.
1378 * This object provides a default interface suitable in some cases as an
1379 * implementation of the IMAPIProp interface (which has no default
1380 * implementation). In addition to the IMAPIProp() methods inherited, this
1381 * interface allows read/write control over access to the object and its
1382 * individual properties.
1384 * To obtain the default implementation of this interface from Mapi, call
1390 /* A single property in a property data collection */
1394 ULONG ulAccess
; /* The property value access level */
1395 LPSPropValue value
; /* The property value */
1396 } IPropDataItem
, *LPIPropDataItem
;
1398 /* The main property data collection structure */
1401 IPropData IPropData_iface
;
1402 LONG lRef
; /* Reference count */
1403 ALLOCATEBUFFER
*lpAlloc
; /* Memory allocation routine */
1404 ALLOCATEMORE
*lpMore
; /* Linked memory allocation routine */
1405 FREEBUFFER
*lpFree
; /* Memory free routine */
1406 ULONG ulObjAccess
; /* Object access level */
1407 ULONG ulNumValues
; /* Number of items in values list */
1408 struct list values
; /* List of property values */
1409 CRITICAL_SECTION cs
; /* Lock for thread safety */
1412 static inline IPropDataImpl
*impl_from_IPropData(IPropData
*iface
)
1414 return CONTAINING_RECORD(iface
, IPropDataImpl
, IPropData_iface
);
1417 /* Internal - Get a property value, assumes lock is held */
1418 static IPropDataItem
*IMAPIPROP_GetValue(IPropDataImpl
*This
, ULONG ulPropTag
)
1420 struct list
*cursor
;
1422 LIST_FOR_EACH(cursor
, &This
->values
)
1424 LPIPropDataItem current
= LIST_ENTRY(cursor
, IPropDataItem
, entry
);
1425 /* Note that property types don't have to match, just Id's */
1426 if (PROP_ID(current
->value
->ulPropTag
) == PROP_ID(ulPropTag
))
1432 /* Internal - Add a new property value, assumes lock is held */
1433 static IPropDataItem
*IMAPIPROP_AddValue(IPropDataImpl
*This
,
1434 LPSPropValue lpProp
)
1437 LPIPropDataItem lpNew
;
1440 hRet
= This
->lpAlloc(sizeof(IPropDataItem
), &lpMem
);
1442 if (SUCCEEDED(hRet
))
1445 lpNew
->ulAccess
= IPROP_READWRITE
;
1447 /* Allocate the value separately so we can update it easily */
1449 hRet
= This
->lpAlloc(sizeof(SPropValue
), &lpMem
);
1450 if (SUCCEEDED(hRet
))
1452 lpNew
->value
= lpMem
;
1454 hRet
= PropCopyMore(lpNew
->value
, lpProp
, This
->lpMore
, lpMem
);
1455 if (SUCCEEDED(hRet
))
1457 list_add_tail(&This
->values
, &lpNew
->entry
);
1458 This
->ulNumValues
++;
1461 This
->lpFree(lpNew
->value
);
1463 This
->lpFree(lpNew
);
1468 /* Internal - Lock an IPropData object */
1469 static inline void IMAPIPROP_Lock(IPropDataImpl
*This
)
1471 EnterCriticalSection(&This
->cs
);
1474 /* Internal - Unlock an IPropData object */
1475 static inline void IMAPIPROP_Unlock(IPropDataImpl
*This
)
1477 LeaveCriticalSection(&This
->cs
);
1480 /* This one seems to be missing from mapidefs.h */
1481 #define CbNewSPropProblemArray(c) \
1482 (offsetof(SPropProblemArray,aProblem)+(c)*sizeof(SPropProblem))
1484 /**************************************************************************
1485 * IPropData_QueryInterface {MAPI32}
1487 * Inherited method from the IUnknown Interface.
1488 * See IUnknown_QueryInterface.
1490 static HRESULT WINAPI
IPropData_fnQueryInterface(LPPROPDATA iface
, REFIID riid
, LPVOID
*ppvObj
)
1492 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1494 TRACE("(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppvObj
);
1496 if (!ppvObj
|| !riid
)
1497 return MAPI_E_INVALID_PARAMETER
;
1501 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1502 IsEqualIID(riid
, &IID_IMAPIProp
) ||
1503 IsEqualIID(riid
, &IID_IMAPIPropData
))
1506 IPropData_AddRef(iface
);
1507 TRACE("returning %p\n", *ppvObj
);
1511 TRACE("returning E_NOINTERFACE\n");
1512 return MAPI_E_INTERFACE_NOT_SUPPORTED
;
1515 /**************************************************************************
1516 * IPropData_AddRef {MAPI32}
1518 * Inherited method from the IUnknown Interface.
1519 * See IUnknown_AddRef.
1521 static ULONG WINAPI
IPropData_fnAddRef(LPPROPDATA iface
)
1523 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1525 TRACE("(%p)->(count before=%u)\n", This
, This
->lRef
);
1527 return InterlockedIncrement(&This
->lRef
);
1530 /**************************************************************************
1531 * IPropData_Release {MAPI32}
1533 * Inherited method from the IUnknown Interface.
1534 * See IUnknown_Release.
1536 static ULONG WINAPI
IPropData_fnRelease(LPPROPDATA iface
)
1538 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1541 TRACE("(%p)->(count before=%u)\n", This
, This
->lRef
);
1543 lRef
= InterlockedDecrement(&This
->lRef
);
1546 TRACE("Destroying IPropData (%p)\n",This
);
1548 /* Note: No need to lock, since no other thread is referencing iface */
1549 while (!list_empty(&This
->values
))
1551 struct list
*head
= list_head(&This
->values
);
1552 LPIPropDataItem current
= LIST_ENTRY(head
, IPropDataItem
, entry
);
1554 This
->lpFree(current
->value
);
1555 This
->lpFree(current
);
1557 This
->cs
.DebugInfo
->Spare
[0] = 0;
1558 DeleteCriticalSection(&This
->cs
);
1564 /**************************************************************************
1565 * IPropData_GetLastError {MAPI32}
1567 * Get information about the last error that occurred in an IMAPIProp object.
1570 * iface [I] IMAPIProp object that experienced the error
1571 * hRes [I] Result of the call that returned an error
1572 * ulFlags [I] 0=return Ascii strings, MAPI_UNICODE=return Unicode strings
1573 * lppError [O] Destination for detailed error information
1576 * Success: S_OK. *lppError contains details about the last error.
1577 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
1578 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
1581 * - If this function succeeds, the returned information in *lppError must be
1582 * freed using MAPIFreeBuffer() once the caller is finished with it.
1583 * - It is possible for this function to succeed and set *lppError to NULL,
1584 * if there is no further information to report about hRes.
1586 static HRESULT WINAPI
IPropData_fnGetLastError(LPPROPDATA iface
, HRESULT hRes
, ULONG ulFlags
,
1587 LPMAPIERROR
*lppError
)
1589 TRACE("(%p,0x%08X,0x%08X,%p)\n", iface
, hRes
, ulFlags
, lppError
);
1591 if (!lppError
|| SUCCEEDED(hRes
) || (ulFlags
& ~MAPI_UNICODE
))
1592 return MAPI_E_INVALID_PARAMETER
;
1598 /**************************************************************************
1599 * IPropData_SaveChanges {MAPI32}
1601 * Update any changes made to a transactional IMAPIProp object.
1604 * iface [I] IMAPIProp object to update
1605 * ulFlags [I] Flags controlling the update.
1608 * Success: S_OK. Any outstanding changes are committed to the object.
1609 * Failure: An HRESULT error code describing the error.
1611 static HRESULT WINAPI
IPropData_fnSaveChanges(LPPROPDATA iface
, ULONG ulFlags
)
1613 TRACE("(%p,0x%08X)\n", iface
, ulFlags
);
1615 /* Since this object is not transacted we do not need to implement this */
1616 /* FIXME: Should we set the access levels to clean? */
1620 /**************************************************************************
1621 * IPropData_GetProps {MAPI32}
1623 * Get property values from an IMAPIProp object.
1626 * iface [I] IMAPIProp object to get the property values from
1627 * lpTags [I] Property tage of property values to be retrieved
1628 * ulFlags [I] Return 0=Ascii MAPI_UNICODE=Unicode strings for
1630 * lpCount [O] Destination for number of properties returned
1631 * lppProps [O] Destination for returned property values
1634 * Success: S_OK. *lppProps and *lpCount are updated.
1635 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1636 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
1637 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
1640 * - If MAPI_W_ERRORS_RETURNED is returned, any properties that could not be
1641 * retrieved from iface are present in lppProps with their type
1642 * changed to PT_ERROR and Id unchanged.
1644 static HRESULT WINAPI
IPropData_fnGetProps(LPPROPDATA iface
, LPSPropTagArray lpTags
, ULONG ulFlags
,
1645 ULONG
*lpCount
, LPSPropValue
*lppProps
)
1647 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1649 HRESULT hRet
= S_OK
;
1651 TRACE("(%p,%p,0x%08x,%p,%p) stub\n", iface
, lpTags
, ulFlags
,
1654 if (!iface
|| ulFlags
& ~MAPI_UNICODE
|| !lpTags
|| *lpCount
|| !lppProps
)
1655 return MAPI_E_INVALID_PARAMETER
;
1657 FIXME("semi-stub, flags not supported\n");
1659 *lpCount
= lpTags
->cValues
;
1664 hRet
= MAPIAllocateBuffer(*lpCount
* sizeof(SPropValue
), (LPVOID
*)lppProps
);
1668 IMAPIPROP_Lock(This
);
1670 for (i
= 0; i
< lpTags
->cValues
; i
++)
1672 HRESULT hRetTmp
= E_INVALIDARG
;
1673 LPIPropDataItem item
;
1675 item
= IMAPIPROP_GetValue(This
, lpTags
->aulPropTag
[i
]);
1678 hRetTmp
= PropCopyMore(&(*lppProps
)[i
], item
->value
,
1679 This
->lpMore
, *lppProps
);
1680 if (FAILED(hRetTmp
))
1682 hRet
= MAPI_W_ERRORS_RETURNED
;
1683 (*lppProps
)[i
].ulPropTag
=
1684 CHANGE_PROP_TYPE(lpTags
->aulPropTag
[i
], PT_ERROR
);
1688 IMAPIPROP_Unlock(This
);
1693 /**************************************************************************
1694 * MAPIProp_GetPropList {MAPI32}
1696 * Get the list of property tags for all values in an IMAPIProp object.
1699 * iface [I] IMAPIProp object to get the property tag list from
1700 * ulFlags [I] Return 0=Ascii MAPI_UNICODE=Unicode strings for
1702 * lppTags [O] Destination for the retrieved property tag list
1705 * Success: S_OK. *lppTags contains the tags for all available properties.
1706 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1707 * MAPI_E_BAD_CHARWIDTH, if Ascii or Unicode strings are requested
1708 * and that type of string is not supported.
1710 static HRESULT WINAPI
IPropData_fnGetPropList(LPPROPDATA iface
, ULONG ulFlags
,
1711 LPSPropTagArray
*lppTags
)
1713 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1717 TRACE("(%p,0x%08x,%p) stub\n", iface
, ulFlags
, lppTags
);
1719 if (!iface
|| ulFlags
& ~MAPI_UNICODE
|| !lppTags
)
1720 return MAPI_E_INVALID_PARAMETER
;
1722 FIXME("semi-stub, flags not supported\n");
1726 IMAPIPROP_Lock(This
);
1728 hRet
= MAPIAllocateBuffer(CbNewSPropTagArray(This
->ulNumValues
),
1730 if (SUCCEEDED(hRet
))
1732 struct list
*cursor
;
1735 LIST_FOR_EACH(cursor
, &This
->values
)
1737 LPIPropDataItem current
= LIST_ENTRY(cursor
, IPropDataItem
, entry
);
1738 (*lppTags
)->aulPropTag
[i
] = current
->value
->ulPropTag
;
1741 (*lppTags
)->cValues
= This
->ulNumValues
;
1744 IMAPIPROP_Unlock(This
);
1748 /**************************************************************************
1749 * IPropData_OpenProperty {MAPI32}
1751 * Not documented at this time.
1754 * An HRESULT success/failure code.
1756 static HRESULT WINAPI
IPropData_fnOpenProperty(LPPROPDATA iface
, ULONG ulPropTag
, LPCIID iid
,
1757 ULONG ulOpts
, ULONG ulFlags
, LPUNKNOWN
*lpUnk
)
1759 FIXME("(%p,%u,%s,%u,0x%08x,%p) stub\n", iface
, ulPropTag
,
1760 debugstr_guid(iid
), ulOpts
, ulFlags
, lpUnk
);
1761 return MAPI_E_NO_SUPPORT
;
1765 /**************************************************************************
1766 * IPropData_SetProps {MAPI32}
1768 * Add or edit the property values in an IMAPIProp object.
1771 * iface [I] IMAPIProp object to get the property tag list from
1772 * ulValues [I] Number of properties in lpProps
1773 * lpProps [I] Property values to set
1774 * lppProbs [O] Optional destination for any problems that occurred
1777 * Success: S_OK. The properties in lpProps are added to iface if they don't
1778 * exist, or changed to the values in lpProps if they do
1779 * Failure: An HRESULT error code describing the error
1781 static HRESULT WINAPI
IPropData_fnSetProps(LPPROPDATA iface
, ULONG ulValues
, LPSPropValue lpProps
,
1782 LPSPropProblemArray
*lppProbs
)
1784 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1785 HRESULT hRet
= S_OK
;
1788 TRACE("(%p,%u,%p,%p)\n", iface
, ulValues
, lpProps
, lppProbs
);
1790 if (!iface
|| !lpProps
)
1791 return MAPI_E_INVALID_PARAMETER
;
1793 for (i
= 0; i
< ulValues
; i
++)
1795 if (FBadProp(&lpProps
[i
]) ||
1796 PROP_TYPE(lpProps
[i
].ulPropTag
) == PT_OBJECT
||
1797 PROP_TYPE(lpProps
[i
].ulPropTag
) == PT_NULL
)
1798 return MAPI_E_INVALID_PARAMETER
;
1801 IMAPIPROP_Lock(This
);
1803 /* FIXME: Under what circumstances is lpProbs created? */
1804 for (i
= 0; i
< ulValues
; i
++)
1806 LPIPropDataItem item
= IMAPIPROP_GetValue(This
, lpProps
[i
].ulPropTag
);
1811 LPVOID lpMem
= NULL
;
1813 /* Found, so update the existing value */
1814 if (item
->value
->ulPropTag
!= lpProps
[i
].ulPropTag
)
1815 FIXME("semi-stub, overwriting type (not coercing)\n");
1817 hRetTmp
= This
->lpAlloc(sizeof(SPropValue
), &lpMem
);
1818 if (SUCCEEDED(hRetTmp
))
1820 hRetTmp
= PropCopyMore(lpMem
, &lpProps
[i
], This
->lpMore
, lpMem
);
1821 if (SUCCEEDED(hRetTmp
))
1823 This
->lpFree(item
->value
);
1824 item
->value
= lpMem
;
1827 This
->lpFree(lpMem
);
1834 if (!IMAPIPROP_AddValue(This
, &lpProps
[i
]))
1835 hRet
= MAPI_E_NOT_ENOUGH_MEMORY
;
1839 IMAPIPROP_Unlock(This
);
1843 /**************************************************************************
1844 * IPropData_DeleteProps {MAPI32}
1846 * Delete one or more property values from an IMAPIProp object.
1849 * iface [I] IMAPIProp object to remove property values from.
1850 * lpTags [I] Collection of property Id's to remove from iface.
1851 * lppProbs [O] Destination for problems encountered, if any.
1854 * Success: S_OK. Any properties in iface matching property Id's in lpTags have
1855 * been deleted. If lppProbs is non-NULL it contains details of any
1856 * errors that occurred.
1857 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
1858 * E_ACCESSDENIED, if this object was created using CreateIProp() and
1859 * a subsequent call to IPropData_SetObjAccess() was made specifying
1860 * IPROP_READONLY as the access type.
1863 * - lppProbs will not be populated for cases where a property Id is present
1864 * in lpTags but not in iface.
1865 * - lppProbs should be deleted with MAPIFreeBuffer() if returned.
1867 static HRESULT WINAPI
IPropData_fnDeleteProps(LPPROPDATA iface
, LPSPropTagArray lpTags
,
1868 LPSPropProblemArray
*lppProbs
)
1870 IPropDataImpl
*This
= impl_from_IPropData(iface
);
1871 ULONG i
, numProbs
= 0;
1872 HRESULT hRet
= S_OK
;
1874 TRACE("(%p,%p,%p)\n", iface
, lpTags
, lppProbs
);
1876 if (!iface
|| !lpTags
)
1877 return MAPI_E_INVALID_PARAMETER
;
1882 for (i
= 0; i
< lpTags
->cValues
; i
++)
1884 if (FBadPropTag(lpTags
->aulPropTag
[i
]) ||
1885 PROP_TYPE(lpTags
->aulPropTag
[i
]) == PT_OBJECT
||
1886 PROP_TYPE(lpTags
->aulPropTag
[i
]) == PT_NULL
)
1887 return MAPI_E_INVALID_PARAMETER
;
1890 IMAPIPROP_Lock(This
);
1892 if (This
->ulObjAccess
!= IPROP_READWRITE
)
1894 IMAPIPROP_Unlock(This
);
1895 return E_ACCESSDENIED
;
1898 for (i
= 0; i
< lpTags
->cValues
; i
++)
1900 LPIPropDataItem item
= IMAPIPROP_GetValue(This
, lpTags
->aulPropTag
[i
]);
1904 if (item
->ulAccess
& IPROP_READWRITE
)
1906 /* Everything hunky-dory, remove the item */
1907 list_remove(&item
->entry
);
1908 This
->lpFree(item
->value
); /* Also frees value pointers */
1910 This
->ulNumValues
--;
1914 /* Can't write the value. Create/populate problems array */
1917 /* Create problems array */
1918 ULONG ulSize
= CbNewSPropProblemArray(lpTags
->cValues
- i
);
1919 HRESULT hRetTmp
= MAPIAllocateBuffer(ulSize
, (LPVOID
*)lppProbs
);
1920 if (FAILED(hRetTmp
))
1925 LPSPropProblem lpProb
= &(*lppProbs
)->aProblem
[numProbs
];
1926 lpProb
->ulIndex
= i
;
1927 lpProb
->ulPropTag
= lpTags
->aulPropTag
[i
];
1928 lpProb
->scode
= E_ACCESSDENIED
;
1934 if (lppProbs
&& *lppProbs
)
1935 (*lppProbs
)->cProblem
= numProbs
;
1937 IMAPIPROP_Unlock(This
);
1942 /**************************************************************************
1943 * IPropData_CopyTo {MAPI32}
1945 * Not documented at this time.
1948 * An HRESULT success/failure code.
1950 static HRESULT WINAPI
IPropData_fnCopyTo(LPPROPDATA iface
, ULONG niids
, LPCIID lpiidExcl
,
1951 LPSPropTagArray lpPropsExcl
, ULONG ulParam
,
1952 LPMAPIPROGRESS lpIProgress
, LPCIID lpIfaceIid
,
1953 LPVOID lpDstObj
, ULONG ulFlags
,
1954 LPSPropProblemArray
*lppProbs
)
1956 FIXME("(%p,%u,%p,%p,%x,%p,%s,%p,0x%08X,%p) stub\n", iface
, niids
,
1957 lpiidExcl
, lpPropsExcl
, ulParam
, lpIProgress
,
1958 debugstr_guid(lpIfaceIid
), lpDstObj
, ulFlags
, lppProbs
);
1959 return MAPI_E_NO_SUPPORT
;
1962 /**************************************************************************
1963 * IPropData_CopyProps {MAPI32}
1965 * Not documented at this time.
1968 * An HRESULT success/failure code.
1970 static HRESULT WINAPI
IPropData_fnCopyProps(LPPROPDATA iface
, LPSPropTagArray lpInclProps
,
1971 ULONG ulParam
, LPMAPIPROGRESS lpIProgress
,
1972 LPCIID lpIface
, LPVOID lpDstObj
, ULONG ulFlags
,
1973 LPSPropProblemArray
*lppProbs
)
1975 FIXME("(%p,%p,%x,%p,%s,%p,0x%08X,%p) stub\n", iface
, lpInclProps
,
1976 ulParam
, lpIProgress
, debugstr_guid(lpIface
), lpDstObj
, ulFlags
,
1978 return MAPI_E_NO_SUPPORT
;
1981 /**************************************************************************
1982 * IPropData_GetNamesFromIDs {MAPI32}
1984 * Get the names of properties from their identifiers.
1987 * iface [I] IMAPIProp object to operate on
1988 * lppPropTags [I/O] Property identifiers to get the names for, or NULL to
1990 * iid [I] Property set identifier, or NULL
1991 * ulFlags [I] MAPI_NO_IDS=Don't return numeric named properties,
1992 * or MAPI_NO_STRINGS=Don't return strings
1993 * lpCount [O] Destination for number of properties returned
1994 * lpppNames [O] Destination for returned names
1997 * Success: S_OK. *lppPropTags and lpppNames contain the returned
1999 * Failure: MAPI_E_NO_SUPPORT, if the object does not support named properties,
2000 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
2001 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
2004 static HRESULT WINAPI
IPropData_fnGetNamesFromIDs(LPPROPDATA iface
, LPSPropTagArray
*lppPropTags
,
2005 LPGUID iid
, ULONG ulFlags
, ULONG
*lpCount
,
2006 LPMAPINAMEID
**lpppNames
)
2008 FIXME("(%p,%p,%s,0x%08X,%p,%p) stub\n", iface
, lppPropTags
,
2009 debugstr_guid(iid
), ulFlags
, lpCount
, lpppNames
);
2010 return MAPI_E_NO_SUPPORT
;
2013 /**************************************************************************
2014 * IPropData_GetIDsFromNames {MAPI32}
2016 * Get property identifiers associated with one or more named properties.
2019 * iface [I] IMAPIProp object to operate on
2020 * ulNames [I] Number of names in lppNames
2021 * lppNames [I] Names to query or create, or NULL to query all names
2022 * ulFlags [I] Pass MAPI_CREATE to create new named properties
2023 * lppPropTags [O] Destination for queried or created property identifiers
2026 * Success: S_OK. *lppPropTags contains the property tags created or requested.
2027 * Failure: MAPI_E_NO_SUPPORT, if the object does not support named properties,
2028 * MAPI_E_TOO_BIG, if the object cannot process the number of
2029 * properties involved.
2030 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
2031 * MAPI_W_ERRORS_RETURNED if not all properties were retrieved
2034 static HRESULT WINAPI
IPropData_fnGetIDsFromNames(LPPROPDATA iface
, ULONG ulNames
,
2035 LPMAPINAMEID
*lppNames
, ULONG ulFlags
,
2036 LPSPropTagArray
*lppPropTags
)
2038 FIXME("(%p,%d,%p,0x%08X,%p) stub\n",
2039 iface
, ulNames
, lppNames
, ulFlags
, lppPropTags
);
2040 return MAPI_E_NO_SUPPORT
;
2043 /**************************************************************************
2044 * IPropData_HrSetObjAccess {MAPI32}
2046 * Set the access level of an IPropData object.
2049 * iface [I] IPropData object to set the access on
2050 * ulAccess [I] Either IPROP_READONLY or IPROP_READWRITE for read or
2051 * read/write access respectively.
2054 * Success: S_OK. The objects access level is changed.
2055 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
2057 static HRESULT WINAPI
2058 IPropData_fnHrSetObjAccess(LPPROPDATA iface
, ULONG ulAccess
)
2060 IPropDataImpl
*This
= impl_from_IPropData(iface
);
2062 TRACE("(%p,%x)\n", iface
, ulAccess
);
2064 if (!iface
|| ulAccess
< IPROP_READONLY
|| ulAccess
> IPROP_READWRITE
)
2065 return MAPI_E_INVALID_PARAMETER
;
2067 IMAPIPROP_Lock(This
);
2069 This
->ulObjAccess
= ulAccess
;
2071 IMAPIPROP_Unlock(This
);
2075 /* Internal - determine if an access value is bad */
2076 static inline BOOL
PROP_IsBadAccess(ULONG ulAccess
)
2080 case IPROP_READONLY
|IPROP_CLEAN
:
2081 case IPROP_READONLY
|IPROP_DIRTY
:
2082 case IPROP_READWRITE
|IPROP_CLEAN
:
2083 case IPROP_READWRITE
|IPROP_DIRTY
:
2089 /**************************************************************************
2090 * IPropData_HrSetPropAccess {MAPI32}
2092 * Set the access levels for a group of property values in an IPropData object.
2095 * iface [I] IPropData object to set access levels in.
2096 * lpTags [I] List of property Id's to set access for.
2097 * lpAccess [O] Access level for each property in lpTags.
2100 * Success: S_OK. The access level of each property value in lpTags that is
2101 * present in iface is changed.
2102 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
2105 * - Each access level in lpAccess must contain at least one of IPROP_READONLY
2106 * or IPROP_READWRITE, but not both, and also IPROP_CLEAN or IPROP_DIRTY,
2107 * but not both. No other bits should be set.
2108 * - If a property Id in lpTags is not present in iface, it is ignored.
2110 static HRESULT WINAPI
2111 IPropData_fnHrSetPropAccess(LPPROPDATA iface
, LPSPropTagArray lpTags
,
2114 IPropDataImpl
*This
= impl_from_IPropData(iface
);
2117 TRACE("(%p,%p,%p)\n", iface
, lpTags
, lpAccess
);
2119 if (!iface
|| !lpTags
|| !lpAccess
)
2120 return MAPI_E_INVALID_PARAMETER
;
2122 for (i
= 0; i
< lpTags
->cValues
; i
++)
2124 if (FBadPropTag(lpTags
->aulPropTag
[i
]) || PROP_IsBadAccess(lpAccess
[i
]))
2125 return MAPI_E_INVALID_PARAMETER
;
2128 IMAPIPROP_Lock(This
);
2130 for (i
= 0; i
< lpTags
->cValues
; i
++)
2132 LPIPropDataItem item
= IMAPIPROP_GetValue(This
, lpTags
->aulPropTag
[i
]);
2135 item
->ulAccess
= lpAccess
[i
];
2138 IMAPIPROP_Unlock(This
);
2142 /**************************************************************************
2143 * IPropData_HrGetPropAccess {MAPI32}
2145 * Get the access levels for a group of property values in an IPropData object.
2148 * iface [I] IPropData object to get access levels from.
2149 * lppTags [O] Destination for the list of property Id's in iface.
2150 * lppAccess [O] Destination for access level for each property in lppTags.
2153 * Success: S_OK. lppTags and lppAccess contain the property Id's and the
2154 * Access level of each property value in iface.
2155 * Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid, or
2156 * MAPI_E_NOT_ENOUGH_MEMORY if memory allocation fails.
2159 * - *lppTags and *lppAccess should be freed with MAPIFreeBuffer() by the caller.
2161 static HRESULT WINAPI
2162 IPropData_fnHrGetPropAccess(LPPROPDATA iface
, LPSPropTagArray
*lppTags
,
2165 IPropDataImpl
*This
= impl_from_IPropData(iface
);
2170 TRACE("(%p,%p,%p) stub\n", iface
, lppTags
, lppAccess
);
2172 if (!iface
|| !lppTags
|| !lppAccess
)
2173 return MAPI_E_INVALID_PARAMETER
;
2178 IMAPIPROP_Lock(This
);
2180 hRet
= This
->lpAlloc(CbNewSPropTagArray(This
->ulNumValues
), &lpMem
);
2181 if (SUCCEEDED(hRet
))
2185 hRet
= This
->lpAlloc(This
->ulNumValues
* sizeof(ULONG
), &lpMem
);
2186 if (SUCCEEDED(hRet
))
2188 struct list
*cursor
;
2191 (*lppTags
)->cValues
= This
->ulNumValues
;
2194 LIST_FOR_EACH(cursor
, &This
->values
)
2196 LPIPropDataItem item
= LIST_ENTRY(cursor
, IPropDataItem
, entry
);
2197 (*lppTags
)->aulPropTag
[i
] = item
->value
->ulPropTag
;
2198 (*lppAccess
)[i
] = item
->ulAccess
;
2201 IMAPIPROP_Unlock(This
);
2204 This
->lpFree(*lppTags
);
2207 IMAPIPROP_Unlock(This
);
2208 return MAPI_E_NOT_ENOUGH_MEMORY
;
2211 /**************************************************************************
2212 * IPropData_HrAddObjProps {MAPI32}
2214 * Not documented at this time.
2217 * An HRESULT success/failure code.
2219 static HRESULT WINAPI
2220 IPropData_fnHrAddObjProps(LPPROPDATA iface
, LPSPropTagArray lpTags
,
2221 LPSPropProblemArray
*lppProbs
)
2226 LPSPropValue lpValues
;
2229 FIXME("(%p,%p,%p) stub\n", iface
, lpTags
, lppProbs
);
2231 if (!iface
|| !lpTags
)
2232 return MAPI_E_INVALID_PARAMETER
;
2234 /* FIXME: Below is the obvious implementation, adding all the properties
2235 * in lpTags to the object. However, it doesn't appear that this
2236 * is what this function does.
2240 if (!lpTags
->cValues
)
2243 lpValues
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2244 lpTags
->cValues
* sizeof(SPropValue
));
2246 return MAPI_E_NOT_ENOUGH_MEMORY
;
2248 for (i
= 0; i
< lpTags
->cValues
; i
++)
2249 lpValues
[i
].ulPropTag
= lpTags
->aulPropTag
[i
];
2251 hRet
= IPropData_SetProps(iface
, lpTags
->cValues
, lpValues
, lppProbs
);
2252 HeapFree(GetProcessHeap(), 0, lpValues
);
2257 static const IPropDataVtbl IPropDataImpl_vtbl
=
2259 IPropData_fnQueryInterface
,
2261 IPropData_fnRelease
,
2262 IPropData_fnGetLastError
,
2263 IPropData_fnSaveChanges
,
2264 IPropData_fnGetProps
,
2265 IPropData_fnGetPropList
,
2266 IPropData_fnOpenProperty
,
2267 IPropData_fnSetProps
,
2268 IPropData_fnDeleteProps
,
2270 IPropData_fnCopyProps
,
2271 IPropData_fnGetNamesFromIDs
,
2272 IPropData_fnGetIDsFromNames
,
2273 IPropData_fnHrSetObjAccess
,
2274 IPropData_fnHrSetPropAccess
,
2275 IPropData_fnHrGetPropAccess
,
2276 IPropData_fnHrAddObjProps
2279 /*************************************************************************
2280 * CreateIProp@24 (MAPI32.60)
2282 * Create an IPropData object.
2285 * iid [I] GUID of the object to create. Use &IID_IMAPIPropData or NULL
2286 * lpAlloc [I] Memory allocation function. Use MAPIAllocateBuffer()
2287 * lpMore [I] Linked memory allocation function. Use MAPIAllocateMore()
2288 * lpFree [I] Memory free function. Use MAPIFreeBuffer()
2289 * lpReserved [I] Reserved, set to NULL
2290 * lppPropData [O] Destination for created IPropData object
2293 * Success: S_OK. *lppPropData contains the newly created object.
2294 * Failure: MAPI_E_INTERFACE_NOT_SUPPORTED, if iid is non-NULL and not supported,
2295 * MAPI_E_INVALID_PARAMETER, if any parameter is invalid
2297 SCODE WINAPI
CreateIProp(LPCIID iid
, ALLOCATEBUFFER
*lpAlloc
,
2298 ALLOCATEMORE
*lpMore
, FREEBUFFER
*lpFree
,
2299 LPVOID lpReserved
, LPPROPDATA
*lppPropData
)
2301 IPropDataImpl
*lpPropData
;
2304 TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_guid(iid
), lpAlloc
, lpMore
, lpFree
,
2305 lpReserved
, lppPropData
);
2308 *lppPropData
= NULL
;
2310 if (iid
&& !IsEqualGUID(iid
, &IID_IMAPIPropData
))
2311 return MAPI_E_INTERFACE_NOT_SUPPORTED
;
2313 if (!lpAlloc
|| !lpMore
|| !lpFree
|| lpReserved
|| !lppPropData
)
2314 return MAPI_E_INVALID_PARAMETER
;
2316 scode
= lpAlloc(sizeof(IPropDataImpl
), (LPVOID
*)&lpPropData
);
2318 if (SUCCEEDED(scode
))
2320 lpPropData
->IPropData_iface
.lpVtbl
= &IPropDataImpl_vtbl
;
2321 lpPropData
->lRef
= 1;
2322 lpPropData
->lpAlloc
= lpAlloc
;
2323 lpPropData
->lpMore
= lpMore
;
2324 lpPropData
->lpFree
= lpFree
;
2325 lpPropData
->ulObjAccess
= IPROP_READWRITE
;
2326 lpPropData
->ulNumValues
= 0;
2327 list_init(&lpPropData
->values
);
2328 InitializeCriticalSection(&lpPropData
->cs
);
2329 lpPropData
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": IPropDataImpl.cs");
2330 *lppPropData
= &lpPropData
->IPropData_iface
;