Thread: ISAPI modules - references or links

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    ISAPI modules - references or links

    Howdy,

    I'm currently working on a web server project, and I was hoping to look into using ISAPI modules. I've seen PHP ships with an ISAPI DLL, and I've been able to load it. My problem is, I don't know what functions my server is supposed to call/create/define/handle.

    I've been on MSDN, google searches, forum searches, but all I've found has been for creating extensions and clients, but not for servers that actually use the extensions. I know its possible, because Apache does it, and I even downloaded the Apache source to see how its done, but the code is shockingly hard to read (for me anyway).

    So what I'm asking is, could anyone provide me with a link or two on how to create the server interface for ISAPI, or provide me with some sample code? I would really appreciate it.

    ~ Paul

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    C'mon guys, someone must know something about this. I'm sorry for bumping this up but its really important to me. Even a link to the source code of a server that implements ISAPI would be enough (apart from apache, i read the code and I think it should be called A Patchy rather than Apache).

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Sang-drax has done this before, but he hasn't posted in a month.

    EDIT: found an old PM to him about that. Clicky
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    a good start is also the php source, which is free available:

    http://snaps.php.net/ (Snapshots)
    http://www.php.net/downloads.php (stable downloads)

  5. #5
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Thanks very much guys, but thats all about creating the extensions, not the server side. This is all I know so far:
    I have to load the DLL, and then find the HttpExtensionProc function in the DLL, which I then call. I can do all that fine. My probblem is, theres lots of stuff I have to pass to the call, and I dont know what to put in there. I think I'm also supposed to create ReadClient() and WriteClient() functions which the DLL uses to read/write the client.

    I know MS is closed source and the only programs that they make that use this is IIS, but they could at least have the information avaliable. I've seen other web servers out there that have ISAPI support, so there must be a way to do it.

    Thanks for the info guys, but do you have any more ideas?

  6. #6
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    OK, what about NSAPI? There must be info on that somewhere, but netscapes bieng a buggar and I can't find any of the specifications. Normally MSDN is really good when it comes to specs, but I guess they only want IIS to be able to use ISAPI. Please does anyone have any info on this?

  7. #7
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Not enough C++ for the C++ board.

    Moved to Tech

  8. #8
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Heres my code so far:

    Code:
    #include <iostream>
    #include <windows.h>
    #include <httpext.h>
    #include <string>
    
    using namespace std;
    
    
    HINSTANCE gMyDLL = NULL;
    typedef DWORD (*HTTPEXTENSIONPROC)( EXTENSION_CONTROL_BLOCK *pECB );
    
    HTTPEXTENSIONPROC pHttpExtensionProc;
    
    BOOL WINAPI pReadClient(HCONN ConnID, LPVOID lpvBuffer, LPDWORD lpdwSize)
    {
    	cout << "ReadClient() called" << endl;
    	return true;
    }
    
    BOOL WINAPI pWriteClient(HCONN ConnID, LPVOID Buffer, LPDWORD lpdwBytes, DWORD dwReserved )
    {
    	cout << "WriteClient() called" << endl;
    	return true;
    }
    
    BOOL WINAPI pServerSupportFunction(HCONN hConn, DWORD dwHSERequest, LPVOID lpvBuffer, LPDWORD lpdwSize, LPDWORD lpdwDataType)
    {
    	cout << "ServerSupportFunction() called" << endl;
    	return true;
    }
    
    BOOL WINAPI pGetServerVariable(HCONN hConn, LPSTR lpszVariableName, LPVOID lpvBuffer, LPDWORD lpdwSize)
    {
    	cout << "GetServerVariable() called" << endl;
    	return true;
    }
    
    
    
    int main()
    {
    	// Create an Extension Control Block
    	EXTENSION_CONTROL_BLOCK ECB;
    	HSE_VERSION_INFO hse;
    
    	// Load the DLL
    	gMyDLL = LoadLibrary("C:\\PHP\\sapi\\php4isapi.dll");
    	if (gMyDLL == NULL)
    	{
    		cout << "ERROR LOADING DLL\n\n";
    		return 0;
    	}
    
    	pHttpExtensionProc  = (HTTPEXTENSIONPROC) GetProcAddress(gMyDLL, "HttpExtensionProc");
    
    	ECB.ReadClient = &pReadClient;
    	ECB.WriteClient = &pWriteClient;
    	ECB.ServerSupportFunction = &pServerSupportFunction;
    	ECB.GetServerVariable = &pGetServerVariable;
    
    	pHttpExtensionProc(&ECB);
    	
    	return 0;	
    }
    As far as I understand so far, I have to create an EXTENSION_CONTROL_BLOCK, and inside it I have to put those pReadClient(), pWriteClient etc... functions. I've done that, and then I call pHttpExtensionProc.

    The program runs... and WOOHOO it prints:
    ServerSupportFunction() called
    WriteClient() called

    But then theres an error, telling me that:
    The value of ESP was not properly saved across a function call. This is usually the result of blah blah calling convention stuff.

    So, I'm getting there. I guess maybe theres something wrong with the stuff I'm returning in my functions. Does anyone know what that error means and what I'm supposed to do?

    PS: Now theres some C++ in it, could you move it back to the C++ board please?

  9. #9
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ok, I filled up the ECB with a few test variables, and I had the PHP ISAPI DLL send me a lot of GetServerVariable() requests for different variable names, which I'mm currently playing with. After that it calls two ServerSupportFunction() calls (but the number used is not documented). Then, It calls two WriteClients(), before getting the ESP error like last time. I feel I'm getting there but I could really appreciate some help on this. Anyone?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Problems with modules
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2005, 08:56 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. declare references to references works!
    By ManuelH in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2003, 08:14 AM