ReactOS 0.4.16-dev-340-g0540c21
nscatent.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/src/nscatent.c
5 * PURPOSE: Namespace Catalog Entry Object
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <ws2_32.h>
12
13/* FUNCTIONS *****************************************************************/
14
18{
19 PNSCATALOG_ENTRY CatalogEntry;
20
21 /* Allocate the catalog */
22 CatalogEntry = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*CatalogEntry));
23 if (CatalogEntry)
24 {
25 /* Set the default non-null members */
26 CatalogEntry->RefCount = 1;
27 CatalogEntry->Enabled = TRUE;
28 CatalogEntry->AddressFamily = -1;
29 }
30
31 /* Return it */
32 return CatalogEntry;
33}
34
35VOID
38{
39 /* Check if a provider is loaded */
40 if (CatalogEntry->Provider)
41 {
42 /* Dereference it too */
43 WsNpDereference(CatalogEntry->Provider);
44 CatalogEntry->Provider = NULL;
45 }
46
47 /* Delete us */
48 HeapFree(WsSockHeap, 0, CatalogEntry);
49}
50
51VOID
54{
55 /* Dereference and check if it's now 0 */
56 if (!(InterlockedDecrement(&CatalogEntry->RefCount)))
57 {
58 /* We can delete the Provider now */
59 WsNcEntryDelete(CatalogEntry);
60 }
61}
62
63INT
67 IN ULONG UniqueId)
68{
70 CHAR CatalogEntryName[13];
71 HKEY EntryKey;
72 ULONG RegType = REG_SZ;
73 ULONG RegSize = MAX_PATH;
74 ULONG RegValue;
75
76 /* Convert to a 00000xxx string */
77 sprintf(CatalogEntryName, "%0""12""i", (int)UniqueId);
78
79 /* Open the Entry */
81 CatalogEntryName,
82 0,
84 &EntryKey);
85 if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
86 /* Read the Library Path */
87 ErrorCode = RegQueryValueExW(EntryKey,
88 L"LibraryPath",
89 0,
90 &RegType,
91 (LPBYTE)&CatalogEntry->DllPath,
92 &RegSize);
93 if (ErrorCode != ERROR_SUCCESS) goto out;
94 /* Query Display String Size*/
95 ErrorCode = RegQueryValueExW(EntryKey,
96 L"DisplayString",
97 0,
98 NULL,
99 NULL,
100 &RegSize);
101 if (ErrorCode != ERROR_SUCCESS) goto out;
102 /* Allocate it */
103 CatalogEntry->ProviderName = (LPWSTR)HeapAlloc(WsSockHeap, 0, RegSize);
104
105 /* Read it */
106 ErrorCode = RegQueryValueExW(EntryKey,
107 L"DisplayString",
108 0,
109 &RegType,
110 (LPBYTE)CatalogEntry->ProviderName,
111 &RegSize);
112 if (ErrorCode != ERROR_SUCCESS) goto out;
113 /* Read the Provider Id */
114 RegType = REG_BINARY;
115 RegSize = sizeof(GUID);
116 ErrorCode = RegQueryValueEx(EntryKey,
117 "ProviderId",
118 0,
119 &RegType,
120 (LPBYTE)&CatalogEntry->ProviderId,
121 &RegSize);
122 if (ErrorCode != ERROR_SUCCESS) goto out;
123 /* Read the Address Family */
124 RegType = REG_DWORD;
125 RegSize = sizeof(DWORD);
126 ErrorCode = RegQueryValueEx(EntryKey,
127 "AddressFamily",
128 0,
129 &RegType,
130 (LPBYTE)&CatalogEntry->AddressFamily,
131 &RegSize);
132 if (ErrorCode != ERROR_SUCCESS) goto out;
133 /* Read the Namespace Id */
134 ErrorCode = RegQueryValueEx(EntryKey,
135 "SupportedNamespace",
136 0,
137 &RegType,
138 (LPBYTE)&CatalogEntry->NamespaceId,
139 &RegSize);
140 if (ErrorCode != ERROR_SUCCESS) goto out;
141 /* Read the Enabled Flag */
142 ErrorCode = RegQueryValueEx(EntryKey,
143 "Enabled",
144 0,
145 &RegType,
146 (LPBYTE)&RegValue,
147 &RegSize);
148 if (ErrorCode != ERROR_SUCCESS) goto out;
149 CatalogEntry->Enabled = RegValue != 0;
150
151 /* Read the Version */
152 ErrorCode = RegQueryValueEx(EntryKey,
153 "Version",
154 0,
155 &RegType,
156 (LPBYTE)&CatalogEntry->Version,
157 &RegSize);
158 if (ErrorCode != ERROR_SUCCESS) goto out;
159 /* Read the Support Service Class Info Flag */
160 ErrorCode = RegQueryValueEx(EntryKey,
161 "StoresServiceClassInfo",
162 0,
163 &RegType,
164 (LPBYTE)&RegValue,
165 &RegSize);
166 CatalogEntry->StoresServiceClassInfo = RegValue != 0;
167out:
168 /* Done */
169 RegCloseKey(EntryKey);
170 return ErrorCode;
171}
172
173VOID
174WSAAPI
177{
178 /* Reference the provider */
179 InterlockedIncrement(&Provider->RefCount);
180
181 /* Set it */
182 Entry->Provider = Provider;
183}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define REG_SZ
Definition: layer.c:22
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
PNSCATALOG_ENTRY WSAAPI WsNcEntryAllocate(VOID)
Definition: nscatent.c:17
VOID WSAAPI WsNcEntryDelete(IN PNSCATALOG_ENTRY CatalogEntry)
Definition: nscatent.c:37
VOID WSAAPI WsNcEntrySetProvider(IN PNSCATALOG_ENTRY Entry, IN PNS_PROVIDER Provider)
Definition: nscatent.c:175
VOID WSAAPI WsNcEntryDereference(IN PNSCATALOG_ENTRY CatalogEntry)
Definition: nscatent.c:53
INT WSAAPI WsNcEntryInitializeFromRegistry(IN PNSCATALOG_ENTRY CatalogEntry, IN HKEY ParentKey, IN ULONG UniqueId)
Definition: nscatent.c:65
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_READ
Definition: nt_native.h:1023
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
static FILE * out
Definition: regtests2xml.c:44
#define REG_DWORD
Definition: sdbapi.c:596
base of all file and directory entries
Definition: entries.h:83
Definition: ws2_32p.h:122
LONG RefCount
Definition: ws2_32p.h:124
LONG AddressFamily
Definition: ws2_32p.h:126
BOOLEAN Enabled
Definition: ws2_32p.h:130
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_opt_ WDFKEY ParentKey
Definition: wdfregistry.h:69
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524
#define WSAAPI
Definition: winsock2.h:605
HANDLE WsSockHeap
Definition: dllmain.c:21
VOID WSAAPI WsNpDereference(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char CHAR
Definition: xmlstorage.h:175