static GkmXdgTrust*
create_trust_for_reference (GkmModule *module, GkmManager *manager,
                            CK_ATTRIBUTE_PTR serial, CK_ATTRIBUTE_PTR issuer)
{
	GkmXdgTrust *trust;
	GNode *asn, *ref, *node;
	GBytes *bytes;

	asn = egg_asn1x_create (xdg_asn1_tab, "trust-1");
	g_return_val_if_fail (asn, NULL);

	ref = egg_asn1x_node (asn, "reference", NULL);
	node = egg_asn1x_node (ref, "certReference", NULL);

	egg_asn1x_set_choice (ref, node);
	bytes = g_bytes_new (serial->pValue, serial->ulValueLen);
	egg_asn1x_set_integer_as_raw (egg_asn1x_node (node, "serialNumber", NULL), bytes);
	g_bytes_unref (bytes);

	bytes = g_bytes_new (issuer->pValue, issuer->ulValueLen);
	egg_asn1x_set_any_raw (egg_asn1x_node (node, "issuer", NULL), bytes);
	g_bytes_unref (bytes);

	trust = g_object_new (GKM_XDG_TYPE_TRUST, "module", module, "manager", manager, NULL);
	trust->pv->asn = asn;

	/* Encode it, so we have read access to all the data */
	trust->pv->bytes = egg_asn1x_encode (asn, NULL);
	if (!trust->pv->bytes) {
		g_warning ("created invalid trust object: %s", egg_asn1x_message (asn));
		return NULL;
	}

	return trust;
}
Beispiel #2
0
static GBytes *
substitute_json_string (const gchar *variable,
                        gpointer user_data)
{
  const gchar *value;
  JsonObject *options = user_data;
  if (options && cockpit_json_get_string (options, variable, "", &value))
    return g_bytes_new (value, strlen (value));
  else if (options)
    g_message ("Couldn't get argument for bridge: got invalid value for '%s'", variable);

  return g_bytes_new ("", 0);
}
gboolean
_gum_duk_parse_bytes (duk_context * ctx,
                      duk_idx_t index,
                      GBytes ** bytes)
{
  gpointer data;
  duk_size_t size;

  data = duk_get_buffer_data (ctx, index, &size);
  if (data != NULL)
  {
    *bytes = g_bytes_new (data, size);
    return TRUE;
  }
  else if (duk_is_array (ctx, index))
  {
    duk_size_t i;

    duk_get_prop_string (ctx, index, "length");
    size = duk_get_uint (ctx, -1);
    duk_pop (ctx);

    if (size >= GUM_MAX_JS_BYTE_ARRAY_LENGTH)
      return FALSE;

    data = g_malloc (size);

    for (i = 0; i != size; i++)
    {
      duk_get_prop_index (ctx, index, (duk_uarridx_t) i);
      ((guint8 *) data)[i] = duk_get_uint (ctx, -1) & 0xff;
      duk_pop (ctx);
    }

    *bytes = g_bytes_new_take (data, size);
    return TRUE;
  }
  else if (duk_is_null_or_undefined (ctx, index) ||
      duk_is_boolean (ctx, index) ||
      duk_is_number (ctx, index) ||
      duk_is_nan (ctx, index) ||
      duk_is_string (ctx, index) ||
      duk_is_function (ctx, index))
  {
    return FALSE;
  }

  *bytes = g_bytes_new (NULL, 0);
  return TRUE;
}
static int
g_tls_server_connection_gnutls_db_store (void            *user_data,
					 gnutls_datum_t   key,
					 gnutls_datum_t   data)
{
  GBytes *session_id, *session_data;

  session_id = g_bytes_new (key.data, key.size);
  session_data = g_bytes_new (data.data, data.size);
  g_tls_backend_gnutls_store_session (GNUTLS_SERVER, session_id, session_data);
  g_bytes_unref (session_id);
  g_bytes_unref (session_data);

  return 0;
}
static gboolean
ssid_transform_from_entry (GBinding     *binding,
                           const GValue *source_value,
                           GValue       *target_value,
                           gpointer      user_data)
{
	NMSettingWireless *s_wireless = user_data;
	const char *text;
	GBytes *old_ssid, *ssid;
	char *utf8;

	text = g_value_get_string (source_value);

	old_ssid = nm_setting_wireless_get_ssid (s_wireless);
	if (old_ssid)
		utf8 = nm_utils_ssid_to_utf8 (g_bytes_get_data (old_ssid, NULL),
		                              g_bytes_get_size (old_ssid));
	else
		utf8 = g_strdup ("");

	if (!g_strcmp0 (text, utf8)) {
		g_free (utf8);
		return FALSE;
	}
	g_free (utf8);

	ssid = g_bytes_new (text, strlen (text));
	g_value_take_boxed (target_value, ssid);
	return TRUE;
}
Beispiel #6
0
void wk_html_close(WkHtml *html)
{
	if (!html->priv->initialised) {
		html->priv->initialised = TRUE;
#ifndef USE_WEBKIT2
		webkit_web_view_set_maintains_back_forward_list(WEBKIT_WEB_VIEW(html), FALSE);
#endif
	}

#ifdef USE_WEBKIT2
	GBytes *html_bytes;
	html_bytes = g_bytes_new(html->priv->content, strlen(html->priv->content));

	webkit_web_view_load_bytes(WEBKIT_WEB_VIEW(html),
				   html_bytes,
				   html->priv->mime,
				   NULL,
				   html->priv->base_uri);

	g_bytes_unref(html_bytes);
#else
	webkit_web_view_load_string(WEBKIT_WEB_VIEW(html),
				    html->priv->content,
				    html->priv->mime,
				    NULL, html->priv->base_uri);
#endif

	g_free(html->priv->content);
	html->priv->content = NULL;
	g_free(html->priv->mime);
	html->priv->mime = NULL;
}
Beispiel #7
0
/**
 * CacheUtilBytesFromString:
 * @value: String containing an even number of hex-digits.
 * @result: (out): Raw bytes used to encode the hex value.
 *
 * Returns: #TRUE if @result was modified or #FALSE if the string was not valid
 * hex-encoded bytes.
 */
gboolean CacheUtilBytesFromString(const gchar *value, GBytes **result) {
  g_assert(result);
  if (!value)
    return FALSE;

  gsize value_len = strlen(value);
  gsize result_len = value_len / 2;
  guint8 result_data[result_len];

  // Hex strings must have a length that's a multiple of two.
  if (value_len & 0x01)
    return FALSE;

  for (guint i = 0; i < value_len; i += 2) {
    gint nibble1 = g_ascii_xdigit_value(value[i]);
    gint nibble2 = g_ascii_xdigit_value(value[i + 1]);
    if (nibble1 < 0 || nibble2 < 0) {
      return FALSE;
    }
    result_data[i >> 1] = (nibble1 << 4) | nibble2;
  }

  *result = g_bytes_new(result_data, result_len);
  return TRUE;
}
static gnutls_datum_t
g_tls_server_connection_gnutls_db_retrieve (void            *user_data,
					    gnutls_datum_t   key)
{
  GBytes *session_id, *session_data;
  gnutls_datum_t data;

  session_id = g_bytes_new (key.data, key.size);
  session_data = g_tls_backend_gnutls_lookup_session (GNUTLS_SERVER, session_id);
  g_bytes_unref (session_id);

  if (session_data)
    {
      data.size = g_bytes_get_size (session_data);
      data.data = gnutls_malloc (data.size);
      memcpy (data.data, g_bytes_get_data (session_data, NULL), data.size);
      g_bytes_unref (session_data);
    }
  else
    {
      data.size = 0;
      data.data = NULL;
    }

  return data;
}
Beispiel #9
0
static gboolean
handle_stdin (GIOChannel * ch, GIOCondition cond, gpointer d)
{
  gchar *buf;
  GBytes *data;
  GError *err = NULL;

  switch (g_io_channel_read_line (ch, &buf, NULL, NULL, &err))
    {
    case G_IO_STATUS_NORMAL:
      g_string_append (inbuf, buf);
      return TRUE;

    case G_IO_STATUS_ERROR:
      g_printerr ("yad_html_handle_stdin(): %s\n", err->message);
      g_error_free (err);
      return FALSE;

    case G_IO_STATUS_EOF:
      data = g_bytes_new (inbuf->str, inbuf->len);
      g_string_free (inbuf, TRUE);
      webkit_web_view_load_bytes (view, data, options.html_data.mime, options.html_data.encoding, NULL);
      g_bytes_unref (data);
      return FALSE;

    case G_IO_STATUS_AGAIN:
      return TRUE;
    }

  return FALSE;
}
Beispiel #10
0
static GBytes *
expand_variables (const gchar *variable,
                  gpointer user_data)
{
  ExpandInfo *expand = user_data;
  CockpitPackage *package;
  gchar *val;

  package = g_hash_table_lookup (expand->listing, variable);
  if (package)
    {
      if (package->checksum)
        {
          return g_bytes_new_with_free_func (package->checksum, strlen (package->checksum),
                                             cockpit_package_unref,
                                             cockpit_package_ref (package));
        }
      else if (expand->host)
        {
          val = g_strdup_printf ("%s@%s", package->name, expand->host);
          return g_bytes_new_take (val, strlen (val));
        }
      else
        {
          return g_bytes_new_with_free_func (package->name, strlen (package->name),
                                             cockpit_package_unref,
                                             cockpit_package_ref (package));
        }
    }
  else
    {
      return g_bytes_new (variable, strlen (variable));
    }
}
Beispiel #11
0
void
test_upload_ok (int errors, int size, ...)
{
    GRID_DEBUG("++++++++++++++++ %s errors %d size %d", __FUNCTION__, errors, size);

    GError *err = NULL;
    gint64 content_length = size;
    struct http_put_s *p = http_put_create (NULL, NULL, content_length);
    g_assert (p != NULL);

    GSList *dests = NULL;
    va_list args;
    va_start(args, size);
    for (guint i=1; ; ++i) {
        struct http_put_dest_s *d;
        char *k = va_arg(args, char *);
        if (!k) break;
        d = http_put_add_dest (p, k, GINT_TO_POINTER(i));
        dests = g_slist_prepend (dests, d);
    }
    va_end(args);

    if (size < 0)
        size = 128;
    int fed = 0;
    while (!http_put_done(p)) {
        if (fed < size) {
            http_put_feed (p, g_bytes_new((guint8*)"00000000", 8));
            fed += 8;
        } else {
            http_put_feed (p, g_bytes_new((guint8*)"", 0));
        }
        err = http_put_step (p);
        g_assert_no_error (err);
        err = http_put_step (p);
        g_assert_no_error (err);
    }

    g_slist_free (dests);

    int count_errors = http_put_get_failure_number (p);
    g_assert (count_errors == errors);

    http_put_destroy (p);
}
Beispiel #12
0
static void
emit_string (TestCase *tc,
             const gchar *channel,
             const gchar *string)
{
  GBytes *bytes = g_bytes_new (string, strlen (string));
  cockpit_transport_emit_recv (COCKPIT_TRANSPORT (tc->transport), channel, bytes);
  g_bytes_unref (bytes);
}
Beispiel #13
0
static GBytes *
substitute_message (const gchar *variable,
                    gpointer user_data)
{
  const gchar *message = user_data;
  if (g_str_equal (variable, "message"))
    return g_bytes_new (message, strlen (message));
  return NULL;
}
Beispiel #14
0
RdmaRmQP *rdma_rm_get_qp(RdmaDeviceResources *dev_res, uint32_t qpn)
{
    GBytes *key = g_bytes_new(&qpn, sizeof(qpn));

    RdmaRmQP *qp = g_hash_table_lookup(dev_res->qp_hash, key);

    g_bytes_unref(key);

    return qp;
}
Beispiel #15
0
static GBytes *bytes_from_bio(BIO *bio)
{
	long size;
	char *data;

	g_return_val_if_fail(bio != NULL, NULL);

	size = BIO_get_mem_data(bio, &data);
	return g_bytes_new(data, size);
}
Beispiel #16
0
void *Thread_Start_Routine(void *arg)
{
	struct Message *msg = (struct Message *)arg;

#if !defined(NDEBUG)
        fprintf(stderr, "Origin : %s\n", msg->origin);
        fprintf(stderr, "Summary: %s\n", msg->summary);
	/* +1 to get rid of the prepended \r of the wall message.
	 */
        fprintf(stderr, "Body   : \"%s\"\n", msg->body + 1);
#endif

	GSubprocess *proc;
	gboolean success;
	GError *error;
	GBytes *buf;

	error = NULL;
	proc  = g_subprocess_new(G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_SILENCE | G_SUBPROCESS_FLAGS_STDERR_SILENCE,
	                         &error,
	                         (char *)msg->argv0,
	                         "--origin", msg->origin,
	                         "--summary", msg->summary,
	                         NULL);
	if (UNLIKELY(!proc)) {
		PTYWATCH_ERROR("g_subprocess_new() failed: %s\n", error->message);
		g_error_free(error);
	}

	buf = g_bytes_new(msg->body, strlen(msg->body));

	error   = NULL;
	success = g_subprocess_communicate(proc,
	                                   buf,
	                                   NULL,
	                                   NULL,
	                                   NULL,
	                                   &error);
	if (UNLIKELY((!success) && error)) {
		PTYWATCH_ERROR("g_subprocess_communicate() failed: %s\n", error->message);
		g_error_free(error);
	}

	g_object_unref(G_OBJECT(proc));
	g_bytes_unref(buf);

	free(msg->argv0);
	free(msg->origin);
	free(msg->summary);
	free(msg->body);
	free(msg);

	return NULL;
}
Beispiel #17
0
static gboolean
as_icon_node_parse_embedded (AsIcon *icon, GNode *n, GError **error)
{
	AsIconPrivate *priv = GET_PRIVATE (icon);
	GNode *c;
	gsize size;
	g_autofree guchar *data = NULL;
	g_autoptr(GdkPixbuf) pixbuf = NULL;
	g_autoptr(GInputStream) stream = NULL;

	/* get the icon name */
	c = as_node_find (n, "name");
	if (c == NULL) {
		g_set_error_literal (error,
				     AS_ICON_ERROR,
				     AS_ICON_ERROR_FAILED,
				     "embedded icons needs <name>");
		return FALSE;
	}
	g_free (priv->name);
	priv->name = as_node_take_data (c);

	/* parse the Base64 data */
	c = as_node_find (n, "filecontent");
	if (c == NULL) {
		g_set_error_literal (error,
				     AS_ICON_ERROR,
				     AS_ICON_ERROR_FAILED,
				     "embedded icons needs <filecontent>");
		return FALSE;
	}
	data = g_base64_decode (as_node_get_data (c), &size);
	stream = g_memory_input_stream_new_from_data (data, (gssize) size, NULL);
	if (stream == NULL) {
		g_set_error_literal (error,
				     AS_ICON_ERROR,
				     AS_ICON_ERROR_FAILED,
				     "failed to load embedded data");
		return FALSE;
	}

	/* load the image */
	pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
	if (pixbuf == NULL)
		return FALSE;
	as_icon_set_pixbuf (icon, pixbuf);

	/* save the raw data */
	if (priv->data != NULL)
		g_bytes_unref (priv->data);
	priv->data = g_bytes_new (data, size);

	return TRUE;
}
Beispiel #18
0
/**
 * gdk_pixbuf_read_pixel_bytes:
 * @pixbuf: A pixbuf
 *
 * Returns: (transfer full): A new reference to a read-only copy of
 * the pixel data.  Note that for mutable pixbufs, this function will
 * incur a one-time copy of the pixel data for conversion into the
 * returned #GBytes.
 *
 * Since: 2.32
 */
GBytes *
gdk_pixbuf_read_pixel_bytes (const GdkPixbuf  *pixbuf)
{
        g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);

        if (pixbuf->bytes) {
                return g_bytes_ref (pixbuf->bytes);
        } else {
                return g_bytes_new (pixbuf->pixels,
                                    gdk_pixbuf_get_byte_length (pixbuf));
        }
}
static int
g_tls_server_connection_gnutls_db_remove (void            *user_data,
					  gnutls_datum_t   key)
{
  GBytes *session_id;

  session_id = g_bytes_new (key.data, key.size);
  g_tls_backend_gnutls_remove_session (GNUTLS_SERVER, session_id);
  g_bytes_unref (session_id);

  return 0;
}
Beispiel #20
0
static void
on_terminal_commit (VteTerminal *vteterminal,
		    gchar       *text,
		    guint        size,
		    gpointer     user_data) 
{
  HotSshTab *self = user_data;
  HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self);

  g_queue_push_tail (&priv->write_queue, g_bytes_new (text, size));
  process_write_queue (self);
}
Beispiel #21
0
/**
 * dfu_firmware_to_dfuse: (skip)
 * @firmware: a #DfuFirmware
 * @error: a #GError, or %NULL
 *
 * Packs a DfuSe firmware
 *
 * Returns: (transfer full): the packed data
 **/
GBytes *
dfu_firmware_to_dfuse (DfuFirmware *firmware, GError **error)
{
	DfuSePrefix *prefix;
	GPtrArray *images;
	guint32 image_size_total = 0;
	guint32 offset = sizeof (DfuSePrefix);
	g_autofree guint8 *buf = NULL;
	g_autoptr(GPtrArray) dfuse_images = NULL;

	/* get all the image data */
	dfuse_images = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
	images = dfu_firmware_get_images (firmware);
	for (guint i = 0; i < images->len; i++) {
		DfuImage *im = g_ptr_array_index (images, i);
		GBytes *contents;
		contents = dfu_image_to_dfuse (im);
		image_size_total += (guint32) g_bytes_get_size (contents);
		g_ptr_array_add (dfuse_images, contents);
	}
	g_debug ("image_size_total: %" G_GUINT32_FORMAT, image_size_total);

	buf = g_malloc0 (sizeof (DfuSePrefix) + image_size_total);

	/* DfuSe header */
	prefix = (DfuSePrefix *) buf;
	memcpy (prefix->sig, "DfuSe", 5);
	prefix->ver = 0x01;
	prefix->image_size = GUINT32_TO_LE (offset + image_size_total);
	if (images->len > G_MAXUINT8) {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_INTERNAL,
			     "too many (%u) images to write DfuSe file",
			     images->len);
		return NULL;
	}
	prefix->targets = (guint8) images->len;

	/* copy images */
	for (guint i = 0; i < dfuse_images->len; i++) {
		GBytes *contents = g_ptr_array_index (dfuse_images, i);
		gsize length;
		const guint8 *data;
		data = g_bytes_get_data (contents, &length);
		memcpy (buf + offset, data, length);
		offset += (guint32) length;
	}

	/* return blob */
	return g_bytes_new (buf, sizeof (DfuSePrefix) + image_size_total);
}
static gboolean
link_set_address (NMPlatform *platform, int ifindex, gconstpointer addr, size_t len)
{
	NMFakePlatformLink *device = link_get (platform, ifindex);

	if (device->address)
		g_bytes_unref (device->address);

	device->address = g_bytes_new (addr, len);

	link_changed (platform, link_get (platform, ifindex));

	return TRUE;
}
Beispiel #23
0
/**
 * dfu_element_from_dfuse: (skip)
 * @data: data buffer
 * @length: length of @data we can access
 * @consumed: (out): the number of bytes we consued
 * @error: a #GError, or %NULL
 *
 * Unpacks an element from DfuSe data.
 *
 * Returns: a #DfuElement, or %NULL for error
 **/
static DfuElement *
dfu_element_from_dfuse (const guint8 *data,
			guint32 length,
			guint32 *consumed,
			GError **error)
{
	DfuElement *element = NULL;
	DfuSeElementPrefix *el = (DfuSeElementPrefix *) data;
	guint32 size;
	g_autoptr(GBytes) contents = NULL;

	g_assert_cmpint(sizeof(DfuSeElementPrefix), ==, 8);

	/* check input buffer size */
	if (length < sizeof(DfuSeElementPrefix)) {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_INTERNAL,
			     "invalid element data size %u",
			     (guint32) length);
		return NULL;
	}

	/* check size */
	size = GUINT32_FROM_LE (el->size);
	if (size + sizeof(DfuSeElementPrefix) > length) {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_INTERNAL,
			     "invalid element size %u, only %u bytes left",
			     size,
			     (guint32) (length - sizeof(DfuSeElementPrefix)));
		return NULL;
	}

	/* create new element */
	element = dfu_element_new ();
	dfu_element_set_address (element, GUINT32_FROM_LE (el->address));
	contents = g_bytes_new (data + sizeof(DfuSeElementPrefix), size);
	dfu_element_set_contents (element, contents);

	/* return size */
	if (consumed != NULL)
		*consumed = (guint32) sizeof(DfuSeElementPrefix) + size;

	return element;
}
Beispiel #24
0
static gboolean
fu_smbios_setup_from_data (FuSmbios *self, const guint8 *buf, gsize sz, GError **error)
{
	/* go through each structure */
	for (gsize i = 0; i < sz; i++) {
		FuSmbiosStructure *str = (FuSmbiosStructure *) &buf[i];
		FuSmbiosItem *item;

		/* invalid */
		if (str->len == 0x00)
			break;
		if (str->len >= sz) {
			g_set_error_literal (error,
					     FWUPD_ERROR,
					     FWUPD_ERROR_INVALID_FILE,
					     "structure larger than available data");
			return FALSE;
		}

		/* create a new result */
		item = g_new0 (FuSmbiosItem, 1);
		item->type = str->type;
		item->handle = GUINT16_FROM_LE (str->handle);
		item->data = g_bytes_new (buf + i, str->len);
		item->strings = g_ptr_array_new_with_free_func (g_free);
		g_ptr_array_add (self->items, item);

		/* jump to the end of the struct */
		i += str->len;
		if (buf[i] == '\0' && buf[i+1] == '\0') {
			i++;
			continue;
		}

		/* add strings from table */
		for (gsize start_offset = i; i < sz; i++) {
			if (buf[i] == '\0') {
				if (start_offset == i)
					break;
				g_ptr_array_add (item->strings,
						 g_strdup ((const gchar *) &buf[start_offset]));
				start_offset = i + 1;
			}
		}
	}
	return TRUE;
}
Beispiel #25
0
/**
 * gdk_pixbuf_read_pixel_bytes:
 * @pixbuf: A pixbuf
 *
 * Provides a #GBytes buffer containing the raw pixel data; the data
 * must not be modified.  This function allows skipping the implicit
 * copy that must be made if gdk_pixbuf_get_pixels() is called on a
 * read-only pixbuf.
 *
 * Returns: (transfer full): A new reference to a read-only copy of
 *   the pixel data.  Note that for mutable pixbufs, this function will
 *   incur a one-time copy of the pixel data for conversion into the
 *   returned #GBytes.
 *
 * Since: 2.32
 */
GBytes *
gdk_pixbuf_read_pixel_bytes (const GdkPixbuf  *pixbuf)
{
        g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);

        switch (pixbuf->storage) {
        case STORAGE_PIXELS:
                return g_bytes_new (pixbuf->s.pixels.pixels,
                                    gdk_pixbuf_get_byte_length (pixbuf));

        case STORAGE_BYTES:
                return g_bytes_ref (pixbuf->s.bytes.bytes);

        default:
                g_assert_not_reached ();
        }
}
/**
 * gdk_pixbuf_buffer_queue_peek:
 * @queue: a #GdkPixbufBufferQueue to read from
 * @length: amount of bytes to peek
 *
 * Creates a new buffer with the first @length bytes from @queue, but unlike 
 * gdk_pixbuf_buffer_queue_pull(), does not remove them from @queue.
 *
 * Returns: NULL if the requested amount of data wasn't available or a new 
 *          #GBytes. Use g_bytes_unref() after use.
 **/
GBytes *
gdk_pixbuf_buffer_queue_peek (GdkPixbufBufferQueue *queue,
                              gsize                 length)
{
  GSList *g;
  GBytes *result, *bytes;

  g_return_val_if_fail (queue != NULL, NULL);

  if (queue->size < length)
    return NULL;

  /* need to special case here, because the queue may be empty */
  if (length == 0)
    return g_bytes_new (NULL, 0);

  g = queue->first_buffer;
  bytes = g->data;
  if (g_bytes_get_size (bytes) == length)
    {
      result = g_bytes_ref (bytes);
    }
  else if (g_bytes_get_size (bytes) > length)
    {
      result = g_bytes_new_from_bytes (bytes, 0, length);
    }
  else
    {
      guchar *data;
      gsize amount, offset;

      data = g_malloc (length);
      
      for (offset = 0; offset < length; offset += amount)
        {
          bytes = g->data;
          amount = MIN (length - offset, g_bytes_get_size (bytes));
          memcpy (data + offset, g_bytes_get_data (bytes, NULL), amount);
          g = g->next;
        }

      result = g_bytes_new_take (data, length);
    }

  return result;
}
GBytes *
ce_page_wifi_get_ssid (CEPageWifi *self)
{
	CEPageWifiPrivate *priv;
	const char *txt_ssid;
	GBytes *ssid;

	g_return_val_if_fail (CE_IS_PAGE_WIFI (self), NULL);

	priv = CE_PAGE_WIFI_GET_PRIVATE (self);
	txt_ssid = gtk_entry_get_text (priv->ssid);
	if (!txt_ssid || !strlen (txt_ssid))
		return NULL;

	ssid = g_bytes_new (txt_ssid, strlen (txt_ssid));

	return ssid;
}
Beispiel #28
0
void rdma_rm_dealloc_qp(RdmaDeviceResources *dev_res, uint32_t qp_handle)
{
    RdmaRmQP *qp;
    GBytes *key;

    key = g_bytes_new(&qp_handle, sizeof(qp_handle));
    qp = g_hash_table_lookup(dev_res->qp_hash, key);
    g_hash_table_remove(dev_res->qp_hash, key);
    g_bytes_unref(key);

    if (!qp) {
        return;
    }

    rdma_backend_destroy_qp(&qp->backend_qp);

    res_tbl_dealloc(&dev_res->qp_tbl, qp->qpn);
}
Beispiel #29
0
static void
test_asn1_bit_string (Test *test, gconstpointer unused)
{
	GNode *asn;
	GBytes *data;
	gboolean ret;
	GBytes *source, *target;
	gsize target_bits, source_bits;

	asn = egg_asn1x_create (test_asn1_tab, "TestBitString");
	g_assert ("asn test structure is null" && asn != NULL);

	/* Create a string */
	source = g_bytes_new (TEST_STRING, strlen(TEST_STRING));
	g_return_if_fail (source);
	source_bits = g_bytes_get_size(source)*8;

	/* Write the string out */
	ret = gkm_data_asn1_write_bit_string (egg_asn1x_node (asn, "data", NULL),
                                              source, source_bits);
	g_assert ("couldn't write string to asn1" && ret);

	/* Now encode the whole caboodle */
	data = egg_asn1x_encode (asn, NULL);
	g_assert ("encoding asn1 didn't work" && data != NULL);

	egg_asn1x_destroy (asn);

	/* Now decode it all nicely */
	asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestBitString", data);
	g_assert (asn != NULL);

	ret = gkm_data_asn1_read_bit_string (egg_asn1x_node (asn, "data", NULL),
                                             &target, &target_bits);
	egg_asn1x_destroy (asn);
	g_assert ("couldn't read bit string from asn1" && ret);
	g_assert ("bit string returned is null" && target != NULL);
	g_assert ("Source and target length differ" && target_bits == source_bits);
	g_assert ("Bit strings differ" && g_bytes_equal (source, target));

	g_bytes_unref (data);
	g_bytes_unref (source);
	g_bytes_unref (target);
}
Beispiel #30
0
/* org.nemomobile.MmsEngine.pushNotify */
static
gboolean
mms_engine_handle_push_notify(
    OrgNemomobileMmsEngine* proxy,
    GDBusMethodInvocation* call,
    const char* imsi,
    const char* type,
    GVariant* data,
    MMSEngine* engine)
{
    gsize len = 0;
    const guint8* bytes = g_variant_get_fixed_array(data, &len, 1);
    MMS_DEBUG("Received %u bytes from %s", (guint)len, imsi);
    if (!type || g_ascii_strcasecmp(type, MMS_CONTENT_TYPE)) {
        MMS_ERR("Unsupported content type %s", type);
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "Unsupported content type");
    } else if (!imsi || !imsi[0]) {
        MMS_ERR_("IMSI is missing");
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "IMSI is missing");
    } else if (!bytes || !len) {
        MMS_ERR_("No data provided");
        g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
            G_DBUS_ERROR_FAILED, "No data provided");
    } else {
        GError* err = NULL;
        GBytes* msg = g_bytes_new(bytes, len);
        if (mms_dispatcher_handle_push(engine->dispatcher, imsi, msg, &err)) {
            if (mms_dispatcher_start(engine->dispatcher)) {
                mms_engine_start_timeout_cancel(engine);
            }
            org_nemomobile_mms_engine_complete_push(proxy, call);
        } else {
            g_dbus_method_invocation_return_error(call, G_DBUS_ERROR,
                G_DBUS_ERROR_FAILED, "%s", MMS_ERRMSG(err));
            g_error_free(err);
        }
        g_bytes_unref(msg);
    }
    return TRUE;
}