[svn] dirmngr - r323 - in trunk: . src

svn author wk cvs at cvs.gnupg.org
Fri Aug 7 17:40:49 CEST 2009


Author: wk
Date: 2009-08-07 17:40:49 +0200 (Fri, 07 Aug 2009)
New Revision: 323

Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/configure.ac
   trunk/src/ChangeLog
   trunk/src/crlfetch.c
   trunk/src/http.c
   trunk/src/http.h
Log:
Hanging HTTP CRL downloads are now fixed.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-08-04 13:49:17 UTC (rev 322)
+++ trunk/ChangeLog	2009-08-07 15:40:49 UTC (rev 323)
@@ -1,3 +1,7 @@
+2009-08-07  Werner Koch  <wk at g10code.com>
+
+	* configure.ac: Check for strtoull.
+
 2009-06-18  Werner Koch  <wk at g10code.com>
 
 	* configure.ac: Fix some URL hints.

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-08-04 13:49:17 UTC (rev 322)
+++ trunk/src/ChangeLog	2009-08-07 15:40:49 UTC (rev 323)
@@ -1,3 +1,16 @@
+2009-08-07  Werner Koch  <wk at g10code.com>
+
+	* crlfetch.c (my_es_read): Add explicit check for EOF.
+
+	* http.c (struct http_context_s): Turn IN_DATA and IS_HTTP_0_9 to
+	bit fields.
+	(struct cookie_s): Add CONTENT_LENGTH_VALID and CONTENT_LENGTH.
+	(parse_response): Parse the Content-Length header.
+	(cookie_read): Handle content length. 
+	(http_open): Make NEED_HEADER the semi-default.
+
+	* http.h (HTTP_FLAG_IGNORE_CL): New.
+
 2009-08-04  Werner Koch  <wk at g10code.com>
 
 	* ldap.c (ldap_wrapper_thread): Factor some code out to ...
@@ -1175,7 +1188,7 @@
 	ChangeLog.
 	
 	
- Copyright 2004, 2005, 2006, 2007, 2008 g10 Code GmbH
+ Copyright 2004, 2005, 2006, 2007, 2008, 2009 g10 Code GmbH
 
  This file is free software; as a special exception the author gives
  unlimited permission to copy and/or distribute it, with or without

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2009-08-04 13:49:17 UTC (rev 322)
+++ trunk/NEWS	2009-08-07 15:40:49 UTC (rev 323)
@@ -3,6 +3,8 @@
 
  * Fixed a resource problem with LDAP CRLs.
 
+ * Fixed a bad EOF detection with HTTP CRLs.
+
  * Made "dirmngr-client --url --load-crl URL" work.
 
 

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2009-08-04 13:49:17 UTC (rev 322)
+++ trunk/configure.ac	2009-08-07 15:40:49 UTC (rev 323)
@@ -348,10 +348,8 @@
 AC_CHECK_FUNCS([funopen fopencookie])
 # end jnlib checks
 
-AC_CHECK_FUNCS([gmtime_r])
+AC_CHECK_FUNCS([gmtime_r getaddrinfo strtoull])
 
-AC_CHECK_FUNCS([getaddrinfo])
-
 AC_CHECK_FUNCS([mmap])
 if test $ac_cv_func_mmap != yes -a $mmap_needed = yes; then
   AC_MSG_ERROR([[Sorry, the current implemenation requires mmap.]])

Modified: trunk/src/crlfetch.c
===================================================================
--- trunk/src/crlfetch.c	2009-08-04 13:49:17 UTC (rev 322)
+++ trunk/src/crlfetch.c	2009-08-07 15:40:49 UTC (rev 323)
@@ -105,6 +105,12 @@
   result = es_read (cb_ctx->fp, buffer, nbytes, nread);
   if (result)
     return result;
+  /* Fixme we should check whether the semantics of es_read are okay
+     and well defined.  I have some doubts.  */
+  if (nbytes && !*nread && es_feof (cb_ctx->fp))
+    return gpg_error (GPG_ERR_EOF);
+  if (!nread && es_ferror (cb_ctx->fp))
+    return gpg_error (GPG_ERR_EIO);
 
   if (!cb_ctx->checked && *nread)
     {
@@ -177,7 +183,7 @@
   if (!err) /* Yes, our HTTP code groks that. */
     {
       http_t hd;
-      
+
       if (opt.disable_http)
         {
           log_error (_("CRL access not possible due to disabled %s\n"),

Modified: trunk/src/http.c
===================================================================
--- trunk/src/http.c	2009-08-04 13:49:17 UTC (rev 322)
+++ trunk/src/http.c	2009-08-07 15:40:49 UTC (rev 323)
@@ -116,6 +116,15 @@
                         "01234567890@"                 \
                         "!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~"
 
+/* A long counter type.  */
+#ifdef HAVE_STRTOULL
+typedef unsigned long long longcounter_t;
+#define counter_strtoul(a) strtoull ((a), NULL, 10)
+#else
+typedef unsigned long longcounter_t;
+#define counter_strtoul(a) strtoul ((a), NULL, 10)
+#endif
+
 #ifndef HTTP_USE_GNUTLS
 typedef void * gnutls_session_t;
 #endif
@@ -149,7 +158,14 @@
 {
   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 the close handler. */
+
+  /* The remaining content length and a flag telling whether to use
+     the content length.  */
+  longcounter_t content_length;  
+  unsigned int content_length_valid:1;
+
+  /* Flag to communicate with the close handler. */
+  unsigned int keep_socket:1;
 };
 typedef struct cookie_s *cookie_t;
 
@@ -174,13 +190,13 @@
 {
   unsigned int status_code;
   int sock;
-  int in_data;
+  unsigned int in_data:1;
+  unsigned int is_http_0_9:1;
   estream_t fp_read;
   estream_t fp_write;
   void *write_cookie;
   void *read_cookie;
   void *tls_context;
-  int is_http_0_9;
   parsed_uri_t uri;
   http_req_t req_type;
   char *buffer;          /* Line buffer. */
@@ -317,6 +333,11 @@
   if (!(reqtype == HTTP_REQ_GET || reqtype == HTTP_REQ_POST))
     return gpg_error (GPG_ERR_INV_ARG);
 
+  /* Make need_header default unless ignore_cl is set.  We might want
+     to drop the need_header entirely.  */
+  if (!(flags & HTTP_FLAG_IGNORE_CL))
+    flags |= HTTP_FLAG_NEED_HEADER;
+
   /* Create the handle. */
   hd = xtrycalloc (1, sizeof *hd);
   if (!hd)
@@ -1173,6 +1194,8 @@
 {
   char *line, *p, *p2;
   size_t maxlen, len;
+  cookie_t cookie = hd->read_cookie;
+  const char *s;
 
   /* Delete old header lines.  */
   while (hd->headers)
@@ -1253,6 +1276,17 @@
     }
   while (len && *line);
 
+  cookie->content_length_valid = 0;
+  if (!(hd->flags & HTTP_FLAG_IGNORE_CL))
+    {
+      s = http_get_header (hd, "Content-Length");
+      if (s)
+        {
+          cookie->content_length_valid = 1;
+          cookie->content_length = counter_strtoul (s);
+        }
+    }
+
   return 0;
 }
 
@@ -1537,6 +1571,14 @@
   cookie_t c = cookie;
   int nread;
 
+  if (c->content_length_valid)
+    {
+      if (!c->content_length)
+        return 0; /* EOF */
+      if (c->content_length < size)
+        size = c->content_length;
+    }
+
 #ifdef HTTP_USE_GNUTLS
   if (c->tls_session)
     {
@@ -1572,6 +1614,14 @@
       while (nread == -1 && errno == EINTR);
     }
 
+  if (c->content_length_valid && nread > 0)
+    {
+      if (nread < c->content_length)
+        c->content_length -= nread;
+      else
+        c->content_length = 0;          
+    }
+
   return nread;
 }
 

Modified: trunk/src/http.h
===================================================================
--- trunk/src/http.h	2009-08-04 13:49:17 UTC (rev 322)
+++ trunk/src/http.h	2009-08-07 15:40:49 UTC (rev 323)
@@ -65,7 +65,8 @@
     HTTP_FLAG_SHUTDOWN = 2,
     HTTP_FLAG_TRY_SRV = 4,
     HTTP_FLAG_LOG_RESP = 8,
-    HTTP_FLAG_NEED_HEADER = 16
+    HTTP_FLAG_NEED_HEADER = 16,
+    HTTP_FLAG_IGNORE_CL = 32
   };
 
 struct http_context_s;




More information about the Gnupg-commits mailing list