mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 05:57:52 +00:00
Reduce code duplication
combined named_server_togglequerylog() and named_server_toggleresponselog() into named_server_setortoggle().
This commit is contained in:
parent
5fad79c92f
commit
c4b7dce376
@ -247,7 +247,9 @@ named_control_docommand(isccc_sexpr_t *message, bool readonly,
|
|||||||
} else if (command_compare(command, NAMED_COMMAND_NULL)) {
|
} else if (command_compare(command, NAMED_COMMAND_NULL)) {
|
||||||
result = ISC_R_SUCCESS;
|
result = ISC_R_SUCCESS;
|
||||||
} else if (command_compare(command, NAMED_COMMAND_QUERYLOG)) {
|
} else if (command_compare(command, NAMED_COMMAND_QUERYLOG)) {
|
||||||
result = named_server_togglequerylog(named_g_server, lex);
|
result = named_server_setortoggle(named_g_server,
|
||||||
|
"query logging",
|
||||||
|
NS_SERVER_LOGQUERIES, lex);
|
||||||
} else if (command_compare(command, NAMED_COMMAND_RECONFIG)) {
|
} else if (command_compare(command, NAMED_COMMAND_RECONFIG)) {
|
||||||
result = named_server_reconfigcommand(named_g_server);
|
result = named_server_reconfigcommand(named_g_server);
|
||||||
} else if (command_compare(command, NAMED_COMMAND_RECURSING)) {
|
} else if (command_compare(command, NAMED_COMMAND_RECURSING)) {
|
||||||
@ -257,7 +259,9 @@ named_control_docommand(isccc_sexpr_t *message, bool readonly,
|
|||||||
} else if (command_compare(command, NAMED_COMMAND_RELOAD)) {
|
} else if (command_compare(command, NAMED_COMMAND_RELOAD)) {
|
||||||
result = named_server_reloadcommand(named_g_server, lex, text);
|
result = named_server_reloadcommand(named_g_server, lex, text);
|
||||||
} else if (command_compare(command, NAMED_COMMAND_RESPONSELOG)) {
|
} else if (command_compare(command, NAMED_COMMAND_RESPONSELOG)) {
|
||||||
result = named_server_toggleresponselog(named_g_server, lex);
|
result = named_server_setortoggle(named_g_server,
|
||||||
|
"response logging",
|
||||||
|
NS_SERVER_LOGRESPONSES, lex);
|
||||||
} else if (command_compare(command, NAMED_COMMAND_RETRANSFER)) {
|
} else if (command_compare(command, NAMED_COMMAND_RETRANSFER)) {
|
||||||
result = named_server_retransfercommand(named_g_server, lex,
|
result = named_server_retransfercommand(named_g_server, lex,
|
||||||
text);
|
text);
|
||||||
|
@ -181,17 +181,20 @@ named_server_retransfercommand(named_server_t *server, isc_lex_t *lex,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
named_server_togglequerylog(named_server_t *server, isc_lex_t *lex);
|
named_server_setortoggle(named_server_t *server, const char *optname,
|
||||||
|
unsigned int option, isc_lex_t *lex);
|
||||||
/*%<
|
/*%<
|
||||||
* Enable/disable logging of queries. (Takes "yes" or "no" argument,
|
* Enable/disable, or toggle, a server option via the command channel.
|
||||||
* but can also be used as a toggle for backward comptibility.)
|
* 'option' is the option value to be changed (for example,
|
||||||
*/
|
* NS_SERVER_LOGQUERIES or NS_SERVER_LOGRESPOSNES) and 'optname' is the
|
||||||
|
* option's human-readable name for logging purposes ("query logging"
|
||||||
isc_result_t
|
* or "response logging").
|
||||||
named_server_toggleresponselog(named_server_t *server, isc_lex_t *lex);
|
*
|
||||||
/*%<
|
* If an explicit argument to enable the option was provided
|
||||||
* Enable/disable logging of responses. (Takes "yes" or "no" argument,
|
* (i.e., "on", "enable", "true", or "yes") or an explicit argument
|
||||||
* but can also be used as a toggle for backward comptibility.)
|
* to disable it ("off", "disable", "false", or "no"), it will be used.
|
||||||
|
*
|
||||||
|
* If no argument is provided, the option's current state will be reversed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*%
|
/*%
|
||||||
|
@ -10673,7 +10673,8 @@ named_server_refreshcommand(named_server_t *server, isc_lex_t *lex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
named_server_togglequerylog(named_server_t *server, isc_lex_t *lex) {
|
named_server_setortoggle(named_server_t *server, const char *optname,
|
||||||
|
unsigned int option, isc_lex_t *lex) {
|
||||||
bool prev, value;
|
bool prev, value;
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
|
|
||||||
@ -10683,7 +10684,7 @@ named_server_togglequerylog(named_server_t *server, isc_lex_t *lex) {
|
|||||||
return (ISC_R_UNEXPECTEDEND);
|
return (ISC_R_UNEXPECTEDEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = ns_server_getoption(server->sctx, NS_SERVER_LOGQUERIES);
|
prev = ns_server_getoption(server->sctx, option);
|
||||||
|
|
||||||
ptr = next_token(lex, NULL);
|
ptr = next_token(lex, NULL);
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
@ -10704,50 +10705,10 @@ named_server_togglequerylog(named_server_t *server, isc_lex_t *lex) {
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
ns_server_setoption(server->sctx, NS_SERVER_LOGQUERIES, value);
|
ns_server_setoption(server->sctx, option, value);
|
||||||
|
|
||||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
||||||
ISC_LOG_INFO, "query logging is now %s",
|
ISC_LOG_INFO, "%s is now %s", optname,
|
||||||
value ? "on" : "off");
|
|
||||||
return (ISC_R_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
isc_result_t
|
|
||||||
named_server_toggleresponselog(named_server_t *server, isc_lex_t *lex) {
|
|
||||||
bool prev, value;
|
|
||||||
char *ptr = NULL;
|
|
||||||
|
|
||||||
/* Skip the command name. */
|
|
||||||
ptr = next_token(lex, NULL);
|
|
||||||
if (ptr == NULL) {
|
|
||||||
return (ISC_R_UNEXPECTEDEND);
|
|
||||||
}
|
|
||||||
|
|
||||||
prev = ns_server_getoption(server->sctx, NS_SERVER_LOGRESPONSES);
|
|
||||||
|
|
||||||
ptr = next_token(lex, NULL);
|
|
||||||
if (ptr == NULL) {
|
|
||||||
value = !prev;
|
|
||||||
} else if (!strcasecmp(ptr, "on") || !strcasecmp(ptr, "yes") ||
|
|
||||||
!strcasecmp(ptr, "enable") || !strcasecmp(ptr, "true"))
|
|
||||||
{
|
|
||||||
value = true;
|
|
||||||
} else if (!strcasecmp(ptr, "off") || !strcasecmp(ptr, "no") ||
|
|
||||||
!strcasecmp(ptr, "disable") || !strcasecmp(ptr, "false"))
|
|
||||||
{
|
|
||||||
value = false;
|
|
||||||
} else {
|
|
||||||
return (DNS_R_SYNTAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value == prev) {
|
|
||||||
return (ISC_R_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
ns_server_setoption(server->sctx, NS_SERVER_LOGRESPONSES, value);
|
|
||||||
|
|
||||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
|
||||||
ISC_LOG_INFO, "response logging is now %s",
|
|
||||||
value ? "on" : "off");
|
value ? "on" : "off");
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user