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; }
// 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 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 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); }
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; }
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 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"; }
/* 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 _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 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 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; }
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 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 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 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; }
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; }
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; }
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; }
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; }
static void _bus_handler (GstBus * bus, GstMessage * message, GstValidatePipelineMonitor * monitor) { GError *err = NULL; gchar *debug = NULL; const GstStructure *details = NULL; gint error_flow = GST_FLOW_OK; switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_ERROR: gst_message_parse_error (message, &err, &debug); gst_message_parse_error_details (message, &details); if (g_error_matches (err, GST_CORE_ERROR, GST_CORE_ERROR_MISSING_PLUGIN)) { GST_VALIDATE_REPORT (monitor, MISSING_PLUGIN, "Error: %s -- Debug message: %s", err->message, debug); } else if ((g_error_matches (err, GST_STREAM_ERROR, GST_STREAM_ERROR_FAILED) && details && gst_structure_get_int (details, "flow-return", &error_flow) && error_flow == GST_FLOW_NOT_NEGOTIATED) || g_error_matches (err, GST_STREAM_ERROR, GST_STREAM_ERROR_FORMAT)) { gchar *report = _generate_not_negotiated_error_report (message); GST_VALIDATE_REPORT (monitor, NOT_NEGOTIATED, "%s", report); g_free (report); } else { GST_VALIDATE_REPORT (monitor, ERROR_ON_BUS, "Got error: %s -- Debug message: %s", err->message, debug); } GST_VALIDATE_MONITOR_LOCK (monitor); monitor->got_error = TRUE; GST_VALIDATE_MONITOR_UNLOCK (monitor); g_error_free (err); g_free (debug); break; case GST_MESSAGE_WARNING: gst_message_parse_warning (message, &err, &debug); GST_VALIDATE_REPORT (monitor, WARNING_ON_BUS, "Got warning: %s -- Debug message: %s", err->message, debug); g_error_free (err); g_free (debug); break; case GST_MESSAGE_STATE_CHANGED: { if (GST_MESSAGE_SRC (message) == GST_VALIDATE_MONITOR (monitor)->target) { GstState oldstate, newstate, pending; gst_message_parse_state_changed (message, &oldstate, &newstate, &pending); if (oldstate == GST_STATE_READY && newstate == GST_STATE_PAUSED) { monitor->print_pos_srcid = g_timeout_add (PRINT_POSITION_TIMEOUT, (GSourceFunc) print_position, monitor); } else if (oldstate >= GST_STATE_PAUSED && newstate <= GST_STATE_READY) { if (monitor->print_pos_srcid && g_source_remove (monitor->print_pos_srcid)) monitor->print_pos_srcid = 0; monitor->got_error = FALSE; } } break; } case GST_MESSAGE_BUFFERING: { JsonBuilder *jbuilder = json_builder_new (); GstBufferingMode mode; gint percent; gst_message_parse_buffering (message, &percent); gst_message_parse_buffering_stats (message, &mode, NULL, NULL, NULL); json_builder_begin_object (jbuilder); json_builder_set_member_name (jbuilder, "type"); json_builder_add_string_value (jbuilder, "buffering"); json_builder_set_member_name (jbuilder, "state"); if (percent == 100) { /* a 100% message means buffering is done */ gst_validate_printf (NULL, "\nDone buffering\n"); json_builder_add_string_value (jbuilder, "done"); if (monitor->buffering) { monitor->print_pos_srcid = g_timeout_add (PRINT_POSITION_TIMEOUT, (GSourceFunc) print_position, monitor); monitor->buffering = FALSE; } } else { /* buffering... */ if (!monitor->buffering) { monitor->buffering = TRUE; gst_validate_printf (NULL, "\nStart buffering\n"); json_builder_add_string_value (jbuilder, "started"); if (monitor->print_pos_srcid && g_source_remove (monitor->print_pos_srcid)) { monitor->print_pos_srcid = 0; } } else { json_builder_add_string_value (jbuilder, "progress"); } gst_validate_printf (NULL, "%s %d%% \r", "Buffering...", percent); } json_builder_set_member_name (jbuilder, "position"); json_builder_add_int_value (jbuilder, percent); json_builder_end_object (jbuilder); gst_validate_send (json_builder_get_root (jbuilder)); g_object_unref (jbuilder); break; } case GST_MESSAGE_STREAM_COLLECTION: { GstStreamCollection *collection = NULL; gst_message_parse_stream_collection (message, &collection); gst_object_replace ((GstObject **) & monitor->stream_collection, (GstObject *) collection); gst_object_unref (collection); break; } case GST_MESSAGE_STREAMS_SELECTED: { guint i; if (monitor->streams_selected) { g_list_free_full (monitor->streams_selected, gst_object_unref); monitor->streams_selected = NULL; } for (i = 0; i < gst_message_streams_selected_get_size (message); i++) { GstStream *stream = gst_message_streams_selected_get_stream (message, i); monitor->streams_selected = g_list_append (monitor->streams_selected, stream); } break; } default: break; } }
gboolean gs_plugin_review_submit (GsPlugin *plugin, GsApp *app, AsReview *review, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autofree gchar *data = NULL; g_autofree gchar *uri = NULL; g_autofree gchar *version = NULL; g_autoptr(JsonBuilder) builder = NULL; g_autoptr(JsonGenerator) json_generator = NULL; g_autoptr(JsonNode) json_root = NULL; /* save as we don't re-request the review from the server */ as_review_set_reviewer_name (review, g_get_real_name ()); as_review_add_metadata (review, "app_id", gs_app_get_id (app)); as_review_add_metadata (review, "user_skey", gs_app_get_metadata_item (app, "ODRS::user_skey")); /* create object with review 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")); json_builder_set_member_name (builder, "locale"); json_builder_add_string_value (builder, gs_plugin_get_locale (plugin)); json_builder_set_member_name (builder, "distro"); json_builder_add_string_value (builder, priv->distro); json_builder_set_member_name (builder, "version"); version = gs_plugin_odrs_sanitize_version (as_review_get_version (review)); json_builder_add_string_value (builder, version); json_builder_set_member_name (builder, "user_display"); json_builder_add_string_value (builder, as_review_get_reviewer_name (review)); json_builder_set_member_name (builder, "summary"); json_builder_add_string_value (builder, as_review_get_summary (review)); json_builder_set_member_name (builder, "description"); json_builder_add_string_value (builder, as_review_get_description (review)); json_builder_set_member_name (builder, "rating"); json_builder_add_int_value (builder, as_review_get_rating (review)); 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); /* clear cache */ if (!gs_plugin_odrs_invalidate_cache (review, error)) return FALSE; /* POST */ uri = g_strdup_printf ("%s/submit", priv->review_server); return gs_plugin_odrs_json_post (gs_plugin_get_soup_session (plugin), uri, data, error); }
static GPtrArray * gs_plugin_odrs_fetch_for_app (GsPlugin *plugin, GsApp *app, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); const gchar *version; guint status_code; g_autofree gchar *cachefn_basename = NULL; g_autofree gchar *cachefn = NULL; g_autofree gchar *data = NULL; g_autofree gchar *uri = NULL; g_autoptr(GFile) cachefn_file = NULL; g_autoptr(GPtrArray) reviews = NULL; g_autoptr(JsonBuilder) builder = NULL; g_autoptr(JsonGenerator) json_generator = NULL; g_autoptr(JsonNode) json_root = NULL; g_autoptr(SoupMessage) msg = NULL; /* look in the cache */ cachefn_basename = g_strdup_printf ("%s.json", gs_app_get_id (app)); cachefn = gs_utils_get_cache_filename ("reviews", cachefn_basename, GS_UTILS_CACHE_FLAG_WRITEABLE, error); if (cachefn == NULL) return NULL; cachefn_file = g_file_new_for_path (cachefn); if (gs_utils_get_file_age (cachefn_file) < ODRS_REVIEW_CACHE_AGE_MAX) { g_autofree gchar *json_data = NULL; if (!g_file_get_contents (cachefn, &json_data, NULL, error)) return NULL; g_debug ("got review data for %s from %s", gs_app_get_id (app), cachefn); return gs_plugin_odrs_parse_reviews (plugin, json_data, -1, error); } /* not always available */ version = gs_app_get_version (app); if (version == NULL) version = "unknown"; /* create object with review 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, "app_id"); json_builder_add_string_value (builder, gs_app_get_id (app)); json_builder_set_member_name (builder, "locale"); json_builder_add_string_value (builder, gs_plugin_get_locale (plugin)); json_builder_set_member_name (builder, "distro"); json_builder_add_string_value (builder, priv->distro); json_builder_set_member_name (builder, "version"); json_builder_add_string_value (builder, version); json_builder_set_member_name (builder, "limit"); json_builder_add_int_value (builder, ODRS_REVIEW_NUMBER_RESULTS_MAX); 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 NULL; uri = g_strdup_printf ("%s/fetch", priv->review_server); msg = soup_message_new (SOUP_METHOD_POST, uri); soup_message_set_request (msg, "application/json; charset=utf-8", SOUP_MEMORY_COPY, data, strlen (data)); status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg); if (status_code != SOUP_STATUS_OK) { if (!gs_plugin_odrs_parse_success (msg->response_body->data, msg->response_body->length, error)) return NULL; /* not sure what to do here */ g_set_error_literal (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_DOWNLOAD_FAILED, "status code invalid"); gs_utils_error_add_unique_id (error, priv->cached_origin); return NULL; } reviews = gs_plugin_odrs_parse_reviews (plugin, msg->response_body->data, msg->response_body->length, error); if (reviews == NULL) return NULL; g_debug ("odrs returned: %s", msg->response_body->data); /* save to the cache */ if (!g_file_set_contents (cachefn, msg->response_body->data, msg->response_body->length, error)) return NULL; /* success */ return g_steal_pointer (&reviews); }
static gboolean get_network_parameters(IpcamIOnvifDiscovery *ionvif_discovery, struct NetworkParameters *param) { JsonBuilder *builder; JsonNode *response; /* Request the Network setting */ 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_add_string_value(builder, "port"); json_builder_end_array(builder); json_builder_end_object(builder); if (onvif_invocate_action(ionvif_discovery, "get_network", json_builder_get_root(builder), &response)) { JsonObject *items_obj; items_obj = json_object_get_object_member(json_node_get_object(response), "items"); if (json_object_has_member(items_obj, "port")) { JsonObject *port_obj = json_object_get_object_member(items_obj, "port"); if (json_object_has_member(port_obj, "http")) { param->http_port = json_object_get_int_member(port_obj, "http"); } } if (json_object_has_member(items_obj, "address")) { JsonObject *addr_obj = json_object_get_object_member(items_obj, "address"); if (json_object_has_member(addr_obj, "ipaddr")) { inet_aton(json_object_get_string_member(addr_obj, "ipaddr"), ¶m->ipaddr); } } } g_object_unref(builder); /* Request the mac address */ 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, "hwaddr"); json_builder_end_array(builder); json_builder_end_object(builder); if (onvif_invocate_action(ionvif_discovery, "get_base_info", json_builder_get_root(builder), &response)) { JsonObject *items_obj; items_obj = json_object_get_object_member(json_node_get_object(response), "items"); if (json_object_has_member(items_obj, "hwaddr")) { int *mac_addr = param->mac_addr; const gchar *mac_addr_str = json_object_get_string_member(items_obj, "hwaddr"); sscanf(mac_addr_str, "%x:%x:%x:%x:%x:%x", &mac_addr[0], &mac_addr[1], &mac_addr[2], &mac_addr[3], &mac_addr[4], &mac_addr[5]); } } g_object_unref(builder); return TRUE; }
static JsonNode * clutter_paint_node_to_json (ClutterPaintNode *node) { JsonBuilder *builder; JsonNode *res; builder = json_builder_new (); json_builder_begin_object (builder); json_builder_set_member_name (builder, "type"); json_builder_add_string_value (builder, g_type_name (G_TYPE_FROM_INSTANCE (node))); json_builder_set_member_name (builder, "name"); json_builder_add_string_value (builder, node->name); json_builder_set_member_name (builder, "node-data"); json_builder_add_value (builder, clutter_paint_node_serialize (node)); json_builder_set_member_name (builder, "operations"); json_builder_begin_array (builder); if (node->operations != NULL) { guint i; for (i = 0; i < node->operations->len; i++) { const ClutterPaintOperation *op; op = &g_array_index (node->operations, ClutterPaintOperation, i); json_builder_begin_object (builder); switch (op->opcode) { case PAINT_OP_TEX_RECT: json_builder_set_member_name (builder, "texrect"); json_builder_begin_array (builder); json_builder_add_double_value (builder, op->op.texrect[0]); json_builder_add_double_value (builder, op->op.texrect[1]); json_builder_add_double_value (builder, op->op.texrect[2]); json_builder_add_double_value (builder, op->op.texrect[3]); json_builder_add_double_value (builder, op->op.texrect[4]); json_builder_add_double_value (builder, op->op.texrect[5]); json_builder_add_double_value (builder, op->op.texrect[6]); json_builder_add_double_value (builder, op->op.texrect[7]); json_builder_end_array (builder); break; case PAINT_OP_PATH: json_builder_set_member_name (builder, "path"); json_builder_add_int_value (builder, (gint64) op->op.path); break; case PAINT_OP_PRIMITIVE: json_builder_set_member_name (builder, "primitive"); json_builder_add_int_value (builder, (gint64) op->op.primitive); break; case PAINT_OP_INVALID: break; } json_builder_end_object (builder); } } json_builder_end_array (builder); json_builder_set_member_name (builder, "children"); json_builder_begin_array (builder); if (node->first_child != NULL) { ClutterPaintNode *child; for (child = node->first_child; child != NULL; child = child->next_sibling) { JsonNode *n = clutter_paint_node_to_json (child); json_builder_add_value (builder, n); } } json_builder_end_array (builder); json_builder_end_object (builder); res = json_builder_get_root (builder); g_object_unref (builder); return res; }
static gchar* do_get_action(IpcamIAjax *iajax, GList *item_list) { JsonBuilder *builder = NULL; JsonNode *res_node = NULL; GList *item; JsonGenerator *generator; GList *user; GList *users = ipcam_iajax_get_users(iajax); users = g_list_sort(users, (GCompareFunc)g_strcmp0); builder = json_builder_new(); json_builder_begin_object(builder); json_builder_set_member_name(builder, "items"); json_builder_begin_array(builder); for (user = g_list_first(users); user; user = g_list_next(user)) { json_builder_begin_object(builder); json_builder_set_member_name(builder, "username"); json_builder_add_string_value(builder, user->data); if (item_list) { for (item = g_list_first(item_list); item; item = g_list_next(item)) { if (g_str_equal(item->data, "password")) { gchar *pwd = ipcam_iajax_get_user_pwd(iajax, user->data); json_builder_set_member_name(builder, "password"); json_builder_add_string_value(builder, pwd); } else if (g_str_equal(item->data, "role")) { gchar *role = ipcam_iajax_get_user_role(iajax, user->data); json_builder_set_member_name(builder, "role"); json_builder_add_string_value(builder, role); g_free(role); } else { g_warn_if_reached(); } } } json_builder_end_object(builder); } g_list_free_full(users, g_free); json_builder_end_array(builder); json_builder_end_object(builder); generator = json_generator_new(); 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; }