summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile2
m---------git0
-rw-r--r--html.c70
-rw-r--r--html.h18
-rw-r--r--shared.c8
-rw-r--r--ui-tree.c2
6 files changed, 69 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index d39a30e..0a5055b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,20 +1,20 @@
1CGIT_VERSION = v0.8.3.1 1CGIT_VERSION = v0.8.3.1
2CGIT_SCRIPT_NAME = cgit.cgi 2CGIT_SCRIPT_NAME = cgit.cgi
3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit 3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
4CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) 4CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
5CGIT_CONFIG = /etc/cgitrc 5CGIT_CONFIG = /etc/cgitrc
6CACHE_ROOT = /var/cache/cgit 6CACHE_ROOT = /var/cache/cgit
7SHA1_HEADER = <openssl/sha.h> 7SHA1_HEADER = <openssl/sha.h>
8GIT_VER = 1.6.4.3 8GIT_VER = 1.7.0
9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
10INSTALL = install 10INSTALL = install
11 11
12# Define NO_STRCASESTR if you don't have strcasestr. 12# Define NO_STRCASESTR if you don't have strcasestr.
13# 13#
14# Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1 14# Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1
15# implementation (slower). 15# implementation (slower).
16# 16#
17# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). 17# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin).
18# 18#
19 19
20#-include config.mak 20#-include config.mak
diff --git a/git b/git
Subproject 7fb6bcff2dece2ff9fbc5ebfe526d9b2a7e764c Subproject e923eaeb901ff056421b9007adcbbce271caa7b
diff --git a/html.c b/html.c
index 66ba65d..337baeb 100644
--- a/html.c
+++ b/html.c
@@ -4,24 +4,50 @@
4 * 4 *
5 * Licensed under GNU General Public License v2 5 * Licensed under GNU General Public License v2
6 * (see COPYING for full license text) 6 * (see COPYING for full license text)
7 */ 7 */
8 8
9#include <unistd.h> 9#include <unistd.h>
10#include <stdio.h> 10#include <stdio.h>
11#include <stdlib.h> 11#include <stdlib.h>
12#include <stdarg.h> 12#include <stdarg.h>
13#include <string.h> 13#include <string.h>
14#include <errno.h> 14#include <errno.h>
15 15
16/* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */
17static const char* url_escape_table[256] = {
18 "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09",
19 "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%10", "%11", "%12", "%13",
20 "%14", "%15", "%16", "%17", "%18", "%19", "%1a", "%1b", "%1c", "%1d",
21 "%1e", "%1f", "%20", 0, "%22", "%23", 0, "%25", "%26", "%27", 0, 0, 0,
22 "%2b", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%3c", "%3d",
23 "%3e", "%3f", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
24 0, 0, 0, 0, 0, 0, 0, 0, 0, "%5c", 0, "%5e", 0, "%60", 0, 0, 0, 0, 0,
25 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "%7b",
26 "%7c", "%7d", 0, "%7f", "%80", "%81", "%82", "%83", "%84", "%85",
27 "%86", "%87", "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",
28 "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", "%98", "%99",
29 "%9a", "%9b", "%9c", "%9d", "%9e", "%9f", "%a0", "%a1", "%a2", "%a3",
30 "%a4", "%a5", "%a6", "%a7", "%a8", "%a9", "%aa", "%ab", "%ac", "%ad",
31 "%ae", "%af", "%b0", "%b1", "%b2", "%b3", "%b4", "%b5", "%b6", "%b7",
32 "%b8", "%b9", "%ba", "%bb", "%bc", "%bd", "%be", "%bf", "%c0", "%c1",
33 "%c2", "%c3", "%c4", "%c5", "%c6", "%c7", "%c8", "%c9", "%ca", "%cb",
34 "%cc", "%cd", "%ce", "%cf", "%d0", "%d1", "%d2", "%d3", "%d4", "%d5",
35 "%d6", "%d7", "%d8", "%d9", "%da", "%db", "%dc", "%dd", "%de", "%df",
36 "%e0", "%e1", "%e2", "%e3", "%e4", "%e5", "%e6", "%e7", "%e8", "%e9",
37 "%ea", "%eb", "%ec", "%ed", "%ee", "%ef", "%f0", "%f1", "%f2", "%f3",
38 "%f4", "%f5", "%f6", "%f7", "%f8", "%f9", "%fa", "%fb", "%fc", "%fd",
39 "%fe", "%ff"
40};
41
16int htmlfd = STDOUT_FILENO; 42int htmlfd = STDOUT_FILENO;
17 43
18char *fmt(const char *format, ...) 44char *fmt(const char *format, ...)
19{ 45{
20 static char buf[8][1024]; 46 static char buf[8][1024];
21 static int bufidx; 47 static int bufidx;
22 int len; 48 int len;
23 va_list args; 49 va_list args;
24 50
25 bufidx++; 51 bufidx++;
26 bufidx &= 7; 52 bufidx &= 7;
27 53
@@ -54,145 +80,147 @@ void htmlf(const char *format, ...)
54 vsnprintf(buf, sizeof(buf), format, args); 80 vsnprintf(buf, sizeof(buf), format, args);
55 va_end(args); 81 va_end(args);
56 html(buf); 82 html(buf);
57} 83}
58 84
59void html_status(int code, const char *msg, int more_headers) 85void html_status(int code, const char *msg, int more_headers)
60{ 86{
61 htmlf("Status: %d %s\n", code, msg); 87 htmlf("Status: %d %s\n", code, msg);
62 if (!more_headers) 88 if (!more_headers)
63 html("\n"); 89 html("\n");
64} 90}
65 91
66void html_txt(char *txt) 92void html_txt(const char *txt)
67{ 93{
68 char *t = txt; 94 const char *t = txt;
69 while(t && *t){ 95 while(t && *t){
70 int c = *t; 96 int c = *t;
71 if (c=='<' || c=='>' || c=='&') { 97 if (c=='<' || c=='>' || c=='&') {
72 write(htmlfd, txt, t - txt); 98 write(htmlfd, txt, t - txt);
73 if (c=='>') 99 if (c=='>')
74 html("&gt;"); 100 html("&gt;");
75 else if (c=='<') 101 else if (c=='<')
76 html("&lt;"); 102 html("&lt;");
77 else if (c=='&') 103 else if (c=='&')
78 html("&amp;"); 104 html("&amp;");
79 txt = t+1; 105 txt = t+1;
80 } 106 }
81 t++; 107 t++;
82 } 108 }
83 if (t!=txt) 109 if (t!=txt)
84 html(txt); 110 html(txt);
85} 111}
86 112
87void html_ntxt(int len, char *txt) 113void html_ntxt(int len, const char *txt)
88{ 114{
89 char *t = txt; 115 const char *t = txt;
90 while(t && *t && len--){ 116 while(t && *t && len--){
91 int c = *t; 117 int c = *t;
92 if (c=='<' || c=='>' || c=='&') { 118 if (c=='<' || c=='>' || c=='&') {
93 write(htmlfd, txt, t - txt); 119 write(htmlfd, txt, t - txt);
94 if (c=='>') 120 if (c=='>')
95 html("&gt;"); 121 html("&gt;");
96 else if (c=='<') 122 else if (c=='<')
97 html("&lt;"); 123 html("&lt;");
98 else if (c=='&') 124 else if (c=='&')
99 html("&amp;"); 125 html("&amp;");
100 txt = t+1; 126 txt = t+1;
101 } 127 }
102 t++; 128 t++;
103 } 129 }
104 if (t!=txt) 130 if (t!=txt)
105 write(htmlfd, txt, t - txt); 131 write(htmlfd, txt, t - txt);
106 if (len<0) 132 if (len<0)
107 html("..."); 133 html("...");
108} 134}
109 135
110void html_attr(char *txt) 136void html_attr(const char *txt)
111{ 137{
112 char *t = txt; 138 const char *t = txt;
113 while(t && *t){ 139 while(t && *t){
114 int c = *t; 140 int c = *t;
115 if (c=='<' || c=='>' || c=='\'' || c=='\"') { 141 if (c=='<' || c=='>' || c=='\'' || c=='\"') {
116 write(htmlfd, txt, t - txt); 142 write(htmlfd, txt, t - txt);
117 if (c=='>') 143 if (c=='>')
118 html("&gt;"); 144 html("&gt;");
119 else if (c=='<') 145 else if (c=='<')
120 html("&lt;"); 146 html("&lt;");
121 else if (c=='\'') 147 else if (c=='\'')
122 html("&#x27;"); 148 html("&#x27;");
123 else if (c=='"') 149 else if (c=='"')
124 html("&quot;"); 150 html("&quot;");
125 txt = t+1; 151 txt = t+1;
126 } 152 }
127 t++; 153 t++;
128 } 154 }
129 if (t!=txt) 155 if (t!=txt)
130 html(txt); 156 html(txt);
131} 157}
132 158
133void html_url_path(char *txt) 159void html_url_path(const char *txt)
134{ 160{
135 char *t = txt; 161 const char *t = txt;
136 while(t && *t){ 162 while(t && *t){
137 int c = *t; 163 int c = *t;
138 if (c=='"' || c=='#' || c=='\'' || c=='?') { 164 const char *e = url_escape_table[c];
165 if (e && c!='+' && c!='&' && c!='+') {
139 write(htmlfd, txt, t - txt); 166 write(htmlfd, txt, t - txt);
140 write(htmlfd, fmt("%%%2x", c), 3); 167 write(htmlfd, e, 3);
141 txt = t+1; 168 txt = t+1;
142 } 169 }
143 t++; 170 t++;
144 } 171 }
145 if (t!=txt) 172 if (t!=txt)
146 html(txt); 173 html(txt);
147} 174}
148 175
149void html_url_arg(char *txt) 176void html_url_arg(const char *txt)
150{ 177{
151 char *t = txt; 178 const char *t = txt;
152 while(t && *t){ 179 while(t && *t){
153 int c = *t; 180 int c = *t;
154 if (c=='"' || c=='#' || c=='%' || c=='&' || c=='\'' || c=='+' || c=='?') { 181 const char *e = url_escape_table[c];
182 if (e) {
155 write(htmlfd, txt, t - txt); 183 write(htmlfd, txt, t - txt);
156 write(htmlfd, fmt("%%%2x", c), 3); 184 write(htmlfd, e, 3);
157 txt = t+1; 185 txt = t+1;
158 } 186 }
159 t++; 187 t++;
160 } 188 }
161 if (t!=txt) 189 if (t!=txt)
162 html(txt); 190 html(txt);
163} 191}
164 192
165void html_hidden(char *name, char *value) 193void html_hidden(const char *name, const char *value)
166{ 194{
167 html("<input type='hidden' name='"); 195 html("<input type='hidden' name='");
168 html_attr(name); 196 html_attr(name);
169 html("' value='"); 197 html("' value='");
170 html_attr(value); 198 html_attr(value);
171 html("'/>"); 199 html("'/>");
172} 200}
173 201
174void html_option(char *value, char *text, char *selected_value) 202void html_option(const char *value, const char *text, const char *selected_value)
175{ 203{
176 html("<option value='"); 204 html("<option value='");
177 html_attr(value); 205 html_attr(value);
178 html("'"); 206 html("'");
179 if (selected_value && !strcmp(selected_value, value)) 207 if (selected_value && !strcmp(selected_value, value))
180 html(" selected='selected'"); 208 html(" selected='selected'");
181 html(">"); 209 html(">");
182 html_txt(text); 210 html_txt(text);
183 html("</option>\n"); 211 html("</option>\n");
184} 212}
185 213
186void html_link_open(char *url, char *title, char *class) 214void html_link_open(const char *url, const char *title, const char *class)
187{ 215{
188 html("<a href='"); 216 html("<a href='");
189 html_attr(url); 217 html_attr(url);
190 if (title) { 218 if (title) {
191 html("' title='"); 219 html("' title='");
192 html_attr(title); 220 html_attr(title);
193 } 221 }
194 if (class) { 222 if (class) {
195 html("' class='"); 223 html("' class='");
196 html_attr(class); 224 html_attr(class);
197 } 225 }
198 html("'>"); 226 html("'>");
@@ -248,32 +276,32 @@ char *convert_query_hexchar(char *txt)
248 d1 = hextoint(*(txt+1)); 276 d1 = hextoint(*(txt+1));
249 d2 = hextoint(*(txt+2)); 277 d2 = hextoint(*(txt+2));
250 if (d1<0 || d2<0) { 278 if (d1<0 || d2<0) {
251 strcpy(txt, txt+3); 279 strcpy(txt, txt+3);
252 return txt-1; 280 return txt-1;
253 } else { 281 } else {
254 *txt = d1 * 16 + d2; 282 *txt = d1 * 16 + d2;
255 strcpy(txt+1, txt+3); 283 strcpy(txt+1, txt+3);
256 return txt; 284 return txt;
257 } 285 }
258} 286}
259 287
260int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)) 288int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const char *value))
261{ 289{
262 char *t, *value = NULL, c; 290 char *t, *txt, *value = NULL, c;
263 291
264 if (!txt) 292 if (!txt_)
265 return 0; 293 return 0;
266 294
267 t = txt = strdup(txt); 295 t = txt = strdup(txt_);
268 if (t == NULL) { 296 if (t == NULL) {
269 printf("Out of memory\n"); 297 printf("Out of memory\n");
270 exit(1); 298 exit(1);
271 } 299 }
272 while((c=*t) != '\0') { 300 while((c=*t) != '\0') {
273 if (c=='=') { 301 if (c=='=') {
274 *t = '\0'; 302 *t = '\0';
275 value = t+1; 303 value = t+1;
276 } else if (c=='+') { 304 } else if (c=='+') {
277 *t = ' '; 305 *t = ' ';
278 } else if (c=='%') { 306 } else if (c=='%') {
279 t = convert_query_hexchar(t); 307 t = convert_query_hexchar(t);
diff --git a/html.h b/html.h
index a55d4b2..16d55ec 100644
--- a/html.h
+++ b/html.h
@@ -1,24 +1,24 @@
1#ifndef HTML_H 1#ifndef HTML_H
2#define HTML_H 2#define HTML_H
3 3
4extern int htmlfd; 4extern int htmlfd;
5 5
6extern void html_raw(const char *txt, size_t size); 6extern void html_raw(const char *txt, size_t size);
7extern void html(const char *txt); 7extern void html(const char *txt);
8extern void htmlf(const char *format,...); 8extern void htmlf(const char *format,...);
9extern void html_status(int code, const char *msg, int more_headers); 9extern void html_status(int code, const char *msg, int more_headers);
10extern void html_txt(char *txt); 10extern void html_txt(const char *txt);
11extern void html_ntxt(int len, char *txt); 11extern void html_ntxt(int len, const char *txt);
12extern void html_attr(char *txt); 12extern void html_attr(const char *txt);
13extern void html_url_path(char *txt); 13extern void html_url_path(const char *txt);
14extern void html_url_arg(char *txt); 14extern void html_url_arg(const char *txt);
15extern void html_hidden(char *name, char *value); 15extern void html_hidden(const char *name, const char *value);
16extern void html_option(char *value, char *text, char *selected_value); 16extern void html_option(const char *value, const char *text, const char *selected_value);
17extern void html_link_open(char *url, char *title, char *class); 17extern void html_link_open(const char *url, const char *title, const char *class);
18extern void html_link_close(void); 18extern void html_link_close(void);
19extern void html_fileperm(unsigned short mode); 19extern void html_fileperm(unsigned short mode);
20extern int html_include(const char *filename); 20extern int html_include(const char *filename);
21 21
22extern int http_parse_querystring(char *txt, void (*fn)(const char *name, const char *value)); 22extern int http_parse_querystring(const char *txt, void (*fn)(const char *name, const char *value));
23 23
24#endif /* HTML_H */ 24#endif /* HTML_H */
diff --git a/shared.c b/shared.c
index 83ded44..8b3a045 100644
--- a/shared.c
+++ b/shared.c
@@ -271,36 +271,44 @@ int cgit_diff_files(const unsigned char *old_sha1,
271 xdemitconf_t emit_params; 271 xdemitconf_t emit_params;
272 xdemitcb_t emit_cb; 272 xdemitcb_t emit_cb;
273 273
274 if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) 274 if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1))
275 return 1; 275 return 1;
276 276
277 *old_size = file1.size; 277 *old_size = file1.size;
278 *new_size = file2.size; 278 *new_size = file2.size;
279 279
280 if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) || 280 if ((file1.ptr && buffer_is_binary(file1.ptr, file1.size)) ||
281 (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) { 281 (file2.ptr && buffer_is_binary(file2.ptr, file2.size))) {
282 *binary = 1; 282 *binary = 1;
283 if (file1.size)
284 free(file1.ptr);
285 if (file2.size)
286 free(file2.ptr);
283 return 0; 287 return 0;
284 } 288 }
285 289
286 memset(&diff_params, 0, sizeof(diff_params)); 290 memset(&diff_params, 0, sizeof(diff_params));
287 memset(&emit_params, 0, sizeof(emit_params)); 291 memset(&emit_params, 0, sizeof(emit_params));
288 memset(&emit_cb, 0, sizeof(emit_cb)); 292 memset(&emit_cb, 0, sizeof(emit_cb));
289 diff_params.flags = XDF_NEED_MINIMAL; 293 diff_params.flags = XDF_NEED_MINIMAL;
290 emit_params.ctxlen = 3; 294 emit_params.ctxlen = 3;
291 emit_params.flags = XDL_EMIT_FUNCNAMES; 295 emit_params.flags = XDL_EMIT_FUNCNAMES;
292 emit_cb.outf = filediff_cb; 296 emit_cb.outf = filediff_cb;
293 emit_cb.priv = fn; 297 emit_cb.priv = fn;
294 xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); 298 xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb);
299 if (file1.size)
300 free(file1.ptr);
301 if (file2.size)
302 free(file2.ptr);
295 return 0; 303 return 0;
296} 304}
297 305
298void cgit_diff_tree(const unsigned char *old_sha1, 306void cgit_diff_tree(const unsigned char *old_sha1,
299 const unsigned char *new_sha1, 307 const unsigned char *new_sha1,
300 filepair_fn fn, const char *prefix) 308 filepair_fn fn, const char *prefix)
301{ 309{
302 struct diff_options opt; 310 struct diff_options opt;
303 int ret; 311 int ret;
304 int prefixlen; 312 int prefixlen;
305 313
306 diff_setup(&opt); 314 diff_setup(&opt);
diff --git a/ui-tree.c b/ui-tree.c
index 94aff8f..0ee38f2 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -166,24 +166,26 @@ static int ls_item(const unsigned char *sha1, const char *base, int baselen,
166 class = "ls-blob"; 166 class = "ls-blob";
167 cgit_tree_link(name, NULL, class, ctx.qry.head, 167 cgit_tree_link(name, NULL, class, ctx.qry.head,
168 curr_rev, fullpath); 168 curr_rev, fullpath);
169 } 169 }
170 htmlf("</td><td class='ls-size'>%li</td>", size); 170 htmlf("</td><td class='ls-size'>%li</td>", size);
171 171
172 html("<td>"); 172 html("<td>");
173 cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev, 173 cgit_log_link("log", NULL, "button", ctx.qry.head, curr_rev,
174 fullpath, 0, NULL, NULL, ctx.qry.showmsg); 174 fullpath, 0, NULL, NULL, ctx.qry.showmsg);
175 if (ctx.repo->max_stats) 175 if (ctx.repo->max_stats)
176 cgit_stats_link("stats", NULL, "button", ctx.qry.head, 176 cgit_stats_link("stats", NULL, "button", ctx.qry.head,
177 fullpath); 177 fullpath);
178 cgit_plain_link("plain", NULL, "button", ctx.qry.head, curr_rev,
179 fullpath);
178 html("</td></tr>\n"); 180 html("</td></tr>\n");
179 free(name); 181 free(name);
180 return 0; 182 return 0;
181} 183}
182 184
183static void ls_head() 185static void ls_head()
184{ 186{
185 html("<table summary='tree listing' class='list'>\n"); 187 html("<table summary='tree listing' class='list'>\n");
186 html("<tr class='nohover'>"); 188 html("<tr class='nohover'>");
187 html("<th class='left'>Mode</th>"); 189 html("<th class='left'>Mode</th>");
188 html("<th class='left'>Name</th>"); 190 html("<th class='left'>Name</th>");
189 html("<th class='right'>Size</th>"); 191 html("<th class='right'>Size</th>");