[PATCH 2/6] wsdapi: Add stub implementation of IWSDiscoveryPublisher_PublishEx.

Huw Davies huw at codeweavers.com
Tue Mar 13 05:22:44 CDT 2018


On Mon, Mar 12, 2018 at 10:58:28PM +0000, Owen Rudge wrote:
> diff --git a/dlls/wsdapi/soap.c b/dlls/wsdapi/soap.c
> new file mode 100644
> index 0000000000..cb1ec0ea9d
> --- /dev/null
> +++ b/dlls/wsdapi/soap.c
> @@ -0,0 +1,73 @@
> +/*
> + * Web Services on Devices
> + *
> + * Copyright 2017-2018 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>
> +#include <limits.h>
> +
> +#define COBJMACROS
> +
> +#include "wsdapi_internal.h"
> +#include "wine/debug.h"
> +#include "wine/heap.h"
> +
> +#define APP_MAX_DELAY                       500
> +
> +static BOOL write_and_send_message(IWSDiscoveryPublisherImpl *impl, WSD_SOAP_HEADER *header, WSDXML_ELEMENT *body_element,

If you return HRESULT rather than BOOL you don't need the hack in the
caller.  Generally, many of the helper functions in this series would
be better returning HRESULT.

> +    struct list *discovered_namespaces, IWSDUdpAddress *remote_address, int max_initial_delay)
> +{
> +    const char *xml_header = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

static const char xml_header[] = "...";

You can then use sizeof() instead of strlen below.

> +    ULONG xml_length = 0;

This is unused at the moment, add it in a later patch when needed.

> +    int xml_header_len;
> +    char *full_xml;
> +    BOOL ret = FALSE;
> +
> +    /* TODO: Create SOAP envelope */
> +
> +    /* Prefix the XML header */
> +    xml_header_len = strlen(xml_header);
> +    full_xml = heap_alloc_zero(xml_length + xml_header_len + 1);

Zeroing the string is expensive just to get a trailing \0.

> +
> +    if (full_xml == NULL)
> +        return FALSE;

You'd return E_OUTOFMEMORY here.

> +
> +    memcpy(full_xml, xml_header, xml_header_len);
> +
> +    /* TODO: Send the message */
> +
> +    heap_free(full_xml);

I'll let you off immediately free()ing the string you've allocated,
since otherwise doing this later in one patch would make that patch
larger.

> +
> +    return ret;
> +}
> +
> +HRESULT send_hello_message(IWSDiscoveryPublisherImpl *impl, LPCWSTR id, ULONGLONG metadata_ver, ULONGLONG instance_id,
> +    ULONGLONG msg_num, LPCWSTR session_id, const WSD_NAME_LIST *types_list, const WSD_URI_LIST *scopes_list,
> +    const WSD_URI_LIST *xaddrs_list, const WSDXML_ELEMENT *hdr_any, const WSDXML_ELEMENT *ref_param_any,
> +    const WSDXML_ELEMENT *endpoint_ref_any, const WSDXML_ELEMENT *any)
> +{
> +    HRESULT ret = E_NOTIMPL;
> +
> +    /* TODO: Populate message body */
> +
> +    /* Write and send the message */
> +    if (write_and_send_message(impl, NULL, NULL, NULL, NULL, APP_MAX_DELAY))
> +        ret = S_OK;

So here you'd just return write_and_send_message();
> +
> +    return ret;
> +}
> diff --git a/dlls/wsdapi/wsdapi_internal.h b/dlls/wsdapi/wsdapi_internal.h
> index 22de4a842a..631dfb3d7e 100644
> --- a/dlls/wsdapi/wsdapi_internal.h
> +++ b/dlls/wsdapi/wsdapi_internal.h
> @@ -32,4 +32,28 @@
>  
>  #define WSD_MAX_TEXT_LENGTH    8192
>  
> +/* discovery.c */
> +
> +struct notificationSink
> +{
> +    struct list entry;
> +    IWSDiscoveryPublisherNotify *notificationSink;
> +};
> +
> +typedef struct IWSDiscoveryPublisherImpl {
> +    IWSDiscoveryPublisher IWSDiscoveryPublisher_iface;
> +    LONG                  ref;
> +    IWSDXMLContext        *xmlContext;
> +    DWORD                 addressFamily;
> +    struct list           notificationSinks;
> +    BOOL                  publisherStarted;
> +} IWSDiscoveryPublisherImpl;
> +
> +/* soap.c */
> +
> +HRESULT send_hello_message(IWSDiscoveryPublisherImpl *impl, LPCWSTR id, ULONGLONG metadata_ver, ULONGLONG instance_id,
> +    ULONGLONG msg_num, LPCWSTR session_id, const WSD_NAME_LIST *types_list, const WSD_URI_LIST *scopes_list,
> +    const WSD_URI_LIST *xaddrs_list, const WSDXML_ELEMENT *hdr_any, const WSDXML_ELEMENT *ref_param_any,
> +    const WSDXML_ELEMENT *endpoint_ref_any, const WSDXML_ELEMENT *any);
> +
>  #endif
> 

> 




More information about the wine-devel mailing list