summaryrefslogtreecommitdiffstatshomepage
path: root/ui-tag.c
blob: 2c96c37efc6cc7be4643b9ecbc5d6031755cf310 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* ui-tag.c: display a tag
 *
 * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com>
 *
 * Licensed under GNU General Public License v2
 *   (see COPYING for full license text)
 */

#include "cgit.h"
#include "ui-tag.h"
#include "html.h"
#include "ui-shared.h"

static void print_tag_content(char *buf)
{
	char *p;

	if (!buf)
		return;

	html("<div class='commit-subject'>");
	p = strchr(buf, '\n');
	if (p)
		*p = '\0';
	html_txt(buf);
	html("</div>");
	if (p) {
		html("<div class='commit-msg'>");
		html_txt(++p);
		html("</div>");
	}
}

static void print_download_links(char *revname)
{
	html("<tr><th>download</th><td class='sha1'>");
	cgit_print_snapshot_links(ctx.repo, revname, "<br/>");
	html("</td></tr>");
}

void cgit_print_tag(char *revname)
{
	struct strbuf fullref = STRBUF_INIT;
	struct object_id oid;
	struct object *obj;

	if (!revname)
		revname = ctx.qry.head;

	strbuf_addf(&fullref, "refs/tags/%s", revname);
	if (get_oid(fullref.buf, &oid)) {
		cgit_print_error_page(404, "Not found",
			"Bad tag reference: %s", revname);
		goto cleanup;
	}
	obj = parse_object(&oid);
	if (!obj) {
		cgit_print_error_page(500, "Internal server error",
			"Bad object id: %s", oid_to_hex(&oid));
		goto cleanup;
	}
	if (obj->type == OBJ_TAG) {
		struct tag *tag;
		struct taginfo *info;

		tag = lookup_tag(&oid);
		if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) {
			cgit_print_error_page(500, "Internal server error",
				"Bad tag object: %s", revname);
			goto cleanup;
		}
		cgit_print_layout_start();
		html("<table class='commit-info'>\n");
		htmlf("<tr><td>tag name</td><td>");
		html_txt(revname);
		htmlf(" (%s)</td></tr>\n", oid_to_hex(&oid));
		if (info->tagger_date > 0) {
			html("<tr><td>tag date</td><td>");
			html_txt(show_date(info->tagger_date, info->tagger_tz,
						cgit_date_mode(DATE_ISO8601)));
			html("</td></tr>\n");
		}
		if (info->tagger) {
			html("<tr><td>tagged by</td><td>");
			cgit_open_filter(ctx.repo->email_filter, info->tagger_email, "tag");
			html_txt(info->tagger);
			if (info->tagger_email && !ctx.cfg.noplainemail) {
				html(" ");
				html_txt(info->tagger_email);
			}
			cgit_close_filter(ctx.repo->email_filter);
			html("</td></tr>\n");
		}
		html("<tr><td>tagged object</td><td class='sha1'>");
		cgit_object_link(tag->tagged);
		html("</td></tr>\n");
		if (ctx.repo->snapshots)
			print_download_links(revname);
		html("</table>\n");
		print_tag_content(info->msg);
		cgit_print_layout_end();
		cgit_free_taginfo(info);
	} else {
		cgit_print_layout_start();
		html("<table class='commit-info'>\n");
		htmlf("<tr><td>tag name</td><td>");
		html_txt(revname);
		html("</td></tr>\n");
		html("<tr><td>tagged object</td><td class='sha1'>");
		cgit_object_link(obj);
		html("</td></tr>\n");
		if (ctx.repo->snapshots)
			print_download_links(revname);
		html("</table>\n");
		cgit_print_layout_end();
	}

cleanup:
	strbuf_release(&fullref);
}
* @brief Mutex for #get_buffer a.k.a. _curl_buffer_body. * * This mutex is locked before anything is read or written from/to * _curl_buffer_body. * * @since 0.1.0 */ mutex buffer_mutex; /*! * @brief Make a HTTP request. * * @param method The HTTP method. * @param uri The full URI. * @param parameters A map of parameters. * * @since 0.1.0 */ [[nodiscard]] answer_type make_request(const http_method &method, string uri, const parametermap &parameters); /*! * @brief Returns a reference to the buffer libcurl writes into. * * @since 0.1.0 */ [[nodiscard]] string &get_buffer() { return _curl_buffer_body; } /*! * @brief Cancel the stream. * * The stream will be cancelled, usually whithin a second. The @link * answer_type::curl_error_code curl_error_code @endlink of the answer will * be set to 42 (`CURLE_ABORTED_BY_CALLBACK`). * * @since 0.1.0 */ inline void cancel_stream() { _stream_cancelled = true; } /*! * @brief Set OAuth 2.0 Bearer Access Token. * * @since 0.1.0 */ void set_access_token(const string_view access_token); private: CURL *_connection; char _curl_buffer_error[CURL_ERROR_SIZE]; string _curl_buffer_headers; string _curl_buffer_body; bool _stream_cancelled; /*! * @brief libcurl write callback function. * * @since 0.1.0 */ size_t writer_body(char *data, size_t size, size_t nmemb); /*! * @brief Wrapper for curl, because it can only call static member * functions. * * <https://curl.haxx.se/docs/faq.html#Using_C_non_static_functions_f> * * @since 0.1.0 */ static inline size_t writer_body_wrapper(char *data, size_t sz, size_t nmemb, void *f) { return static_cast<CURLWrapper*>(f)->writer_body(data, sz, nmemb); } //! @copydoc writer_body size_t writer_header(char *data, size_t size, size_t nmemb); //! @copydoc writer_body_wrapper static inline size_t writer_header_wrapper(char *data, size_t sz, size_t nmemb, void *f) { return static_cast<CURLWrapper*>(f)->writer_header(data, sz, nmemb); } /*! * @brief libcurl transfer info function. * * Used to cancel streams. * * @since 0.1.0 */ int progress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow); //! @copydoc writer_body_wrapper static inline int progress_wrapper(void *f, void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { return static_cast<CURLWrapper*>(f)->progress(clientp, dltotal, dlnow, ultotal, ulnow); } /*! * @brief Setup libcurl connection. * * @since 0.1.0 */ void setup_curl(); /*! * @brief Replace parameter in URI. * * @param uri Reference to the URI. * @param parameter The parameter. * * @return true if parameter was replaced. * * @since 0.1.0 */ bool replace_parameter_in_uri(string &uri, const parameterpair &parameter); /*! * @brief Add parameters to URI. * * @param uri Reference to the URI. * @param parameters The parametermap. * * @since 0.1.0 */ void add_parameters_to_uri(string &uri, const parametermap &parameters); /*! * @brief Add `*curl_mimepart` to `*curl_mime`. * * @param mime Initialized `*curl_mime`. @param name Name of the field. * @param data Data of the field. If it begins with <tt>`\@file:<tt>, the * rest of the ergument is treated as a filename. * * @since 0.1.1 */ void add_mime_part(curl_mime *mime, string_view name, string_view data) const; /*! * @brief Convert parametermap to `*curl_mime`. * * For more information consult [curl_mime_init(3)] * (https://curl.haxx.se/libcurl/c/curl_mime_init.html). Calls * replace_parameter_in_uri(). * * @param uri Reference to the URI. * @param parameters The parametermap. * * @return `*curl_mime`. * * @since 0.1.0 */ curl_mime *parameters_to_curl_mime(string &uri, const parametermap &parameters); }; } // namespace mastodonpp #endif // MASTODONPP_CURL_WRAPPER_HPP