[Gpa-commits] r954 - trunk/src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Feb 25 18:42:15 CET 2009
Author: werner
Date: 2009-02-25 18:42:08 +0100 (Wed, 25 Feb 2009)
New Revision: 954
Modified:
trunk/src/ChangeLog
trunk/src/cm-openpgp.c
trunk/src/gpa.h
trunk/src/utils.c
Log:
Now that scdaemon works again, we can save the name fields.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2009-02-24 14:19:00 UTC (rev 953)
+++ trunk/src/ChangeLog 2009-02-25 17:42:08 UTC (rev 954)
@@ -1,3 +1,9 @@
+2009-02-25 Werner Koch <wk at g10code.com>
+
+ * cm-openpgp.c (save_attr): New.
+
+ * utils.c (percent_escape): New.
+
2009-02-24 Werner Koch <wk at g10code.com>
* cardman.c (scd_inq_cb): Adjust for changed gpgme API.
Modified: trunk/src/cm-openpgp.c
===================================================================
--- trunk/src/cm-openpgp.c 2009-02-24 14:19:00 UTC (rev 953)
+++ trunk/src/cm-openpgp.c 2009-02-25 17:42:08 UTC (rev 954)
@@ -27,6 +27,7 @@
#include <assert.h>
#include "gpa.h"
+#include "gtktools.h"
#include "convert.h"
#include "cm-object.h"
@@ -368,6 +369,44 @@
}
+static void
+save_attr (GpaCMOpenpgp *card, const char *name, const char *value)
+{
+ gpg_error_t err;
+ char *command;
+ char *p;
+ gpgme_ctx_t gpgagent;
+
+ g_return_if_fail (*name && value);
+
+ gpgagent = GPA_CM_OBJECT (card)->agent_ctx;
+ g_return_if_fail (gpgagent);
+
+
+ p = percent_escape (value, NULL, 1);
+ command = g_strdup_printf ("SCD SETATTR %s %s", name, p);
+ xfree (p);
+
+ err = gpgme_op_assuan_transact (gpgagent,
+ command,
+ NULL, NULL,
+ NULL, NULL,
+ NULL, NULL);
+ if (!err)
+ err = gpgme_op_assuan_result (gpgagent)->err;
+
+ if (err)
+ {
+ char *message = g_strdup_printf
+ (_("Error saving the changed values.\n"
+ "(%s <%s>)"), gpg_strerror (err), gpg_strsource (err));
+ gpa_window_error (message, NULL);
+ xfree (message);
+ }
+ xfree (command);
+}
+
+
/* Check the constraints for NAME and return a string with an error
description or NULL if the name is fine. */
static const char *
@@ -397,12 +436,17 @@
{
const char *first, *last;
const char *errstr;
+ int failed = ENTRY_FIRST_NAME;
first = gtk_entry_get_text (GTK_ENTRY (card->entries[ENTRY_FIRST_NAME]));
last = gtk_entry_get_text (GTK_ENTRY (card->entries[ENTRY_LAST_NAME]));
errstr = check_one_name (first);
if (!errstr)
- errstr = check_one_name (last);
+ {
+ errstr = check_one_name (last);
+ if (errstr)
+ failed = ENTRY_LAST_NAME;
+ }
if (!errstr)
{
char *buffer, *p;
@@ -415,18 +459,20 @@
errstr = _("Total length of first and last name "
"may not be longer than 39 characters.");
else
- {
- g_debug ("Saving name `%s'", buffer);
- }
+ save_attr (card, "DISP-NAME", buffer);
g_free (buffer);
}
if (errstr)
- show_edit_error (card, errstr);
+ {
+ show_edit_error (card, errstr);
+ gtk_widget_grab_focus (GTK_WIDGET (card->entries[failed]));
+ }
return !!errstr;
}
+
static gpg_error_t
save_entry_sex (GpaCMOpenpgp *card)
{
Modified: trunk/src/gpa.h
===================================================================
--- trunk/src/gpa.h 2009-02-24 14:19:00 UTC (rev 953)
+++ trunk/src/gpa.h 2009-02-25 17:42:08 UTC (rev 954)
@@ -128,7 +128,10 @@
char *decode_c_string (const char *src);
+char *percent_escape (const char *string,
+ const char *delimiters, int space2plus);
+
/*-- Convenience macros. -- */
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
#define DIMof(type,member) DIM(((type *)0)->member)
Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c 2009-02-24 14:19:00 UTC (rev 953)
+++ trunk/src/utils.c 2009-02-25 17:42:08 UTC (rev 954)
@@ -32,6 +32,9 @@
#include "gpa.h"
+#define tohex_lower(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'a'))
+
+
/* We want our usual xmalloc function. */
void *
xmalloc (size_t n)
@@ -246,3 +249,63 @@
return buffer;
}
+
+/* Percent-escape all characters from the set in DELIMITERS in STRING.
+ If SPACE2PLUS is true, spaces (0x20) are converted to plus signs
+ and PLUS signs are percent escaped. If DELIMITERS is NULL all
+ characters less or equal than 0x20 are escaped. However if
+ SPACE2PLUS istrue spaces are still converted to plus signs.
+ Returns a newly allocated string. */
+char *
+percent_escape (const char *string, const char *delimiters, int space2plus)
+{
+ const unsigned char *s;
+ size_t needed;
+ char *buffer, *ptr;
+
+ if (!delimiters)
+ delimiters = ("\x20\x02\x03\x04\x05\x06\x07\x08"
+ "\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10"
+ "\x11\x12\x13\x14\x15\x16\x17\x18"
+ "\x19\x1a\x1b\x1c\x1d\x1e\x1f\x01");
+
+ for (s=(const unsigned char*)string, needed=0; *s; s++, needed++)
+ if (*s == '%'
+ || (space2plus && *s == '+')
+ || strchr (delimiters, *s))
+ needed += 2;
+
+ buffer = g_malloc (needed + 1);
+
+ for (s=(const unsigned char *)string, ptr=buffer; *s; s++)
+ {
+ if (*s == '%')
+ {
+ *ptr++ = '%';
+ *ptr++ = '2';
+ *ptr++ = '5';
+ }
+ else if (space2plus && *s == ' ')
+ {
+ *ptr++ = '+';
+ }
+ else if (space2plus && *s == '+')
+ {
+ *ptr++ = '%';
+ *ptr++ = '2';
+ *ptr++ = 'b';
+ }
+ else if (strchr (delimiters, *s))
+ {
+ *ptr++ = '%';
+ *ptr++ = tohex_lower ((*s>>4)&15);
+ *ptr++ = tohex_lower (*s&15);
+ }
+ else
+ *ptr++ = *s;
+ }
+ *ptr = 0;
+
+ return buffer;
+}
+
More information about the Gpa-commits
mailing list