jscript: Added Dll[Un]RegisterServer implementation.
[wine] / dlls / qmgr / job.c
1 /*
2  * Background Copy Job Interface for BITS
3  *
4  * Copyright 2007 Google (Roy Shea)
5  *
6  * This library 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.
10  *
11  * This library 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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 "qmgr.h"
22 #include "wine/debug.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
25
26 static void BackgroundCopyJobDestructor(BackgroundCopyJobImpl *This)
27 {
28     HeapFree(GetProcessHeap(), 0, This->displayName);
29     HeapFree(GetProcessHeap(), 0, This);
30 }
31
32 static ULONG WINAPI BITS_IBackgroundCopyJob_AddRef(IBackgroundCopyJob* iface)
33 {
34     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
35     return InterlockedIncrement(&This->ref);
36 }
37
38 static HRESULT WINAPI BITS_IBackgroundCopyJob_QueryInterface(
39     IBackgroundCopyJob* iface, REFIID riid, LPVOID *ppvObject)
40 {
41     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
42     TRACE("IID: %s\n", debugstr_guid(riid));
43
44     if (IsEqualGUID(riid, &IID_IUnknown)
45         || IsEqualGUID(riid, &IID_IBackgroundCopyJob))
46     {
47         *ppvObject = &This->lpVtbl;
48         BITS_IBackgroundCopyJob_AddRef(iface);
49         return S_OK;
50     }
51
52     *ppvObject = NULL;
53     return E_NOINTERFACE;
54 }
55
56 static ULONG WINAPI BITS_IBackgroundCopyJob_Release(IBackgroundCopyJob* iface)
57 {
58     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
59     ULONG ref = InterlockedDecrement(&This->ref);
60
61     if (ref == 0)
62         BackgroundCopyJobDestructor(This);
63
64     return ref;
65 }
66
67 /*** IBackgroundCopyJob methods ***/
68
69 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFileSet(
70     IBackgroundCopyJob* iface,
71     ULONG cFileCount,
72     BG_FILE_INFO *pFileSet)
73 {
74     FIXME("Not implemented\n");
75     return E_NOTIMPL;
76 }
77
78 static HRESULT WINAPI BITS_IBackgroundCopyJob_AddFile(
79     IBackgroundCopyJob* iface,
80     LPCWSTR RemoteUrl,
81     LPCWSTR LocalName)
82 {
83     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
84     IBackgroundCopyFile *pFile;
85     BackgroundCopyFileImpl *file;
86     HRESULT res;
87
88     /* We should return E_INVALIDARG in these cases.  */
89     FIXME("Check for valid filenames and supported protocols\n");
90
91     res = BackgroundCopyFileConstructor(RemoteUrl, LocalName, (LPVOID *) &pFile);
92     if (res != S_OK)
93         return res;
94
95     /* Add a reference to the file to file list */
96     IBackgroundCopyFile_AddRef(pFile);
97     file = (BackgroundCopyFileImpl *) pFile;
98     list_add_head(&This->files, &file->entryFromJob);
99     ++This->jobProgress.FilesTotal;
100
101     return S_OK;
102 }
103
104 static HRESULT WINAPI BITS_IBackgroundCopyJob_EnumFiles(
105     IBackgroundCopyJob* iface,
106     IEnumBackgroundCopyFiles **ppEnum)
107 {
108     TRACE("\n");
109     return EnumBackgroundCopyFilesConstructor((LPVOID *) ppEnum, iface);
110 }
111
112 static HRESULT WINAPI BITS_IBackgroundCopyJob_Suspend(
113     IBackgroundCopyJob* iface)
114 {
115     FIXME("Not implemented\n");
116     return E_NOTIMPL;
117 }
118
119 static HRESULT WINAPI BITS_IBackgroundCopyJob_Resume(
120     IBackgroundCopyJob* iface)
121 {
122     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
123
124     if (This->state == BG_JOB_STATE_CANCELLED
125         || This->state == BG_JOB_STATE_ACKNOWLEDGED)
126     {
127         return BG_E_INVALID_STATE;
128     }
129
130     if (This->jobProgress.FilesTransferred == This->jobProgress.FilesTotal)
131         return BG_E_EMPTY;
132
133     if (This->state == BG_JOB_STATE_CONNECTING
134         || This->state == BG_JOB_STATE_TRANSFERRING)
135     {
136         return S_OK;
137     }
138
139     This->state = BG_JOB_STATE_QUEUED;
140     return S_OK;
141 }
142
143 static HRESULT WINAPI BITS_IBackgroundCopyJob_Cancel(
144     IBackgroundCopyJob* iface)
145 {
146     FIXME("Not implemented\n");
147     return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI BITS_IBackgroundCopyJob_Complete(
151     IBackgroundCopyJob* iface)
152 {
153     FIXME("Not implemented\n");
154     return E_NOTIMPL;
155 }
156
157 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetId(
158     IBackgroundCopyJob* iface,
159     GUID *pVal)
160 {
161     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
162     *pVal = This->jobId;
163     return S_OK;
164 }
165
166 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetType(
167     IBackgroundCopyJob* iface,
168     BG_JOB_TYPE *pVal)
169 {
170     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
171
172     if (!pVal)
173         return E_INVALIDARG;
174
175     *pVal = This->type;
176     return S_OK;
177 }
178
179 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProgress(
180     IBackgroundCopyJob* iface,
181     BG_JOB_PROGRESS *pVal)
182 {
183     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
184
185     if (!pVal)
186         return E_INVALIDARG;
187
188     pVal->BytesTotal = This->jobProgress.BytesTotal;
189     pVal->BytesTransferred = This->jobProgress.BytesTransferred;
190     pVal->FilesTotal = This->jobProgress.FilesTotal;
191     pVal->FilesTransferred = This->jobProgress.FilesTransferred;
192
193     return S_OK;
194 }
195
196 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetTimes(
197     IBackgroundCopyJob* iface,
198     BG_JOB_TIMES *pVal)
199 {
200     FIXME("Not implemented\n");
201     return E_NOTIMPL;
202 }
203
204 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetState(
205     IBackgroundCopyJob* iface,
206     BG_JOB_STATE *pVal)
207 {
208     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
209
210     if (!pVal)
211         return E_INVALIDARG;
212
213     *pVal = This->state;
214     return S_OK;
215 }
216
217 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetError(
218     IBackgroundCopyJob* iface,
219     IBackgroundCopyError **ppError)
220 {
221     FIXME("Not implemented\n");
222     return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetOwner(
226     IBackgroundCopyJob* iface,
227     LPWSTR *pVal)
228 {
229     FIXME("Not implemented\n");
230     return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDisplayName(
234     IBackgroundCopyJob* iface,
235     LPCWSTR Val)
236 {
237     FIXME("Not implemented\n");
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDisplayName(
242     IBackgroundCopyJob* iface,
243     LPWSTR *pVal)
244 {
245     BackgroundCopyJobImpl *This = (BackgroundCopyJobImpl *) iface;
246     int n;
247
248     if (!pVal)
249         return E_INVALIDARG;
250
251     n = (lstrlenW(This->displayName) + 1) * sizeof **pVal;
252     *pVal = CoTaskMemAlloc(n);
253     if (*pVal == NULL)
254         return E_OUTOFMEMORY;
255     memcpy(*pVal, This->displayName, n);
256     return S_OK;
257 }
258
259 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetDescription(
260     IBackgroundCopyJob* iface,
261     LPCWSTR Val)
262 {
263     FIXME("Not implemented\n");
264     return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetDescription(
268     IBackgroundCopyJob* iface,
269     LPWSTR *pVal)
270 {
271     FIXME("Not implemented\n");
272     return E_NOTIMPL;
273 }
274
275 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetPriority(
276     IBackgroundCopyJob* iface,
277     BG_JOB_PRIORITY Val)
278 {
279     FIXME("Not implemented\n");
280     return E_NOTIMPL;
281 }
282
283 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetPriority(
284     IBackgroundCopyJob* iface,
285     BG_JOB_PRIORITY *pVal)
286 {
287     FIXME("Not implemented\n");
288     return E_NOTIMPL;
289 }
290
291 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyFlags(
292     IBackgroundCopyJob* iface,
293     ULONG Val)
294 {
295     FIXME("Not implemented\n");
296     return E_NOTIMPL;
297 }
298
299 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyFlags(
300     IBackgroundCopyJob* iface,
301     ULONG *pVal)
302 {
303     FIXME("Not implemented\n");
304     return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNotifyInterface(
308     IBackgroundCopyJob* iface,
309     IUnknown *Val)
310 {
311     FIXME("Not implemented\n");
312     return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNotifyInterface(
316     IBackgroundCopyJob* iface,
317     IUnknown **pVal)
318 {
319     FIXME("Not implemented\n");
320     return E_NOTIMPL;
321 }
322
323 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetMinimumRetryDelay(
324     IBackgroundCopyJob* iface,
325     ULONG Seconds)
326 {
327     FIXME("Not implemented\n");
328     return E_NOTIMPL;
329 }
330
331 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetMinimumRetryDelay(
332     IBackgroundCopyJob* iface,
333     ULONG *Seconds)
334 {
335     FIXME("Not implemented\n");
336     return E_NOTIMPL;
337 }
338
339 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetNoProgressTimeout(
340     IBackgroundCopyJob* iface,
341     ULONG Seconds)
342 {
343     FIXME("Not implemented\n");
344     return E_NOTIMPL;
345 }
346
347 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetNoProgressTimeout(
348     IBackgroundCopyJob* iface,
349     ULONG *Seconds)
350 {
351     FIXME("Not implemented\n");
352     return E_NOTIMPL;
353 }
354
355 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetErrorCount(
356     IBackgroundCopyJob* iface,
357     ULONG *Errors)
358 {
359     FIXME("Not implemented\n");
360     return E_NOTIMPL;
361 }
362
363 static HRESULT WINAPI BITS_IBackgroundCopyJob_SetProxySettings(
364     IBackgroundCopyJob* iface,
365     BG_JOB_PROXY_USAGE ProxyUsage,
366     const WCHAR *ProxyList,
367     const WCHAR *ProxyBypassList)
368 {
369     FIXME("Not implemented\n");
370     return E_NOTIMPL;
371 }
372
373 static HRESULT WINAPI BITS_IBackgroundCopyJob_GetProxySettings(
374     IBackgroundCopyJob* iface,
375     BG_JOB_PROXY_USAGE *pProxyUsage,
376     LPWSTR *pProxyList,
377     LPWSTR *pProxyBypassList)
378 {
379     FIXME("Not implemented\n");
380     return E_NOTIMPL;
381 }
382
383 static HRESULT WINAPI BITS_IBackgroundCopyJob_TakeOwnership(
384     IBackgroundCopyJob* iface)
385 {
386     FIXME("Not implemented\n");
387     return E_NOTIMPL;
388 }
389
390
391 static const IBackgroundCopyJobVtbl BITS_IBackgroundCopyJob_Vtbl =
392 {
393     BITS_IBackgroundCopyJob_QueryInterface,
394     BITS_IBackgroundCopyJob_AddRef,
395     BITS_IBackgroundCopyJob_Release,
396     BITS_IBackgroundCopyJob_AddFileSet,
397     BITS_IBackgroundCopyJob_AddFile,
398     BITS_IBackgroundCopyJob_EnumFiles,
399     BITS_IBackgroundCopyJob_Suspend,
400     BITS_IBackgroundCopyJob_Resume,
401     BITS_IBackgroundCopyJob_Cancel,
402     BITS_IBackgroundCopyJob_Complete,
403     BITS_IBackgroundCopyJob_GetId,
404     BITS_IBackgroundCopyJob_GetType,
405     BITS_IBackgroundCopyJob_GetProgress,
406     BITS_IBackgroundCopyJob_GetTimes,
407     BITS_IBackgroundCopyJob_GetState,
408     BITS_IBackgroundCopyJob_GetError,
409     BITS_IBackgroundCopyJob_GetOwner,
410     BITS_IBackgroundCopyJob_SetDisplayName,
411     BITS_IBackgroundCopyJob_GetDisplayName,
412     BITS_IBackgroundCopyJob_SetDescription,
413     BITS_IBackgroundCopyJob_GetDescription,
414     BITS_IBackgroundCopyJob_SetPriority,
415     BITS_IBackgroundCopyJob_GetPriority,
416     BITS_IBackgroundCopyJob_SetNotifyFlags,
417     BITS_IBackgroundCopyJob_GetNotifyFlags,
418     BITS_IBackgroundCopyJob_SetNotifyInterface,
419     BITS_IBackgroundCopyJob_GetNotifyInterface,
420     BITS_IBackgroundCopyJob_SetMinimumRetryDelay,
421     BITS_IBackgroundCopyJob_GetMinimumRetryDelay,
422     BITS_IBackgroundCopyJob_SetNoProgressTimeout,
423     BITS_IBackgroundCopyJob_GetNoProgressTimeout,
424     BITS_IBackgroundCopyJob_GetErrorCount,
425     BITS_IBackgroundCopyJob_SetProxySettings,
426     BITS_IBackgroundCopyJob_GetProxySettings,
427     BITS_IBackgroundCopyJob_TakeOwnership,
428 };
429
430 HRESULT BackgroundCopyJobConstructor(LPCWSTR displayName, BG_JOB_TYPE type,
431                                      GUID *pJobId, LPVOID *ppObj)
432 {
433     HRESULT hr;
434     BackgroundCopyJobImpl *This;
435     int n;
436
437     TRACE("(%s,%d,%p)\n", debugstr_w(displayName), type, ppObj);
438
439     This = HeapAlloc(GetProcessHeap(), 0, sizeof *This);
440     if (!This)
441         return E_OUTOFMEMORY;
442
443     This->lpVtbl = &BITS_IBackgroundCopyJob_Vtbl;
444     This->ref = 1;
445     This->type = type;
446
447     n = (lstrlenW(displayName) + 1) *  sizeof *displayName;
448     This->displayName = HeapAlloc(GetProcessHeap(), 0, n);
449     if (!This->displayName)
450     {
451         HeapFree(GetProcessHeap(), 0, This);
452         return E_OUTOFMEMORY;
453     }
454     memcpy(This->displayName, displayName, n);
455
456     hr = CoCreateGuid(&This->jobId);
457     if (FAILED(hr))
458     {
459         HeapFree(GetProcessHeap(), 0, This->displayName);
460         HeapFree(GetProcessHeap(), 0, This);
461         return hr;
462     }
463     *pJobId = This->jobId;
464
465     list_init(&This->files);
466     This->jobProgress.BytesTotal = 0;
467     This->jobProgress.BytesTransferred = 0;
468     This->jobProgress.FilesTotal = 0;
469     This->jobProgress.FilesTransferred = 0;
470
471     This->state = BG_JOB_STATE_SUSPENDED;
472
473     *ppObj = &This->lpVtbl;
474     return S_OK;
475 }