summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2008-10-01 18:17:39 +0200
committerWerner Koch <wk@gnupg.org>2008-10-01 18:17:39 +0200
commitaf7c1fa13460790c933e21b96ef34665d41612ad (patch)
tree69fa81f409d19479e16a7a3e767265d820b08a1d /tools
parentFix bug #922 (diff)
downloadgnupg2-af7c1fa13460790c933e21b96ef34665d41612ad.tar.xz
gnupg2-af7c1fa13460790c933e21b96ef34665d41612ad.zip
Add /daatfile command to gpg-connect-agent.
Diffstat (limited to 'tools')
-rw-r--r--tools/ChangeLog5
-rw-r--r--tools/gpg-connect-agent.c86
2 files changed, 78 insertions, 13 deletions
diff --git a/tools/ChangeLog b/tools/ChangeLog
index 297e5eb4b..b8c90d08e 100644
--- a/tools/ChangeLog
+++ b/tools/ChangeLog
@@ -1,3 +1,8 @@
+2008-10-01 Werner Koch <wk@g10code.com>
+
+ * gpg-connect-agent.c (main): New command datafile.
+ (read_and_print_response): Print to the defined datafile.
+
2008-09-30 Werner Koch <wk@g10code.com>
* gpgconf.c (main) <aListDirs>: Print the bindir.
diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c
index 2f173f930..d48e3512b 100644
--- a/tools/gpg-connect-agent.c
+++ b/tools/gpg-connect-agent.c
@@ -137,6 +137,8 @@ typedef struct loopline_s *loopline_t;
/* This is used to store the pid of the server. */
static pid_t server_pid = (pid_t)(-1);
+/* The current datasink file or NULL. */
+static FILE *current_datasink;
/* A list of open file descriptors. */
static struct
@@ -1442,6 +1444,29 @@ main (int argc, char **argv)
else
add_definq (p, 0, 1);
}
+ else if (!strcmp (cmd, "datafile"))
+ {
+ const char *fname;
+
+ if (current_datasink)
+ {
+ if (current_datasink != stdout)
+ fclose (current_datasink);
+ current_datasink = NULL;
+ }
+ tmpline = opt.enable_varsubst? substitute_line (p) : NULL;
+ fname = tmpline? tmpline : p;
+ if (fname && !strcmp (fname, "-"))
+ current_datasink = stdout;
+ else if (fname && *fname)
+ {
+ current_datasink = fopen (fname, "wb");
+ if (!current_datasink)
+ log_error ("can't open `%s': %s\n",
+ fname, strerror (errno));
+ }
+ xfree (tmpline);
+ }
else if (!strcmp (cmd, "showdef"))
{
show_definq ();
@@ -1669,6 +1694,7 @@ main (int argc, char **argv)
"/definq NAME VAR Use content of VAR for inquiries with NAME.\n"
"/definqfile NAME FILE Use content of FILE for inquiries with NAME.\n"
"/definqprog NAME PGM Run PGM for inquiries with NAME.\n"
+"/datafile [NAME] Write all D line content to file NAME.\n"
"/showdef Print all definitions.\n"
"/cleardef Delete all definitions.\n"
"/sendfd FILE MODE Open FILE and pass descriptor to server.\n"
@@ -1679,7 +1705,7 @@ main (int argc, char **argv)
"/serverpid Retrieve the pid of the server.\n"
"/[no]hex Enable hex dumping of received data lines.\n"
"/[no]decode Enable decoding of received data lines.\n"
-"/[no]subst Enable varibale substitution.\n"
+"/[no]subst Enable variable substitution.\n"
"/run FILE Run commands from FILE.\n"
"/if VAR Begin conditional block controlled by VAR.\n"
"/while VAR Begin loop controlled by VAR.\n"
@@ -1872,7 +1898,25 @@ read_and_print_response (assuan_context_t ctx, int *r_goterr)
if (linelen >= 1
&& line[0] == 'D' && line[1] == ' ')
{
- if (opt.hex)
+ if (current_datasink)
+ {
+ const unsigned char *s;
+ int c = 0;
+
+ for (j=2, s=(unsigned char*)line+2; j < linelen; j++, s++ )
+ {
+ if (*s == '%' && j+2 < linelen)
+ {
+ s++; j++;
+ c = xtoi_2 ( s );
+ s++; j++;
+ }
+ else
+ c = *s;
+ putc (c, current_datasink);
+ }
+ }
+ else if (opt.hex)
{
for (i=2; i < linelen; )
{
@@ -1940,7 +1984,8 @@ read_and_print_response (assuan_context_t ctx, int *r_goterr)
{
if (need_lf)
{
- putchar ('\n');
+ if (!current_datasink || current_datasink != stdout)
+ putchar ('\n');
need_lf = 0;
}
@@ -1948,15 +1993,21 @@ read_and_print_response (assuan_context_t ctx, int *r_goterr)
&& line[0] == 'S'
&& (line[1] == '\0' || line[1] == ' '))
{
- fwrite (line, linelen, 1, stdout);
- putchar ('\n');
+ if (!current_datasink || current_datasink != stdout)
+ {
+ fwrite (line, linelen, 1, stdout);
+ putchar ('\n');
+ }
}
else if (linelen >= 2
&& line[0] == 'O' && line[1] == 'K'
&& (line[2] == '\0' || line[2] == ' '))
{
- fwrite (line, linelen, 1, stdout);
- putchar ('\n');
+ if (!current_datasink || current_datasink != stdout)
+ {
+ fwrite (line, linelen, 1, stdout);
+ putchar ('\n');
+ }
set_int_var ("?", 0);
return 0;
}
@@ -1970,8 +2021,11 @@ read_and_print_response (assuan_context_t ctx, int *r_goterr)
if (!errval)
errval = -1;
set_int_var ("?", errval);
- fwrite (line, linelen, 1, stdout);
- putchar ('\n');
+ if (!current_datasink || current_datasink != stdout)
+ {
+ fwrite (line, linelen, 1, stdout);
+ putchar ('\n');
+ }
*r_goterr = 1;
return 0;
}
@@ -1981,8 +2035,11 @@ read_and_print_response (assuan_context_t ctx, int *r_goterr)
&& line[6] == 'E'
&& (line[7] == '\0' || line[7] == ' '))
{
- fwrite (line, linelen, 1, stdout);
- putchar ('\n');
+ if (!current_datasink || current_datasink != stdout)
+ {
+ fwrite (line, linelen, 1, stdout);
+ putchar ('\n');
+ }
if (!handle_inquire (ctx, line))
assuan_write_line (ctx, "CANCEL");
}
@@ -1990,8 +2047,11 @@ read_and_print_response (assuan_context_t ctx, int *r_goterr)
&& line[0] == 'E' && line[1] == 'N' && line[2] == 'D'
&& (line[3] == '\0' || line[3] == ' '))
{
- fwrite (line, linelen, 1, stdout);
- putchar ('\n');
+ if (!current_datasink || current_datasink != stdout)
+ {
+ fwrite (line, linelen, 1, stdout);
+ putchar ('\n');
+ }
/* Received from server, thus more responses are expected. */
}
else