[couchdb-glib] Add couchdb_document_list_attachments API



commit d3aa5450779e190448bb4031b492b9526529a38f
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Jun 3 16:39:08 2010 +0200

    Add couchdb_document_list_attachments API

 couchdb-glib/couchdb-document.c     |   29 +++++++++++++++++++++++++++++
 couchdb-glib/couchdb-document.h     |    4 +++-
 couchdb-glib/couchdb-struct-field.c |   28 ++++++++++++++++++++++++++++
 couchdb-glib/couchdb-struct-field.h |    2 ++
 4 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document.c b/couchdb-glib/couchdb-document.c
index 2227cf6..eaaddf5 100644
--- a/couchdb-glib/couchdb-document.c
+++ b/couchdb-glib/couchdb-document.c
@@ -537,6 +537,35 @@ couchdb_document_set_struct_field (CouchdbDocument *document, const char *field,
 }
 
 /**
+ * couchdb_document_list_attachments:
+ * @document: A #CouchdbDocument object
+ *
+ * List all the attachments for the given document.
+ *
+ * Return value: A list containing the names of all the attachments included in
+ * the given document. When no longer needed, the list should be freed by calling
+ * #g_slist_free.
+ */
+GSList *
+couchdb_document_list_attachments (CouchdbDocument *document)
+{
+	CouchdbStructField *attachments;
+	GSList *list = NULL;
+
+	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
+
+	attachments = couchdb_document_get_struct_field (document, "_attachments");
+	if (attachments != NULL) {
+		list = couchdb_struct_field_get_field_names (attachments); /* FIXME: the strings in the list are owned by json-glib
+									      see couchdb_struct_field_get_field_names */
+
+		g_object_unref (G_OBJECT (attachments));
+	}
+
+	return list;
+}
+
+/**
  * couchdb_document_to_string:
  * @document: A #CouchdbDocument object
  *
diff --git a/couchdb-glib/couchdb-document.h b/couchdb-glib/couchdb-document.h
index a7ca5d0..57dd22c 100644
--- a/couchdb-glib/couchdb-document.h
+++ b/couchdb-glib/couchdb-document.h
@@ -76,7 +76,9 @@ const char         *couchdb_document_get_string_field (CouchdbDocument *document
 void                couchdb_document_set_string_field (CouchdbDocument *document, const char *field, const char *value);
 CouchdbStructField *couchdb_document_get_struct_field (CouchdbDocument *document, const char *field);
 void                couchdb_document_set_struct_field (CouchdbDocument *document, const char *field, CouchdbStructField *value);
-      
+
+GSList             *couchdb_document_list_attachments (CouchdbDocument *document);
+
 char               *couchdb_document_to_string (CouchdbDocument *document);
 
 G_END_DECLS
diff --git a/couchdb-glib/couchdb-struct-field.c b/couchdb-glib/couchdb-struct-field.c
index 002eff6..aa8a964 100644
--- a/couchdb-glib/couchdb-struct-field.c
+++ b/couchdb-glib/couchdb-struct-field.c
@@ -161,6 +161,34 @@ couchdb_struct_field_remove_field (CouchdbStructField *sf, const char *field)
 }
 
 /**
+ * couchdb_struct_field_get_field_names:
+ * @sf: A #CouchdbStructField object
+ *
+ * Get the list of field names the given #CouchdbStructField object contains.
+ *
+ * Return value: A list of strings containing the names of all the fields contained
+ * in the given #CouchdbStructField object. When no longer needed, the list should
+ * be freed by calling #g_slist_free.
+ */
+GSList *
+couchdb_struct_field_get_field_names (CouchdbStructField *sf)
+{
+	GList *json_list;
+	GSList *result = NULL;
+
+	g_return_val_if_fail (COUCHDB_IS_STRUCT_FIELD (sf), NULL);
+
+	json_list = json_object_get_members (sf->priv->json_object);
+	while (json_list != NULL) {
+		result = g_slist_append (result, json_list->data);
+
+		json_list = g_list_remove (json_list, json_list->data);
+	}
+
+	return result;
+}
+
+/**
  * couchdb_struct_field_get_array_field:
  * @sf: A #CouchdbStructField object
  * @field: Name of the field
diff --git a/couchdb-glib/couchdb-struct-field.h b/couchdb-glib/couchdb-struct-field.h
index 037dd28..ca6b9b2 100644
--- a/couchdb-glib/couchdb-struct-field.h
+++ b/couchdb-glib/couchdb-struct-field.h
@@ -50,6 +50,8 @@ CouchdbStructField *couchdb_struct_field_new_from_string (const char *str);
 gboolean            couchdb_struct_field_has_field (CouchdbStructField *sf, const char *field);
 void                couchdb_struct_field_remove_field (CouchdbStructField *sf, const char *field);
 
+GSList             *couchdb_struct_field_get_field_names (CouchdbStructField *sf);
+
 CouchdbArrayField  *couchdb_struct_field_get_array_field (CouchdbStructField *sf, const char *field);
 void                couchdb_struct_field_set_array_field (CouchdbStructField *sf, const char *field, CouchdbArrayField *value);
 gboolean            couchdb_struct_field_get_boolean_field (CouchdbStructField *sf, const char *field);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]