Allow more than one author, as required by specification
[cascardo/atompub.git] / atom / entry.c
index 069207b..7faccd3 100644 (file)
@@ -28,10 +28,13 @@ struct _atom_entry
   xmlDocPtr doc;
   char *id;
   char *title;
-  AtomPerson *author;
+  GPtrArray *authors;
   char *summary;
 };
 
+void atom_entry_author_add (AtomEntry *, AtomPerson *);
+static void atom_entry_authors_delete (AtomEntry *);
+
 AtomEntry *
 atom_entry_new (char *title, AtomPerson *author)
 {
@@ -40,7 +43,8 @@ atom_entry_new (char *title, AtomPerson *author)
   entry->doc = NULL;
   entry->id = NULL;
   entry->title = g_strdup (title);
-  entry->author = author;
+  entry->authors = NULL;
+  atom_entry_author_add (entry, author);
   entry->summary = NULL;
   return entry;
 }
@@ -77,7 +81,7 @@ atom_entry_new_data_len (char *data, size_t len)
       else if (!xmlStrcmp (child->name, "summary"))
        entry->summary = content;
       else if (!xmlStrcmp (child->name, "author"))
-       entry->author = atom_person_new_from_xmlnode (child);
+       atom_entry_author_add (entry, atom_person_new_from_xmlnode (child));
       else
        xmlFree (content);
     }
@@ -93,8 +97,8 @@ atom_entry_delete (AtomEntry *entry)
     g_free (entry->id);
   if (entry->title)
     g_free (entry->title);
-  if (entry->author)
-    atom_person_delete (entry->author);
+  if (entry->authors)
+    atom_entry_authors_delete (entry);
   if (entry->summary)
     g_free (entry->summary);
   g_slice_free (AtomEntry, entry);
@@ -128,18 +132,33 @@ atom_entry_title_set (AtomEntry *entry, char *title)
   entry->title = g_strdup (entry);
 }
 
-AtomPerson *
-atom_entry_author (AtomEntry *entry)
+void
+atom_entry_authors (AtomEntry *entry, AtomPerson *** authors, size_t *len)
 {
-  return entry->author;
+  if (len)
+    *len = entry->authors->len;
+  if (authors)
+    *authors = entry->authors->pdata;
 }
 
 void
-atom_entry_author_set (AtomEntry *entry, AtomPerson *author)
+atom_entry_author_add (AtomEntry *entry, AtomPerson *author)
+{
+  if (entry->authors == NULL)
+    {
+      entry->authors = g_ptr_array_new ();
+    }
+  g_ptr_array_add (entry->authors, author);
+}
+
+static void
+atom_entry_authors_delete (AtomEntry *entry)
 {
-  if (entry->author)
-    atom_person_delete (entry->author);
-  entry->author = author;
+  size_t len = entry->authors->len;
+  int i;
+  for (i = 0; i < len; i++)
+    atom_person_delete (g_ptr_array_index (entry->authors, i));
+  g_ptr_array_free (entry->authors, TRUE);
 }
 
 char *