ReactOS  0.4.13-dev-100-gc8611ae
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_new/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 
16 WSAAPI
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 
35 VOID
36 WSAAPI
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 
51 VOID
52 WSAAPI
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 
63 INT
64 WSAAPI
66  IN HKEY ParentKey,
67  IN ULONG UniqueId)
68 {
69  INT ErrorCode;
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 */
80  ErrorCode = RegOpenKeyEx(ParentKey,
81  CatalogEntryName,
82  0,
83  KEY_READ,
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;
167 out:
168  /* Done */
169  RegCloseKey(EntryKey);
170  return ErrorCode;
171 }
172 
173 VOID
174 WSAAPI
177 {
178  /* Reference the provider */
179  InterlockedIncrement(&Provider->RefCount);
180 
181  /* Set it */
182  Entry->Provider = Provider;
183 }
#define RegQueryValueEx
Definition: winreg.h:524
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
LONG AddressFamily
Definition: ws2_32p.h:126
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_READ
Definition: nt_native.h:1023
char CHAR
Definition: xmlstorage.h:175
Definition: ws2_32p.h:121
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
#define sprintf(buf, format,...)
Definition: sprintf.c:55
VOID WSAAPI WsNcEntryDereference(IN PNSCATALOG_ENTRY CatalogEntry)
Definition: nscatent.c:53
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
VOID WSAAPI WsNpDereference(IN PNS_PROVIDER Provider)
Definition: nsprovid.c:180
smooth NULL
Definition: ftsmooth.c:416
LONG RefCount
Definition: ws2_32p.h:124
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
BOOLEAN Enabled
Definition: ws2_32p.h:130
#define MAX_PATH
Definition: compat.h:26
static FILE * out
Definition: regtests2xml.c:44
static const WCHAR L[]
Definition: oid.c:1250
#define InterlockedDecrement
Definition: armddk.h:52
PNSCATALOG_ENTRY WSAAPI WsNcEntryAllocate(VOID)
Definition: nscatent.c:17
VOID WSAAPI WsNcEntryDelete(IN PNSCATALOG_ENTRY CatalogEntry)
Definition: nscatent.c:37
struct _GUID GUID
#define RegOpenKeyEx
Definition: winreg.h:520
#define InterlockedIncrement
Definition: armddk.h:53
#define WSAAPI
Definition: winsock2.h:584
VOID WSAAPI WsNcEntrySetProvider(IN PNSCATALOG_ENTRY Entry, IN PNS_PROVIDER Provider)
Definition: nscatent.c:175
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
INT WSAAPI WsNcEntryInitializeFromRegistry(IN PNSCATALOG_ENTRY CatalogEntry, IN HKEY ParentKey, IN ULONG UniqueId)
Definition: nscatent.c:65
#define REG_DWORD
Definition: sdbapi.c:596
HANDLE WsSockHeap
Definition: dllmain.c:21
#define HeapFree(x, y, z)
Definition: compat.h:394
base of all file and directory entries
Definition: entries.h:82
#define REG_SZ
Definition: layer.c:22