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

	time_t	t;
	size_t	s;

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

	if (ti)
		add_thread_info (bob, ti);

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

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

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

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

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

	add_flags (bob, msg);

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

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

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

	g_clear_object (&bob);

	return node;
}
Example #2
0
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;
}
Example #3
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;
}
Example #4
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;
}
Example #5
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;
}
Example #6
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;
}
Example #7
0
static GBytes *
_json_builder_to_bytes (CockpitDBusJson1 *self,
                        JsonBuilder *builder)
{
  JsonNode *root;
  gsize length;
  gchar *ret;

  root = json_builder_get_root (builder);
  ret = cockpit_json_write (root, &length);
  json_node_free (root);

  return g_bytes_new_take (ret, length);
}
Example #8
0
static JsonNode *query_network_address(IpcamIAjax *iajax)
{
	const gchar *token = ipcam_base_app_get_config(IPCAM_BASE_APP(iajax), "token");
	IpcamRequestMessage *req_msg;
	IpcamMessage *resp_msg;
    JsonBuilder *builder;
	JsonNode *addr_node = NULL;
	gboolean ret;

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

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

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

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

		g_object_unref(resp_msg);
	}

	g_object_unref(req_msg);
	g_object_unref(builder);

	return addr_node;
}
Example #9
0
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;
}
Example #10
0
static void
write_builder (CockpitDBusJson *self,
               JsonBuilder *builder)
{
  GBytes *bytes;
  JsonNode *root;
  gsize length;
  gchar *ret;

  json_builder_end_object (builder);

  root = json_builder_get_root (builder);
  ret = cockpit_json_write (root, &length);
  json_node_free (root);

  bytes = g_bytes_new_take (ret, length);
  cockpit_channel_send (COCKPIT_CHANNEL (self), bytes);
  g_bytes_unref (bytes);
}
Example #11
0
static gboolean
output_json(MuMsg *msg, MuMsgIter *iter, MuConfig *opts, GError **err) {
        JsonBuilder *builder;
  JsonNode *root;
  JsonGenerator *gen;
  gchar *json_str;

        builder = get_message_json (msg);
  gen = json_generator_new ();
  root = json_builder_get_root (builder);
  json_generator_set_root (gen, root);

  json_str = json_generator_to_data (gen, NULL);
        g_print ("%s, ", json_str);
        g_free(json_str);

  json_node_free (root);
  g_object_unref (gen);
  g_object_unref (builder);
  return TRUE;
}
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;
}
Example #13
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_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;
}
Example #15
0
static void save_account_info(dt_storage_gphoto_gui_data_t *ui, dt_gphoto_account_info_t *accountinfo)
{
  dt_gphoto_context_t *ctx = ui->gphoto_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, "userid");
  json_builder_add_string_value(builder, accountinfo->id);
  json_builder_set_member_name(builder, "token");
  json_builder_add_string_value(builder, accountinfo->token);
  json_builder_set_member_name(builder, "refresh_token");
  json_builder_add_string_value(builder, accountinfo->refresh_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(GPHOTO_STORAGE);
  g_hash_table_insert(table, g_strdup(accountinfo->id), data);
  dt_pwstorage_set(GPHOTO_STORAGE, table);

  g_hash_table_destroy(table);
}
static gboolean
send_review_request (GsPlugin *plugin,
		     const gchar *method, const gchar *path,
		     JsonBuilder *request,
		     gboolean do_sign,
		     guint *status_code,
		     JsonParser **result,
		     GCancellable *cancellable, GError **error)
{
	g_autofree gchar *uri = NULL;
	g_autoptr(SoupMessage) msg = NULL;

	uri = g_strdup_printf ("%s%s",
			       UBUNTU_REVIEWS_SERVER, path);
	msg = soup_message_new (method, uri);

	if (request != NULL) {
		g_autoptr(JsonGenerator) generator = NULL;
		gchar *data;
		gsize length;

		generator = json_generator_new ();
		json_generator_set_root (generator, json_builder_get_root (request));
		data = json_generator_to_data (generator, &length);
		soup_message_set_request (msg, "application/json", SOUP_MEMORY_TAKE, data, length);
	}

	if (do_sign)
		sign_message (msg,
			      OA_PLAINTEXT,
			      gs_plugin_get_auth_by_id (plugin, "ubuntuone"));

	*status_code = soup_session_send_message (gs_plugin_get_soup_session (plugin), msg);

	if (*status_code == SOUP_STATUS_UNAUTHORIZED) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_AUTH_REQUIRED,
				     "Requires authentication with @ubuntuone");
		return FALSE;
	}

	if (result != NULL) {
		g_autoptr(JsonParser) parser = NULL;
		const gchar *content_type;

		content_type = soup_message_headers_get_content_type (msg->response_headers, NULL);
		if (g_strcmp0 (content_type, "application/json") != 0) {
			g_set_error (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_FAILED,
				     "Got unknown content type %s from reviews.ubuntu.com",
				     content_type);
			return FALSE;
		}

		parser = json_parser_new ();
		if (!json_parser_load_from_data (parser, msg->response_body->data, -1, error)) {
			return FALSE;
		}
		*result = g_steal_pointer (&parser);
	}

	return TRUE;
}
Example #17
0
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;
  }
}
Example #18
0
/* Save state */
static gboolean save_state(gpointer data) {
    queue_status qs;
    gboolean repeat, shuffle;
    int cur_track;
    GArray* tracks = NULL;

    JsonBuilder* jb = NULL;
    JsonGenerator* gen = NULL;
    gchar* out = NULL;

    GError* err = NULL;

    g_debug("savestate: starting to save the current state...");

    /* Get data about the current state */
    qs = queue_get_status(NULL, &cur_track, NULL);
    tracks = queue_tracks();
    repeat = queue_get_repeat();
    shuffle = queue_get_shuffle();

    /* Save them in JSON */
    jb = json_builder_new();
    json_builder_begin_object(jb);

    json_builder_set_member_name(jb, "status");
    switch (qs) {
    case STOPPED:
        json_builder_add_string_value(jb, "stopped"); break;
    case PLAYING:
        json_builder_add_string_value(jb, "playing"); break;
    case PAUSED:
        json_builder_add_string_value(jb, "paused"); break;
    default:
        g_warning("savestate: bad queue_status value: %d", qs);
        goto savestate_clean;
    }

    json_builder_set_member_name(jb, "repeat");
    json_builder_add_boolean_value(jb, repeat);

    json_builder_set_member_name(jb, "shuffle");
    json_builder_add_boolean_value(jb, shuffle);

    json_builder_set_member_name(jb, "current_track");
    json_builder_add_int_value(jb, cur_track);

    json_builder_set_member_name(jb, "tracks");
    json_builder_begin_array(jb);

    int i;
    for (i=0; i < tracks->len; i++) {
        sp_track* tr = g_array_index(tracks, sp_track*, i);
        if (!sp_track_is_loaded(tr)) {
            g_warning("savestate: queue track %d is not loaded", i);
            goto savestate_clean;
        }

        sp_link* lnk = sp_link_create_from_track(tr, 0);
        gchar uri[1024];
        int uri_len = sp_link_as_string(lnk, uri, 1024);
        sp_link_release(lnk);
        if (uri_len >= 1024) {
            g_warning("savestate: URI too long for track %d", i);
            goto savestate_clean;
        }

        json_builder_add_string_value(jb, uri);
    }
    json_builder_end_array(jb);
    json_builder_end_object(jb);

    /* Store JSON to file */
    gen = json_generator_new();
    json_generator_set_root(gen, json_builder_get_root(jb));
    out = json_generator_to_data(gen, NULL);

    if (g_file_set_contents(g_state_file_path, out, -1, &err))
        g_debug("savestate: state saved to %s.", g_state_file_path);
    else
        g_warning("savestate: unable to dump status to file: %s", err->message);

 savestate_clean:
    if (tracks)
        g_array_free(tracks, TRUE);
    if (gen)
        g_object_unref(gen);
    if (jb)
        g_object_unref(jb);
    if (out)
        g_free(out);
    return FALSE;
}
Example #19
0
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);
}
Example #20
0
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);
}
Example #21
0
void
snarf_alert_add_flow_v4(snarf_alert_t *alert,
                        uint64_t stime, uint32_t elapsed,
                        uint32_t sip, uint32_t dip,
                        uint16_t sport, uint16_t dport,
                        uint8_t proto,
                        uint32_t packets, uint32_t bytes,
                        uint8_t flags, uint8_t flags_initial,
                        uint16_t application_id,
                        char *sensor_name,
                        char *flow_class, char *flow_type)
{

JsonBuilder *builder;

// Populate the envelope
builder=json_builder_new();
json_builder_begin_array(builder);
json_builder_begin_object(builder);

json_builder_set_member_name(builder,"stime");
char jsontime[32];
time_t sectime = stime / (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_set_member_name(builder,"elapsed");
json_builder_add_int_value(builder,elapsed);

struct in_addr ip;

ip.s_addr=htonl(sip);
json_builder_set_member_name(builder,"sip");
json_builder_add_string_value(builder,inet_ntoa(ip));

ip.s_addr=htonl(dip);
json_builder_set_member_name(builder,"dip");
json_builder_add_string_value(builder,inet_ntoa(ip));

json_builder_set_member_name(builder,"sport");
json_builder_add_int_value(builder,sport);

json_builder_set_member_name(builder,"dport");
json_builder_add_int_value(builder,dport);

json_builder_set_member_name(builder,"proto");
json_builder_add_int_value(builder,proto);

json_builder_set_member_name(builder,"packets");
json_builder_add_int_value(builder,packets);

json_builder_set_member_name(builder,"bytes");
json_builder_add_int_value(builder,bytes);

// flags
json_builder_set_member_name(builder,"flags");
GString *flag_string = snarf_alert_flags_to_string(flags);
json_builder_add_string_value(builder,flag_string->str);
g_string_free(flag_string,TRUE);


// flags initial
json_builder_set_member_name(builder,"flags_initial");
GString *flag_initial_string = snarf_alert_flags_to_string(flags_initial);
json_builder_add_string_value(builder,flag_initial_string->str);
//g_print(flag_initial_string);
g_string_free(flag_initial_string,TRUE);

// application id
json_builder_set_member_name(builder,"application_id");
json_builder_add_int_value(builder,application_id);

// sensor
json_builder_set_member_name(builder,"sensor_name");
json_builder_add_string_value(builder,sensor_name);

// flow class
json_builder_set_member_name(builder,"flow_class");
json_builder_add_string_value(builder,flow_class);

// flow type
json_builder_set_member_name(builder,"flow_type");
json_builder_add_string_value(builder,flow_type);

json_builder_end_object(builder);
json_builder_end_array(builder);
//json_builder_end_object(builder);

JsonNode *root = json_builder_get_root(builder);

JsonObject * rootobj = json_node_get_object (alert->msg);
JsonObject * bodyobj = json_object_get_object_member(rootobj,"body");
json_object_set_member(bodyobj,"flow",root);

}
Example #22
0
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"), &param->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;
}
Example #23
0
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;
}
Example #24
0
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;
}
Example #25
0
static void kkc_user_rule_write_files (KkcRuleMetadata* parent, const gchar* path, const gchar* name, GError** error) {
	JsonGenerator* generator = NULL;
	JsonGenerator* _tmp0_ = NULL;
	JsonGenerator* _tmp1_ = NULL;
	const gchar* _tmp2_ = NULL;
	JsonBuilder* metadata_builder = NULL;
	KkcRuleMetadata* _tmp3_ = NULL;
	const gchar* _tmp4_ = NULL;
	JsonBuilder* _tmp5_ = NULL;
	JsonGenerator* _tmp6_ = NULL;
	JsonBuilder* _tmp7_ = NULL;
	JsonNode* _tmp8_ = NULL;
	JsonNode* _tmp9_ = NULL;
	gchar* metadata_filename = NULL;
	const gchar* _tmp10_ = NULL;
	gchar* _tmp11_ = NULL;
	JsonGenerator* _tmp12_ = NULL;
	const gchar* _tmp13_ = NULL;
	gchar* keymap_path = NULL;
	const gchar* _tmp14_ = NULL;
	gchar* _tmp15_ = NULL;
	const gchar* _tmp16_ = NULL;
	GEnumClass* enum_class = NULL;
	GTypeClass* _tmp17_ = NULL;
	gchar* rom_kana_path = NULL;
	const gchar* _tmp46_ = NULL;
	gchar* _tmp47_ = NULL;
	const gchar* _tmp48_ = NULL;
	JsonBuilder* rom_kana_builder = NULL;
	KkcRuleMetadata* _tmp49_ = NULL;
	JsonBuilder* _tmp50_ = NULL;
	JsonGenerator* _tmp51_ = NULL;
	JsonBuilder* _tmp52_ = NULL;
	JsonNode* _tmp53_ = NULL;
	JsonNode* _tmp54_ = NULL;
	gchar* rom_kana_filename = NULL;
	const gchar* _tmp55_ = NULL;
	gchar* _tmp56_ = NULL;
	JsonGenerator* _tmp57_ = NULL;
	const gchar* _tmp58_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_if_fail (parent != NULL);
	g_return_if_fail (path != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = json_generator_new ();
	generator = _tmp0_;
	_tmp1_ = generator;
	json_generator_set_pretty (_tmp1_, TRUE);
	_tmp2_ = path;
	g_mkdir_with_parents (_tmp2_, 448);
	_tmp3_ = parent;
	_tmp4_ = name;
	_tmp5_ = kkc_user_rule_create_metadata (_tmp3_, _tmp4_);
	metadata_builder = _tmp5_;
	_tmp6_ = generator;
	_tmp7_ = metadata_builder;
	_tmp8_ = json_builder_get_root (_tmp7_);
	_tmp9_ = _tmp8_;
	json_generator_set_root (_tmp6_, _tmp9_);
	__vala_JsonNode_free0 (_tmp9_);
	_tmp10_ = path;
	_tmp11_ = g_build_filename (_tmp10_, "metadata.json", NULL);
	metadata_filename = _tmp11_;
	_tmp12_ = generator;
	_tmp13_ = metadata_filename;
	json_generator_to_file (_tmp12_, _tmp13_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_free0 (metadata_filename);
		_g_object_unref0 (metadata_builder);
		_g_object_unref0 (generator);
		return;
	}
	_tmp14_ = path;
	_tmp15_ = g_build_filename (_tmp14_, "keymap", NULL);
	keymap_path = _tmp15_;
	_tmp16_ = keymap_path;
	g_mkdir_with_parents (_tmp16_, 448);
	_tmp17_ = g_type_class_ref (KKC_TYPE_INPUT_MODE);
	enum_class = (GEnumClass*) _tmp17_;
	{
		gint i = 0;
		GEnumClass* _tmp18_ = NULL;
		gint _tmp19_ = 0;
		_tmp18_ = enum_class;
		_tmp19_ = _tmp18_->minimum;
		i = _tmp19_;
		{
			gboolean _tmp20_ = FALSE;
			_tmp20_ = TRUE;
			while (TRUE) {
				gint _tmp22_ = 0;
				GEnumClass* _tmp23_ = NULL;
				gint _tmp24_ = 0;
				GEnumValue* enum_value = NULL;
				GEnumClass* _tmp25_ = NULL;
				gint _tmp26_ = 0;
				GEnumValue* _tmp27_ = NULL;
				GEnumValue* _tmp28_ = NULL;
				JsonBuilder* keymap_builder = NULL;
				KkcRuleMetadata* _tmp29_ = NULL;
				GEnumValue* _tmp30_ = NULL;
				const gchar* _tmp31_ = NULL;
				JsonBuilder* _tmp32_ = NULL;
				JsonGenerator* _tmp33_ = NULL;
				JsonBuilder* _tmp34_ = NULL;
				JsonNode* _tmp35_ = NULL;
				JsonNode* _tmp36_ = NULL;
				gchar* keymap_filename = NULL;
				const gchar* _tmp37_ = NULL;
				GEnumValue* _tmp38_ = NULL;
				const gchar* _tmp39_ = NULL;
				gchar* _tmp40_ = NULL;
				gchar* _tmp41_ = NULL;
				gchar* _tmp42_ = NULL;
				gchar* _tmp43_ = NULL;
				JsonGenerator* _tmp44_ = NULL;
				const gchar* _tmp45_ = NULL;
				if (!_tmp20_) {
					gint _tmp21_ = 0;
					_tmp21_ = i;
					i = _tmp21_ + 1;
				}
				_tmp20_ = FALSE;
				_tmp22_ = i;
				_tmp23_ = enum_class;
				_tmp24_ = _tmp23_->maximum;
				if (!(_tmp22_ <= _tmp24_)) {
					break;
				}
				_tmp25_ = enum_class;
				_tmp26_ = i;
				_tmp27_ = g_enum_get_value (_tmp25_, _tmp26_);
				_tmp28_ = __g_enum_value_dup0 (_tmp27_);
				enum_value = _tmp28_;
				_tmp29_ = parent;
				_tmp30_ = enum_value;
				_tmp31_ = (*_tmp30_).value_nick;
				_tmp32_ = kkc_user_rule_create_keymap (_tmp29_, _tmp31_, NULL);
				keymap_builder = _tmp32_;
				_tmp33_ = generator;
				_tmp34_ = keymap_builder;
				_tmp35_ = json_builder_get_root (_tmp34_);
				_tmp36_ = _tmp35_;
				json_generator_set_root (_tmp33_, _tmp36_);
				__vala_JsonNode_free0 (_tmp36_);
				_tmp37_ = keymap_path;
				_tmp38_ = enum_value;
				_tmp39_ = (*_tmp38_).value_nick;
				_tmp40_ = g_strdup_printf ("%s.json", _tmp39_);
				_tmp41_ = _tmp40_;
				_tmp42_ = g_build_filename (_tmp37_, _tmp41_, NULL);
				_tmp43_ = _tmp42_;
				_g_free0 (_tmp41_);
				keymap_filename = _tmp43_;
				_tmp44_ = generator;
				_tmp45_ = keymap_filename;
				json_generator_to_file (_tmp44_, _tmp45_, &_inner_error_);
				if (G_UNLIKELY (_inner_error_ != NULL)) {
					g_propagate_error (error, _inner_error_);
					_g_free0 (keymap_filename);
					_g_object_unref0 (keymap_builder);
					_g_free0 (enum_value);
					_g_type_class_unref0 (enum_class);
					_g_free0 (keymap_path);
					_g_free0 (metadata_filename);
					_g_object_unref0 (metadata_builder);
					_g_object_unref0 (generator);
					return;
				}
				_g_free0 (keymap_filename);
				_g_object_unref0 (keymap_builder);
				_g_free0 (enum_value);
			}
		}
	}
	_tmp46_ = path;
	_tmp47_ = g_build_filename (_tmp46_, "rom-kana", NULL);
	rom_kana_path = _tmp47_;
	_tmp48_ = rom_kana_path;
	g_mkdir_with_parents (_tmp48_, 448);
	_tmp49_ = parent;
	_tmp50_ = kkc_user_rule_create_rom_kana (_tmp49_, "default");
	rom_kana_builder = _tmp50_;
	_tmp51_ = generator;
	_tmp52_ = rom_kana_builder;
	_tmp53_ = json_builder_get_root (_tmp52_);
	_tmp54_ = _tmp53_;
	json_generator_set_root (_tmp51_, _tmp54_);
	__vala_JsonNode_free0 (_tmp54_);
	_tmp55_ = rom_kana_path;
	_tmp56_ = g_build_filename (_tmp55_, "default.json", NULL);
	rom_kana_filename = _tmp56_;
	_tmp57_ = generator;
	_tmp58_ = rom_kana_filename;
	json_generator_to_file (_tmp57_, _tmp58_, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_free0 (rom_kana_filename);
		_g_object_unref0 (rom_kana_builder);
		_g_free0 (rom_kana_path);
		_g_type_class_unref0 (enum_class);
		_g_free0 (keymap_path);
		_g_free0 (metadata_filename);
		_g_object_unref0 (metadata_builder);
		_g_object_unref0 (generator);
		return;
	}
	_g_free0 (rom_kana_filename);
	_g_object_unref0 (rom_kana_builder);
	_g_free0 (rom_kana_path);
	_g_type_class_unref0 (enum_class);
	_g_free0 (keymap_path);
	_g_free0 (metadata_filename);
	_g_object_unref0 (metadata_builder);
	_g_object_unref0 (generator);
}
Example #26
0
static void ipcam_itrain_before_start(IpcamBaseService *base_service)
{
    IpcamITrain *itrain = IPCAM_ITRAIN(base_service);
    IpcamITrainPrivate *priv = ipcam_itrain_get_instance_private(itrain);
    const gchar *addr = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:address");
    const gchar *port = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:port");
	const gchar *osd_port = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "itrain:osd-port");
	JsonBuilder *builder;
	const gchar *token = ipcam_base_app_get_config(IPCAM_BASE_APP(itrain), "token");
	IpcamRequestMessage *req_msg;

    if (!addr || !port)
    {
        g_critical("address and port must be specified.\n");
        return;
    }
    priv->itrain_server = g_object_new(IPCAM_TYPE_ITRAIN_SERVER,
                                       "itrain", itrain,
                                       "address", addr,
                                       "port", strtoul(port, NULL, 0),
                                       "osd-port", strtoul(osd_port, NULL, 0),
                                       NULL);

    ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "video_occlusion_event", IPCAM_TYPE_ITRAIN_EVENT_HANDLER);
    ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "set_base_info", IPCAM_TYPE_ITRAIN_EVENT_HANDLER);
    ipcam_base_app_register_notice_handler(IPCAM_BASE_APP(itrain), "set_szyc", IPCAM_TYPE_ITRAIN_EVENT_HANDLER);

	/* Request the Base Information */
	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, "device_name");
	json_builder_add_string_value(builder, "comment");
	json_builder_add_string_value(builder, "location");
	json_builder_add_string_value(builder, "hardware");
	json_builder_add_string_value(builder, "firmware");
	json_builder_add_string_value(builder, "manufacturer");
	json_builder_add_string_value(builder, "model");
	json_builder_add_string_value(builder, "serial");
    json_builder_add_string_value(builder, "device_type");
	json_builder_end_array(builder);
	json_builder_end_object(builder);
	req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE,
	                       "action", "get_base_info",
	                       "body", json_builder_get_root(builder),
	                       NULL);
	ipcam_base_app_send_message(IPCAM_BASE_APP(itrain), IPCAM_MESSAGE(req_msg),
	                            "iconfig", token,
	                            base_info_message_handler, 60);
	g_object_unref(req_msg);
	g_object_unref(builder);

    /* Request the SZYC Information */
	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, "train_num");
	json_builder_add_string_value(builder, "carriage_num");
	json_builder_add_string_value(builder, "position_num");
	json_builder_end_array(builder);
	json_builder_end_object(builder);
	req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE,
	                       "action", "get_szyc",
	                       "body", json_builder_get_root(builder),
	                       NULL);
	ipcam_base_app_send_message(IPCAM_BASE_APP(itrain), IPCAM_MESSAGE(req_msg),
	                            "iconfig", token,
	                            szyc_message_handler, 60);
	g_object_unref(req_msg);
	g_object_unref(builder);
}
Example #27
0
/**
         * Save keymap for given input mode.
         *
         * @param input_mode input mode
         */
void kkc_user_rule_write (KkcUserRule* self, KkcInputMode input_mode, GError** error) {
	GEnumClass* enum_class = NULL;
	GTypeClass* _tmp0_ = NULL;
	gchar* keymap_name = NULL;
	KkcInputMode _tmp1_ = 0;
	GEnumValue* _tmp2_ = NULL;
	const gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	gchar* keymap_path = NULL;
	const gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	JsonGenerator* generator = NULL;
	JsonGenerator* _tmp7_ = NULL;
	JsonBuilder* builder = NULL;
	KkcRuleMetadata* _tmp8_ = NULL;
	KkcInputMode _tmp9_ = 0;
	KkcKeymap* _tmp10_ = NULL;
	KkcKeymap* _tmp11_ = NULL;
	JsonBuilder* _tmp12_ = NULL;
	JsonBuilder* _tmp13_ = NULL;
	JsonNode* _tmp14_ = NULL;
	JsonNode* _tmp15_ = NULL;
	gchar* filename = NULL;
	gchar* _tmp16_ = NULL;
	gchar* _tmp17_ = NULL;
	gchar* _tmp18_ = NULL;
	gchar* _tmp19_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = g_type_class_ref (KKC_TYPE_INPUT_MODE);
	enum_class = (GEnumClass*) _tmp0_;
	_tmp1_ = input_mode;
	_tmp2_ = g_enum_get_value (enum_class, (gint) _tmp1_);
	_tmp3_ = (*_tmp2_).value_nick;
	_tmp4_ = g_strdup (_tmp3_);
	keymap_name = _tmp4_;
	_tmp5_ = self->priv->path;
	_tmp6_ = g_build_filename (_tmp5_, "keymap", NULL);
	keymap_path = _tmp6_;
	g_mkdir_with_parents (keymap_path, 448);
	_tmp7_ = json_generator_new ();
	generator = _tmp7_;
	json_generator_set_pretty (generator, TRUE);
	_tmp8_ = self->priv->parent;
	_tmp9_ = input_mode;
	_tmp10_ = kkc_rule_get_keymap ((KkcRule*) self, _tmp9_);
	_tmp11_ = _tmp10_;
	_tmp12_ = kkc_user_rule_create_keymap (_tmp8_, keymap_name, _tmp11_);
	_tmp13_ = _tmp12_;
	_g_object_unref0 (_tmp11_);
	builder = _tmp13_;
	_tmp14_ = json_builder_get_root (builder);
	_tmp15_ = _tmp14_;
	json_generator_set_root (generator, _tmp15_);
	__vala_JsonNode_free0 (_tmp15_);
	_tmp16_ = g_strdup_printf ("%s.json", keymap_name);
	_tmp17_ = _tmp16_;
	_tmp18_ = g_build_filename (keymap_path, _tmp17_, NULL);
	_tmp19_ = _tmp18_;
	_g_free0 (_tmp17_);
	filename = _tmp19_;
	json_generator_to_file (generator, filename, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_free0 (filename);
		_g_object_unref0 (builder);
		_g_object_unref0 (generator);
		_g_free0 (keymap_path);
		_g_free0 (keymap_name);
		_g_type_class_unref0 (enum_class);
		return;
	}
	_g_free0 (filename);
	_g_object_unref0 (builder);
	_g_object_unref0 (generator);
	_g_free0 (keymap_path);
	_g_free0 (keymap_name);
	_g_type_class_unref0 (enum_class);
}