opensc-notify: register a desktop menu entry
- fixes showing notifications in gnome-shell via gio2 - removes gdbus interface for notifications - fixes https://github.com/OpenSC/OpenSC/issues/1186
This commit is contained in:
parent
4444d24f59
commit
3f0d5ce336
55
configure.ac
55
configure.ac
|
@ -459,37 +459,26 @@ case "${host}" in
|
||||||
have_notify="yes"
|
have_notify="yes"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
AC_PATH_PROG([GDBUS], [gdbus], [not found])
|
PKG_CHECK_MODULES( [GIO2], [gio-2.0],
|
||||||
if test "${GDBUS}" = "not found"; then
|
[ have_notify="yes"
|
||||||
have_notify="no"
|
have_gio2="yes" ],
|
||||||
have_gdbus="no"
|
[ have_notify="no"
|
||||||
else
|
have_gio2="no" ])
|
||||||
have_notify="yes"
|
saved_CFLAGS="${CFLAGS}"
|
||||||
have_gdbus="yes"
|
CFLAGS="${CFLAGS} ${GIO2_CFLAGS}"
|
||||||
fi
|
AC_CHECK_HEADERS(gio/gio.h, [],
|
||||||
|
[ AC_MSG_WARN([glib2 headers not found])
|
||||||
if test "${have_notify}" = "no"; then
|
have_notify="no"
|
||||||
PKG_CHECK_MODULES( [GIO2], [gio-2.0],
|
have_gio2="no" ])
|
||||||
[ have_notify="yes"
|
CFLAGS="${saved_CFLAGS}"
|
||||||
have_gio2="yes" ],
|
saved_LIBS="$LIBS"
|
||||||
[ have_notify="no"
|
LIBS="$LIBS ${GIO2_LIBS}"
|
||||||
have_gio2="no" ])
|
AC_MSG_CHECKING([for g_application_send_notification])
|
||||||
saved_CFLAGS="${CFLAGS}"
|
AC_TRY_LINK_FUNC(g_application_send_notification, [ AC_MSG_RESULT([yes]) ],
|
||||||
CFLAGS="${CFLAGS} ${GIO2_CFLAGS}"
|
[ AC_MSG_WARN([Cannot link against glib2])
|
||||||
AC_CHECK_HEADERS(gio/gio.h, [],
|
have_notify="no"
|
||||||
[ AC_MSG_WARN([glib2 headers not found])
|
have_gio2="no" ])
|
||||||
have_notify="no"
|
LIBS="$saved_LIBS"
|
||||||
have_gio2="no" ])
|
|
||||||
CFLAGS="${saved_CFLAGS}"
|
|
||||||
saved_LIBS="$LIBS"
|
|
||||||
LIBS="$LIBS ${GIO2_LIBS}"
|
|
||||||
AC_MSG_CHECKING([for g_application_send_notification])
|
|
||||||
AC_TRY_LINK_FUNC(g_application_send_notification, [ AC_MSG_RESULT([yes]) ],
|
|
||||||
[ AC_MSG_WARN([Cannot link against glib2])
|
|
||||||
have_notify="no"
|
|
||||||
have_gio2="no" ])
|
|
||||||
LIBS="$saved_LIBS"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -509,9 +498,6 @@ esac
|
||||||
if test "${enable_notify}" = "yes"; then
|
if test "${enable_notify}" = "yes"; then
|
||||||
if test "${have_notify}" = "yes"; then
|
if test "${have_notify}" = "yes"; then
|
||||||
AC_DEFINE([ENABLE_NOTIFY], [1], [Use notification libraries and header files])
|
AC_DEFINE([ENABLE_NOTIFY], [1], [Use notification libraries and header files])
|
||||||
if test "${have_gdbus}" = "yes"; then
|
|
||||||
AC_DEFINE_UNQUOTED([GDBUS], ["${GDBUS}"], [Path to gdbus])
|
|
||||||
fi
|
|
||||||
if test "${have_gio2}" = "yes"; then
|
if test "${have_gio2}" = "yes"; then
|
||||||
AC_DEFINE([ENABLE_GIO2], [1], [Use glib2 libraries and header files])
|
AC_DEFINE([ENABLE_GIO2], [1], [Use glib2 libraries and header files])
|
||||||
OPTIONAL_NOTIFY_CFLAGS="${GIO2_CFLAGS}"
|
OPTIONAL_NOTIFY_CFLAGS="${GIO2_CFLAGS}"
|
||||||
|
@ -1117,7 +1103,6 @@ OPENCT_CFLAGS: ${OPENCT_CFLAGS}
|
||||||
OPENCT_LIBS: ${OPENCT_LIBS}
|
OPENCT_LIBS: ${OPENCT_LIBS}
|
||||||
PCSC_CFLAGS: ${PCSC_CFLAGS}
|
PCSC_CFLAGS: ${PCSC_CFLAGS}
|
||||||
CRYPTOTOKENKIT_CFLAGS: ${CRYPTOTOKENKIT_CFLAGS}
|
CRYPTOTOKENKIT_CFLAGS: ${CRYPTOTOKENKIT_CFLAGS}
|
||||||
GDBUS: ${GDBUS}
|
|
||||||
GIO2_CFLAGS: ${GIO2_CFLAGS}
|
GIO2_CFLAGS: ${GIO2_CFLAGS}
|
||||||
GIO2_LIBS: ${GIO2_LIBS}
|
GIO2_LIBS: ${GIO2_LIBS}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ VDFORMAT=GZIP
|
||||||
endif
|
endif
|
||||||
|
|
||||||
do_subst = $(SED) \
|
do_subst = $(SED) \
|
||||||
|
-e 's,[@]bindir[@],$(bindir),g' \
|
||||||
-e 's,[@]CVCDIR[@],$(CVCDIR),g' \
|
-e 's,[@]CVCDIR[@],$(CVCDIR),g' \
|
||||||
-e 's,[@]PACKAGE[@],$(PACKAGE),g' \
|
-e 's,[@]PACKAGE[@],$(PACKAGE),g' \
|
||||||
-e 's,[@]PACKAGE_BUGREPORT[@],$(PACKAGE_BUGREPORT),g' \
|
-e 's,[@]PACKAGE_BUGREPORT[@],$(PACKAGE_BUGREPORT),g' \
|
||||||
|
@ -24,7 +25,7 @@ OPENSC_NOTIFY_BUILT_SOURCES = opensc-notify-cmdline.h opensc-notify-cmdline.c
|
||||||
OPENSC_ASN1_BUILT_SOURCES = opensc-asn1-cmdline.h opensc-asn1-cmdline.c
|
OPENSC_ASN1_BUILT_SOURCES = opensc-asn1-cmdline.h opensc-asn1-cmdline.c
|
||||||
|
|
||||||
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in $(srcdir)/versioninfo-tools.rc $(srcdir)/versioninfo-opensc-notify.rc
|
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in $(srcdir)/versioninfo-tools.rc $(srcdir)/versioninfo-opensc-notify.rc
|
||||||
EXTRA_DIST = Makefile.mak versioninfo-tools.rc.in versioninfo-opensc-notify.rc.in npa-tool.ggo.in npa-tool.1 opensc-notify.ggo.in egk-tool.ggo.in egk-tool.1 opensc-asn1.ggo.in opensc-asn1.1
|
EXTRA_DIST = Makefile.mak versioninfo-tools.rc.in versioninfo-opensc-notify.rc.in npa-tool.ggo.in npa-tool.1 opensc-notify.ggo.in egk-tool.ggo.in egk-tool.1 opensc-asn1.ggo.in opensc-asn1.1 org.opensc-project.opensc-notify.desktop.in
|
||||||
|
|
||||||
noinst_HEADERS = util.h fread_to_eof.h
|
noinst_HEADERS = util.h fread_to_eof.h
|
||||||
noinst_PROGRAMS = sceac-example
|
noinst_PROGRAMS = sceac-example
|
||||||
|
@ -209,5 +210,11 @@ gids_tool_SOURCES += versioninfo-tools.rc
|
||||||
opensc_notify_SOURCES += versioninfo-opensc-notify.rc
|
opensc_notify_SOURCES += versioninfo-opensc-notify.rc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
applicationsdir = $(datadir)/applications
|
||||||
|
applications_DATA = org.opensc-project.opensc-notify.desktop
|
||||||
|
|
||||||
|
org.opensc-project.opensc-notify.desktop: org.opensc-project.opensc-notify.desktop
|
||||||
|
$(do_subst) < $(abs_srcdir)/org.opensc-project.opensc-notify.desktop.in > $@
|
||||||
|
|
||||||
clean-local:
|
clean-local:
|
||||||
rm -f $(abs_builddir)/npa-tool.ggo $(abs_builddir)/opensc-notify.ggo
|
rm -f $(abs_builddir)/npa-tool.ggo $(abs_builddir)/opensc-notify.ggo
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
[Desktop Entry]
|
||||||
|
Name=OpenSC Notify
|
||||||
|
Type=Application
|
||||||
|
Comment=Monitor smart card events to send notifications.
|
||||||
|
Exec=@bindir@/opensc-notify
|
||||||
|
Icon=preferences-system-notifications
|
||||||
|
Categories=Security;System;
|
114
src/ui/notify.c
114
src/ui/notify.c
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "notify.h"
|
#include "notify.h"
|
||||||
|
|
||||||
#if defined(ENABLE_NOTIFY) && (defined(__APPLE__) || (defined(GDBUS) && !defined(_WIN32)))
|
#if defined(ENABLE_NOTIFY) && (defined(__APPLE__))
|
||||||
|
|
||||||
#include "libopensc/internal.h"
|
#include "libopensc/internal.h"
|
||||||
#include "libopensc/log.h"
|
#include "libopensc/log.h"
|
||||||
|
@ -371,116 +371,16 @@ void sc_notify_id(struct sc_context *ctx, struct sc_atr *atr,
|
||||||
notify_proxy(ctx, title, NULL, text, icon, NULL, group);
|
notify_proxy(ctx, title, NULL, text, icon, NULL, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(ENABLE_NOTIFY) && defined(GDBUS) && !defined(_WIN32)
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
/* save the notification's id for replacement with a new one */
|
|
||||||
uint32_t message_id = 0;
|
|
||||||
|
|
||||||
static void notify_gio(struct sc_context *ctx,
|
|
||||||
const char *title, const char *text, const char *icon,
|
|
||||||
const char *group)
|
|
||||||
{
|
|
||||||
char message_id_str[22];
|
|
||||||
int pipefd[2];
|
|
||||||
int pass_to_pipe = 1;
|
|
||||||
snprintf(message_id_str, sizeof message_id_str, "%"PRIu32, message_id);
|
|
||||||
|
|
||||||
if (child > 0) {
|
|
||||||
int status;
|
|
||||||
if (0 == waitpid(child, &status, WNOHANG)) {
|
|
||||||
kill(child, SIGKILL);
|
|
||||||
usleep(100);
|
|
||||||
if (0 == waitpid(child, &status, WNOHANG)) {
|
|
||||||
sc_log(ctx, "Can't kill %ld, skipping current notification", (long) child);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == pipe(pipefd)) {
|
|
||||||
pass_to_pipe = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
child = fork();
|
|
||||||
switch (child) {
|
|
||||||
case 0:
|
|
||||||
/* child process */
|
|
||||||
if (pass_to_pipe) {
|
|
||||||
/* close reading end of the pipe */
|
|
||||||
close(pipefd[0]);
|
|
||||||
/* send stdout to the pipe */
|
|
||||||
dup2(pipefd[1], 1);
|
|
||||||
/* this descriptor is no longer needed */
|
|
||||||
close(pipefd[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 > execl(GDBUS, GDBUS,
|
|
||||||
"call", "--session",
|
|
||||||
"--dest", "org.freedesktop.Notifications",
|
|
||||||
"--object-path", "/org/freedesktop/Notifications",
|
|
||||||
"--method", "org.freedesktop.Notifications.Notify",
|
|
||||||
"org.opensc-project",
|
|
||||||
message_id_str,
|
|
||||||
icon ? icon : "",
|
|
||||||
title ? title : "",
|
|
||||||
text ? text : "",
|
|
||||||
"[]", "{}", "5000",
|
|
||||||
(char *) NULL)) {
|
|
||||||
perror("exec failed");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
sc_log(ctx, "failed to fork for notification");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
/* parent process */
|
|
||||||
|
|
||||||
if (ctx) {
|
|
||||||
sc_log(ctx, "Created %ld for notification:", (long) child);
|
|
||||||
sc_log(ctx, "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", GDBUS,
|
|
||||||
"call", "--session",
|
|
||||||
"--dest", "org.freedesktop.Notifications",
|
|
||||||
"--object-path", "/org/freedesktop/Notifications",
|
|
||||||
"--method", "org.freedesktop.Notifications.Notify",
|
|
||||||
"org.opensc-project",
|
|
||||||
message_id_str,
|
|
||||||
icon ? icon : "",
|
|
||||||
title ? title : "",
|
|
||||||
text ? text : "",
|
|
||||||
"[]", "{}", "5000");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pass_to_pipe) {
|
|
||||||
ssize_t r;
|
|
||||||
/* close the write end of the pipe */
|
|
||||||
close(pipefd[1]);
|
|
||||||
memset(message_id_str, '\0', sizeof message_id_str);
|
|
||||||
r = read(pipefd[0], message_id_str, sizeof(message_id_str));
|
|
||||||
if (0 < r) {
|
|
||||||
message_id_str[MIN((sizeof message_id_str) - 1, (size_t) r)] = '\0';
|
|
||||||
if (0 >= sscanf(message_id_str, "(uint32 %"SCNu32",)", &message_id)) {
|
|
||||||
message_id = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* close the read end of the pipe */
|
|
||||||
close(pipefd[0]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif defined(ENABLE_NOTIFY) && defined(ENABLE_GIO2)
|
#elif defined(ENABLE_NOTIFY) && defined(ENABLE_GIO2)
|
||||||
|
|
||||||
static GtkApplication *application = NULL;
|
|
||||||
|
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
static GApplication *application = NULL;
|
||||||
|
|
||||||
void sc_notify_init(void)
|
void sc_notify_init(void)
|
||||||
{
|
{
|
||||||
sc_notify_close();
|
sc_notify_close();
|
||||||
application = g_application_new("org.opensc-project", G_APPLICATION_FLAGS_NONE);
|
application = g_application_new("org.opensc-project.opensc-notify", G_APPLICATION_FLAGS_NONE);
|
||||||
if (application) {
|
if (application) {
|
||||||
g_application_register(application, NULL, NULL);
|
g_application_register(application, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
@ -504,7 +404,9 @@ static void notify_gio(struct sc_context *ctx,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_notification_set_body (notification, text);
|
if (text) {
|
||||||
|
g_notification_set_body (notification, text);
|
||||||
|
}
|
||||||
if (icon) {
|
if (icon) {
|
||||||
gicon = g_themed_icon_new (icon);
|
gicon = g_themed_icon_new (icon);
|
||||||
if (gicon) {
|
if (gicon) {
|
||||||
|
@ -530,7 +432,7 @@ void sc_notify_id(struct sc_context *ctx, struct sc_atr *atr,
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_NOTIFY) && (defined(ENABLE_GIO2) || defined(GDBUS) && !defined(_WIN32))
|
#if defined(ENABLE_NOTIFY) && defined(ENABLE_GIO2)
|
||||||
void sc_notify(const char *title, const char *text)
|
void sc_notify(const char *title, const char *text)
|
||||||
{
|
{
|
||||||
notify_gio(NULL, title, text, NULL, NULL);
|
notify_gio(NULL, title, text, NULL, NULL);
|
||||||
|
|
Loading…
Reference in New Issue