[couchdb-glib] s/couchdb_document_list_attachments/couchdb_document_foreach_attachment



commit 09b8f13a05ce2615f9abd5cfb4644c2b378c40bf
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Fri Jun 4 10:37:14 2010 +0200

    s/couchdb_document_list_attachments/couchdb_document_foreach_attachment

 couchdb-glib/couchdb-document.c |   27 +++++++++++++++------------
 couchdb-glib/couchdb-document.h |    8 +++++++-
 2 files changed, 22 insertions(+), 13 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document.c b/couchdb-glib/couchdb-document.c
index eaaddf5..b7eae34 100644
--- a/couchdb-glib/couchdb-document.c
+++ b/couchdb-glib/couchdb-document.c
@@ -537,32 +537,35 @@ couchdb_document_set_struct_field (CouchdbDocument *document, const char *field,
 }
 
 /**
- * couchdb_document_list_attachments:
+ * couchdb_document_foreach_attachment:
  * @document: A #CouchdbDocument object
+ * @func: Callback function to be called for each attachment found
+ * @user_data: Data to pass to callback function
  *
  * 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)
+void
+couchdb_document_foreach_attachment (CouchdbDocument *document,
+				     CouchdbDocumentForeachAttachmentFunc func,
+				     gpointer user_data)
 {
 	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 */
+		GSList *list;
+
+		list = couchdb_struct_field_get_field_names (attachments);
+		while (list != NULL) {
+			func (document, (const gchar *) list->data, user_data);
+
+			list = g_slist_remove (list, list->data);
+		}
 
 		g_object_unref (G_OBJECT (attachments));
 	}
-
-	return list;
 }
 
 /**
diff --git a/couchdb-glib/couchdb-document.h b/couchdb-glib/couchdb-document.h
index 57dd22c..0c2437f 100644
--- a/couchdb-glib/couchdb-document.h
+++ b/couchdb-glib/couchdb-document.h
@@ -77,7 +77,13 @@ void                couchdb_document_set_string_field (CouchdbDocument *document
 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);
+typedef void (* CouchdbDocumentForeachAttachmentFunc) (CouchdbDocument *document,
+						       const gchar *attachment_id,
+						       gpointer user_data);
+
+void                couchdb_document_foreach_attachment (CouchdbDocument *document,
+							 CouchdbDocumentForeachAttachmentFunc func,
+							 gpointer user_data);
 
 char               *couchdb_document_to_string (CouchdbDocument *document);
 



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