Synchronize with trunk r58528.
[reactos.git] / dll / win32 / inetcomm / inetcomm_main.c
1 /*
2 * Internet Messaging APIs
3 *
4 * Copyright 2006 Robert Shearman for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #define COBJMACROS
26
27 #include <stdarg.h>
28
29 #include <windef.h>
30 #include <winbase.h>
31 //#include "winnt.h"
32 //#include "winuser.h"
33 #include <ole2.h>
34 //#include "ocidl.h"
35 #include <rpcproxy.h>
36 #include <initguid.h>
37 #include <mimeole.h>
38
39 #include "inetcomm_private.h"
40
41 #include <wine/debug.h>
42
43 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm);
44
45 static HINSTANCE instance;
46
47 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
48 {
49 static IMimeInternational *international;
50
51 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
52
53 switch (fdwReason)
54 {
55 case DLL_WINE_PREATTACH:
56 return FALSE;
57 case DLL_PROCESS_ATTACH:
58 DisableThreadLibraryCalls(hinstDLL);
59 instance = hinstDLL;
60 if (!InternetTransport_RegisterClass(hinstDLL))
61 return FALSE;
62 MimeInternational_Construct(&international);
63 break;
64 case DLL_PROCESS_DETACH:
65 IMimeInternational_Release(international);
66 InternetTransport_UnregisterClass(hinstDLL);
67 break;
68 default:
69 break;
70 }
71 return TRUE;
72 }
73
74 /******************************************************************************
75 * ClassFactory
76 */
77 typedef struct
78 {
79 IClassFactory IClassFactory_iface;
80 HRESULT (*create_object)(IUnknown *, void **);
81 } cf;
82
83 static inline cf *impl_from_IClassFactory( IClassFactory *iface )
84 {
85 return CONTAINING_RECORD(iface, cf, IClassFactory_iface);
86 }
87
88 static HRESULT WINAPI cf_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *ppobj )
89 {
90 if (IsEqualGUID(riid, &IID_IUnknown) ||
91 IsEqualGUID(riid, &IID_IClassFactory))
92 {
93 IClassFactory_AddRef( iface );
94 *ppobj = iface;
95 return S_OK;
96 }
97
98 FIXME("interface %s not implemented\n", debugstr_guid(riid));
99 return E_NOINTERFACE;
100 }
101
102 static ULONG WINAPI cf_AddRef( IClassFactory *iface )
103 {
104 return 2;
105 }
106
107 static ULONG WINAPI cf_Release( IClassFactory *iface )
108 {
109 return 1;
110 }
111
112 static HRESULT WINAPI cf_CreateInstance( IClassFactory *iface, LPUNKNOWN pOuter,
113 REFIID riid, LPVOID *ppobj )
114 {
115 cf *This = impl_from_IClassFactory( iface );
116 HRESULT r;
117 IUnknown *punk;
118
119 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
120
121 *ppobj = NULL;
122
123 r = This->create_object( pOuter, (LPVOID*) &punk );
124 if (FAILED(r))
125 return r;
126
127 r = IUnknown_QueryInterface( punk, riid, ppobj );
128 IUnknown_Release( punk );
129
130 return r;
131 }
132
133 static HRESULT WINAPI cf_LockServer( IClassFactory *iface, BOOL dolock)
134 {
135 FIXME("(%p)->(%d),stub!\n",iface,dolock);
136 return S_OK;
137 }
138
139 static const struct IClassFactoryVtbl cf_vtbl =
140 {
141 cf_QueryInterface,
142 cf_AddRef,
143 cf_Release,
144 cf_CreateInstance,
145 cf_LockServer
146 };
147
148 static cf mime_body_cf = { { &cf_vtbl }, MimeBody_create };
149 static cf mime_allocator_cf = { { &cf_vtbl }, MimeAllocator_create };
150 static cf mime_message_cf = { { &cf_vtbl }, MimeMessage_create };
151 static cf mime_security_cf = { { &cf_vtbl }, MimeSecurity_create };
152 static cf virtual_stream_cf = { { &cf_vtbl }, VirtualStream_create };
153
154 /***********************************************************************
155 * DllGetClassObject (INETCOMM.@)
156 */
157 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
158 {
159 IClassFactory *cf = NULL;
160
161 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv );
162
163 if (IsEqualCLSID(rclsid, &CLSID_ISMTPTransport))
164 return SMTPTransportCF_Create(iid, ppv);
165
166 if (IsEqualCLSID(rclsid, &CLSID_ISMTPTransport2))
167 return SMTPTransportCF_Create(iid, ppv);
168
169 if (IsEqualCLSID(rclsid, &CLSID_IIMAPTransport))
170 return IMAPTransportCF_Create(iid, ppv);
171
172 if (IsEqualCLSID(rclsid, &CLSID_IPOP3Transport))
173 return POP3TransportCF_Create(iid, ppv);
174
175 if ( IsEqualCLSID( rclsid, &CLSID_IMimeSecurity ))
176 {
177 cf = &mime_security_cf.IClassFactory_iface;
178 }
179 else if( IsEqualCLSID( rclsid, &CLSID_IMimeMessage ))
180 {
181 cf = &mime_message_cf.IClassFactory_iface;
182 }
183 else if( IsEqualCLSID( rclsid, &CLSID_IMimeBody ))
184 {
185 cf = &mime_body_cf.IClassFactory_iface;
186 }
187 else if( IsEqualCLSID( rclsid, &CLSID_IMimeAllocator ))
188 {
189 cf = &mime_allocator_cf.IClassFactory_iface;
190 }
191 else if( IsEqualCLSID( rclsid, &CLSID_IVirtualStream ))
192 {
193 cf = &virtual_stream_cf.IClassFactory_iface;
194 }
195
196 if ( !cf )
197 {
198 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
199 return CLASS_E_CLASSNOTAVAILABLE;
200 }
201
202 return IClassFactory_QueryInterface( cf, iid, ppv );
203 }
204
205 /***********************************************************************
206 * DllCanUnloadNow (INETCOMM.@)
207 */
208 HRESULT WINAPI DllCanUnloadNow(void)
209 {
210 return S_FALSE;
211 }
212
213 /***********************************************************************
214 * DllRegisterServer (INETCOMM.@)
215 */
216 HRESULT WINAPI DllRegisterServer(void)
217 {
218 return __wine_register_resources( instance );
219 }
220
221 /***********************************************************************
222 * DllUnregisterServer (INETCOMM.@)
223 */
224 HRESULT WINAPI DllUnregisterServer(void)
225 {
226 return __wine_unregister_resources( instance );
227 }