/**
 * Update a SearchExpression with a new key = value condition.
 *
 * Will modifiy the passed expression to (expression AND (key = value))
 *
 * @param expression The expression to update or null to create a new one
 * @param key        Key of the key/value condition
 * @param value      Value of the key/value condition
 */
static void
rygel_media_export_query_container_factory_update_search_expression (RygelSearchExpression **expression,
                                                                     const gchar            *key,
                                                                     const gchar            *value) {
  RygelSearchExpression *search_sub;
  RygelRelationalExpression *subexpression;
  gchar *clean_key;
  GError *error;

  g_return_if_fail (expression != NULL);
  g_return_if_fail (*expression == NULL || RYGEL_IS_SEARCH_EXPRESSION (*expression));
  g_return_if_fail (key != NULL);
  g_return_if_fail (value != NULL);

  subexpression = rygel_relational_expression_new ();
  search_sub = RYGEL_SEARCH_EXPRESSION (subexpression);
  error = NULL;
  clean_key = rygel_media_export_string_replace (key,
                                                 RYGEL_MEDIA_EXPORT_QUERY_CONTAINER_PREFIX,
                                                 "",
                                                 &error);
  if (error) {
    g_warning ("Failed to remove "  " from %s: %s",
               key,
               error->message);
    g_error_free (error);
  }
  search_sub->operand1 = g_uri_unescape_string (clean_key, NULL);
  search_sub->op = (gpointer) ((gintptr) GUPNP_SEARCH_CRITERIA_OP_EQ);
  search_sub->operand2 = g_uri_unescape_string (value, NULL);
  g_free (clean_key);
  if (*expression) {
    RygelLogicalExpression *conjunction = rygel_logical_expression_new ();
    RygelSearchExpression *search_conj = RYGEL_SEARCH_EXPRESSION (conjunction);

    search_conj->operand1 = *expression;
    search_conj->operand2 = subexpression;
    search_conj->op = (gpointer) ((gintptr) RYGEL_LOGICAL_OPERATOR_AND);
    *expression = search_conj;
  } else {
    *expression = search_sub;
  }
}
Пример #2
0
static gboolean rygel_media_container_find_object_co (RygelMediaContainerFindObjectData* data) {
	switch (data->_state_) {
		case 0:
		goto _state_0;
		case 29:
		goto _state_29;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		data->expression = rygel_relational_expression_new ();
#line 220 "rygel-media-container.vala"
		((RygelSearchExpression*) data->expression)->op = GINT_TO_POINTER (GUPNP_SEARCH_CRITERIA_OP_EQ);
#line 221 "rygel-media-container.vala"
		((RygelSearchExpression*) data->expression)->operand1 = (data->_tmp0_ = g_strdup ("@id"), _g_free0 (((RygelSearchExpression*) data->expression)->operand1), data->_tmp0_);
#line 222 "rygel-media-container.vala"
		((RygelSearchExpression*) data->expression)->operand2 = (data->_tmp1_ = g_strdup (data->id), _g_free0 (((RygelSearchExpression*) data->expression)->operand2), data->_tmp1_);
#line 902 "rygel-media-container.c"
		data->_state_ = 29;
		rygel_media_container_search (data->self, (RygelSearchExpression*) data->expression, (guint) 0, (guint) 1, data->cancellable, rygel_media_container_find_object_ready, data);
		return FALSE;
		_state_29:
		data->results = rygel_media_container_search_finish (data->self, data->_res_, &data->total_matches, &data->_inner_error_);
		if (data->_inner_error_ != NULL) {
			g_simple_async_result_set_from_error (data->_async_result, data->_inner_error_);
			g_error_free (data->_inner_error_);
			_rygel_search_expression_unref0 (data->expression);
			{
				if (data->_state_ == 0) {
					g_simple_async_result_complete_in_idle (data->_async_result);
				} else {
					g_simple_async_result_complete (data->_async_result);
				}
				g_object_unref (data->_async_result);
				return FALSE;
			}
		}
#line 230 "rygel-media-container.vala"
		if (gee_collection_get_size ((GeeCollection*) data->results) > 0) {
#line 924 "rygel-media-container.c"
			data->result = (RygelMediaObject*) gee_list_get (data->results, 0);
			_rygel_search_expression_unref0 (data->expression);
			_g_object_unref0 (data->results);
			{
				if (data->_state_ == 0) {
					g_simple_async_result_complete_in_idle (data->_async_result);
				} else {
					g_simple_async_result_complete (data->_async_result);
				}
				g_object_unref (data->_async_result);
				return FALSE;
			}
		} else {
			data->result = NULL;
			_rygel_search_expression_unref0 (data->expression);
			_g_object_unref0 (data->results);
			{
				if (data->_state_ == 0) {
					g_simple_async_result_complete_in_idle (data->_async_result);
				} else {
					g_simple_async_result_complete (data->_async_result);
				}
				g_object_unref (data->_async_result);
				return FALSE;
			}
		}
		_rygel_search_expression_unref0 (data->expression);
		_g_object_unref0 (data->results);
	}
	{
		if (data->_state_ == 0) {
			g_simple_async_result_complete_in_idle (data->_async_result);
		} else {
			g_simple_async_result_complete (data->_async_result);
		}
		g_object_unref (data->_async_result);
		return FALSE;
	}
}