📄 plugininfo.c
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: PluginInfo.c,v 1.18 2002/11/12 18:58:15 pbj Exp $
____________________________________________________________________________*/
#include <windows.h>
#include "PluginInfo.h"
#include "UIutils.h"
#include "resource.h"
#include "pgpClientLib.h"
#include "pgpLnLib.h"
PGPContextRef _pgpContext = NULL; // PGP context of current instance
PGPtlsContextRef _tlsContext = NULL; // TLS context of current instance
BYTE _nCLRef = 0; // Ref counter for clientlib init
BYTE _nTLSRef = 0; // Ref counter for TLS context
char *_szReplyText = NULL;
BOOL g_bOE5=FALSE; //global flag for knowing if this is OE5
//plugininfo objects set their bOE5 flag
//based on the value of this
static BOOL DoIExist(HANDLE *phSem);
static void SetNoLoad(void);
static BOOL ShouldILoad(void);
static HANDLE CheckExpirationStart(void);
static void CheckExpirationEnd(HANDLE hSem);
PluginInfo * CreatePluginInfo(HWND hwnd)
{
PGPError err;
PluginInfo *plugin=NULL;
HANDLE hExpire=NULL;
hExpire = CheckExpirationStart();
if (hExpire == NULL)
return NULL;
CheckExpirationEnd(hExpire);
plugin = (PluginInfo *) calloc(sizeof(PluginInfo), 1);
if(NULL == plugin)
return NULL;
plugin->bLoaded = DoIExist(&(plugin->hInstSemaphore));
if (!ShouldILoad())
{
free(plugin);
return NULL;
}
// Initialize common library
if (!(plugin->bLoaded) || (_pgpContext == NULL))
{
PGPUInt32 nFlags = 0;
if (!(plugin->bLoaded))
nFlags = kPGPclEnableNewUserWizard;
err = PGPclInitLibrary(&_pgpContext, nFlags);
if (IsPGPError(err))
{
if (err == kPGPError_FeatureNotAvailable)
UIDisplayStringID(hwnd, IDS_E_EXPIRED);
else
PGPclErrorBox(hwnd, err);
SetNoLoad();
PGPclCloseLibrary();
_pgpContext = NULL;
free(plugin);
return NULL;
}
// Check for beta/demo expiration
hExpire = CheckExpirationStart();
PGPlnLicenseCheck (_pgpContext);
if (IsPGPError (PGPlnIsExpired(hwnd, kPGPlnModuleGraceExpiration)))
{
SetNoLoad();
PGPclCloseLibrary();
_pgpContext = NULL;
free(plugin);
CheckExpirationEnd(hExpire);
return NULL;
}
CheckExpirationEnd(hExpire);
}
_nCLRef++;
if (_tlsContext == NULL)
PGPNewTLSContext(_pgpContext, &_tlsContext);
_nTLSRef++;
plugin->pgpContext = _pgpContext;
plugin->tlsContext = _tlsContext;
plugin->memoryMgr = PGPPeekContextMemoryMgr(_pgpContext);
plugin->nCopyDoneMsg = RegisterWindowMessage("PGPoe Copy Done");
plugin->nPasteDoneMsg = RegisterWindowMessage("PGPoe Paste Done");
plugin->nPGPPosition = -1;
plugin->nPGPKeysButton = -1;
plugin->nPGPKeysImage = -1;
plugin->nPGPKeysString = -1;
plugin->nEncryptImage = -1;
plugin->nEncryptString = -1;
plugin->nSignImage = -1;
plugin->nSignString = -1;
plugin->nDecryptImage = -1;
plugin->nDecryptString = -1;
plugin->nButtonSizeX = 0;
plugin->nButtonSizeY = 0;
plugin->bOE5 = g_bOE5;
plugin->bOE6 = FALSE;
plugin->bDisableMenus = FALSE;
plugin->szOldText = NULL;
plugin->szOutput = NULL;
return plugin;
}
PluginInfo * GetPluginInfo(HWND hwnd)
{
return (PluginInfo *) GetProp(hwnd, PLUGIN_INFO_PROP);
}
void SavePluginInfo(HWND hwnd, PluginInfo *plugin)
{
if (plugin->hwndCurrent != NULL)
RemoveProp(plugin->hwndCurrent, PLUGIN_INFO_PROP);
SetProp(hwnd, PLUGIN_INFO_PROP, (HANDLE) plugin);
plugin->hwndCurrent = hwnd;
return;
}
void FreePluginInfo(PluginInfo *plugin)
{
if (plugin == NULL)
return;
if (plugin->hwndCurrent != NULL)
{
RemoveProp(plugin->hwndCurrent, PLUGIN_INFO_PROP);
plugin->hwndCurrent = NULL;
}
if (plugin->hPGPMenu != NULL)
{
DestroyMenu(plugin->hPGPMenu);
plugin->hPGPMenu = NULL;
}
if (plugin->szOutput != NULL)
{
free(plugin->szOutput);
plugin->szOutput = NULL;
}
if (_tlsContext)
{
_nTLSRef--;
if (!_nTLSRef)
{
PGPFreeTLSContext(_tlsContext);
_tlsContext = NULL;
}
}
if (_pgpContext)
{
_nCLRef--;
if (!_nCLRef)
{
PGPclCloseLibrary();
_pgpContext = NULL;
}
}
if (!(plugin->bLoaded))
{
FreeReplyText();
if (plugin->hInstSemaphore != NULL)
CloseHandle(plugin->hInstSemaphore);
}
free(plugin);
}
void SetReplyText(char *szText)
{
FreeReplyText();
_szReplyText = szText;
return;
}
char *GetReplyText()
{
return _szReplyText;
}
void FreeReplyText()
{
if (_szReplyText != NULL)
{
free(_szReplyText);
_szReplyText = NULL;
}
return;
}
BOOL DoIExist(HANDLE *phSem)
{
HANDLE hSem;
// Create or open a named semaphore
*phSem = NULL;
hSem = CreateSemaphore (NULL, 0, 1, "pgpOutlookExpressInstSem");
// Close handle and return TRUE if existing semaphore was opened.
if ((hSem != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS))
{
CloseHandle(hSem);
return TRUE;
}
*phSem = hSem;
return FALSE;
}
void SetNoLoad()
{
HANDLE hSem;
// Create or open a named semaphore.
hSem = CreateSemaphore (NULL, 0, 1, "pgpOutlookExpressLoadSem");
if ((hSem != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS))
CloseHandle(hSem);
return;
}
BOOL ShouldILoad()
{
HANDLE hSem;
BOOL bShouldLoad = TRUE;
DWORD dwError;
// Create or open a named semaphore.
hSem = CreateSemaphore (NULL, 0, 1, "pgpOutlookExpressLoadSem");
if (hSem != NULL)
{
dwError = GetLastError();
if (dwError == ERROR_ALREADY_EXISTS)
bShouldLoad = FALSE;
else
bShouldLoad = TRUE;
CloseHandle(hSem);
}
return bShouldLoad;
}
static HANDLE CheckExpirationStart(void)
{
HANDLE hSem;
// Create or open a named semaphore
hSem = CreateSemaphore (NULL, 0, 1, "pgpOutlookExpressCheckExpiration");
// Close handle and return TRUE if existing semaphore was opened.
if ((hSem != NULL) && (GetLastError() == ERROR_ALREADY_EXISTS))
{
CloseHandle(hSem);
return NULL;
}
return hSem;
}
static void CheckExpirationEnd(HANDLE hSem)
{
CloseHandle(hSem);
return;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -