/* Report a GnuTLS error to the user. Return true if the error code was successfully handled. */ static bool emacs_gnutls_handle_error (gnutls_session_t session, int err) { int max_log_level = 0; bool ret; const char *str; /* TODO: use a Lisp_Object generated by gnutls_make_error? */ if (err >= 0) return 1; max_log_level = global_gnutls_log_level; /* TODO: use gnutls-error-fatalp and gnutls-error-string. */ str = fn_gnutls_strerror (err); if (!str) str = "unknown"; if (fn_gnutls_error_is_fatal (err)) { ret = 0; GNUTLS_LOG2 (0, max_log_level, "fatal error:", str); } else { ret = 1; 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 || err == GNUTLS_E_FATAL_ALERT_RECEIVED) { int alert = fn_gnutls_alert_get (session); int level = (err == GNUTLS_E_FATAL_ALERT_RECEIVED) ? 0 : 1; str = fn_gnutls_alert_get_name (alert); if (!str) str = "unknown"; GNUTLS_LOG2 (level, max_log_level, "Received alert: ", str); } return ret; }
/* report a GnuTLS error to the user. Returns zero if the error code was successfully handled. */ static int emacs_gnutls_handle_error (gnutls_session_t session, int err) { int max_log_level = 0; int ret; const char *str; /* TODO: use a Lisp_Object generated by gnutls_make_error? */ if (err >= 0) return 0; max_log_level = global_gnutls_log_level; /* TODO: use gnutls-error-fatalp and gnutls-error-string. */ str = fn_gnutls_strerror (err); if (!str) str = "unknown"; if (fn_gnutls_error_is_fatal (err)) { ret = err; GNUTLS_LOG2 (0, max_log_level, "fatal error:", str); } else { ret = 0; GNUTLS_LOG2 (1, max_log_level, "non-fatal error:", str); /* TODO: EAGAIN AKA Qgnutls_e_again should be level 2. */ } if (err == GNUTLS_E_WARNING_ALERT_RECEIVED || err == GNUTLS_E_FATAL_ALERT_RECEIVED) { int alert = fn_gnutls_alert_get (session); int level = (err == GNUTLS_E_FATAL_ALERT_RECEIVED) ? 0 : 1; str = fn_gnutls_alert_get_name (alert); if (!str) str = "unknown"; GNUTLS_LOG2 (level, max_log_level, "Received alert: ", str); } return ret; }