Author: hbelusca
Date: Thu Sep 25 22:01:42 2014
New Revision: 64291
URL:
http://svn.reactos.org/svn/reactos?rev=64291&view=rev
Log:
[DHCPCSVC]
- Code formatting
- Move ROS service functionalities from BSD module to where it really belongs.
Modified:
trunk/reactos/dll/win32/dhcpcsvc/dhcp/dhclient.c
trunk/reactos/dll/win32/dhcpcsvc/dhcpcsvc.c
trunk/reactos/dll/win32/dhcpcsvc/include/rosdhcp.h
Modified: trunk/reactos/dll/win32/dhcpcsvc/dhcp/dhclient.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/dhcpcsvc/dhcp/dh…
==============================================================================
--- trunk/reactos/dll/win32/dhcpcsvc/dhcp/dhclient.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/dhcpcsvc/dhcp/dhclient.c [iso-8859-1] Thu Sep 25 22:01:42
2014
@@ -55,8 +55,6 @@
#include <rosdhcp.h>
-#include <winsvc.h>
-
#define PERIOD 0x2e
#define hyphenchar(c) ((c) == 0x2d)
#define bslashchar(c) ((c) == 0x5c)
@@ -108,95 +106,10 @@
time_t scripttime;
-static WCHAR ServiceName[] = L"DHCP";
-
-SERVICE_STATUS_HANDLE ServiceStatusHandle = 0;
-SERVICE_STATUS ServiceStatus;
-
-
-/* XXX Implement me */
-int check_arp( struct interface_info *ip, struct client_lease *lp ) {
- return 1;
-}
-
-
-static VOID
-UpdateServiceStatus(DWORD dwState)
-{
- ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
- ServiceStatus.dwCurrentState = dwState;
-
- ServiceStatus.dwControlsAccepted = 0;
-
- ServiceStatus.dwWin32ExitCode = 0;
- ServiceStatus.dwServiceSpecificExitCode = 0;
- ServiceStatus.dwCheckPoint = 0;
-
- if (dwState == SERVICE_START_PENDING ||
- dwState == SERVICE_STOP_PENDING ||
- dwState == SERVICE_PAUSE_PENDING ||
- dwState == SERVICE_CONTINUE_PENDING)
- ServiceStatus.dwWaitHint = 10000;
- else
- ServiceStatus.dwWaitHint = 0;
-
- SetServiceStatus(ServiceStatusHandle,
- &ServiceStatus);
-}
-
-
-static DWORD WINAPI
-ServiceControlHandler(DWORD dwControl,
- DWORD dwEventType,
- LPVOID lpEventData,
- LPVOID lpContext)
-{
- switch (dwControl)
- {
- case SERVICE_CONTROL_STOP:
- UpdateServiceStatus(SERVICE_STOP_PENDING);
- UpdateServiceStatus(SERVICE_STOPPED);
- return ERROR_SUCCESS;
-
- case SERVICE_CONTROL_PAUSE:
- UpdateServiceStatus(SERVICE_PAUSED);
- return ERROR_SUCCESS;
-
- case SERVICE_CONTROL_CONTINUE:
- UpdateServiceStatus(SERVICE_START_PENDING);
- UpdateServiceStatus(SERVICE_RUNNING);
- return ERROR_SUCCESS;
-
- case SERVICE_CONTROL_INTERROGATE:
- SetServiceStatus(ServiceStatusHandle,
- &ServiceStatus);
- return ERROR_SUCCESS;
-
- case SERVICE_CONTROL_SHUTDOWN:
- UpdateServiceStatus(SERVICE_STOP_PENDING);
- UpdateServiceStatus(SERVICE_STOPPED);
- return ERROR_SUCCESS;
-
- default :
- return ERROR_CALL_NOT_IMPLEMENTED;
- }
-}
-
-
-VOID NTAPI
-ServiceMain(DWORD argc, LPWSTR *argv)
-{
- ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
- ServiceControlHandler,
- NULL);
- if (!ServiceStatusHandle)
- {
- DbgPrint("DHCPCSVC: Unable to register service control handler
(%lx)\n", GetLastError());
- return;
- }
-
- UpdateServiceStatus(SERVICE_START_PENDING);
-
+
+int
+init_client(void)
+{
ApiInit();
AdapterInit();
@@ -214,26 +127,23 @@
DbgPrint("DHCPCSVC: PipeInit() failed!\n");
AdapterStop();
ApiFree();
- UpdateServiceStatus(SERVICE_STOPPED);
+ return 0; // FALSE
}
- DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
-
- UpdateServiceStatus(SERVICE_RUNNING);
-
- DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
-
- DH_DbgPrint(MID_TRACE, ("DHCPCSVC: DHCP service is starting up\n"));
-
- dispatch();
-
- DbgPrint("DHCPCSVC: DHCP service is shutting down\n");
-
- //AdapterStop();
- //ApiFree();
+ return 1; // TRUE
+}
+
+void
+stop_client(void)
+{
+ // AdapterStop();
+ // ApiFree();
/* FIXME: Close pipe and kill pipe thread */
-
- UpdateServiceStatus(SERVICE_STOPPED);
+}
+
+/* XXX Implement me */
+int check_arp( struct interface_info *ip, struct client_lease *lp ) {
+ return 1;
}
/*
Modified: trunk/reactos/dll/win32/dhcpcsvc/dhcpcsvc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/dhcpcsvc/dhcpcsv…
==============================================================================
--- trunk/reactos/dll/win32/dhcpcsvc/dhcpcsvc.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/dhcpcsvc/dhcpcsvc.c [iso-8859-1] Thu Sep 25 22:01:42 2014
@@ -7,68 +7,76 @@
*/
#include <rosdhcp.h>
+#include <winsvc.h>
#define NDEBUG
#include <debug.h>
+static WCHAR ServiceName[] = L"DHCP";
+
+SERVICE_STATUS_HANDLE ServiceStatusHandle = 0;
+SERVICE_STATUS ServiceStatus;
+
static HANDLE PipeHandle = INVALID_HANDLE_VALUE;
-DWORD APIENTRY DhcpCApiInitialize(LPDWORD Version) {
+DWORD APIENTRY
+DhcpCApiInitialize(LPDWORD Version)
+{
DWORD PipeMode;
/* Wait for the pipe to be available */
- if (WaitNamedPipeW(DHCP_PIPE_NAME, NMPWAIT_USE_DEFAULT_WAIT))
- {
- /* It's available, let's try to open it */
- PipeHandle = CreateFileW(DHCP_PIPE_NAME,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- 0,
- NULL);
-
- /* Check if we succeeded in opening the pipe */
- if (PipeHandle == INVALID_HANDLE_VALUE)
- {
- /* We didn't */
- return GetLastError();
- }
- else
- {
- /* Change the pipe into message mode */
- PipeMode = PIPE_READMODE_MESSAGE;
- if (!SetNamedPipeHandleState(PipeHandle, &PipeMode, NULL, NULL))
- {
- /* Mode change failed */
- CloseHandle(PipeHandle);
- PipeHandle = INVALID_HANDLE_VALUE;
- return GetLastError();
- }
- else
- {
- /* We're good to go */
- *Version = 2;
- return NO_ERROR;
- }
- }
- }
- else
+ if (!WaitNamedPipeW(DHCP_PIPE_NAME, NMPWAIT_USE_DEFAULT_WAIT))
{
/* No good, we failed */
return GetLastError();
}
-}
-
-VOID APIENTRY DhcpCApiCleanup() {
+
+ /* It's available, let's try to open it */
+ PipeHandle = CreateFileW(DHCP_PIPE_NAME,
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ 0,
+ NULL);
+
+ /* Check if we succeeded in opening the pipe */
+ if (PipeHandle == INVALID_HANDLE_VALUE)
+ {
+ /* We didn't */
+ return GetLastError();
+ }
+
+ /* Change the pipe into message mode */
+ PipeMode = PIPE_READMODE_MESSAGE;
+ if (!SetNamedPipeHandleState(PipeHandle, &PipeMode, NULL, NULL))
+ {
+ /* Mode change failed */
+ CloseHandle(PipeHandle);
+ PipeHandle = INVALID_HANDLE_VALUE;
+ return GetLastError();
+ }
+ else
+ {
+ /* We're good to go */
+ *Version = 2;
+ return NO_ERROR;
+ }
+}
+
+VOID APIENTRY
+DhcpCApiCleanup(VOID)
+{
CloseHandle(PipeHandle);
PipeHandle = INVALID_HANDLE_VALUE;
}
-DWORD APIENTRY DhcpQueryHWInfo( DWORD AdapterIndex,
- PDWORD MediaType,
- PDWORD Mtu,
- PDWORD Speed ) {
+DWORD APIENTRY
+DhcpQueryHWInfo(DWORD AdapterIndex,
+ PDWORD MediaType,
+ PDWORD Mtu,
+ PDWORD Speed)
+{
COMM_DHCP_REQ Req;
COMM_DHCP_REPLY Reply;
DWORD BytesRead;
@@ -89,16 +97,18 @@
return 0;
}
- if( !Reply.Reply ) return 0;
- else {
- *MediaType = Reply.QueryHWInfo.MediaType;
- *Mtu = Reply.QueryHWInfo.Mtu;
- *Speed = Reply.QueryHWInfo.Speed;
- return 1;
- }
-}
-
-DWORD APIENTRY DhcpLeaseIpAddress( DWORD AdapterIndex ) {
+ if (Reply.Reply == 0)
+ return 0;
+
+ *MediaType = Reply.QueryHWInfo.MediaType;
+ *Mtu = Reply.QueryHWInfo.Mtu;
+ *Speed = Reply.QueryHWInfo.Speed;
+ return 1;
+}
+
+DWORD APIENTRY
+DhcpLeaseIpAddress(DWORD AdapterIndex)
+{
COMM_DHCP_REQ Req;
COMM_DHCP_REPLY Reply;
DWORD BytesRead;
@@ -122,7 +132,9 @@
return Reply.Reply;
}
-DWORD APIENTRY DhcpReleaseIpAddressLease( DWORD AdapterIndex ) {
+DWORD APIENTRY
+DhcpReleaseIpAddressLease(DWORD AdapterIndex)
+{
COMM_DHCP_REQ Req;
COMM_DHCP_REPLY Reply;
DWORD BytesRead;
@@ -146,7 +158,9 @@
return Reply.Reply;
}
-DWORD APIENTRY DhcpRenewIpAddressLease( DWORD AdapterIndex ) {
+DWORD APIENTRY
+DhcpRenewIpAddressLease(DWORD AdapterIndex)
+{
COMM_DHCP_REQ Req;
COMM_DHCP_REPLY Reply;
DWORD BytesRead;
@@ -170,9 +184,11 @@
return Reply.Reply;
}
-DWORD APIENTRY DhcpStaticRefreshParams( DWORD AdapterIndex,
- DWORD Address,
- DWORD Netmask ) {
+DWORD APIENTRY
+DhcpStaticRefreshParams(DWORD AdapterIndex,
+ DWORD Address,
+ DWORD Netmask)
+{
COMM_DHCP_REQ Req;
COMM_DHCP_REPLY Reply;
DWORD BytesRead;
@@ -232,9 +248,9 @@
DWORD IpIndex,
DWORD IpAddress,
DWORD SubnetMask,
- int DhcpAction)
-{
- DbgPrint("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n");
+ INT DhcpAction)
+{
+ DPRINT1("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n");
return 0;
}
@@ -262,11 +278,12 @@
*
* \remarks This is a ReactOS-only routine
*/
-DWORD APIENTRY DhcpRosGetAdapterInfo( DWORD AdapterIndex,
- PBOOL DhcpEnabled,
- PDWORD DhcpServer,
- time_t *LeaseObtained,
- time_t *LeaseExpires )
+DWORD APIENTRY
+DhcpRosGetAdapterInfo(DWORD AdapterIndex,
+ PBOOL DhcpEnabled,
+ PDWORD DhcpServer,
+ time_t* LeaseObtained,
+ time_t* LeaseExpires)
{
COMM_DHCP_REQ Req;
COMM_DHCP_REPLY Reply;
@@ -283,16 +300,19 @@
&Reply, sizeof(Reply),
&BytesRead, NULL);
- if ( 0 != Result && 0 != Reply.Reply ) {
+ if (Result && Reply.Reply != 0)
*DhcpEnabled = Reply.GetAdapterInfo.DhcpEnabled;
- } else {
+ else
*DhcpEnabled = FALSE;
- }
- if ( *DhcpEnabled ) {
+
+ if (*DhcpEnabled)
+ {
*DhcpServer = Reply.GetAdapterInfo.DhcpServer;
*LeaseObtained = Reply.GetAdapterInfo.LeaseObtained;
*LeaseExpires = Reply.GetAdapterInfo.LeaseExpires;
- } else {
+ }
+ else
+ {
*DhcpServer = INADDR_NONE;
*LeaseObtained = 0;
*LeaseExpires = 0;
@@ -301,22 +321,120 @@
return Reply.Reply;
}
+
+static VOID
+UpdateServiceStatus(DWORD dwState)
+{
+ ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
+ ServiceStatus.dwCurrentState = dwState;
+
+ ServiceStatus.dwControlsAccepted = 0;
+
+ ServiceStatus.dwWin32ExitCode = 0;
+ ServiceStatus.dwServiceSpecificExitCode = 0;
+ ServiceStatus.dwCheckPoint = 0;
+
+ if (dwState == SERVICE_START_PENDING ||
+ dwState == SERVICE_STOP_PENDING ||
+ dwState == SERVICE_PAUSE_PENDING ||
+ dwState == SERVICE_CONTINUE_PENDING)
+ ServiceStatus.dwWaitHint = 10000;
+ else
+ ServiceStatus.dwWaitHint = 0;
+
+ SetServiceStatus(ServiceStatusHandle,
+ &ServiceStatus);
+}
+
+static DWORD WINAPI
+ServiceControlHandler(DWORD dwControl,
+ DWORD dwEventType,
+ LPVOID lpEventData,
+ LPVOID lpContext)
+{
+ switch (dwControl)
+ {
+ case SERVICE_CONTROL_STOP:
+ UpdateServiceStatus(SERVICE_STOP_PENDING);
+ UpdateServiceStatus(SERVICE_STOPPED);
+ return ERROR_SUCCESS;
+
+ case SERVICE_CONTROL_PAUSE:
+ UpdateServiceStatus(SERVICE_PAUSED);
+ return ERROR_SUCCESS;
+
+ case SERVICE_CONTROL_CONTINUE:
+ UpdateServiceStatus(SERVICE_START_PENDING);
+ UpdateServiceStatus(SERVICE_RUNNING);
+ return ERROR_SUCCESS;
+
+ case SERVICE_CONTROL_INTERROGATE:
+ SetServiceStatus(ServiceStatusHandle,
+ &ServiceStatus);
+ return ERROR_SUCCESS;
+
+ case SERVICE_CONTROL_SHUTDOWN:
+ UpdateServiceStatus(SERVICE_STOP_PENDING);
+ UpdateServiceStatus(SERVICE_STOPPED);
+ return ERROR_SUCCESS;
+
+ default :
+ return ERROR_CALL_NOT_IMPLEMENTED;
+ }
+}
+
+VOID WINAPI
+ServiceMain(DWORD argc, LPWSTR* argv)
+{
+ ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
+ ServiceControlHandler,
+ NULL);
+ if (!ServiceStatusHandle)
+ {
+ DPRINT1("DHCPCSVC: Unable to register service control handler (%lx)\n",
GetLastError());
+ return;
+ }
+
+ UpdateServiceStatus(SERVICE_START_PENDING);
+
+ if (!init_client())
+ {
+ DPRINT1("DHCPCSVC: init_client() failed!\n");
+ UpdateServiceStatus(SERVICE_STOPPED);
+ return;
+ }
+
+ DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
+
+ UpdateServiceStatus(SERVICE_RUNNING);
+
+ DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
+ DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is starting up\n"));
+
+ dispatch();
+
+ DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is shutting down\n"));
+ stop_client();
+
+ UpdateServiceStatus(SERVICE_STOPPED);
+}
+
INT WINAPI
DllMain(PVOID hinstDll,
- ULONG dwReason,
- PVOID reserved)
-{
- switch (dwReason)
- {
- case DLL_PROCESS_ATTACH:
- DisableThreadLibraryCalls(hinstDll);
- break;
-
- case DLL_PROCESS_DETACH:
- break;
- }
-
- return TRUE;
+ ULONG dwReason,
+ PVOID reserved)
+{
+ switch (dwReason)
+ {
+ case DLL_PROCESS_ATTACH:
+ DisableThreadLibraryCalls(hinstDll);
+ break;
+
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+
+ return TRUE;
}
/* EOF */
Modified: trunk/reactos/dll/win32/dhcpcsvc/include/rosdhcp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/dhcpcsvc/include…
==============================================================================
--- trunk/reactos/dll/win32/dhcpcsvc/include/rosdhcp.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/dhcpcsvc/include/rosdhcp.h [iso-8859-1] Thu Sep 25 22:01:42
2014
@@ -81,6 +81,9 @@
#define random rand
#define srandom srand
+int init_client(void);
+void stop_client(void);
+
void AdapterInit(VOID);
HANDLE StartAdapterDiscovery(VOID);
void AdapterStop(VOID);