Exemple #1
0
struct _JsonNode*
mu_msg_to_json (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti,
		MuMsgOptions opts)
{
	JsonNode	*node;
	JsonBuilder	*bob;

	time_t	t;
	size_t	s;

	g_return_val_if_fail (msg, NULL);
	g_return_val_if_fail (!((opts & MU_MSG_OPTION_HEADERS_ONLY) &&
				(opts & MU_MSG_OPTION_EXTRACT_IMAGES)),NULL);
	bob = json_builder_new ();
	bob = json_builder_begin_object (bob);

	if (ti)
		add_thread_info (bob, ti);

	add_string_member (bob, "subject", mu_msg_get_subject (msg));

	/* in the no-headers-only case (see below) we get a more complete list
	 * of contacts, so no need to get them here if that's the case */
	if (opts & MU_MSG_OPTION_HEADERS_ONLY)
		add_contacts (bob, msg);

	t = mu_msg_get_date (msg);
	if (t != (time_t)-1)
		add_int_member (bob, "date", t);

	s = mu_msg_get_size (msg);
	if (s != (size_t)-1)
		add_int_member (bob, "size", s);

	add_string_member (bob, "message-id", mu_msg_get_msgid (msg));
	add_string_member (bob, "mailing-list", mu_msg_get_mailing_list (msg));
	add_string_member (bob, "path", mu_msg_get_path (msg));
	add_string_member (bob, "maildir", mu_msg_get_maildir (msg));
	add_string_member (bob, "priority", mu_msg_prio_name(mu_msg_get_prio(msg)));

	add_flags (bob, msg);

	add_list_member (bob, "tags", mu_msg_get_tags(msg));
	add_list_member (bob, "references", mu_msg_get_references (msg));
	add_string_member (bob, "in-reply-to",
			   mu_msg_get_header (msg, "In-Reply-To"));

	/* headers are retrieved from the database, views from the
	 * message file file attr things can only be gotten from the
	 * file (ie., mu view), not from the database (mu find).  */
	if (!(opts & MU_MSG_OPTION_HEADERS_ONLY))
		add_file_parts (bob, msg, opts);

	bob  = json_builder_end_object (bob);
	node = json_builder_get_root (bob);

	g_clear_object (&bob);

	return node;
}
Exemple #2
0
static void _piwigo_set_account(dt_storage_piwigo_gui_data_t *ui)
{
  /// serialize data;
  JsonBuilder *builder = json_builder_new();
  json_builder_begin_object(builder);
  json_builder_set_member_name(builder, "server");
  json_builder_add_string_value(builder, gtk_entry_get_text(ui->server_entry));
  json_builder_set_member_name(builder, "username");
  json_builder_add_string_value(builder, gtk_entry_get_text(ui->user_entry));
  json_builder_set_member_name(builder, "password");
  json_builder_add_string_value(builder, gtk_entry_get_text(ui->pwd_entry));

  json_builder_end_object(builder);

  JsonNode *node = json_builder_get_root(builder);
  JsonGenerator *generator = json_generator_new();
  json_generator_set_root(generator, node);
#if JSON_CHECK_VERSION(0, 14, 0)
  json_generator_set_pretty(generator, FALSE);
#endif
  gchar *data = json_generator_to_data(generator, NULL);

  json_node_free(node);
  g_object_unref(generator);
  g_object_unref(builder);

  GHashTable *table = dt_pwstorage_get("piwigo");
  g_hash_table_insert(table, g_strdup(gtk_entry_get_text(ui->server_entry)), data);
  dt_pwstorage_set("piwigo", table);
  g_hash_table_destroy(table);
}
Exemple #3
0
static void
add_body_txt_params (JsonBuilder *bob, MuMsg *msg, MuMsgOptions opts)
{
	const GSList    *params;

	params = mu_msg_get_body_text_content_type_parameters (msg, opts);
	if (!params)
		return;

	bob = json_builder_set_member_name (bob, "body-txt-params");
	bob = json_builder_begin_array (bob);

        while (params) {
		const char *key, *val;

		key = (const char *)params->data;
		params = g_slist_next(params);
		if (!params)
			break;
		val = (const char *)params->data;

                if (key && val) {
			bob = json_builder_begin_object(bob);
			add_string_member(bob, key, val);
			bob = json_builder_end_object(bob);
                }

		params = g_slist_next(params);
        }

        bob = json_builder_end_array(bob);
}
Exemple #4
0
static JsonBuilder*
get_message_json (MuMsg *msg)
{
        JsonBuilder *builder = json_builder_new ();
  json_builder_begin_object (builder);

  json_add_recipients(builder, msg);
  json_add_subject(builder, msg);

        json_builder_set_member_name (builder, "msgid");
        json_builder_add_string_value (builder, mu_msg_get_msgid (msg));

        json_builder_set_member_name (builder, "date");
        json_builder_add_int_value (builder, (unsigned)mu_msg_get_date (msg));

  json_add_flags(builder, msg);

  json_builder_set_member_name (builder, "path");
  json_builder_add_string_value (builder, mu_msg_get_path (msg));

  json_builder_set_member_name (builder, "folder");
  json_builder_add_string_value (builder, mu_msg_get_maildir (msg));

  json_builder_set_member_name (builder, "size");
  json_builder_add_int_value (builder, (unsigned)mu_msg_get_size (msg));

  json_builder_end_object (builder);
  return builder;
}
Exemple #5
0
static void
maybe_append_list_post_as_reply_to (JsonBuilder *bob, MuMsg *msg)
{
	/* some mailing lists do not set the reply-to; see pull #1278. So for
	 * those cases, check the List-Post address and use that instead */

	GMatchInfo	*minfo;
	GRegex		*rx;
	const char*	 list_post;

	list_post = mu_msg_get_header (msg, "List-Post");
	if (!list_post)
		return;

	rx = g_regex_new ("^(<?mailto:)?([a-z0-9%[email protected]]+)>?", G_REGEX_CASELESS, 0, NULL);
	g_return_if_fail(rx);

	if (g_regex_match (rx, list_post, 0, &minfo)) {
		char	*addr;
		addr = g_match_info_fetch (minfo, 2);

		bob = json_builder_set_member_name (bob, "reply-to");
		bob = json_builder_begin_array(bob);
		bob = json_builder_begin_object(bob);
		add_string_member(bob, "email", addr);
		g_free (addr);

		bob = json_builder_end_object(bob);
		bob = json_builder_end_array(bob);
	}

	g_match_info_free (minfo);
	g_regex_unref (rx);
}
Exemple #6
0
/* TODO: use a command_finalize_func for that too */
void interface_notify() {
    GString* str = g_string_sized_new(1024);
    JsonBuilder* jb = json_builder_new();
    command_context ctx = { jb, NULL, NULL };

    json_builder_begin_object(jb);
    status(&ctx);
    json_builder_end_object(jb);

    JsonGenerator *gen = json_generator_new();
    g_object_set(gen, "pretty", config_get_bool_opt("pretty_json", FALSE), NULL);
    json_generator_set_root(gen, json_builder_get_root(jb));

    gchar *tmp = json_generator_to_data(gen, NULL);
    g_string_assign(str, tmp);
    g_string_append(str, "\n");

    g_object_unref(gen);
    g_object_unref(jb);
    g_free(tmp);

    /* First notify idle channels */
    g_list_foreach(g_idle_channels, interface_notify_chan, str);
    g_list_free(g_idle_channels);
    g_idle_channels = NULL;

    /* Then call callbacks from plugins */
    g_list_foreach(g_notification_callbacks, interface_notify_callback, str);

    g_string_free(str, TRUE);
}
Exemple #7
0
static void
add_thread_info (JsonBuilder *bob, const MuMsgIterThreadInfo *ti)
{
	bob = json_builder_set_member_name (bob, "thread");
	bob = json_builder_begin_object(bob);

	add_string_member (bob, "path",  ti->threadpath);
	add_int_member    (bob, "level", ti->level);

	bob = json_builder_set_member_name (bob, "flags");
	bob = json_builder_begin_array (bob);

	if (ti->prop & MU_MSG_ITER_THREAD_PROP_FIRST_CHILD)
		bob = json_builder_add_string_value (bob, "first-child");
	if (ti->prop & MU_MSG_ITER_THREAD_PROP_LAST_CHILD)
		bob = json_builder_add_string_value (bob, "last-child");
	if (ti->prop & MU_MSG_ITER_THREAD_PROP_EMPTY_PARENT)
		bob = json_builder_add_string_value (bob, "empty-parent");
	if (ti->prop & MU_MSG_ITER_THREAD_PROP_DUP)
		bob = json_builder_add_string_value (bob, "duplicate");
	if (ti->prop & MU_MSG_ITER_THREAD_PROP_HAS_CHILD)
		bob = json_builder_add_string_value (bob, "has-child");

	bob = json_builder_end_array (bob);
	bob = json_builder_end_object(bob);
}
Exemple #8
0
static void
send_dbus_reply (CockpitDBusJson *self, const gchar *cookie, GVariant *result, GError *error)
{
  gs_unref_object JsonBuilder *builder = NULL;
  builder = prepare_builder ("call-reply");

  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "cookie");
  json_builder_add_string_value (builder, cookie);

  if (result == NULL)
    {
      gchar *error_name;
      error_name = g_dbus_error_get_remote_error (error);
      g_dbus_error_strip_remote_error (error);

      json_builder_set_member_name (builder, "error_name");
      json_builder_add_string_value (builder, error_name != NULL ? error_name : "");

      json_builder_set_member_name (builder, "error_message");
      json_builder_add_string_value (builder, error->message);

      g_free (error_name);
    }
  else
    {
      json_builder_set_member_name (builder, "result");
      build_json (builder, result);
    }
  json_builder_end_object (builder);

  write_builder (self, builder);
}
Exemple #9
0
static void save_account_info(dt_storage_facebook_gui_data_t *ui, FBAccountInfo *accountinfo)
{
  FBContext *ctx = ui->facebook_api;
  g_return_if_fail(ctx != NULL);

  ///serialize data;
  JsonBuilder *builder = json_builder_new();
  json_builder_begin_object(builder);
  json_builder_set_member_name(builder, "username");
  json_builder_add_string_value(builder, accountinfo->username);
  json_builder_set_member_name(builder, "token");
  json_builder_add_string_value(builder, accountinfo->token);
  json_builder_end_object(builder);

  JsonNode *node = json_builder_get_root(builder);
  JsonGenerator *generator = json_generator_new();
  json_generator_set_root(generator, node);
  json_generator_set_pretty(generator, FALSE);
  gchar *data = json_generator_to_data(generator, NULL);

  json_node_free(node);
  g_object_unref(generator);
  g_object_unref(builder);

  GHashTable *table = dt_pwstorage_get("facebook");
  g_hash_table_insert(table, accountinfo->id, data);
  dt_pwstorage_set("facebook", table);

  g_hash_table_destroy(table);
}
static std::string toJson(GHashTable *dict)
{
    fprintf(stderr, "JSONDocument::toJson\n");
    JsonBuilder *builder = json_builder_new ();

    json_builder_begin_object (builder);

    if (dict != NULL)
    {
        g_hash_table_foreach (dict, insertToJson, builder);
    }

    json_builder_end_object (builder);

    JsonGenerator *generator = json_generator_new ();
    json_generator_set_root (generator, json_builder_get_root (builder));
    gchar *str = json_generator_to_data (generator, 0);

    std::string msg(str);

    g_object_unref (generator);
    g_object_unref (builder);

    //g_print("[%s]\n", msg.c_str());

    return msg + "\n";
}
Exemple #11
0
static JsonBuilder* kkc_user_rule_create_rom_kana (KkcRuleMetadata* parent, const gchar* name) {
	JsonBuilder* result = NULL;
	JsonBuilder* builder = NULL;
	JsonBuilder* _tmp0_ = NULL;
	KkcRuleMetadata* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_ = NULL;
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = json_builder_new ();
	builder = _tmp0_;
	json_builder_begin_object (builder);
	json_builder_set_member_name (builder, "include");
	json_builder_begin_array (builder);
	_tmp1_ = parent;
	_tmp2_ = kkc_metadata_file_get_name ((KkcMetadataFile*) _tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp3_, "/", NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = name;
	_tmp7_ = g_strconcat (_tmp5_, _tmp6_, NULL);
	_tmp8_ = _tmp7_;
	json_builder_add_string_value (builder, _tmp8_);
	_g_free0 (_tmp8_);
	_g_free0 (_tmp5_);
	json_builder_end_array (builder);
	json_builder_end_object (builder);
	result = builder;
	return result;
}
static void
on_object_added (GDBusObjectManager *manager,
                 GDBusObject *object,
                 gpointer user_data)
{
  CockpitDBusJson1 *self = user_data;
  cleanup_unref_object JsonBuilder *builder = prepare_builder ("object-added");

  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "object");
  json_builder_begin_object (builder);
  add_object (builder, object);
  json_builder_end_object (builder);
  json_builder_end_object (builder);

  write_builder (self, builder);
}
static gchar* do_get_action(IpcamIAjax *iajax, GList *item_list)
{
    JsonBuilder *builder;
    JsonNode *res_node = NULL;
    GList *item;
    JsonGenerator *generator;

    builder = json_builder_new();
    generator = json_generator_new();

    json_builder_begin_object(builder);
    json_builder_set_member_name(builder, "items");
    json_builder_begin_object(builder);
    for (item = g_list_first(item_list); item; item = g_list_next(item))
    {
        const gchar *name = item->data;
        GVariant *value = NULL;
        gchar *key = NULL;
        asprintf(&key, "day_night_mode:%s", name);
        value = ipcam_iajax_get_configuration(iajax, key);

        if (value)
        {
            add_value(builder, name, value);
            g_variant_unref(value);
        }
        g_free(key);
    }
    json_builder_end_object(builder);
    json_builder_end_object(builder);

    res_node = json_builder_get_root(builder);
    
    json_generator_set_root(generator, res_node);
    json_generator_set_pretty(generator, TRUE);

    gchar *result = json_generator_to_data(generator, NULL);

    json_node_free(res_node);
    g_object_unref(G_OBJECT(builder));
    g_object_unref(G_OBJECT(generator));

    return result;
}
static void
add_interface (JsonBuilder *builder,
               GDBusInterface *interface,
               GVariant *changed_properties)
{
  gchar *s;

  json_builder_set_member_name (builder, g_dbus_proxy_get_interface_name (G_DBUS_PROXY (interface)));
  json_builder_begin_object (builder);

  if (changed_properties == NULL)
    {
      gchar **properties;
      guint n;

      properties = g_dbus_proxy_get_cached_property_names (G_DBUS_PROXY (interface));
      for (n = 0; properties != NULL && properties[n] != NULL; n++)
        {
          const gchar *property_name = properties[n];
          GVariant *value;
          value = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (interface), property_name);
          if (value != NULL)
            {
              s = g_strconcat ("dbus_prop_", property_name, NULL);
              json_builder_set_member_name (builder, s);
              g_free (s);
              _json_builder_add_gvariant (builder, value);
              g_variant_unref (value);
            }
        }
      g_strfreev (properties);

      if (properties == NULL)
        {
          json_builder_set_member_name (builder, "HackEmpty");
          json_builder_add_string_value (builder, "HackEmpty");
        }
    }
  else
    {
      GVariantIter iter;
      const gchar *property_name;
      GVariant *value;
      g_variant_iter_init (&iter, changed_properties);
      while (g_variant_iter_next (&iter, "{&sv}", &property_name, &value))
        {
          s = g_strconcat ("dbus_prop_", property_name, NULL);
          json_builder_set_member_name (builder, property_name);
          g_free (s);
          _json_builder_add_gvariant (builder, value);
          g_variant_unref (value);
        }
    }

  json_builder_end_object (builder);
}
Exemple #15
0
static gboolean
gs_plugin_odrs_vote (GsPlugin *plugin, AsReview *review,
		     const gchar *uri, GError **error)
{
	GsPluginData *priv = gs_plugin_get_data (plugin);
	const gchar *tmp;
	g_autofree gchar *data = NULL;
	g_autoptr(JsonBuilder) builder = NULL;
	g_autoptr(JsonGenerator) json_generator = NULL;
	g_autoptr(JsonNode) json_root = NULL;

	/* create object with vote data */
	builder = json_builder_new ();
	json_builder_begin_object (builder);

	json_builder_set_member_name (builder, "user_hash");
	json_builder_add_string_value (builder, priv->user_hash);
	json_builder_set_member_name (builder, "user_skey");
	json_builder_add_string_value (builder,
				       as_review_get_metadata_item (review, "user_skey"));
	json_builder_set_member_name (builder, "app_id");
	json_builder_add_string_value (builder,
				       as_review_get_metadata_item (review, "app_id"));
	tmp = as_review_get_id (review);
	if (tmp != NULL) {
		gint64 review_id;
		json_builder_set_member_name (builder, "review_id");
		review_id = g_ascii_strtoll (tmp, NULL, 10);
		json_builder_add_int_value (builder, review_id);
	}
	json_builder_end_object (builder);

	/* export as a string */
	json_root = json_builder_get_root (builder);
	json_generator = json_generator_new ();
	json_generator_set_pretty (json_generator, TRUE);
	json_generator_set_root (json_generator, json_root);
	data = json_generator_to_data (json_generator, NULL);
	if (data == NULL)
		return FALSE;

	/* clear cache */
	if (!gs_plugin_odrs_invalidate_cache (review, error))
		return FALSE;

	/* send to server */
	if (!gs_plugin_odrs_json_post (gs_plugin_get_soup_session (plugin),
						  uri, data, error))
		return FALSE;

	/* mark as voted */
	as_review_add_flags (review, AS_REVIEW_FLAG_VOTED);

	/* success */
	return TRUE;
}
static JsonBuilder *
prepare_builder (const gchar *command)
{
  JsonBuilder *builder;
  builder = json_builder_new ();
  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "command");
  json_builder_add_string_value (builder, command);
  json_builder_set_member_name (builder, "data");
  return builder;
}
Exemple #17
0
static gboolean
print_position (GstValidateMonitor * monitor)
{
  GstQuery *query;
  gint64 position, duration;
  JsonBuilder *jbuilder;
  GstElement *pipeline =
      GST_ELEMENT (GST_VALIDATE_MONITOR_GET_OBJECT (monitor));

  gdouble rate = 1.0;
  GstFormat format = GST_FORMAT_TIME;

  if (!gst_element_query_position (pipeline, format, &position)) {
    GST_DEBUG_OBJECT (monitor, "Could not query position");

    return TRUE;
  }

  format = GST_FORMAT_TIME;
  if (!gst_element_query_duration (pipeline, format, &duration)) {
    GST_DEBUG_OBJECT (monitor, "Could not query duration");

    return TRUE;
  }

  query = gst_query_new_segment (GST_FORMAT_DEFAULT);
  if (gst_element_query (pipeline, query))
    gst_query_parse_segment (query, &rate, NULL, NULL, NULL);
  gst_query_unref (query);

  jbuilder = json_builder_new ();
  json_builder_begin_object (jbuilder);
  json_builder_set_member_name (jbuilder, "type");
  json_builder_add_string_value (jbuilder, "position");
  json_builder_set_member_name (jbuilder, "position");
  json_builder_add_int_value (jbuilder, position);
  json_builder_set_member_name (jbuilder, "duration");
  json_builder_add_int_value (jbuilder, duration);
  json_builder_set_member_name (jbuilder, "speed");
  json_builder_add_double_value (jbuilder, rate);
  json_builder_end_object (jbuilder);

  gst_validate_send (json_builder_get_root (jbuilder));
  g_object_unref (jbuilder);

  gst_validate_printf (NULL,
      "<position: %" GST_TIME_FORMAT " duration: %" GST_TIME_FORMAT
      " speed: %f />\r", GST_TIME_ARGS (position), GST_TIME_ARGS (duration),
      rate);

  return TRUE;
}
Exemple #18
0
static gchar *
build_save_items_request (GList *file_list)
{
    GList *l;

    JsonBuilder *json_builder = json_builder_new ();
    json_builder_begin_object (json_builder);

    json_builder_set_member_name (json_builder, "items");
    json_builder_begin_array (json_builder);
    for (l = file_list; l; l = l->next) {
        gchar *path = l->data;

        json_builder_begin_object (json_builder);
        json_builder_set_member_name (json_builder, "itemType");
        json_builder_add_string_value (json_builder, "attachment");
        json_builder_set_member_name (json_builder, "path");
        json_builder_add_string_value (json_builder, path);
        json_builder_set_member_name (json_builder, "attachments");
        json_builder_begin_array (json_builder);
        /* empty (but required for each item) */
        json_builder_end_array (json_builder);
        json_builder_end_object (json_builder);
    }
    json_builder_end_array (json_builder);

    json_builder_set_member_name (json_builder, "attachmentMode");
    json_builder_add_string_value (json_builder, "file");
    json_builder_end_object (json_builder);

    JsonGenerator *json_gen = json_generator_new ();
    JsonNode *root = json_builder_get_root (json_builder);
    json_generator_set_root (json_gen, root);
    gchar *save_items_request = json_generator_to_data (json_gen, NULL);
    json_node_free (root);
    g_object_unref (json_gen);
    g_object_unref (json_builder);
    return save_items_request;
}
static void
on_interface_added (GDBusObjectManager *manager,
                    GDBusObject *object,
                    GDBusInterface *interface,
                    gpointer user_data)
{
  CockpitDBusJson1 *self = user_data;
  cleanup_unref_object JsonBuilder *builder = prepare_builder ("interface-added");

  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "objpath");
  json_builder_add_string_value (builder, g_dbus_object_get_object_path (object));
  json_builder_set_member_name (builder, "iface_name");
  json_builder_add_string_value (builder, g_dbus_proxy_get_interface_name (G_DBUS_PROXY (interface)));
  json_builder_set_member_name (builder, "iface");
  json_builder_begin_object (builder);
  add_interface (builder, interface, NULL);
  json_builder_end_object (builder);
  json_builder_end_object (builder);

  write_builder (self, builder);
}
Exemple #20
0
static JsonNode *
melo_jsonrpc_build_response_node (JsonNode *result, JsonNode *error,
                                  const gchar *id, gint64 nid)
{
  JsonBuilder *builder;
  JsonNode *node;

  /* Create new builder */
  builder = json_builder_new ();
  if (!builder)
    return NULL;

  /* Begin a new object */
  json_builder_begin_object (builder);

  /* Add jsonrpc member */
  json_builder_set_member_name (builder, "jsonrpc");
  json_builder_add_string_value (builder, "2.0");

  /* Set result or error */
  if (error) {
    /* Add error member */
    json_builder_set_member_name (builder, "error");
    json_builder_add_value (builder, error);

    /* Free result if exists */
    if (result)
      json_node_free (result);
  } else if (result) {
    /* Add result member */
    json_builder_set_member_name (builder, "result");
    json_builder_add_value (builder, result);
  }

  /* Add id member: we assume ID cannot be negative */
  json_builder_set_member_name (builder, "id");
  if (nid < 0 || id)
    json_builder_add_string_value (builder, id);
  else
    json_builder_add_int_value (builder, nid);

  json_builder_end_object (builder);

  /* Get final object */
  node = json_builder_get_root (builder);

  /* Free builder */
  g_object_unref (builder);

  return node;
}
static gboolean
ipcam_event_input_msg_handler_read_param(IpcamEventInputMsgHandler *handler, JsonBuilder *builder, const gchar *name)
{
    IpcamIConfig *iconfig;
    g_object_get(G_OBJECT(handler), "app", &iconfig, NULL);
    gboolean ret = FALSE;
    GVariant *value = NULL;

    value = ipcam_iconfig_read(iconfig, IPCAM_EVENT_INPUT_TYPE, name, "enable");
    if (value)
    {
        json_builder_set_member_name(builder, "enable");
        json_builder_add_boolean_value(builder, g_variant_get_boolean(value));
        g_variant_unref(value);
    }
    
    value = ipcam_iconfig_read(iconfig, IPCAM_EVENT_INPUT_TYPE, name, "schedules");
    if (value)
    {
        Schedules *sche;
        if (IS_64BIT_MACHINE)
        {
            sche = GSIZE_TO_POINTER(g_variant_get_uint64(value));
        }
        else
        {
            sche = GSIZE_TO_POINTER(g_variant_get_uint32(value));
        }
        gint i = 0;
        json_builder_set_member_name(builder, "schedules");
        json_builder_begin_object(builder);
        if (sche)
        {            
            for (i = ENUM_MON; i < ENUM_WEEKDAY_LAST; i++)
            {
                if (sche->schedule[i])
                {
                    json_builder_set_member_name(builder, weekday_name[i]);
                    json_builder_add_string_value(builder, sche->schedule[i]);
                    g_free(sche->schedule[i]);
                }
            }
            g_free(sche);
        }
        json_builder_end_object(builder);

        g_variant_unref(value);
    }
    
    return ret;
}
static void
send_seed (CockpitDBusJson1 *self)
{
  cleanup_unref_object JsonBuilder *builder = json_builder_new ();

  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "command");
  json_builder_add_string_value (builder, "seed");

  json_builder_set_member_name (builder, "options");
  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "byteorder");
  if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
    json_builder_add_string_value (builder, "le");
  else if (G_BYTE_ORDER == G_BIG_ENDIAN)
    json_builder_add_string_value (builder, "be");
  else
    json_builder_add_string_value (builder, "");
  json_builder_end_object (builder);

  json_builder_set_member_name (builder, "data");
  json_builder_begin_object (builder);

  GList *objects = g_dbus_object_manager_get_objects (self->object_manager);
  for (GList *l = objects; l != NULL; l = l->next)
    {
      GDBusObject *object = G_DBUS_OBJECT (l->data);
      json_builder_set_member_name (builder, g_dbus_object_get_object_path (object));
      json_builder_begin_object (builder);
      add_object (builder, object);
      json_builder_end_object (builder);
    }
  g_list_foreach (objects, (GFunc)g_object_unref, NULL);
  g_list_free (objects);
  json_builder_end_object (builder);

  write_builder (self, builder);
}
static gboolean
ipcam_event_cover_msg_handler_put_action_impl(IpcamMessageHandler *handler, JsonNode *request, JsonNode **response)
{
    JsonBuilder *builder = json_builder_new();
    JsonObject *req_obj;
    GList *members, *item;

    req_obj = json_object_get_object_member(json_node_get_object(request), "items");
    members = json_object_get_members(req_obj);

    json_builder_begin_object(builder);
    json_builder_set_member_name(builder, "items");
    json_builder_begin_object(builder);
    for (item = g_list_first(members); item; item = g_list_next(item))
    {
        const gchar *name = item->data;
        if (g_str_equal(name, "region1") ||
            g_str_equal(name, "region2"))
        {
            JsonObject *value_obj = json_object_get_object_member(req_obj, name);
            ipcam_event_cover_msg_handler_update_param(IPCAM_EVENT_COVER_MSG_HANDLER(handler), name, value_obj);
            json_builder_set_member_name(builder, name);
            json_builder_begin_object(builder);
            ipcam_event_cover_msg_handler_read_param(IPCAM_EVENT_COVER_MSG_HANDLER(handler), builder, name);
            json_builder_end_object(builder);
        }
    }
    json_builder_end_object(builder);
    json_builder_end_object(builder);

    g_list_free(members);

    *response = json_builder_get_root(builder);

    g_object_unref(builder);

    return TRUE;
}
Exemple #24
0
static void
build_json_variant (JsonBuilder *builder,
                    GVariant *value)
{
  GVariant *child;

  child = g_variant_get_variant (value);
  json_builder_begin_object (builder);

  build_json_with_sig (builder, child);

  json_builder_end_object (builder);
  g_variant_unref (child);
}
static void insertToJson(gpointer name, gpointer v, gpointer user_data)
{
    JsonBuilder *builder = (JsonBuilder *)user_data;

    if (name != NULL)
        json_builder_set_member_name (builder, (const char *)name);

    switch (G_VALUE_TYPE(v)) {
    case G_TYPE_BOOLEAN:
        json_builder_add_boolean_value (builder, g_value_get_boolean((GValue *)v));
        break;
    case G_TYPE_STRING:
        json_builder_add_string_value (builder, g_value_get_string((GValue *)v));
        break;
    case G_TYPE_INT:
        json_builder_add_int_value (builder, g_value_get_int((GValue *)v));
        break;
    case G_TYPE_INT64:
        json_builder_add_int_value (builder, g_value_get_int64((GValue *)v));
        break;
    case G_TYPE_DOUBLE:
        json_builder_add_double_value (builder, g_value_get_double((GValue *)v));
        break;
    default:
        if (G_VALUE_TYPE(v) == G_TYPE_HASH_TABLE)
        {
            json_builder_begin_object (builder);
            GHashTable *map = (GHashTable *) g_value_get_boxed((GValue *)v);
            g_hash_table_foreach (map, insertToJson, builder);
            json_builder_end_object (builder);
        }
        else if (G_VALUE_TYPE(v) == G_TYPE_VALUE_ARRAY)
        {
            json_builder_begin_array (builder);
            GValueArray *array = (GValueArray *) g_value_get_boxed((GValue *)v);
            for (guint i = 0; i < array->n_values; i++)
            {
               GValue *value = g_value_array_get_nth(array, i);
               insertToJson(0, value, builder);
            }
            json_builder_end_array (builder);
        }
        else
        {
            g_print("unhandled type %s\n", G_VALUE_TYPE_NAME(v));
            json_builder_add_null_value (builder);
        }
        break;
    }
}
static void
get_json (GDataParsable *parsable, JsonBuilder *builder)
{
	GDataAccessRule *access_rule;
	const gchar *id, *etag, *role, *scope_type, *scope_value;

	access_rule = GDATA_ACCESS_RULE (parsable);

	id = gdata_entry_get_id (GDATA_ENTRY (parsable));
	if (id != NULL) {
		json_builder_set_member_name (builder, "id");
		json_builder_add_string_value (builder, id);
	}

	json_builder_set_member_name (builder, "kind");
	json_builder_add_string_value (builder, "calendar#aclRule");

	/* Add the ETag, if available. */
	etag = gdata_entry_get_etag (GDATA_ENTRY (parsable));
	if (etag != NULL) {
		json_builder_set_member_name (builder, "etag");
		json_builder_add_string_value (builder, etag);
	}

	role = gdata_access_rule_get_role (access_rule);
	if (role != NULL) {
		json_builder_set_member_name (builder, "role");
		json_builder_add_string_value (builder, role_v2_to_v3 (role));
	}

	gdata_access_rule_get_scope (access_rule, &scope_type, &scope_value);
	if (scope_type != NULL || scope_value != NULL) {
		json_builder_set_member_name (builder, "scope");
		json_builder_begin_object (builder);

		if (scope_type != NULL) {
			json_builder_set_member_name (builder, "type");
			json_builder_add_string_value (builder,
			                               scope_type_v2_to_v3 (scope_type));
		}

		if (scope_value != NULL) {
			json_builder_set_member_name (builder, "value");
			json_builder_add_string_value (builder, scope_value);
		}

		json_builder_end_object (builder);
	}
}
Exemple #27
0
static void
build_json_dictionary (JsonBuilder *builder,
                       const GVariantType *entry_type,
                       GVariant *dict)
{
  const GVariantType *key_type;
  GVariantIter iter;
  GVariant *child;
  GVariant *key;
  GVariant *value;
  gboolean is_string;
  gchar *key_string;

  json_builder_begin_object (builder);
  key_type = g_variant_type_key (entry_type);

  is_string = (g_variant_type_equal (key_type, G_VARIANT_TYPE_STRING) ||
               g_variant_type_equal (key_type, G_VARIANT_TYPE_OBJECT_PATH) ||
               g_variant_type_equal (key_type, G_VARIANT_TYPE_SIGNATURE));

  g_variant_iter_init (&iter, dict);
  while ((child = g_variant_iter_next_value (&iter)) != NULL)
    {
      key = g_variant_get_child_value (child, 0);
      value = g_variant_get_child_value (child, 1);

      if (is_string)
        {
          json_builder_set_member_name (builder, g_variant_get_string (key, NULL));
        }
      else
        {
          key_string = g_variant_print (key, FALSE);
          json_builder_set_member_name (builder, key_string);
          g_free (key_string);
        }

      build_json (builder, value);

      g_variant_unref (key);
      g_variant_unref (value);
    }

  json_builder_end_object (builder);
}
Exemple #28
0
static JsonNode *query_network_address(IpcamIAjax *iajax)
{
	const gchar *token = ipcam_base_app_get_config(IPCAM_BASE_APP(iajax), "token");
	IpcamRequestMessage *req_msg;
	IpcamMessage *resp_msg;
    JsonBuilder *builder;
	JsonNode *addr_node = NULL;
	gboolean ret;

	builder = json_builder_new();
	json_builder_begin_object(builder);
	json_builder_set_member_name(builder, "items");
	json_builder_begin_array(builder);
	json_builder_add_string_value(builder, "address");
	json_builder_end_array(builder);
	json_builder_end_object(builder);

	req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE,
	                       "action", "get_network",
	                       "body", json_builder_get_root(builder),
	                       NULL);
	ipcam_base_app_send_message(IPCAM_BASE_APP(iajax), IPCAM_MESSAGE(req_msg),
	                            "iconfig", token, NULL, 5);
	ret = ipcam_base_app_wait_response(IPCAM_BASE_APP(iajax),
	                                   ipcam_request_message_get_id(req_msg),
	                                   5000, &resp_msg);
	if (ret)
	{
		JsonNode *resp_body;
		JsonObject *items_obj;

		g_object_get(G_OBJECT(resp_msg), "body", &resp_body, NULL);

		items_obj = json_object_get_object_member(json_node_get_object(resp_body), "items");
		addr_node = json_node_copy(json_object_get_member(items_obj, "address"));

		g_object_unref(resp_msg);
	}

	g_object_unref(req_msg);
	g_object_unref(builder);

	return addr_node;
}
Exemple #29
0
static JsonBuilder* kkc_user_rule_create_metadata (KkcRuleMetadata* parent, const gchar* name) {
	JsonBuilder* result = NULL;
	JsonBuilder* builder = NULL;
	JsonBuilder* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	KkcRuleMetadata* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	KkcRuleMetadata* _tmp5_ = NULL;
	const gchar* _tmp6_ = NULL;
	const gchar* _tmp7_ = NULL;
	KkcRuleMetadata* _tmp8_ = NULL;
	gint _tmp9_ = 0;
	gint _tmp10_ = 0;
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = json_builder_new ();
	builder = _tmp0_;
	json_builder_begin_object (builder);
	json_builder_set_member_name (builder, "name");
	_tmp1_ = name;
	json_builder_add_string_value (builder, _tmp1_);
	json_builder_set_member_name (builder, "description");
	_tmp2_ = parent;
	_tmp3_ = kkc_metadata_file_get_description ((KkcMetadataFile*) _tmp2_);
	_tmp4_ = _tmp3_;
	json_builder_add_string_value (builder, _tmp4_);
	json_builder_set_member_name (builder, "filter");
	_tmp5_ = parent;
	_tmp6_ = kkc_rule_metadata_get_filter (_tmp5_);
	_tmp7_ = _tmp6_;
	json_builder_add_string_value (builder, _tmp7_);
	json_builder_set_member_name (builder, "priority");
	_tmp8_ = parent;
	_tmp9_ = kkc_rule_metadata_get_priority (_tmp8_);
	_tmp10_ = _tmp9_;
	json_builder_add_int_value (builder, (gint64) _tmp10_);
	json_builder_end_object (builder);
	result = builder;
	return result;
}
JsonNode *
json_ghashtable_serialize (GHashTable *table)
{
  JsonBuilder *builder;
  JsonNode *root;

  builder = json_builder_new ();

  json_builder_begin_object (builder);

  if (table) {
    g_hash_table_foreach (table, (GHFunc) _serialize_entry, builder);
  }

  json_builder_end_object (builder);

  root = json_builder_get_root (builder);

  g_object_unref (builder);

  return root;
}