[Pcsclite-cvs-commit] r5165 - in /trunk/Drivers/ccid/src: Makefile.am ccid_usb.c ifdhandler.c simclist.c simclist.h

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Thu Aug 19 14:54:48 UTC 2010


Author: rousseau
Date: Thu Aug 19 14:54:47 2010
New Revision: 5165

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=5165
Log:
Use the new Info.plist parser API

Added:
    trunk/Drivers/ccid/src/simclist.c   (with props)
    trunk/Drivers/ccid/src/simclist.h   (with props)
Modified:
    trunk/Drivers/ccid/src/Makefile.am
    trunk/Drivers/ccid/src/ccid_usb.c
    trunk/Drivers/ccid/src/ifdhandler.c

Modified: trunk/Drivers/ccid/src/Makefile.am
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/Makefile.am?rev=5165&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/Makefile.am (original)
+++ trunk/Drivers/ccid/src/Makefile.am Thu Aug 19 14:54:47 2010
@@ -44,7 +44,9 @@
 TOKEN_PARSER = tokenparser.l parser.h \
 	strlcpy.c \
 	misc.h \
-	strlcpycat.h
+	strlcpycat.h \
+	simclist.c \
+	simclist.h
 
 if WITHOUT_PCSC
 PROVIDED_BY_PCSC = debug.c

Modified: trunk/Drivers/ccid/src/ccid_usb.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/ccid_usb.c?rev=5165&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/ccid_usb.c (original)
+++ trunk/Drivers/ccid/src/ccid_usb.c Thu Aug 19 14:54:47 2010
@@ -162,8 +162,6 @@
 {
 	int alias = 0;
 	struct libusb_device_handle *dev_handle;
-	char keyValue[TOKEN_MAX_VALUE_SIZE];
-	unsigned int vendorID, productID;
 	char infofile[FILENAME_MAX];
 #ifndef __APPLE__
 	unsigned int device_vendor, device_product;
@@ -173,6 +171,8 @@
 	static int previous_reader_index = -1;
 	libusb_device **devs, *dev;
 	ssize_t cnt;
+	list_t plist, *values, *ifdVendorID, *ifdProductID, *ifdFriendlyName;
+	int rv;
 
 	DEBUG_COMM3("Reader index: %X, Device: %s", reader_index, device);
 
@@ -246,33 +246,25 @@
 	(void)snprintf(infofile, sizeof(infofile), "%s/%s/Contents/Info.plist",
 		PCSCLITE_HP_DROPDIR, BUNDLE);
 
+	rv = bundleParse(infofile, &plist);
+	if (rv)
+		return STATUS_UNSUCCESSFUL;
+
+#define GET_KEY(key, values) \
+	rv = LTPBundleFindValueWithKey(&plist, key, &values); \
+	if (rv) \
+	{ \
+		DEBUG_CRITICAL2("Value/Key not defined for " key " in %s", infofile); \
+		bundleRelease(&plist); \
+		return STATUS_UNSUCCESSFUL; \
+	} \
+	else \
+		DEBUG_INFO2(key ": %s", list_get_at(values, 0));
+
 	/* general driver info */
-	if (!LTPBundleFindValueWithKey(infofile, "ifdManufacturerString", keyValue, 0))
-	{
-		DEBUG_INFO2("Manufacturer: %s", keyValue);
-	}
-	else
-	{
-		DEBUG_INFO2("LTPBundleFindValueWithKey error. Can't find %s?",
-			infofile);
-		return STATUS_UNSUCCESSFUL;
-	}
-	if (!LTPBundleFindValueWithKey(infofile, "ifdProductString", keyValue, 0))
-	{
-		DEBUG_INFO2("ProductString: %s", keyValue);
-	}
-	else
-		return STATUS_UNSUCCESSFUL;
-	if (!LTPBundleFindValueWithKey(infofile, "Copyright", keyValue, 0))
-	{
-		DEBUG_INFO2("Copyright: %s", keyValue);
-	}
-	else
-		return STATUS_UNSUCCESSFUL;
-	vendorID = strlen(keyValue);
-	alias = 0x1C;
-	for (; vendorID--;)
-		alias ^= keyValue[vendorID];
+	GET_KEY("ifdManufacturerString", values)
+	GET_KEY("ifdProductString", values)
+	GET_KEY("Copyright", values)
 
 	if (NULL == ctx)
 		libusb_init(&ctx);
@@ -284,20 +276,28 @@
 		return STATUS_UNSUCCESSFUL;
 	}
 
+#define GET_KEYS(key, values) \
+	rv = LTPBundleFindValueWithKey(&plist, key, values); \
+	if (rv) \
+	{ \
+		DEBUG_CRITICAL2("Value/Key not defined for " key " in %s", infofile); \
+		bundleRelease(&plist); \
+		return STATUS_UNSUCCESSFUL; \
+	}
+
+	GET_KEYS("ifdVendorID", &ifdVendorID)
+	GET_KEYS("ifdProductID", &ifdProductID);
+	GET_KEYS("ifdFriendlyName", &ifdFriendlyName)
+
 	/* for any supported reader */
-	while (LTPBundleFindValueWithKey(infofile, PCSCLITE_MANUKEY_NAME, keyValue, alias) == 0)
-	{
-		vendorID = strtoul(keyValue, NULL, 0);
-
-		if (LTPBundleFindValueWithKey(infofile, PCSCLITE_PRODKEY_NAME, keyValue, alias))
-			goto end;
-		productID = strtoul(keyValue, NULL, 0);
-
-		if (LTPBundleFindValueWithKey(infofile, PCSCLITE_NAMEKEY_NAME, keyValue, alias))
-			goto end;
-
-		/* go to next supported reader for next round */
-		alias++;
+	for (alias=0; alias<list_size(ifdVendorID); alias++)
+	{
+		unsigned int vendorID, productID;
+		char *friendlyName;
+
+		vendorID = strtoul(list_get_at(ifdVendorID, alias), NULL, 0);
+		productID = strtoul(list_get_at(ifdProductID, alias), NULL, 0);
+		friendlyName = list_get_at(ifdFriendlyName, alias);
 
 #ifndef __APPLE__
 		/* the device was specified but is not the one we are trying to find */
@@ -306,7 +306,7 @@
 			continue;
 #else
 		/* Leopard puts the friendlyname in the device argument */
-		if (device && strcmp(device, keyValue))
+		if (device && strcmp(device, friendlyName))
 			continue;
 #endif
 
@@ -495,7 +495,7 @@
 				}
 
 				DEBUG_INFO4("Found Vendor/Product: %04X/%04X (%s)",
-					desc.idVendor, desc.idProduct, keyValue);
+					desc.idVendor, desc.idProduct, friendlyName);
 				DEBUG_INFO3("Using USB bus/device: %d/%d",
 					bus_number, device_address);
 

Modified: trunk/Drivers/ccid/src/ifdhandler.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/ifdhandler.c?rev=5165&op=diff
==============================================================================
--- trunk/Drivers/ccid/src/ifdhandler.c (original)
+++ trunk/Drivers/ccid/src/ifdhandler.c Thu Aug 19 14:54:47 2010
@@ -1732,9 +1732,10 @@
 
 void init_driver(void)
 {
-	char keyValue[TOKEN_MAX_VALUE_SIZE];
 	char infofile[FILENAME_MAX];
 	char *e;
+	int rv;
+	list_t plist, *values;
 
 	DEBUG_INFO("Driver version: " VERSION);
 
@@ -1742,11 +1743,16 @@
 	(void)snprintf(infofile, sizeof(infofile), "%s/%s/Contents/Info.plist",
 		PCSCLITE_HP_DROPDIR, BUNDLE);
 
+	rv = bundleParse(infofile, &plist);
+	if (rv)
+		return;
+
 	/* Log level */
-	if (0 == LTPBundleFindValueWithKey(infofile, "ifdLogLevel", keyValue, 0))
+	rv = LTPBundleFindValueWithKey(&plist, "ifdLogLevel", &values);
+	if (0 == rv)
 	{
 		/* convert from hex or dec or octal */
-		LogLevel = strtoul(keyValue, NULL, 0);
+		LogLevel = strtoul(list_get_at(values, 0), NULL, 0);
 
 		/* print the log level used */
 		DEBUG_INFO2("LogLevel: 0x%.4X", LogLevel);
@@ -1763,14 +1769,17 @@
 	}
 
 	/* Driver options */
-	if (0 == LTPBundleFindValueWithKey(infofile, "ifdDriverOptions", keyValue, 0))
+	rv = LTPBundleFindValueWithKey(&plist, "ifdDriverOptions", &values);
+	if (0 == rv)
 	{
 		/* convert from hex or dec or octal */
-		DriverOptions = strtoul(keyValue, NULL, 0);
+		DriverOptions = strtoul(list_get_at(values, 0), NULL, 0);
 
 		/* print the log level used */
 		DEBUG_INFO2("DriverOptions: 0x%.4X", DriverOptions);
 	}
+
+	bundleRelease(&plist);
 
 	/* get the voltage parameter */
 	switch ((DriverOptions >> 4) & 0x03)

Added: trunk/Drivers/ccid/src/simclist.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/simclist.c?rev=5165&op=file
==============================================================================
--- trunk/Drivers/ccid/src/simclist.c (added)
+++ trunk/Drivers/ccid/src/simclist.c Thu Aug 19 14:54:47 2010
@@ -1,0 +1,1 @@
+link ../../../PCSC/src/simclist.c

Propchange: trunk/Drivers/ccid/src/simclist.c
------------------------------------------------------------------------------
    svn:special = *

Added: trunk/Drivers/ccid/src/simclist.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/Drivers/ccid/src/simclist.h?rev=5165&op=file
==============================================================================
--- trunk/Drivers/ccid/src/simclist.h (added)
+++ trunk/Drivers/ccid/src/simclist.h Thu Aug 19 14:54:47 2010
@@ -1,0 +1,1 @@
+link ../../../PCSC/src/simclist.h

Propchange: trunk/Drivers/ccid/src/simclist.h
------------------------------------------------------------------------------
    svn:special = *




More information about the Pcsclite-cvs-commit mailing list