From: pdmef Date: Sat, 30 Apr 2005 19:19:01 +0000 (+0000) Subject: Rocco Rutte: X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=814a01519c9605d479201b99eb16c97b0ad8635d Rocco Rutte: - unify/simplify/cleanup/improve/whatever debug output generation - fix bug #3866 git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@281 e385b8ad-14ed-0310-8656-cc95a2468c6d --- diff --git a/alias.c b/alias.c index a41c8d8..d28427a 100644 --- a/alias.c +++ b/alias.c @@ -19,6 +19,7 @@ #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" +#include "lib/debug.h" #include #include @@ -49,10 +50,7 @@ static ADDRESS *mutt_expand_aliases_r (ADDRESS * a, LIST ** expn) i = 0; for (u = *expn; u; u = u->next) { if (safe_strcmp (a->mailbox, u->data) == 0) { /* alias already found */ - dprint (1, - (debugfile, - "mutt_expand_aliases_r(): loop in alias found for '%s'\n", - a->mailbox)); + debug_print(1, ("loop in alias found for '%s'\n", a->mailbox)); i = 1; break; } @@ -487,59 +485,44 @@ int mutt_addr_is_user (ADDRESS * addr) { /* NULL address is assumed to be the user. */ if (!addr) { - dprint (5, (debugfile, "mail_addr_is_user: yes, NULL address\n")); + debug_print(5, ("yes, NULL address\n")); return 1; } if (!addr->mailbox) { - dprint (5, (debugfile, "mail_addr_is_user: no, no mailbox\n")); + debug_print(5, ("no, no mailbox\n")); return 0; } if (ascii_strcasecmp (addr->mailbox, Username) == 0) { - dprint (5, - (debugfile, "mail_addr_is_user: yes, %s = %s\n", addr->mailbox, - Username)); + debug_print(5, ("yes, %s = %s\n", addr->mailbox, Username)); return 1; } if (string_is_address (addr->mailbox, Username, Hostname)) { - dprint (5, - (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", - addr->mailbox, Username, Hostname)); + debug_print(5, ("yes, %s = %s @ %s \n", addr->mailbox, Username, Hostname)); return 1; } if (string_is_address (addr->mailbox, Username, mutt_fqdn (0))) { - dprint (5, - (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", - addr->mailbox, Username, mutt_fqdn (0))); + debug_print(5, ("yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (0))); return 1; } if (string_is_address (addr->mailbox, Username, mutt_fqdn (1))) { - dprint (5, - (debugfile, "mail_addr_is_user: yes, %s = %s @ %s \n", - addr->mailbox, Username, mutt_fqdn (1))); + debug_print(5, ("yes, %s = %s @ %s \n", addr->mailbox, Username, mutt_fqdn (1))); return 1; } if (From && !ascii_strcasecmp (From->mailbox, addr->mailbox)) { - dprint (5, - (debugfile, "mail_addr_is_user: yes, %s = %s\n", addr->mailbox, - From->mailbox)); + debug_print(5, ("yes, %s = %s\n", addr->mailbox, From->mailbox)); return 1; } if (rx_list_match (Alternates, addr->mailbox)) { - dprint (5, - (debugfile, "mail_addr_is_user: yes, %s matched by alternates.\n", - addr->mailbox)); + debug_print(5, ("yes, %s matched by alternates.\n", addr->mailbox)); if (rx_list_match (UnAlternates, addr->mailbox)) - dprint (5, - (debugfile, - "mail_addr_is_user: but, %s matched by unalternates.\n", - addr->mailbox)); + debug_print(5, ("but, %s matched by unalternates.\n", addr->mailbox)); else return 1; } - dprint (5, (debugfile, "mail_addr_is_user: no, all failed.\n")); + debug_print(5, ("no, all failed.\n")); return 0; } diff --git a/attach.c b/attach.c index 57d4bb3..725fa96 100644 --- a/attach.c +++ b/attach.c @@ -26,6 +26,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -97,8 +98,7 @@ int mutt_compose_attachment (BODY * a) strfcpy (command, entry->composecommand, sizeof (command)); if (rfc1524_expand_filename (entry->nametemplate, a->filename, newfile, sizeof (newfile))) { - dprint (1, (debugfile, "oldfile: %s\t newfile: %s\n", - a->filename, newfile)); + debug_print (1, ("oldfile: %s\t newfile: %s\n", a->filename, newfile)); if (safe_symlink (a->filename, newfile) == -1) { if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) != M_YES) @@ -219,8 +219,7 @@ int mutt_edit_attachment (BODY * a) strfcpy (command, entry->editcommand, sizeof (command)); if (rfc1524_expand_filename (entry->nametemplate, a->filename, newfile, sizeof (newfile))) { - dprint (1, (debugfile, "oldfile: %s\t newfile: %s\n", - a->filename, newfile)); + debug_print (1, ("oldfile: %s\t newfile: %s\n", a->filename, newfile)); if (safe_symlink (a->filename, newfile) == -1) { if (mutt_yesorno (_("Can't match nametemplate, continue?"), M_YES) != M_YES) @@ -327,8 +326,7 @@ void mutt_check_lookup_list (BODY * b, char *type, int len) n == TYPEMULTIPART ? "multipart" : n == TYPETEXT ? "text" : n == TYPEVIDEO ? "video" : "other", tmp.subtype); - dprint (1, (debugfile, "mutt_check_lookup_list: \"%s\" -> %s\n", - b->filename, type)); + debug_print (1, ("\"%s\" -> %s\n", b->filename, type)); } if (tmp.subtype) FREE (&tmp.subtype); @@ -891,7 +889,7 @@ int mutt_print_attachment (FILE * fp, BODY * a) rfc1524_entry *entry; int piped = FALSE; - dprint (2, (debugfile, "Using mailcap...\n")); + debug_print (2, ("Using mailcap...\n")); entry = rfc1524_new_entry (); rfc1524_mailcap_lookup (a, type, entry, M_PRINT); @@ -971,8 +969,7 @@ int mutt_print_attachment (FILE * fp, BODY * a) mutt_mktemp (newfile); if (mutt_decode_save_attachment (fp, a, newfile, M_PRINTING, 0) == 0) { - dprint (2, - (debugfile, "successfully decoded %s type attachment to %s\n", + debug_print (2, ("successfully decoded %s type attachment to %s\n", type, newfile)); if ((ifp = fopen (newfile, "r")) == NULL) { @@ -980,7 +977,7 @@ int mutt_print_attachment (FILE * fp, BODY * a) goto bail0; } - dprint (2, (debugfile, "successfully opened %s read-only\n", newfile)); + debug_print (2, ("successfully opened %s read-only\n", newfile)); mutt_endwin (NULL); if ((thepid = @@ -990,7 +987,7 @@ int mutt_print_attachment (FILE * fp, BODY * a) goto bail0; } - dprint (2, (debugfile, "Filter created.\n")); + debug_print (2, ("Filter created.\n")); mutt_copy_stream (ifp, fpout); diff --git a/color.c b/color.c index 69e444e..9270516 100644 --- a/color.c +++ b/color.c @@ -18,6 +18,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -245,8 +246,7 @@ int mutt_alloc_color (int fg, int bg) init_pair (i, fg, bg); - dprint (1, (debugfile, "mutt_alloc_color(): Color pairs used so far: %d\n", - UserColors)); + debug_print (1, ("Color pairs used so far: %d\n", UserColors)); return (COLOR_PAIR (p->index)); } @@ -263,9 +263,7 @@ void mutt_free_color (int fg, int bg) return; UserColors--; - dprint (1, - (debugfile, "mutt_free_color(): Color pairs used so far: %d\n", - UserColors)); + debug_print (1, ("Color pairs used so far: %d\n", UserColors)); if (p == ColorList) { ColorList = ColorList->next; @@ -417,9 +415,7 @@ _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data, if (!safe_strcmp (buf->data, tmp->pattern)) { if (!do_cache) do_cache = 1; - dprint (1, - (debugfile, "Freeing pattern \"%s\" from ColorIndexList\n", - tmp->pattern)); + debug_print (1, ("Freeing pattern \"%s\" from ColorIndexList\n", tmp->pattern)); if (last) last->next = tmp->next; else diff --git a/commands.c b/commands.c index a5255d5..13d26e2 100644 --- a/commands.c +++ b/commands.c @@ -38,6 +38,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -810,7 +811,7 @@ int mutt_update_list_file (char *filename, char *section, char *key, int ext = 0, done = 0, r = 0; snprintf (oldfile, sizeof (oldfile), "%s.bak", filename); - dprint (1, (debugfile, "Renaming %s to %s\n", filename, oldfile)); + debug_print (1, ("Renaming %s to %s\n", filename, oldfile)); /* if file not exist, create it */ if ((ifp = safe_fopen (filename, "a"))) @@ -820,13 +821,13 @@ int mutt_update_list_file (char *filename, char *section, char *key, return (-1); } - dprint (1, (debugfile, "Opening %s\n", oldfile)); + debug_print (1, ("Opening %s\n", oldfile)); if (!(ifp = safe_fopen (oldfile, "r"))) { mutt_perror (_("Unable to open backup file for reading")); return (-1); } - dprint (1, (debugfile, "Opening %s\n", filename)); + debug_print (1, ("Opening %s\n", filename)); if (!(ofp = safe_fopen (filename, "w"))) { fclose (ifp); mutt_perror (_("Unable to open new file for writing")); diff --git a/complete.c b/complete.c index b0c96cf..77cc117 100644 --- a/complete.c +++ b/complete.c @@ -21,6 +21,7 @@ #endif #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -47,7 +48,7 @@ int mutt_complete (char *s, size_t slen) char imap_path[LONG_STRING]; #endif - dprint (2, (debugfile, "mutt_complete: completing %s\n", s)); + debug_print (2, ("completing %s\n", s)); #ifdef USE_NNTP if (option (OPTNEWS)) { @@ -167,9 +168,7 @@ int mutt_complete (char *s, size_t slen) } if (dirp == NULL) { - dprint (1, - (debugfile, "mutt_complete(): %s: %s (errno %d).\n", exp_dirpart, - strerror (errno), errno)); + debug_print (1, ("%s: %s (errno %d).\n", exp_dirpart, strerror (errno), errno)); return (-1); } diff --git a/compress.c b/compress.c index b7439f6..79ead4e 100644 --- a/compress.c +++ b/compress.c @@ -18,6 +18,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -230,7 +231,7 @@ int mutt_open_read_compressed (CONTEXT * ctx) cmd = get_compression_cmd (ci->open, ctx); if (cmd == NULL) return (-1); - dprint (2, (debugfile, "DecompressCmd: '%s'\n", cmd)); + debug_print (2, ("DecompressCmd: '%s'\n", cmd)); if ((fp = fopen (ctx->realpath, "r")) == NULL) { mutt_perror (ctx->realpath); @@ -318,8 +319,7 @@ int mutt_open_append_compressed (CONTEXT * ctx) /* close a compressed mailbox */ void mutt_fast_close_compressed (CONTEXT * ctx) { - dprint (2, (debugfile, "mutt_fast_close_compressed called on '%s'\n", - ctx->path)); + debug_print (2, ("called on '%s'\n", ctx->path)); if (ctx->compressinfo) { if (ctx->fp) @@ -368,7 +368,7 @@ int mutt_sync_compressed (CONTEXT * ctx) return (-1); } - dprint (2, (debugfile, "CompressCommand: '%s'\n", cmd)); + debug_print (2, ("CompressCommand: '%s'\n", cmd)); endwin (); fflush (stdout); @@ -400,8 +400,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx) char *cmd; COMPRESS_INFO *ci = (COMPRESS_INFO *) ctx->compressinfo; - dprint (2, (debugfile, "mutt_slow_close_compressed called on '%s'\n", - ctx->path)); + debug_print (2, ("called on '%s'\n", ctx->path)); if (!(ctx->append && ((append = get_append_command (ctx->realpath, ctx)) || (append = ci->close)))) { /* if we can not or should not append, @@ -442,7 +441,7 @@ int mutt_slow_close_compressed (CONTEXT * ctx) return (-1); } - dprint (2, (debugfile, "CompressCmd: '%s'\n", cmd)); + debug_print (2, ("CompressCmd: '%s'\n", cmd)); endwin (); fflush (stdout); diff --git a/configure.in b/configure.in index aad23c2..a64271a 100644 --- a/configure.in +++ b/configure.in @@ -735,8 +735,10 @@ dnl -- end socket -- AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [Enable debugging support]), [ if test x$enableval = xyes ; then AC_DEFINE(DEBUG,1,[ Define to enable debugging info. ]) + want_debug=yes fi ]) +AM_CONDITIONAL(WANT_DEBUG, test x$want_debug = xyes) AC_ARG_ENABLE(flock, AC_HELP_STRING([--enable-flock], [Use flock() to lock files]), [if test $enableval = yes; then diff --git a/copy.c b/copy.c index 63de716..87f41c6 100644 --- a/copy.c +++ b/copy.c @@ -21,6 +21,7 @@ #include "lib/mem.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -116,12 +117,12 @@ mutt_copy_hdr (FILE * in, FILE * out, long off_start, long off_end, int flags, */ if (flags & CH_REORDER) { for (t = HeaderOrderList; t; t = t->next) { - dprint (1, (debugfile, "Reorder list: %s\n", t->data)); + debug_print (1, ("Reorder list: %s\n", t->data)); hdr_count++; } } - dprint (1, (debugfile, "WEED is %s\n", (flags & CH_WEED) ? "Set" : "Not")); + debug_print (1, ("WEED is %s\n", (flags & CH_WEED) ? "Set" : "Not")); headers = safe_calloc (hdr_count, sizeof (char *)); @@ -198,7 +199,7 @@ mutt_copy_hdr (FILE * in, FILE * out, long off_start, long off_end, int flags, if (flags & CH_REORDER) { for (t = HeaderOrderList, x = 0; (t); t = t->next, x++) { if (!ascii_strncasecmp (buf, t->data, safe_strlen (t->data))) { - dprint (2, (debugfile, "Reorder: %s matches %s\n", t->data, buf)); + debug_print (2, ("Reorder: %s matches %s\n", t->data, buf)); break; } } @@ -208,8 +209,7 @@ mutt_copy_hdr (FILE * in, FILE * out, long off_start, long off_end, int flags, } /* If beginning of header */ if (!ignore) { - dprint (2, - (debugfile, "Reorder: x = %d; hdr_count = %d\n", x, hdr_count)); + debug_print (2, ("Reorder: x = %d; hdr_count = %d\n", x, hdr_count)); if (!this_one) this_one = safe_strdup (buf); else { @@ -682,7 +682,7 @@ mutt_copy_message (FILE * fpout, CONTEXT * src, HEADER * hdr, int flags, _mutt_copy_message (fpout, msg->fp, hdr, hdr->content, flags, chflags)) == 0 && (ferror (fpout) || feof (fpout))) { - dprint (1, (debugfile, "_mutt_copy_message failed to detect EOF!\n")); + debug_print (1, ("_mutt_copy_message failed to detect EOF!\n")); r = -1; } mx_close_message (&msg); diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 5bae449..e3dd337 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -30,6 +30,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -1311,7 +1312,7 @@ static int verify_one (BODY * sigbdy, STATE * s, gpgme_release (ctx); state_attach_puts (_("[-- End signature information --]\n\n"), s); - dprint (1, (debugfile, "verify_one: returning %d.\n", badsig)); + debug_print (1, ("returning %d.\n", badsig)); return badsig ? 1 : anywarn ? 2 : 0; } @@ -1778,7 +1779,7 @@ void pgp_gpgme_application_handler (BODY * m, STATE * s) char body_charset[STRING]; /* Only used for clearsigned messages. */ - dprint (2, (debugfile, "Entering pgp_application_pgp handler\n")); + debug_print (2, ("Entering pgp_application_pgp handler\n")); /* For clearsigned messages we won't be able to get a character set but we know that this may only be text thus we assume Latin-1 @@ -1983,7 +1984,7 @@ void pgp_gpgme_application_handler (BODY * m, STATE * s) " of PGP message! --]\n\n"), s); return; } - dprint (2, (debugfile, "Leaving pgp_application_pgp handler\n")); + debug_print (2, ("Leaving pgp_application_pgp handler\n")); } /* @@ -1999,7 +2000,7 @@ void pgp_gpgme_encrypted_handler (BODY * a, STATE * s) BODY *orig_body = a; int is_signed; - dprint (2, (debugfile, "Entering pgp_encrypted handler\n")); + debug_print (2, ("Entering pgp_encrypted handler\n")); a = a->parts; if (!a || a->type != TYPEAPPLICATION || !a->subtype || ascii_strcasecmp ("pgp-encrypted", a->subtype) @@ -2064,7 +2065,7 @@ void pgp_gpgme_encrypted_handler (BODY * a, STATE * s) fclose (fpout); mutt_unlink (tempfile); - dprint (2, (debugfile, "Leaving pgp_encrypted handler\n")); + debug_print (2, ("Leaving pgp_encrypted handler\n")); } /* Support for application/smime */ @@ -2076,7 +2077,7 @@ void smime_gpgme_application_handler (BODY * a, STATE * s) int is_signed; - dprint (2, (debugfile, "Entering smime_encrypted handler\n")); + debug_print (2, ("Entering smime_encrypted handler\n")); a->warnsig = 0; mutt_mktemp (tempfile); @@ -2133,7 +2134,7 @@ void smime_gpgme_application_handler (BODY * a, STATE * s) fclose (fpout); mutt_unlink (tempfile); - dprint (2, (debugfile, "Leaving smime_encrypted handler\n")); + debug_print (2, ("Leaving smime_encrypted handler\n")); } @@ -3455,16 +3456,13 @@ static crypt_key_t *crypt_getkeybyaddr (ADDRESS * a, short abilities, if (!keys) return NULL; - dprint (5, (debugfile, "crypt_getkeybyaddr: looking for %s <%s>.", - a->personal, a->mailbox)); + debug_print (5, ("looking for %s <%s>.\n", a->personal, a->mailbox)); for (k = keys; k; k = k->next) { - dprint (5, (debugfile, " looking at key: %s `%.15s'\n", - crypt_keyid (k), k->uid)); + debug_print (5, (" looking at key: %s `%.15s'\n", crypt_keyid (k), k->uid)); if (abilities && !(k->flags & abilities)) { - dprint (5, (debugfile, " insufficient abilities: Has %x, want %x\n", - k->flags, abilities)); + debug_print (5, (" insufficient abilities: Has %x, want %x\n", k->flags, abilities)); continue; } @@ -3568,8 +3566,7 @@ static crypt_key_t *crypt_getkeybystr (char *p, short abilities, continue; match = 0; - dprint (5, (debugfile, "crypt_getkeybystr: matching \"%s\" against " - "key %s, \"%s\": ", p, crypt_keyid (k), k->uid)); + debug_print (5, ("matching \"%s\" against " "key %s, \"%s\":\n", p, crypt_keyid (k), k->uid)); if (!*p || !safe_strcasecmp (p, crypt_keyid (k)) || (!safe_strncasecmp (p, "0x", 2) @@ -3580,7 +3577,7 @@ static crypt_key_t *crypt_getkeybystr (char *p, short abilities, || str_isstr (k->uid, p)) { crypt_key_t *tmp; - dprint (5, (debugfile, "match.\n")); + debug_print (5, ("match.\n")); *matches_endp = tmp = crypt_copy_key (k); matches_endp = &tmp->next; diff --git a/curs_lib.c b/curs_lib.c index 043db6e..d987b51 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -24,6 +24,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -293,7 +294,7 @@ void mutt_curses_error (const char *fmt, ...) vsnprintf (Errorbuf, sizeof (Errorbuf), fmt, ap); va_end (ap); - dprint (1, (debugfile, "%s\n", Errorbuf)); + debug_print (1, ("%s\n", Errorbuf)); mutt_format_string (TmpErrorbuf, sizeof (TmpErrorbuf), 0, COLS - 2, 0, 0, Errorbuf, sizeof (Errorbuf), 0); snprintf (Errorbuf, sizeof (Errorbuf), "%s", TmpErrorbuf); /* overkill */ @@ -365,8 +366,7 @@ void _mutt_perror (const char *s, const char* filename, int line) { char *p = strerror (errno); - dprint (1, (debugfile, "%s: %s (errno = %d)\n", s, - p ? p : "unknown error", errno)); + debug_print (1, ("%s: %s (errno = %d)\n", s, p ? p : "unknown error", errno)); mutt_error ("%s: %s (errno = %d) from %s:%i", s, p ? p : _("unknown error"), errno, filename, line); } diff --git a/curs_main.c b/curs_main.c index 8cf1dff..757b006 100644 --- a/curs_main.c +++ b/curs_main.c @@ -41,6 +41,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -597,8 +598,7 @@ int mutt_index_menu (void) op = km_dokey (MENU_MAIN); - dprint (4, - (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op)); + debug_print (4, ("Got op %d\n", op)); #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM) if (SigWinch) { diff --git a/from.c b/from.c index 23cc264..e3d2ad3 100644 --- a/from.c +++ b/from.c @@ -16,6 +16,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -71,7 +72,7 @@ int is_from (const char *s, char *path, size_t pathlen, time_t * tp) if (!*s) return 0; - dprint (3, (debugfile, "\nis_from(): parsing: %s", s)); + debug_print (3, ("parsing: %s\n", s)); if (!is_day_name (s)) { const char *p; @@ -97,7 +98,7 @@ int is_from (const char *s, char *path, size_t pathlen, time_t * tp) len = pathlen - 1; memcpy (path, s, len); path[len] = 0; - dprint (3, (debugfile, "is_from(): got return path: %s\n", path)); + debug_print (3, ("got return path: %s\n", path)); } s = p + 1; @@ -106,7 +107,7 @@ int is_from (const char *s, char *path, size_t pathlen, time_t * tp) return 0; if (!is_day_name (s)) { - dprint (1, (debugfile, "is_from(): expected weekday, got: %s\n", s)); + debug_print (1, ("expected weekday, got: %s\n", s)); return 0; } } @@ -174,9 +175,7 @@ int is_from (const char *s, char *path, size_t pathlen, time_t * tp) return 0; tm.tm_year = yr > 1900 ? yr - 1900 : (yr < 70 ? yr + 100 : yr); - dprint (3, - (debugfile, - "is_from(): month=%d, day=%d, hr=%d, min=%d, sec=%d, yr=%d.\n", + debug_print (3, ("month=%d, day=%d, hr=%d, min=%d, sec=%d, yr=%d.\n", tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_year)); diff --git a/globals.h b/globals.h index 9ce99fb..f938fe1 100644 --- a/globals.h +++ b/globals.h @@ -283,13 +283,6 @@ WHERE char *SmimeGetCertCommand; WHERE char *SmimeImportCertCommand; WHERE char *SmimeGetCertEmailCommand; - - -#ifdef DEBUG -WHERE FILE *debugfile INITVAL (0); -WHERE int debuglevel INITVAL (0); -#endif - #ifdef MAIN_C const char *Weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; const char *Months[] = diff --git a/gnupgparse.c b/gnupgparse.c index 257220f..30e73e2 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -42,6 +42,7 @@ #include "lib/mem.h" #include "lib/str.h" +#include "lib/debug.h" /**************** * Read the GNUPG keys. For now we read the complete keyring by @@ -115,7 +116,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) if (!*buf) return NULL; - dprint (2, (debugfile, "parse_pub_line: buf = `%s'\n", buf)); + debug_print (2, ("buf = `%s'\n", buf)); for (p = buf; p; p = pend) { if ((pend = strchr (p, ':'))) @@ -127,7 +128,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) switch (field) { case 1: /* record type */ { - dprint (2, (debugfile, "record type: %s\n", p)); + debug_print (2, ("record type: %s\n", p)); if (!safe_strcmp (p, "pub")); else if (!safe_strcmp (p, "sub")) @@ -147,7 +148,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) } case 2: /* trust info */ { - dprint (2, (debugfile, "trust info: %s\n", p)); + debug_print (2, ("trust info: %s\n", p)); switch (*p) { /* look only at the first letter */ case 'e': @@ -181,7 +182,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) case 3: /* key length */ { - dprint (2, (debugfile, "key len: %s\n", p)); + debug_print (2, ("key len: %s\n", p)); if (!(*is_subkey && option (OPTPGPIGNORESUB))) k->keylen = atoi (p); /* fixme: add validation checks */ @@ -190,7 +191,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) case 4: /* pubkey algo */ { - dprint (2, (debugfile, "pubkey algorithm: %s\n", p)); + debug_print (2, ("pubkey algorithm: %s\n", p)); if (!(*is_subkey && option (OPTPGPIGNORESUB))) { k->numalg = atoi (p); @@ -200,7 +201,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) } case 5: /* 16 hex digits with the long keyid. */ { - dprint (2, (debugfile, "key id: %s\n", p)); + debug_print (2, ("key id: %s\n", p)); if (!(*is_subkey && option (OPTPGPIGNORESUB))) str_replace (&k->keyid, p); @@ -212,7 +213,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) char tstr[11]; struct tm time; - dprint (2, (debugfile, "time stamp: %s\n", p)); + debug_print (2, ("time stamp: %s\n", p)); if (!p) break; @@ -243,7 +244,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) if (!is_uid && (*is_subkey && option (OPTPGPIGNORESUB))) break; - dprint (2, (debugfile, "user ID: %s\n", p)); + debug_print (2, ("user ID: %s\n", p)); uid = safe_calloc (sizeof (pgp_uid_t), 1); fix_uid (p); @@ -264,7 +265,7 @@ static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) case 11: /* signature class */ break; case 12: /* key capabilities */ - dprint (2, (debugfile, "capabilities info: %s\n", p)); + debug_print (2, ("capabilities info: %s\n", p)); while (*p) { switch (*p++) { diff --git a/handler.c b/handler.c index 5cebcad..08d854c 100644 --- a/handler.c +++ b/handler.c @@ -31,6 +31,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #define BUFI_SIZE 1000 #define BUFO_SIZE 2000 @@ -287,8 +288,7 @@ void mutt_decode_base64 (STATE * s, long len, int istext, iconv_t cd) buf[i++] = ch; } if (i != 4) { - dprint (2, (debugfile, "%s:%d [mutt_decode_base64()]: " - "didn't get a multiple of 4 chars.\n", __FILE__, __LINE__)); + debug_print (2, ("didn't get a multiple of 4 chars.\n")); break; } diff --git a/headers.c b/headers.c index 6134788..1102be8 100644 --- a/headers.c +++ b/headers.c @@ -16,6 +16,7 @@ #include "mutt_idna.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -66,8 +67,7 @@ void mutt_edit_headers (const char *editor, mutt_edit_file (editor, path); stat (path, &st); if (mtime == st.st_mtime) { - dprint (1, - (debugfile, "ci_edit_headers(): temp file was not modified.\n")); + debug_print (1, ("temp file was not modified.\n")); /* the file has not changed! */ mutt_unlink (path); return; diff --git a/imap/auth.c b/imap/auth.c index 6f000ad..448220e 100644 --- a/imap/auth.c +++ b/imap/auth.c @@ -17,6 +17,7 @@ #include "lib/mem.h" #include "lib/intl.h" +#include "lib/debug.h" #include "mutt.h" #include "imap_private.h" @@ -61,8 +62,7 @@ int imap_authenticate (IMAP_DATA * idata) if (!method[0]) continue; - dprint (2, - (debugfile, "imap_authenticate: Trying method %s\n", method)); + debug_print (2, ("Trying method %s\n", method)); authenticator = imap_authenticators; while (authenticator->authenticate) { @@ -82,8 +82,7 @@ int imap_authenticate (IMAP_DATA * idata) } else { /* Fall back to default: any authenticator */ - dprint (2, - (debugfile, "imap_authenticate: Using any available method.\n")); + debug_print (2, ("Using any available method.\n")); authenticator = imap_authenticators; while (authenticator->authenticate) { diff --git a/imap/auth_anon.c b/imap/auth_anon.c index c878073..fc6d401 100644 --- a/imap/auth_anon.c +++ b/imap/auth_anon.c @@ -18,6 +18,7 @@ #include "auth.h" #include "lib/intl.h" +#include "lib/debug.h" /* this is basically a stripped-down version of the cram-md5 method. */ imap_auth_res_t imap_auth_anon (IMAP_DATA * idata, const char *method) @@ -42,7 +43,7 @@ imap_auth_res_t imap_auth_anon (IMAP_DATA * idata, const char *method) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) { - dprint (1, (debugfile, "Invalid response from server.\n")); + debug_print (1, ("Invalid response from server.\n")); goto bail; } @@ -53,7 +54,7 @@ imap_auth_res_t imap_auth_anon (IMAP_DATA * idata, const char *method) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_OK) { - dprint (1, (debugfile, "Error receiving server response.\n")); + debug_print (1, ("Error receiving server response.\n")); goto bail; } diff --git a/imap/auth_cram.c b/imap/auth_cram.c index 3843ca3..de56860 100644 --- a/imap/auth_cram.c +++ b/imap/auth_cram.c @@ -22,6 +22,7 @@ #define MD5_DIGEST_LEN 16 #include "lib/intl.h" +#include "lib/debug.h" /* forward declarations */ static void hmac_md5 (const char *password, char *challenge, @@ -59,17 +60,17 @@ imap_auth_res_t imap_auth_cram_md5 (IMAP_DATA * idata, const char *method) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) { - dprint (1, (debugfile, "Invalid response from server: %s\n", ibuf)); + debug_print (1, ("Invalid response from server: %s\n", ibuf)); goto bail; } if ((len = mutt_from_base64 (obuf, idata->cmd.buf + 2)) == -1) { - dprint (1, (debugfile, "Error decoding base64 response.\n")); + debug_print (1, ("Error decoding base64 response.\n")); goto bail; } obuf[len] = '\0'; - dprint (2, (debugfile, "CRAM challenge: %s\n", obuf)); + debug_print (2, ("CRAM challenge: %s\n", obuf)); /* The client makes note of the data and then responds with a string * consisting of the user name, a space, and a 'digest'. The latter is @@ -93,7 +94,7 @@ imap_auth_res_t imap_auth_cram_md5 (IMAP_DATA * idata, const char *method) hmac_response[9], hmac_response[10], hmac_response[11], hmac_response[12], hmac_response[13], hmac_response[14], hmac_response[15]); - dprint (2, (debugfile, "CRAM response: %s\n", obuf)); + debug_print (2, ("CRAM response: %s\n", obuf)); /* XXX - ibuf must be long enough to store the base64 encoding of obuf, * plus the additional debris @@ -109,7 +110,7 @@ imap_auth_res_t imap_auth_cram_md5 (IMAP_DATA * idata, const char *method) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_OK) { - dprint (1, (debugfile, "Error receiving server response.\n")); + debug_print (1, ("Error receiving server response.\n")); goto bail; } diff --git a/imap/auth_gss.c b/imap/auth_gss.c index 4602c47..bfe6c2f 100644 --- a/imap/auth_gss.c +++ b/imap/auth_gss.c @@ -18,6 +18,7 @@ #include "auth.h" #include "lib/intl.h" +#include "lib/debug.h" #include @@ -63,14 +64,14 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) maj_stat = gss_import_name (&min_stat, &request_buf, gss_nt_service_name, &target_name); if (maj_stat != GSS_S_COMPLETE) { - dprint (2, (debugfile, "Couldn't get service name for [%s]\n", buf1)); + debug_print (2, ("Couldn't get service name for [%s]\n", buf1)); return IMAP_AUTH_UNAVAIL; } #ifdef DEBUG else if (debuglevel >= 2) { maj_stat = gss_display_name (&min_stat, target_name, &request_buf, &mech_name); - dprint (2, (debugfile, "Using service name [%s]\n", + debug_print (2, ("Using service name [%s]\n", (char *) request_buf.value)); maj_stat = gss_release_buffer (&min_stat, &request_buf); } @@ -87,7 +88,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) &send_token, (unsigned int *) &cflags, NULL); if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED) { - dprint (1, (debugfile, "Error acquiring credentials - no TGT?\n")); + debug_print (1, ("Error acquiring credentials - no TGT?\n")); gss_release_name (&min_stat, &target_name); return IMAP_AUTH_UNAVAIL; @@ -104,13 +105,13 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) { - dprint (2, (debugfile, "Invalid response from server: %s\n", buf1)); + debug_print (2, ("Invalid response from server: %s\n", buf1)); gss_release_name (&min_stat, &target_name); goto bail; } /* now start the security context initialisation loop... */ - dprint (2, (debugfile, "Sending credentials\n")); + debug_print (2, ("Sending credentials\n")); mutt_to_base64 ((unsigned char *) buf1, send_token.value, send_token.length, sizeof (buf1) - 2); gss_release_buffer (&min_stat, &send_token); @@ -124,7 +125,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) { - dprint (1, (debugfile, "Error receiving server response.\n")); + debug_print (1, ("Error receiving server response.\n")); gss_release_name (&min_stat, &target_name); goto bail; } @@ -141,7 +142,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) NULL, &send_token, (unsigned int *) &cflags, NULL); if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED) { - dprint (1, (debugfile, "Error exchanging credentials\n")); + debug_print (1, ("Error exchanging credentials\n")); gss_release_name (&min_stat, &target_name); goto err_abort_cmd; @@ -161,7 +162,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) { - dprint (1, (debugfile, "Error receiving server response.\n")); + debug_print (1, ("Error receiving server response.\n")); goto bail; } request_buf.length = mutt_from_base64 (buf2, idata->cmd.buf + 2); @@ -170,16 +171,16 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) maj_stat = gss_unwrap (&min_stat, context, &request_buf, &send_token, &cflags, &quality); if (maj_stat != GSS_S_COMPLETE) { - dprint (2, (debugfile, "Couldn't unwrap security level data\n")); + debug_print (2, ("Couldn't unwrap security level data\n")); gss_release_buffer (&min_stat, &send_token); goto err_abort_cmd; } - dprint (2, (debugfile, "Credential exchange complete\n")); + debug_print (2, ("Credential exchange complete\n")); /* first octet is security levels supported. We want NONE */ server_conf_flags = ((char *) send_token.value)[0]; if (!(((char *) send_token.value)[0] & GSS_AUTH_P_NONE)) { - dprint (2, (debugfile, "Server requires integrity or privacy\n")); + debug_print (2, ("Server requires integrity or privacy\n")); gss_release_buffer (&min_stat, &send_token); goto err_abort_cmd; } @@ -188,11 +189,11 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) ((char *) send_token.value)[0] = 0; buf_size = ntohl (*((long *) send_token.value)); gss_release_buffer (&min_stat, &send_token); - dprint (2, (debugfile, "Unwrapped security level flags: %c%c%c\n", + debug_print (2, ("Unwrapped security level flags: %c%c%c\n", server_conf_flags & GSS_AUTH_P_NONE ? 'N' : '-', server_conf_flags & GSS_AUTH_P_INTEGRITY ? 'I' : '-', server_conf_flags & GSS_AUTH_P_PRIVACY ? 'P' : '-')); - dprint (2, (debugfile, "Maximum GSS token size is %ld\n", buf_size)); + debug_print (2, ("Maximum GSS token size is %ld\n", buf_size)); /* agree to terms (hack!) */ buf_size = htonl (buf_size); /* not relevant without integrity/privacy */ @@ -205,14 +206,13 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) maj_stat = gss_wrap (&min_stat, context, 0, GSS_C_QOP_DEFAULT, &request_buf, &cflags, &send_token); if (maj_stat != GSS_S_COMPLETE) { - dprint (2, (debugfile, "Error creating login request\n")); + debug_print (2, ("Error creating login request\n")); goto err_abort_cmd; } mutt_to_base64 ((unsigned char *) buf1, send_token.value, send_token.length, sizeof (buf1) - 2); - dprint (2, (debugfile, "Requesting authorisation as %s\n", - idata->conn->account.user)); + debug_print (2, ("Requesting authorisation as %s\n", idata->conn->account.user)); safe_strcat (buf1, sizeof (buf1), "\r\n"); mutt_socket_write (idata->conn, buf1); @@ -221,15 +221,15 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method) rc = imap_cmd_step (idata); while (rc == IMAP_CMD_CONTINUE); if (rc == IMAP_CMD_RESPOND) { - dprint (1, (debugfile, "Unexpected server continuation request.\n")); + debug_print (1, ("Unexpected server continuation request.\n")); goto err_abort_cmd; } if (imap_code (idata->cmd.buf)) { /* flush the security context */ - dprint (2, (debugfile, "Releasing GSS credentials\n")); + debug_print (2, ("Releasing GSS credentials\n")); maj_stat = gss_delete_sec_context (&min_stat, &context, &send_token); if (maj_stat != GSS_S_COMPLETE) - dprint (1, (debugfile, "Error releasing credentials\n")); + debug_print (1, ("Error releasing credentials\n")); /* send_token may contain a notification to the server to flush * credentials. RFC 1731 doesn't specify what to do, and since this diff --git a/imap/auth_login.c b/imap/auth_login.c index 29a43b0..c460a5b 100644 --- a/imap/auth_login.c +++ b/imap/auth_login.c @@ -14,6 +14,7 @@ #endif #include "lib/intl.h" +#include "lib/debug.h" #include "mutt.h" #include "imap_private.h" @@ -46,8 +47,8 @@ imap_auth_res_t imap_auth_login (IMAP_DATA * idata, const char *method) /* don't print the password unless we're at the ungodly debugging level * of 5 or higher */ - if (debuglevel < IMAP_LOG_PASS) - dprint (2, (debugfile, "Sending LOGIN command for %s...\n", + if (DebugLevel < IMAP_LOG_PASS) + debug_print (2, ("Sending LOGIN command for %s...\n", idata->conn->account.user)); #endif diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index e83544f..075e4b5 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -20,6 +20,7 @@ #include "lib/mem.h" #include "lib/intl.h" +#include "lib/debug.h" #ifdef USE_SASL2 #include @@ -47,8 +48,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) unsigned char client_start; if (mutt_sasl_client_new (idata->conn, &saslconn) < 0) { - dprint (1, (debugfile, - "imap_auth_sasl: Error allocating SASL connection.\n")); + debug_print (1, ("Error allocating SASL connection.\n")); return IMAP_AUTH_FAILURE; } @@ -97,11 +97,9 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) if (rc != SASL_OK && rc != SASL_CONTINUE) { if (method) - dprint (2, (debugfile, "imap_auth_sasl: %s unavailable\n", method)); + debug_print (2, ("%s unavailable\n", method)); else - dprint (1, - (debugfile, - "imap_auth_sasl: Failure starting authentication exchange. No shared mechanisms?\n")); + debug_print (1, ("Failure starting authentication exchange. No shared mechanisms?\n")); /* SASL doesn't support LOGIN, so fall back */ return IMAP_AUTH_UNAVAIL; @@ -120,7 +118,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) while (irc == IMAP_CMD_CONTINUE); if (method && irc == IMAP_CMD_NO) { - dprint (2, (debugfile, "imap_auth_sasl: %s failed\n", method)); + debug_print (2, ("%s failed\n", method)); sasl_dispose (&saslconn); return IMAP_AUTH_UNAVAIL; } @@ -137,9 +135,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) if (sasl_decode64 (idata->cmd.buf + 2, safe_strlen (idata->cmd.buf + 2), buf, #endif &len) != SASL_OK) { - dprint (1, - (debugfile, - "imap_auth_sasl: error base64-decoding server response.\n")); + debug_print (1, ("error base64-decoding server response.\n")); goto bail; } } @@ -158,9 +154,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) /* send out response, or line break if none needed */ if (olen) { if (sasl_encode64 (pc, olen, buf, sizeof (buf), &olen) != SASL_OK) { - dprint (1, - (debugfile, - "imap_auth_sasl: error base64-encoding client response.\n")); + debug_print (1, ("error base64-encoding client response.\n")); goto bail; } @@ -179,8 +173,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method) /* If SASL has errored out, send an abort string to the server */ if (rc < 0) { mutt_socket_write (idata->conn, "*\r\n"); - dprint (1, - (debugfile, "imap_auth_sasl: sasl_client_step error %d\n", rc)); + debug_print (1, ("sasl_client_step error %d\n", rc)); } olen = 0; diff --git a/imap/browse.c b/imap/browse.c index dbccc6a..9911fe5 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -20,6 +20,7 @@ #include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" +#include "lib/debug.h" #include "mutt.h" #include "imap_private.h" @@ -99,7 +100,7 @@ int imap_browse (char *path, struct browser_state *state) strncpy (mbox, buf, sizeof (mbox) - 1); n = safe_strlen (mbox); - dprint (3, (debugfile, "imap_browse: mbox: %s\n", mbox)); + debug_print (3, ("mbox: %s\n", mbox)); /* if our target exists and has inferiors, enter it if we * aren't already going to */ @@ -148,7 +149,7 @@ int imap_browse (char *path, struct browser_state *state) mbox[n] = '\0'; if (showparents) { - dprint (3, (debugfile, "imap_init_browse: adding parent %s\n", mbox)); + debug_print (3, ("adding parent %s\n", mbox)); imap_add_folder (idata->delim, mbox, 1, 0, state, 1); } @@ -188,17 +189,17 @@ int imap_browse (char *path, struct browser_state *state) /* Listing the home namespace, so INBOX should be included. Home * namespace is not "", so we have to list it explicitly. We ask the * server to see if it has descendants. */ - dprint (3, (debugfile, "imap_browse: adding INBOX\n")); + debug_print (3, ("adding INBOX\n")); if (browse_add_list_result (idata, "LIST \"\" \"INBOX\"", state, 0)) goto fail; } nsup = state->entrylen; - dprint (3, (debugfile, "imap_browse: Quoting mailbox scan: %s -> ", mbox)); + debug_print (3, ("Quoting mailbox scan: %s:\n", mbox)); snprintf (buf, sizeof (buf), "%s%%", mbox); imap_quote_string (buf2, sizeof (buf2), buf); - dprint (3, (debugfile, "%s\n", buf2)); + debug_print (3, ("%s\n", buf2)); snprintf (buf, sizeof (buf), "%s \"\" %s", list_cmd, buf2); if (browse_add_list_result (idata, buf, state, 0)) goto fail; @@ -219,8 +220,7 @@ int imap_browse (char *path, struct browser_state *state) if (nsi[i].listable && !nsi[i].home_namespace) { imap_add_folder (nsi[i].delim, nsi[i].prefix, nsi[i].noselect, nsi[i].noinferiors, state, 0); - dprint (3, (debugfile, "imap_browse: adding namespace: %s\n", - nsi[i].prefix)); + debug_print (3, ("adding namespace: %s\n", nsi[i].prefix)); } } @@ -241,16 +241,12 @@ int imap_mailbox_create (const char *folder) short n; if (imap_parse_path (folder, &mx) < 0) { - dprint (1, (debugfile, "imap_mailbox_create: Bad starting path %s\n", - folder)); + debug_print (1, ("Bad starting path %s\n", folder)); return -1; } if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW))) { - dprint (1, - (debugfile, - "imap_mailbox_create: Couldn't find open connection to %s", - mx.account.host)); + debug_print (1, ("Couldn't find open connection to %s\n", mx.account.host)); goto fail; } @@ -295,16 +291,12 @@ int imap_mailbox_rename (const char *mailbox) char newname[SHORT_STRING]; if (imap_parse_path (mailbox, &mx) < 0) { - dprint (1, (debugfile, "imap_mailbox_rename: Bad source mailbox %s\n", - mailbox)); + debug_print (1, ("Bad source mailbox %s\n", mailbox)); return -1; } if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW))) { - dprint (1, - (debugfile, - "imap_mailbox_rename: Couldn't find open connection to %s", - mx.account.host)); + debug_print (1, ("Couldn't find open connection to %s\n", mx.account.host)); goto fail; } @@ -346,9 +338,7 @@ static int browse_add_list_result (IMAP_DATA * idata, const char *cmd, IMAP_MBOX mx; if (imap_parse_path (state->folder, &mx)) { - dprint (2, (debugfile, - "browse_add_list_result: current folder %s makes no sense\n", - state->folder)); + debug_print (2, ("current folder %s makes no sense\n", state->folder)); return -1; } @@ -509,8 +499,7 @@ static int browse_get_namespace (IMAP_DATA * idata, char *nsbuf, int nsblen, } /* skip "" namespaces, they are already listed at the root */ if ((ns[0] != '\0') && (nsbused < nsblen) && (*nns < nsilen)) { - dprint (3, - (debugfile, "browse_get_namespace: adding %s\n", ns)); + debug_print (3, ("adding %s\n", ns)); nsi->type = type; /* Cyrus doesn't append the delimiter to the namespace, * but UW-IMAP does. We'll strip it here and add it back diff --git a/imap/command.c b/imap/command.c index 413bec0..0a52ca4 100644 --- a/imap/command.c +++ b/imap/command.c @@ -23,6 +23,7 @@ #include "lib/mem.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -101,14 +102,12 @@ int imap_cmd_step (IMAP_DATA * idata) if (len == cmd->blen) { safe_realloc (&cmd->buf, cmd->blen + IMAP_CMD_BUFSIZE); cmd->blen = cmd->blen + IMAP_CMD_BUFSIZE; - dprint (3, (debugfile, "imap_cmd_step: grew buffer to %u bytes\n", - cmd->blen)); + debug_print (3, ("grew buffer to %u bytes\n", cmd->blen)); } c = mutt_socket_readln (cmd->buf + len, cmd->blen - len, idata->conn); if (c <= 0) { - dprint (1, - (debugfile, "imap_cmd_step: Error reading server response.\n")); + debug_print (1, ("Error reading server response.\n")); /* cmd_handle_fatal (idata); */ return IMAP_CMD_BAD; } @@ -124,9 +123,7 @@ int imap_cmd_step (IMAP_DATA * idata) if ((cmd->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE)) { safe_realloc (&cmd->buf, IMAP_CMD_BUFSIZE); cmd->blen = IMAP_CMD_BUFSIZE; - dprint (3, - (debugfile, "imap_cmd_step: shrank buffer to %u bytes\n", - cmd->blen)); + debug_print (3, ("shrank buffer to %u bytes\n", cmd->blen)); } idata->lastread = time (NULL); @@ -211,8 +208,7 @@ int imap_exec (IMAP_DATA * idata, const char *cmd, int flags) if (flags & IMAP_CMD_FAIL_OK) return -2; - dprint (1, - (debugfile, "imap_exec: command failed: %s\n", idata->cmd.buf)); + debug_print (1, ("command failed: %s\n", idata->cmd.buf)); return -1; } @@ -250,14 +246,14 @@ void imap_cmd_finish (IMAP_DATA * idata) (idata->reopen & IMAP_NEWMAIL_PENDING) && count > idata->ctx->msgcount) { /* read new mail messages */ - dprint (2, (debugfile, "imap_cmd_finish: Fetching new mail\n")); + debug_print (2, ("Fetching new mail\n")); /* check_status: curs_main uses imap_check_mailbox to detect * whether the index needs updating */ idata->check_status = IMAP_NEWMAIL_PENDING; imap_read_headers (idata, idata->ctx->msgcount, count - 1); } else if (idata->reopen & IMAP_EXPUNGE_PENDING) { - dprint (2, (debugfile, "imap_cmd_finish: Expunging mailbox\n")); + debug_print (2, ("Expunging mailbox\n")); imap_expunge_mailbox (idata); /* Detect whether we've gotten unexpected EXPUNGE messages */ if (idata->reopen & IMAP_EXPUNGE_PENDING && @@ -309,7 +305,7 @@ static int cmd_handle_untagged (IMAP_DATA * idata) * connection, so update that one. */ if (ascii_strncasecmp ("EXISTS", s, 6) == 0) { - dprint (2, (debugfile, "Handling EXISTS\n")); + debug_print (2, ("Handling EXISTS\n")); /* new mail arrived */ count = atoi (pn); @@ -327,13 +323,10 @@ static int cmd_handle_untagged (IMAP_DATA * idata) /* at least the InterChange server sends EXISTS messages freely, * even when there is no new mail */ else if (count == idata->ctx->msgcount) - dprint (3, (debugfile, - "cmd_handle_untagged: superfluous EXISTS message.\n")); + debug_print (3, ("superfluous EXISTS message.\n")); else { if (!(idata->reopen & IMAP_EXPUNGE_PENDING)) { - dprint (2, (debugfile, - "cmd_handle_untagged: New mail in %s - %d messages total.\n", - idata->mailbox, count)); + debug_print (2, ("New mail in %s - %d messages total.\n", idata->mailbox, count)); idata->reopen |= IMAP_NEWMAIL_PENDING; } idata->newMailCount = count; @@ -350,7 +343,7 @@ static int cmd_handle_untagged (IMAP_DATA * idata) else if (ascii_strncasecmp ("MYRIGHTS", s, 8) == 0) cmd_parse_myrights (idata, s); else if (ascii_strncasecmp ("BYE", s, 3) == 0) { - dprint (2, (debugfile, "Handling BYE\n")); + debug_print (2, ("Handling BYE\n")); /* check if we're logging out */ if (idata->status == IMAP_BYE) @@ -374,7 +367,7 @@ static int cmd_handle_untagged (IMAP_DATA * idata) } else if (option (OPTIMAPSERVERNOISE) && (ascii_strncasecmp ("NO", s, 2) == 0)) { - dprint (2, (debugfile, "Handling untagged NO\n")); + debug_print (2, ("Handling untagged NO\n")); /* Display the warning message from the server */ mutt_error ("%s", s + 3); @@ -399,7 +392,7 @@ static void cmd_parse_capabilities (IMAP_DATA * idata, char *s) { int x; - dprint (2, (debugfile, "Handling CAPABILITY\n")); + debug_print (2, ("Handling CAPABILITY\n")); s = imap_next_word (s); FREE (&idata->capstr); @@ -424,7 +417,7 @@ static void cmd_parse_expunge (IMAP_DATA * idata, const char *s) int expno, cur; HEADER *h; - dprint (2, (debugfile, "Handling EXPUNGE\n")); + debug_print (2, ("Handling EXPUNGE\n")); expno = atoi (s); @@ -453,7 +446,7 @@ static void cmd_parse_fetch (IMAP_DATA * idata, char *s) int msgno, cur; HEADER *h = NULL; - dprint (2, (debugfile, "Handling FETCH\n")); + debug_print (2, ("Handling FETCH\n")); msgno = atoi (s); @@ -463,9 +456,7 @@ static void cmd_parse_fetch (IMAP_DATA * idata, char *s) h = idata->ctx->hdrs[cur]; if (h->active && h->index + 1 == msgno) { - dprint (2, - (debugfile, "Message UID %d updated\n", - HEADER_DATA (h)->uid)); + debug_print (2, ("Message UID %d updated\n", HEADER_DATA (h)->uid)); break; } @@ -473,7 +464,7 @@ static void cmd_parse_fetch (IMAP_DATA * idata, char *s) } if (!h) { - dprint (1, (debugfile, "FETCH response ignored for this message\n")); + debug_print (1, ("FETCH response ignored for this message\n")); return; } @@ -482,13 +473,13 @@ static void cmd_parse_fetch (IMAP_DATA * idata, char *s) s = imap_next_word (s); if (*s != '(') { - dprint (1, (debugfile, "Malformed FETCH response")); + debug_print (1, ("Malformed FETCH response\n")); return; } s++; if (ascii_strncasecmp ("FLAGS", s, 5) != 0) { - dprint (2, (debugfile, "Only handle FLAGS updates\n")); + debug_print (2, ("Only handle FLAGS updates\n")); return; } @@ -504,7 +495,7 @@ static void cmd_parse_fetch (IMAP_DATA * idata, char *s) /* cmd_parse_myrights: set rights bits according to MYRIGHTS response */ static void cmd_parse_myrights (IMAP_DATA * idata, char *s) { - dprint (2, (debugfile, "Handling MYRIGHTS\n")); + debug_print (2, ("Handling MYRIGHTS\n")); s = imap_next_word (s); s = imap_next_word (s); diff --git a/imap/imap.c b/imap/imap.c index aa4453c..0aa906b 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -30,6 +30,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -75,12 +76,12 @@ int imap_access (const char *path, int flags) else if (mutt_bit_isset (idata->capabilities, STATUS)) snprintf (buf, sizeof (buf), "STATUS %s (UID-VALIDITY)", mbox); else { - dprint (2, (debugfile, "imap_access: STATUS not supported?\n")); + debug_print (2, ("STATUS not supported?\n")); return -1; } if (imap_exec (idata, buf, IMAP_CMD_FAIL_OK) < 0) { - dprint (1, (debugfile, "imap_access: Can't check STATUS of %s\n", mbox)); + debug_print (1, ("Can't check STATUS of %s\n", mbox)); return -1; } @@ -178,14 +179,11 @@ int imap_read_literal (FILE * fp, IMAP_DATA * idata, long bytes) int r = 0; - dprint (2, (debugfile, "imap_read_literal: reading %ld bytes\n", bytes)); + debug_print (2, ("reading %ld bytes\n", bytes)); for (pos = 0; pos < bytes; pos++) { if (mutt_socket_readchar (idata->conn, &c) != 1) { - dprint (1, - (debugfile, - "imap_read_literal: error during read, %ld bytes read\n", - pos)); + debug_print (1, ("error during read, %ld bytes read\n", pos)); idata->status = IMAP_FATAL; return -1; @@ -204,8 +202,8 @@ int imap_read_literal (FILE * fp, IMAP_DATA * idata, long bytes) #endif fputc (c, fp); #ifdef DEBUG - if (debuglevel >= IMAP_LOG_LTRL) - fputc (c, debugfile); + if (DebugLevel >= IMAP_LOG_LTRL) + fputc (c, DebugFile); #endif } @@ -224,9 +222,7 @@ void imap_expunge_mailbox (IMAP_DATA * idata) h = idata->ctx->hdrs[i]; if (h->index == -1) { - dprint (2, - (debugfile, "Expunging message UID %d.\n", - HEADER_DATA (h)->uid)); + debug_print (2, ("Expunging message UID %d.\n", HEADER_DATA (h)->uid)); h->active = 0; @@ -277,11 +273,11 @@ static int imap_get_delim (IMAP_DATA * idata) while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_OK) { - dprint (1, (debugfile, "imap_get_delim: failed.\n")); + debug_print (1, ("failed.\n")); return -1; } - dprint (2, (debugfile, "Delimiter: %c\n", idata->delim)); + debug_print (2, ("Delimiter: %c\n", idata->delim)); return -1; } @@ -372,8 +368,7 @@ IMAP_DATA *imap_conn_find (const ACCOUNT * account, int flags) if (!imap_authenticate (idata)) { idata->state = IMAP_AUTHENTICATED; if (idata->conn->ssf) - dprint (2, (debugfile, "Communication encrypted at %d bits\n", - idata->conn->ssf)); + debug_print (2, ("Communication encrypted at %d bits\n", idata->conn->ssf)); } else mutt_account_unsetpass (&idata->conn->account); @@ -472,13 +467,13 @@ static char *imap_get_flags (LIST ** hflags, char *s) /* sanity-check string */ if (ascii_strncasecmp ("FLAGS", s, 5) != 0) { - dprint (1, (debugfile, "imap_get_flags: not a FLAGS response: %s\n", s)); + debug_print (1, ("not a FLAGS response: %s\n", s)); return NULL; } s += 5; SKIPWS (s); if (*s != '(') { - dprint (1, (debugfile, "imap_get_flags: bogus FLAGS response: %s\n", s)); + debug_print (1, ("bogus FLAGS response: %s\n", s)); return NULL; } @@ -501,8 +496,7 @@ static char *imap_get_flags (LIST ** hflags, char *s) /* note bad flags response */ if (*s != ')') { - dprint (1, (debugfile, - "imap_get_flags: Unterminated FLAGS response: %s\n", s)); + debug_print (1, ("Unterminated FLAGS response: %s\n", s)); mutt_free_list (hflags); return NULL; @@ -577,14 +571,14 @@ int imap_open_mailbox (CONTEXT * ctx) if (ascii_strncasecmp ("FLAGS", pc, 5) == 0) { /* don't override PERMANENTFLAGS */ if (!idata->flags) { - dprint (2, (debugfile, "Getting mailbox FLAGS\n")); + debug_print (2, ("Getting mailbox FLAGS\n")); if ((pc = imap_get_flags (&(idata->flags), pc)) == NULL) goto fail; } } /* PERMANENTFLAGS are massaged to look like FLAGS, then override FLAGS */ else if (ascii_strncasecmp ("OK [PERMANENTFLAGS", pc, 18) == 0) { - dprint (2, (debugfile, "Getting mailbox PERMANENTFLAGS\n")); + debug_print (2, ("Getting mailbox PERMANENTFLAGS\n")); /* safe to call on NULL */ mutt_free_list (&(idata->flags)); /* skip "OK [PERMANENT" so syntax is the same as FLAGS */ @@ -595,7 +589,7 @@ int imap_open_mailbox (CONTEXT * ctx) #ifdef USE_HCACHE /* save UIDVALIDITY for the header cache */ else if (ascii_strncasecmp ("OK [UIDVALIDITY", pc, 14) == 0) { - dprint (2, (debugfile, "Getting mailbox UIDVALIDITY\n")); + debug_print (2, ("Getting mailbox UIDVALIDITY\n")); pc += 3; pc = imap_next_word (pc); @@ -629,26 +623,25 @@ int imap_open_mailbox (CONTEXT * ctx) if (!ascii_strncasecmp (imap_get_qualifier (idata->cmd.buf), "[READ-ONLY]", 11) && !mutt_bit_isset (idata->capabilities, ACL)) { - dprint (2, (debugfile, "Mailbox is read-only.\n")); + debug_print (2, ("Mailbox is read-only.\n")); ctx->readonly = 1; } #ifdef DEBUG /* dump the mailbox flags we've found */ - if (debuglevel > 2) { + if (DebugLevel > 2) { if (!idata->flags) - dprint (3, (debugfile, "No folder flags found\n")); + debug_print (3, ("No folder flags found\n")); else { LIST *t = idata->flags; - dprint (3, (debugfile, "Mailbox flags: ")); + debug_print (3, ("Mailbox flags:\n")); t = t->next; while (t) { - dprint (3, (debugfile, "[%s] ", t->data)); + debug_print (3, ("[%s]\n", t->data)); t = t->next; } - dprint (3, (debugfile, "\n")); } } #endif @@ -685,8 +678,7 @@ int imap_open_mailbox (CONTEXT * ctx) goto fail; } - dprint (2, - (debugfile, "imap_open_mailbox: msgcount is %d\n", ctx->msgcount)); + debug_print (2, ("msgcount is %d\n", ctx->msgcount)); FREE (&mx.mbox); return 0; @@ -776,7 +768,7 @@ void imap_logout (IMAP_DATA * idata) /* int imap_close_connection (CONTEXT *ctx) { - dprint (1, (debugfile, "imap_close_connection(): closing connection\n")); + debug_print (1, (debugfile, "imap_close_connection(): closing connection\n")); if (CTX_DATA->status != IMAP_BYE) { mutt_message _("Closing connection to IMAP server..."); @@ -972,7 +964,7 @@ int imap_sync_mailbox (CONTEXT * ctx, int expunge, int *index_hint) idata = (IMAP_DATA *) ctx->data; if (idata->state != IMAP_SELECTED) { - dprint (2, (debugfile, "imap_sync_mailbox: no mailbox selected\n")); + debug_print (2, ("no mailbox selected\n")); return -1; } @@ -1027,15 +1019,11 @@ int imap_sync_mailbox (CONTEXT * ctx, int expunge, int *index_hint) * This works better if we're expunging, of course. */ if (ctx->hdrs[n]->refs_changed || ctx->hdrs[n]->irt_changed || ctx->hdrs[n]->attach_del) { - dprint (3, - (debugfile, - "imap_sync_mailbox: Attachments to be deleted, falling back to _mutt_save_message\n")); + debug_print (3, ("Attachments to be deleted, falling back to _mutt_save_message\n")); if (!appendctx) appendctx = mx_open_mailbox (ctx->path, M_APPEND | M_QUIET, NULL); if (!appendctx) { - dprint (1, - (debugfile, - "imap_sync_mailbox: Error opening mailbox in append mode\n")); + debug_print (1, ("Error opening mailbox in append mode\n")); } else _mutt_save_message (ctx->hdrs[n], appendctx, 1, 0, 0); @@ -1222,15 +1210,12 @@ int imap_mailbox_check (char *path, int new) if (isdigit ((unsigned char) *s)) { if (*s != '0') { msgcount = atoi (s); - dprint (2, - (debugfile, "%d new messages in %s\n", msgcount, path)); + debug_print (2, ("%d new messages in %s\n", msgcount, path)); } } } else - dprint (1, - (debugfile, - "imap_mailbox_check: STATUS response doesn't match requested mailbox.\n")); + debug_print (1, ("STATUS response doesn't match requested mailbox.\n")); } } while (rc == IMAP_CMD_CONTINUE); @@ -1371,7 +1356,7 @@ int imap_complete (char *dest, size_t dlen, char *path) /* verify passed in path is an IMAP path */ if (imap_parse_path (path, &mx)) { - dprint (2, (debugfile, "imap_complete: bad path %s\n", path)); + debug_print (2, ("bad path %s\n", path)); return -1; } diff --git a/imap/message.c b/imap/message.c index 19cbe9f..264e65b 100644 --- a/imap/message.c +++ b/imap/message.c @@ -30,6 +30,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #if HAVE_STDINT_H #include @@ -161,9 +162,7 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) mutt_hcache_restore ((unsigned char *) uid_validity, 0); ctx->hdrs[msgno]->index = h.sid - 1; if (h.sid != ctx->msgcount + 1) - dprint (1, - (debugfile, - "imap_read_headers: msgcount and sequence ID are inconsistent!")); + debug_print (1, ("msgcount and sequence ID are inconsistent!\n")); /* messages which have not been expunged are ACTIVE (borrowed from mh * folders) */ ctx->hdrs[msgno]->active = 1; @@ -254,9 +253,7 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) ctx->hdrs[msgno]->index = h.sid - 1; if (h.sid != ctx->msgcount + 1) - dprint (1, - (debugfile, - "imap_read_headers: msgcount and sequence ID are inconsistent!")); + debug_print (1, ("msgcount and sequence ID are inconsistent!\n")); /* messages which have not been expunged are ACTIVE (borrowed from mh * folders) */ ctx->hdrs[msgno]->active = 1; @@ -557,8 +554,7 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg) if (rc != IMAP_CMD_RESPOND) { char *pc; - dprint (1, (debugfile, "imap_append_message(): command failed: %s\n", - idata->cmd.buf)); + debug_print (1, ("command failed: %s\n", idata->cmd.buf)); pc = idata->cmd.buf + SEQLEN; SKIPWS (pc); @@ -594,8 +590,7 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg) if (!imap_code (idata->cmd.buf)) { char *pc; - dprint (1, (debugfile, "imap_append_message(): command failed: %s\n", - idata->cmd.buf)); + debug_print (1, ("command failed: %s\n", idata->cmd.buf)); pc = idata->cmd.buf + SEQLEN; SKIPWS (pc); pc = imap_next_word (pc); @@ -633,21 +628,18 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete) idata = (IMAP_DATA *) ctx->data; if (imap_parse_path (dest, &mx)) { - dprint (1, (debugfile, "imap_copy_messages: bad destination %s\n", dest)); + debug_print (1, ("bad destination %s\n", dest)); return -1; } /* check that the save-to folder is in the same account */ if (!mutt_account_match (&(CTX_DATA->conn->account), &(mx.account))) { - dprint (3, (debugfile, "imap_copy_messages: %s not same server as %s\n", - dest, ctx->path)); + debug_print (3, ("%s not same server as %s\n", dest, ctx->path)); return 1; } if (h && h->attach_del) { - dprint (3, - (debugfile, - "imap_copy_messages: Message contains attachments to be deleted\n")); + debug_print (3, ("Message contains attachments to be deleted\n")); return 1; } @@ -664,9 +656,7 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete) * remainder. */ for (n = 0; n < ctx->msgcount; n++) { if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->attach_del) { - dprint (3, - (debugfile, - "imap_copy_messages: Message contains attachments to be deleted\n")); + debug_print (3, ("Message contains attachments to be deleted\n")); return 1; } @@ -676,7 +666,7 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete) rc = imap_sync_message (idata, ctx->hdrs[n], &sync_cmd, &err_continue); if (rc < 0) { - dprint (1, (debugfile, "imap_copy_messages: could not sync\n")); + debug_print (1, ("could not sync\n")); goto fail; } } @@ -684,7 +674,7 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete) rc = imap_make_msg_set (idata, &cmd, M_TAG, 0); if (!rc) { - dprint (1, (debugfile, "imap_copy_messages: No messages tagged\n")); + debug_print (1, ("No messages tagged\n")); goto fail; } mutt_message (_("Copying %d messages to %s..."), rc, mbox); @@ -699,7 +689,7 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete) rc = imap_sync_message (idata, h, &sync_cmd, &err_continue); if (rc < 0) { - dprint (1, (debugfile, "imap_copy_messages: could not sync\n")); + debug_print (1, ("could not sync\n")); goto fail; } } @@ -718,8 +708,7 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete) imap_error ("imap_copy_messages", idata->cmd.buf); goto fail; } - dprint (2, - (debugfile, "imap_copy_messages: server suggests TRYCREATE\n")); + debug_print (2, ("server suggests TRYCREATE\n")); snprintf (mmbox, sizeof (mmbox), _("Create %s?"), mbox); if (option (OPTCONFIRMCREATE) && mutt_yesorno (mmbox, 1) < 1) { mutt_clear_error (); @@ -812,7 +801,7 @@ char *imap_set_flags (IMAP_DATA * idata, HEADER * h, char *s) memset (&newh, 0, sizeof (newh)); newh.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA)); - dprint (2, (debugfile, "imap_fetch_message: parsing FLAGS\n")); + debug_print (2, ("parsing FLAGS\n")); if ((s = msg_parse_flags (&newh, s)) == NULL) { FREE (&newh.data); return NULL; @@ -1001,9 +990,7 @@ static int msg_parse_fetch (IMAP_HEADER * h, char *s) s += 12; SKIPWS (s); if (*s != '\"') { - dprint (1, - (debugfile, - "msg_parse_fetch(): bogus INTERNALDATE entry: %s\n", s)); + debug_print (1, ("bogus INTERNALDATE entry: %s\n", s)); return -1; } s++; @@ -1049,13 +1036,13 @@ static char *msg_parse_flags (IMAP_HEADER * h, char *s) /* sanity-check string */ if (ascii_strncasecmp ("FLAGS", s, 5) != 0) { - dprint (1, (debugfile, "msg_parse_flags: not a FLAGS response: %s\n", s)); + debug_print (1, ("not a FLAGS response: %s\n", s)); return NULL; } s += 5; SKIPWS (s); if (*s != '(') { - dprint (1, (debugfile, "msg_parse_flags: bogus FLAGS response: %s\n", s)); + debug_print (1, ("bogus FLAGS response: %s\n", s)); return NULL; } s++; @@ -1108,8 +1095,7 @@ static char *msg_parse_flags (IMAP_HEADER * h, char *s) s++; } else { - dprint (1, (debugfile, - "msg_parse_flags: Unterminated FLAGS response: %s\n", s)); + debug_print (1, ("Unterminated FLAGS response: %s\n", s)); return NULL; } diff --git a/imap/util.c b/imap/util.c index d2b6002..328a86e 100644 --- a/imap/util.c +++ b/imap/util.c @@ -21,6 +21,7 @@ #include "lib/mem.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -79,7 +80,7 @@ int imap_parse_path (const char *path, IMAP_MBOX * mx) ImapPort = ntohs (service->s_port); else ImapPort = IMAP_PORT; - dprint (3, (debugfile, "Using default IMAP port %d\n", ImapPort)); + debug_print (3, ("Using default IMAP port %d\n", ImapPort)); } if (!ImapsPort) { service = getservbyname ("imaps", "tcp"); @@ -87,7 +88,7 @@ int imap_parse_path (const char *path, IMAP_MBOX * mx) ImapsPort = ntohs (service->s_port); else ImapsPort = IMAP_SSL_PORT; - dprint (3, (debugfile, "Using default IMAPS port %d\n", ImapsPort)); + debug_print (3, ("Using default IMAPS port %d\n", ImapsPort)); } /* Defaults */ @@ -131,7 +132,7 @@ int imap_parse_path (const char *path, IMAP_MBOX * mx) } if ((n = sscanf (tmp, "%127[^:/]%127s", mx->account.host, tmp)) < 1) { - dprint (1, (debugfile, "imap_parse_path: NULL host in %s\n", path)); + debug_print (1, ("NULL host in %s\n", path)); FREE (&mx->mbox); return -1; } @@ -143,9 +144,7 @@ int imap_parse_path (const char *path, IMAP_MBOX * mx) if (!ascii_strncmp (tmp, "ssl", 3)) mx->account.flags |= M_ACCT_SSL; else { - dprint (1, - (debugfile, - "imap_parse_path: Unknown connection type in %s\n", path)); + debug_print (1, ("Unknown connection type in %s\n", path)); FREE (&mx->mbox); return -1; } diff --git a/init.c b/init.c index 1c870b5..eab1c57 100644 --- a/init.c +++ b/init.c @@ -32,6 +32,7 @@ #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" +#include "lib/debug.h" #include #include @@ -41,7 +42,36 @@ #include #include +/* for synonym warning reports: synonym found during parsing */ +typedef struct { + char* f; /* file */ + int l; /* line */ + int n; /* new name (index) */ + int o; /* old name (index) */ +} syn_t; + +/* for synonym warning reports: list of synonyms found */ list2_t* Synonyms; +/* for synonym warning reports: current rc file */ +char* CurRCFile = NULL; +/* for synonym warning reports: current rc line */ +int CurRCLine = 0; + +/* for synonym warning reports: adds synonym to end of list */ +static void syn_add (int n, int o) { + syn_t* tmp = safe_malloc (sizeof (syn_t)); + tmp->f = safe_strdup (CurRCFile); + tmp->l = CurRCLine; + tmp->n = n; + tmp->o = o; + list_push_back (&Synonyms, tmp); +} + +/* for synonym warning reports: free single item (for list_del()) */ +static void syn_del (void** p) { + FREE(&(*(syn_t**) p)->f); + FREE(p); +} void toggle_quadoption (int opt) { @@ -95,7 +125,7 @@ int mutt_option_index (char *s) for (i = 0; MuttVars[i].option; i++) if (safe_strcmp (s, MuttVars[i].option) == 0) { if (MuttVars[i].type == DT_SYN) - list_push_back (&Synonyms, &MuttVars[i]); + syn_add (mutt_option_index ((char *) MuttVars[i].data), i); return (MuttVars[i].type == DT_SYN ? mutt_option_index ((char *) MuttVars[i].data) : i); } @@ -201,14 +231,12 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags) } } while (pc && *pc != '`'); if (!pc) { - dprint (1, (debugfile, "mutt_get_token: mismatched backtics\n")); + debug_print (1, ("mismatched backtics\n")); return (-1); } cmd = str_substrdup (tok->dptr, pc); if ((pid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) { - dprint (1, - (debugfile, "mutt_get_token: unable to fork command: %s", - cmd)); + debug_print (1, ("unable to fork command: %s\n", cmd)); FREE (&cmd); return (-1); } @@ -831,7 +859,7 @@ static int parse_alias (BUFFER * buf, BUFFER * s, unsigned long data, mutt_extract_token (buf, s, 0); - dprint (2, (debugfile, "parse_alias: First token is '%s'.\n", buf->data)); + debug_print (2, ("first token is '%s'.\n", buf->data)); /* check to see if an alias with this name already exists */ for (; tmp; tmp = tmp->next) { @@ -858,7 +886,7 @@ static int parse_alias (BUFFER * buf, BUFFER * s, unsigned long data, mutt_extract_token (buf, s, M_TOKEN_QUOTE | M_TOKEN_SPACE | M_TOKEN_SEMICOLON); - dprint (2, (debugfile, "parse_alias: Second token is '%s'.\n", buf->data)); + debug_print (2, ("second token is '%s'.\n", buf->data)); tmp->addr = mutt_parse_adrlist (tmp->addr, buf->data); if (last) last->next = tmp; @@ -870,14 +898,14 @@ static int parse_alias (BUFFER * buf, BUFFER * s, unsigned long data, return -1; } #ifdef DEBUG - if (debuglevel >= 2) { + if (DebugLevel >= 2) { ADDRESS *a; for (a = tmp->addr; a; a = a->next) { if (!a->group) - dprint (2, (debugfile, "parse_alias: %s\n", a->mailbox)); + debug_print (2, ("%s\n", a->mailbox)); else - dprint (2, (debugfile, "parse_alias: Group %s\n", a->mailbox)); + debug_print (2, ("group %s\n", a->mailbox)); } } #endif @@ -1527,7 +1555,9 @@ static int source_rc (const char *rcfile, BUFFER * err) size_t buflen; pid_t pid; - dprint (2, (debugfile, "Reading configuration file '%s'.\n", rcfile)); + debug_print (2, ("reading configuration file '%s'.\n", rcfile)); + str_replace (&CurRCFile, rcfile); + CurRCLine = 0; if ((f = mutt_open_read (rcfile, &pid)) == NULL) { snprintf (err->data, err->dsize, "%s: %s", rcfile, strerror (errno)); @@ -1536,6 +1566,7 @@ static int source_rc (const char *rcfile, BUFFER * err) memset (&token, 0, sizeof (token)); while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line)) != NULL) { + CurRCLine++; conv = ConfigCharset && (*ConfigCharset) && Charset; if (conv) { currentline = safe_strdup (linebuf); @@ -1979,31 +2010,6 @@ int mutt_getvaluebyname (const char *name, const struct mapping_t *map) return (-1); } -#ifdef DEBUG -static void start_debug (void) -{ - time_t t; - int i; - char buf[_POSIX_PATH_MAX]; - char buf2[_POSIX_PATH_MAX]; - - /* rotate the old debug logs */ - for (i = 3; i >= 0; i--) { - snprintf (buf, sizeof (buf), "%s/.muttdebug%d", NONULL (Homedir), i); - snprintf (buf2, sizeof (buf2), "%s/.muttdebug%d", NONULL (Homedir), - i + 1); - rename (buf, buf2); - } - if ((debugfile = safe_fopen (buf, "w")) != NULL) { - t = time (0); - setbuf (debugfile, NULL); /* don't buffer the debugging output! */ - fprintf (debugfile, - "Mutt-ng %s started at %s.\nDebugging at level %d.\n\n", - MUTT_VERSION, asctime (localtime (&t)), debuglevel); - } -} -#endif - static int mutt_execute_commands (LIST * p) { BUFFER err, token; @@ -2074,11 +2080,7 @@ void mutt_init (int skip_sys_rc, LIST * commands) Shell = safe_strdup ((p = getenv ("SHELL")) ? p : "/bin/sh"); } -#ifdef DEBUG - /* Start up debugging mode if requested */ - if (debuglevel > 0) - start_debug (); -#endif + debug_start(Homedir); /* And about the host... */ uname (&utsname); @@ -2292,13 +2294,17 @@ void mutt_init (int skip_sys_rc, LIST * commands) int i = 0; fprintf (stderr, _("Warning: the following synonym variables were found:\n")); for (i = 0; i < Synonyms->length; i++) - fprintf (stderr, "$%s ($%s should be used)\n", - ((struct option_t*) Synonyms->data[i])->option, - (char*) ((struct option_t*) Synonyms->data[i])->data); + fprintf (stderr, "$%s ($%s should be used) (%s:%d)\n", + MuttVars[((syn_t*) Synonyms->data[i])->o].option, + MuttVars[((syn_t*) Synonyms->data[i])->n].option, + NONULL(((syn_t*) Synonyms->data[i])->f), + ((syn_t*) Synonyms->data[i])->l); fprintf (stderr, _("Warning: Synonym variables are scheduled for removal.\n")); - list_del (&Synonyms, NULL); + list_del (&Synonyms, syn_del); need_pause = 1; } + /* this is not needed during runtime */ + FREE(&CurRCFile); if (need_pause && !option (OPTNOCURSES)) { if (mutt_any_key_to_continue (NULL) == -1) diff --git a/lib.c b/lib.c index b57070b..e730022 100644 --- a/lib.c +++ b/lib.c @@ -32,6 +32,7 @@ #include "lib/mem.h" #include "lib/str.h" +#include "lib/debug.h" extern short Umask; @@ -104,7 +105,7 @@ int mutt_copy_bytes (FILE * in, FILE * out, size_t size) if ((chunk = fread (buf, 1, chunk, in)) < 1) break; if (fwrite (buf, 1, chunk, out) != chunk) { - /* dprint (1, (debugfile, "mutt_copy_bytes(): fwrite() returned short byte count\n")); */ + debug_print (1, ("fwrite() returned short byte count\n")); return (-1); } size -= chunk; @@ -250,7 +251,7 @@ int safe_open (const char *path, int flags) /* make sure the file is not symlink */ if (lstat (path, &osb) < 0 || fstat (fd, &nsb) < 0 || compare_stat (&osb, &nsb) == -1) { -/* dprint (1, (debugfile, "safe_open(): %s is a symlink!\n", path)); */ + debug_print (1, ("%s is a symlink!\n", path)); close (fd); return (-1); } diff --git a/lib/Makefile.am b/lib/Makefile.am index 137b63e..8355295 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -7,7 +7,11 @@ AUTOMAKE_OPTIONS = foreign INCLUDES = -I$(top_srcdir) -I../intl noinst_LIBRARIES = libsane.a -noinst_HEADERS = mem.h str.h exit.h intl.h list.h rx.h +noinst_HEADERS = mem.h str.h exit.h intl.h list.h rx.h debug.h libsane_a_SOURCES = mem.c exit.c str.c list.c rx.h \ - mem.h exit.h str.h list.h rx.c intl.h + mem.h exit.h str.h list.h rx.c debug.h intl.h + +if WANT_DEBUG +libsane_a_SOURCES += debug.c +endif diff --git a/lib/debug.c b/lib/debug.c new file mode 100644 index 0000000..ddf6284 --- /dev/null +++ b/lib/debug.c @@ -0,0 +1,74 @@ +/* + * written for mutt-ng by: + * Rocco Rutte + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. + */ +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#if DEBUG + +#include +#include +#include + +#include "debug.h" + +#include "mutt.h" +#include "globals.h" +#include "str.h" + +short DebugLevel = -1; +FILE* DebugFile = NULL; + +void debug_setlevel (short level) { + DebugLevel = level; +} + +void debug_start (const char* basedir) { + time_t t; + int i; + char buf[_POSIX_PATH_MAX]; + char buf2[_POSIX_PATH_MAX]; + + if (DebugLevel < 0 || !basedir || !*basedir) + return; + /* rotate the old debug logs */ + for (i = 3; i >= 0; i--) { + snprintf (buf, sizeof (buf), "%s/.muttngdebug%d", NONULL (basedir), i); + snprintf (buf2, sizeof (buf2), "%s/.muttngdebug%d", NONULL (basedir), i + 1); + rename (buf, buf2); + } + if ((DebugFile = safe_fopen (buf, "w")) != NULL) { + t = time (NULL); + setbuf (DebugFile, NULL); /* don't buffer the debugging output! */ + fprintf (DebugFile, + "Mutt-ng %s started at %s\nDebugging at level %d\n\n", + MUTT_VERSION, asctime (localtime (&t)), DebugLevel); + } +} + +void _debug_print_intro (const char* file, int line, const char* function, int level) { + if (!DebugFile || DebugLevel < 0) + return; + fprintf (DebugFile, "[%d:%s:%d", level, NONULL(file), line); + if (function && *function) + fprintf (DebugFile, ":%s()", function); + fprintf (DebugFile, "] "); +} + +void _debug_print_msg (const char* fmt, ...) { + va_list ap; + + if (!DebugFile || DebugLevel < 0) + return; + va_start (ap, fmt); + vfprintf (DebugFile, fmt, ap); + va_end (ap); +} + +#endif /* DEBUG */ diff --git a/lib/debug.h b/lib/debug.h new file mode 100644 index 0000000..225aff5 --- /dev/null +++ b/lib/debug.h @@ -0,0 +1,68 @@ +/* + * written for mutt-ng by: + * Rocco Rutte + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. + */ + +/* generic interface for debug messages */ + +#ifndef _LIB_DEBUG_H +#define _LIB_DEBUG_H + +#include + +#ifdef DEBUG + +extern short DebugLevel; +extern FILE* DebugFile; + +void debug_setlevel (short); +void debug_start (const char*); + +void _debug_print_intro (const char*, int, const char*, int); +void _debug_print_msg (const char*, ...); + +/* + * the debug_print() macro will (in the end) print debug messages of the + * following format: + * + * (file:line:function:level): message + * + * for GCC and: + * + * (file:line:level): message + * + * otherwise + */ +#ifdef __GNUC__ +#define debug_print(level,msg) do { \ + if (DebugLevel >= level) { \ + _debug_print_intro (__FILE__,__LINE__,__FUNCTION__,level); \ + _debug_print_msg msg; \ + } \ +} while(0) +#else /* __GNUC__ */ +#define debug_print(level,msg) do { \ + if (DebugLevel >= level) { \ + _debug_print_intro (__FILE__,__LINE__,NULL,level); \ + _debug_print_msg msg; \ + } \ +} while(0) +#endif /* !__GNUC__ */ + +#else /* DEBUG */ + +/* + * without debug support, we don't need these + * (this also kills the dozens of #ifdef for debug... + */ +#define debug_start(basedir) +#define debug_setlevel(level) +#define debug_print(level,msg) + +#endif /* !DEBUG */ + +#endif /* !_LIB_DEBUG_H */ diff --git a/main.c b/main.c index a2805f8..a6e848f 100644 --- a/main.c +++ b/main.c @@ -29,6 +29,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -588,9 +589,9 @@ int main (int argc, char **argv) break; case 'd': + debug_setlevel(atoi(optarg)); #ifdef DEBUG - debuglevel = atoi (optarg); - printf (_("Debugging at level %d.\n"), debuglevel); + printf (_("Debugging at level %d.\n"), atoi(optarg)); #else printf _("DEBUG was not defined during compilation. Ignored.\n"); #endif diff --git a/mbox.c b/mbox.c index 2470bb3..ddd144d 100644 --- a/mbox.c +++ b/mbox.c @@ -27,6 +27,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -142,7 +143,7 @@ static int mmdf_parse_mailbox (CONTEXT * ctx) if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL) { /* TODO: memory leak??? */ - dprint (1, (debugfile, "mmdf_parse_mailbox: unexpected EOF\n")); + debug_print (1, ("unexpected EOF\n")); break; } @@ -150,7 +151,7 @@ static int mmdf_parse_mailbox (CONTEXT * ctx) if (!is_from (buf, return_path, sizeof (return_path), &t)) { if (fseek (ctx->fp, loc, SEEK_SET) != 0) { - dprint (1, (debugfile, "mmdf_parse_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); mutt_error _("Mailbox is corrupt!"); return (-1); @@ -171,7 +172,7 @@ static int mmdf_parse_mailbox (CONTEXT * ctx) fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL || safe_strcmp (MMDF_SEP, buf) != 0) { if (fseek (ctx->fp, loc, SEEK_SET) != 0) - dprint (1, (debugfile, "mmdf_parse_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); hdr->content->length = -1; } } @@ -204,7 +205,7 @@ static int mmdf_parse_mailbox (CONTEXT * ctx) ctx->msgcount++; } else { - dprint (1, (debugfile, "mmdf_parse_mailbox: corrupt mailbox!\n")); + debug_print (1, ("corrupt mailbox!\n")); mutt_error _("Mailbox is corrupt!"); return (-1); @@ -310,13 +311,11 @@ static int mbox_parse_mailbox (CONTEXT * ctx) if (fseek (ctx->fp, tmploc, SEEK_SET) != 0 || fgets (buf, sizeof (buf), ctx->fp) == NULL || safe_strncmp ("From ", buf, 5) != 0) { - dprint (1, - (debugfile, - "mbox_parse_mailbox: bad content-length in message %d (cl=%ld)\n", - curhdr->index, curhdr->content->length)); - dprint (1, (debugfile, "\tLINE: %s", buf)); + debug_print (1, ("bad content-length in message %d (cl=%ld)\n", + curhdr->index, curhdr->content->length)); + debug_print (1, ("LINE: %s\n", buf)); if (fseek (ctx->fp, loc, SEEK_SET) != 0) { /* nope, return the previous position */ - dprint (1, (debugfile, "mbox_parse_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); } curhdr->content->length = -1; } @@ -337,7 +336,7 @@ static int mbox_parse_mailbox (CONTEXT * ctx) /* count the number of lines in this message */ if (fseek (ctx->fp, loc, SEEK_SET) != 0) - dprint (1, (debugfile, "mbox_parse_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); while (cl-- > 0) { if (fgetc (ctx->fp) == '\n') curhdr->lines++; @@ -346,7 +345,7 @@ static int mbox_parse_mailbox (CONTEXT * ctx) /* return to the offset of the next message separator */ if (fseek (ctx->fp, tmploc, SEEK_SET) != 0) - dprint (1, (debugfile, "mbox_parse_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); } } @@ -576,12 +575,12 @@ int mbox_check_mailbox (CONTEXT * ctx, int *index_hint) * folder. */ if (fseek (ctx->fp, ctx->size, SEEK_SET) != 0) - dprint (1, (debugfile, "mbox_check_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); if (fgets (buffer, sizeof (buffer), ctx->fp) != NULL) { if ((ctx->magic == M_MBOX && safe_strncmp ("From ", buffer, 5) == 0) || (ctx->magic == M_MMDF && safe_strcmp (MMDF_SEP, buffer) == 0)) { if (fseek (ctx->fp, ctx->size, SEEK_SET) != 0) - dprint (1, (debugfile, "mbox_check_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); if (ctx->magic == M_MBOX) mbox_parse_mailbox (ctx); else @@ -603,7 +602,7 @@ int mbox_check_mailbox (CONTEXT * ctx, int *index_hint) modified = 1; } else { - dprint (1, (debugfile, "mbox_check_mailbox: fgets returned NULL.\n")); + debug_print (1, ("fgets returned NULL.\n")); modified = 1; } } @@ -717,7 +716,7 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) mutt_error _("sync: mbox modified, but no modified messages! (report this bug)"); mutt_sleep (5); /* the mutt_error /will/ get cleared! */ - dprint (1, (debugfile, "_mbox_sync_mailbox(): no modified messages.\n")); + debug_print (1, ("no modified messages.\n")); unlink (tempfile); goto bail; } @@ -812,8 +811,7 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) if (fclose (fp) != 0) { fp = NULL; - dprint (1, - (debugfile, "_mbox_sync_mailbox: fclose() returned non-zero.\n")); + debug_print (1, ("fclose() returned non-zero.\n")); unlink (tempfile); mutt_perror (tempfile); mutt_sleep (5); @@ -832,9 +830,7 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) if ((fp = fopen (tempfile, "r")) == NULL) { mutt_unblock_signals (); mx_fastclose_mailbox (ctx); - dprint (1, - (debugfile, - "_mbox_sync_mailbox: unable to reopen temp copy of mailbox!\n")); + debug_print (1, ("unable to reopen temp copy of mailbox!\n")); mutt_perror (tempfile); mutt_sleep (5); return (-1); @@ -845,16 +841,14 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint) fgets (buf, sizeof (buf), ctx->fp) == NULL || (ctx->magic == M_MBOX && safe_strncmp ("From ", buf, 5) != 0) || (ctx->magic == M_MMDF && safe_strcmp (MMDF_SEP, buf) != 0)) { - dprint (1, - (debugfile, - "_mbox_sync_mailbox: message not in expected position.")); - dprint (1, (debugfile, "\tLINE: %s\n", buf)); + debug_print (1, ("message not in expected position.\n")); + debug_print (1, ("LINE: %s\n", buf)); i = -1; } else { if (fseek (ctx->fp, offset, SEEK_SET) != 0) { /* return to proper offset */ i = -1; - dprint (1, (debugfile, "_mbox_sync_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); } else { /* copy the temp mailbox back into place starting at the first @@ -1059,7 +1053,7 @@ static int mbox_reopen_mailbox (CONTEXT * ctx, int *index_hint) case M_MBOX: case M_MMDF: if (fseek (ctx->fp, 0, SEEK_SET) != 0) { - dprint (1, (debugfile, "mbox_reopen_mailbox: fseek() failed\n")); + debug_print (1, ("fseek() failed\n")); rc = -1; } else { diff --git a/mh.c b/mh.c index 1c6483b..91d584c 100644 --- a/mh.c +++ b/mh.c @@ -28,6 +28,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -696,9 +697,7 @@ static int maildir_parse_dir (CONTEXT * ctx, struct maildir ***last, /* FOO - really ignore the return value? */ - dprint (2, - (debugfile, "%s:%d: parsing %s\n", __FILE__, __LINE__, - de->d_name)); + debug_print (2, ("parsing %s\n", de->d_name)); maildir_parse_entry (ctx, last, subdir, de->d_name, count, is_old, de->d_ino); } @@ -713,16 +712,12 @@ static int maildir_add_to_context (CONTEXT * ctx, struct maildir *md) while (md) { - dprint (2, (debugfile, "%s:%d maildir_add_to_context(): Considering %s\n", - __FILE__, __LINE__, NONULL (md->canon_fname))); + debug_print (2, ("considering %s\n", NONULL (md->canon_fname))); if (md->h) { - dprint (2, - (debugfile, - "%s:%d Adding header structure. Flags: %s%s%s%s%s\n", __FILE__, - __LINE__, md->h->flagged ? "f" : "", md->h->deleted ? "D" : "", - md->h->replied ? "r" : "", md->h->old ? "O" : "", - md->h->read ? "R" : "")); + debug_print (2, ("flags: %s%s%s%s%s\n", md->h->flagged ? "f" : "", + md->h->deleted ? "D" : "", md->h->replied ? "r" : "", + md->h->old ? "O" : "", md->h->read ? "R" : "")); if (ctx->msgcount == ctx->hdrmax) mx_alloc_memory (ctx); @@ -1047,8 +1042,7 @@ static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr dest->path, subdir, (long) time (NULL), (unsigned int) getpid (), Counter++, NONULL (Hostname), suffix); - dprint (2, (debugfile, "maildir_open_new_message (): Trying %s.\n", - path)); + debug_print (2, ("trying %s.\n", path)); umask (Umask); if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0666)) == -1) { @@ -1058,7 +1052,7 @@ static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr } } else { - dprint (2, (debugfile, "maildir_open_new_message (): Success.\n")); + debug_print (2, ("success.\n")); msg->path = safe_strdup (path); break; } @@ -1125,8 +1119,7 @@ int maildir_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr) NONULL (Hostname), suffix); snprintf (full, _POSIX_PATH_MAX, "%s/%s", ctx->path, path); - dprint (2, (debugfile, "maildir_commit_message (): renaming %s to %s.\n", - msg->path, full)); + debug_print (2, ("renaming %s to %s.\n", msg->path, full)); if (safe_rename (msg->path, full) == 0) { if (hdr) @@ -1344,10 +1337,7 @@ static int maildir_sync_message (CONTEXT * ctx, int msgno) char *p; if ((p = strrchr (h->path, '/')) == NULL) { - dprint (1, - (debugfile, - "maildir_sync_message: %s: unable to find subdir!\n", - h->path)); + debug_print (1, ("%s: unable to find subdir!\n", h->path)); return (-1); } p++; diff --git a/mutt_idna.c b/mutt_idna.c index 6c341a6..75bee92 100644 --- a/mutt_idna.c +++ b/mutt_idna.c @@ -18,6 +18,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" /* The low-level interface we use. */ @@ -68,10 +69,7 @@ int mutt_idna_to_local (const char *in, char **out, int flags) if (!irrev && idna_to_ascii_8z (tmp, &t2, 1) != IDNA_SUCCESS) irrev = 1; if (!irrev && ascii_strcasecmp (t2, in)) { - dprint (1, - (debugfile, - "mutt_idna_to_local: Not reversible. in = '%s', t2 = '%s'.\n", - in, t2)); + debug_print (1, ("not reversible. in = '%s', t2 = '%s'.\n", in, t2)); irrev = 1; } diff --git a/mutt_sasl.c b/mutt_sasl.c index 6bc3a29..ea34387 100644 --- a/mutt_sasl.c +++ b/mutt_sasl.c @@ -19,6 +19,7 @@ #include "mutt_socket.h" #include "lib/mem.h" +#include "lib/debug.h" #ifdef USE_SASL2 #include @@ -35,47 +36,38 @@ static int getnameinfo_err (int ret) { int err; - dprint (1, (debugfile, "getnameinfo: ")); switch (ret) { case EAI_AGAIN: - dprint (1, - (debugfile, - "The name could not be resolved at this time. Future attempts may succeed.\n")); + debug_print (1, ("The name could not be resolved at this time. Future attempts may succeed.\n")); err = SASL_TRYAGAIN; break; case EAI_BADFLAGS: - dprint (1, (debugfile, "The flags had an invalid value.\n")); + debug_print (1, ("The flags had an invalid value.\n")); err = SASL_BADPARAM; break; case EAI_FAIL: - dprint (1, (debugfile, "A non-recoverable error occurred.\n")); + debug_print (1, ("A non-recoverable error occurred.\n")); err = SASL_FAIL; break; case EAI_FAMILY: - dprint (1, - (debugfile, - "The address family was not recognized or the address length was invalid for the specified family.\n")); + debug_print (1, ("The address family was not recognized or the address length was invalid for the specified family.\n")); err = SASL_BADPROT; break; case EAI_MEMORY: - dprint (1, (debugfile, "There was a memory allocation failure.\n")); + debug_print (1, ("There was a memory allocation failure.\n")); err = SASL_NOMEM; break; case EAI_NONAME: - dprint (1, - (debugfile, - "The name does not resolve for the supplied parameters. NI_NAMEREQD is set and the host's name cannot be located, or both nodename and servname were null.\n")); + debug_print (1, ("The name does not resolve for the supplied parameters. NI_NAMEREQD is set and the host's name cannot be located, or both nodename and servname were null.\n")); err = SASL_FAIL; /* no real equivalent */ break; case EAI_SYSTEM: - dprint (1, - (debugfile, - "A system error occurred. The error code can be found in errno(%d,%s)).\n", - errno, strerror (errno))); + debug_print (1, ("A system error occurred. The error code can be found in errno(%d,%s)).\n", + errno, strerror (errno))); err = SASL_FAIL; /* no real equivalent */ break; default: - dprint (1, (debugfile, "Unknown error %d\n", ret)); + debug_print (1, ("Unknown error %d\n", ret)); err = SASL_FAIL; /* no real equivalent */ break; } @@ -164,8 +156,7 @@ int mutt_sasl_start (void) rc = sasl_client_init (callbacks); if (rc != SASL_OK) { - dprint (1, - (debugfile, "mutt_sasl_start: libsasl initialisation failed.\n")); + debug_print (1, ("libsasl initialisation failed.\n")); return SASL_FAIL; } @@ -202,48 +193,38 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn) service = "pop"; break; default: - dprint (1, (debugfile, "mutt_sasl_client_new: account type unset\n")); + debug_print (1, ("account type unset\n")); return -1; } #ifdef USE_SASL2 size = sizeof (local); if (getsockname (conn->fd, (struct sockaddr *) &local, &size)) { - dprint (1, - (debugfile, - "mutt_sasl_client_new: getsockname for local failed\n")); + debug_print (1, ("getsockname for local failed\n")); return -1; } else if (iptostring ((struct sockaddr *) &local, size, iplocalport, IP_PORT_BUFLEN) != SASL_OK) { - dprint (1, - (debugfile, - "mutt_sasl_client_new: iptostring for local failed\n")); + debug_print (1, ("iptostring for local failed\n")); return -1; } size = sizeof (remote); if (getpeername (conn->fd, (struct sockaddr *) &remote, &size)) { - dprint (1, - (debugfile, - "mutt_sasl_client_new: getsockname for remote failed\n")); + debug_print (1, ("getsockname for remote failed\n")); return -1; } else if (iptostring ((struct sockaddr *) &remote, size, ipremoteport, IP_PORT_BUFLEN) != SASL_OK) { - dprint (1, - (debugfile, - "mutt_sasl_client_new: iptostring for remote failed\n")); + debug_print (1, ("iptostring for remote failed\n")); return -1; } - dprint (1, - (debugfile, "local ip: %s, remote ip:%s\n", iplocalport, - ipremoteport)); + debug_print (1, ("local ip: %s, remote ip:%s\n", iplocalport, ipremoteport)); rc = sasl_client_new (service, conn->account.host, iplocalport, ipremoteport, @@ -256,8 +237,7 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn) #endif if (rc != SASL_OK) { - dprint (1, (debugfile, - "mutt_sasl_client_new: Error allocating SASL connection\n")); + debug_print (1, ("Error allocating SASL connection\n")); return -1; } @@ -280,16 +260,14 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn) #ifdef SASL_IP_LOCAL if (sasl_setprop (*saslconn, SASL_IP_LOCAL, &local) != SASL_OK) { - dprint (1, (debugfile, - "mutt_sasl_client_new: Error setting local IP address\n")); + debug_print (1, ("Error setting local IP address\n")); return -1; } #endif #ifdef SASL_IP_REMOTE if (sasl_setprop (*saslconn, SASL_IP_REMOTE, &remote) != SASL_OK) { - dprint (1, (debugfile, - "mutt_sasl_client_new: Error setting remote IP address\n")); + debug_print (1, ("Error setting remote IP address\n")); return -1; } #endif @@ -306,8 +284,7 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn) secprops.maxbufsize = M_SASL_MAXBUF; secprops.security_flags |= SASL_SEC_NOPLAINTEXT; if (sasl_setprop (*saslconn, SASL_SEC_PROPS, &secprops) != SASL_OK) { - dprint (1, (debugfile, - "mutt_sasl_client_new: Error setting security properties\n")); + debug_print (1, ("Error setting security properties\n")); return -1; } @@ -318,29 +295,23 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn) #if (defined(USE_SSL) || defined(USE_GNUTLS) && !defined(USE_NSS)) if (conn->account.flags & M_ACCT_SSL) { #ifdef USE_SASL2 /* I'm not sure this actually has an effect, at least with SASLv2 */ - dprint (2, (debugfile, "External SSF: %d\n", conn->ssf)); + debug_print (2, ("External SSF: %d\n", conn->ssf)); if (sasl_setprop (*saslconn, SASL_SSF_EXTERNAL, &(conn->ssf)) != SASL_OK) #else memset (&extprops, 0, sizeof (extprops)); extprops.ssf = conn->ssf; - dprint (2, (debugfile, "External SSF: %d\n", extprops.ssf)); + debug_print (2, ("External SSF: %d\n", extprops.ssf)); if (sasl_setprop (*saslconn, SASL_SSF_EXTERNAL, &extprops) != SASL_OK) #endif { - dprint (1, - (debugfile, - "mutt_sasl_client_new: Error setting external properties\n")); + debug_print (1, ("Error setting external properties\n")); return -1; } #ifdef USE_SASL2 - dprint (2, - (debugfile, "External authentication name: %s\n", - conn->account.user)); + debug_print (2, ("External authentication name: %s\n", conn->account.user)); if (sasl_setprop (*saslconn, SASL_AUTH_EXTERNAL, conn->account.user) != SASL_OK) { - dprint (1, - (debugfile, - "mutt_sasl_client_new: Error setting external properties\n")); + debug_print (1, ("Error setting external properties\n")); return -1; } #endif @@ -389,10 +360,7 @@ int mutt_sasl_interact (sasl_interact_t * interaction) char resp[SHORT_STRING]; while (interaction->id != SASL_CB_LIST_END) { - dprint (2, - (debugfile, - "mutt_sasl_interact: filling in SASL interaction %ld.\n", - interaction->id)); + debug_print (2, ("filling in SASL interaction %ld.\n", interaction->id)); snprintf (prompt, sizeof (prompt), "%s: ", interaction->prompt); resp[0] = '\0'; @@ -436,7 +404,7 @@ void mutt_sasl_setup_conn (CONNECTION * conn, sasl_conn_t * saslconn) #else sasl_getprop (saslconn, SASL_SSF, (void **) &sasldata->ssf); #endif - dprint (3, (debugfile, "SASL protection strength: %u\n", *sasldata->ssf)); + debug_print (3, ("SASL protection strength: %u\n", *sasldata->ssf)); /* Add SASL SSF to transport SSF */ conn->ssf += *sasldata->ssf; #ifdef USE_SASL2 @@ -445,9 +413,7 @@ void mutt_sasl_setup_conn (CONNECTION * conn, sasl_conn_t * saslconn) #else sasl_getprop (saslconn, SASL_MAXOUTBUF, (void **) &sasldata->pbufsize); #endif - dprint (3, - (debugfile, "SASL protection buffer size: %u\n", - *sasldata->pbufsize)); + debug_print (3, ("SASL protection buffer size: %u\n", *sasldata->pbufsize)); /* clear input buffer */ sasldata->buf = NULL; @@ -472,7 +438,7 @@ void mutt_sasl_setup_conn (CONNECTION * conn, sasl_conn_t * saslconn) /* mutt_sasl_cb_log: callback to log SASL messages */ static int mutt_sasl_cb_log (void *context, int priority, const char *message) { - dprint (priority, (debugfile, "SASL: %s\n", message)); + debug_print (priority, ("SASL: %s\n", message)); return SASL_OK; } @@ -491,7 +457,7 @@ static int mutt_sasl_cb_authname (void *context, int id, const char **result, if (!account) return SASL_BADPARAM; - dprint (2, (debugfile, "mutt_sasl_cb_authname: getting %s for %s:%u\n", + debug_print (2, ("getting %s for %s:%u\n", id == SASL_CB_AUTHNAME ? "authname" : "user", account->host, account->port)); @@ -515,8 +481,7 @@ static int mutt_sasl_cb_pass (sasl_conn_t * conn, void *context, int id, if (!account || !psecret) return SASL_BADPARAM; - dprint (2, (debugfile, - "mutt_sasl_cb_pass: getting password for %s@%s:%u\n", + debug_print (2, ("getting password for %s@%s:%u\n", account->user, account->host, account->port)); if (mutt_account_getpass (account)) @@ -616,7 +581,7 @@ static int mutt_sasl_conn_read (CONNECTION * conn, char *buf, size_t len) rc = sasl_decode (sasldata->saslconn, buf, rc, &sasldata->buf, &sasldata->blen); if (rc != SASL_OK) { - dprint (1, (debugfile, "SASL decode failed: %s\n", + debug_print (1, ("SASL decode failed: %s\n", sasl_errstring (rc, NULL, NULL))); goto out; } @@ -664,7 +629,7 @@ static int mutt_sasl_conn_write (CONNECTION * conn, const char *buf, rc = sasl_encode (sasldata->saslconn, buf, olen, &pbuf, &plen); if (rc != SASL_OK) { - dprint (1, (debugfile, "SASL encoding failed: %s\n", + debug_print (1, ("SASL encoding failed: %s\n", sasl_errstring (rc, NULL, NULL))); goto fail; } diff --git a/mutt_socket.c b/mutt_socket.c index b231454..2cdbf25 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -26,6 +26,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -59,9 +60,7 @@ int mutt_socket_close (CONNECTION * conn) int rc = -1; if (conn->fd < 0) - dprint (1, - (debugfile, - "mutt_socket_close: Attempt to close closed connection.\n")); + debug_print (1, ("Attempt to close closed connection.\n")); else rc = conn->conn_close (conn); @@ -76,9 +75,7 @@ int mutt_socket_read (CONNECTION * conn, char *buf, size_t len) int rc; if (conn->fd < 0) { - dprint (1, - (debugfile, - "mutt_socket_read: attempt to read from closed connection\n")); + debug_print (1, ("attempt to read from closed connection\n")); return -1; } @@ -99,28 +96,23 @@ int mutt_socket_write_d (CONNECTION * conn, const char *buf, int dbg) int rc; int len; - dprint (dbg, (debugfile, "> %s", buf)); + debug_print (dbg, ("> %s", buf)); if (conn->fd < 0) { - dprint (1, - (debugfile, - "mutt_socket_write: attempt to write to closed connection\n")); + debug_print (1, ("attempt to write to closed connection\n")); return -1; } len = safe_strlen (buf); if ((rc = conn->conn_write (conn, buf, len)) < 0) { - dprint (1, (debugfile, - "mutt_socket_write: error writing, closing socket\n")); + debug_print (1, ("error writing, closing socket\n")); mutt_socket_close (conn); return -1; } if (rc < len) { - dprint (1, (debugfile, - "mutt_socket_write: ERROR: wrote %d of %d bytes!\n", rc, - len)); + debug_print (1, ("ERROR: wrote %d of %d bytes!\n", rc, len)); } return rc; @@ -134,9 +126,7 @@ int mutt_socket_readchar (CONNECTION * conn, char *c) conn->available = conn->conn_read (conn, conn->inbuf, sizeof (conn->inbuf)); else { - dprint (1, - (debugfile, - "mutt_socket_readchar: attempt to read from closed connection.\n")); + debug_print (1, ("attempt to read from closed connection.\n")); return -1; } conn->bufpos = 0; @@ -177,7 +167,7 @@ int mutt_socket_readln_d (char *buf, size_t buflen, CONNECTION * conn, else buf[i] = '\0'; - dprint (dbg, (debugfile, "< %s\n", buf)); + debug_print (dbg, ("< %s\n", buf)); /* number of bytes read, not safe_strlen */ return i + 1; @@ -281,9 +271,9 @@ static int socket_preconnect (void) int save_errno; if (safe_strlen (Preconnect)) { - dprint (2, (debugfile, "Executing preconnect: %s\n", Preconnect)); + debug_print (2, ("Executing preconnect: %s\n", Preconnect)); rc = mutt_system (Preconnect); - dprint (2, (debugfile, "Preconnect result: %d\n", rc)); + debug_print (2, ("Preconnect result: %d\n", rc)); if (rc) { save_errno = errno; mutt_perror (_("Preconnect command failed.")); @@ -309,7 +299,7 @@ static int socket_connect (int fd, struct sockaddr *sa) sa_size = sizeof (struct sockaddr_in6); #endif else { - dprint (1, (debugfile, "Unknown address family!\n")); + debug_print (1, ("Unknown address family!\n")); return -1; } @@ -322,7 +312,7 @@ static int socket_connect (int fd, struct sockaddr *sa) if (connect (fd, sa, sa_size) < 0) { save_errno = errno; - dprint (2, (debugfile, "Connection failed. errno: %d...\n", errno)); + debug_print (2, ("Connection failed. errno: %d...\n", errno)); SigInt = 0; /* reset in case we caught SIGINTR while in connect() */ } diff --git a/mutt_ssl.c b/mutt_ssl.c index 5196e48..0cf05f7 100644 --- a/mutt_ssl.c +++ b/mutt_ssl.c @@ -29,6 +29,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #if OPENSSL_VERSION_NUMBER >= 0x00904000L #define READ_X509_KEY(fp, key) PEM_read_X509(fp, key, NULL, NULL) @@ -86,19 +87,19 @@ int mutt_ssl_starttls (CONNECTION * conn) ssldata = (sslsockdata *) safe_calloc (1, sizeof (sslsockdata)); /* the ssl_use_xxx protocol options don't apply. We must use TLS in TLS. */ if (!(ssldata->ctx = SSL_CTX_new (TLSv1_client_method ()))) { - dprint (1, (debugfile, "mutt_ssl_starttls: Error allocating SSL_CTX\n")); + debug_print (1, ("Error allocating SSL_CTX\n")); goto bail_ssldata; } ssl_get_client_cert (ssldata, conn); if (!(ssldata->ssl = SSL_new (ssldata->ctx))) { - dprint (1, (debugfile, "mutt_ssl_starttls: Error allocating SSL\n")); + debug_print (1, ("Error allocating SSL\n")); goto bail_ctx; } if (SSL_set_fd (ssldata->ssl, conn->fd) != 1) { - dprint (1, (debugfile, "mutt_ssl_starttls: Error setting fd\n")); + debug_print (1, ("Error setting fd\n")); goto bail_ssl; } @@ -435,13 +436,13 @@ static int check_certificate_by_signer (X509 * peercert) if (X509_STORE_set_default_paths (ctx)) pass++; else - dprint (2, (debugfile, "X509_STORE_set_default_paths failed\n")); + debug_print (2, ("X509_STORE_set_default_paths failed\n")); } if (X509_STORE_load_locations (ctx, SslCertFile, NULL)) pass++; else - dprint (2, (debugfile, "X509_STORE_load_locations_failed\n")); + debug_print (2, ("X509_STORE_load_locations_failed\n")); if (pass == 0) { /* nothing to do */ @@ -460,7 +461,7 @@ static int check_certificate_by_signer (X509 * peercert) err = X509_STORE_CTX_get_error (&xsc); snprintf (buf, sizeof (buf), "%s (%d)", X509_verify_cert_error_string (err), err); - dprint (2, (debugfile, "X509_verify_cert: %s\n", buf)); + debug_print (2, ("X509_verify_cert: %s\n", buf)); } #endif X509_STORE_CTX_cleanup (&xsc); @@ -479,13 +480,13 @@ static int check_certificate_by_digest (X509 * peercert) /* expiration check */ if (X509_cmp_current_time (X509_get_notBefore (peercert)) >= 0) { - dprint (2, (debugfile, "Server certificate is not yet valid\n")); + debug_print (2, ("Server certificate is not yet valid\n")); mutt_error (_("Server certificate is not yet valid")); mutt_sleep (2); return 0; } if (X509_cmp_current_time (X509_get_notAfter (peercert)) <= 0) { - dprint (2, (debugfile, "Server certificate has expired")); + debug_print (2, ("Server certificate has expired\n")); mutt_error (_("Server certificate has expired")); mutt_sleep (2); return 0; @@ -536,13 +537,13 @@ static int ssl_check_certificate (sslsockdata * data) char *name = NULL, *c; if (check_certificate_by_signer (data->cert)) { - dprint (1, (debugfile, "ssl_check_certificate: signer check passed\n")); + debug_print (1, ("signer check passed\n")); return 1; } /* automatic check from user's database */ if (SslCertFile && check_certificate_by_digest (data->cert)) { - dprint (1, (debugfile, "ssl_check_certificate: digest check passed\n")); + debug_print (1, ("digest check passed\n")); return 1; } @@ -643,7 +644,7 @@ static int ssl_check_certificate (sslsockdata * data) static void ssl_get_client_cert (sslsockdata * ssldata, CONNECTION * conn) { if (SslClientCert) { - dprint (2, (debugfile, "Using client certificate %s\n", SslClientCert)); + debug_print (2, ("Using client certificate %s\n", SslClientCert)); SSL_CTX_set_default_passwd_cb_userdata (ssldata->ctx, &conn->account); SSL_CTX_set_default_passwd_cb (ssldata->ctx, ssl_passwd_cb); SSL_CTX_use_certificate_file (ssldata->ctx, SslClientCert, @@ -660,7 +661,7 @@ static int ssl_passwd_cb (char *buf, int size, int rwflag, void *userdata) if (mutt_account_getuser (account)) return 0; - dprint (2, (debugfile, "ssl_passwd_cb: getting password for %s@%s:%u\n", + debug_print (2, ("getting password for %s@%s:%u\n", account->user, account->host, account->port)); if (mutt_account_getpass (account)) diff --git a/muttlib.c b/muttlib.c index 0676729..d7e88ed 100644 --- a/muttlib.c +++ b/muttlib.c @@ -30,6 +30,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -170,13 +171,11 @@ void mutt_free_body (BODY ** p) if (b->parameter) mutt_free_parameter (&b->parameter); if (b->unlink && b->filename) { - dprint (1, (debugfile, "mutt_free_body: Unlinking %s.\n", b->filename)); + debug_print (1, ("unlinking %s.\n", b->filename)); unlink (b->filename); } else if (b->filename) - dprint (1, - (debugfile, "mutt_free_body: Not unlinking %s.\n", - b->filename)); + debug_print (1, ("not unlinking %s.\n", b->filename)); FREE (&b->filename); FREE (&b->content); @@ -650,8 +649,7 @@ void _mutt_mktemp (char *s, const char *src, int line) { snprintf (s, _POSIX_PATH_MAX, "%s/muttng-%s-%d-%d-%d", NONULL (Tempdir), NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++); - dprint (1, - (debugfile, "%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s)); + debug_print (1, ("%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s)); unlink (s); } @@ -1475,12 +1473,7 @@ int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x) if (regexec (l->rx->rx, s, (size_t) l->nmatch, (regmatch_t *) pmatch, (int) 0) == 0) { - dprint (5, - (debugfile, "mutt_match_spam_list: %s matches %s\n", s, - l->rx->pattern)); - dprint (5, - (debugfile, "mutt_match_spam_list: %d subs\n", - l->rx->rx->re_nsub)); + debug_print (5, ("%s matches %s\n%d subst", s, l->rx->pattern, l->rx->rx->re_nsub)); /* Copy template into text, with substitutions. */ for (p = l->template; *p;) { @@ -1496,7 +1489,7 @@ int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x) } } text[tlen] = '\0'; - dprint (5, (debugfile, "mutt_match_spam_list: \"%s\"\n", text)); + debug_print (5, ("\"%s\"\n", text)); return 1; } } diff --git a/mx.c b/mx.c index 5764a51..7f92fb6 100644 --- a/mx.c +++ b/mx.c @@ -55,6 +55,7 @@ #include "lib/intl.h" #include "lib/str.h" #include "lib/list.h" +#include "lib/debug.h" #include #include @@ -200,7 +201,7 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout) while (fcntl (fd, F_SETLK, &lck) == -1) { struct stat sb; - dprint (1, (debugfile, "mx_lock_file(): fcntl errno %d.\n", errno)); + debug_print (1, ("fcntl errno %d.\n", errno)); if (errno != EAGAIN && errno != EACCES) { mutt_perror ("fcntl"); return (-1); @@ -1105,8 +1106,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) ADDRESS *p = NULL; if (!MX_IDX(dest->magic-1)) { - dprint (1, (debugfile, "mx_open_new_message(): function " - "unimplemented for mailbox type %d.\n", dest->magic)); + debug_print (1, ("function unimplemented for mailbox type %d.\n", dest->magic)); return (NULL); } @@ -1206,7 +1206,7 @@ int mx_check_mailbox (CONTEXT * ctx, int *index_hint, int lock) } } - dprint (1, (debugfile, "mx_check_mailbox: null or invalid context.\n")); + debug_print (1, ("null or invalid context.\n")); return (-1); } @@ -1236,8 +1236,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) if (msg->fp == NULL) { mutt_perror (path); - dprint (1, (debugfile, "mx_open_message: fopen: %s: %s (errno %d).\n", - path, strerror (errno), errno)); + debug_print (1, ("fopen: %s: %s (errno %d).\n", path, strerror (errno), errno)); FREE (&msg); } } @@ -1271,10 +1270,7 @@ MESSAGE *mx_open_message (CONTEXT * ctx, int msgno) #endif /* USE_NNTP */ default: - dprint (1, - (debugfile, - "mx_open_message(): function not implemented for mailbox type %d.\n", - ctx->magic)); + debug_print (1, ("function not implemented for mailbox type %d.\n", ctx->magic)); FREE (&msg); break; } @@ -1288,10 +1284,7 @@ int mx_commit_message (MESSAGE * msg, CONTEXT * ctx) int r = 0; if (!(msg->write && ctx->append)) { - dprint (1, - (debugfile, - "mx_commit_message(): msg->write = %d, ctx->append = %d\n", - msg->write, ctx->append)); + debug_print (1, ("msg->write = %d, ctx->append = %d\n", msg->write, ctx->append)); return -1; } @@ -1364,8 +1357,7 @@ int mx_close_message (MESSAGE ** msg) (*msg)->fp = NULL; if ((*msg)->path) { - dprint (1, (debugfile, "mx_close_message (): unlinking %s\n", - (*msg)->path)); + debug_print (1, ("unlinking %s\n", (*msg)->path)); unlink ((*msg)->path); FREE (&(*msg)->path); } diff --git a/nntp/newsrc.c b/nntp/newsrc.c index 32df852..0978381 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -26,6 +26,7 @@ #include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -124,7 +125,7 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) data->lastMessage = data->entries[x - 1].last; data->num = x; mutt_newsgroup_stat (data); - dprint (2, (debugfile, "parse_line: Newsgroup %s\n", data->group)); + debug_print (2, ("Newsgroup %s\n", data->group)); return 0; } @@ -437,7 +438,7 @@ void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article) if (!data) { #ifdef DEBUG if (group) - dprint (3, (debugfile, "newsgroup %s not found\n", group)); + debug_print (3, ("newsgroup %s not found\n", group)); #endif return; } @@ -644,7 +645,7 @@ int mutt_newsrc_update (NNTP_SERVER * news) if (!data || !data->rc) continue; nntp_create_newsrc_line (data, &buf, &line, &llen); - dprint (2, (debugfile, "Added to newsrc: %s", line)); + debug_print (2, ("Added to newsrc: %s\n", line)); line += safe_strlen (line); } /* newrc being fully rewritten */ @@ -715,7 +716,7 @@ void nntp_clear_cacheindex (NNTP_SERVER * news) if (!data || data->subscribed || !data->cache) continue; nntp_delete_cache (data); - dprint (2, (debugfile, "Removed from .index: %s\n", data->group)); + debug_print (2, ("Removed from .index: %s\n", data->group)); } return; } diff --git a/nntp/nntp.c b/nntp/nntp.c index 311a0fc..11bfea0 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -34,6 +34,7 @@ #include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -42,14 +43,9 @@ static unsigned int _checked = 0; -#ifdef DEBUG -static void nntp_error (const char *where, const char *msg) -{ - dprint (1, - (debugfile, "nntp_error(): unexpected response in %s: %s\n", where, - msg)); +static void nntp_error (const char *where, const char *msg) { + debug_print (1, ("unexpected response in %s: %s\n", where, msg)); } -#endif /* DEBUG */ static int nntp_auth (NNTP_SERVER * serv) { @@ -74,8 +70,8 @@ static int nntp_auth (NNTP_SERVER * serv) #ifdef DEBUG /* don't print the password unless we're at the ungodly debugging level */ - if (debuglevel < M_SOCK_LOG_FULL) - dprint (M_SOCK_LOG_CMD, (debugfile, "> AUTHINFO PASS *\n")); + if (DebugLevel < M_SOCK_LOG_FULL) + debug_print (M_SOCK_LOG_CMD, ("> AUTHINFO PASS *\n")); #endif snprintf (buf, sizeof (buf), "AUTHINFO PASS %s\r\n", conn->account.pass); mutt_socket_write_d (conn, buf, M_SOCK_LOG_FULL); @@ -431,10 +427,8 @@ static int nntp_read_header (CONTEXT * ctx, const char *msgid, ret = mutt_nntp_fetch (nntp_data, buf, NULL, nntp_read_tempfile, f, 0); if (ret) { -#ifdef DEBUG if (ret != -1) - dprint (1, (debugfile, "nntp_read_header: %s\n", buf)); -#endif + debug_print (1, ("%s\n", buf)); fclose (f); unlink (tempfile); return (ret == -1 ? -1 : 1); @@ -470,7 +464,7 @@ static int parse_description (char *line, void *n) d++; while (*d && (*d == '\t' || *d == ' ')) d++; - dprint (2, (debugfile, "group: %s, desc: %s\n", line, d)); + debug_print (2, ("group: %s, desc: %s\n", line, d)); if ((data = (NNTP_DATA *) hash_find (news->newsgroups, line)) != NULL && safe_strcmp (d, data->desc)) { FREE (&data->desc); @@ -937,7 +931,7 @@ int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) if (ret == 1) { mutt_error (_("Article %d not found on server"), ctx->hdrs[msgno]->article_num); - dprint (1, (debugfile, "nntp_fetch_message: %s\n", buf)); + debug_print (1, ("%s\n", buf)); } if (ret) { diff --git a/pager.c b/pager.c index 8c01daa..4a935c3 100644 --- a/pager.c +++ b/pager.c @@ -39,6 +39,7 @@ #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" +#include "lib/debug.h" #include #include @@ -915,7 +916,7 @@ fill_buffer (FILE * f, long *last_pos, long offset, unsigned char *buf, } else if (*p == '\033' && *(p + 1) == ']' && check_attachment_marker ((char *) p) == 0) { - dprint (2, (debugfile, "fill_buffer: Seen attachment marker.\n")); + debug_print (2, ("seen attachment marker.\n")); while (*p++ != '\a') /* skip pseudo-ANSI sequence */ ; } @@ -974,8 +975,7 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf, k = mbrtowc (&wc, (char *) buf + ch, cnt - ch, &mbstate); if (k == -2 || k == -1) { - dprint (1, (debugfile, "%s:%d: mbrtowc returned %d; errno = %d.\n", - __FILE__, __LINE__, k, errno)); + debug_print (1, ("mbrtowc returned %d; errno = %d.\n", k, errno)); if (col + 4 > wrap_cols) break; col += 4; diff --git a/parse.c b/parse.c index e074911..65a02b4 100644 --- a/parse.c +++ b/parse.c @@ -23,6 +23,7 @@ #include "lib/intl.h" #include "lib/str.h" #include "lib/rx.h" +#include "lib/debug.h" #include #include @@ -168,12 +169,11 @@ static PARAMETER *parse_parameters (const char *s) const char *p; size_t i; - dprint (2, (debugfile, "parse_parameters: `%s'\n", s)); + debug_print (2, ("`%s'\n", s)); while (*s) { if ((p = strpbrk (s, "=;")) == NULL) { - dprint (1, - (debugfile, "parse_parameters: malformed parameter: %s\n", s)); + debug_print (1, ("malformed parameter: %s\n", s)); goto bail; } @@ -233,8 +233,7 @@ static PARAMETER *parse_parameters (const char *s) new->value = safe_strdup (buffer); - dprint (2, (debugfile, "parse_parameter: `%s' = `%s'\n", - new->attribute ? new->attribute : "", + debug_print (2, ("`%s' = `%s'\n", new->attribute ? new->attribute : "", new->value ? new->value : "")); /* Add this parameter to the list */ @@ -246,9 +245,7 @@ static PARAMETER *parse_parameters (const char *s) head = cur = new; } else { - dprint (1, - (debugfile, "parse_parameters(): parameter with no value: %s\n", - s)); + debug_print (1, ("parameter with no value: %s\n", s)); s = p; } @@ -431,16 +428,12 @@ BODY *mutt_read_mime_header (FILE * fp, int digest) c++; SKIPWS (c); if (!*c) { - dprint (1, - (debugfile, - "mutt_read_mime_header(): skipping empty header field: %s\n", - line)); + debug_print (1, ("skipping empty header field: %s\n", line)); continue; } } else { - dprint (1, - (debugfile, "read_mime_header: bogus MIME header: %s\n", line)); + debug_print (1, ("bogus MIME header: %s\n", line)); break; } @@ -836,9 +829,7 @@ time_t mutt_parse_date (const char *s, HEADER * h) else if (sscanf (t, "%d:%d", &hour, &min) == 2) sec = 0; else { - dprint (1, - (debugfile, "parse_date: could not process time format: %s\n", - t)); + debug_print (1, ("could not process time format: %s\n", t)); return (-1); } tm.tm_hour = hour; @@ -898,9 +889,7 @@ time_t mutt_parse_date (const char *s, HEADER * h) } if (count < 4) { /* don't check for missing timezone */ - dprint (1, - (debugfile, - "parse_date(): error parsing date format, using received time\n")); + debug_print (1, ("error parsing date format, using received time\n")); return (-1); } @@ -1380,7 +1369,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs, } if (e->spam && e->spam->data) - dprint (5, (debugfile, "p822: spam = %s\n", e->spam->data)); + debug_print (5, ("spam = %s\n", e->spam->data)); } } @@ -1424,9 +1413,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs, /* check for missing or invalid date */ if (hdr->date_sent <= 0) { - dprint (1, - (debugfile, - "read_rfc822_header(): no date found, using received time from msg separator\n")); + debug_print (1, ("no date found, using received time from msg separator\n")); hdr->date_sent = hdr->received; } } diff --git a/pgp.c b/pgp.c index 7bf892c..b971626 100644 --- a/pgp.c +++ b/pgp.c @@ -30,6 +30,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -139,14 +140,11 @@ static int pgp_copy_checksig (FILE * fpin, FILE * fpout) while ((line = mutt_read_line (line, &linelen, fpin, &lineno)) != NULL) { if (regexec (PgpGoodSign.rx, line, 0, NULL, 0) == 0) { - dprint (2, (debugfile, "pgp_copy_checksig: \"%s\" matches regexp.\n", - line)); + debug_print (2, ("\"%s\" matches regexp.\n", line)); rv = 0; } else - dprint (2, - (debugfile, - "pgp_copy_checksig: \"%s\" doesn't match regexp.\n", line)); + debug_print (2, ("\"%s\" doesn't match regexp.\n", line)); if (strncmp (line, "[GNUPG:] ", 9) == 0) continue; @@ -156,7 +154,7 @@ static int pgp_copy_checksig (FILE * fpin, FILE * fpout) FREE (&line); } else { - dprint (2, (debugfile, "pgp_copy_checksig: No pattern.\n")); + debug_print (2, ("No pattern.\n")); mutt_copy_stream (fpin, fpout); rv = 1; } @@ -561,9 +559,7 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) if ((rv = mutt_wait_filter (thepid))) badsig = -1; - dprint (1, - (debugfile, "pgp_verify_one: mutt_wait_filter returned %d.\n", - rv)); + debug_print (1, ("mutt_wait_filter returned %d.\n", rv)); } safe_fclose (&pgperr); @@ -573,7 +569,7 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) mutt_unlink (sigfile); mutt_unlink (pgperrfile); - dprint (1, (debugfile, "pgp_verify_one: returning %d.\n", badsig)); + debug_print (1, ("returning %d.\n", badsig)); return badsig; } diff --git a/pgpinvoke.c b/pgpinvoke.c index 91d2b00..a02a5f3 100644 --- a/pgpinvoke.c +++ b/pgpinvoke.c @@ -34,6 +34,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" /* * The actual command line formatter. @@ -139,7 +140,7 @@ void mutt_pgp_command (char *d, size_t dlen, struct pgp_command_context *cctx, { mutt_FormatString (d, dlen, NONULL (fmt), _mutt_fmt_pgp_command, (unsigned long) cctx, 0); - dprint (2, (debugfile, "mutt_pgp_command: %s\n", d)); + debug_print (2, ("%s\n", d)); } /* diff --git a/pgpkey.c b/pgpkey.c index 5e5172d..42dc0ff 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -23,6 +23,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -811,17 +812,15 @@ pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) if (!keys) return NULL; - dprint (5, (debugfile, "pgp_getkeybyaddr: looking for %s <%s>.", - a->personal, a->mailbox)); - + debug_print (5, ("looking for %s <%s>\n", a->personal, a->mailbox)); for (k = keys; k; k = kn) { kn = k->next; - dprint (5, (debugfile, " looking at key: %s\n", pgp_keyid (k))); + debug_print (5, (" looking at key: %s\n", pgp_keyid (k))); if (abilities && !(k->flags & abilities)) { - dprint (5, (debugfile, " insufficient abilities: Has %x, want %x\n", + debug_print (5, (" insufficient abilities: Has %x, want %x\n", k->flags, abilities)); continue; } @@ -928,17 +927,14 @@ pgp_key_t pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring) match = 0; for (a = k->address; a; a = a->next) { - dprint (5, - (debugfile, - "pgp_getkeybystr: matching \"%s\" against key %s, \"%s\": ", p, - pgp_keyid (k), a->addr)); + debug_print (5, ("matching \"%s\" against key %s, \"%s\":\n", p, pgp_keyid (k), a->addr)); if (!*p || safe_strcasecmp (p, pgp_keyid (k)) == 0 || (!safe_strncasecmp (p, "0x", 2) && !safe_strcasecmp (p + 2, pgp_keyid (k))) || (option (OPTPGPLONGIDS) && !safe_strncasecmp (p, "0x", 2) && !safe_strcasecmp (p + 2, k->keyid + 8)) || str_isstr (a->addr, p)) { - dprint (5, (debugfile, "match.\n")); + debug_print (5, ("match.\n")); match = 1; break; } diff --git a/pgpmicalg.c b/pgpmicalg.c index 0fc65c0..80f7c38 100644 --- a/pgpmicalg.c +++ b/pgpmicalg.c @@ -26,6 +26,8 @@ #include #include +#include "lib/debug.h" + static struct { short id; const char *name; @@ -73,8 +75,7 @@ static void pgp_dearmor (FILE * in, FILE * out) break; } if (r == NULL) { - dprint (1, - (debugfile, "pgp_dearmor: Can't find begin of ASCII armor.\n")); + debug_print (1, ("Can't find begin of ASCII armor.\n")); return; } @@ -86,7 +87,7 @@ static void pgp_dearmor (FILE * in, FILE * out) break; } if (r == NULL) { - dprint (1, (debugfile, "pgp_dearmor: Armor header doesn't end.\n")); + debug_print (1, ("Armor header doesn't end.\n")); return; } @@ -100,17 +101,17 @@ static void pgp_dearmor (FILE * in, FILE * out) break; } if (r == NULL) { - dprint (1, (debugfile, "pgp_dearmor: Can't find end of ASCII armor.\n")); + debug_print (1, ("Can't find end of ASCII armor.\n")); return; } if ((end = ftell (in) - safe_strlen (line)) < start) { - dprint (1, (debugfile, "pgp_dearmor: end < start???\n")); + debug_print (1, ("end < start???\n")); return; } if (fseek (in, start, SEEK_SET) == -1) { - dprint (1, (debugfile, "pgp_dearmor: Can't seekto start.\n")); + debug_print (1, ("Can't seekto start.\n")); return; } @@ -121,8 +122,7 @@ static short pgp_mic_from_packet (unsigned char *p, size_t len) { /* is signature? */ if ((p[0] & 0x3f) != PT_SIG) { - dprint (1, (debugfile, "pgp_mic_from_packet: tag = %d, want %d.\n", - p[0] & 0x3f, PT_SIG)); + debug_print (1, ("tag = %d, want %d.\n", p[0] & 0x3f, PT_SIG)); return -1; } @@ -133,7 +133,7 @@ static short pgp_mic_from_packet (unsigned char *p, size_t len) /* version 4 signature */ return (short) p[4]; else { - dprint (1, (debugfile, "pgp_mic_from_packet: Bad signature packet.\n")); + debug_print (1, ("Bad signature packet.\n")); return -1; } } @@ -169,7 +169,7 @@ static short pgp_find_hash (const char *fname) rv = pgp_mic_from_packet (p, l); } else { - dprint (1, (debugfile, "pgp_find_hash: No packet.\n")); + debug_print (1, ("No packet.\n")); } bye: diff --git a/pop/pop.c b/pop/pop.c index d737521..1e578c7 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -19,6 +19,7 @@ #include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -71,13 +72,13 @@ static pop_query_status pop_read_header (POP_DATA * pop_data, HEADER * h) if (ret == PQ_OK) { pop_data->cmd_top = CMD_AVAILABLE; - dprint (1, (debugfile, "pop_read_header: set TOP capability\n")); + debug_print (1, ("set TOP capability\n")); } if (ret == PQ_ERR) { pop_data->cmd_top = CMD_NOT_AVAILABLE; - dprint (1, (debugfile, "pop_read_header: unset TOP capability\n")); + debug_print (1, ("unset TOP capability\n")); snprintf (pop_data->err_msg, sizeof (pop_data->err_msg), _("Command TOP is not supported by server.")); } @@ -128,9 +129,7 @@ static int fetch_uidl (char *line, void *data) break; if (i == ctx->msgcount) { - dprint (1, - (debugfile, "pop_fetch_headers: new header %d %s\n", index, - line)); + debug_print (1, ("new header %d %s\n", index, line)); if (i >= ctx->hdrmax) mx_alloc_memory (ctx); @@ -177,13 +176,13 @@ static int pop_fetch_headers (CONTEXT * ctx) if (ret == PQ_OK) { pop_data->cmd_uidl = CMD_AVAILABLE; - dprint (1, (debugfile, "pop_fetch_headers: set UIDL capability\n")); + debug_print (1, ("set UIDL capability\n")); } if (ret == PQ_ERR && pop_data->cmd_uidl == CMD_UNKNOWN) { pop_data->cmd_uidl = CMD_NOT_AVAILABLE; - dprint (1, (debugfile, "pop_fetch_headers: unset UIDL capability\n")); + debug_print (1, ("unset UIDL capability\n")); snprintf (pop_data->err_msg, sizeof (pop_data->err_msg), _("Command UIDL is not supported by server.")); } @@ -282,7 +281,7 @@ static void pop_clear_cache (POP_DATA * pop_data) if (!pop_data->clear_cache) return; - dprint (1, (debugfile, "pop_clear_cache: delete cached messages\n")); + debug_print (1, ("delete cached messages\n")); for (i = 0; i < POP_CACHE_LEN; i++) { if (pop_data->cache[i].path) { diff --git a/pop/pop_auth.c b/pop/pop_auth.c index df6de73..840f9e8 100644 --- a/pop/pop_auth.c +++ b/pop/pop_auth.c @@ -18,6 +18,7 @@ #include "lib/mem.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -54,9 +55,7 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method) unsigned char client_start; if (mutt_sasl_client_new (pop_data->conn, &saslconn) < 0) { - dprint (1, - (debugfile, - "pop_auth_sasl: Error allocating SASL connection.\n")); + debug_print (1, ("Error allocating SASL connection.\n")); return POP_A_FAILURE; } @@ -77,9 +76,7 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method) } if (rc != SASL_OK && rc != SASL_CONTINUE) { - dprint (1, - (debugfile, - "pop_auth_sasl: Failure starting authentication exchange. No shared mechanisms?\n")); + debug_print (1, ("Failure starting authentication exchange. No shared mechanisms?\n")); /* SASL doesn't support suggested mechanisms, so fall back */ return POP_A_UNAVAIL; @@ -114,9 +111,7 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method) && sasl_decode64 (inbuf, strlen (inbuf), buf, &len) != SASL_OK) #endif { - dprint (1, - (debugfile, - "pop_auth_sasl: error base64-decoding server response.\n")); + debug_print (1, ("error base64-decoding server response.\n")); goto bail; } @@ -136,9 +131,7 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method) /* send out response, or line break if none needed */ if (pc) { if (sasl_encode64 (pc, olen, buf, sizeof (buf), &olen) != SASL_OK) { - dprint (1, - (debugfile, - "pop_auth_sasl: error base64-encoding client response.\n")); + debug_print (1, ("error base64-encoding client response.\n")); goto bail; } @@ -250,13 +243,13 @@ static pop_auth_res_t pop_auth_user (POP_DATA * pop_data, const char *method) if (ret == PQ_OK) { pop_data->cmd_user = CMD_AVAILABLE; - dprint (1, (debugfile, "pop_auth_user: set USER capability\n")); + debug_print (1, ("set USER capability\n")); } if (ret == PQ_ERR) { pop_data->cmd_user = CMD_NOT_AVAILABLE; - dprint (1, (debugfile, "pop_auth_user: unset USER capability\n")); + debug_print (1, ("unset USER capability\n")); snprintf (pop_data->err_msg, sizeof (pop_data->err_msg), _("Command USER is not supported by server.")); } @@ -266,10 +259,10 @@ static pop_auth_res_t pop_auth_user (POP_DATA * pop_data, const char *method) snprintf (buf, sizeof (buf), "PASS %s\r\n", pop_data->conn->account.pass); ret = pop_query_d (pop_data, buf, sizeof (buf), #ifdef DEBUG - /* don't print the password unless we're at the ungodly debugging level */ - debuglevel < M_SOCK_LOG_FULL ? "PASS *\r\n" : + /* don't print the password unless we're at the ungodly debugging level */ + DebugLevel < M_SOCK_LOG_FULL ? "PASS *\r\n" : #endif - NULL); + NULL); } switch (ret) { @@ -324,7 +317,7 @@ pop_query_status pop_authenticate (POP_DATA * pop_data) comma = strchr (method, ':'); if (comma) *comma++ = '\0'; - dprint (2, (debugfile, "pop_authenticate: Trying method %s\n", method)); + debug_print (2, ("Trying method %s\n", method)); authenticator = pop_authenticators; while (authenticator->authenticate) { @@ -360,8 +353,7 @@ pop_query_status pop_authenticate (POP_DATA * pop_data) } else { /* Fall back to default: any authenticator */ - dprint (2, - (debugfile, "pop_authenticate: Using any available method.\n")); + debug_print (2, ("Using any available method.\n")); authenticator = pop_authenticators; while (authenticator->authenticate) { diff --git a/pop/pop_lib.c b/pop/pop_lib.c index 1b4e267..f63e4f7 100644 --- a/pop/pop_lib.c +++ b/pop/pop_lib.c @@ -21,6 +21,7 @@ #include "lib/mem.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -388,7 +389,7 @@ pop_query_status pop_query_d (POP_DATA * pop_data, char *buf, size_t buflen, cha /* print msg instaed of real command */ if (msg) { dbg = M_SOCK_LOG_FULL; - dprint (M_SOCK_LOG_CMD, (debugfile, "> %s", msg)); + debug_print (M_SOCK_LOG_CMD, ("> %s", msg)); } #endif diff --git a/postpone.c b/postpone.c index a2815c9..bee4690 100644 --- a/postpone.c +++ b/postpone.c @@ -28,6 +28,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -83,15 +84,10 @@ int mutt_num_postponed (int force) newpc = imap_mailbox_check (Postponed, 0); if (newpc >= 0) { PostCount = newpc; - dprint (2, - (debugfile, - "mutt_num_postponed: %d postponed IMAP messages found.\n", - PostCount)); + debug_print (2, ("%d postponed IMAP messages found.\n", PostCount)); } else - dprint (2, - (debugfile, - "mutt_num_postponed: using old IMAP postponed count.\n")); + debug_print (2, ("using old IMAP postponed count.\n")); } return PostCount; } diff --git a/protos.h b/protos.h index b8c08cc..f1d38b2 100644 --- a/protos.h +++ b/protos.h @@ -18,12 +18,6 @@ #endif #include "mbyte.h" -#ifdef DEBUG -#define dprint(N,X) do { if(debuglevel>=N) fprintf X; } while (0) -#else -#define dprint(N,X) -#endif - #define MoreArgs(p) (*p->dptr && *p->dptr != ';' && *p->dptr != '#') #define mutt_make_string(A,B,C,D,E) _mutt_make_string(A,B,C,D,E,0) diff --git a/query.c b/query.c index 9390bcf..570ef07 100644 --- a/query.c +++ b/query.c @@ -20,6 +20,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -85,7 +86,7 @@ static QUERY *run_query (char *s, int quiet) mutt_expand_file_fmt (cmd, sizeof (cmd), QueryCmd, s); if ((thepid = mutt_create_filter (cmd, NULL, &fp, NULL)) < 0) { - dprint (1, (debugfile, "unable to fork command: %s", cmd)); + debug_print (1, ("unable to fork command: %s\n", cmd)); return 0; } if (!quiet) @@ -128,7 +129,7 @@ static QUERY *run_query (char *s, int quiet) FREE (&buf); fclose (fp); if (mutt_wait_filter (thepid)) { - dprint (1, (debugfile, "Error: %s\n", msg)); + debug_print (1, ("Error: %s\n", msg)); if (!quiet) mutt_error ("%s", msg); } diff --git a/rfc1524.c b/rfc1524.c index 5466a75..75a986b 100644 --- a/rfc1524.c +++ b/rfc1524.c @@ -27,6 +27,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -188,7 +189,7 @@ static int rfc1524_mailcap_parse (BODY * a, /* ignore comments */ if (*buf == '#') continue; - dprint (2, (debugfile, "mailcap entry: %s\n", buf)); + debug_print (2, ("mailcap entry: %s\n", buf)); /* check type */ ch = get_field (buf); @@ -212,7 +213,7 @@ static int rfc1524_mailcap_parse (BODY * a, while (ch) { field = ch; ch = get_field (ch); - dprint (2, (debugfile, "field: %s\n", field)); + debug_print (2, ("field: %s\n", field)); if (!ascii_strcasecmp (field, "needsterminal")) { if (entry) @@ -376,7 +377,7 @@ int rfc1524_mailcap_lookup (BODY * a, char *type, rfc1524_entry * entry, path[x] = '\0'; mutt_expand_path (path, sizeof (path)); - dprint (2, (debugfile, "Checking mailcap file: %s\n", path)); + debug_print (2, ("Checking mailcap file: %s\n", path)); found = rfc1524_mailcap_parse (a, path, type, entry, opt); } diff --git a/send.c b/send.c index 6f988dd..d789804 100644 --- a/send.c +++ b/send.c @@ -25,6 +25,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -1208,10 +1209,8 @@ int ci_send_message (int flags, /* send mode */ } if (!tempfp) { - dprint (1, - (debugfile, - "newsend_message: can't create tempfile %s (errno=%d)\n", - msg->content->filename, errno)); + debug_print (1, ("can't create tempfile %s (errno=%d)\n", + msg->content->filename, errno)); mutt_perror (msg->content->filename); goto cleanup; } diff --git a/sendlib.c b/sendlib.c index 010e72e..12f8df5 100644 --- a/sendlib.c +++ b/sendlib.c @@ -28,6 +28,7 @@ #include "lib/mem.h" #include "lib/str.h" #include "lib/intl.h" +#include "lib/debug.h" #include #include @@ -456,9 +457,7 @@ int mutt_write_mime_body (BODY * a, FILE * f) if (a->type == TYPEMULTIPART) { /* First, find the boundary to use */ if (!(p = mutt_get_parameter ("boundary", a->parameter))) { - dprint (1, - (debugfile, - "mutt_write_mime_body(): no boundary parameter found!\n")); + debug_print (1, ("no boundary parameter found!\n")); mutt_error _("No boundary parameter found! [report this error]"); return (-1); @@ -486,9 +485,7 @@ int mutt_write_mime_body (BODY * a, FILE * f) } if ((fpin = fopen (a->filename, "r")) == NULL) { - dprint (1, - (debugfile, "write_mime_body: %s no longer exists!\n", - a->filename)); + debug_print (1, ("%s no longer exists!\n", a->filename)); mutt_error (_("%s no longer exists!"), a->filename); return -1; } @@ -898,8 +895,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b) } if ((fp = fopen (fname, "r")) == NULL) { - dprint (1, (debugfile, "mutt_get_content_info: %s: %s (errno %d).\n", - fname, strerror (errno), errno)); + debug_print (1, ("%s: %s (errno %d).\n", fname, strerror (errno), errno)); return (NULL); } @@ -980,10 +976,7 @@ int mutt_lookup_mime_type (BODY * att, const char *path) strfcpy (buf, PKGDATADIR "/mime.types", sizeof (buf)); break; default: - dprint (1, - (debugfile, - "mutt_lookup_mime_type: Internal error, count = %d.\n", - count)); + debug_print (1, ("Internal error, count = %d.\n", count)); goto bye; /* shouldn't happen */ } @@ -2397,8 +2390,7 @@ ADDRESS *mutt_remove_duplicates (ADDRESS * addr) } if (dup) { - dprint (2, (debugfile, "mutt_remove_duplicates: Removing %s\n", - addr->mailbox)); + debug_print (2, ("Removing %s\n", addr->mailbox)); *last = addr->next; @@ -2443,10 +2435,7 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, set_noconv_flags (hdr->content, 1); if (mx_open_mailbox (path, M_APPEND | M_QUIET, &f) == NULL) { - dprint (1, - (debugfile, - "mutt_write_fcc(): unable to open mailbox %s in append-mode, aborting.\n", - path)); + debug_print (1, ("unable to open mailbox %s in append-mode, aborting.\n", path)); return (-1); } @@ -2561,8 +2550,7 @@ int mutt_write_fcc (const char *path, HEADER * hdr, const char *msgid, fflush (tempfp); if (ferror (tempfp)) { - dprint (1, - (debugfile, "mutt_write_fcc(): %s: write failed.\n", tempfile)); + debug_print (1, ("%s: write failed.\n", tempfile)); fclose (tempfp); unlink (tempfile); mx_commit_message (msg, &f); /* XXX - really? */ diff --git a/smime.c b/smime.c index d7a4d7c..6928585 100644 --- a/smime.c +++ b/smime.c @@ -23,6 +23,7 @@ #include "lib/mem.h" #include "lib/intl.h" #include "lib/str.h" +#include "lib/debug.h" #include #include @@ -249,12 +250,9 @@ static void mutt_smime_command (char *d, size_t dlen, { mutt_FormatString (d, dlen, NONULL (fmt), _mutt_fmt_smime_command, (unsigned long) cctx, 0); - dprint (2, (debugfile, "mutt_smime_command: %s\n", d)); + debug_print (2, ("%s\n", d)); } - - - static pid_t smime_invoke (FILE ** smimein, FILE ** smimeout, FILE ** smimeerr, int smimeinfd, int smimeoutfd, int smimeerrfd, const char *fname, diff --git a/snprintf.c b/snprintf.c index 72c3d11..2ec459b 100644 --- a/snprintf.c +++ b/snprintf.c @@ -50,6 +50,7 @@ #include #include #include "lib/str.h" +#include "lib/debug.h" /* Define this as a fall through, HAVE_STDARG_H is probably already set */ @@ -479,7 +480,7 @@ static void fmtint (char *buffer, size_t * currlen, size_t maxlen, spadlen = -spadlen; /* Left Justifty */ #ifdef DEBUG_SNPRINTF - dprint (1, (debugfile, "zpad: %d, spad: %d, min: %d, max: %d, place: %d\n", + debug_print (1, ("zpad: %d, spad: %d, min: %d, max: %d, place: %d\n", zpadlen, spadlen, min, max, place)); #endif @@ -602,7 +603,7 @@ static void fmtfp (char *buffer, size_t * currlen, size_t maxlen, } #ifdef DEBUG_SNPRINTF - dprint (1, (debugfile, "fmtfp: %f =? %d.%d\n", fvalue, intpart, fracpart)); + debug_print (1, ("fmtfp: %f =? %d.%d\n", fvalue, intpart, fracpart)); #endif /* Convert integer part */