omapi.c revision 7e4135abb92a44425e9a653b1623db7cb2837c3c
c40265eba0c99708887d68e67901924065ba2514Brian Wellington/*
24abfe433efd98bb2099b867fb14d049b2f1f531Tinderbox User * Copyright (C) 2000 Internet Software Consortium.
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews *
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * Permission to use, copy, modify, and distribute this software for any
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater * purpose with or without fee is hereby granted, provided that the above
c40265eba0c99708887d68e67901924065ba2514Brian Wellington * copyright notice and this permission notice appear in all copies.
c40265eba0c99708887d68e67901924065ba2514Brian Wellington *
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
af5073d03288a53b646ec3b807ac25ced64d7879Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
c40265eba0c99708887d68e67901924065ba2514Brian Wellington */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein/* $Id: omapi.c,v 1.18 2000/10/05 23:48:47 marka Exp $ */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein/*
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User * Principal Author: DCL
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein */
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews#include <config.h>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein#include <isc/app.h>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User#include <isc/event.h>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein#include <isc/util.h>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein#include <named/log.h>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User#include <named/omapi.h>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User#include <named/server.h>
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User/*
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User * The control_object structure is used for receiving commands that
d856585f5fe37cc2ea82115c10339578d2b517b1Automatic Updater * request the server to perform some action, but that do not set or
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User * get any state.
d856585f5fe37cc2ea82115c10339578d2b517b1Automatic Updater */
d856585f5fe37cc2ea82115c10339578d2b517b1Automatic Updatertypedef struct control_object {
d856585f5fe37cc2ea82115c10339578d2b517b1Automatic Updater OMAPI_OBJECT_PREAMBLE;
d856585f5fe37cc2ea82115c10339578d2b517b1Automatic Updater} control_object_t;
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox Userstatic control_object_t control;
d856585f5fe37cc2ea82115c10339578d2b517b1Automatic Updaterstatic omapi_objecttype_t *control_type;
d856585f5fe37cc2ea82115c10339578d2b517b1Automatic Updater
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User#undef REGION_FMT
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User/*
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User * Ok, kind of gross. Sorry. A little.
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User */
d856585f5fe37cc2ea82115c10339578d2b517b1Automatic Updater#define REGION_FMT(r) (int)(r)->length, (r)->base
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User/*
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User * This is the function that is called when an incoming OMAPI_OP_OPEN
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User * message is received with either the create or update option set.
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User * It is called once for each name/value pair in the message's object
f7b41fd9291b8f4dba27e2b57e1d93f0913a4f1dMark Andrews * value list.
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User */
f7b41fd9291b8f4dba27e2b57e1d93f0913a4f1dMark Andrewsstatic isc_result_t
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox Usercontrol_setvalue(omapi_object_t *handle, omapi_string_t *name,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein omapi_data_t *value)
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User{
d85c83c4144116fbc2734a6a623a888fea1a307fAutomatic Updater isc_region_t region;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein isc_result_t result;
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User INSIST(handle == (omapi_object_t *)&control);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User omapi_string_totext(name, &region);
2eeb74d1cf5355dd98f6d507a10086e16bb08c4bTinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User NS_LOGMODULE_OMAPI, ISC_LOG_DEBUG(1),
d85c83c4144116fbc2734a6a623a888fea1a307fAutomatic Updater "control_setvalue: '%.*s' control command received",
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User REGION_FMT(&region));
d85c83c4144116fbc2734a6a623a888fea1a307fAutomatic Updater
d85c83c4144116fbc2734a6a623a888fea1a307fAutomatic Updater /*
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User * Compare the 'name' parameter against all known control commands.
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User */
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User if (omapi_string_strcmp(name, NS_OMAPI_COMMAND_RELOAD) == 0) {
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User if (omapi_data_getint(value) != 0)
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User ns_server_reloadwanted(ns_g_server);
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User result = ISC_R_SUCCESS;
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User } else if (omapi_string_strcmp(name,NS_OMAPI_COMMAND_HALT) == 0) {
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User if (omapi_data_getint(value) != 0) {
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User ns_server_flushonshutdown(ns_g_server, ISC_FALSE);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein isc_app_shutdown();
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User }
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews result = ISC_R_SUCCESS;
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews } else if (omapi_string_strcmp(name,NS_OMAPI_COMMAND_STOP) == 0) {
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User if (omapi_data_getint(value) != 0) {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein ns_server_flushonshutdown(ns_g_server, ISC_TRUE);
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User isc_app_shutdown();
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein }
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User result = ISC_R_SUCCESS;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein } else if (omapi_string_strcmp(name,
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User NS_OMAPI_COMMAND_RELOADCONFIG) == 0 ||
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein omapi_string_strcmp(name,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein NS_OMAPI_COMMAND_RELOADZONES) == 0) {
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User "control_setvalue: '%.*s' not yet implemented",
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User REGION_FMT(&region));
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User result = ISC_R_NOTIMPLEMENTED;
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein } else {
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein NS_LOGMODULE_OMAPI, ISC_LOG_WARNING,
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User "control_setvalue: unknown name: '%.*s'",
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User REGION_FMT(&region));
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User result = omapi_object_passsetvalue(handle, name, value);
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User }
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return (result);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein}
fd2597f75693a2279fdf588bd40dfe2407c42028Tinderbox User
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein/*
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein * This is the function that is called by the library's internal
* message_process function when an incoming OMAPI_OP_OPEN message is received.
* It is supposed to look up the object in the server that corresponds to the
* key data (name/value pair(s)) in 'key'.
*/
static isc_result_t
control_lookup(omapi_object_t **control_object, omapi_object_t *key) {
/*
* There is only one control object so no key is needed to look it up.
*/
UNUSED(key);
omapi_object_reference(control_object, (omapi_object_t *)&control);
return (ISC_R_SUCCESS);
}
/*
* This function is called when the server is sending a reply to a client
* that opened an object of its type. It needs to output all published
* name/value pairs for the object, and will typically also put the data
* for any inner objects (but in this program, there will be no inner
* objects). The handle parameter is an object of the type registered
* in ns_omapi_listen.
*/
static isc_result_t
control_stuffvalues(omapi_object_t *connection, omapi_object_t *handle) {
/*
* Currently the server has no values to publish, but it needs
* to publish something for its OMAPI_OP_UPDATE function to work
* when received by the client.
*/
return (omapi_object_passstuffvalues(connection, handle));
}
isc_result_t
ns_omapi_init(void) {
isc_result_t result;
result = omapi_lib_init(ns_g_mctx, ns_g_taskmgr, ns_g_socketmgr);
if (result == ISC_R_SUCCESS)
/*
* Register the control_object. NS_OMAPI_CONTROL is
* what a client would need to specify as a value for
* the value of "type" in a message when contacting
* the server to perform a control function.
*/
result = omapi_object_register(&control_type, NS_OMAPI_CONTROL,
control_setvalue,
NULL, /* getvalue */
NULL, /* destroy */
NULL, /* signalhandler */
control_stuffvalues,
control_lookup,
NULL, /* create */
NULL); /* remove */
if (result == ISC_R_SUCCESS) {
/*
* Initialize the static control object.
*/
control.refcnt = 1;
control.type = control_type;
}
return (result);
}