ReactOS 0.4.15-dev-8428-g6910fa6
precomp.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <wincon.h>
#include <winuser.h>
#include <errno.h>
#include <conutils.h>
#include <netsh.h>
#include "resource.h"
Include dependency graph for precomp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _DLL_LIST_ENTRY
 
struct  _HELPER_ENTRY
 
struct  _COMMAND_ENTRY
 
struct  _COMMAND_GROUP
 
struct  _CONTEXT_ENTRY
 

Macros

#define WIN32_NO_STATUS
 
#define MAX_STRING_SIZE   1024
 
#define MAX_ARGS_COUNT   256
 
#define REG_NETSH_PATH   L"Software\\Microsoft\\NetSh"
 

Typedefs

typedef struct _DLL_LIST_ENTRY DLL_LIST_ENTRY
 
typedef struct _DLL_LIST_ENTRYPDLL_LIST_ENTRY
 
typedef struct _HELPER_ENTRY HELPER_ENTRY
 
typedef struct _HELPER_ENTRYPHELPER_ENTRY
 
typedef struct _COMMAND_ENTRY COMMAND_ENTRY
 
typedef struct _COMMAND_ENTRYPCOMMAND_ENTRY
 
typedef struct _COMMAND_GROUP COMMAND_GROUP
 
typedef struct _COMMAND_GROUPPCOMMAND_GROUP
 
typedef struct _CONTEXT_ENTRY CONTEXT_ENTRY
 
typedef struct _CONTEXT_ENTRYPCONTEXT_ENTRY
 

Functions

BOOL CreateRootContext (VOID)
 
DWORD WINAPI HelpCommand (LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
VOID HelpGroup (PCOMMAND_GROUP pGroup)
 
VOID LoadHelpers (VOID)
 
VOID UnloadHelpers (VOID)
 
DWORD WINAPI AddHelperCommand (LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
DWORD WINAPI DeleteHelperCommand (LPCWSTR pwszMachine, LPWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
DWORD WINAPI ShowHelperCommand (LPCWSTR pwszMachine, PWSTR *ppwcArguments, DWORD dwCurrentIndex, DWORD dwArgCount, DWORD dwFlags, LPCVOID pvData, BOOL *pbDone)
 
BOOL InterpretScript (LPWSTR pszFileName)
 
BOOL InterpretCommand (LPWSTR *argv, DWORD dwArgCount)
 
VOID InterpretInteractive (VOID)
 

Variables

PCONTEXT_ENTRY pRootContext
 
PCONTEXT_ENTRY pCurrentContext
 

Macro Definition Documentation

◆ MAX_ARGS_COUNT

#define MAX_ARGS_COUNT   256

Definition at line 35 of file precomp.h.

◆ MAX_STRING_SIZE

#define MAX_STRING_SIZE   1024

Definition at line 34 of file precomp.h.

◆ REG_NETSH_PATH

#define REG_NETSH_PATH   L"Software\\Microsoft\\NetSh"

Definition at line 37 of file precomp.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 17 of file precomp.h.

Typedef Documentation

◆ COMMAND_ENTRY

◆ COMMAND_GROUP

◆ CONTEXT_ENTRY

◆ DLL_LIST_ENTRY

◆ HELPER_ENTRY

◆ PCOMMAND_ENTRY

◆ PCOMMAND_GROUP

◆ PCONTEXT_ENTRY

◆ PDLL_LIST_ENTRY

◆ PHELPER_ENTRY

Function Documentation

◆ AddHelperCommand()

DWORD WINAPI AddHelperCommand ( LPCWSTR  pwszMachine,
LPWSTR ppwcArguments,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)

Definition at line 425 of file helper.c.

433{
434 DWORD dwError = ERROR_SUCCESS;
435
436 DPRINT("AddHelperCommand()\n");
437
438 if (dwArgCount == 2)
439 {
440// ConResPrintf(StdErr, IDS_INVALID_SYNTAX);
441// ConResPrintf(StdErr, IDS_HLP_ADD_HELPER_EX);
442 return 1;
443 }
444
445 dwError = LoadHelperDll(ppwcArguments[2], TRUE);
446 if (dwError != ERROR_SUCCESS)
447 return dwError;
448
449 StartHelpers();
450
451 return ERROR_SUCCESS;
452}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
unsigned long DWORD
Definition: ntddk_ex.h:95
static VOID StartHelpers(VOID)
Definition: helper.c:29
static DWORD LoadHelperDll(_In_ PWSTR pszDllName, _In_ BOOL bRegister)
Definition: helper.c:109
#define DPRINT
Definition: sndvol32.h:73

Referenced by CreateRootContext().

◆ CreateRootContext()

BOOL CreateRootContext ( VOID  )

Definition at line 282 of file context.c.

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}
PCOMMAND_GROUP AddCommandGroup(PCONTEXT_ENTRY pContext, LPCWSTR pwszCmdGroupToken, DWORD dwShortCmdHelpToken, DWORD dwFlags)
Definition: context.c:130
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
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 NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
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
#define L(x)
Definition: ntvdm.h:50
HMODULE hModule
Definition: precomp.h:106
#define GetModuleHandle
Definition: winbase.h:3827

Referenced by wmain().

◆ DeleteHelperCommand()

DWORD WINAPI DeleteHelperCommand ( LPCWSTR  pwszMachine,
LPWSTR ppwcArguments,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)

Definition at line 457 of file helper.c.

465{
467 HKEY hKey;
468 DWORD dwError;
469
470 DPRINT("DeleteHelper()\n");
471
472 if (dwArgCount == 2)
473 {
474// ConResPrintf(StdErr, IDS_INVALID_SYNTAX);
475// ConResPrintf(StdErr, IDS_HLP_DEL_HELPER_EX);
476 return 1;
477 }
478
480 while (pEntry != NULL)
481 {
482 if (wcscmp(pEntry->pszShortName, ppwcArguments[2]) == 0)
483 {
484 DPRINT1("remove %S\n", pEntry->pszShortName);
485
486 if (pEntry->pPrev != NULL)
487 pEntry->pPrev->pNext = pEntry->pNext;
488 if (pEntry->pNext != NULL)
489 pEntry->pNext->pPrev = pEntry->pPrev;
490 if (pDllListTail == pEntry)
491 pDllListTail = pEntry->pPrev;
492 if (pDllListHead == pEntry)
493 pDllListHead = pEntry->pNext;
494 pEntry->pPrev = NULL;
495 pEntry->pNext = NULL;
496
499 0,
500 KEY_WRITE,
501 &hKey);
502 if (dwError == ERROR_SUCCESS)
503 {
504 RegDeleteValue(hKey, pEntry->pszValueName);
506 }
507
509
510 return 1;
511 }
512
513 pEntry = pEntry->pNext;
514 }
515
516 return ERROR_SUCCESS;
517}
#define REG_NETSH_PATH
Definition: precomp.h:37
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
FxAutoRegKey hKey
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
PDLL_LIST_ENTRY pDllListHead
Definition: helper.c:17
static VOID FreeHelperDll(_In_ PDLL_LIST_ENTRY pEntry)
Definition: helper.c:88
PDLL_LIST_ENTRY pDllListTail
Definition: helper.c:18
#define KEY_WRITE
Definition: nt_native.h:1031
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: precomp.h:43
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegDeleteValue
Definition: winreg.h:508

Referenced by CreateRootContext().

◆ HelpCommand()

DWORD WINAPI HelpCommand ( LPCWSTR  pwszMachine,
LPWSTR ppwcArguments,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)

Definition at line 116 of file help.c.

124{
125 PCONTEXT_ENTRY pContext;
126
128
129 pContext = pCurrentContext;
130 if (pContext == NULL)
131 {
132 DPRINT1("HelpCommand: invalid context %p\n", pContext);
133 return 1;
134 }
135
136 HelpContext(pContext);
137
139 {
142 while (pContext != NULL)
143 {
144 ConPrintf(StdOut, L" %s", pContext->pszContextName);
145 pContext = pContext->pNext;
146 }
147 ConPuts(StdOut, L"\n");
148 }
149 ConPuts(StdOut, L"\n");
150
151 return ERROR_SUCCESS;
152}
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
static VOID HelpContext(PCONTEXT_ENTRY pContext)
Definition: help.c:39
#define IDS_HELP_HEADER
Definition: resource.h:18
#define IDS_SUBCONTEXT_HEADER
Definition: resource.h:19
Definition: precomp.h:98
PWSTR pszContextName
Definition: precomp.h:104
struct _CONTEXT_ENTRY * pSubContextHead
Definition: precomp.h:114
struct _CONTEXT_ENTRY * pNext
Definition: precomp.h:100

Referenced by CreateRootContext(), help_main(), InterpretCmd(), and main().

◆ HelpGroup()

VOID HelpGroup ( PCOMMAND_GROUP  pGroup)

Definition at line 93 of file help.c.

95{
96 PCOMMAND_ENTRY pCommand;
97 WCHAR szBuffer[64];
98
100
101 ConPrintf(StdOut, L"\nCommands in this context:\n");
102
103 pCommand = pGroup->pCommandListHead;
104 while (pCommand != NULL)
105 {
106 swprintf(szBuffer, L"%s %s", pGroup->pwszCmdGroupToken, pCommand->pwszCmdToken);
107 ConPrintf(StdOut, L"%-15s - ", szBuffer);
109 pCommand = pCommand->pNext;
110 }
111}
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define swprintf
Definition: precomp.h:40
Definition: precomp.h:73
LPCWSTR pwszCmdToken
Definition: precomp.h:77
DWORD dwShortCmdHelpToken
Definition: precomp.h:79
struct _COMMAND_ENTRY * pNext
Definition: precomp.h:75
PCOMMAND_ENTRY pCommandListHead
Definition: precomp.h:93
LPCWSTR pwszCmdGroupToken
Definition: precomp.h:89
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by InterpretCommand().

◆ InterpretCommand()

BOOL InterpretCommand ( LPWSTR argv,
DWORD  dwArgCount 
)

◆ InterpretInteractive()

VOID InterpretInteractive ( VOID  )

Definition at line 188 of file interpreter.c.

189{
190 WCHAR input_line[MAX_STRING_SIZE];
191 LPWSTR args_vector[MAX_ARGS_COUNT];
192 DWORD dwArgCount = 0;
193 BOOL bWhiteSpace = TRUE;
194 BOOL bRun = TRUE;
195 LPWSTR ptr;
196
197 while (bRun != FALSE)
198 {
199 dwArgCount = 0;
200 memset(args_vector, 0, sizeof(args_vector));
201
202 /* Shown just before the input where the user places commands */
203// ConResPuts(StdOut, IDS_APP_PROMPT);
204 ConPuts(StdOut, L"netsh");
206 {
207 ConPuts(StdOut, L" ");
209 }
210 ConPuts(StdOut, L">");
211
212 /* Get input from the user. */
213 fgetws(input_line, MAX_STRING_SIZE, stdin);
214
215 ptr = input_line;
216 while (*ptr != 0)
217 {
218 if (iswspace(*ptr) || *ptr == L'\n')
219 {
220 *ptr = 0;
221 bWhiteSpace = TRUE;
222 }
223 else
224 {
225 if ((bWhiteSpace != FALSE) && (dwArgCount < MAX_ARGS_COUNT))
226 {
227 args_vector[dwArgCount] = ptr;
228 dwArgCount++;
229 }
230 bWhiteSpace = FALSE;
231 }
232 ptr++;
233 }
234
235 /* Send the string to find the command */
236 bRun = InterpretCommand(args_vector, dwArgCount);
237 }
238}
BOOL InterpretCommand(_In_ LPWSTR *argv, _In_ DWORD dwArgCount)
Definition: interpreter.c:18
#define MAX_STRING_SIZE
Definition: precomp.h:34
#define MAX_ARGS_COUNT
Definition: precomp.h:35
unsigned int BOOL
Definition: ntddk_ex.h:94
#define iswspace(_c)
Definition: ctype.h:669
#define stdin
Definition: stdio.h:98
static PVOID ptr
Definition: dispmode.c:27
#define memset(x, y, z)
Definition: compat.h:39
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by wmain().

◆ InterpretScript()

BOOL InterpretScript ( LPWSTR  pszFileName)

Definition at line 183 of file interpreter.c.

184{
185 LPWSTR args_vector[MAX_ARGS_COUNT];
186 INT args_count = 0;
187 BOOL bWhiteSpace = TRUE;
188 BOOL bQuote = FALSE;
189 LPWSTR ptr;
190
191 memset(args_vector, 0, sizeof(args_vector));
192
193 bQuote = FALSE;
194 ptr = input_line;
195 while (*ptr != 0)
196 {
197 if (*ptr == L'"')
198 bQuote = !bQuote;
199
200 if ((iswspace(*ptr) && (bQuote == FALSE))|| *ptr == L'\n')
201 {
202 *ptr = 0;
203 bWhiteSpace = TRUE;
204 }
205 else
206 {
207 if ((bWhiteSpace != FALSE) && (bQuote == FALSE) && (args_count < MAX_ARGS_COUNT))
208 {
209 args_vector[args_count] = ptr;
210 args_count++;
211 }
212
213 bWhiteSpace = FALSE;
214 }
215
216 ptr++;
217 }
218
219 /* sends the string to find the command */
220 return InterpretCmd(args_count, args_vector);
221}
BOOL InterpretCmd(int argc, LPWSTR *argv)
Definition: interpreter.c:108
int32_t INT
Definition: typedefs.h:58

◆ LoadHelpers()

VOID LoadHelpers ( VOID  )

Definition at line 241 of file helper.c.

242{
243 PWSTR pszNameBuffer = NULL;
244 PWSTR pszValueBuffer = NULL;
245 HKEY hKey;
246 DWORD dwValueCount, dwMaxNameLength, dwMaxValueLength;
247 DWORD dwNameLength, dwValueLength, dwType;
248 DWORD dwIndex, dwError;
249
250 DPRINT1("LoadHelpers()\n");
251
254 0,
255 KEY_READ,
256 &hKey);
257 if (dwError != ERROR_SUCCESS)
258 return;
259
260 dwError = RegQueryInfoKeyW(hKey,
261 NULL,
262 NULL,
263 NULL,
264 NULL,
265 NULL,
266 NULL,
267 &dwValueCount,
268 &dwMaxNameLength,
269 &dwMaxValueLength,
270 NULL,
271 NULL);
272 if (dwError != ERROR_SUCCESS)
273 goto done;
274
275 pszNameBuffer = HeapAlloc(GetProcessHeap(), 0,
276 (dwMaxNameLength + 1) * sizeof(WCHAR));
277 if (pszNameBuffer == NULL)
278 goto done;
279
280 pszValueBuffer = HeapAlloc(GetProcessHeap(), 0,
281 dwMaxValueLength + sizeof(WCHAR));
282 if (pszValueBuffer == NULL)
283 goto done;
284
285 for (dwIndex = 0; dwIndex < dwValueCount; dwIndex++)
286 {
287 dwNameLength = dwMaxNameLength + 1;
288 dwValueLength = dwMaxValueLength + sizeof(WCHAR);
289 dwError = RegEnumValueW(hKey,
290 dwIndex,
291 pszNameBuffer,
292 &dwNameLength,
293 NULL,
294 &dwType,
295 (PBYTE)pszValueBuffer,
296 &dwValueLength);
297 if (dwError != ERROR_SUCCESS)
298 break;
299
300 DPRINT1("Dll: %S --> %S %lu\n", pszNameBuffer, pszValueBuffer, dwError);
301 LoadHelperDll(pszValueBuffer, FALSE);
302 }
303
304done:
305 if (pszValueBuffer)
306 HeapFree(GetProcessHeap(), 0, pszValueBuffer);
307
308 if (pszNameBuffer)
309 HeapFree(GetProcessHeap(), 0, pszNameBuffer);
310
312
313 StartHelpers();
314}
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3662
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define KEY_READ
Definition: nt_native.h:1023
BYTE * PBYTE
Definition: pedump.c:66
uint16_t * PWSTR
Definition: typedefs.h:56

Referenced by wmain().

◆ ShowHelperCommand()

DWORD WINAPI ShowHelperCommand ( LPCWSTR  pwszMachine,
PWSTR ppwcArguments,
DWORD  dwCurrentIndex,
DWORD  dwArgCount,
DWORD  dwFlags,
LPCVOID  pvData,
BOOL pbDone 
)

◆ UnloadHelpers()

VOID UnloadHelpers ( VOID  )

Definition at line 318 of file helper.c.

319{
321
322 while (pDllListHead != NULL)
323 {
325 pDllListHead = pEntry->pNext;
326
327// if (pEntry->Attributes.pfnStop)
328// pEntry->Attributes.pfnStop(0);
329
331 }
332
334}

Referenced by wmain().

Variable Documentation

◆ pCurrentContext

PCONTEXT_ENTRY pCurrentContext
extern

◆ pRootContext