inetcomm: Add support for PID ids in MimeBody Get/SetProp.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair@hotmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alistair Leslie-Hughes 2016-05-30 10:19:16 +00:00 committed by Alexandre Julliard
parent a3547a1359
commit 4c92dd98a4
3 changed files with 113 additions and 5 deletions

View File

@ -496,7 +496,15 @@ static HRESULT find_prop(MimeBody *body, const char *name, header_t **prop)
LIST_FOR_EACH_ENTRY(header, &body->headers, header_t, entry) LIST_FOR_EACH_ENTRY(header, &body->headers, header_t, entry)
{ {
if(!lstrcmpiA(name, header->prop->name)) if(ISPIDSTR(name))
{
if(STRTOPID(name) == header->prop->id)
{
*prop = header;
return S_OK;
}
}
else if(!lstrcmpiA(name, header->prop->name))
{ {
*prop = header; *prop = header;
return S_OK; return S_OK;
@ -506,6 +514,33 @@ static HRESULT find_prop(MimeBody *body, const char *name, header_t **prop)
return MIME_E_NOT_FOUND; return MIME_E_NOT_FOUND;
} }
static const property_t *find_default_prop(const char *name)
{
const property_t *prop_def = NULL;
for(prop_def = default_props; prop_def->name; prop_def++)
{
if(ISPIDSTR(name))
{
if(STRTOPID(name) == prop_def->id)
{
break;
}
}
else if(!lstrcmpiA(name, prop_def->name))
{
break;
}
}
if(prop_def->id)
TRACE("%s: found match with default property id %d\n", prop_def->name, prop_def->id);
else
prop_def = NULL;
return prop_def;
}
static HRESULT WINAPI MimeBody_QueryInterface(IMimeBody* iface, static HRESULT WINAPI MimeBody_QueryInterface(IMimeBody* iface,
REFIID riid, REFIID riid,
void** ppvObject) void** ppvObject)
@ -650,7 +685,7 @@ static HRESULT WINAPI MimeBody_GetProp(
if(!pszName || !pValue) if(!pszName || !pValue)
return E_INVALIDARG; return E_INVALIDARG;
if(!lstrcmpiA(pszName, "att:pri-content-type")) if(!ISPIDSTR(pszName) && !lstrcmpiA(pszName, "att:pri-content-type"))
{ {
PropVariantClear(pValue); PropVariantClear(pValue);
pValue->vt = VT_LPSTR; pValue->vt = VT_LPSTR;
@ -690,7 +725,16 @@ static HRESULT WINAPI MimeBody_SetProp(
LIST_FOR_EACH_ENTRY(prop_entry, &This->new_props, property_list_entry_t, entry) LIST_FOR_EACH_ENTRY(prop_entry, &This->new_props, property_list_entry_t, entry)
{ {
if(!lstrcmpiA(pszName, prop_entry->prop.name)) if(ISPIDSTR(pszName))
{
if(STRTOPID(pszName) == prop_entry->prop.id)
{
TRACE("Found match with already added new property id %d\n", prop_entry->prop.id);
prop = &prop_entry->prop;
break;
}
}
else if(!lstrcmpiA(pszName, prop_entry->prop.name))
{ {
TRACE("Found match with already added new property id %d\n", prop_entry->prop.id); TRACE("Found match with already added new property id %d\n", prop_entry->prop.id);
prop = &prop_entry->prop; prop = &prop_entry->prop;
@ -704,14 +748,33 @@ static HRESULT WINAPI MimeBody_SetProp(
if(!prop) if(!prop)
{ {
const property_t *prop_def = NULL;
prop_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*prop_entry)); prop_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*prop_entry));
if(!prop_entry) if(!prop_entry)
{ {
HeapFree(GetProcessHeap(), 0, header); HeapFree(GetProcessHeap(), 0, header);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
prop_def = find_default_prop(pszName);
if(prop_def)
{
prop_entry->prop.name = strdupA(prop_def->name);
prop_entry->prop.id = prop_def->id;
}
else
{
if(ISPIDSTR(pszName))
{
HeapFree(GetProcessHeap(), 0, prop_entry);
HeapFree(GetProcessHeap(), 0, header);
return MIME_E_NOT_FOUND;
}
prop_entry->prop.name = strdupA(pszName); prop_entry->prop.name = strdupA(pszName);
prop_entry->prop.id = This->next_prop_id++; prop_entry->prop.id = This->next_prop_id++;
}
prop_entry->prop.flags = 0; prop_entry->prop.flags = 0;
prop_entry->prop.default_vt = pValue->vt; prop_entry->prop.default_vt = pValue->vt;
list_add_tail(&This->new_props, &prop_entry->entry); list_add_tail(&This->new_props, &prop_entry->entry);

View File

@ -379,6 +379,47 @@ static void test_MessageSetProp(void)
PropVariantClear(&prop); PropVariantClear(&prop);
} }
prop.vt = VT_LPSTR;
prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
strcpy(prop.u.pszVal, topic);
hr = IMimeBody_SetProp(body, PIDTOSTR(PID_HDR_SUBJECT), 0, &prop);
ok(hr == S_OK, "ret %08x\n", hr);
PropVariantClear(&prop);
hr = IMimeBody_GetProp(body, PIDTOSTR(PID_HDR_SUBJECT), 0, &prop);
ok(hr == S_OK, "ret %08x\n", hr);
if(hr == S_OK)
{
ok(prop.vt == VT_LPSTR, "type %d\n", prop.vt);
ok(!strcmp(prop.u.pszVal, topic), "got %s\n", prop.u.pszVal);
PropVariantClear(&prop);
}
/* Using the name or PID returns the same result. */
hr = IMimeBody_GetProp(body, "Subject", 0, &prop);
ok(hr == S_OK, "ret %08x\n", hr);
if(hr == S_OK)
{
ok(prop.vt == VT_LPSTR, "type %d\n", prop.vt);
ok(!strcmp(prop.u.pszVal, topic), "got %s\n", prop.u.pszVal);
PropVariantClear(&prop);
}
prop.vt = VT_LPSTR;
prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
strcpy(prop.u.pszVal, topic);
hr = IMimeBody_SetProp(body, PIDTOSTR(PID_HDR_TO), 0, &prop);
ok(hr == S_OK, "ret %08x\n", hr);
PropVariantClear(&prop);
/* Out of Range PID */
prop.vt = VT_LPSTR;
prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
strcpy(prop.u.pszVal, topic);
hr = IMimeBody_SetProp(body, PIDTOSTR(124), 0, &prop);
ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
PropVariantClear(&prop);
IMimeBody_Release(body); IMimeBody_Release(body);
IMimeMessage_Release(msg); IMimeMessage_Release(msg);
} }

View File

@ -153,6 +153,10 @@ cpp_quote(" PID_ATT_ACCOUNTNAME = 78,")
cpp_quote(" PID_LAST = 79,") cpp_quote(" PID_LAST = 79,")
cpp_quote("} MIMEPROPID;") cpp_quote("} MIMEPROPID;")
cpp_quote("#define ISPIDSTR(_name) (((DWORD_PTR)(_name) >> 16) == 0)")
cpp_quote("#define STRTOPID(_name) ((DWORD)((DWORD_PTR)((LPCSTR)(_name))))")
cpp_quote("#define PIDTOSTR(_id) ((LPCSTR)((DWORD_PTR)(_id)))")
cpp_quote("#define TYPEDID_ID(_typedid) (((ULONG)(_typedid))>>16)") cpp_quote("#define TYPEDID_ID(_typedid) (((ULONG)(_typedid))>>16)")
cpp_quote("#define TYPEDID_MASK ((ULONG)0xffff)") cpp_quote("#define TYPEDID_MASK ((ULONG)0xffff)")
cpp_quote("#define TYPEDID_TYPE(t) ((VARTYPE)((t) & TYPEDID_MASK))") cpp_quote("#define TYPEDID_TYPE(t) ((VARTYPE)((t) & TYPEDID_MASK))")