Skip to content

Commit

Permalink
Use GLib error reporting/logging instead of fprintf()
Browse files Browse the repository at this point in the history
This makes logging and error reporting in the plugin more consistent
with other plugins and Geany.
Also set the G_LOG_DOMAIN for the plugin in order to have proper
log messages.
  • Loading branch information
eht16 committed Feb 25, 2016
1 parent 7b4ea0a commit 9f50401
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 2 additions & 0 deletions geanypg/src/Makefile.am
Expand Up @@ -21,5 +21,7 @@ geanypg_la_LIBADD = \
geanypg_la_CFLAGS = \
$(AM_CFLAGS) \
$(GPGME_CFLAGS)
geanypg_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DG_LOG_DOMAIN=\"GeanyPG\"

include $(top_srcdir)/build/cppcheck.mk
2 changes: 1 addition & 1 deletion geanypg/src/decrypt_cb.c
Expand Up @@ -30,7 +30,7 @@ static void geanypg_decrypt_verify(encrypt_data * ed)
tempfile = tmpfile();
if (!(tempfile))
{
fprintf(stderr, "GeanyPG: %s: %s.\n", _("couldn't create tempfile"), strerror(errno));
g_warning("%s: %s.", _("couldn't create tempfile"), strerror(errno));
return ;
}
gpgme_data_new_from_stream(&plain, tempfile);
Expand Down
2 changes: 1 addition & 1 deletion geanypg/src/encrypt_cb.c
Expand Up @@ -29,7 +29,7 @@ static void geanypg_encrypt(encrypt_data * ed, gpgme_key_t * recp, int sign, int
tempfile = tmpfile();
if (!(tempfile))
{
fprintf(stderr, "GeanyPG: %s: %s.\n", _("couldn't create tempfile"), strerror(errno));
g_warning("%s: %s.", _("couldn't create tempfile"), strerror(errno));
return ;
}
gpgme_data_new_from_stream(&cipher, tempfile);
Expand Down
5 changes: 2 additions & 3 deletions geanypg/src/geanypg.c
Expand Up @@ -44,8 +44,7 @@ static gpgme_error_t geanypg_init_gpgme(void)
{
/* Initialize the locale environment. */
setlocale(LC_ALL, "");
fprintf(stderr, "GeanyPG: %s %s\n", _("Using libgpgme version:"),
gpgme_check_version("1.1.0"));
g_message("%s %s", _("Using libgpgme version:"), gpgme_check_version("1.1.0"));
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
#ifdef LC_MESSAGES /* only necessary for portability to W32 systems */
gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
Expand All @@ -58,7 +57,7 @@ gpgme_error_t geanypg_show_err_msg(gpgme_error_t err)
gchar const * msg = (gchar const *)gpgme_strerror(err);
gchar const * src = (gchar const *)gpgme_strsource(err);
dialogs_show_msgbox(GTK_MESSAGE_ERROR, "%s %s: %s\n", _("Error from"), src, msg);
fprintf(stderr, "GeanyPG: %s %s: %s\n", _("Error from"), msg, src);
g_warning("%s %s: %s", _("Error from"), msg, src);
return err;
}

Expand Down
12 changes: 6 additions & 6 deletions geanypg/src/pinentry.c
Expand Up @@ -83,12 +83,12 @@ gpgme_error_t geanypg_passphrase_cb(void * hook,

if (pipe(outpipe))
{
fprintf(stderr, "GeanyPG: %s\n", strerror(errno));
g_warning("%s", strerror(errno));
return gpgme_error_from_errno(errno);
}
if (pipe(inpipe))
{
fprintf(stderr, "GeanyPG: %s\n", strerror(errno));
g_warning("%s", strerror(errno));
return gpgme_error_from_errno(errno);
}

Expand All @@ -108,7 +108,7 @@ gpgme_error_t geanypg_passphrase_cb(void * hook,

execvp(*argv, argv);
/* shouldn't get here */
fprintf(stderr, "GeanyPG: %s\n%s\n", _("Could not use pinentry."), strerror(errno));
g_warning("%s: %s", _("Could not use pinentry."), strerror(errno));
exit(1); /* kill the child */
}
/* GeanpyPG */
Expand All @@ -120,7 +120,7 @@ gpgme_error_t geanypg_passphrase_cb(void * hook,
geanypg_read(outpipe[READ], ' ', 2049, readbuffer);
if (strncmp(readbuffer, "OK", 3))
{
fprintf(stderr, "GeanyPG: %s\n", _("Unexpected output from pinentry."));
g_warning(_("Unexpected output from pinentry."));
fclose(childin);
waitpid(childpid, &status, 0);
close(outpipe[READ]);
Expand Down Expand Up @@ -168,10 +168,10 @@ gpgme_error_t geanypg_passphrase_cb(void * hook,
geanypg_read(outpipe[READ], ' ', 2049, readbuffer);
sscanf(readbuffer, "%lu", &errval);
geanypg_read(outpipe[READ], '\n', 2049, readbuffer);
fprintf(stderr, "GeanyPG: %s %lu %s\n", _("pinentry gave error"), errval, readbuffer);
g_warning("%s %lu %s", _("pinentry gave error"), errval, readbuffer);
}
else
fprintf(stderr, "GeanyPG: %s\n", _("Unexpected error from pinentry."));
g_warning(_("Unexpected error from pinentry."));
fclose(childin);
waitpid(childpid, &status, 0);
close(outpipe[READ]);
Expand Down
2 changes: 1 addition & 1 deletion geanypg/src/sign_cb.c
Expand Up @@ -30,7 +30,7 @@ static void geanypg_sign(encrypt_data * ed)
tempfile = tmpfile();
if (!(tempfile))
{
fprintf(stderr, "GeanyPG: %s: %s\n", _("couldn't create tempfile"), strerror(errno));
g_warning("%s: %s", _("couldn't create tempfile"), strerror(errno));
return ;
}
gpgme_data_new_from_stream(&cipher, tempfile);
Expand Down
2 changes: 1 addition & 1 deletion geanypg/src/verify_aux.c
Expand Up @@ -176,7 +176,7 @@ void geanypg_handle_signatures(encrypt_data * ed, int need_error)
}
if (!verified && need_error)
{
fprintf(stderr, "GeanyPG: %s\n", _("Could not find verification results"));
g_warning(_("Could not find verification results"));
dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Error, could not find verification results"));
}
}

0 comments on commit 9f50401

Please sign in to comment.