Esempio n. 1
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);
#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("facebook");
  g_hash_table_insert(table, accountinfo->id, data);
  dt_pwstorage_set("facebook", table);

  g_hash_table_destroy(table);
}
Esempio n. 2
0
static void
on_interface_proxy_properties_changed (GDBusObjectManager *manager,
                                       GDBusObjectProxy *object_proxy,
                                       GDBusProxy *interface_proxy,
                                       GVariant *changed_properties,
                                       const gchar * const *invalidated_properties,
                                       gpointer user_data)
{
  CockpitDBusJson1 *self = user_data;
  cleanup_unref_object JsonBuilder *builder = prepare_builder ("interface-properties-changed");

  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "objpath");
  json_builder_add_string_value (builder, g_dbus_object_get_object_path (G_DBUS_OBJECT (object_proxy)));
  json_builder_set_member_name (builder, "iface_name");
  json_builder_add_string_value (builder, g_dbus_proxy_get_interface_name (interface_proxy));
  /* It's a bit of a waste to send all properties - would be cheaper to just
   * send @changed_properties and @invalidated_properties. But this is simpler.
   */
  json_builder_set_member_name (builder, "iface");
  json_builder_begin_object (builder);
  add_interface (builder, G_DBUS_INTERFACE (interface_proxy), changed_properties);
  json_builder_end_object (builder);
  json_builder_end_object (builder);

  write_builder (self, builder);
}
Esempio n. 3
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);
}
Esempio n. 4
0
static void
send_dbus_reply (CockpitDBusJson1 *self, const gchar *cookie, GVariant *result, GError *error)
{
  cleanup_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");
      _json_builder_add_gvariant (builder, result);
    }
  json_builder_end_object (builder);

  write_builder (self, builder);
}
Esempio n. 5
0
// Creates a response. Transfers ownership of reply.
static JsonNode* create_response(JsonNode *reply, int id)
{
  JsonBuilder *builder = json_builder_new ();

  // {"jsonrpc": "2.0", "result": 19, "id": 1}
  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "jsonrpc");
  json_builder_add_string_value (builder, "2.0");
  
  json_builder_set_member_name (builder, "id");
  json_builder_add_int_value (builder, id);

  json_builder_set_member_name (builder, "result");

  if (reply)
    json_builder_add_value (builder, json_node_copy(reply));
  else
    // default "ok" message
    json_builder_add_string_value (builder, "ok");

  json_builder_end_object (builder);
  
  JsonNode *node = json_node_copy(json_builder_get_root (builder));

  g_object_unref(builder);
  return node;
}
Esempio n. 6
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);
}
Esempio n. 7
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;
}
Esempio n. 8
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;
}
Esempio n. 9
0
/**
 * fwupd_release_to_json:
 * @release: A #FwupdRelease
 * @builder: A #JsonBuilder
 *
 * Adds a fwupd release to a JSON builder
 *
 * Since: 1.2.6
 **/
void
fwupd_release_to_json (FwupdRelease *release, JsonBuilder *builder)
{
	FwupdReleasePrivate *priv = GET_PRIVATE (release);
	g_autoptr(GList) keys = NULL;

	g_return_if_fail (FWUPD_IS_RELEASE (release));
	g_return_if_fail (builder != NULL);

	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_APPSTREAM_ID, priv->appstream_id);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_REMOTE_ID, priv->remote_id);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_SUMMARY, priv->summary);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_DESCRIPTION, priv->description);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_VERSION, priv->version);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_FILENAME, priv->filename);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_PROTOCOL, priv->protocol);
	if (priv->checksums->len > 0) {
		json_builder_set_member_name (builder, FWUPD_RESULT_KEY_CHECKSUM);
		json_builder_begin_array (builder);
		for (guint i = 0; i < priv->checksums->len; i++) {
			const gchar *checksum = g_ptr_array_index (priv->checksums, i);
			json_builder_add_string_value (builder, checksum);
		}
		json_builder_end_array (builder);
	}
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_LICENSE, priv->license);
	fwupd_release_json_add_int (builder, FWUPD_RESULT_KEY_SIZE, priv->size);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_URI, priv->uri);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_HOMEPAGE, priv->homepage);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_DETAILS_URL, priv->details_url);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_SOURCE_URL, priv->source_url);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_VENDOR, priv->vendor);
	if (priv->flags != FWUPD_RELEASE_FLAG_NONE) {
		json_builder_set_member_name (builder, FWUPD_RESULT_KEY_FLAGS);
		json_builder_begin_array (builder);
		for (guint i = 0; i < 64; i++) {
			const gchar *tmp;
			if ((priv->flags & ((guint64) 1 << i)) == 0)
				continue;
			tmp = fwupd_release_flag_to_string ((guint64) 1 << i);
			json_builder_add_string_value (builder, tmp);
		}
		json_builder_end_array (builder);
	}
	fwupd_release_json_add_int (builder, FWUPD_RESULT_KEY_INSTALL_DURATION, priv->install_duration);
	fwupd_release_json_add_string (builder, FWUPD_RESULT_KEY_UPDATE_MESSAGE, priv->update_message);

	/* metadata */
	keys = g_hash_table_get_keys (priv->metadata);
	for (GList *l = keys; l != NULL; l = l->next) {
		const gchar *key = l->data;
		const gchar *value = g_hash_table_lookup (priv->metadata, key);
		fwupd_release_json_add_string (builder, key, value);
	}
}
Esempio n. 10
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;
}
Esempio n. 11
0
static gboolean
fwupd_build_history_report_json_metadata (JsonBuilder *builder, GError **error)
{
	g_autoptr(GHashTable) hash = NULL;
	struct {
		const gchar *key;
		const gchar *val;
	} distro_kv[] = {
		{ "ID",			"DistroId" },
		{ "VERSION_ID",		"DistroVersion" },
		{ "VARIANT_ID",		"DistroVariant" },
		{ NULL, NULL }
	};

	/* get all required os-release keys */
	hash = fwupd_get_os_release (error);
	if (hash == NULL)
		return FALSE;
	for (guint i = 0; distro_kv[i].key != NULL; i++) {
		const gchar *tmp = g_hash_table_lookup (hash, distro_kv[i].key);
		if (tmp != NULL) {
			json_builder_set_member_name (builder, distro_kv[i].val);
			json_builder_add_string_value (builder, tmp);
		}
	}
	return TRUE;
}
Esempio n. 12
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;
}
Esempio n. 13
0
void
JSONBuilder::add_string_member(const gchar *member_name,
                               const gchar *string_value) {
  std::unique_lock<std::mutex> lock(thread_safe_);
  json_builder_set_member_name(builder_, member_name);
  json_builder_add_string_value(builder_, string_value);
}
Esempio n. 14
0
snarf_alert_t *
snarf_alert_new(
    snarf_alert_severity_t severity,
    uint64_t               timestamp)
{

snarf_alert_t *alert = g_new0(snarf_alert_t, 1);
JsonBuilder *builder;

// Populate the envelope
builder=json_builder_new();
json_builder_begin_object(builder);
json_builder_set_member_name(builder,"envelope");
json_builder_begin_object(builder);
json_builder_set_member_name(builder,"severity");
json_builder_add_int_value (builder, severity);
json_builder_set_member_name(builder,"timestamp");
char jsontime[32];
time_t sectime=timestamp / (1000*1000);
struct tm gmt;
gmtime_r(&sectime,&gmt);
strftime(jsontime,21,"%Y-%m-%dT%H:%M:%SZ",&gmt);
json_builder_add_string_value(builder,jsontime);
json_builder_end_object(builder);
json_builder_set_member_name(builder,"body");

json_builder_begin_object(builder);
json_builder_end_object(builder);
json_builder_end_object(builder);
alert->msg=json_builder_get_root(builder);

return alert;

}
Esempio n. 15
0
static void
add_part_type (JsonBuilder *bob, MuMsgPartType ptype)
{
	unsigned u;
	struct PartTypes {
		MuMsgPartType ptype;
		const char* name;
	} ptypes[] = {
		{ MU_MSG_PART_TYPE_LEAF,       "leaf" },
		{ MU_MSG_PART_TYPE_MESSAGE,    "message" },
		{ MU_MSG_PART_TYPE_INLINE,     "inline" },
		{ MU_MSG_PART_TYPE_ATTACHMENT, "attachment" },
		{ MU_MSG_PART_TYPE_SIGNED,     "signed" },
		{ MU_MSG_PART_TYPE_ENCRYPTED,  "encrypted" }
	};

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

	for (u = 0; u!= G_N_ELEMENTS(ptypes); ++u)
		if (ptype & ptypes[u].ptype)
			json_builder_add_string_value (bob, ptypes[u].name);

	bob = json_builder_end_array(bob);
}
Esempio n. 16
0
static JsonNode* create_fault_value_response(int error_num, JsonNode *msg_node, int id)
{
  JsonBuilder *builder = json_builder_new ();

  json_builder_begin_object (builder);
  json_builder_set_member_name (builder, "jsonrpc");
  json_builder_add_string_value (builder, "2.0");
  json_builder_set_member_name (builder, "error");
  json_builder_begin_object(builder);
  json_builder_set_member_name (builder, "code");
  json_builder_add_int_value(builder, error_num);
  json_builder_set_member_name (builder, "message");
  json_builder_add_value (builder, json_node_copy(msg_node));
  json_builder_end_object (builder);
  json_builder_set_member_name(builder, "id");
  if (id < 0)
    json_builder_add_null_value(builder);
  else
    json_builder_add_int_value(builder, id);
  json_builder_end_object (builder);
  JsonNode *node = json_node_copy(json_builder_get_root (builder));
  
  g_object_unref(builder);
  return node;
}
static void
_serialize_entry (gchar *key,
                  gchar *value,
                  JsonBuilder *builder)
{
  json_builder_set_member_name (builder, key);
  json_builder_add_string_value (builder, value);
}
Esempio n. 18
0
static void
fwupd_release_json_add_string (JsonBuilder *builder, const gchar *key, const gchar *str)
{
	if (str == NULL)
		return;
	json_builder_set_member_name (builder, key);
	json_builder_add_string_value (builder, str);
}
Esempio n. 19
0
static void
each_flag (MuFlags flag, FlagData *fdata)
{
	if (!(flag & fdata->msgflags))
		return;

	json_builder_add_string_value (fdata->bob,
				       mu_flag_name(flag));
}
Esempio n. 20
0
static void
add_string_member (JsonBuilder *bob, const char* elm, const char *str)
{
	if (!str)
		return; /* don't include */

	bob = json_builder_set_member_name (bob, elm);
	bob = json_builder_add_string_value (bob, str);
}
Esempio n. 21
0
static void
on_interface_removed (GDBusObjectManager *manager,
                      GDBusObject *object,
                      GDBusInterface *interface,
                      gpointer user_data)
{
  CockpitDBusJson1 *self = user_data;
  cleanup_unref_object JsonBuilder *builder = prepare_builder ("interface-removed");

  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_end_object (builder);

  write_builder (self, builder);
}
Esempio n. 22
0
static void
build_json_with_sig (JsonBuilder *builder,
                     GVariant *value)
{
  json_builder_set_member_name (builder, "sig");
  json_builder_add_string_value (builder, g_variant_get_type_string (value));
  json_builder_set_member_name (builder, "val");
  build_json (builder, value);
}
Esempio n. 23
0
/**
 * fwupd_build_history_report_json:
 * @devices: (element-type FwupdDevice): devices
 * @error: A #GError or %NULL
 *
 * Builds a JSON report for the list of devices. No filtering is done on the
 * @devices array, and it is expected that the caller will filter to something
 * sane, e.g. %FWUPD_DEVICE_FLAG_REPORTED at the bare minimum.
 *
 * Returns: a string, or %NULL if the ID is not present
 *
 * Since: 1.0.4
 **/
gchar *
fwupd_build_history_report_json (GPtrArray *devices, GError **error)
{
	gchar *data;
	g_autofree gchar *machine_id = NULL;
	g_autoptr(JsonBuilder) builder = NULL;
	g_autoptr(JsonGenerator) json_generator = NULL;
	g_autoptr(JsonNode) json_root = NULL;

	/* get a hash that represents the machine */
	machine_id = fwupd_build_machine_id ("fwupd", error);
	if (machine_id == NULL)
		return NULL;

	/* create header */
	builder = json_builder_new ();
	json_builder_begin_object (builder);
	json_builder_set_member_name (builder, "ReportVersion");
	json_builder_add_int_value (builder, 2);
	json_builder_set_member_name (builder, "MachineId");
	json_builder_add_string_value (builder, machine_id);

	/* this is system metadata not stored in the database */
	json_builder_set_member_name (builder, "Metadata");
	json_builder_begin_object (builder);
	if (!fwupd_build_history_report_json_metadata (builder, error))
		return NULL;
	json_builder_end_object (builder);

	/* add each device */
	json_builder_set_member_name (builder, "Reports");
	json_builder_begin_array (builder);
	for (guint i = 0; i < devices->len; i++) {
		FwupdDevice *dev = g_ptr_array_index (devices, i);
		json_builder_begin_object (builder);
		fwupd_build_history_report_json_device (builder, dev);
		json_builder_end_object (builder);
	}
	json_builder_end_array (builder);
	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) {
		g_set_error_literal (error,
				     FWUPD_ERROR,
				     FWUPD_ERROR_INTERNAL,
				     "Failed to convert to JSON string");
		return NULL;
	}
	return data;
}
Esempio n. 24
0
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);
}
Esempio n. 25
0
static void
json_add_subject(JsonBuilder *builder, MuMsg *msg)
{
        const char *subject;
        subject = mu_msg_get_subject (msg);
        if (subject) {
        json_builder_set_member_name (builder, "subject");
        json_builder_add_string_value (builder, subject);
  }
}
Esempio n. 26
0
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;
}
Esempio n. 27
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;
}
Esempio n. 28
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;
}
Esempio n. 29
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 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;
}