blob: 0bf2cf20c7af1834dfcd8b4eaa1dcff08471499b [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;
John Keepingeb80b4e2016-01-19 19:33:07 +000020 struct date_mode mode = {
21 .type = DATE_STRFTIME,
22 .strftime_fmt = FMT_ATOMDATE,
23 .local = 0,
24 };
Lars Hjemlib2a3d312008-05-21 08:17:54 +020025
26 info = cgit_parse_commit(commit);
Christian Hesse559ab5e2016-01-05 07:38:53 +010027 hex = oid_to_hex(&commit->object.oid);
Lars Hjemlib2a3d312008-05-21 08:17:54 +020028 html("<entry>\n");
29 html("<title>");
30 html_txt(info->subject);
31 html("</title>\n");
32 html("<updated>");
John Keepingeb80b4e2016-01-19 19:33:07 +000033 html_txt(show_date(info->committer_date, 0, &mode));
Lars Hjemlib2a3d312008-05-21 08:17:54 +020034 html("</updated>\n");
35 html("<author>\n");
36 if (info->author) {
37 html("<name>");
38 html_txt(info->author);
39 html("</name>\n");
40 }
Martin Szulecki2f56e392009-08-07 14:05:17 +020041 if (info->author_email && !ctx.cfg.noplainemail) {
Lars Hjemlib2a3d312008-05-21 08:17:54 +020042 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>");
John Keepingeb80b4e2016-01-19 19:33:07 +000058 html_txt(show_date(info->author_date, 0, &mode));
Lars Hjemlib2a3d312008-05-21 08:17:54 +020059 html("</published>\n");
60 if (host) {
Christian Hesseed5dccb2015-10-10 16:56:27 +020061 char *pageurl;
Diego Ongaro694dd432009-06-10 18:18:34 -050062 html("<link rel='alternate' type='text/html' href='");
63 html(cgit_httpscheme());
Lars Hjemlib2a3d312008-05-21 08:17:54 +020064 html_attr(host);
Christian Hesseed5dccb2015-10-10 16:56:27 +020065 pageurl = cgit_pageurl(ctx.repo->url, "commit", NULL);
66 html_attr(pageurl);
Lars Hjemlib2a3d312008-05-21 08:17:54 +020067 if (ctx.cfg.virtual_root)
68 delim = '?';
69 htmlf("%cid=%s", delim, hex);
70 html("'/>\n");
Christian Hesseed5dccb2015-10-10 16:56:27 +020071 free(pageurl);
Lars Hjemlib2a3d312008-05-21 08:17:54 +020072 }
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{
Christian Hesse144e3c62015-10-10 16:56:26 +020091 char *host;
Lars Hjemlib2a3d312008-05-21 08:17:54 +020092 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
93 struct commit *commit;
94 struct rev_info rev;
95 int argc = 2;
96
Aaron Griffin65ced7c2010-02-03 18:31:17 -060097 if (ctx.qry.show_all)
98 argv[1] = "--all";
99 else if (!tip)
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200100 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";
Lukas Fleischerf60ffa12014-01-15 21:53:15 +0100119 cgit_print_http_headers();
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200120 html("<feed xmlns='http://www.w3.org/2005/Atom'>\n");
121 html("<title>");
122 html_txt(ctx.repo->name);
Lars Hjemlicda1b782010-09-25 14:25:32 +0100123 if (path) {
124 html("/");
125 html_txt(path);
126 }
127 if (tip && !ctx.qry.show_all) {
128 html(", branch ");
129 html_txt(tip);
130 }
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200131 html("</title>\n");
132 html("<subtitle>");
133 html_txt(ctx.repo->desc);
134 html("</subtitle>\n");
135 if (host) {
Christian Hesse97da17b2015-10-10 16:56:25 +0200136 char *repourl = cgit_repourl(ctx.repo->url);
Diego Ongaro694dd432009-06-10 18:18:34 -0500137 html("<link rel='alternate' type='text/html' href='");
138 html(cgit_httpscheme());
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200139 html_attr(host);
Christian Hesse97da17b2015-10-10 16:56:25 +0200140 html_attr(repourl);
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200141 html("'/>\n");
Christian Hesse97da17b2015-10-10 16:56:25 +0200142 free(repourl);
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200143 }
144 while ((commit = get_revision(&rev)) != NULL) {
145 add_entry(commit, host);
John Keeping865afe02014-07-27 11:56:19 +0100146 free_commit_buffer(commit);
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200147 free_commit_list(commit->parents);
148 commit->parents = NULL;
149 }
150 html("</feed>\n");
Christian Hesse144e3c62015-10-10 16:56:26 +0200151 free(host);
Lars Hjemlib2a3d312008-05-21 08:17:54 +0200152}