summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/ui-shared.c b/ui-shared.c
index c398d7a..ae29615 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -160,432 +160,442 @@ static void site_url(const char *page, const char *search, int ofs)
160 } 160 }
161} 161}
162 162
163static void site_link(const char *page, const char *name, const char *title, 163static void site_link(const char *page, const char *name, const char *title,
164 const char *class, const char *search, int ofs) 164 const char *class, const char *search, int ofs)
165{ 165{
166 html("<a"); 166 html("<a");
167 if (title) { 167 if (title) {
168 html(" title='"); 168 html(" title='");
169 html_attr(title); 169 html_attr(title);
170 html("'"); 170 html("'");
171 } 171 }
172 if (class) { 172 if (class) {
173 html(" class='"); 173 html(" class='");
174 html_attr(class); 174 html_attr(class);
175 html("'"); 175 html("'");
176 } 176 }
177 html(" href='"); 177 html(" href='");
178 site_url(page, search, ofs); 178 site_url(page, search, ofs);
179 html("'>"); 179 html("'>");
180 html_txt(name); 180 html_txt(name);
181 html("</a>"); 181 html("</a>");
182} 182}
183 183
184void cgit_index_link(const char *name, const char *title, const char *class, 184void cgit_index_link(const char *name, const char *title, const char *class,
185 const char *pattern, int ofs) 185 const char *pattern, int ofs)
186{ 186{
187 site_link(NULL, name, title, class, pattern, ofs); 187 site_link(NULL, name, title, class, pattern, ofs);
188} 188}
189 189
190static char *repolink(const char *title, const char *class, const char *page, 190static char *repolink(const char *title, const char *class, const char *page,
191 const char *head, const char *path) 191 const char *head, const char *path)
192{ 192{
193 char *delim = "?"; 193 char *delim = "?";
194 194
195 html("<a"); 195 html("<a");
196 if (title) { 196 if (title) {
197 html(" title='"); 197 html(" title='");
198 html_attr(title); 198 html_attr(title);
199 html("'"); 199 html("'");
200 } 200 }
201 if (class) { 201 if (class) {
202 html(" class='"); 202 html(" class='");
203 html_attr(class); 203 html_attr(class);
204 html("'"); 204 html("'");
205 } 205 }
206 html(" href='"); 206 html(" href='");
207 if (ctx.cfg.virtual_root) { 207 if (ctx.cfg.virtual_root) {
208 html_url_path(ctx.cfg.virtual_root); 208 html_url_path(ctx.cfg.virtual_root);
209 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/') 209 if (ctx.cfg.virtual_root[strlen(ctx.cfg.virtual_root) - 1] != '/')
210 html("/"); 210 html("/");
211 html_url_path(ctx.repo->url); 211 html_url_path(ctx.repo->url);
212 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') 212 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
213 html("/"); 213 html("/");
214 if (page) { 214 if (page) {
215 html_url_path(page); 215 html_url_path(page);
216 html("/"); 216 html("/");
217 if (path) 217 if (path)
218 html_url_path(path); 218 html_url_path(path);
219 } 219 }
220 } else { 220 } else {
221 html(ctx.cfg.script_name); 221 html(ctx.cfg.script_name);
222 html("?url="); 222 html("?url=");
223 html_url_arg(ctx.repo->url); 223 html_url_arg(ctx.repo->url);
224 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/') 224 if (ctx.repo->url[strlen(ctx.repo->url) - 1] != '/')
225 html("/"); 225 html("/");
226 if (page) { 226 if (page) {
227 html_url_arg(page); 227 html_url_arg(page);
228 html("/"); 228 html("/");
229 if (path) 229 if (path)
230 html_url_arg(path); 230 html_url_arg(path);
231 } 231 }
232 delim = "&amp;"; 232 delim = "&amp;";
233 } 233 }
234 if (head && strcmp(head, ctx.repo->defbranch)) { 234 if (head && strcmp(head, ctx.repo->defbranch)) {
235 html(delim); 235 html(delim);
236 html("h="); 236 html("h=");
237 html_url_arg(head); 237 html_url_arg(head);
238 delim = "&amp;"; 238 delim = "&amp;";
239 } 239 }
240 return fmt("%s", delim); 240 return fmt("%s", delim);
241} 241}
242 242
243static void reporevlink(const char *page, const char *name, const char *title, 243static void reporevlink(const char *page, const char *name, const char *title,
244 const char *class, const char *head, const char *rev, 244 const char *class, const char *head, const char *rev,
245 const char *path) 245 const char *path)
246{ 246{
247 char *delim; 247 char *delim;
248 248
249 delim = repolink(title, class, page, head, path); 249 delim = repolink(title, class, page, head, path);
250 if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { 250 if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) {
251 html(delim); 251 html(delim);
252 html("id="); 252 html("id=");
253 html_url_arg(rev); 253 html_url_arg(rev);
254 } 254 }
255 html("'>"); 255 html("'>");
256 html_txt(name); 256 html_txt(name);
257 html("</a>"); 257 html("</a>");
258} 258}
259 259
260void cgit_summary_link(const char *name, const char *title, const char *class, 260void cgit_summary_link(const char *name, const char *title, const char *class,
261 const char *head) 261 const char *head)
262{ 262{
263 reporevlink(NULL, name, title, class, head, NULL, NULL); 263 reporevlink(NULL, name, title, class, head, NULL, NULL);
264} 264}
265 265
266void cgit_tag_link(const char *name, const char *title, const char *class, 266void cgit_tag_link(const char *name, const char *title, const char *class,
267 const char *head, const char *rev) 267 const char *head, const char *rev)
268{ 268{
269 reporevlink("tag", name, title, class, head, rev, NULL); 269 reporevlink("tag", name, title, class, head, rev, NULL);
270} 270}
271 271
272void cgit_tree_link(const char *name, const char *title, const char *class, 272void cgit_tree_link(const char *name, const char *title, const char *class,
273 const char *head, const char *rev, const char *path) 273 const char *head, const char *rev, const char *path)
274{ 274{
275 reporevlink("tree", name, title, class, head, rev, path); 275 reporevlink("tree", name, title, class, head, rev, path);
276} 276}
277 277
278void cgit_plain_link(const char *name, const char *title, const char *class, 278void cgit_plain_link(const char *name, const char *title, const char *class,
279 const char *head, const char *rev, const char *path) 279 const char *head, const char *rev, const char *path)
280{ 280{
281 reporevlink("plain", name, title, class, head, rev, path); 281 reporevlink("plain", name, title, class, head, rev, path);
282} 282}
283 283
284void cgit_log_link(const char *name, const char *title, const char *class, 284void cgit_log_link(const char *name, const char *title, const char *class,
285 const char *head, const char *rev, const char *path, 285 const char *head, const char *rev, const char *path,
286 int ofs, const char *grep, const char *pattern, int showmsg) 286 int ofs, const char *grep, const char *pattern, int showmsg)
287{ 287{
288 char *delim; 288 char *delim;
289 289
290 delim = repolink(title, class, "log", head, path); 290 delim = repolink(title, class, "log", head, path);
291 if (rev && strcmp(rev, ctx.qry.head)) { 291 if (rev && strcmp(rev, ctx.qry.head)) {
292 html(delim); 292 html(delim);
293 html("id="); 293 html("id=");
294 html_url_arg(rev); 294 html_url_arg(rev);
295 delim = "&"; 295 delim = "&";
296 } 296 }
297 if (grep && pattern) { 297 if (grep && pattern) {
298 html(delim); 298 html(delim);
299 html("qt="); 299 html("qt=");
300 html_url_arg(grep); 300 html_url_arg(grep);
301 delim = "&"; 301 delim = "&";
302 html(delim); 302 html(delim);
303 html("q="); 303 html("q=");
304 html_url_arg(pattern); 304 html_url_arg(pattern);
305 } 305 }
306 if (ofs > 0) { 306 if (ofs > 0) {
307 html(delim); 307 html(delim);
308 html("ofs="); 308 html("ofs=");
309 htmlf("%d", ofs); 309 htmlf("%d", ofs);
310 delim = "&"; 310 delim = "&";
311 } 311 }
312 if (showmsg) { 312 if (showmsg) {
313 html(delim); 313 html(delim);
314 html("showmsg=1"); 314 html("showmsg=1");
315 } 315 }
316 html("'>"); 316 html("'>");
317 html_txt(name); 317 html_txt(name);
318 html("</a>"); 318 html("</a>");
319} 319}
320 320
321void cgit_commit_link(char *name, const char *title, const char *class, 321void cgit_commit_link(char *name, const char *title, const char *class,
322 const char *head, const char *rev, const char *path, 322 const char *head, const char *rev, const char *path,
323 int toggle_ssdiff) 323 int toggle_ssdiff)
324{ 324{
325 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { 325 if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) {
326 name[ctx.cfg.max_msg_len] = '\0'; 326 name[ctx.cfg.max_msg_len] = '\0';
327 name[ctx.cfg.max_msg_len - 1] = '.'; 327 name[ctx.cfg.max_msg_len - 1] = '.';
328 name[ctx.cfg.max_msg_len - 2] = '.'; 328 name[ctx.cfg.max_msg_len - 2] = '.';
329 name[ctx.cfg.max_msg_len - 3] = '.'; 329 name[ctx.cfg.max_msg_len - 3] = '.';
330 } 330 }
331 331
332 char *delim; 332 char *delim;
333 333
334 delim = repolink(title, class, "commit", head, path); 334 delim = repolink(title, class, "commit", head, path);
335 if (rev && strcmp(rev, ctx.qry.head)) { 335 if (rev && strcmp(rev, ctx.qry.head)) {
336 html(delim); 336 html(delim);
337 html("id="); 337 html("id=");
338 html_url_arg(rev); 338 html_url_arg(rev);
339 delim = "&amp;"; 339 delim = "&amp;";
340 } 340 }
341 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { 341 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
342 html(delim); 342 html(delim);
343 html("ss=1"); 343 html("ss=1");
344 delim = "&amp;"; 344 delim = "&amp;";
345 } 345 }
346 if (ctx.qry.context > 0 && ctx.qry.context != 3) { 346 if (ctx.qry.context > 0 && ctx.qry.context != 3) {
347 html(delim); 347 html(delim);
348 html("context="); 348 html("context=");
349 htmlf("%d", ctx.qry.context); 349 htmlf("%d", ctx.qry.context);
350 delim = "&amp;"; 350 delim = "&amp;";
351 } 351 }
352 if (ctx.qry.ignorews) {
353 html(delim);
354 html("ignorews=1");
355 delim = "&amp;";
356 }
352 html("'>"); 357 html("'>");
353 html_txt(name); 358 html_txt(name);
354 html("</a>"); 359 html("</a>");
355} 360}
356 361
357void cgit_refs_link(const char *name, const char *title, const char *class, 362void cgit_refs_link(const char *name, const char *title, const char *class,
358 const char *head, const char *rev, const char *path) 363 const char *head, const char *rev, const char *path)
359{ 364{
360 reporevlink("refs", name, title, class, head, rev, path); 365 reporevlink("refs", name, title, class, head, rev, path);
361} 366}
362 367
363void cgit_snapshot_link(const char *name, const char *title, const char *class, 368void cgit_snapshot_link(const char *name, const char *title, const char *class,
364 const char *head, const char *rev, 369 const char *head, const char *rev,
365 const char *archivename) 370 const char *archivename)
366{ 371{
367 reporevlink("snapshot", name, title, class, head, rev, archivename); 372 reporevlink("snapshot", name, title, class, head, rev, archivename);
368} 373}
369 374
370void cgit_diff_link(const char *name, const char *title, const char *class, 375void cgit_diff_link(const char *name, const char *title, const char *class,
371 const char *head, const char *new_rev, const char *old_rev, 376 const char *head, const char *new_rev, const char *old_rev,
372 const char *path, int toggle_ssdiff) 377 const char *path, int toggle_ssdiff)
373{ 378{
374 char *delim; 379 char *delim;
375 380
376 delim = repolink(title, class, "diff", head, path); 381 delim = repolink(title, class, "diff", head, path);
377 if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) { 382 if (new_rev && ctx.qry.head != NULL && strcmp(new_rev, ctx.qry.head)) {
378 html(delim); 383 html(delim);
379 html("id="); 384 html("id=");
380 html_url_arg(new_rev); 385 html_url_arg(new_rev);
381 delim = "&amp;"; 386 delim = "&amp;";
382 } 387 }
383 if (old_rev) { 388 if (old_rev) {
384 html(delim); 389 html(delim);
385 html("id2="); 390 html("id2=");
386 html_url_arg(old_rev); 391 html_url_arg(old_rev);
387 delim = "&amp;"; 392 delim = "&amp;";
388 } 393 }
389 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) { 394 if ((ctx.qry.ssdiff && !toggle_ssdiff) || (!ctx.qry.ssdiff && toggle_ssdiff)) {
390 html(delim); 395 html(delim);
391 html("ss=1"); 396 html("ss=1");
392 delim = "&amp;"; 397 delim = "&amp;";
393 } 398 }
394 if (ctx.qry.context > 0 && ctx.qry.context != 3) { 399 if (ctx.qry.context > 0 && ctx.qry.context != 3) {
395 html(delim); 400 html(delim);
396 html("context="); 401 html("context=");
397 htmlf("%d", ctx.qry.context); 402 htmlf("%d", ctx.qry.context);
398 delim = "&amp;"; 403 delim = "&amp;";
399 } 404 }
405 if (ctx.qry.ignorews) {
406 html(delim);
407 html("ignorews=1");
408 delim = "&amp;";
409 }
400 html("'>"); 410 html("'>");
401 html_txt(name); 411 html_txt(name);
402 html("</a>"); 412 html("</a>");
403} 413}
404 414
405void cgit_patch_link(const char *name, const char *title, const char *class, 415void cgit_patch_link(const char *name, const char *title, const char *class,
406 const char *head, const char *rev, const char *path) 416 const char *head, const char *rev, const char *path)
407{ 417{
408 reporevlink("patch", name, title, class, head, rev, path); 418 reporevlink("patch", name, title, class, head, rev, path);
409} 419}
410 420
411void cgit_stats_link(const char *name, const char *title, const char *class, 421void cgit_stats_link(const char *name, const char *title, const char *class,
412 const char *head, const char *path) 422 const char *head, const char *path)
413{ 423{
414 reporevlink("stats", name, title, class, head, NULL, path); 424 reporevlink("stats", name, title, class, head, NULL, path);
415} 425}
416 426
417void cgit_self_link(char *name, const char *title, const char *class, 427void cgit_self_link(char *name, const char *title, const char *class,
418 struct cgit_context *ctx) 428 struct cgit_context *ctx)
419{ 429{
420 if (!strcmp(ctx->qry.page, "repolist")) 430 if (!strcmp(ctx->qry.page, "repolist"))
421 return cgit_index_link(name, title, class, ctx->qry.search, 431 return cgit_index_link(name, title, class, ctx->qry.search,
422 ctx->qry.ofs); 432 ctx->qry.ofs);
423 else if (!strcmp(ctx->qry.page, "summary")) 433 else if (!strcmp(ctx->qry.page, "summary"))
424 return cgit_summary_link(name, title, class, ctx->qry.head); 434 return cgit_summary_link(name, title, class, ctx->qry.head);
425 else if (!strcmp(ctx->qry.page, "tag")) 435 else if (!strcmp(ctx->qry.page, "tag"))
426 return cgit_tag_link(name, title, class, ctx->qry.head, 436 return cgit_tag_link(name, title, class, ctx->qry.head,
427 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL); 437 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL);
428 else if (!strcmp(ctx->qry.page, "tree")) 438 else if (!strcmp(ctx->qry.page, "tree"))
429 return cgit_tree_link(name, title, class, ctx->qry.head, 439 return cgit_tree_link(name, title, class, ctx->qry.head,
430 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 440 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
431 ctx->qry.path); 441 ctx->qry.path);
432 else if (!strcmp(ctx->qry.page, "plain")) 442 else if (!strcmp(ctx->qry.page, "plain"))
433 return cgit_plain_link(name, title, class, ctx->qry.head, 443 return cgit_plain_link(name, title, class, ctx->qry.head,
434 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 444 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
435 ctx->qry.path); 445 ctx->qry.path);
436 else if (!strcmp(ctx->qry.page, "log")) 446 else if (!strcmp(ctx->qry.page, "log"))
437 return cgit_log_link(name, title, class, ctx->qry.head, 447 return cgit_log_link(name, title, class, ctx->qry.head,
438 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 448 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
439 ctx->qry.path, ctx->qry.ofs, 449 ctx->qry.path, ctx->qry.ofs,
440 ctx->qry.grep, ctx->qry.search, 450 ctx->qry.grep, ctx->qry.search,
441 ctx->qry.showmsg); 451 ctx->qry.showmsg);
442 else if (!strcmp(ctx->qry.page, "commit")) 452 else if (!strcmp(ctx->qry.page, "commit"))
443 return cgit_commit_link(name, title, class, ctx->qry.head, 453 return cgit_commit_link(name, title, class, ctx->qry.head,
444 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 454 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
445 ctx->qry.path, 0); 455 ctx->qry.path, 0);
446 else if (!strcmp(ctx->qry.page, "patch")) 456 else if (!strcmp(ctx->qry.page, "patch"))
447 return cgit_patch_link(name, title, class, ctx->qry.head, 457 return cgit_patch_link(name, title, class, ctx->qry.head,
448 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 458 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
449 ctx->qry.path); 459 ctx->qry.path);
450 else if (!strcmp(ctx->qry.page, "refs")) 460 else if (!strcmp(ctx->qry.page, "refs"))
451 return cgit_refs_link(name, title, class, ctx->qry.head, 461 return cgit_refs_link(name, title, class, ctx->qry.head,
452 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 462 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
453 ctx->qry.path); 463 ctx->qry.path);
454 else if (!strcmp(ctx->qry.page, "snapshot")) 464 else if (!strcmp(ctx->qry.page, "snapshot"))
455 return cgit_snapshot_link(name, title, class, ctx->qry.head, 465 return cgit_snapshot_link(name, title, class, ctx->qry.head,
456 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL, 466 ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
457 ctx->qry.path); 467 ctx->qry.path);
458 else if (!strcmp(ctx->qry.page, "diff")) 468 else if (!strcmp(ctx->qry.page, "diff"))
459 return cgit_diff_link(name, title, class, ctx->qry.head, 469 return cgit_diff_link(name, title, class, ctx->qry.head,
460 ctx->qry.sha1, ctx->qry.sha2, 470 ctx->qry.sha1, ctx->qry.sha2,
461 ctx->qry.path, 0); 471 ctx->qry.path, 0);
462 else if (!strcmp(ctx->qry.page, "stats")) 472 else if (!strcmp(ctx->qry.page, "stats"))
463 return cgit_stats_link(name, title, class, ctx->qry.head, 473 return cgit_stats_link(name, title, class, ctx->qry.head,
464 ctx->qry.path); 474 ctx->qry.path);
465 475
466 /* Don't known how to make link for this page */ 476 /* Don't known how to make link for this page */
467 repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path); 477 repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path);
468 html("><!-- cgit_self_link() doesn't know how to make link for page '"); 478 html("><!-- cgit_self_link() doesn't know how to make link for page '");
469 html_txt(ctx->qry.page); 479 html_txt(ctx->qry.page);
470 html("' -->"); 480 html("' -->");
471 html_txt(name); 481 html_txt(name);
472 html("</a>"); 482 html("</a>");
473} 483}
474 484
475void cgit_object_link(struct object *obj) 485void cgit_object_link(struct object *obj)
476{ 486{
477 char *page, *shortrev, *fullrev, *name; 487 char *page, *shortrev, *fullrev, *name;
478 488
479 fullrev = sha1_to_hex(obj->sha1); 489 fullrev = sha1_to_hex(obj->sha1);
480 shortrev = xstrdup(fullrev); 490 shortrev = xstrdup(fullrev);
481 shortrev[10] = '\0'; 491 shortrev[10] = '\0';
482 if (obj->type == OBJ_COMMIT) { 492 if (obj->type == OBJ_COMMIT) {
483 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL, 493 cgit_commit_link(fmt("commit %s...", shortrev), NULL, NULL,
484 ctx.qry.head, fullrev, NULL, 0); 494 ctx.qry.head, fullrev, NULL, 0);
485 return; 495 return;
486 } else if (obj->type == OBJ_TREE) 496 } else if (obj->type == OBJ_TREE)
487 page = "tree"; 497 page = "tree";
488 else if (obj->type == OBJ_TAG) 498 else if (obj->type == OBJ_TAG)
489 page = "tag"; 499 page = "tag";
490 else 500 else
491 page = "blob"; 501 page = "blob";
492 name = fmt("%s %s...", typename(obj->type), shortrev); 502 name = fmt("%s %s...", typename(obj->type), shortrev);
493 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL); 503 reporevlink(page, name, NULL, NULL, ctx.qry.head, fullrev, NULL);
494} 504}
495 505
496void cgit_print_date(time_t secs, const char *format, int local_time) 506void cgit_print_date(time_t secs, const char *format, int local_time)
497{ 507{
498 char buf[64]; 508 char buf[64];
499 struct tm *time; 509 struct tm *time;
500 510
501 if (!secs) 511 if (!secs)
502 return; 512 return;
503 if(local_time) 513 if(local_time)
504 time = localtime(&secs); 514 time = localtime(&secs);
505 else 515 else
506 time = gmtime(&secs); 516 time = gmtime(&secs);
507 strftime(buf, sizeof(buf)-1, format, time); 517 strftime(buf, sizeof(buf)-1, format, time);
508 html_txt(buf); 518 html_txt(buf);
509} 519}
510 520
511void cgit_print_age(time_t t, time_t max_relative, const char *format) 521void cgit_print_age(time_t t, time_t max_relative, const char *format)
512{ 522{
513 time_t now, secs; 523 time_t now, secs;
514 524
515 if (!t) 525 if (!t)
516 return; 526 return;
517 time(&now); 527 time(&now);
518 secs = now - t; 528 secs = now - t;
519 529
520 if (secs > max_relative && max_relative >= 0) { 530 if (secs > max_relative && max_relative >= 0) {
521 cgit_print_date(t, format, ctx.cfg.local_time); 531 cgit_print_date(t, format, ctx.cfg.local_time);
522 return; 532 return;
523 } 533 }
524 534
525 if (secs < TM_HOUR * 2) { 535 if (secs < TM_HOUR * 2) {
526 htmlf("<span class='age-mins'>%.0f min.</span>", 536 htmlf("<span class='age-mins'>%.0f min.</span>",
527 secs * 1.0 / TM_MIN); 537 secs * 1.0 / TM_MIN);
528 return; 538 return;
529 } 539 }
530 if (secs < TM_DAY * 2) { 540 if (secs < TM_DAY * 2) {
531 htmlf("<span class='age-hours'>%.0f hours</span>", 541 htmlf("<span class='age-hours'>%.0f hours</span>",
532 secs * 1.0 / TM_HOUR); 542 secs * 1.0 / TM_HOUR);
533 return; 543 return;
534 } 544 }
535 if (secs < TM_WEEK * 2) { 545 if (secs < TM_WEEK * 2) {
536 htmlf("<span class='age-days'>%.0f days</span>", 546 htmlf("<span class='age-days'>%.0f days</span>",
537 secs * 1.0 / TM_DAY); 547 secs * 1.0 / TM_DAY);
538 return; 548 return;
539 } 549 }
540 if (secs < TM_MONTH * 2) { 550 if (secs < TM_MONTH * 2) {
541 htmlf("<span class='age-weeks'>%.0f weeks</span>", 551 htmlf("<span class='age-weeks'>%.0f weeks</span>",
542 secs * 1.0 / TM_WEEK); 552 secs * 1.0 / TM_WEEK);
543 return; 553 return;
544 } 554 }
545 if (secs < TM_YEAR * 2) { 555 if (secs < TM_YEAR * 2) {
546 htmlf("<span class='age-months'>%.0f months</span>", 556 htmlf("<span class='age-months'>%.0f months</span>",
547 secs * 1.0 / TM_MONTH); 557 secs * 1.0 / TM_MONTH);
548 return; 558 return;
549 } 559 }
550 htmlf("<span class='age-years'>%.0f years</span>", 560 htmlf("<span class='age-years'>%.0f years</span>",
551 secs * 1.0 / TM_YEAR); 561 secs * 1.0 / TM_YEAR);
552} 562}
553 563
554void cgit_print_http_headers(struct cgit_context *ctx) 564void cgit_print_http_headers(struct cgit_context *ctx)
555{ 565{
556 if (ctx->env.no_http && !strcmp(ctx->env.no_http, "1")) 566 if (ctx->env.no_http && !strcmp(ctx->env.no_http, "1"))
557 return; 567 return;
558 568
559 if (ctx->page.status) 569 if (ctx->page.status)
560 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); 570 htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg);
561 if (ctx->page.mimetype && ctx->page.charset) 571 if (ctx->page.mimetype && ctx->page.charset)
562 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, 572 htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype,
563 ctx->page.charset); 573 ctx->page.charset);
564 else if (ctx->page.mimetype) 574 else if (ctx->page.mimetype)
565 htmlf("Content-Type: %s\n", ctx->page.mimetype); 575 htmlf("Content-Type: %s\n", ctx->page.mimetype);
566 if (ctx->page.size) 576 if (ctx->page.size)
567 htmlf("Content-Length: %ld\n", ctx->page.size); 577 htmlf("Content-Length: %ld\n", ctx->page.size);
568 if (ctx->page.filename) 578 if (ctx->page.filename)
569 htmlf("Content-Disposition: inline; filename=\"%s\"\n", 579 htmlf("Content-Disposition: inline; filename=\"%s\"\n",
570 ctx->page.filename); 580 ctx->page.filename);
571 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); 581 htmlf("Last-Modified: %s\n", http_date(ctx->page.modified));
572 htmlf("Expires: %s\n", http_date(ctx->page.expires)); 582 htmlf("Expires: %s\n", http_date(ctx->page.expires));
573 if (ctx->page.etag) 583 if (ctx->page.etag)
574 htmlf("ETag: \"%s\"\n", ctx->page.etag); 584 htmlf("ETag: \"%s\"\n", ctx->page.etag);
575 html("\n"); 585 html("\n");
576 if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD")) 586 if (ctx->env.request_method && !strcmp(ctx->env.request_method, "HEAD"))
577 exit(0); 587 exit(0);
578} 588}
579 589
580void cgit_print_docstart(struct cgit_context *ctx) 590void cgit_print_docstart(struct cgit_context *ctx)
581{ 591{
582 if (ctx->cfg.embedded) { 592 if (ctx->cfg.embedded) {
583 if (ctx->cfg.header) 593 if (ctx->cfg.header)
584 html_include(ctx->cfg.header); 594 html_include(ctx->cfg.header);
585 return; 595 return;
586 } 596 }
587 597
588 char *host = cgit_hosturl(); 598 char *host = cgit_hosturl();
589 html(cgit_doctype); 599 html(cgit_doctype);
590 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); 600 html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
591 html("<head>\n"); 601 html("<head>\n");