ReactOS  0.4.12-dev-714-gfaac916
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 
14 typedef struct _COMMAND
15 {
17  INT (*func)(INT, WCHAR**);
18 // VOID (*help)(INT, WCHAR**);
19 } COMMAND, *PCOMMAND;
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"name", unimplemented},
33  {L"pause", cmdPause},
34  {L"print", unimplemented},
35  {L"send", unimplemented},
36  {L"session", unimplemented},
37  {L"share", unimplemented},
38  {L"start", cmdStart},
39  {L"statistics", cmdStatistics},
40  {L"stop", cmdStop},
41  {L"time", unimplemented},
42  {L"use", cmdUse},
43  {L"user", cmdUser},
44  {L"view", unimplemented},
45  {NULL, NULL}
46 };
47 
49 
50 
51 VOID
53  UINT uID,
54  INT nPaddedLength)
55 {
56  INT nLength;
57 
58  nLength = ConResPuts(StdOut, uID);
59  if (nLength < nPaddedLength)
60  PrintPadding(L' ', nPaddedLength - nLength);
61 }
62 
63 
64 VOID
66  WCHAR chr,
67  INT nPaddedLength)
68 {
69  INT i;
70  WCHAR szMsgBuffer[MAX_BUFFER_SIZE];
71 
72  for (i = 0; i < nPaddedLength; i++)
73  szMsgBuffer[i] = chr;
74  szMsgBuffer[nPaddedLength] = UNICODE_NULL;
75 
76  ConPuts(StdOut, szMsgBuffer);
77 }
78 
79 
80 VOID
82  DWORD dwError)
83 {
84  WCHAR szErrorBuffer[16];
85  PWSTR pBuffer;
86  PWSTR pErrorInserts[2] = {NULL, NULL};
87 
88  if (dwError >= MIN_LANMAN_MESSAGE_ID && dwError <= MAX_LANMAN_MESSAGE_ID)
89  {
93  dwError,
95  (LPWSTR)&pBuffer,
96  0,
97  NULL);
98  if (pBuffer)
99  {
100  ConPrintf(StdErr, L"%s\n", pBuffer);
102  pBuffer = NULL;
103  }
104  }
105  else
106  {
109  NULL,
110  dwError,
112  (LPWSTR)&pBuffer,
113  0,
114  NULL);
115  if (pBuffer)
116  {
117  ConPrintf(StdErr, L"%s\n", pBuffer);
119  pBuffer = NULL;
120  }
121  }
122 
123  if (dwError != ERROR_SUCCESS)
124  {
125  /* Format insert for the 3514 message */
126  swprintf(szErrorBuffer, L"%lu", dwError);
127  pErrorInserts[0] = szErrorBuffer;
128 
129  /* Format and print the 3514 message */
133  3514,
135  (LPWSTR)&pBuffer,
136  0,
137  (va_list *)pErrorInserts);
138  if (pBuffer)
139  {
140  ConPrintf(StdErr, L"%s\n", pBuffer);
142  pBuffer = NULL;
143  }
144  }
145 }
146 
147 
148 VOID
150  DWORD dwMessage)
151 {
152  PWSTR pBuffer;
153 
158  dwMessage,
160  (LPWSTR)&pBuffer,
161  0,
162  NULL);
163  if (pBuffer)
164  {
165  ConPrintf(StdOut, L"%s\n", pBuffer);
167  pBuffer = NULL;
168  }
169 }
170 
171 
172 VOID
174  LPWSTR lpInput,
175  DWORD dwLength,
176  BOOL bEcho)
177 {
178  DWORD dwOldMode;
179  DWORD dwRead = 0;
180  HANDLE hFile;
181  LPWSTR p;
182  PCHAR pBuf;
183 
184  pBuf = HeapAlloc(GetProcessHeap(), 0, dwLength - 1);
185  ZeroMemory(lpInput, dwLength * sizeof(WCHAR));
187  GetConsoleMode(hFile, &dwOldMode);
188 
190 
191  ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
192 
193  MultiByteToWideChar(CP_OEMCP, 0, pBuf, dwRead, lpInput, dwLength - 1);
194  HeapFree(GetProcessHeap(), 0, pBuf);
195 
196  for (p = lpInput; *p; p++)
197  {
198  if (*p == L'\x0d')
199  {
200  *p = L'\0';
201  break;
202  }
203  }
204 
205  SetConsoleMode(hFile, dwOldMode);
206 }
207 
208 
209 int wmain(int argc, WCHAR **argv)
210 {
211  WCHAR szDllBuffer[MAX_PATH];
212  PCOMMAND cmdptr;
213  int nResult = 0;
214  BOOL bRun = FALSE;
215 
216  /* Initialize the Console Standard Streams */
218 
219  /* Load netmsg.dll */
220  GetSystemDirectoryW(szDllBuffer, ARRAYSIZE(szDllBuffer));
221  wcscat(szDllBuffer, L"\\netmsg.dll");
222 
223  hModuleNetMsg = LoadLibrary(szDllBuffer);
224  if (hModuleNetMsg == NULL)
225  {
226  ConPrintf(StdErr, L"Failed to load netmsg.dll\n");
227  return 1;
228  }
229 
230  if (argc < 2)
231  {
232  nResult = 1;
233  goto done;
234  }
235 
236  /* Scan the command table */
237  for (cmdptr = cmds; cmdptr->name; cmdptr++)
238  {
239  if (_wcsicmp(argv[1], cmdptr->name) == 0)
240  {
241  nResult = cmdptr->func(argc, argv);
242  bRun = TRUE;
243  break;
244  }
245  }
246 
247 done:
248  if (bRun == FALSE)
249  PrintNetMessage(MSG_NET_SYNTAX);
250 
251  if (hModuleNetMsg != NULL)
253 
254  return nResult;
255 }
256 
258 {
259  ConPuts(StdOut, L"This command is not implemented yet\n");
260  return 1;
261 }
signed char * PCHAR
Definition: retypes.h:7
struct _COMMAND COMMAND
GLenum func
Definition: glext.h:6028
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LoadLibrary
Definition: winbase.h:3676
__wchar_t WCHAR
Definition: xmlstorage.h:180
uint16_t * PWSTR
Definition: typedefs.h:54
#define FORMAT_MESSAGE_ARGUMENT_ARRAY
Definition: winbase.h:405
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1571
_In_ DWORD nLength
Definition: wincon.h:461
COMMAND cmds[]
Definition: main.c:21
INT unimplemented(INT argc, WCHAR **argv)
Definition: main.c:257
BOOL bEcho
Definition: batch.c:68
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
INT cmdStart(INT argc, WCHAR **argv)
Definition: cmdStart.c:163
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
INT(* func)(INT, WCHAR **)
Definition: main.c:17
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:149
#define argv
Definition: mplay32.c:18
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
int wmain(int argc, WCHAR *argv[])
Definition: main.c:269
int32_t INT
Definition: typedefs.h:56
VOID ReadFromConsole(LPWSTR lpInput, DWORD dwLength, BOOL bEcho)
Definition: main.c:173
#define ENABLE_ECHO_INPUT
Definition: wincon.h:77
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
#define ConInitStdStreams()
Definition: stream.h:122
#define UNICODE_NULL
struct _COMMAND * PCOMMAND
#define MIN_LANMAN_MESSAGE_ID
Definition: lmcons.h:10
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
VOID PrintErrorMessage(DWORD dwError)
Definition: main.c:81
INT cmdComputer(INT argc, WCHAR **argv)
Definition: cmdComputer.c:11
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
INT cmdConfig(INT argc, WCHAR **argv)
Definition: cmdConfig.c:151
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
INT cmdHelp(INT argc, WCHAR **argv)
Definition: cmdHelp.c:12
char * va_list
Definition: acmsvcex.h:78
INT cmdHelpMsg(INT argc, WCHAR **argv)
Definition: cmdHelpMsg.c:14
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
#define FreeLibrary(x)
Definition: compat.h:405
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define MAX_LANMAN_MESSAGE_ID
Definition: lmcons.h:11
#define MAX_BUFFER_SIZE
Definition: main.c:12
static DWORD DWORD * dwLength
Definition: fusion.c:83
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
unsigned int UINT
Definition: ndis.h:50
INT cmdAccounts(INT argc, WCHAR **argv)
Definition: cmdAccounts.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ENABLE_LINE_INPUT
Definition: wincon.h:76
#define StdErr
Definition: stream.h:77
INT cmdContinue(INT argc, WCHAR **argv)
Definition: cmdContinue.c:12
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
INT cmdUse(INT argc, WCHAR **argv)
Definition: cmdUse.c:102
INT cmdUser(INT argc, WCHAR **argv)
Definition: cmdUser.c:616
INT cmdStop(INT argc, WCHAR **argv)
Definition: cmdStop.c:12
_In_ HANDLE hFile
Definition: mswsock.h:90
int chr(char *serport)
Definition: gdblib.c:152
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
VOID PrintPaddedResourceString(UINT uID, INT nPaddedLength)
Definition: main.c:52
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT cmdStatistics(INT argc, WCHAR **argv)
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define INT
Definition: msvc.h:26
INT cmdLocalGroup(INT argc, WCHAR **argv)
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:65
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define MultiByteToWideChar
Definition: compat.h:100
#define StdOut
Definition: stream.h:76
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:845
INT cmdPause(INT argc, WCHAR **argv)
Definition: cmdPause.c:12
HMODULE hModuleNetMsg
Definition: main.c:48
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
INT cmdGroup(INT argc, WCHAR **argv)
Definition: cmdGroup.c:154
Definition: main.c:14
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define CP_OEMCP
Definition: winnls.h:228
#define HeapFree(x, y, z)
Definition: compat.h:394
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
WCHAR * name
Definition: main.c:16