[svn] GnuPG - r4844 - in trunk: doc tools
svn author wk
cvs at cvs.gnupg.org
Wed Oct 1 18:17:39 CEST 2008
Author: wk
Date: 2008-10-01 18:17:39 +0200 (Wed, 01 Oct 2008)
New Revision: 4844
Modified:
trunk/doc/ChangeLog
trunk/doc/tools.texi
trunk/tools/ChangeLog
trunk/tools/gpg-connect-agent.c
Log:
Add /daatfile command to gpg-connect-agent.
Modified: trunk/doc/ChangeLog
===================================================================
--- trunk/doc/ChangeLog 2008-09-30 18:24:10 UTC (rev 4843)
+++ trunk/doc/ChangeLog 2008-10-01 16:17:39 UTC (rev 4844)
@@ -1,3 +1,7 @@
+2008-10-01 Werner Koch <wk at g10code.com>
+
+ * tools.texi (Controlling gpg-connect-agent): Describe /datafile.
+
2008-09-23 David Shaw <dshaw at jabberwocky.com>
* gpg.texi (OpenPGP Key Management): Clarify setpref a bit.
Modified: trunk/tools/ChangeLog
===================================================================
--- trunk/tools/ChangeLog 2008-09-30 18:24:10 UTC (rev 4843)
+++ trunk/tools/ChangeLog 2008-10-01 16:17:39 UTC (rev 4844)
@@ -1,3 +1,8 @@
+2008-10-01 Werner Koch <wk at 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 at g10code.com>
* gpgconf.c (main) <aListDirs>: Print the bindir.
Modified: trunk/doc/tools.texi
===================================================================
--- trunk/doc/tools.texi 2008-09-30 18:24:10 UTC (rev 4843)
+++ trunk/doc/tools.texi 2008-10-01 16:17:39 UTC (rev 4844)
@@ -1280,6 +1280,14 @@
Run @var{prog} for inquiries matching @var{name} and pass the
entire line to it as command line arguments.
+ at item /datafile @var{name}
+Write all data lines from the server to the file @var{name}. The file
+is opened for writing and created if it does not exists. An existsing
+file is first truncated to 0. The data written to the file fully
+decoded. Using a singel dash for @var{name} writes to stdout. The
+file is kept open until a new file is set using this command or this
+command is used without an argument.
+
@item /showdef
Print all definitions
Modified: trunk/tools/gpg-connect-agent.c
===================================================================
--- trunk/tools/gpg-connect-agent.c 2008-09-30 18:24:10 UTC (rev 4843)
+++ trunk/tools/gpg-connect-agent.c 2008-10-01 16:17:39 UTC (rev 4844)
@@ -137,6 +137,8 @@
/* 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 @@
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 @@
"/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 @@
"/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,8 +1898,26 @@
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; )
{
int save_i = i;
@@ -1940,7 +1984,8 @@
{
if (need_lf)
{
- putchar ('\n');
+ if (!current_datasink || current_datasink != stdout)
+ putchar ('\n');
need_lf = 0;
}
@@ -1948,15 +1993,21 @@
&& 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 @@
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 @@
&& 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 @@
&& 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
More information about the Gnupg-commits
mailing list