ReactOS 0.4.16-dev-2613-g9533ad7
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 DWORD nPaddedLength)
53{
55
57 if (dwLength < nPaddedLength)
58 PrintPadding(L' ', nPaddedLength - dwLength);
59}
60
61
62VOID
64 WCHAR chr,
65 DWORD nPaddedLength)
66{
67 DWORD 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{
98
99 va_start(args, dwMessage);
103 dwMessage,
105 &args);
106 va_end(args);
107}
108
109VOID
111 DWORD dwMessage)
112{
116 dwMessage,
118}
119
120
121VOID
123 DWORD dwMessage,
124 DWORD nPaddedLength)
125{
127
131 dwMessage,
133
134 if (dwLength < nPaddedLength)
135 PrintPadding(L' ', nPaddedLength - dwLength);
136}
137
138
139VOID
141 DWORD dwError)
142{
143 WCHAR szErrorBuffer[16];
145 PWSTR pErrorInserts[2] = {NULL, NULL};
146
147 if (dwError >= MIN_LANMAN_MESSAGE_ID && dwError <= MAX_LANMAN_MESSAGE_ID)
148 {
152 dwError,
154 (LPWSTR)&pBuffer,
155 0,
156 NULL);
157 if (pBuffer)
158 {
159 ConPrintf(StdErr, L"%s\n", pBuffer);
161 pBuffer = NULL;
162 }
163 }
164 else
165 {
168 NULL,
169 dwError,
171 (LPWSTR)&pBuffer,
172 0,
173 NULL);
174 if (pBuffer)
175 {
176 ConPrintf(StdErr, L"%s\n", pBuffer);
178 pBuffer = NULL;
179 }
180 }
181
182 if (dwError != ERROR_SUCCESS)
183 {
184 /* Format insert for the 3514 message */
185 swprintf(szErrorBuffer, L"%lu", dwError);
186 pErrorInserts[0] = szErrorBuffer;
187
188 /* Format and print the 3514 message */
192 3514,
194 (LPWSTR)&pBuffer,
195 0,
196 (va_list *)pErrorInserts);
197 if (pBuffer)
198 {
199 ConPrintf(StdErr, L"%s\n", pBuffer);
201 pBuffer = NULL;
202 }
203 }
204}
205
206
207VOID
209 DWORD dwMessage)
210{
212
217 dwMessage,
219 (LPWSTR)&pBuffer,
220 0,
221 NULL);
222 if (pBuffer)
223 {
225 ConPuts(StdOut, L"\n");
227 pBuffer = NULL;
228 }
229}
230
231
232VOID
234 LPWSTR lpInput,
236 BOOL bEcho)
237{
238 DWORD dwOldMode;
239 DWORD dwRead = 0;
241 LPWSTR p;
242 PCHAR pBuf;
243
244 pBuf = HeapAlloc(GetProcessHeap(), 0, dwLength - 1);
245 ZeroMemory(lpInput, dwLength * sizeof(WCHAR));
247 GetConsoleMode(hFile, &dwOldMode);
248
250
251 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
252
253 MultiByteToWideChar(CP_OEMCP, 0, pBuf, dwRead, lpInput, dwLength - 1);
254 HeapFree(GetProcessHeap(), 0, pBuf);
255
256 for (p = lpInput; *p; p++)
257 {
258 if (*p == L'\x0d')
259 {
260 *p = L'\0';
261 break;
262 }
263 }
264
265 SetConsoleMode(hFile, dwOldMode);
266}
267
268
269int wmain(int argc, WCHAR **argv)
270{
271 WCHAR szDllBuffer[MAX_PATH];
272 PCOMMAND cmdptr;
273 int nResult = 0;
274 BOOL bRun = FALSE;
275
276 /* Initialize the Console Standard Streams */
278
279 /* Load netmsg.dll */
280 GetSystemDirectoryW(szDllBuffer, ARRAYSIZE(szDllBuffer));
281 wcscat(szDllBuffer, L"\\netmsg.dll");
282
283 hModuleNetMsg = LoadLibrary(szDllBuffer);
284 if (hModuleNetMsg == NULL)
285 {
286 ConPrintf(StdErr, L"Failed to load netmsg.dll\n");
287 return 1;
288 }
289
290 if (argc < 2)
291 {
292 nResult = 1;
293 goto done;
294 }
295
296 /* Scan the command table */
297 for (cmdptr = cmds; cmdptr->name; cmdptr++)
298 {
299 if (_wcsicmp(argv[1], cmdptr->name) == 0)
300 {
301 nResult = cmdptr->func(argc, argv);
302 bRun = TRUE;
303 break;
304 }
305 }
306
307done:
308 if (bRun == FALSE)
309 {
310 PrintMessageString(4381);
311 ConPuts(StdOut, L"\n");
312 PrintNetMessage(MSG_NET_SYNTAX);
313 }
314
315 if (hModuleNetMsg != NULL)
317
318 return nResult;
319}
320
322{
323 ConPuts(StdOut, L"This command is not implemented yet\n");
324 return 1;
325}
HMODULE hModuleNetMsg
Definition: main.c:46
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:208
DWORD TranslateAppMessage(DWORD dwMessage)
Definition: main.c:79
INT unimplemented(INT argc, WCHAR **argv)
Definition: main.c:321
VOID PrintMessageStringV(DWORD dwMessage,...)
Definition: main.c:93
VOID PrintPaddedMessageString(DWORD dwMessage, DWORD nPaddedLength)
Definition: main.c:122
struct _COMMAND * PCOMMAND
VOID PrintErrorMessage(DWORD dwError)
Definition: main.c:140
VOID PrintPadding(WCHAR chr, DWORD nPaddedLength)
Definition: main.c:63
struct _COMMAND COMMAND
VOID PrintPaddedResourceString(UINT uID, DWORD nPaddedLength)
Definition: main.c:50
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:110
VOID ReadFromConsole(LPWSTR lpInput, DWORD dwLength, BOOL bEcho)
Definition: main.c:233
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:94
INT cmdUser(INT argc, WCHAR **argv)
Definition: cmdUser.c:1148
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: conutils_noros.h:8
#define ConInitStdStreams()
Definition: conutils_noros.h:5
void ConPrintf(FILE *fp, LPCWSTR psz,...)
#define StdOut
Definition: conutils_noros.h:6
#define StdErr
Definition: conutils_noros.h:7
void ConResPuts(FILE *fp, UINT nID)
#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:1571
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2232
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
MonoAssembly int argc
Definition: metahost.c:107
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
#define swprintf
Definition: precomp.h:40
#define L(x)
Definition: resources.c:13
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 ZeroMemory
Definition: minwinbase.h:31
#define argv
Definition: mplay32.c:18
_In_ HANDLE hFile
Definition: mswsock.h:90
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
#define UNICODE_NULL
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:835
INT ConMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1028
short WCHAR
Definition: pedump.c:58
#define INT
Definition: polytest.cpp:20
_In_ UINT uID
Definition: shlwapi.h:156
PVOID pBuffer
int wmain()
Deprecated header file that includes net_sockets.h.
wcscat
#define args
Definition: format.c:66
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
uint16_t * LPWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
char * PCHAR
Definition: typedefs.h:51
#define STD_INPUT_HANDLE
Definition: winbase.h:291
#define LoadLibrary
Definition: winbase.h:3611
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:397
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:396
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:401
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:399
#define ENABLE_ECHO_INPUT
Definition: wincon.h:109
#define ENABLE_LINE_INPUT
Definition: wincon.h:108
#define CP_OEMCP
Definition: winnls.h:249