blob: 5a1e5fc6f0d5fb2c16fb61177dd1bd5bf9eacd0f (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * The page furniture and the link builders every renderer shares. A page
 * handler renders its own body and calls in here for all that surrounds it,
 * which is the HTTP headers, the document head and footer, the header block
 * with its tabs and search form, the error page, and an anchor to any other
 * cgit page. Whether a site addresses a request as a path below a virtual root
 * or as a query string is settled behind these calls, so that nothing else has
 * to know which of the two it is looking at.
 */

#ifndef CGIT_UI_SHARED_H
#define CGIT_UI_SHARED_H

#include "cgit.h"
extern const char *cgit_httpscheme(void);
extern char *cgit_hosturl(void);

/*
 * The URL of the request being answered, which cgit_currentfullurl gives with
 * the query string on the end as well, minus the url argument that the path
 * was taken from. cgit_currentquery is that query string alone, led by its
 * question mark, or an empty string when nothing is left of it.
 */
extern char *cgit_currenturl(void);
extern char *cgit_currentfullurl(void);
extern char *cgit_currentquery(void);
extern const char *cgit_loginurl(void);

/*
 * The urls of a repository and of its pages. The repository url is encoded
 * here, since it is configuration or a scanned path and may hold any byte,
 * while a page name, file name or query must arrive encoded already. The
 * result still needs escaping for wherever it lands.
 */
extern char *cgit_repourl(const char *reponame);
extern void cgit_print_clone_row(const char *url, int colspan);
extern char *cgit_fileurl(const char *reponame, const char *pagename, const char *filename,
	const char *query);
extern char *cgit_pageurl(const char *reponame, const char *pagename, const char *query);

/*
 * The url of the current repository's tree page at head, split where a path
 * in the tree goes, for a filter to build links of its own from. Both parts
 * are escaped for a url but not for HTML, and query stays empty for the
 * default branch.
 */
extern void cgit_tree_url(const char *head, struct strbuf *base, struct strbuf *query);

/*
 * Call fn once for every URL this repository can be cloned from.
 */
extern void cgit_add_clone_urls(void (*fn)(const char *));

/*
 * Each of these writes one anchor to the page and nothing around it, with name
 * as the text a reader sees. A NULL title or class leaves that attribute out,
 * and what follows them is the state the target page should open in.
 */
extern void cgit_index_link(const char *name, const char *title, const char *class,
	const char *pattern, const char *sort, int ofs, int always_root);
extern void cgit_summary_link(const char *name, const char *title, const char *class,
	const char *head);
extern void cgit_tag_link(const char *name, const char *title, const char *class, const char *tag);
extern void cgit_tree_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_plain_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_blame_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_log_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path, int ofs, const char *grep,
	const char *pattern, int showmsg, int follow);
extern void cgit_commit_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_patch_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_refs_link(const char *name, const char *title, const char *class,
	const char *head, const char *rev, const char *path);
extern void cgit_diff_link(const char *name, const char *title, const char *class,
	const char *head, const char *new_rev, const char *old_rev, const char *path);
extern void cgit_stats_link(const char *name, const char *title, const char *class,
	const char *head, const char *path);
/*
 * Names the object by type and id, abbreviated unless full is set.
 */
extern void cgit_object_link(struct object *obj, int full);

extern void cgit_submodule_link(const char *class, char *path, const char *rev);

extern void cgit_print_layout_start(void);
extern void cgit_print_layout_end(void);

__attribute__((format (printf,1,2)))
extern void cgit_print_error(const char *fmt, ...);
extern struct date_mode cgit_date_mode(enum date_mode_type type);

/*
 * Print the time t, which was recorded in the timezone tz, as an age. An age
 * further back than max_relative is given as a calendar date instead, and a
 * negative max_relative stays relative however old it is. A site that turns
 * relative dates off gets the date either way.
 */
extern void cgit_print_age(time_t t, int tz, time_t max_relative);
extern void cgit_print_http_headers(void);
/*
 * Answer with a redirect to url, followed by query when one is given. Both
 * are written as they arrived, encoded already, the url the way cgit_repourl
 * builds it, and only a byte a header line cannot carry is encoded here.
 */
extern void cgit_redirect(const char *url, const char *query, bool permanent);
extern void cgit_print_docstart(void);
extern void cgit_print_docend(void);
__attribute__((format (printf,3,4)))
extern void cgit_print_error_page(int code, const char *msg, const char *fmt, ...);
extern void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap);

/*
 * Answer with the error page for a blob of size bytes past max-blob-size.
 */
extern void cgit_print_blob_too_large(size_t size);
extern void cgit_print_pageheader(void);
extern void cgit_print_filemode(unsigned short mode);
extern void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref,
	const char *separator);

/*
 * The name a snapshot of this repository is downloaded under, which is the
 * configured prefix or the last component of the repository URL.
 */
extern const char *cgit_snapshot_prefix(const struct cgit_repo *repo);

/*
 * Carry the current request into a form as hidden inputs, so that submitting
 * it changes only what the form itself asks about. The branch and the search
 * terms are carried only when the caller asks for them, since a form with a
 * field of its own for either would otherwise submit that name twice.
 */
extern void cgit_add_hidden_formfields(int incl_head, int incl_search, const char *page);

/*
 * Put path in front of the page title, its last component first.
 */
extern void cgit_set_title_from_path(const char *path);
#endif // CGIT_UI_SHARED_H