From 80767bc9732bf6716697198e53ff2cb8d4ae96be Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Wed, 12 Aug 2026 18:23:17 -1000 Subject: Restyle the sources and fix the audit's findings --- source/ui-atom.c | 107 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 41 deletions(-) (limited to 'source/ui-atom.c') diff --git a/source/ui-atom.c b/source/ui-atom.c index f968e24..aa9237a 100644 --- a/source/ui-atom.c +++ b/source/ui-atom.c @@ -1,24 +1,57 @@ -/* ui-atom.c: functions for atom feeds - * - * Copyright (C) 2006-2014 cgit Development Team - * - * Licensed under GNU General Public License v2 - * (see LICENSE.txt for full license text) +/* + * The Atom feed for a repository, which lists recent commits so a reader can + * follow the project from a feed reader instead of the browsable pages. The + * response is XML rather than a page, so this file writes its own HTTP headers + * and never goes through the shared HTML layout. */ #define USE_THE_REPOSITORY_VARIABLE #include "cgit.h" -#include "ui-atom.h" #include "html.h" +#include "parsing.h" +#include "shared.h" +#include "ui-atom.h" #include "ui-shared.h" -static void add_entry(struct commit *commit, const char *host) +/* + * Atom timestamps have to be RFC 3339, so a feed ignores the date-format and + * local-time settings the browsable pages honour. The zero is the timezone + * offset, which pins every feed date to UTC. + */ +static const char *feed_date(timestamp_t when) +{ + return show_date(when, 0, date_mode_from_type(DATE_ISO8601_STRICT)); +} + +/* + * cgit keeps an address with the angle brackets it was written with, while + * Atom wants the bare address. + */ +static void print_email(const char *email) +{ + char *copy = xstrdup(email); + char *start, *end; + + start = strchr(copy, '<'); + if (start) + start++; + else + start = copy; + end = strchr(start, '>'); + if (end) + *end = '\0'; + + html(""); + html_txt(start); + html("\n"); + free(copy); +} + +static void print_entry(struct commit *commit, const char *host) { - char delim = '&'; - char *hex; - char *mail, *t, *t2; struct commitinfo *info; + char *hex; info = cgit_parse_commit(commit); hex = oid_to_hex(&commit->object.oid); @@ -27,8 +60,7 @@ static void add_entry(struct commit *commit, const char *host) html_txt(info->subject); html("\n"); html(""); - html_txt(show_date(info->committer_date, 0, - date_mode_from_type(DATE_ISO8601_STRICT))); + html_txt(feed_date(info->committer_date)); html("\n"); html("\n"); if (info->author) { @@ -36,33 +68,24 @@ static void add_entry(struct commit *commit, const char *host) html_txt(info->author); html("\n"); } - if (info->author_email && !ctx.cfg.noplainemail) { - mail = xstrdup(info->author_email); - t = strchr(mail, '<'); - if (t) - t++; - else - t = mail; - t2 = strchr(t, '>'); - if (t2) - *t2 = '\0'; - html(""); - html_txt(t); - html("\n"); - free(mail); - } + if (info->author_email && !ctx.cfg.noplainemail) + print_email(info->author_email); html("\n"); html(""); - html_txt(show_date(info->author_date, 0, - date_mode_from_type(DATE_ISO8601_STRICT))); + html_txt(feed_date(info->author_date)); html("\n"); if (host) { char *pageurl; + char delim = '&'; + html(""); - html_txt(show_date(commit->date, 0, - date_mode_from_type(DATE_ISO8601_STRICT))); + html_txt(feed_date(commit->date)); html("\n"); - first = false; + need_updated = false; } - add_entry(commit, host); + print_entry(commit, host); + // release_commit_memory frees the parent list without clearing + // the pointer to it, so drop the dangling reference here. release_commit_memory(the_repository->parsed_objects, commit); commit->parents = NULL; } - if (first) { - /* An empty feed still needs one feed-level . */ + if (need_updated) { + // Atom makes a feed level updated mandatory, and an empty feed + // has no commit to take one from. html(""); - html_txt(show_date(time(NULL), 0, - date_mode_from_type(DATE_ISO8601_STRICT))); + html_txt(feed_date(time(NULL))); html("\n"); } html("\n"); -- cgit v2.8.0