📄 extprof.c
字号:
/*
* Program to register a callback routine that traps updates to a user's calendar profile
and logs the date and time of the update to a log file.
*/
/* Program header file */
#include "extprof.h"
/*
* Global Data
*/
HEMREGISTRATION hHandler = 0;
EMHANDLER gHandlerProc;
char gTextBuffer[1024];
char DataDir[256];
char FileName[256];
BOOL gHooksRegistered=FALSE;
WORD gRecursionID;
FILE *gFStream = (__FILE *)0;
/* Storage needed for synchronization */
CRITICAL_SECTION gCriticalSection;
/* Functions defined in this file */
STATUS LNPUBLIC DLL_EXPORT MainEntryPoint( void );
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD fdwReason,
LPVOID lpReserved );
STATUS LNPUBLIC DLL_EXPORT EMHandlerProc( EMRECORD FAR * pExRecord);
void CleanUp( void );
/*
* Function to write to a log file - output.log
*/
void LogLine(char *Line)
{
if (gFStream) {
__WriteLine(Line, gFStream);
if (__FileError(gFStream)) {
__CloseFile(gFStream);
gFStream = (__FILE *)0;
}
}
}
/* The Entry point */
STATUS LNPUBLIC DLL_EXPORT MainEntryPoint( void )
{
STATUS error = NOERROR;
/*
* When run on a server the dll is called multiple times, this flag
* keeps the main code from being executed more than once.
*/
if ( gHooksRegistered )
return(NOERROR);
gHooksRegistered = TRUE;
/* Open the log file. */
OSGetDataDirectory(DataDir);
strcpy(FileName, DataDir);
strcat(FileName, LOG_FILE_NAME);
gFStream = __OpenFile( FileName, WRITE_PERMISSION );
/* Get a RecursionID */
error = EMCreateRecursionID( &gRecursionID );
if (error)
{
LogLine("-------------------------------------------------\n");
LogLine("EMCreateRecursionID Failed\n");
}
else
{
/* Register the callback for NSFNoteUpdateExtended() - that is operation we are interested in */
error = EMRegister (
EM_NSFNOTEUPDATEXTENDED,
EM_REG_BEFORE,
(EMHANDLER)gHandlerProc,
gRecursionID,
&hHandler);
}
if ( gFStream ) {
__CloseFile(gFStream);
gFStream = (__FILE *)0;
}
return( error );
}
/* The actual callback routine */
STATUS LNPUBLIC EMHandlerProc( EMRECORD FAR * pExRecord )
{
STATUS error = 0;
switch (pExRecord->EId)
{
case EM_NSFNOTEUPDATEXTENDED:
{
NOTEHANDLE hNote; /* A handle to the note */
char far retCpath[MAXPATH]; /* Canonical path name */
char far retEpath[MAXPATH]; /* Extended path name*/
DBHANDLE hDB; /* A handle to the Database */
VARARG_PTR ap; /* The arguements from the EMRECORD */
char PathName[256]; /* The path to the database we are interested in */
char *calprofileformname = MAIL_CALENDAR_PROFILE_FORM; /* The form we are interested in*/
char formname[256]; /* The form of the note being updated */
char szTDBuffer[MAXSPRINTF]; /* Buffer used for converting TimeDate to text */
TIMEDATE tdMod; /* TimeDate */
OSCurrentTIMEDATE(&tdMod); /* The current date and time */
/* Current Date & Time in text format */
ConvertTIMEDATEToText(NULL, NULL, &tdMod, szTDBuffer, MAXALPHATIMEDATE, NULL);
/* get arguments */
ap = pExRecord->Ap;
hNote = VARARG_GET (ap, NOTEHANDLE);
/* check error code */
if (pExRecord->Status != NOERROR)
break;
if (pExRecord->NotificationType != EM_BEFORE)
break;
NSFNoteGetInfo(hNote, _NOTE_DB, &hDB);
if (NSFDbPathGet(hDB,retCpath,retEpath))
break;
/* construct database path name */
strcpy(PathName,DataDir);
strcat(PathName,"\\mail\\");
strcat(PathName,"admin.nsf");
/* if this isn't the database we're looking for then break */
if (strcmp(retEpath, PathName))
break;
/* If the form isn't Calendar Profile, break */
if (NSFItemGetText(hNote, FIELD_FORM,formname, sizeof(formname)))
{
if (strcmp(formname, MAIL_CALENDAR_PROFILE_FORM))
break;
}
else
{
break;
}
gFStream = __OpenFile( FileName, APPEND_PERMISSION );
LogLine("-------------------------------------------------\n");
sprintf(gTextBuffer, "Updating cal. profile on Database: %s on %s\n",retEpath, szTDBuffer);
LogLine( gTextBuffer );
LogLine("-------------------------------------------------\n");
__CloseFile(gFStream);
break;
}
}
return( ERR_EM_CONTINUE );
}
/* clean up */
void CleanUp(void)
{
gHooksRegistered = FALSE;
}
/* Startup and Shutdown Function DllMain for Win32
Standard windows NT DLL entrypoint, does initialzation required to get the
FARPROC for the Extension Manager callback function.
*/
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD fdwReason,
LPVOID lpReserved )
{
STATUS error=NOERROR;
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
InitializeCriticalSection(&gCriticalSection);
gHandlerProc = (EMHANDLER)MakeProcInstance((FARPROC)EMHandlerProc,
hInstance);
break;
case DLL_PROCESS_DETACH:
CleanUp();
/* Free procedure instance */
FreeProcInstance( gHandlerProc );
/* Deregister Extension Manager routines */
error = EMDeregister (hHandler);
if (error)
break;
DeleteCriticalSection(&gCriticalSection);
break;
}
return( TRUE );
UNREFERENCED_PARAMETER(lpReserved);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -