Add a field to guc enums to allow hiding of values from display while
authorMagnus Hagander
Wed, 28 May 2008 09:04:06 +0000 (09:04 +0000)
committerMagnus Hagander
Wed, 28 May 2008 09:04:06 +0000 (09:04 +0000)
still accepting them as input, used to allow alternate syntax for the
same setting.

Alex Hunsaker

src/backend/utils/misc/guc.c
src/include/utils/guc.h

index bc38810a810d60f852010441920f7a87e4913844..b3409111b11bf69cedd9af5ed4038e7be42708ed 100644 (file)
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut .
  *
  * 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.
  */
 static const struct config_enum_entry message_level_options[] = {
-   {"debug", DEBUG2},
-   {"debug5", DEBUG5},
-   {"debug4", DEBUG4},
-   {"debug3", DEBUG3},
-   {"debug2", DEBUG2},
-   {"debug1", DEBUG1},
-   {"log", LOG},
-   {"info", INFO},
-   {"notice", NOTICE},
-   {"warning", WARNING},
-   {"error", ERROR},
-   {"fatal", FATAL},
-   {"panic", PANIC},
-   {NULL, 0}
+   {"debug", DEBUG2, false},
+   {"debug5", DEBUG5, false},
+   {"debug4", DEBUG4, false},
+   {"debug3", DEBUG3, false},
+   {"debug2", DEBUG2, false},
+   {"debug1", DEBUG1, false},
+   {"log", LOG, false},
+   {"info", INFO, false},
+   {"notice", NOTICE, false},
+   {"warning", WARNING, false},
+   {"error", ERROR, false},
+   {"fatal", FATAL, false},
+   {"panic", PANIC, false},
+   {NULL, 0, false}
 };
 
 static const struct config_enum_entry log_error_verbosity_options[] = {
-   {"default", PGERROR_DEFAULT},
-   {"terse", PGERROR_TERSE},
-   {"verbose", PGERROR_VERBOSE},
-   {NULL, 0}
+   {"default", PGERROR_DEFAULT, false},
+   {"terse", PGERROR_TERSE, false},
+   {"verbose", PGERROR_VERBOSE, false},
+   {NULL, 0, false}
 };
 
 static const struct config_enum_entry log_statement_options[] = {
-   {"none", LOGSTMT_NONE},
-   {"ddl", LOGSTMT_DDL},
-   {"mod", LOGSTMT_MOD},
-   {"all", LOGSTMT_ALL},
-   {NULL, 0}
+   {"none", LOGSTMT_NONE, false},
+   {"ddl", LOGSTMT_DDL, false},
+   {"mod", LOGSTMT_MOD, false},
+   {"all", LOGSTMT_ALL, false},
+   {NULL, 0, false}
 };
 
 static const struct config_enum_entry regex_flavor_options[] = {
-    {"advanced", REG_ADVANCED},
-    {"extended", REG_EXTENDED},
-    {"basic", REG_BASIC},
-    {NULL, 0}
+    {"advanced", REG_ADVANCED, false},
+    {"extended", REG_EXTENDED, false},
+    {"basic", REG_BASIC, false},
+    {NULL, 0, false}
 };
 
 static const struct config_enum_entry isolation_level_options[] = {
-   {"serializable", XACT_SERIALIZABLE},
-   {"repeatable read", XACT_REPEATABLE_READ},
-   {"read committed", XACT_READ_COMMITTED},
-   {"read uncommitted", XACT_READ_UNCOMMITTED},
+   {"serializable", XACT_SERIALIZABLE, false},
+   {"repeatable read", XACT_REPEATABLE_READ, false},
+   {"read committed", XACT_READ_COMMITTED, false},
+   {"read uncommitted", XACT_READ_UNCOMMITTED, false},
    {NULL, 0}
 };
 
 static const struct config_enum_entry session_replication_role_options[] = {
-   {"origin", SESSION_REPLICATION_ROLE_ORIGIN},
-   {"replica", SESSION_REPLICATION_ROLE_REPLICA},
-   {"local", SESSION_REPLICATION_ROLE_LOCAL},
-   {NULL, 0}
+   {"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
+   {"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
+   {"local", SESSION_REPLICATION_ROLE_LOCAL, false},
+   {NULL, 0, false}
 };
 
 #ifdef HAVE_SYSLOG
 static const struct config_enum_entry syslog_facility_options[] = {
-   {"local0", LOG_LOCAL0},
-   {"local1", LOG_LOCAL1},
-   {"local2", LOG_LOCAL2},
-   {"local3", LOG_LOCAL3},
-   {"local4", LOG_LOCAL4},
-   {"local5", LOG_LOCAL5},
-   {"local6", LOG_LOCAL6},
-   {"local7", LOG_LOCAL7},
+   {"local0", LOG_LOCAL0, false},
+   {"local1", LOG_LOCAL1, false},
+   {"local2", LOG_LOCAL2, false},
+   {"local3", LOG_LOCAL3, false},
+   {"local4", LOG_LOCAL4, false},
+   {"local5", LOG_LOCAL5, false},
+   {"local6", LOG_LOCAL6, false},
+   {"local7", LOG_LOCAL7, false},
    {NULL, 0}
 };
 #endif
 
 static const struct config_enum_entry track_function_options[] = {
-   {"none", TRACK_FUNC_OFF},
-   {"pl", TRACK_FUNC_PL},
-   {"all", TRACK_FUNC_ALL},
-   {NULL, 0}
+   {"none", TRACK_FUNC_OFF, false},
+   {"pl", TRACK_FUNC_PL, false},
+   {"all", TRACK_FUNC_ALL, false},
+   {NULL, 0, false}
 };
 
 static const struct config_enum_entry xmlbinary_options[] = {
-   {"base64", XMLBINARY_BASE64},
-   {"hex", XMLBINARY_HEX},
-   {NULL, 0}
+   {"base64", XMLBINARY_BASE64, false},
+   {"hex", XMLBINARY_HEX, false},
+   {NULL, 0, false}
 };
 
 static const struct config_enum_entry xmloption_options[] = {
-   {"content", XMLOPTION_CONTENT},
-   {"document", XMLOPTION_DOCUMENT},
-   {NULL, 0}
+   {"content", XMLOPTION_CONTENT, false},
+   {"document", XMLOPTION_DOCUMENT, false},
+   {NULL, 0, false}
 };
 
 /*
@@ -264,16 +264,16 @@ static const struct config_enum_entry xmloption_options[] = {
  * accept all the likely variants of "on" and "off".
  */
 static const struct config_enum_entry backslash_quote_options[] = {
-   {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING},
-   {"on", BACKSLASH_QUOTE_ON},
-   {"off", BACKSLASH_QUOTE_OFF},
-   {"true", BACKSLASH_QUOTE_ON},
-   {"false", BACKSLASH_QUOTE_OFF},
-   {"yes", BACKSLASH_QUOTE_ON},
-   {"no", BACKSLASH_QUOTE_OFF},
-   {"1", BACKSLASH_QUOTE_ON},
-   {"0", BACKSLASH_QUOTE_OFF},
-   {NULL, 0}
+   {"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
+   {"on", BACKSLASH_QUOTE_ON, false},
+   {"off", BACKSLASH_QUOTE_OFF, false},
+   {"true", BACKSLASH_QUOTE_ON, true},
+   {"false", BACKSLASH_QUOTE_OFF, true},
+   {"yes", BACKSLASH_QUOTE_ON, true},
+   {"no", BACKSLASH_QUOTE_OFF, true},
+   {"1", BACKSLASH_QUOTE_ON, true},
+   {"0", BACKSLASH_QUOTE_OFF, true},
+   {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
- * by ", " (comma-space).
+ * Return a list of all available options for an enum, excluding
+ * hidden ones, separated by ", " (comma-space).
  * 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.
  */
@@ -4353,10 +4353,12 @@ config_enum_get_options(struct config_enum *record, const char *prefix, const ch
 
    if (!entry || !entry->name)
        return NULL;                    /* Should not happen */
-   
+
    while (entry && entry->name)
    {
-       len += strlen(entry->name) + 2; /* string and ", " */
+       if (!entry->hidden)
+           len += strlen(entry->name) + 2; /* string and ", " */
+
        entry++;
    }
 
@@ -4367,13 +4369,28 @@ config_enum_get_options(struct config_enum *record, const char *prefix, const ch
    entry = record->options;
    while (entry && entry->name)
    {
-       strcat(hintmsg, entry->name);
-       strcat(hintmsg, ", ");
+       if (!entry->hidden)
+       {
+           strcat(hintmsg, entry->name);
+           strcat(hintmsg, ", ");
+       }
+
        entry++;
    }
 
-   /* Replace final comma/space */
-   hintmsg[strlen(hintmsg)-2] = '\0';
+   len = strlen(hintmsg);
+
+   /*
+    * 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);
 
    return hintmsg;
index fc737ec4cf43efb73d39060852c4b2de8807d6f7..2337487d463ec90467032b2d0922814e6ee5c45f 100644 (file)
@@ -7,7 +7,7 @@
  * Copyright (c) 2000-2008, PostgreSQL Global Development Group
  * Written by Peter Eisentraut .
  *
- * $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
@@ -100,6 +100,7 @@ struct config_enum_entry
 {
    const char *name;
    int         val;
+   bool        hidden;
 };