author | Lars Hjemli <hjemli@gmail.com> | 2008-10-05 17:25:47 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-10-05 17:25:47 (UTC) |
commit | 2e884f3162771880a2a5260713d6b7d1aa25bc6f (patch) (unidiff) | |
tree | 6d7193cc2ce766ac3d350ba3f2ea20e546ec5344 | |
parent | b7f33786ef4b155a11b0324f84bbde5d7fc9c998 (diff) | |
download | cgit-2e884f3162771880a2a5260713d6b7d1aa25bc6f.zip cgit-2e884f3162771880a2a5260713d6b7d1aa25bc6f.tar.gz cgit-2e884f3162771880a2a5260713d6b7d1aa25bc6f.tar.bz2 |
ui-shared: use html_url_path() to get properly escaped url in form action
When a repo uses an url with e.g. '#' or '?' characters this needs to be
properly escaped when used as action in a form tag.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-shared.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ui-shared.c b/ui-shared.c index f858ab6..1e12529 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -268,448 +268,448 @@ void cgit_tree_link(char *name, char *title, char *class, char *head, | |||
268 | reporevlink("tree", name, title, class, head, rev, path); | 268 | reporevlink("tree", name, title, class, head, rev, path); |
269 | } | 269 | } |
270 | 270 | ||
271 | void cgit_plain_link(char *name, char *title, char *class, char *head, | 271 | void cgit_plain_link(char *name, char *title, char *class, char *head, |
272 | char *rev, char *path) | 272 | char *rev, char *path) |
273 | { | 273 | { |
274 | reporevlink("plain", name, title, class, head, rev, path); | 274 | reporevlink("plain", name, title, class, head, rev, path); |
275 | } | 275 | } |
276 | 276 | ||
277 | void cgit_log_link(char *name, char *title, char *class, char *head, | 277 | void cgit_log_link(char *name, char *title, char *class, char *head, |
278 | char *rev, char *path, int ofs, char *grep, char *pattern) | 278 | char *rev, char *path, int ofs, char *grep, char *pattern) |
279 | { | 279 | { |
280 | char *delim; | 280 | char *delim; |
281 | 281 | ||
282 | delim = repolink(title, class, "log", head, path); | 282 | delim = repolink(title, class, "log", head, path); |
283 | if (rev && strcmp(rev, ctx.qry.head)) { | 283 | if (rev && strcmp(rev, ctx.qry.head)) { |
284 | html(delim); | 284 | html(delim); |
285 | html("id="); | 285 | html("id="); |
286 | html_url_arg(rev); | 286 | html_url_arg(rev); |
287 | delim = "&"; | 287 | delim = "&"; |
288 | } | 288 | } |
289 | if (grep && pattern) { | 289 | if (grep && pattern) { |
290 | html(delim); | 290 | html(delim); |
291 | html("qt="); | 291 | html("qt="); |
292 | html_url_arg(grep); | 292 | html_url_arg(grep); |
293 | delim = "&"; | 293 | delim = "&"; |
294 | html(delim); | 294 | html(delim); |
295 | html("q="); | 295 | html("q="); |
296 | html_url_arg(pattern); | 296 | html_url_arg(pattern); |
297 | } | 297 | } |
298 | if (ofs > 0) { | 298 | if (ofs > 0) { |
299 | html(delim); | 299 | html(delim); |
300 | html("ofs="); | 300 | html("ofs="); |
301 | htmlf("%d", ofs); | 301 | htmlf("%d", ofs); |
302 | } | 302 | } |
303 | html("'>"); | 303 | html("'>"); |
304 | html_txt(name); | 304 | html_txt(name); |
305 | html("</a>"); | 305 | html("</a>"); |
306 | } | 306 | } |
307 | 307 | ||
308 | void cgit_commit_link(char *name, char *title, char *class, char *head, | 308 | void cgit_commit_link(char *name, char *title, char *class, char *head, |
309 | char *rev) | 309 | char *rev) |
310 | { | 310 | { |
311 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { | 311 | if (strlen(name) > ctx.cfg.max_msg_len && ctx.cfg.max_msg_len >= 15) { |
312 | name[ctx.cfg.max_msg_len] = '\0'; | 312 | name[ctx.cfg.max_msg_len] = '\0'; |
313 | name[ctx.cfg.max_msg_len - 1] = '.'; | 313 | name[ctx.cfg.max_msg_len - 1] = '.'; |
314 | name[ctx.cfg.max_msg_len - 2] = '.'; | 314 | name[ctx.cfg.max_msg_len - 2] = '.'; |
315 | name[ctx.cfg.max_msg_len - 3] = '.'; | 315 | name[ctx.cfg.max_msg_len - 3] = '.'; |
316 | } | 316 | } |
317 | reporevlink("commit", name, title, class, head, rev, NULL); | 317 | reporevlink("commit", name, title, class, head, rev, NULL); |
318 | } | 318 | } |
319 | 319 | ||
320 | void cgit_refs_link(char *name, char *title, char *class, char *head, | 320 | void cgit_refs_link(char *name, char *title, char *class, char *head, |
321 | char *rev, char *path) | 321 | char *rev, char *path) |
322 | { | 322 | { |
323 | reporevlink("refs", name, title, class, head, rev, path); | 323 | reporevlink("refs", name, title, class, head, rev, path); |
324 | } | 324 | } |
325 | 325 | ||
326 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, | 326 | void cgit_snapshot_link(char *name, char *title, char *class, char *head, |
327 | char *rev, char *archivename) | 327 | char *rev, char *archivename) |
328 | { | 328 | { |
329 | reporevlink("snapshot", name, title, class, head, rev, archivename); | 329 | reporevlink("snapshot", name, title, class, head, rev, archivename); |
330 | } | 330 | } |
331 | 331 | ||
332 | void cgit_diff_link(char *name, char *title, char *class, char *head, | 332 | void cgit_diff_link(char *name, char *title, char *class, char *head, |
333 | char *new_rev, char *old_rev, char *path) | 333 | char *new_rev, char *old_rev, char *path) |
334 | { | 334 | { |
335 | char *delim; | 335 | char *delim; |
336 | 336 | ||
337 | delim = repolink(title, class, "diff", head, path); | 337 | delim = repolink(title, class, "diff", head, path); |
338 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { | 338 | if (new_rev && strcmp(new_rev, ctx.qry.head)) { |
339 | html(delim); | 339 | html(delim); |
340 | html("id="); | 340 | html("id="); |
341 | html_url_arg(new_rev); | 341 | html_url_arg(new_rev); |
342 | delim = "&"; | 342 | delim = "&"; |
343 | } | 343 | } |
344 | if (old_rev) { | 344 | if (old_rev) { |
345 | html(delim); | 345 | html(delim); |
346 | html("id2="); | 346 | html("id2="); |
347 | html_url_arg(old_rev); | 347 | html_url_arg(old_rev); |
348 | } | 348 | } |
349 | html("'>"); | 349 | html("'>"); |
350 | html_txt(name); | 350 | html_txt(name); |
351 | html("</a>"); | 351 | html("</a>"); |
352 | } | 352 | } |
353 | 353 | ||
354 | void cgit_patch_link(char *name, char *title, char *class, char *head, | 354 | void cgit_patch_link(char *name, char *title, char *class, char *head, |
355 | char *rev) | 355 | char *rev) |
356 | { | 356 | { |
357 | reporevlink("patch", name, title, class, head, rev, NULL); | 357 | reporevlink("patch", name, title, class, head, rev, NULL); |
358 | } | 358 | } |
359 | 359 | ||
360 | void cgit_object_link(struct object *obj) | 360 | void cgit_object_link(struct object *obj) |
361 | { | 361 | { |
362 | char *page, *arg, *url; | 362 | char *page, *arg, *url; |
363 | 363 | ||
364 | if (obj->type == OBJ_COMMIT) { | 364 | if (obj->type == OBJ_COMMIT) { |
365 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, | 365 | cgit_commit_link(fmt("commit %s", sha1_to_hex(obj->sha1)), NULL, NULL, |
366 | ctx.qry.head, sha1_to_hex(obj->sha1)); | 366 | ctx.qry.head, sha1_to_hex(obj->sha1)); |
367 | return; | 367 | return; |
368 | } else if (obj->type == OBJ_TREE) { | 368 | } else if (obj->type == OBJ_TREE) { |
369 | page = "tree"; | 369 | page = "tree"; |
370 | arg = "id"; | 370 | arg = "id"; |
371 | } else if (obj->type == OBJ_TAG) { | 371 | } else if (obj->type == OBJ_TAG) { |
372 | page = "tag"; | 372 | page = "tag"; |
373 | arg = "id"; | 373 | arg = "id"; |
374 | } else { | 374 | } else { |
375 | page = "blob"; | 375 | page = "blob"; |
376 | arg = "id"; | 376 | arg = "id"; |
377 | } | 377 | } |
378 | 378 | ||
379 | url = cgit_pageurl(ctx.qry.repo, page, | 379 | url = cgit_pageurl(ctx.qry.repo, page, |
380 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); | 380 | fmt("%s=%s", arg, sha1_to_hex(obj->sha1))); |
381 | html_link_open(url, NULL, NULL); | 381 | html_link_open(url, NULL, NULL); |
382 | htmlf("%s %s", typename(obj->type), | 382 | htmlf("%s %s", typename(obj->type), |
383 | sha1_to_hex(obj->sha1)); | 383 | sha1_to_hex(obj->sha1)); |
384 | html_link_close(); | 384 | html_link_close(); |
385 | } | 385 | } |
386 | 386 | ||
387 | void cgit_print_date(time_t secs, char *format, int local_time) | 387 | void cgit_print_date(time_t secs, char *format, int local_time) |
388 | { | 388 | { |
389 | char buf[64]; | 389 | char buf[64]; |
390 | struct tm *time; | 390 | struct tm *time; |
391 | 391 | ||
392 | if (!secs) | 392 | if (!secs) |
393 | return; | 393 | return; |
394 | if(local_time) | 394 | if(local_time) |
395 | time = localtime(&secs); | 395 | time = localtime(&secs); |
396 | else | 396 | else |
397 | time = gmtime(&secs); | 397 | time = gmtime(&secs); |
398 | strftime(buf, sizeof(buf)-1, format, time); | 398 | strftime(buf, sizeof(buf)-1, format, time); |
399 | html_txt(buf); | 399 | html_txt(buf); |
400 | } | 400 | } |
401 | 401 | ||
402 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 402 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
403 | { | 403 | { |
404 | time_t now, secs; | 404 | time_t now, secs; |
405 | 405 | ||
406 | if (!t) | 406 | if (!t) |
407 | return; | 407 | return; |
408 | time(&now); | 408 | time(&now); |
409 | secs = now - t; | 409 | secs = now - t; |
410 | 410 | ||
411 | if (secs > max_relative && max_relative >= 0) { | 411 | if (secs > max_relative && max_relative >= 0) { |
412 | cgit_print_date(t, format, ctx.cfg.local_time); | 412 | cgit_print_date(t, format, ctx.cfg.local_time); |
413 | return; | 413 | return; |
414 | } | 414 | } |
415 | 415 | ||
416 | if (secs < TM_HOUR * 2) { | 416 | if (secs < TM_HOUR * 2) { |
417 | htmlf("<span class='age-mins'>%.0f min.</span>", | 417 | htmlf("<span class='age-mins'>%.0f min.</span>", |
418 | secs * 1.0 / TM_MIN); | 418 | secs * 1.0 / TM_MIN); |
419 | return; | 419 | return; |
420 | } | 420 | } |
421 | if (secs < TM_DAY * 2) { | 421 | if (secs < TM_DAY * 2) { |
422 | htmlf("<span class='age-hours'>%.0f hours</span>", | 422 | htmlf("<span class='age-hours'>%.0f hours</span>", |
423 | secs * 1.0 / TM_HOUR); | 423 | secs * 1.0 / TM_HOUR); |
424 | return; | 424 | return; |
425 | } | 425 | } |
426 | if (secs < TM_WEEK * 2) { | 426 | if (secs < TM_WEEK * 2) { |
427 | htmlf("<span class='age-days'>%.0f days</span>", | 427 | htmlf("<span class='age-days'>%.0f days</span>", |
428 | secs * 1.0 / TM_DAY); | 428 | secs * 1.0 / TM_DAY); |
429 | return; | 429 | return; |
430 | } | 430 | } |
431 | if (secs < TM_MONTH * 2) { | 431 | if (secs < TM_MONTH * 2) { |
432 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 432 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
433 | secs * 1.0 / TM_WEEK); | 433 | secs * 1.0 / TM_WEEK); |
434 | return; | 434 | return; |
435 | } | 435 | } |
436 | if (secs < TM_YEAR * 2) { | 436 | if (secs < TM_YEAR * 2) { |
437 | htmlf("<span class='age-months'>%.0f months</span>", | 437 | htmlf("<span class='age-months'>%.0f months</span>", |
438 | secs * 1.0 / TM_MONTH); | 438 | secs * 1.0 / TM_MONTH); |
439 | return; | 439 | return; |
440 | } | 440 | } |
441 | htmlf("<span class='age-years'>%.0f years</span>", | 441 | htmlf("<span class='age-years'>%.0f years</span>", |
442 | secs * 1.0 / TM_YEAR); | 442 | secs * 1.0 / TM_YEAR); |
443 | } | 443 | } |
444 | 444 | ||
445 | void cgit_print_http_headers(struct cgit_context *ctx) | 445 | void cgit_print_http_headers(struct cgit_context *ctx) |
446 | { | 446 | { |
447 | if (ctx->page.mimetype && ctx->page.charset) | 447 | if (ctx->page.mimetype && ctx->page.charset) |
448 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 448 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
449 | ctx->page.charset); | 449 | ctx->page.charset); |
450 | else if (ctx->page.mimetype) | 450 | else if (ctx->page.mimetype) |
451 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 451 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
452 | if (ctx->page.size) | 452 | if (ctx->page.size) |
453 | htmlf("Content-Length: %ld\n", ctx->page.size); | 453 | htmlf("Content-Length: %ld\n", ctx->page.size); |
454 | if (ctx->page.filename) | 454 | if (ctx->page.filename) |
455 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 455 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
456 | ctx->page.filename); | 456 | ctx->page.filename); |
457 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 457 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
458 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 458 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
459 | html("\n"); | 459 | html("\n"); |
460 | } | 460 | } |
461 | 461 | ||
462 | void cgit_print_docstart(struct cgit_context *ctx) | 462 | void cgit_print_docstart(struct cgit_context *ctx) |
463 | { | 463 | { |
464 | char *host = cgit_hosturl(); | 464 | char *host = cgit_hosturl(); |
465 | html(cgit_doctype); | 465 | html(cgit_doctype); |
466 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 466 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
467 | html("<head>\n"); | 467 | html("<head>\n"); |
468 | html("<title>"); | 468 | html("<title>"); |
469 | html_txt(ctx->page.title); | 469 | html_txt(ctx->page.title); |
470 | html("</title>\n"); | 470 | html("</title>\n"); |
471 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 471 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
472 | if (ctx->cfg.robots && *ctx->cfg.robots) | 472 | if (ctx->cfg.robots && *ctx->cfg.robots) |
473 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 473 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
474 | html("<link rel='stylesheet' type='text/css' href='"); | 474 | html("<link rel='stylesheet' type='text/css' href='"); |
475 | html_attr(ctx->cfg.css); | 475 | html_attr(ctx->cfg.css); |
476 | html("'/>\n"); | 476 | html("'/>\n"); |
477 | if (ctx->cfg.favicon) { | 477 | if (ctx->cfg.favicon) { |
478 | html("<link rel='shortcut icon' href='"); | 478 | html("<link rel='shortcut icon' href='"); |
479 | html_attr(ctx->cfg.favicon); | 479 | html_attr(ctx->cfg.favicon); |
480 | html("'/>\n"); | 480 | html("'/>\n"); |
481 | } | 481 | } |
482 | if (host && ctx->repo) { | 482 | if (host && ctx->repo) { |
483 | html("<link rel='alternate' title='Atom feed' href='http://"); | 483 | html("<link rel='alternate' title='Atom feed' href='http://"); |
484 | html_attr(cgit_hosturl()); | 484 | html_attr(cgit_hosturl()); |
485 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 485 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, |
486 | fmt("h=%s", ctx->qry.head))); | 486 | fmt("h=%s", ctx->qry.head))); |
487 | html("' type='application/atom+xml'/>"); | 487 | html("' type='application/atom+xml'/>"); |
488 | } | 488 | } |
489 | html("</head>\n"); | 489 | html("</head>\n"); |
490 | html("<body>\n"); | 490 | html("<body>\n"); |
491 | } | 491 | } |
492 | 492 | ||
493 | void cgit_print_docend() | 493 | void cgit_print_docend() |
494 | { | 494 | { |
495 | html("</div>"); | 495 | html("</div>"); |
496 | if (ctx.cfg.footer) | 496 | if (ctx.cfg.footer) |
497 | html_include(ctx.cfg.footer); | 497 | html_include(ctx.cfg.footer); |
498 | else { | 498 | else { |
499 | htmlf("<div class='footer'>generated by cgit %s at ", | 499 | htmlf("<div class='footer'>generated by cgit %s at ", |
500 | cgit_version); | 500 | cgit_version); |
501 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 501 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
502 | html("</div>\n"); | 502 | html("</div>\n"); |
503 | } | 503 | } |
504 | html("</body>\n</html>\n"); | 504 | html("</body>\n</html>\n"); |
505 | } | 505 | } |
506 | 506 | ||
507 | int print_branch_option(const char *refname, const unsigned char *sha1, | 507 | int print_branch_option(const char *refname, const unsigned char *sha1, |
508 | int flags, void *cb_data) | 508 | int flags, void *cb_data) |
509 | { | 509 | { |
510 | char *name = (char *)refname; | 510 | char *name = (char *)refname; |
511 | html_option(name, name, ctx.qry.head); | 511 | html_option(name, name, ctx.qry.head); |
512 | return 0; | 512 | return 0; |
513 | } | 513 | } |
514 | 514 | ||
515 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 515 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
516 | int flags, void *cb_data) | 516 | int flags, void *cb_data) |
517 | { | 517 | { |
518 | struct tag *tag; | 518 | struct tag *tag; |
519 | struct taginfo *info; | 519 | struct taginfo *info; |
520 | struct object *obj; | 520 | struct object *obj; |
521 | char buf[256], *url; | 521 | char buf[256], *url; |
522 | unsigned char fileid[20]; | 522 | unsigned char fileid[20]; |
523 | int *header = (int *)cb_data; | 523 | int *header = (int *)cb_data; |
524 | 524 | ||
525 | if (prefixcmp(refname, "refs/archives")) | 525 | if (prefixcmp(refname, "refs/archives")) |
526 | return 0; | 526 | return 0; |
527 | strncpy(buf, refname+14, sizeof(buf)); | 527 | strncpy(buf, refname+14, sizeof(buf)); |
528 | obj = parse_object(sha1); | 528 | obj = parse_object(sha1); |
529 | if (!obj) | 529 | if (!obj) |
530 | return 1; | 530 | return 1; |
531 | if (obj->type == OBJ_TAG) { | 531 | if (obj->type == OBJ_TAG) { |
532 | tag = lookup_tag(sha1); | 532 | tag = lookup_tag(sha1); |
533 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 533 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
534 | return 0; | 534 | return 0; |
535 | hashcpy(fileid, tag->tagged->sha1); | 535 | hashcpy(fileid, tag->tagged->sha1); |
536 | } else if (obj->type != OBJ_BLOB) { | 536 | } else if (obj->type != OBJ_BLOB) { |
537 | return 0; | 537 | return 0; |
538 | } else { | 538 | } else { |
539 | hashcpy(fileid, sha1); | 539 | hashcpy(fileid, sha1); |
540 | } | 540 | } |
541 | if (!*header) { | 541 | if (!*header) { |
542 | html("<h1>download</h1>\n"); | 542 | html("<h1>download</h1>\n"); |
543 | *header = 1; | 543 | *header = 1; |
544 | } | 544 | } |
545 | url = cgit_pageurl(ctx.qry.repo, "blob", | 545 | url = cgit_pageurl(ctx.qry.repo, "blob", |
546 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 546 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
547 | buf)); | 547 | buf)); |
548 | html_link_open(url, NULL, "menu"); | 548 | html_link_open(url, NULL, "menu"); |
549 | html_txt(strlpart(buf, 20)); | 549 | html_txt(strlpart(buf, 20)); |
550 | html_link_close(); | 550 | html_link_close(); |
551 | return 0; | 551 | return 0; |
552 | } | 552 | } |
553 | 553 | ||
554 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 554 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
555 | { | 555 | { |
556 | char *url; | 556 | char *url; |
557 | 557 | ||
558 | if (!ctx.cfg.virtual_root) { | 558 | if (!ctx.cfg.virtual_root) { |
559 | url = fmt("%s/%s", ctx.qry.repo, page); | 559 | url = fmt("%s/%s", ctx.qry.repo, page); |
560 | if (ctx.qry.path) | 560 | if (ctx.qry.path) |
561 | url = fmt("%s/%s", url, ctx.qry.path); | 561 | url = fmt("%s/%s", url, ctx.qry.path); |
562 | html_hidden("url", url); | 562 | html_hidden("url", url); |
563 | } | 563 | } |
564 | 564 | ||
565 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 565 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
566 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 566 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
567 | html_hidden("h", ctx.qry.head); | 567 | html_hidden("h", ctx.qry.head); |
568 | 568 | ||
569 | if (ctx.qry.sha1) | 569 | if (ctx.qry.sha1) |
570 | html_hidden("id", ctx.qry.sha1); | 570 | html_hidden("id", ctx.qry.sha1); |
571 | if (ctx.qry.sha2) | 571 | if (ctx.qry.sha2) |
572 | html_hidden("id2", ctx.qry.sha2); | 572 | html_hidden("id2", ctx.qry.sha2); |
573 | 573 | ||
574 | if (incl_search) { | 574 | if (incl_search) { |
575 | if (ctx.qry.grep) | 575 | if (ctx.qry.grep) |
576 | html_hidden("qt", ctx.qry.grep); | 576 | html_hidden("qt", ctx.qry.grep); |
577 | if (ctx.qry.search) | 577 | if (ctx.qry.search) |
578 | html_hidden("q", ctx.qry.search); | 578 | html_hidden("q", ctx.qry.search); |
579 | } | 579 | } |
580 | } | 580 | } |
581 | 581 | ||
582 | char *hc(struct cgit_cmd *cmd, const char *page) | 582 | char *hc(struct cgit_cmd *cmd, const char *page) |
583 | { | 583 | { |
584 | return (strcmp(cmd->name, page) ? NULL : "active"); | 584 | return (strcmp(cmd->name, page) ? NULL : "active"); |
585 | } | 585 | } |
586 | 586 | ||
587 | void cgit_print_pageheader(struct cgit_context *ctx) | 587 | void cgit_print_pageheader(struct cgit_context *ctx) |
588 | { | 588 | { |
589 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | 589 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); |
590 | 590 | ||
591 | html("<table id='header'>\n"); | 591 | html("<table id='header'>\n"); |
592 | html("<tr>\n"); | 592 | html("<tr>\n"); |
593 | html("<td class='logo' rowspan='2'><a href='"); | 593 | html("<td class='logo' rowspan='2'><a href='"); |
594 | if (ctx->cfg.logo_link) | 594 | if (ctx->cfg.logo_link) |
595 | html_attr(ctx->cfg.logo_link); | 595 | html_attr(ctx->cfg.logo_link); |
596 | else | 596 | else |
597 | html_attr(cgit_rooturl()); | 597 | html_attr(cgit_rooturl()); |
598 | html("'><img src='"); | 598 | html("'><img src='"); |
599 | html_attr(ctx->cfg.logo); | 599 | html_attr(ctx->cfg.logo); |
600 | html("' alt='cgit logo'/></a></td>\n"); | 600 | html("' alt='cgit logo'/></a></td>\n"); |
601 | 601 | ||
602 | html("<td class='main'>"); | 602 | html("<td class='main'>"); |
603 | if (ctx->repo) { | 603 | if (ctx->repo) { |
604 | cgit_index_link("index", NULL, NULL, NULL, 0); | 604 | cgit_index_link("index", NULL, NULL, NULL, 0); |
605 | html(" : "); | 605 | html(" : "); |
606 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); | 606 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
607 | html("</td><td class='form'>"); | 607 | html("</td><td class='form'>"); |
608 | html("<form method='get' action=''>\n"); | 608 | html("<form method='get' action=''>\n"); |
609 | add_hidden_formfields(0, 1, ctx->qry.page); | 609 | add_hidden_formfields(0, 1, ctx->qry.page); |
610 | html("<select name='h' onchange='this.form.submit();'>\n"); | 610 | html("<select name='h' onchange='this.form.submit();'>\n"); |
611 | for_each_branch_ref(print_branch_option, ctx->qry.head); | 611 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
612 | html("</select> "); | 612 | html("</select> "); |
613 | html("<input type='submit' name='' value='switch'/>"); | 613 | html("<input type='submit' name='' value='switch'/>"); |
614 | html("</form>"); | 614 | html("</form>"); |
615 | } else | 615 | } else |
616 | html_txt(ctx->cfg.root_title); | 616 | html_txt(ctx->cfg.root_title); |
617 | html("</td></tr>\n"); | 617 | html("</td></tr>\n"); |
618 | 618 | ||
619 | html("<tr><td class='sub'>"); | 619 | html("<tr><td class='sub'>"); |
620 | if (ctx->repo) { | 620 | if (ctx->repo) { |
621 | html_txt(ctx->repo->desc); | 621 | html_txt(ctx->repo->desc); |
622 | html("</td><td class='sub right'>"); | 622 | html("</td><td class='sub right'>"); |
623 | html_txt(ctx->repo->owner); | 623 | html_txt(ctx->repo->owner); |
624 | } else { | 624 | } else { |
625 | if (ctx->cfg.root_desc) | 625 | if (ctx->cfg.root_desc) |
626 | html_txt(ctx->cfg.root_desc); | 626 | html_txt(ctx->cfg.root_desc); |
627 | else if (ctx->cfg.index_info) | 627 | else if (ctx->cfg.index_info) |
628 | html_include(ctx->cfg.index_info); | 628 | html_include(ctx->cfg.index_info); |
629 | } | 629 | } |
630 | html("</td></tr></table>\n"); | 630 | html("</td></tr></table>\n"); |
631 | 631 | ||
632 | html("<table class='tabs'><tr><td>\n"); | 632 | html("<table class='tabs'><tr><td>\n"); |
633 | if (ctx->repo) { | 633 | if (ctx->repo) { |
634 | cgit_summary_link("summary", NULL, NULL, ctx->qry.head); | 634 | cgit_summary_link("summary", NULL, NULL, ctx->qry.head); |
635 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 635 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, |
636 | ctx->qry.sha1, NULL); | 636 | ctx->qry.sha1, NULL); |
637 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | 637 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, |
638 | NULL, NULL, 0, NULL, NULL); | 638 | NULL, NULL, 0, NULL, NULL); |
639 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | 639 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, |
640 | ctx->qry.sha1, NULL); | 640 | ctx->qry.sha1, NULL); |
641 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 641 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), |
642 | ctx->qry.head, ctx->qry.sha1); | 642 | ctx->qry.head, ctx->qry.sha1); |
643 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 643 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, |
644 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 644 | ctx->qry.sha1, ctx->qry.sha2, NULL); |
645 | if (ctx->repo->readme) | 645 | if (ctx->repo->readme) |
646 | reporevlink("about", "about", NULL, | 646 | reporevlink("about", "about", NULL, |
647 | hc(cmd, "about"), ctx->qry.head, NULL, | 647 | hc(cmd, "about"), ctx->qry.head, NULL, |
648 | NULL); | 648 | NULL); |
649 | html("</td><td class='form'>"); | 649 | html("</td><td class='form'>"); |
650 | html("<form class='right' method='get' action='"); | 650 | html("<form class='right' method='get' action='"); |
651 | if (ctx->cfg.virtual_root) | 651 | if (ctx->cfg.virtual_root) |
652 | html_attr(cgit_fileurl(ctx->qry.repo, "log", | 652 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", |
653 | ctx->qry.path, NULL)); | 653 | ctx->qry.path, NULL)); |
654 | html("'>\n"); | 654 | html("'>\n"); |
655 | add_hidden_formfields(1, 0, "log"); | 655 | add_hidden_formfields(1, 0, "log"); |
656 | html("<select name='qt'>\n"); | 656 | html("<select name='qt'>\n"); |
657 | html_option("grep", "log msg", ctx->qry.grep); | 657 | html_option("grep", "log msg", ctx->qry.grep); |
658 | html_option("author", "author", ctx->qry.grep); | 658 | html_option("author", "author", ctx->qry.grep); |
659 | html_option("committer", "committer", ctx->qry.grep); | 659 | html_option("committer", "committer", ctx->qry.grep); |
660 | html("</select>\n"); | 660 | html("</select>\n"); |
661 | html("<input class='txt' type='text' size='10' name='q' value='"); | 661 | html("<input class='txt' type='text' size='10' name='q' value='"); |
662 | html_attr(ctx->qry.search); | 662 | html_attr(ctx->qry.search); |
663 | html("'/>\n"); | 663 | html("'/>\n"); |
664 | html("<input type='submit' value='search'/>\n"); | 664 | html("<input type='submit' value='search'/>\n"); |
665 | html("</form>\n"); | 665 | html("</form>\n"); |
666 | } else { | 666 | } else { |
667 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); | 667 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); |
668 | if (ctx->cfg.root_readme) | 668 | if (ctx->cfg.root_readme) |
669 | site_link("about", "about", NULL, hc(cmd, "about"), | 669 | site_link("about", "about", NULL, hc(cmd, "about"), |
670 | NULL, 0); | 670 | NULL, 0); |
671 | html("</td><td class='form'>"); | 671 | html("</td><td class='form'>"); |
672 | html("<form method='get' action='"); | 672 | html("<form method='get' action='"); |
673 | html_attr(cgit_rooturl()); | 673 | html_attr(cgit_rooturl()); |
674 | html("'>\n"); | 674 | html("'>\n"); |
675 | html("<input type='text' name='q' size='10' value='"); | 675 | html("<input type='text' name='q' size='10' value='"); |
676 | html_attr(ctx->qry.search); | 676 | html_attr(ctx->qry.search); |
677 | html("'/>\n"); | 677 | html("'/>\n"); |
678 | html("<input type='submit' value='search'/>\n"); | 678 | html("<input type='submit' value='search'/>\n"); |
679 | html("</form>"); | 679 | html("</form>"); |
680 | } | 680 | } |
681 | html("</td></tr></table>\n"); | 681 | html("</td></tr></table>\n"); |
682 | html("<div class='content'>"); | 682 | html("<div class='content'>"); |
683 | } | 683 | } |
684 | 684 | ||
685 | void cgit_print_filemode(unsigned short mode) | 685 | void cgit_print_filemode(unsigned short mode) |
686 | { | 686 | { |
687 | if (S_ISDIR(mode)) | 687 | if (S_ISDIR(mode)) |
688 | html("d"); | 688 | html("d"); |
689 | else if (S_ISLNK(mode)) | 689 | else if (S_ISLNK(mode)) |
690 | html("l"); | 690 | html("l"); |
691 | else if (S_ISGITLINK(mode)) | 691 | else if (S_ISGITLINK(mode)) |
692 | html("m"); | 692 | html("m"); |
693 | else | 693 | else |
694 | html("-"); | 694 | html("-"); |
695 | html_fileperm(mode >> 6); | 695 | html_fileperm(mode >> 6); |
696 | html_fileperm(mode >> 3); | 696 | html_fileperm(mode >> 3); |
697 | html_fileperm(mode); | 697 | html_fileperm(mode); |
698 | } | 698 | } |
699 | 699 | ||
700 | void cgit_print_snapshot_links(const char *repo, const char *head, | 700 | void cgit_print_snapshot_links(const char *repo, const char *head, |
701 | const char *hex, int snapshots) | 701 | const char *hex, int snapshots) |
702 | { | 702 | { |
703 | const struct cgit_snapshot_format* f; | 703 | const struct cgit_snapshot_format* f; |
704 | char *filename; | 704 | char *filename; |
705 | 705 | ||
706 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 706 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
707 | if (!(snapshots & f->bit)) | 707 | if (!(snapshots & f->bit)) |
708 | continue; | 708 | continue; |
709 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | 709 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, |
710 | f->suffix); | 710 | f->suffix); |
711 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, | 711 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, |
712 | (char *)hex, filename); | 712 | (char *)hex, filename); |
713 | html("<br/>"); | 713 | html("<br/>"); |
714 | } | 714 | } |
715 | } | 715 | } |