[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 14/20] ccid-card-emulated: use PROP_TYPE_ENUM for ba
From: |
Alon Levy |
Subject: |
[Qemu-devel] [PATCH 14/20] ccid-card-emulated: use PROP_TYPE_ENUM for backend |
Date: |
Wed, 2 Feb 2011 22:28:14 +0200 |
Signed-off-by: Alon Levy <address@hidden>
---
hw/ccid-card-emulated.c | 33 ++++++++++++++++++++++-----------
1 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c
index 5531ce1..3c5bf6c 100644
--- a/hw/ccid-card-emulated.c
+++ b/hw/ccid-card-emulated.c
@@ -35,8 +35,15 @@ do { if (lvl <= card->debug) { printf("ccid-card-emul: %s: "
fmt , __func__, ##
#define EMULATED_DEV_NAME "ccid-card-emulated"
-#define BACKEND_NSS_EMULATED "nss-emulated" /* the default */
-#define BACKEND_CERTIFICATES "certificates"
+#define BACKEND_NSS_EMULATED_NAME "nss-emulated"
+#define BACKEND_CERTIFICATES_NAME "certificates"
+
+enum {
+ BACKEND_NSS_EMULATED=1,
+ BACKEND_CERTIFICATES
+};
+
+#define DEFAULT_BACKEND BACKEND_NSS_EMULATED
typedef struct EmulatedState EmulatedState;
@@ -88,7 +95,7 @@ typedef struct EmulEvent {
struct EmulatedState {
CCIDCardState base;
uint8_t debug;
- char* backend;
+ uint32_t backend;
char* cert1;
char* cert2;
char* cert3;
@@ -449,22 +456,20 @@ static int emulated_initfn(CCIDCardState *base)
if (init_pipe_signaling(card) < 0) {
return -1;
}
- if (!card->backend) {
- card->backend = strdup((char*)BACKEND_NSS_EMULATED);
- }
+ ASSERT(card->backend); /* 0 is not a value in the enumeration */
/* TODO: a passthru backened that works on local machine. third card type?
*/
- if (strcmp(BACKEND_CERTIFICATES, card->backend) == 0
+ if (card->backend == BACKEND_CERTIFICATES
&& card->cert1 != NULL && card->cert2 != NULL && card->cert3 != NULL) {
ret = emulated_initialize_vcard_from_certificates(card);
} else {
- if (strcmp(BACKEND_CERTIFICATES, card->backend) == 0) {
+ if (card->backend != BACKEND_CERTIFICATES) {
printf("%s: you must provide all three certs for certificates
backend\n",
EMULATED_DEV_NAME);
return -1;
}
- if (card->backend && strcmp(BACKEND_NSS_EMULATED, card->backend) != 0)
{
+ if (card->backend != BACKEND_NSS_EMULATED) {
printf("%s: bad backend specified. The options are:\n%s (default),
%s.\n",
- EMULATED_DEV_NAME, BACKEND_NSS_EMULATED, BACKEND_CERTIFICATES);
+ EMULATED_DEV_NAME, BACKEND_NSS_EMULATED_NAME,
BACKEND_CERTIFICATES_NAME);
return -1;
}
/* default to mirroring the local hardware readers */
@@ -507,6 +512,12 @@ static int emulated_exitfn(CCIDCardState *base)
return 0;
}
+EnumTable backend_enum_table[] = {
+ {BACKEND_NSS_EMULATED_NAME, BACKEND_NSS_EMULATED},
+ {BACKEND_CERTIFICATES_NAME, BACKEND_CERTIFICATES},
+ {NULL, 0},
+};
+
static CCIDCardInfo emulated_card_info = {
.qdev.name = EMULATED_DEV_NAME,
.qdev.size = sizeof(EmulatedState),
@@ -516,7 +527,7 @@ static CCIDCardInfo emulated_card_info = {
.apdu_from_guest = emulated_apdu_from_guest,
.qdev.unplug = qdev_simple_unplug_cb,
.qdev.props = (Property[]) {
- DEFINE_PROP_STRING("backend", EmulatedState, backend),
+ DEFINE_PROP_ENUM("backend", EmulatedState, backend, DEFAULT_BACKEND,
backend_enum_table),
DEFINE_PROP_STRING("cert1", EmulatedState, cert1),
DEFINE_PROP_STRING("cert2", EmulatedState, cert2),
DEFINE_PROP_STRING("cert3", EmulatedState, cert3),
--
1.7.4
- [Qemu-devel] [PATCH 06/20] usb-ccid: review fixes (v15-v16), (continued)
- [Qemu-devel] [PATCH 08/20] libcacard/vscard_common.h update (v15->v16), Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 09/20] ccid: add passthru card device, Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 10/20] ccid-card-passthru: review fixes (v15->v16), Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 14/20] ccid-card-emulated: use PROP_TYPE_ENUM for backend,
Alon Levy <=
- [Qemu-devel] [PATCH 15/20] ccid-card-emulated: review fixes (v15->v16), Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 20/20] smartcard,configure: report only nss, Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 12/20] libcacard: fixes from review (v15->v16), Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 17/20] ccid: configure: add --enable/disable and nss only disable, Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 18/20] ccid: add qdev description strings, Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 19/20] smartcard, configure: add --enable-smartcard-nss, report only nss, Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 13/20] ccid: add ccid-card-emulated device (v2), Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 16/20] ccid: add docs, Alon Levy, 2011/02/02
- [Qemu-devel] [PATCH 11/20] libcacard: initial commit after coding style fixes, Alon Levy, 2011/02/02