/* rygel-external-variant-util.c generated by valac 0.56.19, the Vala compiler
 * generated from rygel-external-variant-util.vala, do not modify */

/*
 * Copyright (C) 2012 Jens Georg <mail@jensge.org>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include "rygel-external.h"
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL)))

static gchar* _variant_get33 (GVariant* value);
static gchar** _vala_array_dup1 (gchar** self,
                          gssize length);
static gchar** _variant_get34 (GVariant* value,
                        gint* result_length1);

static gpointer
_g_variant_ref0 (gpointer self)
{
	return self ? g_variant_ref (self) : NULL;
}

GVariant*
rygel_external_get_mandatory (GHashTable* props,
                              const gchar* key,
                              const gchar* service_name)
{
	GVariant* value = NULL;
	gconstpointer _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp2_;
	GVariant* result;
	g_return_val_if_fail (props != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (service_name != NULL, NULL);
	_tmp0_ = g_hash_table_lookup (props, key);
	_tmp1_ = _g_variant_ref0 ((GVariant*) _tmp0_);
	value = _tmp1_;
	_tmp2_ = value;
	if (_tmp2_ == NULL) {
		g_warning (_ (RYGEL_EXTERNAL_MANDATORY_MISSING_MESSAGE), service_name, key);
		result = NULL;
		_g_variant_unref0 (value);
		return result;
	}
	result = value;
	return result;
}

static gchar*
_variant_get33 (GVariant* value)
{
	return g_variant_dup_string (value, NULL);
}

gchar*
rygel_external_get_mandatory_string_value (GHashTable* props,
                                           const gchar* key,
                                           const gchar* _default_,
                                           const gchar* service_name)
{
	GVariant* value = NULL;
	GVariant* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (props != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (_default_ != NULL, NULL);
	g_return_val_if_fail (service_name != NULL, NULL);
	_tmp0_ = rygel_external_get_mandatory (props, key, service_name);
	value = _tmp0_;
	_tmp1_ = value;
	if (_tmp1_ == NULL) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup (_default_);
		result = _tmp2_;
		_g_variant_unref0 (value);
		return result;
	}
	_tmp3_ = value;
	_tmp4_ = _variant_get33 (_tmp3_);
	result = _tmp4_;
	_g_variant_unref0 (value);
	return result;
}

static gchar**
_vala_array_dup1 (gchar** self,
                  gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gchar**
_variant_get34 (GVariant* value,
                gint* result_length1)
{
	gchar** _tmp0_;
	gint _tmp0__length;
	gint _tmp0__size;
	gint _tmp0__length1;
	GVariantIter _tmp1_;
	GVariant* _tmp2_;
	_tmp0_ = g_new (gchar*, 5);
	_tmp0__length = 0;
	_tmp0__size = 4;
	_tmp0__length1 = 0;
	g_variant_iter_init (&_tmp1_, value);
	for (; (_tmp2_ = g_variant_iter_next_value (&_tmp1_)) != NULL; _tmp0__length1++) {
		if (_tmp0__size == _tmp0__length) {
			_tmp0__size = 2 * _tmp0__size;
			_tmp0_ = g_renew (gchar*, _tmp0_, _tmp0__size + 1);
		}
		_tmp0_[_tmp0__length++] = g_variant_dup_string (_tmp2_, NULL);
		g_variant_unref (_tmp2_);
	}
	*result_length1 = _tmp0__length1;
	_tmp0_[_tmp0__length] = NULL;
	return _tmp0_;
}

gchar**
rygel_external_get_mandatory_string_list_value (GHashTable* props,
                                                const gchar* key,
                                                gchar** _default_,
                                                gint _default__length1,
                                                const gchar* service_name,
                                                gint* result_length1)
{
	GVariant* value = NULL;
	GVariant* _tmp0_;
	GVariant* _tmp1_;
	GVariant* _tmp4_;
	gchar** _tmp5_ = NULL;
	gint _tmp5__length1 = 0;
	gchar** _tmp6_;
	gint _tmp6__length1;
	gchar** result;
	g_return_val_if_fail (props != NULL, NULL);
	g_return_val_if_fail (key != NULL, NULL);
	g_return_val_if_fail (service_name != NULL, NULL);
	_tmp0_ = rygel_external_get_mandatory (props, key, service_name);
	value = _tmp0_;
	_tmp1_ = value;
	if (_tmp1_ == NULL) {
		gchar** _tmp2_;
		gint _tmp2__length1;
		gchar** _tmp3_;
		gint _tmp3__length1;
		_tmp2_ = (_default_ != NULL) ? _vala_array_dup1 (_default_, _default__length1) : _default_;
		_tmp2__length1 = _default__length1;
		_tmp3_ = _tmp2_;
		_tmp3__length1 = _tmp2__length1;
		if (result_length1) {
			*result_length1 = _tmp3__length1;
		}
		result = _tmp3_;
		_g_variant_unref0 (value);
		return result;
	}
	_tmp4_ = value;
	_tmp5_ = _variant_get34 (_tmp4_, &_tmp5__length1);
	_tmp6_ = _tmp5_;
	_tmp6__length1 = _tmp5__length1;
	if (result_length1) {
		*result_length1 = _tmp6__length1;
	}
	result = _tmp6_;
	_g_variant_unref0 (value);
	return result;
}

