Changeset View
Changeset View
Standalone View
Standalone View
b/scd/pcsc-wrapper.c
Context not available. | |||||
handle_open (unsigned char *argbuf, size_t arglen) | handle_open (unsigned char *argbuf, size_t arglen) | ||||
{ | { | ||||
long err; | long err; | ||||
const char * portstr; | const char *portstr; | ||||
char *list = NULL; | char *list = NULL; | ||||
char *rdrname = NULL; | |||||
pcsc_dword_t nreader, atrlen; | pcsc_dword_t nreader, atrlen; | ||||
char *p; | char *p; | ||||
pcsc_dword_t card_state, card_protocol; | pcsc_dword_t card_state, card_protocol; | ||||
Context not available. | |||||
/* Make sure there is only the port string */ | /* Make sure there is only the port string */ | ||||
if (arglen != strlen ((char*)argbuf)) | if (arglen != strlen ((char*)argbuf)) | ||||
bad_request ("OPEN"); | bad_request ("OPEN"); | ||||
portstr = (char*)argbuf; | if (arglen == 0) | ||||
portstr = NULL; | |||||
else | |||||
portstr = (char*)argbuf; | |||||
if (driver_is_open) | if (driver_is_open) | ||||
{ | { | ||||
Context not available. | |||||
fprintf (stderr, PGM": invalid response from pcsc_list_readers\n"); | fprintf (stderr, PGM": invalid response from pcsc_list_readers\n"); | ||||
break; | break; | ||||
} | } | ||||
if (!rdrname && portstr && !strncmp (p, portstr, strlen (portstr))) | |||||
rdrname = p; | |||||
nreader -= strlen (p)+1; | nreader -= strlen (p)+1; | ||||
p += strlen (p) + 1; | p += strlen (p) + 1; | ||||
} | } | ||||
current_rdrname = malloc (strlen (portstr && *portstr? portstr:list)+1); | if (!rdrname) | ||||
rdrname = list; | |||||
current_rdrname = strdup (rdrname); | |||||
if (!current_rdrname) | if (!current_rdrname) | ||||
{ | { | ||||
fprintf (stderr, PGM": error allocating memory for reader name\n"); | fprintf (stderr, PGM": error allocating memory for reader name\n"); | ||||
exit (1); | exit (1); | ||||
} | } | ||||
strcpy (current_rdrname, portstr && *portstr? portstr:list); | |||||
free (list); | free (list); | ||||
err = pcsc_connect (pcsc_context, | err = pcsc_connect (pcsc_context, | ||||
Context not available. |