xref: /netbsd/external/bsd/unbound/dist/winrc/win_svc.h (revision eaad808e)
1*eaad808eSchristos /*
2*eaad808eSchristos  * winrc/win_svc.h - windows services API implementation for unbound
3*eaad808eSchristos  *
4*eaad808eSchristos  * Copyright (c) 2009, NLnet Labs. All rights reserved.
5*eaad808eSchristos  *
6*eaad808eSchristos  * This software is open source.
7*eaad808eSchristos  *
8*eaad808eSchristos  * Redistribution and use in source and binary forms, with or without
9*eaad808eSchristos  * modification, are permitted provided that the following conditions
10*eaad808eSchristos  * are met:
11*eaad808eSchristos  *
12*eaad808eSchristos  * Redistributions of source code must retain the above copyright notice,
13*eaad808eSchristos  * this list of conditions and the following disclaimer.
14*eaad808eSchristos  *
15*eaad808eSchristos  * Redistributions in binary form must reproduce the above copyright notice,
16*eaad808eSchristos  * this list of conditions and the following disclaimer in the documentation
17*eaad808eSchristos  * and/or other materials provided with the distribution.
18*eaad808eSchristos  *
19*eaad808eSchristos  * Neither the name of the NLNET LABS nor the names of its contributors may
20*eaad808eSchristos  * be used to endorse or promote products derived from this software without
21*eaad808eSchristos  * specific prior written permission.
22*eaad808eSchristos  *
23*eaad808eSchristos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24*eaad808eSchristos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25*eaad808eSchristos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26*eaad808eSchristos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27*eaad808eSchristos  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28*eaad808eSchristos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29*eaad808eSchristos  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30*eaad808eSchristos  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31*eaad808eSchristos  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32*eaad808eSchristos  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33*eaad808eSchristos  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*eaad808eSchristos  */
35*eaad808eSchristos 
36*eaad808eSchristos /**
37*eaad808eSchristos  * \file
38*eaad808eSchristos  *
39*eaad808eSchristos  * This file contains functions to integrate with the windows services API.
40*eaad808eSchristos  * This means it handles the commandline switches to install and remove
41*eaad808eSchristos  * the service (via CreateService and DeleteService), it handles
42*eaad808eSchristos  * the ServiceMain() main service entry point when started as a service,
43*eaad808eSchristos  * and it handles the Handler[_ex]() to process requests to the service
44*eaad808eSchristos  * (such as start and stop and status).
45*eaad808eSchristos  */
46*eaad808eSchristos 
47*eaad808eSchristos #ifndef WINRC_WIN_SVC_H
48*eaad808eSchristos #define WINRC_WIN_SVC_H
49*eaad808eSchristos struct worker;
50*eaad808eSchristos 
51*eaad808eSchristos /** service name for unbound (internal to ServiceManager) */
52*eaad808eSchristos #define SERVICE_NAME "unbound"
53*eaad808eSchristos 
54*eaad808eSchristos /** from gen_msg.h - success message record for windows message log */
55*eaad808eSchristos #define MSG_GENERIC_SUCCESS              ((DWORD)0x20010001L)
56*eaad808eSchristos /** from gen_msg.h - informational message record for windows message log */
57*eaad808eSchristos #define MSG_GENERIC_INFO                 ((DWORD)0x60010002L)
58*eaad808eSchristos /** from gen_msg.h - warning message record for windows message log */
59*eaad808eSchristos #define MSG_GENERIC_WARN                 ((DWORD)0xA0010003L)
60*eaad808eSchristos /** from gen_msg.h - error message record for windows message log */
61*eaad808eSchristos #define MSG_GENERIC_ERR                  ((DWORD)0xE0010004L)
62*eaad808eSchristos 
63*eaad808eSchristos /**
64*eaad808eSchristos  * Handle commandline service for windows.
65*eaad808eSchristos  * @param wopt: windows option string (install, remove, service).
66*eaad808eSchristos  * @param cfgfile: configfile to open (default or passed with -c).
67*eaad808eSchristos  * @param v: amount of commandline verbosity added with -v.
68*eaad808eSchristos  * @param c: true if cfgfile was set by commandline -c option.
69*eaad808eSchristos  */
70*eaad808eSchristos void wsvc_command_option(const char* wopt, const char* cfgfile, int v, int c);
71*eaad808eSchristos 
72*eaad808eSchristos /**
73*eaad808eSchristos  * Setup lead worker events.
74*eaad808eSchristos  * @param worker: the worker
75*eaad808eSchristos  */
76*eaad808eSchristos void wsvc_setup_worker(struct worker* worker);
77*eaad808eSchristos 
78*eaad808eSchristos /**
79*eaad808eSchristos  * Desetup lead worker events.
80*eaad808eSchristos  * @param worker: the worker
81*eaad808eSchristos  */
82*eaad808eSchristos void wsvc_desetup_worker(struct worker* worker);
83*eaad808eSchristos 
84*eaad808eSchristos /** windows worker stop event callback handler */
85*eaad808eSchristos void worker_win_stop_cb(int fd, short ev, void* arg);
86*eaad808eSchristos 
87*eaad808eSchristos /** windows cron timer callback handler */
88*eaad808eSchristos void wsvc_cron_cb(void* arg);
89*eaad808eSchristos 
90*eaad808eSchristos #endif /* WINRC_WIN_SVC_H */
91