Skip to content

Commit d88cd7d

Browse files
committed
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
1 parent a8f98c0 commit d88cd7d

File tree

2 files changed

+91
-73
lines changed

2 files changed

+91
-73
lines changed

src/backend/utils/misc/guc.c

+89-72
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.455 2008/05/26 18:54:29 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.456 2008/05/28 09:04:06 mha Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -173,107 +173,107 @@ static char *config_enum_get_options(struct config_enum *record,
173173
* Options for enum values defined in this module.
174174
*/
175175
static const struct config_enum_entry message_level_options[] = {
176-
{"debug", DEBUG2},
177-
{"debug5", DEBUG5},
178-
{"debug4", DEBUG4},
179-
{"debug3", DEBUG3},
180-
{"debug2", DEBUG2},
181-
{"debug1", DEBUG1},
182-
{"log", LOG},
183-
{"info", INFO},
184-
{"notice", NOTICE},
185-
{"warning", WARNING},
186-
{"error", ERROR},
187-
{"fatal", FATAL},
188-
{"panic", PANIC},
189-
{NULL, 0}
176+
{"debug", DEBUG2, false},
177+
{"debug5", DEBUG5, false},
178+
{"debug4", DEBUG4, false},
179+
{"debug3", DEBUG3, false},
180+
{"debug2", DEBUG2, false},
181+
{"debug1", DEBUG1, false},
182+
{"log", LOG, false},
183+
{"info", INFO, false},
184+
{"notice", NOTICE, false},
185+
{"warning", WARNING, false},
186+
{"error", ERROR, false},
187+
{"fatal", FATAL, false},
188+
{"panic", PANIC, false},
189+
{NULL, 0, false}
190190
};
191191

192192
static const struct config_enum_entry log_error_verbosity_options[] = {
193-
{"default", PGERROR_DEFAULT},
194-
{"terse", PGERROR_TERSE},
195-
{"verbose", PGERROR_VERBOSE},
196-
{NULL, 0}
193+
{"default", PGERROR_DEFAULT, false},
194+
{"terse", PGERROR_TERSE, false},
195+
{"verbose", PGERROR_VERBOSE, false},
196+
{NULL, 0, false}
197197
};
198198

199199
static const struct config_enum_entry log_statement_options[] = {
200-
{"none", LOGSTMT_NONE},
201-
{"ddl", LOGSTMT_DDL},
202-
{"mod", LOGSTMT_MOD},
203-
{"all", LOGSTMT_ALL},
204-
{NULL, 0}
200+
{"none", LOGSTMT_NONE, false},
201+
{"ddl", LOGSTMT_DDL, false},
202+
{"mod", LOGSTMT_MOD, false},
203+
{"all", LOGSTMT_ALL, false},
204+
{NULL, 0, false}
205205
};
206206

207207
static const struct config_enum_entry regex_flavor_options[] = {
208-
{"advanced", REG_ADVANCED},
209-
{"extended", REG_EXTENDED},
210-
{"basic", REG_BASIC},
211-
{NULL, 0}
208+
{"advanced", REG_ADVANCED, false},
209+
{"extended", REG_EXTENDED, false},
210+
{"basic", REG_BASIC, false},
211+
{NULL, 0, false}
212212
};
213213

214214
static const struct config_enum_entry isolation_level_options[] = {
215-
{"serializable", XACT_SERIALIZABLE},
216-
{"repeatable read", XACT_REPEATABLE_READ},
217-
{"read committed", XACT_READ_COMMITTED},
218-
{"read uncommitted", XACT_READ_UNCOMMITTED},
215+
{"serializable", XACT_SERIALIZABLE, false},
216+
{"repeatable read", XACT_REPEATABLE_READ, false},
217+
{"read committed", XACT_READ_COMMITTED, false},
218+
{"read uncommitted", XACT_READ_UNCOMMITTED, false},
219219
{NULL, 0}
220220
};
221221

222222
static const struct config_enum_entry session_replication_role_options[] = {
223-
{"origin", SESSION_REPLICATION_ROLE_ORIGIN},
224-
{"replica", SESSION_REPLICATION_ROLE_REPLICA},
225-
{"local", SESSION_REPLICATION_ROLE_LOCAL},
226-
{NULL, 0}
223+
{"origin", SESSION_REPLICATION_ROLE_ORIGIN, false},
224+
{"replica", SESSION_REPLICATION_ROLE_REPLICA, false},
225+
{"local", SESSION_REPLICATION_ROLE_LOCAL, false},
226+
{NULL, 0, false}
227227
};
228228

229229
#ifdef HAVE_SYSLOG
230230
static const struct config_enum_entry syslog_facility_options[] = {
231-
{"local0", LOG_LOCAL0},
232-
{"local1", LOG_LOCAL1},
233-
{"local2", LOG_LOCAL2},
234-
{"local3", LOG_LOCAL3},
235-
{"local4", LOG_LOCAL4},
236-
{"local5", LOG_LOCAL5},
237-
{"local6", LOG_LOCAL6},
238-
{"local7", LOG_LOCAL7},
231+
{"local0", LOG_LOCAL0, false},
232+
{"local1", LOG_LOCAL1, false},
233+
{"local2", LOG_LOCAL2, false},
234+
{"local3", LOG_LOCAL3, false},
235+
{"local4", LOG_LOCAL4, false},
236+
{"local5", LOG_LOCAL5, false},
237+
{"local6", LOG_LOCAL6, false},
238+
{"local7", LOG_LOCAL7, false},
239239
{NULL, 0}
240240
};
241241
#endif
242242

243243
static const struct config_enum_entry track_function_options[] = {
244-
{"none", TRACK_FUNC_OFF},
245-
{"pl", TRACK_FUNC_PL},
246-
{"all", TRACK_FUNC_ALL},
247-
{NULL, 0}
244+
{"none", TRACK_FUNC_OFF, false},
245+
{"pl", TRACK_FUNC_PL, false},
246+
{"all", TRACK_FUNC_ALL, false},
247+
{NULL, 0, false}
248248
};
249249

250250
static const struct config_enum_entry xmlbinary_options[] = {
251-
{"base64", XMLBINARY_BASE64},
252-
{"hex", XMLBINARY_HEX},
253-
{NULL, 0}
251+
{"base64", XMLBINARY_BASE64, false},
252+
{"hex", XMLBINARY_HEX, false},
253+
{NULL, 0, false}
254254
};
255255

256256
static const struct config_enum_entry xmloption_options[] = {
257-
{"content", XMLOPTION_CONTENT},
258-
{"document", XMLOPTION_DOCUMENT},
259-
{NULL, 0}
257+
{"content", XMLOPTION_CONTENT, false},
258+
{"document", XMLOPTION_DOCUMENT, false},
259+
{NULL, 0, false}
260260
};
261261

262262
/*
263263
* Although only "on", "off", and "safe_encoding" are documented, we
264264
* accept all the likely variants of "on" and "off".
265265
*/
266266
static const struct config_enum_entry backslash_quote_options[] = {
267-
{"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING},
268-
{"on", BACKSLASH_QUOTE_ON},
269-
{"off", BACKSLASH_QUOTE_OFF},
270-
{"true", BACKSLASH_QUOTE_ON},
271-
{"false", BACKSLASH_QUOTE_OFF},
272-
{"yes", BACKSLASH_QUOTE_ON},
273-
{"no", BACKSLASH_QUOTE_OFF},
274-
{"1", BACKSLASH_QUOTE_ON},
275-
{"0", BACKSLASH_QUOTE_OFF},
276-
{NULL, 0}
267+
{"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false},
268+
{"on", BACKSLASH_QUOTE_ON, false},
269+
{"off", BACKSLASH_QUOTE_OFF, false},
270+
{"true", BACKSLASH_QUOTE_ON, true},
271+
{"false", BACKSLASH_QUOTE_OFF, true},
272+
{"yes", BACKSLASH_QUOTE_ON, true},
273+
{"no", BACKSLASH_QUOTE_OFF, true},
274+
{"1", BACKSLASH_QUOTE_ON, true},
275+
{"0", BACKSLASH_QUOTE_OFF, true},
276+
{NULL, 0, false}
277277
};
278278

279279
/*
@@ -4339,8 +4339,8 @@ config_enum_lookup_by_name(struct config_enum *record, const char *value, int *r
43394339

43404340

43414341
/*
4342-
* Return a list of all available options for an enum, separated
4343-
* by ", " (comma-space).
4342+
* Return a list of all available options for an enum, excluding
4343+
* hidden ones, separated by ", " (comma-space).
43444344
* If prefix is non-NULL, it is added before the first enum value.
43454345
* If suffix is non-NULL, it is added to the end of the string.
43464346
*/
@@ -4353,10 +4353,12 @@ config_enum_get_options(struct config_enum *record, const char *prefix, const ch
43534353

43544354
if (!entry || !entry->name)
43554355
return NULL; /* Should not happen */
4356-
4356+
43574357
while (entry && entry->name)
43584358
{
4359-
len += strlen(entry->name) + 2; /* string and ", " */
4359+
if (!entry->hidden)
4360+
len += strlen(entry->name) + 2; /* string and ", " */
4361+
43604362
entry++;
43614363
}
43624364

@@ -4367,13 +4369,28 @@ config_enum_get_options(struct config_enum *record, const char *prefix, const ch
43674369
entry = record->options;
43684370
while (entry && entry->name)
43694371
{
4370-
strcat(hintmsg, entry->name);
4371-
strcat(hintmsg, ", ");
4372+
if (!entry->hidden)
4373+
{
4374+
strcat(hintmsg, entry->name);
4375+
strcat(hintmsg, ", ");
4376+
}
4377+
43724378
entry++;
43734379
}
43744380

4375-
/* Replace final comma/space */
4376-
hintmsg[strlen(hintmsg)-2] = '\0';
4381+
len = strlen(hintmsg);
4382+
4383+
/*
4384+
* All the entries may have been hidden, leaving the string empty
4385+
* if no prefix was given. This indicates a broken GUC setup, since
4386+
* there is no use for an enum without any values, so we just check
4387+
* to make sure we don't write to invalid memory instead of actually
4388+
* trying to do something smart with it.
4389+
*/
4390+
if (len > 1)
4391+
/* Replace final comma/space */
4392+
hintmsg[len-2] = '\0';
4393+
43774394
strcat(hintmsg, suffix);
43784395

43794396
return hintmsg;

src/include/utils/guc.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.95 2008/05/12 08:35:05 mha Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.96 2008/05/28 09:04:06 mha Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndef GUC_H
@@ -100,6 +100,7 @@ struct config_enum_entry
100100
{
101101
const char *name;
102102
int val;
103+
bool hidden;
103104
};
104105

105106

0 commit comments

Comments
 (0)