Add a field to guc enums to allow hiding of values from display while

still accepting them as input, used to allow alternate syntax for the
same setting.

Alex Hunsaker
REL8_5_ALPHA1_BRANCH
Magnus Hagander 18 years ago
parent a8f98c068e
commit d88cd7db63
  1. 159
      src/backend/utils/misc/guc.c
  2. 3
      src/include/utils/guc.h

@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.455 2008/05/26 18:54:29 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.456 2008/05/28 09:04:06 mha Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
@ -173,90 +173,90 @@ static char *config_enum_get_options(struct config_enum *record,
* Options for enum values defined in this module. * Options for enum values defined in this module.
*/ */
static const struct config_enum_entry message_level_options[] = { static const struct config_enum_entry message_level_options[] = {
{"debug", DEBUG2}, {"debug", DEBUG2, false},
{"debug5", DEBUG5}, {"debug5", DEBUG5, false},
{"debug4", DEBUG4}, {"debug4", DEBUG4, false},
{"debug3", DEBUG3}, {"debug3", DEBUG3, false},
{"debug2", DEBUG2}, {"debug2", DEBUG2, false},
{"debug1", DEBUG1}, {"debug1", DEBUG1, false},
{"log", LOG}, {"log", LOG, false},
{"info", INFO}, {"info", INFO, false},
{"notice", NOTICE}, {"notice", NOTICE, false},
{"warning", WARNING}, {"warning", WARNING, false},
{"error", ERROR}, {"error", ERROR, false},
{"fatal", FATAL}, {"fatal", FATAL, false},
{"panic", PANIC}, {"panic", PANIC, false},
{NULL, 0} {NULL, 0, false}
}; };
static const struct config_enum_entry log_error_verbosity_options[] = { static const struct config_enum_entry log_error_verbosity_options[] = {
{"default", PGERROR_DEFAULT}, {"default", PGERROR_DEFAULT, false},
{"terse", PGERROR_TERSE}, {"terse", PGERROR_TERSE, false},
{"verbose", PGERROR_VERBOSE}, {"verbose", PGERROR_VERBOSE, false},
{NULL, 0} {NULL, 0, false}
}; };
static const struct config_enum_entry log_statement_options[] = { static const struct config_enum_entry log_statement_options[] = {
{"none", LOGSTMT_NONE}, {"none", LOGSTMT_NONE, false},
{"ddl", LOGSTMT_DDL}, {"ddl", LOGSTMT_DDL, false},
{"mod", LOGSTMT_MOD}, {"mod", LOGSTMT_MOD, false},
{"all", LOGSTMT_ALL}, {"all", LOGSTMT_ALL, false},
{NULL, 0} {NULL, 0, false}
}; };
static const struct config_enum_entry regex_flavor_options[] = { static const struct config_enum_entry regex_flavor_options[] = {
{"advanced", REG_ADVANCED}, {"advanced", REG_ADVANCED, false},
{"extended", REG_EXTENDED}, {"extended", REG_EXTENDED, false},
{"basic", REG_BASIC}, {"basic", REG_BASIC, false},
{NULL, 0} {NULL, 0, false}
}; };
static const struct config_enum_entry isolation_level_options[] = { static const struct config_enum_entry isolation_level_options[] = {
{"serializable", XACT_SERIALIZABLE}, {"serializable", XACT_SERIALIZABLE, false},
{"repeatable read", XACT_REPEATABLE_READ}, {"repeatable read", XACT_REPEATABLE_READ, false},
{"read committed", XACT_READ_COMMITTED}, {"read committed", XACT_READ_COMMITTED, false},
{"read uncommitted", XACT_READ_UNCOMMITTED}, {"read uncommitted", XACT_READ_UNCOMMITTED, false},
{NULL, 0} {NULL, 0}
}; };
static const struct config_enum_entry session_replication_role_options[] = { static const struct config_enum_entry session_replication_role_options[] = {
{"origin", SESSION_REPLICATION_ROLE_ORIGIN}, {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
{"replica", SESSION_REPLICATION_ROLE_REPLICA}, {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
{"local", SESSION_REPLICATION_ROLE_LOCAL}, {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
{NULL, 0} {NULL, 0, false}
}; };
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
static const struct config_enum_entry syslog_facility_options[] = { static const struct config_enum_entry syslog_facility_options[] = {
{"local0", LOG_LOCAL0}, {"local0", LOG_LOCAL0, false},
{"local1", LOG_LOCAL1}, {"local1", LOG_LOCAL1, false},
{"local2", LOG_LOCAL2}, {"local2", LOG_LOCAL2, false},
{"local3", LOG_LOCAL3}, {"local3", LOG_LOCAL3, false},
{"local4", LOG_LOCAL4}, {"local4", LOG_LOCAL4, false},
{"local5", LOG_LOCAL5}, {"local5", LOG_LOCAL5, false},
{"local6", LOG_LOCAL6}, {"local6", LOG_LOCAL6, false},
{"local7", LOG_LOCAL7}, {"local7", LOG_LOCAL7, false},
{NULL, 0} {NULL, 0}
}; };
#endif #endif
static const struct config_enum_entry track_function_options[] = { static const struct config_enum_entry track_function_options[] = {
{"none", TRACK_FUNC_OFF}, {"none", TRACK_FUNC_OFF, false},
{"pl", TRACK_FUNC_PL}, {"pl", TRACK_FUNC_PL, false},
{"all", TRACK_FUNC_ALL}, {"all", TRACK_FUNC_ALL, false},
{NULL, 0} {NULL, 0, false}
}; };
static const struct config_enum_entry xmlbinary_options[] = { static const struct config_enum_entry xmlbinary_options[] = {
{"base64", XMLBINARY_BASE64}, {"base64", XMLBINARY_BASE64, false},
{"hex", XMLBINARY_HEX}, {"hex", XMLBINARY_HEX, false},
{NULL, 0} {NULL, 0, false}
}; };
static const struct config_enum_entry xmloption_options[] = { static const struct config_enum_entry xmloption_options[] = {
{"content", XMLOPTION_CONTENT}, {"content", XMLOPTION_CONTENT, false},
{"document", XMLOPTION_DOCUMENT}, {"document", XMLOPTION_DOCUMENT, false},
{NULL, 0} {NULL, 0, false}
}; };
/* /*
@ -264,16 +264,16 @@ static const struct config_enum_entry xmloption_options[] = {
* accept all the likely variants of "on" and "off". * accept all the likely variants of "on" and "off".
*/ */
static const struct config_enum_entry backslash_quote_options[] = { static const struct config_enum_entry backslash_quote_options[] = {
{"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING}, {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
{"on", BACKSLASH_QUOTE_ON}, {"on", BACKSLASH_QUOTE_ON, false},
{"off", BACKSLASH_QUOTE_OFF}, {"off", BACKSLASH_QUOTE_OFF, false},
{"true", BACKSLASH_QUOTE_ON}, {"true", BACKSLASH_QUOTE_ON, true},
{"false", BACKSLASH_QUOTE_OFF}, {"false", BACKSLASH_QUOTE_OFF, true},
{"yes", BACKSLASH_QUOTE_ON}, {"yes", BACKSLASH_QUOTE_ON, true},
{"no", BACKSLASH_QUOTE_OFF}, {"no", BACKSLASH_QUOTE_OFF, true},
{"1", BACKSLASH_QUOTE_ON}, {"1", BACKSLASH_QUOTE_ON, true},
{"0", BACKSLASH_QUOTE_OFF}, {"0", BACKSLASH_QUOTE_OFF, true},
{NULL, 0} {NULL, 0, false}
}; };
/* /*
@ -4339,8 +4339,8 @@ config_enum_lookup_by_name(struct config_enum *record, const char *value, int *r
/* /*
* Return a list of all available options for an enum, separated * Return a list of all available options for an enum, excluding
* by ", " (comma-space). * hidden ones, separated by ", " (comma-space).
* If prefix is non-NULL, it is added before the first enum value. * If prefix is non-NULL, it is added before the first enum value.
* If suffix is non-NULL, it is added to the end of the string. * If suffix is non-NULL, it is added to the end of the string.
*/ */
@ -4356,7 +4356,9 @@ config_enum_get_options(struct config_enum *record, const char *prefix, const ch
while (entry && entry->name) while (entry && entry->name)
{ {
len += strlen(entry->name) + 2; /* string and ", " */ if (!entry->hidden)
len += strlen(entry->name) + 2; /* string and ", " */
entry++; entry++;
} }
@ -4367,13 +4369,28 @@ config_enum_get_options(struct config_enum *record, const char *prefix, const ch
entry = record->options; entry = record->options;
while (entry && entry->name) while (entry && entry->name)
{ {
strcat(hintmsg, entry->name); if (!entry->hidden)
strcat(hintmsg, ", "); {
strcat(hintmsg, entry->name);
strcat(hintmsg, ", ");
}
entry++; entry++;
} }
/* Replace final comma/space */ len = strlen(hintmsg);
hintmsg[strlen(hintmsg)-2] = '\0';
/*
* All the entries may have been hidden, leaving the string empty
* if no prefix was given. This indicates a broken GUC setup, since
* there is no use for an enum without any values, so we just check
* to make sure we don't write to invalid memory instead of actually
* trying to do something smart with it.
*/
if (len > 1)
/* Replace final comma/space */
hintmsg[len-2] = '\0';
strcat(hintmsg, suffix); strcat(hintmsg, suffix);
return hintmsg; return hintmsg;

@ -7,7 +7,7 @@
* Copyright (c) 2000-2008, PostgreSQL Global Development Group * Copyright (c) 2000-2008, PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.95 2008/05/12 08:35:05 mha Exp $ * $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.96 2008/05/28 09:04:06 mha Exp $
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
#ifndef GUC_H #ifndef GUC_H
@ -100,6 +100,7 @@ struct config_enum_entry
{ {
const char *name; const char *name;
int val; int val;
bool hidden;
}; };

Loading…
Cancel
Save