| ︙ | | | ︙ | |
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
};
if( !looks_like_binary(pBlob) ) {
return 0; /* Plain text */
}
x = (const unsigned char*)blob_buffer(pBlob);
n = blob_size(pBlob);
for(i=0; i<ArraySize(aMime); i++){
if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){
return aMime[i].zMimetype;
}
}
return "unknown/unknown";
}
|
|
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
};
if( !looks_like_binary(pBlob) ) {
return 0; /* Plain text */
}
x = (const unsigned char*)blob_buffer(pBlob);
n = blob_size(pBlob);
for(i=0; i<count(aMime); i++){
if( n>=aMime[i].size && memcmp(x, aMime[i].zPrefix, aMime[i].size)==0 ){
return aMime[i].zMimetype;
}
}
return "unknown/unknown";
}
|
| ︙ | | | ︙ | |
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/*
** Verify that all entries in the aMime[] table are in sorted order.
** Abort with a fatal error if any is out-of-order.
*/
static void mimetype_verify(void){
int i;
for(i=1; i<ArraySize(aMime); i++){
if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){
fossil_fatal("mimetypes out of sequence: %s before %s",
aMime[i-1].zSuffix, aMime[i].zSuffix);
}
}
}
|
|
|
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/*
** Verify that all entries in the aMime[] table are in sorted order.
** Abort with a fatal error if any is out-of-order.
*/
static void mimetype_verify(void){
int i;
for(i=1; i<count(aMime); i++){
if( fossil_strcmp(aMime[i-1].zSuffix,aMime[i].zSuffix)>=0 ){
fossil_fatal("mimetypes out of sequence: %s before %s",
aMime[i-1].zSuffix, aMime[i].zSuffix);
}
}
}
|
| ︙ | | | ︙ | |
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
if( zName[i]=='.' ) z = &zName[i+1];
}
len = strlen(z);
if( len<sizeof(zSuffix)-1 ){
sqlite3_snprintf(sizeof(zSuffix), zSuffix, "%s", z);
for(i=0; zSuffix[i]; i++) zSuffix[i] = fossil_tolower(zSuffix[i]);
first = 0;
last = ArraySize(aMime) - 1;
while( first<=last ){
int c;
i = (first+last)/2;
c = fossil_strcmp(zSuffix, aMime[i].zSuffix);
if( c==0 ) return aMime[i].zMimetype;
if( c<0 ){
last = i-1;
|
|
|
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
|
if( zName[i]=='.' ) z = &zName[i+1];
}
len = strlen(z);
if( len<sizeof(zSuffix)-1 ){
sqlite3_snprintf(sizeof(zSuffix), zSuffix, "%s", z);
for(i=0; zSuffix[i]; i++) zSuffix[i] = fossil_tolower(zSuffix[i]);
first = 0;
last = count(aMime) - 1;
while( first<=last ){
int c;
i = (first+last)/2;
c = fossil_strcmp(zSuffix, aMime[i].zSuffix);
if( c==0 ) return aMime[i].zMimetype;
if( c<0 ){
last = i-1;
|
| ︙ | | | ︙ | |
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
@ suffixes and the following table to guess at the appropriate mimetype
@ for each document.</p>
@ <table id='mimeTable' border=1 cellpadding=0 class='mimetypetable'>
@ <thead>
@ <tr><th>Suffix<th>Mimetype
@ </thead>
@ <tbody>
for(i=0; i<ArraySize(aMime); i++){
@ <tr><td>%h(aMime[i].zSuffix)<td>%h(aMime[i].zMimetype)</tr>
}
@ </tbody></table>
output_table_sorting_javascript("mimeTable","tt",1);
style_footer();
}
|
|
|
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
|
@ suffixes and the following table to guess at the appropriate mimetype
@ for each document.</p>
@ <table id='mimeTable' border=1 cellpadding=0 class='mimetypetable'>
@ <thead>
@ <tr><th>Suffix<th>Mimetype
@ </thead>
@ <tbody>
for(i=0; i<count(aMime); i++){
@ <tr><td>%h(aMime[i].zSuffix)<td>%h(aMime[i].zMimetype)</tr>
}
@ </tbody></table>
output_table_sorting_javascript("mimeTable","tt",1);
style_footer();
}
|
| ︙ | | | ︙ | |
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
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
|
};
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)<=ArraySize(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==ArraySize(azSuffix) ){
zName = "404.md";
}else if( zName[i]==0 ){
assert( nMiss>=0 && nMiss<ArraySize(azSuffix) );
zName = azSuffix[nMiss];
}else if( !isUV ){
zName += i;
}
while( zName[0]=='/' ){ zName++; }
if( isUV ){
g.zPath = mprintf("%s/%s", g.zPath, zName);
}else{
g.zPath = mprintf("%s/%s/%s", g.zPath, zCheckin, zName);
}
if( nMiss==0 ) zOrigName = zName;
if( !file_is_simple_pathname(zName, 1) ){
if( sqlite3_strglob("*/", zName)==0 ){
assert( nMiss>=0 && nMiss<ArraySize(azSuffix) );
zName = mprintf("%s%s", zName, azSuffix[nMiss]);
if( !file_is_simple_pathname(zName, 1) ){
goto doc_not_found;
}
}else{
goto doc_not_found;
}
|
|
|
|
|
|
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
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
|
};
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";
}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 ){
g.zPath = mprintf("%s/%s", g.zPath, zName);
}else{
g.zPath = mprintf("%s/%s/%s", g.zPath, 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;
}
|
| ︙ | | | ︙ | |
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
style_footer();
}else if( fossil_strcmp(zMime, "text/x-markdown")==0 ){
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>=ArraySize(azSuffix)?
"Not Found" : zDfltTitle);
}
convert_href_and_output(&tail);
style_footer();
}else if( fossil_strcmp(zMime, "text/plain")==0 ){
style_header("%s", zDfltTitle);
@ <blockquote><pre>
|
|
|
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
|
style_footer();
}else if( fossil_strcmp(zMime, "text/x-markdown")==0 ){
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>=count(azSuffix)?
"Not Found" : zDfltTitle);
}
convert_href_and_output(&tail);
style_footer();
}else if( fossil_strcmp(zMime, "text/plain")==0 ){
style_header("%s", zDfltTitle);
@ <blockquote><pre>
|
| ︙ | | | ︙ | |
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
|
style_footer();
}
#endif
}else{
cgi_set_content_type(zMime);
cgi_set_content(&filebody);
}
if( nMiss>=ArraySize(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 ){
|
|
|
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
|
style_footer();
}
#endif
}else{
cgi_set_content_type(zMime);
cgi_set_content(&filebody);
}
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 ){
|
| ︙ | | | ︙ | |