/* smtp-response.c generated by valac 0.56.19, the Vala compiler
 * generated from smtp-response.vala, do not modify */

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-engine.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.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 _geary_smtp_response_code_unref0(var) ((var == NULL) ? NULL : (var = (geary_smtp_response_code_unref (var), NULL)))
#define _geary_smtp_response_line_unref0(var) ((var == NULL) ? NULL : (var = (geary_smtp_response_line_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
typedef struct _GearySmtpParamSpecResponse GearySmtpParamSpecResponse;
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GearySmtpResponsePrivate {
	GearySmtpResponseCode* _code;
	GearySmtpResponseLine* _first_line;
	GeeList* _lines;
};

struct _GearySmtpParamSpecResponse {
	GParamSpec parent_instance;
};

static gint GearySmtpResponse_private_offset;
static gpointer geary_smtp_response_parent_class = NULL;

static void geary_smtp_response_set_code (GearySmtpResponse* self,
                                   GearySmtpResponseCode* value);
static void geary_smtp_response_set_first_line (GearySmtpResponse* self,
                                         GearySmtpResponseLine* value);
static void geary_smtp_response_set_lines (GearySmtpResponse* self,
                                    GeeList* value);
static void geary_smtp_response_finalize (GearySmtpResponse * obj);
static GType geary_smtp_response_get_type_once (void);

static inline gpointer
geary_smtp_response_get_instance_private (GearySmtpResponse* self)
{
	return G_STRUCT_MEMBER_P (self, GearySmtpResponse_private_offset);
}

GearySmtpResponseCode*
geary_smtp_response_get_code (GearySmtpResponse* self)
{
	GearySmtpResponseCode* result;
	GearySmtpResponseCode* _tmp0_;
	g_return_val_if_fail (GEARY_SMTP_IS_RESPONSE (self), NULL);
	_tmp0_ = self->priv->_code;
	result = _tmp0_;
	return result;
}

static gpointer
_geary_smtp_response_code_ref0 (gpointer self)
{
	return self ? geary_smtp_response_code_ref (self) : NULL;
}

static void
geary_smtp_response_set_code (GearySmtpResponse* self,
                              GearySmtpResponseCode* value)
{
	GearySmtpResponseCode* _tmp0_;
	g_return_if_fail (GEARY_SMTP_IS_RESPONSE (self));
	_tmp0_ = _geary_smtp_response_code_ref0 (value);
	_geary_smtp_response_code_unref0 (self->priv->_code);
	self->priv->_code = _tmp0_;
}

GearySmtpResponseLine*
geary_smtp_response_get_first_line (GearySmtpResponse* self)
{
	GearySmtpResponseLine* result;
	GearySmtpResponseLine* _tmp0_;
	g_return_val_if_fail (GEARY_SMTP_IS_RESPONSE (self), NULL);
	_tmp0_ = self->priv->_first_line;
	result = _tmp0_;
	return result;
}

static gpointer
_geary_smtp_response_line_ref0 (gpointer self)
{
	return self ? geary_smtp_response_line_ref (self) : NULL;
}

static void
geary_smtp_response_set_first_line (GearySmtpResponse* self,
                                    GearySmtpResponseLine* value)
{
	GearySmtpResponseLine* _tmp0_;
	g_return_if_fail (GEARY_SMTP_IS_RESPONSE (self));
	_tmp0_ = _geary_smtp_response_line_ref0 (value);
	_geary_smtp_response_line_unref0 (self->priv->_first_line);
	self->priv->_first_line = _tmp0_;
}

GeeList*
geary_smtp_response_get_lines (GearySmtpResponse* self)
{
	GeeList* result;
	GeeList* _tmp0_;
	g_return_val_if_fail (GEARY_SMTP_IS_RESPONSE (self), NULL);
	_tmp0_ = self->priv->_lines;
	result = _tmp0_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
geary_smtp_response_set_lines (GearySmtpResponse* self,
                               GeeList* value)
{
	GeeList* _tmp0_;
	g_return_if_fail (GEARY_SMTP_IS_RESPONSE (self));
	_tmp0_ = _g_object_ref0 (value);
	_g_object_unref0 (self->priv->_lines);
	self->priv->_lines = _tmp0_;
}

GearySmtpResponse*
geary_smtp_response_construct (GType object_type,
                               GeeList* lines)
{
	GearySmtpResponse* self = NULL;
	gint _tmp0_;
	gint _tmp1_;
	gpointer _tmp2_;
	GearySmtpResponseLine* _tmp3_;
	GearySmtpResponseCode* _tmp4_;
	GearySmtpResponseCode* _tmp5_;
	gpointer _tmp6_;
	GearySmtpResponseLine* _tmp7_;
	GeeList* _tmp8_;
	GeeList* _tmp9_;
	GeeList* _tmp10_;
	g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (lines, GEE_TYPE_LIST), NULL);
	self = (GearySmtpResponse*) g_type_create_instance (object_type);
	_tmp0_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (lines, GEE_TYPE_COLLECTION, GeeCollection));
	_tmp1_ = _tmp0_;
	_vala_assert (_tmp1_ > 0, "lines.size > 0");
	_tmp2_ = gee_list_get (lines, 0);
	_tmp3_ = (GearySmtpResponseLine*) _tmp2_;
	_tmp4_ = geary_smtp_response_line_get_code (_tmp3_);
	_tmp5_ = _tmp4_;
	geary_smtp_response_set_code (self, _tmp5_);
	_geary_smtp_response_line_unref0 (_tmp3_);
	_tmp6_ = gee_list_get (lines, 0);
	_tmp7_ = (GearySmtpResponseLine*) _tmp6_;
	geary_smtp_response_set_first_line (self, _tmp7_);
	_geary_smtp_response_line_unref0 (_tmp7_);
	_tmp8_ = gee_list_get_read_only_view (lines);
	_tmp9_ = _tmp8_;
	_tmp10_ = _tmp9_;
	geary_smtp_response_set_lines (self, _tmp10_);
	_g_object_unref0 (_tmp10_);
	return self;
}

GearySmtpResponse*
geary_smtp_response_new (GeeList* lines)
{
	return geary_smtp_response_construct (GEARY_SMTP_TYPE_RESPONSE, lines);
}

void
geary_smtp_response_throw_error (GearySmtpResponse* self,
                                 const gchar* msg,
                                 GError** error)
{
	GearySmtpResponseLine* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	GError* _tmp3_;
	GError* _tmp4_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (GEARY_SMTP_IS_RESPONSE (self));
	g_return_if_fail (msg != NULL);
	_tmp0_ = self->priv->_first_line;
	_tmp1_ = geary_smtp_response_line_to_string (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_error_new (GEARY_SMTP_ERROR, GEARY_SMTP_ERROR_SERVER_ERROR, "%s: %s", msg, _tmp2_);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	_inner_error0_ = _tmp4_;
	if (_inner_error0_->domain == GEARY_SMTP_ERROR) {
		g_propagate_error (error, _inner_error0_);
		return;
	} 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;
	}
}

gchar*
geary_smtp_response_to_string (GearySmtpResponse* self)
{
	GString* builder = NULL;
	GString* _tmp0_;
	GString* _tmp14_;
	const gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* result;
	g_return_val_if_fail (GEARY_SMTP_IS_RESPONSE (self), NULL);
	_tmp0_ = g_string_new ("");
	builder = _tmp0_;
	{
		GeeList* _line_list = NULL;
		GeeList* _tmp1_;
		gint _line_size = 0;
		GeeList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _line_index = 0;
		_tmp1_ = self->priv->_lines;
		_line_list = _tmp1_;
		_tmp2_ = _line_list;
		_tmp3_ = gee_collection_get_size (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GEE_TYPE_COLLECTION, GeeCollection));
		_tmp4_ = _tmp3_;
		_line_size = _tmp4_;
		_line_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			GearySmtpResponseLine* line = NULL;
			GeeList* _tmp7_;
			gpointer _tmp8_;
			GString* _tmp9_;
			GearySmtpResponseLine* _tmp10_;
			gchar* _tmp11_;
			gchar* _tmp12_;
			GString* _tmp13_;
			_line_index = _line_index + 1;
			_tmp5_ = _line_index;
			_tmp6_ = _line_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _line_list;
			_tmp8_ = gee_list_get (_tmp7_, _line_index);
			line = (GearySmtpResponseLine*) _tmp8_;
			_tmp9_ = builder;
			_tmp10_ = line;
			_tmp11_ = geary_smtp_response_line_to_string (_tmp10_);
			_tmp12_ = _tmp11_;
			g_string_append (_tmp9_, _tmp12_);
			_g_free0 (_tmp12_);
			_tmp13_ = builder;
			g_string_append (_tmp13_, "\n");
			_geary_smtp_response_line_unref0 (line);
		}
	}
	_tmp14_ = builder;
	_tmp15_ = _tmp14_->str;
	_tmp16_ = g_strdup (_tmp15_);
	result = _tmp16_;
	_g_string_free0 (builder);
	return result;
}

static void
geary_smtp_value_response_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
geary_smtp_value_response_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		geary_smtp_response_unref (value->data[0].v_pointer);
	}
}

static void
geary_smtp_value_response_copy_value (const GValue* src_value,
                                      GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = geary_smtp_response_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
geary_smtp_value_response_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
geary_smtp_value_response_collect_value (GValue* value,
                                         guint n_collect_values,
                                         GTypeCValue* collect_values,
                                         guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		GearySmtpResponse * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = geary_smtp_response_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
geary_smtp_value_response_lcopy_value (const GValue* value,
                                       guint n_collect_values,
                                       GTypeCValue* collect_values,
                                       guint collect_flags)
{
	GearySmtpResponse ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = geary_smtp_response_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
geary_smtp_param_spec_response (const gchar* name,
                                const gchar* nick,
                                const gchar* blurb,
                                GType object_type,
                                GParamFlags flags)
{
	GearySmtpParamSpecResponse* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GEARY_SMTP_TYPE_RESPONSE), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
geary_smtp_value_get_response (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_SMTP_TYPE_RESPONSE), NULL);
	return value->data[0].v_pointer;
}

void
geary_smtp_value_set_response (GValue* value,
                               gpointer v_object)
{
	GearySmtpResponse * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_SMTP_TYPE_RESPONSE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEARY_SMTP_TYPE_RESPONSE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		geary_smtp_response_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		geary_smtp_response_unref (old);
	}
}

void
geary_smtp_value_take_response (GValue* value,
                                gpointer v_object)
{
	GearySmtpResponse * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GEARY_SMTP_TYPE_RESPONSE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GEARY_SMTP_TYPE_RESPONSE));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		geary_smtp_response_unref (old);
	}
}

static void
geary_smtp_response_class_init (GearySmtpResponseClass * klass,
                                gpointer klass_data)
{
	geary_smtp_response_parent_class = g_type_class_peek_parent (klass);
	((GearySmtpResponseClass *) klass)->finalize = geary_smtp_response_finalize;
	g_type_class_adjust_private_offset (klass, &GearySmtpResponse_private_offset);
}

static void
geary_smtp_response_instance_init (GearySmtpResponse * self,
                                   gpointer klass)
{
	self->priv = geary_smtp_response_get_instance_private (self);
	self->ref_count = 1;
}

static void
geary_smtp_response_finalize (GearySmtpResponse * obj)
{
	GearySmtpResponse * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_SMTP_TYPE_RESPONSE, GearySmtpResponse);
	g_signal_handlers_destroy (self);
	_geary_smtp_response_code_unref0 (self->priv->_code);
	_geary_smtp_response_line_unref0 (self->priv->_first_line);
	_g_object_unref0 (self->priv->_lines);
}

 G_GNUC_NO_INLINE static GType
geary_smtp_response_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { geary_smtp_value_response_init, geary_smtp_value_response_free_value, geary_smtp_value_response_copy_value, geary_smtp_value_response_peek_pointer, "p", geary_smtp_value_response_collect_value, "p", geary_smtp_value_response_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GearySmtpResponseClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_smtp_response_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearySmtpResponse), 0, (GInstanceInitFunc) geary_smtp_response_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType geary_smtp_response_type_id;
	geary_smtp_response_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GearySmtpResponse", &g_define_type_info, &g_define_type_fundamental_info, 0);
	GearySmtpResponse_private_offset = g_type_add_instance_private (geary_smtp_response_type_id, sizeof (GearySmtpResponsePrivate));
	return geary_smtp_response_type_id;
}

GType
geary_smtp_response_get_type (void)
{
	static gsize geary_smtp_response_type_id__once = 0;
	if (g_once_init_enter (&geary_smtp_response_type_id__once)) {
		GType geary_smtp_response_type_id;
		geary_smtp_response_type_id = geary_smtp_response_get_type_once ();
		g_once_init_leave (&geary_smtp_response_type_id__once, geary_smtp_response_type_id);
	}
	return geary_smtp_response_type_id__once;
}

gpointer
geary_smtp_response_ref (gpointer instance)
{
	GearySmtpResponse * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
geary_smtp_response_unref (gpointer instance)
{
	GearySmtpResponse * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GEARY_SMTP_RESPONSE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

