Ejemplo n.º 1
0
static s4_sourcepref_t *
normalize_source_preferences (xmmsv_t *fetch, s4_sourcepref_t *prefs, xmms_error_t *err)
{
	s4_sourcepref_t *sp;
	xmmsv_list_iter_t *it;
	const char **strv;
	const gchar *str;
	xmmsv_t *list;
	gint length, idx;

	if (!xmmsv_dict_get (fetch, "source-preference", &list)) {
		return s4_sourcepref_ref (prefs);
	}

	if (xmmsv_get_type (list) != XMMSV_TYPE_LIST) {
		const gchar *message = "'source-preference' must be a list of strings.";
		xmms_error_set (err, XMMS_ERROR_INVAL, message);
		return NULL;
	}

	length = xmmsv_list_get_size (list);
	if (length == 0) {
		return s4_sourcepref_ref (prefs);
	}

	strv = g_new0 (const char *, length + 1);

	idx = 0;

	xmmsv_get_list_iter (list, &it);
	while (xmmsv_list_iter_valid (it)) {
		if (!xmmsv_list_iter_entry_string (it, &str)) {
			const gchar *message = "'source-preference' must be a list of strings.";
			xmms_error_set (err, XMMS_ERROR_INVAL, message);
			g_free (strv);
			return NULL;
		}

		strv[idx++] = str;

		xmmsv_list_iter_next (it);
	}

	sp = s4_sourcepref_create (strv);
	g_free (strv);

	return sp;
}
Ejemplo n.º 2
0
Archivo: cond.c Proyecto: dchokola/s4
/**
 * Creates a new filter condition with a user specified filter function.
 * The filter function should return 0 if the value meets the condition,
 * non-zero otherwise.
 *
 * @param func The filter function to use
 * @param userdata The data that will be passed to the function
 * along with the value to check
 * @param free The function that should be called to free userdata
 * @param key The key the condition should check
 * @param sourcepref The source preference
 * @param cmp_mode The comparison mode to use
 * @param flags Condition flags, or 0
 * @return A new custom filter condition
 */
s4_condition_t *s4_cond_new_custom_filter (filter_function_t func, void *userdata,
		free_func_t free, const char *key, s4_sourcepref_t *sourcepref,
		s4_cmp_mode_t cmp_mode, int monotonic, int flags)
{
	s4_condition_t *cond = malloc (sizeof (s4_condition_t));

	cond->type = S4_COND_FILTER;
	cond->u.filter.type = S4_FILTER_CUSTOM;
	cond->ref_count = 1;
	cond->u.filter.key = key==NULL?NULL:strdup (key);
	cond->u.filter.flags = flags;
	cond->u.filter.func = func;
	cond->u.filter.funcdata = userdata;
	cond->u.filter.free_func = free;
	cond->u.filter.monotonic = monotonic;
	cond->u.filter.cmp_mode = cmp_mode;
	cond->u.filter.const_key = 0;

	if (sourcepref != NULL) {
		cond->u.filter.sp = s4_sourcepref_ref (sourcepref);
	} else {
		cond->u.filter.sp = NULL;
	}

	return cond;
}
Ejemplo n.º 3
0
Archivo: cond.c Proyecto: dchokola/s4
/**
 * Creates a new filter condition
 *
 * @param type The type of the filter
 * @param key The key the condition should check
 * @param value The value to check against
 * @param sourcepref The source preference
 * @param cmp_mode The comparison mode to use
 * @param flags Condition flags, or 0
 * @return A new filter condition
 */
s4_condition_t *s4_cond_new_filter (s4_filter_type_t type,
		const char *key, const s4_val_t *value,
		s4_sourcepref_t *sourcepref, s4_cmp_mode_t cmp_mode,
		int flags)
{
	s4_condition_t *cond = malloc (sizeof (s4_condition_t));

	cond->type = S4_COND_FILTER;
	cond->u.filter.type = type;
	cond->ref_count = 1;
	cond->u.filter.key = key==NULL?NULL:strdup (key);
	cond->u.filter.flags = flags;
	cond->u.filter.cmp_mode = cmp_mode;
	cond->u.filter.const_key = 0;

	if (sourcepref != NULL) {
		cond->u.filter.sp = s4_sourcepref_ref (sourcepref);
	} else {
		cond->u.filter.sp = NULL;
	}

	_set_filter_function (cond, type, value);

	return cond;
}
Ejemplo n.º 4
0
/**
 * Adds something to fetch to the fetch specification. If key is NULL, it will fetch
 * everything in an entry
 *
 * @param spec The specification to add to
 * @param key The key to fetch
 * @param sourcepref The sourcepref to use when deciding which key-value pair to fetch
 * @param flags Flags to decide what to fetch
 */
void s4_fetchspec_add (s4_fetchspec_t *spec, const char *key, s4_sourcepref_t *sourcepref, int flags)
{
	fetch_data_t data;
	data.flags = flags;
	data.const_key = 0;
	if (key == NULL) {
		data.key = NULL;
	} else {
		data.key = strdup (key);
	}
	if (sourcepref != NULL) {
		data.pref = s4_sourcepref_ref (sourcepref);
	} else {
		data.pref = NULL;
	}

	g_array_append_val (spec->array, data);
}
Ejemplo n.º 5
0
s4_sourcepref_t *
xmms_medialib_get_source_preferences (xmms_medialib_t *medialib)
{
	return s4_sourcepref_ref (medialib->default_sp);
}