-
Notifications
You must be signed in to change notification settings - Fork 2
/
eudc.c
140 lines (113 loc) · 2.89 KB
/
eudc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* eudc.c
*/
#include "postgres.h"
#include "mb/pg_wchar.h"
#include "utils/guc.h"
#include "pgut/pgut-be.h"
PG_MODULE_MAGIC;
static const struct config_enum_entry log_level_options[] = {
{"debug", DEBUG2, true},
{"debug5", DEBUG5, false},
{"debug4", DEBUG4, false},
{"debug3", DEBUG3, false},
{"debug2", DEBUG2, false},
{"debug1", DEBUG1, false},
{"log", LOG, false},
{"info", INFO, true},
{"notice", NOTICE, false},
{"warning", WARNING, false},
{"error", ERROR, false},
{"fatal", FATAL, true},
/* should not have PANIC here! */
{NULL, 0, false}
};
#if PG_VERSION_NUM >= 90100
char *eudc_fallback_character = "";
#else
char *eudc_fallback_character = NULL;
#endif
int eudc_log_level = DEBUG2;
extern void PGDLLEXPORT _PG_init(void);
#if PG_VERSION_NUM >= 90100
static bool eudc_fallback_character_check_hook(
const char **newval, void** extra, GucSource source);
static const char *eudc_fallback_character_assign_hook(
const char *newval, void* extra);
#else
static const char *eudc_fallback_character_assign_hook(
const char *newval, bool doit, GucSource source);
#endif
void
_PG_init(void)
{
/* Define custom GUC variables. */
DefineCustomStringVariable("eudc.fallback_character",
"Character used for EUDC. Or, use linear mapping when empty.",
NULL,
&eudc_fallback_character,
NULL,
PGC_USERSET,
0,
#if PG_VERSION_NUM >= 90100
(GucStringCheckHook)&eudc_fallback_character_check_hook,
(GucStringAssignHook)&eudc_fallback_character_assign_hook,
#else
eudc_fallback_character_assign_hook,
#endif
NULL);
#if PG_VERSION_NUM >= 80400
DefineCustomEnumVariable("eudc.log_level",
"Level to log EUDC characters.",
NULL,
&eudc_log_level,
DEBUG2,
log_level_options,
PGC_USERSET,
0,
#if PG_VERSION_NUM >= 90100
NULL,
#endif
NULL,
NULL);
#endif
EmitWarningsOnPlaceholders("eudc");
}
#if PG_VERSION_NUM >= 90100
static const char *
eudc_fallback_character_assign_hook(
const char *newval, void* extra)
{
return newval;
}
static bool eudc_fallback_character_check_hook(
const char **newval, void** extra, GucSource source)
{
int len;
GUC_check_errhint("must be one character or empty string");
/* handle explicit setting of eudc.fallback_character */
if (*newval)
{
/* eudc.fallback_character
* should be 0 or 1 character
*/
len = pg_mbstrlen(*newval);
if (len >= 2 || len < 0)
return false;
}
return true;
}
#else
static const char *
eudc_fallback_character_assign_hook(
const char *newval, bool doit, GucSource source)
{
int len = pg_mbstrlen(newval);
if (len >= 2 || len < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid value for parameter \"eudc.fallback_character\": \"%s\"", newval),
errhint("must be one character or empty string")));
return newval;
}
#endif