56 |
int |
int |
57 |
hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern) |
hkp_send_key (HWND dlg, const char *kserver, u16 port, const char *pattern) |
58 |
{ |
{ |
59 |
gpgme_ctx_t c; |
gpgme_ctx_t c; |
|
gpgme_recipients_t rset; |
|
60 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
61 |
gpgme_error_t ec; |
gpgme_error_t ec; |
62 |
char *rawkey = NULL, msg[1024]; |
char *rawkey = NULL, msg[1024]; |
63 |
|
size_t n; |
64 |
int rc; |
int rc; |
65 |
|
|
|
ec = gpgme_recipients_new( &rset ); |
|
|
if( ec ) |
|
|
BUG( NULL ); |
|
|
gpgme_recipients_add_name( rset, pattern ); |
|
66 |
ec = gpgme_new( &c ); |
ec = gpgme_new( &c ); |
67 |
if( ec ) |
if( ec ) |
68 |
BUG( NULL ); |
BUG( NULL ); |
69 |
gpgme_control( c, GPGME_CTRL_ARMOR, 1 ); |
gpgme_set_armor (c, 1); |
70 |
ec = gpgme_data_new( &keydata ); |
ec = gpgme_data_new( &keydata ); |
71 |
if( ec ) |
if( ec ) |
72 |
BUG( NULL ); |
BUG( NULL ); |
73 |
rc = (int) gpgme_op_export( c, rset, keydata ); |
rc = (int) gpgme_op_export( c, pattern, 0, keydata ); |
74 |
if( rc ) { |
if( rc ) { |
75 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Export"), MB_ERR ); |
76 |
goto leave; |
goto leave; |
77 |
} |
} |
78 |
rawkey = gpgme_data_release_and_return_string (keydata); |
rawkey = gpgme_data_release_and_get_mem (keydata, &n); |
79 |
|
rawkey[n] = 0; |
80 |
rc = kserver_sendkey (kserver, port, rawkey, strlen (rawkey)); |
rc = kserver_sendkey (kserver, port, rawkey, strlen (rawkey)); |
81 |
if (rc) { |
if (rc) { |
82 |
hkp_err_box (dlg, kserver, port, rc); |
hkp_err_box (dlg, kserver, port, rc); |
88 |
|
|
89 |
leave: |
leave: |
90 |
gpgme_release (c); |
gpgme_release (c); |
|
gpgme_recipients_release (rset); |
|
91 |
safe_free (rawkey); |
safe_free (rawkey); |
92 |
return rc; |
return rc; |
93 |
} /* hkp_send_key */ |
} /* hkp_send_key */ |
100 |
gpgme_ctx_t ctx; |
gpgme_ctx_t ctx; |
101 |
gpgme_data_t keydata; |
gpgme_data_t keydata; |
102 |
gpgme_error_t ec; |
gpgme_error_t ec; |
103 |
int rc, import_res[14]; |
gpgme_import_result_t import_res; |
104 |
|
int rc; |
105 |
char *rawkey = NULL, msg[384]; |
char *rawkey = NULL, msg[384]; |
106 |
|
|
107 |
rawkey = new char[MAX_KEYSIZE]; |
rawkey = new char[MAX_KEYSIZE]; |
143 |
if( ec ) |
if( ec ) |
144 |
BUG( NULL ); |
BUG( NULL ); |
145 |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
gpgme_data_new_from_mem( &keydata, rawkey, strlen( rawkey ), 1 ); |
146 |
rc = gpgme_op_import( ctx, NULL, keydata ); |
rc = gpgme_op_import( ctx, keydata ); |
147 |
if( rc ) { |
if( rc ) { |
148 |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
msg_box( dlg, gpgme_strerror( (gpgme_error_t)rc ), _("Import"), MB_ERR ); |
149 |
goto leave; |
goto leave; |
150 |
} |
} |
151 |
gpgme_get_import_status (ctx, import_res, NULL); |
import_res = gpgme_op_import_result (ctx); |
152 |
} |
} |
153 |
|
|
154 |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
/* if we use the refresh mode, a lot of keys will be fetched and thus only |
155 |
a summarize at the end is presented and not for each key. */ |
a summarize at the end is presented and not for each key. */ |
156 |
if (!(flags & KM_KS_REFRESH)) { |
if (!(flags & KM_KS_REFRESH)) { |
157 |
if (import_res[GPGME_IMPSTAT_NPKEYS] == 0) { |
if (import_res->new_user_ids == 0) { |
158 |
_snprintf (msg, DIM (msg)-1, |
_snprintf (msg, DIM (msg)-1, |
159 |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
_("Key '%s' successfully received but nothing was changed."), pattern ); |
160 |
status_box (dlg, msg, _("GnuPG Status")); |
status_box (dlg, msg, _("GnuPG Status")); |
363 |
#endif |
#endif |
364 |
set_proxy (dlg); |
set_proxy (dlg); |
365 |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
keyserver_list_build (&lv, GetDlgItem (dlg, IDC_KEYSERVER_LIST)); |
366 |
center_window (dlg); |
center_window (dlg, NULL); |
367 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
368 |
return TRUE; |
return TRUE; |
369 |
|
|