⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxssi.pas

📁 Well known and usefull component for delphi 7
💻 PAS
📖 第 1 页 / 共 2 页
字号:
              modification to our components!

              To make support easier for us, we ask that you use the Add*Event
              procedures to expand our code, reducing code changes when an
              upgrade is released!

              See documentation for complete information on how this works.

              Example Usage: AddExecEvent('CDROM',MySpecialEvent);
******************************************************************************)

procedure TDXSSI.AddExecEvent(Command:string; EventProc:SSITExecEvent);
var
   PExecEvent:PSSIExecEvent;
   Loop:Integer;

begin
   Command:=Uppercase(Command);
   Loop:=0;
   while Loop<fEventArray.Count do begin
      if PSSIExecEvent(fEventArray[Loop]).Command=Command then begin
         PSSIExecEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      end
      else
         Inc(Loop);
   end;
   New(PExecEvent);
   PExecEvent.Tag:=3;
   PExecEvent.Command:=Command;
   PExecEvent.EventProcedure:=EventProc;
   fEventArray.Add(PExecEvent);
end;

(******************************************************************************
ADDINCLUDEEVENT:
              Allows you to dynamically assign a new command to the internal
              parser. This allows the servercore to support the 'pre-defined'
              OnCommand* events, plus you can add other commands dynamically
              at run-time in your application without requiring a source code
              modification to our components!

              To make support easier for us, we ask that you use the Add*Event
              procedures to expand our code, reducing code changes when an
              upgrade is released!

              See documentation for complete information on how this works.

              Example Usage: AddIncludeEvent('CDROM',MySpecialEvent);
******************************************************************************)

procedure TDXSSI.AddIncludeEvent(Command:string; EventProc:SSITIncludeEvent);
var
   PIncludeEvent:PSSIIncludeEvent;
   Loop:Integer;

begin
   Command:=Uppercase(Command);
   Loop:=0;
   while Loop<fEventArray.Count do begin
      if PSSIIncludeEvent(fEventArray[Loop]).Command=Command then begin
         PSSIIncludeEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      end
      else
         Inc(Loop);
   end;
   New(PIncludeEvent);
   PIncludeEvent.Tag:=4;
   PIncludeEvent.Command:=Command;
   PIncludeEvent.EventProcedure:=EventProc;
   fEventArray.Add(PIncludeEvent);
end;

procedure TDXSSI.SetOnEmbeddedEnableEXEC(value:SSITChangeSettingEvent);
begin
   fOnEmbeddedEnabledEXEC:=Value;
   AddChangeSettingEvent('ALLOWEXECUTE', Value);
end;

procedure TDXSSI.SetOnEmbeddedDisableEXEC(value:SSITChangeSettingEvent);
begin
   fOnEmbeddedDisableEXEC:=Value;
   AddChangeSettingEvent('DISALLOWEXECUTE', Value);
end;

procedure TDXSSI.SetOnEmbeddedPageCounter(value:SSITStringEvent);
begin
   fOnEmbeddedPageCounter:=Value;
   AddStringEvent('HITCOUNT', Value);
   AddStringEvent('PAGECOUNT', Value);
end;

procedure TDXSSI.SetOnEmbeddedSiteCounter(value:SSITStringEvent);
begin
   fOnEmbeddedSiteCounter:=Value;
   AddStringEvent('SITECOUNT', Value);
end;

procedure TDXSSI.SetOnEmbeddedSiteBytesServed(value:SSITStringEvent);
begin
   fOnEmbeddedSiteBytesServed:=Value;
   AddStringEvent('BYTES_SERVED', Value);
end;

procedure TDXSSI.SetOnEmbeddedServerBytesServed(value:SSITStringEvent);
begin
   fOnEmbeddedServerBytesServed:=Value;
   AddStringEvent('TOTAL_BYTES_SERVED', Value);
end;

procedure TDXSSI.SetOnEmbeddedFileLastModified(value:SSITStringEvent);
begin
   fOnEmbeddedFileLastModified:=Value;
   AddStringEvent('FLASTMOD', Value);
end;

procedure TDXSSI.SetOnEmbeddedFileSize(value:SSITStringEvent);
begin
   fOnEmbeddedFileSize:=Value;
   AddStringEvent('FSIZE', Value);
end;

procedure TDXSSI.SetOnCommandECHO(value:SSITEchoEvent);
begin
   fOnCommandEcho:=Value;
   AddEchoEvent('ECHO', Value);
end;

procedure TDXSSI.SetOnCommandEXEC(value:SSITExecEvent);
begin
   fOnCommandExec:=Value;
   AddExecEvent('EXEC', Value);
end;

procedure TDXSSI.SetOnCommandINCLUDE(value:SSITIncludeEvent);
begin
   fOnCommandInclude:=Value;
   AddIncludeEvent('INCLUDE', Value);
end;

procedure TDXSSI.SetOnCommandCONFIG(value:SSITChangeSettingEvent);
begin
   fOnCommandConfig:=Value;
   AddChangeSettingEvent('CONFIG', Value);
end;

function TDXSSI.GetCurrentLine:Integer;
begin
   Result:=fIntLoop;
end;

procedure TDXSSI.SetCurrentLine(value:integer);
begin
   fIntLoop:=Value;
end;

function TDXSSI.PreviewCurrentLine:string;
begin
   Result:=fsCurrentLine;
end;

function TDXSSI.ProcessStream(const UniqueID:Cardinal; Stream:TStream):Boolean;
var
   Strlist:TStringList;

begin
   Result:=False;
   if not Assigned(Stream) then Exit;
   Stream.Position:=0;
   StrList:=TStringList.Create;
   try
      StrList.LoadFromStream(Stream);
      Stream.Size:=0;
      fIntLoop:=0;
      while fIntLoop<StrList.Count do begin
         fsCurrentLine:=StrList[fIntLoop];
         if Assigned(fOnNewLine) then fOnNewLine(UniqueID);
         if QuickPos(SSIStart, StrList[fIntLoop])>0 then
            StrList[fIntLoop]:=ProcessLine(UniqueID, StrList[fIntLoop]);
         fsCurrentLine:=StrList[fIntLoop];
         if Assigned(fOnLineDone) then fOnLineDone(UniqueID);
         Inc(fIntLoop);
      end;
      Stream.Position:=0;
      StrList.SaveToStream(Stream);
   finally
      StrList.Free;
   end;
   Stream.Position:=0;
   Result:=True;
end;

function TDXSSI.ProcessLine(const UniqueID:Cardinal; const S:string):string;
var
   BeforeSSI, AfterSSI:string;
   SSICommand:string;
   SSILine:string;

   {$HINTS OFF}

   function ServerSideInclude(sCmd, ExtraStuff:string):string;
   var
      Loop:Integer;
      WasHandled:Boolean;
      Answer:string;
      MemoryStream:TStream;
      MemoryString:TStringList;
      SubLoop:Integer;

   begin
      Result:='';
      Loop:=0;
      WasHandled:=False;
      while (Loop<fEventArray.Count)and(not WasHandled) do begin
         if PSSIStringEvent(fEventArray[Loop]).Command=sCMD then begin
            Answer:='';
            case PSSIStringEvent(fEventArray[Loop]).Tag of
               1:
                  if Assigned(PSSIStringEvent(fEventArray[Loop]).EventProcedure)
                     then
                     SSITStringEvent(PSSIStringEvent(fEventArray[Loop]).EventProcedure)(UniqueID, Answer);
               2:
                  if Assigned(PSSIEchoEvent(fEventArray[Loop]).EventProcedure)
                     then
                     SSITEchoEvent(PSSIEchoEvent(fEventArray[Loop]).EventProcedure)(UniqueID, ExtraStuff, Answer);
               3:begin
                     MemoryStream:=TMemoryStream.Create;
                     MemoryString:=TStringList.Create;
                     if Assigned(PSSIExecEvent(fEventArray[Loop]).EventProcedure)
                        then
                        SSITExecEvent(PSSIExecEvent(fEventArray[Loop]).EventProcedure)(UniqueID, ExtraStuff, MemoryStream);
                     MemoryString.LoadFromStream(MemoryStream);
                     MemoryStream.Free;
                     MemoryStream:=nil;
                     SubLoop:=0;
                     while SubLoop<MemoryString.Count do begin
                        Answer:=Answer+MemoryString[SubLoop]+#13#10;
                        Inc(SubLoop);
                     end;
                     MemoryString.Free;
                     MemoryString:=nil;
                  end;
               4:begin
                     MemoryStream:=TMemoryStream.Create;
                     MemoryString:=TStringList.Create;
                     if
                        Assigned(PSSIIncludeEvent(fEventArray[Loop]).EventProcedure) then
                        SSITIncludeEvent(PSSIIncludeEvent(fEventArray[Loop]).
                           EventProcedure)(UniqueID, ExtraStuff, MemoryStream);
                     MemoryString.LoadFromStream(MemoryStream);
                     MemoryStream.Free;
                     MemoryStream:=nil;
                     while MemoryString.Count>0 do begin
                        Answer:=Answer+MemoryString[0]+#13#10;
                        MemoryString.Delete(0);
                     end;
                     MemoryString.Free;
                     MemoryString:=nil;
                  end;
               5:
                  if
                     Assigned(PSSIChangeSettingEvent(fEventArray[Loop]).EventProcedure) then
                     SSITChangeSettingEvent(PSSIChangeSettingEvent(fEventArray[Loop]).EventProcedure)(UniqueID, ExtraStuff);
            end;
            WasHandled:=True;
         end
         else
            Inc(Loop);
      end;
      if not WasHandled then begin
         Answer:='';
         if assigned(OnCommandOther) then
            OnCommandOther(UniqueID, sCmd, Answer, WasHandled);
      end;
      Result:=Answer;
   end;
   {$HINTS ON}

   function SSICodes(Str:string):Integer;
   begin
      Result:=0;
      while QuickPos(SSIStart, Str)>0 do begin
         Inc(Result);
         Delete(Str, 1, QuickPos(SSIStart, Str)+Length(SSIStart));
      end;
   end;

begin
   SSILine:=S;
   while SSICodes(SSILine)>0 do begin
      BEFORESSI:=Copy(SSILine, 1, QuickPos(SSIStart, SSILine)-1);
      Delete(SSILine, 1, Length(BEFORESSI)+Length(SSIStart));
      AFTERSSI:=Copy(SSILine, QuickPos(SSIEnd, SSILine)+Length(SSIEnd),
         Length(SSILine));
      Delete(SSILine, QuickPos(SSIEnd, SSILine), Length(SSILine));
      while QuickPos(SSIStart, SSILine)>0 do begin
         BEFORESSI:=BEFORESSI+SSIStart+Copy(SSILine, 1, QuickPos(SSIStart,
            SSILine)-1);
         Delete(SSILine, 1, Length(BEFORESSI)+Length(SSIStart));
      end;
      SSICommand:=Fetch(SSILine, #32, False);
      SSILine:=BEFORESSI+ServerSideInclude(Uppercase(SSICommand),
         SSILine)+AFTERSSI;
   end;
   Result:=SSILine;
end;

procedure TDXSSI.GetSSIToken(SSI:string; WhichOne:Integer; var Token,
   Value:string);
var
   Loop:Integer;

begin
   Token:='';
   Value:='';
   Delete(SSI, 1, QuickPos(#32, SSI));
   while Copy(SSI, 1, 1)=#32 do
      Delete(SSI, 1, 1);
   SSI:=Copy(SSI, 1, QuickPos(SSIEnd, SSI)-1);
   Loop:=0;
   while Loop<WhichOne do begin
      Token:=Uppercase(Copy(SSI, 1, QuickPos('=', SSI)-1));
      if Token='' then Token:=SSI;
      Delete(SSI, 1, Length(Token)+1);
      Trim(SSI);
      Trim(Token);
      Value:=SSI;
      if Copy(Value, 1, 1)='"' then begin
         Delete(Value, 1, 1);
         Delete(Value, QuickPos('"', Value), Length(Value));
         Delete(SSI, 1, 1);
         Delete(SSI, 1, QuickPos('"', SSI));
      end
      else begin
         Value:=Fetch(SSI, #32, False);
      end;
      Inc(Loop);
   end;
end;

procedure TDXSSI.SetTimeFormat(value:string);
begin
   fDateFormat:=Value;
end;

procedure TDXSSI.SetSizeFormat(value:string);
begin
   if Uppercase(Copy(Value, 1, 1))='B' then
      fSizeFormat:='bytes'
   else
      fSizeFormat:='abbrev';
end;

function TDXSSI.FormattedSize(Size:Integer):string;
begin
   if fSizeFormat='bytes' then
      Result:=IntToCommaStr(Size)
   else begin
      if Size>1024 then begin
         Size:=Size div 1024;
         if Size>=1000 then begin
            Size:=Size div 1000;
            if Size>=1000 then begin
               Size:=Size div 1000;
               if Size>=1000 then begin
                  Result:=IntToCommaStr(Size)+'tb';
               end
               else
                  Result:=IntegerToString(Size)+'gb';
            end
            else
               Result:=IntegerToString(Size)+'mb';
         end
         else
            Result:=IntegerToString(Size)+'kb';
      end
      else
         Result:=IntToCommaStr(Size);
   end;
end;

function TDXSSI.FormattedTime(DateTime:TDateTime):string;
begin
   Result:=DateTimeToStr(DateTime);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -