Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Clean up the /doc webpage. Use newer interfaces that were created since that page was original written. Set the HTTP status to 404 on not found. Try to find a "404.md" page to display and use it if found instead of the default 404 page. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
cfcd9b87dcf54a16f206cbeebf7c443b |
| User & Date: | drh 2015-01-23 04:26:39.353 |
Context
|
2015-01-23
| ||
| 05:49 | Fix build issue for MinGW due to missing 'ws2tcpip.h' functions. ... (check-in: 4c247512a8 user: mistachkin tags: trunk) | |
| 05:41 | Slightly 'improve' summary line for push/pull/sync operations. ... (check-in: dbf93c23f7 user: mistachkin tags: xferSumFmt) | |
| 04:26 | Clean up the /doc webpage. Use newer interfaces that were created since that page was original written. Set the HTTP status to 404 on not found. Try to find a "404.md" page to display and use it if found instead of the default 404 page. ... (check-in: cfcd9b87dc user: drh tags: trunk) | |
| 02:05 | Use IPv6 for "fossil sync" when available. ... (check-in: 1dbd4d0d0b user: drh tags: trunk) | |
Changes
Changes to src/doc.c.
| ︙ | ︙ | |||
351 352 353 354 355 356 357 |
for(i=2; i<g.argc; i++){
fossil_print("%-20s -> %s\n", g.argv[i], mimetype_from_name(g.argv[i]));
}
}
/*
** WEBPAGE: doc
| | | | | | > | < | | > > > > > > > > > > > > > | | > | | < | < < < | > > | < | > | | | > | | < > > | | < > > > < < < < | < < < | | | < < < < < < < | < < | < < < < < < < | < < < < < < > | | > < < < < < < | < < | < < | < > > < < | | | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
for(i=2; i<g.argc; i++){
fossil_print("%-20s -> %s\n", g.argv[i], mimetype_from_name(g.argv[i]));
}
}
/*
** WEBPAGE: doc
** URL: /doc?name=CHECKIN/FILE
** URL: /doc/CHECKIN/FILE
**
** CHECKIN can be either tag or SHA1 hash or timestamp identifying a
** particular check, or the name of a branch (meaning the most recent
** check-in on that branch) or one of various magic words:
**
** "tip" means the most recent check-in
**
** "ckout" means the current check-out, if the server is run from
** within a check-out, otherwise it is the same as "tip"
**
** FILE is the name of a file to delivered up as a webpage. FILE is relative
** to the root of the source tree of the repository. The FILE must
** be a part of CHECKIN, except when CHECKIN=="ckout" when FILE is read
** directly from disk and need not be a managed file.
**
** The "ckout" CHECKIN is intended for development - to provide a mechanism
** for looking at what a file will look like using the /doc webpage after
** it gets checked in.
**
** The file extension is used to decide how to render the file.
*/
void doc_page(void){
const char *zName; /* Argument to the /doc page */
const char *zOrigName; /* Original document name */
const char *zMime; /* Document MIME type */
char *zCheckin; /* The checkin holding the document */
int vid = 0; /* Artifact of checkin */
int rid = 0; /* Artifact of file */
int i; /* Loop counter */
Blob filebody; /* Content of the documentation file */
int nMiss = 0; /* Failed attempts to find the document */
login_check_credentials();
if( !g.perm.Read ){ login_needed(); return; }
zName = PD("name", "tip/index.wiki");
for(i=0; zName[i] && zName[i]!='/'; i++){}
zCheckin = mprintf("%.*s", i, zName);
if( zName[i]==0 ){
zName = "index.wiki";
}else{
zName += i;
}
while( zName[0]=='/' ){ zName++; }
g.zPath = mprintf("%s/%s/%s", g.zPath, zCheckin, zName);
if( !file_is_simple_pathname(zName, 1) ){
if( sqlite3_strglob("*/", zName)==0 ){
zName = mprintf("%sindex.wiki", zName);
if( !file_is_simple_pathname(zName, 1) ){
goto doc_not_found;
}
}else{
goto doc_not_found;
}
}
zOrigName = zName;
if( fossil_strcmp(zCheckin,"ckout")==0 && db_open_local(0)==0 ){
sqlite3_snprintf(sizeof(zCheckin), zCheckin, "tip");
}
if( fossil_strcmp(zCheckin,"ckout")==0 ){
/* Read from the local checkout */
char *zFullpath;
db_must_be_within_tree();
while( rid==0 && nMiss<2 ){
zFullpath = mprintf("%s/%s", g.zLocalRoot, zName);
if( file_isfile(zFullpath)
&& blob_read_from_file(&filebody, zFullpath)<0 ){
rid = 1; /* Fake RID just to get the loop to end */
}
fossil_free(zFullpath);
if( rid ) break;
nMiss++;
zName = "404.md";
}
}else{
db_begin_transaction();
vid = name_to_typed_rid(zCheckin, "ci");
db_multi_exec(
"CREATE TABLE IF NOT EXISTS vcache(\n"
" vid INTEGER, -- checkin ID\n"
" fname TEXT, -- filename\n"
" rid INTEGER, -- artifact ID\n"
" PRIMARY KEY(vid,fname)\n"
") WITHOUT ROWID"
);
if( !db_exists("SELECT 1 FROM vcache WHERE vid=%d", vid) ){
db_multi_exec(
"DELETE FROM vcache;\n"
"CREATE VIRTUAL TABLE temp.foci USING files_of_checkin;\n"
"INSERT INTO vcache(vid,fname,rid)"
" SELECT checkinID, filename, blob.rid FROM foci, blob"
" WHERE blob.uuid=foci.uuid"
" AND foci.checkinID=%d;",
vid
);
}
while( rid==0 && nMiss<2 ){
rid = db_int(0, "SELECT rid FROM vcache"
" WHERE vid=%d AND fname=%Q", vid, zName);
if( rid ) break;
nMiss++;
zName = "404.md";
}
if( rid==0 || content_get(rid, &filebody)==0 ){
goto doc_not_found;
}
db_end_transaction(0);
}
blob_to_utf8_no_bom(&filebody, 0);
/* The file is now contained in the filebody blob. Deliver the
** file to the user
*/
zMime = nMiss==0 ? P("mimetype") : 0;
if( zMime==0 ){
zMime = mimetype_from_name(zName);
}
Th_Store("doc_name", zName);
Th_Store("doc_version", db_text(0, "SELECT '[' || substr(uuid,1,10) || ']'"
" FROM blob WHERE rid=%d", vid));
Th_Store("doc_date", db_text(0, "SELECT datetime(mtime) FROM event"
|
| ︙ | ︙ | |||
514 515 516 517 518 519 520 |
}else if( fossil_strcmp(zMime, "text/x-markdown")==0 ){
Blob title = BLOB_INITIALIZER;
Blob tail = BLOB_INITIALIZER;
markdown_to_html(&filebody, &title, &tail);
if( blob_size(&title)>0 ){
style_header("%s", blob_str(&title));
}else{
| | > < > > | | > > > | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 |
}else if( fossil_strcmp(zMime, "text/x-markdown")==0 ){
Blob title = BLOB_INITIALIZER;
Blob tail = BLOB_INITIALIZER;
markdown_to_html(&filebody, &title, &tail);
if( blob_size(&title)>0 ){
style_header("%s", blob_str(&title));
}else{
style_header("%s", nMiss?"Not Found":"Documentation");
}
blob_append(cgi_output_blob(), blob_buffer(&tail), blob_size(&tail));
style_footer();
}else if( fossil_strcmp(zMime, "text/plain")==0 ){
style_header("Documentation");
@ <blockquote><pre>
@ %h(blob_str(&filebody))
@ </pre></blockquote>
style_footer();
#ifdef FOSSIL_ENABLE_TH1_DOCS
}else if( db_get_boolean("th1-docs", 0) &&
fossil_strcmp(zMime, "application/x-th1")==0 ){
style_header("%h", zName);
Th_Render(blob_str(&filebody));
style_footer();
#endif
}else{
cgi_set_content_type(zMime);
cgi_set_content(&filebody);
}
if( nMiss ) cgi_set_status(404, "Not Found");
return;
/* Jump here when unable to locate the document */
doc_not_found:
db_end_transaction(0);
cgi_set_status(404, "Not Found");
style_header("Not Found");
@ <p>Document %h(zOrigName) not found
if( fossil_strcmp(zCheckin,"ckout")!=0 ){
@ in %z(href("%R/tree?ci=%T",zCheckin))%h(zCheckin)</a>
}
style_footer();
return;
}
/*
** The default logo.
*/
|
| ︙ | ︙ |