1020 |
static int |
static int |
1021 |
find_keypos (listview_ctrl_t lv, gpgme_key_t key) |
find_keypos (listview_ctrl_t lv, gpgme_key_t key) |
1022 |
{ |
{ |
1023 |
gpgme_key_t src; |
char keyid[16+1]; |
1024 |
int i; |
int i; |
1025 |
|
|
1026 |
for (i=0; i < listview_count_items (lv, 0); i++) { |
for (i=0; i < listview_count_items (lv, 0); i++) { |
1027 |
src = (gpgme_key_t)listview_get_item2 (lv, i); |
listview_get_item_text (lv, i, KM_COL_KEYID, keyid, sizeof (keyid)-1); |
1028 |
if (src && src->subkeys->keyid == key->subkeys->keyid) |
if (!strcmp (key->subkeys->keyid+8, keyid+2)) |
1029 |
return i; |
return i; |
1030 |
} |
} |
1031 |
return -1; |
return -1; |
1039 |
{ |
{ |
1040 |
struct keycache_s *ctx; |
struct keycache_s *ctx; |
1041 |
gpg_keycache_t kc; |
gpg_keycache_t kc; |
1042 |
int status=0; |
int status=0, pos; |
1043 |
|
|
1044 |
kc = keycache_get_ctx (1); |
kc = keycache_get_ctx (1); |
1045 |
while (!gpg_keycache_next_updated_key (kc, &ctx, &status)) { |
while (!gpg_keycache_next_updated_key (kc, &ctx, &status)) { |
1046 |
if (status == KC_FLAG_ADD) |
if (status == KC_FLAG_ADD) |
1047 |
keylist_add_key (kmi->lv, KEYLIST_LIST, ctx->key); |
keylist_add_key (kmi->lv, KEYLIST_LIST, ctx->key); |
1048 |
else |
else { |
1049 |
keylist_upd_key (kmi->lv, find_keypos (kmi->lv, ctx->key), ctx->key); |
pos = find_keypos (kmi->lv, ctx->key); |
1050 |
/*log_box ("debug", 0, "(%d) %s", status, ctx->key->uids->name);*/ |
if (pos != -1) |
1051 |
|
keylist_upd_key (kmi->lv, pos, ctx->key); |
1052 |
|
} |
1053 |
} |
} |
1054 |
keylist_sort (kmi->lv, KEY_SORT_USERID); |
keylist_sort (kmi->lv, KEY_SORT_USERID); |
1055 |
update_status_bar (kmi->statbar, kmi->lv); |
update_status_bar (kmi->statbar, kmi->lv); |
1063 |
keycache_reload (kmi->dlg); |
keycache_reload (kmi->dlg); |
1064 |
keylist_reload (kmi->lv, keycache_get_ctx (1), |
keylist_reload (kmi->lv, keycache_get_ctx (1), |
1065 |
KEYLIST_LIST, KEY_SORT_USERID); |
KEYLIST_LIST, KEY_SORT_USERID); |
1066 |
|
update_status_bar (kmi->statbar, kmi->lv); |
1067 |
|
keyring_check_last_access (); |
1068 |
|
} |
1069 |
|
|
1070 |
|
|
1071 |
|
/* Reload the entire key cache and update the listview. */ |
1072 |
|
static void |
1073 |
|
reload_keycache (struct km_info_s *kmi) |
1074 |
|
{ |
1075 |
|
refresh_cache_s rcs = {0}; |
1076 |
|
gpg_keycache_t c; |
1077 |
|
|
1078 |
|
rcs.kr_reload = rcs.kr_update = 1; |
1079 |
|
rcs.tr_update = 0; |
1080 |
|
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, kmi->dlg, |
1081 |
|
keycache_dlg_proc, (LPARAM)&rcs); |
1082 |
|
c = keycache_get_ctx (1); |
1083 |
|
if (!c) |
1084 |
|
BUG (0); |
1085 |
|
keylist_reload (kmi->lv, c, KEYLIST_LIST, KEY_SORT_USERID); |
1086 |
|
update_status_bar (kmi->statbar, kmi->lv); |
1087 |
|
SetForegroundWindow (kmi->dlg); |
1088 |
|
} |
1089 |
|
|
1090 |
|
|
1091 |
|
/* Handle all import request. */ |
1092 |
|
static void |
1093 |
|
km_gui_import (struct km_info_s *kmi, int cmd_id) |
1094 |
|
{ |
1095 |
|
int newkeys=0, newsks=0; |
1096 |
|
int err = 0; |
1097 |
|
|
1098 |
|
switch (cmd_id) { |
1099 |
|
case ID_KEYMISC_PASTE: |
1100 |
|
err = km_clip_import (kmi->dlg, &newkeys, &newsks); |
1101 |
|
break; |
1102 |
|
|
1103 |
|
case ID_KEYMISC_IMPORT: |
1104 |
|
err = km_file_import (kmi->dlg, NULL, &newkeys, &newsks); |
1105 |
|
break; |
1106 |
|
|
1107 |
|
default: |
1108 |
|
err = 1; |
1109 |
|
break; |
1110 |
|
} |
1111 |
|
|
1112 |
|
if (!err && !newsks && (newkeys > 0 && newkeys < KM_PRELOAD_KEYS)) |
1113 |
|
refresh_keylist (kmi); |
1114 |
|
else if (!err) /* avoid to spawn too much processes. */ |
1115 |
|
reload_keylist (kmi); |
1116 |
|
|
1117 |
|
SetForegroundWindow (kmi->dlg); |
1118 |
|
center_window (kmi->dlg, NULL); |
1119 |
} |
} |
1120 |
|
|
1121 |
|
|
1132 |
struct genkey_s genkey; |
struct genkey_s genkey; |
1133 |
struct winpt_key_s k = {0}; |
struct winpt_key_s k = {0}; |
1134 |
struct URL_ctx_s *url; |
struct URL_ctx_s *url; |
|
refresh_cache_s rcs = {0}; |
|
1135 |
char type[32], *name; |
char type[32], *name; |
1136 |
const char *t, *host; |
const char *t, *host; |
1137 |
WORD port = 0; |
WORD port = 0; |
1202 |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", type); |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_X", type); |
1203 |
ltoa (kmi->pos_y, type, 10); |
ltoa (kmi->pos_y, type, 10); |
1204 |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", type); |
set_reg_entry (HKEY_CURRENT_USER, "Software\\WinPT", "KM_Pos_Y", type); |
1205 |
|
/* XXX: store window size. */ |
1206 |
|
|
1207 |
/* Remove runtime information. This should be the last action taken here. */ |
/* Remove runtime information. This should be the last action taken here. */ |
1208 |
delete kmi; kmi = NULL; |
delete kmi; kmi = NULL; |
1564 |
|
|
1565 |
case ID_KEYMISC_PROPS: |
case ID_KEYMISC_PROPS: |
1566 |
if (kmi->lv_idx == -1) { |
if (kmi->lv_idx == -1) { |
1567 |
msg_box( dlg, _("Please select a key."), _("Key Manager"), MB_ERR ); |
msg_box (dlg, _("Please select a key."), _("Key Manager"), MB_ERR); |
1568 |
return TRUE; |
return TRUE; |
1569 |
} |
} |
1570 |
key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx); |
key = (gpgme_key_t)listview_get_item2 (kmi->lv, kmi->lv_idx); |
1571 |
if (!key) |
if (!key) |
1572 |
BUG (NULL); |
BUG (NULL); |
1573 |
memset (&k, 0, sizeof (k)); |
memset (&k, 0, sizeof (k)); |
1574 |
|
strncpy (k.tmp_keyid, key->subkeys->keyid+8, 8); |
1575 |
|
k.keyid = k.tmp_keyid; |
1576 |
k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL)? 1 : 0; |
k.key_pair = km_check_for_seckey (kmi->lv, kmi->lv_idx, NULL)? 1 : 0; |
|
k.keyid = key->subkeys->keyid+8; |
|
1577 |
k.callback.ctl = kmi->lv; |
k.callback.ctl = kmi->lv; |
1578 |
k.callback.idx = kmi->lv_idx; |
k.callback.idx = kmi->lv_idx; |
1579 |
k.is_v3 = km_key_is_v3 (kmi->lv, kmi->lv_idx); |
k.is_v3 = km_key_is_v3 (kmi->lv, kmi->lv_idx); |
1580 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg, |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROPS, dlg, |
1581 |
keyprops_dlg_proc, (LPARAM)&k, |
keyprops_dlg_proc, (LPARAM)&k, |
1582 |
_("Key Properties"), IDS_WINPT_KEYPROPS ); |
_("Key Properties"), IDS_WINPT_KEYPROPS); |
|
if (k.callback.new_val != 0) { |
|
|
t = get_key_trust_str (k.callback.new_val); |
|
|
listview_add_sub_item (kmi->lv, kmi->lv_idx, 6, t); |
|
|
} |
|
1583 |
if (k.update) |
if (k.update) |
1584 |
refresh_keylist (kmi); |
update_key (kmi->lv, kmi->lv_idx, k.tmp_keyid, k.key_pair); |
1585 |
return TRUE; |
return TRUE; |
1586 |
|
|
1587 |
case ID_KEYMISC_RECACHE: |
case ID_KEYMISC_RECACHE: |
1595 |
"Do you really want to reload the keycache?")); |
"Do you really want to reload the keycache?")); |
1596 |
l_idx = msg_box (dlg, inf, _("Key Manager"), MB_YESNO); |
l_idx = msg_box (dlg, inf, _("Key Manager"), MB_YESNO); |
1597 |
} |
} |
1598 |
if (l_idx == IDYES) { |
if (l_idx == IDYES) |
1599 |
rcs.kr_reload = rcs.kr_update = 1; |
reload_keycache (kmi); |
|
rcs.tr_update = 0; |
|
|
DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYCACHE, dlg, |
|
|
keycache_dlg_proc, (LPARAM)&rcs); |
|
|
c = keycache_get_ctx (1); |
|
|
if (!c) |
|
|
BUG (dlg); |
|
|
keylist_reload (kmi->lv, c, KEYLIST_LIST, KEY_SORT_USERID); |
|
|
} |
|
|
SetForegroundWindow (dlg); |
|
1600 |
return TRUE; |
return TRUE; |
1601 |
|
|
1602 |
case ID_KEYMISC_REBUILD: |
case ID_KEYMISC_REBUILD: |
1650 |
return TRUE; |
return TRUE; |
1651 |
|
|
1652 |
case ID_KEYMISC_GPGPREFS: |
case ID_KEYMISC_GPGPREFS: |
1653 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, dlg, |
rc = dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_GPGPREFS, |
1654 |
gpgprefs_dlg_proc, 0, _("GnuPG Preferences"), |
dlg, gpgprefs_dlg_proc, 0, |
1655 |
IDS_WINPT_GPGPREFS); |
_("GnuPG Preferences"), IDS_WINPT_GPGPREFS); |
1656 |
|
if (rc == TRUE) { |
1657 |
|
/* XXX: TRUE should indicate a value changed. */ |
1658 |
|
reload_keycache (kmi); |
1659 |
|
} |
1660 |
return TRUE; |
return TRUE; |
1661 |
|
|
1662 |
case ID_KEYMISC_GPGOPT: |
case ID_KEYMISC_GPGOPT: |
1666 |
return TRUE; |
return TRUE; |
1667 |
|
|
1668 |
case ID_KEYMISC_IMPORT: |
case ID_KEYMISC_IMPORT: |
1669 |
t = get_fileopen_dlg (dlg, _("Choose Name of the Key File"), |
km_gui_import (kmi, LOWORD (wparam)); |
|
NULL, NULL); |
|
|
if (!t) |
|
|
break; |
|
|
if (!km_file_import (dlg, t, &i)) { |
|
|
if (i < KM_PRELOAD_KEYS) |
|
|
refresh_keylist (kmi); |
|
|
else /* avoid to spawn too much processes. */ |
|
|
reload_keylist (kmi); |
|
|
} |
|
1670 |
return TRUE; |
return TRUE; |
1671 |
|
|
1672 |
case ID_KEYMISC_IMPORT_HTTP: |
case ID_KEYMISC_IMPORT_HTTP: |
1781 |
break; |
break; |
1782 |
|
|
1783 |
case ID_KEYMISC_PASTE: |
case ID_KEYMISC_PASTE: |
1784 |
if (!km_clip_import (dlg, &i)) { |
km_gui_import (kmi, LOWORD (wparam)); |
|
if (i < KM_PRELOAD_KEYS) |
|
|
refresh_keylist (kmi); |
|
|
else |
|
|
reload_keylist (kmi); |
|
|
} |
|
1785 |
break; |
break; |
1786 |
|
|
1787 |
case ID_KEYCTX_SETPREFKS: |
case ID_KEYCTX_SETPREFKS: |
1906 |
|
|
1907 |
case ID_KEYCTX_RECVFROM: |
case ID_KEYCTX_RECVFROM: |
1908 |
km_refresh_from_keyserver (kmi->lv, dlg); |
km_refresh_from_keyserver (kmi->lv, dlg); |
1909 |
|
if (updated_keys_avail ()) |
1910 |
|
refresh_keylist (kmi); |
1911 |
|
else |
1912 |
|
msg_box (NULL, "no updates", "", MB_OK); |
1913 |
break; |
break; |
1914 |
|
|
1915 |
case ID_KEYCTX_UID_COPY: |
case ID_KEYCTX_UID_COPY: |