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