[libsoup: 3/3] Add some helper functions to aid language bindings
- From: Andreas Rottmann <rotty src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup: 3/3] Add some helper functions to aid language bindings
- Date: Mon, 3 May 2010 21:14:03 +0000 (UTC)
commit ce8b4c4654a1a8c2a44a1ecf2a4558eda53aa527
Author: Andreas Rottmann <a rottmann gmx at>
Date: Mon May 3 22:49:10 2010 +0200
Add some helper functions to aid language bindings
- Add constructor `soup_buffer_new_take', which is bindable and
annotate it "Rename to: soup_buffer_new".
- Likewise, create `soup_message_body_append_take' and "Rename to:
soup_message_body_append".
- Added `soup_buffer_get_data' allowing bindings to access the buffer
data.
See <https://bugzilla.gnome.org/show_bug.cgi?id=576595>.
libsoup/soup-message-body.c | 68 ++++++++++++++++++++++++++++++++++++++++++-
libsoup/soup-message-body.h | 9 +++++-
2 files changed, 75 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-message-body.c b/libsoup/soup-message-body.c
index f723374..7b4c3b4 100644
--- a/libsoup/soup-message-body.c
+++ b/libsoup/soup-message-body.c
@@ -56,7 +56,7 @@ enum {
/**
* SoupBuffer:
- * @data: the data
+ * @data: (type pointer): the data
* @length: length of @data
*
* A data buffer, generally used to represent a chunk of a
@@ -109,6 +109,28 @@ soup_buffer_new (SoupMemoryUse use, gconstpointer data, gsize length)
}
/**
+ * soup_buffer_new_take:
+ * @data: (array length=length) (transfer full): data
+ * @length: length of @data
+ *
+ * Creates a new #SoupBuffer containing @length bytes from @data.
+ *
+ * This function is exactly equivalent to soup_buffer_new() with
+ * %SOUP_MEMORY_TAKE as first argument; it exists mainly for
+ * convenience and simplifying language bindings.
+ *
+ * Return value: the new #SoupBuffer.
+ *
+ * Since: 2.32
+ * Rename to: soup_buffer_new
+ **/
+SoupBuffer *
+soup_buffer_new_take (guchar *data, gsize length)
+{
+ return soup_buffer_new (SOUP_MEMORY_TAKE, data, length);
+}
+
+/**
* soup_buffer_new_subbuffer:
* @parent: the parent #SoupBuffer
* @offset: offset within @parent to start at
@@ -205,6 +227,28 @@ soup_buffer_get_owner (SoupBuffer *buffer)
}
/**
+ * soup_buffer_get_data:
+ * @buffer: a #SoupBuffer
+ * @data: (out) (array length=length) (transfer none): the pointer
+ * to the buffer data is stored here
+ * @length: (out): the length of the buffer data is stored here
+ *
+ * This function exists for use by language bindings, because it's not
+ * currently possible to get the right effect by annotating the fields
+ * of #SoupBuffer.
+ *
+ * Since: 2.32
+ */
+void
+soup_buffer_get_data (SoupBuffer *buffer,
+ const guint8 **data,
+ gsize *length)
+{
+ *data = (const guint8 *)buffer->data;
+ *length = buffer->length;
+}
+
+/**
* soup_buffer_copy:
* @buffer: a #SoupBuffer
*
@@ -429,6 +473,28 @@ soup_message_body_append (SoupMessageBody *body, SoupMemoryUse use,
}
/**
+ * soup_message_body_append_take:
+ * @body: a #SoupMessageBody
+ * @data: (array length=length) (transfer full): data to append
+ * @length: length of @data
+ *
+ * Appends @length bytes from @data to @body.
+ *
+ * This function is exactly equivalent to soup_message_body_apppend()
+ * with %SOUP_MEMORY_TAKE as second argument; it exists mainly for
+ * convenience and simplifying language bindings.
+ *
+ * Since: 2.32
+ * Rename to: soup_message_body_append
+ **/
+void
+soup_message_body_append_take (SoupMessageBody *body,
+ guchar *data, gsize length)
+{
+ soup_message_body_append(body, SOUP_MEMORY_TAKE, data, length);
+}
+
+/**
* soup_message_body_append_buffer:
* @body: a #SoupMessageBody
* @buffer: a #SoupBuffer
diff --git a/libsoup/soup-message-body.h b/libsoup/soup-message-body.h
index 53a3891..4edaaf0 100644
--- a/libsoup/soup-message-body.h
+++ b/libsoup/soup-message-body.h
@@ -28,6 +28,8 @@ GType soup_buffer_get_type (void);
SoupBuffer *soup_buffer_new (SoupMemoryUse use,
gconstpointer data,
gsize length);
+SoupBuffer *soup_buffer_new_take (guchar *data,
+ gsize length);
SoupBuffer *soup_buffer_new_subbuffer (SoupBuffer *parent,
gsize offset,
gsize length);
@@ -37,7 +39,9 @@ SoupBuffer *soup_buffer_new_with_owner (gconstpointer data,
gpointer owner,
GDestroyNotify owner_dnotify);
gpointer soup_buffer_get_owner (SoupBuffer *buffer);
-
+void soup_buffer_get_data (SoupBuffer *buffer,
+ const guint8 **data,
+ gsize *length);
SoupBuffer *soup_buffer_copy (SoupBuffer *buffer);
void soup_buffer_free (SoupBuffer *buffer);
@@ -59,6 +63,9 @@ void soup_message_body_append (SoupMessageBody *body,
SoupMemoryUse use,
gconstpointer data,
gsize length);
+void soup_message_body_append_take (SoupMessageBody *body,
+ guchar *data,
+ gsize length);
void soup_message_body_append_buffer (SoupMessageBody *body,
SoupBuffer *buffer);
void soup_message_body_truncate (SoupMessageBody *body);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]