2 * Copyright 2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define WIN32_LEAN_AND_MEAN
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(telnetd
);
26 static WCHAR telnetdW
[] = {'t','e','l','n','e','t','d',0};
28 static SERVICE_STATUS_HANDLE service_handle
;
29 static HANDLE stop_event
;
31 static DWORD WINAPI
service_handler( DWORD ctrl
, DWORD event_type
, LPVOID event_data
, LPVOID context
)
33 SERVICE_STATUS status
;
35 status
.dwServiceType
= SERVICE_WIN32
;
36 status
.dwControlsAccepted
= SERVICE_ACCEPT_STOP
;
37 status
.dwWin32ExitCode
= 0;
38 status
.dwServiceSpecificExitCode
= 0;
39 status
.dwCheckPoint
= 0;
40 status
.dwWaitHint
= 0;
44 case SERVICE_CONTROL_STOP
:
45 case SERVICE_CONTROL_SHUTDOWN
:
46 WINE_TRACE( "shutting down\n" );
47 status
.dwCurrentState
= SERVICE_STOP_PENDING
;
48 status
.dwControlsAccepted
= 0;
49 SetServiceStatus( service_handle
, &status
);
50 SetEvent( stop_event
);
53 WINE_FIXME( "got service ctrl %x\n", ctrl
);
54 status
.dwCurrentState
= SERVICE_RUNNING
;
55 SetServiceStatus( service_handle
, &status
);
60 static void WINAPI
serv_main(DWORD argc
, LPWSTR
*argv
)
62 SERVICE_STATUS status
;
65 WINE_TRACE( "starting service\n" );
67 stop_event
= CreateEventW( NULL
, TRUE
, FALSE
, NULL
);
69 service_handle
= RegisterServiceCtrlHandlerExW( telnetdW
, service_handler
, NULL
);
73 status
.dwServiceType
= SERVICE_WIN32
;
74 status
.dwCurrentState
= SERVICE_RUNNING
;
75 status
.dwControlsAccepted
= SERVICE_ACCEPT_STOP
| SERVICE_ACCEPT_SHUTDOWN
;
76 status
.dwWin32ExitCode
= 0;
77 status
.dwServiceSpecificExitCode
= 0;
78 status
.dwCheckPoint
= 0;
79 status
.dwWaitHint
= 10000;
80 SetServiceStatus( service_handle
, &status
);
82 /* Argument Ignored for now */
83 retval
= kickoff_telnetd();
85 WaitForSingleObject( stop_event
, INFINITE
);
87 status
.dwCurrentState
= SERVICE_STOPPED
;
88 status
.dwControlsAccepted
= 0;
89 SetServiceStatus( service_handle
, &status
);
90 WINE_TRACE( "service stopped\n" );
93 int main(int argc
, char **argv
)
95 static const SERVICE_TABLE_ENTRYW servtbl
[] = {
96 {telnetdW
, serv_main
},
100 WINE_TRACE("(%d %p)\n", argc
, argv
);
102 StartServiceCtrlDispatcherW(servtbl
);