Release 1.5.29.
[wine] / dlls / dpwsockx / dpwsockx_main.c
1 /* Internet TCP/IP and IPX Connection For DirectPlay
2  *
3  * Copyright 2008 Ismael Barros Barros
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winsock2.h"
27 #include "dpwsockx_dll.h"
28 #include "wine/debug.h"
29 #include "dplay.h"
30 #include "wine/dplaysp.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(dplay);
33
34
35 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
36 {
37     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
38
39     switch (fdwReason)
40     {
41     case DLL_WINE_PREATTACH:
42         return FALSE;    /* prefer native version */
43     case DLL_PROCESS_ATTACH:
44         /* TODO: Initialization */
45         DisableThreadLibraryCalls(hinstDLL);
46         break;
47     }
48
49     return TRUE;
50 }
51
52
53 static HRESULT WINAPI DPWSCB_EnumSessions( LPDPSP_ENUMSESSIONSDATA data )
54 {
55     FIXME( "(%p,%d,%p,%u) stub\n",
56            data->lpMessage, data->dwMessageSize,
57            data->lpISP, data->bReturnStatus );
58     return DPERR_UNSUPPORTED;
59 }
60
61 static HRESULT WINAPI DPWSCB_Reply( LPDPSP_REPLYDATA data )
62 {
63     FIXME( "(%p,%p,%d,%d,%p) stub\n",
64            data->lpSPMessageHeader, data->lpMessage, data->dwMessageSize,
65            data->idNameServer, data->lpISP );
66     return DPERR_UNSUPPORTED;
67 }
68
69 static HRESULT WINAPI DPWSCB_Send( LPDPSP_SENDDATA data )
70 {
71     FIXME( "(0x%08x,%d,%d,%p,%d,%u,%p) stub\n",
72            data->dwFlags, data->idPlayerTo, data->idPlayerFrom,
73            data->lpMessage, data->dwMessageSize,
74            data->bSystemMessage, data->lpISP );
75     return DPERR_UNSUPPORTED;
76 }
77
78 static HRESULT WINAPI DPWSCB_CreatePlayer( LPDPSP_CREATEPLAYERDATA data )
79 {
80     FIXME( "(%d,0x%08x,%p,%p) stub\n",
81            data->idPlayer, data->dwFlags,
82            data->lpSPMessageHeader, data->lpISP );
83     return DPERR_UNSUPPORTED;
84 }
85
86 static HRESULT WINAPI DPWSCB_DeletePlayer( LPDPSP_DELETEPLAYERDATA data )
87 {
88     FIXME( "(%d,0x%08x,%p) stub\n",
89            data->idPlayer, data->dwFlags, data->lpISP );
90     return DPERR_UNSUPPORTED;
91 }
92
93 static HRESULT WINAPI DPWSCB_GetAddress( LPDPSP_GETADDRESSDATA data )
94 {
95     FIXME( "(%d,0x%08x,%p,%p,%p) stub\n",
96            data->idPlayer, data->dwFlags, data->lpAddress,
97            data->lpdwAddressSize, data->lpISP );
98     return DPERR_UNSUPPORTED;
99 }
100
101 static HRESULT WINAPI DPWSCB_GetCaps( LPDPSP_GETCAPSDATA data )
102 {
103     FIXME( "(%d,%p,0x%08x,%p)\n",
104            data->idPlayer, data->lpCaps, data->dwFlags, data->lpISP );
105     return DPERR_UNSUPPORTED;
106 }
107
108 static HRESULT WINAPI DPWSCB_Open( LPDPSP_OPENDATA data )
109 {
110     FIXME( "(%u,%p,%p,%u,0x%08x,0x%08x) stub\n",
111            data->bCreate, data->lpSPMessageHeader, data->lpISP,
112            data->bReturnStatus, data->dwOpenFlags, data->dwSessionFlags );
113     return DPERR_UNSUPPORTED;
114 }
115
116 static HRESULT WINAPI DPWSCB_CloseEx( LPDPSP_CLOSEDATA data )
117 {
118     FIXME( "(%p) stub\n", data->lpISP );
119     return DPERR_UNSUPPORTED;
120 }
121
122 static HRESULT WINAPI DPWSCB_ShutdownEx( LPDPSP_SHUTDOWNDATA data )
123 {
124     FIXME( "(%p) stub\n", data->lpISP );
125     return DPERR_UNSUPPORTED;
126 }
127
128 static HRESULT WINAPI DPWSCB_GetAddressChoices( LPDPSP_GETADDRESSCHOICESDATA data )
129 {
130     FIXME( "(%p,%p,%p) stub\n",
131            data->lpAddress, data->lpdwAddressSize, data->lpISP );
132     return DPERR_UNSUPPORTED;
133 }
134
135 static HRESULT WINAPI DPWSCB_SendEx( LPDPSP_SENDEXDATA data )
136 {
137     FIXME( "(%p,0x%08x,%d,%d,%p,%d,%d,%d,%d,%p,%p,%u) stub\n",
138            data->lpISP, data->dwFlags, data->idPlayerTo, data->idPlayerFrom,
139            data->lpSendBuffers, data->cBuffers, data->dwMessageSize,
140            data->dwPriority, data->dwTimeout, data->lpDPContext,
141            data->lpdwSPMsgID, data->bSystemMessage );
142     return DPERR_UNSUPPORTED;
143 }
144
145 static HRESULT WINAPI DPWSCB_SendToGroupEx( LPDPSP_SENDTOGROUPEXDATA data )
146 {
147     FIXME( "(%p,0x%08x,%d,%d,%p,%d,%d,%d,%d,%p,%p) stub\n",
148            data->lpISP, data->dwFlags, data->idGroupTo, data->idPlayerFrom,
149            data->lpSendBuffers, data->cBuffers, data->dwMessageSize,
150            data->dwPriority, data->dwTimeout, data->lpDPContext,
151            data->lpdwSPMsgID );
152     return DPERR_UNSUPPORTED;
153 }
154
155 static HRESULT WINAPI DPWSCB_Cancel( LPDPSP_CANCELDATA data )
156 {
157     FIXME( "(%p,0x%08x,%p,%d,0x%08x,0x%08x) stub\n",
158            data->lpISP, data->dwFlags, data->lprglpvSPMsgID, data->cSPMsgID,
159            data->dwMinPriority, data->dwMaxPriority );
160     return DPERR_UNSUPPORTED;
161 }
162
163 static HRESULT WINAPI DPWSCB_GetMessageQueue( LPDPSP_GETMESSAGEQUEUEDATA data )
164 {
165     FIXME( "(%p,0x%08x,%d,%d,%p,%p) stub\n",
166            data->lpISP, data->dwFlags, data->idFrom, data->idTo,
167            data->lpdwNumMsgs, data->lpdwNumBytes );
168     return DPERR_UNSUPPORTED;
169 }
170
171 static void setup_callbacks( LPDPSP_SPCALLBACKS lpCB )
172 {
173     lpCB->EnumSessions           = DPWSCB_EnumSessions;
174     lpCB->Reply                  = DPWSCB_Reply;
175     lpCB->Send                   = DPWSCB_Send;
176     lpCB->CreatePlayer           = DPWSCB_CreatePlayer;
177     lpCB->DeletePlayer           = DPWSCB_DeletePlayer;
178     lpCB->GetAddress             = DPWSCB_GetAddress;
179     lpCB->GetCaps                = DPWSCB_GetCaps;
180     lpCB->Open                   = DPWSCB_Open;
181     lpCB->CloseEx                = DPWSCB_CloseEx;
182     lpCB->ShutdownEx             = DPWSCB_ShutdownEx;
183     lpCB->GetAddressChoices      = DPWSCB_GetAddressChoices;
184     lpCB->SendEx                 = DPWSCB_SendEx;
185     lpCB->SendToGroupEx          = DPWSCB_SendToGroupEx;
186     lpCB->Cancel                 = DPWSCB_Cancel;
187     lpCB->GetMessageQueue        = DPWSCB_GetMessageQueue;
188
189     lpCB->AddPlayerToGroup       = NULL;
190     lpCB->Close                  = NULL;
191     lpCB->CreateGroup            = NULL;
192     lpCB->DeleteGroup            = NULL;
193     lpCB->RemovePlayerFromGroup  = NULL;
194     lpCB->SendToGroup            = NULL;
195     lpCB->Shutdown               = NULL;
196 }
197
198
199
200 /******************************************************************
201  *              SPInit (DPWSOCKX.1)
202  */
203 HRESULT WINAPI SPInit( LPSPINITDATA lpspData )
204 {
205     WSADATA wsaData;
206     DPWS_DATA dpwsData;
207
208     TRACE( "Initializing library for %s (%s)\n",
209            wine_dbgstr_guid(lpspData->lpGuid), debugstr_w(lpspData->lpszName) );
210
211     /* We only support TCP/IP service */
212     if ( !IsEqualGUID(lpspData->lpGuid, &DPSPGUID_TCPIP) )
213     {
214         return DPERR_UNAVAILABLE;
215     }
216
217     /* Assign callback functions */
218     setup_callbacks( lpspData->lpCB );
219
220     /* Load Winsock 2.0 DLL */
221     if ( WSAStartup( MAKEWORD(2, 0), &wsaData ) != 0 )
222     {
223         ERR( "WSAStartup() failed\n" );
224         return DPERR_UNAVAILABLE;
225     }
226
227     /* Initialize internal data */
228     memset( &dpwsData, 0, sizeof(DPWS_DATA) );
229     dpwsData.lpISP = lpspData->lpISP;
230     IDirectPlaySP_SetSPData( lpspData->lpISP, &dpwsData, sizeof(DPWS_DATA),
231                              DPSET_LOCAL );
232
233     /* dplay needs to know the size of the header */
234     lpspData->dwSPHeaderSize = sizeof(DPSP_MSG_HEADER);
235
236     return DP_OK;
237 }