mshtml: Implement onprogress for XMLHttpRequest.
[wine.git] / dlls / dmband / dmutils.c
blob01cec0f4c64e8094655036d00e6242eac6720ff2
1 /* Debug and Helper Functions
3 * Copyright (C) 2004 Rok Mandeljc
4 * Copyright (C) 2004 Raphael Junqueira
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
24 #include <stdio.h>
25 #include <stdarg.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnt.h"
31 #include "wingdi.h"
32 #include "winuser.h"
34 #include "wine/debug.h"
35 #include "objbase.h"
37 #include "initguid.h"
38 #include "dmusici.h"
39 #include "dmusicf.h"
40 #include "dmusics.h"
42 #include "dmutils.h"
43 #include "dmobject.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(dmfile);
47 HRESULT IDirectMusicUtils_IPersistStream_ParseDescGeneric (DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, LPDMUS_OBJECTDESC pDesc) {
49 switch (pChunk->fccID) {
50 case DMUS_FOURCC_GUID_CHUNK: {
51 TRACE(": GUID chunk\n");
52 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
53 IStream_Read (pStm, &pDesc->guidObject, pChunk->dwSize, NULL);
54 break;
56 case DMUS_FOURCC_DATE_CHUNK: {
57 TRACE(": file date chunk\n");
58 pDesc->dwValidData |= DMUS_OBJ_DATE;
59 IStream_Read (pStm, &pDesc->ftDate, pChunk->dwSize, NULL);
60 break;
62 case DMUS_FOURCC_NAME_CHUNK: {
63 TRACE(": name chunk\n");
64 pDesc->dwValidData |= DMUS_OBJ_NAME;
65 IStream_Read (pStm, pDesc->wszName, pChunk->dwSize, NULL);
66 break;
68 case DMUS_FOURCC_FILE_CHUNK: {
69 TRACE(": file name chunk\n");
70 pDesc->dwValidData |= DMUS_OBJ_FILENAME;
71 IStream_Read (pStm, pDesc->wszFileName, pChunk->dwSize, NULL);
72 break;
74 case DMUS_FOURCC_VERSION_CHUNK: {
75 TRACE(": version chunk\n");
76 pDesc->dwValidData |= DMUS_OBJ_VERSION;
77 IStream_Read (pStm, &pDesc->vVersion, pChunk->dwSize, NULL);
78 break;
80 case DMUS_FOURCC_CATEGORY_CHUNK: {
81 TRACE(": category chunk\n");
82 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
83 IStream_Read (pStm, pDesc->wszCategory, pChunk->dwSize, NULL);
84 break;
86 default:
87 /* not handled */
88 return S_FALSE;
91 return S_OK;
94 HRESULT IDirectMusicUtils_IPersistStream_ParseUNFOGeneric (DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, LPDMUS_OBJECTDESC pDesc) {
96 LARGE_INTEGER liMove; /* used when skipping chunks */
98 /**
99 * don't ask me why, but M$ puts INFO elements in UNFO list sometimes
100 * (though strings seem to be valid unicode)
102 switch (pChunk->fccID) {
104 case mmioFOURCC('I','N','A','M'):
105 case DMUS_FOURCC_UNAM_CHUNK: {
106 TRACE(": name chunk\n");
107 pDesc->dwValidData |= DMUS_OBJ_NAME;
108 IStream_Read (pStm, pDesc->wszName, pChunk->dwSize, NULL);
109 TRACE(" - wszName: %s\n", debugstr_w(pDesc->wszName));
110 break;
113 case mmioFOURCC('I','A','R','T'):
114 case DMUS_FOURCC_UART_CHUNK: {
115 TRACE(": artist chunk (ignored)\n");
116 liMove.QuadPart = pChunk->dwSize;
117 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
118 break;
120 case mmioFOURCC('I','C','O','P'):
121 case DMUS_FOURCC_UCOP_CHUNK: {
122 TRACE(": copyright chunk (ignored)\n");
123 liMove.QuadPart = pChunk->dwSize;
124 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
125 break;
127 case mmioFOURCC('I','S','B','J'):
128 case DMUS_FOURCC_USBJ_CHUNK: {
129 TRACE(": subject chunk (ignored)\n");
130 liMove.QuadPart = pChunk->dwSize;
131 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
132 break;
134 case mmioFOURCC('I','C','M','T'):
135 case DMUS_FOURCC_UCMT_CHUNK: {
136 TRACE(": comment chunk (ignored)\n");
137 liMove.QuadPart = pChunk->dwSize;
138 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
139 break;
141 default:
142 /* not handled */
143 return S_FALSE;
146 return S_OK;
149 HRESULT IDirectMusicUtils_IPersistStream_ParseReference (LPPERSISTSTREAM iface, DMUS_PRIVATE_CHUNK* pChunk, IStream* pStm, IDirectMusicObject** ppObject) {
150 DMUS_PRIVATE_CHUNK Chunk;
151 DWORD ListSize[3], ListCount[3];
152 LARGE_INTEGER liMove; /* used when skipping chunks */
153 HRESULT hr;
155 DMUS_IO_REFERENCE ref;
156 DMUS_OBJECTDESC ref_desc;
158 memset(&ref, 0, sizeof(ref));
159 memset(&ref_desc, 0, sizeof(ref_desc));
161 if (pChunk->fccID != DMUS_FOURCC_REF_LIST) {
162 ERR_(dmfile)(": %s chunk should be a REF list\n", debugstr_fourcc (pChunk->fccID));
163 return E_FAIL;
166 ListSize[0] = pChunk->dwSize - sizeof(FOURCC);
167 ListCount[0] = 0;
169 do {
170 IStream_Read (pStm, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
171 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
172 TRACE(": %s chunk (size = %ld)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
174 hr = IDirectMusicUtils_IPersistStream_ParseDescGeneric(&Chunk, pStm, &ref_desc);
175 if (FAILED(hr)) return hr;
177 if (hr == S_FALSE) {
178 switch (Chunk.fccID) {
179 case DMUS_FOURCC_REF_CHUNK: {
180 TRACE(": Reference chunk\n");
181 if (Chunk.dwSize != sizeof(DMUS_IO_REFERENCE)) return E_FAIL;
182 IStream_Read (pStm, &ref, sizeof(DMUS_IO_REFERENCE), NULL);
183 TRACE(" - guidClassID: %s\n", debugstr_dmguid(&ref.guidClassID));
184 TRACE(" - dwValidData: %lu\n", ref.dwValidData);
185 break;
187 default: {
188 TRACE(": unknown chunk (irrelevant & skipping)\n");
189 liMove.QuadPart = Chunk.dwSize;
190 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
191 break;
195 TRACE(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
196 } while (ListCount[0] < ListSize[0]);
198 ref_desc.dwValidData |= DMUS_OBJ_CLASS;
199 ref_desc.guidClass = ref.guidClassID;
201 TRACE("** DM Reference Begin of Load ***\n");
202 TRACE("With Desc:\n");
203 dump_DMUS_OBJECTDESC(&ref_desc);
206 LPDIRECTMUSICGETLOADER pGetLoader = NULL;
207 LPDIRECTMUSICLOADER pLoader = NULL;
209 IStream_QueryInterface (pStm, &IID_IDirectMusicGetLoader, (LPVOID*)&pGetLoader);
210 IDirectMusicGetLoader_GetLoader (pGetLoader, &pLoader);
211 IDirectMusicGetLoader_Release (pGetLoader);
213 hr = IDirectMusicLoader_GetObject (pLoader, &ref_desc, &IID_IDirectMusicObject, (LPVOID*)ppObject);
214 IDirectMusicLoader_Release (pLoader); /* release loader */
216 TRACE("** DM Reference End of Load ***\n");
218 return hr;