예제 #1
0
파일: log.c 프로젝트: Acidburn0zzz/mpd
bool
log_init(bool verbose, bool use_stdout, GError **error_r)
{
	const struct config_param *param;

	g_get_charset(&log_charset);

	if (verbose)
		log_threshold = G_LOG_LEVEL_DEBUG;
	else if ((param = config_get_param(CONF_LOG_LEVEL)) != NULL)
		log_threshold = parse_log_level(param->value, param->line);

	if (use_stdout) {
		log_init_stdout();
		return true;
	} else {
		param = config_get_param(CONF_LOG_FILE);
		if (param == NULL) {
#ifdef HAVE_SYSLOG
			/* no configuration: default to syslog (if
			   available) */
			log_init_syslog();
			return true;
#else
			g_set_error(error_r, log_quark(), 0,
				    "config parameter \"%s\" not found",
				    CONF_LOG_FILE);
			return false;
#endif
#ifdef HAVE_SYSLOG
		} else if (strcmp(param->value, "syslog") == 0) {
			log_init_syslog();
			return true;
#endif
		} else {
			GError *error = NULL;
			char *path = config_dup_path(CONF_LOG_FILE, &error);
			if (path == NULL) {
				assert(error != NULL);
				g_propagate_error(error_r, error);
				return false;
			}

			bool success = log_init_file(path, param->line,
						     error_r);
			g_free(path);
			return success;
		}
	}
}
예제 #2
0
void replay_gain_global_init(void)
{
	const struct config_param *param = config_get_param(CONF_REPLAYGAIN);

	if (param != NULL && !replay_gain_set_mode_string(param->value)) {
		MPD_ERROR("replaygain value \"%s\" at line %i is invalid\n",
			  param->value, param->line);
	}

	param = config_get_param(CONF_REPLAYGAIN_PREAMP);

	if (param) {
		char *test;
		float f = strtod(param->value, &test);

		if (*test != '\0') {
			MPD_ERROR("Replaygain preamp \"%s\" is not a number at "
				  "line %i\n", param->value, param->line);
		}

		if (f < -15 || f > 15) {
			MPD_ERROR("Replaygain preamp \"%s\" is not between -15 and"
				  "15 at line %i\n", param->value, param->line);
		}

		replay_gain_preamp = pow(10, f / 20.0);
	}

	param = config_get_param(CONF_REPLAYGAIN_MISSING_PREAMP);

	if (param) {
		char *test;
		float f = strtod(param->value, &test);

		if (*test != '\0') {
			MPD_ERROR("Replaygain missing preamp \"%s\" is not a number at "
				  "line %i\n", param->value, param->line);
		}

		if (f < -15 || f > 15) {
			MPD_ERROR("Replaygain missing preamp \"%s\" is not between -15 and"
				  "15 at line %i\n", param->value, param->line);
		}

		replay_gain_missing_preamp = pow(10, f / 20.0);
	}

	replay_gain_limit = config_get_bool(CONF_REPLAYGAIN_LIMIT, DEFAULT_REPLAYGAIN_LIMIT);
}
예제 #3
0
파일: main.c 프로젝트: andrewrk/mpd
/**
 * Returns the database.  If this function returns false, this has not
 * succeeded, and the caller should create the database after the
 * process has been daemonized.
 */
static bool
glue_db_init_and_load(void)
{
	const struct config_param *path = config_get_param(CONF_DB_FILE);

	GError *error = NULL;
	bool ret;

	if (!mapper_has_music_directory()) {
		if (path != NULL)
			g_message("Found " CONF_DB_FILE " setting without "
				  CONF_MUSIC_DIR " - disabling database");
		db_init(NULL, NULL);
		return true;
	}

	if (path == NULL)
		MPD_ERROR(CONF_DB_FILE " setting missing");

	if (!db_init(path, &error))
		MPD_ERROR("%s", error->message);

	ret = db_load(&error);
	if (!ret)
		MPD_ERROR("%s", error->message);

	/* run database update after daemonization? */
	return db_exists();
}
예제 #4
0
파일: main.c 프로젝트: andrewrk/mpd
/**
 * Initialize the decoder and player core, including the music pipe.
 */
static void
initialize_decoder_and_player(void)
{
	const struct config_param *param;
	char *test;
	size_t buffer_size;
	float perc;
	unsigned buffered_chunks;
	unsigned buffered_before_play;

	param = config_get_param(CONF_AUDIO_BUFFER_SIZE);
	if (param != NULL) {
		long tmp = strtol(param->value, &test, 10);
		if (*test != '\0' || tmp <= 0 || tmp == LONG_MAX)
			MPD_ERROR("buffer size \"%s\" is not a positive integer, "
				  "line %i\n", param->value, param->line);
		buffer_size = tmp;
	} else
		buffer_size = DEFAULT_BUFFER_SIZE;

	buffer_size *= 1024;

	buffered_chunks = buffer_size / CHUNK_SIZE;

	if (buffered_chunks >= 1 << 15)
		MPD_ERROR("buffer size \"%li\" is too big\n", (long)buffer_size);

	param = config_get_param(CONF_BUFFER_BEFORE_PLAY);
	if (param != NULL) {
		perc = strtod(param->value, &test);
		if (*test != '%' || perc < 0 || perc > 100) {
			MPD_ERROR("buffered before play \"%s\" is not a positive "
				  "percentage and less than 100 percent, line %i",
				  param->value, param->line);
		}
	} else
		perc = DEFAULT_BUFFER_BEFORE_PLAY;

	buffered_before_play = (perc / 100) * buffered_chunks;
	if (buffered_before_play > buffered_chunks)
		buffered_before_play = buffered_chunks;

	global_player_control = pc_new(buffered_chunks, buffered_before_play);
}
예제 #5
0
파일: log.c 프로젝트: azuwis/mpd
void log_init(bool verbose, bool use_stdout)
{
	const struct config_param *param;

	g_get_charset(&log_charset);

	if (verbose)
		log_threshold = G_LOG_LEVEL_DEBUG;
	else if ((param = config_get_param(CONF_LOG_LEVEL)) != NULL)
		log_threshold = parse_log_level(param->value, param->line);

	if (use_stdout) {
		log_init_stdout();
	} else {
		param = config_get_param(CONF_LOG_FILE);
		if (param == NULL) {
#ifdef HAVE_SYSLOG
			/* no configuration: default to syslog (if
			   available) */
			log_init_syslog();
#else
			g_error("config parameter \"%s\" not found\n",
				CONF_LOG_FILE);
#endif
#ifdef HAVE_SYSLOG
		} else if (strcmp(param->value, "syslog") == 0) {
			log_init_syslog();
#endif
		} else {
			char *path = parsePath(param->value);
			g_free(param->value);

			if (path == NULL)
				g_error("error parsing \"%s\" at line %i\n",
					CONF_LOG_FILE, param->line);

			log_init_file(path, param->line);
		}
	}
}
예제 #6
0
int config_file_parse (char *file, stud_config *cfg) {
  if (cfg == NULL)
    config_die("Undefined stud options; THIS IS A BUG!\n");

  char line[CONFIG_BUF_SIZE];
  FILE *fd = NULL;

  // should we read stdin?
  if (file == NULL || strlen(file) < 1 || strcmp(file, "-") == 0) {
    fd = stdin;
  } else {
    fd = fopen(file, "r");
  }
  if (fd == NULL)
      config_die("Unable to open configuration file '%s': %s\n", file, strerror(errno));

  // read config
  int i = 0;
  while (i < CONFIG_MAX_LINES) {
    memset(line, '\0', sizeof(line));
    if (fgets(line, (sizeof(line) - 1), fd) == NULL) break;
    i++;

    // get configuration key
    char *key, *val;
    key = config_get_param(line);
    if (key == NULL) continue;

    // get configuration key value...
    val = config_get_value(line);
    if (val == NULL) continue;
    str_trim(val);

    // printf("File '%s', line %d, key: '%s', value: '%s'\n", file, i, key, val);

    // validate configuration key => value
    config_param_validate(key, val, cfg, file, i);
  }

  fclose(fd);

  return 1;
}
예제 #7
0
void initPermissions(void)
{
	char *password;
	unsigned permission;
	const struct config_param *param;

	permission_passwords = g_hash_table_new_full(g_str_hash, g_str_equal,
						     g_free, NULL);

	permission_default = PERMISSION_READ | PERMISSION_ADD |
	    PERMISSION_CONTROL | PERMISSION_ADMIN;

	param = config_get_next_param(CONF_PASSWORD, NULL);

	if (param) {
		permission_default = 0;

		do {
			const char *separator =
				strchr(param->value, PERMISSION_PASSWORD_CHAR);

			if (separator == NULL)
				MPD_ERROR("\"%c\" not found in password string "
					"\"%s\", line %i",
					PERMISSION_PASSWORD_CHAR,
					param->value, param->line);

			password = g_strndup(param->value,
					     separator - param->value);

			permission = parsePermissions(separator + 1);

			g_hash_table_replace(permission_passwords,
					     password,
					     GINT_TO_POINTER(permission));
		} while ((param = config_get_next_param(CONF_PASSWORD, param)));
	}

	param = config_get_param(CONF_DEFAULT_PERMS);

	if (param)
		permission_default = parsePermissions(param->value);
}
/**
 * loads configuration file
 * @param configuration file
 * @return 1 on success, otherwise false
 */
int load_config_file (char *file) {
	FILE *fd;
	char buf[GEN_BUF_SIZE];
	char *var, *val;

	if (file == NULL) {
		log_msg("Unspecified configuration file (file == NULL)");
		return 0;
	}
	else if ((fd = fopen(file, "r")) == NULL) {
		/** log_msg("Unable to open configuration file '%s': %s", file, strerror(errno));
		*/
		return 0;
	}

	int lines = 0;
	
	/* read and parse config */
	while (lines < CONF_FILE_MAXLINES) {
		memset(buf, '\0', sizeof(buf));
		if (fgets(buf, sizeof(buf), fd) == NULL) break;
		lines++;
		
		var = config_get_param(buf);
		if (var == NULL) continue;
		val = config_get_value(buf);
		if (val == NULL) continue;
		
		if (strcmp(var, "hostname") == 0) {
			strncpy(hostname, val, sizeof(hostname));
		}
		else if (strcmp(var, "port") == 0)
			port = (val != NULL) ? atoi(val) : DEFAULT_PORT;
		else if (strcmp(var, "timeout") == 0)
			timeout = (val != NULL) ? atoi(val) : DEFAULT_AUTH_TIMEOUT;
		else
			log_msg("Warning: unknown configuration parameter '%s' in configuration file '%s' line %d.", var, file, lines);
	}

	fclose(fd);
	return 1;
}