2000-03-12 21:18:33 +01:00
|
|
|
/* DPLAYX.DLL name server implementation
|
|
|
|
*
|
2001-04-12 23:10:54 +02:00
|
|
|
* Copyright 2000-2001 - Peter Hunnisett
|
2000-03-12 21:18:33 +01:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-03-12 21:18:33 +01:00
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-03-12 21:18:33 +01:00
|
|
|
/* NOTE: Methods with the NS_ prefix are name server methods */
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2003-01-07 21:36:20 +01:00
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-05-27 00:26:30 +02:00
|
|
|
#include "winbase.h"
|
2000-11-16 01:28:52 +01:00
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/unicode.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-09-27 01:11:48 +02:00
|
|
|
#include "mmsystem.h"
|
2000-05-27 00:26:30 +02:00
|
|
|
|
|
|
|
#include "dplayx_global.h"
|
2000-03-12 21:18:33 +01:00
|
|
|
#include "name_server.h"
|
2008-07-22 21:23:05 +02:00
|
|
|
#include "wine/dplaysp.h"
|
2000-08-25 23:58:05 +02:00
|
|
|
#include "dplayx_messages.h"
|
|
|
|
#include "dplayx_queue.h"
|
2000-03-12 21:18:33 +01:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
/* FIXME: Need to create a crit section, store and use it */
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dplay);
|
2000-03-12 21:18:33 +01:00
|
|
|
|
2000-05-27 00:26:30 +02:00
|
|
|
/* NS specific structures */
|
2000-08-25 23:58:05 +02:00
|
|
|
struct NSCacheData
|
2000-05-27 00:26:30 +02:00
|
|
|
{
|
2000-08-25 23:58:05 +02:00
|
|
|
DPQ_ENTRY(NSCacheData) next;
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
DWORD dwTime; /* Time at which data was last known valid */
|
2000-05-27 00:26:30 +02:00
|
|
|
LPDPSESSIONDESC2 data;
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
LPVOID lpNSAddrHdr;
|
2000-03-12 21:18:33 +01:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
};
|
|
|
|
typedef struct NSCacheData NSCacheData, *lpNSCacheData;
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
struct NSCache
|
|
|
|
{
|
|
|
|
lpNSCacheData present; /* keep track of what is to be looked at when walking */
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
DPQ_HEAD(NSCacheData) first;
|
2001-04-12 23:10:54 +02:00
|
|
|
|
|
|
|
BOOL bNsIsLocal;
|
|
|
|
LPVOID lpLocalAddrHdr; /* FIXME: Not yet used */
|
|
|
|
LPVOID lpRemoteAddrHdr; /* FIXME: Not yet used */
|
2002-06-01 01:06:46 +02:00
|
|
|
};
|
2000-08-25 23:58:05 +02:00
|
|
|
typedef struct NSCache NSCache, *lpNSCache;
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2000-09-27 01:11:48 +02:00
|
|
|
/* Function prototypes */
|
2007-01-06 20:31:56 +01:00
|
|
|
static DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData );
|
2000-09-27 01:11:48 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Name Server functions
|
|
|
|
* ---------------------
|
2000-05-27 00:26:30 +02:00
|
|
|
*/
|
2001-04-12 23:10:54 +02:00
|
|
|
void NS_SetLocalComputerAsNameServer( LPCDPSESSIONDESC2 lpsd, LPVOID lpNSInfo )
|
2000-05-27 00:26:30 +02:00
|
|
|
{
|
2000-08-25 23:58:05 +02:00
|
|
|
#if 0
|
2000-09-27 01:11:48 +02:00
|
|
|
/* FIXME: Remove this method? */
|
2000-05-27 00:26:30 +02:00
|
|
|
DPLAYX_SetLocalSession( lpsd );
|
2000-08-25 23:58:05 +02:00
|
|
|
#endif
|
2001-04-12 23:10:54 +02:00
|
|
|
lpNSCache lpCache = (lpNSCache)lpNSInfo;
|
|
|
|
|
|
|
|
lpCache->bNsIsLocal = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NS_SetRemoteComputerAsNameServer( LPCDPSESSIONDESC2 lpsd, LPVOID lpNSInfo )
|
|
|
|
{
|
|
|
|
lpNSCache lpCache = (lpNSCache)lpNSInfo;
|
|
|
|
|
|
|
|
lpCache->bNsIsLocal = FALSE;
|
2000-08-25 23:58:05 +02:00
|
|
|
}
|
|
|
|
|
2005-07-05 14:49:14 +02:00
|
|
|
static DPQ_DECL_COMPARECB( cbUglyPig, GUID )
|
2000-09-27 01:11:48 +02:00
|
|
|
{
|
|
|
|
return IsEqualGUID( elem1, elem2 );
|
|
|
|
}
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
/* Store the given NS remote address for future reference */
|
2006-09-10 01:14:23 +02:00
|
|
|
void NS_AddRemoteComputerAsNameServer( LPCVOID lpcNSAddrHdr,
|
|
|
|
DWORD dwHdrSize,
|
|
|
|
LPCDPMSG_ENUMSESSIONSREPLY lpcMsg,
|
|
|
|
LPVOID lpNSInfo )
|
2000-08-25 23:58:05 +02:00
|
|
|
{
|
2000-11-16 01:28:52 +01:00
|
|
|
DWORD len;
|
2000-08-25 23:58:05 +02:00
|
|
|
lpNSCache lpCache = (lpNSCache)lpNSInfo;
|
|
|
|
lpNSCacheData lpCacheNode;
|
|
|
|
|
2006-09-10 01:14:23 +02:00
|
|
|
TRACE( "%p, %p, %p\n", lpcNSAddrHdr, lpcMsg, lpNSInfo );
|
2000-09-27 01:11:48 +02:00
|
|
|
|
|
|
|
/* See if we can find this session. If we can, remove it as it's a dup */
|
|
|
|
DPQ_REMOVE_ENTRY_CB( lpCache->first, next, data->guidInstance, cbUglyPig,
|
2006-09-10 01:14:23 +02:00
|
|
|
lpcMsg->sd.guidInstance, lpCacheNode );
|
2000-09-27 01:11:48 +02:00
|
|
|
|
|
|
|
if( lpCacheNode != NULL )
|
|
|
|
{
|
|
|
|
TRACE( "Duplicate session entry for %s removed - updated version kept\n",
|
|
|
|
debugstr_guid( &lpCacheNode->data->guidInstance ) );
|
|
|
|
cbDeleteNSNodeFromHeap( lpCacheNode );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add this to the list */
|
2005-03-24 22:01:35 +01:00
|
|
|
lpCacheNode = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpCacheNode ) );
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
if( lpCacheNode == NULL )
|
|
|
|
{
|
|
|
|
ERR( "no memory for NS node\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpCacheNode->lpNSAddrHdr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
dwHdrSize );
|
2001-04-12 23:10:54 +02:00
|
|
|
CopyMemory( lpCacheNode->lpNSAddrHdr, lpcNSAddrHdr, dwHdrSize );
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2005-03-24 22:01:35 +01:00
|
|
|
lpCacheNode->data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *(lpCacheNode->data) ) );
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
if( lpCacheNode->data == NULL )
|
|
|
|
{
|
|
|
|
ERR( "no memory for SESSIONDESC2\n" );
|
2007-09-22 16:40:15 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, lpCacheNode );
|
2000-08-25 23:58:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-28 23:52:28 +01:00
|
|
|
*lpCacheNode->data = lpcMsg->sd;
|
2006-09-10 01:14:23 +02:00
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1, NULL, 0, NULL, NULL );
|
2000-12-03 04:16:05 +01:00
|
|
|
if ((lpCacheNode->data->u1.lpszSessionNameA = HeapAlloc( GetProcessHeap(), 0, len )))
|
2001-04-12 23:10:54 +02:00
|
|
|
{
|
2006-09-10 01:14:23 +02:00
|
|
|
WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)(lpcMsg+1), -1,
|
2000-12-03 04:16:05 +01:00
|
|
|
lpCacheNode->data->u1.lpszSessionNameA, len, NULL, NULL );
|
2001-04-12 23:10:54 +02:00
|
|
|
}
|
2000-08-25 23:58:05 +02:00
|
|
|
|
2000-09-27 01:11:48 +02:00
|
|
|
lpCacheNode->dwTime = timeGetTime();
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
DPQ_INSERT(lpCache->first, lpCacheNode, next );
|
|
|
|
|
|
|
|
lpCache->present = lpCacheNode;
|
|
|
|
|
2003-05-13 02:41:57 +02:00
|
|
|
/* Use this message as an opportunity to weed out any old sessions so
|
2002-06-01 01:06:46 +02:00
|
|
|
* that we don't enum them again
|
2000-08-25 23:58:05 +02:00
|
|
|
*/
|
|
|
|
NS_PruneSessionCache( lpNSInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
LPVOID NS_GetNSAddr( LPVOID lpNSInfo )
|
|
|
|
{
|
|
|
|
lpNSCache lpCache = (lpNSCache)lpNSInfo;
|
|
|
|
|
|
|
|
FIXME( ":quick stub\n" );
|
|
|
|
|
|
|
|
/* Ok. Cheat and don't search for the correct stuff just take the first.
|
|
|
|
* FIXME: In the future how are we to know what is _THE_ enum we used?
|
2000-09-27 01:11:48 +02:00
|
|
|
* This is going to have to go into dplay somehow. Perhaps it
|
2008-11-25 17:42:38 +01:00
|
|
|
* comes back with app server id for the join command! Oh... that
|
2000-09-27 01:11:48 +02:00
|
|
|
* must be it. That would make this method obsolete once that's
|
|
|
|
* in place.
|
2000-08-25 23:58:05 +02:00
|
|
|
*/
|
2001-04-12 23:10:54 +02:00
|
|
|
#if 1
|
2000-08-25 23:58:05 +02:00
|
|
|
return lpCache->first.lpQHFirst->lpNSAddrHdr;
|
2001-04-12 23:10:54 +02:00
|
|
|
#else
|
|
|
|
/* FIXME: Should convert over to this */
|
|
|
|
return lpCache->bNsIsLocal ? lpCache->lpLocalAddrHdr
|
|
|
|
: lpCache->lpRemoteAddrHdr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the magic number associated with the Name Server */
|
|
|
|
DWORD NS_GetNsMagic( LPVOID lpNSInfo )
|
|
|
|
{
|
2009-01-16 09:53:59 +01:00
|
|
|
LPDWORD lpHdrInfo = NS_GetNSAddr( lpNSInfo );
|
2001-04-12 23:10:54 +02:00
|
|
|
|
|
|
|
return lpHdrInfo[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the magic number associated with the non NS end */
|
|
|
|
DWORD NS_GetOtherMagic( LPVOID lpNSInfo )
|
|
|
|
{
|
|
|
|
lpNSCache lpCache = (lpNSCache)lpNSInfo;
|
|
|
|
|
|
|
|
return ((LPDWORD)lpCache->lpLocalAddrHdr)[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void NS_SetLocalAddr( LPVOID lpNSInfo, LPCVOID lpHdr, DWORD dwHdrSize )
|
|
|
|
{
|
|
|
|
lpNSCache lpCache = (lpNSCache)lpNSInfo;
|
|
|
|
|
|
|
|
lpCache->lpLocalAddrHdr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwHdrSize );
|
|
|
|
|
|
|
|
CopyMemory( lpCache->lpLocalAddrHdr, lpHdr, dwHdrSize );
|
2000-03-12 21:18:33 +01:00
|
|
|
}
|
|
|
|
|
2000-05-27 00:26:30 +02:00
|
|
|
/* This function is responsible for sending a request for all other known
|
|
|
|
nameservers to send us what sessions they have registered locally
|
|
|
|
*/
|
2000-08-25 23:58:05 +02:00
|
|
|
HRESULT NS_SendSessionRequestBroadcast( LPCGUID lpcGuid,
|
|
|
|
DWORD dwFlags,
|
2007-04-26 23:45:27 +02:00
|
|
|
const SPINITDATA *lpSpData )
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-05-27 00:26:30 +02:00
|
|
|
{
|
2000-08-25 23:58:05 +02:00
|
|
|
DPSP_ENUMSESSIONSDATA data;
|
|
|
|
LPDPMSG_ENUMSESSIONSREQUEST lpMsg;
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
TRACE( "enumerating for guid %s\n", debugstr_guid( lpcGuid ) );
|
|
|
|
|
|
|
|
/* Get the SP to deal with sending the EnumSessions request */
|
|
|
|
FIXME( ": not all data fields are correct\n" );
|
|
|
|
|
|
|
|
data.dwMessageSize = lpSpData->dwSPHeaderSize + sizeof( *lpMsg ); /*FIXME!*/
|
2002-06-01 01:06:46 +02:00
|
|
|
data.lpMessage = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2000-08-25 23:58:05 +02:00
|
|
|
data.dwMessageSize );
|
|
|
|
data.lpISP = lpSpData->lpISP;
|
|
|
|
data.bReturnStatus = (dwFlags & DPENUMSESSIONS_RETURNSTATUS) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
lpMsg = (LPDPMSG_ENUMSESSIONSREQUEST)(((BYTE*)data.lpMessage)+lpSpData->dwSPHeaderSize);
|
2000-08-25 23:58:05 +02:00
|
|
|
|
2003-05-13 02:41:57 +02:00
|
|
|
/* Setup EnumSession request message */
|
2000-08-25 23:58:05 +02:00
|
|
|
lpMsg->envelope.dwMagic = DPMSGMAGIC_DPLAYMSG;
|
|
|
|
lpMsg->envelope.wCommandId = DPMSGCMD_ENUMSESSIONSREQUEST;
|
|
|
|
lpMsg->envelope.wVersion = DPMSGVER_DP6;
|
|
|
|
|
|
|
|
lpMsg->dwPasswordSize = 0; /* FIXME: If enumerating passwords..? */
|
|
|
|
lpMsg->dwFlags = dwFlags;
|
|
|
|
|
2008-03-28 23:52:28 +01:00
|
|
|
lpMsg->guidApplication = *lpcGuid;
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
return (lpSpData->lpCB->EnumSessions)( &data );
|
2000-05-27 00:26:30 +02:00
|
|
|
}
|
|
|
|
|
2000-09-27 01:11:48 +02:00
|
|
|
/* Delete a name server node which has been allocated on the heap */
|
2007-01-06 20:31:56 +01:00
|
|
|
static DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData )
|
2000-08-25 23:58:05 +02:00
|
|
|
{
|
2000-09-27 01:11:48 +02:00
|
|
|
/* NOTE: This proc doesn't deal with the walking pointer */
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
/* FIXME: Memory leak on data (contained ptrs) */
|
|
|
|
HeapFree( GetProcessHeap(), 0, elem->data );
|
|
|
|
HeapFree( GetProcessHeap(), 0, elem->lpNSAddrHdr );
|
|
|
|
HeapFree( GetProcessHeap(), 0, elem );
|
|
|
|
}
|
|
|
|
|
2000-05-27 00:26:30 +02:00
|
|
|
/* Render all data in a session cache invalid */
|
2000-08-25 23:58:05 +02:00
|
|
|
void NS_InvalidateSessionCache( LPVOID lpNSInfo )
|
2000-05-27 00:26:30 +02:00
|
|
|
{
|
2000-08-25 23:58:05 +02:00
|
|
|
lpNSCache lpCache = (lpNSCache)lpNSInfo;
|
|
|
|
|
2000-05-27 00:26:30 +02:00
|
|
|
if( lpCache == NULL )
|
|
|
|
{
|
2005-02-10 20:19:35 +01:00
|
|
|
ERR( ": invalidate nonexistent cache\n" );
|
2000-05-27 00:26:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
DPQ_DELETEQ( lpCache->first, next, lpNSCacheData, cbDeleteNSNodeFromHeap );
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
/* NULL out the walking pointer */
|
2000-05-27 00:26:30 +02:00
|
|
|
lpCache->present = NULL;
|
2001-04-12 23:10:54 +02:00
|
|
|
|
|
|
|
lpCache->bNsIsLocal = FALSE;
|
|
|
|
|
2000-05-27 00:26:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Create and initialize a session cache */
|
|
|
|
BOOL NS_InitializeSessionCache( LPVOID* lplpNSInfo )
|
|
|
|
{
|
2005-03-24 22:01:35 +01:00
|
|
|
lpNSCache lpCache = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( *lpCache ) );
|
2000-05-27 00:26:30 +02:00
|
|
|
|
|
|
|
*lplpNSInfo = lpCache;
|
|
|
|
|
|
|
|
if( lpCache == NULL )
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
DPQ_INIT(lpCache->first);
|
|
|
|
lpCache->present = NULL;
|
2000-05-27 00:26:30 +02:00
|
|
|
|
2001-04-12 23:10:54 +02:00
|
|
|
lpCache->bNsIsLocal = FALSE;
|
|
|
|
|
2000-05-27 00:26:30 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete a session cache */
|
|
|
|
void NS_DeleteSessionCache( LPVOID lpNSInfo )
|
|
|
|
{
|
|
|
|
NS_InvalidateSessionCache( (lpNSCache)lpNSInfo );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reinitialize the present pointer for this cache */
|
|
|
|
void NS_ResetSessionEnumeration( LPVOID lpNSInfo )
|
|
|
|
{
|
2000-08-25 23:58:05 +02:00
|
|
|
((lpNSCache)lpNSInfo)->present = ((lpNSCache)lpNSInfo)->first.lpQHFirst;
|
2000-05-27 00:26:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LPDPSESSIONDESC2 NS_WalkSessions( LPVOID lpNSInfo )
|
|
|
|
{
|
|
|
|
LPDPSESSIONDESC2 lpSessionDesc;
|
|
|
|
lpNSCache lpCache = (lpNSCache)lpNSInfo;
|
|
|
|
|
2000-08-25 23:58:05 +02:00
|
|
|
/* FIXME: The pointers could disappear when walking if a prune happens */
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Test for end of the list */
|
2000-05-27 00:26:30 +02:00
|
|
|
if( lpCache->present == NULL )
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpSessionDesc = lpCache->present->data;
|
|
|
|
|
|
|
|
/* Advance tracking pointer */
|
2000-08-25 23:58:05 +02:00
|
|
|
lpCache->present = lpCache->present->next.lpQNext;
|
2000-05-27 00:26:30 +02:00
|
|
|
|
|
|
|
return lpSessionDesc;
|
|
|
|
}
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
/* This method should check to see if there are any sessions which are
|
|
|
|
* older than the criteria. If so, just delete that information.
|
|
|
|
*/
|
2000-09-27 01:11:48 +02:00
|
|
|
/* FIXME: This needs to be called by some periodic timer */
|
2000-08-25 23:58:05 +02:00
|
|
|
void NS_PruneSessionCache( LPVOID lpNSInfo )
|
|
|
|
{
|
|
|
|
lpNSCache lpCache = lpNSInfo;
|
|
|
|
|
2000-09-27 01:11:48 +02:00
|
|
|
const DWORD dwPresentTime = timeGetTime();
|
2001-04-12 23:10:54 +02:00
|
|
|
const DWORD dwPrunePeriod = DPMSG_WAIT_60_SECS; /* is 60 secs enough? */
|
2000-08-25 23:58:05 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* This silly little algorithm is based on the fact we keep entries in
|
2000-09-27 01:11:48 +02:00
|
|
|
* the queue in a time based order. It also assumes that it is not possible
|
|
|
|
* to wrap around over yourself (which is not unreasonable).
|
2002-06-01 01:06:46 +02:00
|
|
|
* The if statements verify if the first entry in the queue is less
|
2000-09-27 01:11:48 +02:00
|
|
|
* than dwPrunePeriod old depending on the "clock" roll over.
|
|
|
|
*/
|
|
|
|
for( ;; )
|
2000-08-25 23:58:05 +02:00
|
|
|
{
|
2000-09-27 01:11:48 +02:00
|
|
|
lpNSCacheData lpFirstData;
|
|
|
|
|
|
|
|
if( DPQ_IS_EMPTY(lpCache->first) )
|
|
|
|
{
|
|
|
|
/* Nothing to prune */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-05-13 02:41:57 +02:00
|
|
|
/* Deal with time in a wrap around safe manner - unsigned arithmetic.
|
2001-04-12 23:10:54 +02:00
|
|
|
* Check the difference in time */
|
|
|
|
if( (dwPresentTime - (DPQ_FIRST(lpCache->first)->dwTime)) < dwPrunePeriod )
|
2000-09-27 01:11:48 +02:00
|
|
|
{
|
2001-04-12 23:10:54 +02:00
|
|
|
/* First entry has not expired yet; don't prune */
|
|
|
|
break;
|
2000-09-27 01:11:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lpFirstData = DPQ_FIRST(lpCache->first);
|
|
|
|
DPQ_REMOVE( lpCache->first, DPQ_FIRST(lpCache->first), next );
|
|
|
|
cbDeleteNSNodeFromHeap( lpFirstData );
|
2000-08-25 23:58:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-09-27 01:11:48 +02:00
|
|
|
/* NAME SERVER Message stuff */
|
2002-06-01 01:06:46 +02:00
|
|
|
void NS_ReplyToEnumSessionsRequest( LPCVOID lpcMsg,
|
2001-04-12 23:10:54 +02:00
|
|
|
LPVOID* lplpReplyData,
|
|
|
|
LPDWORD lpdwReplySize,
|
2000-08-25 23:58:05 +02:00
|
|
|
IDirectPlay2Impl* lpDP )
|
|
|
|
{
|
|
|
|
LPDPMSG_ENUMSESSIONSREPLY rmsg;
|
|
|
|
DWORD dwVariableSize;
|
|
|
|
DWORD dwVariableLen;
|
2001-04-12 23:10:54 +02:00
|
|
|
/* LPCDPMSG_ENUMSESSIONSREQUEST msg = (LPDPMSG_ENUMSESSIONSREQUEST)lpcMsg; */
|
2000-08-25 23:58:05 +02:00
|
|
|
BOOL bAnsi = TRUE; /* FIXME: This needs to be in the DPLAY interface */
|
|
|
|
|
|
|
|
FIXME( ": few fixed + need to check request for response\n" );
|
|
|
|
|
2000-11-16 01:28:52 +01:00
|
|
|
if (bAnsi)
|
2001-04-12 23:10:54 +02:00
|
|
|
{
|
2000-11-16 01:28:52 +01:00
|
|
|
dwVariableLen = MultiByteToWideChar( CP_ACP, 0,
|
2000-12-03 04:16:05 +01:00
|
|
|
lpDP->dp2->lpSessionDesc->u1.lpszSessionNameA,
|
2000-11-16 01:28:52 +01:00
|
|
|
-1, NULL, 0 );
|
2001-04-12 23:10:54 +02:00
|
|
|
}
|
2000-11-16 01:28:52 +01:00
|
|
|
else
|
2001-04-12 23:10:54 +02:00
|
|
|
{
|
2000-12-03 04:16:05 +01:00
|
|
|
dwVariableLen = strlenW( lpDP->dp2->lpSessionDesc->u1.lpszSessionName ) + 1;
|
2001-04-12 23:10:54 +02:00
|
|
|
}
|
2000-08-25 23:58:05 +02:00
|
|
|
|
|
|
|
dwVariableSize = dwVariableLen * sizeof( WCHAR );
|
|
|
|
|
2001-04-12 23:10:54 +02:00
|
|
|
*lpdwReplySize = lpDP->dp2->spData.dwSPHeaderSize +
|
|
|
|
sizeof( *rmsg ) + dwVariableSize;
|
|
|
|
*lplpReplyData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
*lpdwReplySize );
|
2000-08-25 23:58:05 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
rmsg = (LPDPMSG_ENUMSESSIONSREPLY)( (BYTE*)*lplpReplyData +
|
2000-08-30 01:55:06 +02:00
|
|
|
lpDP->dp2->spData.dwSPHeaderSize);
|
2000-08-25 23:58:05 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
rmsg->envelope.dwMagic = DPMSGMAGIC_DPLAYMSG;
|
2000-08-25 23:58:05 +02:00
|
|
|
rmsg->envelope.wCommandId = DPMSGCMD_ENUMSESSIONSREPLY;
|
|
|
|
rmsg->envelope.wVersion = DPMSGVER_DP6;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
CopyMemory( &rmsg->sd, lpDP->dp2->lpSessionDesc,
|
2007-03-22 17:20:17 +01:00
|
|
|
lpDP->dp2->lpSessionDesc->dwSize );
|
2000-08-25 23:58:05 +02:00
|
|
|
rmsg->dwUnknown = 0x0000005c;
|
|
|
|
if( bAnsi )
|
2001-04-12 23:10:54 +02:00
|
|
|
{
|
2000-12-03 04:16:05 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpDP->dp2->lpSessionDesc->u1.lpszSessionNameA, -1,
|
2000-11-16 01:28:52 +01:00
|
|
|
(LPWSTR)(rmsg+1), dwVariableLen );
|
2001-04-12 23:10:54 +02:00
|
|
|
}
|
2000-08-25 23:58:05 +02:00
|
|
|
else
|
2001-04-12 23:10:54 +02:00
|
|
|
{
|
2000-12-03 04:16:05 +01:00
|
|
|
strcpyW( (LPWSTR)(rmsg+1), lpDP->dp2->lpSessionDesc->u1.lpszSessionName );
|
2001-04-12 23:10:54 +02:00
|
|
|
}
|
2000-08-25 23:58:05 +02:00
|
|
|
}
|