51 if (strcmp(
name,
"none") == 0)
53 else if (strcmp(
name,
"gzip") == 0)
55 else if (strcmp(
name,
"lz4") == 0)
57 else if (strcmp(
name,
"zstd") == 0)
111 char *bare_level_endp;
132 psprintf(
_(
"this build does not support compression with %s"),
138 result->
level = ZSTD_CLEVEL_DEFAULT;
141 psprintf(
_(
"this build does not support compression with %s"),
147 result->
level = Z_DEFAULT_COMPRESSION;
150 psprintf(
_(
"this build does not support compression with %s"),
157 if (specification == NULL)
161 bare_level = strtol(specification, &bare_level_endp, 10);
162 if (specification != bare_level_endp && *bare_level_endp ==
'\0')
164 result->
level = bare_level;
182 kwstart = kwend = specification;
183 while (*kwend !=
'\0' && *kwend !=
',' && *kwend !=
'=')
185 kwlen = kwend - kwstart;
188 vstart = vend = NULL;
194 vstart = vend = kwend + 1;
195 while (*vend !=
'\0' && *vend !=
',')
197 vlen = vend - vstart;
205 pstrdup(
_(
"found empty string where a compression option was expected"));
210 keyword =
palloc(kwlen + 1);
211 memcpy(keyword, kwstart, kwlen);
212 keyword[kwlen] =
'\0';
218 memcpy(
value, vstart, vlen);
223 if (strcmp(keyword,
"level") == 0)
232 else if (strcmp(keyword,
"workers") == 0)
237 else if (strcmp(keyword,
"long") == 0)
244 psprintf(
_(
"unrecognized compression option: \"%s\""), keyword);
260 (vend == NULL ? *kwend ==
'\0' : *vend ==
'\0'))
264 specification = vend == NULL ? kwend + 1 : vend + 1;
283 psprintf(
_(
"compression option \"%s\" requires a value"),
288 ivalue = strtol(
value, &ivalue_endp, 10);
289 if (ivalue_endp ==
value || *ivalue_endp !=
'\0')
292 psprintf(
_(
"value for compression option \"%s\" must be an integer"),
331 psprintf(
_(
"value for compression option \"%s\" must be a Boolean value"),
348 int default_level = 0;
363 default_level = Z_DEFAULT_COMPRESSION;
372 max_level = ZSTD_maxCLevel();
373 min_level = ZSTD_minCLevel();
374 default_level = ZSTD_CLEVEL_DEFAULT;
378 if (spec->
level != 0)
379 return psprintf(
_(
"compression algorithm \"%s\" does not accept a compression level"),
384 if ((spec->
level < min_level || spec->
level > max_level) &&
385 spec->
level != default_level)
386 return psprintf(
_(
"compression algorithm \"%s\" expects a compression level between %d and %d (default at %d)"),
388 min_level, max_level, default_level);
397 return psprintf(
_(
"compression algorithm \"%s\" does not accept a worker count"),
408 return psprintf(
_(
"compression algorithm \"%s\" does not support long-distance mode"),
438 result = strtol(
option, &endp, 10);
458 sep = strchr(
option,
':');
#define Assert(condition)
static bool expect_boolean_value(char *keyword, char *value, pg_compress_specification *result)
bool parse_compress_algorithm(char *name, pg_compress_algorithm *algorithm)
const char * get_compress_algorithm_name(pg_compress_algorithm algorithm)
static int expect_integer_value(char *keyword, char *value, pg_compress_specification *result)
void parse_compress_specification(pg_compress_algorithm algorithm, char *specification, pg_compress_specification *result)
char * validate_compress_specification(pg_compress_specification *spec)
#define PG_COMPRESSION_OPTION_WORKERS
#define PG_COMPRESSION_OPTION_LONG_DISTANCE
void parse_compress_options(const char *option, char **algorithm, char **detail)
char * pstrdup(const char *in)
void pfree(void *pointer)
int pg_strcasecmp(const char *s1, const char *s2)
char * psprintf(const char *fmt,...)
pg_compress_algorithm algorithm