ReactOS  0.4.14-dev-552-g2fad488
dcatitem.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/dcatitem.c
5  * PURPOSE: Transport 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  PTCATALOG_ENTRY CatalogEntry;
20 
21  /* Allocate the catalog entry */
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  }
28 
29  /* Return it */
30  return CatalogEntry;
31 }
32 
33 VOID
34 WSAAPI
36 {
37  /* Check if a provider is loaded */
38  if (CatalogEntry->Provider)
39  {
40  /* Dereference it too */
41  WsTpDereference(CatalogEntry->Provider);
42  CatalogEntry->Provider = NULL;
43  }
44 
45  /* Delete us */
46  HeapFree(WsSockHeap, 0, CatalogEntry);
47 }
48 
49 VOID
50 WSAAPI
52 {
53  /* Dereference and check if it's now 0 */
54  if (!(InterlockedDecrement(&CatalogEntry->RefCount)))
55  {
56  /* We can delete the Provider now */
57  WsTcEntryDelete(CatalogEntry);
58  }
59 }
60 
61 DWORD
62 WSAAPI
64  IN HKEY ParentKey,
65  IN DWORD UniqueId)
66 {
67  CHAR CatalogEntryName[13];
68  DWORD RegSize;
69  DWORD RegType = REG_BINARY;
70  HKEY EntryKey;
71  DWORD Return;
72  LPBYTE Buf;
73  DWORD index;
74 
75  /* Convert to a 00000xxx string */
76  sprintf(CatalogEntryName, "%0""12""lu", UniqueId);
77 
78  /* Open the Entry */
79  Return = RegOpenKeyEx(ParentKey,
80  CatalogEntryName,
81  0,
82  KEY_READ,
83  &EntryKey);
84 
85  /* Get Size of Catalog Entry Structure */
86  Return = RegQueryValueEx(EntryKey,
87  "PackedCatalogItem",
88  0,
89  NULL,
90  NULL,
91  &RegSize);
92 
93  if (!(Buf = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, RegSize)))
95 
96  /* Read the Whole Catalog Entry Structure */
97  Return = RegQueryValueEx(EntryKey,
98  "PackedCatalogItem",
99  0,
100  &RegType,
101  Buf,
102  &RegSize);
103 
104 
105  memcpy(CatalogEntry->DllPath, Buf, sizeof(CatalogEntry->DllPath));
106  index = sizeof(CatalogEntry->DllPath);
107  if (index < RegSize)
108  {
109  memcpy(&CatalogEntry->ProtocolInfo, &Buf[index], sizeof(WSAPROTOCOL_INFOW));
110  index += sizeof(WSAPROTOCOL_INFOW);
111  }
112  HeapFree(WsSockHeap, 0, Buf);
113 
114  /* Done */
115  RegCloseKey(EntryKey);
116  return Return;
117 }
118 
119 VOID
120 WSAAPI
123 {
124  /* Reference the provider */
125  InterlockedIncrement(&Provider->RefCount);
126 
127  /* Set it */
128  Entry->Provider = Provider;
129 }
#define RegQueryValueEx
Definition: winreg.h:524
#define IN
Definition: typedefs.h:38
VOID WSAAPI WsTpDereference(IN PTPROVIDER Provider)
Definition: dprovide.c:143
Definition: ws2_32p.h:85
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_READ
Definition: nt_native.h:1023
char CHAR
Definition: xmlstorage.h:175
PTCATALOG_ENTRY WSAAPI WsTcEntryAllocate(VOID)
Definition: dcatitem.c:17
LONG RefCount
Definition: ws2_32p.h:88
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WSAAPI WsTcEntryInitializeFromRegistry(IN PTCATALOG_ENTRY CatalogEntry, IN HKEY ParentKey, IN DWORD UniqueId)
Definition: dcatitem.c:63
#define sprintf(buf, format,...)
Definition: sprintf.c:55
VOID WSAAPI WsTcEntrySetProvider(IN PTCATALOG_ENTRY Entry, IN PTPROVIDER Provider)
Definition: dcatitem.c:121
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
struct _WSAPROTOCOL_INFOW WSAPROTOCOL_INFOW
VOID WSAAPI WsTcEntryDereference(IN PTCATALOG_ENTRY CatalogEntry)
Definition: dcatitem.c:51
smooth NULL
Definition: ftsmooth.c:416
GLuint index
Definition: glext.h:6031
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define index(s, c)
Definition: various.h:29
#define InterlockedDecrement
Definition: armddk.h:52
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define RegOpenKeyEx
Definition: winreg.h:520
#define InterlockedIncrement
Definition: armddk.h:53
#define WSAAPI
Definition: winsock2.h:584
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID WSAAPI WsTcEntryDelete(IN PTCATALOG_ENTRY CatalogEntry)
Definition: dcatitem.c:35
HANDLE WsSockHeap
Definition: dllmain.c:21
#define HeapFree(x, y, z)
Definition: compat.h:402
base of all file and directory entries
Definition: entries.h:82