filter: don't use dlsym unnecessarily
[cgit.git] / ui-atom.c
blobe2b39ee1d1c51cb109e69dc65b26feefe866d76d
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 = 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>");
28 cgit_print_date(info->committer_date, FMT_ATOMDATE, 0);
29 html("</updated>\n");
30 html("<author>\n");
31 if (info->author) {
32 html("<name>");
33 html_txt(info->author);
34 html("</name>\n");
36 if (info->author_email && !ctx.cfg.noplainemail) {
37 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);
51 html("</author>\n");
52 html("<published>");
53 cgit_print_date(info->author_date, FMT_ATOMDATE, 0);
54 html("</published>\n");
55 if (host) {
56 html("<link rel='alternate' type='text/html' href='");
57 html(cgit_httpscheme());
58 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");
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);
81 void cgit_print_atom(char *tip, char *path, int max_count)
83 const char *host;
84 const char *argv[] = {NULL, tip, NULL, NULL, NULL};
85 struct commit *commit;
86 struct rev_info rev;
87 int argc = 2;
89 if (ctx.qry.show_all)
90 argv[1] = "--all";
91 else if (!tip)
92 argv[1] = ctx.qry.head;
94 if (path) {
95 argv[argc++] = "--";
96 argv[argc++] = path;
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);
108 host = cgit_hosturl();
109 ctx.page.mimetype = "text/xml";
110 ctx.page.charset = "utf-8";
111 cgit_print_http_headers();
112 html("<feed xmlns='http://www.w3.org/2005/Atom'>\n");
113 html("<title>");
114 html_txt(ctx.repo->name);
115 if (path) {
116 html("/");
117 html_txt(path);
119 if (tip && !ctx.qry.show_all) {
120 html(", branch ");
121 html_txt(tip);
123 html("</title>\n");
124 html("<subtitle>");
125 html_txt(ctx.repo->desc);
126 html("</subtitle>\n");
127 if (host) {
128 html("<link rel='alternate' type='text/html' href='");
129 html(cgit_httpscheme());
130 html_attr(host);
131 html_attr(cgit_repourl(ctx.repo->url));
132 html("'/>\n");
134 while ((commit = get_revision(&rev)) != NULL) {
135 add_entry(commit, host);
136 free_commit_buffer(commit);
137 free_commit_list(commit->parents);
138 commit->parents = NULL;
140 html("</feed>\n");