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

#include <glib-object.h>
#include <libsoup/soup.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include "config.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define PROTON_PLUS_UTILS_TYPE_WEB (proton_plus_utils_web_get_type ())
#define PROTON_PLUS_UTILS_WEB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PROTON_PLUS_UTILS_TYPE_WEB, ProtonPlusUtilsWeb))
#define PROTON_PLUS_UTILS_WEB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PROTON_PLUS_UTILS_TYPE_WEB, ProtonPlusUtilsWebClass))
#define PROTON_PLUS_UTILS_IS_WEB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PROTON_PLUS_UTILS_TYPE_WEB))
#define PROTON_PLUS_UTILS_IS_WEB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PROTON_PLUS_UTILS_TYPE_WEB))
#define PROTON_PLUS_UTILS_WEB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PROTON_PLUS_UTILS_TYPE_WEB, ProtonPlusUtilsWebClass))

typedef struct _ProtonPlusUtilsWeb ProtonPlusUtilsWeb;
typedef struct _ProtonPlusUtilsWebClass ProtonPlusUtilsWebClass;
typedef struct _ProtonPlusUtilsWebPrivate ProtonPlusUtilsWebPrivate;
typedef enum  {
	PROTON_PLUS_UTILS_WEB_GET_TYPE_OTHER,
	PROTON_PLUS_UTILS_WEB_GET_TYPE_GITHUB,
	PROTON_PLUS_UTILS_WEB_GET_TYPE_GITLAB,
	PROTON_PLUS_UTILS_WEB_GET_TYPE_FORGEJO,
	PROTON_PLUS_UTILS_WEB_GET_TYPE_STEAMTINKERLAUNCH
} ProtonPlusUtilsWebGetType;

#define PROTON_PLUS_UTILS_WEB_TYPE_GET_TYPE (proton_plus_utils_web_get_type_get_type ())
#define _g_free0(var) (var = (g_free (var), NULL))
typedef enum  {
	PROTON_PLUS_RETURN_CODE_UNKNOWN_ERROR,
	PROTON_PLUS_RETURN_CODE_RELEASES_LOADED,
	PROTON_PLUS_RETURN_CODE_NOTHING_TO_UPDATE,
	PROTON_PLUS_RETURN_CODE_RUNNERS_UPDATED,
	PROTON_PLUS_RETURN_CODE_RUNNER_UPDATED,
	PROTON_PLUS_RETURN_CODE_VALID_REQUEST,
	PROTON_PLUS_RETURN_CODE_CONNECTION_ISSUE,
	PROTON_PLUS_RETURN_CODE_CONNECTION_REFUSED,
	PROTON_PLUS_RETURN_CODE_CONNECTION_UNKNOWN,
	PROTON_PLUS_RETURN_CODE_API_LIMIT_REACHED,
	PROTON_PLUS_RETURN_CODE_INVALID_ACCESS_TOKEN
} ProtonPlusReturnCode;

#define PROTON_PLUS_TYPE_RETURN_CODE (proton_plus_return_code_get_type ())
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _ProtonPlusUtilsWebGetRequestData ProtonPlusUtilsWebGetRequestData;
typedef gboolean (*ProtonPlusUtilsWebcancel_callback) (gpointer user_data);
typedef void (*ProtonPlusUtilsWebprogress_callback) (gboolean is_percent, gint64 progress_percentage, gdouble speed_kbps, gdouble* remaining_seconds, gpointer user_data);
typedef struct _proton_plus_utils_web_DownloadData proton_plus_utils_web_DownloadData;
typedef struct _ProtonPlusUtilsParamSpecWeb ProtonPlusUtilsParamSpecWeb;

struct _ProtonPlusUtilsWeb {
	GTypeInstance parent_instance;
	volatile int ref_count;
	ProtonPlusUtilsWebPrivate * priv;
};

struct _ProtonPlusUtilsWebClass {
	GTypeClass parent_class;
	void (*finalize) (ProtonPlusUtilsWeb *self);
};

struct _ProtonPlusUtilsWebGetRequestData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* uri;
	ProtonPlusUtilsWebGetType get_type;
	gchar* response;
	ProtonPlusReturnCode result;
	SoupMessage* message;
	SoupMessage* _tmp0_;
	GSettings* _tmp1_;
	gboolean _tmp2_;
	gchar* key;
	GSettings* _tmp3_;
	gchar* _tmp4_;
	const gchar* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	SoupMessage* _tmp8_;
	SoupMessageHeaders* _tmp9_;
	SoupMessageHeaders* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _vala1_key;
	GSettings* _tmp14_;
	gchar* _tmp15_;
	const gchar* _tmp16_;
	gint _tmp17_;
	gint _tmp18_;
	SoupMessage* _tmp19_;
	SoupMessageHeaders* _tmp20_;
	SoupMessageHeaders* _tmp21_;
	const gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	SoupMessage* _tmp25_;
	SoupMessageHeaders* _tmp26_;
	SoupMessageHeaders* _tmp27_;
	SoupMessage* _tmp28_;
	SoupMessageHeaders* _tmp29_;
	SoupMessageHeaders* _tmp30_;
	GBytes* bytes;
	SoupSession* _tmp31_;
	SoupSession* _tmp32_;
	SoupMessage* _tmp33_;
	GBytes* _tmp34_;
	guint8* data;
	GBytes* _tmp35_;
	gsize _tmp36_;
	guint8* _tmp37_;
	gint data_length1;
	gint _data_size_;
	gchar* str_data;
	guint8* _tmp38_;
	gint _tmp38__length1;
	gchar* _tmp39_;
	gint str_data_length1;
	gint _str_data_size_;
	gchar* _tmp40_;
	gint _tmp40__length1;
	guint8* _tmp41_;
	gint _tmp41__length1;
	guint8* _tmp42_;
	gint _tmp42__length1;
	gchar* _tmp43_;
	gint _tmp43__length1;
	guint8* _tmp44_;
	gint _tmp44__length1;
	gchar* _tmp45_;
	gint _tmp45__length1;
	gchar* _tmp46_;
	const gchar* _tmp47_;
	const gchar* _tmp48_;
	const gchar* _tmp49_;
	const gchar* _tmp50_;
	GError* e;
	GError* _tmp51_;
	const gchar* _tmp52_;
	GError* _tmp53_;
	const gchar* _tmp54_;
	GError* _tmp55_;
	const gchar* _tmp56_;
	GError* _tmp57_;
	const gchar* _tmp58_;
	GError* _inner_error0_;
};

struct _proton_plus_utils_web_DownloadData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	gchar* url;
	gchar* path;
	ProtonPlusUtilsWebcancel_callback cancel_callback;
	gpointer cancel_callback_target;
	ProtonPlusUtilsWebprogress_callback progress_callback;
	gpointer progress_callback_target;
	gchar* error_message;
	gboolean result;
	SoupMessage* soup_message;
	SoupMessage* _tmp0_;
	GInputStream* input_stream;
	SoupSession* _tmp1_;
	SoupSession* _tmp2_;
	SoupMessage* _tmp3_;
	GInputStream* _tmp4_;
	SoupMessage* _tmp5_;
	guint _tmp6_;
	guint _tmp7_;
	SoupMessage* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	SoupMessage* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	GFile* file;
	GFile* _tmp15_;
	GFile* _tmp16_;
	GFile* _tmp17_;
	GFileOutputStream* output_stream;
	GFile* _tmp18_;
	GFileOutputStream* _tmp19_;
	gint64 server_download_size;
	SoupMessage* _tmp20_;
	SoupMessageHeaders* _tmp21_;
	gboolean is_percent;
	gint64 bytes_downloaded;
	gdouble _tmp22_;
	gboolean is_canceled;
	gint64 start_time;
	gboolean _tmp23_;
	GBytes* chunk;
	GInputStream* _tmp24_;
	GBytes* _tmp25_;
	GBytes* _tmp26_;
	GFileOutputStream* _tmp27_;
	GBytes* _tmp28_;
	gsize _tmp29_;
	guint8* _tmp30_;
	GBytes* _tmp31_;
	gint64 elapsed_us;
	gdouble elapsed_s;
	gdouble _tmp32_;
	gdouble speed_kbps;
	gdouble _tmp33_;
	gdouble speed_bps;
	gdouble* remaining_seconds;
	gboolean _tmp34_;
	gint64 bytes_left;
	gdouble _tmp35_;
	gdouble* _tmp36_;
	gint64 _tmp37_;
	gint64 progress;
	gdouble* _tmp38_;
	GFileOutputStream* _tmp39_;
	gboolean _tmp40_;
	GFile* _tmp41_;
	GFile* _tmp42_;
	GError* e;
	GError* _tmp43_;
	const gchar* _tmp44_;
	GError* _tmp45_;
	const gchar* _tmp46_;
	gchar* _tmp47_;
	GError* _inner_error0_;
};

struct _ProtonPlusUtilsParamSpecWeb {
	GParamSpec parent_instance;
};

static gpointer proton_plus_utils_web_parent_class = NULL;
static SoupSession* proton_plus_utils_web__session;
static SoupSession* proton_plus_utils_web__session = NULL;
VALA_EXTERN GSettings* proton_plus_globals_SETTINGS;

VALA_EXTERN gpointer proton_plus_utils_web_ref (gpointer instance);
VALA_EXTERN void proton_plus_utils_web_unref (gpointer instance);
VALA_EXTERN GParamSpec* proton_plus_utils_param_spec_web (const gchar* name,
                                              const gchar* nick,
                                              const gchar* blurb,
                                              GType object_type,
                                              GParamFlags flags);
VALA_EXTERN void proton_plus_utils_value_set_web (GValue* value,
                                      gpointer v_object);
VALA_EXTERN void proton_plus_utils_value_take_web (GValue* value,
                                       gpointer v_object);
VALA_EXTERN gpointer proton_plus_utils_value_get_web (const GValue* value);
VALA_EXTERN GType proton_plus_utils_web_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ProtonPlusUtilsWeb, proton_plus_utils_web_unref)
VALA_EXTERN GType proton_plus_utils_web_get_type_get_type (void) G_GNUC_CONST ;
static void proton_plus_utils_web_get_request_data_free (gpointer _data);
VALA_EXTERN GType proton_plus_return_code_get_type (void) G_GNUC_CONST ;
VALA_EXTERN void proton_plus_utils_web_get_request (const gchar* uri,
                                        ProtonPlusUtilsWebGetType get_type,
                                        GAsyncReadyCallback _callback_,
                                        gpointer _user_data_);
VALA_EXTERN ProtonPlusReturnCode proton_plus_utils_web_get_request_finish (GAsyncResult* _res_,
                                                               gchar** response);
static gboolean proton_plus_utils_web_get_request_co (ProtonPlusUtilsWebGetRequestData* _data_);
static SoupSession* proton_plus_utils_web_get_session (void);
static void proton_plus_utils_web_get_request_ready (GObject* source_object,
                                              GAsyncResult* _res_,
                                              gpointer _user_data_);
static void proton_plus_utils_web_Download_data_free (gpointer _data);
VALA_EXTERN void proton_plus_utils_web_Download (const gchar* url,
                                     const gchar* path,
                                     ProtonPlusUtilsWebcancel_callback cancel_callback,
                                     gpointer cancel_callback_target,
                                     ProtonPlusUtilsWebprogress_callback progress_callback,
                                     gpointer progress_callback_target,
                                     GAsyncReadyCallback _callback_,
                                     gpointer _user_data_);
VALA_EXTERN gboolean proton_plus_utils_web_Download_finish (GAsyncResult* _res_,
                                                gchar** error_message);
static gboolean proton_plus_utils_web_Download_co (proton_plus_utils_web_DownloadData* _data_);
static void proton_plus_utils_web_Download_ready (GObject* source_object,
                                           GAsyncResult* _res_,
                                           gpointer _user_data_);
static gdouble* _double_dup (gdouble* self);
VALA_EXTERN ProtonPlusUtilsWeb* proton_plus_utils_web_new (void);
VALA_EXTERN ProtonPlusUtilsWeb* proton_plus_utils_web_construct (GType object_type);
static void proton_plus_utils_web_finalize (ProtonPlusUtilsWeb * obj);
static GType proton_plus_utils_web_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static GType
proton_plus_utils_web_get_type_get_type_once (void)
{
	static const GEnumValue values[] = {{PROTON_PLUS_UTILS_WEB_GET_TYPE_OTHER, "PROTON_PLUS_UTILS_WEB_GET_TYPE_OTHER", "other"}, {PROTON_PLUS_UTILS_WEB_GET_TYPE_GITHUB, "PROTON_PLUS_UTILS_WEB_GET_TYPE_GITHUB", "github"}, {PROTON_PLUS_UTILS_WEB_GET_TYPE_GITLAB, "PROTON_PLUS_UTILS_WEB_GET_TYPE_GITLAB", "gitlab"}, {PROTON_PLUS_UTILS_WEB_GET_TYPE_FORGEJO, "PROTON_PLUS_UTILS_WEB_GET_TYPE_FORGEJO", "forgejo"}, {PROTON_PLUS_UTILS_WEB_GET_TYPE_STEAMTINKERLAUNCH, "PROTON_PLUS_UTILS_WEB_GET_TYPE_STEAMTINKERLAUNCH", "steamtinkerlaunch"}, {0, NULL, NULL}};
	GType proton_plus_utils_web_get_type_type_id;
	proton_plus_utils_web_get_type_type_id = g_enum_register_static ("ProtonPlusUtilsWebGetType", values);
	return proton_plus_utils_web_get_type_type_id;
}

GType
proton_plus_utils_web_get_type_get_type (void)
{
	static volatile gsize proton_plus_utils_web_get_type_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_web_get_type_type_id__once)) {
		GType proton_plus_utils_web_get_type_type_id;
		proton_plus_utils_web_get_type_type_id = proton_plus_utils_web_get_type_get_type_once ();
		g_once_init_leave (&proton_plus_utils_web_get_type_type_id__once, proton_plus_utils_web_get_type_type_id);
	}
	return proton_plus_utils_web_get_type_type_id__once;
}

static void
proton_plus_utils_web_get_request_data_free (gpointer _data)
{
	ProtonPlusUtilsWebGetRequestData* _data_;
	_data_ = _data;
	_g_free0 (_data_->uri);
	g_slice_free (ProtonPlusUtilsWebGetRequestData, _data_);
}

void
proton_plus_utils_web_get_request (const gchar* uri,
                                   ProtonPlusUtilsWebGetType get_type,
                                   GAsyncReadyCallback _callback_,
                                   gpointer _user_data_)
{
	ProtonPlusUtilsWebGetRequestData* _data_;
	gchar* _tmp0_;
	g_return_if_fail (uri != NULL);
	_data_ = g_slice_new0 (ProtonPlusUtilsWebGetRequestData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_web_get_request_data_free);
	_tmp0_ = g_strdup (uri);
	_g_free0 (_data_->uri);
	_data_->uri = _tmp0_;
	_data_->get_type = get_type;
	proton_plus_utils_web_get_request_co (_data_);
}

ProtonPlusReturnCode
proton_plus_utils_web_get_request_finish (GAsyncResult* _res_,
                                          gchar** response)
{
	ProtonPlusReturnCode result;
	ProtonPlusUtilsWebGetRequestData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (response) {
		*response = _data_->response;
	} else {
		_g_free0 (_data_->response);
	}
	_data_->response = NULL;
	result = _data_->result;
	return result;
}

static void
proton_plus_utils_web_get_request_ready (GObject* source_object,
                                         GAsyncResult* _res_,
                                         gpointer _user_data_)
{
	ProtonPlusUtilsWebGetRequestData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_utils_web_get_request_co (_data_);
}

static gboolean
string_contains (const gchar* self,
                 const gchar* needle)
{
	gchar* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = strstr ((gchar*) self, (gchar*) needle);
	result = _tmp0_ != NULL;
	return result;
}

static gboolean
proton_plus_utils_web_get_request_co (ProtonPlusUtilsWebGetRequestData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_g_free0 (_data_->response);
	_data_->response = NULL;
	{
		_data_->_tmp0_ = soup_message_new ("GET", _data_->uri);
		_data_->message = _data_->_tmp0_;
		_data_->_tmp1_ = proton_plus_globals_SETTINGS;
		if (_data_->_tmp1_ != NULL) {
			if (_data_->get_type == PROTON_PLUS_UTILS_WEB_GET_TYPE_GITHUB) {
				_data_->_tmp2_ = TRUE;
			} else {
				_data_->_tmp2_ = _data_->get_type == PROTON_PLUS_UTILS_WEB_GET_TYPE_STEAMTINKERLAUNCH;
			}
			if (_data_->_tmp2_) {
				_data_->_tmp3_ = proton_plus_globals_SETTINGS;
				_data_->_tmp4_ = g_settings_get_string (_data_->_tmp3_, "github-api-key");
				_data_->key = _data_->_tmp4_;
				_data_->_tmp5_ = _data_->key;
				_data_->_tmp6_ = strlen (_data_->_tmp5_);
				_data_->_tmp7_ = _data_->_tmp6_;
				if (_data_->_tmp7_ > 0) {
					_data_->_tmp8_ = _data_->message;
					_data_->_tmp9_ = soup_message_get_request_headers (_data_->_tmp8_);
					_data_->_tmp10_ = _data_->_tmp9_;
					_data_->_tmp11_ = _data_->key;
					_data_->_tmp12_ = g_strdup_printf ("token %s", _data_->_tmp11_);
					_data_->_tmp13_ = _data_->_tmp12_;
					soup_message_headers_append (_data_->_tmp10_, "Authorization", _data_->_tmp13_);
					_g_free0 (_data_->_tmp13_);
				}
				_g_free0 (_data_->key);
			}
			if (_data_->get_type == PROTON_PLUS_UTILS_WEB_GET_TYPE_GITLAB) {
				_data_->_tmp14_ = proton_plus_globals_SETTINGS;
				_data_->_tmp15_ = g_settings_get_string (_data_->_tmp14_, "gitlab-api-key");
				_data_->_vala1_key = _data_->_tmp15_;
				_data_->_tmp16_ = _data_->_vala1_key;
				_data_->_tmp17_ = strlen (_data_->_tmp16_);
				_data_->_tmp18_ = _data_->_tmp17_;
				if (_data_->_tmp18_ > 0) {
					_data_->_tmp19_ = _data_->message;
					_data_->_tmp20_ = soup_message_get_request_headers (_data_->_tmp19_);
					_data_->_tmp21_ = _data_->_tmp20_;
					_data_->_tmp22_ = _data_->_vala1_key;
					_data_->_tmp23_ = g_strdup_printf ("Bearer %s", _data_->_tmp22_);
					_data_->_tmp24_ = _data_->_tmp23_;
					soup_message_headers_append (_data_->_tmp21_, "Authorization", _data_->_tmp24_);
					_g_free0 (_data_->_tmp24_);
				}
				_g_free0 (_data_->_vala1_key);
			}
			if (_data_->get_type == PROTON_PLUS_UTILS_WEB_GET_TYPE_STEAMTINKERLAUNCH) {
				_data_->_tmp25_ = _data_->message;
				_data_->_tmp26_ = soup_message_get_request_headers (_data_->_tmp25_);
				_data_->_tmp27_ = _data_->_tmp26_;
				soup_message_headers_append (_data_->_tmp27_, "Accept", "application/vnd.github+json");
				_data_->_tmp28_ = _data_->message;
				_data_->_tmp29_ = soup_message_get_request_headers (_data_->_tmp28_);
				_data_->_tmp30_ = _data_->_tmp29_;
				soup_message_headers_append (_data_->_tmp30_, "X-GitHub-Api-Version", "2022-11-28");
			}
		}
		_data_->_tmp31_ = proton_plus_utils_web_get_session ();
		_data_->_tmp32_ = _data_->_tmp31_;
		_data_->_tmp33_ = _data_->message;
		_data_->_state_ = 1;
		soup_session_send_and_read_async (_data_->_tmp32_, _data_->_tmp33_, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_get_request_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp34_ = soup_session_send_and_read_finish (_data_->_tmp32_, _data_->_res_, &_data_->_inner_error0_);
		_data_->bytes = _data_->_tmp34_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->message);
			goto __catch0_g_error;
		}
		_data_->_tmp35_ = _data_->bytes;
		_data_->_tmp36_ = 0;
		_data_->_tmp37_ = g_bytes_get_data (_data_->_tmp35_, &_data_->_tmp36_);
		_data_->data = _data_->_tmp37_;
		_data_->data_length1 = _data_->_tmp36_;
		_data_->_data_size_ = _data_->data_length1;
		_data_->_tmp38_ = _data_->data;
		_data_->_tmp38__length1 = _data_->data_length1;
		_data_->_tmp39_ = g_new0 (gchar, _data_->_tmp38__length1 + 1);
		_data_->str_data = _data_->_tmp39_;
		_data_->str_data_length1 = _data_->_tmp38__length1 + 1;
		_data_->_str_data_size_ = _data_->str_data_length1;
		_data_->_tmp40_ = _data_->str_data;
		_data_->_tmp40__length1 = _data_->str_data_length1;
		_data_->_tmp41_ = _data_->data;
		_data_->_tmp41__length1 = _data_->data_length1;
		_data_->_tmp42_ = _data_->data;
		_data_->_tmp42__length1 = _data_->data_length1;
		memcpy (_data_->_tmp40_, _data_->_tmp41_, (gsize) _data_->_tmp42__length1);
		_data_->_tmp43_ = _data_->str_data;
		_data_->_tmp43__length1 = _data_->str_data_length1;
		_data_->_tmp44_ = _data_->data;
		_data_->_tmp44__length1 = _data_->data_length1;
		_data_->_tmp43_[_data_->_tmp44__length1] = '\0';
		_data_->_tmp45_ = _data_->str_data;
		_data_->_tmp45__length1 = _data_->str_data_length1;
		_data_->_tmp46_ = g_strdup ((const gchar*) _data_->_tmp45_);
		_g_free0 (_data_->response);
		_data_->response = _data_->_tmp46_;
		_data_->_tmp47_ = _data_->response;
		if (_data_->_tmp47_ == NULL) {
			_data_->result = PROTON_PLUS_RETURN_CODE_UNKNOWN_ERROR;
			_data_->str_data = (g_free (_data_->str_data), NULL);
			_g_bytes_unref0 (_data_->bytes);
			_g_object_unref0 (_data_->message);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		switch (_data_->get_type) {
			case PROTON_PLUS_UTILS_WEB_GET_TYPE_GITHUB:
			{
				_data_->_tmp48_ = _data_->response;
				if (string_contains (_data_->_tmp48_, "https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-l" \
"imiting")) {
					_data_->result = PROTON_PLUS_RETURN_CODE_API_LIMIT_REACHED;
					_data_->str_data = (g_free (_data_->str_data), NULL);
					_g_bytes_unref0 (_data_->bytes);
					_g_object_unref0 (_data_->message);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				_data_->_tmp49_ = _data_->response;
				if (string_contains (_data_->_tmp49_, "Bad credentials")) {
					_data_->result = PROTON_PLUS_RETURN_CODE_INVALID_ACCESS_TOKEN;
					_data_->str_data = (g_free (_data_->str_data), NULL);
					_g_bytes_unref0 (_data_->bytes);
					_g_object_unref0 (_data_->message);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				break;
			}
			case PROTON_PLUS_UTILS_WEB_GET_TYPE_GITLAB:
			{
				_data_->_tmp50_ = _data_->response;
				if (string_contains (_data_->_tmp50_, "401 Unauthorized")) {
					_data_->result = PROTON_PLUS_RETURN_CODE_INVALID_ACCESS_TOKEN;
					_data_->str_data = (g_free (_data_->str_data), NULL);
					_g_bytes_unref0 (_data_->bytes);
					_g_object_unref0 (_data_->message);
					g_task_return_pointer (_data_->_async_result, _data_, NULL);
					if (_data_->_state_ != 0) {
						while (!g_task_get_completed (_data_->_async_result)) {
							g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
						}
					}
					g_object_unref (_data_->_async_result);
					return FALSE;
				}
				break;
			}
			default:
			{
				break;
			}
		}
		_data_->result = PROTON_PLUS_RETURN_CODE_VALID_REQUEST;
		_data_->str_data = (g_free (_data_->str_data), NULL);
		_g_bytes_unref0 (_data_->bytes);
		_g_object_unref0 (_data_->message);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp51_ = _data_->e;
		_data_->_tmp52_ = _data_->_tmp51_->message;
		g_warning ("web.vala:80: %s", _data_->_tmp52_);
		_data_->_tmp53_ = _data_->e;
		_data_->_tmp54_ = _data_->_tmp53_->message;
		if (string_contains (_data_->_tmp54_, "Temporary failure in name resolution")) {
			_data_->result = PROTON_PLUS_RETURN_CODE_CONNECTION_ISSUE;
			_g_error_free0 (_data_->e);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp55_ = _data_->e;
		_data_->_tmp56_ = _data_->_tmp55_->message;
		if (string_contains (_data_->_tmp56_, "Connection refused")) {
			_data_->result = PROTON_PLUS_RETURN_CODE_CONNECTION_REFUSED;
			_g_error_free0 (_data_->e);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp57_ = _data_->e;
		_data_->_tmp58_ = _data_->_tmp57_->message;
		if (string_contains (_data_->_tmp58_, "Name or service not known")) {
			_data_->result = PROTON_PLUS_RETURN_CODE_CONNECTION_UNKNOWN;
			_g_error_free0 (_data_->e);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->result = PROTON_PLUS_RETURN_CODE_UNKNOWN_ERROR;
		_g_error_free0 (_data_->e);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	_g_free0 (_data_->response);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
	g_clear_error (&_data_->_inner_error0_);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static void
proton_plus_utils_web_Download_data_free (gpointer _data)
{
	proton_plus_utils_web_DownloadData* _data_;
	_data_ = _data;
	_g_free0 (_data_->url);
	_g_free0 (_data_->path);
	g_slice_free (proton_plus_utils_web_DownloadData, _data_);
}

void
proton_plus_utils_web_Download (const gchar* url,
                                const gchar* path,
                                ProtonPlusUtilsWebcancel_callback cancel_callback,
                                gpointer cancel_callback_target,
                                ProtonPlusUtilsWebprogress_callback progress_callback,
                                gpointer progress_callback_target,
                                GAsyncReadyCallback _callback_,
                                gpointer _user_data_)
{
	proton_plus_utils_web_DownloadData* _data_;
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (url != NULL);
	g_return_if_fail (path != NULL);
	_data_ = g_slice_new0 (proton_plus_utils_web_DownloadData);
	_data_->_async_result = g_task_new (NULL, NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, proton_plus_utils_web_Download_data_free);
	_tmp0_ = g_strdup (url);
	_g_free0 (_data_->url);
	_data_->url = _tmp0_;
	_tmp1_ = g_strdup (path);
	_g_free0 (_data_->path);
	_data_->path = _tmp1_;
	_data_->cancel_callback = cancel_callback;
	_data_->cancel_callback_target = cancel_callback_target;
	_data_->progress_callback = progress_callback;
	_data_->progress_callback_target = progress_callback_target;
	proton_plus_utils_web_Download_co (_data_);
}

gboolean
proton_plus_utils_web_Download_finish (GAsyncResult* _res_,
                                       gchar** error_message)
{
	gboolean result;
	proton_plus_utils_web_DownloadData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	if (error_message) {
		*error_message = _data_->error_message;
	} else {
		_g_free0 (_data_->error_message);
	}
	_data_->error_message = NULL;
	result = _data_->result;
	return result;
}

static void
proton_plus_utils_web_Download_ready (GObject* source_object,
                                      GAsyncResult* _res_,
                                      gpointer _user_data_)
{
	proton_plus_utils_web_DownloadData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	proton_plus_utils_web_Download_co (_data_);
}

static gdouble*
_double_dup (gdouble* self)
{
	gdouble* dup;
	dup = g_new0 (gdouble, 1);
	memcpy (dup, self, sizeof (gdouble));
	return dup;
}

static gpointer
__double_dup0 (gpointer self)
{
	return self ? _double_dup (self) : NULL;
}

static gboolean
proton_plus_utils_web_Download_co (proton_plus_utils_web_DownloadData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		case 3:
		goto _state_3;
		case 4:
		goto _state_4;
		case 5:
		goto _state_5;
		case 6:
		goto _state_6;
		case 7:
		goto _state_7;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_g_free0 (_data_->error_message);
	_data_->error_message = NULL;
	{
		static const gsize chunk_size = (gsize) 4096;
		_data_->_tmp0_ = soup_message_new ("GET", _data_->url);
		_data_->soup_message = _data_->_tmp0_;
		_data_->_tmp1_ = proton_plus_utils_web_get_session ();
		_data_->_tmp2_ = _data_->_tmp1_;
		_data_->_tmp3_ = _data_->soup_message;
		_data_->_state_ = 1;
		soup_session_send_async (_data_->_tmp2_, _data_->_tmp3_, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_Download_ready, _data_);
		return FALSE;
		_state_1:
		_data_->_tmp4_ = soup_session_send_finish (_data_->_tmp2_, _data_->_res_, &_data_->_inner_error0_);
		_data_->input_stream = _data_->_tmp4_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->soup_message);
			goto __catch0_g_error;
		}
		_data_->_tmp5_ = _data_->soup_message;
		g_object_get (_data_->_tmp5_, "status-code", &_data_->_tmp6_, NULL);
		_data_->_tmp7_ = _data_->_tmp6_;
		if (_data_->_tmp7_ != ((guint) 200)) {
			_data_->_tmp8_ = _data_->soup_message;
			_data_->_tmp9_ = soup_message_get_reason_phrase (_data_->_tmp8_);
			_data_->_tmp10_ = _data_->_tmp9_;
			g_warning ("web.vala:107: %s", _data_->_tmp10_);
			_data_->_tmp11_ = _data_->soup_message;
			_data_->_tmp12_ = soup_message_get_reason_phrase (_data_->_tmp11_);
			_data_->_tmp13_ = _data_->_tmp12_;
			_data_->_tmp14_ = g_strdup (_data_->_tmp13_);
			_g_free0 (_data_->error_message);
			_data_->error_message = _data_->_tmp14_;
			_data_->result = FALSE;
			_g_object_unref0 (_data_->input_stream);
			_g_object_unref0 (_data_->soup_message);
			g_task_return_pointer (_data_->_async_result, _data_, NULL);
			if (_data_->_state_ != 0) {
				while (!g_task_get_completed (_data_->_async_result)) {
					g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
				}
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		}
		_data_->_tmp15_ = g_file_new_for_path (_data_->path);
		_data_->file = _data_->_tmp15_;
		_data_->_tmp16_ = _data_->file;
		if (g_file_query_exists (_data_->_tmp16_, NULL)) {
			_data_->_tmp17_ = _data_->file;
			_data_->_state_ = 2;
			g_file_delete_async (_data_->_tmp17_, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_Download_ready, _data_);
			return FALSE;
			_state_2:
			g_file_delete_finish (_data_->_tmp17_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->file);
				_g_object_unref0 (_data_->input_stream);
				_g_object_unref0 (_data_->soup_message);
				goto __catch0_g_error;
			}
		}
		_data_->_tmp18_ = _data_->file;
		_data_->_state_ = 3;
		g_file_create_async (_data_->_tmp18_, G_FILE_CREATE_REPLACE_DESTINATION, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_Download_ready, _data_);
		return FALSE;
		_state_3:
		_data_->_tmp19_ = g_file_create_finish (_data_->_tmp18_, _data_->_res_, &_data_->_inner_error0_);
		_data_->output_stream = _data_->_tmp19_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->file);
			_g_object_unref0 (_data_->input_stream);
			_g_object_unref0 (_data_->soup_message);
			goto __catch0_g_error;
		}
		_data_->_tmp20_ = _data_->soup_message;
		_data_->_tmp21_ = soup_message_get_response_headers (_data_->_tmp20_);
		_data_->server_download_size = soup_message_headers_get_content_length (_data_->_tmp21_);
		_data_->is_percent = _data_->server_download_size > ((gint64) 0);
		_data_->bytes_downloaded = (gint64) 0;
		if (_data_->progress_callback != NULL) {
			_data_->_tmp22_ = (gdouble) 0;
			_data_->progress_callback (_data_->is_percent, (gint64) 0, (gdouble) 0, &_data_->_tmp22_, _data_->progress_callback_target);
		}
		_data_->is_canceled = FALSE;
		_data_->start_time = g_get_monotonic_time ();
		while (TRUE) {
			if (_data_->cancel_callback != NULL) {
				_data_->_tmp23_ = _data_->cancel_callback (_data_->cancel_callback_target);
			} else {
				_data_->_tmp23_ = FALSE;
			}
			if (_data_->_tmp23_) {
				_data_->is_canceled = TRUE;
				break;
			}
			_data_->_tmp24_ = _data_->input_stream;
			_data_->_state_ = 4;
			g_input_stream_read_bytes_async (_data_->_tmp24_, chunk_size, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_Download_ready, _data_);
			return FALSE;
			_state_4:
			_data_->_tmp25_ = g_input_stream_read_bytes_finish (_data_->_tmp24_, _data_->_res_, &_data_->_inner_error0_);
			_data_->chunk = _data_->_tmp25_;
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->output_stream);
				_g_object_unref0 (_data_->file);
				_g_object_unref0 (_data_->input_stream);
				_g_object_unref0 (_data_->soup_message);
				goto __catch0_g_error;
			}
			_data_->_tmp26_ = _data_->chunk;
			if (g_bytes_get_size (_data_->_tmp26_) == ((gsize) 0)) {
				_g_bytes_unref0 (_data_->chunk);
				break;
			}
			_data_->_tmp27_ = _data_->output_stream;
			_data_->_tmp28_ = _data_->chunk;
			_data_->_tmp29_ = 0;
			_data_->_tmp30_ = g_bytes_get_data (_data_->_tmp28_, &_data_->_tmp29_);
			_data_->_state_ = 5;
			g_output_stream_write_async ((GOutputStream*) _data_->_tmp27_, _data_->_tmp30_, (gsize) _data_->_tmp29_, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_Download_ready, _data_);
			return FALSE;
			_state_5:
			g_output_stream_write_finish ((GOutputStream*) _data_->_tmp27_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_bytes_unref0 (_data_->chunk);
				_g_object_unref0 (_data_->output_stream);
				_g_object_unref0 (_data_->file);
				_g_object_unref0 (_data_->input_stream);
				_g_object_unref0 (_data_->soup_message);
				goto __catch0_g_error;
			}
			_data_->_tmp31_ = _data_->chunk;
			_data_->bytes_downloaded += (gint64) g_bytes_get_size (_data_->_tmp31_);
			if (_data_->progress_callback != NULL) {
				_data_->elapsed_us = g_get_monotonic_time () - _data_->start_time;
				_data_->elapsed_s = _data_->elapsed_us / 1000000.0;
				if (_data_->elapsed_s > ((gdouble) 0)) {
					_data_->_tmp32_ = (_data_->bytes_downloaded / 1024.0) / _data_->elapsed_s;
				} else {
					_data_->_tmp32_ = 0.0;
				}
				_data_->speed_kbps = _data_->_tmp32_;
				if (_data_->elapsed_s > ((gdouble) 0)) {
					_data_->_tmp33_ = _data_->bytes_downloaded / _data_->elapsed_s;
				} else {
					_data_->_tmp33_ = 0.0;
				}
				_data_->speed_bps = _data_->_tmp33_;
				_data_->remaining_seconds = NULL;
				if (_data_->is_percent) {
					_data_->_tmp34_ = _data_->speed_bps > 0.0;
				} else {
					_data_->_tmp34_ = FALSE;
				}
				if (_data_->_tmp34_) {
					_data_->bytes_left = _data_->server_download_size - _data_->bytes_downloaded;
					_data_->_tmp35_ = _data_->bytes_left / _data_->speed_bps;
					_data_->_tmp36_ = __double_dup0 (&_data_->_tmp35_);
					_g_free0 (_data_->remaining_seconds);
					_data_->remaining_seconds = _data_->_tmp36_;
				}
				if (!_data_->is_percent) {
					_data_->_tmp37_ = _data_->bytes_downloaded;
				} else {
					_data_->_tmp37_ = (gint64) ((((gdouble) _data_->bytes_downloaded) / _data_->server_download_size) * 100);
				}
				_data_->progress = _data_->_tmp37_;
				_data_->_tmp38_ = _data_->remaining_seconds;
				_data_->progress_callback (_data_->is_percent, _data_->progress, _data_->speed_kbps, _data_->_tmp38_, _data_->progress_callback_target);
				_g_free0 (_data_->remaining_seconds);
			}
			_g_bytes_unref0 (_data_->chunk);
		}
		_data_->_tmp39_ = _data_->output_stream;
		_data_->_state_ = 6;
		g_output_stream_close_async ((GOutputStream*) _data_->_tmp39_, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_Download_ready, _data_);
		return FALSE;
		_state_6:
		g_output_stream_close_finish ((GOutputStream*) _data_->_tmp39_, _data_->_res_, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_g_object_unref0 (_data_->output_stream);
			_g_object_unref0 (_data_->file);
			_g_object_unref0 (_data_->input_stream);
			_g_object_unref0 (_data_->soup_message);
			goto __catch0_g_error;
		}
		if (_data_->is_canceled) {
			_data_->_tmp41_ = _data_->file;
			_data_->_tmp40_ = g_file_query_exists (_data_->_tmp41_, NULL);
		} else {
			_data_->_tmp40_ = FALSE;
		}
		if (_data_->_tmp40_) {
			_data_->_tmp42_ = _data_->file;
			_data_->_state_ = 7;
			g_file_delete_async (_data_->_tmp42_, G_PRIORITY_DEFAULT, NULL, proton_plus_utils_web_Download_ready, _data_);
			return FALSE;
			_state_7:
			g_file_delete_finish (_data_->_tmp42_, _data_->_res_, &_data_->_inner_error0_);
			if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
				_g_object_unref0 (_data_->output_stream);
				_g_object_unref0 (_data_->file);
				_g_object_unref0 (_data_->input_stream);
				_g_object_unref0 (_data_->soup_message);
				goto __catch0_g_error;
			}
		}
		_data_->result = !_data_->is_canceled;
		_g_object_unref0 (_data_->output_stream);
		_g_object_unref0 (_data_->file);
		_g_object_unref0 (_data_->input_stream);
		_g_object_unref0 (_data_->soup_message);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp43_ = _data_->e;
		_data_->_tmp44_ = _data_->_tmp43_->message;
		g_warning ("web.vala:179: %s", _data_->_tmp44_);
		_data_->_tmp45_ = _data_->e;
		_data_->_tmp46_ = _data_->_tmp45_->message;
		_data_->_tmp47_ = g_strdup (_data_->_tmp46_);
		_g_free0 (_data_->error_message);
		_data_->error_message = _data_->_tmp47_;
		_data_->result = FALSE;
		_g_error_free0 (_data_->e);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	__finally0:
	_g_free0 (_data_->error_message);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
	g_clear_error (&_data_->_inner_error0_);
	g_object_unref (_data_->_async_result);
	return FALSE;
}

ProtonPlusUtilsWeb*
proton_plus_utils_web_construct (GType object_type)
{
	ProtonPlusUtilsWeb* self = NULL;
	self = (ProtonPlusUtilsWeb*) g_type_create_instance (object_type);
	return self;
}

ProtonPlusUtilsWeb*
proton_plus_utils_web_new (void)
{
	return proton_plus_utils_web_construct (PROTON_PLUS_UTILS_TYPE_WEB);
}

static SoupSession*
proton_plus_utils_web_get_session (void)
{
	SoupSession* result;
	SoupSession* _tmp0_;
	SoupSession* _tmp3_;
	_tmp0_ = proton_plus_utils_web__session;
	if (_tmp0_ == NULL) {
		SoupSession* _tmp1_;
		SoupSession* _tmp2_;
		_tmp1_ = soup_session_new ();
		_g_object_unref0 (proton_plus_utils_web__session);
		proton_plus_utils_web__session = _tmp1_;
		_tmp2_ = proton_plus_utils_web__session;
		soup_session_set_user_agent (_tmp2_, APP_NAME "/" APP_VERSION);
	}
	_tmp3_ = proton_plus_utils_web__session;
	result = _tmp3_;
	return result;
}

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

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

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

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

static gchar*
proton_plus_utils_value_web_collect_value (GValue* value,
                                           guint n_collect_values,
                                           GTypeCValue* collect_values,
                                           guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		ProtonPlusUtilsWeb * 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 = proton_plus_utils_web_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
proton_plus_utils_value_web_lcopy_value (const GValue* value,
                                         guint n_collect_values,
                                         GTypeCValue* collect_values,
                                         guint collect_flags)
{
	ProtonPlusUtilsWeb ** 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 = proton_plus_utils_web_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
proton_plus_utils_param_spec_web (const gchar* name,
                                  const gchar* nick,
                                  const gchar* blurb,
                                  GType object_type,
                                  GParamFlags flags)
{
	ProtonPlusUtilsParamSpecWeb* spec;
	g_return_val_if_fail (g_type_is_a (object_type, PROTON_PLUS_UTILS_TYPE_WEB), 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
proton_plus_utils_value_get_web (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PROTON_PLUS_UTILS_TYPE_WEB), NULL);
	return value->data[0].v_pointer;
}

void
proton_plus_utils_value_set_web (GValue* value,
                                 gpointer v_object)
{
	ProtonPlusUtilsWeb * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PROTON_PLUS_UTILS_TYPE_WEB));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, PROTON_PLUS_UTILS_TYPE_WEB));
		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;
		proton_plus_utils_web_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		proton_plus_utils_web_unref (old);
	}
}

void
proton_plus_utils_value_take_web (GValue* value,
                                  gpointer v_object)
{
	ProtonPlusUtilsWeb * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, PROTON_PLUS_UTILS_TYPE_WEB));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, PROTON_PLUS_UTILS_TYPE_WEB));
		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) {
		proton_plus_utils_web_unref (old);
	}
}

static void
proton_plus_utils_web_class_init (ProtonPlusUtilsWebClass * klass,
                                  gpointer klass_data)
{
	proton_plus_utils_web_parent_class = g_type_class_peek_parent (klass);
	((ProtonPlusUtilsWebClass *) klass)->finalize = proton_plus_utils_web_finalize;
}

static void
proton_plus_utils_web_instance_init (ProtonPlusUtilsWeb * self,
                                     gpointer klass)
{
	self->ref_count = 1;
}

static void
proton_plus_utils_web_finalize (ProtonPlusUtilsWeb * obj)
{
	ProtonPlusUtilsWeb * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, PROTON_PLUS_UTILS_TYPE_WEB, ProtonPlusUtilsWeb);
	g_signal_handlers_destroy (self);
}

static GType
proton_plus_utils_web_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { proton_plus_utils_value_web_init, proton_plus_utils_value_web_free_value, proton_plus_utils_value_web_copy_value, proton_plus_utils_value_web_peek_pointer, "p", proton_plus_utils_value_web_collect_value, "p", proton_plus_utils_value_web_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (ProtonPlusUtilsWebClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) proton_plus_utils_web_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ProtonPlusUtilsWeb), 0, (GInstanceInitFunc) proton_plus_utils_web_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 proton_plus_utils_web_type_id;
	proton_plus_utils_web_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ProtonPlusUtilsWeb", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return proton_plus_utils_web_type_id;
}

GType
proton_plus_utils_web_get_type (void)
{
	static volatile gsize proton_plus_utils_web_type_id__once = 0;
	if (g_once_init_enter (&proton_plus_utils_web_type_id__once)) {
		GType proton_plus_utils_web_type_id;
		proton_plus_utils_web_type_id = proton_plus_utils_web_get_type_once ();
		g_once_init_leave (&proton_plus_utils_web_type_id__once, proton_plus_utils_web_type_id);
	}
	return proton_plus_utils_web_type_id__once;
}

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

void
proton_plus_utils_web_unref (gpointer instance)
{
	ProtonPlusUtilsWeb * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		PROTON_PLUS_UTILS_WEB_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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;
}

