Logo Search packages:      
Sourcecode: betaradio version File versions  Download package

json_soup.c

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

/* -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- */
/* vim:set fileencodings=utf-8 tabstop=4 expandtab shiftwidth=4 softtabstop=4: */

#include <glib.h>
#include <glib-object.h>
#include <json-glib/json-glib.h>
#include <stdlib.h>
#include <string.h>
#include <libsoup/soup.h>
#include <float.h>
#include <math.h>


#define TYPE_JSON_SOUP (json_soup_get_type ())
#define JSON_SOUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_JSON_SOUP, JsonSoup))
#define JSON_SOUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_JSON_SOUP, JsonSoupClass))
#define IS_JSON_SOUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_JSON_SOUP))
#define IS_JSON_SOUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_JSON_SOUP))
#define JSON_SOUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_JSON_SOUP, JsonSoupClass))

typedef struct _JsonSoup JsonSoup;
typedef struct _JsonSoupClass JsonSoupClass;
typedef struct _JsonSoupPrivate JsonSoupPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _soup_uri_free0(var) ((var == NULL) ? NULL : (var = (soup_uri_free (var), NULL)))
#define _json_object_unref0(var) ((var == NULL) ? NULL : (var = (json_object_unref (var), NULL)))
#define _json_array_unref0(var) ((var == NULL) ? NULL : (var = (json_array_unref (var), NULL)))

00033 struct _JsonSoup {
      GObject parent_instance;
      JsonSoupPrivate * priv;
};

00038 struct _JsonSoupClass {
      GObjectClass parent_class;
};

00042 struct _JsonSoupPrivate {
      JsonParser* parser;
      JsonNode* node;
};


static gpointer json_soup_parent_class = NULL;

GType json_soup_get_type (void);
#define JSON_SOUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_JSON_SOUP, JsonSoupPrivate))
enum  {
      JSON_SOUP_DUMMY_PROPERTY
};
JsonSoup* json_soup_new_buffer (const char* buffer);
JsonSoup* json_soup_construct_buffer (GType object_type, const char* buffer);
JsonSoup* json_soup_new_file (const char* file);
JsonSoup* json_soup_construct_file (GType object_type, const char* file);
JsonSoup* json_soup_new_http (const char* url);
JsonSoup* json_soup_construct_http (GType object_type, const char* url);
JsonSoup* json_soup_object (JsonSoup* self, const char* name);
JsonSoup* json_soup_parent (JsonSoup* self);
JsonSoup* json_soup_sibling (JsonSoup* self, const char* name);
JsonSoup* json_soup_array (JsonSoup* self, gint idx);
JsonSoup* json_soup_grandparent (JsonSoup* self);
JsonSoup* json_soup_reset (JsonSoup* self);
static gboolean json_soup_is_value (JsonSoup* self);
gboolean json_soup_is_object (JsonSoup* self);
gboolean json_soup_is_array (JsonSoup* self);
gboolean json_soup_is_string (JsonSoup* self);
gboolean json_soup_is_int (JsonSoup* self);
gboolean json_soup_is_double (JsonSoup* self);
gboolean json_soup_is_bool (JsonSoup* self);
char* json_soup_get_string (JsonSoup* self);
gint64 json_soup_get_int (JsonSoup* self);
double json_soup_get_double (JsonSoup* self);
gboolean json_soup_get_bool (JsonSoup* self);
gint json_soup_length (JsonSoup* self);
JsonSoup* json_soup_new (void);
JsonSoup* json_soup_construct (GType object_type);
static void json_soup_finalize (GObject* obj);



JsonSoup* json_soup_construct_buffer (GType object_type, const char* buffer) {
      GError * _inner_error_;
      JsonSoup * self;
      JsonParser* _tmp0_;
      g_return_val_if_fail (buffer != NULL, NULL);
      _inner_error_ = NULL;
      self = (JsonSoup*) g_object_new (object_type, NULL);
      self->priv->parser = (_tmp0_ = json_parser_new (), _g_object_unref0 (self->priv->parser), _tmp0_);
      {
            json_parser_load_from_data (self->priv->parser, buffer, -1, &_inner_error_);
            if (_inner_error_ != NULL) {
                  goto __catch1_g_error;
            }
            self->priv->node = json_parser_get_root (self->priv->parser);
      }
      goto __finally1;
      __catch1_g_error:
      {
            GError * e;
            e = _inner_error_;
            _inner_error_ = NULL;
            {
                  g_warning ("json_soup.vala:34: %s", e->message);
                  _g_error_free0 (e);
            }
      }
      __finally1:
      if (_inner_error_ != NULL) {
            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);
            g_clear_error (&_inner_error_);
            return NULL;
      }
      return self;
}


JsonSoup* json_soup_new_buffer (const char* buffer) {
      return json_soup_construct_buffer (TYPE_JSON_SOUP, buffer);
}


JsonSoup* json_soup_construct_file (GType object_type, const char* file) {
      GError * _inner_error_;
      JsonSoup * self;
      JsonParser* _tmp0_;
      g_return_val_if_fail (file != NULL, NULL);
      _inner_error_ = NULL;
      self = (JsonSoup*) g_object_new (object_type, NULL);
      self->priv->parser = (_tmp0_ = json_parser_new (), _g_object_unref0 (self->priv->parser), _tmp0_);
      {
            json_parser_load_from_file (self->priv->parser, file, &_inner_error_);
            if (_inner_error_ != NULL) {
                  goto __catch2_g_error;
            }
            self->priv->node = json_parser_get_root (self->priv->parser);
      }
      goto __finally2;
      __catch2_g_error:
      {
            GError * e;
            e = _inner_error_;
            _inner_error_ = NULL;
            {
                  g_warning ("json_soup.vala:43: %s", e->message);
                  _g_error_free0 (e);
            }
      }
      __finally2:
      if (_inner_error_ != NULL) {
            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);
            g_clear_error (&_inner_error_);
            return NULL;
      }
      return self;
}


JsonSoup* json_soup_new_file (const char* file) {
      return json_soup_construct_file (TYPE_JSON_SOUP, file);
}


JsonSoup* json_soup_construct_http (GType object_type, const char* url) {
      GError * _inner_error_;
      JsonSoup * self;
      SoupSessionAsync* session;
      SoupURI* _tmp0_;
      SoupMessage* _tmp1_;
      SoupMessage* message;
      JsonParser* _tmp2_;
      g_return_val_if_fail (url != NULL, NULL);
      _inner_error_ = NULL;
      self = (JsonSoup*) g_object_new (object_type, NULL);
      session = (SoupSessionAsync*) soup_session_async_new ();
      message = (_tmp1_ = soup_message_new_from_uri ("GET", _tmp0_ = soup_uri_new (url)), _soup_uri_free0 (_tmp0_), _tmp1_);
      if (soup_session_send_message ((SoupSession*) session, message) != 200) {
            g_warning ("json_soup.vala:50: Can not connect to %s", url);
      }
      self->priv->parser = (_tmp2_ = json_parser_new (), _g_object_unref0 (self->priv->parser), _tmp2_);
      {
            json_parser_load_from_data (self->priv->parser, (const char*) message->response_body->data, -1, &_inner_error_);
            if (_inner_error_ != NULL) {
                  goto __catch3_g_error;
            }
            self->priv->node = json_parser_get_root (self->priv->parser);
      }
      goto __finally3;
      __catch3_g_error:
      {
            GError * e;
            e = _inner_error_;
            _inner_error_ = NULL;
            {
                  g_warning ("json_soup.vala:57: %s", e->message);
                  _g_error_free0 (e);
            }
      }
      __finally3:
      if (_inner_error_ != NULL) {
            _g_object_unref0 (session);
            _g_object_unref0 (message);
            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);
            g_clear_error (&_inner_error_);
            return NULL;
      }
      _g_object_unref0 (session);
      _g_object_unref0 (message);
      return self;
}


JsonSoup* json_soup_new_http (const char* url) {
      return json_soup_construct_http (TYPE_JSON_SOUP, url);
}


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


static gpointer _json_object_ref0 (gpointer self) {
      return self ? json_object_ref (self) : NULL;
}


JsonSoup* json_soup_object (JsonSoup* self, const char* name) {
      JsonSoup* result = NULL;
      JsonObject* object;
      g_return_val_if_fail (self != NULL, NULL);
      g_return_val_if_fail (name != NULL, NULL);
      if (json_node_get_node_type (self->priv->node) != JSON_NODE_OBJECT) {
            g_warning ("json_soup.vala:70: This is not a object.");
            result = _g_object_ref0 (self);
            return result;
      }
      object = _json_object_ref0 (json_node_get_object (self->priv->node));
      if (json_object_has_member (object, name) == FALSE) {
            g_warning ("json_soup.vala:75: There is no such member as %s.", name);
            result = _g_object_ref0 (self);
            _json_object_unref0 (object);
            return result;
      }
      self->priv->node = json_object_get_member (object, name);
      result = _g_object_ref0 (self);
      _json_object_unref0 (object);
      return result;
}


JsonSoup* json_soup_sibling (JsonSoup* self, const char* name) {
      JsonSoup* result = NULL;
      JsonSoup* _tmp0_;
      JsonSoup* _tmp1_;
      g_return_val_if_fail (self != NULL, NULL);
      g_return_val_if_fail (name != NULL, NULL);
      _tmp0_ = json_soup_parent (self);
      _g_object_unref0 (_tmp0_);
      _tmp1_ = json_soup_object (self, name);
      _g_object_unref0 (_tmp1_);
      result = _g_object_ref0 (self);
      return result;
}


static gpointer _json_array_ref0 (gpointer self) {
      return self ? json_array_ref (self) : NULL;
}


JsonSoup* json_soup_array (JsonSoup* self, gint idx) {
      JsonSoup* result = NULL;
      JsonArray* array;
      gint length;
      gboolean _tmp0_ = FALSE;
      g_return_val_if_fail (self != NULL, NULL);
      if (json_node_get_node_type (self->priv->node) != JSON_NODE_ARRAY) {
            g_warning ("json_soup.vala:88: This is not a array.");
            result = _g_object_ref0 (self);
            return result;
      }
      array = _json_array_ref0 (json_node_get_array (self->priv->node));
      length = (gint) json_array_get_length (array);
      if (idx > length) {
            _tmp0_ = TRUE;
      } else {
            _tmp0_ = idx < 0;
      }
      if (_tmp0_) {
            g_warning ("json_soup.vala:94: Out of index. %d", idx);
            result = _g_object_ref0 (self);
            _json_array_unref0 (array);
            return result;
      }
      self->priv->node = json_array_get_element (array, (guint) idx);
      result = _g_object_ref0 (self);
      _json_array_unref0 (array);
      return result;
}


JsonSoup* json_soup_parent (JsonSoup* self) {
      JsonSoup* result = NULL;
      JsonNode* parent_node;
      g_return_val_if_fail (self != NULL, NULL);
      parent_node = json_node_get_parent (self->priv->node);
      if (parent_node == NULL) {
            g_warning ("json_soup.vala:103: Already be root.");
            result = _g_object_ref0 (self);
            return result;
      }
      self->priv->node = parent_node;
      result = _g_object_ref0 (self);
      return result;
}


JsonSoup* json_soup_grandparent (JsonSoup* self) {
      JsonSoup* result = NULL;
      JsonSoup* _tmp0_;
      JsonSoup* _tmp1_;
      g_return_val_if_fail (self != NULL, NULL);
      _tmp0_ = json_soup_parent (self);
      _g_object_unref0 (_tmp0_);
      _tmp1_ = json_soup_parent (self);
      _g_object_unref0 (_tmp1_);
      result = _g_object_ref0 (self);
      return result;
}


JsonSoup* json_soup_reset (JsonSoup* self) {
      JsonSoup* result = NULL;
      g_return_val_if_fail (self != NULL, NULL);
      self->priv->node = json_parser_get_root (self->priv->parser);
      result = _g_object_ref0 (self);
      return result;
}


static gboolean json_soup_is_value (JsonSoup* self) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      if (json_node_get_node_type (self->priv->node) == JSON_NODE_VALUE) {
            result = TRUE;
            return result;
      } else {
            result = FALSE;
            return result;
      }
}


gboolean json_soup_is_object (JsonSoup* self) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      result = json_node_get_node_type (self->priv->node) == JSON_NODE_OBJECT;
      return result;
}


gboolean json_soup_is_array (JsonSoup* self) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      result = json_node_get_node_type (self->priv->node) == JSON_NODE_ARRAY;
      return result;
}


gboolean json_soup_is_string (JsonSoup* self) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      if (json_soup_is_value (self) == FALSE) {
            result = FALSE;
            return result;
      }
      result = json_node_get_value_type (self->priv->node) == G_TYPE_STRING;
      return result;
}


gboolean json_soup_is_int (JsonSoup* self) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      if (json_soup_is_value (self) == FALSE) {
            result = FALSE;
            return result;
      }
      result = json_node_get_value_type (self->priv->node) == G_TYPE_INT64;
      return result;
}


gboolean json_soup_is_double (JsonSoup* self) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      if (json_soup_is_value (self) == FALSE) {
            result = FALSE;
            return result;
      }
      result = json_node_get_value_type (self->priv->node) == G_TYPE_DOUBLE;
      return result;
}


gboolean json_soup_is_bool (JsonSoup* self) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      if (json_soup_is_value (self) == FALSE) {
            result = FALSE;
            return result;
      }
      result = json_node_get_value_type (self->priv->node) == G_TYPE_BOOLEAN;
      return result;
}


char* json_soup_get_string (JsonSoup* self) {
      char* result = NULL;
      g_return_val_if_fail (self != NULL, NULL);
      result = g_strdup (json_node_get_string (self->priv->node));
      return result;
}


gint64 json_soup_get_int (JsonSoup* self) {
      gint64 result = 0LL;
      g_return_val_if_fail (self != NULL, 0LL);
      result = json_node_get_int (self->priv->node);
      return result;
}


double json_soup_get_double (JsonSoup* self) {
      double result = 0.0;
      g_return_val_if_fail (self != NULL, 0.0);
      result = json_node_get_double (self->priv->node);
      return result;
}


gboolean json_soup_get_bool (JsonSoup* self) {
      gboolean result = FALSE;
      g_return_val_if_fail (self != NULL, FALSE);
      result = json_node_get_boolean (self->priv->node);
      return result;
}


gint json_soup_length (JsonSoup* self) {
      gint result = 0;
      JsonArray* array;
      g_return_val_if_fail (self != NULL, 0);
      if (json_soup_is_array (self) == FALSE) {
            result = 0;
            return result;
      }
      array = _json_array_ref0 (json_node_get_array (self->priv->node));
      result = (gint) json_array_get_length (array);
      _json_array_unref0 (array);
      return result;
}


JsonSoup* json_soup_construct (GType object_type) {
      JsonSoup * self;
      self = (JsonSoup*) g_object_new (object_type, NULL);
      return self;
}


JsonSoup* json_soup_new (void) {
      return json_soup_construct (TYPE_JSON_SOUP);
}


static void json_soup_class_init (JsonSoupClass * klass) {
      json_soup_parent_class = g_type_class_peek_parent (klass);
      g_type_class_add_private (klass, sizeof (JsonSoupPrivate));
      G_OBJECT_CLASS (klass)->finalize = json_soup_finalize;
}


static void json_soup_instance_init (JsonSoup * self) {
      self->priv = JSON_SOUP_GET_PRIVATE (self);
      self->priv->parser = NULL;
      self->priv->node = NULL;
}


static void json_soup_finalize (GObject* obj) {
      JsonSoup * self;
      self = JSON_SOUP (obj);
      {
            JsonParser* _tmp0_;
            self->priv->node = NULL;
            self->priv->parser = (_tmp0_ = NULL, _g_object_unref0 (self->priv->parser), _tmp0_);
      }
      _g_object_unref0 (self->priv->parser);
      G_OBJECT_CLASS (json_soup_parent_class)->finalize (obj);
}


GType json_soup_get_type (void) {
      static volatile gsize json_soup_type_id__volatile = 0;
      if (g_once_init_enter (&json_soup_type_id__volatile)) {
            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 };
            GType json_soup_type_id;
            json_soup_type_id = g_type_register_static (G_TYPE_OBJECT, "JsonSoup", &g_define_type_info, 0);
            g_once_init_leave (&json_soup_type_id__volatile, json_soup_type_id);
      }
      return json_soup_type_id__volatile;
}





Generated by  Doxygen 1.6.0   Back to index