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