Several GnuTLS fixes for log level and initialization.
authorTed Zlatanov <tzz@lifelogs.com>
Tue, 5 Nov 2013 02:29:03 +0000 (21:29 -0500)
committerTed Zlatanov <tzz@lifelogs.com>
Tue, 5 Nov 2013 02:29:03 +0000 (21:29 -0500)
* gnutls.c (emacs_gnutls_handle_error): Adjust log level for EAGAIN.
(Fgnutls_boot): Set process gnutls_p later, after initialization.

* process.c (wait_reading_process_output, read_process_output)
(send_process): Check gnutls_state is not NULL.

src/ChangeLog
src/gnutls.c
src/process.c

index 5f919b8..d0bdc6b 100644 (file)
@@ -1,3 +1,11 @@
+2013-11-05  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * process.c (wait_reading_process_output, read_process_output)
+       (send_process): Check gnutls_state is not NULL.
+
+       * gnutls.c (emacs_gnutls_handle_error): Adjust log level for EAGAIN.
+       (Fgnutls_boot): Set process gnutls_p later, after initialization.
+
 2013-11-04  Jan Djärv  <jan.h.d@swipnet.se>
 
        * nsterm.m (init, run, stop:): New methods in EmacsApp for
index 0ee3fca..5241c91 100644 (file)
@@ -488,8 +488,20 @@ emacs_gnutls_handle_error (gnutls_session_t session, int err)
   else
     {
       ret = 1;
-      GNUTLS_LOG2 (1, max_log_level, "non-fatal error:", str);
-      /* TODO: EAGAIN AKA Qgnutls_e_again should be level 2.  */
+
+      switch (err)
+        {
+        case GNUTLS_E_AGAIN:
+          GNUTLS_LOG2 (3,
+                       max_log_level,
+                       "retry:",
+                       str);
+        default:
+          GNUTLS_LOG2 (1,
+                       max_log_level,
+                       "non-fatal error:",
+                       str);
+        }
     }
 
   if (err == GNUTLS_E_WARNING_ALERT_RECEIVED
@@ -810,7 +822,6 @@ one trustfile (usually a CA bundle).  */)
   c_hostname = SSDATA (hostname);
 
   state = XPROCESS (proc)->gnutls_state;
-  XPROCESS (proc)->gnutls_p = 1;
 
   if (TYPE_RANGED_INTEGERP (int, loglevel))
     {
@@ -833,7 +844,6 @@ one trustfile (usually a CA bundle).  */)
   emacs_gnutls_deinit (proc);
 
   /* Mark PROC as a GnuTLS process.  */
-  XPROCESS (proc)->gnutls_p = 1;
   XPROCESS (proc)->gnutls_state = NULL;
   XPROCESS (proc)->gnutls_x509_cred = NULL;
   XPROCESS (proc)->gnutls_anon_cred = NULL;
@@ -1093,6 +1103,9 @@ one trustfile (usually a CA bundle).  */)
       fn_gnutls_x509_crt_deinit (gnutls_verify_cert);
     }
 
+  // Only set this flag if the whole initialization succeeded.
+  XPROCESS (proc)->gnutls_p = 1;
+
   return gnutls_make_error (ret);
 }
 
index f6aa576..ec4cda7 100644 (file)
@@ -4609,7 +4609,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
                      {
                        struct Lisp_Process *p =
                          XPROCESS (chan_process[channel]);
-                       if (p && p->gnutls_p && p->infd
+                       if (p && p->gnutls_p && p->gnutls_state && p->infd
                            && ((emacs_gnutls_record_check_pending
                                 (p->gnutls_state))
                                > 0))
@@ -4623,6 +4623,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
                {
                  /* Check this specific channel. */
                  if (wait_proc->gnutls_p /* Check for valid process.  */
+                      && p->gnutls_state
                      /* Do we have pending data?  */
                      && ((emacs_gnutls_record_check_pending
                           (wait_proc->gnutls_state))
@@ -5004,7 +5005,7 @@ read_process_output (Lisp_Object proc, register int channel)
          proc_buffered_char[channel] = -1;
        }
 #ifdef HAVE_GNUTLS
-      if (p->gnutls_p)
+      if (p->gnutls_p && p->gnutls_state)
        nbytes = emacs_gnutls_read (p, chars + carryover + buffered,
                                    readmax - buffered);
       else
@@ -5498,7 +5499,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
 #endif
            {
 #ifdef HAVE_GNUTLS
-             if (p->gnutls_p)
+             if (p->gnutls_p && p->gnutls_state)
                written = emacs_gnutls_write (p, cur_buf, cur_len);
              else
 #endif