610
611
612
613
614
615
616
617
618
619
620
621
622
623
|
#endif
}else{
cgi_set_content_type(zMime);
cgi_set_content(pBody);
}
}
/*
** WEBPAGE: uv
** WEBPAGE: doc
** URL: /uv/FILE
** URL: /doc/CHECKIN/FILE
**
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
|
#endif
}else{
cgi_set_content_type(zMime);
cgi_set_content(pBody);
}
}
/*
** Returns a list of possible index page names, in the order of their
** priority, and writes the number of entries in the list to *pCount
** (which must not be NULL). The returned memory is static but the
** number of entries depends on compile-time options.
*/
const char * const * document_index_list( int * pCount ){
static const char *const azSuffix[] = {
"index.html", "index.wiki", "index.md"
#ifdef FOSSIL_ENABLE_TH1_DOCS
, "index.th1"
#endif
};
*pCount = (int)count(azSuffix);
return azSuffix;
}
/*
** If the given NUL-terminated directory name contains one of the
** index files defined by document_index_list(), the path to that file
** is returned in the form zDirName/FILE_NAME, else NULL is
** returned. Ownership of the returned memory is transfered to the
** caller.
**
** If pNResult is not NULL and non-NULL is returned, the length of the
** returned string is written to *pNResult, otherwise pNResult is not
** dereferenced.
*/
char * document_dir_has_index(const char * zDirName, int * pNResult){
Blob bName = BLOB_INITIALIZER; /* File path */
int i; /* Loop counter */
int nIndex; /* Number of index entries. */
const char * const * azIndex = document_index_list(&nIndex);
unsigned int nDirName = strlen(zDirName)
/* Cursor for the end of the initial
path+separator part of bName */;
blob_appendf( &bName, "%s%s", zDirName,
zDirName[nDirName-1]=='/' ? "" : "/" );
nDirName = bName.nUsed;
for(i=0; i<nIndex; ++i){
bName.nUsed = nDirName;
blob_append(&bName, azIndex[i], strlen(azIndex[i]));
if(file_isfile(bName.aData, ExtFILE)!=0){
break;
}
}
if(i<nIndex){
if(pNResult) *pNResult = (int)bName.nUsed;
return bName.aData;
}else{
blob_reset(&bName);
return 0;
}
}
/*
** WEBPAGE: uv
** WEBPAGE: doc
** URL: /uv/FILE
** URL: /doc/CHECKIN/FILE
**
|
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
|
int rid = 0; /* Artifact of file */
int i; /* Loop counter */
Blob filebody; /* Content of the documentation file */
Blob title; /* Document title */
int nMiss = (-1); /* Failed attempts to find the document */
int isUV = g.zPath[0]=='u'; /* True for /uv. False for /doc */
const char *zDfltTitle;
static const char *const azSuffix[] = {
"index.html", "index.wiki", "index.md"
#ifdef FOSSIL_ENABLE_TH1_DOCS
, "index.th1"
#endif
};
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
blob_init(&title, 0, 0);
zDfltTitle = isUV ? "" : "Documentation";
db_begin_transaction();
while( rid==0 && (++nMiss)<=count(azSuffix) ){
zName = P("name");
if( isUV ){
if( zName==0 ) zName = "index.wiki";
i = 0;
}else{
if( zName==0 || zName[0]==0 ) zName = "tip/index.wiki";
for(i=0; zName[i] && zName[i]!='/'; i++){}
zCheckin = mprintf("%.*s", i, zName);
if( fossil_strcmp(zCheckin,"ckout")==0 && g.localOpen==0 ){
zCheckin = "tip";
}
}
if( nMiss==count(azSuffix) ){
zName = "404.md";
zDfltTitle = "Not Found";
}else if( zName[i]==0 ){
assert( nMiss>=0 && nMiss<count(azSuffix) );
zName = azSuffix[nMiss];
}else if( !isUV ){
zName += i;
}
while( zName[0]=='/' ){ zName++; }
if( isUV ){
zPathSuffix = fossil_strdup(zName);
}else{
zPathSuffix = mprintf("%s/%s", zCheckin, zName);
}
if( nMiss==0 ) zOrigName = zName;
if( !file_is_simple_pathname(zName, 1) ){
if( sqlite3_strglob("*/", zName)==0 ){
assert( nMiss>=0 && nMiss<count(azSuffix) );
zName = mprintf("%s%s", zName, azSuffix[nMiss]);
if( !file_is_simple_pathname(zName, 1) ){
goto doc_not_found;
}
}else{
goto doc_not_found;
}
|
>
|
<
<
<
<
<
|
|
|
|
|
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
int rid = 0; /* Artifact of file */
int i; /* Loop counter */
Blob filebody; /* Content of the documentation file */
Blob title; /* Document title */
int nMiss = (-1); /* Failed attempts to find the document */
int isUV = g.zPath[0]=='u'; /* True for /uv. False for /doc */
const char *zDfltTitle;
int nSuffix; /* Number of entries in azSuffix */
const char *const * azSuffix = document_index_list(&nSuffix);
login_check_credentials();
if( !g.perm.Read ){ login_needed(g.anon.Read); return; }
blob_init(&title, 0, 0);
zDfltTitle = isUV ? "" : "Documentation";
db_begin_transaction();
while( rid==0 && (++nMiss)<=nSuffix ){
zName = P("name");
if( isUV ){
if( zName==0 ) zName = "index.wiki";
i = 0;
}else{
if( zName==0 || zName[0]==0 ) zName = "tip/index.wiki";
for(i=0; zName[i] && zName[i]!='/'; i++){}
zCheckin = mprintf("%.*s", i, zName);
if( fossil_strcmp(zCheckin,"ckout")==0 && g.localOpen==0 ){
zCheckin = "tip";
}
}
if( nMiss==nSuffix ){
zName = "404.md";
zDfltTitle = "Not Found";
}else if( zName[i]==0 ){
assert( nMiss>=0 && nMiss<nSuffix );
zName = azSuffix[nMiss];
}else if( !isUV ){
zName += i;
}
while( zName[0]=='/' ){ zName++; }
if( isUV ){
zPathSuffix = fossil_strdup(zName);
}else{
zPathSuffix = mprintf("%s/%s", zCheckin, zName);
}
if( nMiss==0 ) zOrigName = zName;
if( !file_is_simple_pathname(zName, 1) ){
if( sqlite3_strglob("*/", zName)==0 ){
assert( nMiss>=0 && nMiss<nSuffix );
zName = mprintf("%s%s", zName, azSuffix[nMiss]);
if( !file_is_simple_pathname(zName, 1) ){
goto doc_not_found;
}
}else{
goto doc_not_found;
}
|
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
if( vid ){
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"
" WHERE objid=%d AND type='ci'", vid));
}
document_render(&filebody, zMime, zDfltTitle, zName);
if( nMiss>=count(azSuffix) ) cgi_set_status(404, "Not Found");
db_end_transaction(0);
return;
/* Jump here when unable to locate the document */
doc_not_found:
db_end_transaction(0);
if( isUV && P("name")==0 ){
|
|
|
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
|
if( vid ){
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"
" WHERE objid=%d AND type='ci'", vid));
}
document_render(&filebody, zMime, zDfltTitle, zName);
if( nMiss>=nSuffix ) cgi_set_status(404, "Not Found");
db_end_transaction(0);
return;
/* Jump here when unable to locate the document */
doc_not_found:
db_end_transaction(0);
if( isUV && P("name")==0 ){
|