[svn] dirmngr - r320 - in trunk: . doc po src

svn author wk cvs at cvs.gnupg.org
Fri Jul 31 15:10:43 CEST 2009


Author: wk
Date: 2009-07-31 15:10:43 +0200 (Fri, 31 Jul 2009)
New Revision: 320

Modified:
   trunk/NEWS
   trunk/doc/dirmngr.texi
   trunk/po/de.po
   trunk/po/dirmngr.pot
   trunk/src/ChangeLog
   trunk/src/crlfetch.c
   trunk/src/dirmngr-client.c
   trunk/src/estream-printf.c
   trunk/src/estream.c
   trunk/src/estream.h
   trunk/src/http.c
   trunk/src/http.h
   trunk/src/server.c
Log:
Streamlined the http code.
Allow to debug HTTP header lines.
Extend dirmngr-client.


[The diff below has been truncated]

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/src/ChangeLog	2009-07-31 13:10:43 UTC (rev 320)
@@ -1,3 +1,22 @@
+2009-07-31  Werner Koch  <wk at g10code.com>
+
+	* server.c (cmd_loadcrl): Add option --url.
+	* dirmngr-client.c (do_loadcrl): Make use of --url.
+
+	* crlfetch.c (crl_fetch): Remove HTTP_FLAG_NO_SHUTDOWN.  Add
+	flag HTTP_FLAG_LOG_RESP with active DBG_LOOKUP.
+
+	* http.c: Require estream.  Remove P_ES macro.
+	(write_server): Remove.
+	(my_read_line): Remove.  Replace all callers by es_read_line.
+	(send_request): Use es_asprintf.  Always store the cookie.
+	(http_wait_response): Remove the need to dup the socket.  USe new
+	shutdown flag.
+	* http.h (HTTP_FLAG_NO_SHUTDOWN): Rename to HTTP_FLAG_SHUTDOWN.
+
+	* estream.c, estream.h, estream-printf.c, estream-printf.h: Update
+	from current libestream.  This is provide es_asprintf.
+
 2009-07-20  Werner Koch  <wk at g10code.com>
 
 	* dirmngr.c (pid_suffix_callback): New.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/NEWS	2009-07-31 13:10:43 UTC (rev 320)
@@ -1,7 +1,11 @@
 Noteworthy changes in version 1.0.4
 ------------------------------------------------
 
+ * Fixed a resource problem with LDAP CRLs.
 
+ * Made "dirmngr-client --url --load-crl URL" work.
+
+
 Noteworthy changes in version 1.0.3 (2009-06-17)
 ------------------------------------------------
 

Modified: trunk/doc/dirmngr.texi
===================================================================
--- trunk/doc/dirmngr.texi	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/doc/dirmngr.texi	2009-07-31 13:10:43 UTC (rev 320)
@@ -281,7 +281,8 @@
 @opindex fetch-crl
 This command requires an URL as additional argument, and it will make
 dirmngr try to retrieve an import the CRL from that @var{url} into
-it's cache.  This is mainly useful for debugging purposes.
+it's cache.  This is mainly useful for debugging purposes.  The
+ at command{dirmngr-client} provides the same feature for a running dirmngr.
 
 @item --shutdown
 @opindex shutdown
@@ -999,7 +1000,9 @@
 @item --load-crl
 @opindex load-crl
 This command expects a list of filenames with DER encoded CRL files.
-All CRL will be validated and then loaded into dirmngr's cache.
+With the option @option{--url} URLs are expected in palce of filenames
+and they are loaded directly from the given location.  All CRLs will be
+validated and then loaded into dirmngr's cache.
 
 @item --lookup
 @opindex lookup
@@ -1011,7 +1014,7 @@
 @item --url
 @itemx -u
 @opindex url
-Modify the @command{lookup} command to take an URL and not a pattern. 
+Modify the @command{lookup} and @command{load-crl} commands to take an URL.
 
 @item --local
 @itemx -l

Modified: trunk/po/de.po  [not shown]
Modified: trunk/po/dirmngr.pot
===================================================================
--- trunk/po/dirmngr.pot	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/po/dirmngr.pot	2009-07-31 13:10:43 UTC (rev 320)
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: gpa-dev at gnupg.org\n"
-"POT-Creation-Date: 2009-06-17 15:10+0200\n"
+"POT-Creation-Date: 2009-07-31 13:57+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL at ADDRESS>\n"
 "Language-Team: LANGUAGE <LL at li.org>\n"
@@ -16,7 +16,7 @@
 "Content-Type: text/plain; charset=CHARSET\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: jnlib/logging.c:628
+#: jnlib/logging.c:642
 #, c-format
 msgid "you found a bug ... (%s:%d)\n"
 msgstr ""
@@ -51,7 +51,7 @@
 msgid "can't access directory `%s': %s\n"
 msgstr ""
 
-#: src/certcache.c:390 src/crlcache.c:2367 src/dirmngr.c:1433
+#: src/certcache.c:390 src/crlcache.c:2367 src/dirmngr.c:1458
 #, c-format
 msgid "can't open `%s': %s\n"
 msgstr ""
@@ -245,7 +245,7 @@
 msgstr ""
 
 #: src/crlcache.c:649 src/crlcache.c:654 src/crlcache.c:908 src/crlcache.c:914
-#: src/dirmngr.c:1379
+#: src/dirmngr.c:1404
 #, c-format
 msgid "error reading `%s': %s\n"
 msgstr ""
@@ -606,7 +606,7 @@
 msgid "End CRL dump\n"
 msgstr ""
 
-#: src/crlcache.c:2376 src/crlfetch.c:213 src/ldap.c:656
+#: src/crlcache.c:2376 src/crlfetch.c:213 src/ldap.c:685
 #, c-format
 msgid "error initializing reader object: %s\n"
 msgstr ""
@@ -822,211 +822,211 @@
 #. TRANSLATORS: @EMAIL@ will get replaced by the actual bug
 #. reporting address.  This is so that we can change the
 #. reporting address without breaking the translations.
-#: src/dirmngr.c:266 src/dirmngr-client.c:149 src/dirmngr_ldap.c:148
+#: src/dirmngr.c:273 src/dirmngr-client.c:149 src/dirmngr_ldap.c:148
 msgid "Please report bugs to <@EMAIL@>.\n"
 msgstr ""
 
-#: src/dirmngr.c:269
+#: src/dirmngr.c:276
 msgid "Usage: dirmngr [options] (-h for help)"
 msgstr ""
 
-#: src/dirmngr.c:271
+#: src/dirmngr.c:278
 msgid ""
 "Syntax: dirmngr [options] [command [args]]\n"
 "LDAP and OCSP access for GnuPG\n"
 msgstr ""
 
-#: src/dirmngr.c:346
+#: src/dirmngr.c:353
 #, c-format
 msgid "invalid debug-level `%s' given\n"
 msgstr ""
 
-#: src/dirmngr.c:347
+#: src/dirmngr.c:354
 #, c-format
 msgid "valid debug levels are: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:385
+#: src/dirmngr.c:392
 msgid "usage: dirmngr [options] "
 msgstr ""
 
-#: src/dirmngr.c:410
+#: src/dirmngr.c:417
 #, c-format
 msgid "error spawning ldap wrapper reaper thread: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:622 src/dirmngr.c:632
+#: src/dirmngr.c:638 src/dirmngr.c:648
 #, c-format
 msgid "%s is too old (need %s, have %s)\n"
 msgstr ""
 
-#: src/dirmngr.c:735
+#: src/dirmngr.c:760
 #, c-format
 msgid "NOTE: no default option file `%s'\n"
 msgstr ""
 
-#: src/dirmngr.c:740 src/dirmngr.c:1539
+#: src/dirmngr.c:765 src/dirmngr.c:1564
 #, c-format
 msgid "option file `%s': %s\n"
 msgstr ""
 
-#: src/dirmngr.c:748
+#: src/dirmngr.c:773
 #, c-format
 msgid "reading options from `%s'\n"
 msgstr ""
 
-#: src/dirmngr.c:850
+#: src/dirmngr.c:875
 #, c-format
 msgid "WARNING: running with faked system time %s\n"
 msgstr ""
 
-#: src/dirmngr.c:933
+#: src/dirmngr.c:958
 msgid "colons are not allowed in the socket name\n"
 msgstr ""
 
-#: src/dirmngr.c:939
+#: src/dirmngr.c:964
 msgid "name of socket too long\n"
 msgstr ""
 
-#: src/dirmngr.c:946
+#: src/dirmngr.c:971
 #, c-format
 msgid "can't create socket: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:965
+#: src/dirmngr.c:990
 msgid "error getting nonce for the socket\n"
 msgstr ""
 
-#: src/dirmngr.c:968
+#: src/dirmngr.c:993
 #, c-format
 msgid "error binding socket to `%s': %s\n"
 msgstr ""
 
-#: src/dirmngr.c:977
+#: src/dirmngr.c:1002
 #, c-format
 msgid "listen() failed: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:983
+#: src/dirmngr.c:1008
 #, c-format
 msgid "listening on socket `%s'\n"
 msgstr ""
 
-#: src/dirmngr.c:994
+#: src/dirmngr.c:1019
 #, c-format
 msgid "fork failed: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:1012
+#: src/dirmngr.c:1037
 msgid "out of core\n"
 msgstr ""
 
-#: src/dirmngr.c:1051
+#: src/dirmngr.c:1076
 #, c-format
 msgid "setsid() failed: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:1061
+#: src/dirmngr.c:1086
 #, c-format
 msgid "chdir to / failed: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:1131
+#: src/dirmngr.c:1156 src/server.c:1102
 #, c-format
 msgid "fetching CRL from `%s' failed: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:1137
+#: src/dirmngr.c:1162 src/server.c:1108
 #, c-format
 msgid "processing CRL from `%s' failed: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:1341
+#: src/dirmngr.c:1366
 #, c-format
 msgid "error opening `%s': %s\n"
 msgstr ""
 
-#: src/dirmngr.c:1356
+#: src/dirmngr.c:1381
 #, c-format
 msgid "%s:%u: line too long - skipped\n"
 msgstr ""
 
-#: src/dirmngr.c:1411 src/dirmngr.c:1495
+#: src/dirmngr.c:1436 src/dirmngr.c:1520
 #, c-format
 msgid "%s:%u: invalid fingerprint detected\n"
 msgstr ""
 
-#: src/dirmngr.c:1447 src/dirmngr.c:1473
+#: src/dirmngr.c:1472 src/dirmngr.c:1498
 #, c-format
 msgid "%s:%u: read error: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:1502
+#: src/dirmngr.c:1527
 #, c-format
 msgid "%s:%u: garbage at end of line ignored\n"
 msgstr ""
 
-#: src/dirmngr.c:1572
+#: src/dirmngr.c:1597
 msgid "SIGHUP received - re-reading configuration and flushing caches\n"
 msgstr ""
 
-#: src/dirmngr.c:1586
+#: src/dirmngr.c:1611
 msgid "SIGUSR2 received - no action defined\n"
 msgstr ""
 
-#: src/dirmngr.c:1591 src/dirmngr.c:1628
+#: src/dirmngr.c:1616 src/dirmngr.c:1653
 msgid "SIGTERM received - shutting down ...\n"
 msgstr ""
 
-#: src/dirmngr.c:1593
+#: src/dirmngr.c:1618
 #, c-format
 msgid "SIGTERM received - still %d active connections\n"
 msgstr ""
 
-#: src/dirmngr.c:1598 src/dirmngr.c:1631
+#: src/dirmngr.c:1623 src/dirmngr.c:1656
 msgid "shutdown forced\n"
 msgstr ""
 
-#: src/dirmngr.c:1606
+#: src/dirmngr.c:1631
 msgid "SIGINT received - immediate shutdown\n"
 msgstr ""
 
-#: src/dirmngr.c:1613
+#: src/dirmngr.c:1638
 #, c-format
 msgid "signal %d received - no action defined\n"
 msgstr ""
 
-#: src/dirmngr.c:1647
+#: src/dirmngr.c:1672
 #, c-format
 msgid "error reading nonce on fd %d: %s\n"
 msgstr ""
 
-#: src/dirmngr.c:1668
+#: src/dirmngr.c:1697
 #, c-format
 msgid "handler for fd %d started\n"
 msgstr ""
 
-#: src/dirmngr.c:1673
+#: src/dirmngr.c:1702
 #, c-format
 msgid "handler for fd %d terminated\n"
 msgstr ""
 
-#: src/dirmngr.c:1752
+#: src/dirmngr.c:1785
 #, c-format
 msgid "accept failed: %s - waiting 1s\n"
 msgstr ""
 
-#: src/dirmngr.c:1778
+#: src/dirmngr.c:1811
 #, c-format
 msgid "error spawning connection handler: %s\n"
 msgstr ""
 
-#: src/http.c:1643
+#: src/http.c:1471
 #, c-format
 msgid "error creating socket: %s\n"
 msgstr ""
 
-#: src/http.c:1687
+#: src/http.c:1515
 msgid "host not found"
 msgstr ""
 
@@ -1050,57 +1050,57 @@
 msgid "error printing log line: %s\n"
 msgstr ""
 
-#: src/ldap.c:269
+#: src/ldap.c:270
 #, c-format
 msgid "pth_event failed: %s\n"
 msgstr ""
 
-#: src/ldap.c:289
+#: src/ldap.c:290
 #, c-format
 msgid "pth_wait failed: %s\n"
 msgstr ""
 
-#: src/ldap.c:319
+#: src/ldap.c:320
 #, c-format
 msgid "error reading log from ldap wrapper %d: %s\n"
 msgstr ""
 
-#: src/ldap.c:349
+#: src/ldap.c:352
 #, c-format
 msgid "ldap wrapper %d ready: timeout\n"
 msgstr ""
 
-#: src/ldap.c:350
+#: src/ldap.c:353
 #, c-format
 msgid "ldap wrapper %d ready"
 msgstr ""
 
-#: src/ldap.c:357
+#: src/ldap.c:361
 #, c-format
 msgid "waiting for ldap wrapper %d failed: %s\n"
 msgstr ""
 
-#: src/ldap.c:368
+#: src/ldap.c:373
 #, c-format
 msgid "ldap wrapper %d stalled - killing\n"
 msgstr ""
 
-#: src/ldap.c:433 src/ldap.c:454
+#: src/ldap.c:462 src/ldap.c:483
 #, c-format
 msgid "reading from ldap wrapper %d failed: %s\n"
 msgstr ""
 
-#: src/ldap.c:623
+#: src/ldap.c:652
 #, c-format
 msgid "error allocating memory: %s\n"
 msgstr ""
 
-#: src/ldap.c:1189
+#: src/ldap.c:1218
 #, c-format
 msgid "start_cert_fetch: invalid pattern `%s'\n"
 msgstr ""
 
-#: src/ldap.c:1395
+#: src/ldap.c:1424
 msgid "ldap_search hit the size limit of the server\n"
 msgstr ""
 
@@ -1305,12 +1305,12 @@
 msgstr ""
 
 #: src/server.c:575 src/server.c:689 src/server.c:774 src/server.c:1069
-#: src/server.c:1097 src/server.c:1123 src/server.c:1176 src/server.c:1245
+#: src/server.c:1129 src/server.c:1155 src/server.c:1208 src/server.c:1277
 #, c-format
 msgid "command %s failed: %s\n"
 msgstr ""
 
-#: src/server.c:660 src/server.c:748 src/server.c:1156 src/server.c:1209
+#: src/server.c:660 src/server.c:748 src/server.c:1188 src/server.c:1241
 #, c-format
 msgid "assuan_inquire failed: %s\n"
 msgstr ""
@@ -1340,31 +1340,31 @@
 msgid "max_replies %d exceeded\n"
 msgstr ""
 
-#: src/server.c:1119
+#: src/server.c:1151
 msgid "no data stream"
 msgstr ""
 
-#: src/server.c:1311
+#: src/server.c:1343
 #, c-format
 msgid "can't allocate control structure: %s\n"
 msgstr ""
 
-#: src/server.c:1334
+#: src/server.c:1366
 #, c-format
 msgid "failed to initialize the server: %s\n"
 msgstr ""
 
-#: src/server.c:1342
+#: src/server.c:1374
 #, c-format
 msgid "failed to the register commands with Assuan: %s\n"
 msgstr ""
 
-#: src/server.c:1385
+#: src/server.c:1417
 #, c-format
 msgid "Assuan accept problem: %s\n"
 msgstr ""
 
-#: src/server.c:1405
+#: src/server.c:1437
 #, c-format
 msgid "Assuan processing failed: %s\n"
 msgstr ""
@@ -1563,7 +1563,7 @@
 "not valid and other error codes for general failures\n"
 msgstr ""
 
-#: src/dirmngr-client.c:285 src/dirmngr-client.c:997
+#: src/dirmngr-client.c:285 src/dirmngr-client.c:1005
 #, c-format
 msgid "error reading certificate from stdin: %s\n"
 msgstr ""
@@ -1596,15 +1596,15 @@
 msgid "validation of certificate failed: %s\n"
 msgstr ""
 
-#: src/dirmngr-client.c:404 src/dirmngr-client.c:1008
+#: src/dirmngr-client.c:404 src/dirmngr-client.c:1016
 msgid "certificate is valid\n"
 msgstr ""
 
-#: src/dirmngr-client.c:410 src/dirmngr-client.c:1016
+#: src/dirmngr-client.c:410 src/dirmngr-client.c:1024
 msgid "certificate has been revoked\n"
 msgstr ""
 
-#: src/dirmngr-client.c:415 src/dirmngr-client.c:1018
+#: src/dirmngr-client.c:415 src/dirmngr-client.c:1026
 #, c-format
 msgid "certificate check failed: %s\n"
 msgstr ""
@@ -1650,11 +1650,11 @@
 msgid "unsupported inquiry `%s'\n"
 msgstr ""
 
-#: src/dirmngr-client.c:899
+#: src/dirmngr-client.c:906
 msgid "absolute file name expected\n"
 msgstr ""
 
-#: src/dirmngr-client.c:941
+#: src/dirmngr-client.c:949
 #, c-format
 msgid "looking up `%s'\n"
 msgstr ""

Modified: trunk/src/crlfetch.c
===================================================================
--- trunk/src/crlfetch.c	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/src/crlfetch.c	2009-07-31 13:10:43 UTC (rev 320)
@@ -187,8 +187,8 @@
       else
         err = http_open_document (&hd, url, NULL,
                                   (opt.honor_http_proxy? HTTP_FLAG_TRY_PROXY:0)
-                                  |HTTP_FLAG_NO_SHUTDOWN
-                                  |HTTP_FLAG_NEED_HEADER, 
+                                  |HTTP_FLAG_NEED_HEADER
+                                  |(DBG_LOOKUP? HTTP_FLAG_LOG_RESP:0), 
                                   opt.http_proxy, NULL);
 
       switch ( err? 99999 : http_get_status_code (hd) )

Modified: trunk/src/dirmngr-client.c
===================================================================
--- trunk/src/dirmngr-client.c	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/src/dirmngr-client.c	2009-07-31 13:10:43 UTC (rev 320)
@@ -883,38 +883,46 @@
   const char *s;
   char *fname, *line, *p;
 
-#ifdef HAVE_CANONICALIZE_FILE_NAME
-  fname = canonicalize_file_name (filename);
-  if (!fname)
+  if (opt.url)
     {
-      log_error ("error canonicalizing `%s': %s\n",
-                 filename, strerror (errno));
-      return gpg_error (GPG_ERR_GENERAL);
-    }      
-#else
-  fname = xstrdup (filename);
-#endif
-  if (*fname != '/')
-    {
-      log_error (_("absolute file name expected\n"));
-      return gpg_error (GPG_ERR_GENERAL);
+      line = xmalloc (8+6+ strlen (filename) + 1);
+      strcpy (stpcpy (line, "LOADCRL --url "), filename?filename:"");
     }
-
-  line = xmalloc (8+ strlen (fname) * 3 + 1);
-  p = stpcpy (line, "LOADCRL ");
-  for (s = fname; *s; s++)
+  else
     {
-      if (*s < ' ' || *s == '+')
+#ifdef HAVE_CANONICALIZE_FILE_NAME
+      fname = canonicalize_file_name (filename);
+      if (!fname)
         {
-          sprintf (p, "%%%02X", *s);
-          p += 3;
+          log_error ("error canonicalizing `%s': %s\n",
+                     filename, strerror (errno));
+          return gpg_error (GPG_ERR_GENERAL);
+        }      
+#else
+      fname = xstrdup (filename);
+#endif
+      if (*fname != '/')
+        {
+          log_error (_("absolute file name expected\n"));
+          return gpg_error (GPG_ERR_GENERAL);
         }
-      else if (*s == ' ')
-        *p++ = '+';
-      else
-        *p++ = *s;
+      
+      line = xmalloc (8+ strlen (fname) * 3 + 1);
+      p = stpcpy (line, "LOADCRL ");
+      for (s = fname; *s; s++)
+        {
+          if (*s < ' ' || *s == '+')
+            {
+              sprintf (p, "%%%02X", *s);
+              p += 3;
+            }
+          else if (*s == ' ')
+            *p++ = '+';
+          else
+            *p++ = *s;
+        }
+      *p = 0;
     }
-  *p = 0;
 
   err = assuan_transact (ctx, line, NULL, NULL,
                         NULL, NULL,

Modified: trunk/src/estream-printf.c
===================================================================
--- trunk/src/estream-printf.c	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/src/estream-printf.c	2009-07-31 13:10:43 UTC (rev 320)
@@ -1,5 +1,5 @@
 /* estream-printf.c - Versatile C-99 compliant printf formatting
- * Copyright (C) 2007, 2008 g10 Code GmbH
+ * Copyright (C) 2007, 2008, 2009 g10 Code GmbH
  *
  * This file is part of Libestream.
  *
@@ -34,6 +34,7 @@
 
   Missing stuff:  wchar and wint_t
                   thousands_sep in pr_float.
+
 */
 
 #ifdef HAVE_CONFIG_H
@@ -54,22 +55,21 @@
 #ifdef HAVE_LANGINFO_THOUSANDS_SEP
 #include <langinfo.h>
 #endif
-#ifdef TEST
-# include <locale.h>
-#else
-# ifdef _ESTREAM_PRINTF_EXTRA_INCLUDE
-#  include _ESTREAM_PRINTF_EXTRA_INCLUDE
-# endif
+#ifdef _ESTREAM_PRINTF_EXTRA_INCLUDE
+# include _ESTREAM_PRINTF_EXTRA_INCLUDE
 #endif
 #include "estream-printf.h"
 
+/* #define DEBUG 1 */
+
+
 /* Allow redefinition of asprintf used malloc functions.  */
-#if defined(_ESTREAM_PRINTF_MALLOC) && !defined(TEST)
+#if defined(_ESTREAM_PRINTF_MALLOC)
 #define my_printf_malloc(a) _ESTREAM_PRINTF_MALLOC((a))  
 #else
 #define my_printf_malloc(a) malloc((a))
 #endif
-#if defined(_ESTREAM_PRINTF_FREE) && !defined(TEST)
+#if defined(_ESTREAM_PRINTF_FREE)
 #define my_printf_free(a)   _ESTREAM_PRINTF_FREE((a))  
 #else
 #define my_printf_free(a)   free((a))
@@ -257,9 +257,7 @@
 typedef struct valueitem_s *valueitem_t;
 
 
-#ifdef TEST
-static int verbose; 
-
+#ifdef DEBUG
 static void
 dump_argspecs (argspec_t arg, size_t argcount)
 {
@@ -281,7 +279,7 @@
              arg->width_pos,
              arg->precision_pos);
 }
-#endif /*TEST*/
+#endif /*DEBUG*/
 
 
 /* Set the vt field for ARG.  */
@@ -995,7 +993,7 @@
   int use_dbl = 0;
 #endif
   double afloat;
-  char numbuf[200];
+  char numbuf[350];
   char formatstr[20];
   char *p, *pend;
   size_t n;
@@ -1482,8 +1480,7 @@
   if (max_pos < 0 || max_pos >= strlen (format))
     goto leave_einval;
 
-#ifdef TEST
-  if (verbose > 1)
+#ifdef DEBUG
     dump_argspecs (argspecs, argspecs_len);
 #endif
 
@@ -1787,324 +1784,3 @@
 }
 
 
-#ifdef TEST
-
-static int
-one_test (const char *format, ...)
-{
-#ifdef _WIN32
-  {
-    static int show;
-
-    if (!show)
-      {
-        /* We do not have a system vasprintf.  */
-        printf ("one-test: disabled under W32\n");
-        show = 1;
-      }
-  }
-#else    
-  int rc1, rc2;
-  va_list arg_ptr;
-  char *buf1, *buf2;
-
-  if (verbose)
-    printf ("format: ->%s<-\n", format);
-
-  va_start (arg_ptr, format);
-  rc1 = vasprintf (&buf1, format, arg_ptr);
-  va_end (arg_ptr);
-  if (rc1 == -1)
-    {
-      printf ("   sys: errno=%d (%s)\n", errno, strerror (errno));
-      buf1 = NULL;
-    }
-  else if (verbose)
-    printf ("   sys: ->%s<-\n", buf1);
-  
-  va_start (arg_ptr, format);
-  rc2 = estream_vasprintf (&buf2, format, arg_ptr);
-  va_end (arg_ptr);
-  if (rc2 == -1)
-    printf ("   our: errno=%d (%s)\n", errno, strerror (errno));
-  else if (verbose)
-    printf ("   our: ->%s<-\n", buf2);
-
-  if (rc1 != -1 && rc2 != -1 && strcmp (buf1, buf2))
-    printf ("error: output does not match\n"
-            "format: ->%s<-\n   sys: ->%s<-\n   our: ->%s<-\n",
-            format, buf1, buf2);
-  else if ( rc1 != rc2 )
-    printf ("error: return codes are different: sys_rc=%d our_rc=%d\n",
-            rc1, rc2);
-
-  free (buf2);
-  free (buf1);
-#endif
-  return 0;
-}
-
-
-static void
-run_tests (void)
-{
-  /*one_test ("%d %% %'d", 17, 19681977);*/
-
-  one_test ("%d %% %d", 17, 768114563);
-  one_test ("%d %% %d", 17, -768114563);
-
-  one_test ("%d", 17);
-  one_test ("%4d", 17);
-  one_test ("%40d", 17);
-  one_test ("%-d", 17);
-  one_test ("%-4d", 17);
-  one_test ("%-140d", 17);
-  one_test ("%d", -17);
-  one_test ("%4d", -17);
-  one_test ("%40d", -17);
-  one_test ("%-d", -17);
-  one_test ("%-4d", -17);
-  one_test ("%-40d", -17);
-
-  one_test ("%+4d", 17);
-  one_test ("%+4d", -17);
-  one_test ("%-+4d", 17);
-  one_test ("%-+4d", -17);
-  one_test ("% 4d", 17);
-  one_test ("% 4d", -17);
-  one_test ("%- +4d", 17);
-  one_test ("%- +4d", -17);
-
-  one_test ("%.4d", 17);
-  one_test ("%.0d", 17);
-  one_test ("%.0d", 0);
-  one_test ("%.4d", -17);
-  one_test ("%.0d", -17);
-  one_test ("%6.4d", 17);
-  one_test ("%6.4d", -17);
-  one_test ("%6.0d", 0);
-  one_test ("%4.6d", 17);
-  one_test ("%4.6d", -17);
-
-  one_test ("% 4.6d", 17);
-  one_test ("% 6.0d", 0);
-
-  one_test ("%.4d", 17);
-  one_test ("%04d", 17);
-  one_test ("%.4d", -17);
-  one_test ("%04d", -17);
-  one_test ("%0.d", 0);
-
-  one_test ("%*d", 7, 42);
-  one_test ("%*d", -7, 42);
-  one_test ("%.*d", 7, 42);
-  one_test ("%.*d", -7, 42);
-  one_test ("%*.*d", 10, 7, 42);
-  one_test ("%*.*d", 10, -7, 42);
-  one_test ("%*.*d", -10, 7, 42);
-  one_test ("%*.*d", -10, -7, 42);
-
-  one_test ("%*x", 7, 42);
-  one_test ("%*x", -7, 42);
-  one_test ("%.*x", 7, 42);
-  one_test ("%.*x", -7, 42);
-  one_test ("%*.*x", 10, 7, 42);
-  one_test ("%*.*x", 10, -7, 42);
-  one_test ("%*.*x", -10, 7, 42);
-  one_test ("%*.*x", -10, -7, 42);
-  one_test ("%#*x", 7, 42);
-  one_test ("%#*x", -7, 42);
-  one_test ("%#.*x", 7, 42);
-  one_test ("%#.*x", -7, 42);
-  one_test ("%#*.*x", 10, 7, 42);
-  one_test ("%#*.*x", 10, -7, 42);
-  one_test ("%#*.*x", -10, 7, 42);
-  one_test ("%#*.*x", -10, -7, 42);
-
-  one_test ("%*X", 7, 42);
-  one_test ("%*X", -7, 42);
-  one_test ("%.*X", 7, 42);
-  one_test ("%.*X", -7, 42);
-  one_test ("%*.*X", 10, 7, 42);
-  one_test ("%*.*X", 10, -7, 42);
-  one_test ("%*.*X", -10, 7, 42);
-  one_test ("%*.*X", -10, -7, 42);
-  one_test ("%#*X", 7, 42);
-  one_test ("%#*X", -7, 42);
-  one_test ("%#.*X", 7, 42);
-  one_test ("%#.*X", -7, 42);
-  one_test ("%#*.*X", 10, 7, 42);
-  one_test ("%#*.*X", 10, -7, 42);
-  one_test ("%#*.*X", -10, 7, 42);
-  one_test ("%#*.*X", -10, -7, 42);
-
-  one_test ("%*o", 7, 42);
-  one_test ("%*o", -7, 42);
-  one_test ("%.*o", 7, 42);
-  one_test ("%.*o", -7, 42);
-  one_test ("%*.*o", 10, 7, 42);
-  one_test ("%*.*o", 10, -7, 42);
-  one_test ("%*.*o", -10, 7, 42);
-  one_test ("%*.*o", -10, -7, 42);
-  one_test ("%#*o", 7, 42);
-  one_test ("%#*o", -7, 42);
-  one_test ("%#.*o", 7, 42);
-  one_test ("%#.*o", -7, 42);
-  one_test ("%#*.*o", 10, 7, 42);
-  one_test ("%#*.*o", 10, -7, 42);
-  one_test ("%#*.*o", -10, 7, 42);
-  one_test ("%#*.*o", -10, -7, 42);
-
-  one_test ("%s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%.0s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%.10s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%.48s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%.49s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%.50s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%.51s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%48s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%49s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%50s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%51s", "the quick brown fox jumps over the lazy dogs back");
-  one_test ("%-51s", "the quick brown fox jumps over the lazy dogs back");
-
-  one_test ("/%s=", "CN");
-
-  one_test ("%f", 3.1415926535);
-  one_test ("%f", -3.1415926535);
-  one_test ("%.10f", 3.1415926535);
-  one_test ("%.2f", 3.1415926535);
-  one_test ("%.1f", 3.1415926535);
-  one_test ("%.0f", 3.1415926535);
-  one_test ("%.20f", 3.1415926535);
-  one_test ("%10.10f", 3.1415926535);
-  one_test ("%10.2f", 3.1415926535);
-  one_test ("%10.1f", 3.1415926535);
-  one_test ("%10.0f", 3.1415926535);
-  one_test ("%30.20f", 3.1415926535);
-  one_test ("%10.10f", -3.1415926535);
-  one_test ("%10.2f", -3.1415926535);
-  one_test ("%10.1f", -3.1415926535);
-  one_test ("%10.0f", -3.1415926535);
-  one_test ("%30.20f", -3.1415926535);
-
-  one_test ("%-10f", 3.1415926535);
-  one_test ("%-10.10f", 3.1415926535);
-  one_test ("%-10.2f", 3.1415926535);
-  one_test ("%-10.1f", 3.1415926535);
-  one_test ("%-10.0f", 3.1415926535);
-  one_test ("%-30.20f", 3.1415926535);
-  one_test ("%-10f", -3.1415926535);
-  one_test ("%-10.10f", -3.1415926535);
-  one_test ("%-10.2f", -3.1415926535);
-  one_test ("%-10.1f", -3.1415926535);
-  one_test ("%-10.0f", -3.1415926535);
-  one_test ("%-30.20f", -3.1415926535);
-
-  one_test ("%#.0f",  3.1415926535);
-  one_test ("%#10.0f",  3.1415926535);
-  one_test ("%#10.0f", -3.1415926535);
-  one_test ("%-#10.0f",  3.1415926535);
-  one_test ("%-#10.0f", -3.1415926535);
-
-  one_test ("%e", 3.1415926535);
-  one_test ("%g", 3.1415926535);
-
-  one_test ("%a", 1);
-  one_test ("%a", -1);
-  one_test ("%a", 3.1415926535);
-
-#ifdef HAVE_LONG_DOUBLE
-  one_test ("%La", 1);
-  one_test ("%La", -1);
-  one_test ("%La", 3.1415926535);
-#endif
-
-#ifdef __GLIBC__
-  /* "%m" is a glibc extension so this _test_ will only work on such a
-     system.  */
-  errno = ENOENT;
-  one_test ("%m");
-  errno = ENOENT;
-  one_test ("%d=%m", 17);
-  errno = ENOENT;
-  one_test ("%2$d:%m:%1$d", 42, 17);
-#endif /*__GLIBC__*/
-
-}
-
-static void
-check_snprintf (void)
-{
-  char buffer[20];
-  int rc, rc2;
-  size_t tmplen, blen, blen2;
-
-  rc = estream_snprintf (buffer, 0, "%*s", 18, "");
-  if (rc != 18)
-    printf ("rc=%d\n", rc );
-  rc = estream_snprintf (buffer, sizeof buffer, "%*s", 18, "");
-  if (rc != 18)
-    printf ("rc=%d, strlen(buffer)=%d\n", rc, (int)strlen (buffer));
-  rc = estream_snprintf (buffer, sizeof buffer, "%*s", 19, "");
-  if (rc != 19)
-    printf ("rc=%d, strlen(buffer)=%d\n", rc, (int)strlen (buffer));
-  rc = estream_snprintf (buffer, sizeof buffer, "%*s", 20, "");
-  if (rc != 20)
-    printf ("rc=%d, strlen(buffer)=%d\n", rc, (int)strlen (buffer));
-  rc = estream_snprintf (buffer, sizeof buffer, "%*s", 21, "");
-  if (rc != 21)
-    printf ("rc=%d, strlen(buffer)=%d\n", rc, (int)strlen (buffer));
-
-  for (tmplen = 0; tmplen <= sizeof buffer; tmplen++)
-    {
-      rc = estream_snprintf (buffer, tmplen, "%04d%02d%02dT%02d%02d%02d",
-                             1998, 9, 7, 16, 56, 05);
-      blen = strlen (buffer);
-      rc2 = snprintf (buffer, tmplen, "%04d%02d%02dT%02d%02d%02d",
-                     1998, 9, 7, 16, 56, 05);
-      blen2 = strlen (buffer);
-      if (rc != rc2 || blen != blen2)
-        printf ("snprintf test with len %u gives %d instead of %d (%d,%d)\n",
-                (unsigned int)tmplen, rc, rc2, blen, blen2);
-    }
-}
-
-
-
-int
-main (int argc, char **argv)
-{
-  int rc;
-
-  if (argc) {argc--; argv++; }
-
-  setlocale (LC_NUMERIC, "");
-
-  while (argc && !strcmp (*argv, "--verbose"))
-    {
-      verbose++;
-      argc--;
-      argv++;
-    }
-
-  if (!argc)
-    {
-      run_tests ();
-      check_snprintf () ;
-    }
-  else
-    {
-      rc = estream_vfprintf (stdout, argv[0], NULL);
-      fflush (stdout);
-      fprintf (stderr, "[estream_vfprintf returns: %d]\n", rc);
-    }
-
-  return 0;
-}
-#endif /*TEST*/
-/*
-Local Variables:
-compile-command: "cc -Wall -O3 -g -I.. -DHAVE_CONFIG_H -DTEST -o estream-printf estream-printf.c"
-End:
-*/

Modified: trunk/src/estream.c
===================================================================
--- trunk/src/estream.c	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/src/estream.c	2009-07-31 13:10:43 UTC (rev 320)
@@ -2892,6 +2892,45 @@
 }
 
 
+/* A variant of asprintf.  The function returns the allocated buffer
+   or NULL on error; ERRNO is set in the error case.  The caller
+   should use es_free to release the buffer.  This function actually
+   belongs into estream-printf but we put it here as a convenience
+   and because es_free is required anyway.  */
+char *
+es_asprintf (const char *ES__RESTRICT format, ...)
+{
+  int rc;
+  va_list ap;
+  char *buf;
+
+  va_start (ap, format);
+  rc = estream_vasprintf (&buf, format, ap);
+  va_end (ap);
+  if (rc < 0)
+    return NULL;
+  return buf;
+}
+
+
+/* A variant of vasprintf.  The function returns the allocated buffer
+   or NULL on error; ERRNO is set in the error case.  The caller
+   should use es_free to release the buffer.  This function actually
+   belongs into estream-printf but we put it here as a convenience
+   and because es_free is required anyway.  */
+char * 
+es_vasprintf (const char *ES__RESTRICT format, va_list ap)
+{
+  int rc;
+  char *buf;
+
+  rc = estream_vasprintf (&buf, format, ap);
+  if (rc < 0)
+    return NULL;
+  return buf;
+}
+
+
 static int
 tmpfd (void)
 {

Modified: trunk/src/estream.h
===================================================================
--- trunk/src/estream.h	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/src/estream.h	2009-07-31 13:10:43 UTC (rev 320)
@@ -292,6 +292,12 @@
 int es_vfprintf (estream_t ES__RESTRICT stream,
 		 const char *ES__RESTRICT format, va_list ap)
      _ESTREAM_GCC_A_PRINTF(2,0);
+
+char *es_asprintf (const char *ES__RESTRICT format, ...)
+     _ESTREAM_GCC_A_PRINTF(1,2);
+char *es_vasprintf (const char *ES__RESTRICT format, va_list ap)
+     _ESTREAM_GCC_A_PRINTF(1,0);
+
 int es_setvbuf (estream_t ES__RESTRICT stream,
 		char *ES__RESTRICT buf, int mode, size_t size);
 void es_setbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf);

Modified: trunk/src/http.c
===================================================================
--- trunk/src/http.c	2009-07-20 19:06:44 UTC (rev 319)
+++ trunk/src/http.c	2009-07-31 13:10:43 UTC (rev 320)
@@ -1,6 +1,6 @@
 /* http.c  -  HTTP protocol handler
  * Copyright (C) 1999, 2001, 2002, 2003, 2004,
- *               2006 Free Software Foundation, Inc.
+ *               2006, 2009  Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -23,11 +23,13 @@
 /* Simple HTTP client implementation.  We try to keep the code as
    self-contained as possible.  There are some contraints however:
 
+  - estream is required.  We now require estream because it provides a
+    very useful and portable asprintf implementation and the fopencookie
+    function.
   - stpcpy is required
   - fixme: list other requirements.
 
 
-  - With HTTP_USE_ESTREAM defined, all I/O is done through estream.
   - With HTTP_USE_GNUTLS support for https is provided (this also
     requires estream).
   - With HTTP_NO_WSASTARTUP the socket initialization is not done
@@ -114,18 +116,9 @@
                         "01234567890@"                 \
                         "!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~"
 
-/* Define a prefix to map stream functions to the estream library. */
-#ifdef HTTP_USE_ESTREAM
-#define P_ES(a)  es_ ## a
-#else
-#define P_ES(a)  a
-#endif
 #ifndef HTTP_USE_GNUTLS
 typedef void * gnutls_session_t;
 #endif
-#if defined(HTTP_USE_GNUTLS) && !defined(HTTP_USE_ESTREAM)
-#error Use of GNUTLS also requires support for Estream
-#endif
 
 static gpg_error_t do_parse_uri (parsed_uri_t uri, int only_local_part);
 static int remove_escapes (char *string);
@@ -139,11 +132,7 @@
 
 static int connect_server (const char *server, unsigned short port,
                            unsigned int flags, const char *srvtag);
-#ifndef HTTP_USE_ESTREAM
-static gpg_error_t write_server (int sock, const char *data, size_t length);
-#endif
 
-#ifdef HTTP_USE_ESTREAM
 static ssize_t cookie_read (void *cookie, void *buffer, size_t size);
 static ssize_t cookie_write (void *cookie, const void *buffer, size_t size);
 static int cookie_close (void *cookie);
@@ -160,11 +149,10 @@
 {
   int fd;  /* File descriptor or -1 if already closed. */
   gnutls_session_t tls_session;  /* TLS session context or NULL if not used. */
-  int keep_socket; /* Flag to communicate with teh close handler. */
+  int keep_socket; /* Flag to communicate with the close handler. */
 };
 typedef struct cookie_s *cookie_t;
 
-#endif /*HTTP_USE_ESTREAM*/
 
 #ifdef HTTP_USE_GNUTLS
 static gpg_error_t (*tls_callback) (http_t, gnutls_session_t, int);
@@ -187,14 +175,10 @@
   unsigned int status_code;
   int sock;
   int in_data;
-#ifdef HTTP_USE_ESTREAM
   estream_t fp_read;
   estream_t fp_write;
   void *write_cookie;
-#else /*!HTTP_USE_ESTREAM*/
-  FILE *fp_read;
-  FILE *fp_write;
-#endif /*!HTTP_USE_ESTREAM*/
+  void *read_cookie;
   void *tls_context;
   int is_http_0_9;
   parsed_uri_t uri;
@@ -351,9 +335,9 @@
       if (!hd->fp_read && !hd->fp_write && hd->sock != -1)
         sock_close (hd->sock);
       if (hd->fp_read)
-        P_ES(fclose) (hd->fp_read);
+        es_fclose (hd->fp_read);
       if (hd->fp_write)
-        P_ES(fclose) (hd->fp_write);
+        es_fclose (hd->fp_write);
       http_release_parsed_uri (hd->uri);
       xfree (hd);
     }
@@ -368,17 +352,12 @@
 {
   if (!hd->in_data)
     {
-#ifdef HTTP_USE_ESTREAM
       es_fputs ("\r\n", hd->fp_write);
       es_fflush (hd->fp_write);
-#else
-      fflush (hd->fp_write);
-      write_server (hd->sock, "\r\n", 2);
-#endif
       hd->in_data = 1;
     }
   else
-    P_ES(fflush) (hd->fp_write);
+    es_fflush (hd->fp_write);
 }
 
 
@@ -386,69 +365,45 @@
 http_wait_response (http_t hd)
 {
   gpg_error_t err;
+  cookie_t cookie;
 
   /* Make sure that we are in the data. */
   http_start_data (hd);	
 
-  /* We dup the socket, to cope with the fact that fclose closes the
-     underlying socket. In TLS mode we don't do that because we can't
-     close the socket gnutls is working on; instead we make sure that
-     the fclose won't close the socket in this case. */
-#ifdef HTTP_USE_ESTREAM
-  if (hd->write_cookie)
-    {
-      /* The write cookie is only set in the TLS case. */
-      cookie_t cookie = hd->write_cookie;
-      cookie->keep_socket = 1;
-    }
-  else
-#endif /*HTTP_USE_ESTREAM*/
-    {
-#ifndef HAVE_W32_SYSTEM
-      hd->sock = dup (hd->sock);
-#else
-      if (!DuplicateHandle (GetCurrentProcess(), hd->sock,
-			    GetCurrentProcess(), &hd->sock, 0,
-			    TRUE, DUPLICATE_SAME_ACCESS ))
-	return gpg_error_from_syserror ();
-#endif
-      if (hd->sock == -1)
-        return gpg_error_from_syserror ();
-    }
-  P_ES(fclose) (hd->fp_write);
+  cookie = hd->write_cookie;
+  if (!cookie)
+    return gpg_error (GPG_ERR_INTERNAL);
+
+  /* Close the write stream but keep the socket open.  */
+  cookie->keep_socket = 1;
+  es_fclose (hd->fp_write);
   hd->fp_write = NULL;
-#ifdef HTTP_USE_ESTREAM
   hd->write_cookie = NULL;
-#endif
 
-  if (!(hd->flags & HTTP_FLAG_NO_SHUTDOWN))
+  /* Shutdown one end of the socket is desired.  As per HTTP/1.0 this
+     is not required but some very old servers (e.g. the original pksd
+     key server didn't worked without it.  */
+  if ((hd->flags & HTTP_FLAG_SHUTDOWN))
     shutdown (hd->sock, 1);
   hd->in_data = 0;
 
-#ifdef HTTP_USE_ESTREAM
-  {
-    cookie_t cookie;
-
-    cookie = xtrycalloc (1, sizeof *cookie);
-    if (!cookie)
+  /* Create a new cookie and a stream for reading.  */
+  cookie = xtrycalloc (1, sizeof *cookie);
+  if (!cookie)
+    return gpg_error_from_syserror ();
+  cookie->fd = hd->sock;
+  if (hd->uri->use_tls)
+    cookie->tls_session = hd->tls_context;
+  
+  hd->read_cookie = cookie;
+  hd->fp_read = es_fopencookie (cookie, "r", cookie_functions);
+  if (!hd->fp_read)
+    {
+      xfree (cookie);
+      hd->read_cookie = NULL;
       return gpg_error_from_syserror ();
-    cookie->fd = hd->sock;
-    if (hd->uri->use_tls)
-      cookie->tls_session = hd->tls_context;
+    }
 
-    hd->fp_read = es_fopencookie (cookie, "r", cookie_functions);
-    if (!hd->fp_read)
-      {
-        xfree (cookie);
-        return gpg_error_from_syserror ();
-      }
-  }
-#else /*!HTTP_USE_ESTREAM*/
-  hd->fp_read = fdopen (hd->sock, "r");
-  if (!hd->fp_read)
-    return gpg_error_from_syserror ();
-#endif /*!HTTP_USE_ESTREAM*/
-
   err = parse_response (hd);
   return err;
 }
@@ -486,9 +441,9 @@
   if (!hd->fp_read && !hd->fp_write && hd->sock != -1)
     sock_close (hd->sock);
   if (hd->fp_read && !keep_read_stream)
-    P_ES(fclose) (hd->fp_read);
+    es_fclose (hd->fp_read);
   if (hd->fp_write)
-    P_ES(fclose) (hd->fp_write);
+    es_fclose (hd->fp_write);
   http_release_parsed_uri (hd->uri);
   while (hd->headers)
     {
@@ -502,29 +457,18 @@
 }
 
 
-#ifdef HTTP_USE_ESTREAM
 estream_t
 http_get_read_ptr (http_t hd)
 {
   return hd?hd->fp_read:NULL;
 }
+
 estream_t
 http_get_write_ptr (http_t hd)
 {
   return hd?hd->fp_write:NULL;
 }
-#else /*!HTTP_USE_ESTREAM*/
-FILE *
-http_get_read_ptr (http_t hd)
-{
-  return hd?hd->fp_read:NULL;
-}
-FILE *
-http_get_write_ptr (http_t hd)
-{
-  return hd?hd->fp_write:NULL;
-}
-#endif /*!HTTP_USE_ESTREAM*/
+
 unsigned int
 http_get_status_code (http_t hd)
 {
@@ -840,7 +784,9 @@
   char *proxy_authstr = NULL;
   char *authstr = NULL;
   int save_errno;
+  cookie_t cookie;
 
+
   tls_session = hd->tls_context;
   if (hd->uri->use_tls && !tls_session)
     {
@@ -973,29 +919,16 @@
   if (!p)
     return gpg_error_from_syserror ();
 
-  request = xtrymalloc (2 * strlen (server) 
-                        + strlen (p)
-                        + (authstr?strlen(authstr):0)
-                        + (proxy_authstr?strlen(proxy_authstr):0)
-                        + 100);
-  if (!request)
-    {
-      err = gpg_error_from_syserror ();
-      xfree (p);
-      xfree (authstr);
-      xfree (proxy_authstr);
-      return err;
-    }
-
   if (http_proxy && *http_proxy)
     {
-      sprintf (request, "%s http://%s:%hu%s%s HTTP/1.0\r\n%s%s",
-	       hd->req_type == HTTP_REQ_GET ? "GET" :
-	       hd->req_type == HTTP_REQ_HEAD ? "HEAD" :
-	       hd->req_type == HTTP_REQ_POST ? "POST" : "OOPS",
-	       server, port, *p == '/' ? "" : "/", p,
-	       authstr ? authstr : "",
-               proxy_authstr ? proxy_authstr : "");
+      request = es_asprintf 
+        ("%s http://%s:%hu%s%s HTTP/1.0\r\n%s%s",
+         hd->req_type == HTTP_REQ_GET ? "GET" :
+         hd->req_type == HTTP_REQ_HEAD ? "HEAD" :
+         hd->req_type == HTTP_REQ_POST ? "POST" : "OOPS",
+         server, port, *p == '/' ? "" : "/", p,
+         authstr ? authstr : "",
+         proxy_authstr ? proxy_authstr : "");
     }
   else
     {
@@ -1004,65 +937,51 @@
       if (port == 80)
         *portstr = 0;
       else
-        sprintf (portstr, ":%u", port);
+        snprintf (portstr, sizeof portstr, ":%u", port);
 
-      sprintf (request, "%s %s%s HTTP/1.0\r\nHost: %s%s\r\n%s",
-	       hd->req_type == HTTP_REQ_GET ? "GET" :
-	       hd->req_type == HTTP_REQ_HEAD ? "HEAD" :
-	       hd->req_type == HTTP_REQ_POST ? "POST" : "OOPS",
-	       *p == '/' ? "" : "/", p, server, portstr,
-               authstr? authstr:"");
+      request = es_asprintf 
+        ("%s %s%s HTTP/1.0\r\nHost: %s%s\r\n%s",
+         hd->req_type == HTTP_REQ_GET ? "GET" :
+         hd->req_type == HTTP_REQ_HEAD ? "HEAD" :
+         hd->req_type == HTTP_REQ_POST ? "POST" : "OOPS",
+         *p == '/' ? "" : "/", p, server, portstr,
+         authstr? authstr:"");
     }
   xfree (p);
+  if (!request)
+    {
+      err = gpg_error_from_syserror ();
+      xfree (authstr);
+      xfree (proxy_authstr);
+      return err;
+    }
 
-
-#ifdef HTTP_USE_ESTREAM
   /* First setup estream so that we can write even the first line
      using estream.  This is also required for the sake of gnutls. */
-  {
-    cookie_t cookie;
-
-    cookie = xtrycalloc (1, sizeof *cookie);
-    if (!cookie)
-      {
-        err = gpg_error_from_syserror ();
-        goto leave;
-      }
-    cookie->fd = hd->sock;
-    if (hd->uri->use_tls)
-      {
-        cookie->tls_session = tls_session;
-        hd->write_cookie = cookie;
-      }
-
-    hd->fp_write = es_fopencookie (cookie, "w", cookie_functions);
-    if (!hd->fp_write)
-      {
-        xfree (cookie);
-        err = gpg_error_from_syserror ();
-      }
-    else if (es_fputs (request, hd->fp_write) || es_fflush (hd->fp_write))
+  cookie = xtrycalloc (1, sizeof *cookie);
+  if (!cookie)
+    {
       err = gpg_error_from_syserror ();
-    else
-      err = 0;
-  }
-
- leave:
-
-#else /*!HTTP_USE_ESTREAM*/
-  /* We send out the start of the request through our own send
-     function and only then assign a stdio stream.  This allows for
-     better error reporting that through standard stdio means. */
-  err = write_server (hd->sock, request, strlen (request));
-  if (!err)
+      goto leave;
+    }
+  cookie->fd = hd->sock;
+  hd->write_cookie = cookie;
+  if (hd->uri->use_tls)
+    cookie->tls_session = tls_session;
+  hd->fp_write = es_fopencookie (cookie, "w", cookie_functions);
+  if (!hd->fp_write)
     {
-      hd->fp_write = fdopen (hd->sock, "w");
-      if (!hd->fp_write)
-        err = gpg_error_from_syserror ();
+      xfree (cookie);
+      hd->write_cookie = NULL;
+      err = gpg_error_from_syserror ();
     }
-#endif /*!HTTP_USE_ESTREAM*/
+  else if (es_fputs (request, hd->fp_write) || es_fflush (hd->fp_write))
+    err = gpg_error_from_syserror ();
+  else




More information about the Gnupg-commits mailing list