Require atom entries to have ID, title and authors
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 17 Dec 2008 01:55:18 +0000 (23:55 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Tue, 23 Dec 2008 15:23:06 +0000 (13:23 -0200)
As required by RFC, entries must have an ID, title and authors. This
will avoid some possible errors when creating the correspondent XML.

atom/entry.c
include/atompub/entry.h

index d4732c3..31994c3 100644 (file)
@@ -40,12 +40,12 @@ void atom_entry_category_add (AtomEntry *, AtomCategory *);
 static void atom_entry_categories_delete (AtomEntry *);
 
 AtomEntry *
-atom_entry_new (char *title, AtomPerson *author)
+atom_entry_new (char *id, char *title, AtomPerson *author)
 {
   AtomEntry *entry;
   entry = g_slice_new (AtomEntry);
   entry->doc = NULL;
-  entry->id = NULL;
+  entry->id = atom_id_new (id);
   entry->title = g_strdup (title);
   entry->authors = NULL;
   entry->categories = NULL;
@@ -92,6 +92,11 @@ atom_entry_new_data_len (char *data, size_t len)
       else
         xmlFree (content);
     }
+  if (entry->id == NULL || entry->title == NULL || entry->authors == NULL)
+    {
+      atom_entry_delete (entry);
+      return NULL;
+    }
   return entry;
 }
 
@@ -122,6 +127,8 @@ atom_entry_id (AtomEntry *entry)
 void
 atom_entry_id_set (AtomEntry *entry, AtomID *id)
 {
+  if (id == NULL)
+    return;
   if (entry->id)
     atom_id_delete (entry->id);
   entry->id = id;
@@ -136,6 +143,8 @@ atom_entry_title (AtomEntry *entry)
 void
 atom_entry_title_set (AtomEntry *entry, char *title)
 {
+  if (title == NULL)
+    return;
   if (entry->title)
     g_free (title);
   entry->title = g_strdup (title);
index ce6bd12..4e0869e 100644 (file)
@@ -27,7 +27,7 @@
 
 typedef struct _atom_entry AtomEntry;
 
-AtomEntry * atom_entry_new (char *, AtomPerson *);
+AtomEntry * atom_entry_new (char *, char *, AtomPerson *);
 AtomEntry * atom_entry_new_data_len (char *, size_t);
 void atom_entry_delete (AtomEntry *);
 AtomID * atom_entry_id (AtomEntry *);