ReactOS 0.4.15-dev-8138-g1e75ea8
context.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS NetSh
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Network Shell context management functions
5 * COPYRIGHT: Copyright 2023 Eric Kohl <eric.kohl@reactos.org>
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include "precomp.h"
11
12#define NDEBUG
13#include <debug.h>
14
15/* GLOBALS ********************************************************************/
16
19
20/* FUNCTIONS ******************************************************************/
21
24 PCONTEXT_ENTRY pParentContext,
25 PWSTR pszName,
26 GUID *pGuid)
27{
29
30 if (pParentContext != NULL && pszName == NULL)
31 return NULL;
32
33 /* Allocate the entry */
35 if (pEntry == NULL)
36 return NULL;
37
38 /* Allocate the name buffer */
39 if (pszName != NULL)
40 {
41 pEntry->pszContextName = HeapAlloc(GetProcessHeap(),
43 (wcslen(pszName) + 1) * sizeof(WCHAR));
44 if (pEntry->pszContextName == NULL)
45 {
47 return NULL;
48 }
49
50 /* Fill the entry */
51 wcscpy(pEntry->pszContextName, pszName);
52 }
53
54 pEntry->pParentContext = pParentContext;
55 if (pGuid != NULL)
56 CopyMemory(&pEntry->Guid, pGuid, sizeof(pEntry->Guid));
57
58 /* Insert it */
59 if (pParentContext != NULL)
60 {
61 if (pParentContext->pSubContextHead == NULL && pParentContext->pSubContextTail == NULL)
62 {
63 pParentContext->pSubContextHead = pEntry;
64 pParentContext->pSubContextTail = pEntry;
65 }
66 else
67 {
68 pEntry->pPrev = pParentContext->pSubContextTail;
69 pParentContext->pSubContextTail->pNext = pEntry;
70 pParentContext->pSubContextTail = pEntry;
71 }
72 }
73
74 return pEntry;
75}
76
77
80 PCONTEXT_ENTRY pContext,
81 LPCWSTR pwszCmdToken,
82 PFN_HANDLE_CMD pfnCmdHandler,
83 DWORD dwShortCmdHelpToken,
84 DWORD dwCmdHlpToken,
86{
88
89 if (pfnCmdHandler == NULL)
90 return NULL;
91
92 /* Allocate the entry */
94 if (pEntry == NULL)
95 return NULL;
96
97 pEntry->pwszCmdToken = HeapAlloc(GetProcessHeap(),
99 (wcslen(pwszCmdToken) + 1) * sizeof(WCHAR));
100 if (pEntry->pwszCmdToken == NULL)
101 {
103 return NULL;
104 }
105
106 wcscpy((LPWSTR)pEntry->pwszCmdToken, pwszCmdToken);
107
108 pEntry->pfnCmdHandler = pfnCmdHandler;
109 pEntry->dwShortCmdHelpToken = dwShortCmdHelpToken;
110 pEntry->dwCmdHlpToken = dwCmdHlpToken;
111 pEntry->dwFlags = dwFlags;
112
113 if (pContext->pCommandListHead == NULL && pContext->pCommandListTail == NULL)
114 {
115 pContext->pCommandListHead = pEntry;
116 pContext->pCommandListTail = pEntry;
117 }
118 else
119 {
120 pEntry->pPrev = pContext->pCommandListTail;
121 pContext->pCommandListTail->pNext = pEntry;
122 pContext->pCommandListTail = pEntry;
123 }
124
125 return pEntry;
126}
127
128
131 PCONTEXT_ENTRY pContext,
132 LPCWSTR pwszCmdGroupToken,
133 DWORD dwShortCmdHelpToken,
135{
137
138 /* Allocate the entry */
140 if (pEntry == NULL)
141 return NULL;
142
143 pEntry->pwszCmdGroupToken = HeapAlloc(GetProcessHeap(),
145 (wcslen(pwszCmdGroupToken) + 1) * sizeof(WCHAR));
146 if (pEntry->pwszCmdGroupToken == NULL)
147 {
149 return NULL;
150 }
151
152 wcscpy((LPWSTR)pEntry->pwszCmdGroupToken, pwszCmdGroupToken);
153 pEntry->dwShortCmdHelpToken = dwShortCmdHelpToken;
154 pEntry->dwFlags = dwFlags;
155
156 if (pContext->pGroupListHead == NULL && pContext->pGroupListTail == NULL)
157 {
158 pContext->pGroupListHead = pEntry;
159 pContext->pGroupListTail = pEntry;
160 }
161 else
162 {
163 pEntry->pPrev = pContext->pGroupListTail;
164 pContext->pGroupListTail->pNext = pEntry;
165 pContext->pGroupListTail = pEntry;
166 }
167
168 return pEntry;
169}
170
171
174 PCOMMAND_GROUP pGroup,
175 LPCWSTR pwszCmdToken,
176 PFN_HANDLE_CMD pfnCmdHandler,
177 DWORD dwShortCmdHelpToken,
178 DWORD dwCmdHlpToken,
180{
182
183 if (pfnCmdHandler == NULL)
184 return NULL;
185
186 /* Allocate the entry */
188 if (pEntry == NULL)
189 return NULL;
190
191 pEntry->pwszCmdToken = HeapAlloc(GetProcessHeap(),
193 (wcslen(pwszCmdToken) + 1) * sizeof(WCHAR));
194 if (pEntry->pwszCmdToken == NULL)
195 {
197 return NULL;
198 }
199
200 wcscpy((LPWSTR)pEntry->pwszCmdToken, pwszCmdToken);
201
202 pEntry->pfnCmdHandler = pfnCmdHandler;
203 pEntry->dwShortCmdHelpToken = dwShortCmdHelpToken;
204 pEntry->dwCmdHlpToken = dwCmdHlpToken;
205 pEntry->dwFlags = dwFlags;
206
207 if (pGroup->pCommandListHead == NULL && pGroup->pCommandListTail == NULL)
208 {
209 pGroup->pCommandListHead = pEntry;
210 pGroup->pCommandListTail = pEntry;
211 }
212 else
213 {
214 pEntry->pPrev = pGroup->pCommandListTail;
215 pGroup->pCommandListTail->pNext = pEntry;
216 pGroup->pCommandListTail = pEntry;
217 }
218
219 return pEntry;
220}
221
222
223VOID
225 PWSTR pszName)
226{
227 /* Delete all commands */
228 /* Delete the context */
229}
230
231
232DWORD
233WINAPI
235 LPCWSTR pwszMachine,
236 LPWSTR *argv,
237 DWORD dwCurrentIndex,
238 DWORD dwArgCount,
241 BOOL *pbDone)
242{
245
246 return 0;
247}
248
249
250DWORD
251WINAPI
253 LPCWSTR pwszMachine,
254 LPWSTR *argv,
255 DWORD dwCurrentIndex,
256 DWORD dwArgCount,
259 BOOL *pbDone)
260{
261 *pbDone = TRUE;
262 return 0;
263}
264
265
266DWORD
267WINAPI
269 LPCWSTR pwszMachine,
270 LPWSTR *argv,
271 DWORD dwCurrentIndex,
272 DWORD dwArgCount,
275 BOOL *pbDone)
276{
277 return 0;
278}
279
280
281BOOL
283{
284 PCOMMAND_GROUP pGroup;
285
287 DPRINT1("pRootContext: %p\n", pRootContext);
288 if (pRootContext == NULL)
289 return FALSE;
290
292
299
301 if (pGroup)
302 {
304 }
305
306 pGroup = AddCommandGroup(pRootContext, L"delete", IDS_HLP_GROUP_DELETE, 0);
307 if (pGroup)
308 {
310 }
311
313 if (pGroup)
314 {
316 }
317
319
320 return TRUE;
321}
322
323
324DWORD
325WINAPI
327 _In_ const NS_CONTEXT_ATTRIBUTES *pChildContext)
328{
329 PCONTEXT_ENTRY pContext;
330 DWORD i;
331
332 DPRINT1("RegisterContext(%p)\n", pChildContext);
333 if (pChildContext == NULL)
334 {
335 DPRINT1("Invalid child context!\n");
337 }
338
339 if ((pChildContext->pwszContext == NULL) ||
340 (wcslen(pChildContext->pwszContext) == 0) ||
341 (wcschr(pChildContext->pwszContext, L' ') != 0) ||
342 (wcschr(pChildContext->pwszContext, L'=') != 0))
343 {
344 DPRINT1("Invalid context name!\n");
346 }
347
348 DPRINT1("Name: %S\n", pChildContext->pwszContext);
349
350 pContext = AddContext(pRootContext, pChildContext->pwszContext, (GUID*)&pChildContext->guidHelper);
351 if (pContext != NULL)
352 {
353 for (i = 0; i < pChildContext->ulNumTopCmds; i++)
354 {
355 AddContextCommand(pContext,
356 pChildContext->pTopCmds[i].pwszCmdToken,
357 pChildContext->pTopCmds[i].pfnCmdHandler,
358 pChildContext->pTopCmds[i].dwShortCmdHelpToken,
359 pChildContext->pTopCmds[i].dwCmdHlpToken,
360 pChildContext->pTopCmds[i].dwFlags);
361 }
362
363 /* Add command groups */
364 for (i = 0; i < pChildContext->ulNumGroups; i++)
365 {
366 AddCommandGroup(pContext,
367 pChildContext->pCmdGroups[i].pwszCmdGroupToken,
368 pChildContext->pCmdGroups[i].dwShortCmdHelpToken,
369 pChildContext->pCmdGroups[i].dwFlags);
370 }
371 }
372
373 return ERROR_SUCCESS;
374}
BOOL CreateRootContext(VOID)
Definition: context.c:282
PCOMMAND_GROUP AddCommandGroup(PCONTEXT_ENTRY pContext, LPCWSTR pwszCmdGroupToken, DWORD dwShortCmdHelpToken, DWORD dwFlags)
Definition: context.c:130
DWORD WINAPI RemCommand(LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: context.c:268
DWORD WINAPI RegisterContext(_In_ const NS_CONTEXT_ATTRIBUTES *pChildContext)
Definition: context.c:326
PCOMMAND_ENTRY AddContextCommand(PCONTEXT_ENTRY pContext, LPCWSTR pwszCmdToken, PFN_HANDLE_CMD pfnCmdHandler, DWORD dwShortCmdHelpToken, DWORD dwCmdHlpToken, DWORD dwFlags)
Definition: context.c:79
PCOMMAND_ENTRY AddGroupCommand(PCOMMAND_GROUP pGroup, LPCWSTR pwszCmdToken, PFN_HANDLE_CMD pfnCmdHandler, DWORD dwShortCmdHelpToken, DWORD dwCmdHlpToken, DWORD dwFlags)
Definition: context.c:173
PCONTEXT_ENTRY pRootContext
Definition: context.c:17
PCONTEXT_ENTRY pCurrentContext
Definition: context.c:18
DWORD WINAPI UpCommand(LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: context.c:234
VOID DeleteContext(PWSTR pszName)
Definition: context.c:224
PCONTEXT_ENTRY AddContext(PCONTEXT_ENTRY pParentContext, PWSTR pszName, GUID *pGuid)
Definition: context.c:23
DWORD WINAPI ExitCommand(LPCWSTR pwszMachine, LPWSTR *argv, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: context.c:252
DWORD WINAPI HelpCommand(LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: help.c:116
#define IDS_HLP_DEL_HELPER
Definition: resource.h:30
#define IDS_HLP_GROUP_ADD
Definition: resource.h:35
#define IDS_HLP_HELP
Definition: resource.h:23
#define IDS_HLP_GROUP_SHOW
Definition: resource.h:37
#define IDS_HLP_EXIT
Definition: resource.h:21
#define IDS_HLP_DEL_HELPER_EX
Definition: resource.h:31
#define IDS_HLP_GROUP_DELETE
Definition: resource.h:36
#define IDS_HLP_HELP_EX
Definition: resource.h:24
#define IDS_HLP_UP_EX
Definition: resource.h:26
#define IDS_HLP_SHOW_HELPER
Definition: resource.h:32
#define IDS_HLP_EXIT_EX
Definition: resource.h:22
#define IDS_HLP_ADD_HELPER_EX
Definition: resource.h:29
#define IDS_HLP_SHOW_HELPER_EX
Definition: resource.h:33
#define IDS_HLP_ADD_HELPER
Definition: resource.h:28
#define IDS_HLP_UP
Definition: resource.h:25
#define DPRINT1
Definition: precomp.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
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
DWORD WINAPI ShowHelperCommand(LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: helper.c:573
DWORD WINAPI AddHelperCommand(LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: helper.c:425
DWORD WINAPI DeleteHelperCommand(LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
Definition: helper.c:457
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define argv
Definition: mplay32.c:18
#define _In_
Definition: ms_sal.h:308
DWORD(WINAPI * PFN_HANDLE_CMD)(_In_ LPCWSTR pwszMachine, _In_ LPWSTR *ppwcArguments, _In_ DWORD dwCurrentIndex, _In_ DWORD dwArgCount, _In_ DWORD dwFlags, _In_ LPCVOID pvData, _Out_ BOOL *pbDone)
Definition: netsh.h:64
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
Definition: precomp.h:73
struct _COMMAND_ENTRY * pNext
Definition: precomp.h:75
PCOMMAND_ENTRY pCommandListTail
Definition: precomp.h:94
PCOMMAND_ENTRY pCommandListHead
Definition: precomp.h:93
struct _COMMAND_GROUP * pNext
Definition: precomp.h:87
Definition: precomp.h:98
PCOMMAND_ENTRY pCommandListTail
Definition: precomp.h:109
PCOMMAND_GROUP pGroupListTail
Definition: precomp.h:112
struct _CONTEXT_ENTRY * pSubContextHead
Definition: precomp.h:114
HMODULE hModule
Definition: precomp.h:106
struct _CONTEXT_ENTRY * pParentContext
Definition: precomp.h:102
PCOMMAND_GROUP pGroupListHead
Definition: precomp.h:111
PCOMMAND_ENTRY pCommandListHead
Definition: precomp.h:108
struct _CONTEXT_ENTRY * pSubContextTail
Definition: precomp.h:115
uint16_t * PWSTR
Definition: typedefs.h:56
#define CopyMemory
Definition: winbase.h:1710
#define GetModuleHandle
Definition: winbase.h:3827
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3749
CONST void * LPCVOID
Definition: windef.h:191
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185