📄 clserver.c
字号:
PGPKeyServerDisposeThreadStorage(previousStorage);
PGPKeyServerCleanup ();
}
//done :
// let window know that we're done
psts->err = err;
event.szmessage[0] = '\0';
if (err == kPGPError_UserAbort)
{
event.nmhdr.code = PGPCL_SERVERABORT;
LoadString (g_hInst, IDS_SERVERABORT, event.szmessage,
sizeof(event.szmessage));
lstrcat (event.szmessage, psts->ksentry.serverDNS);
}
else if (IsPGPError (err))
{
event.nmhdr.code = PGPCL_SERVERERROR;
LoadString (g_hInst, IDS_SERVERERROR, event.szmessage,
sizeof(event.szmessage));
lstrcat (event.szmessage, psts->ksentry.serverDNS);
}
else
{
event.nmhdr.code = PGPCL_SERVERDONE;
LoadString (g_hInst, IDS_SERVEROK, event.szmessage,
sizeof(event.szmessage));
lstrcat (event.szmessage, psts->ksentry.serverDNS);
}
bThreadFree = psts->bThreadFree;
SendMessage (hwndParent, WM_NOTIFY, (WPARAM)hwndParent,
(LPARAM)&event);
// if thread should free data structure, do it
if (bThreadFree)
{
if (PGPKeySetRefIsValid (psts->keysetIn))
PGPFreeKeySet (psts->keysetIn);
PGPclFreeCACertRequestAVList (psts->pAVlist, psts->numAVs);
PGPFreeData (psts);
}
return 0;
}
// ____________________________________
//
// Draw the "LED" progress indicator
static VOID
sDrawStatus (
HWND hwnd,
PSERVERTHREADSTRUCT psts)
{
HBRUSH hBrushLit, hBrushUnlit, hBrushOld;
HPEN hPen, hPenOld;
INT i;
INT itop, ibot, ileft, iright, iwidth;
PAINTSTRUCT ps;
HDC hdc;
RECT rc;
if (psts->iStatusValue < -1) return;
hdc = BeginPaint (hwnd, &ps);
// draw 3D shadow
GetClientRect (hwnd, &rc);
itop = rc.top+1;
ibot = rc.bottom-2;
iwidth = (rc.right-rc.left) / NUMLEDS;
iwidth -= LEDSPACING;
ileft = rc.left + 4;
for (i=0; i<NUMLEDS; i++) {
iright = ileft + iwidth;
MoveToEx (hdc, ileft, ibot, NULL);
LineTo (hdc, iright, ibot);
LineTo (hdc, iright, itop);
ileft += iwidth + LEDSPACING;
}
hPen = CreatePen (PS_SOLID, 0, RGB (128, 128, 128));
hPenOld = SelectObject (hdc, hPen);
hBrushLit = CreateSolidBrush (RGB (0, 255, 0));
hBrushUnlit = CreateSolidBrush (RGB (0, 128, 0));
ileft = rc.left + 4;
// draw "Knight Rider" LEDs
if (psts->iStatusDirection) {
hBrushOld = SelectObject (hdc, hBrushUnlit);
for (i=0; i<NUMLEDS; i++) {
iright = ileft + iwidth;
if (i == psts->iStatusValue) {
SelectObject (hdc, hBrushLit);
Rectangle (hdc, ileft, itop, iright, ibot);
SelectObject (hdc, hBrushUnlit);
}
else {
Rectangle (hdc, ileft, itop, iright, ibot);
}
ileft += iwidth + LEDSPACING;
}
}
// draw "progress bar" LEDs
else {
if (psts->iStatusValue >= 0)
hBrushOld = SelectObject (hdc, hBrushLit);
else
hBrushOld = SelectObject (hdc, hBrushUnlit);
for (i=0; i<NUMLEDS; i++) {
iright = ileft + iwidth;
if (i > psts->iStatusValue) {
SelectObject (hdc, hBrushUnlit);
}
Rectangle (hdc, ileft, itop, iright, ibot);
ileft += iwidth + LEDSPACING;
}
}
SelectObject (hdc, hBrushOld);
SelectObject (hdc, hPenOld);
DeleteObject (hPen);
DeleteObject (hBrushLit);
DeleteObject (hBrushUnlit);
EndPaint (hwnd, &ps);
}
// ______________________________________________________
//
// Server progress dialog procedure (used for disable and delete)
static UINT CALLBACK
sServerProgressDlgProc (
HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
{
PSERVERTHREADSTRUCT psts = (PSERVERTHREADSTRUCT)lParam;
DWORD dwThreadID;
SetWindowLong (hDlg, GWL_USERDATA, lParam);
psts->hwnd = hDlg;
CreateThread (NULL, 0, psts->lpThread,
(void*)psts, 0, &dwThreadID);
return TRUE;
}
case WM_PAINT :
{
PSERVERTHREADSTRUCT psts =
(PSERVERTHREADSTRUCT)GetWindowLong (hDlg, GWL_USERDATA);
sDrawStatus (GetDlgItem (hDlg, IDC_PROGRESS), psts);
break;
}
case WM_TIMER :
{
PSERVERTHREADSTRUCT psts =
(PSERVERTHREADSTRUCT)GetWindowLong (hDlg, GWL_USERDATA);
psts->iStatusValue += psts->iStatusDirection;
if (psts->iStatusValue <= 0) {
psts->iStatusValue = 0;
psts->iStatusDirection = 1;
}
else if (psts->iStatusValue >= NUMLEDS-1) {
psts->iStatusValue = NUMLEDS-1;
psts->iStatusDirection = -1;
}
InvalidateRect (hDlg, NULL, FALSE);
break;
}
case WM_NOTIFY :
{
LPNMHDR pnmh = (LPNMHDR) lParam;
PSERVERTHREADSTRUCT psts =
(PSERVERTHREADSTRUCT)GetWindowLong (hDlg, GWL_USERDATA);
if (pnmh->hwndFrom != hDlg) break;
switch (pnmh->code) {
case PGPCL_SERVERPROGRESS :
{
PPGPclSERVEREVENT pEvent = (PPGPclSERVEREVENT)lParam;
if (!(psts->bSearchInProgress)) {
psts->bSearchInProgress = TRUE;
psts->iStatusValue = 0;
if (pEvent->step == PGPCL_SERVERINFINITE) {
psts->iStatusDirection = 1;
SetTimer (hDlg, LEDTIMER, LEDTIMERPERIOD, NULL);
}
else {
psts->iStatusDirection = 0;
psts->iStatusValue = 0;
}
}
else {
if (pEvent->step != PGPCL_SERVERINFINITE) {
psts->iStatusDirection = 0;
psts->iStatusValue = (pEvent->step * 9) /
pEvent->total;
InvalidateRect (hDlg, NULL, FALSE);
}
}
SetDlgItemText (hDlg, IDC_PROGRESSTEXT,
pEvent->szmessage);
return FALSE;
}
case PGPCL_SERVERDONE :
case PGPCL_SERVERABORT :
case PGPCL_SERVERERROR :
{
PPGPclSERVEREVENT pEvent = (PPGPclSERVEREVENT)lParam;
PGPError err;
KillTimer (hDlg, LEDTIMER);
psts->keysetOut = (PGPKeySetRef)(pEvent->pData);
err = psts->err;
EndDialog (hDlg, err);
return FALSE;
}
}
break;
}
case WM_COMMAND :
switch(LOWORD (wParam)) {
case IDCANCEL :
{
PSERVERTHREADSTRUCT psts =
(PSERVERTHREADSTRUCT)GetWindowLong (hDlg, GWL_USERDATA);
KillTimer (hDlg, LEDTIMER);
psts->bThreadFree = TRUE;
psts->bCancel = TRUE;
if (psts->server) {
PGPError err;
err = PGPCancelKeyServerCall (psts->server);
PGPclErrorBox (hDlg, err);
}
EndDialog (hDlg, kPGPError_UserAbort);
break;
}
}
return TRUE;
}
return FALSE;
}
// ___________________________________________________
//
// update all groups from keyserver
PGPError PGPclExport
PGPclGetGroupsFromRootServer (
PGPContextRef context,
PGPtlsContextRef tlsContext,
HWND hwndParent,
PGPKeySetRef keysetMain,
PGPGroupSetRef* pgroupsetDownloaded)
{
PGPError err = kPGPError_NoErr;
PSERVERTHREADSTRUCT psts;
psts = (PSERVERTHREADSTRUCT)malloc (sizeof(SERVERTHREADSTRUCT));
memset(psts,0x00,sizeof(SERVERTHREADSTRUCT));
if (psts) {
psts->uOperation = GETGROUPS;
psts->context = context;
psts->tlsContext = tlsContext;
psts->keysetMain = keysetMain;
psts->hwnd = hwndParent;
psts->lpThread = sKeyserverThreadRoutine;
psts->bSearchInProgress = FALSE;
psts->bCancel = FALSE;
psts->bThreadFree = FALSE;
psts->iStatusValue = -1;
psts->iStatusDirection = 1;
psts->space = kPGPKeyServerKeySpace_Default;
psts->groupset = kInvalidPGPGroupSetRef;
ZeroMemory (&psts->ksentry, sizeof(PGPKeyServerEntry));
err = DialogBoxParam (g_hInst, MAKEINTRESOURCE(IDD_SERVERPROGRESS),
hwndParent, sServerProgressDlgProc, (LPARAM)psts);
if (IsntPGPError (err)) {
if (pgroupsetDownloaded)
*pgroupsetDownloaded = psts->groupset;
}
if (!psts->bThreadFree) {
free (psts);
}
}
return err;
}
// ___________________________________________________
//
// send all groups to keyserver
PGPError PGPclExport
PGPclSendGroupsToRootServer (
PGPContextRef context,
PGPtlsContextRef tlsContext,
HWND hwndParent,
PGPKeySetRef keysetMain,
PGPGroupSetRef groupsetToSend)
{
PGPError err = kPGPError_NoErr;
PSERVERTHREADSTRUCT psts;
psts = (PSERVERTHREADSTRUCT)malloc (sizeof(SERVERTHREADSTRUCT));
memset(psts,0x00,sizeof(SERVERTHREADSTRUCT));
if (psts) {
psts->uOperation = SENDGROUPS;
psts->context = context;
psts->tlsContext = tlsContext;
psts->keysetMain = keysetMain;
psts->hwnd = hwndParent;
psts->lpThread = sKeyserverThreadRoutine;
psts->bSearchInProgress = FALSE;
psts->bCancel = FALSE;
psts->bThreadFree = FALSE;
psts->iStatusValue = -1;
psts->iStatusDirection = 1;
psts->space = kPGPKeyServerKeySpace_Default;
psts->groupset = groupsetToSend;
ZeroMemory (&psts->ksentry, sizeof(PGPKeyServerEntry));
err = DialogBoxParam (g_hInst, MAKEINTRESOURCE(IDD_SERVERPROGRESS),
hwndParent, sServerProgressDlgProc, (LPARAM)psts);
if (!psts->bThreadFree) {
free (psts);
}
}
return err;
}
// ___________________________________________________
//
// send keyset to keyserver
PGPError PGPclExport
PGPclSendKeysToRootServerNotify (
PGPContextRef context,
PGPtlsContextRef tlsContext,
HWND hwndToNotify,
PGPKeySetRef keysetMain,
PGPKeySetRef keysetToSend)
{
PSERVERTHREADSTRUCT psts;
DWORD dwThreadID;
psts = (PSERVERTHREADSTRUCT)malloc (sizeof(SERVERTHREADSTRUCT));
memset(psts,0x00,sizeof(SERVERTHREADSTRUCT));
if (psts) {
PGPNewKeySet (context, &(psts->keysetIn));
PGPAddKeys (keysetToSend, psts->keysetIn);
PGPCommitKeyRingChanges (psts->keysetIn);
psts->uOperation = SENDKEY;
psts->context = context;
psts->tlsContext = tlsContext;
psts->keysetMain = keysetMain;
psts->hwnd = hwndToNotify;
psts->lpThread = NULL;
psts->bSearchInProgress = FALSE;
psts->bCancel = FALSE;
psts->bThreadFree = TRUE;
psts->iStatusValue = -1;
psts->iStatusDirection = 1;
psts->space = kPGPKeyServerKeySpace_Default,
psts->groupset = kInvalidPGPGroupSetRef;
ZeroMemory (&psts->ksentry, sizeof(PGPKeyServerEntry));
CreateThread (NULL, 0, sKeyserverThreadRoutine,
(void*)psts, 0, &dwThreadID);
}
return kPGPError_NoErr;
}
// ___________________________________________________
//
// disable keyset on keyserver
PGPError PGPclExport
PGPclDisableKeysOnServer (
PGPContextRef context,
PGPtlsContextRef tlsContext,
HWND hwndParent,
PGPKeyServerEntry* pkeyserver,
PGPKeyServerKeySpace space,
PGPKeySetRef keysetMain,
PGPKeySetRef keysetToSend)
{
PSERVERTHREADSTRUCT psts;
PGPError err;
psts = (PSERVERTHREADSTRUCT)malloc (sizeof(SERVERTHREADSTRUCT));
if (psts) {
PGPNewKeySet (context, &(psts->keysetIn));
PGPAddKeys (keysetToSend, psts->keysetIn);
PGPCommitKeyRingChanges (psts->keysetIn);
psts->uOperation = DISABLEKEY;
psts->context = context;
psts->tlsContext = tlsContext;
psts->keysetMain = keysetMain;
psts->lpThread = sKeyserverThreadRoutine;
psts->bSearchInProgress = FALSE;
psts->bCancel = FALSE;
psts->bThreadFree = FALSE;
psts->iStatusValue = -1;
psts->iStatusDirection = 1;
psts->space = space;
psts->groupset = kInvalidPGPGroupSetRef;
CopyMemory (&psts->ksentry, pkeyserver, sizeof(PGPKeyServerEntry));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -