Chinaunix首页 | 论坛 | 博客
  • 博客访问: 690893
  • 博文数量: 148
  • 博客积分: 4086
  • 博客等级: 上校
  • 技术积分: 1766
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-06 23:27
文章分类

全部博文(148)

文章存档

2013年(19)

2012年(9)

2011年(106)

2009年(14)

分类: WINDOWS

2011-03-18 17:04:22

这两天帮在调查WinCE环境下的HTTP服务器。
如果在Win32环境下,我们可以选择HTTP Server API 来写HTTP1.1 的服务程序。但是在WinCE下没有这套API,所以我们可以选择IsAPI,它是依靠IIS服务器的的,底层是用了httpd.dll。
WinCE下这套API只有限支持http 1.0,如果在WinCE下定制http 1.1服务程序的话,貌似只能用socket (winsock)来写服务了。
另外简单介绍下isapi,它是IIS暴露给用户用来使用IIS定制web 服务器的。
它分filter和extension两部分,这里就只介绍下extension,它是允许用户定制一个扩展的DLL来实现自己想要的一些http服务器的行为和功能,比如支持DLNA的协议等。它和IIS的关系如下:

Whenever an extension is accessed (e.g., & Tx=870250AZT6), IIS checks to see whether the example.dll is loaded into memory. If it is not, then it initiates the loading process. Once the DLL is loaded into memory, a worker thread starts running to manage our extension, and thereafter the entry point (DLLMain function) is called.

When the DLLMain finishes, the server makes a call to GetExtensionVersion function to perform two tasks:

  1. Exchange version information
  2. Get a short text description of the extension

The server then calls the HttpExtensionProc function passing a copy of the ECB's pointer to start the actual ISAPI extension. This is the function that makes writing data back to the client。


For an ISAPI extension to be used by IIS, it must provide a standard interface. To provide a standard interface, each ISAPI extension DLL must implement and export two primary functions, and . A third function, , is optional and is commonly used by extensions to perform cleanup operations.

Initialization Using GetExtensionVersion
Initialization is handled by the entry-point function
. This function's role is to perform all initialization, including the creation of worker threads, synchronization objects, and database connections, and to establish the version of ISAPI that was used to build the DLL.

Adding Functionality Using HttpExtensionProc

In general, an extension's functionality is exposed through the entry-point function. This function receives a pointer to an structure, which contains data used for the required processing and is also used by the extension to communicate with IIS.
When
in employed, it should first to the client. The header provides the client with information, such as the content type that is returned. After the header is sent, any other processing can be performed through the various callback functions provided in the EXTENSION_CONTROL_BLOCK.

Termination Using TerminateExtension

When an extension is no longer needed, IIS removes it from memory. If the extension provides the function, IIS calls it before removing the extension. Use of is recommended to close down any threads that an extension initialized during processing.

After IIS finishes processing a request for an ISAPI extension, the connection can either be closed or kept open. A request can specify that the connection remain open by specifying the Connection: Keep-Alive header. If an ISAPI extension is designed to support Keep-Alive requests, this should be indicated to the client by calling the server support function. The specified response header should contain Connection: Keep-Alive.

DWORD SendHeaderToClient(LPEXTENSION_BLOCK pECB) {

CHAR szHeader[] = "Content-type: test/html\r\n\r\n";

DWORD hseStatus = HSE_STATUS_SUCCESS;

BOOL fReturn = pECB->ServerSupportFunction(pECB->ConnID,

HSE_REQ_SEND_RESPONSE_HEADER,

"Connection:Keep-Alive" // Telling the client not to close the connection.

NULL,

(LPDWORD) szHeader

);

  if (!fReturn)      hseStatus = HSE_STATUS_ERROR;

  return hseStatus;

}

另外在这里把WinCE条件下的,调试方法记录下。
使用WinCE模拟器来作运行程序的环境和用remote file viewer来上传文件。deploy 我们的程序到模拟器,在模拟器里启动程序,最后把solution attach 到模拟器上。
这里都是针对本程序的dbg方法。注:一个upnpapi.dll的调试。

还有一个很好的介绍isapi extension的地址:

阅读(1742) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~