ReactOS  0.4.13-dev-73-gcfe54aa
dmobject.c File Reference
#include <assert.h>
#include "objbase.h"
#include "dmusici.h"
#include "dmusicf.h"
#include "dmobject.h"
#include "wine/debug.h"
#include "dmusic_private.h"
Include dependency graph for dmobject.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define CHUNK_HDR_SIZE   (sizeof(FOURCC) + sizeof(DWORD))
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dmobj)
 
 WINE_DECLARE_DEBUG_CHANNEL (dmfile)
 
static const chardebugstr_fourcc (DWORD fourcc)
 
const chardebugstr_chunk (const struct chunk_entry *chunk)
 
static HRESULT stream_read (IStream *stream, void *data, ULONG size)
 
HRESULT stream_get_chunk (IStream *stream, struct chunk_entry *chunk)
 
HRESULT stream_skip_chunk (IStream *stream, struct chunk_entry *chunk)
 
HRESULT stream_next_chunk (IStream *stream, struct chunk_entry *chunk)
 
HRESULT stream_chunk_get_data (IStream *stream, const struct chunk_entry *chunk, void *data, ULONG size)
 
HRESULT stream_chunk_get_wstr (IStream *stream, const struct chunk_entry *chunk, WCHAR *str, ULONG size)
 
static struct dmobjectimpl_from_IDirectMusicObject (IDirectMusicObject *iface)
 
HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface (IDirectMusicObject *iface, REFIID riid, void **ret_iface)
 
ULONG WINAPI dmobj_IDirectMusicObject_AddRef (IDirectMusicObject *iface)
 
ULONG WINAPI dmobj_IDirectMusicObject_Release (IDirectMusicObject *iface)
 
HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor (IDirectMusicObject *iface, DMUS_OBJECTDESC *desc)
 
HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor (IDirectMusicObject *iface, DMUS_OBJECTDESC *desc)
 
static void info_get_name (IStream *stream, const struct chunk_entry *info, DMUS_OBJECTDESC *desc)
 
static void unfo_get_name (IStream *stream, const struct chunk_entry *unfo, DMUS_OBJECTDESC *desc, BOOL inam)
 
HRESULT dmobj_parsedescriptor (IStream *stream, const struct chunk_entry *riff, DMUS_OBJECTDESC *desc, DWORD supported)
 
static struct dmobjectimpl_from_IPersistStream (IPersistStream *iface)
 
HRESULT WINAPI dmobj_IPersistStream_QueryInterface (IPersistStream *iface, REFIID riid, void **ret_iface)
 
ULONG WINAPI dmobj_IPersistStream_AddRef (IPersistStream *iface)
 
ULONG WINAPI dmobj_IPersistStream_Release (IPersistStream *iface)
 
HRESULT WINAPI dmobj_IPersistStream_GetClassID (IPersistStream *iface, CLSID *class)
 
HRESULT WINAPI unimpl_IPersistStream_GetClassID (IPersistStream *iface, CLSID *class)
 
HRESULT WINAPI unimpl_IPersistStream_IsDirty (IPersistStream *iface)
 
HRESULT WINAPI unimpl_IPersistStream_Save (IPersistStream *iface, IStream *stream, BOOL clear_dirty)
 
HRESULT WINAPI unimpl_IPersistStream_GetSizeMax (IPersistStream *iface, ULARGE_INTEGER *size)
 
void dmobject_init (struct dmobject *dmobj, const GUID *class, IUnknown *outer_unk)
 

Macro Definition Documentation

◆ CHUNK_HDR_SIZE

#define CHUNK_HDR_SIZE   (sizeof(FOURCC) + sizeof(DWORD))

Definition at line 37 of file dmobject.c.

◆ COBJMACROS

#define COBJMACROS

Definition at line 23 of file dmobject.c.

Function Documentation

◆ debugstr_chunk()

const char* debugstr_chunk ( const struct chunk_entry chunk)

Definition at line 48 of file dmobject.c.

49 {
50  const char *type = "";
51 
52  if (!chunk)
53  return "(null)";
54  if (chunk->id == FOURCC_RIFF || chunk->id == FOURCC_LIST)
55  type = wine_dbg_sprintf("type %s, ", debugstr_fourcc(chunk->type));
56  return wine_dbg_sprintf("%s chunk, %ssize %u", debugstr_fourcc(chunk->id), type, chunk->size);
57 }
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:271
#define FOURCC_LIST
Definition: mmsystem.h:565
static const char * debugstr_fourcc(DWORD fourcc)
Definition: dmobject.c:40
#define FOURCC_RIFF
Definition: mmsystem.h:564
UINT16 size
Definition: btrfs_drv.h:520

Referenced by col_IDirectMusicObject_ParseDescriptor(), dmobj_parsedescriptor(), and stream_get_chunk().

◆ debugstr_fourcc()

static const char* debugstr_fourcc ( DWORD  fourcc)
inlinestatic

Definition at line 40 of file dmobject.c.

41 {
42  if (!fourcc) return "''";
43  return wine_dbg_sprintf("'%c%c%c%c'", (char)(fourcc), (char)(fourcc >> 8),
44  (char)(fourcc >> 16), (char)(fourcc >> 24));
45 }
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:271

Referenced by debugstr_chunk(), and stream_chunk_get_data().

◆ dmobj_IDirectMusicObject_AddRef()

ULONG WINAPI dmobj_IDirectMusicObject_AddRef ( IDirectMusicObject *  iface)

Definition at line 188 of file dmobject.c.

189 {
190  struct dmobject *This = impl_from_IDirectMusicObject(iface);
191  return IUnknown_AddRef(This->outer_unk);
192 }
static struct dmobject * impl_from_IDirectMusicObject(IDirectMusicObject *iface)
Definition: dmobject.c:176

◆ dmobj_IDirectMusicObject_GetDescriptor()

HRESULT WINAPI dmobj_IDirectMusicObject_GetDescriptor ( IDirectMusicObject *  iface,
DMUS_OBJECTDESC desc 
)

Definition at line 200 of file dmobject.c.

202 {
203  struct dmobject *This = impl_from_IDirectMusicObject(iface);
204 
205  TRACE("(%p/%p)->(%p)\n", iface, This, desc);
206 
207  if (!desc)
208  return E_POINTER;
209 
210  memcpy(desc, &This->desc, This->desc.dwSize);
211 
212  return S_OK;
213 }
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
#define TRACE(s)
Definition: solgame.cpp:4
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define S_OK
Definition: intsafe.h:59
#define E_POINTER
Definition: winerror.h:2365
static struct dmobject * impl_from_IDirectMusicObject(IDirectMusicObject *iface)
Definition: dmobject.c:176

◆ dmobj_IDirectMusicObject_QueryInterface()

HRESULT WINAPI dmobj_IDirectMusicObject_QueryInterface ( IDirectMusicObject *  iface,
REFIID  riid,
void **  ret_iface 
)

Definition at line 181 of file dmobject.c.

183 {
184  struct dmobject *This = impl_from_IDirectMusicObject(iface);
185  return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface);
186 }
REFIID riid
Definition: precomp.h:44
static struct dmobject * impl_from_IDirectMusicObject(IDirectMusicObject *iface)
Definition: dmobject.c:176

◆ dmobj_IDirectMusicObject_Release()

ULONG WINAPI dmobj_IDirectMusicObject_Release ( IDirectMusicObject *  iface)

Definition at line 194 of file dmobject.c.

195 {
196  struct dmobject *This = impl_from_IDirectMusicObject(iface);
197  return IUnknown_Release(This->outer_unk);
198 }
static struct dmobject * impl_from_IDirectMusicObject(IDirectMusicObject *iface)
Definition: dmobject.c:176

◆ dmobj_IDirectMusicObject_SetDescriptor()

HRESULT WINAPI dmobj_IDirectMusicObject_SetDescriptor ( IDirectMusicObject *  iface,
DMUS_OBJECTDESC desc 
)

Definition at line 215 of file dmobject.c.

217 {
218  struct dmobject *This = impl_from_IDirectMusicObject(iface);
219  HRESULT ret = S_OK;
220 
221  TRACE("(%p, %p)\n", iface, desc);
222 
223  if (!desc)
224  return E_POINTER;
225 
226  /* Immutable property */
227  if (desc->dwValidData & DMUS_OBJ_CLASS)
228  {
229  desc->dwValidData &= ~DMUS_OBJ_CLASS;
230  ret = S_FALSE;
231  }
232  /* Set only valid fields */
233  if (desc->dwValidData & DMUS_OBJ_OBJECT)
234  This->desc.guidObject = desc->guidObject;
235  if (desc->dwValidData & DMUS_OBJ_NAME)
236  lstrcpynW(This->desc.wszName, desc->wszName, DMUS_MAX_NAME);
237  if (desc->dwValidData & DMUS_OBJ_CATEGORY)
238  lstrcpynW(This->desc.wszCategory, desc->wszCategory, DMUS_MAX_CATEGORY);
239  if (desc->dwValidData & DMUS_OBJ_FILENAME)
240  lstrcpynW(This->desc.wszFileName, desc->wszFileName, DMUS_MAX_FILENAME);
241  if (desc->dwValidData & DMUS_OBJ_VERSION)
242  This->desc.vVersion = desc->vVersion;
243  if (desc->dwValidData & DMUS_OBJ_DATE)
244  This->desc.ftDate = desc->ftDate;
245  if (desc->dwValidData & DMUS_OBJ_MEMORY) {
246  This->desc.llMemLength = desc->llMemLength;
247  memcpy(This->desc.pbMemData, desc->pbMemData, desc->llMemLength);
248  }
249  if (desc->dwValidData & DMUS_OBJ_STREAM)
250  IStream_Clone(desc->pStream, &This->desc.pStream);
251 
252  This->desc.dwValidData |= desc->dwValidData;
253 
254  return ret;
255 }
#define DMUS_OBJ_NAME
Definition: dmusici.h:267
#define DMUS_MAX_CATEGORY
Definition: dmusici.h:246
#define lstrcpynW
Definition: compat.h:397
#define DMUS_OBJ_FILENAME
Definition: dmusici.h:269
#define S_FALSE
Definition: winerror.h:2357
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
#define DMUS_OBJ_OBJECT
Definition: dmusici.h:265
int ret
#define DMUS_OBJ_MEMORY
Definition: dmusici.h:275
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define DMUS_OBJ_DATE
Definition: dmusici.h:273
#define DMUS_OBJ_CATEGORY
Definition: dmusici.h:268
#define S_OK
Definition: intsafe.h:59
#define DMUS_MAX_FILENAME
Definition: dmusici.h:247
#define DMUS_OBJ_VERSION
Definition: dmusici.h:272
#define E_POINTER
Definition: winerror.h:2365
static struct dmobject * impl_from_IDirectMusicObject(IDirectMusicObject *iface)
Definition: dmobject.c:176
#define DMUS_OBJ_CLASS
Definition: dmusici.h:266
#define DMUS_OBJ_STREAM
Definition: dmusici.h:276
#define DMUS_MAX_NAME
Definition: dmusici.h:245

◆ dmobj_IPersistStream_AddRef()

ULONG WINAPI dmobj_IPersistStream_AddRef ( IPersistStream iface)

Definition at line 354 of file dmobject.c.

355 {
356  struct dmobject *This = impl_from_IPersistStream(iface);
357  return IUnknown_AddRef(This->outer_unk);
358 }
static struct dmobject * impl_from_IPersistStream(IPersistStream *iface)
Definition: dmobject.c:342

◆ dmobj_IPersistStream_GetClassID()

HRESULT WINAPI dmobj_IPersistStream_GetClassID ( IPersistStream iface,
CLSID class 
)

Definition at line 366 of file dmobject.c.

367 {
368  struct dmobject *This = impl_from_IPersistStream(iface);
369 
370  TRACE("(%p, %p)\n", This, class);
371 
372  if (!class)
373  return E_POINTER;
374 
375  *class = This->desc.guidClass;
376 
377  return S_OK;
378 }
static struct dmobject * impl_from_IPersistStream(IPersistStream *iface)
Definition: dmobject.c:342
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
#define TRACE(s)
Definition: solgame.cpp:4
#define S_OK
Definition: intsafe.h:59
#define E_POINTER
Definition: winerror.h:2365

◆ dmobj_IPersistStream_QueryInterface()

HRESULT WINAPI dmobj_IPersistStream_QueryInterface ( IPersistStream iface,
REFIID  riid,
void **  ret_iface 
)

Definition at line 347 of file dmobject.c.

349 {
350  struct dmobject *This = impl_from_IPersistStream(iface);
351  return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface);
352 }
REFIID riid
Definition: precomp.h:44
static struct dmobject * impl_from_IPersistStream(IPersistStream *iface)
Definition: dmobject.c:342

◆ dmobj_IPersistStream_Release()

ULONG WINAPI dmobj_IPersistStream_Release ( IPersistStream iface)

Definition at line 360 of file dmobject.c.

361 {
362  struct dmobject *This = impl_from_IPersistStream(iface);
363  return IUnknown_Release(This->outer_unk);
364 }
static struct dmobject * impl_from_IPersistStream(IPersistStream *iface)
Definition: dmobject.c:342

◆ dmobj_parsedescriptor()

HRESULT dmobj_parsedescriptor ( IStream stream,
const struct chunk_entry riff,
DMUS_OBJECTDESC desc,
DWORD  supported 
)

Definition at line 296 of file dmobject.c.

298 {
299 #ifndef __REACTOS__
300  struct chunk_entry chunk = {.parent = riff};
301 #else
302  struct chunk_entry chunk = { 0, 0, 0, {{0}}, riff };
303 #endif
304  HRESULT hr;
305 
306  TRACE("Looking for %#x in %p: %s\n", supported, stream, debugstr_chunk(riff));
307 
308  desc->dwValidData = 0;
309  desc->dwSize = sizeof(*desc);
310 
311  while ((hr = stream_next_chunk(stream, &chunk)) == S_OK) {
312  switch (chunk.id) {
314  if ((supported & DMUS_OBJ_OBJECT) && stream_chunk_get_data(stream, &chunk,
315  &desc->guidObject, sizeof(desc->guidObject)) == S_OK)
316  desc->dwValidData |= DMUS_OBJ_OBJECT;
317  break;
319  if ((supported & DMUS_OBJ_CATEGORY) && stream_chunk_get_wstr(stream, &chunk,
320  desc->wszCategory, sizeof(desc->wszCategory)) == S_OK)
321  desc->dwValidData |= DMUS_OBJ_CATEGORY;
322  break;
324  if ((supported & DMUS_OBJ_VERSION) && stream_chunk_get_data(stream, &chunk,
325  &desc->vVersion, sizeof(desc->vVersion)) == S_OK)
326  desc->dwValidData |= DMUS_OBJ_VERSION;
327  break;
328  case FOURCC_LIST:
329  if (chunk.type == DMUS_FOURCC_UNFO_LIST && (supported & DMUS_OBJ_NAME))
331  else if (chunk.type == DMUS_FOURCC_INFO_LIST && (supported & DMUS_OBJ_NAME_INFO))
333  break;
334  }
335  }
336  TRACE("Found %#x\n", desc->dwValidData);
337 
338  return hr;
339 }
#define DMUS_FOURCC_VERSION_CHUNK
Definition: dmusicf.h:51
HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk)
Definition: dmobject.c:130
HRESULT hr
Definition: shlfolder.c:183
#define DMUS_OBJ_NAME
Definition: dmusici.h:267
#define DMUS_FOURCC_UNFO_LIST
Definition: dmusicf.h:44
#define DMUS_OBJ_NAME_INAM
Definition: dmobject.h:93
#define DMUS_FOURCC_CATEGORY_CHUNK
Definition: dmusicf.h:50
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
const char * debugstr_chunk(const struct chunk_entry *chunk)
Definition: dmobject.c:48
#define DMUS_FOURCC_GUID_CHUNK
Definition: dmusicf.h:42
#define TRACE(s)
Definition: solgame.cpp:4
#define DMUS_OBJ_NAME_INFO
Definition: dmobject.h:94
#define FOURCC_LIST
Definition: mmsystem.h:565
LONG HRESULT
Definition: typedefs.h:77
Definition: dmobject.h:28
#define DMUS_OBJ_OBJECT
Definition: dmusici.h:265
Definition: parse.h:22
HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, ULONG size)
Definition: dmobject.c:155
#define DMUS_OBJ_CATEGORY
Definition: dmusici.h:268
#define S_OK
Definition: intsafe.h:59
#define DMUS_FOURCC_INFO_LIST
Definition: dmusicf.h:43
static void unfo_get_name(IStream *stream, const struct chunk_entry *unfo, DMUS_OBJECTDESC *desc, BOOL inam)
Definition: dmobject.c:281
static void info_get_name(IStream *stream, const struct chunk_entry *info, DMUS_OBJECTDESC *desc)
Definition: dmobject.c:258
HRESULT stream_chunk_get_data(IStream *stream, const struct chunk_entry *chunk, void *data, ULONG size)
Definition: dmobject.c:143
#define DMUS_OBJ_VERSION
Definition: dmusici.h:272

Referenced by col_IDirectMusicObject_ParseDescriptor().

◆ dmobject_init()

void dmobject_init ( struct dmobject dmobj,
const GUID class,
IUnknown outer_unk 
)

Definition at line 407 of file dmobject.c.

408 {
409  dmobj->outer_unk = outer_unk;
410  dmobj->desc.dwSize = sizeof(dmobj->desc);
412  dmobj->desc.guidClass = *class;
413 }
DMUS_OBJECTDESC desc
Definition: dmobject.h:73
DWORD dwValidData
Definition: dmusici.h:743
#define DMUS_OBJ_CLASS
Definition: dmusici.h:266
IUnknown * outer_unk
Definition: dmobject.h:72

Referenced by DMUSIC_CreateDirectMusicCollectionImpl().

◆ impl_from_IDirectMusicObject()

static struct dmobject* impl_from_IDirectMusicObject ( IDirectMusicObject *  iface)
inlinestatic

Definition at line 176 of file dmobject.c.

177 {
178  return CONTAINING_RECORD(iface, struct dmobject, IDirectMusicObject_iface);
179 }
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560

Referenced by dmobj_IDirectMusicObject_AddRef(), dmobj_IDirectMusicObject_GetDescriptor(), dmobj_IDirectMusicObject_QueryInterface(), dmobj_IDirectMusicObject_Release(), and dmobj_IDirectMusicObject_SetDescriptor().

◆ impl_from_IPersistStream()

static struct dmobject* impl_from_IPersistStream ( IPersistStream iface)
inlinestatic

Definition at line 342 of file dmobject.c.

343 {
344  return CONTAINING_RECORD(iface, struct dmobject, IPersistStream_iface);
345 }
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560

Referenced by dmobj_IPersistStream_AddRef(), dmobj_IPersistStream_GetClassID(), dmobj_IPersistStream_QueryInterface(), and dmobj_IPersistStream_Release().

◆ info_get_name()

static void info_get_name ( IStream stream,
const struct chunk_entry info,
DMUS_OBJECTDESC desc 
)
inlinestatic

Definition at line 258 of file dmobject.c.

260 {
261 #ifndef __REACTOS__
262  struct chunk_entry chunk = {.parent = info};
263 #else
264  struct chunk_entry chunk = { 0, 0, 0, {{0}}, info };
265 #endif
266  char name[DMUS_MAX_NAME];
267  ULONG len;
268  HRESULT hr = E_FAIL;
269 
270  while (stream_next_chunk(stream, &chunk) == S_OK)
271  if (chunk.id == mmioFOURCC('I','N','A','M'))
272  hr = IStream_Read(stream, name, min(chunk.size, sizeof(name)), &len);
273 
274  if (SUCCEEDED(hr)) {
275  len = MultiByteToWideChar(CP_ACP, 0, name, len, desc->wszName, sizeof(desc->wszName));
276  desc->wszName[min(len, sizeof(desc->wszName) - 1)] = 0;
277  desc->dwValidData |= DMUS_OBJ_NAME;
278  }
279 }
HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk)
Definition: dmobject.c:130
HRESULT hr
Definition: shlfolder.c:183
#define CP_ACP
Definition: compat.h:99
#define DMUS_OBJ_NAME
Definition: dmusici.h:267
#define E_FAIL
Definition: ddrawi.h:102
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
LONG HRESULT
Definition: typedefs.h:77
Definition: dmobject.h:28
Definition: parse.h:22
#define mmioFOURCC(c0, c1, c2, c3)
Definition: mmsystem.h:38
GLenum GLsizei len
Definition: glext.h:6722
#define S_OK
Definition: intsafe.h:59
#define min(a, b)
Definition: monoChain.cc:55
#define MultiByteToWideChar
Definition: compat.h:100
UINT16 size
Definition: btrfs_drv.h:520
Definition: name.c:36
unsigned int ULONG
Definition: retypes.h:1
#define DMUS_MAX_NAME
Definition: dmusici.h:245
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by dmobj_parsedescriptor().

◆ stream_chunk_get_data()

HRESULT stream_chunk_get_data ( IStream stream,
const struct chunk_entry chunk,
void data,
ULONG  size 
)

Definition at line 143 of file dmobject.c.

145 {
146  if (chunk->size != size) {
147  WARN_(dmfile)("Chunk %s (size %u, offset %s) doesn't contains the expected data size %u\n",
149  wine_dbgstr_longlong(chunk->offset.QuadPart), size);
150  return E_FAIL;
151  }
152  return stream_read(stream, data, size);
153 }
UINT64 offset
Definition: btrfs_drv.h:521
#define E_FAIL
Definition: ddrawi.h:102
GLsizeiptr size
Definition: glext.h:5919
static const char * debugstr_fourcc(DWORD fourcc)
Definition: dmobject.c:40
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Definition: parse.h:22
UINT16 size
Definition: btrfs_drv.h:520
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
#define WARN_(ch,...)
Definition: debug.h:157
static HRESULT stream_read(IStream *stream, void *data, ULONG size)
Definition: dmobject.c:59

Referenced by dmobj_parsedescriptor().

◆ stream_chunk_get_wstr()

HRESULT stream_chunk_get_wstr ( IStream stream,
const struct chunk_entry chunk,
WCHAR str,
ULONG  size 
)

Definition at line 155 of file dmobject.c.

157 {
158  ULONG len;
159  HRESULT hr;
160 
161  hr = IStream_Read(stream, str, min(chunk->size, size), &len);
162  if (FAILED(hr))
163  return hr;
164 
165  /* Don't assume the string is properly zero terminated */
166  str[min(len, size - 1)] = 0;
167 
168  if (len < chunk->size)
169  return S_FALSE;
170  return S_OK;
171 }
HRESULT hr
Definition: shlfolder.c:183
#define S_FALSE
Definition: winerror.h:2357
const WCHAR * str
GLsizeiptr size
Definition: glext.h:5919
LONG HRESULT
Definition: typedefs.h:77
Definition: parse.h:22
GLenum GLsizei len
Definition: glext.h:6722
#define S_OK
Definition: intsafe.h:59
#define min(a, b)
Definition: monoChain.cc:55
UINT16 size
Definition: btrfs_drv.h:520
unsigned int ULONG
Definition: retypes.h:1

Referenced by dmobj_parsedescriptor(), and unfo_get_name().

◆ stream_get_chunk()

HRESULT stream_get_chunk ( IStream stream,
struct chunk_entry chunk 
)

Definition at line 76 of file dmobject.c.

77 {
78  static const LARGE_INTEGER zero;
79  ULONGLONG ck_end = 0, p_end = 0;
80  HRESULT hr;
81 
82  hr = IStream_Seek(stream, zero, STREAM_SEEK_CUR, &chunk->offset);
83  if (FAILED(hr))
84  return hr;
85  assert(!(chunk->offset.QuadPart & 1));
86  if (chunk->parent) {
87  p_end = chunk->parent->offset.QuadPart + CHUNK_HDR_SIZE + ((chunk->parent->size + 1) & ~1);
88  if (chunk->offset.QuadPart == p_end)
89  return S_FALSE;
90  ck_end = chunk->offset.QuadPart + CHUNK_HDR_SIZE;
91  if (ck_end > p_end) {
92  WARN_(dmfile)("No space for sub-chunk header in parent chunk: ends at offset %s > %s\n",
94  return E_FAIL;
95  }
96  }
97 
99  if (hr != S_OK)
100  return hr;
101  if (chunk->parent) {
102  ck_end += (chunk->size + 1) & ~1;
103  if (ck_end > p_end) {
104  WARN_(dmfile)("No space for sub-chunk data in parent chunk: ends at offset %s > %s\n",
106  return E_FAIL;
107  }
108  }
109 
110  if (chunk->id == FOURCC_LIST || chunk->id == FOURCC_RIFF) {
111  hr = stream_read(stream, &chunk->type, sizeof(FOURCC));
112  if (hr != S_OK)
113  return hr != S_FALSE ? hr : E_FAIL;
114  }
115 
116  TRACE_(dmfile)("Returning %s\n", debugstr_chunk(chunk));
117 
118  return S_OK;
119 }
HRESULT hr
Definition: shlfolder.c:183
#define assert(x)
Definition: debug.h:53
#define CHUNK_HDR_SIZE
Definition: dmobject.c:37
UINT64 offset
Definition: btrfs_drv.h:521
#define E_FAIL
Definition: ddrawi.h:102
#define S_FALSE
Definition: winerror.h:2357
const char * debugstr_chunk(const struct chunk_entry *chunk)
Definition: dmobject.c:48
#define TRACE_(x)
Definition: compat.h:66
#define FOURCC_LIST
Definition: mmsystem.h:565
LONG HRESULT
Definition: typedefs.h:77
uint64_t ULONGLONG
Definition: typedefs.h:65
static double zero
Definition: j0_y0.c:96
#define FOURCC_RIFF
Definition: mmsystem.h:564
Definition: parse.h:22
DWORD FOURCC
Definition: dmdls.h:25
#define S_OK
Definition: intsafe.h:59
UINT16 size
Definition: btrfs_drv.h:520
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
#define WARN_(ch,...)
Definition: debug.h:157
static HRESULT stream_read(IStream *stream, void *data, ULONG size)
Definition: dmobject.c:59

Referenced by col_IDirectMusicObject_ParseDescriptor(), and stream_next_chunk().

◆ stream_next_chunk()

HRESULT stream_next_chunk ( IStream stream,
struct chunk_entry chunk 
)

Definition at line 130 of file dmobject.c.

131 {
132  HRESULT hr;
133 
134  if (chunk->id) {
136  if (FAILED(hr))
137  return hr;
138  }
139 
140  return stream_get_chunk(stream, chunk);
141 }
HRESULT hr
Definition: shlfolder.c:183
LONG HRESULT
Definition: typedefs.h:77
Definition: parse.h:22
HRESULT stream_skip_chunk(IStream *stream, struct chunk_entry *chunk)
Definition: dmobject.c:121
HRESULT stream_get_chunk(IStream *stream, struct chunk_entry *chunk)
Definition: dmobject.c:76

Referenced by dmobj_parsedescriptor(), info_get_name(), and unfo_get_name().

◆ stream_read()

static HRESULT stream_read ( IStream stream,
void data,
ULONG  size 
)
static

Definition at line 59 of file dmobject.c.

60 {
61  ULONG read;
62  HRESULT hr;
63 
64  hr = IStream_Read(stream, data, size, &read);
65  if (FAILED(hr))
66  TRACE_(dmfile)("IStream_Read failed: %08x\n", hr);
67  else if (!read && read < size) {
68  /* All or nothing: Handle a partial read due to end of stream as an error */
69  TRACE_(dmfile)("Short read: %u < %u\n", read, size);
70  return E_FAIL;
71  }
72 
73  return hr;
74 }
HRESULT hr
Definition: shlfolder.c:183
#define E_FAIL
Definition: ddrawi.h:102
#define TRACE_(x)
Definition: compat.h:66
GLsizeiptr size
Definition: glext.h:5919
LONG HRESULT
Definition: typedefs.h:77
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Definition: parse.h:22
unsigned int ULONG
Definition: retypes.h:1
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by stream_chunk_get_data(), and stream_get_chunk().

◆ stream_skip_chunk()

HRESULT stream_skip_chunk ( IStream stream,
struct chunk_entry chunk 
)

Definition at line 121 of file dmobject.c.

122 {
124 
125  end.QuadPart = (chunk->offset.QuadPart + CHUNK_HDR_SIZE + chunk->size + 1) & ~(ULONGLONG)1;
126 
127  return IStream_Seek(stream, end, STREAM_SEEK_SET, NULL);
128 }
#define CHUNK_HDR_SIZE
Definition: dmobject.c:37
GLuint GLuint end
Definition: gl.h:1545
UINT64 offset
Definition: btrfs_drv.h:521
smooth NULL
Definition: ftsmooth.c:416
uint64_t ULONGLONG
Definition: typedefs.h:65
Definition: parse.h:22
UINT16 size
Definition: btrfs_drv.h:520

Referenced by col_IDirectMusicObject_ParseDescriptor(), and stream_next_chunk().

◆ unfo_get_name()

static void unfo_get_name ( IStream stream,
const struct chunk_entry unfo,
DMUS_OBJECTDESC desc,
BOOL  inam 
)
inlinestatic

Definition at line 281 of file dmobject.c.

283 {
284 #ifndef __REACTOS__
285  struct chunk_entry chunk = {.parent = unfo};
286 #else
287  struct chunk_entry chunk = { 0, 0, 0, {{0}}, unfo };
288 #endif
289 
290  while (stream_next_chunk(stream, &chunk) == S_OK)
291  if (chunk.id == DMUS_FOURCC_UNAM_CHUNK || (inam && chunk.id == mmioFOURCC('I','N','A','M')))
292  if (stream_chunk_get_wstr(stream, &chunk, desc->wszName, sizeof(desc->wszName)) == S_OK)
293  desc->dwValidData |= DMUS_OBJ_NAME;
294 }
HRESULT stream_next_chunk(IStream *stream, struct chunk_entry *chunk)
Definition: dmobject.c:130
#define DMUS_OBJ_NAME
Definition: dmusici.h:267
const struct builtin_class_descr * desc
Definition: regcontrol.c:48
Definition: dmobject.h:28
Definition: parse.h:22
#define mmioFOURCC(c0, c1, c2, c3)
Definition: mmsystem.h:38
HRESULT stream_chunk_get_wstr(IStream *stream, const struct chunk_entry *chunk, WCHAR *str, ULONG size)
Definition: dmobject.c:155
#define S_OK
Definition: intsafe.h:59
#define DMUS_FOURCC_UNAM_CHUNK
Definition: dmusicf.h:45

Referenced by dmobj_parsedescriptor().

◆ unimpl_IPersistStream_GetClassID()

HRESULT WINAPI unimpl_IPersistStream_GetClassID ( IPersistStream iface,
CLSID class 
)

Definition at line 381 of file dmobject.c.

382 {
383  TRACE("(%p, %p): method not implemented\n", iface, class);
384  return E_NOTIMPL;
385 }
#define TRACE(s)
Definition: solgame.cpp:4
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ unimpl_IPersistStream_GetSizeMax()

HRESULT WINAPI unimpl_IPersistStream_GetSizeMax ( IPersistStream iface,
ULARGE_INTEGER size 
)

Definition at line 400 of file dmobject.c.

401 {
402  TRACE("(%p, %p): method not implemented\n", iface, size);
403  return E_NOTIMPL;
404 }
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ unimpl_IPersistStream_IsDirty()

HRESULT WINAPI unimpl_IPersistStream_IsDirty ( IPersistStream iface)

Definition at line 387 of file dmobject.c.

388 {
389  TRACE("(%p): method not implemented, always returning S_FALSE\n", iface);
390  return S_FALSE;
391 }
#define S_FALSE
Definition: winerror.h:2357
#define TRACE(s)
Definition: solgame.cpp:4

◆ unimpl_IPersistStream_Save()

HRESULT WINAPI unimpl_IPersistStream_Save ( IPersistStream iface,
IStream stream,
BOOL  clear_dirty 
)

Definition at line 393 of file dmobject.c.

395 {
396  TRACE("(%p, %p, %d): method not implemented\n", iface, stream, clear_dirty);
397  return E_NOTIMPL;
398 }
#define TRACE(s)
Definition: solgame.cpp:4
Definition: parse.h:22
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ WINE_DECLARE_DEBUG_CHANNEL()

WINE_DECLARE_DEBUG_CHANNEL ( dmfile  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dmobj  )