This is converted to the maximum size of the number.
if (strchr(value, '%') != NULL)
break;
+ if (settings_value_is_unlimited(value))
+ break;
if (str_to_uint(value, &num) < 0) {
ctx->error = p_strdup_printf(ctx->pool,
"Invalid number %s: %s", value,
unsigned int interval;
if (strchr(value, '%') != NULL)
break;
+ if (settings_value_is_unlimited(value))
+ break;
if (str_parse_get_interval(value, &interval, &error) < 0) {
ctx->error = p_strdup(ctx->pool, error);
return -1;
unsigned int interval;
if (strchr(value, '%') != NULL)
break;
+ if (settings_value_is_unlimited(value))
+ break;
if (str_parse_get_interval_msecs(value, &interval, &error) < 0) {
ctx->error = p_strdup(ctx->pool, error);
return -1;
uoff_t size;
if (strchr(value, '%') != NULL)
break;
+ if (settings_value_is_unlimited(value))
+ break;
if (str_parse_get_size(value, &size, &error) < 0) {
ctx->error = p_strdup(ctx->pool, error);
return -1;
str_append_c(str, '0');
return;
}
+ if (size == SET_SIZE_UNLIMITED) {
+ str_append(str, SET_VALUE_UNLIMITED);
+ return;
+ }
for (i = 1; i < N_ELEMENTS(suffixes) && (size % 1024) == 0; i++) {
suffix = suffixes[i];
size /= 1024;
str_append_c(str, '0');
return;
}
+ if (stamp == SET_TIME_INFINITE) {
+ str_append(str, SET_VALUE_INFINITE);
+ return;
+ }
if (stamp % 60 == 0) {
stamp /= 60;
static void config_export_time_msecs(string_t *str, unsigned int stamp_msecs)
{
- if ((stamp_msecs % 1000) == 0)
+ if (stamp_msecs == SET_TIME_MSECS_INFINITE)
+ str_append(str, SET_VALUE_INFINITE);
+ else if ((stamp_msecs % 1000) == 0)
config_export_time(str, stamp_msecs/1000);
else
str_printfa(str, "%u ms", stamp_msecs);
break;
}
case SET_UINT:
- case SET_UINT_OCT:
+ case SET_UINT_OCT: {
+ const unsigned int *val = value;
+ if (*val == SET_UINT_UNLIMITED) {
+ str_append(str, SET_VALUE_UNLIMITED);
+ break;
+ }
+ if (type == SET_UINT_OCT)
+ str_printfa(str, "0%o", *val);
+ else
+ str_printfa(str, "%u", *val);
+ break;
+ }
case SET_TIME:
case SET_TIME_MSECS: {
const unsigned int *val = value;
- switch (type) {
- case SET_UINT_OCT:
- str_printfa(str, "0%o", *val);
- break;
- case SET_TIME:
+ if (type == SET_TIME)
config_export_time(str, *val);
- break;
- case SET_TIME_MSECS:
+ else
config_export_time_msecs(str, *val);
- break;
- default:
- str_printfa(str, "%u", *val);
- break;
- }
break;
}
case SET_IN_PORT: {
get_uint(struct setting_parser_context *ctx, const char *value,
unsigned int *result_r)
{
+ if (settings_value_is_unlimited(value)) {
+ *result_r = SET_UINT_UNLIMITED;
+ return 0;
+ }
if (str_to_uint(value, result_r) < 0) {
settings_parser_set_error(ctx, t_strdup_printf(
"Invalid number %s: %s", value,
return -1;
break;
case SET_TIME:
+ if (settings_value_is_unlimited(value)) {
+ *(unsigned int *)ptr = SET_TIME_INFINITE;
+ return 0;
+ }
if (str_parse_get_interval(value, (unsigned int *)ptr, &error) < 0) {
settings_parser_set_error(ctx, error);
return -1;
}
break;
case SET_TIME_MSECS:
+ if (settings_value_is_unlimited(value)) {
+ *(unsigned int *)ptr = SET_TIME_MSECS_INFINITE;
+ return 0;
+ }
if (str_parse_get_interval_msecs(value, (unsigned int *)ptr, &error) < 0) {
settings_parser_set_error(ctx, error);
return -1;
}
break;
case SET_SIZE:
+ if (settings_value_is_unlimited(value)) {
+ *(uoff_t *)ptr = SET_SIZE_UNLIMITED;
+ return 0;
+ }
if (str_parse_get_size(value, (uoff_t *)ptr, &error) < 0) {
settings_parser_set_error(ctx, error);
return -1;
#define SETTINGS_SEPARATOR '/'
#define SETTINGS_SEPARATOR_S "/"
+/* These values are shown as "unlimited" */
+#define SET_VALUE_UNLIMITED "unlimited"
+#define SET_UINT_UNLIMITED UINT_MAX
+#define SET_SIZE_UNLIMITED UOFF_T_MAX
+
+/* These values are shown as "infinite" */
+#define SET_VALUE_INFINITE "infinite"
+#define SET_TIME_INFINITE UINT_MAX
+#define SET_TIME_MSECS_INFINITE UINT_MAX
+
enum setting_type {
SET_BOOL,
SET_UINT,
const char *settings_section_escape(const char *name);
const char *settings_section_unescape(const char *name);
+static inline bool settings_value_is_unlimited(const char *value)
+{
+ /* allow both as input for all types */
+ return strcmp(value, SET_VALUE_UNLIMITED) == 0 ||
+ strcmp(value, SET_VALUE_INFINITE) == 0;
+}
+
void set_config_binary(bool value);
bool is_config_binary(void);