prop.c 76.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Property functions
 *
 * Copyright 2004 Jon Griffiths
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21
 */

#include <stdarg.h>
22

23 24 25 26 27 28 29
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "winerror.h"
#include "winternl.h"
#include "objbase.h"
#include "shlwapi.h"
30
#include "wine/list.h"
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include "wine/debug.h"
#include "wine/unicode.h"
#include "mapival.h"

WINE_DEFAULT_DEBUG_CHANNEL(mapi);

BOOL WINAPI FBadRglpszA(LPSTR*,ULONG);

/* Internal: Check if a property value array is invalid */
static inline ULONG PROP_BadArray(LPSPropValue lpProp, size_t elemSize)
{
    return IsBadReadPtr(lpProp->Value.MVi.lpi, lpProp->Value.MVi.cValues * elemSize);
}

/*************************************************************************
 * PropCopyMore@16 (MAPI32.76)
 *
 * Copy a property value.
 *
 * PARAMS
 *  lpDest [O] Destination for the copied value
 *  lpSrc  [I] Property value to copy to lpDest
 *  lpMore [I] Linked memory allocation function (pass MAPIAllocateMore())
 *  lpOrig [I] Original allocation to which memory will be linked
 *
 * RETURNS
 *  Success: S_OK. lpDest contains a deep copy of lpSrc.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
 *           MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
 *
 * NOTES
 *  Any elements within the property returned should not be individually
 *  freed, as they will be freed when lpOrig is.
 */
65
SCODE WINAPI PropCopyMore(LPSPropValue lpDest, LPSPropValue lpSrc,
66 67 68 69
                          ALLOCATEMORE *lpMore, LPVOID lpOrig)
{
    ULONG ulLen, i;
    SCODE scode = S_OK;
70

71
    TRACE("(%p,%p,%p,%p)\n", lpDest, lpSrc, lpMore, lpOrig);
72

73 74 75 76 77 78
    if (!lpDest || IsBadWritePtr(lpDest, sizeof(SPropValue)) ||
        FBadProp(lpSrc) || !lpMore)
        return MAPI_E_INVALID_PARAMETER;

    /* Shallow copy first, this is sufficient for properties without pointers */
    *lpDest = *lpSrc;
79

80 81 82 83 84
   switch (PROP_TYPE(lpSrc->ulPropTag))
    {
    case PT_CLSID:
        scode = lpMore(sizeof(GUID), lpOrig, (LPVOID*)&lpDest->Value.lpguid);
        if (SUCCEEDED(scode))
85
            *lpDest->Value.lpguid = *lpSrc->Value.lpguid;
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
        break;
    case PT_STRING8:
        ulLen = lstrlenA(lpSrc->Value.lpszA) + 1u;
        scode = lpMore(ulLen, lpOrig, (LPVOID*)&lpDest->Value.lpszA);
        if (SUCCEEDED(scode))
            memcpy(lpDest->Value.lpszA, lpSrc->Value.lpszA, ulLen);
        break;
    case PT_UNICODE:
        ulLen = (strlenW(lpSrc->Value.lpszW) + 1u) * sizeof(WCHAR);
        scode = lpMore(ulLen, lpOrig, (LPVOID*)&lpDest->Value.lpszW);
        if (SUCCEEDED(scode))
            memcpy(lpDest->Value.lpszW, lpSrc->Value.lpszW, ulLen);
        break;
    case PT_BINARY:
        scode = lpMore(lpSrc->Value.bin.cb, lpOrig, (LPVOID*)&lpDest->Value.bin.lpb);
        if (SUCCEEDED(scode))
            memcpy(lpDest->Value.bin.lpb, lpSrc->Value.bin.lpb, lpSrc->Value.bin.cb);
        break;
    default:
        if (lpSrc->ulPropTag & MV_FLAG)
        {
            ulLen = UlPropSize(lpSrc);

            if (PROP_TYPE(lpSrc->ulPropTag) == PT_MV_STRING8 ||
                PROP_TYPE(lpSrc->ulPropTag) == PT_MV_UNICODE)
            {
                /* UlPropSize doesn't account for the string pointers */
                ulLen += lpSrc->Value.MVszA.cValues * sizeof(char*);
            }
            else if (PROP_TYPE(lpSrc->ulPropTag) == PT_MV_BINARY)
            {
               /* UlPropSize doesn't account for the SBinary structs */
               ulLen += lpSrc->Value.MVbin.cValues * sizeof(SBinary);
            }

            lpDest->Value.MVi.cValues = lpSrc->Value.MVi.cValues;
            scode = lpMore(ulLen, lpOrig, (LPVOID*)&lpDest->Value.MVi.lpi);
            if (FAILED(scode))
                break;

126
            /* Note that we could allocate the memory for each value in a
127
             * multi-value property separately, however if an allocation failed
128
             * we would be left with a bunch of allocated memory, which (while
129 130
             * not really leaked) is unusable until lpOrig is freed. So for
             * strings and binary arrays we make a single allocation for all
131 132 133
             * of the data. This is consistent since individual elements can't
             * be freed anyway.
             */
134

135 136 137 138
            switch (PROP_TYPE(lpSrc->ulPropTag))
            {
            case PT_MV_STRING8:
            {
139
                char *lpNextStr = (char*)(lpDest->Value.MVszA.lppszA +
140
                                          lpDest->Value.MVszA.cValues);
141

142 143 144
                for (i = 0; i < lpSrc->Value.MVszA.cValues; i++)
                {
                    ULONG ulStrLen = lstrlenA(lpSrc->Value.MVszA.lppszA[i]) + 1u;
145

146 147 148
                    lpDest->Value.MVszA.lppszA[i] = lpNextStr;
                    memcpy(lpNextStr, lpSrc->Value.MVszA.lppszA[i], ulStrLen);
                    lpNextStr += ulStrLen;
149
                }
150 151 152 153
                break;
            }
            case PT_MV_UNICODE:
            {
154
                WCHAR *lpNextStr = (WCHAR*)(lpDest->Value.MVszW.lppszW +
155
                                            lpDest->Value.MVszW.cValues);
156

157 158 159
                for (i = 0; i < lpSrc->Value.MVszW.cValues; i++)
                {
                    ULONG ulStrLen = strlenW(lpSrc->Value.MVszW.lppszW[i]) + 1u;
160

161
                    lpDest->Value.MVszW.lppszW[i] = lpNextStr;
162
                    memcpy(lpNextStr, lpSrc->Value.MVszW.lppszW[i], ulStrLen * sizeof(WCHAR));
163
                    lpNextStr += ulStrLen;
164
                }
165 166 167 168
                break;
            }
            case PT_MV_BINARY:
            {
169
                LPBYTE lpNext = (LPBYTE)(lpDest->Value.MVbin.lpbin +
170
                                         lpDest->Value.MVbin.cValues);
171

172 173 174 175 176 177
                for (i = 0; i < lpSrc->Value.MVszW.cValues; i++)
                {
                    lpDest->Value.MVbin.lpbin[i].cb = lpSrc->Value.MVbin.lpbin[i].cb;
                    lpDest->Value.MVbin.lpbin[i].lpb = lpNext;
                    memcpy(lpNext, lpSrc->Value.MVbin.lpbin[i].lpb, lpDest->Value.MVbin.lpbin[i].cb);
                    lpNext += lpDest->Value.MVbin.lpbin[i].cb;
178
                }
179 180 181 182 183 184 185 186 187 188 189 190
                break;
            }
            default:
                /* No embedded pointers, just copy the data over */
                memcpy(lpDest->Value.MVi.lpi, lpSrc->Value.MVi.lpi, ulLen);
                break;
            }
            break;
        }
    }
    return scode;
}
191

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
/*************************************************************************
 * UlPropSize@4 (MAPI32.77)
 *
 * Determine the size of a property in bytes.
 *
 * PARAMS
 *  lpProp [I] Property to determine the size of
 *
 * RETURNS
 *  Success: The size of the value in lpProp.
 *  Failure: 0, if a multi-value (array) property is invalid or the type of lpProp
 *           is unknown.
 *
 * NOTES
 *  - The size returned does not include the size of the SPropValue struct
 *    or the size of the array of pointers for multi-valued properties that
 *    contain pointers (such as PT_MV_STRING8 or PT-MV_UNICODE).
 *  - MSDN incorrectly states that this function returns MAPI_E_CALL_FAILED if
 *    lpProp is invalid. In reality no checking is performed and this function
 *    will crash if passed an invalid property, or return 0 if the property
 *    type is PT_OBJECT or is unknown.
 */
ULONG WINAPI UlPropSize(LPSPropValue lpProp)
{
    ULONG ulRet = 1u, i;

    TRACE("(%p)\n", lpProp);

    switch (PROP_TYPE(lpProp->ulPropTag))
    {
    case PT_MV_I2:       ulRet = lpProp->Value.MVi.cValues;
223
                         /* fall through */
224 225 226 227
    case PT_BOOLEAN:
    case PT_I2:          ulRet *= sizeof(USHORT);
                         break;
    case PT_MV_I4:       ulRet = lpProp->Value.MVl.cValues;
228
                         /* fall through */
229 230 231 232
    case PT_ERROR:
    case PT_I4:          ulRet *= sizeof(LONG);
                         break;
    case PT_MV_I8:       ulRet = lpProp->Value.MVli.cValues;
233
                         /* fall through */
234 235 236
    case PT_I8:          ulRet *= sizeof(LONG64);
                         break;
    case PT_MV_R4:       ulRet = lpProp->Value.MVflt.cValues;
237
                         /* fall through */
238 239 240 241
    case PT_R4:          ulRet *= sizeof(float);
                         break;
    case PT_MV_APPTIME:
    case PT_MV_R8:       ulRet = lpProp->Value.MVdbl.cValues;
242
                         /* fall through */
243 244 245 246
    case PT_APPTIME:
    case PT_R8:          ulRet *= sizeof(double);
                         break;
    case PT_MV_CURRENCY: ulRet = lpProp->Value.MVcur.cValues;
247
                         /* fall through */
248 249 250
    case PT_CURRENCY:    ulRet *= sizeof(CY);
                         break;
    case PT_MV_SYSTIME:  ulRet = lpProp->Value.MVft.cValues;
251
                         /* fall through */
252 253 254
    case PT_SYSTIME:     ulRet *= sizeof(FILETIME);
                         break;
    case PT_MV_CLSID:    ulRet = lpProp->Value.MVguid.cValues;
255
                         /* fall through */
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
    case PT_CLSID:       ulRet *= sizeof(GUID);
                         break;
    case PT_MV_STRING8:  ulRet = 0u;
                         for (i = 0; i < lpProp->Value.MVszA.cValues; i++)
                             ulRet += (lstrlenA(lpProp->Value.MVszA.lppszA[i]) + 1u);
                         break;
    case PT_STRING8:     ulRet = lstrlenA(lpProp->Value.lpszA) + 1u;
                         break;
    case PT_MV_UNICODE:  ulRet = 0u;
                         for (i = 0; i < lpProp->Value.MVszW.cValues; i++)
                             ulRet += (strlenW(lpProp->Value.MVszW.lppszW[i]) + 1u);
                         ulRet *= sizeof(WCHAR);
                         break;
    case PT_UNICODE:     ulRet = (lstrlenW(lpProp->Value.lpszW) + 1u) * sizeof(WCHAR);
                         break;
    case PT_MV_BINARY:   ulRet = 0u;
                         for (i = 0; i < lpProp->Value.MVbin.cValues; i++)
                             ulRet += lpProp->Value.MVbin.lpbin[i].cb;
                         break;
    case PT_BINARY:      ulRet = lpProp->Value.bin.cb;
                         break;
    case PT_OBJECT:
    default:             ulRet = 0u;
                         break;
    }

    return ulRet;
}

/*************************************************************************
 * FPropContainsProp@12 (MAPI32.78)
 *
 * Find a property with a given property tag in a property array.
 *
 * PARAMS
 *  lpHaystack [I] Property to match to
 *  lpNeedle   [I] Property to find in lpHaystack
 *  ulFuzzy    [I] Flags controlling match type and strictness (FL_* flags from "mapidefs.h")
 *
 * RETURNS
 *  TRUE, if lpNeedle matches lpHaystack according to the criteria of ulFuzzy.
 *
 * NOTES
 *  Only property types of PT_STRING8 and PT_BINARY are handled by this function.
 */
BOOL WINAPI FPropContainsProp(LPSPropValue lpHaystack, LPSPropValue lpNeedle, ULONG ulFuzzy)
{
303
    TRACE("(%p,%p,0x%08x)\n", lpHaystack, lpNeedle, ulFuzzy);
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

    if (FBadProp(lpHaystack) || FBadProp(lpNeedle) ||
        PROP_TYPE(lpHaystack->ulPropTag) != PROP_TYPE(lpNeedle->ulPropTag))
        return FALSE;

    /* FIXME: Do later versions support Unicode as well? */

    if (PROP_TYPE(lpHaystack->ulPropTag) == PT_STRING8)
    {
        DWORD dwFlags = 0, dwNeedleLen, dwHaystackLen;

        if (ulFuzzy & FL_IGNORECASE)
            dwFlags |= NORM_IGNORECASE;
        if (ulFuzzy & FL_IGNORENONSPACE)
            dwFlags |= NORM_IGNORENONSPACE;
        if (ulFuzzy & FL_LOOSE)
            dwFlags |= (NORM_IGNORECASE|NORM_IGNORENONSPACE|NORM_IGNORESYMBOLS);

        dwNeedleLen = lstrlenA(lpNeedle->Value.lpszA);
        dwHaystackLen = lstrlenA(lpHaystack->Value.lpszA);

        if ((ulFuzzy & (FL_SUBSTRING|FL_PREFIX)) == FL_PREFIX)
        {
            if (dwNeedleLen <= dwHaystackLen &&
                CompareStringA(LOCALE_USER_DEFAULT, dwFlags,
                               lpHaystack->Value.lpszA, dwNeedleLen,
                               lpNeedle->Value.lpszA, dwNeedleLen) == CSTR_EQUAL)
                return TRUE; /* needle is a prefix of haystack */
        }
        else if ((ulFuzzy & (FL_SUBSTRING|FL_PREFIX)) == FL_SUBSTRING)
        {
            LPSTR (WINAPI *pStrChrFn)(LPCSTR,WORD) = StrChrA;
            LPSTR lpStr = lpHaystack->Value.lpszA;

            if (dwFlags & NORM_IGNORECASE)
                pStrChrFn = StrChrIA;

            while ((lpStr = pStrChrFn(lpStr, *lpNeedle->Value.lpszA)) != NULL)
            {
                dwHaystackLen -= (lpStr - lpHaystack->Value.lpszA);
                if (dwNeedleLen <= dwHaystackLen &&
                    CompareStringA(LOCALE_USER_DEFAULT, dwFlags,
                               lpStr, dwNeedleLen,
                               lpNeedle->Value.lpszA, dwNeedleLen) == CSTR_EQUAL)
                    return TRUE; /* needle is a substring of haystack */
                lpStr++;
            }
        }
        else if (CompareStringA(LOCALE_USER_DEFAULT, dwFlags,
                                lpHaystack->Value.lpszA, dwHaystackLen,
                                lpNeedle->Value.lpszA, dwNeedleLen) == CSTR_EQUAL)
            return TRUE; /* full string match */
    }
    else if (PROP_TYPE(lpHaystack->ulPropTag) == PT_BINARY)
    {
        if ((ulFuzzy & (FL_SUBSTRING|FL_PREFIX)) == FL_PREFIX)
        {
            if (lpNeedle->Value.bin.cb <= lpHaystack->Value.bin.cb &&
                !memcmp(lpNeedle->Value.bin.lpb, lpHaystack->Value.bin.lpb,
                        lpNeedle->Value.bin.cb))
                return TRUE; /* needle is a prefix of haystack */
        }
        else if ((ulFuzzy & (FL_SUBSTRING|FL_PREFIX)) == FL_SUBSTRING)
        {
            ULONG ulLen = lpHaystack->Value.bin.cb;
            LPBYTE lpb = lpHaystack->Value.bin.lpb;

            while ((lpb = memchr(lpb, *lpNeedle->Value.bin.lpb, ulLen)) != NULL)
            {
                ulLen = lpHaystack->Value.bin.cb - (lpb - lpHaystack->Value.bin.lpb);
                if (lpNeedle->Value.bin.cb <= ulLen &&
                    !memcmp(lpNeedle->Value.bin.lpb, lpb, lpNeedle->Value.bin.cb))
                    return TRUE; /* needle is a substring of haystack */
                lpb++;
            }
        }
        else if (!LPropCompareProp(lpHaystack, lpNeedle))
            return TRUE; /* needle is an exact match with haystack */

    }
    return FALSE;
}

/*************************************************************************
 * FPropCompareProp@12 (MAPI32.79)
 *
 * Compare two properties.
 *
 * PARAMS
 *  lpPropLeft  [I] Left hand property to compare to lpPropRight
394
 *  ulOp        [I] Comparison operator (RELOP_* enum from "mapidefs.h")
395 396 397
 *  lpPropRight [I] Right hand property to compare to lpPropLeft
 *
 * RETURNS
398
 *  TRUE, if the comparison is true, FALSE otherwise.
399 400 401 402 403
 */
BOOL WINAPI FPropCompareProp(LPSPropValue lpPropLeft, ULONG ulOp, LPSPropValue lpPropRight)
{
    LONG iCmp;

404
    TRACE("(%p,%d,%p)\n", lpPropLeft, ulOp, lpPropRight);
405 406 407 408 409 410

    if (ulOp > RELOP_RE || FBadProp(lpPropLeft) || FBadProp(lpPropRight))
        return FALSE;

    if (ulOp == RELOP_RE)
    {
411
        FIXME("Comparison operator RELOP_RE not yet implemented!\n");
412 413 414 415 416 417 418
        return FALSE;
    }

    iCmp = LPropCompareProp(lpPropLeft, lpPropRight);

    switch (ulOp)
    {
419 420 421 422 423 424
    case RELOP_LT: return iCmp <  0;
    case RELOP_LE: return iCmp <= 0;
    case RELOP_GT: return iCmp >  0;
    case RELOP_GE: return iCmp >= 0;
    case RELOP_EQ: return iCmp == 0;
    case RELOP_NE: return iCmp != 0;
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
    }
    return FALSE;
}

/*************************************************************************
 * LPropCompareProp@8 (MAPI32.80)
 *
 * Compare two properties.
 *
 * PARAMS
 *  lpPropLeft  [I] Left hand property to compare to lpPropRight
 *  lpPropRight [I] Right hand property to compare to lpPropLeft
 *
 * RETURNS
 *  An integer less than, equal to or greater than 0, indicating that
 *  lpszStr is less than, the same, or greater than lpszComp.
 */
LONG WINAPI LPropCompareProp(LPSPropValue lpPropLeft, LPSPropValue lpPropRight)
{
    LONG iRet;

446
    TRACE("(%p->0x%08x,%p->0x%08x)\n", lpPropLeft, lpPropLeft->ulPropTag,
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
          lpPropRight, lpPropRight->ulPropTag);

    /* If the properties are not the same, sort by property type */
    if (PROP_TYPE(lpPropLeft->ulPropTag) != PROP_TYPE(lpPropRight->ulPropTag))
        return (LONG)PROP_TYPE(lpPropLeft->ulPropTag) - (LONG)PROP_TYPE(lpPropRight->ulPropTag);

    switch (PROP_TYPE(lpPropLeft->ulPropTag))
    {
    case PT_UNSPECIFIED:
    case PT_NULL:
        return 0; /* NULLs are equal */
    case PT_I2:
        return lpPropLeft->Value.i - lpPropRight->Value.i;
    case PT_I4:
        return lpPropLeft->Value.l - lpPropRight->Value.l;
    case PT_I8:
        if (lpPropLeft->Value.li.QuadPart > lpPropRight->Value.li.QuadPart)
            return 1;
        if (lpPropLeft->Value.li.QuadPart == lpPropRight->Value.li.QuadPart)
            return 0;
        return -1;
    case PT_R4:
        if (lpPropLeft->Value.flt > lpPropRight->Value.flt)
            return 1;
        if (lpPropLeft->Value.flt == lpPropRight->Value.flt)
            return 0;
        return -1;
    case PT_APPTIME:
    case PT_R8:
        if (lpPropLeft->Value.dbl > lpPropRight->Value.dbl)
            return 1;
        if (lpPropLeft->Value.dbl == lpPropRight->Value.dbl)
            return 0;
        return -1;
    case PT_CURRENCY:
        if (lpPropLeft->Value.cur.int64 > lpPropRight->Value.cur.int64)
            return 1;
        if (lpPropLeft->Value.cur.int64 == lpPropRight->Value.cur.int64)
            return 0;
        return -1;
    case PT_SYSTIME:
        return CompareFileTime(&lpPropLeft->Value.ft, &lpPropRight->Value.ft);
    case PT_BOOLEAN:
        return (lpPropLeft->Value.b ? 1 : 0) - (lpPropRight->Value.b ? 1 : 0);
    case PT_BINARY:
        if (lpPropLeft->Value.bin.cb == lpPropRight->Value.bin.cb)
            iRet = memcmp(lpPropLeft->Value.bin.lpb, lpPropRight->Value.bin.lpb,
                          lpPropLeft->Value.bin.cb);
        else
        {
            iRet = memcmp(lpPropLeft->Value.bin.lpb, lpPropRight->Value.bin.lpb,
                          min(lpPropLeft->Value.bin.cb, lpPropRight->Value.bin.cb));

            if (!iRet)
                iRet = lpPropLeft->Value.bin.cb - lpPropRight->Value.bin.cb;
        }
        return iRet;
    case PT_STRING8:
        return lstrcmpA(lpPropLeft->Value.lpszA, lpPropRight->Value.lpszA);
    case PT_UNICODE:
        return strcmpW(lpPropLeft->Value.lpszW, lpPropRight->Value.lpszW);
    case PT_ERROR:
        if (lpPropLeft->Value.err > lpPropRight->Value.err)
            return 1;
        if (lpPropLeft->Value.err == lpPropRight->Value.err)
            return 0;
        return -1;
    case PT_CLSID:
        return memcmp(lpPropLeft->Value.lpguid, lpPropRight->Value.lpguid,
                      sizeof(GUID));
    }
518
    FIXME("Unhandled property type %d\n", PROP_TYPE(lpPropLeft->ulPropTag));
519 520 521
    return 0;
}

522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
/*************************************************************************
 * HrGetOneProp@8 (MAPI32.135)
 *
 * Get a property value from an IMAPIProp object.
 *
 * PARAMS
 *  lpIProp   [I] IMAPIProp object to get the property value in
 *  ulPropTag [I] Property tag of the property to get
 *  lppProp   [O] Destination for the returned property
 *
 * RETURNS
 *  Success: S_OK. *lppProp contains the property value requested.
 *  Failure: MAPI_E_NOT_FOUND, if no property value has the tag given by ulPropTag.
 */
HRESULT WINAPI HrGetOneProp(LPMAPIPROP lpIProp, ULONG ulPropTag, LPSPropValue *lppProp)
{
    SPropTagArray pta;
    ULONG ulCount;
    HRESULT hRet;

542
    TRACE("(%p,%d,%p)\n", lpIProp, ulPropTag, lppProp);
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596

    pta.cValues = 1u;
    pta.aulPropTag[0] = ulPropTag;
    hRet = IMAPIProp_GetProps(lpIProp, &pta, 0u, &ulCount, lppProp);
    if (hRet == MAPI_W_ERRORS_RETURNED)
    {
        MAPIFreeBuffer(*lppProp);
        *lppProp = NULL;
        hRet = MAPI_E_NOT_FOUND;
    }
    return hRet;
}

/*************************************************************************
 * HrSetOneProp@8 (MAPI32.136)
 *
 * Set a property value in an IMAPIProp object.
 *
 * PARAMS
 *  lpIProp [I] IMAPIProp object to set the property value in
 *  lpProp  [I] Property value to set
 *
 * RETURNS
 *  Success: S_OK. The value in lpProp is set in lpIProp.
 *  Failure: An error result from IMAPIProp_SetProps().
 */
HRESULT WINAPI HrSetOneProp(LPMAPIPROP lpIProp, LPSPropValue lpProp)
{
    TRACE("(%p,%p)\n", lpIProp, lpProp);

    return IMAPIProp_SetProps(lpIProp, 1u, lpProp, NULL);
}

/*************************************************************************
 * FPropExists@8 (MAPI32.137)
 *
 * Find a property with a given property tag in an IMAPIProp object.
 *
 * PARAMS
 *  lpIProp   [I] IMAPIProp object to find the property tag in
 *  ulPropTag [I] Property tag to find
 *
 * RETURNS
 *  TRUE, if ulPropTag matches a property held in lpIProp,
 *  FALSE, otherwise.
 *
 * NOTES
 *  if ulPropTag has a property type of PT_UNSPECIFIED, then only the property
 *  Ids need to match for a successful match to occur.
 */
 BOOL WINAPI FPropExists(LPMAPIPROP lpIProp, ULONG ulPropTag)
 {
    BOOL bRet = FALSE;

597
    TRACE("(%p,%d)\n", lpIProp, ulPropTag);
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622

    if (lpIProp)
    {
        LPSPropTagArray lpTags;
        ULONG i;

        if (FAILED(IMAPIProp_GetPropList(lpIProp, 0u, &lpTags)))
            return FALSE;

        for (i = 0; i < lpTags->cValues; i++)
        {
            if (!FBadPropTag(lpTags->aulPropTag[i]) &&
                (lpTags->aulPropTag[i] == ulPropTag ||
                 (PROP_TYPE(ulPropTag) == PT_UNSPECIFIED &&
                  PROP_ID(lpTags->aulPropTag[i]) == lpTags->aulPropTag[i])))
            {
                bRet = TRUE;
                break;
            }
        }
        MAPIFreeBuffer(lpTags);
    }
    return bRet;
}

623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
/*************************************************************************
 * PpropFindProp@12 (MAPI32.138)
 *
 * Find a property with a given property tag in a property array.
 *
 * PARAMS
 *  lpProps   [I] Property array to search
 *  cValues   [I] Number of properties in lpProps
 *  ulPropTag [I] Property tag to find
 *
 * RETURNS
 *  A pointer to the matching property, or NULL if none was found.
 *
 * NOTES
 *  if ulPropTag has a property type of PT_UNSPECIFIED, then only the property
 *  Ids need to match for a successful match to occur.
 */
LPSPropValue WINAPI PpropFindProp(LPSPropValue lpProps, ULONG cValues, ULONG ulPropTag)
{
642
    TRACE("(%p,%d,%d)\n", lpProps, cValues, ulPropTag);
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658

    if (lpProps && cValues)
    {
        ULONG i;
        for (i = 0; i < cValues; i++)
        {
            if (!FBadPropTag(lpProps[i].ulPropTag) &&
                (lpProps[i].ulPropTag == ulPropTag ||
                 (PROP_TYPE(ulPropTag) == PT_UNSPECIFIED &&
                  PROP_ID(lpProps[i].ulPropTag) == PROP_ID(ulPropTag))))
                return &lpProps[i];
        }
    }
    return NULL;
}

659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
/*************************************************************************
 * FreePadrlist@4 (MAPI32.139)
 *
 * Free the memory used by an address book list.
 *
 * PARAMS
 *  lpAddrs [I] Address book list to free
 *
 * RETURNS
 *  Nothing.
 */
VOID WINAPI FreePadrlist(LPADRLIST lpAddrs)
{
    TRACE("(%p)\n", lpAddrs);

    /* Structures are binary compatible; use the same implementation */
675
    FreeProws((LPSRowSet)lpAddrs);
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
}

/*************************************************************************
 * FreeProws@4 (MAPI32.140)
 *
 * Free the memory used by a row set.
 *
 * PARAMS
 *  lpRowSet [I] Row set to free
 *
 * RETURNS
 *  Nothing.
 */
VOID WINAPI FreeProws(LPSRowSet lpRowSet)
{
    TRACE("(%p)\n", lpRowSet);

    if (lpRowSet)
    {
        ULONG i;

        for (i = 0; i < lpRowSet->cRows; i++)
            MAPIFreeBuffer(lpRowSet->aRow[i].lpProps);

        MAPIFreeBuffer(lpRowSet);
    }
}

704 705 706 707 708 709 710 711 712 713 714
/*************************************************************************
 * ScCountProps@12 (MAPI32.170)
 *
 * Validate and determine the length of an array of properties.
 *
 * PARAMS
 *  iCount  [I] Length of the lpProps array
 *  lpProps [I] Array of properties to validate/size
 *  pcBytes [O] If non-NULL, destination for the size of the property array
 *
 * RETURNS
715 716
 *  Success: S_OK. If pcBytes is non-NULL, it contains the size of the
 *           properties array.
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid or validation
 *           of the property array fails.
 */
SCODE WINAPI ScCountProps(INT iCount, LPSPropValue lpProps, ULONG *pcBytes)
{
    ULONG i, ulCount = iCount, ulBytes = 0;

    TRACE("(%d,%p,%p)\n", iCount, lpProps, pcBytes);

    if (iCount <= 0 || !lpProps ||
        IsBadReadPtr(lpProps, iCount * sizeof(SPropValue)))
        return MAPI_E_INVALID_PARAMETER;

    for (i = 0; i < ulCount; i++)
    {
        ULONG ulPropSize = 0;
733

734 735 736 737
        if (FBadProp(&lpProps[i]) || lpProps[i].ulPropTag == PROP_ID_NULL ||
            lpProps[i].ulPropTag == PROP_ID_INVALID)
            return MAPI_E_INVALID_PARAMETER;

Andrew Talbot's avatar
Andrew Talbot committed
738 739 740 741 742 743
        if (PROP_TYPE(lpProps[i].ulPropTag) != PT_OBJECT)
        {
            ulPropSize = UlPropSize(&lpProps[i]);
            if (!ulPropSize)
                return MAPI_E_INVALID_PARAMETER;
        }
744

Andrew Talbot's avatar
Andrew Talbot committed
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
        switch (PROP_TYPE(lpProps[i].ulPropTag))
        {
        case PT_STRING8:
        case PT_UNICODE:
        case PT_CLSID:
        case PT_BINARY:
        case PT_MV_I2:
        case PT_MV_I4:
        case PT_MV_I8:
        case PT_MV_R4:
        case PT_MV_R8:
        case PT_MV_CURRENCY:
        case PT_MV_SYSTIME:
        case PT_MV_APPTIME:
            ulPropSize += sizeof(SPropValue);
            break;
        case PT_MV_CLSID:
            ulPropSize += lpProps[i].Value.MVszA.cValues * sizeof(char*) + sizeof(SPropValue);
            break;
        case PT_MV_STRING8:
        case PT_MV_UNICODE:
            ulPropSize += lpProps[i].Value.MVszA.cValues * sizeof(char*) + sizeof(SPropValue);
            break;
        case PT_MV_BINARY:
            ulPropSize += lpProps[i].Value.MVbin.cValues * sizeof(SBinary) + sizeof(SPropValue);
            break;
        default:
            ulPropSize = sizeof(SPropValue);
            break;
        }
        ulBytes += ulPropSize;
776 777 778
    }
    if (pcBytes)
        *pcBytes = ulBytes;
779

780 781 782
    return S_OK;
}

783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
/*************************************************************************
 * ScCopyProps@16 (MAPI32.171)
 *
 * Copy an array of property values into a buffer suited for serialisation.
 *
 * PARAMS
 *  cValues   [I] Number of properties in lpProps
 *  lpProps   [I] Property array to copy
 *  lpDst     [O] Destination for the serialised data
 *  lpCount   [O] If non-NULL, destination for the number of bytes of data written to lpDst
 *
 * RETURNS
 *  Success: S_OK. lpDst contains the serialised data from lpProps.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
 *
 * NOTES
799
 *  The resulting property value array is stored in a contiguous block starting at lpDst.
800 801 802 803 804
 */
SCODE WINAPI ScCopyProps(int cValues, LPSPropValue lpProps, LPVOID lpDst, ULONG *lpCount)
{
    LPSPropValue lpDest = (LPSPropValue)lpDst;
    char *lpDataDest = (char *)(lpDest + cValues);
805 806
    ULONG ulLen, i;
    int iter;
807

808
    TRACE("(%d,%p,%p,%p)\n", cValues, lpProps, lpDst, lpCount);
809

810 811 812 813
    if (!lpProps || cValues < 0 || !lpDest)
        return MAPI_E_INVALID_PARAMETER;

    memcpy(lpDst, lpProps, cValues * sizeof(SPropValue));
814 815

    for (iter = 0; iter < cValues; iter++)
816 817 818 819 820
    {
        switch (PROP_TYPE(lpProps->ulPropTag))
        {
        case PT_CLSID:
            lpDest->Value.lpguid = (LPGUID)lpDataDest;
821
            *lpDest->Value.lpguid = *lpProps->Value.lpguid;
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
            lpDataDest += sizeof(GUID);
            break;
        case PT_STRING8:
            ulLen = lstrlenA(lpProps->Value.lpszA) + 1u;
            lpDest->Value.lpszA = lpDataDest;
            memcpy(lpDest->Value.lpszA, lpProps->Value.lpszA, ulLen);
            lpDataDest += ulLen;
            break;
        case PT_UNICODE:
            ulLen = (strlenW(lpProps->Value.lpszW) + 1u) * sizeof(WCHAR);
            lpDest->Value.lpszW = (LPWSTR)lpDataDest;
            memcpy(lpDest->Value.lpszW, lpProps->Value.lpszW, ulLen);
            lpDataDest += ulLen;
            break;
        case PT_BINARY:
            lpDest->Value.bin.lpb = (LPBYTE)lpDataDest;
            memcpy(lpDest->Value.bin.lpb, lpProps->Value.bin.lpb, lpProps->Value.bin.cb);
            lpDataDest += lpProps->Value.bin.cb;
            break;
        default:
            if (lpProps->ulPropTag & MV_FLAG)
            {
                lpDest->Value.MVi.cValues = lpProps->Value.MVi.cValues;
                /* Note: Assignment uses lppszA but covers all cases by union aliasing */
                lpDest->Value.MVszA.lppszA = (char**)lpDataDest;

                switch (PROP_TYPE(lpProps->ulPropTag))
                {
                case PT_MV_STRING8:
                {
                    lpDataDest += lpProps->Value.MVszA.cValues * sizeof(char *);
853

854 855 856
                    for (i = 0; i < lpProps->Value.MVszA.cValues; i++)
                    {
                        ULONG ulStrLen = lstrlenA(lpProps->Value.MVszA.lppszA[i]) + 1u;
857

858 859 860 861 862 863 864 865 866
                        lpDest->Value.MVszA.lppszA[i] = lpDataDest;
                        memcpy(lpDataDest, lpProps->Value.MVszA.lppszA[i], ulStrLen);
                        lpDataDest += ulStrLen;
                    }
                    break;
                }
                case PT_MV_UNICODE:
                {
                    lpDataDest += lpProps->Value.MVszW.cValues * sizeof(WCHAR *);
867

868 869 870
                    for (i = 0; i < lpProps->Value.MVszW.cValues; i++)
                    {
                        ULONG ulStrLen = (strlenW(lpProps->Value.MVszW.lppszW[i]) + 1u) * sizeof(WCHAR);
871

872 873 874
                        lpDest->Value.MVszW.lppszW[i] = (LPWSTR)lpDataDest;
                        memcpy(lpDataDest, lpProps->Value.MVszW.lppszW[i], ulStrLen);
                        lpDataDest += ulStrLen;
875
                    }
876 877 878 879 880
                    break;
                }
                case PT_MV_BINARY:
                {
                    lpDataDest += lpProps->Value.MVszW.cValues * sizeof(SBinary);
881

882 883 884 885 886 887
                    for (i = 0; i < lpProps->Value.MVszW.cValues; i++)
                    {
                        lpDest->Value.MVbin.lpbin[i].cb = lpProps->Value.MVbin.lpbin[i].cb;
                        lpDest->Value.MVbin.lpbin[i].lpb = (LPBYTE)lpDataDest;
                        memcpy(lpDataDest, lpProps->Value.MVbin.lpbin[i].lpb, lpDest->Value.MVbin.lpbin[i].cb);
                        lpDataDest += lpDest->Value.MVbin.lpbin[i].cb;
888
                    }
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
                    break;
                }
                default:
                    /* No embedded pointers, just copy the data over */
                    ulLen = UlPropSize(lpProps);
                    memcpy(lpDest->Value.MVi.lpi, lpProps->Value.MVi.lpi, ulLen);
                    lpDataDest += ulLen;
                    break;
                }
                break;
            }
        }
        lpDest++;
        lpProps++;
    }
    if (lpCount)
        *lpCount = lpDataDest - (char *)lpDst;
906

907 908
    return S_OK;
}
909

910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
/*************************************************************************
 * ScRelocProps@20 (MAPI32.172)
 *
 * Relocate the pointers in an array of property values after it has been copied.
 *
 * PARAMS
 *  cValues   [I] Number of properties in lpProps
 *  lpProps   [O] Property array to relocate the pointers in.
 *  lpOld     [I] Position where the data was copied from
 *  lpNew     [I] Position where the data was copied to
 *  lpCount   [O] If non-NULL, destination for the number of bytes of data at lpDst
 *
 * RETURNS
 *  Success: S_OK. Any pointers in lpProps are relocated.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
 *
 * NOTES
 *  MSDN states that this function can be used for serialisation by passing
 *  NULL as either lpOld or lpNew, thus converting any pointers in lpProps
 *  between offsets and pointers. This does not work in native (it crashes),
930
 *  and cannot be made to work in Wine because the original interface design
931
 *  is deficient. The only use left for this function is to remap pointers
932 933
 *  in a contiguous property array that has been copied with memcpy() to
 *  another memory location.
934
 */
935
SCODE WINAPI ScRelocProps(int cValues, LPSPropValue lpProps, LPVOID lpOld,
936 937 938
                          LPVOID lpNew, ULONG *lpCount)
{
    static const BOOL bBadPtr = TRUE; /* Windows bug - Assumes source is bad */
939
    LPSPropValue lpDest = lpProps;
940
    ULONG ulCount = cValues * sizeof(SPropValue);
941 942
    ULONG ulLen, i;
    int iter;
943

944
    TRACE("(%d,%p,%p,%p,%p)\n", cValues, lpProps, lpOld, lpNew, lpCount);
945

946 947 948 949 950 951 952 953 954 955 956 957 958
    if (!lpProps || cValues < 0 || !lpOld || !lpNew)
        return MAPI_E_INVALID_PARAMETER;

    /* The reason native doesn't work as MSDN states is that it assumes that
     * the lpProps pointer contains valid pointers. This is obviously not
     * true if the array is being read back from serialisation (the pointers
     * are just offsets). Native can't actually work converting the pointers to
     * offsets either, because it converts any array pointers to offsets then
     * _dereferences the offset_ in order to convert the array elements!
     *
     * The code below would handle both cases except that the design of this
     * function makes it impossible to know when the pointers in lpProps are
     * valid. If both lpOld and lpNew are non-NULL, native reads the pointers
959
     * after converting them, so we must do the same. It seems this
960 961
     * functionality was never tested by MS.
     */
962

963
#define RELOC_PTR(p) (((char*)(p)) - (char*)lpOld + (char*)lpNew)
964 965

    for (iter = 0; iter < cValues; iter++)
966 967 968 969 970 971 972 973 974
    {
        switch (PROP_TYPE(lpDest->ulPropTag))
        {
        case PT_CLSID:
            lpDest->Value.lpguid = (LPGUID)RELOC_PTR(lpDest->Value.lpguid);
            ulCount += sizeof(GUID);
            break;
        case PT_STRING8:
            ulLen = bBadPtr ? 0 : lstrlenA(lpDest->Value.lpszA) + 1u;
975
            lpDest->Value.lpszA = RELOC_PTR(lpDest->Value.lpszA);
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998
            if (bBadPtr)
                ulLen = lstrlenA(lpDest->Value.lpszA) + 1u;
            ulCount += ulLen;
            break;
        case PT_UNICODE:
            ulLen = bBadPtr ? 0 : (lstrlenW(lpDest->Value.lpszW) + 1u) * sizeof(WCHAR);
            lpDest->Value.lpszW = (LPWSTR)RELOC_PTR(lpDest->Value.lpszW);
            if (bBadPtr)
                ulLen = (strlenW(lpDest->Value.lpszW) + 1u) * sizeof(WCHAR);
            ulCount += ulLen;
            break;
        case PT_BINARY:
            lpDest->Value.bin.lpb = (LPBYTE)RELOC_PTR(lpDest->Value.bin.lpb);
            ulCount += lpDest->Value.bin.cb;
            break;
        default:
            if (lpDest->ulPropTag & MV_FLAG)
            {
                /* Since we have to access the array elements, don't map the
                 * array unless it is invalid (otherwise, map it at the end)
                 */
                if (bBadPtr)
                    lpDest->Value.MVszA.lppszA = (LPSTR*)RELOC_PTR(lpDest->Value.MVszA.lppszA);
999

1000 1001 1002 1003 1004 1005 1006 1007 1008
                switch (PROP_TYPE(lpProps->ulPropTag))
                {
                case PT_MV_STRING8:
                {
                    ulCount += lpDest->Value.MVszA.cValues * sizeof(char *);

                    for (i = 0; i < lpDest->Value.MVszA.cValues; i++)
                    {
                        ULONG ulStrLen = bBadPtr ? 0 : lstrlenA(lpDest->Value.MVszA.lppszA[i]) + 1u;
1009

1010
                        lpDest->Value.MVszA.lppszA[i] = RELOC_PTR(lpDest->Value.MVszA.lppszA[i]);
1011 1012 1013 1014 1015 1016 1017 1018 1019
                        if (bBadPtr)
                            ulStrLen = lstrlenA(lpDest->Value.MVszA.lppszA[i]) + 1u;
                        ulCount += ulStrLen;
                    }
                    break;
                }
                case PT_MV_UNICODE:
                {
                    ulCount += lpDest->Value.MVszW.cValues * sizeof(WCHAR *);
1020

1021 1022 1023
                    for (i = 0; i < lpDest->Value.MVszW.cValues; i++)
                    {
                        ULONG ulStrLen = bBadPtr ? 0 : (strlenW(lpDest->Value.MVszW.lppszW[i]) + 1u) * sizeof(WCHAR);
1024

1025 1026 1027 1028
                        lpDest->Value.MVszW.lppszW[i] = (LPWSTR)RELOC_PTR(lpDest->Value.MVszW.lppszW[i]);
                        if (bBadPtr)
                            ulStrLen = (strlenW(lpDest->Value.MVszW.lppszW[i]) + 1u) * sizeof(WCHAR);
                        ulCount += ulStrLen;
1029
                    }
1030 1031 1032 1033 1034
                    break;
                }
                case PT_MV_BINARY:
                {
                    ulCount += lpDest->Value.MVszW.cValues * sizeof(SBinary);
1035

1036 1037 1038 1039
                    for (i = 0; i < lpDest->Value.MVszW.cValues; i++)
                    {
                        lpDest->Value.MVbin.lpbin[i].lpb = (LPBYTE)RELOC_PTR(lpDest->Value.MVbin.lpbin[i].lpb);
                        ulCount += lpDest->Value.MVbin.lpbin[i].cb;
1040
                    }
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
                    break;
                }
                default:
                    ulCount += UlPropSize(lpDest);
                    break;
                }
                if (!bBadPtr)
                    lpDest->Value.MVszA.lppszA = (LPSTR*)RELOC_PTR(lpDest->Value.MVszA.lppszA);
                break;
            }
        }
        lpDest++;
    }
    if (lpCount)
        *lpCount = ulCount;
1056

1057 1058 1059
    return S_OK;
}

1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
/*************************************************************************
 * LpValFindProp@12 (MAPI32.173)
 *
 * Find a property with a given property id in a property array.
 *
 * PARAMS
 *  ulPropTag [I] Property tag containing property id to find
 *  cValues   [I] Number of properties in lpProps
 *  lpProps   [I] Property array to search
 *
 * RETURNS
 *  A pointer to the matching property, or NULL if none was found.
 *
 * NOTES
 *  This function matches only on the property id and does not care if the
 *  property types differ.
 */
LPSPropValue WINAPI LpValFindProp(ULONG ulPropTag, ULONG cValues, LPSPropValue lpProps)
{
1079
    TRACE("(%d,%d,%p)\n", ulPropTag, cValues, lpProps);
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092

    if (lpProps && cValues)
    {
        ULONG i;
        for (i = 0; i < cValues; i++)
        {
            if (PROP_ID(ulPropTag) == PROP_ID(lpProps[i].ulPropTag))
                return &lpProps[i];
        }
    }
    return NULL;
}

1093 1094 1095
/*************************************************************************
 * ScDupPropset@16 (MAPI32.174)
 *
1096
 * Duplicate a property value array into a contiguous block of memory.
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
 *
 * PARAMS
 *  cValues   [I] Number of properties in lpProps
 *  lpProps   [I] Property array to duplicate
 *  lpAlloc   [I] Memory allocation function, use MAPIAllocateBuffer()
 *  lpNewProp [O] Destination for the newly duplicated property value array
 *
 * RETURNS
 *  Success: S_OK. *lpNewProp contains the duplicated array.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
 *           MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
 */
SCODE WINAPI ScDupPropset(int cValues, LPSPropValue lpProps,
                          LPALLOCATEBUFFER lpAlloc, LPSPropValue *lpNewProp)
{
    ULONG ulCount;
    SCODE sc;

    TRACE("(%d,%p,%p,%p)\n", cValues, lpProps, lpAlloc, lpNewProp);

    sc = ScCountProps(cValues, lpProps, &ulCount);
    if (SUCCEEDED(sc))
    {
        sc = lpAlloc(ulCount, (LPVOID*)lpNewProp);
        if (SUCCEEDED(sc))
            sc = ScCopyProps(cValues, lpProps, *lpNewProp, &ulCount);
    }
    return sc;
}

1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
/*************************************************************************
 * FBadRglpszA@8 (MAPI32.175)
 *
 * Determine if an array of strings is invalid
 *
 * PARAMS
 *  lppszStrs [I] Array of strings to check
 *  ulCount   [I] Number of strings in lppszStrs
 *
 * RETURNS
 *  TRUE, if lppszStrs is invalid, FALSE otherwise.
 */
BOOL WINAPI FBadRglpszA(LPSTR *lppszStrs, ULONG ulCount)
{
    ULONG i;

1143
    TRACE("(%p,%d)\n", lppszStrs, ulCount);
1144 1145 1146

    if (!ulCount)
        return FALSE;
1147

1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
    if (!lppszStrs || IsBadReadPtr(lppszStrs, ulCount * sizeof(LPWSTR)))
        return TRUE;

    for (i = 0; i < ulCount; i++)
    {
        if (!lppszStrs[i] || IsBadStringPtrA(lppszStrs[i], -1))
            return TRUE;
    }
    return FALSE;
}

/*************************************************************************
 * FBadRglpszW@8 (MAPI32.176)
 *
 * See FBadRglpszA.
 */
BOOL WINAPI FBadRglpszW(LPWSTR *lppszStrs, ULONG ulCount)
{
    ULONG i;

1168
    TRACE("(%p,%d)\n", lppszStrs, ulCount);
1169 1170 1171

    if (!ulCount)
        return FALSE;
1172

1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
    if (!lppszStrs || IsBadReadPtr(lppszStrs, ulCount * sizeof(LPWSTR)))
        return TRUE;

    for (i = 0; i < ulCount; i++)
    {
        if (!lppszStrs[i] || IsBadStringPtrW(lppszStrs[i], -1))
            return TRUE;
    }
    return FALSE;
}

/*************************************************************************
 * FBadRowSet@4 (MAPI32.177)
 *
 * Determine if a row is invalid
 *
 * PARAMS
 *  lpRow [I] Row to check
 *
 * RETURNS
 *  TRUE, if lpRow is invalid, FALSE otherwise.
 */
BOOL WINAPI FBadRowSet(LPSRowSet lpRowSet)
{
    ULONG i;
    TRACE("(%p)\n", lpRowSet);

    if (!lpRowSet || IsBadReadPtr(lpRowSet, CbSRowSet(lpRowSet)))
        return TRUE;

    for (i = 0; i < lpRowSet->cRows; i++)
    {
        if (FBadRow(&lpRowSet->aRow[i]))
            return TRUE;
    }
    return FALSE;
}

/*************************************************************************
 * FBadPropTag@4 (MAPI32.179)
 *
 * Determine if a property tag is invalid
 *
 * PARAMS
 *  ulPropTag [I] Property tag to check
 *
 * RETURNS
 *  TRUE, if ulPropTag is invalid, FALSE otherwise.
 */
ULONG WINAPI FBadPropTag(ULONG ulPropTag)
{
1224
    TRACE("(0x%08x)\n", ulPropTag);
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341

    switch (ulPropTag & (~MV_FLAG & PROP_TYPE_MASK))
    {
    case PT_UNSPECIFIED:
    case PT_NULL:
    case PT_I2:
    case PT_LONG:
    case PT_R4:
    case PT_DOUBLE:
    case PT_CURRENCY:
    case PT_APPTIME:
    case PT_ERROR:
    case PT_BOOLEAN:
    case PT_OBJECT:
    case PT_I8:
    case PT_STRING8:
    case PT_UNICODE:
    case PT_SYSTIME:
    case PT_CLSID:
    case PT_BINARY:
        return FALSE;
    }
    return TRUE;
}

/*************************************************************************
 * FBadRow@4 (MAPI32.180)
 *
 * Determine if a row is invalid
 *
 * PARAMS
 *  lpRow [I] Row to check
 *
 * RETURNS
 *  TRUE, if lpRow is invalid, FALSE otherwise.
 */
ULONG WINAPI FBadRow(LPSRow lpRow)
{
    ULONG i;
    TRACE("(%p)\n", lpRow);

    if (!lpRow || IsBadReadPtr(lpRow, sizeof(SRow)) || !lpRow->lpProps ||
        IsBadReadPtr(lpRow->lpProps, lpRow->cValues * sizeof(SPropValue)))
        return TRUE;

    for (i = 0; i < lpRow->cValues; i++)
    {
        if (FBadProp(&lpRow->lpProps[i]))
            return TRUE;
    }
    return FALSE;
}

/*************************************************************************
 * FBadProp@4 (MAPI32.181)
 *
 * Determine if a property is invalid
 *
 * PARAMS
 *  lpProp [I] Property to check
 *
 * RETURNS
 *  TRUE, if lpProp is invalid, FALSE otherwise.
 */
ULONG WINAPI FBadProp(LPSPropValue lpProp)
{
    if (!lpProp || IsBadReadPtr(lpProp, sizeof(SPropValue)) ||
        FBadPropTag(lpProp->ulPropTag))
        return TRUE;

    switch (PROP_TYPE(lpProp->ulPropTag))
    {
    /* Single value properties containing pointers */
    case PT_STRING8:
        if (!lpProp->Value.lpszA || IsBadStringPtrA(lpProp->Value.lpszA, -1))
            return TRUE;
        break;
    case PT_UNICODE:
        if (!lpProp->Value.lpszW || IsBadStringPtrW(lpProp->Value.lpszW, -1))
            return TRUE;
        break;
    case PT_BINARY:
        if (IsBadReadPtr(lpProp->Value.bin.lpb, lpProp->Value.bin.cb))
            return TRUE;
        break;
    case PT_CLSID:
        if (IsBadReadPtr(lpProp->Value.lpguid, sizeof(GUID)))
            return TRUE;
        break;

    /* Multiple value properties (arrays) containing no pointers */
    case PT_MV_I2:
        return PROP_BadArray(lpProp, sizeof(SHORT));
    case PT_MV_LONG:
        return PROP_BadArray(lpProp, sizeof(LONG));
    case PT_MV_LONGLONG:
        return PROP_BadArray(lpProp, sizeof(LONG64));
    case PT_MV_FLOAT:
        return PROP_BadArray(lpProp, sizeof(float));
    case PT_MV_SYSTIME:
        return PROP_BadArray(lpProp, sizeof(FILETIME));
    case PT_MV_APPTIME:
    case PT_MV_DOUBLE:
        return PROP_BadArray(lpProp, sizeof(double));
    case PT_MV_CURRENCY:
        return PROP_BadArray(lpProp, sizeof(CY));
    case PT_MV_CLSID:
        return PROP_BadArray(lpProp, sizeof(GUID));

    /* Multiple value properties containing pointers */
    case PT_MV_STRING8:
        return FBadRglpszA(lpProp->Value.MVszA.lppszA,
                           lpProp->Value.MVszA.cValues);
    case PT_MV_UNICODE:
        return FBadRglpszW(lpProp->Value.MVszW.lppszW,
                           lpProp->Value.MVszW.cValues);
    case PT_MV_BINARY:
1342
        return FBadEntryList(&lpProp->Value.MVbin);
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
    }
    return FALSE;
}

/*************************************************************************
 * FBadColumnSet@4 (MAPI32.182)
 *
 * Determine if an array of property tags is invalid
 *
 * PARAMS
 *  lpCols [I] Property tag array to check
 *
 * RETURNS
 *  TRUE, if lpCols is invalid, FALSE otherwise.
 */
ULONG WINAPI FBadColumnSet(LPSPropTagArray lpCols)
{
    ULONG ulRet = FALSE, i;

    TRACE("(%p)\n", lpCols);

    if (!lpCols || IsBadReadPtr(lpCols, CbSPropTagArray(lpCols)))
        ulRet = TRUE;
    else
    {
        for (i = 0; i < lpCols->cValues; i++)
        {
            if ((lpCols->aulPropTag[i] & PROP_TYPE_MASK) == PT_ERROR ||
                FBadPropTag(lpCols->aulPropTag[i]))
            {
                ulRet = TRUE;
                break;
            }
        }
    }
    TRACE("Returning %s\n", ulRet ? "TRUE" : "FALSE");
    return ulRet;
}
1381 1382 1383


/**************************************************************************
1384
 *  IPropData {MAPI32}
1385
 *
1386
 * A default Mapi interface to provide manipulation of object properties.
1387 1388
 *
 * DESCRIPTION
1389 1390 1391 1392 1393 1394 1395 1396
 *  This object provides a default interface suitable in some cases as an
 *  implementation of the IMAPIProp interface (which has no default
 *  implementation). In addition to the IMAPIProp() methods inherited, this
 *  interface allows read/write control over access to the object and its
 *  individual properties.
 *
 *  To obtain the default implementation of this interface from Mapi, call
 *  CreateIProp().
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
 *
 * METHODS
 */

/* A single property in a property data collection */
typedef struct
{
  struct list  entry;
  ULONG        ulAccess; /* The property value access level */
  LPSPropValue value;    /* The property value */
} IPropDataItem, *LPIPropDataItem;

 /* The main property data collection structure */
typedef struct
{
1412
    IPropData        IPropData_iface;
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
    LONG             lRef;        /* Reference count */
    ALLOCATEBUFFER  *lpAlloc;     /* Memory allocation routine */
    ALLOCATEMORE    *lpMore;      /* Linked memory allocation routine */
    FREEBUFFER      *lpFree;      /* Memory free routine */
    ULONG            ulObjAccess; /* Object access level */
    ULONG            ulNumValues; /* Number of items in values list */
    struct list      values;      /* List of property values */
    CRITICAL_SECTION cs;          /* Lock for thread safety */
} IPropDataImpl;

1423 1424 1425 1426 1427
static inline IPropDataImpl *impl_from_IPropData(IPropData *iface)
{
    return CONTAINING_RECORD(iface, IPropDataImpl, IPropData_iface);
}

1428 1429 1430 1431 1432 1433 1434 1435
/* Internal - Get a property value, assumes lock is held */
static IPropDataItem *IMAPIPROP_GetValue(IPropDataImpl *This, ULONG ulPropTag)
{
    struct list *cursor;

    LIST_FOR_EACH(cursor, &This->values)
    {
        LPIPropDataItem current = LIST_ENTRY(cursor, IPropDataItem, entry);
1436
        /* Note that property types don't have to match, just Id's */
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
        if (PROP_ID(current->value->ulPropTag) == PROP_ID(ulPropTag))
            return current;
    }
    return NULL;
}

/* Internal - Add a new property value, assumes lock is held */
static IPropDataItem *IMAPIPROP_AddValue(IPropDataImpl *This,
                                         LPSPropValue lpProp)
{
    LPVOID lpMem;
    LPIPropDataItem lpNew;
    HRESULT hRet;

    hRet = This->lpAlloc(sizeof(IPropDataItem), &lpMem);

    if (SUCCEEDED(hRet))
    {
        lpNew = lpMem;
        lpNew->ulAccess = IPROP_READWRITE;

1458
        /* Allocate the value separately so we can update it easily */
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
        lpMem = NULL;
        hRet = This->lpAlloc(sizeof(SPropValue), &lpMem);
        if (SUCCEEDED(hRet))
        {
            lpNew->value = lpMem;

            hRet = PropCopyMore(lpNew->value, lpProp, This->lpMore, lpMem);
            if (SUCCEEDED(hRet))
            {
                list_add_tail(&This->values, &lpNew->entry);
                This->ulNumValues++;
                return lpNew;
            }
            This->lpFree(lpNew->value);
        }
        This->lpFree(lpNew);
    }
    return NULL;
}

/* Internal - Lock an IPropData object */
static inline void IMAPIPROP_Lock(IPropDataImpl *This)
{
1482
    EnterCriticalSection(&This->cs);
1483 1484 1485 1486 1487
}

/* Internal - Unlock an IPropData object */
static inline void IMAPIPROP_Unlock(IPropDataImpl *This)
{
1488
    LeaveCriticalSection(&This->cs);
1489 1490 1491 1492 1493 1494 1495
}

/* This one seems to be missing from mapidefs.h */
#define CbNewSPropProblemArray(c) \
    (offsetof(SPropProblemArray,aProblem)+(c)*sizeof(SPropProblem))

/**************************************************************************
1496
 *  IPropData_QueryInterface {MAPI32}
1497 1498 1499 1500
 *
 * Inherited method from the IUnknown Interface.
 * See IUnknown_QueryInterface.
 */
1501
static WINAPI HRESULT IPropData_fnQueryInterface(LPPROPDATA iface, REFIID riid, LPVOID *ppvObj)
1502
{
1503
    IPropDataImpl *This = impl_from_IPropData(iface);
1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515

    TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppvObj);

    if (!ppvObj || !riid)
        return MAPI_E_INVALID_PARAMETER;

    *ppvObj = NULL;

    if(IsEqualIID(riid, &IID_IUnknown) ||
       IsEqualIID(riid, &IID_IMAPIProp) ||
       IsEqualIID(riid, &IID_IMAPIPropData))
    {
1516
        *ppvObj = &This->IPropData_iface;
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526
        IPropData_AddRef(iface);
        TRACE("returning %p\n", *ppvObj);
        return S_OK;
    }

    TRACE("returning E_NOINTERFACE\n");
    return MAPI_E_INTERFACE_NOT_SUPPORTED;
}

/**************************************************************************
1527
 *  IPropData_AddRef {MAPI32}
1528 1529 1530 1531
 *
 * Inherited method from the IUnknown Interface.
 * See IUnknown_AddRef.
 */
1532
static ULONG WINAPI IPropData_fnAddRef(LPPROPDATA iface)
1533
{
1534
    IPropDataImpl *This = impl_from_IPropData(iface);
1535

1536
    TRACE("(%p)->(count before=%u)\n", This, This->lRef);
1537 1538 1539 1540 1541

    return InterlockedIncrement(&This->lRef);
}

/**************************************************************************
1542
 *  IPropData_Release {MAPI32}
1543 1544 1545 1546
 *
 * Inherited method from the IUnknown Interface.
 * See IUnknown_Release.
 */
1547
static ULONG WINAPI IPropData_fnRelease(LPPROPDATA iface)
1548
{
1549
    IPropDataImpl *This = impl_from_IPropData(iface);
1550
    LONG lRef;
1551

1552
    TRACE("(%p)->(count before=%u)\n", This, This->lRef);
1553

1554 1555
    lRef = InterlockedDecrement(&This->lRef);
    if (!lRef)
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567
    {
        TRACE("Destroying IPropData (%p)\n",This);

        /* Note: No need to lock, since no other thread is referencing iface */
        while (!list_empty(&This->values))
        {
            struct list *head = list_head(&This->values);
            LPIPropDataItem current = LIST_ENTRY(head, IPropDataItem, entry);
            list_remove(head);
            This->lpFree(current->value);
            This->lpFree(current);
        }
1568
        This->cs.DebugInfo->Spare[0] = 0;
1569
        DeleteCriticalSection(&This->cs);
1570 1571
        This->lpFree(This);
    }
1572
    return (ULONG)lRef;
1573 1574 1575
}

/**************************************************************************
1576
 *  IPropData_GetLastError {MAPI32}
1577
 *
1578
 * Get information about the last error that occurred in an IMAPIProp object.
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
 *
 * PARAMS
 *  iface    [I] IMAPIProp object that experienced the error
 *  hRes     [I] Result of the call that returned an error
 *  ulFlags  [I] 0=return Ascii strings, MAPI_UNICODE=return Unicode strings
 *  lppError [O] Destination for detailed error information
 *
 * RETURNS
 *  Success: S_OK. *lppError contains details about the last error.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid,
 *           MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
 *
 * NOTES
 *  - If this function succeeds, the returned information in *lppError must be
 *  freed using MAPIFreeBuffer() once the caller is finished with it.
Austin English's avatar
Austin English committed
1594
 *  - It is possible for this function to succeed and set *lppError to NULL,
1595 1596
 *  if there is no further information to report about hRes.
 */
1597 1598
static HRESULT WINAPI IPropData_fnGetLastError(LPPROPDATA iface, HRESULT hRes, ULONG ulFlags,
                                               LPMAPIERROR *lppError)
1599
{
1600
    TRACE("(%p,0x%08X,0x%08X,%p)\n", iface, hRes, ulFlags, lppError);
1601 1602 1603 1604 1605 1606 1607 1608 1609

    if (!lppError  || SUCCEEDED(hRes) || (ulFlags & ~MAPI_UNICODE))
        return MAPI_E_INVALID_PARAMETER;

    *lppError = NULL;
    return S_OK;
}

/**************************************************************************
1610
 *  IPropData_SaveChanges {MAPI32}
1611
 *
Austin English's avatar
Austin English committed
1612
 * Update any changes made to a transactional IMAPIProp object.
1613 1614 1615 1616 1617 1618 1619 1620 1621
 *
 * PARAMS
 *  iface    [I] IMAPIProp object to update
 *  ulFlags  [I] Flags controlling the update.
 *
 * RETURNS
 *  Success: S_OK. Any outstanding changes are committed to the object.
 *  Failure: An HRESULT error code describing the error.
 */
1622
static HRESULT WINAPI IPropData_fnSaveChanges(LPPROPDATA iface, ULONG ulFlags)
1623
{
1624
    TRACE("(%p,0x%08X)\n", iface, ulFlags);
1625 1626 1627 1628 1629 1630 1631

     /* Since this object is not transacted we do not need to implement this */
     /* FIXME: Should we set the access levels to clean? */
    return S_OK;
}

/**************************************************************************
1632
 *  IPropData_GetProps {MAPI32}
1633 1634 1635 1636 1637
 *
 * Get property values from an IMAPIProp object.
 *
 * PARAMS
 *  iface    [I] IMAPIProp object to get the property values from
1638
 *  lpTags   [I] Property tags of property values to be retrieved
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651
 *  ulFlags  [I] Return 0=Ascii MAPI_UNICODE=Unicode strings for
 *                 unspecified types
 *  lpCount  [O] Destination for number of properties returned
 *  lppProps [O] Destination for returned property values
 *
 * RETURNS
 *  Success: S_OK. *lppProps and *lpCount are updated.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
 *           MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
 *           MAPI_W_ERRORS_RETURNED if not all properties were retrieved
 *           successfully.
 * NOTES
 *  - If MAPI_W_ERRORS_RETURNED is returned, any properties that could not be
1652
 *    retrieved from iface are present in lppProps with their type
1653 1654
 *    changed to PT_ERROR and Id unchanged.
 */
1655 1656
static HRESULT WINAPI IPropData_fnGetProps(LPPROPDATA iface, LPSPropTagArray lpTags, ULONG ulFlags,
                                           ULONG *lpCount, LPSPropValue *lppProps)
1657
{
1658
    IPropDataImpl *This = impl_from_IPropData(iface);
1659 1660 1661
    ULONG i;
    HRESULT hRet = S_OK;

1662
    TRACE("(%p,%p,0x%08x,%p,%p) stub\n", iface, lpTags, ulFlags,
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712
          lpCount, lppProps);

    if (!iface || ulFlags & ~MAPI_UNICODE || !lpTags || *lpCount || !lppProps)
        return MAPI_E_INVALID_PARAMETER;

    FIXME("semi-stub, flags not supported\n");

    *lpCount = lpTags->cValues;
    *lppProps = NULL;

    if (*lpCount)
    {
        hRet = MAPIAllocateBuffer(*lpCount * sizeof(SPropValue), (LPVOID*)lppProps);
        if (FAILED(hRet))
            return hRet;

        IMAPIPROP_Lock(This);

        for (i = 0; i < lpTags->cValues; i++)
        {
            HRESULT hRetTmp = E_INVALIDARG;
            LPIPropDataItem item;

            item = IMAPIPROP_GetValue(This, lpTags->aulPropTag[i]);

            if (item)
                hRetTmp = PropCopyMore(&(*lppProps)[i], item->value,
                                       This->lpMore, *lppProps);
            if (FAILED(hRetTmp))
            {
                hRet = MAPI_W_ERRORS_RETURNED;
                (*lppProps)[i].ulPropTag =
                    CHANGE_PROP_TYPE(lpTags->aulPropTag[i], PT_ERROR);
            }
        }

        IMAPIPROP_Unlock(This);
    }
    return hRet;
}

/**************************************************************************
 *  MAPIProp_GetPropList {MAPI32}
 *
 * Get the list of property tags for all values in an IMAPIProp object.
 *
 * PARAMS
 *  iface   [I] IMAPIProp object to get the property tag list from
 *  ulFlags [I] Return 0=Ascii MAPI_UNICODE=Unicode strings for
 *              unspecified types
Austin English's avatar
Austin English committed
1713
 *  lppTags [O] Destination for the retrieved property tag list
1714 1715 1716 1717 1718 1719 1720
 *
 * RETURNS
 *  Success: S_OK. *lppTags contains the tags for all available properties.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
 *           MAPI_E_BAD_CHARWIDTH, if Ascii or Unicode strings are requested
 *           and that type of string is not supported.
 */
1721 1722
static HRESULT WINAPI IPropData_fnGetPropList(LPPROPDATA iface, ULONG ulFlags,
                                              LPSPropTagArray *lppTags)
1723
{
1724
    IPropDataImpl *This = impl_from_IPropData(iface);
1725 1726 1727
    ULONG i;
    HRESULT hRet;

1728
    TRACE("(%p,0x%08x,%p) stub\n", iface, ulFlags, lppTags);
1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759

    if (!iface || ulFlags & ~MAPI_UNICODE || !lppTags)
        return MAPI_E_INVALID_PARAMETER;

    FIXME("semi-stub, flags not supported\n");

    *lppTags = NULL;

    IMAPIPROP_Lock(This);

    hRet = MAPIAllocateBuffer(CbNewSPropTagArray(This->ulNumValues),
                              (LPVOID*)lppTags);
    if (SUCCEEDED(hRet))
    {
        struct list *cursor;

        i = 0;
        LIST_FOR_EACH(cursor, &This->values)
        {
            LPIPropDataItem current = LIST_ENTRY(cursor, IPropDataItem, entry);
            (*lppTags)->aulPropTag[i] = current->value->ulPropTag;
            i++;
        }
        (*lppTags)->cValues = This->ulNumValues;
    }

    IMAPIPROP_Unlock(This);
    return hRet;
}

/**************************************************************************
1760
 *  IPropData_OpenProperty {MAPI32}
1761 1762 1763 1764 1765 1766
 *
 * Not documented at this time.
 *
 * RETURNS
 *  An HRESULT success/failure code.
 */
1767 1768
static HRESULT WINAPI IPropData_fnOpenProperty(LPPROPDATA iface, ULONG ulPropTag, LPCIID iid,
                                               ULONG ulOpts, ULONG ulFlags, LPUNKNOWN *lpUnk)
1769
{
1770
    FIXME("(%p,%u,%s,%u,0x%08x,%p) stub\n", iface, ulPropTag,
1771 1772 1773 1774 1775 1776
          debugstr_guid(iid), ulOpts, ulFlags, lpUnk);
    return MAPI_E_NO_SUPPORT;
}


/**************************************************************************
1777
 *  IPropData_SetProps {MAPI32}
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
 *
 * Add or edit the property values in an IMAPIProp object.
 *
 * PARAMS
 *  iface    [I] IMAPIProp object to get the property tag list from
 *  ulValues [I] Number of properties in lpProps
 *  lpProps  [I] Property values to set
 *  lppProbs [O] Optional destination for any problems that occurred
 *
 * RETURNS
 *  Success: S_OK. The properties in lpProps are added to iface if they don't
 *           exist, or changed to the values in lpProps if they do
 *  Failure: An HRESULT error code describing the error
 */
1792 1793
static HRESULT WINAPI IPropData_fnSetProps(LPPROPDATA iface, ULONG ulValues, LPSPropValue lpProps,
                                           LPSPropProblemArray *lppProbs)
1794
{
1795
    IPropDataImpl *This = impl_from_IPropData(iface);
1796 1797 1798
    HRESULT hRet = S_OK;
    ULONG i;

1799
    TRACE("(%p,%u,%p,%p)\n", iface, ulValues, lpProps, lppProbs);
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844

    if (!iface || !lpProps)
      return MAPI_E_INVALID_PARAMETER;

    for (i = 0; i < ulValues; i++)
    {
        if (FBadProp(&lpProps[i]) ||
            PROP_TYPE(lpProps[i].ulPropTag) == PT_OBJECT ||
            PROP_TYPE(lpProps[i].ulPropTag) == PT_NULL)
          return MAPI_E_INVALID_PARAMETER;
    }

    IMAPIPROP_Lock(This);

    /* FIXME: Under what circumstances is lpProbs created? */
    for (i = 0; i < ulValues; i++)
    {
        LPIPropDataItem item = IMAPIPROP_GetValue(This, lpProps[i].ulPropTag);

        if (item)
        {
            HRESULT hRetTmp;
            LPVOID lpMem = NULL;

            /* Found, so update the existing value */
            if (item->value->ulPropTag != lpProps[i].ulPropTag)
                FIXME("semi-stub, overwriting type (not coercing)\n");

            hRetTmp = This->lpAlloc(sizeof(SPropValue), &lpMem);
            if (SUCCEEDED(hRetTmp))
            {
                hRetTmp = PropCopyMore(lpMem, &lpProps[i], This->lpMore, lpMem);
                if (SUCCEEDED(hRetTmp))
                {
                    This->lpFree(item->value);
                    item->value = lpMem;
                    continue;
                }
                This->lpFree(lpMem);
            }
            hRet = hRetTmp;
        }
        else
        {
            /* Add new value */
1845
            if (!IMAPIPROP_AddValue(This, &lpProps[i]))
1846 1847 1848 1849 1850 1851 1852 1853 1854
                hRet = MAPI_E_NOT_ENOUGH_MEMORY;
        }
    }

    IMAPIPROP_Unlock(This);
    return hRet;
}

/**************************************************************************
1855
 *  IPropData_DeleteProps {MAPI32}
1856
 *
1857
 * Delete one or more property values from an IMAPIProp object.
1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869
 *
 * PARAMS
 *  iface    [I] IMAPIProp object to remove property values from.
 *  lpTags   [I] Collection of property Id's to remove from iface.
 *  lppProbs [O] Destination for problems encountered, if any.
 *
 * RETURNS
 *  Success: S_OK. Any properties in iface matching property Id's in lpTags have
 *           been deleted. If lppProbs is non-NULL it contains details of any
 *           errors that occurred.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
 *           E_ACCESSDENIED, if this object was created using CreateIProp() and
1870
 *           a subsequent call to IPropData_SetObjAccess() was made specifying
1871 1872 1873 1874 1875 1876 1877
 *           IPROP_READONLY as the access type.
 *
 * NOTES
 *  - lppProbs will not be populated for cases where a property Id is present
 *    in lpTags but not in iface.
 *  - lppProbs should be deleted with MAPIFreeBuffer() if returned.
 */
1878 1879
static HRESULT WINAPI IPropData_fnDeleteProps(LPPROPDATA iface, LPSPropTagArray lpTags,
                                              LPSPropProblemArray *lppProbs)
1880
{
1881
    IPropDataImpl *This = impl_from_IPropData(iface);
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
    ULONG i, numProbs = 0;
    HRESULT hRet = S_OK;

    TRACE("(%p,%p,%p)\n", iface, lpTags, lppProbs);

    if (!iface || !lpTags)
        return MAPI_E_INVALID_PARAMETER;

    if (lppProbs)
        *lppProbs = NULL;

    for (i = 0; i < lpTags->cValues; i++)
    {
        if (FBadPropTag(lpTags->aulPropTag[i]) ||
            PROP_TYPE(lpTags->aulPropTag[i]) == PT_OBJECT ||
            PROP_TYPE(lpTags->aulPropTag[i]) == PT_NULL)
          return MAPI_E_INVALID_PARAMETER;
    }

    IMAPIPROP_Lock(This);

    if (This->ulObjAccess != IPROP_READWRITE)
    {
        IMAPIPROP_Unlock(This);
        return E_ACCESSDENIED;
    }

    for (i = 0; i < lpTags->cValues; i++)
    {
        LPIPropDataItem item = IMAPIPROP_GetValue(This, lpTags->aulPropTag[i]);

        if (item)
        {
            if (item->ulAccess & IPROP_READWRITE)
            {
                /* Everything hunky-dory, remove the item */
                list_remove(&item->entry);
                This->lpFree(item->value); /* Also frees value pointers */
                This->lpFree(item);
                This->ulNumValues--;
            }
            else if (lppProbs)
            {
                 /* Can't write the value. Create/populate problems array */
                 if (!*lppProbs)
                 {
                     /* Create problems array */
                     ULONG ulSize = CbNewSPropProblemArray(lpTags->cValues - i);
                     HRESULT hRetTmp = MAPIAllocateBuffer(ulSize, (LPVOID*)lppProbs);
                     if (FAILED(hRetTmp))
                         hRet = hRetTmp;
                 }
                 if (*lppProbs)
                 {
                     LPSPropProblem lpProb = &(*lppProbs)->aProblem[numProbs];
                     lpProb->ulIndex = i;
                     lpProb->ulPropTag = lpTags->aulPropTag[i];
                     lpProb->scode = E_ACCESSDENIED;
                     numProbs++;
                 }
            }
        }
    }
    if (lppProbs && *lppProbs)
        (*lppProbs)->cProblem = numProbs;

    IMAPIPROP_Unlock(This);
    return hRet;
}


/**************************************************************************
1954
 *  IPropData_CopyTo {MAPI32}
1955 1956 1957 1958 1959 1960
 *
 * Not documented at this time.
 *
 * RETURNS
 *  An HRESULT success/failure code.
 */
1961 1962 1963 1964 1965
static HRESULT WINAPI IPropData_fnCopyTo(LPPROPDATA iface, ULONG niids, LPCIID lpiidExcl,
                                         LPSPropTagArray lpPropsExcl, ULONG ulParam,
                                         LPMAPIPROGRESS lpIProgress, LPCIID lpIfaceIid,
                                         LPVOID lpDstObj, ULONG ulFlags,
                                         LPSPropProblemArray *lppProbs)
1966
{
1967
    FIXME("(%p,%u,%p,%p,%x,%p,%s,%p,0x%08X,%p) stub\n", iface, niids,
1968 1969 1970 1971 1972 1973
          lpiidExcl, lpPropsExcl, ulParam, lpIProgress,
          debugstr_guid(lpIfaceIid), lpDstObj, ulFlags, lppProbs);
    return MAPI_E_NO_SUPPORT;
}

/**************************************************************************
1974
 *  IPropData_CopyProps {MAPI32}
1975 1976 1977 1978 1979 1980
 *
 * Not documented at this time.
 *
 * RETURNS
 *  An HRESULT success/failure code.
 */
1981 1982 1983 1984
static HRESULT WINAPI IPropData_fnCopyProps(LPPROPDATA iface, LPSPropTagArray lpInclProps,
                                            ULONG ulParam, LPMAPIPROGRESS lpIProgress,
                                            LPCIID lpIface, LPVOID lpDstObj, ULONG ulFlags,
                                            LPSPropProblemArray *lppProbs)
1985
{
1986
    FIXME("(%p,%p,%x,%p,%s,%p,0x%08X,%p) stub\n", iface, lpInclProps,
1987 1988 1989 1990 1991 1992
          ulParam, lpIProgress, debugstr_guid(lpIface), lpDstObj, ulFlags,
          lppProbs);
    return MAPI_E_NO_SUPPORT;
}

/**************************************************************************
1993
 *  IPropData_GetNamesFromIDs {MAPI32}
1994
 *
1995
 * Get the names of properties from their identifiers.
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014
 *
 * PARAMS
 *  iface       [I]   IMAPIProp object to operate on
 *  lppPropTags [I/O] Property identifiers to get the names for, or NULL to
 *                    get all names
 *  iid         [I]   Property set identifier, or NULL
 *  ulFlags     [I]   MAPI_NO_IDS=Don't return numeric named properties,
 *                    or MAPI_NO_STRINGS=Don't return strings
 *  lpCount     [O]   Destination for number of properties returned
 *  lpppNames   [O]   Destination for returned names
 *
 * RETURNS
 *  Success: S_OK. *lppPropTags and lpppNames contain the returned
 *           name/identifiers.
 *  Failure: MAPI_E_NO_SUPPORT, if the object does not support named properties,
 *           MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
 *           MAPI_W_ERRORS_RETURNED if not all properties were retrieved
 *           successfully.
 */
2015 2016 2017
static HRESULT WINAPI IPropData_fnGetNamesFromIDs(LPPROPDATA iface, LPSPropTagArray *lppPropTags,
                                                  LPGUID iid, ULONG ulFlags, ULONG *lpCount,
                                                  LPMAPINAMEID **lpppNames)
2018
{
2019
    FIXME("(%p,%p,%s,0x%08X,%p,%p) stub\n", iface, lppPropTags,
2020 2021 2022 2023 2024
          debugstr_guid(iid), ulFlags, lpCount, lpppNames);
    return MAPI_E_NO_SUPPORT;
}

/**************************************************************************
2025
 *  IPropData_GetIDsFromNames {MAPI32}
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044
 *
 * Get property identifiers associated with one or more named properties.
 *
 * PARAMS
 *  iface       [I] IMAPIProp object to operate on
 *  ulNames     [I] Number of names in lppNames
 *  lppNames    [I] Names to query or create, or NULL to query all names
 *  ulFlags     [I] Pass MAPI_CREATE to create new named properties
 *  lppPropTags [O] Destination for queried or created property identifiers
 *
 * RETURNS
 *  Success: S_OK. *lppPropTags contains the property tags created or requested.
 *  Failure: MAPI_E_NO_SUPPORT, if the object does not support named properties,
 *           MAPI_E_TOO_BIG, if the object cannot process the number of
 *           properties involved.
 *           MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails, or
 *           MAPI_W_ERRORS_RETURNED if not all properties were retrieved
 *           successfully.
 */
2045 2046 2047
static HRESULT WINAPI IPropData_fnGetIDsFromNames(LPPROPDATA iface, ULONG ulNames,
                                                  LPMAPINAMEID *lppNames, ULONG ulFlags,
                                                  LPSPropTagArray *lppPropTags)
2048
{
2049
    FIXME("(%p,%d,%p,0x%08X,%p) stub\n",
2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
          iface, ulNames, lppNames, ulFlags, lppPropTags);
    return MAPI_E_NO_SUPPORT;
}

/**************************************************************************
 *  IPropData_HrSetObjAccess {MAPI32}
 *
 * Set the access level of an IPropData object.
 *
 * PARAMS
 *  iface    [I] IPropData object to set the access on
 *  ulAccess [I] Either IPROP_READONLY or IPROP_READWRITE for read or
 *               read/write access respectively.
 *
 * RETURNS
 *  Success: S_OK. The objects access level is changed.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
 */
static HRESULT WINAPI
IPropData_fnHrSetObjAccess(LPPROPDATA iface, ULONG ulAccess)
{
2071
    IPropDataImpl *This = impl_from_IPropData(iface);
2072

2073
    TRACE("(%p,%x)\n", iface, ulAccess);
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124

    if (!iface || ulAccess < IPROP_READONLY || ulAccess > IPROP_READWRITE)
        return MAPI_E_INVALID_PARAMETER;

    IMAPIPROP_Lock(This);

    This->ulObjAccess = ulAccess;

    IMAPIPROP_Unlock(This);
    return S_OK;
}

/* Internal - determine if an access value is bad */
static inline BOOL PROP_IsBadAccess(ULONG ulAccess)
{
    switch (ulAccess)
    {
    case IPROP_READONLY|IPROP_CLEAN:
    case IPROP_READONLY|IPROP_DIRTY:
    case IPROP_READWRITE|IPROP_CLEAN:
    case IPROP_READWRITE|IPROP_DIRTY:
        return FALSE;
    }
    return TRUE;
}

/**************************************************************************
 *  IPropData_HrSetPropAccess {MAPI32}
 *
 * Set the access levels for a group of property values in an IPropData object.
 *
 * PARAMS
 *  iface    [I] IPropData object to set access levels in.
 *  lpTags   [I] List of property Id's to set access for.
 *  lpAccess [O] Access level for each property in lpTags.
 *
 * RETURNS
 *  Success: S_OK. The access level of each property value in lpTags that is
 *           present in iface is changed.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid.
 *
 * NOTES
 *  - Each access level in lpAccess must contain at least one of IPROP_READONLY
 *    or IPROP_READWRITE, but not both, and also IPROP_CLEAN or IPROP_DIRTY,
 *    but not both. No other bits should be set.
 *  - If a property Id in lpTags is not present in iface, it is ignored.
 */
static HRESULT WINAPI
IPropData_fnHrSetPropAccess(LPPROPDATA iface, LPSPropTagArray lpTags,
                            ULONG *lpAccess)
{
2125
    IPropDataImpl *This = impl_from_IPropData(iface);
2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
    ULONG i;

    TRACE("(%p,%p,%p)\n", iface, lpTags, lpAccess);

    if (!iface || !lpTags || !lpAccess)
        return MAPI_E_INVALID_PARAMETER;

    for (i = 0; i < lpTags->cValues; i++)
    {
        if (FBadPropTag(lpTags->aulPropTag[i]) || PROP_IsBadAccess(lpAccess[i]))
            return MAPI_E_INVALID_PARAMETER;
    }

    IMAPIPROP_Lock(This);

    for (i = 0; i < lpTags->cValues; i++)
    {
        LPIPropDataItem item = IMAPIPROP_GetValue(This, lpTags->aulPropTag[i]);

        if (item)
            item->ulAccess = lpAccess[i];
    }

    IMAPIPROP_Unlock(This);
    return S_OK;
}

/**************************************************************************
 *  IPropData_HrGetPropAccess {MAPI32}
 *
 * Get the access levels for a group of property values in an IPropData object.
 *
 * PARAMS
 *  iface     [I] IPropData object to get access levels from.
 *  lppTags   [O] Destination for the list of property Id's in iface.
 *  lppAccess [O] Destination for access level for each property in lppTags.
 *
 * RETURNS
 *  Success: S_OK. lppTags and lppAccess contain the property Id's and the
 *           Access level of each property value in iface.
 *  Failure: MAPI_E_INVALID_PARAMETER, if any parameter is invalid, or
 *           MAPI_E_NOT_ENOUGH_MEMORY if memory allocation fails.
 *
 * NOTES
 *  - *lppTags and *lppAccess should be freed with MAPIFreeBuffer() by the caller.
 */
static HRESULT WINAPI
IPropData_fnHrGetPropAccess(LPPROPDATA iface, LPSPropTagArray *lppTags,
                            ULONG **lppAccess)
{
2176
    IPropDataImpl *This = impl_from_IPropData(iface);
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267
    LPVOID lpMem;
    HRESULT hRet;
    ULONG i;

    TRACE("(%p,%p,%p) stub\n", iface, lppTags, lppAccess);

    if (!iface || !lppTags || !lppAccess)
        return MAPI_E_INVALID_PARAMETER;

    *lppTags = NULL;
    *lppAccess = NULL;

    IMAPIPROP_Lock(This);

    hRet = This->lpAlloc(CbNewSPropTagArray(This->ulNumValues), &lpMem);
    if (SUCCEEDED(hRet))
    {
        *lppTags = lpMem;

        hRet = This->lpAlloc(This->ulNumValues * sizeof(ULONG), &lpMem);
        if (SUCCEEDED(hRet))
        {
            struct list *cursor;

            *lppAccess = lpMem;
            (*lppTags)->cValues = This->ulNumValues;

            i = 0;
            LIST_FOR_EACH(cursor, &This->values)
            {
                LPIPropDataItem item = LIST_ENTRY(cursor, IPropDataItem, entry);
                (*lppTags)->aulPropTag[i] = item->value->ulPropTag;
                (*lppAccess)[i] = item->ulAccess;
                i++;
            }
            IMAPIPROP_Unlock(This);
            return S_OK;
        }
        This->lpFree(*lppTags);
        *lppTags = 0;
    }
    IMAPIPROP_Unlock(This);
    return MAPI_E_NOT_ENOUGH_MEMORY;
}

/**************************************************************************
 *  IPropData_HrAddObjProps {MAPI32}
 *
 * Not documented at this time.
 *
 * RETURNS
 *  An HRESULT success/failure code.
 */
static HRESULT WINAPI
IPropData_fnHrAddObjProps(LPPROPDATA iface, LPSPropTagArray lpTags,
                          LPSPropProblemArray *lppProbs)
{
#if 0
    ULONG i;
    HRESULT hRet;
    LPSPropValue lpValues;
#endif

    FIXME("(%p,%p,%p) stub\n", iface, lpTags, lppProbs);

    if (!iface || !lpTags)
        return MAPI_E_INVALID_PARAMETER;

    /* FIXME: Below is the obvious implementation, adding all the properties
     *        in lpTags to the object. However, it doesn't appear that this
     *        is what this function does.
     */
    return S_OK;
#if 0
    if (!lpTags->cValues)
        return S_OK;

    lpValues = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                         lpTags->cValues * sizeof(SPropValue));
    if (!lpValues)
        return MAPI_E_NOT_ENOUGH_MEMORY;

    for (i = 0; i < lpTags->cValues; i++)
        lpValues[i].ulPropTag = lpTags->aulPropTag[i];

    hRet = IPropData_SetProps(iface, lpTags->cValues, lpValues, lppProbs);
    HeapFree(GetProcessHeap(), 0, lpValues);
    return hRet;
#endif
}

2268
static const IPropDataVtbl IPropDataImpl_vtbl =
2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330
{
    IPropData_fnQueryInterface,
    IPropData_fnAddRef,
    IPropData_fnRelease,
    IPropData_fnGetLastError,
    IPropData_fnSaveChanges,
    IPropData_fnGetProps,
    IPropData_fnGetPropList,
    IPropData_fnOpenProperty,
    IPropData_fnSetProps,
    IPropData_fnDeleteProps,
    IPropData_fnCopyTo,
    IPropData_fnCopyProps,
    IPropData_fnGetNamesFromIDs,
    IPropData_fnGetIDsFromNames,
    IPropData_fnHrSetObjAccess,
    IPropData_fnHrSetPropAccess,
    IPropData_fnHrGetPropAccess,
    IPropData_fnHrAddObjProps
};

/*************************************************************************
 * CreateIProp@24 (MAPI32.60)
 *
 * Create an IPropData object.
 *
 * PARAMS
 *  iid         [I] GUID of the object to create. Use &IID_IMAPIPropData or NULL
 *  lpAlloc     [I] Memory allocation function. Use MAPIAllocateBuffer()
 *  lpMore      [I] Linked memory allocation function. Use MAPIAllocateMore()
 *  lpFree      [I] Memory free function. Use MAPIFreeBuffer()
 *  lpReserved  [I] Reserved, set to NULL
 *  lppPropData [O] Destination for created IPropData object
 *
 * RETURNS
 *  Success: S_OK. *lppPropData contains the newly created object.
 *  Failure: MAPI_E_INTERFACE_NOT_SUPPORTED, if iid is non-NULL and not supported,
 *           MAPI_E_INVALID_PARAMETER, if any parameter is invalid
 */
SCODE WINAPI CreateIProp(LPCIID iid, ALLOCATEBUFFER *lpAlloc,
                         ALLOCATEMORE *lpMore, FREEBUFFER *lpFree,
                         LPVOID lpReserved, LPPROPDATA *lppPropData)
{
    IPropDataImpl *lpPropData;
    SCODE scode;

    TRACE("(%s,%p,%p,%p,%p,%p)\n", debugstr_guid(iid), lpAlloc, lpMore, lpFree,
          lpReserved, lppPropData);

    if (lppPropData)
        *lppPropData = NULL;

    if (iid && !IsEqualGUID(iid, &IID_IMAPIPropData))
        return MAPI_E_INTERFACE_NOT_SUPPORTED;

    if (!lpAlloc || !lpMore || !lpFree || lpReserved || !lppPropData)
        return MAPI_E_INVALID_PARAMETER;

    scode = lpAlloc(sizeof(IPropDataImpl), (LPVOID*)&lpPropData);

    if (SUCCEEDED(scode))
    {
2331
        lpPropData->IPropData_iface.lpVtbl = &IPropDataImpl_vtbl;
2332 2333 2334 2335 2336 2337 2338
        lpPropData->lRef = 1;
        lpPropData->lpAlloc = lpAlloc;
        lpPropData->lpMore = lpMore;
        lpPropData->lpFree = lpFree;
        lpPropData->ulObjAccess = IPROP_READWRITE;
        lpPropData->ulNumValues = 0;
        list_init(&lpPropData->values);
2339
        InitializeCriticalSection(&lpPropData->cs);
2340
        lpPropData->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": IPropDataImpl.cs");
2341
        *lppPropData = &lpPropData->IPropData_iface;
2342 2343 2344
    }
    return scode;
}