[Winpt-commits] r303 - trunk/Src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Mar 21 11:48:03 CET 2007
Author: twoaday
Date: 2007-03-21 11:48:02 +0100 (Wed, 21 Mar 2007)
New Revision: 303
Modified:
trunk/Src/ChangeLog
trunk/Src/wptGPGMEWrapper.cpp
trunk/Src/wptKeyManager.cpp
Log:
bug fix for the export problem
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2007-03-21 10:46:47 UTC (rev 302)
+++ trunk/Src/ChangeLog 2007-03-21 10:48:02 UTC (rev 303)
@@ -1,3 +1,10 @@
+2007-03-21 Timo Schulz <twoaday at gmx.net>
+
+ * wptKeyManager.cpp (gpg_keylist_to_pattern): Return allocated
+ array of strings.
+ (km_clip_export): Really export all selected keys.
+ (km_file_export): Likewise.
+
2007-03-17 Timo Schulz <twoaday at gmx.net>
* wptErrors.cpp (debug_end): Reset FP pointer.
Modified: trunk/Src/wptGPGMEWrapper.cpp
===================================================================
--- trunk/Src/wptGPGMEWrapper.cpp 2007-03-21 10:46:47 UTC (rev 302)
+++ trunk/Src/wptGPGMEWrapper.cpp 2007-03-21 10:48:02 UTC (rev 303)
@@ -138,7 +138,8 @@
}
-/* Export key pattern @patt to file @outfile.
+/* Export a single key or all keys which matches the pattern @patt
+ to file @outfile.
Return value: 0 on success. */
gpgme_error_t
GPGME::exportToFile (const char *patt, const char *outfile)
@@ -152,17 +153,41 @@
op_begin ();
err = gpgme_op_export (ctx, patt, 0, dat);
op_end ();
- if (err) {
+ if (err)
gpgme_data_release (dat);
- return err;
+ else {
+ err = gpg_data_release_and_set_file (dat, outfile);
+ if (err)
+ gpgme_data_release (dat);
}
- err = gpg_data_release_and_set_file (dat, outfile);
+
+ return err;
+}
+
+/* Export multiple keys using @pattern. */
+gpgme_error_t
+GPGME::exportToFile (const char *pattern[], const char *outfile)
+{
+ gpgme_error_t err;
+ gpgme_data_t dat;
+
+ err = gpgme_data_new (&dat);
if (err)
+ return err;
+
+ op_begin ();
+ err = gpgme_op_export_ext (ctx, pattern, 0, dat);
+ op_end ();
+ if (err)
gpgme_data_release (dat);
+ else {
+ err = gpg_data_release_and_set_file (dat, outfile);
+ if (err)
+ gpgme_data_release (dat);
+ }
+
return err;
}
-
-
/* Export key pattern @patt to the clipboard.
Return value: 0 on success. */
gpgme_error_t
@@ -177,15 +202,32 @@
op_begin ();
err = gpgme_op_export (ctx, patt, 0, dat);
op_end ();
- if (err) {
+ if (err)
gpgme_data_release (dat);
+ else
+ gpg_data_release_and_set_clipboard (dat, chg_ver? 1 : 0);
+ return err;
+}
+
+gpgme_error_t
+GPGME::exportToClipboard (const char *pattern[])
+{
+ gpgme_data_t dat;
+ gpgme_error_t err;
+
+ err = gpgme_data_new (&dat);
+ if (err)
return err;
- }
- gpg_data_release_and_set_clipboard (dat, chg_ver? 1 : 0);
+ op_begin ();
+ err = gpgme_op_export_ext (ctx, pattern, 0, dat);
+ op_end ();
+ if (err)
+ gpgme_data_release (dat);
+ else
+ gpg_data_release_and_set_clipboard (dat, chg_ver? 1: 0);
return err;
}
-
/* Export key pattern @patt to the buffer @outdata.
Return value: 0 on success. */
gpgme_error_t
Modified: trunk/Src/wptKeyManager.cpp
===================================================================
--- trunk/Src/wptKeyManager.cpp 2007-03-21 10:46:47 UTC (rev 302)
+++ trunk/Src/wptKeyManager.cpp 2007-03-21 10:48:02 UTC (rev 303)
@@ -238,21 +238,19 @@
/* Create a string that contain all keyids from
the key list @rset separated by a space. */
-char*
+char**
gpg_keylist_to_pattern (gpgme_key_t *rset, size_t n)
{
- char *p;
+ char **p;
size_t i;
if (!n)
return NULL;
- p = (char *)calloc (1, n*(16+1)+n+2);
- if (!p)
- BUG (NULL);
- for (i=0; i < n; i++) {
- strcat (p, rset[i]->subkeys->keyid);
- strcat (p, " ");
- }
+
+ p = new char*[n+1];
+ for (i=0; i < n; i++)
+ p[i] = m_strdup (rset[i]->subkeys->keyid);
+ p[n] = NULL; /* end of list marker. */
return p;
}
@@ -264,7 +262,7 @@
gpgme_error_t err;
gpgme_key_t *rset;
GPGME ctx;
- char *patt=NULL;
+ char **patt;
char buf[256];
size_t n=0;
int rc=0;
@@ -279,7 +277,7 @@
patt = gpg_keylist_to_pattern (rset, n);
ctx.setArmor (true);
- err = ctx.exportToClipboard (patt);
+ err = ctx.exportToClipboard ((const char **)patt);
if (err) {
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR);
rc = WPTERR_GENERAL;
@@ -294,7 +292,8 @@
leave:
safe_free (rset);
- safe_free (patt);
+ while (n-- > 0) delete[] patt[n];
+ delete patt;
return rc;
}
@@ -340,7 +339,7 @@
GPGME ctx;
gpgme_key_t *rset;
gpgme_error_t err;
- char *patt;
+ char **patt;
size_t n;
rset = keylist_enum_recipients (lv, KEYLIST_LIST, &n);
@@ -352,7 +351,7 @@
patt = gpg_keylist_to_pattern (rset, n);
ctx.setArmor (true);
- err = ctx.exportToFile (patt, fname);
+ err = ctx.exportToFile ((const char**)patt, fname);
if (err) {
msg_box (dlg, gpgme_strerror (err), _("Key Manager"), MB_ERR);
goto leave;
@@ -362,7 +361,8 @@
_("Key(s) successfully saved in '%s'."), fname);
leave:
- safe_free (patt);
+ while (n-- > 0) delete[] patt[n];
+ delete patt;
return (int)err;
}
@@ -790,7 +790,7 @@
{
gpgme_key_t key;
gpgme_error_t rc;
- GPGME *ctx;
+ GPGME ctx;
struct keycache_s *c;
char *fname, *uid;
int pos, n;
@@ -812,15 +812,13 @@
fname = new char[n+1];
get_temp_name (fname, n-5-strlen (uid)-1, uid);
strcat (fname, ".asc");
- ctx = new GPGME ();
- ctx->setArmor (true);
- rc = ctx->exportToFile (key->subkeys->keyid, fname);
+ ctx.setArmor (true);
+ rc = ctx.exportToFile (key->subkeys->keyid, fname);
if (rc)
msg_box (dlg, gpgme_strerror (rc), _("Key Manager"), MB_ERR);
else
mapi_send_pubkey (key->subkeys->keyid+8, fname);
- delete ctx;
free_if_alloc (fname);
free_if_alloc (uid);
return rc;
More information about the Winpt-commits
mailing list