service.c 11.5 KB
Newer Older
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
/*
 * Copyright 2009 Hans Leidekker 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 "config.h"
#include <stdarg.h>
#include <stdio.h>

#define COBJMACROS

#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "ole2.h"
#include "netfw.h"

#include "wine/debug.h"
#include "wine/unicode.h"
#include "hnetcfg_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(hnetcfg);

typedef struct fw_service
{
39
    INetFwService INetFwService_iface;
40 41 42 43 44
    LONG refs;
} fw_service;

static inline fw_service *impl_from_INetFwService( INetFwService *iface )
{
45
    return CONTAINING_RECORD(iface, fw_service, INetFwService_iface);
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
}

static ULONG WINAPI fw_service_AddRef(
    INetFwService *iface )
{
    fw_service *fw_service = impl_from_INetFwService( iface );
    return InterlockedIncrement( &fw_service->refs );
}

static ULONG WINAPI fw_service_Release(
    INetFwService *iface )
{
    fw_service *fw_service = impl_from_INetFwService( iface );
    LONG refs = InterlockedDecrement( &fw_service->refs );
    if (!refs)
    {
        TRACE("destroying %p\n", fw_service);
        HeapFree( GetProcessHeap(), 0, fw_service );
    }
    return refs;
}

static HRESULT WINAPI fw_service_QueryInterface(
    INetFwService *iface,
    REFIID riid,
    void **ppvObject )
{
    fw_service *This = impl_from_INetFwService( iface );

    TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );

    if ( IsEqualGUID( riid, &IID_INetFwService ) ||
         IsEqualGUID( riid, &IID_IDispatch ) ||
         IsEqualGUID( riid, &IID_IUnknown ) )
    {
        *ppvObject = iface;
    }
    else
    {
        FIXME("interface %s not implemented\n", debugstr_guid(riid));
        return E_NOINTERFACE;
    }
    INetFwService_AddRef( iface );
    return S_OK;
}

static HRESULT WINAPI fw_service_GetTypeInfoCount(
    INetFwService *iface,
    UINT *pctinfo )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %p\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_GetTypeInfo(
    INetFwService *iface,
    UINT iTInfo,
    LCID lcid,
    ITypeInfo **ppTInfo )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_GetIDsOfNames(
    INetFwService *iface,
    REFIID riid,
    LPOLESTR *rgszNames,
    UINT cNames,
    LCID lcid,
    DISPID *rgDispId )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_Invoke(
    INetFwService *iface,
    DISPID dispIdMember,
    REFIID riid,
    LCID lcid,
    WORD wFlags,
    DISPPARAMS *pDispParams,
    VARIANT *pVarResult,
    EXCEPINFO *pExcepInfo,
    UINT *puArgErr )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
          lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_get_Name(
    INetFwService *iface,
    BSTR *name )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %p\n", This, name);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_get_Type(
    INetFwService *iface,
    NET_FW_SERVICE_TYPE *type )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %p\n", This, type);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_get_Customized(
        INetFwService *iface,
        VARIANT_BOOL *customized )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %p\n", This, customized);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_get_IpVersion(
    INetFwService *iface,
    NET_FW_IP_VERSION *ipVersion )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %p\n", This, ipVersion);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_put_IpVersion(
    INetFwService *iface,
    NET_FW_IP_VERSION ipVersion )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %u\n", This, ipVersion);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_get_Scope(
    INetFwService *iface,
    NET_FW_SCOPE *scope )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %p\n", This, scope);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_put_Scope(
    INetFwService *iface,
    NET_FW_SCOPE scope )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %u\n", This, scope);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_get_RemoteAddresses(
    INetFwService *iface,
    BSTR *remoteAddrs )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %p\n", This, remoteAddrs);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_put_RemoteAddresses(
    INetFwService *iface,
    BSTR remoteAddrs )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %s\n", This, debugstr_w(remoteAddrs));
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_get_Enabled(
    INetFwService *iface,
    VARIANT_BOOL *enabled )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %p\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_put_Enabled(
    INetFwService *iface,
    VARIANT_BOOL enabled )
{
    fw_service *This = impl_from_INetFwService( iface );

    FIXME("%p %d\n", This, enabled);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_service_get_GloballyOpenPorts(
    INetFwService *iface,
    INetFwOpenPorts **openPorts )
{
    fw_service *This = impl_from_INetFwService( iface );

    TRACE("%p %p\n", This, openPorts);
    return NetFwOpenPorts_create( NULL, (void **)openPorts );
}

static const struct INetFwServiceVtbl fw_service_vtbl =
{
    fw_service_QueryInterface,
    fw_service_AddRef,
    fw_service_Release,
    fw_service_GetTypeInfoCount,
    fw_service_GetTypeInfo,
    fw_service_GetIDsOfNames,
    fw_service_Invoke,
    fw_service_get_Name,
    fw_service_get_Type,
    fw_service_get_Customized,
    fw_service_get_IpVersion,
    fw_service_put_IpVersion,
    fw_service_get_Scope,
    fw_service_put_Scope,
    fw_service_get_RemoteAddresses,
    fw_service_put_RemoteAddresses,
    fw_service_get_Enabled,
    fw_service_put_Enabled,
    fw_service_get_GloballyOpenPorts
};

289
static HRESULT NetFwService_create( IUnknown *pUnkOuter, LPVOID *ppObj )
290 291 292 293 294 295 296 297
{
    fw_service *fp;

    TRACE("(%p,%p)\n", pUnkOuter, ppObj);

    fp = HeapAlloc( GetProcessHeap(), 0, sizeof(*fp) );
    if (!fp) return E_OUTOFMEMORY;

298
    fp->INetFwService_iface.lpVtbl = &fw_service_vtbl;
299 300
    fp->refs = 1;

301
    *ppObj = &fp->INetFwService_iface;
302 303 304 305 306 307 308

    TRACE("returning iface %p\n", *ppObj);
    return S_OK;
}

typedef struct fw_services
{
309
    INetFwServices INetFwServices_iface;
310 311 312 313 314
    LONG refs;
} fw_services;

static inline fw_services *impl_from_INetFwServices( INetFwServices *iface )
{
315
    return CONTAINING_RECORD(iface, fw_services, INetFwServices_iface);
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
}

static ULONG WINAPI fw_services_AddRef(
    INetFwServices *iface )
{
    fw_services *fw_services = impl_from_INetFwServices( iface );
    return InterlockedIncrement( &fw_services->refs );
}

static ULONG WINAPI fw_services_Release(
    INetFwServices *iface )
{
    fw_services *fw_services = impl_from_INetFwServices( iface );
    LONG refs = InterlockedDecrement( &fw_services->refs );
    if (!refs)
    {
        TRACE("destroying %p\n", fw_services);
        HeapFree( GetProcessHeap(), 0, fw_services );
    }
    return refs;
}

static HRESULT WINAPI fw_services_QueryInterface(
    INetFwServices *iface,
    REFIID riid,
    void **ppvObject )
{
    fw_services *This = impl_from_INetFwServices( iface );

    TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );

    if ( IsEqualGUID( riid, &IID_INetFwServices ) ||
         IsEqualGUID( riid, &IID_IDispatch ) ||
         IsEqualGUID( riid, &IID_IUnknown ) )
    {
        *ppvObject = iface;
    }
    else
    {
        FIXME("interface %s not implemented\n", debugstr_guid(riid));
        return E_NOINTERFACE;
    }
    INetFwServices_AddRef( iface );
    return S_OK;
}

static HRESULT WINAPI fw_services_GetTypeInfoCount(
    INetFwServices *iface,
    UINT *pctinfo )
{
    fw_services *This = impl_from_INetFwServices( iface );

    FIXME("%p %p\n", This, pctinfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_services_GetTypeInfo(
    INetFwServices *iface,
    UINT iTInfo,
    LCID lcid,
    ITypeInfo **ppTInfo )
{
    fw_services *This = impl_from_INetFwServices( iface );

    FIXME("%p %u %u %p\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_services_GetIDsOfNames(
    INetFwServices *iface,
    REFIID riid,
    LPOLESTR *rgszNames,
    UINT cNames,
    LCID lcid,
    DISPID *rgDispId )
{
    fw_services *This = impl_from_INetFwServices( iface );

    FIXME("%p %s %p %u %u %p\n", This, debugstr_guid(riid), rgszNames, cNames, lcid, rgDispId);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_services_Invoke(
    INetFwServices *iface,
    DISPID dispIdMember,
    REFIID riid,
    LCID lcid,
    WORD wFlags,
    DISPPARAMS *pDispParams,
    VARIANT *pVarResult,
    EXCEPINFO *pExcepInfo,
    UINT *puArgErr )
{
    fw_services *This = impl_from_INetFwServices( iface );

    FIXME("%p %d %s %d %d %p %p %p %p\n", This, dispIdMember, debugstr_guid(riid),
          lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
    return E_NOTIMPL;
}

static HRESULT WINAPI fw_services_get_Count(
    INetFwServices *iface,
    LONG *count )
{
    fw_services *This = impl_from_INetFwServices( iface );

    FIXME("%p, %p\n", This, count);

    *count = 0;
    return S_OK;
}

static HRESULT WINAPI fw_services_Item(
    INetFwServices *iface,
    NET_FW_SERVICE_TYPE svcType,
    INetFwService **service )
{
    fw_services *This = impl_from_INetFwServices( iface );

    FIXME("%p, %u, %p\n", This, svcType, service);
436
    return NetFwService_create( NULL, (void **)service );
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
}

static HRESULT WINAPI fw_services_get__NewEnum(
    INetFwServices *iface,
    IUnknown **newEnum )
{
    fw_services *This = impl_from_INetFwServices( iface );

    FIXME("%p, %p\n", This, newEnum);
    return E_NOTIMPL;
}

static const struct INetFwServicesVtbl fw_services_vtbl =
{
    fw_services_QueryInterface,
    fw_services_AddRef,
    fw_services_Release,
    fw_services_GetTypeInfoCount,
    fw_services_GetTypeInfo,
    fw_services_GetIDsOfNames,
    fw_services_Invoke,
    fw_services_get_Count,
    fw_services_Item,
    fw_services_get__NewEnum
};

HRESULT NetFwServices_create( IUnknown *pUnkOuter, LPVOID *ppObj )
{
    fw_services *fp;

    TRACE("(%p,%p)\n", pUnkOuter, ppObj);

    fp = HeapAlloc( GetProcessHeap(), 0, sizeof(*fp) );
    if (!fp) return E_OUTOFMEMORY;

472
    fp->INetFwServices_iface.lpVtbl = &fw_services_vtbl;
473 474
    fp->refs = 1;

475
    *ppObj = &fp->INetFwServices_iface;
476 477 478 479

    TRACE("returning iface %p\n", *ppObj);
    return S_OK;
}