mshtml: Added IHTMLStyleSheet::get_rules implementation.
[wine] / dlls / hlink / extserv.c
1 /*
2  * Copyright 2007 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "hlink_private.h"
20
21 #include "wine/debug.h"
22 #include "wine/unicode.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(hlink);
25
26 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
27
28 typedef struct {
29     const IUnknownVtbl        *lpIUnknownVtbl;
30     const IAuthenticateVtbl   *lpIAuthenticateVtbl;
31
32     LONG ref;
33     IUnknown *outer;
34
35     HWND hwnd;
36     LPWSTR username;
37     LPWSTR password;
38 } ExtensionService;
39
40 #define EXTSERVUNK(x)    ((IUnknown*)       &(x)->lpIUnknownVtbl)
41 #define AUTHENTICATE(x)  ((IAuthenticate*)  &(x)->lpIAuthenticateVtbl)
42
43 #define EXTSERVUNK_THIS(iface)  DEFINE_THIS(ExtensionService, IUnknown, iface)
44
45 static HRESULT WINAPI ExtServUnk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
46 {
47     ExtensionService *This = EXTSERVUNK_THIS(iface);
48
49     *ppv = NULL;
50
51     if(IsEqualGUID(&IID_IUnknown, riid)) {
52         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
53         *ppv = EXTSERVUNK(This);
54     }else if(IsEqualGUID(&IID_IAuthenticate, riid)) {
55         TRACE("(%p)->(IID_IAuthenticate %p)\n", This, ppv);
56         *ppv = AUTHENTICATE(This);
57     }
58
59     if(*ppv) {
60         IUnknown_AddRef(EXTSERVUNK(This));
61         return S_OK;
62     }
63
64     FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
65     return E_NOINTERFACE;
66 }
67
68 static ULONG WINAPI ExtServUnk_AddRef(IUnknown *iface)
69 {
70     ExtensionService *This = EXTSERVUNK_THIS(iface);
71     LONG ref = InterlockedIncrement(&This->ref);
72
73     TRACE("(%p) ref=%d\n", This, ref);
74
75     return ref;
76 }
77
78 static ULONG WINAPI ExtServUnk_Release(IUnknown *iface)
79 {
80     ExtensionService *This = EXTSERVUNK_THIS(iface);
81     LONG ref = InterlockedDecrement(&This->ref);
82
83     TRACE("(%p) ref=%d\n", This, ref);
84
85     if(!ref) {
86         hlink_free(This->username);
87         hlink_free(This->password);
88         hlink_free(This);
89     }
90
91     return ref;
92 }
93
94 #undef EXTSERVUNK_THIS
95
96 static const IUnknownVtbl ExtServUnkVtbl = {
97     ExtServUnk_QueryInterface,
98     ExtServUnk_AddRef,
99     ExtServUnk_Release
100 };
101
102 #define AUTHENTICATE_THIS(iface) DEFINE_THIS(ExtensionService, IAuthenticate, iface)
103
104 static HRESULT WINAPI Authenticate_QueryInterface(IAuthenticate *iface, REFIID riid, void **ppv)
105 {
106     ExtensionService *This = AUTHENTICATE_THIS(iface);
107     return IUnknown_QueryInterface(This->outer, riid, ppv);
108 }
109
110 static ULONG WINAPI Authenticate_AddRef(IAuthenticate *iface)
111 {
112     ExtensionService *This = AUTHENTICATE_THIS(iface);
113     return IUnknown_AddRef(This->outer);
114 }
115
116 static ULONG WINAPI Authenticate_Release(IAuthenticate *iface)
117 {
118     ExtensionService *This = AUTHENTICATE_THIS(iface);
119     return IUnknown_Release(This->outer);
120 }
121
122 static HRESULT WINAPI Authenticate_Authenticate(IAuthenticate *iface,
123         HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword)
124 {
125     ExtensionService *This = AUTHENTICATE_THIS(iface);
126
127     TRACE("(%p)->(%p %p %p)\n", This, phwnd, pszUsername, pszPassword);
128
129     if(!phwnd || !pszUsername || !pszPassword)
130         return E_INVALIDARG;
131
132     *phwnd = This->hwnd;
133     *pszUsername = hlink_co_strdupW(This->username);
134     *pszPassword = hlink_co_strdupW(This->password);
135
136     return S_OK;
137 }
138
139 #undef AUTHENTICATE_THIS
140
141 static const IAuthenticateVtbl AuthenticateVtbl = {
142     Authenticate_QueryInterface,
143     Authenticate_AddRef,
144     Authenticate_Release,
145     Authenticate_Authenticate
146 };
147
148 HRESULT WINAPI HlinkCreateExtensionServices(LPCWSTR pwzAdditionalHeaders,
149         HWND phwnd, LPCWSTR pszUsername, LPCWSTR pszPassword,
150         IUnknown *punkOuter, REFIID riid, void** ppv)
151 {
152     ExtensionService *ret;
153     HRESULT hres = S_OK;
154
155     TRACE("%s %p %s %s %p %s %p\n",debugstr_w(pwzAdditionalHeaders),
156             phwnd, debugstr_w(pszUsername), debugstr_w(pszPassword),
157             punkOuter, debugstr_guid(riid), ppv);
158
159     if(pwzAdditionalHeaders)
160         FIXME("Unsupported pwzAdditionalHeaders\n");
161
162     ret = hlink_alloc(sizeof(*ret));
163
164     ret->lpIUnknownVtbl = &ExtServUnkVtbl;
165     ret->lpIAuthenticateVtbl = &AuthenticateVtbl;
166     ret->ref = 1;
167     ret->hwnd = phwnd;
168     ret->username = hlink_strdupW(pszUsername);
169     ret->password = hlink_strdupW(pszPassword);
170
171
172     if(!punkOuter) {
173         ret->outer = EXTSERVUNK(ret);
174         hres = IUnknown_QueryInterface(EXTSERVUNK(ret), riid, ppv);
175         IUnknown_Release(EXTSERVUNK(ret));
176     }else if(IsEqualGUID(&IID_IUnknown, riid)) {
177         ret->outer = punkOuter;
178         *ppv = EXTSERVUNK(ret);
179     }else {
180         IUnknown_Release(EXTSERVUNK(ret));
181         hres = E_INVALIDARG;
182     }
183
184     return hres;
185 }