]> gitweb.ps.run Git - ps-cgit/blob - ui-atom.c
git: update to v2.39.1
[ps-cgit] / ui-atom.c
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
14 static 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
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");
36         }
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);
51         }
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                 html_attrf("%cid=%s", delim, hex);
67                 html("'/>\n");
68                 free(pageurl);
69         }
70         html("<id>");
71         html_txtf("urn:%s:%s", the_hash_algo->name, hex);
72         html("</id>\n");
73         html("<content type='text'>\n");
74         html_txt(info->msg);
75         html("</content>\n");
76         html("</entry>\n");
77         cgit_free_commitinfo(info);
78 }
79
80
81 void cgit_print_atom(char *tip, const char *path, int max_count)
82 {
83         char *host;
84         const char *argv[] = {NULL, tip, NULL, NULL, NULL};
85         struct commit *commit;
86         struct rev_info rev;
87         int argc = 2;
88         bool first = true;
89
90         if (ctx.qry.show_all)
91                 argv[1] = "--all";
92         else if (!tip)
93                 argv[1] = ctx.qry.head;
94
95         if (path) {
96                 argv[argc++] = "--";
97                 argv[argc++] = path;
98         }
99
100         init_revisions(&rev, NULL);
101         rev.abbrev = DEFAULT_ABBREV;
102         rev.commit_format = CMIT_FMT_DEFAULT;
103         rev.verbose_header = 1;
104         rev.show_root_diff = 0;
105         rev.max_count = max_count;
106         setup_revisions(argc, argv, &rev, NULL);
107         prepare_revision_walk(&rev);
108
109         host = cgit_hosturl();
110         ctx.page.mimetype = "text/xml";
111         ctx.page.charset = "utf-8";
112         cgit_print_http_headers();
113         html("<feed xmlns='http://www.w3.org/2005/Atom'>\n");
114         html("<title>");
115         html_txt(ctx.repo->name);
116         if (path) {
117                 html("/");
118                 html_txt(path);
119         }
120         if (tip && !ctx.qry.show_all) {
121                 html(", branch ");
122                 html_txt(tip);
123         }
124         html("</title>\n");
125         html("<subtitle>");
126         html_txt(ctx.repo->desc);
127         html("</subtitle>\n");
128         if (host) {
129                 char *fullurl = cgit_currentfullurl();
130                 char *repourl = cgit_repourl(ctx.repo->url);
131                 html("<id>");
132                 html_txtf("%s%s%s", cgit_httpscheme(), host, fullurl);
133                 html("</id>\n");
134                 html("<link rel='self' href='");
135                 html_attrf("%s%s%s", cgit_httpscheme(), host, fullurl);
136                 html("'/>\n");
137                 html("<link rel='alternate' type='text/html' href='");
138                 html_attrf("%s%s%s", cgit_httpscheme(), host, repourl);
139                 html("'/>\n");
140                 free(fullurl);
141                 free(repourl);
142         }
143         while ((commit = get_revision(&rev)) != NULL) {
144                 if (first) {
145                         html("<updated>");
146                         html_txt(show_date(commit->date, 0,
147                                 date_mode_from_type(DATE_ISO8601_STRICT)));
148                         html("</updated>\n");
149                         first = false;
150                 }
151                 add_entry(commit, host);
152                 release_commit_memory(the_repository->parsed_objects, commit);
153                 commit->parents = NULL;
154         }
155         html("</feed>\n");
156         free(host);
157 }