ReactOS 0.4.15-dev-8348-gc1b9bb5
dcatalog.c File Reference
#include <ws2_32.h>
#include <debug.h>
Include dependency graph for dcatalog.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define WsTcLock()   EnterCriticalSection(&Catalog->Lock)
 
#define WsTcUnlock()   LeaveCriticalSection(&Catalog->Lock)
 

Functions

PTCATALOG WSAAPI WsTcAllocate (VOID)
 
BOOL WSAAPI WsTcOpen (IN PTCATALOG Catalog, IN HKEY ParentKey)
 
DWORD WSAAPI WsTcInitializeFromRegistry (IN PTCATALOG Catalog, IN HKEY ParentKey, IN HANDLE CatalogEvent)
 
DWORD WSAAPI WsTcRefreshFromRegistry (IN PTCATALOG Catalog, IN HANDLE CatalogEvent)
 
DWORD WSAAPI WsTcGetEntryFromAf (IN PTCATALOG Catalog, IN INT AddressFamily, IN PTCATALOG_ENTRY *CatalogEntry)
 
DWORD WSAAPI WsTcGetEntryFromCatalogEntryId (IN PTCATALOG Catalog, IN DWORD CatalogEntryId, IN PTCATALOG_ENTRY *CatalogEntry)
 
DWORD WSAAPI WsTcGetEntryFromTriplet (IN PTCATALOG Catalog, IN INT af, IN INT type, IN INT protocol, IN DWORD StartId, IN PTCATALOG_ENTRY *CatalogEntry)
 
PTPROVIDER WSAAPI WsTcFindProvider (IN PTCATALOG Catalog, IN LPGUID ProviderId)
 
DWORD WSAAPI WsTcLoadProvider (IN PTCATALOG Catalog, IN PTCATALOG_ENTRY CatalogEntry)
 
VOID WSAAPI WsTcUpdateProtocolList (IN PTCATALOG Catalog, IN PLIST_ENTRY List)
 
VOID WSAAPI WsTcEnumerateCatalogItems (IN PTCATALOG Catalog, IN PTCATALOG_ENUMERATE_PROC Callback, IN PVOID Context)
 
DWORD WSAAPI WsTcFindIfsProviderForSocket (IN PTCATALOG Catalog, IN SOCKET Handle)
 
VOID WSAAPI WsTcRemoveCatalogItem (IN PTCATALOG Catalog, IN PTCATALOG_ENTRY Entry)
 
VOID WSAAPI WsTcDelete (IN PTCATALOG Catalog)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file dcatalog.c.

◆ WsTcLock

#define WsTcLock ( )    EnterCriticalSection(&Catalog->Lock)

Definition at line 18 of file dcatalog.c.

◆ WsTcUnlock

#define WsTcUnlock ( )    LeaveCriticalSection(&Catalog->Lock)

Definition at line 19 of file dcatalog.c.

Function Documentation

◆ WsTcAllocate()

PTCATALOG WSAAPI WsTcAllocate ( VOID  )

Definition at line 25 of file dcatalog.c.

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}
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HANDLE WsSockHeap
Definition: dllmain.c:21

Referenced by OpenInitializedCatalog(), and WsProcInitialize().

◆ WsTcDelete()

VOID WSAAPI WsTcDelete ( IN PTCATALOG  Catalog)

Definition at line 883 of file dcatalog.c.

884{
886 PTCATALOG_ENTRY CatalogEntry;
887
888 /* Check if we're initialized */
889 if (!Catalog->ProtocolList.Flink) return;
890
891 /* Acquire lock */
892 WsTcLock();
893
894 /* Loop every entry */
895 Entry = Catalog->ProtocolList.Flink;
896 while (Entry != &Catalog->ProtocolList)
897 {
898 /* Get this entry */
899 CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
900
901 /* Remove it and dereference it */
902 WsTcRemoveCatalogItem(Catalog, CatalogEntry);
903 WsTcEntryDereference(CatalogEntry);
904
905 /* Move to the next entry */
906 Entry = Catalog->ProtocolList.Flink;
907 }
908
909 /* Check if the catalog key is opened */
910 if (Catalog->CatalogKey)
911 {
912 /* Close it */
913 RegCloseKey(Catalog->CatalogKey);
914 Catalog->CatalogKey = NULL;
915 }
916
917 /* Release and delete the lock */
918 WsTcUnlock();
919 DeleteCriticalSection(&Catalog->Lock);
920
921 /* Delete the object */
922 HeapFree(WsSockHeap, 0, Catalog);
923}
#define RegCloseKey(hKey)
Definition: registry.h:49
VOID WSAAPI WsTcRemoveCatalogItem(IN PTCATALOG Catalog, IN PTCATALOG_ENTRY Entry)
Definition: dcatalog.c:871
#define WsTcUnlock()
Definition: dcatalog.c:19
#define WsTcLock()
Definition: dcatalog.c:18
#define NULL
Definition: types.h:112
#define HeapFree(x, y, z)
Definition: compat.h:735
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
Definition: ws2_32p.h:86
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
VOID WSAAPI WsTcEntryDereference(IN PTCATALOG_ENTRY CatalogEntry)
Definition: dcatitem.c:51

Referenced by WSCEnumProtocols(), and WsProcDelete().

◆ WsTcEnumerateCatalogItems()

VOID WSAAPI WsTcEnumerateCatalogItems ( IN PTCATALOG  Catalog,
IN PTCATALOG_ENUMERATE_PROC  Callback,
IN PVOID  Context 
)

Definition at line 750 of file dcatalog.c.

753{
755 PTCATALOG_ENTRY CatalogEntry;
756 BOOL GoOn = TRUE;
757
758 /* Lock the catalog */
759 WsTcLock();
760
761 /* Loop the entries */
762 Entry = Catalog->ProtocolList.Flink;
763 while (GoOn && (Entry != &Catalog->ProtocolList))
764 {
765 /* Get the entry */
766 CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
767
768 /* Move to the next one and call the callback */
769 Entry = Entry->Flink;
770 GoOn = Callback(Context, CatalogEntry);
771 }
772
773 /* Release lock */
774 WsTcUnlock();
775}
#define TRUE
Definition: types.h:120
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458

Referenced by WSCEnumProtocols(), and WsProcDelete().

◆ WsTcFindIfsProviderForSocket()

DWORD WSAAPI WsTcFindIfsProviderForSocket ( IN PTCATALOG  Catalog,
IN SOCKET  Handle 
)

Definition at line 779 of file dcatalog.c.

781{
783 IN SOCKET NewHandle;
784 INT Error;
785 INT OptionLength;
787 WSAPROTOCOL_INFOW ProtocolInfo;
788 DWORD UniqueId;
790 PTCATALOG_ENTRY CatalogEntry;
791
792 /* Get the catalog lock */
793 WsTcLock();
794
795 /* Loop as long as the catalog changes */
796CatalogChanged:
797
798 /* Loop every provider */
799 Entry = Catalog->ProtocolList.Flink;
800 while (Entry != &Catalog->ProtocolList)
801 {
802 /* Get the catalog entry */
803 CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
804
805 /* Move to the next entry */
806 Entry = Entry->Flink;
807
808 /* Skip it if it doesn't support IFS */
809 if (!(CatalogEntry->ProtocolInfo.dwServiceFlags1 & XP1_IFS_HANDLES)) continue;
810
811 /* Check if we need to load it */
812 if (!(Provider = CatalogEntry->Provider))
813 {
814 /* Load it */
815 ErrorCode = WsTcLoadProvider(Catalog, CatalogEntry);
816
817 /* Skip it if we failed to load it */
818 if (ErrorCode != ERROR_SUCCESS) continue;
819
820 /* Get the provider again */
821 Provider = CatalogEntry->Provider;
822 }
823
824 /* Reference the entry and get our unique id */
825 InterlockedIncrement(&CatalogEntry->RefCount);
826 UniqueId = Catalog->UniqueId;
827
828 /* Release the lock now */
829 WsTcUnlock();
830
831 /* Get the catalog entry ID */
832 OptionLength = sizeof(ProtocolInfo);
833 ErrorCode = Provider->Service.lpWSPGetSockOpt(Handle,
836 (PCHAR)&ProtocolInfo,
837 &OptionLength,
838 &Error);
839
840 /* Dereference the entry and check the result */
841 WsTcEntryDereference(CatalogEntry);
843 {
844 /* Lock and make sure this provider is still valid */
845 WsTcLock();
846 if (UniqueId == Catalog->UniqueId) continue;
847
848 /* It changed! We need to start over */
849 goto CatalogChanged;
850 }
851
852 /* Now get the IFS handle */
853 NewHandle = WPUModifyIFSHandle(ProtocolInfo.dwCatalogEntryId,
854 Handle,
855 &Error);
856
857 /* Check if the socket is invalid */
858 if (NewHandle == INVALID_SOCKET) return WSAENOTSOCK;
859
860 /* We succeeded, get out of here */
861 return ERROR_SUCCESS;
862 }
863
864 /* Unrecognized socket if we get here: note, we still have the lock */
865 WsTcUnlock();
866 return WSAENOTSOCK;
867}
#define InterlockedIncrement
Definition: armddk.h:53
BOOL Error
Definition: chkdsk.c:66
DWORD WSAAPI WsTcLoadProvider(IN PTCATALOG Catalog, IN PTCATALOG_ENTRY CatalogEntry)
Definition: dcatalog.c:629
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG Handle
Definition: gdb_input.c:15
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
SOCKET WSPAPI WPUModifyIFSHandle(IN DWORD dwCatalogEntryId, IN SOCKET ProposedHandle, OUT LPINT lpErrno)
Definition: socklife.c:201
LONG RefCount
Definition: ws2_32p.h:88
PTPROVIDER Provider
Definition: ws2_32p.h:89
WSAPROTOCOL_INFOW ProtocolInfo
Definition: ws2_32p.h:91
DWORD dwCatalogEntryId
Definition: winsock2.h:686
DWORD dwServiceFlags1
Definition: winsock2.h:680
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
char * PCHAR
Definition: typedefs.h:51
#define WSAENOTSOCK
Definition: winerror.h:1951
#define XP1_IFS_HANDLES
Definition: winsock2.h:453
#define SO_PROTOCOL_INFOW
Definition: winsock2.h:249
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOL_SOCKET
Definition: winsock.h:398

◆ WsTcFindProvider()

PTPROVIDER WSAAPI WsTcFindProvider ( IN PTCATALOG  Catalog,
IN LPGUID  ProviderId 
)

Definition at line 596 of file dcatalog.c.

598{
601 PTCATALOG_ENTRY CatalogEntry;
602
603 /* Loop the provider list */
604 Entry = Catalog->ProtocolList.Flink;
605 while (Entry != &Catalog->ProtocolList)
606 {
607 /* Get the entry */
608 CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
609
610 /* Move to the next one, get the provider */
611 Entry = Entry->Flink;
612 Provider = CatalogEntry->Provider;
613
614 /* Check for a match */
615 if (Provider &&
616 IsEqualGUID(&CatalogEntry->ProtocolInfo.ProviderId, ProviderId))
617 {
618 /* Found a match */
619 return Provider;
620 }
621 }
622
623 /* No match here */
624 return NULL;
625}
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147

Referenced by WsTcLoadProvider().

◆ WsTcGetEntryFromAf()

DWORD WSAAPI WsTcGetEntryFromAf ( IN PTCATALOG  Catalog,
IN INT  AddressFamily,
IN PTCATALOG_ENTRY CatalogEntry 
)

Definition at line 403 of file dcatalog.c.

406{
408 PLIST_ENTRY NextEntry;
410
411 /* Assume failure */
412 *CatalogEntry = NULL;
413
414 /* Lock the catalog */
415 WsTcLock();
416
417 /* Match the Id with all the entries in the List */
418 NextEntry = Catalog->ProtocolList.Flink;
419 while (NextEntry != &Catalog->ProtocolList)
420 {
421 /* Get the Current Entry */
422 Entry = CONTAINING_RECORD(NextEntry, TCATALOG_ENTRY, CatalogLink);
423 NextEntry = NextEntry->Flink;
424
425 /* Check if this is the Catalog Entry ID we want */
426 if (Entry->ProtocolInfo.iAddressFamily == AddressFamily)
427 {
428 /* Check if it doesn't already have a provider */
429 if (!Entry->Provider)
430 {
431 /* Match, load the Provider */
432 ErrorCode = WsTcLoadProvider(Catalog, Entry);
433
434 /* Make sure this didn't fail */
435 if (ErrorCode != ERROR_SUCCESS) break;
436 }
437
438 /* Reference the entry and return it */
439 InterlockedIncrement(&Entry->RefCount);
440 *CatalogEntry = Entry;
442 break;
443 }
444 }
445
446 /* Release the catalog */
447 WsTcUnlock();
448
449 /* Return */
450 return ErrorCode;
451}
IN PCO_ADDRESS_FAMILY AddressFamily
Definition: ndis.h:1906
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define WSAEINVAL
Definition: winerror.h:1946

Referenced by WSAAddressToStringA(), WSAAddressToStringW(), WSAStringToAddressA(), and WSAStringToAddressW().

◆ WsTcGetEntryFromCatalogEntryId()

DWORD WSAAPI WsTcGetEntryFromCatalogEntryId ( IN PTCATALOG  Catalog,
IN DWORD  CatalogEntryId,
IN PTCATALOG_ENTRY CatalogEntry 
)

Definition at line 455 of file dcatalog.c.

458{
460 PLIST_ENTRY NextEntry;
462
463 /* Lock the catalog */
464 WsTcLock();
465
466 /* Match the Id with all the entries in the List */
467 NextEntry = Catalog->ProtocolList.Flink;
468 while (NextEntry != &Catalog->ProtocolList)
469 {
470 /* Get the Current Entry */
471 Entry = CONTAINING_RECORD(NextEntry, TCATALOG_ENTRY, CatalogLink);
472 NextEntry = NextEntry->Flink;
473
474 /* Check if this is the Catalog Entry ID we want */
475 if (Entry->ProtocolInfo.dwCatalogEntryId == CatalogEntryId)
476 {
477 /* Check if it doesn't already have a provider */
478 if (!Entry->Provider)
479 {
480 /* Match, load the Provider */
481 WsTcLoadProvider(Catalog, Entry);
482 }
483
484 /* Reference the entry and return it */
485 InterlockedIncrement(&Entry->RefCount);
486 *CatalogEntry = Entry;
488 break;
489 }
490 }
491
492 /* Release the catalog */
493 WsTcUnlock();
494
495 /* Return */
496 return ErrorCode;
497}
DWORD CatalogEntryId
Definition: dllmain.c:21

Referenced by WPUModifyIFSHandle(), WPUQueryBlockingCallback(), WSAAddressToStringA(), WSAAddressToStringW(), WSASocketW(), WSAStringToAddressA(), and WSAStringToAddressW().

◆ WsTcGetEntryFromTriplet()

DWORD WSAAPI WsTcGetEntryFromTriplet ( IN PTCATALOG  Catalog,
IN INT  af,
IN INT  type,
IN INT  protocol,
IN DWORD  StartId,
IN PTCATALOG_ENTRY CatalogEntry 
)

Definition at line 501 of file dcatalog.c.

507{
509 PLIST_ENTRY NextEntry;
511 DPRINT("WsTcGetEntryFromTriplet: %lx, %lx, %lx, %lx\n", af, type, protocol, StartId);
512
513 /* Assume failure */
514 *CatalogEntry = NULL;
515
516 /* Lock the catalog */
517 WsTcLock();
518
519 NextEntry = Catalog->ProtocolList.Flink;
520
521 /* Check if we are starting past 0 */
522 if (StartId)
523 {
524 /* Loop the list */
525 while (NextEntry != &Catalog->ProtocolList)
526 {
527 /* Get the Current Entry */
528 Entry = CONTAINING_RECORD(NextEntry, TCATALOG_ENTRY, CatalogLink);
529 NextEntry = NextEntry->Flink;
530
531 /* Check if this is the ID where we are starting */
532 if (Entry->ProtocolInfo.dwCatalogEntryId == StartId) break;
533 }
534 }
535
536 /* Match the Id with all the entries in the List */
537 while (NextEntry != &Catalog->ProtocolList)
538 {
539 /* Get the Current Entry */
540 Entry = CONTAINING_RECORD(NextEntry, TCATALOG_ENTRY, CatalogLink);
541 NextEntry = NextEntry->Flink;
542
543 /* Check if Address Family Matches or if it's wildcard */
544 if ((Entry->ProtocolInfo.iAddressFamily == af) || (af == AF_UNSPEC))
545 {
546 /* Check if Socket Type Matches or if it's wildcard */
547 if ((Entry->ProtocolInfo.iSocketType == type) || (type == 0))
548 {
549 /* Check if Protocol is In Range or if it's wildcard */
550 if (((Entry->ProtocolInfo.iProtocol <= protocol) &&
551 ((Entry->ProtocolInfo.iProtocol +
552 Entry->ProtocolInfo.iProtocolMaxOffset) >= protocol)) ||
553 (protocol == 0))
554 {
555 /* Check if it doesn't already have a provider */
556 if (!Entry->Provider)
557 {
558 /* Match, load the Provider */
559 ErrorCode = WsTcLoadProvider(Catalog, Entry);
560
561 /* Make sure this didn't fail */
562 if (ErrorCode != ERROR_SUCCESS) break;
563 }
564
565 /* Reference the entry and return it */
566 InterlockedIncrement(&Entry->RefCount);
567 *CatalogEntry = Entry;
569 break;
570 }
571 else
572 {
574 }
575 }
576 else
577 {
579 }
580 }
581 else
582 {
584 }
585 }
586
587 /* Release the catalog */
588 WsTcUnlock();
589
590 /* Return */
591 return ErrorCode;
592}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define DPRINT
Definition: sndvol32.h:73
#define WSAEPROTONOSUPPORT
Definition: winerror.h:1956
#define WSAESOCKTNOSUPPORT
Definition: winerror.h:1957
#define WSAEAFNOSUPPORT
Definition: winerror.h:1960
#define AF_UNSPEC
Definition: winsock.h:344

Referenced by WSASocketW().

◆ WsTcInitializeFromRegistry()

DWORD WSAAPI WsTcInitializeFromRegistry ( IN PTCATALOG  Catalog,
IN HKEY  ParentKey,
IN HANDLE  CatalogEvent 
)

Definition at line 227 of file dcatalog.c.

230{
232
233 /* Open the catalog */
234 if (WsTcOpen(Catalog, ParentKey))
235 {
236 /* Refresh it */
237 ErrorCode = WsTcRefreshFromRegistry(Catalog, CatalogEvent);
238 }
239
240 /* Return the status */
241 return ErrorCode;
242}
DWORD WSAAPI WsTcRefreshFromRegistry(IN PTCATALOG Catalog, IN HANDLE CatalogEvent)
Definition: dcatalog.c:246
BOOL WSAAPI WsTcOpen(IN PTCATALOG Catalog, IN HKEY ParentKey)
Definition: dcatalog.c:38
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
#define WSASYSCALLFAILURE
Definition: winerror.h:1994

◆ WsTcLoadProvider()

DWORD WSAAPI WsTcLoadProvider ( IN PTCATALOG  Catalog,
IN PTCATALOG_ENTRY  CatalogEntry 
)

Definition at line 629 of file dcatalog.c.

631{
634 DPRINT("WsTcLoadProvider: %p, %p\n", Catalog, CatalogEntry);
635
636 /* Lock the catalog */
637 WsTcLock();
638
639 /* Check if we have a provider already */
640 if (!CatalogEntry->Provider)
641 {
642 /* Try to find another instance */
643 Provider = WsTcFindProvider(Catalog,
644 &CatalogEntry->ProtocolInfo.ProviderId);
645
646 /* Check if we found one now */
647 if (Provider)
648 {
649 /* Set this one as the provider */
650 WsTcEntrySetProvider(CatalogEntry, Provider);
652 }
653 else
654 {
655 /* Nothing found, Allocate a provider */
656 if ((Provider = WsTpAllocate()))
657 {
658 /* Initialize it */
660 CatalogEntry->DllPath,
661 &CatalogEntry->ProtocolInfo);
662
663 /* Ensure success */
665 {
666 /* Set the provider */
667 WsTcEntrySetProvider(CatalogEntry, Provider);
668 }
669
670 /* Dereference it */
672 }
673 else
674 {
675 /* No memory */
677 }
678 }
679 }
680
681 /* Release the lock */
682 WsTcUnlock();
683 return ErrorCode;
684}
PTPROVIDER WSAAPI WsTcFindProvider(IN PTCATALOG Catalog, IN LPGUID ProviderId)
Definition: dcatalog.c:596
#define WSA_NOT_ENOUGH_MEMORY
Definition: winsock2.h:620
VOID WSAAPI WsTcEntrySetProvider(IN PTCATALOG_ENTRY CatalogEntry, IN PTPROVIDER Provider)
Definition: dcatitem.c:121
VOID WSAAPI WsTpDereference(IN PTPROVIDER Provider)
Definition: dprovide.c:143
PTPROVIDER WSAAPI WsTpAllocate(VOID)
Definition: dprovide.c:20
DWORD WSAAPI WsTpInitialize(IN PTPROVIDER Provider, IN LPSTR DllName, LPWSAPROTOCOL_INFOW ProtocolInfo)

Referenced by WsTcFindIfsProviderForSocket(), WsTcGetEntryFromAf(), WsTcGetEntryFromCatalogEntryId(), and WsTcGetEntryFromTriplet().

◆ WsTcOpen()

BOOL WSAAPI WsTcOpen ( IN PTCATALOG  Catalog,
IN HKEY  ParentKey 
)

Definition at line 38 of file dcatalog.c.

40{
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 */
57 "Current_Protocol_Catalog",
58 0,
59 &RegType,
60 NULL,
61 &RegSize);
63 {
64 static const CHAR DefaultCatalogName[] = "Protocol_Catalog9";
65 RegSize = sizeof(DefaultCatalogName);
66 CatalogKeyName = HeapAlloc(WsSockHeap, 0, RegSize);
67 memcpy(CatalogKeyName, DefaultCatalogName, RegSize);
68 }
69 else
70 {
72 {
73 DPRINT1("Failed to get protocol catalog name: %d.\n", ErrorCode);
74 return FALSE;
75 }
76
77 if (RegType != REG_SZ)
78 {
79 DPRINT1("Protocol catalog name is not a string (Type %d).\n", RegType);
80 return FALSE;
81 }
82
83 CatalogKeyName = HeapAlloc(WsSockHeap, 0, RegSize);
84
85 /* Read the catalog name */
87 "Current_Protocol_Catalog",
88 0,
89 &RegType,
90 (LPBYTE)CatalogKeyName,
91 &RegSize);
92
93 /* Open the Catalog Key */
95 CatalogKeyName,
96 0,
98 &CatalogKey);
99 }
100
101 /* If we didn't find the key, create it */
103 {
104 /* Fake that we opened an existing key */
106 }
108 {
109 /* Create the Catalog Name */
111 CatalogKeyName,
112 0,
113 NULL,
116 NULL,
117 &CatalogKey,
119 }
120
121 HeapFree(WsSockHeap, 0, CatalogKeyName);
122 RegType = REG_DWORD;
123 RegSize = sizeof(DWORD);
124
125 /* Fail if that didn't work */
126 if (ErrorCode != ERROR_SUCCESS) return FALSE;
127
128 /* Check if we had to create the key */
130 {
131 /* Write the count of entries (0 now) */
132 ErrorCode = RegSetValueEx(CatalogKey,
133 "Num_Catalog_Entries",
134 0,
135 REG_DWORD,
136 (LPBYTE)&NewData,
137 sizeof(NewData));
139 {
140 /* Close the key and fail */
141 RegCloseKey(CatalogKey);
142 return FALSE;
143 }
144
145 /* Write the first catalog entry ID */
146 NewData = 1001;
147 ErrorCode = RegSetValueEx(CatalogKey,
148 "Next_Catalog_Entry_ID",
149 0,
150 REG_DWORD,
151 (LPBYTE)&NewData,
152 sizeof(NewData));
154 {
155 /* Close the key and fail */
156 RegCloseKey(CatalogKey);
157 return FALSE;
158 }
159
160 /* Write the first catalog entry Uniqe ID */
161 NewData = 1;
162 ErrorCode = RegSetValueEx(CatalogKey,
163 "Serial_Access_Num",
164 0,
165 REG_DWORD,
166 (LPBYTE)&NewData,
167 sizeof(NewData));
169 {
170 /* Close the key and fail */
171 RegCloseKey(CatalogKey);
172 return FALSE;
173 }
174
175 /* Create a key for this entry */
176 ErrorCode = RegCreateKeyEx(CatalogKey,
177 "Catalog_Entries",
178 0,
179 NULL,
182 NULL,
183 &NewKey,
186 {
187 /* Close the key and fail */
188 RegCloseKey(CatalogKey);
189 return FALSE;
190 }
191
192 /* Close the key since we don't need it */
193 RegCloseKey(NewKey);
194 }
195 else
196 {
197 RegSize = sizeof(DWORD);
198 /* Read the serial number */
199 ErrorCode = RegQueryValueEx(CatalogKey,
200 "Serial_Access_Num",
201 0,
202 &RegType,
203 (LPBYTE)&UniqueId,
204 &RegSize);
205
206 /* Check if it's missing for some reason */
208 {
209 /* Write the first catalog entry Unique ID */
210 NewData = 1;
211 ErrorCode = RegSetValueEx(CatalogKey,
212 "Serial_Access_Num",
213 0,
214 REG_DWORD,
215 (LPBYTE)&NewData,
216 sizeof(NewData));
217 }
218 }
219
220 /* Set the Catalog Key */
221 Catalog->CatalogKey = CatalogKey;
222 return TRUE;
223}
#define DPRINT1
Definition: precomp.h:8
#define FALSE
Definition: types.h:117
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define REG_SZ
Definition: layer.c:22
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define DWORD
Definition: nt_native.h:44
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
#define REG_DWORD
Definition: sdbapi.c:596
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
unsigned char * LPBYTE
Definition: typedefs.h:53
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG _Out_opt_ PULONG CreateDisposition
Definition: wdfregistry.h:120
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define RegQueryValueEx
Definition: winreg.h:524
char CHAR
Definition: xmlstorage.h:175

Referenced by WsTcInitializeFromRegistry().

◆ WsTcRefreshFromRegistry()

DWORD WSAAPI WsTcRefreshFromRegistry ( IN PTCATALOG  Catalog,
IN HANDLE  CatalogEvent 
)

Definition at line 246 of file dcatalog.c.

248{
250 BOOLEAN LocalEvent = FALSE;
251 LIST_ENTRY LocalList;
252 DWORD UniqueId;
253 HKEY EntriesKey;
254 DWORD CatalogEntries;
255 PTCATALOG_ENTRY CatalogEntry;
256 DWORD NextCatalogEntry;
257 BOOL NewChangesMade;
259 DWORD RegType = REG_DWORD;
260 DWORD RegSize = sizeof(DWORD);
261 DWORD i;
262
263 /* Check if we got an event */
264 if (!CatalogEvent)
265 {
266 /* Create an event ourselves */
267 CatalogEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
268 if (!CatalogEvent) return WSASYSCALLFAILURE;
269 LocalEvent = TRUE;
270 }
271
272 /* Lock the catalog */
273 WsTcLock();
274
275 /* Initialize our local list for the loop */
276 InitializeListHead(&LocalList);
277
278 /* Start looping */
279 do
280 {
281 /* Setup notifications for the catalog entry */
282 ErrorCode = WsSetupCatalogProtection(Catalog->CatalogKey,
283 CatalogEvent,
284 &UniqueId);
285 if (ErrorCode != ERROR_SUCCESS) break;
286
287 /* Check if we've changed till now */
288 if (UniqueId == Catalog->UniqueId)
289 {
290 /* We haven't, so return */
292 break;
293 }
294
295 /* Now Open the Entries */
296 ErrorCode = RegOpenKeyEx(Catalog->CatalogKey,
297 "Catalog_Entries",
298 0,
300 &EntriesKey);
302 {
303 /* Critical failure */
305 break;
306 }
307
308 /* Get the next entry */
309 ErrorCode = RegQueryValueEx(Catalog->CatalogKey,
310 "Next_Catalog_Entry_ID",
311 0,
312 &RegType,
313 (LPBYTE)&NextCatalogEntry,
314 &RegSize);
316 {
317 /* Critical failure */
319 break;
320 }
321
322 /* Find out how many there are */
323 ErrorCode = RegQueryValueEx(Catalog->CatalogKey,
324 "Num_Catalog_Entries",
325 0,
326 &RegType,
327 (LPBYTE)&CatalogEntries,
328 &RegSize);
330 {
331 /* Critical failure */
333 break;
334 }
335
336 /* Initialize them all */
337 for (i = 1; i <= CatalogEntries; i++)
338 {
339 /* Allocate a Catalog Entry Structure */
340 CatalogEntry = WsTcEntryAllocate();
341 if (!CatalogEntry)
342 {
343 /* Not enough memory, fail */
345 break;
346 }
347
348 /* Initialize it from the Registry Key */
350 EntriesKey,
351 i);
353 {
354 /* We failed to get it, dereference the entry and leave */
355 WsTcEntryDereference(CatalogEntry);
356 break;
357 }
358
359 /* Insert it to our List */
360 InsertTailList(&LocalList, &CatalogEntry->CatalogLink);
361 }
362
363 /* Close the catalog key */
364 RegCloseKey(EntriesKey);
365
366 /* Check if we changed during our read and if we have success */
367 NewChangesMade = WsCheckCatalogState(CatalogEvent);
368 if (!NewChangesMade && ErrorCode == ERROR_SUCCESS)
369 {
370 /* All is good, update the protocol list */
371 WsTcUpdateProtocolList(Catalog, &LocalList);
372
373 /* Update and return */
374 Catalog->UniqueId = UniqueId;
375 Catalog->NextId = NextCatalogEntry;
376 break;
377 }
378
379 /* We failed and/or catalog data changed, free what we did till now */
380 while (!IsListEmpty(&LocalList))
381 {
382 /* Get the LP Catalog Item */
383 Entry = RemoveHeadList(&LocalList);
384 CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
385
386 /* Dereference it */
387 WsTcEntryDereference(CatalogEntry);
388 }
389 } while (NewChangesMade);
390
391 /* Release the lock */
392 WsTcUnlock();
393
394 /* Close the event, if any was created by us */
395 if (LocalEvent) CloseHandle(CatalogEvent);
396
397 /* All Done */
398 return ErrorCode;
399}
unsigned char BOOLEAN
VOID WSAAPI WsTcUpdateProtocolList(IN PTCATALOG Catalog, IN PLIST_ENTRY List)
Definition: dcatalog.c:688
#define CloseHandle
Definition: compat.h:739
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
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
LIST_ENTRY CatalogLink
Definition: ws2_32p.h:87
#define CreateEvent
Definition: winbase.h:3748
DWORD WSAAPI WsTcEntryInitializeFromRegistry(IN PTCATALOG_ENTRY CatalogEntry, IN HKEY, unsigned long)
PTCATALOG_ENTRY WSAAPI WsTcEntryAllocate(VOID)
Definition: dcatitem.c:17
INT WSAAPI WsSetupCatalogProtection(IN HKEY CatalogKey, IN HANDLE CatalogEvent, OUT LPDWORD UniqueId)
Definition: wsautil.c:142
BOOL WSAAPI WsCheckCatalogState(IN HANDLE Event)
Definition: wsautil.c:75

Referenced by WsTcInitializeFromRegistry().

◆ WsTcRemoveCatalogItem()

VOID WSAAPI WsTcRemoveCatalogItem ( IN PTCATALOG  Catalog,
IN PTCATALOG_ENTRY  Entry 
)

Definition at line 871 of file dcatalog.c.

873{
874 /* Remove the entry from the list */
875 RemoveEntryList(&Entry->CatalogLink);
876
877 /* Decrease our count */
878 Catalog->ItemCount--;
879}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986

Referenced by WsTcDelete().

◆ WsTcUpdateProtocolList()

VOID WSAAPI WsTcUpdateProtocolList ( IN PTCATALOG  Catalog,
IN PLIST_ENTRY  List 
)

Definition at line 688 of file dcatalog.c.

690{
691 LIST_ENTRY TempList;
692 PTCATALOG_ENTRY CatalogEntry, OldCatalogEntry;
694
695 /* First move from our list to the old one */
696 InsertHeadList(&Catalog->ProtocolList, &TempList);
697 RemoveEntryList(&Catalog->ProtocolList);
698 InitializeListHead(&Catalog->ProtocolList);
699
700 /* Loop every item in the list */
701 while (!IsListEmpty(List))
702 {
703 /* Get the catalog entry */
705 CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
706
707 /* Check if this item is already in our list */
708 Entry = TempList.Flink;
709 while (Entry != &TempList)
710 {
711 /* Get the catalog entry */
712 OldCatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
713 Entry = Entry->Flink;
714
715 /* Check if they match */
716 if (CatalogEntry->ProtocolInfo.dwCatalogEntryId ==
717 OldCatalogEntry->ProtocolInfo.dwCatalogEntryId)
718 {
719 /* We have a match, use the old item instead */
720 WsTcEntryDereference(CatalogEntry);
721 CatalogEntry = OldCatalogEntry;
722 RemoveEntryList(&CatalogEntry->CatalogLink);
723
724 /* Decrease the number of protocols we have */
725 Catalog->ItemCount--;
726 break;
727 }
728 }
729
730 /* Add this item */
731 InsertTailList(&Catalog->ProtocolList, &CatalogEntry->CatalogLink);
732 Catalog->ItemCount++;
733 }
734
735 /* If there's anything left in the temporary list */
736 while (!IsListEmpty(&TempList))
737 {
738 /* Get the entry */
739 Entry = RemoveHeadList(&TempList);
740 CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
741
742 /* Remove it */
743 Catalog->ItemCount--;
744 WsTcEntryDereference(CatalogEntry);
745 }
746}
#define InsertHeadList(ListHead, Entry)
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550

Referenced by WsTcRefreshFromRegistry().