static void loghistorysize_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
	if (value) {
		uint32_t newsize = strToUIntVal(value, 4096);
		if (newsize < 1024 && newsize != 0) {
			fprintf(stderr, "WARNING: loghistorysize is too small, adjusted to 1024\n");
			newsize = 1024;
		}
		cs_reinit_loghist(newsize);
		return;
	}
	if (cfg.loghistorysize != 4096 || cfg.http_full_cfg)
		fprintf_conf(f, token, "%u\n", cfg.loghistorysize);
}
Example #2
0
int config_list_parse(const struct config_list *clist, const char *token, char *value, void *config_data)
{
	const struct config_list *c;
	for(c = clist; c->opt_type != OPT_UNKNOWN; c++)
	{
		if(c->opt_type == OPT_SAVE_FUNC || c->opt_type == OPT_FIXUP_FUNC)
			{ continue; }
		if(strcasecmp(token, c->config_name) != 0)
			{ continue; }
		void *var = config_data + c->var_offset;
		switch(c->opt_type)
		{
		case OPT_INT8:
		{
			*(int8_t *)var = (int8_t)strToIntVal(value, c->def.d_int8);
			return 1;
		}
		case OPT_UINT8:
		{
			uint32_t tmp = strToUIntVal(value, c->def.d_uint8);
			*(uint8_t *)var = (uint8_t)(tmp <= 0xff ? tmp : 0xff);
			return 1;
		}
		case OPT_INT32:
		{
			int32_t tmp = strToIntVal(value, c->def.d_int32);
			memcpy(var, &tmp, sizeof(int32_t));
			return 1;
		}
		case OPT_UINT32:
		{
			uint32_t tmp = strToUIntVal(value, c->def.d_uint32);
			memcpy(var, &tmp, sizeof(uint32_t));
			return 1;
		}
		case OPT_STRING:
		{
			char **scfg = var;
			if(c->def.d_char && strlen(value) == 0)  // Set default
				{ value = c->def.d_char; }
			NULLFREE(*scfg);
			if(strlen(value))
				{ *scfg = cs_strdup(value); }
			return 1;
		}
		case OPT_SSTRING:
		{
			char *scfg = var;
			if(c->def.d_char && strlen(value) == 0)  // Set default
				{ value = c->def.d_char; }
			scfg[0] = '\0';
			unsigned int len = strlen(value);
			if(len)
			{
				strncpy(scfg, value, c->str_size - 1);
				if(len > c->str_size)
				{
					fprintf(stderr, "WARNING: Config value for '%s' (%s, len=%u) exceeds max length: %d (%s)\n",
							token, value, len, c->str_size - 1, scfg);
				}
			}
			return 1;
		}
		case OPT_HEX_ARRAY:
		{
			uint8_t *hex_array = var;
			if(!strlen(value))
				{ memset(hex_array, 0, c->def.array_size); }
			else if(key_atob_l(value, hex_array, c->def.array_size * 2))
			{
				memset(hex_array, 0, c->def.array_size);
				fprintf(stderr, "WARNING: Config value for '%s' (%s, len=%zu) requires %d chars.\n",
						token, value, strlen(value), c->def.array_size * 2);
			}
			return 1;
		}
		case OPT_FUNC:
		{
			c->ops.process_fn(token, value, var, NULL);
			return 1;
		}
		case OPT_FUNC_EXTRA:
		{
			c->ops.process_fn_extra(token, value, var, c->def.d_extra, NULL);
			return 1;
		}
		case OPT_FIXUP_FUNC:
		case OPT_SAVE_FUNC:
			return 1;
		case OPT_UNKNOWN:
		{
			fprintf(stderr, "Unknown config type (%s = %s).", token, value);
			break;
		}
		}
	}
	return 0;
}
Example #3
0
int config_list_parse(const struct config_list *clist, const char *token, char *value, void *config_data) {
	const struct config_list *c;
	for (c = clist; c->opt_type != OPT_UNKNOWN; c++) {
		if (c->opt_type == OPT_SAVE_FUNC || c->opt_type == OPT_FIXUP_FUNC)
			continue;
		if (strcasecmp(token, c->config_name) != 0)
			continue;
		void *var = config_data + c->var_offset;
		switch (c->opt_type) {
		case OPT_INT8: {
			*(int8_t *)var = (int8_t)strToIntVal(value, c->def.d_int8);
			return 1;
		}
		case OPT_UINT8: {
			uint32_t tmp = strToUIntVal(value, c->def.d_uint8);
			*(uint8_t *)var = (uint8_t)(tmp <= 0xff ? tmp : 0xff);
			return 1;
		}
		case OPT_INT32: {
			*(int32_t *)var = strToIntVal(value, c->def.d_int32);
			return 1;
		}
		case OPT_UINT32: {
			*(uint32_t *)var = strToUIntVal(value, c->def.d_uint32);
			return 1;
		}
		case OPT_STRING: {
			char **scfg = var;
			if (c->def.d_char && strlen(value) == 0) // Set default
				value = c->def.d_char;
			NULLFREE(*scfg);
			if (strlen(value))
				*scfg = cs_strdup(value);
			return 1;
		}
		case OPT_SSTRING: {
			char *scfg = var;
			if (c->def.d_char && strlen(value) == 0) // Set default
				value = c->def.d_char;
			scfg[0] = '\0';
			unsigned int len = strlen(value);
			if (len) {
				strncpy(scfg, value, c->str_size - 1);
				if (len > c->str_size) {
					fprintf(stderr, "WARNING: Config value for '%s' (%s, len=%u) exceeds max length: %d (%s)\n",
						token, value, len, c->str_size - 1, scfg);
				}
			}
			return 1;
		}
		case OPT_FUNC: {
			c->ops.process_fn(token, value, var, NULL);
			return 1;
		}
		case OPT_FIXUP_FUNC:
		case OPT_SAVE_FUNC:
			return 1;
		case OPT_UNKNOWN: {
			fprintf(stderr, "Unknown config type (%s = %s).", token, value);
			break;
		}
		}
	}
	return 0;
}