blob: e2b39ee1d1c51cb109e69dc65b26feefe866d76d [file] [log] [blame]
Lars Hjemlib2a3d312008-05-21 08:17:54 +02001/* ui-atom.c: functions for atom feeds
2 *
Lukas Fleischerf7f26f82014-01-08 15:10:49 +01003 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
Lars Hjemlib2a3d312008-05-21 08:17:54 +02004 *
5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text)
7 */
8
9#include "cgit.h"
John Keeping8f208792013-04-06 11:37:59 +010010#include "ui-atom.h"
Lars Hjemlib2a3d312008-05-21 08:17:54 +020011#include "html.h"
12#include "ui-shared.h"
13
Lukas Fleischer996f86e2013-04-01 17:11:13 +020014static void add_entry(struct commit *commit, const char *host)
Lars Hjemlib2a3d312008-05-21 08:17:54 +020015{
16 char delim = '&';
17 char *hex;
18 char *mail, *t, *t2;
19 struct commitinfo *info;
20
21 info = cgit_parse_commit(commit);
22 hex = sha1_to_hex(commit->object.sha1);
23 html("<entry>\n");
24 html("<title>");
25 html_txt(info->subject);
26 html("</title>\n");
27 html("<updated>");
Chris Mayoeca95222010-09-25 13:05:52 +010028 cgit_print_date(info->committer_date, FMT_ATOMDATE, 0);
Lars Hjemlib2a3d312008-05-21 08:17:54 +020029 html("</updated>\n");
30 html("<author>\n");
31 if (info->author) {
32 html("<name>");
33 html_txt(info->author);
34 html("</name>\n");
35 }
Martin Szulecki2f56e392009-08-07 14:05:17 +020036 if (info->author_email && !ctx.cfg.noplainemail) {
Lars Hjemlib2a3d312008-05-21 08:17:54 +020037 mail = xstrdup(info->author_email);
38 t = strchr(mail, '<');
39 if (t)
40 t++;
41 else
42 t = mail;
43 t2 = strchr(t, '>');
44 if (t2)
45 *t2 = '\0';
46 html("<email>");
47 html_txt(t);
48 html("</email>\n");
49 free(mail);
50 }
51 html("</author>\n");
52 html("<published>");
Aaron Griffinaaa3f782010-09-15 10:16:33 -050053 cgit_print_date(info->author_date, FMT_ATOMDATE, 0);
Lars Hjemlib2a3d312008-05-21 08:17:54 +020054 html("</published>\n");
55 if (host) {
Diego Ongaro694dd432009-06-10 18:18:34 -050056 html("<link rel='alternate' type='text/html' href='");
57 html(cgit_httpscheme());
Lars Hjemlib2a3d312008-05-21 08:17:54 +020058 html_attr(host);
59 html_attr(cgit_pageurl(ctx.repo->url, "commit", NULL));
60 if (ctx.cfg.virtual_root)
61 delim = '?';
62 htmlf("%cid=%s", delim, hex);
63 html("'/>\n");
64 }
65 htmlf("<id>%s</id>\n", hex);
66 html("<content type='text'>\n");
67 html_txt(info->msg);
68 html("</content>\n");
69 html("<content type='xhtml'>\n");
70 html("<div xmlns='http://www.w3.org/1999/xhtml'>\n");
71 html("<pre>\n");
72 html_txt(info->msg);
73 html("</pre>\n");
74 html("</div>\n");
75 html("</content>\n");
76 html("</entry>\n");
77 cgit_free_commitinfo(info);
78}
79
80
81void cgit_print_atom(char *tip, char *path, int max_count)
82{
Lukas Fleischer996f86e2013-04-01 17:11:13 +020083 const char *host;
Lars Hjemlib2a3d312008-05-21 08:17:54 +020084 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
85 struct commit *commit;
86 struct rev_info rev;
87 int argc = 2;
88
Aaron Griffin65ced7c2010-02-03 18:31:17 -060089 if (ctx.qry.show_all)
90 argv[1] = "--all";
91 else if (!tip)
Lars Hjemlib2a3d312008-05-21 08:17:54 +020092 argv[1] = ctx.qry.head;
93
94 if (path) {
95 argv[argc++] = "--";
96 argv[argc++] = path;
97 }
98
99 init_revisions(&rev, NULL);
100 rev.abbrev = DEFAULT_ABBREV;
101 rev.commit_format = CMIT_FMT_DEFAULT;
102 rev.verbose_header = 1;
103 rev.show_root_diff = 0;
104 rev.max_count = max_count;
105 setup_revisions(argc, argv, &rev, NULL);
106 prepare_revision_walk(&rev);
107
108 host = cgit_hosturl();
109 ctx.page.mimetype = "text/xml";
110 ctx.page.charset = "utf-8";
Lukas Fleischerf60ffa12014-01-15 21:53:15 +0100111 cgit_print_http_headers();
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200112 html("<feed xmlns='http://www.w3.org/2005/Atom'>\n");
113 html("<title>");
114 html_txt(ctx.repo->name);
Lars Hjemlicda1b782010-09-25 14:25:32 +0100115 if (path) {
116 html("/");
117 html_txt(path);
118 }
119 if (tip && !ctx.qry.show_all) {
120 html(", branch ");
121 html_txt(tip);
122 }
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200123 html("</title>\n");
124 html("<subtitle>");
125 html_txt(ctx.repo->desc);
126 html("</subtitle>\n");
127 if (host) {
Diego Ongaro694dd432009-06-10 18:18:34 -0500128 html("<link rel='alternate' type='text/html' href='");
129 html(cgit_httpscheme());
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200130 html_attr(host);
131 html_attr(cgit_repourl(ctx.repo->url));
132 html("'/>\n");
133 }
134 while ((commit = get_revision(&rev)) != NULL) {
135 add_entry(commit, host);
John Keeping865afe02014-07-27 11:56:19 +0100136 free_commit_buffer(commit);
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200137 free_commit_list(commit->parents);
138 commit->parents = NULL;
139 }
140 html("</feed>\n");
141}