From 5034f5109cf7202efd6f6a85949961975d88c2f2 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Tue, 16 Dec 2008 23:55:18 -0200 Subject: [PATCH] Require atom entries to have ID, title and authors 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 | 13 +++++++++++-- include/atompub/entry.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/atom/entry.c b/atom/entry.c index d4732c3..31994c3 100644 --- a/atom/entry.c +++ b/atom/entry.c @@ -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); diff --git a/include/atompub/entry.h b/include/atompub/entry.h index ce6bd12..4e0869e 100644 --- a/include/atompub/entry.h +++ b/include/atompub/entry.h @@ -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 *); -- 2.20.1