/* rygel-dlna-available-seek-request.c generated by valac 0.56.1, the Vala compiler
 * generated from rygel-dlna-available-seek-request.vala, do not modify */

/*
 * Copyright (C) 2014  Cable Television Laboratories, Inc.
 * Contact: http://www.cablelabs.com/
 *
 * Author: Craig Pratt <craig@ecaspia.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 "rygel-server.h"
#include <libsoup/soup.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

enum  {
	RYGEL_DLNA_AVAILABLE_SEEK_RANGE_REQUEST_0_PROPERTY,
	RYGEL_DLNA_AVAILABLE_SEEK_RANGE_REQUEST_NUM_PROPERTIES
};
static GParamSpec* rygel_dlna_available_seek_range_request_properties[RYGEL_DLNA_AVAILABLE_SEEK_RANGE_REQUEST_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer rygel_dlna_available_seek_range_request_parent_class = NULL;

VALA_EXTERN RygelDLNAAvailableSeekRangeRequest* rygel_dlna_available_seek_range_request_new (SoupMessage* message,
                                                                                 RygelHTTPGetHandler* handler,
                                                                                 GError** error);
VALA_EXTERN RygelDLNAAvailableSeekRangeRequest* rygel_dlna_available_seek_range_request_construct (GType object_type,
                                                                                       SoupMessage* message,
                                                                                       RygelHTTPGetHandler* handler,
                                                                                       GError** error);
static GType rygel_dlna_available_seek_range_request_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/**
     * Create a DLNAAvailableSeekRangeRequest corresponding with a HTTPGet
     * that contains a getAvailableSeekRange.dlna.org header value.
     *
     * @param request The HTTP GET/HEAD request
     */
static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

RygelDLNAAvailableSeekRangeRequest*
rygel_dlna_available_seek_range_request_construct (GType object_type,
                                                   SoupMessage* message,
                                                   RygelHTTPGetHandler* handler,
                                                   GError** error)
{
	RygelDLNAAvailableSeekRangeRequest * self = NULL;
	gchar* params = NULL;
	SoupMessageHeaders* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gboolean _tmp8_;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (message != NULL, NULL);
	g_return_val_if_fail (handler != NULL, NULL);
	self = (RygelDLNAAvailableSeekRangeRequest*) rygel_http_seek_request_construct (object_type);
	_tmp0_ = message->request_headers;
	_tmp1_ = soup_message_headers_get_one (_tmp0_, RYGEL_DLNA_AVAILABLE_SEEK_RANGE_REQUEST_GET_AVAILABLE_SEEK_RANGE_HEADER);
	_tmp2_ = g_strdup (_tmp1_);
	params = _tmp2_;
	_tmp3_ = params;
	if (_tmp3_ == NULL) {
		GError* _tmp4_;
		_tmp4_ = g_error_new (RYGEL_HTTP_SEEK_REQUEST_ERROR, RYGEL_HTTP_SEEK_REQUEST_ERROR_BAD_REQUEST, "%s not present", RYGEL_DLNA_AVAILABLE_SEEK_RANGE_REQUEST_GET_AVAILABLE_SEEK_RANGE_HEADER);
		_inner_error0_ = _tmp4_;
		if (_inner_error0_->domain == RYGEL_HTTP_SEEK_REQUEST_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (params);
			_g_object_unref0 (self);
			return NULL;
		} else {
			_g_free0 (params);
			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;
		}
	}
	_tmp5_ = params;
	_tmp6_ = string_strip (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = g_strcmp0 (_tmp7_, "1") != 0;
	_g_free0 (_tmp7_);
	if (_tmp8_) {
		const gchar* _tmp9_;
		GError* _tmp10_;
		_tmp9_ = params;
		_tmp10_ = g_error_new (RYGEL_HTTP_SEEK_REQUEST_ERROR, RYGEL_HTTP_SEEK_REQUEST_ERROR_BAD_REQUEST, "%s != 1 (found \"%s\")", RYGEL_DLNA_AVAILABLE_SEEK_RANGE_REQUEST_GET_AVAILABLE_SEEK_RANGE_HEADER, _tmp9_);
		_inner_error0_ = _tmp10_;
		if (_inner_error0_->domain == RYGEL_HTTP_SEEK_REQUEST_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (params);
			_g_object_unref0 (self);
			return NULL;
		} else {
			_g_free0 (params);
			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;
		}
	}
	_g_free0 (params);
	return self;
}

RygelDLNAAvailableSeekRangeRequest*
rygel_dlna_available_seek_range_request_new (SoupMessage* message,
                                             RygelHTTPGetHandler* handler,
                                             GError** error)
{
	return rygel_dlna_available_seek_range_request_construct (RYGEL_TYPE_DLNA_AVAILABLE_SEEK_RANGE_REQUEST, message, handler, error);
}

/**
     * Return true if getAvailableSeekRange is supported.
     */
gboolean
rygel_dlna_available_seek_range_request_supported (SoupMessage* message,
                                                   RygelHTTPGetHandler* handler)
{
	gboolean result;
	g_return_val_if_fail (message != NULL, FALSE);
	g_return_val_if_fail (handler != NULL, FALSE);
	result = TRUE;
	return result;
}

/**
     * Return true of the HTTPGet contains a getAvailableSeekRange request.
     */
gboolean
rygel_dlna_available_seek_range_request_requested (SoupMessage* message)
{
	SoupMessageHeaders* _tmp0_;
	const gchar* _tmp1_;
	gboolean result;
	g_return_val_if_fail (message != NULL, FALSE);
	_tmp0_ = message->request_headers;
	_tmp1_ = soup_message_headers_get_one (_tmp0_, RYGEL_DLNA_AVAILABLE_SEEK_RANGE_REQUEST_GET_AVAILABLE_SEEK_RANGE_HEADER);
	result = _tmp1_ != NULL;
	return result;
}

static void
rygel_dlna_available_seek_range_request_class_init (RygelDLNAAvailableSeekRangeRequestClass * klass,
                                                    gpointer klass_data)
{
	rygel_dlna_available_seek_range_request_parent_class = g_type_class_peek_parent (klass);
}

static void
rygel_dlna_available_seek_range_request_instance_init (RygelDLNAAvailableSeekRangeRequest * self,
                                                       gpointer klass)
{
}

/**
 * This class represents a DLNA getAvailableSeekRange request.
 *
 * A getAvailableSeekRange request can only have a single parameter: "1"
 */
static GType
rygel_dlna_available_seek_range_request_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelDLNAAvailableSeekRangeRequestClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_dlna_available_seek_range_request_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelDLNAAvailableSeekRangeRequest), 0, (GInstanceInitFunc) rygel_dlna_available_seek_range_request_instance_init, NULL };
	GType rygel_dlna_available_seek_range_request_type_id;
	rygel_dlna_available_seek_range_request_type_id = g_type_register_static (RYGEL_TYPE_HTTP_SEEK_REQUEST, "RygelDLNAAvailableSeekRangeRequest", &g_define_type_info, 0);
	return rygel_dlna_available_seek_range_request_type_id;
}

GType
rygel_dlna_available_seek_range_request_get_type (void)
{
	static volatile gsize rygel_dlna_available_seek_range_request_type_id__once = 0;
	if (g_once_init_enter (&rygel_dlna_available_seek_range_request_type_id__once)) {
		GType rygel_dlna_available_seek_range_request_type_id;
		rygel_dlna_available_seek_range_request_type_id = rygel_dlna_available_seek_range_request_get_type_once ();
		g_once_init_leave (&rygel_dlna_available_seek_range_request_type_id__once, rygel_dlna_available_seek_range_request_type_id);
	}
	return rygel_dlna_available_seek_range_request_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;
}

