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(§ime,&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; }
static gboolean ipcam_event_cover_msg_handler_get_action_impl(IpcamMessageHandler *handler, JsonNode *request, JsonNode **response) { JsonBuilder *builder = json_builder_new(); JsonArray *req_array; int i; req_array = json_object_get_array_member(json_node_get_object(request), "items"); json_builder_begin_object(builder); json_builder_set_member_name(builder, "items"); json_builder_begin_object(builder); for (i = 0; i < json_array_get_length(req_array); i++) { const gchar *name = json_array_get_string_element(req_array, i); if (g_str_equal(name, "region1") || g_str_equal(name, "region2")) { 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); *response = json_builder_get_root(builder); g_object_unref(builder); return TRUE; }
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); }
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 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; if (g_str_equal(name, "method")) { GVariant *value = NULL; value = ipcam_iajax_get_configuration(iajax, "network:method"); if (value) { add_value(builder, name, value); g_variant_unref(value); } } else if (g_str_equal(name, "address")) { do_get_action_address(iajax, builder); } else if (g_str_equal(name, "pppoe")) { do_get_action_pppoe(iajax, builder); } else if (g_str_equal(name, "port")) { do_get_action_port(iajax, builder); } else { g_warn_if_reached(); } } 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; }
/** * 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; }
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 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; }
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"; }
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); }
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; }
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); }
// 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; }
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); }
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); }
/* 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); }
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); }
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); }
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 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 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); }
static void write_builder (CockpitDBusJson1 *self, JsonBuilder *builder) { GBytes *bytes; json_builder_end_object (builder); bytes = _json_builder_to_bytes (self, builder); cockpit_channel_send (COCKPIT_CHANNEL (self), bytes, TRUE); g_bytes_unref (bytes); }
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; }
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); }
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 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; }