只问耕耘
分类: 数据库开发技术
2007-06-22 12:20:37
二,实现
1,VC++ 创建Win32 Dynamic-Link Library工程
2,修改工程设置
--工程->设置->C/C++->General->添加W32到预处理程序定义,如:WIN32,_DEBUG,_CONSOLE,_MBCS,W32
--工程->设置->C/C++->Code Generation->Struct member alignment->选择"1 Byte"
--工程->添加工程->文件,把notes.lib添加到工程里
3,添加代码如下:
//dsapi.c
/* Input and output include files */
#include
/* Notes SDK include files */
#include "global.h"
#include "osmem.h"
#include "addin.h"
#include "dsapi.h"
unsigned int FilterInit(FilterInitData* filterInitData)
{
/*
* Description: Filter initialization is performed when the filter
* shared library is dynamically loaded.
*
* Input: filterInitData dsapi specification controls the format
* of data
* Output: filterInitData several fields are filled in
*
* Return: kFilterHandledEvent
*/
/*Required*/
filterInitData->appFilterVersion = kInterfaceVersion;
/* Modify the following code to set the flags you want */
filterInitData->eventFlags = kFilterAuthenticate;
/* Set a short description for your filter */
strcpy(filterInitData->filterDesc,
"Superuser Authentication sample Filter");
/* insert any global initialization code here... */
/* Output sent to stdout and stderr is displayed on the
* server console, but is not written to the server log file.
*/
printf("\nDSAPI Authentication filter initialized\n");
return kFilterHandledEvent;
}
unsigned int TerminateFilter(unsigned int reserved)
{
return kFilterHandledEvent;
}
/*---
* filter notification handling
*/
unsigned int HttpFilterProc(FilterContext* context,
unsigned int eventType, void* eventData)
{
/*
* Description: This routine is called for all dsapi filter events.
*
* Input: reserved currently unused (dsapi spec controls the
* format of data)
* Output: none
*
* Return: kFilterNotHandled for all events that we don't customize,
* otherwise allow our filter routine to provide a return
* value.
*/
/* Include only those events we want to handle */
FilterAuthenticate* authData;
char string1[] = "\n user is found in the cache \n";
char string2[] = "\nERROR: Username and password must be specified\n";
switch (eventType) {
case kFilterAuthenticate:
authData=(FilterAuthenticate *)eventData;
/* If the user is found in the cache, then we don't need to do
* anything further.
*/
if (!authData || authData->foundInCache) {
//AddInLogMessageText (string1, NOERROR);
return kFilterNotHandled;
}
if (authData->userName==NULL || authData->password==NULL)
{
AddInLogMessageText (string2, NOERROR);
return kFilterNotHandled;
}
else
{
if (strcmp(authData->userName,"super")==0 && strcmp(authData->password,"password" )==0)
{
AddInLogMessageText ("super logged in successful", NOERROR);
authData->authType = kAuthenticBasic;
authData->foundInCache = TRUE;
return kFilterHandledEvent;
}
}
return kFilterNotHandled;
default:
break;
}
return kFilterNotHandled;
}
4,添加dsapi.def文件如下:
LIBRARY dsapi
DESCRIPTION "Web Server API"
EXPORTS
FilterInit @1
TerminateFilter @2
HttpFilterProc @3
5,把编译好的dsapi.dll拷贝到Domino程序目录
6,打开Domino地址本names.nsf,从Server - Servers视图, 打开server document,
From Notes UI, open the Directory database of the Lotus Domino server
(the names.nsf database).
7. From the Server - Servers view, open this server's server document. 在Internet Protocols tab, DSAPI filter file names: 输入dsapi.dll, 保存。
8,当http服务起动的时候,dsapi.dll会被调用。