ReactOS  0.4.14-dev-49-gfb4591c
dcatalog.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS WinSock 2 API
4  * FILE: dll/win32/ws2_32_new/src/dcatalog.c
5  * PURPOSE: Transport Catalog Object
6  * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <ws2_32.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* DATA **********************************************************************/
17 
18 #define WsTcLock() EnterCriticalSection(&Catalog->Lock)
19 #define WsTcUnlock() LeaveCriticalSection(&Catalog->Lock)
20 
21 /* FUNCTIONS *****************************************************************/
22 
24 WSAAPI
26 {
27  PTCATALOG Catalog;
28 
29  /* Allocate the object */
30  Catalog = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Catalog));
31 
32  /* Return it */
33  return Catalog;
34 }
35 
36 BOOL
37 WSAAPI
39  IN HKEY ParentKey)
40 {
41  INT ErrorCode;
43  HKEY CatalogKey, NewKey;
44  //DWORD CatalogEntries = 0;
45  DWORD RegType = REG_DWORD;
46  DWORD RegSize = sizeof(DWORD);
47  DWORD UniqueId = 0;
48  DWORD NewData = 0;
49  CHAR* CatalogKeyName;
50 
51  /* Initialize the catalog lock and namespace list */
52  InitializeCriticalSection(&Catalog->Lock);
53  InitializeListHead(&Catalog->ProtocolList);
54 
55  /* Read the catalog name */
56  ErrorCode = RegQueryValueEx(ParentKey,
57  "Current_Protocol_Catalog",
58  0,
59  &RegType,
60  NULL,
61  &RegSize);
62 
63  CatalogKeyName = HeapAlloc(WsSockHeap, 0, RegSize);
64 
65  /* Read the catalog name */
66  ErrorCode = RegQueryValueEx(ParentKey,
67  "Current_Protocol_Catalog",
68  0,
69  &RegType,
70  (LPBYTE)CatalogKeyName,
71  &RegSize);
72 
73  /* Open the Catalog Key */
74  ErrorCode = RegOpenKeyEx(ParentKey,
75  CatalogKeyName,
76  0,
78  &CatalogKey);
79 
80  /* If we didn't find the key, create it */
81  if (ErrorCode == ERROR_SUCCESS)
82  {
83  /* Fake that we opened an existing key */
85  }
86  else if (ErrorCode == ERROR_FILE_NOT_FOUND)
87  {
88  /* Create the Catalog Name */
89  ErrorCode = RegCreateKeyEx(ParentKey,
90  CatalogKeyName,
91  0,
92  NULL,
95  NULL,
96  &CatalogKey,
98  }
99 
100  HeapFree(WsSockHeap, 0, CatalogKeyName);
101  RegType = REG_DWORD;
102  RegSize = sizeof(DWORD);
103 
104  /* Fail if that didn't work */
105  if (ErrorCode != ERROR_SUCCESS) return FALSE;
106 
107  /* Check if we had to create the key */
109  {
110  /* Write the count of entries (0 now) */
111  ErrorCode = RegSetValueEx(CatalogKey,
112  "Num_Catalog_Entries",
113  0,
114  REG_DWORD,
115  (LPBYTE)&NewData,
116  sizeof(NewData));
117  if (ErrorCode != ERROR_SUCCESS)
118  {
119  /* Close the key and fail */
120  RegCloseKey(CatalogKey);
121  return FALSE;
122  }
123 
124  /* Write the first catalog entry ID */
125  NewData = 1001;
126  ErrorCode = RegSetValueEx(CatalogKey,
127  "Next_Catalog_Entry_ID",
128  0,
129  REG_DWORD,
130  (LPBYTE)&NewData,
131  sizeof(NewData));
132  if (ErrorCode != ERROR_SUCCESS)
133  {
134  /* Close the key and fail */
135  RegCloseKey(CatalogKey);
136  return FALSE;
137  }
138 
139  /* Write the first catalog entry Uniqe ID */
140  NewData = 1;
141  ErrorCode = RegSetValueEx(CatalogKey,
142  "Serial_Access_Num",
143  0,
144  REG_DWORD,
145  (LPBYTE)&NewData,
146  sizeof(NewData));
147  if (ErrorCode != ERROR_SUCCESS)
148  {
149  /* Close the key and fail */
150  RegCloseKey(CatalogKey);
151  return FALSE;
152  }
153 
154  /* Create a key for this entry */
155  ErrorCode = RegCreateKeyEx(CatalogKey,
156  "Catalog_Entries",
157  0,
158  NULL,
161  NULL,
162  &NewKey,
164  if (ErrorCode != ERROR_SUCCESS)
165  {
166  /* Close the key and fail */
167  RegCloseKey(CatalogKey);
168  return FALSE;
169  }
170 
171  /* Close the key since we don't need it */
172  RegCloseKey(NewKey);
173  }
174  else
175  {
176  RegSize = sizeof(DWORD);
177  /* Read the serial number */
178  ErrorCode = RegQueryValueEx(CatalogKey,
179  "Serial_Access_Num",
180  0,
181  &RegType,
182  (LPBYTE)&UniqueId,
183  &RegSize);
184 
185  /* Check if it's missing for some reason */
186  if (ErrorCode != ERROR_SUCCESS)
187  {
188  /* Write the first catalog entry Unique ID */
189  NewData = 1;
190  ErrorCode = RegSetValueEx(CatalogKey,
191  "Serial_Access_Num",
192  0,
193  REG_DWORD,
194  (LPBYTE)&NewData,
195  sizeof(NewData));
196  }
197  }
198 
199  /* Set the Catalog Key */
200  Catalog->CatalogKey = CatalogKey;
201  return TRUE;
202 }
203 
204 DWORD
205 WSAAPI
207  IN HKEY ParentKey,
208  IN HANDLE CatalogEvent)
209 {
211 
212  /* Open the catalog */
213  if (WsTcOpen(Catalog, ParentKey))
214  {
215  /* Refresh it */
216  ErrorCode = WsTcRefreshFromRegistry(Catalog, CatalogEvent);
217  }
218 
219  /* Return the status */
220  return ErrorCode;
221 }
222 
223 DWORD
224 WSAAPI
226  IN HANDLE CatalogEvent)
227 {
228  INT ErrorCode;
229  BOOLEAN LocalEvent = FALSE;
230  LIST_ENTRY LocalList;
231  DWORD UniqueId;
232  HKEY EntriesKey;
233  DWORD CatalogEntries;
234  PTCATALOG_ENTRY CatalogEntry;
235  DWORD NextCatalogEntry;
236  BOOL NewChangesMade;
238  DWORD RegType = REG_DWORD;
239  DWORD RegSize = sizeof(DWORD);
240  DWORD i;
241 
242  /* Check if we got an event */
243  if (!CatalogEvent)
244  {
245  /* Create an event ourselves */
246  CatalogEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
247  if (!CatalogEvent) return WSASYSCALLFAILURE;
248  LocalEvent = TRUE;
249  }
250 
251  /* Lock the catalog */
252  WsTcLock();
253 
254  /* Initialize our local list for the loop */
255  InitializeListHead(&LocalList);
256 
257  /* Start looping */
258  do
259  {
260  /* Setup notifications for the catalog entry */
261  ErrorCode = WsSetupCatalogProtection(Catalog->CatalogKey,
262  CatalogEvent,
263  &UniqueId);
264  if (ErrorCode != ERROR_SUCCESS) break;
265 
266  /* Check if we've changed till now */
267  if (UniqueId == Catalog->UniqueId)
268  {
269  /* We haven't, so return */
271  break;
272  }
273 
274  /* Now Open the Entries */
275  ErrorCode = RegOpenKeyEx(Catalog->CatalogKey,
276  "Catalog_Entries",
277  0,
279  &EntriesKey);
280  if (ErrorCode != ERROR_SUCCESS)
281  {
282  /* Critical failure */
284  break;
285  }
286 
287  /* Get the next entry */
288  ErrorCode = RegQueryValueEx(Catalog->CatalogKey,
289  "Next_Catalog_Entry_ID",
290  0,
291  &RegType,
292  (LPBYTE)&NextCatalogEntry,
293  &RegSize);
294  if (ErrorCode != ERROR_SUCCESS)
295  {
296  /* Critical failure */
298  break;
299  }
300 
301  /* Find out how many there are */
302  ErrorCode = RegQueryValueEx(Catalog->CatalogKey,
303  "Num_Catalog_Entries",
304  0,
305  &RegType,
306  (LPBYTE)&CatalogEntries,
307  &RegSize);
308  if (ErrorCode != ERROR_SUCCESS)
309  {
310  /* Critical failure */
312  break;
313  }
314 
315  /* Initialize them all */
316  for (i = 1; i <= CatalogEntries; i++)
317  {
318  /* Allocate a Catalog Entry Structure */
319  CatalogEntry = WsTcEntryAllocate();
320  if (!CatalogEntry)
321  {
322  /* Not enough memory, fail */
324  break;
325  }
326 
327  /* Initialize it from the Registry Key */
329  EntriesKey,
330  i);
331  if (ErrorCode != ERROR_SUCCESS)
332  {
333  /* We failed to get it, dereference the entry and leave */
334  WsTcEntryDereference(CatalogEntry);
335  break;
336  }
337 
338  /* Insert it to our List */
339  InsertTailList(&LocalList, &CatalogEntry->CatalogLink);
340  }
341 
342  /* Close the catalog key */
343  RegCloseKey(EntriesKey);
344 
345  /* Check if we changed during our read and if we have success */
346  NewChangesMade = WsCheckCatalogState(CatalogEvent);
347  if (!NewChangesMade && ErrorCode == ERROR_SUCCESS)
348  {
349  /* All is good, update the protocol list */
350  WsTcUpdateProtocolList(Catalog, &LocalList);
351 
352  /* Update and return */
353  Catalog->UniqueId = UniqueId;
354  Catalog->NextId = NextCatalogEntry;
355  break;
356  }
357 
358  /* We failed and/or catalog data changed, free what we did till now */
359  while (!IsListEmpty(&LocalList))
360  {
361  /* Get the LP Catalog Item */
362  Entry = RemoveHeadList(&LocalList);
363  CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
364 
365  /* Dereference it */
366  WsTcEntryDereference(CatalogEntry);
367  }
368  } while (NewChangesMade);
369 
370  /* Release the lock */
371  WsTcUnlock();
372 
373  /* Close the event, if any was created by us */
374  if (LocalEvent) CloseHandle(CatalogEvent);
375 
376  /* All Done */
377  return ErrorCode;
378 }
379 
380 DWORD
381 WSAAPI
384  IN PTCATALOG_ENTRY *CatalogEntry)
385 {
387  PLIST_ENTRY NextEntry;
389 
390  /* Assume failure */
391  *CatalogEntry = NULL;
392 
393  /* Lock the catalog */
394  WsTcLock();
395 
396  /* Match the Id with all the entries in the List */
397  NextEntry = Catalog->ProtocolList.Flink;
398  while (NextEntry != &Catalog->ProtocolList)
399  {
400  /* Get the Current Entry */
401  Entry = CONTAINING_RECORD(NextEntry, TCATALOG_ENTRY, CatalogLink);
402  NextEntry = NextEntry->Flink;
403 
404  /* Check if this is the Catalog Entry ID we want */
405  if (Entry->ProtocolInfo.iAddressFamily == AddressFamily)
406  {
407  /* Check if it doesn't already have a provider */
408  if (!Entry->Provider)
409  {
410  /* Match, load the Provider */
411  ErrorCode = WsTcLoadProvider(Catalog, Entry);
412 
413  /* Make sure this didn't fail */
414  if (ErrorCode != ERROR_SUCCESS) break;
415  }
416 
417  /* Reference the entry and return it */
418  InterlockedIncrement(&Entry->RefCount);
419  *CatalogEntry = Entry;
421  break;
422  }
423  }
424 
425  /* Release the catalog */
426  WsTcUnlock();
427 
428  /* Return */
429  return ErrorCode;
430 }
431 
432 DWORD
433 WSAAPI
436  IN PTCATALOG_ENTRY *CatalogEntry)
437 {
439  PLIST_ENTRY NextEntry;
441 
442  /* Lock the catalog */
443  WsTcLock();
444 
445  /* Match the Id with all the entries in the List */
446  NextEntry = Catalog->ProtocolList.Flink;
447  while (NextEntry != &Catalog->ProtocolList)
448  {
449  /* Get the Current Entry */
450  Entry = CONTAINING_RECORD(NextEntry, TCATALOG_ENTRY, CatalogLink);
451  NextEntry = NextEntry->Flink;
452 
453  /* Check if this is the Catalog Entry ID we want */
454  if (Entry->ProtocolInfo.dwCatalogEntryId == CatalogEntryId)
455  {
456  /* Check if it doesn't already have a provider */
457  if (!Entry->Provider)
458  {
459  /* Match, load the Provider */
460  WsTcLoadProvider(Catalog, Entry);
461  }
462 
463  /* Reference the entry and return it */
464  InterlockedIncrement(&Entry->RefCount);
465  *CatalogEntry = Entry;
467  break;
468  }
469  }
470 
471  /* Release the catalog */
472  WsTcUnlock();
473 
474  /* Return */
475  return ErrorCode;
476 }
477 
478 DWORD
479 WSAAPI
481  IN INT af,
482  IN INT type,
483  IN INT protocol,
484  IN DWORD StartId,
485  IN PTCATALOG_ENTRY *CatalogEntry)
486 {
488  PLIST_ENTRY NextEntry;
490  DPRINT("WsTcGetEntryFromTriplet: %lx, %lx, %lx, %lx\n", af, type, protocol, StartId);
491 
492  /* Assume failure */
493  *CatalogEntry = NULL;
494 
495  /* Lock the catalog */
496  WsTcLock();
497 
498  NextEntry = Catalog->ProtocolList.Flink;
499 
500  /* Check if we are starting past 0 */
501  if (StartId)
502  {
503  /* Loop the list */
504  while (NextEntry != &Catalog->ProtocolList)
505  {
506  /* Get the Current Entry */
507  Entry = CONTAINING_RECORD(NextEntry, TCATALOG_ENTRY, CatalogLink);
508  NextEntry = NextEntry->Flink;
509 
510  /* Check if this is the ID where we are starting */
511  if (Entry->ProtocolInfo.dwCatalogEntryId == StartId) break;
512  }
513  }
514 
515  /* Match the Id with all the entries in the List */
516  while (NextEntry != &Catalog->ProtocolList)
517  {
518  /* Get the Current Entry */
519  Entry = CONTAINING_RECORD(NextEntry, TCATALOG_ENTRY, CatalogLink);
520  NextEntry = NextEntry->Flink;
521 
522  /* Check if Address Family Matches or if it's wildcard */
523  if ((Entry->ProtocolInfo.iAddressFamily == af) || (af == AF_UNSPEC))
524  {
525  /* Check if Socket Type Matches or if it's wildcard */
526  if ((Entry->ProtocolInfo.iSocketType == type) || (type == 0))
527  {
528  /* Check if Protocol is In Range or if it's wildcard */
529  if (((Entry->ProtocolInfo.iProtocol <= protocol) &&
530  ((Entry->ProtocolInfo.iProtocol +
531  Entry->ProtocolInfo.iProtocolMaxOffset) >= protocol)) ||
532  (protocol == 0))
533  {
534  /* Check if it doesn't already have a provider */
535  if (!Entry->Provider)
536  {
537  /* Match, load the Provider */
538  ErrorCode = WsTcLoadProvider(Catalog, Entry);
539 
540  /* Make sure this didn't fail */
541  if (ErrorCode != ERROR_SUCCESS) break;
542  }
543 
544  /* Reference the entry and return it */
545  InterlockedIncrement(&Entry->RefCount);
546  *CatalogEntry = Entry;
548  break;
549  }
550  else
551  {
553  }
554  }
555  else
556  {
558  }
559  }
560  else
561  {
563  }
564  }
565 
566  /* Release the catalog */
567  WsTcUnlock();
568 
569  /* Return */
570  return ErrorCode;
571 }
572 
574 WSAAPI
576  IN LPGUID ProviderId)
577 {
580  PTCATALOG_ENTRY CatalogEntry;
581 
582  /* Loop the provider list */
583  Entry = Catalog->ProtocolList.Flink;
584  while (Entry != &Catalog->ProtocolList)
585  {
586  /* Get the entry */
587  CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
588 
589  /* Move to the next one, get the provider */
590  Entry = Entry->Flink;
591  Provider = CatalogEntry->Provider;
592 
593  /* Check for a match */
594  if (Provider &&
595  IsEqualGUID(&CatalogEntry->ProtocolInfo.ProviderId, ProviderId))
596  {
597  /* Found a match */
598  return Provider;
599  }
600  }
601 
602  /* No match here */
603  return NULL;
604 }
605 
606 DWORD
607 WSAAPI
609  IN PTCATALOG_ENTRY CatalogEntry)
610 {
613  DPRINT("WsTcLoadProvider: %p, %p\n", Catalog, CatalogEntry);
614 
615  /* Lock the catalog */
616  WsTcLock();
617 
618  /* Check if we have a provider already */
619  if (!CatalogEntry->Provider)
620  {
621  /* Try to find another instance */
622  Provider = WsTcFindProvider(Catalog,
623  &CatalogEntry->ProtocolInfo.ProviderId);
624 
625  /* Check if we found one now */
626  if (Provider)
627  {
628  /* Set this one as the provider */
629  WsTcEntrySetProvider(CatalogEntry, Provider);
631  }
632  else
633  {
634  /* Nothing found, Allocate a provider */
635  if ((Provider = WsTpAllocate()))
636  {
637  /* Initialize it */
639  CatalogEntry->DllPath,
640  &CatalogEntry->ProtocolInfo);
641 
642  /* Ensure success */
643  if (ErrorCode == ERROR_SUCCESS)
644  {
645  /* Set the provider */
646  WsTcEntrySetProvider(CatalogEntry, Provider);
647  }
648 
649  /* Dereference it */
651  }
652  else
653  {
654  /* No memory */
656  }
657  }
658  }
659 
660  /* Release the lock */
661  WsTcUnlock();
662  return ErrorCode;
663 }
664 
665 VOID
666 WSAAPI
669 {
670  LIST_ENTRY TempList;
671  PTCATALOG_ENTRY CatalogEntry, OldCatalogEntry;
673 
674  /* First move from our list to the old one */
675  InsertHeadList(&Catalog->ProtocolList, &TempList);
676  RemoveEntryList(&Catalog->ProtocolList);
677  InitializeListHead(&Catalog->ProtocolList);
678 
679  /* Loop every item in the list */
680  while (!IsListEmpty(List))
681  {
682  /* Get the catalog entry */
684  CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
685 
686  /* Check if this item is already in our list */
687  Entry = TempList.Flink;
688  while (Entry != &TempList)
689  {
690  /* Get the catalog entry */
691  OldCatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
692  Entry = Entry->Flink;
693 
694  /* Check if they match */
695  if (CatalogEntry->ProtocolInfo.dwCatalogEntryId ==
696  OldCatalogEntry->ProtocolInfo.dwCatalogEntryId)
697  {
698  /* We have a match, use the old item instead */
699  WsTcEntryDereference(CatalogEntry);
700  CatalogEntry = OldCatalogEntry;
701  RemoveEntryList(&CatalogEntry->CatalogLink);
702 
703  /* Decrease the number of protocols we have */
704  Catalog->ItemCount--;
705  break;
706  }
707  }
708 
709  /* Add this item */
710  InsertTailList(&Catalog->ProtocolList, &CatalogEntry->CatalogLink);
711  Catalog->ItemCount++;
712  }
713 
714  /* If there's anything left in the temporary list */
715  while (!IsListEmpty(&TempList))
716  {
717  /* Get the entry */
718  Entry = RemoveHeadList(&TempList);
719  CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
720 
721  /* Remove it */
722  Catalog->ItemCount--;
723  WsTcEntryDereference(CatalogEntry);
724  }
725 }
726 
727 VOID
728 WSAAPI
731  IN PVOID Context)
732 {
734  PTCATALOG_ENTRY CatalogEntry;
735  BOOL GoOn = TRUE;
736 
737  /* Lock the catalog */
738  WsTcLock();
739 
740  /* Loop the entries */
741  Entry = Catalog->ProtocolList.Flink;
742  while (GoOn && (Entry != &Catalog->ProtocolList))
743  {
744  /* Get the entry */
745  CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
746 
747  /* Move to the next one and call the callback */
748  Entry = Entry->Flink;
749  GoOn = Callback(Context, CatalogEntry);
750  }
751 
752  /* Release lock */
753  WsTcUnlock();
754 }
755 
756 DWORD
757 WSAAPI
759  IN SOCKET Handle)
760 {
762  IN SOCKET NewHandle;
763  INT Error;
764  INT OptionLength;
766  WSAPROTOCOL_INFOW ProtocolInfo;
767  DWORD UniqueId;
768  INT ErrorCode;
769  PTCATALOG_ENTRY CatalogEntry;
770 
771  /* Get the catalog lock */
772  WsTcLock();
773 
774  /* Loop as long as the catalog changes */
775 CatalogChanged:
776 
777  /* Loop every provider */
778  Entry = Catalog->ProtocolList.Flink;
779  while (Entry != &Catalog->ProtocolList)
780  {
781  /* Get the catalog entry */
782  CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
783 
784  /* Move to the next entry */
785  Entry = Entry->Flink;
786 
787  /* Skip it if it doesn't support IFS */
788  if (!(CatalogEntry->ProtocolInfo.dwServiceFlags1 & XP1_IFS_HANDLES)) continue;
789 
790  /* Check if we need to load it */
791  if (!(Provider = CatalogEntry->Provider))
792  {
793  /* Load it */
794  ErrorCode = WsTcLoadProvider(Catalog, CatalogEntry);
795 
796  /* Skip it if we failed to load it */
797  if (ErrorCode != ERROR_SUCCESS) continue;
798 
799  /* Get the provider again */
800  Provider = CatalogEntry->Provider;
801  }
802 
803  /* Reference the entry and get our unique id */
804  InterlockedIncrement(&CatalogEntry->RefCount);
805  UniqueId = Catalog->UniqueId;
806 
807  /* Release the lock now */
808  WsTcUnlock();
809 
810  /* Get the catalog entry ID */
811  OptionLength = sizeof(ProtocolInfo);
812  ErrorCode = Provider->Service.lpWSPGetSockOpt(Handle,
813  SOL_SOCKET,
815  (PCHAR)&ProtocolInfo,
816  &OptionLength,
817  &Error);
818 
819  /* Dereference the entry and check the result */
820  WsTcEntryDereference(CatalogEntry);
821  if (ErrorCode != ERROR_SUCCESS)
822  {
823  /* Lock and make sure this provider is still valid */
824  WsTcLock();
825  if (UniqueId == Catalog->UniqueId) continue;
826 
827  /* It changed! We need to start over */
828  goto CatalogChanged;
829  }
830 
831  /* Now get the IFS handle */
832  NewHandle = WPUModifyIFSHandle(ProtocolInfo.dwCatalogEntryId,
833  Handle,
834  &Error);
835 
836  /* Check if the socket is invalid */
837  if (NewHandle == INVALID_SOCKET) return WSAENOTSOCK;
838 
839  /* We succeeded, get out of here */
840  return ERROR_SUCCESS;
841  }
842 
843  /* Unrecognized socket if we get here: note, we still have the lock */
844  WsTcUnlock();
845  return WSAENOTSOCK;
846 }
847 
848 VOID
849 WSAAPI
852 {
853  /* Remove the entry from the list */
854  RemoveEntryList(&Entry->CatalogLink);
855 
856  /* Decrease our count */
857  Catalog->ItemCount--;
858 }
859 
860 VOID
861 WSAAPI
863 {
865  PTCATALOG_ENTRY CatalogEntry;
866 
867  /* Check if we're initialized */
868  if (!Catalog->ProtocolList.Flink) return;
869 
870  /* Acquire lock */
871  WsTcLock();
872 
873  /* Loop every entry */
874  Entry = Catalog->ProtocolList.Flink;
875  while (Entry != &Catalog->ProtocolList)
876  {
877  /* Get this entry */
878  CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
879 
880  /* Remove it and dereference it */
881  WsTcRemoveCatalogItem(Catalog, CatalogEntry);
882  WsTcEntryDereference(CatalogEntry);
883 
884  /* Move to the next entry */
885  Entry = Catalog->ProtocolList.Flink;
886  }
887 
888  /* Check if the catalog key is opened */
889  if (Catalog->CatalogKey)
890  {
891  /* Close it */
892  RegCloseKey(Catalog->CatalogKey);
893  Catalog->CatalogKey = NULL;
894  }
895 
896  /* Release and delete the lock */
897  WsTcUnlock();
898  DeleteCriticalSection(&Catalog->Lock);
899 
900  /* Delete the object */
901  HeapFree(WsSockHeap, 0, Catalog);
902 }
DWORD WSAAPI WsTcGetEntryFromTriplet(IN PTCATALOG Catalog, IN INT af, IN INT type, IN INT protocol, IN DWORD StartId, IN PTCATALOG_ENTRY *CatalogEntry)
Definition: dcatalog.c:480
#define CreateEvent
Definition: winbase.h:3565
#define RegQueryValueEx
Definition: winreg.h:524
#define WSAENOTSOCK
Definition: winerror.h:1951
signed char * PCHAR
Definition: retypes.h:7
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define IN
Definition: typedefs.h:38
IN PCO_ADDRESS_FAMILY AddressFamily
Definition: ndis.h:1906
#define TRUE
Definition: types.h:120
VOID WSAAPI WsTpDereference(IN PTPROVIDER Provider)
Definition: dprovide.c:143
#define CloseHandle
Definition: compat.h:398
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
Definition: ws2_32p.h:85
DWORD CatalogEntryId
Definition: dllmain.c:21
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WSAAPI WsTcOpen(IN PTCATALOG Catalog, IN HKEY ParentKey)
Definition: dcatalog.c:38
struct _Entry Entry
Definition: kefuncs.h:640
#define WsTcUnlock()
Definition: dcatalog.c:19
DWORD WSAAPI WsTcGetEntryFromCatalogEntryId(IN PTCATALOG Catalog, IN DWORD CatalogEntryId, IN PTCATALOG_ENTRY *CatalogEntry)
Definition: dcatalog.c:434
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define WSAEINVAL
Definition: winerror.h:1946
char CHAR
Definition: xmlstorage.h:175
#define WSAEAFNOSUPPORT
Definition: winerror.h:1960
SOCKET WSPAPI WPUModifyIFSHandle(IN DWORD dwCatalogEntryId, IN SOCKET ProposedHandle, OUT LPINT lpErrno)
Definition: socklife.c:201
#define SO_PROTOCOL_INFOW
Definition: winsock2.h:249
LONG RefCount
Definition: ws2_32p.h:88
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
PTPROVIDER WSAAPI WsTpAllocate(VOID)
Definition: dprovide.c:20
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define SOL_SOCKET
Definition: winsock.h:398
#define InsertTailList(ListHead, Entry)
PTPROVIDER Provider
Definition: ws2_32p.h:89
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VOID WSAAPI WsTcRemoveCatalogItem(IN PTCATALOG Catalog, IN PTCATALOG_ENTRY Entry)
Definition: dcatalog.c:850
DWORD WSAAPI WsTcLoadProvider(IN PTCATALOG Catalog, IN PTCATALOG_ENTRY CatalogEntry)
Definition: dcatalog.c:608
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define WSAEPROTONOSUPPORT
Definition: winerror.h:1956
VOID WSAAPI WsTcEntrySetProvider(IN PTCATALOG_ENTRY CatalogEntry, IN PTPROVIDER Provider)
Definition: dcatitem.c:121
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
DWORD WSAAPI WsTcFindIfsProviderForSocket(IN PTCATALOG Catalog, IN SOCKET Handle)
Definition: dcatalog.c:758
DWORD dwCatalogEntryId
Definition: winsock2.h:686
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WSAAPI WsTpInitialize(IN PTPROVIDER Provider, IN LPSTR DllName, LPWSAPROTOCOL_INFOW ProtocolInfo)
INT WSAAPI WsSetupCatalogProtection(IN HKEY CatalogKey, IN HANDLE CatalogEvent, OUT LPDWORD UniqueId)
Definition: wsautil.c:142
PTPROVIDER WSAAPI WsTcFindProvider(IN PTCATALOG Catalog, IN LPGUID ProviderId)
Definition: dcatalog.c:575
unsigned char BOOLEAN
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define AF_UNSPEC
Definition: winsock.h:344
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID WSAAPI WsTcEnumerateCatalogItems(IN PTCATALOG Catalog, IN PTCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
Definition: dcatalog.c:729
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_In_ HANDLE Handle
Definition: extypes.h:390
VOID WSAAPI WsTcEntryDereference(IN PTCATALOG_ENTRY CatalogEntry)
Definition: dcatitem.c:51
DWORD WSAAPI WsTcRefreshFromRegistry(IN PTCATALOG Catalog, IN HANDLE CatalogEvent)
Definition: dcatalog.c:225
PTCATALOG_ENTRY WSAAPI WsTcEntryAllocate(VOID)
Definition: dcatitem.c:17
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define INVALID_SOCKET
Definition: winsock.h:332
LIST_ENTRY List
Definition: psmgr.c:57
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define XP1_IFS_HANDLES
Definition: winsock2.h:453
#define WsTcLock()
Definition: dcatalog.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
DWORD WSAAPI WsTcEntryInitializeFromRegistry(IN PTCATALOG_ENTRY CatalogEntry, IN HKEY, unsigned long)
#define WSAESOCKTNOSUPPORT
Definition: winerror.h:1957
LIST_ENTRY CatalogLink
Definition: ws2_32p.h:87
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:593
WSAPROTOCOL_INFOW ProtocolInfo
Definition: ws2_32p.h:91
BOOL WSAAPI WsCheckCatalogState(IN HANDLE Event)
Definition: wsautil.c:75
VOID WSAAPI WsTcDelete(IN PTCATALOG Catalog)
Definition: dcatalog.c:862
Definition: typedefs.h:117
DWORD WSAAPI WsTcInitializeFromRegistry(IN PTCATALOG Catalog, IN HKEY ParentKey, IN HANDLE CatalogEvent)
Definition: dcatalog.c:206
DWORD WSAAPI WsTcGetEntryFromAf(IN PTCATALOG Catalog, IN INT AddressFamily, IN PTCATALOG_ENTRY *CatalogEntry)
Definition: dcatalog.c:382
#define WSASYSCALLFAILURE
Definition: winerror.h:1994
#define RegOpenKeyEx
Definition: winreg.h:520
#define InterlockedIncrement
Definition: armddk.h:53
DWORD dwServiceFlags1
Definition: winsock2.h:680
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define WSAAPI
Definition: winsock2.h:584
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4021
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
UINT_PTR SOCKET
Definition: winsock.h:47
VOID WSAAPI WsTcUpdateProtocolList(IN PTCATALOG Catalog, IN PLIST_ENTRY List)
Definition: dcatalog.c:667
#define REG_DWORD
Definition: sdbapi.c:596
LPFNPSPCALLBACK Callback
Definition: desk.c:111
HANDLE WsSockHeap
Definition: dllmain.c:21
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB _In_ PDCB _In_ PDIRENT _In_ ULONG _In_ ULONG _In_ PUNICODE_STRING _In_ PACCESS_MASK _In_ USHORT _In_ ULONG CreateDisposition
Definition: create.c:4157
#define HeapFree(x, y, z)
Definition: compat.h:394
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
base of all file and directory entries
Definition: entries.h:82
PTCATALOG WSAAPI WsTcAllocate(VOID)
Definition: dcatalog.c:25
BOOL(WINAPI * PTCATALOG_ENUMERATE_PROC)(IN PVOID Context, IN PTCATALOG_ENTRY Entry)
Definition: ws2_32p.h:259