[Pcsclite-cvs-commit] r5215 - in /trunk/PCSC/src: eventhandler.c readerfactory.c readerfactory.h winscard.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Thu Sep 2 09:33:42 UTC 2010


Author: rousseau
Date: Thu Sep  2 09:33:39 2010
New Revision: 5215

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=5215
Log:
Get rid of the lpcReader[] field in struct ReaderContext

The reader name is already present in readerState->readerName linked
from struct ReaderContext

Gain: MAX_READERNAME*PCSCLITE_MAX_READERS_CONTEXTS = 100*16 = 1600 bytes
fo RAM on pcscd

Modified:
    trunk/PCSC/src/eventhandler.c
    trunk/PCSC/src/readerfactory.c
    trunk/PCSC/src/readerfactory.h
    trunk/PCSC/src/winscard.c

Modified: trunk/PCSC/src/eventhandler.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/eventhandler.c?rev=5215&op=diff
==============================================================================
--- trunk/PCSC/src/eventhandler.c (original)
+++ trunk/PCSC/src/eventhandler.c Thu Sep  2 09:33:39 2010
@@ -215,12 +215,10 @@
 	rv = IFDStatusICC(rContext, &dwStatus, ucAtr, &dwAtrLen);
 	if (rv != SCARD_S_SUCCESS)
 	{
-		Log2(PCSC_LOG_ERROR, "Initial Check Failed on %s", rContext->lpcReader);
+		Log2(PCSC_LOG_ERROR, "Initial Check Failed on %s",
+			rContext->readerState->readerName);
 		return SCARD_F_UNKNOWN_ERROR;
 	}
-
-	(void)strlcpy(rContext->readerState->readerName, rContext->lpcReader,
-		sizeof(rContext->readerState->readerName));
 
 	rContext->pthCardEvent = card_event;
 	rv = ThreadCreate(&rContext->pthThread, 0,
@@ -260,7 +258,7 @@
 	readerSharing = 0;
 	dwCurrentState = 0;
 
-	lpcReader = rContext->lpcReader;
+	lpcReader = rContext->readerState->readerName;
 
 	dwAtrLen = rContext->readerState->cardAtrLength;
 	rv = IFDStatusICC(rContext, &dwStatus, rContext->readerState->cardAtr,

Modified: trunk/PCSC/src/readerfactory.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/readerfactory.c?rev=5215&op=diff
==============================================================================
--- trunk/PCSC/src/readerfactory.c (original)
+++ trunk/PCSC/src/readerfactory.c Thu Sep  2 09:33:39 2010
@@ -134,7 +134,8 @@
 				int tmplen;
 
 				/* get the reader name without the reader and slot numbers */
-				strncpy(lpcStripReader, (sReadersContexts[i])->lpcReader,
+				strncpy(lpcStripReader,
+					sReadersContexts[i]->readerState->readerName,
 					sizeof(lpcStripReader));
 				tmplen = strlen(lpcStripReader);
 				lpcStripReader[tmplen - 6] = 0;
@@ -337,9 +338,10 @@
 		}
 
 		/* Copy the previous reader name and increment the slot number */
-		tmpReader = sReadersContexts[dwContextB]->lpcReader;
-		(void)strlcpy(tmpReader, sReadersContexts[dwContext]->lpcReader,
-			sizeof(sReadersContexts[dwContextB]->lpcReader));
+		tmpReader = sReadersContexts[dwContextB]->readerState->readerName;
+		(void)strlcpy(tmpReader,
+			sReadersContexts[dwContext]->readerState->readerName,
+			sizeof(sReadersContexts[dwContextB]->readerState->readerName));
 		sprintf(tmpReader + strlen(tmpReader) - 2, "%02X", j);
 
 		sReadersContexts[dwContextB]->lpcLibrary =
@@ -577,7 +579,7 @@
 						&& ((sReadersContexts[i])->port != port))
 						|| (supportedChannels > 1))
 					{
-						char *lpcReader = sReadersContexts[i]->lpcReader;
+						char *lpcReader = sReadersContexts[i]->readerState->readerName;
 
 						/*
 						 * tells the caller who the parent of this
@@ -629,7 +631,8 @@
 		}
 	}
 
-	snprintf(rContext->lpcReader, sizeof(rContext->lpcReader), "%s %02X %02lX",
+	snprintf(rContext->readerState->readerName,
+		sizeof(rContext->readerState->readerName), "%s %02X %02lX",
 		readerName, i, slot);
 
 	/* Set the slot in 0xDDDDCCCC */
@@ -649,7 +652,8 @@
 	{
 		if ((sReadersContexts[i])->vHandle != 0)
 		{
-			if (strcmp(lpcReader, (sReadersContexts[i])->lpcReader) == 0)
+			if (strcmp(lpcReader,
+				sReadersContexts[i]->readerState->readerName) == 0)
 			{
 				*sReader = sReadersContexts[i];
 				return SCARD_S_SUCCESS;
@@ -672,7 +676,8 @@
 		{
 			int tmplen;
 
-			strncpy(lpcStripReader, (sReadersContexts[i])->lpcReader,
+			strncpy(lpcStripReader,
+				sReadersContexts[i]->readerState->readerName,
 				sizeof(lpcStripReader));
 			tmplen = strlen(lpcStripReader);
 			lpcStripReader[tmplen - 6] = 0;
@@ -959,7 +964,7 @@
 
 	/* Spawn the event handler thread */
 	Log3(PCSC_LOG_INFO, "Attempting startup of %s using %s",
-		rContext->lpcReader, rContext->lpcLibrary);
+		rContext->readerState->readerName, rContext->lpcLibrary);
 
 #ifndef PCSCLITE_STATIC_DRIVER
 	/* loads the library */
@@ -1005,7 +1010,7 @@
 LONG RFUnInitializeReader(READER_CONTEXT * rContext)
 {
 	Log2(PCSC_LOG_INFO, "Attempting shutdown of %s.",
-		rContext->lpcReader);
+		rContext->readerState->readerName);
 
 	/* Close the port, unbind the functions, and unload the library */
 
@@ -1275,9 +1280,10 @@
 			char lpcStripReader[MAX_READERNAME];
 
 			Log2(PCSC_LOG_INFO, "Stopping reader: %s",
-				sReadersContexts[i]->lpcReader);
-
-			strncpy(lpcStripReader, (sReadersContexts[i])->lpcReader,
+				sReadersContexts[i]->readerState->readerName);
+
+			strncpy(lpcStripReader,
+				sReadersContexts[i]->readerState->readerName,
 				sizeof(lpcStripReader));
 			/* strip the 6 last char ' 00 00' */
 			lpcStripReader[strlen(lpcStripReader) - 6] = '\0';
@@ -1382,7 +1388,8 @@
 				int tmplen;
 
 				/* get the reader name without the reader and slot numbers */
-				strncpy(lpcStripReader, sReadersContexts[i]->lpcReader,
+				strncpy(lpcStripReader,
+					sReadersContexts[i]->readerState->readerName,
 					sizeof(lpcStripReader));
 				tmplen = strlen(lpcStripReader);
 				lpcStripReader[tmplen - 6] = 0;

Modified: trunk/PCSC/src/readerfactory.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/readerfactory.h?rev=5215&op=diff
==============================================================================
--- trunk/PCSC/src/readerfactory.h (original)
+++ trunk/PCSC/src/readerfactory.h Thu Sep  2 09:33:39 2010
@@ -105,7 +105,6 @@
 
 	struct ReaderContext
 	{
-		char lpcReader[MAX_READERNAME];	/**< Reader Name */
 		char *lpcLibrary;	/**< Library Path */
 		char *lpcDevice;	/**< Device Name */
 		pthread_t pthThread;	/**< Event polling thread */

Modified: trunk/PCSC/src/winscard.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard.c?rev=5215&op=diff
==============================================================================
--- trunk/PCSC/src/winscard.c (original)
+++ trunk/PCSC/src/winscard.c Thu Sep  2 09:33:39 2010
@@ -1207,6 +1207,8 @@
 {
 	LONG rv;
 	READER_CONTEXT * rContext = NULL;
+	char *readerName;
+	unsigned int readerLen;
 
 	if (hCard == 0)
 		return SCARD_E_INVALID_HANDLE;
@@ -1251,19 +1253,21 @@
 	rv = RFCheckReaderStatus(rContext);
 	if (rv != SCARD_S_SUCCESS)
 		return rv;
+
+	readerName = rContext->readerState->readerName;
+	readerLen = strlen(readerName);
 
 	if (mszReaderNames)
 	{  /* want reader name */
 		if (pcchReaderLen)
 		{ /* & present reader name length */
-			if (*pcchReaderLen >= strlen(rContext->lpcReader))
+			*pcchReaderLen = readerLen;
+			if (*pcchReaderLen >= readerLen)
 			{ /* & enough room */
-				*pcchReaderLen = strlen(rContext->lpcReader);
-				strncpy(mszReaderNames, rContext->lpcReader, MAX_READERNAME);
+				strncpy(mszReaderNames, readerName, MAX_READERNAME);
 			}
 			else
 			{        /* may report only reader name len */
-				*pcchReaderLen = strlen(rContext->lpcReader);
 				rv = SCARD_E_INSUFFICIENT_BUFFER;
 			}
 		}
@@ -1276,7 +1280,7 @@
 	{
 		if (pcchReaderLen)
 		{ /* want reader len only */
-			*pcchReaderLen = strlen(rContext->lpcReader);
+			*pcchReaderLen = readerLen;
 		}
 		else
 		{
@@ -1447,15 +1451,15 @@
 			 */
 			if (dwAttrId == SCARD_ATTR_DEVICE_FRIENDLY_NAME)
 			{
-				unsigned int len = strlen(rContext->lpcReader)+1;
+				unsigned int len = strlen(rContext->readerState->readerName)+1;
 
 				*pcbAttrLen = len;
 				if (len > *pcbAttrLen)
 					rv = SCARD_E_INSUFFICIENT_BUFFER;
 				else
 				{
-					(void)strlcpy((char *)pbAttr, rContext->lpcReader,
-						*pcbAttrLen);
+					(void)strlcpy((char *)pbAttr,
+						rContext->readerState->readerName, *pcbAttrLen);
 					rv = SCARD_S_SUCCESS;
 				}
 




More information about the Pcsclite-cvs-commit mailing list