Thread: ISAPI problem with IIS 6.0

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445

    ISAPI problem with IIS 6.0

    I have an ISAPI dll that I wrote, and all it is designed to do at the moment is to display a message on the page, but I get a "connection reset" message from my web browser when I try to load the dll. in the dll, I have added some logging so that it tries to log its activity to a file. the file is not even getting created, so I suspect that the dll is not getting loaded at all. I have tried explicitly creating an extension in IIS for my DLL, and I have also tried enabling all unknown ISAPI extensions, and both have the same result. I have tested my DLL with an ISAPI debugger program, which loads the dll, gives it a request, and shows the result. with the debugger it works fine, but in IIS it appears to cause DefaultAppPool to crash. in the log files, the lines representing requests to this DLL end with "500 0 14001" which means there is some internal server error going on, but I have no idea how to find out what the error is or what is causing it. I have searched for about 2 hours now for a solution to this problem with no luck.

    I tried a program (DebugDiag) suggested by a poster on the IIS board, and the dump report says it crashed in a call to RtlEqualSid in ntdll.dll. This is not a function that I am calling, so I have no clue what to do with this information. I tried immediately returning from the HttpExtensionProc function with no effect, so I'm guessing the problem is coming from the attempt to load the DLL and attach it to the process or thread. I also tried immediately returning from the DllMain function, but that had no effect either. I'm really at a loss as to why this is happening.



    Please Help.

  2. #2
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Without code any help would be shots in the dark.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    ok, so I started over. now, the dll loads, and I can interact with it on the web, but for some reason, no matter what I try, I can't get more than the first 48k of post data, even though I'm sending about 80k.

    the html file that contains the submission form is as follows:
    Code:
    <HTML>
      <HEAD>
        <TITLE>
          Test Form
        </TITLE>
      </HEAD>
    
      <BODY>
        <FORM method="POST" action="/team_isapi/plain-isapi.dll?foo=bar">
          <INPUT type="text" name="T1"><br>
          <TEXTAREA name="T2" rows="10" cols="60"></TEXTAREA><br>
          <INPUT type="submit" value="Submit" name="B1"><br>
          <INPUT type="reset" value="Reset" name="B2"><br>
        </FORM>
      </BODY>
    </HTML>
    the only header file in the project is as follows:
    Code:
    // plain-isapi.h
    
    #ifndef __PLAIN_ISAPI_H
    #define __PLAIN_ISAPI_H
    
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <sstream>
    #include <vector>
    #include <queue>
    #include <httpext.h>
    
    using std::endl;
    using std::ofstream;
    using std::ifstream;
    using std::string;
    using std::stringstream;
    using std::vector;
    using std::queue;
    
    #endif // __PLAIN_ISAPI_H
    and the main source file:
    Code:
    // plain-isapi.cpp
    
    #include "plain-isapi.h"
    
    void PrintHtml(EXTENSION_CONTROL_BLOCK* pECB, string s);
    string ReadFromClient(EXTENSION_CONTROL_BLOCK* pECB);
    
    BOOL WINAPI DllMain(HMODULE hMod, DWORD fReason, LPVOID pvRes)
    {
      switch (fReason)
      {
        case DLL_PROCESS_ATTACH:
        {
          break;
        }
        case DLL_THREAD_ATTACH:
        {
          break;
        }
        case DLL_THREAD_DETACH:
        {
          break;
        }
        case DLL_PROCESS_DETACH:
        {
          break;
        }
      }
      return TRUE;
    }
    
    BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO* pVer)
    {
      pVer->dwExtensionVersion = 1;
      strncpy(pVer->lpszExtensionDesc, "plain-isapi extension.", HSE_MAX_EXT_DLL_NAME_LEN);
      return TRUE;
    }
    
    DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK* pECB)
    {
      stringstream ss_post;
      string str(pECB->lpszQueryString);
      PrintHtml(pECB, "<HTML><HEAD><TITLE>plain-isapi extension test</TITLE></HEAD><BODY><H1>FOO!</H1><br><hr>");
      PrintHtml(pECB, str);
      PrintHtml(pECB, "<br><hr>");
      char buffer[4096];
      int size = 4096;
      memset(buffer, 0, 4096);
      if (pECB->GetServerVariable(pECB->ConnID, (LPSTR)"CONTENT_LENGTH", (LPVOID)buffer, (LPDWORD)&size))
      {
        ss_post << "CONTENT_LENGTH: " << buffer << "<br>" << endl;
      }
      string post = ReadFromClient(pECB);
      ss_post << "Post string length: " << post.length() << "<br>" << endl;
      ss_post << "Post string: " << post << "<br>" << endl;
      ss_post << "</BODY></HTML>";
      post = ss_post.str();
      PrintHtml(pECB, post);
      pECB->dwHttpStatusCode = 200;
      return HSE_STATUS_SUCCESS;
    }
    
    string ReadFromClient(EXTENSION_CONTROL_BLOCK* pECB)
    {
      PrintHtml(pECB, "In ReadClient()...<br>\r\n");
      string str;
      stringstream ss;
      str.assign((char*)pECB->lpbData, pECB->cbAvailable);
      ss << "str.length(): " << str.length() << "<br>" << endl;
      size_t bytes, num_bytes;
      size_t data_read = pECB->cbAvailable;
      bytes = pECB->cbTotalBytes - pECB->cbAvailable;
      ss << "Bytes left to read: " << bytes << "<br>" << endl;
      PrintHtml(pECB, ss.str());
      char *buffer = NULL;
      if (bytes)
      {
        PrintHtml(pECB, "Attempting to read from client...<br>\r\n");
        buffer = new char[bytes];
        while (data_read < pECB->cbTotalBytes)
        {
          PrintHtml(pECB, "Iteration of loop...<br>\r\n");
          memset(buffer, 0, bytes);
          if (pECB->ReadClient(pECB->ConnID, (LPVOID)buffer, (LPDWORD)&num_bytes))
          {
            PrintHtml(pECB, "Read data from client...<br>\r\n");
            if (num_bytes) str.append(buffer, num_bytes);
            data_read += num_bytes;
          }
          else
          {
            PrintHtml(pECB, "Failed to read more data...<br>\r\n");
            break;
          }
        }
        delete buffer;
      }
      else
      {
        PrintHtml(pECB, "No data available for reading...<br>\r\n");
      }
      
      return str;
    }
    
    void PrintHtml(EXTENSION_CONTROL_BLOCK* pECB, string s)
    {
      char* str = new char[s.length() + 1];
      size_t len = s.length();
      pECB->WriteClient(pECB->ConnID, (LPVOID)s.c_str(), (LPDWORD)&len, 0);
    }
    I have been working on this one issue for about 4 hours now, with no progress. I'm sure it's something simple that I'm overlooking, but I just don't get it.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    now this is really strange.....

    I took the code I posted here and ran it on my XP x64 machine at my house, compiled as x64 native code, and it ran just fine on IIS on XP. it read all of the data I fed it, with no problem, but when I take the code I have at home (modified slightly from the code I posted earlier) and try to run it on my dev server (windows server 2003) at work, it still only gets the first 48k (49152 bytes) of data. what gives?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  2. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  3. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  4. Problem with Visual C++ 6.0
    By toonlover in forum C++ Programming
    Replies: 4
    Last Post: 05-25-2005, 09:32 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM