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>"); |
Chris Mayo | eca9522 | 2010-09-25 13:05:52 +0100 | [diff] [blame] | 28 | cgit_print_date(info->committer_date, FMT_ATOMDATE, 0); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 29 | html("</updated>\n"); |
| 30 | html("<author>\n"); |
| 31 | if (info->author) { |
| 32 | html("<name>"); |
| 33 | html_txt(info->author); |
| 34 | html("</name>\n"); |
| 35 | } |
Martin Szulecki | 2f56e39 | 2009-08-07 14:05:17 +0200 | [diff] [blame] | 36 | if (info->author_email && !ctx.cfg.noplainemail) { |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 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); |
| 50 | } |
| 51 | html("</author>\n"); |
| 52 | html("<published>"); |
Aaron Griffin | aaa3f78 | 2010-09-15 10:16:33 -0500 | [diff] [blame] | 53 | cgit_print_date(info->author_date, FMT_ATOMDATE, 0); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 54 | html("</published>\n"); |
| 55 | if (host) { |
Christian Hesse | ed5dccb | 2015-10-10 16:56:27 +0200 | [diff] [blame] | 56 | char *pageurl; |
Diego Ongaro | 694dd43 | 2009-06-10 18:18:34 -0500 | [diff] [blame] | 57 | html("<link rel='alternate' type='text/html' href='"); |
| 58 | html(cgit_httpscheme()); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 59 | html_attr(host); |
Christian Hesse | ed5dccb | 2015-10-10 16:56:27 +0200 | [diff] [blame] | 60 | pageurl = cgit_pageurl(ctx.repo->url, "commit", NULL); |
| 61 | html_attr(pageurl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 62 | if (ctx.cfg.virtual_root) |
| 63 | delim = '?'; |
| 64 | htmlf("%cid=%s", delim, hex); |
| 65 | html("'/>\n"); |
Christian Hesse | ed5dccb | 2015-10-10 16:56:27 +0200 | [diff] [blame] | 66 | free(pageurl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 67 | } |
| 68 | htmlf("<id>%s</id>\n", hex); |
| 69 | html("<content type='text'>\n"); |
| 70 | html_txt(info->msg); |
| 71 | html("</content>\n"); |
| 72 | html("<content type='xhtml'>\n"); |
| 73 | html("<div xmlns='http://www.w3.org/1999/xhtml'>\n"); |
| 74 | html("<pre>\n"); |
| 75 | html_txt(info->msg); |
| 76 | html("</pre>\n"); |
| 77 | html("</div>\n"); |
| 78 | html("</content>\n"); |
| 79 | html("</entry>\n"); |
| 80 | cgit_free_commitinfo(info); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | void cgit_print_atom(char *tip, char *path, int max_count) |
| 85 | { |
Christian Hesse | 144e3c6 | 2015-10-10 16:56:26 +0200 | [diff] [blame] | 86 | char *host; |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 87 | const char *argv[] = {NULL, tip, NULL, NULL, NULL}; |
| 88 | struct commit *commit; |
| 89 | struct rev_info rev; |
| 90 | int argc = 2; |
| 91 | |
Aaron Griffin | 65ced7c | 2010-02-03 18:31:17 -0600 | [diff] [blame] | 92 | if (ctx.qry.show_all) |
| 93 | argv[1] = "--all"; |
| 94 | else if (!tip) |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 95 | argv[1] = ctx.qry.head; |
| 96 | |
| 97 | if (path) { |
| 98 | argv[argc++] = "--"; |
| 99 | argv[argc++] = path; |
| 100 | } |
| 101 | |
| 102 | init_revisions(&rev, NULL); |
| 103 | rev.abbrev = DEFAULT_ABBREV; |
| 104 | rev.commit_format = CMIT_FMT_DEFAULT; |
| 105 | rev.verbose_header = 1; |
| 106 | rev.show_root_diff = 0; |
| 107 | rev.max_count = max_count; |
| 108 | setup_revisions(argc, argv, &rev, NULL); |
| 109 | prepare_revision_walk(&rev); |
| 110 | |
| 111 | host = cgit_hosturl(); |
| 112 | ctx.page.mimetype = "text/xml"; |
| 113 | ctx.page.charset = "utf-8"; |
Lukas Fleischer | f60ffa1 | 2014-01-15 21:53:15 +0100 | [diff] [blame] | 114 | cgit_print_http_headers(); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 115 | html("<feed xmlns='http://www.w3.org/2005/Atom'>\n"); |
| 116 | html("<title>"); |
| 117 | html_txt(ctx.repo->name); |
Lars Hjemli | cda1b78 | 2010-09-25 14:25:32 +0100 | [diff] [blame] | 118 | if (path) { |
| 119 | html("/"); |
| 120 | html_txt(path); |
| 121 | } |
| 122 | if (tip && !ctx.qry.show_all) { |
| 123 | html(", branch "); |
| 124 | html_txt(tip); |
| 125 | } |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 126 | html("</title>\n"); |
| 127 | html("<subtitle>"); |
| 128 | html_txt(ctx.repo->desc); |
| 129 | html("</subtitle>\n"); |
| 130 | if (host) { |
Christian Hesse | 97da17b | 2015-10-10 16:56:25 +0200 | [diff] [blame] | 131 | char *repourl = cgit_repourl(ctx.repo->url); |
Diego Ongaro | 694dd43 | 2009-06-10 18:18:34 -0500 | [diff] [blame] | 132 | html("<link rel='alternate' type='text/html' href='"); |
| 133 | html(cgit_httpscheme()); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 134 | html_attr(host); |
Christian Hesse | 97da17b | 2015-10-10 16:56:25 +0200 | [diff] [blame] | 135 | html_attr(repourl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 136 | html("'/>\n"); |
Christian Hesse | 97da17b | 2015-10-10 16:56:25 +0200 | [diff] [blame] | 137 | free(repourl); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 138 | } |
| 139 | while ((commit = get_revision(&rev)) != NULL) { |
| 140 | add_entry(commit, host); |
John Keeping | 865afe0 | 2014-07-27 11:56:19 +0100 | [diff] [blame] | 141 | free_commit_buffer(commit); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 142 | free_commit_list(commit->parents); |
| 143 | commit->parents = NULL; |
| 144 | } |
| 145 | html("</feed>\n"); |
Christian Hesse | 144e3c6 | 2015-10-10 16:56:26 +0200 | [diff] [blame] | 146 | free(host); |
Lars Hjemli | b2a3d31 | 2008-05-21 08:17:54 +0200 | [diff] [blame] | 147 | } |