Replaced all lstr* calls from inside Wine code by their str* equivalent.
[wine/hacks.git] / dlls / dplayx / name_server.c
blobd81ad5721dba6cfdf6f74acf89e5d0e18765a9a8
1 /* DPLAYX.DLL name server implementation
3 * Copyright 2000 - Peter Hunnisett
5 * <presently under construction - contact hunnise@nortelnetworks.com>
7 */
9 /* NOTE: Methods with the NS_ prefix are name server methods */
11 #include "winbase.h"
12 #include "debugtools.h"
14 #include "dplayx_global.h"
15 #include "name_server.h"
17 /* FIXME: Need to aquire the interface semaphore before didlling data */
19 DEFAULT_DEBUG_CHANNEL(dplay);
21 /* NS specific structures */
22 typedef struct tagNSCacheData
24 struct tagNSCacheData* next;
26 LPDPSESSIONDESC2 data;
28 } NSCacheData, *lpNSCacheData;
30 typedef struct tagNSCache
32 lpNSCacheData present; /* keep track of what is to be looked at */
33 lpNSCacheData first;
34 } NSCache, *lpNSCache;
36 /* Local Prototypes */
37 static void NS_InvalidateSessionCache( lpNSCache lpCache );
40 /* Name Server functions
41 * ---------------------
43 void NS_SetLocalComputerAsNameServer( LPCDPSESSIONDESC2 lpsd )
45 DPLAYX_SetLocalSession( lpsd );
48 /* This function is responsible for sending a request for all other known
49 nameservers to send us what sessions they have registered locally
51 void NS_SendSessionRequestBroadcast( LPVOID lpNSInfo )
53 UINT index = 0;
54 lpNSCache lpCache = (lpNSCache)lpNSInfo;
55 LPDPSESSIONDESC2 lpTmp = NULL;
57 /* Invalidate the session cache for the interface */
58 NS_InvalidateSessionCache( lpCache );
60 /* Add the local known sessions to the cache */
61 if( ( lpTmp = DPLAYX_CopyAndAllocateLocalSession( &index ) ) != NULL )
63 lpCache->first = (lpNSCacheData)HeapAlloc( GetProcessHeap(),
64 HEAP_ZERO_MEMORY,
65 sizeof( *(lpCache->first) ) );
66 lpCache->first->data = lpTmp;
67 lpCache->first->next = NULL;
68 lpCache->present = lpCache->first;
70 while( ( lpTmp = DPLAYX_CopyAndAllocateLocalSession( &index ) ) != NULL )
72 lpCache->present->next = (lpNSCacheData)HeapAlloc( GetProcessHeap(),
73 HEAP_ZERO_MEMORY,
74 sizeof( *(lpCache->present) ) );
75 lpCache->present = lpCache->present->next;
76 lpCache->present->data = lpTmp;
77 lpCache->present->next = NULL;
80 lpCache->present = lpCache->first;
83 /* Send out requests for matching sessions to all other known computers */
84 FIXME( ": no remote requests sent\n" );
85 /* FIXME - how to handle responses to messages anyways? */
88 /* Render all data in a session cache invalid */
89 static void NS_InvalidateSessionCache( lpNSCache lpCache )
91 if( lpCache == NULL )
93 ERR( ": invalidate non existant cache\n" );
94 return;
97 /* Remove everything from the cache */
98 while( lpCache->first )
100 lpCache->present = lpCache->first;
101 lpCache->first = lpCache->first->next;
102 HeapFree( GetProcessHeap(), 0, lpCache->present );
105 /* NULL out the cache pointers */
106 lpCache->present = NULL;
107 lpCache->first = NULL;
110 /* Create and initialize a session cache */
111 BOOL NS_InitializeSessionCache( LPVOID* lplpNSInfo )
113 lpNSCache lpCache = (lpNSCache)HeapAlloc( GetProcessHeap(),
114 HEAP_ZERO_MEMORY,
115 sizeof( *lpCache ) );
117 *lplpNSInfo = lpCache;
119 if( lpCache == NULL )
121 return FALSE;
124 lpCache->first = lpCache->present = NULL;
126 return TRUE;
129 /* Delete a session cache */
130 void NS_DeleteSessionCache( LPVOID lpNSInfo )
132 NS_InvalidateSessionCache( (lpNSCache)lpNSInfo );
135 /* Reinitialize the present pointer for this cache */
136 void NS_ResetSessionEnumeration( LPVOID lpNSInfo )
139 ((lpNSCache)lpNSInfo)->present = ((lpNSCache)lpNSInfo)->first;
142 LPDPSESSIONDESC2 NS_WalkSessions( LPVOID lpNSInfo )
144 LPDPSESSIONDESC2 lpSessionDesc;
145 lpNSCache lpCache = (lpNSCache)lpNSInfo;
147 /* Test for end of the list */
148 if( lpCache->present == NULL )
150 return NULL;
153 lpSessionDesc = lpCache->present->data;
155 /* Advance tracking pointer */
156 lpCache->present = lpCache->present->next;
158 return lpSessionDesc;