summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2010-10-08 17:02:47 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2010-10-08 17:02:47 +0200
commit10c6b1f0978710cf5a9f309b6fdcaef922f9b07f (patch)
tree00679d479d9554f91f5d3beb4f4e709705ba55df /src
parent5fc53d25a171fbd85ee09c9fc771580350d689c8 (diff)
downloadcataract-10c6b1f0978710cf5a9f309b6fdcaef922f9b07f.tar.xz
Add basic Atom feed writer
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/atom-writer.c307
-rw-r--r--src/atom-writer.h70
-rw-r--r--src/cgg.c34
-rw-r--r--src/generators.c18
-rw-r--r--src/items.c66
-rw-r--r--src/job-manager.c4
-rw-r--r--src/setup.c43
-rw-r--r--src/setup.h6
-rw-r--r--src/xml-parser.c13
-rw-r--r--src/xml-parser.h1
11 files changed, 530 insertions, 34 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 492e863..8c4aa15 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,6 +19,8 @@ bin_SCRIPTS = \
cgg_SOURCES = \
cgg.c \
+ atom-writer.c \
+ atom-writer.h \
block-parser.c \
block-parser.h \
gallery-utils.c \
diff --git a/src/atom-writer.c b/src/atom-writer.c
new file mode 100644
index 0000000..958d700
--- /dev/null
+++ b/src/atom-writer.c
@@ -0,0 +1,307 @@
+/* Cataract - Static web photo gallery generator
+ * Copyright (C) 2010 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#define _XOPEN_SOURCE /* for strptime() */
+#define _BSD_SOURCE /* for struct tm.tm_gmtoff */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <time.h>
+
+#include <glib.h>
+
+#include <config.h>
+
+#include "setup.h"
+#include "atom-writer.h"
+#include "gallery-utils.h"
+
+
+
+
+TAtomFeed *
+atom_writer_new ()
+{
+ return g_new0 (TAtomFeed, 1);
+}
+
+static time_t
+parse_timestamp (const gchar *timestamp)
+{
+ struct tm t = {0};
+ long saved_tm_gmtoff;
+
+
+ if (timestamp == NULL || strlen (timestamp) == 0) {
+ g_print ("parse_timestamp() error: invalid timestamp NULL\n");
+ return 0;
+ }
+
+ strptime (timestamp, "%FT%T%z", &t);
+ saved_tm_gmtoff = t.tm_gmtoff;
+
+ return mktime (&t) - saved_tm_gmtoff;
+}
+
+static gint
+feed_list_date_sort_func (TAtomFeedItem *item1, TAtomFeedItem *item2)
+{
+ time_t t1, t2;
+
+ t1 = parse_timestamp (item1->date);
+ t2 = parse_timestamp (item2->date);
+
+ return - (t1 - t2);
+}
+
+static gchar *
+atom_create_tag (const gchar *base_url, const gchar *date, const gchar *title, const gchar *path)
+{
+ gchar *s, *s2, *s3;
+
+ /* http://feedvalidator.org/docs/error/InvalidTAG.html */
+
+ /* extract domain name */
+ s2 = strstr (base_url, "://");
+ if (s2 != NULL) {
+ s2 += 3;
+ s3 = strstr (s2, "/");
+
+ /* no slash found, treat it as is */
+ if (s3 == NULL)
+ s3 = g_strdup (s2);
+ else
+ s3 = g_strndup (s2, s3 - s2);
+
+ s = g_strdup_printf ("tag:%s,", s3);
+ g_free (s3);
+ }
+ else {
+ g_print ("atom_create_tag() error: invalid base_url '%s'\n", base_url);
+ s = g_strdup ("tag:unknown.cgg.gallery.com,");
+ }
+
+ /* copy the date, let's assume correct format */
+ s3 = g_strndup (date, 10);
+ s2 = g_strdup_printf ("%s%s:x", s, s3 ? s3 : "2010-01-01");
+ g_free (s3);
+ g_free (s);
+ s = s2;
+
+ /* append hashed title and path */
+ if (title) {
+ s2 = g_strdup_printf ("%s.%u", s, g_str_hash (title));
+ g_free (s);
+ s = s2;
+ }
+ if (path) {
+ s2 = g_strdup_printf ("%s.%u", s, g_str_hash (path));
+ g_free (s);
+ s = s2;
+ }
+
+ return s;
+}
+
+void
+atom_writer_write_to_file (TAtomFeed *feed, const gchar *filename, TGallerySetup *setup)
+{
+ FILE* f;
+ GSList *list;
+ TAtomFeedItem *item;
+ gchar *s;
+ const gchar *last_updated;
+
+ f = fopen (filename, "w");
+ if (f == NULL) {
+ log_error ("Error writing atom feed: %s\n", strerror (errno));
+ return;
+ }
+
+ /* sort items by date */
+ feed->items = g_slist_sort (feed->items, (GCompareFunc) feed_list_date_sort_func);
+
+ /* find most recent date */
+ last_updated = NULL;
+ for (list = feed->items; list; list = list->next) {
+ item = list->data;
+ last_updated = item->date;
+ if (last_updated)
+ break;
+ }
+
+ /* write header */
+ fprintf (f, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
+ fprintf (f, "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n");
+ fprintf (f, " <title>%s</title>\n", feed->title);
+ if (last_updated)
+ fprintf (f, " <updated>%s</updated>\n", last_updated);
+
+ s = atom_create_tag (feed->base_url, last_updated, feed->title, NULL);
+ fprintf (f, " <id>%s</id>\n", s);
+ g_free (s);
+
+ s = g_build_path ("/", feed->base_url, "/", NULL);
+ fprintf (f, " <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n", s);
+ g_free (s);
+
+ fprintf (f, " <link rel=\"self\" type=\"application/atom+xml\" href=\"%s\"/>\n", feed->feed_url);
+ fprintf (f, " <generator uri=\"%s\" version=\"%s\">%s</generator>\n", APP_HOMEPAGE, VERSION, APP_NAME_FULL);
+
+ if (setup->favicon_file)
+ fprintf (f, " <icon>%s</icon>\n", setup->favicon_file);
+
+ if (setup->meta_author || setup->meta_author_email) {
+ fprintf (f, " <author>\n");
+ if (setup->meta_author)
+ fprintf (f, " <name>%s</name>\n", setup->meta_author);
+ if (setup->meta_author_email)
+ fprintf (f, " <email>%s</email>\n", setup->meta_author_email);
+ fprintf (f, " </author>\n");
+ }
+ fprintf (f, "\n");
+
+ /* write items */
+ for (list = feed->items; list; list = list->next) {
+ item = list->data;
+ if (item->title == NULL || strlen (item->title) == 0 ||
+ item->date == NULL || strlen (item->date) == 0 ||
+ item->path == NULL || strlen (item->path) == 0)
+ log_error ("Error: missing required fields in feed item data (title = '%s').\n", item->title);
+ else {
+ fprintf (f, " <entry>\n");
+ fprintf (f, " <title>%s</title>\n", item->title);
+ s = g_build_path ("/", setup->feed_base_url, item->path, "/", NULL);
+ fprintf (f, " <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n", s);
+ g_free (s);
+
+ s = atom_create_tag (feed->base_url, item->date, item->title, item->path);
+ fprintf (f, " <id>%s</id>\n", s);
+ g_free (s);
+
+ fprintf (f, " <updated>%s</updated>\n", item->date);
+ fprintf (f, " <summary");
+ if (item->summary_type)
+ fprintf (f, " type=\"%s\"", item->summary_type);
+ fprintf (f, ">\n%s\n </summary>\n", item->summary);
+ fprintf (f, " </entry>\n\n");
+ }
+ }
+
+ fprintf (f, "</feed>\n");
+ fclose (f);
+}
+
+static void
+atom_feed_item_free (TAtomFeedItem *item)
+{
+ g_free (item->title);
+ g_free (item->path);
+ g_free (item->date);
+ g_free (item->summary);
+ g_free (item->summary_type);
+}
+
+void
+atom_writer_free (TAtomFeed *feed)
+{
+ if (feed) {
+ g_slist_foreach (feed->items, (GFunc) atom_feed_item_free, NULL);
+ g_slist_free (feed->items);
+ g_free (feed->title);
+ g_free (feed->base_url);
+ g_free (feed->feed_url);
+ g_free (feed);
+ }
+}
+
+void
+atom_writer_set_title (TAtomFeed *feed, const gchar *title)
+{
+ g_free (feed->title);
+ feed->title = g_markup_escape_text (title, -1);
+}
+
+void
+atom_writer_set_base_url (TAtomFeed *feed, const gchar *base_url)
+{
+ g_free (feed->base_url);
+ feed->base_url = g_strdup (base_url);
+}
+
+void
+atom_writer_set_feed_url (TAtomFeed *feed, const gchar *feed_url)
+{
+ g_free (feed->feed_url);
+ feed->feed_url = g_strdup (feed_url);
+}
+
+
+G_LOCK_DEFINE (atom_writer_items);
+
+TAtomFeedItem *
+atom_writer_add_item (TAtomFeed *feed)
+{
+ TAtomFeedItem *item;
+
+ item = g_new0 (TAtomFeedItem, 1);
+
+ G_LOCK (atom_writer_items);
+ feed->items = g_slist_append (feed->items, item);
+ G_UNLOCK (atom_writer_items);
+
+ return item;
+}
+
+
+void
+atom_feed_item_set_title (TAtomFeedItem *item, const gchar *title)
+{
+ g_free (item->title);
+ item->title = g_markup_escape_text (title, -1);
+}
+
+void
+atom_feed_item_set_path (TAtomFeedItem *item, const gchar *path)
+{
+ g_free (item->path);
+ item->path = g_strdup (path);
+}
+
+void
+atom_feed_item_set_date (TAtomFeedItem *item, const gchar *date)
+{
+ g_free (item->date);
+ item->date = g_strdup (date);
+}
+
+void
+atom_feed_item_set_summary (TAtomFeedItem *item, const gchar *summary)
+{
+ g_free (item->summary);
+ item->summary = g_markup_escape_text (summary, -1);
+}
+
+void
+atom_feed_item_set_summary_type (TAtomFeedItem *item, const gchar *summary_type)
+{
+ g_free (item->summary_type);
+ item->summary_type = g_strdup (summary_type);
+}
+
diff --git a/src/atom-writer.h b/src/atom-writer.h
new file mode 100644
index 0000000..cf90001
--- /dev/null
+++ b/src/atom-writer.h
@@ -0,0 +1,70 @@
+/* Cataract - Static web photo gallery generator
+ * Copyright (C) 2010 Tomas Bzatek <tbzatek@users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+#ifndef __ATOM_WRITER_H__
+#define __ATOM_WRITER_H__
+
+#include <glib.h>
+#include "setup.h"
+
+/*
+ * Resources:
+ * http://tools.ietf.org/html/rfc4287
+ * http://www.atomenabled.org/developers/syndication/
+ * http://feedvalidator.org/
+ * http://diveintomark.org/archives/2004/05/28/howto-atom-id
+ *
+ */
+
+
+typedef struct {
+ gchar *title;
+ gchar *base_url;
+ gchar *feed_url;
+
+ GSList *items;
+} TAtomFeed;
+
+typedef struct {
+ gchar *title;
+ gchar *path; /* relative path in the gallery structure */
+ gchar *date; /* format ISO.8601.1988 yyyy-mm-ddThh:mm:ssZ or yyyy-mm-ddThh:mm:ss+hh:mm (timezone) */
+ gchar *summary; /* escaped automatically */
+ gchar *summary_type; /* valid values are "text", "html", "xhtml" */
+} TAtomFeedItem;
+
+
+/* Global instances */
+TAtomFeed *news_feed;
+
+
+TAtomFeed * atom_writer_new ();
+void atom_writer_write_to_file (TAtomFeed *feed, const gchar *filename, TGallerySetup *setup);
+void atom_writer_set_title (TAtomFeed *feed, const gchar *title);
+void atom_writer_set_base_url (TAtomFeed *feed, const gchar *base_url);
+void atom_writer_set_feed_url (TAtomFeed *feed, const gchar *feed_url);
+void atom_writer_free (TAtomFeed *feed); /* will free data of all items */
+
+TAtomFeedItem * atom_writer_add_item (TAtomFeed *feed);
+void atom_feed_item_set_title (TAtomFeedItem *item, const gchar *title);
+void atom_feed_item_set_path (TAtomFeedItem *item, const gchar *path);
+void atom_feed_item_set_date (TAtomFeedItem *item, const gchar *date);
+void atom_feed_item_set_summary (TAtomFeedItem *item, const gchar *summary);
+void atom_feed_item_set_summary_type (TAtomFeedItem *item, const gchar *summary_type);
+
+
+#endif /* __ATOM_WRITER_H__ */
diff --git a/src/cgg.c b/src/cgg.c
index 00cd63d..5ec8652 100644
--- a/src/cgg.c
+++ b/src/cgg.c
@@ -34,6 +34,8 @@
#include "setup.h"
#include "job-manager.h"
#include "stats.h"
+#include "atom-writer.h"
+#include "gallery-utils.h"
@@ -118,6 +120,7 @@ main (int argc, char* argv[])
TGallerySetup *setup;
time_t time_start = time (NULL);
time_t time_stop;
+ gchar *s;
/*
* this initialize the library and check potential ABI mismatches
@@ -173,12 +176,42 @@ main (int argc, char* argv[])
printf ("Using setup file \"%s\"\n", setup->setup_xml_path);
}
+ /* Setup feeds */
+ news_feed = NULL;
+ if (setup->feed_enabled) {
+ news_feed = atom_writer_new ();
+ atom_writer_set_title (news_feed, setup->feed_title ? setup->feed_title : setup->site_title);
+ }
+
/* Start building the gallery tree */
setup->verbose = verbose;
setup->update_mode = update;
setup->override_nofullsize = fullsize;
build_tree (setup, source_dir, dst_dir, NULL, -1, jobs);
+ /* Write feeds */
+ if (news_feed) {
+ if (verbose)
+ printf ("Writing Atom feed: %s\n", setup->feed_filename);
+ if (setup->feed_base_url == NULL || strlen (setup->feed_base_url) == 0)
+ log_error ("Error: feed base URL not defined!\n");
+ else
+ if (setup->feed_filename == NULL || strlen (setup->feed_filename) == 0)
+ log_error ("Error: feed file name not defined!\n");
+ else {
+ atom_writer_set_base_url (news_feed, setup->feed_base_url);
+ s = g_build_filename (setup->feed_base_url, setup->feed_filename, NULL);
+ atom_writer_set_feed_url (news_feed, s);
+ g_free (s);
+
+ s = g_strdup_printf ("%s/%s", dst_dir, setup->feed_filename);
+ atom_writer_write_to_file (news_feed, s, setup);
+ g_free (s);
+ }
+ atom_writer_free (news_feed);
+ }
+
+ /* Write stats */
if (verbose) {
time_stop = time (NULL);
printf ("\nProcessed %d images in %d albums, elapsed time = %dm %ds\n", stats_images, stats_dirs, (int) ((time_stop - time_start) / 60), (int) ((time_stop - time_start) % 60));
@@ -189,7 +222,6 @@ main (int argc, char* argv[])
}
-
MagickWandTerminus();
/* Cleanup function for the XML library. */
diff --git a/src/generators.c b/src/generators.c
index a28eb8a..f0ba940 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -399,6 +399,15 @@ write_html_album (TGallerySetup *setup,
replace_table_add_key (global_replace_table, "CGG_META_TAGS", s1);
g_free (s1);
+ /* Atom feeds */
+ if (setup->feed_enabled) {
+ s3 = make_string ("../", level - 1);
+ s1 = g_strdup_printf ("\t<link href=\"%s%s\" type=\"application/atom+xml\" rel=\"alternate\" title=\"%s\" />\n", s3, setup->feed_filename, setup->feed_title);
+ g_free (s3);
+ replace_table_add_key (global_replace_table, "CGG_ATOM_FEED_TAGS", s1);
+ g_free (s1);
+ }
+
/* Setup block parser */
block_parser_register_key (block_parser, "IMG_LIST", "IMG_LIST");
@@ -797,6 +806,15 @@ write_html_image (TGallerySetup *setup,
replace_table_add_key (replace_table, "CGG_META_TAGS", s1);
g_free (s1);
+ /* Atom feeds */
+ if (setup->feed_enabled) {
+ s3 = make_string ("../", level - 1);
+ s1 = g_strdup_printf ("\t<link href=\"%s%s\" type=\"application/atom+xml\" rel=\"alternate\" title=\"%s\" />\n", s3, setup->feed_filename, setup->feed_title);
+ g_free (s3);
+ replace_table_add_key (replace_table, "CGG_ATOM_FEED_TAGS", s1);
+ g_free (s1);
+ }
+
/* Setup block parser */
block_parser_register_key (block_parser, "IMG_FULLSIZE_LINK", "IMG_FULLSIZE_LINK");
diff --git a/src/items.c b/src/items.c
index 730908e..4a6f7ea 100644
--- a/src/items.c
+++ b/src/items.c
@@ -27,8 +27,35 @@
#include "items.h"
#include "xml-parser.h"
#include "gallery-utils.h"
+#include "atom-writer.h"
+static gchar *
+get_album_path (TAlbum *items)
+{
+ TIndexItem *parent_item;
+ TAlbum *parent;
+ int old_parent_item_index;
+ gchar *path;
+ gchar *s;
+
+ path = NULL;
+ parent = items->parent_index;
+ old_parent_item_index = items->parent_item_index;
+ while (parent) {
+ parent_item = g_ptr_array_index (parent->items, old_parent_item_index);
+ if (! parent_item)
+ break;
+ s = g_strdup_printf ("/%s%s", parent_item->path, path ? path : "");
+ g_free (path);
+ path = s;
+ old_parent_item_index = parent->parent_item_index;
+ parent = parent->parent_index;
+ }
+
+ return path ? path : g_strdup ("/");
+}
+
/*
* parse_album_xml: XML parser for gallery index.xml files
@@ -43,16 +70,12 @@ parse_album_xml (const gchar *filename, TAlbum *index)
gchar *s, *s2;
gchar *node_name;
TIndexItem *item;
+ TAtomFeedItem *feed_item;
xml = xml_parser_load (filename);
if (xml == NULL)
return FALSE;
- /* Initialize data struct */
- if (index == NULL)
- index = g_malloc0 (sizeof (TAlbum));
- memset (index, 0, sizeof (TAlbum));
-
index->base_dir = g_path_get_dirname (filename);
/* Retrieve gallery type */
@@ -81,7 +104,6 @@ parse_album_xml (const gchar *filename, TAlbum *index)
g_free (s);
}
-
index->quality = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "quality", -1);
index->landscape_width = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "landscape_w", 0);
index->landscape_height = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "landscape_h", 0);
@@ -96,6 +118,38 @@ parse_album_xml (const gchar *filename, TAlbum *index)
index->nofullsize = xml_file_get_node_present (xml, "/gallery/general/nofullsize");
index->fullsize = xml_file_get_node_present (xml, "/gallery/general/fullsize");
+ /* News records */
+ if (news_feed) {
+ count = xml_file_node_get_children_count (xml, "/gallery/general/news");
+ for (i = 0; i < count; i++) {
+ feed_item = atom_writer_add_item (news_feed);
+ s = g_strdup_printf ("/gallery/general/news[%d]", i + 1);
+
+ s2 = xml_file_get_node_attribute (xml, s, "title");
+ atom_feed_item_set_title (feed_item, s2);
+ g_free (s2);
+
+ s2 = xml_file_get_node_attribute (xml, s, "timestamp");
+ atom_feed_item_set_date (feed_item, s2);
+ g_free (s2);
+
+ s2 = xml_file_get_node_attribute (xml, s, "type");
+ atom_feed_item_set_summary_type (feed_item, s2);
+ g_free (s2);
+ g_free (s);
+
+ s = g_strdup_printf ("/gallery/general/news[%d]/text()", i + 1);
+ s2 = xml_file_get_node_value (xml, s);
+ atom_feed_item_set_summary (feed_item, s2);
+ g_free (s2);
+
+ s = get_album_path (index);
+ atom_feed_item_set_path (feed_item, s);
+ g_free (s);
+ }
+
+ }
+
/* Section Items */
count = xml_file_node_get_children_count (xml, "/gallery/items/*");
index->items = g_ptr_array_new();
diff --git a/src/job-manager.c b/src/job-manager.c
index ecfe5b6..87b3425 100644
--- a/src/job-manager.c
+++ b/src/job-manager.c
@@ -226,14 +226,14 @@ build_tree (TGallerySetup *setup,
/* Read the index file and fill items array */
items = g_malloc0 (sizeof (TAlbum));
+ items->parent_index = parent_index;
+ items->parent_item_index = parent_item_index;
if (! parse_album_xml (idx_file, items)) {
log_error ("error reading index file '%s'\n", idx_file);
g_free (idx_file);
free_album_data (items);
return FALSE;
}
- items->parent_index = parent_index;
- items->parent_item_index = parent_item_index;
/* Check if update is necessary */
dst_album_file = g_strconcat (dst_dir, "/", setup->index_file_name, NULL);
diff --git a/src/setup.c b/src/setup.c
index f394838..521b184 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -101,9 +101,7 @@ parse_setup_xml (const gchar *filename, TGallerySetup *setup)
setup->template_files = g_strsplit (s, "\n", -1);
g_free (s);
}
- s = xml_file_get_node_attribute (xml, "/gallery_setup/templates/support_files_use_common_root", "value");
- setup->support_files_use_common_root = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */
- g_free (s);
+ setup->support_files_use_common_root = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/templates/support_files_use_common_root", "value", FALSE);
setup->index_file_name = xml_file_get_node_value (xml, "/gallery_setup/templates/index_file/text()");
if (setup->index_file_name == NULL || strlen (setup->index_file_name) == 0)
setup->index_file_name = g_strdup (DEFAULT_INDEX_FILENAME);
@@ -121,7 +119,6 @@ parse_setup_xml (const gchar *filename, TGallerySetup *setup)
if (setup->thumbnail_name_format == NULL || strlen (setup->thumbnail_name_format) == 0 || strstr (setup->thumbnail_name_format, "%s") == NULL)
setup->thumbnail_name_format = g_strdup (DEFAULT_THUMBNAIL_NAME_FORMAT);
-
setup->thumbnail_landscape_width = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "landscape_w", 0);
setup->thumbnail_landscape_height = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "landscape_h", 0);
setup->thumbnail_portrait_width = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "portrait_w", 0);
@@ -135,39 +132,31 @@ parse_setup_xml (const gchar *filename, TGallerySetup *setup)
setup->footer = xml_file_get_node_value (xml, "/gallery_setup/footer/text()");
setup->border_style = xml_file_get_node_attribute (xml, "/gallery_setup/images/border", "style");
setup->meta_author = xml_file_get_node_value (xml, "/gallery_setup/meta/author/text()");
+ setup->meta_author_email = xml_file_get_node_value (xml, "/gallery_setup/meta/author_email/text()");
setup->meta_description = xml_file_get_node_value (xml, "/gallery_setup/meta/description/text()");
setup->meta_keywords = xml_file_get_node_value (xml, "/gallery_setup/meta/keywords/text()");
- s = xml_file_get_node_attribute (xml, "/gallery_setup/images/preload", "value");
- setup->preload = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */
- g_free (s);
- s = xml_file_get_node_attribute (xml, "/gallery_setup/images/use_iptc_exif", "value");
- setup->use_iptc_exif = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */
- g_free (s);
- s = xml_file_get_node_attribute (xml, "/gallery_setup/images/erase_embed_thumbnail", "value");
- setup->erase_exif_thumbnail = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */
- g_free (s);
- s = xml_file_get_node_attribute (xml, "/gallery_setup/meta/use_title_as_meta", "value");
- setup->use_title_as_meta = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */
- g_free (s);
+ setup->preload = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/images/preload", "value", TRUE);
+ setup->use_iptc_exif = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/images/use_iptc_exif", "value", FALSE);
+ setup->erase_exif_thumbnail = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/images/erase_embed_thumbnail", "value", FALSE);
+ setup->use_title_as_meta = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/meta/use_title_as_meta", "value", TRUE);
setup->site_title = xml_file_get_node_attribute (xml, "/gallery_setup/meta/site", "title");
setup->add_copyright = xml_file_get_node_value (xml, "/gallery_setup/meta/add_copyright/text()");
- s = xml_file_get_node_attribute (xml, "/gallery_setup/navigation/use_inpage_links", "value");
- setup->use_inpage_links = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */
- g_free (s);
- s = xml_file_get_node_attribute (xml, "/gallery_setup/navigation/show_go_up", "value");
- setup->show_go_up = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */
- g_free (s);
- s = xml_file_get_node_attribute (xml, "/gallery_setup/navigation/show_exif_table", "value");
- setup->show_exif_table = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */
- g_free (s);
+ setup->use_inpage_links = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/navigation/use_inpage_links", "value", TRUE);
+ setup->show_go_up = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/navigation/show_go_up", "value", TRUE);
+ setup->show_exif_table = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/navigation/show_exif_table", "value", TRUE);
setup->nofullsize = xml_file_get_node_present (xml, "/gallery_setup/images/nofullsize");
setup->favicon_file = xml_file_get_node_value (xml, "/gallery_setup/meta/favicon/text()");
setup->favicon_type = xml_file_get_node_attribute (xml, "/gallery_setup/meta/favicon", "type");
+ setup->feed_enabled = xml_file_get_node_attribute_boolean (xml, "/gallery_setup/feed", "enable", FALSE);
+ setup->feed_filename = xml_file_get_node_value (xml, "/gallery_setup/feed/filename/text()");
+ setup->feed_title = xml_file_get_node_value (xml, "/gallery_setup/feed/title/text()");
+ setup->feed_base_url = xml_file_get_node_value (xml, "/gallery_setup/feed/base_url/text()");
+
xml_parser_close (xml);
return TRUE;
}
@@ -238,6 +227,7 @@ free_setup_data (TGallerySetup *setup)
g_free (setup->index_file_name);
g_free (setup->footer);
g_free (setup->meta_author);
+ g_free (setup->meta_author_email);
g_free (setup->border_style);
g_free (setup->site_title);
g_free (setup->add_copyright);
@@ -247,6 +237,9 @@ free_setup_data (TGallerySetup *setup)
g_free (setup->img_big_dir);
g_free (setup->img_orig_dir);
g_free (setup->thumbnail_name_format);
+ g_free (setup->feed_filename);
+ g_free (setup->feed_title);
+ g_free (setup->feed_base_url);
g_free (setup);
setup = NULL;
}
diff --git a/src/setup.h b/src/setup.h
index d4f275b..8c9927f 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -55,6 +55,7 @@ typedef struct {
gchar *footer;
gchar *meta_author;
+ gchar *meta_author_email;
gchar *meta_description;
gchar *meta_keywords;
gboolean use_title_as_meta;
@@ -87,6 +88,11 @@ typedef struct {
gchar *favicon_file;
gchar *favicon_type;
+
+ gboolean feed_enabled;
+ gchar *feed_filename;
+ gchar *feed_title;
+ gchar *feed_base_url;
} TGallerySetup;
diff --git a/src/xml-parser.c b/src/xml-parser.c
index ee40dad..70c7528 100644
--- a/src/xml-parser.c
+++ b/src/xml-parser.c
@@ -210,6 +210,19 @@ xml_file_get_node_attribute_long (TXMLFile *file, const gchar *x_path, const gch
return i;
}
+gboolean
+xml_file_get_node_attribute_boolean (TXMLFile *file, const gchar *x_path, const gchar *attr, const gboolean _default)
+{
+ gchar *s;
+ gboolean b;
+
+ s = xml_file_get_node_attribute (file, x_path, attr);
+ b = s ? (strcasecmp (s, "yes") == 0 || strcasecmp (s, "true") == 0) : _default;
+ g_free (s);
+ return b;
+}
+
+
/*
* xml_file_get_node_present: existency test of the XPath node
*/
diff --git a/src/xml-parser.h b/src/xml-parser.h
index 53abf08..3d89616 100644
--- a/src/xml-parser.h
+++ b/src/xml-parser.h
@@ -55,6 +55,7 @@ gchar * xml_file_get_node_value (TXMLFile *file, const gchar *x_path);
*/
gchar * xml_file_get_node_attribute (TXMLFile *file, const gchar *x_path, const gchar *attr);
long int xml_file_get_node_attribute_long (TXMLFile *file, const gchar *x_path, const gchar *attr, const int _default);
+gboolean xml_file_get_node_attribute_boolean (TXMLFile *file, const gchar *x_path, const gchar *attr, const gboolean _default);
/*
* xml_file_get_node_present: existency test of the XPath node