/* rygel-xbmc-hacks.c generated by valac 0.56.19, the Vala compiler
 * generated from rygel-xbmc-hacks.vala, do not modify */

/*
 * Copyright (C) 2011 Nokia Corporation.
 *
 * Author: Jens Georg <jensg@openismus.com>
 *
 * 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 <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "rygel-server.h"
#include <gio/gio.h>
#include <libsoup/soup.h>
#include <gee.h>

#define RYGEL_XBMC_HACKS_AGENT ".*Platinum/.*|.*XBMC/.*|.*Kodi.*"
#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 RYGEL_TYPE_CLIENT_HACKS (rygel_client_hacks_get_type ())
#define RYGEL_CLIENT_HACKS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_CLIENT_HACKS, RygelClientHacks))
#define RYGEL_CLIENT_HACKS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_CLIENT_HACKS, RygelClientHacksClass))
#define RYGEL_IS_CLIENT_HACKS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_CLIENT_HACKS))
#define RYGEL_IS_CLIENT_HACKS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_CLIENT_HACKS))
#define RYGEL_CLIENT_HACKS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_CLIENT_HACKS, RygelClientHacksClass))

typedef struct _RygelClientHacks RygelClientHacks;
typedef struct _RygelClientHacksClass RygelClientHacksClass;
typedef struct _RygelClientHacksPrivate RygelClientHacksPrivate;

#define RYGEL_TYPE_MEDIA_QUERY_ACTION (rygel_media_query_action_get_type ())
#define RYGEL_MEDIA_QUERY_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_MEDIA_QUERY_ACTION, RygelMediaQueryAction))
#define RYGEL_MEDIA_QUERY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_MEDIA_QUERY_ACTION, RygelMediaQueryActionClass))
#define RYGEL_IS_MEDIA_QUERY_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_MEDIA_QUERY_ACTION))
#define RYGEL_IS_MEDIA_QUERY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_MEDIA_QUERY_ACTION))
#define RYGEL_MEDIA_QUERY_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_MEDIA_QUERY_ACTION, RygelMediaQueryActionClass))

typedef struct _RygelMediaQueryAction RygelMediaQueryAction;
typedef struct _RygelMediaQueryActionClass RygelMediaQueryActionClass;

#define RYGEL_TYPE_XBMC_HACKS (rygel_xbmc_hacks_get_type ())
#define RYGEL_XBMC_HACKS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TYPE_XBMC_HACKS, RygelXBMCHacks))
#define RYGEL_XBMC_HACKS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TYPE_XBMC_HACKS, RygelXBMCHacksClass))
#define RYGEL_IS_XBMC_HACKS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TYPE_XBMC_HACKS))
#define RYGEL_IS_XBMC_HACKS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TYPE_XBMC_HACKS))
#define RYGEL_XBMC_HACKS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TYPE_XBMC_HACKS, RygelXBMCHacksClass))

typedef struct _RygelXBMCHacks RygelXBMCHacks;
typedef struct _RygelXBMCHacksClass RygelXBMCHacksClass;
typedef struct _RygelXBMCHacksPrivate RygelXBMCHacksPrivate;
enum  {
	RYGEL_XBMC_HACKS_0_PROPERTY,
	RYGEL_XBMC_HACKS_NUM_PROPERTIES
};
static GParamSpec* rygel_xbmc_hacks_properties[RYGEL_XBMC_HACKS_NUM_PROPERTIES];

#define RYGEL_TYPE_CLIENT_HACKS_ERROR (rygel_client_hacks_error_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _RygelClientHacks {
	GObject parent_instance;
	RygelClientHacksPrivate * priv;
	GRegex* agent_regex;
};

struct _RygelClientHacksClass {
	GObjectClass parent_class;
	void (*translate_container_id) (RygelClientHacks* self, RygelMediaQueryAction* action, gchar** container_id);
	void (*apply) (RygelClientHacks* self, RygelMediaObject* object);
	void (*filter_sort_criteria) (RygelClientHacks* self, gchar** sort_criteria);
	gboolean (*force_seek) (RygelClientHacks* self);
	void (*modify_headers) (RygelClientHacks* self, RygelHTTPRequest* request);
	void (*search) (RygelClientHacks* self, RygelSearchableContainer* container, RygelSearchExpression* expression, guint offset, guint max_count, const gchar* sort_criteria, GCancellable* cancellable, GAsyncReadyCallback _callback_, gpointer _user_data_);
	RygelMediaObjects* (*search_finish) (RygelClientHacks* self, GAsyncResult* _res_, guint* total_matches, GError** error);
};

struct _RygelXBMCHacks {
	RygelClientHacks parent_instance;
	RygelXBMCHacksPrivate * priv;
};

struct _RygelXBMCHacksClass {
	RygelClientHacksClass parent_class;
};

typedef enum  {
	RYGEL_CLIENT_HACKS_ERROR_NA
} RygelClientHacksError;
#define RYGEL_CLIENT_HACKS_ERROR rygel_client_hacks_error_quark ()

static gpointer rygel_xbmc_hacks_parent_class = NULL;

VALA_EXTERN GType rygel_client_hacks_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType rygel_media_query_action_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GType rygel_xbmc_hacks_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void rygel_client_hacks_apply (RygelClientHacks* self,
                               RygelMediaObject* object);
VALA_EXTERN gboolean rygel_client_hacks_force_seek (RygelClientHacks* self);
VALA_EXTERN GQuark rygel_client_hacks_error_quark (void);
VALA_EXTERN GType rygel_client_hacks_error_get_type (void) G_GNUC_CONST ;
VALA_EXTERN RygelXBMCHacks* rygel_xbmc_hacks_new (SoupServerMessage* message,
                                      const gchar* agent,
                                      GError** error);
VALA_EXTERN RygelXBMCHacks* rygel_xbmc_hacks_construct (GType object_type,
                                            SoupServerMessage* message,
                                            const gchar* agent,
                                            GError** error);
VALA_EXTERN RygelClientHacks* rygel_client_hacks_construct (GType object_type,
                                                const gchar* agent,
                                                SoupServerMessage* message,
                                                GError** error);
static void rygel_xbmc_hacks_real_apply (RygelClientHacks* base,
                                  RygelMediaObject* object);
static gboolean rygel_xbmc_hacks_real_force_seek (RygelClientHacks* base);
static GType rygel_xbmc_hacks_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

RygelXBMCHacks*
rygel_xbmc_hacks_construct (GType object_type,
                            SoupServerMessage* message,
                            const gchar* agent,
                            GError** error)
{
	RygelXBMCHacks * self = NULL;
	const gchar* _tmp0_ = NULL;
	GError* _inner_error0_ = NULL;
	if (agent == NULL) {
		_tmp0_ = RYGEL_XBMC_HACKS_AGENT;
	} else {
		_tmp0_ = agent;
	}
	self = (RygelXBMCHacks*) rygel_client_hacks_construct (object_type, _tmp0_, message, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == RYGEL_CLIENT_HACKS_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_object_unref0 (self);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return NULL;
		}
	}
	return self;
}

RygelXBMCHacks*
rygel_xbmc_hacks_new (SoupServerMessage* message,
                      const gchar* agent,
                      GError** error)
{
	return rygel_xbmc_hacks_construct (RYGEL_TYPE_XBMC_HACKS, message, agent, error);
}

static void
rygel_xbmc_hacks_real_apply (RygelClientHacks* base,
                             RygelMediaObject* object)
{
	RygelXBMCHacks * self;
	self = (RygelXBMCHacks*) base;
	g_return_if_fail (object != NULL);
	{
		GeeList* _resource_list = NULL;
		GeeList* _tmp0_;
		gint _resource_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _resource_index = 0;
		_tmp0_ = rygel_media_object_get_resource_list (object);
		_resource_list = _tmp0_;
		_tmp1_ = _resource_list;
		_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_resource_size = _tmp3_;
		_resource_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			RygelMediaResource* resource = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			gboolean _tmp8_ = FALSE;
			gboolean _tmp9_ = FALSE;
			RygelMediaResource* _tmp10_;
			const gchar* _tmp11_;
			const gchar* _tmp12_;
			_resource_index = _resource_index + 1;
			_tmp4_ = _resource_index;
			_tmp5_ = _resource_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _resource_list;
			_tmp7_ = gee_list_get (_tmp6_, _resource_index);
			resource = (RygelMediaResource*) _tmp7_;
			_tmp10_ = resource;
			_tmp11_ = rygel_media_resource_get_mime_type (_tmp10_);
			_tmp12_ = _tmp11_;
			if (g_strcmp0 (_tmp12_, "audio/mp4") == 0) {
				_tmp9_ = TRUE;
			} else {
				RygelMediaResource* _tmp13_;
				const gchar* _tmp14_;
				const gchar* _tmp15_;
				_tmp13_ = resource;
				_tmp14_ = rygel_media_resource_get_mime_type (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp9_ = g_strcmp0 (_tmp15_, "audio/3gpp") == 0;
			}
			if (_tmp9_) {
				_tmp8_ = TRUE;
			} else {
				RygelMediaResource* _tmp16_;
				const gchar* _tmp17_;
				const gchar* _tmp18_;
				_tmp16_ = resource;
				_tmp17_ = rygel_media_resource_get_mime_type (_tmp16_);
				_tmp18_ = _tmp17_;
				_tmp8_ = g_strcmp0 (_tmp18_, "audio/vnd.dlna.adts") == 0;
			}
			if (_tmp8_) {
				RygelMediaResource* _tmp19_;
				_tmp19_ = resource;
				rygel_media_resource_set_mime_type (_tmp19_, "audio/aac");
			}
			_g_object_unref0 (resource);
		}
		_g_object_unref0 (_resource_list);
	}
}

static gboolean
rygel_xbmc_hacks_real_force_seek (RygelClientHacks* base)
{
	RygelXBMCHacks * self;
	gboolean result;
	self = (RygelXBMCHacks*) base;
	result = TRUE;
	return result;
}

static void
rygel_xbmc_hacks_class_init (RygelXBMCHacksClass * klass,
                             gpointer klass_data)
{
	rygel_xbmc_hacks_parent_class = g_type_class_peek_parent (klass);
	((RygelClientHacksClass *) klass)->apply = (void (*) (RygelClientHacks*, RygelMediaObject*)) rygel_xbmc_hacks_real_apply;
	((RygelClientHacksClass *) klass)->force_seek = (gboolean (*) (RygelClientHacks*)) rygel_xbmc_hacks_real_force_seek;
}

static void
rygel_xbmc_hacks_instance_init (RygelXBMCHacks * self,
                                gpointer klass)
{
}

 G_GNUC_NO_INLINE static GType
rygel_xbmc_hacks_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelXBMCHacksClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_xbmc_hacks_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelXBMCHacks), 0, (GInstanceInitFunc) rygel_xbmc_hacks_instance_init, NULL };
	GType rygel_xbmc_hacks_type_id;
	rygel_xbmc_hacks_type_id = g_type_register_static (RYGEL_TYPE_CLIENT_HACKS, "RygelXBMCHacks", &g_define_type_info, 0);
	return rygel_xbmc_hacks_type_id;
}

GType
rygel_xbmc_hacks_get_type (void)
{
	static volatile gsize rygel_xbmc_hacks_type_id__once = 0;
	if (g_once_init_enter (&rygel_xbmc_hacks_type_id__once)) {
		GType rygel_xbmc_hacks_type_id;
		rygel_xbmc_hacks_type_id = rygel_xbmc_hacks_get_type_once ();
		g_once_init_leave (&rygel_xbmc_hacks_type_id__once, rygel_xbmc_hacks_type_id);
	}
	return rygel_xbmc_hacks_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

