inetcomm: Implement IMimeBody:IsContentType.
This commit is contained in:
parent
0bcd30773e
commit
19cb4bcd36
|
@ -101,6 +101,8 @@ typedef struct MimeBody
|
||||||
struct list headers;
|
struct list headers;
|
||||||
struct list new_props; /* FIXME: This should be in a PropertySchema */
|
struct list new_props; /* FIXME: This should be in a PropertySchema */
|
||||||
DWORD next_prop_id;
|
DWORD next_prop_id;
|
||||||
|
char *content_pri_type;
|
||||||
|
char *content_sub_type;
|
||||||
} MimeBody;
|
} MimeBody;
|
||||||
|
|
||||||
static inline MimeBody *impl_from_IMimeBody( IMimeBody *iface )
|
static inline MimeBody *impl_from_IMimeBody( IMimeBody *iface )
|
||||||
|
@ -343,6 +345,30 @@ static void read_value(header_t *header, char **cur)
|
||||||
*cur = end;
|
*cur = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void init_content_type(MimeBody *body, header_t *header)
|
||||||
|
{
|
||||||
|
char *slash;
|
||||||
|
DWORD len;
|
||||||
|
|
||||||
|
if(header->prop->id != PID_HDR_CNTTYPE)
|
||||||
|
{
|
||||||
|
ERR("called with header %s\n", header->prop->name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
slash = strchr(header->value.pszVal, '/');
|
||||||
|
if(!slash)
|
||||||
|
{
|
||||||
|
WARN("malformed context type value\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
len = slash - header->value.pszVal;
|
||||||
|
body->content_pri_type = HeapAlloc(GetProcessHeap(), 0, len + 1);
|
||||||
|
memcpy(body->content_pri_type, header->value.pszVal, len);
|
||||||
|
body->content_pri_type[len] = '\0';
|
||||||
|
body->content_sub_type = strdupA(slash + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static HRESULT parse_headers(MimeBody *body, IStream *stm)
|
static HRESULT parse_headers(MimeBody *body, IStream *stm)
|
||||||
{
|
{
|
||||||
char *header_buf, *cur_header_ptr;
|
char *header_buf, *cur_header_ptr;
|
||||||
|
@ -357,6 +383,9 @@ static HRESULT parse_headers(MimeBody *body, IStream *stm)
|
||||||
{
|
{
|
||||||
read_value(header, &cur_header_ptr);
|
read_value(header, &cur_header_ptr);
|
||||||
list_add_tail(&body->headers, &header->entry);
|
list_add_tail(&body->headers, &header->entry);
|
||||||
|
|
||||||
|
if(header->prop->id == PID_HDR_CNTTYPE)
|
||||||
|
init_content_type(body, header);
|
||||||
}
|
}
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, header_buf);
|
HeapFree(GetProcessHeap(), 0, header_buf);
|
||||||
|
@ -448,6 +477,8 @@ static ULONG WINAPI MimeBody_Release(IMimeBody* iface)
|
||||||
empty_header_list(&This->headers);
|
empty_header_list(&This->headers);
|
||||||
empty_new_prop_list(&This->new_props);
|
empty_new_prop_list(&This->new_props);
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, This->content_pri_type);
|
||||||
|
HeapFree(GetProcessHeap(), 0, This->content_sub_type);
|
||||||
HeapFree(GetProcessHeap(), 0, This);
|
HeapFree(GetProcessHeap(), 0, This);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,8 +662,24 @@ static HRESULT WINAPI MimeBody_IsContentType(
|
||||||
LPCSTR pszPriType,
|
LPCSTR pszPriType,
|
||||||
LPCSTR pszSubType)
|
LPCSTR pszSubType)
|
||||||
{
|
{
|
||||||
FIXME("stub\n");
|
MimeBody *This = impl_from_IMimeBody(iface);
|
||||||
return E_NOTIMPL;
|
|
||||||
|
TRACE("(%p)->(%s, %s)\n", This, debugstr_a(pszPriType), debugstr_a(pszSubType));
|
||||||
|
if(pszPriType)
|
||||||
|
{
|
||||||
|
const char *pri = This->content_pri_type;
|
||||||
|
if(!pri) pri = "text";
|
||||||
|
if(strcasecmp(pri, pszPriType)) return S_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pszSubType)
|
||||||
|
{
|
||||||
|
const char *sub = This->content_sub_type;
|
||||||
|
if(!sub) sub = "plain";
|
||||||
|
if(strcasecmp(sub, pszSubType)) return S_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI MimeBody_BindToObject(
|
static HRESULT WINAPI MimeBody_BindToObject(
|
||||||
|
@ -875,6 +922,8 @@ HRESULT MimeBody_create(IUnknown *outer, void **obj)
|
||||||
list_init(&This->headers);
|
list_init(&This->headers);
|
||||||
list_init(&This->new_props);
|
list_init(&This->new_props);
|
||||||
This->next_prop_id = FIRST_CUSTOM_PROP_ID;
|
This->next_prop_id = FIRST_CUSTOM_PROP_ID;
|
||||||
|
This->content_pri_type = NULL;
|
||||||
|
This->content_sub_type = NULL;
|
||||||
|
|
||||||
*obj = (IMimeBody *)&This->lpVtbl;
|
*obj = (IMimeBody *)&This->lpVtbl;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
|
|
|
@ -113,6 +113,13 @@ static void test_CreateBody(void)
|
||||||
IStream_Seek(in, off, STREAM_SEEK_CUR, &pos);
|
IStream_Seek(in, off, STREAM_SEEK_CUR, &pos);
|
||||||
ok(pos.LowPart == 328, "pos %u\n", pos.LowPart);
|
ok(pos.LowPart == 328, "pos %u\n", pos.LowPart);
|
||||||
|
|
||||||
|
hr = IMimeBody_IsContentType(body, "multipart", "mixed");
|
||||||
|
ok(hr == S_OK, "ret %08x\n", hr);
|
||||||
|
hr = IMimeBody_IsContentType(body, "text", "plain");
|
||||||
|
ok(hr == S_FALSE, "ret %08x\n", hr);
|
||||||
|
hr = IMimeBody_IsContentType(body, NULL, "mixed");
|
||||||
|
ok(hr == S_OK, "ret %08x\n", hr);
|
||||||
|
|
||||||
IMimeBody_Release(body);
|
IMimeBody_Release(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue