Example #1
0
File: json.c Project: GNOME/gegl
static GType
json_op_register_type_for_file (GTypeModule *type_module, const gchar *filepath)
{
    GType ret = 0;
    GError *error = NULL;
    JsonParser *parser = json_parser_new();
    const gboolean success = json_parser_load_from_file(parser, filepath, &error);

    if (success) {
        JsonNode *root_node = json_node_copy (json_parser_get_root (parser));
        JsonObject *root = json_node_get_object (root_node);
        const gchar *name;
        gchar *type_name;

        g_assert(root_node);

        name = metadata_get_property(root, "name");
        type_name = (name) ? component2gtypename(name) : component2gtypename(filepath);
        ret = json_op_register_type(type_module, type_name, root);
        g_free(type_name);
    }

//    g_object_unref(parser);
    return ret;
}
Example #2
0
/*!
 * Convert a JSON file into a tree of nodes.
 *
 * \param[out] node Tree representation of \p filename.
 * \param filename Absolute path to JSON file to parse.
 *
 * \return \c true on success, else \c false.
 */
bool
clr_oci_json_parse (GNode** node, const gchar* filename) {
	bool result = false;
	GError* error = NULL;
	JsonParser* parser = NULL;
	JsonNode *root = NULL;

	if ((!node) || (!filename) || (!(*filename))) {
		return false;
	}

	parser = json_parser_new();
	if (! json_parser_load_from_file(parser, filename, &error)) {
		g_debug("unable to parse '%s'", filename);
		if (error) {
			g_debug("Error parsing '%s': %s", filename, error->message);
			g_error_free(error);
		}
		goto exit;
	}

	root = json_parser_get_root (parser);
	if (! root) {
		goto exit;
	}

	*node = g_node_new(g_strdup(filename));
	clr_oci_json_parse_aux(root, *node, false);

	result = true;

exit:
	g_object_unref(parser);
	return result;
}
Example #3
0
gsweb_t json_parse_gsweb() {
    JsonParser *parser;
    JsonNode *root;
    JsonReader *reader;
    GError *error;
    int array_size = 0;
    const char * tmp;
    gsweb_t ret;
    memset(&ret, 0, sizeof(ret));

    g_type_init();

    parser = json_parser_new();
    error = NULL;
    json_parser_load_from_file(parser, GTMPFILE, &error);
    if (error)
    {
        g_error_free(error);
        g_object_unref(parser);
        ret.success = 2;
        return ret;
    }
    root = json_parser_get_root(parser);
    reader = json_reader_new(root);

    json_reader_read_member (reader, "responseData");
    json_reader_read_member (reader, "results");
    array_size = json_reader_count_elements(reader);
    if (array_size > 0) {
        json_reader_read_element (reader, 0);

        json_reader_read_member (reader, "unescapedUrl");
        tmp = json_reader_get_string_value (reader);
        strncpy(ret.url, tmp, (strlen(tmp) < BUFF_SIZE)?strlen(tmp):BUFF_SIZE);
        json_reader_end_member (reader);

        json_reader_read_member (reader, "titleNoFormatting");
        tmp = json_reader_get_string_value (reader);
        strncpy(ret.title, tmp, (strlen(tmp) < BUFF_SIZE)?strlen(tmp):BUFF_SIZE);
        json_reader_end_member (reader);

        json_reader_read_member (reader, "content");
        tmp = json_reader_get_string_value (reader);
        strncpy(ret.content, tmp, (strlen(tmp) < BUFF_SIZE)?strlen(tmp):BUFF_SIZE);
        json_reader_end_member (reader);

        json_reader_end_element (reader);
        ret.success = 0;
    }
    else
        ret.success = 1;
    json_reader_end_member (reader);
    json_reader_end_member (reader);

    g_object_unref(parser);
    g_object_unref(reader);
    return ret;
}
GssAdaptive *
gss_adaptive_load (GssServer * server, const char *key, const char *dir,
    const char *version, GssDrmType drm_type, GssAdaptiveStream stream_type)
{
  GssAdaptive *adaptive;
  char *filename;
  gboolean ret;
  GError *error = NULL;
  JsonParser *parser;

  g_return_val_if_fail (GSS_IS_SERVER (server), NULL);
  g_return_val_if_fail (key != NULL, NULL);
  g_return_val_if_fail (dir != NULL, NULL);

  GST_DEBUG ("looking for %s", key);

  parser = json_parser_new ();
  filename = g_strdup_printf ("%s/gss-manifest", dir);
  ret = json_parser_load_from_file (parser, filename, &error);
  if (!ret) {
    GST_DEBUG ("failed to open %s", filename);
    g_free (filename);
    g_object_unref (parser);
    g_error_free (error);
    return NULL;
  }
  g_free (filename);

  GST_DEBUG ("loading %s", key);

  adaptive = gss_adaptive_new ();

  adaptive->server = server;

  adaptive->content_id = g_strdup (key);
  adaptive->kid = create_key_id (key);
  adaptive->kid_len = 16;
  adaptive->drm_type = drm_type;
  adaptive->stream_type = stream_type;

  gss_playready_generate_key (server->playready, adaptive->content_key,
      adaptive->kid, adaptive->kid_len);

  ret = parse_json (adaptive, parser, dir, version);
  if (!ret) {
    gss_adaptive_free (adaptive);
    g_object_unref (parser);
    GST_WARNING ("json format error in %s/gss-manifest", dir);
    return NULL;
  }

  g_object_unref (parser);

  GST_DEBUG ("loading done");

  return adaptive;
}
void trg_prefs_load(TrgPrefs * p)
{
    TrgPrefsPrivate *priv = p->priv;
    JsonParser *parser = json_parser_new();
    JsonNode *root;
    guint n_profiles;
    JsonArray *profiles;

    gboolean parsed = json_parser_load_from_file(parser, priv->file, NULL);

    if (!parsed) {
        trg_prefs_empty_init(p);
        g_object_unref(parser);
        return;
    }

    root = json_parser_get_root(parser);
    if (root) {
        priv->user = json_node_copy(root);
        priv->userObj = json_node_get_object(priv->user);
    }

    g_object_unref(parser);

    if (!root) {
        trg_prefs_empty_init(p);
        return;
    }

    if (!json_object_has_member(priv->userObj, TRG_PREFS_KEY_PROFILES)) {
        profiles = json_array_new();
        json_object_set_array_member(priv->userObj, TRG_PREFS_KEY_PROFILES,
                                     profiles);
    } else {
        profiles = json_object_get_array_member(priv->userObj,
                                                TRG_PREFS_KEY_PROFILES);
    }

    n_profiles = json_array_get_length(profiles);

    if (n_profiles < 1) {
        priv->profile = trg_prefs_new_profile_object();
        json_array_add_object_element(profiles, priv->profile);
        trg_prefs_set_int(p, TRG_PREFS_KEY_PROFILE_ID, 0,
                          TRG_PREFS_GLOBAL);
    } else {
        gint profile_id = trg_prefs_get_int(p, TRG_PREFS_KEY_PROFILE_ID,
                                            TRG_PREFS_GLOBAL);
        if (profile_id >= n_profiles)
            trg_prefs_set_int(p, TRG_PREFS_KEY_PROFILE_ID, profile_id = 0,
                              TRG_PREFS_GLOBAL);

        priv->profile =
            json_array_get_object_element(profiles, profile_id);
    }
}
/* This function is synchronous! Blocking once at startup seems pretty
 * reasonable and allows us to avoid any complexity re. races
 */
static void
mex_queue_model_load (MexQueueModel *model)
{
  JsonParser *parser;
  gchar *filename;
  GError *error = NULL;
  JsonNode *root;
  JsonArray *array;
  gint i = 0;

  filename = _queue_file_name ();

  if (!g_file_test (filename, G_FILE_TEST_EXISTS))
    {
      g_free (filename);

      return;
    }

  parser = json_parser_new ();
  if (!json_parser_load_from_file (parser, filename, &error))
    {
      g_warning (G_STRLOC ": error populating from file: %s",
                 error->message);
      g_clear_error (&error);
      goto out;
    }

  root = json_parser_get_root (parser);

  if (!JSON_NODE_HOLDS_ARRAY (root))
    {
      g_warning (G_STRLOC ": JSON data not of expected format!");

      goto out;
    }

  array = json_node_get_array (root);

  for (i = 0; i < json_array_get_length (array); i++)
    {
      MexContent *content;
      JsonNode *node;

      node = json_array_get_element (array, i);
      content = (MexContent *)json_gobject_deserialize (MEX_TYPE_PROGRAM,
                                                        node);

      mex_model_add_content (MEX_MODEL (model), content);
    }

out:
  g_free (filename);
  g_object_unref (parser);
}
Example #7
0
void
gml_gtk_widget_set_file (GmlGtkWidget *gml, gchar *f)
{
    JsonParser *parser = NULL;
    JsonNode *node = NULL;
    JsonObject *obj = NULL;
    JsonArray *arr = NULL;
    GError *error = NULL;
    GList *l = NULL;
    GList *p = NULL;

    parser = json_parser_new ();
    json_parser_load_from_file (parser, f, &error);
    if (error) {
        g_print ("Unable to parse `%s': %s\n", f, error->message);
        g_error_free (error);
        g_object_unref (parser);
        return;
    }

    node = json_parser_get_root (parser);
    obj = json_node_get_object (node);
    l = json_object_get_members (obj);

    for (p = l; p; p = p->next) {
        if (!strcmp (p->data, "width")) {
            gml->width = json_object_get_int_member (obj, p->data);
        } else if (!strcmp (p->data, "height")) {
            gml->height = json_object_get_int_member (obj, p->data);
        } else if (!strcmp (p->data, "color")) {
            clutter_color_from_string (&(gml->stage_color),
                    json_object_get_string_member (obj, p->data));
        } else if (!strcmp (p->data, "elements")) {
            GList *al = NULL;
            GList *ap = NULL;
            JsonObject *arro = NULL;
            // parsing elements
            arr = json_object_get_array_member (obj, p->data);
            al = json_array_get_elements (arr);
            for (ap = al; ap; ap = ap->next) {
                arro = json_node_get_object (ap->data);
                gml_gtk_widget_create_element (gml->stage, arro);
            }

        }
    }

    g_list_free (l);
    g_object_unref (parser);

    gtk_widget_set_size_request (gml->clutter_widget, gml->width, gml->height);
    clutter_stage_set_color (CLUTTER_STAGE (gml->stage), &(gml->stage_color));
}
Example #8
0
int inputParser(char *path, JsonParser *parser) {
    GError *error;
    error = NULL;
    json_parser_load_from_file(parser, path, &error); 

    if(error) {
        g_error_free (error);
        return EXIT_FAILURE;
    }

    
    return EXIT_SUCCESS;
}
static void
move_local_favourites_cb(GtkInfoBar* bar,
                         gint res,
                         gpointer udata)
{
    GtFavouritesManager* self = GT_FAVOURITES_MANAGER(udata);
    gchar* fp = FAV_CHANNELS_FILE;
    gchar* new_fp = g_strconcat(fp, ".bak", NULL);

    if (res == GTK_RESPONSE_YES)
    {
        JsonParser* parse = json_parser_new();
        JsonNode* root;
        JsonArray* jarr;
        gchar* fp = FAV_CHANNELS_FILE;
        GError* err = NULL;

        gt_channel_free_list(self->favourite_channels);
        self->favourite_channels = NULL;
        g_signal_emit(self, sigs[SIG_FINISHED_LOADING_FAVOURITES], 0); //TODO: Add a LOADING_FAVOURITES signal

        json_parser_load_from_file(parse, fp, &err);

        if (err)
        {
            g_warning("{GtFavouritesManager} Error move local favourite channels to twitch '%s'", err->message);
            return;
        }

        root = json_parser_get_root(parse);
        jarr = json_node_get_array(root);

        for (GList* l = json_array_get_elements(jarr); l != NULL; l = l->next)
        {
            GtChannel* chan = GT_CHANNEL(json_gobject_deserialize(GT_TYPE_CHANNEL, l->data));
            //TODO: Error handling
            gt_twitch_follow_channel_async(main_app->twitch, gt_channel_get_name(chan), NULL, NULL);
            g_object_unref(chan);
        }

        g_object_unref(parse);
        g_free(fp);

        gt_favourites_manager_load_from_twitch(self);
    }

    g_rename(fp, new_fp);

    g_free(fp);
    g_free(new_fp);
}
Example #10
0
static gboolean
gs_plugin_odrs_load_ratings (GsPlugin *plugin, const gchar *fn, GError **error)
{
	GsPluginData *priv = gs_plugin_get_data (plugin);
	GList *l;
	JsonNode *json_root;
	JsonObject *json_item;
	g_autoptr(GList) apps = NULL;
	g_autoptr(JsonParser) json_parser = NULL;

	/* remove all existing */
	g_hash_table_remove_all (priv->ratings);

	/* parse the data and find the success */
	json_parser = json_parser_new ();
	if (!json_parser_load_from_file (json_parser, fn, error)) {
		gs_utils_error_convert_json_glib (error);
		return FALSE;
	}
	json_root = json_parser_get_root (json_parser);
	if (json_root == NULL) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_INVALID_FORMAT,
				     "no ratings root");
		return FALSE;
	}
	if (json_node_get_node_type (json_root) != JSON_NODE_OBJECT) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_INVALID_FORMAT,
				     "no ratings array");
		return FALSE;
	}

	/* parse each app */
	json_item = json_node_get_object (json_root);
	apps = json_object_get_members (json_item);
	for (l = apps; l != NULL; l = l->next) {
		const gchar *app_id = (const gchar *) l->data;
		JsonObject *json_app = json_object_get_object_member (json_item, app_id);
		g_autoptr(GArray) ratings = NULL;;
		ratings = gs_plugin_odrs_load_ratings_for_app (json_app);
		if (ratings->len == 6) {
			g_hash_table_insert (priv->ratings,
					     g_strdup (app_id),
					     g_array_ref (ratings));
		}
	}
	return TRUE;
}
Example #11
0
static gboolean
emojione_parse_json_file (const gchar *filename,
                          GHashTable  *dict)
{
    JsonParser *parser = json_parser_new ();
    JsonNode *node;
    JsonObject *object;
    GList *members, *m;
    GError *error = NULL;
    EmojiData data = { 0, };

    g_return_val_if_fail (filename != NULL, FALSE);
    g_return_val_if_fail (dict != NULL, FALSE);

    if (!json_parser_load_from_file (parser, filename, &error)) {
        g_error ("%s", error->message);
        g_error_free (error);
        goto fail_to_json_file;
    }

    node = json_parser_get_root (parser);
    if (json_node_get_node_type (node) != JSON_NODE_OBJECT) {
        g_warning ("Json file does not have Json object %s", filename);
        goto fail_to_json_file;
    }

    object = json_node_get_object (node);
    members = json_object_get_members (object);
    data.dict = dict;

    m = members;
    while (m) {
       const gchar *member = (const gchar *) m->data;
       if (!parse_emojione_element (json_object_get_member (object, member),
                                    &data)) {
           g_warning ("Failed to parse member '%s' in %s", member, filename);
       }
       m = m->next;
    }

    g_list_free (members);
    reset_emoji_element (&data);
    g_object_unref (parser);

    return TRUE;

fail_to_json_file:
    g_object_unref (parser);
    return FALSE;
}
Example #12
0
Settings::Settings(std::string path){
  filePath = path;
  GError* error;
  parser = json_parser_new();
  error = nullptr;
  json_parser_load_from_file(parser, path.c_str(), &error);
  if (error)
  {
          g_error_free(error);
          g_object_unref(parser);
          std::cout<<"settings error"<<std::endl;
  }
  root = json_parser_get_root(parser);
  reader = json_reader_new(root);
}
Example #13
0
int rm_json_cache_read(RmTrie *file_trie, const char *json_path) {
#if !HAVE_JSON_GLIB
    (void)file_trie;
    (void)json_path;

    rm_log_info_line(_("caching is not supported due to missing json-glib library."));
    return EXIT_FAILURE;
#else
    rm_assert_gentle(file_trie);
    rm_assert_gentle(json_path);

    int result = EXIT_FAILURE;
    GError *error = NULL;
    size_t keys_in_table = rm_trie_size(file_trie);
    JsonParser *parser = json_parser_new();

    rm_log_info_line(_("Loading json-cache `%s'"), json_path);

    if(!json_parser_load_from_file(parser, json_path, &error)) {
        rm_log_warning_line(_("FAILED: %s\n"), error->message);
        g_error_free(error);
        goto failure;
    }

    JsonNode *root = json_parser_get_root(parser);
    if(JSON_NODE_TYPE(root) != JSON_NODE_ARRAY) {
        rm_log_warning_line(_("No valid json cache (no array in /)"));
        goto failure;
    }

    /* Iterate over all objects in it */
    json_array_foreach_element(json_node_get_array(root),
                               (JsonArrayForeach)rm_json_cache_parse_entry,
                               file_trie);

    /* check if some entries were added */
    result = (keys_in_table >= rm_trie_size(file_trie));

failure:
    if(parser) {
        g_object_unref(parser);
    }
    return result;
#endif
}
void
gt_favourites_manager_load_from_file(GtFavouritesManager* self)
{
    GtFavouritesManagerPrivate* priv = gt_favourites_manager_get_instance_private(self);
    JsonParser* parse = json_parser_new();
    JsonNode* root;
    JsonArray* jarr;
    gchar* fp = FAV_CHANNELS_FILE;
    GError* err = NULL;

    if (!g_file_test(fp, G_FILE_TEST_EXISTS))
        goto finish;

    json_parser_load_from_file(parse, fp, &err);

    if (err)
    {
        g_warning("{GtFavouritesManager} Error loading favourite channels '%s'", err->message);
        goto finish;
    }

    root = json_parser_get_root(parse);
    jarr = json_node_get_array(root);

    for (GList* l = json_array_get_elements(jarr); l != NULL; l = l->next)
    {
        GtChannel* chan = GT_CHANNEL(json_gobject_deserialize(GT_TYPE_CHANNEL, l->data));
        self->favourite_channels = g_list_append(self->favourite_channels, chan);
        g_signal_handlers_block_by_func(chan, channel_favourited_cb, self);
        g_object_set(chan,
                     "auto-update", TRUE,
                     "favourited", TRUE,
                     NULL);
        gt_channel_update(chan);
        g_signal_handlers_unblock_by_func(chan, channel_favourited_cb, self);

        g_signal_connect(chan, "notify::updating", G_CALLBACK(oneshot_updating_cb), self);
    }

finish:

    g_object_unref(parse);
    g_free(fp);
}
Example #15
0
static gboolean
read_config_file(AppContext *app, GError **err)
{
  JsonNode *root;
  JsonParser *parser;
  parser = json_parser_new ();
  if (!json_parser_load_from_file (parser, app->config_filename, err)) {
    g_object_unref(parser);
    return FALSE;
  }
  root = json_parser_get_root(parser);
  if (JSON_NODE_HOLDS_OBJECT(root)) {
    JsonNode *value_node;
    JsonObject *root_obj = json_node_get_object(root);
    value_node = json_object_get_member(root_obj, "extensionPort");
    if (value_node && JSON_NODE_HOLDS_VALUE(value_node)) {
      app->http_port = json_node_get_int(value_node);
    }
    value_node = json_object_get_member(root_obj, "httpRootPath");
    if (value_node && JSON_NODE_HOLDS_VALUE(value_node)) {
      GFile *base;
      GFile *http_root;
      GFile *config;
      char *path = json_node_dup_string(value_node);
      config = g_file_new_for_path(app->config_filename);
      base = g_file_get_parent(config);
      g_object_unref(config);
      g_free(app->http_root);
      http_root = g_file_resolve_relative_path (base, path);
      g_free(path);
      g_object_unref(base);
      if (http_root) {
	app->http_root = g_file_get_path(http_root);
	g_debug("HTTP root: %s", app->http_root);
	g_object_unref(http_root);
      }
    }
  }
  g_object_unref(parser);
  return TRUE;
}
Example #16
0
JsonParser *dt_noiseprofile_init(const char *alternative)
{
  GError *error = NULL;
  char filename[PATH_MAX] = { 0 };

  if(alternative == NULL)
  {
    // TODO: shall we look for profiles in the user config dir?
    char datadir[PATH_MAX] = { 0 };
    dt_loc_get_datadir(datadir, sizeof(datadir));
    snprintf(filename, sizeof(filename), "%s/%s", datadir, "noiseprofiles.json");
  }
  else
    snprintf(filename, sizeof(filename), "%s", alternative);

  dt_print(DT_DEBUG_CONTROL, "[noiseprofile] loading noiseprofiles from `%s'\n", filename);
  if(!g_file_test(filename, G_FILE_TEST_EXISTS)) return NULL;

  // TODO: shall we cache the content? for now this looks fast enough(TM)
  JsonParser *parser = json_parser_new();
  if(!json_parser_load_from_file(parser, filename, &error))
  {
    fprintf(stderr, "[noiseprofile] error: parsing json from `%s' failed\n%s\n", filename, error->message);
    g_error_free(error);
    g_object_unref(parser);
    return NULL;
  }

  // run over the file once to verify that it is sane
  if(!dt_noiseprofile_verify(parser))
  {
    dt_control_log(_("noiseprofile file `%s' is not valid"), filename);
    fprintf(stderr, "[noiseprofile] error: `%s' is not a valid noiseprofile file. run with -d control for details\n", filename);
    g_object_unref(parser);
    return NULL;
  }

  return parser;
}
Example #17
0
void
glide_window_open_document (GlideWindow *window,
			    const gchar *filename)
{
  JsonParser *p = json_parser_new ();
  GError *e = NULL;
  JsonNode *root, *slide_n;
  JsonArray *slide_array;
  JsonObject *root_obj;

  json_parser_load_from_file (p, filename, &e);
  if (e)
    {
      gchar *sec = g_strdup_printf ("Failed to load the document: %s", filename);
      g_warning("Error loading file: %s", e->message);

      glide_gtk_util_show_error_dialog ("Failed to load document", sec);
					
      g_error_free (e);
      g_free (sec);
      g_object_unref (G_OBJECT (p));
      
      return;
    }
  root = json_parser_get_root (p);
  root_obj = json_node_get_object (root);

  glide_window_set_document (window, glide_document_new (glide_json_object_get_string (root_obj, "name")));
  glide_document_set_path (window->priv->document, filename);

  
  slide_n = json_object_get_member (root_obj, "slides");
  slide_array = json_node_get_array (slide_n);
  
  glide_stage_manager_load_slides (window->priv->manager, slide_array);
  
  g_object_unref (p);
}
Example #18
0
/**
 * glide_document_load_archive:
 * @document: A #GlideDocument
 * @filename: Path to a Glide archive file to open.
 *
 * Opens a Glide archive file, and returns a #JsonParser for
 * the contained document.
 *
 * Return value: A newly created #JsonParser for @filename.
 */
JsonParser *
glide_document_load_archive (GlideDocument *document,
			     const gchar *filename)
{
  JsonParser *p;
  GError *e = NULL;
  gchar *json_file;
  
  g_return_val_if_fail (GLIDE_IS_DOCUMENT (document), NULL);
  
  p = json_parser_new ();

  glide_document_make_working_dir (document);
  glide_document_extract_archive (document, filename);
  
  json_file = g_strdup_printf("%s/document.json",document->priv->working_path);

  json_parser_load_from_file (p, json_file, &e);
  if (e)
    {
      gchar *sec = g_strdup_printf ("Failed to load the document: %s", filename);
      g_warning("Error loading file: %s", e->message);

      glide_gtk_util_show_error_dialog ("Failed to load document", sec);
					
      g_error_free (e);
      g_object_unref (G_OBJECT (p));
      g_free (json_file);
      g_free (sec);
      
      return NULL;
    }
  g_free (json_file);
  
  glide_document_set_path (document, filename);
  
  return p;
}
Example #19
0
void
render_json (const char *filename)
{
  JsonParser *parser;
  JsonNode *root;
  GError *error;
  parser = json_parser_new ();

  error = NULL;
  json_parser_load_from_file (parser, filename, &error);
  if (error) {
    g_print ("Parsing error `%s':\n %s\n", filename, error->message);
    g_error_free (error);
    g_object_unref (parser);
    exit (0);
  }

  root = json_parser_get_root (parser);

  JsonReader *reader = json_reader_new (root);
  GESTimeline *timeline;

  json_reader_read_member (reader, "composition");

  // comp strings
  const char *name = getString (reader, "name");
  //const char *src_dir = getString (reader, "src-dir");
  //g_print ("Source Directory: %s\nName: %s\n", src_dir, name);

  // comp ints
  int width = getInt (reader, "width");
  int height = getInt (reader, "height");
  int fps = getInt (reader, "fps");

  gboolean transparency = TRUE;

  if (is_in_members (reader, "transparency")) {
    transparency = getBool (reader, "transparency");
  }

  gboolean absolute_paths = FALSE;

  if (is_in_members (reader, "absolute_paths")) {
    absolute_paths = getBool (reader, "absolute_paths");
  }

  g_print ("Resolution: %dx%d, FPS: %d\n", width, height, fps);

  timeline = ges_timeline_new_audio_video ();

  int i;
  json_reader_read_member (reader, "layers");

  for (i = 0; i < json_reader_count_elements (reader); i++) {
    json_reader_read_element (reader, i);

    GESLayer *layer = ges_layer_new ();

    g_object_set (layer, "priority", i, NULL);

    if (is_in_members (reader, "autotransition")) {
      gboolean autotransition = getBool (reader, "autotransition");
      if (autotransition)
        g_print ("Auto Transitions on.\n");
      g_object_set (layer, "auto-transition", autotransition, NULL);
    }

    ges_timeline_add_layer (timeline, layer);

    getClips (reader, layer, GES_TRACK_TYPE_UNKNOWN, absolute_paths);

    json_reader_end_element (reader);
  }
  json_reader_end_member (reader);

  ges_timeline_commit (timeline);

  const gchar *xges_path = g_strconcat ("file://", filename, ".xges", NULL);

  ges_timeline_save_xges (timeline, xges_path);

  //free(xges_path);

  // formats
  GESRendererProfile res =
      { width, height, fps, PROFILE_AAC_H264_QUICKTIME, NULL };
  if (!transparency) {
    g_print ("Deactivating transparency\n");
    res.format = "I420";
  }

  json_reader_read_member (reader, "formats");
  for (i = 0; i < json_reader_count_elements (reader); i++) {
    json_reader_read_element (reader, i);
    const char *format = json_reader_get_string_value (reader);
    json_reader_end_element (reader);
    g_print ("format: %s\n", format);
    EncodingProfile prof = PROFILE_AAC_H264_QUICKTIME;
    if (strcmp (format, "webm") == 0) {
      prof = PROFILE_VORBIS_VP8_WEBM;
    } else if (strcmp (format, "mkv") == 0) {
      prof = PROFILE_VORBIS_H264_MATROSKA;
    } else if (strcmp (format, "mp4") == 0) {
      prof = PROFILE_AAC_H264_QUICKTIME;
    } else if (strcmp (format, "ogg") == 0) {
      prof = PROFILE_VORBIS_THEORA_OGG;
    }
    res.profile = prof;
    ges_renderer_render (timeline, name, &res, absolute_paths);
  }
  json_reader_end_member (reader);

  json_reader_end_member (reader);

  g_object_unref (reader);
  g_object_unref (parser);
}
int
rpmostree_compose_builtin_tree (int             argc,
                                char          **argv,
                                GCancellable   *cancellable,
                                GError        **error)
{
  int exit_status = EXIT_FAILURE;
  GError *temp_error = NULL;
  GOptionContext *context = g_option_context_new ("TREEFILE - Run yum and commit the result to an OSTree repository");
  RpmOstreeTreeComposeContext selfdata = { NULL, };
  RpmOstreeTreeComposeContext *self = &selfdata;
  JsonNode *treefile_rootval = NULL;
  JsonObject *treefile = NULL;
  g_autofree char *cachekey = NULL;
  g_autofree char *new_inputhash = NULL;
  g_autoptr(GFile) previous_root = NULL;
  g_autofree char *previous_checksum = NULL;
  g_autoptr(GFile) yumroot = NULL;
  g_autoptr(GFile) yumroot_varcache = NULL;
  glnx_fd_close int rootfs_fd = -1;
  glnx_unref_object OstreeRepo *repo = NULL;
  g_autoptr(GPtrArray) bootstrap_packages = NULL;
  g_autoptr(GPtrArray) packages = NULL;
  g_autoptr(GFile) treefile_path = NULL;
  g_autoptr(GFile) treefile_dirpath = NULL;
  g_autoptr(GFile) repo_path = NULL;
  glnx_unref_object JsonParser *treefile_parser = NULL;
  gs_unref_variant_builder GVariantBuilder *metadata_builder = 
    g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
  g_autoptr(RpmOstreeContext) corectx = NULL;
  g_autoptr(GHashTable) varsubsts = NULL;
  gboolean workdir_is_tmp = FALSE;
  g_autofree char *next_version = NULL;

  self->treefile_context_dirs = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
  
  if (!rpmostree_option_context_parse (context,
                                       option_entries,
                                       &argc, &argv,
                                       RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
                                       cancellable,
                                       NULL,
                                       error))
    goto out;

  if (argc < 2)
    {
      rpmostree_usage_error (context, "TREEFILE must be specified", error);
      goto out;
    }
  
  if (!opt_repo)
    {
      rpmostree_usage_error (context, "--repo must be specified", error);
      goto out;
    }

  if (getuid () != 0)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "compose tree must presently be run as uid 0 (root)");
      goto out;
    }

  /* Test whether or not bwrap is going to work - we will fail inside e.g. a Docker
   * container without --privileged or userns exposed.
   */
  if (!rpmostree_bwrap_selftest (error))
    goto out;

  repo_path = g_file_new_for_path (opt_repo);
  repo = self->repo = ostree_repo_new (repo_path);
  if (!ostree_repo_open (repo, cancellable, error))
    goto out;

  treefile_path = g_file_new_for_path (argv[1]);

  if (opt_workdir)
    {
      self->workdir = g_file_new_for_path (opt_workdir);
    }
  else
    {
      g_autofree char *tmpd = NULL;

      if (!rpmostree_mkdtemp ("/var/tmp/rpm-ostree.XXXXXX", &tmpd, NULL, error))
        goto out;

      self->workdir = g_file_new_for_path (tmpd);
      workdir_is_tmp = TRUE;

      if (opt_workdir_tmpfs)
        {
          if (mount ("tmpfs", tmpd, "tmpfs", 0, (const void*)"mode=755") != 0)
            {
              _rpmostree_set_prefix_error_from_errno (error, errno,
                                                      "mount(tmpfs): ");
              goto out;
            }
        }
    }

  if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (self->workdir),
                       FALSE, &self->workdir_dfd, error))
    goto out;

  if (opt_cachedir)
    {
      if (!glnx_opendirat (AT_FDCWD, opt_cachedir, TRUE, &self->cachedir_dfd, error))
        {
          g_prefix_error (error, "Opening cachedir '%s': ", opt_cachedir);
          goto out;
        }
    }
  else
    {
      self->cachedir_dfd = fcntl (self->workdir_dfd, F_DUPFD_CLOEXEC, 3);
      if (self->cachedir_dfd < 0)
        {
          glnx_set_error_from_errno (error);
          goto out;
        }
    }

  if (opt_metadata_strings)
    {
      if (!parse_keyvalue_strings (opt_metadata_strings,
                                   metadata_builder, error))
        goto out;
    }

  if (fchdir (self->workdir_dfd) != 0)
    {
      glnx_set_error_from_errno (error);
      goto out;
    }

  corectx = rpmostree_context_new_compose (self->cachedir_dfd, cancellable, error);
  if (!corectx)
    goto out;

  varsubsts = rpmostree_context_get_varsubsts (corectx);

  treefile_parser = json_parser_new ();
  if (!json_parser_load_from_file (treefile_parser,
                                   gs_file_get_path_cached (treefile_path),
                                   error))
    goto out;

  treefile_rootval = json_parser_get_root (treefile_parser);
  if (!JSON_NODE_HOLDS_OBJECT (treefile_rootval))
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Treefile root is not an object");
      goto out;
    }
  treefile = json_node_get_object (treefile_rootval);

  if (!process_includes (self, treefile_path, 0, treefile,
                         cancellable, error))
    goto out;

  if (opt_print_only)
    {
      glnx_unref_object JsonGenerator *generator = json_generator_new ();
      g_autoptr(GOutputStream) stdout = g_unix_output_stream_new (1, FALSE);

      json_generator_set_pretty (generator, TRUE);
      json_generator_set_root (generator, treefile_rootval);
      (void) json_generator_to_stream (generator, stdout, NULL, NULL);

      exit_status = EXIT_SUCCESS;
      goto out;
    }

  { const char *input_ref = _rpmostree_jsonutil_object_require_string_member (treefile, "ref", error);
    if (!input_ref)
      goto out;
    self->ref = _rpmostree_varsubst_string (input_ref, varsubsts, error);
    if (!self->ref)
      goto out;
  }

  if (!ostree_repo_read_commit (repo, self->ref, &previous_root, &previous_checksum,
                                cancellable, &temp_error))
    {
      if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
        { 
          g_clear_error (&temp_error);
          g_print ("No previous commit for %s\n", self->ref);
        }
      else
        {
          g_propagate_error (error, temp_error);
          goto out;
        }
    }
  else
    g_print ("Previous commit: %s\n", previous_checksum);

  self->previous_checksum = previous_checksum;

  yumroot = g_file_get_child (self->workdir, "rootfs.tmp");
  if (!glnx_shutil_rm_rf_at (self->workdir_dfd, "rootfs.tmp", cancellable, error))
    goto out;

  if (json_object_has_member (treefile, "automatic_version_prefix") &&
      !compose_strv_contains_prefix (opt_metadata_strings, "version="))
    {
      g_autoptr(GVariant) variant = NULL;
      g_autofree char *last_version = NULL;
      const char *ver_prefix;

      ver_prefix = _rpmostree_jsonutil_object_require_string_member (treefile,
                                                                     "automatic_version_prefix",
                                                                     error);
      if (!ver_prefix)
          goto out;

      if (previous_checksum)
        {
          if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
                                         previous_checksum, &variant, error))
            goto out;

          last_version = checksum_version (variant);
        }

      next_version = _rpmostree_util_next_version (ver_prefix, last_version);
      g_variant_builder_add (metadata_builder, "{sv}", "version",
                             g_variant_new_string (next_version));
    }

  bootstrap_packages = g_ptr_array_new ();
  packages = g_ptr_array_new ();

  if (json_object_has_member (treefile, "bootstrap_packages"))
    {
      if (!_rpmostree_jsonutil_append_string_array_to (treefile, "bootstrap_packages", packages, error))
        goto out;
    }
  if (!_rpmostree_jsonutil_append_string_array_to (treefile, "packages", packages, error))
    goto out;

  { g_autofree char *thisarch_packages = g_strconcat ("packages-", dnf_context_get_base_arch (rpmostree_context_get_hif (corectx)), NULL);

    if (json_object_has_member (treefile, thisarch_packages))
      {
        if (!_rpmostree_jsonutil_append_string_array_to (treefile, thisarch_packages, packages, error))
          goto out;
      }
  }
  g_ptr_array_add (packages, NULL);

  { glnx_unref_object JsonGenerator *generator = json_generator_new ();
    char *treefile_buf = NULL;
    gsize len;

    json_generator_set_root (generator, treefile_rootval);
    json_generator_set_pretty (generator, TRUE);
    treefile_buf = json_generator_to_data (generator, &len);

    self->serialized_treefile = g_bytes_new_take (treefile_buf, len);
  }

  treefile_dirpath = g_file_get_parent (treefile_path);
  if (TRUE)
    {
      gboolean generate_from_previous = TRUE;

      if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treefile,
                                                                   "preserve-passwd",
                                                                   &generate_from_previous,
                                                                   error))
        goto out;

      if (generate_from_previous)
        {
          if (!rpmostree_generate_passwd_from_previous (repo, yumroot,
                                                        treefile_dirpath,
                                                        previous_root, treefile,
                                                        cancellable, error))
            goto out;
        }
    }

  { gboolean unmodified = FALSE;

    if (!install_packages_in_root (self, corectx, treefile, yumroot,
                                   (char**)packages->pdata,
                                   opt_force_nocache ? NULL : &unmodified,
                                   &new_inputhash,
                                   cancellable, error))
      goto out;

    if (unmodified)
      {
        g_print ("No apparent changes since previous commit; use --force-nocache to override\n");
        exit_status = EXIT_SUCCESS;
        goto out;
      }
    else if (opt_dry_run)
      {
        g_print ("--dry-run complete, exiting\n");
        exit_status = EXIT_SUCCESS;
        goto out;
      }
  }

  if (g_strcmp0 (g_getenv ("RPM_OSTREE_BREAK"), "post-yum") == 0)
    goto out;

  if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (yumroot), TRUE,
                       &rootfs_fd, error))
    goto out;

  if (!rpmostree_treefile_postprocessing (rootfs_fd, self->treefile_context_dirs->pdata[0],
                                          self->serialized_treefile, treefile,
                                          next_version, cancellable, error))
    goto out;

  if (!rpmostree_prepare_rootfs_for_commit (yumroot, treefile, cancellable, error))
    goto out;

  /* Reopen since the prepare renamed */
  (void) close (rootfs_fd);
  if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (yumroot), TRUE,
                       &rootfs_fd, error))
    goto out;

  if (!rpmostree_copy_additional_files (yumroot, self->treefile_context_dirs->pdata[0], treefile, cancellable, error))
    goto out;

  if (!rpmostree_check_passwd (repo, yumroot, treefile_dirpath, treefile,
                               previous_checksum,
                               cancellable, error))
    goto out;

  if (!rpmostree_check_groups (repo, yumroot, treefile_dirpath, treefile,
                               previous_checksum,
                               cancellable, error))
    goto out;

  {
    const char *gpgkey;
    gboolean selinux = TRUE;
    g_autoptr(GVariant) metadata = NULL;

    g_variant_builder_add (metadata_builder, "{sv}",
                           "rpmostree.inputhash",
                           g_variant_new_string (new_inputhash));

    metadata = g_variant_ref_sink (g_variant_builder_end (metadata_builder));

    if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile, "gpg_key", &gpgkey, error))
      goto out;

    if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treefile,
                                                                 "selinux",
                                                                 &selinux,
                                                                 error))
      goto out;

    { g_autofree char *new_revision = NULL;

      if (!rpmostree_commit (rootfs_fd, repo, self->ref, metadata, gpgkey, selinux, NULL,
                             &new_revision,
                             cancellable, error))
        goto out;

      g_print ("%s => %s\n", self->ref, new_revision);

    }
  }

  if (opt_touch_if_changed)
    {
      gs_fd_close int fd = open (opt_touch_if_changed, O_CREAT|O_WRONLY|O_NOCTTY, 0644);
      if (fd == -1)
        {
          gs_set_error_from_errno (error, errno);
          g_prefix_error (error, "Updating '%s': ", opt_touch_if_changed);
          goto out;
        }
      if (futimens (fd, NULL) == -1)
        {
          gs_set_error_from_errno (error, errno);
          goto out;
        }
    }

  exit_status = EXIT_SUCCESS;

 out:
  /* Explicitly close this one now as it may have references to files
   * we delete below.
   */
  g_clear_object (&corectx);
  
  /* Move back out of the workding directory to ensure unmount works */
  (void )chdir ("/");

  if (self->workdir_dfd != -1)
    (void) close (self->workdir_dfd);

  if (workdir_is_tmp)
    {
      if (opt_workdir_tmpfs)
        if (umount (gs_file_get_path_cached (self->workdir)) != 0)
          {
            fprintf (stderr, "warning: umount failed: %m\n");
          }
      (void) gs_shutil_rm_rf (self->workdir, NULL, NULL);
    }
  if (self)
    {
      g_clear_object (&self->workdir);
      g_clear_pointer (&self->serialized_treefile, g_bytes_unref);
      g_ptr_array_unref (self->treefile_context_dirs);
    }

  return exit_status;
}
Example #21
0
// FIXME: check for memory leaks
JSONcontext* Network::readJSON(const char* file){
   JsonParser *parser;
   JsonObject *obj;
   JsonArray *jnodes;
   JsonArray *jedges;
   int i,k;
   JSONcontext* ctx=new JSONcontext();
   GError *error;
   g_type_init ();
   parser = json_parser_new ();
   
   error = NULL;
   json_parser_load_from_file (parser, file, &error);
   if (error)
   {
      g_print ("Unable to parse `%s': %s\n", file, error->message);
      g_error_free (error);
      g_object_unref (parser);
      abort();
   }
   addCompartment(0,"unknown"); // add dummy compartment, may be overwritten by compartment from json
   ctx->root = json_node_copy(json_parser_get_root(parser)); // needs to be copied ??
   obj=json_node_get_object (ctx->root);
   jnodes=json_object_get_array_member(obj,"nodes");
   jedges=json_object_get_array_member(obj,"edges");
   g_print ("%i nodes\n",json_array_get_length(jnodes));
   for (i=0;i<json_array_get_length(jnodes);i++){
      JsonObject *n=json_array_get_object_element(jnodes,i);
      JsonObject *data=json_object_get_object_member(n,"data");
      const char* type=json_object_get_string_member(n,"type");
      const char* id=json_object_get_string_member(n,"id");
      if (json_object_has_member(n,"is_abstract") && (json_object_get_boolean_member(n,"is_abstract") || json_object_get_int_member(n,"is_abstract"))){
         continue;
      }
      if (!json_object_has_member(n,"index")){
         g_print ("no index defined for %s %s\n",type,id);
         abort();
      }
      int idx=json_object_get_int_member(n,"index");
      g_print ("node %d %s id %s\n",idx,type,id);
      if(strcmp(type,"Compartment")==0){
         addCompartment(idx,id);
      } else {
         double x=json_object_get_double_member(data,"x");
         double y=json_object_get_double_member(data,"y");
         double w=json_object_get_double_member(data,"width");
         double h=json_object_get_double_member(data,"height");
         double d=json_object_get_double_member(data,"dir");
         int c=json_object_get_int_member(data,"compartmentidx");
         for(k=0;k<7;k++){
            if(strcmp(jnodetypes[k],type)==0)break;
         }
         if (k==7){
            g_print ("unknown node type %s\n",type);
            abort();
         }
         addNode(idx,inodetypes[k],id,w,h,x,y,d,c);
         if (idx>=ctx->nodeidx->size()) ctx->nodeidx->resize(idx+1);
         (*(ctx->nodeidx))[idx]=i;
      }
   }
   g_print ("%i edges\n",json_array_get_length(jedges));
   for (i=0;i<json_array_get_length(jedges);i++){
      JsonObject *e=json_array_get_object_element(jedges,i);
      const char* type=json_object_get_string_member(e,"type");
      if ((!json_object_has_member(e,"sourceidx")) || (!json_object_has_member(e,"targetidx"))){
         g_print ("no source/targetindex defined for edge %s %i",type,i);
         abort;
      }
      for(k=0;k<7;k++){
         if(strcmp(edgetypes[k],type)==0)break;
      }
      int from=json_object_get_int_member(e,"sourceidx");
      int to=json_object_get_int_member(e,"targetidx");
      addEdge(from,to,(Edgetype)k);
      g_print ("edge %s %i -> %i\n",edgetypes[k],from,to);
   }
   g_object_unref(parser);
   return ctx;
}
Example #22
0
static void skk_map_file_load (SkkMapFile* self, const gchar* rule, const gchar* type, const gchar* name, GeeSet* included, GError** error) {
	const gchar* _tmp0_;
	SkkRuleMetadata* _tmp1_ = NULL;
	SkkRuleMetadata* metadata;
	SkkRuleMetadata* _tmp2_;
	SkkRuleMetadata* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_ = NULL;
	gchar* _tmp12_;
	gchar* filename;
	const gchar* _tmp13_;
	gboolean _tmp14_ = FALSE;
	JsonParser* _tmp17_;
	JsonParser* parser;
	JsonParser* _tmp30_;
	JsonNode* _tmp31_ = NULL;
	JsonNode* _tmp32_;
	JsonNode* root;
	JsonNode* _tmp33_;
	JsonNodeType _tmp34_ = 0;
	JsonNode* _tmp36_;
	JsonObject* _tmp37_ = NULL;
	JsonObject* _tmp38_;
	JsonObject* object;
	JsonNode* member = NULL;
	JsonObject* _tmp39_;
	gboolean _tmp40_ = FALSE;
	JsonObject* _tmp83_;
	gboolean _tmp84_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (rule != NULL);
	g_return_if_fail (type != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (included != NULL);
	_tmp0_ = rule;
	_tmp1_ = skk_rule_find_rule (_tmp0_);
	metadata = _tmp1_;
	_tmp2_ = metadata;
	if (_tmp2_ == NULL) {
		const gchar* _tmp3_;
		GError* _tmp4_;
		_tmp3_ = rule;
		_tmp4_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "can't find rule %s", _tmp3_);
		_inner_error_ = _tmp4_;
		if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error_);
			_skk_rule_metadata_free0 (metadata);
			return;
		} else {
			_skk_rule_metadata_free0 (metadata);
			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;
		}
	}
	_tmp5_ = metadata;
	_tmp6_ = (*_tmp5_).base_dir;
	_tmp7_ = type;
	_tmp8_ = name;
	_tmp9_ = g_strconcat (_tmp8_, ".json", NULL);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_build_filename (_tmp6_, _tmp7_, _tmp10_, NULL);
	_tmp12_ = _tmp11_;
	_g_free0 (_tmp10_);
	filename = _tmp12_;
	_tmp13_ = filename;
	_tmp14_ = g_file_test (_tmp13_, G_FILE_TEST_EXISTS);
	if (!_tmp14_) {
		const gchar* _tmp15_;
		GError* _tmp16_;
		_tmp15_ = filename;
		_tmp16_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "no such file %s", _tmp15_);
		_inner_error_ = _tmp16_;
		if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			return;
		} else {
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			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;
		}
	}
	_tmp17_ = json_parser_new ();
	parser = _tmp17_;
	{
		JsonParser* _tmp18_;
		const gchar* _tmp19_;
		gboolean _tmp20_ = FALSE;
		gboolean _tmp21_;
		_tmp18_ = parser;
		_tmp19_ = filename;
		_tmp20_ = json_parser_load_from_file (_tmp18_, _tmp19_, &_inner_error_);
		_tmp21_ = _tmp20_;
		if (_inner_error_ != NULL) {
			goto __catch28_g_error;
		}
		if (!_tmp21_) {
			GError* _tmp22_;
			_tmp22_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "");
			_inner_error_ = _tmp22_;
			goto __catch28_g_error;
		}
	}
	goto __finally28;
	__catch28_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp23_;
		GError* _tmp24_;
		const gchar* _tmp25_;
		gchar* _tmp26_ = NULL;
		gchar* _tmp27_;
		GError* _tmp28_;
		GError* _tmp29_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp23_ = filename;
		_tmp24_ = e;
		_tmp25_ = _tmp24_->message;
		_tmp26_ = g_strdup_printf ("can't load %s: %s", _tmp23_, _tmp25_);
		_tmp27_ = _tmp26_;
		_tmp28_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, _tmp27_);
		_tmp29_ = _tmp28_;
		_g_free0 (_tmp27_);
		_inner_error_ = _tmp29_;
		_g_error_free0 (e);
		goto __finally28;
	}
	__finally28:
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			return;
		} else {
			_g_object_unref0 (parser);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			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;
		}
	}
	_tmp30_ = parser;
	_tmp31_ = json_parser_get_root (_tmp30_);
	_tmp32_ = __vala_JsonNode_copy0 (_tmp31_);
	root = _tmp32_;
	_tmp33_ = root;
	_tmp34_ = json_node_get_node_type (_tmp33_);
	if (_tmp34_ != JSON_NODE_OBJECT) {
		GError* _tmp35_;
		_tmp35_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "root element must be an object");
		_inner_error_ = _tmp35_;
		if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error_);
			__vala_JsonNode_free0 (root);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			return;
		} else {
			__vala_JsonNode_free0 (root);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			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;
		}
	}
	_tmp36_ = root;
	_tmp37_ = json_node_get_object (_tmp36_);
	_tmp38_ = __vala_JsonObject_copy0 (_tmp37_);
	object = _tmp38_;
	_tmp39_ = object;
	_tmp40_ = json_object_has_member (_tmp39_, "include");
	if (_tmp40_) {
		JsonObject* _tmp41_;
		JsonNode* _tmp42_ = NULL;
		JsonNode* _tmp43_;
		JsonNode* _tmp44_;
		JsonNodeType _tmp45_ = 0;
		JsonNode* _tmp47_;
		JsonArray* _tmp48_ = NULL;
		JsonArray* _tmp49_;
		JsonArray* include;
		JsonArray* _tmp50_;
		GList* _tmp51_ = NULL;
		GList* elements;
		GList* _tmp52_;
		_tmp41_ = object;
		_tmp42_ = json_object_get_member (_tmp41_, "include");
		_tmp43_ = __vala_JsonNode_copy0 (_tmp42_);
		__vala_JsonNode_free0 (member);
		member = _tmp43_;
		_tmp44_ = member;
		_tmp45_ = json_node_get_node_type (_tmp44_);
		if (_tmp45_ != JSON_NODE_ARRAY) {
			GError* _tmp46_;
			_tmp46_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "\"include\" element must be an array");
			_inner_error_ = _tmp46_;
			if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
				g_propagate_error (error, _inner_error_);
				__vala_JsonNode_free0 (member);
				__vala_JsonObject_free0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				_skk_rule_metadata_free0 (metadata);
				return;
			} else {
				__vala_JsonNode_free0 (member);
				__vala_JsonObject_free0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				_skk_rule_metadata_free0 (metadata);
				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;
			}
		}
		_tmp47_ = member;
		_tmp48_ = json_node_get_array (_tmp47_);
		_tmp49_ = __vala_JsonArray_copy0 (_tmp48_);
		include = _tmp49_;
		_tmp50_ = include;
		_tmp51_ = json_array_get_elements (_tmp50_);
		elements = _tmp51_;
		_tmp52_ = elements;
		{
			GList* element_collection = NULL;
			GList* element_it = NULL;
			element_collection = _tmp52_;
			for (element_it = element_collection; element_it != NULL; element_it = element_it->next) {
				JsonNode* element = NULL;
				element = (JsonNode*) element_it->data;
				{
					JsonNode* _tmp53_;
					const gchar* _tmp54_ = NULL;
					gchar* _tmp55_;
					gchar* parent;
					GeeSet* _tmp56_;
					const gchar* _tmp57_;
					gboolean _tmp58_ = FALSE;
					const gchar* _tmp61_;
					gint _tmp62_ = 0;
					gint index;
					gint _tmp63_;
					GeeSet* _tmp81_;
					const gchar* _tmp82_;
					_tmp53_ = element;
					_tmp54_ = json_node_get_string (_tmp53_);
					_tmp55_ = g_strdup (_tmp54_);
					parent = _tmp55_;
					_tmp56_ = included;
					_tmp57_ = parent;
					_tmp58_ = gee_collection_contains ((GeeCollection*) _tmp56_, _tmp57_);
					if (_tmp58_) {
						const gchar* _tmp59_;
						GError* _tmp60_;
						_tmp59_ = parent;
						_tmp60_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "found circular include of %s", _tmp59_);
						_inner_error_ = _tmp60_;
						if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
							g_propagate_error (error, _inner_error_);
							_g_free0 (parent);
							_g_list_free0 (elements);
							__vala_JsonArray_free0 (include);
							__vala_JsonNode_free0 (member);
							__vala_JsonObject_free0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							_skk_rule_metadata_free0 (metadata);
							return;
						} else {
							_g_free0 (parent);
							_g_list_free0 (elements);
							__vala_JsonArray_free0 (include);
							__vala_JsonNode_free0 (member);
							__vala_JsonObject_free0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							_skk_rule_metadata_free0 (metadata);
							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;
						}
					}
					_tmp61_ = parent;
					_tmp62_ = string_index_of (_tmp61_, "/", 0);
					index = _tmp62_;
					_tmp63_ = index;
					if (_tmp63_ < 0) {
						const gchar* _tmp64_;
						const gchar* _tmp65_;
						const gchar* _tmp66_;
						GeeSet* _tmp67_;
						_tmp64_ = rule;
						_tmp65_ = type;
						_tmp66_ = parent;
						_tmp67_ = included;
						skk_map_file_load (self, _tmp64_, _tmp65_, _tmp66_, _tmp67_, &_inner_error_);
						if (_inner_error_ != NULL) {
							if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
								g_propagate_error (error, _inner_error_);
								_g_free0 (parent);
								_g_list_free0 (elements);
								__vala_JsonArray_free0 (include);
								__vala_JsonNode_free0 (member);
								__vala_JsonObject_free0 (object);
								__vala_JsonNode_free0 (root);
								_g_object_unref0 (parser);
								_g_free0 (filename);
								_skk_rule_metadata_free0 (metadata);
								return;
							} else {
								_g_free0 (parent);
								_g_list_free0 (elements);
								__vala_JsonArray_free0 (include);
								__vala_JsonNode_free0 (member);
								__vala_JsonObject_free0 (object);
								__vala_JsonNode_free0 (root);
								_g_object_unref0 (parser);
								_g_free0 (filename);
								_skk_rule_metadata_free0 (metadata);
								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;
							}
						}
					} else {
						const gchar* _tmp68_;
						gint _tmp69_;
						gchar* _tmp70_ = NULL;
						gchar* _tmp71_;
						const gchar* _tmp72_;
						const gchar* _tmp73_;
						gint _tmp74_;
						const gchar* _tmp75_;
						gint _tmp76_;
						gint _tmp77_;
						gchar* _tmp78_ = NULL;
						gchar* _tmp79_;
						GeeSet* _tmp80_;
						_tmp68_ = parent;
						_tmp69_ = index;
						_tmp70_ = string_slice (_tmp68_, (glong) 0, (glong) _tmp69_);
						_tmp71_ = _tmp70_;
						_tmp72_ = type;
						_tmp73_ = parent;
						_tmp74_ = index;
						_tmp75_ = parent;
						_tmp76_ = strlen (_tmp75_);
						_tmp77_ = _tmp76_;
						_tmp78_ = string_slice (_tmp73_, (glong) (_tmp74_ + 1), (glong) _tmp77_);
						_tmp79_ = _tmp78_;
						_tmp80_ = included;
						skk_map_file_load (self, _tmp71_, _tmp72_, _tmp79_, _tmp80_, &_inner_error_);
						_g_free0 (_tmp79_);
						_g_free0 (_tmp71_);
						if (_inner_error_ != NULL) {
							if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
								g_propagate_error (error, _inner_error_);
								_g_free0 (parent);
								_g_list_free0 (elements);
								__vala_JsonArray_free0 (include);
								__vala_JsonNode_free0 (member);
								__vala_JsonObject_free0 (object);
								__vala_JsonNode_free0 (root);
								_g_object_unref0 (parser);
								_g_free0 (filename);
								_skk_rule_metadata_free0 (metadata);
								return;
							} else {
								_g_free0 (parent);
								_g_list_free0 (elements);
								__vala_JsonArray_free0 (include);
								__vala_JsonNode_free0 (member);
								__vala_JsonObject_free0 (object);
								__vala_JsonNode_free0 (root);
								_g_object_unref0 (parser);
								_g_free0 (filename);
								_skk_rule_metadata_free0 (metadata);
								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;
							}
						}
					}
					_tmp81_ = included;
					_tmp82_ = parent;
					gee_collection_add ((GeeCollection*) _tmp81_, _tmp82_);
					_g_free0 (parent);
				}
			}
		}
		_g_list_free0 (elements);
		__vala_JsonArray_free0 (include);
	}
	_tmp83_ = object;
	_tmp84_ = json_object_has_member (_tmp83_, "define");
	if (_tmp84_) {
		JsonObject* _tmp85_;
		JsonNode* _tmp86_ = NULL;
		JsonNode* _tmp87_;
		JsonNode* _tmp88_;
		JsonNodeType _tmp89_ = 0;
		JsonNode* _tmp91_;
		JsonObject* _tmp92_ = NULL;
		JsonObject* _tmp93_;
		JsonObject* define;
		JsonObject* _tmp94_;
		GList* _tmp95_ = NULL;
		GList* keys;
		GList* _tmp96_;
		_tmp85_ = object;
		_tmp86_ = json_object_get_member (_tmp85_, "define");
		_tmp87_ = __vala_JsonNode_copy0 (_tmp86_);
		__vala_JsonNode_free0 (member);
		member = _tmp87_;
		_tmp88_ = member;
		_tmp89_ = json_node_get_node_type (_tmp88_);
		if (_tmp89_ != JSON_NODE_OBJECT) {
			GError* _tmp90_;
			_tmp90_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "\"define\" element must be an object");
			_inner_error_ = _tmp90_;
			if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
				g_propagate_error (error, _inner_error_);
				__vala_JsonNode_free0 (member);
				__vala_JsonObject_free0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				_skk_rule_metadata_free0 (metadata);
				return;
			} else {
				__vala_JsonNode_free0 (member);
				__vala_JsonObject_free0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				_skk_rule_metadata_free0 (metadata);
				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;
			}
		}
		_tmp91_ = member;
		_tmp92_ = json_node_get_object (_tmp91_);
		_tmp93_ = __vala_JsonObject_copy0 (_tmp92_);
		define = _tmp93_;
		_tmp94_ = define;
		_tmp95_ = json_object_get_members (_tmp94_);
		keys = _tmp95_;
		_tmp96_ = keys;
		{
			GList* key_collection = NULL;
			GList* key_it = NULL;
			key_collection = _tmp96_;
			for (key_it = key_collection; key_it != NULL; key_it = key_it->next) {
				const gchar* key = NULL;
				key = (const gchar*) key_it->data;
				{
					GeeMap* _tmp97_;
					const gchar* _tmp98_;
					gboolean _tmp99_ = FALSE;
					JsonObject* _tmp104_;
					const gchar* _tmp105_;
					JsonNode* _tmp106_ = NULL;
					JsonNode* _tmp107_;
					JsonNode* _tmp108_;
					JsonNodeType _tmp109_ = 0;
					GeeMap* _tmp111_;
					const gchar* _tmp112_;
					gpointer _tmp113_ = NULL;
					GeeMap* _tmp114_;
					JsonNode* _tmp115_;
					JsonObject* _tmp116_ = NULL;
					_tmp97_ = self->priv->maps;
					_tmp98_ = key;
					_tmp99_ = gee_map_has_key (_tmp97_, _tmp98_);
					if (!_tmp99_) {
						GeeHashMap* _tmp100_;
						GeeHashMap* map;
						GeeMap* _tmp101_;
						const gchar* _tmp102_;
						GeeHashMap* _tmp103_;
						_tmp100_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, json_node_get_type (), (GBoxedCopyFunc) _vala_JsonNode_copy, _vala_JsonNode_free, NULL, NULL, NULL);
						map = _tmp100_;
						_tmp101_ = self->priv->maps;
						_tmp102_ = key;
						_tmp103_ = map;
						gee_map_set (_tmp101_, _tmp102_, (GeeMap*) _tmp103_);
						_g_object_unref0 (map);
					}
					_tmp104_ = define;
					_tmp105_ = key;
					_tmp106_ = json_object_get_member (_tmp104_, _tmp105_);
					_tmp107_ = __vala_JsonNode_copy0 (_tmp106_);
					__vala_JsonNode_free0 (member);
					member = _tmp107_;
					_tmp108_ = member;
					_tmp109_ = json_node_get_node_type (_tmp108_);
					if (_tmp109_ != JSON_NODE_OBJECT) {
						GError* _tmp110_;
						_tmp110_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "map element must be an object");
						_inner_error_ = _tmp110_;
						if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
							g_propagate_error (error, _inner_error_);
							_g_list_free0 (keys);
							__vala_JsonObject_free0 (define);
							__vala_JsonNode_free0 (member);
							__vala_JsonObject_free0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							_skk_rule_metadata_free0 (metadata);
							return;
						} else {
							_g_list_free0 (keys);
							__vala_JsonObject_free0 (define);
							__vala_JsonNode_free0 (member);
							__vala_JsonObject_free0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							_skk_rule_metadata_free0 (metadata);
							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;
						}
					}
					_tmp111_ = self->priv->maps;
					_tmp112_ = key;
					_tmp113_ = gee_map_get (_tmp111_, _tmp112_);
					_tmp114_ = (GeeMap*) _tmp113_;
					_tmp115_ = member;
					_tmp116_ = json_node_get_object (_tmp115_);
					skk_map_file_load_map (self, _tmp114_, _tmp116_);
					_g_object_unref0 (_tmp114_);
				}
			}
		}
		_g_list_free0 (keys);
		__vala_JsonObject_free0 (define);
	}
	__vala_JsonNode_free0 (member);
	__vala_JsonObject_free0 (object);
	__vala_JsonNode_free0 (root);
	_g_object_unref0 (parser);
	_g_free0 (filename);
	_skk_rule_metadata_free0 (metadata);
}
Example #23
0
static void restore_state(session_callback_type type, gpointer data, gpointer user_data) {
    JsonParser* jp = NULL;
    JsonReader* jr = NULL;

    const gchar* sqs;
    saved_state* s = NULL;

    GError* err = NULL;

    /* Is it the callback we're interested in? */
    if (type != SPOP_SESSION_LOGGED_IN)
        return;

    /* First disable the callback so it's not called again */
    session_remove_callback(restore_state, NULL);

    g_debug("savestate: reading saved state...");
    s = g_new0(saved_state, 1);

    /* Read and parse state file */
    jp = json_parser_new();
    if (!json_parser_load_from_file(jp, g_state_file_path, &err)) {
        g_warning("savestate: error while reading state file: %s", err->message);
        goto restorestate_error;
    }

    jr = json_reader_new(json_parser_get_root(jp));

    /* Read basic state */
    if (!json_reader_read_member(jr, "status")) goto restorestate_jr_error;
    sqs = json_reader_get_string_value(jr);
    json_reader_end_member(jr);
    if      (strcmp(sqs, "stopped")) s->qs = STOPPED;
    else if (strcmp(sqs, "playing")) s->qs = PLAYING;
    else if (strcmp(sqs, "paused"))  s->qs = PAUSED;
    else {
        g_warning("savestate: bad value for queue status: %s", sqs);
        goto restorestate_error;
    }

    if (!json_reader_read_member(jr, "repeat")) goto restorestate_jr_error;
    s->repeat = json_reader_get_boolean_value(jr);
    json_reader_end_member(jr);

    if (!json_reader_read_member(jr, "shuffle")) goto restorestate_jr_error;
    s->shuffle = json_reader_get_boolean_value(jr);
    json_reader_end_member(jr);

    if (!json_reader_read_member(jr, "current_track")) goto restorestate_jr_error;
    s->cur_track = json_reader_get_int_value(jr);
    json_reader_end_member(jr);

    /* Now read tracks URIs */
    if (!json_reader_read_member(jr, "tracks")) goto restorestate_jr_error;
    if (!json_reader_is_array(jr)) {
        g_warning("savestate: error while parsing JSON: tracks is not an array");
        goto restorestate_error;
    }
    gint tracks = json_reader_count_elements(jr);
    if (s->cur_track >= tracks) {
        g_warning("savestate: incoherent state file: cur_track >= tracks");
        goto restorestate_error;
    }

    s->tracks = g_array_sized_new(FALSE, FALSE, sizeof(sp_track*), tracks);
    if (!s->tracks)
        g_error("Can't allocate array of %d tracks.", tracks);

    size_t i;
    gboolean can_restore_now = TRUE;
    for (i=0; i < tracks; i++) {
        json_reader_read_element(jr, i);
        const gchar* uri = json_reader_get_string_value(jr);
        json_reader_end_element(jr);

        sp_link* lnk = sp_link_create_from_string(uri);
        sp_linktype lt = sp_link_type(lnk);
        if (lt != SP_LINKTYPE_TRACK) {
            g_warning("savestate: invalid link type for track %zu: %d", i, lt);
            sp_link_release(lnk);
            goto restorestate_error;
        }
        sp_track* tr = sp_link_as_track(lnk);
        sp_track_add_ref(tr);
        sp_link_release(lnk);
        g_array_append_val(s->tracks, tr);
        if (!sp_track_is_loaded(tr))
            can_restore_now = FALSE;
    }

    /* If possible, restore now, else wait for all tracks to be loaded */
    if (can_restore_now)
        really_restore_state(s);
    else {
        g_timeout_add(100, (GSourceFunc) really_restore_state, s);
        g_debug("savestate: waiting for all tracks to be loaded before restoring saved state...");
    }

    /* Add a notification callback */
    if (!interface_notify_add_callback(savestate_notification_callback, NULL))
        g_error("Could not add savestate callback.");

    goto restorestate_clean;

 restorestate_jr_error:
    err = (GError*) json_reader_get_error(jr);
    g_warning("savestate: error while parsing JSON: %s", err->message);

 restorestate_error:
    if (s) {
        if (s->tracks)
            g_array_free(s->tracks, TRUE);
        g_free(s);
    }

 restorestate_clean:
    if (jp)
        g_object_unref(jp);
    if (jr)
        g_object_unref(jr);
}
Example #24
0
static void get_language_names(GList *languages)
{
#ifdef HAVE_ISO_CODES

  JsonReader *reader = NULL;
  JsonParser *parser = NULL;
  GError *error = NULL;

#if defined(_WIN32) && !defined(MSYS2_INSTALL) // TODO: add osx?
  char datadir[PATH_MAX] = { 0 };
  dt_loc_get_datadir(datadir, sizeof(datadir));
  char *filename = g_build_filename(datadir, "..",  "iso-codes", "json", "iso_639-2.json", NULL);
#else
  char *filename = g_build_filename(ISO_CODES_LOCATION, "iso_639-2.json", NULL);
#endif

  if(!g_file_test(filename, G_FILE_TEST_EXISTS))
  {
    fprintf(stderr, "[l10n] error: can't open iso-codes file `%s'\n"
                    "       there won't be nicely translated language names in the preferences.\n", filename);
    goto end;
  }

#if defined(_WIN32) && !defined(MSYS2_INSTALL) // TODO: add osx?
  // on windows we are shipping the translations of iso-codes along ours
  char *localedir = g_build_filename(datadir, "..", "locale", NULL);
  bindtextdomain("iso_639", localedir);
  g_free(localedir);
#else
  bindtextdomain("iso_639", ISO_CODES_LOCALEDIR);
#endif

  bind_textdomain_codeset("iso_639", "UTF-8");

  parser = json_parser_new();
  if(!json_parser_load_from_file(parser, filename, &error))
  {
    fprintf(stderr, "[l10n] error: parsing json from `%s' failed\n%s\n", filename, error->message);
    goto end;
  }

  // go over the json
  JsonNode *root = json_parser_get_root(parser);
  if(!root)
  {
    fprintf(stderr, "[l10n] error: can't get root node of `%s'\n", filename);
    goto end;
  }

  reader = json_reader_new(root);

  if(!json_reader_read_member(reader, "639-2"))
  {
    fprintf(stderr, "[l10n] error: unexpected layout of `%s'\n", filename);
    goto end;
  }

  if(!json_reader_is_array(reader))
  {
    fprintf(stderr, "[l10n] error: unexpected layout of `%s'\n", filename);
    goto end;
  }

  int n_elements = json_reader_count_elements(reader);
  for(int i = 0; i < n_elements; i++)
  {
    json_reader_read_element(reader, i);
    if(!json_reader_is_object(reader))
    {
      fprintf(stderr, "[l10n] error: unexpected layout of `%s' (element %d)\n", filename, i);
      goto end;
    }

    const char *alpha_2 = NULL, *alpha_3 = NULL, *name = NULL;
    if(json_reader_read_member(reader, "alpha_2"))
      alpha_2 = json_reader_get_string_value(reader);
    json_reader_end_member(reader); // alpha_2

    if(json_reader_read_member(reader, "alpha_3"))
      alpha_3 = json_reader_get_string_value(reader);
    json_reader_end_member(reader); // alpha_3

    if(json_reader_read_member(reader, "name"))
      name = json_reader_get_string_value(reader);
    json_reader_end_member(reader); // name

    if(name && (alpha_2 || alpha_3))
    {
      // check if alpha_2 or alpha_3 is in our translations
      for(GList *iter = languages; iter; iter = g_list_next(iter))
      {
        dt_l10n_language_t *language = (dt_l10n_language_t *)iter->data;
        if(!g_strcmp0(language->base_code, alpha_2) || !g_strcmp0(language->base_code, alpha_3))
        {
          // code taken in parts from GIMP's gimplanguagestore-parser.c
          g_setenv("LANGUAGE", language->code, TRUE);
          setlocale (LC_ALL, language->code);

          char *localized_name = g_strdup(dgettext("iso_639", name));

          /* If original and localized names are the same for other than English,
           * maybe localization failed. Try now in the main dialect. */
          if(g_strcmp0(name, localized_name) == 0 &&
             g_strcmp0(language->code, language->base_code) != 0)
          {
            g_free(localized_name);

            g_setenv("LANGUAGE", language->base_code, TRUE);
            setlocale (LC_ALL, language->base_code);

            localized_name = g_strdup(dgettext("iso_639", name));
          }

          /*  there might be several language names; use the first one  */
          char *semicolon = strchr(localized_name, ';');

          if(semicolon)
          {
            char *tmp = localized_name;
            localized_name = g_strndup(localized_name, semicolon - localized_name);
            g_free(tmp);
          }

          // we initialize the name to the language code to have something on systems lacking iso-codes, so free it!
          g_free(language->name);
          language->name = g_strdup_printf("%s (%s)%s", localized_name, language->code, language->is_default ? " *" : "");
          g_free(localized_name);

          // we can't break out of the loop here. at least pt is in our list twice!
        }
      }
    }
    else
      fprintf(stderr, "[l10n] error: element %d has no name, skipping\n", i);

    json_reader_end_element(reader);
  }

  json_reader_end_member(reader); // 639-2

end:
  // cleanup
  g_free(filename);
  if(error) g_error_free(error);
  if(reader) g_object_unref(reader);
  if(parser) g_object_unref(parser);

#endif // HAVE_ISO_CODES
}
static gboolean
process_includes (RpmOstreeTreeComposeContext  *self,
                  GFile             *treefile_path,
                  guint              depth,
                  JsonObject        *root,
                  GCancellable      *cancellable,
                  GError           **error)
{
  gboolean ret = FALSE;
  const char *include_path;
  const guint maxdepth = 50;

  if (depth > maxdepth)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Exceeded maximum include depth of %u", maxdepth);
      goto out;
    }

  {
    g_autoptr(GFile) parent = g_file_get_parent (treefile_path);
    gboolean existed = FALSE;
    if (self->treefile_context_dirs->len > 0)
      {
        GFile *prev = self->treefile_context_dirs->pdata[self->treefile_context_dirs->len-1];
        if (g_file_equal (parent, prev))
          existed = TRUE;
      }
    if (!existed)
      {
        g_ptr_array_add (self->treefile_context_dirs, parent);
        parent = NULL; /* Transfer ownership */
      }
  }

  if (!_rpmostree_jsonutil_object_get_optional_string_member (root, "include", &include_path, error))
    goto out;
                                          
  if (include_path)
    {
      g_autoptr(GFile) treefile_dirpath = g_file_get_parent (treefile_path);
      g_autoptr(GFile) parent_path = g_file_resolve_relative_path (treefile_dirpath, include_path);
      glnx_unref_object JsonParser *parent_parser = json_parser_new ();
      JsonNode *parent_rootval;
      JsonObject *parent_root;
      GList *members;
      GList *iter;

      if (!json_parser_load_from_file (parent_parser,
                                       gs_file_get_path_cached (parent_path),
                                       error))
        goto out;

      parent_rootval = json_parser_get_root (parent_parser);
      if (!JSON_NODE_HOLDS_OBJECT (parent_rootval))
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Treefile root is not an object");
          goto out;
        }
      parent_root = json_node_get_object (parent_rootval);
      
      if (!process_includes (self, parent_path, depth + 1, parent_root,
                             cancellable, error))
        goto out;
                             
      members = json_object_get_members (parent_root);
      for (iter = members; iter; iter = iter->next)
        {
          const char *name = iter->data;
          JsonNode *parent_val = json_object_get_member (parent_root, name);
          JsonNode *val = json_object_get_member (root, name);

          g_assert (parent_val);

          if (!val)
            json_object_set_member (root, name, json_node_copy (parent_val));
          else
            {
              JsonNodeType parent_type =
                json_node_get_node_type (parent_val);
              JsonNodeType child_type =
                json_node_get_node_type (val);
              if (parent_type != child_type)
                {
                  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                               "Conflicting element type of '%s'",
                               name);
                  goto out;
                }
              if (child_type == JSON_NODE_ARRAY)
                {
                  JsonArray *parent_array = json_node_get_array (parent_val);
                  JsonArray *child_array = json_node_get_array (val);
                  JsonArray *new_child = json_array_new ();
                  guint i, len;

                  len = json_array_get_length (parent_array);
                  for (i = 0; i < len; i++)
                    json_array_add_element (new_child, json_node_copy (json_array_get_element (parent_array, i)));
                  len = json_array_get_length (child_array);
                  for (i = 0; i < len; i++)
                    json_array_add_element (new_child, json_node_copy (json_array_get_element (child_array, i)));
                  
                  json_object_set_array_member (root, name, new_child);
                }
            }
        }

      json_object_remove_member (root, "include");
    }

  ret = TRUE;
 out:
  return ret;
}