Smilly
asked on
Indy HTTPServer and isapi?
Hi there
I've made a HTTPServer with indy. Is there a way to run external isapi module, from this server?
If so, HOW?
Smilly
I've made a HTTPServer with indy. Is there a way to run external isapi module, from this server?
If so, HOW?
Smilly
ASKER
Hi AvonWyss
Thanks for a greate response to my question.
How do I use it? I tried this :
************************** ********** *****
procedure TForm1.IdHTTPServer1Comman dGet(AThre ad: TIdPeerThread;
RequestInfo: TIdHTTPRequestInfo; ResponseInfo: TIdHTTPResponseInfo);
var
req : TYourWebRequest;
MyIsapi: TISAPIExtension;
begin
MyIsapi := TISAPIExtension.Create('C: \Inetpub\S cripts\say hello.dll' );
req := TYourWebRequest.Create;
req.Method := RequestInfo.Command;
req.QueryString := RequestInfo.Params.Text;
req.PathInfo := RequestInfo.Host;
req.PathTranslated := 'D:\delphi\webserver\root' ;
req.ContentType := ResponseInfo.ContentType;
req.ContentSize := ResponseInfo.ContentLength ;
req.AvailableSize := 0;
req.AvailableData := nil;
MyIsapi.Invoke(req);
req.Free;
MyIsapi.Free;
end;
************************** ********** ********** *******
But it didn't work.
You wrote :
-->read
// copy data from the request in buffer to the ISAPI DLL
-->support
// execute the wanted support function
-->write
// copy data from the ISAPI DLL to the request out buffer
But how?
The only thing I want is to run a simple Isapi extension from within my server. The helloworld.dll writes "hello world" in the response context, nothing else.
Please help me a little more, and I increase the point.
Thanks for a greate response to my question.
How do I use it? I tried this :
**************************
procedure TForm1.IdHTTPServer1Comman
RequestInfo: TIdHTTPRequestInfo; ResponseInfo: TIdHTTPResponseInfo);
var
req : TYourWebRequest;
MyIsapi: TISAPIExtension;
begin
MyIsapi := TISAPIExtension.Create('C:
req := TYourWebRequest.Create;
req.Method := RequestInfo.Command;
req.QueryString := RequestInfo.Params.Text;
req.PathInfo := RequestInfo.Host;
req.PathTranslated := 'D:\delphi\webserver\root'
req.ContentType := ResponseInfo.ContentType;
req.ContentSize := ResponseInfo.ContentLength
req.AvailableSize := 0;
req.AvailableData := nil;
MyIsapi.Invoke(req);
req.Free;
MyIsapi.Free;
end;
**************************
But it didn't work.
You wrote :
-->read
// copy data from the request in buffer to the ISAPI DLL
-->support
// execute the wanted support function
-->write
// copy data from the ISAPI DLL to the request out buffer
But how?
The only thing I want is to run a simple Isapi extension from within my server. The helloworld.dll writes "hello world" in the response context, nothing else.
Please help me a little more, and I increase the point.
Hi, Smilly.
Perhaps you've overlooked these open questions, one quite old, the other without comments for which you may wish a refund.
For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20044308.html
https://www.experts-exchange.com/questions/Q.20144496.html
Thank you everyone.
Moondancer
Moderator @ Experts Exchange
Perhaps you've overlooked these open questions, one quite old, the other without comments for which you may wish a refund.
For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.20044308.html
https://www.experts-exchange.com/questions/Q.20144496.html
Thank you everyone.
Moondancer
Moderator @ Experts Exchange
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
And one more thing: Don't load and unload the DLL for each request! Load it (e.g. create the object) when starting your server application, use it and free it only when stopping the server. This will greaty enhance the response time of the server because the DLL does not need to be loaded and unloaded all the time!
In the file ISAPI.PAS (which ships with Delphi) you'll find all the needed ISAPI definitions. I have prepared a base class which will do the basic stuff for you, you only need to fill in the things specific to your self-made web server:
// uses Windows,ISAPI;
type
TYourWebRequest=class
Method, // GET, HEAD, POST, ...
QueryString, // the string behind the ? of the URI
PathInfo, // the string before the ? in the URI (without host name)
PathTranslated, // the physical path on the web server of that request
ContentType: string; // the content-type (from the Content-Type header)
ContentSize, // number of bytes indicated by client (in the Content-Length header)
AvailableSize: Integer;// number of bytes currently waiting to be read
AvailableData: Pointer;// pointer to the data (ReadAvailable bytes)
end;
TISAPIExtension=class;
TGetExtensionVersion=funct
THttpExtensionProc=functio
PCONN=^TCONN;
TCONN=record
Request: TYourWebRequest;
Extension: TISAPIExtension;
ECB: TEXTENSION_CONTROL_BLOCK;
end;
TISAPIExtension=class
private
FISAPIDLL: string;
FDLLHandle: THandle;
FExtensionVersion: THSE_VERSION_INFO;
FHttpExtensionProc: THttpExtensionProc;
protected
function GetServerVariable(Request:
function WriteClient(Request: TYourWebRequest; Buffer: Pointer; var Bytes: Integer; dwReserved: Integer): Boolean;
function ReadClient(Request: TYourWebRequest; Buffer: Pointer; var Size: Integer): Boolean;
function ServerSupportFunction(Requ
public
constructor Create(const ISAPIDLL: string);
procedure Invoke(Request: TYourWebRequest);
destructor Destroy; override;
end;
implementation
function GetServerVariableProc(Conn
var
Conn: PCONN absolute ConnID;
begin
Result:=Conn.Extension.Get
end;
function WriteClientProc(ConnID: HCONN; Buffer: Pointer; var Bytes: DWORD; dwReserved: DWORD): BOOL; stdcall;
var
Conn: PCONN absolute ConnID;
begin
Result:=Conn.Extension.Wri
end;
function ReadClientProc(ConnID: HCONN; Buffer: Pointer; var Size: DWORD): BOOL; stdcall;
var
Conn: PCONN absolute ConnID;
begin
Result:=Conn.Extension.Rea
end;
function ServerSupportFunctionProc(
var
Conn: PCONN absolute ConnID;
begin
Result:=Conn.Extension.Ser
end;
{ TISAPIExtension }
constructor TISAPIExtension.Create(con
var
GetVersion: TGetExtensionVersion;
begin
FDLLHandle:=LoadLibrary(PC
if FDLLHandle=null then
raise Exception.Create('Cannot load ISAPI DLL '+ISAPIDLL);
FISAPIDLL:=ISAPIDLL;
GetVersion:=TGetExtensionV
FHttpExtensionProc:=THttpE
GetVersion(FExtensionVersi
end;
destructor TISAPIExtension.Destroy;
begin
FreeLibrary(FDLLHandle);
inherited;
end;
function TISAPIExtension.GetServerV
begin
// read a server variable in this requests context here
end;
procedure TISAPIExtension.Invoke(Req
var
Connection: TCONN;
begin
Connection.Request:=Reques
Connection.Extension:=self
with Connection,ECB do begin
FillChar(ECB,SizeOf(ECB),0
cbSize:=SizeOf(ECB);
dwVersion:=HSE_VERSION_MAJ
ConnID:=Cardinal(@Connecti
lpszMethod:=PChar(Request.
lpszQueryString:=PChar(Req
lpszPathInfo:=PChar(Reques
lpszPathTranslated:=PChar(
cbTotalBytes:=Integer(Requ
cbAvailable:=Integer(Reque
lpbData:=Request.Available
lpszContentType:=PChar(Req
GetServerVariable:=GetServ
WriteClient:=WriteClientPr
ReadClient:=ReadClientProc
ServerSupportFunction:=Ser
end;
FHttpExtensionProc(Connect
end;
function TISAPIExtension.ReadClient
begin
// copy data from the request in buffer to the ISAPI DLL
end;
function TISAPIExtension.ServerSupp
begin
// execute the wanted support function
end;
function TISAPIExtension.WriteClien
begin
// copy data from the ISAPI DLL to the request out buffer
end;
For further reading on the callback functions and server variables, please read here:
http://msdn.microsoft.com/library/en-us/iisref/html/psdk/asp/isre0wit.asp