Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 1 | /* ui-atom.c: functions for atom feeds |
| 2 | * |
Lukas Fleischer | f7f26f8 | 2014-01-08 15:10:49 +0100 | [diff] [blame] | 3 | * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 4 | * |
| 5 | * Licensed under GNU General Public License v2 |
| 6 | * (see COPYING for full license text) |
| 7 | */ |
| 8 | |
| 9 | #include "cgit.h" |
John Keeping | 8f20879 | 2013-04-06 11:37:59 +0100 | [diff] [blame] | 10 | #include "ui-atom.h" |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 11 | #include "html.h" |
| 12 | #include "ui-shared.h" |
| 13 | |
Lukas Fleischer | 996f86e | 2013-04-01 17:11:13 +0200 | [diff] [blame] | 14 | static void add_entry(struct commit *commit, const char *host) |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 15 | { |
| 16 | char delim = '&'; |
| 17 | char *hex; |
| 18 | char *mail, *t, *t2; |
| 19 | struct commitinfo *info; |
| 20 | |
| 21 | info = cgit_parse_commit(commit); |
Christian Hesse | 559ab5e | 2016-01-05 07:38:53 +0100 | [diff] [blame] | 22 | hex = oid_to_hex(&commit->object.oid); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 23 | html("<entry>\n"); |
| 24 | html("<title>"); |
| 25 | html_txt(info->subject); |
| 26 | html("</title>\n"); |
| 27 | html("<updated>"); |
John Keeping | 7529820 | 2016-02-08 15:06:27 +0000 | [diff] [blame] | 28 | html_txt(show_date(info->committer_date, 0, |
| 29 | date_mode_from_type(DATE_ISO8601_STRICT))); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 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 | } |
Martin Szulecki | 2f56e39 | 2009-08-07 14:05:17 +0200 | [diff] [blame] | 37 | if (info->author_email && !ctx.cfg.noplainemail) { |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 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>"); |
John Keeping | 7529820 | 2016-02-08 15:06:27 +0000 | [diff] [blame] | 54 | html_txt(show_date(info->author_date, 0, |
| 55 | date_mode_from_type(DATE_ISO8601_STRICT))); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 56 | html("</published>\n"); |
| 57 | if (host) { |
Christian Hesse | ed5dccb | 2015-10-10 16:56:27 +0200 | [diff] [blame] | 58 | char *pageurl; |
Diego Ongaro | 694dd43 | 2009-06-10 18:18:34 -0500 | [diff] [blame] | 59 | html("<link rel='alternate' type='text/html' href='"); |
| 60 | html(cgit_httpscheme()); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 61 | html_attr(host); |
Christian Hesse | ed5dccb | 2015-10-10 16:56:27 +0200 | [diff] [blame] | 62 | pageurl = cgit_pageurl(ctx.repo->url, "commit", NULL); |
| 63 | html_attr(pageurl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 64 | if (ctx.cfg.virtual_root) |
| 65 | delim = '?'; |
John Keeping | 6d3c8bc | 2017-01-15 12:29:38 +0000 | [diff] [blame] | 66 | html_attrf("%cid=%s", delim, hex); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 67 | html("'/>\n"); |
Christian Hesse | ed5dccb | 2015-10-10 16:56:27 +0200 | [diff] [blame] | 68 | free(pageurl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 69 | } |
| 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); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | void cgit_print_atom(char *tip, char *path, int max_count) |
| 87 | { |
Christian Hesse | 144e3c6 | 2015-10-10 16:56:26 +0200 | [diff] [blame] | 88 | char *host; |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 89 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
| 90 | struct commit *commit; |
| 91 | struct rev_info rev; |
| 92 | int argc = 2; |
| 93 | |
Aaron Griffin | 65ced7c | 2010-02-03 18:31:17 -0600 | [diff] [blame] | 94 | if (ctx.qry.show_all) |
| 95 | argv[1] = "--all"; |
| 96 | else if (!tip) |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 97 | argv[1] = ctx.qry.head; |
| 98 | |
| 99 | if (path) { |
| 100 | argv[argc++] = "--"; |
| 101 | argv[argc++] = path; |
| 102 | } |
| 103 | |
| 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); |
| 112 | |
| 113 | host = cgit_hosturl(); |
| 114 | ctx.page.mimetype = "text/xml"; |
| 115 | ctx.page.charset = "utf-8"; |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 116 | cgit_print_http_headers(); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 117 | html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); |
| 118 | html("<title>"); |
| 119 | html_txt(ctx.repo->name); |
Lars Hjemli | cda1b78 | 2010-09-25 14:25:32 +0100 | [diff] [blame] | 120 | if (path) { |
| 121 | html("/"); |
| 122 | html_txt(path); |
| 123 | } |
| 124 | if (tip && !ctx.qry.show_all) { |
| 125 | html(", branch "); |
| 126 | html_txt(tip); |
| 127 | } |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 128 | html("</title>\n"); |
| 129 | html("<subtitle>"); |
| 130 | html_txt(ctx.repo->desc); |
| 131 | html("</subtitle>\n"); |
| 132 | if (host) { |
Christian Hesse | 97da17b | 2015-10-10 16:56:25 +0200 | [diff] [blame] | 133 | char *repourl = cgit_repourl(ctx.repo->url); |
Diego Ongaro | 694dd43 | 2009-06-10 18:18:34 -0500 | [diff] [blame] | 134 | html("<link rel='alternate' type='text/html' href='"); |
| 135 | html(cgit_httpscheme()); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 136 | html_attr(host); |
Christian Hesse | 97da17b | 2015-10-10 16:56:25 +0200 | [diff] [blame] | 137 | html_attr(repourl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 138 | html("'/>\n"); |
Christian Hesse | 97da17b | 2015-10-10 16:56:25 +0200 | [diff] [blame] | 139 | free(repourl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 140 | } |
| 141 | while ((commit = get_revision(&rev)) != NULL) { |
| 142 | add_entry(commit, host); |
John Keeping | 865afe0 | 2014-07-27 11:56:19 +0100 | [diff] [blame] | 143 | free_commit_buffer(commit); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 144 | free_commit_list(commit->parents); |
| 145 | commit->parents = NULL; |
| 146 | } |
| 147 | html("</feed>\n"); |
Christian Hesse | 144e3c6 | 2015-10-10 16:56:26 +0200 | [diff] [blame] | 148 | free(host); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 149 | } |