1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
* Web Services on Devices
*
* Copyright 2017 Owen Rudge for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#define COBJMACROS
#include "windef.h"
#include "winbase.h"
#include "wine/debug.h"
#include "wsdapi.h"
WINE_DEFAULT_DEBUG_CHANNEL(wsdapi);
typedef struct IWSDMessageParametersImpl {
IWSDMessageParameters IWSDMessageParameters_iface;
LONG ref;
IWSDAddress *localAddress;
IWSDAddress *remoteAddress;
} IWSDMessageParametersImpl;
typedef struct IWSDUdpMessageParametersImpl {
IWSDMessageParametersImpl base;
WSDUdpRetransmitParams retransmitParams;
} IWSDUdpMessageParametersImpl;
static inline IWSDMessageParametersImpl *impl_from_IWSDMessageParameters(IWSDMessageParameters *iface)
{
return CONTAINING_RECORD(iface, IWSDMessageParametersImpl, IWSDMessageParameters_iface);
}
static inline IWSDUdpMessageParametersImpl *impl_from_IWSDUdpMessageParameters(IWSDUdpMessageParameters *iface)
{
return CONTAINING_RECORD(iface, IWSDUdpMessageParametersImpl, base.IWSDMessageParameters_iface);
}
/* IWSDMessageParameters implementation */
static ULONG IWSDMessageParametersImpl_AddRef(IWSDMessageParameters *iface)
{
IWSDMessageParametersImpl *This = impl_from_IWSDMessageParameters(iface);
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) ref=%ld\n", This, ref);
return ref;
}
static ULONG IWSDMessageParametersImpl_Release(IWSDMessageParameters *iface)
{
IWSDMessageParametersImpl *This = impl_from_IWSDMessageParameters(iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) ref=%ld\n", This, ref);
if (ref == 0)
{
if (This->localAddress != NULL)
{
IWSDAddress_Release(This->localAddress);
}
if (This->remoteAddress != NULL)
{
IWSDAddress_Release(This->remoteAddress);
}
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
static HRESULT IWSDMessageParametersImpl_GetLocalAddress(IWSDMessageParameters *This, IWSDAddress **ppAddress)
{
IWSDMessageParametersImpl *impl = impl_from_IWSDMessageParameters(This);
TRACE("(%p, %p)\n", impl, ppAddress);
if (ppAddress == NULL)
{
return E_POINTER;
}
if (impl->localAddress == NULL)
{
return E_ABORT;
}
*ppAddress = impl->localAddress;
IWSDAddress_AddRef(*ppAddress);
return S_OK;
}
static HRESULT IWSDMessageParametersImpl_SetLocalAddress(IWSDMessageParameters *This, IWSDAddress *pAddress)
{
IWSDMessageParametersImpl *impl = impl_from_IWSDMessageParameters(This);
TRACE("(%p, %p)\n", impl, pAddress);
if (pAddress == NULL)
{
return E_POINTER;
}
if (impl->localAddress != NULL)
{
IWSDAddress_Release(impl->localAddress);
}
impl->localAddress = pAddress;
IWSDAddress_AddRef(pAddress);
return S_OK;
}
static HRESULT IWSDMessageParametersImpl_GetRemoteAddress(IWSDMessageParameters *This, IWSDAddress **ppAddress)
{
IWSDMessageParametersImpl *impl = impl_from_IWSDMessageParameters(This);
TRACE("(%p, %p)\n", impl, ppAddress);
if (ppAddress == NULL)
{
return E_POINTER;
}
if (impl->remoteAddress == NULL)
{
return E_ABORT;
}
*ppAddress = impl->remoteAddress;
IWSDAddress_AddRef(*ppAddress);
return S_OK;
}
static HRESULT IWSDMessageParametersImpl_SetRemoteAddress(IWSDMessageParameters *This, IWSDAddress *pAddress)
{
IWSDMessageParametersImpl *impl = impl_from_IWSDMessageParameters(This);
TRACE("(%p, %p)\n", impl, pAddress);
if (pAddress == NULL)
{
return E_POINTER;
}
if (impl->remoteAddress != NULL)
{
IWSDAddress_Release(impl->remoteAddress);
}
impl->remoteAddress = pAddress;
IWSDAddress_AddRef(pAddress);
return S_OK;
}
static HRESULT IWSDMessageParametersImpl_GetLowerParameters(IWSDMessageParameters *This, IWSDMessageParameters **ppTxParams)
{
FIXME("(%p, %p)\n", This, ppTxParams);
return E_NOTIMPL;
}
/* IWSDUdpMessageParameters implementation */
static HRESULT WINAPI IWSDUdpMessageParametersImpl_QueryInterface(IWSDUdpMessageParameters *iface, REFIID riid, void **ppv)
{
IWSDUdpMessageParametersImpl *This = impl_from_IWSDUdpMessageParameters(iface);
TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppv);
if (!ppv)
{
WARN("Invalid parameter\n");
return E_INVALIDARG;
}
*ppv = NULL;
if (IsEqualIID(riid, &IID_IUnknown) ||
IsEqualIID(riid, &IID_IWSDMessageParameters) ||
IsEqualIID(riid, &IID_IWSDUdpMessageParameters))
{
*ppv = &This->base.IWSDMessageParameters_iface;
}
else
{
WARN("Unknown IID %s\n", debugstr_guid(riid));
return E_NOINTERFACE;
}
IUnknown_AddRef((IUnknown*)*ppv);
return S_OK;
}
static ULONG WINAPI IWSDUdpMessageParametersImpl_AddRef(IWSDUdpMessageParameters *iface)
{
return IWSDMessageParametersImpl_AddRef((IWSDMessageParameters *)iface);
}
static ULONG WINAPI IWSDUdpMessageParametersImpl_Release(IWSDUdpMessageParameters *iface)
{
return IWSDMessageParametersImpl_Release((IWSDMessageParameters *)iface);
}
static HRESULT WINAPI IWSDUdpMessageParametersImpl_GetLocalAddress(IWSDUdpMessageParameters *This, IWSDAddress **ppAddress)
{
return IWSDMessageParametersImpl_GetLocalAddress((IWSDMessageParameters *)This, ppAddress);
}
static HRESULT WINAPI IWSDUdpMessageParametersImpl_SetLocalAddress(IWSDUdpMessageParameters *This, IWSDAddress *pAddress)
{
return IWSDMessageParametersImpl_SetLocalAddress((IWSDMessageParameters *)This, pAddress);
}
static HRESULT WINAPI IWSDUdpMessageParametersImpl_GetRemoteAddress(IWSDUdpMessageParameters *This, IWSDAddress **ppAddress)
{
return IWSDMessageParametersImpl_GetRemoteAddress((IWSDMessageParameters *)This, ppAddress);
}
static HRESULT WINAPI IWSDUdpMessageParametersImpl_SetRemoteAddress(IWSDUdpMessageParameters *This, IWSDAddress *pAddress)
{
return IWSDMessageParametersImpl_SetRemoteAddress((IWSDMessageParameters *)This, pAddress);
}
static HRESULT WINAPI IWSDUdpMessageParametersImpl_GetLowerParameters(IWSDUdpMessageParameters *This, IWSDMessageParameters **ppTxParams)
{
return IWSDMessageParametersImpl_GetLowerParameters((IWSDMessageParameters *)This, ppTxParams);
}
static HRESULT WINAPI IWSDUdpMessageParametersImpl_SetRetransmitParams(IWSDUdpMessageParameters *This, const WSDUdpRetransmitParams *pParams)
{
IWSDUdpMessageParametersImpl *impl = impl_from_IWSDUdpMessageParameters(This);
TRACE("(%p, %p)\n", impl, pParams);
if (pParams == NULL)
{
return E_INVALIDARG;
}
impl->retransmitParams = *pParams;
return S_OK;
}
static HRESULT WINAPI IWSDUdpMessageParametersImpl_GetRetransmitParams(IWSDUdpMessageParameters *This, WSDUdpRetransmitParams *pParams)
{
IWSDUdpMessageParametersImpl *impl = impl_from_IWSDUdpMessageParameters(This);
TRACE("(%p, %p)\n", impl, pParams);
if (pParams == NULL)
{
return E_POINTER;
}
* pParams = impl->retransmitParams;
return S_OK;
}
static const IWSDUdpMessageParametersVtbl udpMsgParamsVtbl =
{
/* IUnknown */
IWSDUdpMessageParametersImpl_QueryInterface,
IWSDUdpMessageParametersImpl_AddRef,
IWSDUdpMessageParametersImpl_Release,
/* IWSDMessageParameters */
IWSDUdpMessageParametersImpl_GetLocalAddress,
IWSDUdpMessageParametersImpl_SetLocalAddress,
IWSDUdpMessageParametersImpl_GetRemoteAddress,
IWSDUdpMessageParametersImpl_SetRemoteAddress,
IWSDUdpMessageParametersImpl_GetLowerParameters,
/* IWSDUdpMessageParameters */
IWSDUdpMessageParametersImpl_SetRetransmitParams,
IWSDUdpMessageParametersImpl_GetRetransmitParams
};
HRESULT WINAPI WSDCreateUdpMessageParameters(IWSDUdpMessageParameters **ppTxParams)
{
IWSDUdpMessageParametersImpl *obj;
TRACE("(%p)\n", ppTxParams);
if (ppTxParams == NULL)
{
WARN("Invalid parameter: ppTxParams == NULL\n");
return E_POINTER;
}
*ppTxParams = NULL;
obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*obj));
if (!obj) return E_OUTOFMEMORY;
obj->base.IWSDMessageParameters_iface.lpVtbl = (IWSDMessageParametersVtbl *)&udpMsgParamsVtbl;
obj->base.ref = 1;
/* Populate default retransmit parameters */
obj->retransmitParams.ulSendDelay = 0;
obj->retransmitParams.ulRepeat = 1;
obj->retransmitParams.ulRepeatMinDelay = 50;
obj->retransmitParams.ulRepeatMaxDelay = 250;
obj->retransmitParams.ulRepeatUpperDelay = 450;
*ppTxParams = (IWSDUdpMessageParameters *)&obj->base.IWSDMessageParameters_iface;
TRACE("Returning iface %p\n", *ppTxParams);
return S_OK;
}