all repos — cgit @ a8b9ef8c1c68fbb9c89db2d8c12dca38c15e2bfd

a hyperfast web frontend for git written in c

ui-atom.c (view raw)

  1/* ui-atom.c: functions for atom feeds
  2 *
  3 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
  4 *
  5 * Licensed under GNU General Public License v2
  6 *   (see COPYING for full license text)
  7 */
  8
  9#include "cgit.h"
 10#include "ui-atom.h"
 11#include "html.h"
 12#include "ui-shared.h"
 13
 14static void add_entry(struct commit *commit, const char *host)
 15{
 16	char delim = '&';
 17	char *hex;
 18	char *mail, *t, *t2;
 19	struct commitinfo *info;
 20	struct date_mode mode = {
 21		.type = DATE_STRFTIME,
 22		.strftime_fmt = FMT_ATOMDATE,
 23		.local = 0,
 24	};
 25
 26	info = cgit_parse_commit(commit);
 27	hex = oid_to_hex(&commit->object.oid);
 28	html("<entry>\n");
 29	html("<title>");
 30	html_txt(info->subject);
 31	html("</title>\n");
 32	html("<updated>");
 33	html_txt(show_date(info->committer_date, 0, &mode));
 34	html("</updated>\n");
 35	html("<author>\n");
 36	if (info->author) {
 37		html("<name>");
 38		html_txt(info->author);
 39		html("</name>\n");
 40	}
 41	if (info->author_email && !ctx.cfg.noplainemail) {
 42		mail = xstrdup(info->author_email);
 43		t = strchr(mail, '<');
 44		if (t)
 45			t++;
 46		else
 47			t = mail;
 48		t2 = strchr(t, '>');
 49		if (t2)
 50			*t2 = '\0';
 51		html("<email>");
 52		html_txt(t);
 53		html("</email>\n");
 54		free(mail);
 55	}
 56	html("</author>\n");
 57	html("<published>");
 58	html_txt(show_date(info->author_date, 0, &mode));
 59	html("</published>\n");
 60	if (host) {
 61		char *pageurl;
 62		html("<link rel='alternate' type='text/html' href='");
 63		html(cgit_httpscheme());
 64		html_attr(host);
 65		pageurl = cgit_pageurl(ctx.repo->url, "commit", NULL);
 66		html_attr(pageurl);
 67		if (ctx.cfg.virtual_root)
 68			delim = '?';
 69		htmlf("%cid=%s", delim, hex);
 70		html("'/>\n");
 71		free(pageurl);
 72	}
 73	htmlf("<id>%s</id>\n", hex);
 74	html("<content type='text'>\n");
 75	html_txt(info->msg);
 76	html("</content>\n");
 77	html("<content type='xhtml'>\n");
 78	html("<div xmlns='http://www.w3.org/1999/xhtml'>\n");
 79	html("<pre>\n");
 80	html_txt(info->msg);
 81	html("</pre>\n");
 82	html("</div>\n");
 83	html("</content>\n");
 84	html("</entry>\n");
 85	cgit_free_commitinfo(info);
 86}
 87
 88
 89void cgit_print_atom(char *tip, char *path, int max_count)
 90{
 91	char *host;
 92	const char *argv[] = {NULL, tip, NULL, NULL, NULL};
 93	struct commit *commit;
 94	struct rev_info rev;
 95	int argc = 2;
 96
 97	if (ctx.qry.show_all)
 98		argv[1] = "--all";
 99	else if (!tip)
100		argv[1] = ctx.qry.head;
101
102	if (path) {
103		argv[argc++] = "--";
104		argv[argc++] = path;
105	}
106
107	init_revisions(&rev, NULL);
108	rev.abbrev = DEFAULT_ABBREV;
109	rev.commit_format = CMIT_FMT_DEFAULT;
110	rev.verbose_header = 1;
111	rev.show_root_diff = 0;
112	rev.max_count = max_count;
113	setup_revisions(argc, argv, &rev, NULL);
114	prepare_revision_walk(&rev);
115
116	host = cgit_hosturl();
117	ctx.page.mimetype = "text/xml";
118	ctx.page.charset = "utf-8";
119	cgit_print_http_headers();
120	html("<feed xmlns='http://www.w3.org/2005/Atom'>\n");
121	html("<title>");
122	html_txt(ctx.repo->name);
123	if (path) {
124		html("/");
125		html_txt(path);
126	}
127	if (tip && !ctx.qry.show_all) {
128		html(", branch ");
129		html_txt(tip);
130	}
131	html("</title>\n");
132	html("<subtitle>");
133	html_txt(ctx.repo->desc);
134	html("</subtitle>\n");
135	if (host) {
136		char *repourl = cgit_repourl(ctx.repo->url);
137		html("<link rel='alternate' type='text/html' href='");
138		html(cgit_httpscheme());
139		html_attr(host);
140		html_attr(repourl);
141		html("'/>\n");
142		free(repourl);
143	}
144	while ((commit = get_revision(&rev)) != NULL) {
145		add_entry(commit, host);
146		free_commit_buffer(commit);
147		free_commit_list(commit->parents);
148		commit->parents = NULL;
149	}
150	html("</feed>\n");
151	free(host);
152}