2 * Web Services on Devices
4 * Copyright 2017 Owen Rudge for CodeWeavers
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.
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.
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
26 #include "wsdapi_internal.h"
27 #include "wine/debug.h"
28 #include "wine/heap.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wsdapi
);
33 static inline IWSDiscoveryPublisherImpl
*impl_from_IWSDiscoveryPublisher(IWSDiscoveryPublisher
*iface
)
35 return CONTAINING_RECORD(iface
, IWSDiscoveryPublisherImpl
, IWSDiscoveryPublisher_iface
);
38 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_QueryInterface(IWSDiscoveryPublisher
*iface
, REFIID riid
, void **ppv
)
40 IWSDiscoveryPublisherImpl
*This
= impl_from_IWSDiscoveryPublisher(iface
);
42 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppv
);
46 WARN("Invalid parameter\n");
52 if (IsEqualIID(riid
, &IID_IUnknown
) ||
53 IsEqualIID(riid
, &IID_IWSDiscoveryPublisher
))
55 *ppv
= &This
->IWSDiscoveryPublisher_iface
;
59 WARN("Unknown IID %s\n", debugstr_guid(riid
));
63 IUnknown_AddRef((IUnknown
*)*ppv
);
67 static ULONG WINAPI
IWSDiscoveryPublisherImpl_AddRef(IWSDiscoveryPublisher
*iface
)
69 IWSDiscoveryPublisherImpl
*This
= impl_from_IWSDiscoveryPublisher(iface
);
70 ULONG ref
= InterlockedIncrement(&This
->ref
);
72 TRACE("(%p) ref=%d\n", This
, ref
);
76 static ULONG WINAPI
IWSDiscoveryPublisherImpl_Release(IWSDiscoveryPublisher
*iface
)
78 IWSDiscoveryPublisherImpl
*This
= impl_from_IWSDiscoveryPublisher(iface
);
79 ULONG ref
= InterlockedDecrement(&This
->ref
);
80 struct notificationSink
*sink
, *cursor
;
82 TRACE("(%p) ref=%d\n", This
, ref
);
86 terminate_networking(This
);
88 if (This
->xmlContext
!= NULL
)
90 IWSDXMLContext_Release(This
->xmlContext
);
93 LIST_FOR_EACH_ENTRY_SAFE(sink
, cursor
, &This
->notificationSinks
, struct notificationSink
, entry
)
95 IWSDiscoveryPublisherNotify_Release(sink
->notificationSink
);
96 list_remove(&sink
->entry
);
97 HeapFree(GetProcessHeap(), 0, sink
);
100 HeapFree(GetProcessHeap(), 0, This
);
106 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_SetAddressFamily(IWSDiscoveryPublisher
*This
, DWORD dwAddressFamily
)
108 IWSDiscoveryPublisherImpl
*impl
= impl_from_IWSDiscoveryPublisher(This
);
110 TRACE("(%p, %d)\n", This
, dwAddressFamily
);
112 /* Has the address family already been set? */
113 if (impl
->addressFamily
!= 0)
115 return STG_E_INVALIDFUNCTION
;
118 if ((dwAddressFamily
== WSDAPI_ADDRESSFAMILY_IPV4
) || (dwAddressFamily
== WSDAPI_ADDRESSFAMILY_IPV6
) ||
119 (dwAddressFamily
== (WSDAPI_ADDRESSFAMILY_IPV4
| WSDAPI_ADDRESSFAMILY_IPV6
)))
121 /* TODO: Check that the address family is supported by the system */
122 impl
->addressFamily
= dwAddressFamily
;
129 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_RegisterNotificationSink(IWSDiscoveryPublisher
*This
, IWSDiscoveryPublisherNotify
*pSink
)
131 IWSDiscoveryPublisherImpl
*impl
= impl_from_IWSDiscoveryPublisher(This
);
132 struct notificationSink
*sink
;
134 TRACE("(%p, %p)\n", This
, pSink
);
141 sink
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*sink
));
145 return E_OUTOFMEMORY
;
148 sink
->notificationSink
= pSink
;
149 IWSDiscoveryPublisherNotify_AddRef(pSink
);
151 list_add_tail(&impl
->notificationSinks
, &sink
->entry
);
153 if ((!impl
->publisherStarted
) && (!init_networking(impl
)))
159 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_UnRegisterNotificationSink(IWSDiscoveryPublisher
*This
, IWSDiscoveryPublisherNotify
*pSink
)
161 IWSDiscoveryPublisherImpl
*impl
= impl_from_IWSDiscoveryPublisher(This
);
162 struct notificationSink
*sink
;
164 TRACE("(%p, %p)\n", This
, pSink
);
171 LIST_FOR_EACH_ENTRY(sink
, &impl
->notificationSinks
, struct notificationSink
, entry
)
173 if (sink
->notificationSink
== pSink
)
175 IWSDiscoveryPublisherNotify_Release(pSink
);
176 list_remove(&sink
->entry
);
177 HeapFree(GetProcessHeap(), 0, sink
);
183 /* Notification sink is not registered */
187 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_Publish(IWSDiscoveryPublisher
*This
, LPCWSTR pszId
, ULONGLONG ullMetadataVersion
, ULONGLONG ullInstanceId
,
188 ULONGLONG ullMessageNumber
, LPCWSTR pszSessionId
, const WSD_NAME_LIST
*pTypesList
,
189 const WSD_URI_LIST
*pScopesList
, const WSD_URI_LIST
*pXAddrsList
)
191 return IWSDiscoveryPublisher_PublishEx(This
, pszId
, ullMetadataVersion
, ullInstanceId
, ullMessageNumber
,
192 pszSessionId
, pTypesList
, pScopesList
, pXAddrsList
, NULL
, NULL
, NULL
, NULL
, NULL
);
195 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_UnPublish(IWSDiscoveryPublisher
*This
, LPCWSTR pszId
, ULONGLONG ullInstanceId
, ULONGLONG ullMessageNumber
,
196 LPCWSTR pszSessionId
, const WSDXML_ELEMENT
*pAny
)
198 IWSDiscoveryPublisherImpl
*impl
= impl_from_IWSDiscoveryPublisher(This
);
200 TRACE("(%p, %s, %s, %s, %s, %p)\n", This
, debugstr_w(pszId
), wine_dbgstr_longlong(ullInstanceId
),
201 wine_dbgstr_longlong(ullMessageNumber
), debugstr_w(pszSessionId
), pAny
);
203 if ((!impl
->publisherStarted
) || (pszId
== NULL
) || (lstrlenW(pszId
) > WSD_MAX_TEXT_LENGTH
) ||
204 ((pszSessionId
!= NULL
) && (lstrlenW(pszSessionId
) > WSD_MAX_TEXT_LENGTH
)))
209 return send_bye_message(impl
, pszId
, ullInstanceId
, ullMessageNumber
, pszSessionId
, pAny
);
212 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_MatchProbe(IWSDiscoveryPublisher
*This
, const WSD_SOAP_MESSAGE
*pProbeMessage
,
213 IWSDMessageParameters
*pMessageParameters
, LPCWSTR pszId
, ULONGLONG ullMetadataVersion
,
214 ULONGLONG ullInstanceId
, ULONGLONG ullMessageNumber
, LPCWSTR pszSessionId
,
215 const WSD_NAME_LIST
*pTypesList
, const WSD_URI_LIST
*pScopesList
,
216 const WSD_URI_LIST
*pXAddrsList
)
218 FIXME("(%p, %p, %p, %s, %s, %s, %s, %s, %p, %p, %p)\n", This
, pProbeMessage
, pMessageParameters
, debugstr_w(pszId
),
219 wine_dbgstr_longlong(ullMetadataVersion
), wine_dbgstr_longlong(ullInstanceId
), wine_dbgstr_longlong(ullMessageNumber
), debugstr_w(pszSessionId
),
220 pTypesList
, pScopesList
, pXAddrsList
);
225 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_MatchResolve(IWSDiscoveryPublisher
*This
, const WSD_SOAP_MESSAGE
*pResolveMessage
,
226 IWSDMessageParameters
*pMessageParameters
, LPCWSTR pszId
, ULONGLONG ullMetadataVersion
,
227 ULONGLONG ullInstanceId
, ULONGLONG ullMessageNumber
, LPCWSTR pszSessionId
,
228 const WSD_NAME_LIST
*pTypesList
, const WSD_URI_LIST
*pScopesList
,
229 const WSD_URI_LIST
*pXAddrsList
)
231 FIXME("(%p, %p, %p, %s, %s, %s, %s, %s, %p, %p, %p)\n", This
, pResolveMessage
, pMessageParameters
, debugstr_w(pszId
),
232 wine_dbgstr_longlong(ullMetadataVersion
), wine_dbgstr_longlong(ullInstanceId
), wine_dbgstr_longlong(ullMessageNumber
), debugstr_w(pszSessionId
),
233 pTypesList
, pScopesList
, pXAddrsList
);
238 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_PublishEx(IWSDiscoveryPublisher
*This
, LPCWSTR pszId
, ULONGLONG ullMetadataVersion
,
239 ULONGLONG ullInstanceId
, ULONGLONG ullMessageNumber
, LPCWSTR pszSessionId
,
240 const WSD_NAME_LIST
*pTypesList
, const WSD_URI_LIST
*pScopesList
,
241 const WSD_URI_LIST
*pXAddrsList
, const WSDXML_ELEMENT
*pHeaderAny
,
242 const WSDXML_ELEMENT
*pReferenceParameterAny
, const WSDXML_ELEMENT
*pPolicyAny
,
243 const WSDXML_ELEMENT
*pEndpointReferenceAny
, const WSDXML_ELEMENT
*pAny
)
245 IWSDiscoveryPublisherImpl
*impl
= impl_from_IWSDiscoveryPublisher(This
);
247 TRACE("(%p, %s, %s, %s, %s, %s, %p, %p, %p, %p, %p, %p, %p, %p)\n", This
, debugstr_w(pszId
), wine_dbgstr_longlong(ullMetadataVersion
),
248 wine_dbgstr_longlong(ullInstanceId
), wine_dbgstr_longlong(ullMessageNumber
), debugstr_w(pszSessionId
), pTypesList
, pScopesList
, pXAddrsList
,
249 pHeaderAny
, pReferenceParameterAny
, pPolicyAny
, pEndpointReferenceAny
, pAny
);
251 if ((!impl
->publisherStarted
) || (pszId
== NULL
) || (lstrlenW(pszId
) > WSD_MAX_TEXT_LENGTH
) ||
252 ((pszSessionId
!= NULL
) && (lstrlenW(pszSessionId
) > WSD_MAX_TEXT_LENGTH
)))
257 return send_hello_message(impl
, pszId
, ullMetadataVersion
, ullInstanceId
, ullMessageNumber
, pszSessionId
,
258 pTypesList
, pScopesList
, pXAddrsList
, pHeaderAny
, pReferenceParameterAny
, pEndpointReferenceAny
, pAny
);
261 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_MatchProbeEx(IWSDiscoveryPublisher
*This
, const WSD_SOAP_MESSAGE
*pProbeMessage
,
262 IWSDMessageParameters
*pMessageParameters
, LPCWSTR pszId
, ULONGLONG ullMetadataVersion
,
263 ULONGLONG ullInstanceId
, ULONGLONG ullMessageNumber
, LPCWSTR pszSessionId
,
264 const WSD_NAME_LIST
*pTypesList
, const WSD_URI_LIST
*pScopesList
,
265 const WSD_URI_LIST
*pXAddrsList
, const WSDXML_ELEMENT
*pHeaderAny
,
266 const WSDXML_ELEMENT
*pReferenceParameterAny
, const WSDXML_ELEMENT
*pPolicyAny
,
267 const WSDXML_ELEMENT
*pEndpointReferenceAny
, const WSDXML_ELEMENT
*pAny
)
269 FIXME("(%p, %p, %p, %s, %s, %s, %s, %s, %p, %p, %p, %p, %p, %p, %p, %p)\n", This
, pProbeMessage
, pMessageParameters
, debugstr_w(pszId
),
270 wine_dbgstr_longlong(ullMetadataVersion
), wine_dbgstr_longlong(ullInstanceId
), wine_dbgstr_longlong(ullMessageNumber
), debugstr_w(pszSessionId
),
271 pTypesList
, pScopesList
, pXAddrsList
, pHeaderAny
, pReferenceParameterAny
, pPolicyAny
, pEndpointReferenceAny
, pAny
);
276 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_MatchResolveEx(IWSDiscoveryPublisher
*This
, const WSD_SOAP_MESSAGE
*pResolveMessage
,
277 IWSDMessageParameters
*pMessageParameters
, LPCWSTR pszId
, ULONGLONG ullMetadataVersion
,
278 ULONGLONG ullInstanceId
, ULONGLONG ullMessageNumber
, LPCWSTR pszSessionId
,
279 const WSD_NAME_LIST
*pTypesList
, const WSD_URI_LIST
*pScopesList
,
280 const WSD_URI_LIST
*pXAddrsList
, const WSDXML_ELEMENT
*pHeaderAny
,
281 const WSDXML_ELEMENT
*pReferenceParameterAny
, const WSDXML_ELEMENT
*pPolicyAny
,
282 const WSDXML_ELEMENT
*pEndpointReferenceAny
, const WSDXML_ELEMENT
*pAny
)
284 FIXME("(%p, %p, %p, %s, %s, %s, %s, %s, %p, %p, %p, %p, %p, %p, %p, %p)\n", This
, pResolveMessage
, pMessageParameters
, debugstr_w(pszId
),
285 wine_dbgstr_longlong(ullMetadataVersion
), wine_dbgstr_longlong(ullInstanceId
), wine_dbgstr_longlong(ullMessageNumber
), debugstr_w(pszSessionId
),
286 pTypesList
, pScopesList
, pXAddrsList
, pHeaderAny
, pReferenceParameterAny
, pPolicyAny
, pEndpointReferenceAny
, pAny
);
291 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_RegisterScopeMatchingRule(IWSDiscoveryPublisher
*This
, IWSDScopeMatchingRule
*pScopeMatchingRule
)
293 FIXME("(%p, %p)\n", This
, pScopeMatchingRule
);
297 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_UnRegisterScopeMatchingRule(IWSDiscoveryPublisher
*This
, IWSDScopeMatchingRule
*pScopeMatchingRule
)
299 FIXME("(%p, %p)\n", This
, pScopeMatchingRule
);
303 static HRESULT WINAPI
IWSDiscoveryPublisherImpl_GetXMLContext(IWSDiscoveryPublisher
*This
, IWSDXMLContext
**ppContext
)
305 IWSDiscoveryPublisherImpl
*impl
= impl_from_IWSDiscoveryPublisher(This
);
307 TRACE("%p, %p)\n", This
, ppContext
);
309 if (ppContext
== NULL
)
312 if (impl
->xmlContext
!= NULL
)
314 IWSDXMLContext_AddRef(impl
->xmlContext
);
317 *ppContext
= impl
->xmlContext
;
321 static const IWSDiscoveryPublisherVtbl publisher_vtbl
=
323 IWSDiscoveryPublisherImpl_QueryInterface
,
324 IWSDiscoveryPublisherImpl_AddRef
,
325 IWSDiscoveryPublisherImpl_Release
,
326 IWSDiscoveryPublisherImpl_SetAddressFamily
,
327 IWSDiscoveryPublisherImpl_RegisterNotificationSink
,
328 IWSDiscoveryPublisherImpl_UnRegisterNotificationSink
,
329 IWSDiscoveryPublisherImpl_Publish
,
330 IWSDiscoveryPublisherImpl_UnPublish
,
331 IWSDiscoveryPublisherImpl_MatchProbe
,
332 IWSDiscoveryPublisherImpl_MatchResolve
,
333 IWSDiscoveryPublisherImpl_PublishEx
,
334 IWSDiscoveryPublisherImpl_MatchProbeEx
,
335 IWSDiscoveryPublisherImpl_MatchResolveEx
,
336 IWSDiscoveryPublisherImpl_RegisterScopeMatchingRule
,
337 IWSDiscoveryPublisherImpl_UnRegisterScopeMatchingRule
,
338 IWSDiscoveryPublisherImpl_GetXMLContext
341 HRESULT WINAPI
WSDCreateDiscoveryPublisher(IWSDXMLContext
*pContext
, IWSDiscoveryPublisher
**ppPublisher
)
343 IWSDiscoveryPublisherImpl
*obj
;
346 TRACE("(%p, %p)\n", pContext
, ppPublisher
);
348 if (ppPublisher
== NULL
)
350 WARN("Invalid parameter: ppPublisher == NULL\n");
356 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*obj
));
360 WARN("Out of memory\n");
361 return E_OUTOFMEMORY
;
364 obj
->IWSDiscoveryPublisher_iface
.lpVtbl
= &publisher_vtbl
;
367 if (pContext
== NULL
)
369 ret
= WSDXMLCreateContext(&obj
->xmlContext
);
373 WARN("Unable to create XML context\n");
380 obj
->xmlContext
= pContext
;
381 IWSDXMLContext_AddRef(pContext
);
384 ret
= register_namespaces(obj
->xmlContext
);
388 WARN("Unable to register default namespaces\n");
394 list_init(&obj
->notificationSinks
);
396 *ppPublisher
= &obj
->IWSDiscoveryPublisher_iface
;
397 TRACE("Returning iface %p\n", *ppPublisher
);