~ubuntu-branches/debian/sid/betaradio/sid

« back to all changes in this revision

Viewing changes to src/json_soup.c

  • Committer: Bazaar Package Importer
  • Author(s): Shih-Yuan Lee (FourDollars)
  • Date: 2010-10-08 12:18:06 UTC
  • Revision ID: james.westby@ubuntu.com-20101008121806-k1sj8jn5elq86v71
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* json_soup.c generated by valac, the Vala compiler
 
2
 * generated from json_soup.vala, do not modify */
 
3
 
 
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: */
 
6
 
 
7
#include <glib.h>
 
8
#include <glib-object.h>
 
9
#include <json-glib/json-glib.h>
 
10
#include <stdlib.h>
 
11
#include <string.h>
 
12
#include <libsoup/soup.h>
 
13
#include <float.h>
 
14
#include <math.h>
 
15
 
 
16
 
 
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))
 
23
 
 
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)))
 
32
 
 
33
struct _JsonSoup {
 
34
        GObject parent_instance;
 
35
        JsonSoupPrivate * priv;
 
36
};
 
37
 
 
38
struct _JsonSoupClass {
 
39
        GObjectClass parent_class;
 
40
};
 
41
 
 
42
struct _JsonSoupPrivate {
 
43
        JsonParser* parser;
 
44
        JsonNode* node;
 
45
};
 
46
 
 
47
 
 
48
static gpointer json_soup_parent_class = NULL;
 
49
 
 
50
GType json_soup_get_type (void);
 
51
#define JSON_SOUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_JSON_SOUP, JsonSoupPrivate))
 
52
enum  {
 
53
        JSON_SOUP_DUMMY_PROPERTY
 
54
};
 
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);
 
82
 
 
83
 
 
84
 
 
85
JsonSoup* json_soup_construct_buffer (GType object_type, const char* buffer) {
 
86
        GError * _inner_error_;
 
87
        JsonSoup * self;
 
88
        JsonParser* _tmp0_;
 
89
        g_return_val_if_fail (buffer != NULL, NULL);
 
90
        _inner_error_ = 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_);
 
93
        {
 
94
                json_parser_load_from_data (self->priv->parser, buffer, -1, &_inner_error_);
 
95
                if (_inner_error_ != NULL) {
 
96
                        goto __catch1_g_error;
 
97
                }
 
98
                self->priv->node = json_parser_get_root (self->priv->parser);
 
99
        }
 
100
        goto __finally1;
 
101
        __catch1_g_error:
 
102
        {
 
103
                GError * e;
 
104
                e = _inner_error_;
 
105
                _inner_error_ = NULL;
 
106
                {
 
107
                        g_warning ("json_soup.vala:34: %s", e->message);
 
108
                        _g_error_free0 (e);
 
109
                }
 
110
        }
 
111
        __finally1:
 
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_);
 
115
                return NULL;
 
116
        }
 
117
        return self;
 
118
}
 
119
 
 
120
 
 
121
JsonSoup* json_soup_new_buffer (const char* buffer) {
 
122
        return json_soup_construct_buffer (TYPE_JSON_SOUP, buffer);
 
123
}
 
124
 
 
125
 
 
126
JsonSoup* json_soup_construct_file (GType object_type, const char* file) {
 
127
        GError * _inner_error_;
 
128
        JsonSoup * self;
 
129
        JsonParser* _tmp0_;
 
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_);
 
134
        {
 
135
                json_parser_load_from_file (self->priv->parser, file, &_inner_error_);
 
136
                if (_inner_error_ != NULL) {
 
137
                        goto __catch2_g_error;
 
138
                }
 
139
                self->priv->node = json_parser_get_root (self->priv->parser);
 
140
        }
 
141
        goto __finally2;
 
142
        __catch2_g_error:
 
143
        {
 
144
                GError * e;
 
145
                e = _inner_error_;
 
146
                _inner_error_ = NULL;
 
147
                {
 
148
                        g_warning ("json_soup.vala:43: %s", e->message);
 
149
                        _g_error_free0 (e);
 
150
                }
 
151
        }
 
152
        __finally2:
 
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_);
 
156
                return NULL;
 
157
        }
 
158
        return self;
 
159
}
 
160
 
 
161
 
 
162
JsonSoup* json_soup_new_file (const char* file) {
 
163
        return json_soup_construct_file (TYPE_JSON_SOUP, file);
 
164
}
 
165
 
 
166
 
 
167
JsonSoup* json_soup_construct_http (GType object_type, const char* url) {
 
168
        GError * _inner_error_;
 
169
        JsonSoup * self;
 
170
        SoupSessionAsync* session;
 
171
        SoupURI* _tmp0_;
 
172
        SoupMessage* _tmp1_;
 
173
        SoupMessage* message;
 
174
        JsonParser* _tmp2_;
 
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);
 
182
        }
 
183
        self->priv->parser = (_tmp2_ = json_parser_new (), _g_object_unref0 (self->priv->parser), _tmp2_);
 
184
        {
 
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;
 
188
                }
 
189
                self->priv->node = json_parser_get_root (self->priv->parser);
 
190
        }
 
191
        goto __finally3;
 
192
        __catch3_g_error:
 
193
        {
 
194
                GError * e;
 
195
                e = _inner_error_;
 
196
                _inner_error_ = NULL;
 
197
                {
 
198
                        g_warning ("json_soup.vala:57: %s", e->message);
 
199
                        _g_error_free0 (e);
 
200
                }
 
201
        }
 
202
        __finally3:
 
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_);
 
208
                return NULL;
 
209
        }
 
210
        _g_object_unref0 (session);
 
211
        _g_object_unref0 (message);
 
212
        return self;
 
213
}
 
214
 
 
215
 
 
216
JsonSoup* json_soup_new_http (const char* url) {
 
217
        return json_soup_construct_http (TYPE_JSON_SOUP, url);
 
218
}
 
219
 
 
220
 
 
221
static gpointer _g_object_ref0 (gpointer self) {
 
222
        return self ? g_object_ref (self) : NULL;
 
223
}
 
224
 
 
225
 
 
226
static gpointer _json_object_ref0 (gpointer self) {
 
227
        return self ? json_object_ref (self) : NULL;
 
228
}
 
229
 
 
230
 
 
231
JsonSoup* json_soup_object (JsonSoup* self, const char* name) {
 
232
        JsonSoup* result = NULL;
 
233
        JsonObject* object;
 
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);
 
239
                return result;
 
240
        }
 
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);
 
246
                return result;
 
247
        }
 
248
        self->priv->node = json_object_get_member (object, name);
 
249
        result = _g_object_ref0 (self);
 
250
        _json_object_unref0 (object);
 
251
        return result;
 
252
}
 
253
 
 
254
 
 
255
JsonSoup* json_soup_sibling (JsonSoup* self, const char* name) {
 
256
        JsonSoup* result = NULL;
 
257
        JsonSoup* _tmp0_;
 
258
        JsonSoup* _tmp1_;
 
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);
 
266
        return result;
 
267
}
 
268
 
 
269
 
 
270
static gpointer _json_array_ref0 (gpointer self) {
 
271
        return self ? json_array_ref (self) : NULL;
 
272
}
 
273
 
 
274
 
 
275
JsonSoup* json_soup_array (JsonSoup* self, gint idx) {
 
276
        JsonSoup* result = NULL;
 
277
        JsonArray* array;
 
278
        gint length;
 
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);
 
284
                return result;
 
285
        }
 
286
        array = _json_array_ref0 (json_node_get_array (self->priv->node));
 
287
        length = (gint) json_array_get_length (array);
 
288
        if (idx > length) {
 
289
                _tmp0_ = TRUE;
 
290
        } else {
 
291
                _tmp0_ = idx < 0;
 
292
        }
 
293
        if (_tmp0_) {
 
294
                g_warning ("json_soup.vala:94: Out of index. %d", idx);
 
295
                result = _g_object_ref0 (self);
 
296
                _json_array_unref0 (array);
 
297
                return result;
 
298
        }
 
299
        self->priv->node = json_array_get_element (array, (guint) idx);
 
300
        result = _g_object_ref0 (self);
 
301
        _json_array_unref0 (array);
 
302
        return result;
 
303
}
 
304
 
 
305
 
 
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);
 
314
                return result;
 
315
        }
 
316
        self->priv->node = parent_node;
 
317
        result = _g_object_ref0 (self);
 
318
        return result;
 
319
}
 
320
 
 
321
 
 
322
JsonSoup* json_soup_grandparent (JsonSoup* self) {
 
323
        JsonSoup* result = NULL;
 
324
        JsonSoup* _tmp0_;
 
325
        JsonSoup* _tmp1_;
 
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);
 
332
        return result;
 
333
}
 
334
 
 
335
 
 
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);
 
341
        return result;
 
342
}
 
343
 
 
344
 
 
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) {
 
349
                result = TRUE;
 
350
                return result;
 
351
        } else {
 
352
                result = FALSE;
 
353
                return result;
 
354
        }
 
355
}
 
356
 
 
357
 
 
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;
 
362
        return result;
 
363
}
 
364
 
 
365
 
 
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;
 
370
        return result;
 
371
}
 
372
 
 
373
 
 
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) {
 
378
                result = FALSE;
 
379
                return result;
 
380
        }
 
381
        result = json_node_get_value_type (self->priv->node) == G_TYPE_STRING;
 
382
        return result;
 
383
}
 
384
 
 
385
 
 
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) {
 
390
                result = FALSE;
 
391
                return result;
 
392
        }
 
393
        result = json_node_get_value_type (self->priv->node) == G_TYPE_INT64;
 
394
        return result;
 
395
}
 
396
 
 
397
 
 
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) {
 
402
                result = FALSE;
 
403
                return result;
 
404
        }
 
405
        result = json_node_get_value_type (self->priv->node) == G_TYPE_DOUBLE;
 
406
        return result;
 
407
}
 
408
 
 
409
 
 
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) {
 
414
                result = FALSE;
 
415
                return result;
 
416
        }
 
417
        result = json_node_get_value_type (self->priv->node) == G_TYPE_BOOLEAN;
 
418
        return result;
 
419
}
 
420
 
 
421
 
 
422
char* json_soup_get_string (JsonSoup* self) {
 
423
        char* result = NULL;
 
424
        g_return_val_if_fail (self != NULL, NULL);
 
425
        result = g_strdup (json_node_get_string (self->priv->node));
 
426
        return result;
 
427
}
 
428
 
 
429
 
 
430
gint64 json_soup_get_int (JsonSoup* self) {
 
431
        gint64 result = 0LL;
 
432
        g_return_val_if_fail (self != NULL, 0LL);
 
433
        result = json_node_get_int (self->priv->node);
 
434
        return result;
 
435
}
 
436
 
 
437
 
 
438
double json_soup_get_double (JsonSoup* self) {
 
439
        double result = 0.0;
 
440
        g_return_val_if_fail (self != NULL, 0.0);
 
441
        result = json_node_get_double (self->priv->node);
 
442
        return result;
 
443
}
 
444
 
 
445
 
 
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);
 
450
        return result;
 
451
}
 
452
 
 
453
 
 
454
gint json_soup_length (JsonSoup* self) {
 
455
        gint result = 0;
 
456
        JsonArray* array;
 
457
        g_return_val_if_fail (self != NULL, 0);
 
458
        if (json_soup_is_array (self) == FALSE) {
 
459
                result = 0;
 
460
                return result;
 
461
        }
 
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);
 
465
        return result;
 
466
}
 
467
 
 
468
 
 
469
JsonSoup* json_soup_construct (GType object_type) {
 
470
        JsonSoup * self;
 
471
        self = (JsonSoup*) g_object_new (object_type, NULL);
 
472
        return self;
 
473
}
 
474
 
 
475
 
 
476
JsonSoup* json_soup_new (void) {
 
477
        return json_soup_construct (TYPE_JSON_SOUP);
 
478
}
 
479
 
 
480
 
 
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;
 
485
}
 
486
 
 
487
 
 
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;
 
492
}
 
493
 
 
494
 
 
495
static void json_soup_finalize (GObject* obj) {
 
496
        JsonSoup * self;
 
497
        self = JSON_SOUP (obj);
 
498
        {
 
499
                JsonParser* _tmp0_;
 
500
                self->priv->node = NULL;
 
501
                self->priv->parser = (_tmp0_ = NULL, _g_object_unref0 (self->priv->parser), _tmp0_);
 
502
        }
 
503
        _g_object_unref0 (self->priv->parser);
 
504
        G_OBJECT_CLASS (json_soup_parent_class)->finalize (obj);
 
505
}
 
506
 
 
507
 
 
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);
 
515
        }
 
516
        return json_soup_type_id__volatile;
 
517
}
 
518
 
 
519
 
 
520
 
 
521