Example #1
0
static bool config_load_sensor(int sensor)
{
	int i;
	char key[CONFIG_STR_MAX];
	char str_value[CONFIG_STR_MAX];

	for (i = 0; i < CONFIG_MAX_SENSOR_PARAMS; i++) {
		snprintf(key, CONFIG_STR_MAX, config_uci_sensor_tpl[i], sensor + 1);
		switch (i) {
		case 0:
			if (!config_load_str(key, conf.sensor[sensor].id)) {
				return false;
			}
			break;
		case 1:
			/* we only require a type for pulse sensors */
			if (sensor < CONFIG_MAX_SENSORS - 3) {
				break;
			}
			if (!config_load_str(key, str_value)) {
				return false;
			}
			conf.sensor[sensor].type = (uint8_t)config_type_to_index(str_value);
			break;
		case 2:
			conf.sensor[sensor].enable = (uint8_t)config_load_uint(key, 0);
			break;
		}
	}
	return true;
}
Example #2
0
static double config_load_fp(char *key, double def)
{
	char str_value[CONFIG_STR_MAX];

	if (!config_load_str(key, str_value)) {
		return def;
	}
	return atof(str_value);
}
Example #3
0
static uint32_t config_load_uint(char *key, uint32_t def)
{
	char str_value[CONFIG_STR_MAX];

	if (!config_load_str(key, str_value)) {
		return def;
	}
	return strtoul(str_value, (char **)NULL, 10);
}
Example #4
0
static void config_load_main(void)
{
	char str_value[CONFIG_STR_MAX];

	conf.main.phase = config_load_str(CONFIG_UCI_PHASE, str_value) ?
		config_phase_to_index(str_value) : CONFIG_1PHASE;
	conf.main.led = (uint8_t)config_load_uint(CONFIG_UCI_LED_MODE,
	                                          CONFIG_LED_MODE_DEFAULT);
}
Example #5
0
bool config_load_all(void)
{
	int i;

	if (!config_load_str(CONFIG_UCI_DEVICE, conf.device))
		return false;
	for (i = 0; i < CONFIG_MAX_SENSORS; i++) {
		if (!config_load_sensor(i)) {
			return false;
		}
	}
	for (i = 0; i < CONFIG_MAX_PORTS; i++) {
		config_load_port(i);
	}
	config_load_main();
	config_push();
	return true;
}
Example #6
0
int config_load(const char *fname)
{
	struct val *lv;
	char *raw;

	srand(time(NULL));

	if (fname) {
		raw = read_file(fname);
		if (IS_ERR(raw))
			return PTR_ERR(raw);

		lv = sexpr_parse_cstr(raw);

		free(raw);

		if (!lv)
			return -EINVAL;
	} else {
		lv = NULL;
	}

	config_load_scgi_port(lv);
	config_load_scgi_threads(lv);
	config_load_u64(lv, CONFIG_HTML_INDEX_STORIES, &config.html_index_stories,
			DEFAULT_HTML_INDEX_STORIES);
	config_load_u64(lv, CONFIG_FEED_INDEX_STORIES, &config.feed_index_stories,
			DEFAULT_FEED_INDEX_STORIES);
	config_load_u64(lv, CONFIG_COMMENT_MAX_THINK, &config.comment_max_think,
			DEFAULT_COMMENT_MAX_THINK);
	config_load_u64(lv, CONFIG_COMMENT_MIN_THINK, &config.comment_min_think,
			DEFAULT_COMMENT_MIN_THINK);
	config_load_u64(lv, CONFIG_COMMENT_CAPTCHA_A, &config.comment_captcha_a,
			rand());
	config_load_u64(lv, CONFIG_COMMENT_CAPTCHA_B, &config.comment_captcha_b,
			rand());
	config_load_str(lv, CONFIG_DATA_DIR, &config.data_dir, DEFAULT_DATA_DIR);
	config_load_str(lv, CONFIG_WEB_DIR, &config.web_dir, DEFAULT_WEB_DIR);
	config_load_url(lv, CONFIG_BASE_URL, &config.base_url);
	config_load_url(lv, CONFIG_BUG_BASE_URL, &config.bug_base_url);
	config_load_url(lv, CONFIG_WIKI_BASE_URL, &config.wiki_base_url);
	config_load_url(lv, CONFIG_PHOTO_BASE_URL, &config.photo_base_url);
	config_load_u64(lv, CONFIG_TAGCLOUD_MIN_SIZE, &config.tagcloud_min_size,
			DEFAULT_TAGCLOUD_MIN_SIZE);
	config_load_u64(lv, CONFIG_TAGCLOUD_MAX_SIZE, &config.tagcloud_max_size,
			DEFAULT_TAGCLOUD_MAX_SIZE);
	config_load_str(lv, CONFIG_LATEX_BIN, &config.latex_bin,
			DEFAULT_LATEX_BIN);
	config_load_str(lv, CONFIG_DVIPS_BIN, &config.dvips_bin,
			DEFAULT_DVIPS_BIN);
	config_load_str(lv, CONFIG_CONVERT_BIN, &config.convert_bin,
			DEFAULT_CONVERT_BIN);
	config_load_str(lv, CONFIG_TWITTER_USERNAME, &config.twitter_username,
			NULL);
	config_load_str(lv, CONFIG_TWITTER_DESCRIPTION, &config.twitter_description,
			NULL);

	val_putref(lv);

	DBG("config.scgi_port = %u", config.scgi_port);
	DBG("config.scgi_threads = %"PRIu64, config.scgi_threads);
	DBG("config.html_index_stories = %"PRIu64, config.html_index_stories);
	DBG("config.feed_index_stories = %"PRIu64, config.feed_index_stories);
	DBG("config.comment_max_think = %"PRIu64, config.comment_max_think);
	DBG("config.comment_min_think = %"PRIu64, config.comment_min_think);
	DBG("config.comment_captcha_a = %"PRIu64, config.comment_captcha_a);
	DBG("config.comment_captcha_b = %"PRIu64, config.comment_captcha_b);
	DBG("config.data_dir = %s", str_cstr(config.data_dir));
	DBG("config.web_dir = %s", str_cstr(config.web_dir));
	DBG("config.base_url = %s", str_cstr(config.base_url));
	DBG("config.wiki_base_url = %s", str_cstr(config.wiki_base_url));
	DBG("config.bug_base_url = %s", str_cstr(config.bug_base_url));
	DBG("config.photo_base_url = %s", str_cstr(config.photo_base_url));
	DBG("config.tagcloud_min_size = %"PRIu64, config.tagcloud_min_size);
	DBG("config.tagcloud_max_size = %"PRIu64, config.tagcloud_max_size);
	DBG("config.latex_bin = %s", str_cstr(config.latex_bin));
	DBG("config.dvips_bin = %s", str_cstr(config.dvips_bin));
	DBG("config.convert_bin = %s", str_cstr(config.convert_bin));
	DBG("config.twitter_username = %s", str_cstr(config.twitter_username));
	DBG("config.twitter_description = %s", str_cstr(config.twitter_description));

	return 0;
}