Skip to content

Commit b028c47

Browse files
committed
added 'no log' section flag to support SAP themes like 'mobil-light'
1 parent 782702c commit b028c47

File tree

2 files changed

+98
-80
lines changed

2 files changed

+98
-80
lines changed

classesLib.pas

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ TstringToIntHash = class(ThashedStringList)
139139
PtplSection = ^TtplSection;
140140
TtplSection = record
141141
name, txt: string;
142-
nolog, nourl, cache: boolean;
142+
nolog, nourl, noList, cache: boolean;
143143
ts: Tdatetime;
144144
end;
145145

@@ -1023,9 +1023,10 @@ procedure Ttpl.appendString(txt:string);
10231023
// there may be flags after |
10241024
s:=cur_section;
10251025
cur_section:=chop('|', s);
1026-
base.nolog:=ansiPos('no log', s) > 0;
1027-
base.nourl:=ansiPos('private', s) > 0;
1028-
base.cache:=ansiPos('cache', s) > 0;
1026+
base.nolog:=containsStr('no log', s);
1027+
base.nourl:=containsStr('private', s);
1028+
base.noList:=containsStr('no list', s);
1029+
base.cache:=containsStr('cache', s);
10291030
base.ts:=now();
10301031

10311032
s:=cur_section;

main.pas

Lines changed: 93 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
Copyright (C) 2002-2014 Massimo Melina (www.rejetto.com)
33
44
This file is part of HFS ~ HTTP File Server.
@@ -36,8 +36,8 @@ interface
3636
HSlib, traylib, monoLib, progFrmLib, classesLib;
3737

3838
const
39-
VERSION = '2.4.0 RC1';
40-
VERSION_BUILD = '313';
39+
VERSION = '2.4.0 RC2';
40+
VERSION_BUILD = '314';
4141
VERSION_STABLE = {$IFDEF STABLE } TRUE {$ELSE} FALSE {$ENDIF};
4242
CURRENT_VFS_FORMAT :integer = 1;
4343
CRLF = #13#10;
@@ -3645,16 +3645,12 @@ function Tmainfrm.getFolderPage(folder:Tfile; cd:TconnData; otpl:Tobject):string
36453645
var
36463646
i, n: integer;
36473647
f: Tfile;
3648+
useList: boolean;
3649+
mainSection: PtplSection;
36483650
begin
36493651
result:='';
36503652
if (folder = NIL) or not folder.isFolder() then exit;
36513653

3652-
if not available() then
3653-
begin
3654-
cd.conn.reply.mode:=HRM_OVERLOAD;
3655-
cd.conn.addHeader('Refresh: '+intToStr(1+random(2))); // random for less collisions
3656-
exit('Please wait, server busy');
3657-
end;
36583654
if macrosLogChk.checked and not appendmacroslog1.checked then
36593655
resetLog();
36603656
diffTpl:=Ttpl.create();
@@ -3676,6 +3672,18 @@ function Tmainfrm.getFolderPage(folder:Tfile; cd:TconnData; otpl:Tobject):string
36763672
if otpl <> filelistTpl then
36773673
diffTpl.fullText:=folder.getRecursiveDiffTplAsStr();
36783674

3675+
mainSection:=diffTpl.getSection('');
3676+
if mainSection = NIL then
3677+
exit;
3678+
useList:=not mainSection.noList;
3679+
3680+
if useList and not available() then
3681+
begin
3682+
cd.conn.reply.mode:=HRM_OVERLOAD;
3683+
cd.conn.addHeader('Refresh: '+intToStr(1+random(2))); // random for less collisions
3684+
exit('Please wait, server busy');
3685+
end;
3686+
36793687
fullEncode:=FALSE;
36803688
ofsRelUrl:=length(folder.url(fullEncode))+1;
36813689
ofsRelItemUrl:=length(folder.pathTill())+1;
@@ -3693,81 +3701,88 @@ function Tmainfrm.getFolderPage(folder:Tfile; cd:TconnData; otpl:Tobject):string
36933701
result:=diffTpl['special:begin'];
36943702
tryApplyMacrosAndSymbols(result, md, FALSE);
36953703

3696-
// cache these values
3697-
fileTpl:=xtpl(diffTpl['file'], table);
3698-
folderTpl:=xtpl(diffTpl['folder'], table);
3699-
linkTpl:=xtpl(diffTpl['link'], table);
3700-
// this may be heavy to calculate, only do it upon request
3701-
img_file:=pos('~img_file', fileTpl) > 0;
3702-
3703-
// build %list% based on dir[]
3704-
numberFolders:=0; numberFiles:=0; numberLinks:=0;
3705-
totalBytes:=0;
3706-
oneAccessible:=FALSE;
3707-
fast:=TfastStringAppend.Create();
3708-
listing:=TfileListing.create();
3709-
hasher:=Thasher.create();
3710-
if fingerprintsChk.checked then
3711-
hasher.loadFrom(folder.resource);
3712-
try
3713-
listing.fromFolder( folder, cd, recur );
3714-
listing.sort(cd, if_(recur or (otpl = filelistTpl), '?', diffTpl['sort by']) ); // '?' is just a way to cause the sort to fail in case the sort key is not defined by the connection
3704+
if useList then
3705+
begin
3706+
// cache these values
3707+
fileTpl:=xtpl(diffTpl['file'], table);
3708+
folderTpl:=xtpl(diffTpl['folder'], table);
3709+
linkTpl:=xtpl(diffTpl['link'], table);
3710+
// this may be heavy to calculate, only do it upon request
3711+
img_file:=pos('~img_file', fileTpl) > 0;
37153712

3716-
n:=length(listing.dir);
3717-
for i:=0 to n-1 do
3718-
begin
3719-
f:=listing.dir[i];
3720-
if f.size > 0 then
3721-
inc(totalBytes, f.size);
3722-
if f.isLink() then
3723-
inc(numberLinks)
3724-
else if f.isFolder() then
3725-
inc(numberFolders)
3726-
else
3727-
inc(numberFiles);
3728-
end;
3729-
{TODO this symbols will be available when executing macros in handleItem. Having
3730-
them at this stage is useful only in case immediate calculations are required.
3731-
This may happen seldom, but maybe some template is using it since we got this here.
3732-
Each symbols is an extra iteration on the template piece and we may be tempted
3733-
to consider for optimizations. To not risk legacy problems we should consider
3734-
treating table symbols with a regular expression and a Tdictionary instead.
3735-
}
3736-
table:=toSA([
3737-
'%upload-link%', if_(accountAllowed(FA_UPLOAD, cd, folder), diffTpl['upload-link']),
3738-
'%files%', diffTpl[if_(n>0, 'files','nofiles')],
3739-
'%number%', intToStr(n),
3740-
'%number-files%', intToStr(numberFiles),
3741-
'%number-folders%', intToStr(numberFolders),
3742-
'%number-links%', intToStr(numberlinks),
3743-
'%total-bytes%', intToStr(totalBytes),
3744-
'%total-kbytes%', intToStr(totalBytes div KILO),
3745-
'%total-size%', smartsize(totalBytes)
3746-
]);
3713+
// build %list% based on dir[]
3714+
numberFolders:=0; numberFiles:=0; numberLinks:=0;
3715+
totalBytes:=0;
3716+
oneAccessible:=FALSE;
3717+
fast:=TfastStringAppend.Create();
3718+
listing:=TfileListing.create();
3719+
hasher:=Thasher.create();
3720+
if fingerprintsChk.checked then
3721+
hasher.loadFrom(folder.resource);
3722+
try
3723+
listing.fromFolder( folder, cd, recur );
3724+
listing.sort(cd, if_(recur or (otpl = filelistTpl), '?', diffTpl['sort by']) ); // '?' is just a way to cause the sort to fail in case the sort key is not defined by the connection
37473725

3748-
for i:=0 to length(listing.dir)-1 do
3749-
begin
3750-
application.ProcessMessages();
3751-
if cd.conn.state = HCS_DISCONNECTED then exit;
3752-
cd.lastActivityTime:=now();
3753-
handleItem(listing.dir[i])
3726+
n:=length(listing.dir);
3727+
for i:=0 to n-1 do
3728+
begin
3729+
f:=listing.dir[i];
3730+
if f.size > 0 then
3731+
inc(totalBytes, f.size);
3732+
if f.isLink() then
3733+
inc(numberLinks)
3734+
else if f.isFolder() then
3735+
inc(numberFolders)
3736+
else
3737+
inc(numberFiles);
3738+
end;
3739+
{TODO these symbols will be available when executing macros in handleItem. Having
3740+
them at this stage is useful only in case immediate calculations are required.
3741+
This may happen seldom, but maybe some template is using it since we got this here.
3742+
Each symbols is an extra iteration on the template piece and we may be tempted
3743+
to consider for optimizations. To not risk legacy problems we should consider
3744+
treating table symbols with a regular expression and a Tdictionary instead.
3745+
}
3746+
table:=toSA([
3747+
'%upload-link%', if_(accountAllowed(FA_UPLOAD, cd, folder), diffTpl['upload-link']),
3748+
'%files%', diffTpl[if_(n>0, 'files','nofiles')],
3749+
'%number%', intToStr(n),
3750+
'%number-files%', intToStr(numberFiles),
3751+
'%number-folders%', intToStr(numberFolders),
3752+
'%number-links%', intToStr(numberlinks),
3753+
'%total-bytes%', intToStr(totalBytes),
3754+
'%total-kbytes%', intToStr(totalBytes div KILO),
3755+
'%total-size%', smartsize(totalBytes)
3756+
]);
3757+
3758+
for i:=0 to length(listing.dir)-1 do
3759+
begin
3760+
application.ProcessMessages();
3761+
if cd.conn.state = HCS_DISCONNECTED then exit;
3762+
cd.lastActivityTime:=now();
3763+
handleItem(listing.dir[i])
3764+
end;
3765+
list:=fast.reset();
3766+
finally
3767+
listing.free;
3768+
fast.free;
3769+
hasher.free;
37543770
end;
3755-
list:=fast.reset();
3756-
finally
3757-
listing.free;
3758-
fast.free;
3759-
hasher.free;
3760-
end;
37613771

3762-
if cd.conn.state = HCS_DISCONNECTED then exit;
3772+
if cd.conn.state = HCS_DISCONNECTED then exit;
3773+
3774+
// build final page
3775+
if not oneAccessible then
3776+
md.archiveAvailable:=FALSE;
3777+
end
3778+
else
3779+
list:='';
37633780

3764-
// build final page
3765-
if not oneAccessible then md.archiveAvailable:=FALSE;
37663781
md.table:=table;
37673782
addArray(md.table, [
37683783
'%list%',list
37693784
]);
3770-
result:=diffTpl[''];
3785+
result:=mainSection.txt;
37713786
md.f:=NIL;
37723787
md.afterTheList:=TRUE;
37733788
try tryApplyMacrosAndSymbols(result, md)
@@ -3777,7 +3792,8 @@ function Tmainfrm.getFolderPage(folder:Tfile; cd:TconnData; otpl:Tobject):string
37773792
result:=replaceText(result, '%build-time%',
37783793
floatToStrF((now()-buildTime)*SECONDS, ffFixed, 7,3) );
37793794
finally
3780-
updateAvailability();
3795+
if useList then
3796+
updateAvailability();
37813797
folder.unlock();
37823798
diffTpl.free;
37833799
end;
@@ -4987,6 +5003,7 @@ procedure Tmainfrm.httpEvent(event:ThttpEvent; conn:ThttpConn);
49875003
data.session:=sessions[sid];
49885004
if data.session.ip <> conn.address then
49895005
begin
5006+
conn.delCookie(SESSION_COOKIE); // legitimate clients that changed address must clear their cookie, or they will be stuck with this invalid session
49905007
conn.reply.mode:=HRM_DENY;
49915008
result:=FALSE;
49925009
exit;

0 commit comments

Comments
 (0)