📄 searchproc.c
字号:
}
if( IsPGPError(error) )
{
SEARCHABORT abort;
if (filter) PGPFreeFilter (filter);
abort.nmhdr.hwndFrom = hwnd;
abort.nmhdr.idFrom = IDD_SEARCH;
abort.nmhdr.code = SEARCH_ABORT;
abort.error = kPGPError_UserAbort;
SendMessage(GetParent(hwnd),
WM_NOTIFY,
(WPARAM)hwnd,
(LPARAM)&abort);
}
break;
}
case IDC_STOP:
{
HWND hwndSearch, hwndStop;
PSEARCHTHREADSTRUCT psts;
if(wNotifyCode)
{
break;
}
hwndSearch = GetDlgItem(hwnd, IDC_SEARCH);
hwndStop = GetDlgItem(hwnd, IDC_STOP);
if(!IsWindowEnabled (hwndStop))
{
break;
}
psts = (PSEARCHTHREADSTRUCT) GetProp(hwnd, "SearchInfo");
EnableWindow(hwndStop, FALSE);
if(psts)
{
PGPEvent event;
PGPEventErrorData data;
PGPError err;
if (PGPKeyServerRefIsValid (psts->server))
{
err = PGPCancelKeyServerCall (psts->server);
PGPclErrorBox (hwnd, err);
}
data.error = kPGPError_UserAbort;
memset(&event, 0x00, sizeof(PGPEvent));
event.type = kPGPEvent_ErrorEvent;
event.data.errorData = data;
SearchEventHandler( NULL,
&event,
psts);
}
if(psts)
{
SEARCHABORT abort;
memset(&abort, 0x00, sizeof(abort));
abort.nmhdr.hwndFrom = psts->hwnd;
abort.nmhdr.idFrom = IDD_SEARCH;
abort.nmhdr.code = SEARCH_ABORT;
abort.error = kPGPError_UserAbort;
SendMessage(GetParent(psts->hwnd),
WM_NOTIFY,
(WPARAM)psts->hwnd,
(LPARAM)&abort);
}
break;
}
case IDHELP:
{
PSEARCHTHREADSTRUCT psts;
if(wNotifyCode)
{
break;
}
psts = (PSEARCHTHREADSTRUCT) GetProp(hwnd, "SearchInfo");
PGPclHtmlHelp (psts->hwnd, kPGPclHelpContext, 0, 0,
(char*)kPGPclHelpFile,
(DWORD*)IDH_PGPPK_SEARCH_DIALOG);
break;
}
case IDC_ATTRIBUTE:
{
HANDLE_IDC_ATTRIBUTE(hwnd, msg, wParam, lParam);
break;
}
case IDC_LOCATION:
{
PSEARCHTHREADSTRUCT psts;
psts = (PSEARCHTHREADSTRUCT)
GetProp( hwnd, "SearchInfo");
if (!psts->bHidePending)
{
EnableWindow (GetDlgItem (hwnd, IDC_PENDING),
(ComboBox_GetCurSel(hwndCtl) >=
INDEX_FIRST_KEYSERVER));
}
break;
}
}
return TRUE;
}
}
return FALSE;
}
PGPError PerformSearch(HWND hwndLocation,
PSEARCHTHREADSTRUCT psts,
BOOL bPending,
long* flags,
PGPKeySetRef* pKeySetOut)
{
HINSTANCE hinst = GetModuleHandle(NULL);
PGPError error = kPGPError_NoErr;
PGPKeySetRef keysetLocal = kInvalidPGPKeySetRef;
PGPKeyDBRef keydbOut = kInvalidPGPKeyDBRef;
int locationSelection = 0;
int lastSearchIndex = 0;
int localSearchIndex = 0;
int searchPathIndex = 0;
char* locationBuffer = NULL;
int locationLength = 0;
LPARAM lParam = 0;
int lastSearchType = 0;
char szString[256] = {0x00};
PGPKeyServerAccessType accessType = kPGPKeyServerAccessType_Normal;
CRITICAL_SECTION* keyserverLock =
(CRITICAL_SECTION*) GetProp(GetParent(hwndLocation),
"KeyserverLock");
PGPKeyServerThreadStorageRef previousStorage;
if(PGPlnEnterprise())
{
if (PGPclIsAdminInstall ())
accessType = kPGPKeyServerAccessType_Administrator;
}
PGPKeyServerInit();
PGPKeyServerCreateThreadStorage(&previousStorage);
EnterCriticalSection(keyserverLock);
lastSearchType = (int)GetProp(hwndLocation, "LastSearchType");
LoadString(hinst, IDS_DEFAULT_PATH, szString, sizeof(szString));
searchPathIndex = ComboBox_FindString(hwndLocation, -1, szString);
LoadString(hinst, IDS_LOCAL_KEYRING, szString, sizeof(szString));
localSearchIndex = ComboBox_FindString(hwndLocation, -1, szString);
LoadString(hinst, IDS_CURRENT_SEARCH, szString, sizeof(szString));
lastSearchIndex = ComboBox_FindString(hwndLocation, -1, szString);
locationSelection = ComboBox_GetCurSel(hwndLocation);
lParam = ComboBox_GetItemData(hwndLocation, locationSelection);
LeaveCriticalSection(keyserverLock);
if (lParam == 0L ) // NULL: Invalid Selection
{
*pKeySetOut = kInvalidPGPKeySetRef;
}
// Default Path
else if( locationSelection == searchPathIndex )
{
PGPPrefRef prefs;
PGPtlsSessionRef tls = kInvalidPGPtlsSessionRef;
PGPKeyServerEntry* keyserverList = NULL;
PGPUInt32 keyserverCount = 0;
char* searchString = NULL;
int searchStringLength = 0;
char emailDomain[512] = {0x00};
*flags = FLAG_SEARCH_SERVER;
SetProp( hwndLocation, "LastSearchType",(HANDLE) *flags);
// retrieve search string from control
GrabUserIdStrings( GetParent(hwndLocation),
&searchString,
&searchStringLength);
if(searchString)
{
PGPFindEmailDomain(searchString, emailDomain);
}
error = PGPclPeekClientLibPrefRefs (&prefs, NULL);
if( IsntPGPError( error ) )
{
DWORD index = 0;
error = PGPCreateKeyServerPath( prefs,
emailDomain,
&keyserverList,
&keyserverCount);
if( IsntPGPError( error ) )
{
for(index = 0; index < keyserverCount; index++)
{
SEARCHPROGRESS progress;
char templateString[256];
memset(&progress, 0x00, sizeof(progress));
progress.nmhdr.hwndFrom = GetParent(hwndLocation);
progress.nmhdr.idFrom = IDD_SEARCH;
progress.nmhdr.code = SEARCH_PROGRESS;
progress.step = SEARCH_PROGRESS_INFINITE;
progress.total = SEARCH_PROGRESS_INFINITE;
LoadString( g_hinst,
IDS_SEARCH_MESSAGE_SERVER_NAME,
templateString,
sizeof(templateString));
wsprintf( progress.message,
templateString,
keyserverList[index].serverDNS);
SendMessage(GetParent(GetParent(hwndLocation)),
WM_NOTIFY,
(WPARAM)GetParent(hwndLocation),
(LPARAM)&progress);
error = PGPNewKeyServer(
g_context, keyserverList[index].type,
&psts->server,
PGPONetHostName (g_context,
keyserverList[index].serverDNS,
keyserverList[index].serverPort),
PGPOKeyServerProtocol (g_context,
keyserverList[index].protocol),
PGPOKeyServerAccessType (g_context,
accessType),
(bPending ?
PGPOKeyServerKeySpace (g_context,
kPGPKeyServerKeySpace_Pending) :
PGPOKeyServerKeySpace (g_context,
kPGPKeyServerKeySpace_Default)),
PGPOKeyServerKeyStoreDN (g_context,
keyserverList[index].keystoredn),
PGPOLastOption (g_context));
if( IsntPGPError( error ) )
{
memcpy(&(psts->keyserverEntry),
&(keyserverList[index]),
sizeof(PGPKeyServerEntry));
error = PGPSetKeyServerEventHandler( psts->server,
SearchEventHandler, psts );
if ( IsntPGPError( error ) )
{
if( (kPGPKeyServerProtocol_LDAPS ==
keyserverList[index].protocol) ||
(kPGPKeyServerProtocol_HTTPS ==
keyserverList[index].protocol))
{
error = PGPNewTLSSession( g_tlscontext,
&tls );
if( IsPGPError(error) )
{
// warn beyond the icon?
tls = kInvalidPGPtlsSessionRef;
}
}
error = PGPKeyServerOpen( psts->server, tls );
if ( IsntPGPError(error) )
{
error = PGPQueryKeyServer( psts->server,
psts->filter,
&keydbOut);
PGPKeyServerClose ( psts->server );
}
}
PGPFreeKeyServer( psts->server );
psts->server = kInvalidPGPKeyServerRef;
if( PGPtlsSessionRefIsValid(tls) )
{
PGPFreeTLSSession( tls );
tls = kInvalidPGPtlsSessionRef;
}
if( IsntPGPError( error ) )
{
EnterCriticalSection(keyserverLock);
*pKeySetOut = PGPPeekKeyDBRootKeySet (keydbOut);
ComboBox_SetItemData( hwndLocation,
lastSearchIndex,
*pKeySetOut);
LeaveCriticalSection(keyserverLock);
break;
}
}
}
PGPDisposeKeyServerPath(keyserverList);
}
}
if(searchString)
{
free(searchString);
}
}
// peform search on a local KeySet (keyring or mem)
else if(locationSelection == localSearchIndex ||
locationSelection == lastSearchIndex)
{
keysetLocal = (PGPKeySetRef) lParam;
if(locationSelection == lastSearchIndex)
{
*flags = FLAG_SEARCH_CURRENT;
}
else
{
*flags = FLAG_SEARCH_LOCAL_KEYSET;
SetProp( hwndLocation, "LastSearchType",(HANDLE) *flags);
}
if(keysetLocal != kInvalidPGPKeySetRef)
{
error = PGPFilterKeySet( keysetLocal, psts->filter, pKeySetOut);
if( IsPGPError(error) )
{
*pKeySetOut = kInvalidPGPKeySetRef;
}
}
else
{
*pKeySetOut = kInvalidPGPKeySetRef;
}
EnterCriticalSection(keyserverLock);
ComboBox_SetItemData(hwndLocation, lastSearchIndex, *pKeySetOut);
LeaveCriticalSection(keyserverLock);
}
// perform search on specified keyserver
else
{
PGPtlsSessionRef tls = kInvalidPGPtlsSessionRef;
PGPKeyServerEntry* entry = NULL;
*flags = FLAG_SEARCH_SERVER;
SetProp( hwndLocation, "LastSearchType",(HANDLE) *flags);
// retrieve keyserver entry from control
entry = (PGPKeyServerEntry*)lParam;
if( entry )
{
error = PGPNewKeyServer(
g_context, entry->type,
&psts->server,
PGPONetHostName (g_context,
entry->serverDNS,
entry->serverPort),
PGPOKeyServerProtocol (g_context,
entry->protocol),
PGPOKeyServerAccessType (g_context,
accessType),
(bPending ?
PGPOKeyServerKeySpace (g_context,
kPGPKeyServerKeySpace_Pending) :
PGPOKeyServerKeySpace (g_context,
kPGPKeyServerKeySpace_Default)),
PGPOKeyServerKeyStoreDN (g_context, entry->keystoredn),
PGPOLastOption (g_context));
memcpy(&(psts->keyserverEntry),
entry, sizeof(PGPKeyServerEntry));
}
else
{
error = kPGPError_OutOfMemory;
}
if( IsntPGPError( error ) )
{
error = PGPSetKeyServerEventHandler( psts->server,
SearchEventHandler, psts );
if ( IsntPGPError( error ) )
{
if( kPGPKeyServerProtocol_LDAPS == entry->protocol ||
kPGPKeyServerProtocol_HTTPS == entry->protocol)
{
error = PGPNewTLSSession( g_tlscontext,
&tls );
if( IsPGPError(error) )
{
// warn beyond the icon?
tls = kInvalidPGPtlsSessionRef;
}
}
error = PGPKeyServerOpen( psts->server, tls );
if ( IsntPGPError(error) )
{
error = PGPQueryKeyServer( psts->server,
psts->filter,
&keydbOut);
PGPKeyServerClose ( psts->server );
}
}
PGPFreeKeyServer( psts->server );
psts->server = kInvalidPGPKeyServerRef;
if( PGPtlsSessionRefIsValid(tls) )
{
PGPFreeTLSSession( tls );
tls = kInvalidPGPtlsSessionRef;
}
if( (IsntPGPError( error )) ||
(error == kPGPError_ServerPartialSearchResults ))
{
EnterCriticalSection(keyserverLock);
*pKeySetOut = PGPPeekKeyDBRootKeySet (keydbOut);
ComboBox_SetItemData( hwndLocation,
lastSearchIndex,
*pKeySetOut);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -