From patchwork Wed Feb 2 20:28:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 81534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 23A01B70A9 for ; Thu, 3 Feb 2011 07:38:24 +1100 (EST) Received: from localhost ([127.0.0.1]:51132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkjSx-0003A6-Cn for incoming@patchwork.ozlabs.org; Wed, 02 Feb 2011 15:38:15 -0500 Received: from [140.186.70.92] (port=54497 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkjKL-0007z8-EO for qemu-devel@nongnu.org; Wed, 02 Feb 2011 15:29:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PkjKB-0000OS-5A for qemu-devel@nongnu.org; Wed, 02 Feb 2011 15:29:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29074) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PkjKA-0000OC-S7 for qemu-devel@nongnu.org; Wed, 02 Feb 2011 15:29:11 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p12KTAE1020724 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 2 Feb 2011 15:29:10 -0500 Received: from playa.redhat.com (vpn-200-14.tlv.redhat.com [10.35.200.14]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p12KSLpe025755 for ; Wed, 2 Feb 2011 15:29:09 -0500 From: Alon Levy To: qemu-devel@nongnu.org Date: Wed, 2 Feb 2011 22:28:14 +0200 Message-Id: <1296678500-19497-15-git-send-email-alevy@redhat.com> In-Reply-To: <1296678500-19497-1-git-send-email-alevy@redhat.com> References: <1296678500-19497-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 14/20] ccid-card-emulated: use PROP_TYPE_ENUM for backend X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Alon Levy --- 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),