ReactOS  0.4.13-dev-982-g9853eab
name_server.h File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "dplay.h"
#include "wine/dplaysp.h"
#include "dplayx_messages.h"
#include "dplay_global.h"
Include dependency graph for name_server.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void NS_SetLocalComputerAsNameServer (LPCDPSESSIONDESC2 lpsd, LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_AddRemoteComputerAsNameServer (LPCVOID lpNSAddrHdr, DWORD dwHdrSize, LPCDPMSG_ENUMSESSIONSREPLY lpcMsg, LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
LPVOID NS_GetNSAddr (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
DWORD NS_GetNsMagic (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_SetLocalAddr (LPVOID lpNSInfo, LPCVOID lpHdr, DWORD dwHdrSize) DECLSPEC_HIDDEN
 
void NS_ReplyToEnumSessionsRequest (LPCVOID lpcMsg, LPVOID *lplpReplyData, LPDWORD lpdwReplySize, IDirectPlayImpl *lpDP) DECLSPEC_HIDDEN
 
HRESULT NS_SendSessionRequestBroadcast (LPCGUID lpcGuid, DWORD dwFlags, const SPINITDATA *lpSpData) DECLSPEC_HIDDEN
 
BOOL NS_InitializeSessionCache (LPVOID *lplpNSInfo) DECLSPEC_HIDDEN
 
void NS_DeleteSessionCache (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_InvalidateSessionCache (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_ResetSessionEnumeration (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
LPDPSESSIONDESC2 NS_WalkSessions (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 
void NS_PruneSessionCache (LPVOID lpNSInfo) DECLSPEC_HIDDEN
 

Function Documentation

◆ NS_AddRemoteComputerAsNameServer()

void NS_AddRemoteComputerAsNameServer ( LPCVOID  lpNSAddrHdr,
DWORD  dwHdrSize,
LPCDPMSG_ENUMSESSIONSREPLY  lpcMsg,
LPVOID  lpNSInfo 
)

Definition at line 88 of file name_server.c.

92 {
93  DWORD len;
94  lpNSCache lpCache = (lpNSCache)lpNSInfo;
95  lpNSCacheData lpCacheNode;
96 
97  TRACE( "%p, %p, %p\n", lpcNSAddrHdr, lpcMsg, lpNSInfo );
98 
99  /* See if we can find this session. If we can, remove it as it's a dup */
100  DPQ_REMOVE_ENTRY_CB( lpCache->first, next, data->guidInstance, cbUglyPig,
101  lpcMsg->sd.guidInstance, lpCacheNode );
102 
103  if( lpCacheNode != NULL )
104  {
105  TRACE( "Duplicate session entry for %s removed - updated version kept\n",
106  debugstr_guid( &lpCacheNode->data->guidInstance ) );
107  cbDeleteNSNodeFromHeap( lpCacheNode );
108  }
109 
110  /* Add this to the list */
111  lpCacheNode = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpCacheNode ) );
112 
113  if( lpCacheNode == NULL )
114  {
115  ERR( "no memory for NS node\n" );
116  return;
117  }
118 
119  lpCacheNode->lpNSAddrHdr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
120  dwHdrSize );
121  CopyMemory( lpCacheNode->lpNSAddrHdr, lpcNSAddrHdr, dwHdrSize );
122 
123  lpCacheNode->data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(lpCacheNode->data) ) );
124 
125  if( lpCacheNode->data == NULL )
126  {
127  ERR( "no memory for SESSIONDESC2\n" );
128  HeapFree( GetProcessHeap(), 0, lpCacheNode );
129  return;
130  }
131 
132  *lpCacheNode->data = lpcMsg->sd;
133  len = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1, NULL, 0, NULL, NULL );
134  if ((lpCacheNode->data->u1.lpszSessionNameA = HeapAlloc( GetProcessHeap(), 0, len )))
135  {
136  WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1,
137  lpCacheNode->data->u1.lpszSessionNameA, len, NULL, NULL );
138  }
139 
140  lpCacheNode->dwTime = timeGetTime();
141 
142  DPQ_INSERT(lpCache->first, lpCacheNode, next );
143 
144  lpCache->present = lpCacheNode;
145 
146  /* Use this message as an opportunity to weed out any old sessions so
147  * that we don't enum them again
148  */
149  NS_PruneSessionCache( lpNSInfo );
150 }
#define WideCharToMultiByte
Definition: compat.h:101
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define CP_ACP
Definition: compat.h:99
struct NSCache * lpNSCache
Definition: name_server.c:67
GUID guidInstance
Definition: dplay.h:234
smooth NULL
Definition: ftsmooth.c:416
#define debugstr_guid
Definition: kernel32.h:35
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CopyMemory
Definition: winbase.h:1633
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
void NS_PruneSessionCache(LPVOID lpNSInfo)
Definition: name_server.c:320
GLenum GLsizei len
Definition: glext.h:6722
lpNSCacheData present
Definition: name_server.c:59
#define ERR(fmt,...)
Definition: debug.h:109
static unsigned __int64 next
Definition: rand_nt.c:6
DWORD WINAPI timeGetTime(void)
Definition: time.c:454
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPQ_REMOVE_ENTRY_CB(head, elm, field, compare_cb, fieldToCompare, rc)
Definition: dplayx_queue.h:181
#define HeapFree(x, y, z)
Definition: compat.h:394
#define DPQ_INSERT(a, b, c)
Definition: dplayx_queue.h:34

Referenced by DP_HandleMessage().

◆ NS_DeleteSessionCache()

void NS_DeleteSessionCache ( LPVOID  lpNSInfo)

Definition at line 284 of file name_server.c.

285 {
287 }
void NS_InvalidateSessionCache(LPVOID lpNSInfo)
Definition: name_server.c:244

Referenced by DP_DestroyDirectPlay2().

◆ NS_GetNSAddr()

LPVOID NS_GetNSAddr ( LPVOID  lpNSInfo)

Definition at line 152 of file name_server.c.

153 {
154  lpNSCache lpCache = (lpNSCache)lpNSInfo;
155 
156  FIXME( ":quick stub\n" );
157 
158  /* Ok. Cheat and don't search for the correct stuff just take the first.
159  * FIXME: In the future how are we to know what is _THE_ enum we used?
160  * This is going to have to go into dplay somehow. Perhaps it
161  * comes back with app server id for the join command! Oh... that
162  * must be it. That would make this method obsolete once that's
163  * in place.
164  */
165 #if 1
166  if ( lpCache->first.lpQHFirst )
167  return lpCache->first.lpQHFirst->lpNSAddrHdr;
168 
169  return NULL;
170 #else
171  /* FIXME: Should convert over to this */
172  return lpCache->bNsIsLocal ? lpCache->lpLocalAddrHdr
173  : lpCache->lpRemoteAddrHdr;
174 #endif
175 }
struct NSCache * lpNSCache
Definition: name_server.c:67
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416

Referenced by DP_SecureOpen(), and NS_GetNsMagic().

◆ NS_GetNsMagic()

DWORD NS_GetNsMagic ( LPVOID  lpNSInfo)

Definition at line 178 of file name_server.c.

179 {
180  LPDWORD lpHdrInfo = NS_GetNSAddr( lpNSInfo );
181 
182  return lpHdrInfo[1];
183 }
LPVOID NS_GetNSAddr(LPVOID lpNSInfo)
Definition: name_server.c:152
uint32_t * LPDWORD
Definition: typedefs.h:57

Referenced by DP_MSG_ForwardPlayerCreation().

◆ NS_InitializeSessionCache()

BOOL NS_InitializeSessionCache ( LPVOID lplpNSInfo)

Definition at line 264 of file name_server.c.

265 {
266  lpNSCache lpCache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpCache ) );
267 
268  *lplpNSInfo = lpCache;
269 
270  if( lpCache == NULL )
271  {
272  return FALSE;
273  }
274 
275  DPQ_INIT(lpCache->first);
276  lpCache->present = NULL;
277 
278  lpCache->bNsIsLocal = FALSE;
279 
280  return TRUE;
281 }
#define TRUE
Definition: types.h:120
#define DPQ_INIT(head)
Definition: dplayx_queue.h:54
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
lpNSCacheData present
Definition: name_server.c:59
#define HEAP_ZERO_MEMORY
Definition: compat.h:123

Referenced by DP_CreateDirectPlay2().

◆ NS_InvalidateSessionCache()

void NS_InvalidateSessionCache ( LPVOID  lpNSInfo)

Definition at line 244 of file name_server.c.

245 {
246  lpNSCache lpCache = (lpNSCache)lpNSInfo;
247 
248  if( lpCache == NULL )
249  {
250  ERR( ": invalidate nonexistent cache\n" );
251  return;
252  }
253 
254  DPQ_DELETEQ( lpCache->first, next, lpNSCacheData, cbDeleteNSNodeFromHeap );
255 
256  /* NULL out the walking pointer */
257  lpCache->present = NULL;
258 
259  lpCache->bNsIsLocal = FALSE;
260 
261 }
#define DPQ_DELETEQ(head, field, type, df)
Definition: dplayx_queue.h:199
struct NSCache * lpNSCache
Definition: name_server.c:67
smooth NULL
Definition: ftsmooth.c:416
lpNSCacheData present
Definition: name_server.c:59
#define ERR(fmt,...)
Definition: debug.h:109
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by IDirectPlay4Impl_EnumSessions(), and NS_DeleteSessionCache().

◆ NS_PruneSessionCache()

void NS_PruneSessionCache ( LPVOID  lpNSInfo)

Definition at line 320 of file name_server.c.

321 {
322  lpNSCache lpCache = lpNSInfo;
323 
324  const DWORD dwPresentTime = timeGetTime();
325  const DWORD dwPrunePeriod = DPMSG_WAIT_60_SECS; /* is 60 secs enough? */
326 
327  /* This silly little algorithm is based on the fact we keep entries in
328  * the queue in a time based order. It also assumes that it is not possible
329  * to wrap around over yourself (which is not unreasonable).
330  * The if statements verify if the first entry in the queue is less
331  * than dwPrunePeriod old depending on the "clock" roll over.
332  */
333  for( ;; )
334  {
335  lpNSCacheData lpFirstData;
336 
337  if( DPQ_IS_EMPTY(lpCache->first) )
338  {
339  /* Nothing to prune */
340  break;
341  }
342 
343  /* Deal with time in a wrap around safe manner - unsigned arithmetic.
344  * Check the difference in time */
345  if( (dwPresentTime - (DPQ_FIRST(lpCache->first)->dwTime)) < dwPrunePeriod )
346  {
347  /* First entry has not expired yet; don't prune */
348  break;
349  }
350 
351  lpFirstData = DPQ_FIRST(lpCache->first);
352  DPQ_REMOVE( lpCache->first, DPQ_FIRST(lpCache->first), next );
353  cbDeleteNSNodeFromHeap( lpFirstData );
354  }
355 
356 }
#define DPQ_IS_EMPTY(head)
Definition: dplayx_queue.h:64
#define DPMSG_WAIT_60_SECS
unsigned long DWORD
Definition: ntddk_ex.h:95
static unsigned __int64 next
Definition: rand_nt.c:6
DWORD WINAPI timeGetTime(void)
Definition: time.c:454
#define DPQ_REMOVE(head, elm, field)
Definition: dplayx_queue.h:82
#define DPQ_FIRST(head)
Definition: dplayx_queue.h:61

Referenced by DP_InvokeEnumSessionCallbacks(), and NS_AddRemoteComputerAsNameServer().

◆ NS_ReplyToEnumSessionsRequest()

void NS_ReplyToEnumSessionsRequest ( LPCVOID  lpcMsg,
LPVOID lplpReplyData,
LPDWORD  lpdwReplySize,
IDirectPlayImpl lpDP 
)

◆ NS_ResetSessionEnumeration()

void NS_ResetSessionEnumeration ( LPVOID  lpNSInfo)

Definition at line 290 of file name_server.c.

291 {
292  ((lpNSCache)lpNSInfo)->present = ((lpNSCache)lpNSInfo)->first.lpQHFirst;
293 }
struct NSCache * lpNSCache
Definition: name_server.c:67

Referenced by DP_InvokeEnumSessionCallbacks().

◆ NS_SendSessionRequestBroadcast()

HRESULT NS_SendSessionRequestBroadcast ( LPCGUID  lpcGuid,
DWORD  dwFlags,
const SPINITDATA lpSpData 
)

Definition at line 197 of file name_server.c.

201 {
204 
205  TRACE( "enumerating for guid %s\n", debugstr_guid( lpcGuid ) );
206 
207  /* Get the SP to deal with sending the EnumSessions request */
208  FIXME( ": not all data fields are correct\n" );
209 
210  data.dwMessageSize = lpSpData->dwSPHeaderSize + sizeof( *lpMsg ); /*FIXME!*/
212  data.dwMessageSize );
213  data.lpISP = lpSpData->lpISP;
214  data.bReturnStatus = (dwFlags & DPENUMSESSIONS_RETURNSTATUS) != 0;
215 
216 
217  lpMsg = (LPDPMSG_ENUMSESSIONSREQUEST)(((BYTE*)data.lpMessage)+lpSpData->dwSPHeaderSize);
218 
219  /* Setup EnumSession request message */
222  lpMsg->envelope.wVersion = DPMSGVER_DP6;
223 
224  lpMsg->dwPasswordSize = 0; /* FIXME: If enumerating passwords..? */
225  lpMsg->dwFlags = dwFlags;
226 
227  lpMsg->guidApplication = *lpcGuid;
228 
229  return (lpSpData->lpCB->EnumSessions)( &data );
230 }
#define DPENUMSESSIONS_RETURNSTATUS
Definition: dplay.h:1021
struct tagDPMSG_ENUMSESSIONSREQUEST * LPDPMSG_ENUMSESSIONSREQUEST
#define DPMSGCMD_ENUMSESSIONSREQUEST
#define FIXME(fmt,...)
Definition: debug.h:110
IDirectPlaySP * lpISP
Definition: dplaysp.h:355
#define debugstr_guid
Definition: kernel32.h:35
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define DPMSGVER_DP6
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define DPMSGMAGIC_DPLAYMSG
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
unsigned char BYTE
Definition: mem.h:68
LPDPSP_ENUMSESSIONS EnumSessions
Definition: dplaysp.h:326
LPDPSP_SPCALLBACKS lpCB
Definition: dplaysp.h:354
DWORD dwSPHeaderSize
Definition: dplaysp.h:360
#define HEAP_ZERO_MEMORY
Definition: compat.h:123

Referenced by DP_EnumSessionsSendAsyncRequestThread(), and IDirectPlay4Impl_EnumSessions().

◆ NS_SetLocalAddr()

void NS_SetLocalAddr ( LPVOID  lpNSInfo,
LPCVOID  lpHdr,
DWORD  dwHdrSize 
)

Definition at line 185 of file name_server.c.

186 {
187  lpNSCache lpCache = (lpNSCache)lpNSInfo;
188 
189  lpCache->lpLocalAddrHdr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwHdrSize );
190 
191  CopyMemory( lpCache->lpLocalAddrHdr, lpHdr, dwHdrSize );
192 }
struct NSCache * lpNSCache
Definition: name_server.c:67
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define CopyMemory
Definition: winbase.h:1633
#define HEAP_ZERO_MEMORY
Definition: compat.h:123

Referenced by DP_HandleMessage().

◆ NS_SetLocalComputerAsNameServer()

void NS_SetLocalComputerAsNameServer ( LPCDPSESSIONDESC2  lpsd,
LPVOID  lpNSInfo 
)

Definition at line 75 of file name_server.c.

76 {
77  lpNSCache lpCache = (lpNSCache)lpNSInfo;
78 
79  lpCache->bNsIsLocal = TRUE;
80 }
#define TRUE
Definition: types.h:120
struct NSCache * lpNSCache
Definition: name_server.c:67

Referenced by DP_SecureOpen().

◆ NS_WalkSessions()

LPDPSESSIONDESC2 NS_WalkSessions ( LPVOID  lpNSInfo)

Definition at line 295 of file name_server.c.

296 {
297  LPDPSESSIONDESC2 lpSessionDesc;
298  lpNSCache lpCache = (lpNSCache)lpNSInfo;
299 
300  /* FIXME: The pointers could disappear when walking if a prune happens */
301 
302  /* Test for end of the list */
303  if( lpCache->present == NULL )
304  {
305  return NULL;
306  }
307 
308  lpSessionDesc = lpCache->present->data;
309 
310  /* Advance tracking pointer */
311  lpCache->present = lpCache->present->next.lpQNext;
312 
313  return lpSessionDesc;
314 }
struct NSCache * lpNSCache
Definition: name_server.c:67
smooth NULL
Definition: ftsmooth.c:416
lpNSCacheData present
Definition: name_server.c:59

Referenced by DP_InvokeEnumSessionCallbacks().