diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2011-06-27 21:33:20 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@gmail.com> | 2011-06-28 19:35:58 +0200 |
commit | 1fec772893544d5388dbece7f52fff7b640e3017 (patch) | |
tree | f1fabb7958a69cee78b95455e26901365a1b70e1 /gtk | |
parent | 66461433ca7b5a22c2fb18a4030b4a6e51000f79 (diff) |
gtk/smartcard: make cacard dependency optional without breaking API
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/Makefile.am | 17 | ||||
-rw-r--r-- | gtk/channel-smartcard.c | 40 | ||||
-rw-r--r-- | gtk/map-file | 1 | ||||
-rw-r--r-- | gtk/smartcard-manager-priv.h | 31 | ||||
-rw-r--r-- | gtk/smartcard-manager.c | 52 | ||||
-rw-r--r-- | gtk/smartcard-manager.h | 13 | ||||
-rw-r--r-- | gtk/spicy.c | 3 |
7 files changed, 120 insertions, 37 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index addaed9..fb5054c 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -177,6 +177,10 @@ libspice_client_glib_2_0_la_SOURCES = \ channel-main.c \ channel-playback.c \ channel-record.c \ + channel-smartcard.c \ + smartcard-manager.c \ + smartcard-manager.h \ + smartcard-manager-priv.h \ \ decode.h \ decode-glz.c \ @@ -222,6 +226,7 @@ libspice_client_glibinclude_HEADERS = \ channel-main.h \ channel-playback.h \ channel-record.h \ + channel-smartcard.h \ $(NULL) # file for API compatibility, but we don't want warning during our compilation @@ -243,18 +248,6 @@ libspice_client_glib_2_0_la_SOURCES += \ $(NULL) endif -if WITH_SMARTCARD -libspice_client_glib_2_0_la_SOURCES += \ - channel-smartcard.c \ - smartcard-manager.c \ - smartcard-manager.h \ - $(NULL) - -libspice_client_glibinclude_HEADERS += \ - channel-smartcard.h \ - $(NULL) -endif - if WITH_UCONTEXT libspice_client_glib_2_0_la_SOURCES += continuation.h continuation.c coroutine_ucontext.c EXTRA_DIST += coroutine_gthread.c diff --git a/gtk/channel-smartcard.c b/gtk/channel-smartcard.c index 3a542d0..5274950 100644 --- a/gtk/channel-smartcard.c +++ b/gtk/channel-smartcard.c @@ -15,13 +15,18 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" + +#ifdef USE_SMARTCARD #include <vreader.h> +#endif #include "spice-client.h" #include "spice-common.h" #include "spice-channel-priv.h" #include "smartcard-manager.h" +#include "smartcard-manager-priv.h" /** * SECTION:channel-smartcard @@ -39,7 +44,9 @@ (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_SMARTCARD_CHANNEL, spice_smartcard_channel)) struct _SpiceSmartCardChannelMessage { +#ifdef USE_SMARTCARD VSCMsgType message_type; +#endif spice_msg_out *message; }; typedef struct _SpiceSmartCardChannelMessage SpiceSmartCardChannelMessage; @@ -85,7 +92,7 @@ static void handle_smartcard_msg(SpiceChannel *channel, spice_msg_in *in); static void smartcard_message_free(SpiceSmartCardChannelMessage *message); /* ------------------------------------------------------------------ */ - +#ifdef USE_SMARTCARD static void reader_added_cb(SpiceSmartCardManager *manager, VReader *reader, gpointer user_data); static void reader_removed_cb(SpiceSmartCardManager *manager, VReader *reader, @@ -94,23 +101,28 @@ static void card_inserted_cb(SpiceSmartCardManager *manager, VReader *reader, gpointer user_data); static void card_removed_cb(SpiceSmartCardManager *manager, VReader *reader, gpointer user_data); +#endif static void spice_smartcard_channel_init(SpiceSmartCardChannel *channel) { - SpiceSmartCardManager *manager; spice_smartcard_channel *priv; channel->priv = SPICE_SMARTCARD_CHANNEL_GET_PRIVATE(channel); priv = channel->priv; + priv->message_queue = g_queue_new(); + +#ifdef USE_SMARTCARD + SpiceSmartCardManager *manager; + + manager = spice_smartcard_manager_get(); + priv->pending_card_insertions = g_hash_table_new_full(g_direct_hash, g_direct_equal, (GDestroyNotify)vreader_free, NULL); priv->pending_reader_removals = g_hash_table_new_full(g_direct_hash, g_direct_equal, (GDestroyNotify)vreader_free, NULL); - priv->message_queue = g_queue_new(); - manager = spice_smartcard_manager_get(); g_signal_connect(G_OBJECT(manager), "reader-added", (GCallback)reader_added_cb, channel); g_signal_connect(G_OBJECT(manager), "reader-removed", @@ -119,6 +131,7 @@ static void spice_smartcard_channel_init(SpiceSmartCardChannel *channel) (GCallback)card_inserted_cb, channel); g_signal_connect(G_OBJECT(manager), "card-removed", (GCallback)card_removed_cb, channel); +#endif } static void spice_smartcard_channel_finalize(GObject *obj) @@ -166,6 +179,15 @@ static const spice_msg_handler smartcard_handlers[] = { /* ------------------------------------------------------------------ */ /* private api */ + +static void +smartcard_message_free(SpiceSmartCardChannelMessage *message) +{ + spice_msg_out_unref(message->message); + g_slice_free(SpiceSmartCardChannelMessage, message); +} + +#if USE_SMARTCARD static gboolean is_attached_to_server(VReader *reader) { return (vreader_get_id(reader) != (vreader_id_t)-1); @@ -229,13 +251,6 @@ smartcard_message_new(VSCMsgType msg_type, spice_msg_out *msg_out) return message; } -static void -smartcard_message_free(SpiceSmartCardChannelMessage *message) -{ - spice_msg_out_unref(message->message); - g_slice_free(SpiceSmartCardChannelMessage, message); -} - /* Indicates that handling of the message that is currently in flight has * been completed. If needed, sends the next queued command to the server. */ static void @@ -371,6 +386,7 @@ static void card_removed_cb(SpiceSmartCardManager *manager, VReader *reader, spice_channel_drop_pending_card_insertion(channel, reader); } } +#endif /* USE_SMARTCARD */ /* coroutine context */ static void spice_smartcard_handle_msg(SpiceChannel *channel, spice_msg_in *msg) @@ -401,6 +417,7 @@ static void spice_smartcard_channel_up(SpiceChannel *channel) static void handle_smartcard_msg(SpiceChannel *channel, spice_msg_in *in) { +#ifdef USE_SMARTCARD spice_smartcard_channel *priv = SPICE_SMARTCARD_CHANNEL_GET_PRIVATE(channel); SpiceMsgSmartcard *msg = spice_msg_in_parsed(in); VReader *reader; @@ -478,5 +495,6 @@ static void handle_smartcard_msg(SpiceChannel *channel, spice_msg_in *in) default: g_return_if_reached(); } +#endif } diff --git a/gtk/map-file b/gtk/map-file index ed4035c..8eef771 100644 --- a/gtk/map-file +++ b/gtk/map-file @@ -66,7 +66,6 @@ spice_session_verify_get_type; spice_smartcard_channel_get_type; spice_smartcard_manager_get; spice_smartcard_manager_get_type; -spice_smartcard_manager_init_libcacard; spice_smartcard_manager_insert_card; spice_smartcard_manager_remove_card; spice_smartcard_reader_is_software; diff --git a/gtk/smartcard-manager-priv.h b/gtk/smartcard-manager-priv.h new file mode 100644 index 0000000..d40064c --- /dev/null +++ b/gtk/smartcard-manager-priv.h @@ -0,0 +1,31 @@ +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */ +/* + Copyright (C) 2010 Red Hat, Inc. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef __SMARTCARD_MANAGER_PRIV_H__ +#define __SMARTCARD_MANAGER_PRIV_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +G_BEGIN_DECLS + +gboolean spice_smartcard_manager_init_libcacard(SpiceSession *session); + +G_END_DECLS + +#endif /* __SMARTCARD_MANAGER_PRIV_H__ */ diff --git a/gtk/smartcard-manager.c b/gtk/smartcard-manager.c index 6585112..51ebd02 100644 --- a/gtk/smartcard-manager.c +++ b/gtk/smartcard-manager.c @@ -15,12 +15,16 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" + #include <glib-object.h> #include <string.h> + +#ifdef USE_SMARTCARD #include <vcard_emul.h> #include <vevent.h> #include <vreader.h> - +#endif #include "smartcard-manager.h" #include "spice-marshal.h" @@ -53,11 +57,17 @@ struct spice_smartcard_manager { * existence, it's all controlled by explicit software * insertion/removal of cards */ +#ifdef USE_SMARTCARD VReader *software_reader; +#endif }; G_DEFINE_TYPE(SpiceSmartCardManager, spice_smartcard_manager, G_TYPE_OBJECT); +#ifdef USE_SMARTCARD G_DEFINE_BOXED_TYPE(VReader, spice_smartcard_reader, vreader_reference, vreader_free); +#else +G_DEFINE_BOXED_TYPE(GObject, spice_smartcard_reader, NULL, NULL); +#endif /* Properties */ enum { @@ -76,10 +86,12 @@ enum { static guint signals[SPICE_SMARTCARD_MANAGER_LAST_SIGNAL]; +#ifdef USE_SMARTCARD typedef gboolean (*SmartCardSourceFunc)(VEvent *event, gpointer user_data); static guint smartcard_monitor_add(SmartCardSourceFunc callback, gpointer user_data); static gboolean smartcard_monitor_dispatch(VEvent *event, gpointer user_data); +#endif /* ------------------------------------------------------------------ */ @@ -89,8 +101,10 @@ static void spice_smartcard_manager_init(SpiceSmartCardManager *smartcard_manage priv = SPICE_SMARTCARD_MANAGER_GET_PRIVATE(smartcard_manager); smartcard_manager->priv = priv; +#ifdef USE_SMARTCARD priv->monitor_id = smartcard_monitor_add(smartcard_monitor_dispatch, smartcard_manager); +#endif } static void spice_smartcard_manager_dispose(GObject *gobject) @@ -110,10 +124,12 @@ static void spice_smartcard_manager_finalize(GObject *gobject) priv->monitor_id = 0; } +#ifdef USE_SMARTCARD if (priv->software_reader != NULL) { vreader_free(priv->software_reader); priv->software_reader = NULL; } +#endif /* Chain up to the parent class */ if (G_OBJECT_CLASS(spice_smartcard_manager_parent_class)->finalize) @@ -227,6 +243,7 @@ SpiceSmartCardManager *spice_smartcard_manager_get(void) NULL); } +#ifdef USE_SMARTCARD static gboolean smartcard_monitor_dispatch(VEvent *event, gpointer user_data) { g_return_val_if_fail(event != NULL, TRUE); @@ -234,7 +251,7 @@ static gboolean smartcard_monitor_dispatch(VEvent *event, gpointer user_data) switch (event->type) { case VEVENT_READER_INSERT: - if (spice_smartcard_reader_is_software(event->reader)) { + if (spice_smartcard_reader_is_software((SpiceSmartCardReader*)event->reader)) { g_warn_if_fail(manager->priv->software_reader == NULL); manager->priv->software_reader = vreader_reference(event->reader); } @@ -245,7 +262,7 @@ static gboolean smartcard_monitor_dispatch(VEvent *event, gpointer user_data) break; case VEVENT_READER_REMOVE: - if (spice_smartcard_reader_is_software(event->reader)) { + if (spice_smartcard_reader_is_software((SpiceSmartCardReader*)event->reader)) { g_warn_if_fail(manager->priv->software_reader != NULL); vreader_free(manager->priv->software_reader); manager->priv->software_reader = NULL; @@ -366,11 +383,13 @@ static guint smartcard_monitor_add(SmartCardSourceFunc callback, #define SPICE_SOFTWARE_READER_NAME "Spice Software Smartcard" -gboolean spice_smartcard_reader_is_software(VReader *reader) +gboolean spice_smartcard_reader_is_software(SpiceSmartCardReader *reader) { - return (strcmp(vreader_get_name(reader), SPICE_SOFTWARE_READER_NAME) == 0); + g_return_val_if_fail(reader != NULL, FALSE); + return (strcmp(vreader_get_name((VReader*)reader), SPICE_SOFTWARE_READER_NAME) == 0); } +G_GNUC_INTERNAL gboolean spice_smartcard_manager_init_libcacard(SpiceSession *session) { gchar *emul_args = NULL; @@ -439,3 +458,26 @@ gboolean spice_smartcard_manager_remove_card(SpiceSmartCardManager *manager) return (status == VCARD_EMUL_OK); } +#else +gboolean spice_smartcard_reader_is_software(SpiceSmartCardReader *reader) +{ + return TRUE; +} + +G_GNUC_INTERNAL +gboolean spice_smartcard_manager_init_libcacard(SpiceSession *session) +{ + SPICE_DEBUG("using fake smartcard backend"); + return TRUE; +} + +gboolean spice_smartcard_manager_insert_card(SpiceSmartCardManager *manager) +{ + return FALSE; +} + +gboolean spice_smartcard_manager_remove_card(SpiceSmartCardManager *manager) +{ + return FALSE; +} +#endif /* USE_SMARTCARD */ diff --git a/gtk/smartcard-manager.h b/gtk/smartcard-manager.h index 91be37d..0c1b70e 100644 --- a/gtk/smartcard-manager.h +++ b/gtk/smartcard-manager.h @@ -23,7 +23,6 @@ G_BEGIN_DECLS #include "spice-types.h" #include "spice-glib-enums.h" #include "spice-util.h" -#include <vreader.h> #define SPICE_TYPE_SMARTCARD_MANAGER (spice_smartcard_manager_get_type ()) #define SPICE_SMARTCARD_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SPICE_TYPE_SMARTCARD_MANAGER, SpiceSmartCardManager)) @@ -37,6 +36,7 @@ G_BEGIN_DECLS typedef struct _SpiceSmartCardManager SpiceSmartCardManager; typedef struct _SpiceSmartCardManagerClass SpiceSmartCardManagerClass; typedef struct spice_smartcard_manager spice_smartcard_manager; +typedef struct _SpiceSmartCardReader SpiceSmartCardReader; struct _SpiceSmartCardManager { @@ -50,10 +50,10 @@ struct _SpiceSmartCardManagerClass GObjectClass parent_class; /*< public >*/ /* signals */ - void (*reader_added)(SpiceSmartCardManager *manager, VReader *reader); - void (*reader_removed)(SpiceSmartCardManager *manager, VReader *reader); - void (*card_inserted)(SpiceSmartCardManager *manager, VReader *reader); - void (*card_removed)(SpiceSmartCardManager *manager, VReader *reader ); + void (*reader_added)(SpiceSmartCardManager *manager, SpiceSmartCardReader *reader); + void (*reader_removed)(SpiceSmartCardManager *manager, SpiceSmartCardReader *reader); + void (*card_inserted)(SpiceSmartCardManager *manager, SpiceSmartCardReader *reader); + void (*card_removed)(SpiceSmartCardManager *manager, SpiceSmartCardReader *reader ); /* * If adding fields to this struct, remove corresponding * amount of padding to avoid changing overall struct size @@ -67,8 +67,7 @@ GType spice_smartcard_reader_get_type(void); SpiceSmartCardManager *spice_smartcard_manager_get(void); gboolean spice_smartcard_manager_insert_card(SpiceSmartCardManager *manager); gboolean spice_smartcard_manager_remove_card(SpiceSmartCardManager *manager); -gboolean spice_smartcard_manager_init_libcacard(SpiceSession *session); -gboolean spice_smartcard_reader_is_software(VReader *reader); +gboolean spice_smartcard_reader_is_software(SpiceSmartCardReader *reader); G_END_DECLS diff --git a/gtk/spicy.c b/gtk/spicy.c index b16e3f5..c4cd018 100644 --- a/gtk/spicy.c +++ b/gtk/spicy.c @@ -28,6 +28,7 @@ #include "display/gnome-rr-config.h" #ifdef USE_SMARTCARD +#include <vreader.h> #include "smartcard-manager.h" #endif @@ -356,7 +357,7 @@ static void enable_smartcard_actions(spice_window *win, VReader *reader, { GtkAction *action; - if ((reader != NULL) && (!spice_smartcard_reader_is_software(reader))) + if ((reader != NULL) && (!spice_smartcard_reader_is_software((SpiceSmartCardReader*)reader))) { /* Having menu actions to insert/remove smartcards only makes sense * for software smartcard readers, don't do anything when the event |