1
/* json_soup.c generated by valac, the Vala compiler
2
* generated from json_soup.vala, do not modify */
4
/* -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- */
5
/* vim:set fileencodings=utf-8 tabstop=4 expandtab shiftwidth=4 softtabstop=4: */
8
#include <glib-object.h>
9
#include <json-glib/json-glib.h>
12
#include <libsoup/soup.h>
17
#define TYPE_JSON_SOUP (json_soup_get_type ())
18
#define JSON_SOUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_JSON_SOUP, JsonSoup))
19
#define JSON_SOUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_JSON_SOUP, JsonSoupClass))
20
#define IS_JSON_SOUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_JSON_SOUP))
21
#define IS_JSON_SOUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_JSON_SOUP))
22
#define JSON_SOUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_JSON_SOUP, JsonSoupClass))
24
typedef struct _JsonSoup JsonSoup;
25
typedef struct _JsonSoupClass JsonSoupClass;
26
typedef struct _JsonSoupPrivate JsonSoupPrivate;
27
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
28
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
29
#define _soup_uri_free0(var) ((var == NULL) ? NULL : (var = (soup_uri_free (var), NULL)))
30
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
31
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))
34
GObject parent_instance;
35
JsonSoupPrivate * priv;
38
struct _JsonSoupClass {
39
GObjectClass parent_class;
42
struct _JsonSoupPrivate {
48
static gpointer json_soup_parent_class = NULL;
50
GType json_soup_get_type (void);
51
#define JSON_SOUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_JSON_SOUP, JsonSoupPrivate))
53
JSON_SOUP_DUMMY_PROPERTY
55
JsonSoup* json_soup_new_buffer (const char* buffer);
56
JsonSoup* json_soup_construct_buffer (GType object_type, const char* buffer);
57
JsonSoup* json_soup_new_file (const char* file);
58
JsonSoup* json_soup_construct_file (GType object_type, const char* file);
59
JsonSoup* json_soup_new_http (const char* url);
60
JsonSoup* json_soup_construct_http (GType object_type, const char* url);
61
JsonSoup* json_soup_object (JsonSoup* self, const char* name);
62
JsonSoup* json_soup_parent (JsonSoup* self);
63
JsonSoup* json_soup_sibling (JsonSoup* self, const char* name);
64
JsonSoup* json_soup_array (JsonSoup* self, gint idx);
65
JsonSoup* json_soup_grandparent (JsonSoup* self);
66
JsonSoup* json_soup_reset (JsonSoup* self);
67
static gboolean json_soup_is_value (JsonSoup* self);
68
gboolean json_soup_is_object (JsonSoup* self);
69
gboolean json_soup_is_array (JsonSoup* self);
70
gboolean json_soup_is_string (JsonSoup* self);
71
gboolean json_soup_is_int (JsonSoup* self);
72
gboolean json_soup_is_double (JsonSoup* self);
73
gboolean json_soup_is_bool (JsonSoup* self);
74
char* json_soup_get_string (JsonSoup* self);
75
gint64 json_soup_get_int (JsonSoup* self);
76
double json_soup_get_double (JsonSoup* self);
77
gboolean json_soup_get_bool (JsonSoup* self);
78
gint json_soup_length (JsonSoup* self);
79
JsonSoup* json_soup_new (void);
80
JsonSoup* json_soup_construct (GType object_type);
81
static void json_soup_finalize (GObject* obj);
85
JsonSoup* json_soup_construct_buffer (GType object_type, const char* buffer) {
86
GError * _inner_error_;
89
g_return_val_if_fail (buffer != NULL, NULL);
91
self = (JsonSoup*) g_object_new (object_type, NULL);
92
self->priv->parser = (_tmp0_ = json_parser_new (), _g_object_unref0 (self->priv->parser), _tmp0_);
94
json_parser_load_from_data (self->priv->parser, buffer, -1, &_inner_error_);
95
if (_inner_error_ != NULL) {
96
goto __catch1_g_error;
98
self->priv->node = json_parser_get_root (self->priv->parser);
105
_inner_error_ = NULL;
107
g_warning ("json_soup.vala:34: %s", e->message);
112
if (_inner_error_ != NULL) {
113
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
114
g_clear_error (&_inner_error_);
121
JsonSoup* json_soup_new_buffer (const char* buffer) {
122
return json_soup_construct_buffer (TYPE_JSON_SOUP, buffer);
126
JsonSoup* json_soup_construct_file (GType object_type, const char* file) {
127
GError * _inner_error_;
130
g_return_val_if_fail (file != NULL, NULL);
131
_inner_error_ = NULL;
132
self = (JsonSoup*) g_object_new (object_type, NULL);
133
self->priv->parser = (_tmp0_ = json_parser_new (), _g_object_unref0 (self->priv->parser), _tmp0_);
135
json_parser_load_from_file (self->priv->parser, file, &_inner_error_);
136
if (_inner_error_ != NULL) {
137
goto __catch2_g_error;
139
self->priv->node = json_parser_get_root (self->priv->parser);
146
_inner_error_ = NULL;
148
g_warning ("json_soup.vala:43: %s", e->message);
153
if (_inner_error_ != NULL) {
154
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
155
g_clear_error (&_inner_error_);
162
JsonSoup* json_soup_new_file (const char* file) {
163
return json_soup_construct_file (TYPE_JSON_SOUP, file);
167
JsonSoup* json_soup_construct_http (GType object_type, const char* url) {
168
GError * _inner_error_;
170
SoupSessionAsync* session;
173
SoupMessage* message;
175
g_return_val_if_fail (url != NULL, NULL);
176
_inner_error_ = NULL;
177
self = (JsonSoup*) g_object_new (object_type, NULL);
178
session = (SoupSessionAsync*) soup_session_async_new ();
179
message = (_tmp1_ = soup_message_new_from_uri ("GET", _tmp0_ = soup_uri_new (url)), _soup_uri_free0 (_tmp0_), _tmp1_);
180
if (soup_session_send_message ((SoupSession*) session, message) != 200) {
181
g_warning ("json_soup.vala:50: Can not connect to %s", url);
183
self->priv->parser = (_tmp2_ = json_parser_new (), _g_object_unref0 (self->priv->parser), _tmp2_);
185
json_parser_load_from_data (self->priv->parser, (const char*) message->response_body->data, -1, &_inner_error_);
186
if (_inner_error_ != NULL) {
187
goto __catch3_g_error;
189
self->priv->node = json_parser_get_root (self->priv->parser);
196
_inner_error_ = NULL;
198
g_warning ("json_soup.vala:57: %s", e->message);
203
if (_inner_error_ != NULL) {
204
_g_object_unref0 (session);
205
_g_object_unref0 (message);
206
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
207
g_clear_error (&_inner_error_);
210
_g_object_unref0 (session);
211
_g_object_unref0 (message);
216
JsonSoup* json_soup_new_http (const char* url) {
217
return json_soup_construct_http (TYPE_JSON_SOUP, url);
221
static gpointer _g_object_ref0 (gpointer self) {
222
return self ? g_object_ref (self) : NULL;
226
static gpointer _json_object_ref0 (gpointer self) {
227
return self ? json_object_ref (self) : NULL;
231
JsonSoup* json_soup_object (JsonSoup* self, const char* name) {
232
JsonSoup* result = NULL;
234
g_return_val_if_fail (self != NULL, NULL);
235
g_return_val_if_fail (name != NULL, NULL);
236
if (json_node_get_node_type (self->priv->node) != JSON_NODE_OBJECT) {
237
g_warning ("json_soup.vala:70: This is not a object.");
238
result = _g_object_ref0 (self);
241
object = _json_object_ref0 (json_node_get_object (self->priv->node));
242
if (json_object_has_member (object, name) == FALSE) {
243
g_warning ("json_soup.vala:75: There is no such member as %s.", name);
244
result = _g_object_ref0 (self);
245
_json_object_unref0 (object);
248
self->priv->node = json_object_get_member (object, name);
249
result = _g_object_ref0 (self);
250
_json_object_unref0 (object);
255
JsonSoup* json_soup_sibling (JsonSoup* self, const char* name) {
256
JsonSoup* result = NULL;
259
g_return_val_if_fail (self != NULL, NULL);
260
g_return_val_if_fail (name != NULL, NULL);
261
_tmp0_ = json_soup_parent (self);
262
_g_object_unref0 (_tmp0_);
263
_tmp1_ = json_soup_object (self, name);
264
_g_object_unref0 (_tmp1_);
265
result = _g_object_ref0 (self);
270
static gpointer _json_array_ref0 (gpointer self) {
271
return self ? json_array_ref (self) : NULL;
275
JsonSoup* json_soup_array (JsonSoup* self, gint idx) {
276
JsonSoup* result = NULL;
279
gboolean _tmp0_ = FALSE;
280
g_return_val_if_fail (self != NULL, NULL);
281
if (json_node_get_node_type (self->priv->node) != JSON_NODE_ARRAY) {
282
g_warning ("json_soup.vala:88: This is not a array.");
283
result = _g_object_ref0 (self);
286
array = _json_array_ref0 (json_node_get_array (self->priv->node));
287
length = (gint) json_array_get_length (array);
294
g_warning ("json_soup.vala:94: Out of index. %d", idx);
295
result = _g_object_ref0 (self);
296
_json_array_unref0 (array);
299
self->priv->node = json_array_get_element (array, (guint) idx);
300
result = _g_object_ref0 (self);
301
_json_array_unref0 (array);
306
JsonSoup* json_soup_parent (JsonSoup* self) {
307
JsonSoup* result = NULL;
308
JsonNode* parent_node;
309
g_return_val_if_fail (self != NULL, NULL);
310
parent_node = json_node_get_parent (self->priv->node);
311
if (parent_node == NULL) {
312
g_warning ("json_soup.vala:103: Already be root.");
313
result = _g_object_ref0 (self);
316
self->priv->node = parent_node;
317
result = _g_object_ref0 (self);
322
JsonSoup* json_soup_grandparent (JsonSoup* self) {
323
JsonSoup* result = NULL;
326
g_return_val_if_fail (self != NULL, NULL);
327
_tmp0_ = json_soup_parent (self);
328
_g_object_unref0 (_tmp0_);
329
_tmp1_ = json_soup_parent (self);
330
_g_object_unref0 (_tmp1_);
331
result = _g_object_ref0 (self);
336
JsonSoup* json_soup_reset (JsonSoup* self) {
337
JsonSoup* result = NULL;
338
g_return_val_if_fail (self != NULL, NULL);
339
self->priv->node = json_parser_get_root (self->priv->parser);
340
result = _g_object_ref0 (self);
345
static gboolean json_soup_is_value (JsonSoup* self) {
346
gboolean result = FALSE;
347
g_return_val_if_fail (self != NULL, FALSE);
348
if (json_node_get_node_type (self->priv->node) == JSON_NODE_VALUE) {
358
gboolean json_soup_is_object (JsonSoup* self) {
359
gboolean result = FALSE;
360
g_return_val_if_fail (self != NULL, FALSE);
361
result = json_node_get_node_type (self->priv->node) == JSON_NODE_OBJECT;
366
gboolean json_soup_is_array (JsonSoup* self) {
367
gboolean result = FALSE;
368
g_return_val_if_fail (self != NULL, FALSE);
369
result = json_node_get_node_type (self->priv->node) == JSON_NODE_ARRAY;
374
gboolean json_soup_is_string (JsonSoup* self) {
375
gboolean result = FALSE;
376
g_return_val_if_fail (self != NULL, FALSE);
377
if (json_soup_is_value (self) == FALSE) {
381
result = json_node_get_value_type (self->priv->node) == G_TYPE_STRING;
386
gboolean json_soup_is_int (JsonSoup* self) {
387
gboolean result = FALSE;
388
g_return_val_if_fail (self != NULL, FALSE);
389
if (json_soup_is_value (self) == FALSE) {
393
result = json_node_get_value_type (self->priv->node) == G_TYPE_INT64;
398
gboolean json_soup_is_double (JsonSoup* self) {
399
gboolean result = FALSE;
400
g_return_val_if_fail (self != NULL, FALSE);
401
if (json_soup_is_value (self) == FALSE) {
405
result = json_node_get_value_type (self->priv->node) == G_TYPE_DOUBLE;
410
gboolean json_soup_is_bool (JsonSoup* self) {
411
gboolean result = FALSE;
412
g_return_val_if_fail (self != NULL, FALSE);
413
if (json_soup_is_value (self) == FALSE) {
417
result = json_node_get_value_type (self->priv->node) == G_TYPE_BOOLEAN;
422
char* json_soup_get_string (JsonSoup* self) {
424
g_return_val_if_fail (self != NULL, NULL);
425
result = g_strdup (json_node_get_string (self->priv->node));
430
gint64 json_soup_get_int (JsonSoup* self) {
432
g_return_val_if_fail (self != NULL, 0LL);
433
result = json_node_get_int (self->priv->node);
438
double json_soup_get_double (JsonSoup* self) {
440
g_return_val_if_fail (self != NULL, 0.0);
441
result = json_node_get_double (self->priv->node);
446
gboolean json_soup_get_bool (JsonSoup* self) {
447
gboolean result = FALSE;
448
g_return_val_if_fail (self != NULL, FALSE);
449
result = json_node_get_boolean (self->priv->node);
454
gint json_soup_length (JsonSoup* self) {
457
g_return_val_if_fail (self != NULL, 0);
458
if (json_soup_is_array (self) == FALSE) {
462
array = _json_array_ref0 (json_node_get_array (self->priv->node));
463
result = (gint) json_array_get_length (array);
464
_json_array_unref0 (array);
469
JsonSoup* json_soup_construct (GType object_type) {
471
self = (JsonSoup*) g_object_new (object_type, NULL);
476
JsonSoup* json_soup_new (void) {
477
return json_soup_construct (TYPE_JSON_SOUP);
481
static void json_soup_class_init (JsonSoupClass * klass) {
482
json_soup_parent_class = g_type_class_peek_parent (klass);
483
g_type_class_add_private (klass, sizeof (JsonSoupPrivate));
484
G_OBJECT_CLASS (klass)->finalize = json_soup_finalize;
488
static void json_soup_instance_init (JsonSoup * self) {
489
self->priv = JSON_SOUP_GET_PRIVATE (self);
490
self->priv->parser = NULL;
491
self->priv->node = NULL;
495
static void json_soup_finalize (GObject* obj) {
497
self = JSON_SOUP (obj);
500
self->priv->node = NULL;
501
self->priv->parser = (_tmp0_ = NULL, _g_object_unref0 (self->priv->parser), _tmp0_);
503
_g_object_unref0 (self->priv->parser);
504
G_OBJECT_CLASS (json_soup_parent_class)->finalize (obj);
508
GType json_soup_get_type (void) {
509
static volatile gsize json_soup_type_id__volatile = 0;
510
if (g_once_init_enter (&json_soup_type_id__volatile)) {
511
static const GTypeInfo g_define_type_info = { sizeof (JsonSoupClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) json_soup_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (JsonSoup), 0, (GInstanceInitFunc) json_soup_instance_init, NULL };
512
GType json_soup_type_id;
513
json_soup_type_id = g_type_register_static (G_TYPE_OBJECT, "JsonSoup", &g_define_type_info, 0);
514
g_once_init_leave (&json_soup_type_id__volatile, json_soup_type_id);
516
return json_soup_type_id__volatile;