static void disablelog_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
	if (value) {
		cs_disable_log(strToIntVal(value, 0));
		return;
	}
	if (cfg.disablelog || cfg.http_full_cfg)
		fprintf_conf(f, token, "%d\n", cfg.disablelog);
}
static void account_tosleep_fn(const char *token, char *value, void *setting, FILE *f) {
	int32_t *tosleep = setting;
	if (value) {
		*tosleep = strToIntVal(value, cfg.tosleep);
		return;
	}
	if (*tosleep != cfg.tosleep || cfg.http_full_cfg)
		fprintf_conf(f, token, "%d\n", *tosleep);
}
static void account_ncd_keepalive_fn(const char *token, char *value, void *setting, FILE *f) {
	int8_t *ncd_keepalive = setting;
	if (value) {
		*ncd_keepalive = (int8_t)strToIntVal(value, cfg.ncd_keepalive);
		return;
	}
	if (*ncd_keepalive != cfg.ncd_keepalive || cfg.http_full_cfg)
		fprintf_conf(f, token, "%d\n", *ncd_keepalive);
}
static void account_c35_suppresscmd08_fn(const char *token, char *value, void *setting, FILE *f) {
	int8_t *c35_suppresscmd08 = setting;
	if (value) {
		*c35_suppresscmd08 = (int8_t)strToIntVal(value, cfg.c35_suppresscmd08);
		return;
	}
	if (*c35_suppresscmd08 != cfg.c35_suppresscmd08 || cfg.http_full_cfg)
		fprintf_conf(f, token, "%d\n", *c35_suppresscmd08);
}
Example #5
0
static void account_ncd_keepalive_fn(const char *token, char *value, void *setting, FILE *f)
{
	int8_t *ncd_keepalive = setting;
	int8_t def_value = 0;
#ifdef MODULE_NEWCAMD
	def_value = cfg.ncd_keepalive;
#endif
	if(value)
	{
		*ncd_keepalive = (int8_t)strToIntVal(value, def_value);
		return;
	}
	if(*ncd_keepalive != def_value || cfg.http_full_cfg)
		{ fprintf_conf(f, token, "%d\n", *ncd_keepalive); }
}
Example #6
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 #7
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;
}