ReactOS 0.4.15-dev-7788-g1ad9096
main.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/main.c
5 * PURPOSE:
6 *
7 * PROGRAMMERS: Magnus Olsen (greatlord@reactos.org)
8 */
9
10#include "net.h"
11
12#define MAX_BUFFER_SIZE 4096
13
14typedef struct _COMMAND
15{
17 INT (*func)(INT, WCHAR**);
18// VOID (*help)(INT, WCHAR**);
20
22{
23 {L"accounts", cmdAccounts},
24 {L"computer", cmdComputer},
25 {L"config", cmdConfig},
26 {L"continue", cmdContinue},
27 {L"file", unimplemented},
28 {L"group", cmdGroup},
29 {L"help", cmdHelp},
30 {L"helpmsg", cmdHelpMsg},
31 {L"localgroup", cmdLocalGroup},
32 {L"pause", cmdPause},
33 {L"session", cmdSession},
34 {L"share", cmdShare},
35 {L"start", cmdStart},
36 {L"statistics", cmdStatistics},
37 {L"stop", cmdStop},
38 {L"syntax", cmdSyntax},
39 {L"time", unimplemented},
40 {L"use", cmdUse},
41 {L"user", cmdUser},
42 {L"view", unimplemented},
43 {NULL, NULL}
44};
45
47
48
49VOID
51 UINT uID,
52 INT nPaddedLength)
53{
55
57 if (nLength < nPaddedLength)
58 PrintPadding(L' ', nPaddedLength - nLength);
59}
60
61
62VOID
64 WCHAR chr,
65 INT nPaddedLength)
66{
67 INT i;
68 WCHAR szMsgBuffer[MAX_BUFFER_SIZE];
69
70 for (i = 0; i < nPaddedLength; i++)
71 szMsgBuffer[i] = chr;
72 szMsgBuffer[nPaddedLength] = UNICODE_NULL;
73
74 ConPuts(StdOut, szMsgBuffer);
75}
76
77
80 DWORD dwMessage)
81{
82 switch (dwMessage)
83 {
84 case NERR_Success:
85 return 3500; // APPERR_3500
86 case ERROR_MORE_DATA:
87 return 3513; // APPERR_3513
88 }
89 return dwMessage;
90}
91
92VOID
94 DWORD dwMessage,
95 ...)
96{
99
100 va_start(args, dwMessage);
101
104 dwMessage,
106 (LPWSTR)&pBuffer,
107 0,
108 &args);
109 va_end(args);
110
111 if (pBuffer)
112 {
115 pBuffer = NULL;
116 }
117}
118
119VOID
121 DWORD dwMessage)
122{
124
128 dwMessage,
130 (LPWSTR)&pBuffer,
131 0,
132 NULL);
133 if (pBuffer)
134 {
137 pBuffer = NULL;
138 }
139}
140
141
142VOID
144 DWORD dwMessage,
145 INT nPaddedLength)
146{
149
153 dwMessage,
155 (LPWSTR)&pBuffer,
156 0,
157 NULL);
158 if (pBuffer)
159 {
162 pBuffer = NULL;
163 }
164
165 if (dwLength < (DWORD)nPaddedLength)
166 PrintPadding(L' ', (DWORD)nPaddedLength - dwLength);
167}
168
169
170VOID
172 DWORD dwError)
173{
174 WCHAR szErrorBuffer[16];
176 PWSTR pErrorInserts[2] = {NULL, NULL};
177
178 if (dwError >= MIN_LANMAN_MESSAGE_ID && dwError <= MAX_LANMAN_MESSAGE_ID)
179 {
183 dwError,
185 (LPWSTR)&pBuffer,
186 0,
187 NULL);
188 if (pBuffer)
189 {
190 ConPrintf(StdErr, L"%s\n", pBuffer);
192 pBuffer = NULL;
193 }
194 }
195 else
196 {
199 NULL,
200 dwError,
202 (LPWSTR)&pBuffer,
203 0,
204 NULL);
205 if (pBuffer)
206 {
207 ConPrintf(StdErr, L"%s\n", pBuffer);
209 pBuffer = NULL;
210 }
211 }
212
213 if (dwError != ERROR_SUCCESS)
214 {
215 /* Format insert for the 3514 message */
216 swprintf(szErrorBuffer, L"%lu", dwError);
217 pErrorInserts[0] = szErrorBuffer;
218
219 /* Format and print the 3514 message */
223 3514,
225 (LPWSTR)&pBuffer,
226 0,
227 (va_list *)pErrorInserts);
228 if (pBuffer)
229 {
230 ConPrintf(StdErr, L"%s\n", pBuffer);
232 pBuffer = NULL;
233 }
234 }
235}
236
237
238VOID
240 DWORD dwMessage)
241{
243
248 dwMessage,
250 (LPWSTR)&pBuffer,
251 0,
252 NULL);
253 if (pBuffer)
254 {
256 ConPuts(StdOut, L"\n");
258 pBuffer = NULL;
259 }
260}
261
262
263VOID
265 LPWSTR lpInput,
267 BOOL bEcho)
268{
269 DWORD dwOldMode;
270 DWORD dwRead = 0;
272 LPWSTR p;
273 PCHAR pBuf;
274
275 pBuf = HeapAlloc(GetProcessHeap(), 0, dwLength - 1);
276 ZeroMemory(lpInput, dwLength * sizeof(WCHAR));
278 GetConsoleMode(hFile, &dwOldMode);
279
281
282 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
283
284 MultiByteToWideChar(CP_OEMCP, 0, pBuf, dwRead, lpInput, dwLength - 1);
285 HeapFree(GetProcessHeap(), 0, pBuf);
286
287 for (p = lpInput; *p; p++)
288 {
289 if (*p == L'\x0d')
290 {
291 *p = L'\0';
292 break;
293 }
294 }
295
296 SetConsoleMode(hFile, dwOldMode);
297}
298
299
300int wmain(int argc, WCHAR **argv)
301{
302 WCHAR szDllBuffer[MAX_PATH];
303 PCOMMAND cmdptr;
304 int nResult = 0;
305 BOOL bRun = FALSE;
306
307 /* Initialize the Console Standard Streams */
309
310 /* Load netmsg.dll */
311 GetSystemDirectoryW(szDllBuffer, ARRAYSIZE(szDllBuffer));
312 wcscat(szDllBuffer, L"\\netmsg.dll");
313
314 hModuleNetMsg = LoadLibrary(szDllBuffer);
315 if (hModuleNetMsg == NULL)
316 {
317 ConPrintf(StdErr, L"Failed to load netmsg.dll\n");
318 return 1;
319 }
320
321 if (argc < 2)
322 {
323 nResult = 1;
324 goto done;
325 }
326
327 /* Scan the command table */
328 for (cmdptr = cmds; cmdptr->name; cmdptr++)
329 {
330 if (_wcsicmp(argv[1], cmdptr->name) == 0)
331 {
332 nResult = cmdptr->func(argc, argv);
333 bRun = TRUE;
334 break;
335 }
336 }
337
338done:
339 if (bRun == FALSE)
340 {
341 PrintMessageString(4381);
342 ConPuts(StdOut, L"\n");
343 PrintNetMessage(MSG_NET_SYNTAX);
344 }
345
346 if (hModuleNetMsg != NULL)
348
349 return nResult;
350}
351
353{
354 ConPuts(StdOut, L"This command is not implemented yet\n");
355 return 1;
356}
static int argc
Definition: ServiceArgs.c:12
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define ConInitStdStreams()
Definition: fc.c:13
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
HMODULE hModuleNetMsg
Definition: main.c:46
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
DWORD TranslateAppMessage(DWORD dwMessage)
Definition: main.c:79
VOID PrintPaddedMessageString(DWORD dwMessage, INT nPaddedLength)
Definition: main.c:143
INT unimplemented(INT argc, WCHAR **argv)
Definition: main.c:352
VOID PrintMessageStringV(DWORD dwMessage,...)
Definition: main.c:93
struct _COMMAND * PCOMMAND
VOID PrintErrorMessage(DWORD dwError)
Definition: main.c:171
VOID PrintPaddedResourceString(UINT uID, INT nPaddedLength)
Definition: main.c:50
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:63
struct _COMMAND COMMAND
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
VOID ReadFromConsole(LPWSTR lpInput, DWORD dwLength, BOOL bEcho)
Definition: main.c:264
COMMAND cmds[]
Definition: main.c:21
#define MAX_BUFFER_SIZE
Definition: main.c:12
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL bEcho
Definition: batch.c:73
INT cmdAccounts(INT argc, WCHAR **argv)
Definition: cmdAccounts.c:13
INT cmdComputer(INT argc, WCHAR **argv)
Definition: cmdComputer.c:11
INT cmdConfig(INT argc, WCHAR **argv)
Definition: cmdConfig.c:165
INT cmdContinue(INT argc, WCHAR **argv)
Definition: cmdContinue.c:12
INT cmdGroup(INT argc, WCHAR **argv)
Definition: cmdGroup.c:154
INT cmdHelpMsg(INT argc, WCHAR **argv)
Definition: cmdHelpMsg.c:14
INT cmdHelp(INT argc, WCHAR **argv)
Definition: cmdHelp.c:12
INT cmdSyntax(INT argc, WCHAR **argv)
Definition: cmdHelp.c:180
INT cmdLocalGroup(INT argc, WCHAR **argv)
INT cmdPause(INT argc, WCHAR **argv)
Definition: cmdPause.c:12
INT cmdSession(_In_ INT argc, _In_ WCHAR **argv)
Definition: cmdSession.c:91
INT cmdShare(INT argc, WCHAR **argv)
Definition: cmdShare.c:94
INT cmdStart(INT argc, WCHAR **argv)
Definition: cmdStart.c:172
INT cmdStatistics(INT argc, WCHAR **argv)
INT cmdStop(INT argc, WCHAR **argv)
Definition: cmdStop.c:12
INT cmdUse(INT argc, WCHAR **argv)
Definition: cmdUse.c:104
INT cmdUser(INT argc, WCHAR **argv)
Definition: cmdUser.c:1148
#define ERROR_MORE_DATA
Definition: dderror.h:13
#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 ARRAYSIZE(array)
Definition: filtermapper.c:47
#define GetProcessHeap()
Definition: compat.h:736
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define HeapAlloc
Definition: compat.h:733
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
static DWORD DWORD * dwLength
Definition: fusion.c:86
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1569
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1606
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define swprintf
Definition: precomp.h:40
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum func
Definition: glext.h:6028
GLfloat GLfloat p
Definition: glext.h:8902
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
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define MAX_LANMAN_MESSAGE_ID
Definition: lmcons.h:11
#define MIN_LANMAN_MESSAGE_ID
Definition: lmcons.h:10
#define NERR_Success
Definition: lmerr.h:5
#define argv
Definition: mplay32.c:18
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
#define INT
Definition: polytest.cpp:20
PVOID pBuffer
int wmain()
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
Deprecated header file that includes net_sockets.h.
Definition: main.c:15
WCHAR * name
Definition: main.c:16
INT(* func)(INT, WCHAR **)
Definition: main.c:17
Definition: match.c:390
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
char * PCHAR
Definition: typedefs.h:51
#define ZeroMemory
Definition: winbase.h:1712
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define LoadLibrary
Definition: winbase.h:3797
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:424
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:422
#define ENABLE_ECHO_INPUT
Definition: wincon.h:80
_In_ DWORD nLength
Definition: wincon.h:473
#define ENABLE_LINE_INPUT
Definition: wincon.h:79
#define CP_OEMCP
Definition: winnls.h:231
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184