mac: other types
This commit is contained in:
67
src/pcsc.hxx
67
src/pcsc.hxx
@@ -10,9 +10,35 @@
|
|||||||
#ifndef PCSC_HXX
|
#ifndef PCSC_HXX
|
||||||
#define PCSC_HXX
|
#define PCSC_HXX
|
||||||
|
|
||||||
#include <PCSC/wintypes.h>
|
#ifdef WIN32
|
||||||
#include <PCSC/pcsclite.h>
|
#include "WinSCard.h"
|
||||||
#include <PCSC/winscard.h>
|
#ifndef MAX_ATR_SIZE
|
||||||
|
#define MAX_ATR_SIZE 33
|
||||||
|
#endif
|
||||||
|
namespace pcsc {
|
||||||
|
//! stupid windows needs std::wstring
|
||||||
|
std::wstring strconv(std::string s) {
|
||||||
|
return std::wstring(s.begin(), s.end());
|
||||||
|
}
|
||||||
|
std::string strconv(std::wstring s) {
|
||||||
|
return std::string(s.begin(), s.end());
|
||||||
|
}
|
||||||
|
typedef wchar_t char_t;
|
||||||
|
typedef std::wstring string;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#include <PCSC/pcsclite.h>
|
||||||
|
#include <PCSC/wintypes.h>
|
||||||
|
#include <PCSC/pcsclite.h>
|
||||||
|
#include <PCSC/winscard.h>
|
||||||
|
namespace pcsc {
|
||||||
|
const std::string& strconv(const std::string& s) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
typedef char char_t;
|
||||||
|
typedef std::string string;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -169,9 +195,9 @@ namespace pcsc {
|
|||||||
|
|
||||||
//! Get reader status.
|
//! Get reader status.
|
||||||
Status status() {
|
Status status() {
|
||||||
unsigned long dummy(0);
|
DWORD dummy(0);
|
||||||
unsigned long s;
|
DWORD s;
|
||||||
unsigned long len(MAX_ATR_SIZE);
|
DWORD len(MAX_ATR_SIZE);
|
||||||
unsigned char a[len];
|
unsigned char a[len];
|
||||||
check(SCardStatus(_id, 0, &dummy, &s, &_protocol, a, &len));
|
check(SCardStatus(_id, 0, &dummy, &s, &_protocol, a, &len));
|
||||||
return Status(s, std::string((char*)a, len));
|
return Status(s, std::string((char*)a, len));
|
||||||
@@ -179,7 +205,7 @@ namespace pcsc {
|
|||||||
|
|
||||||
//! Transmit data to reader.
|
//! Transmit data to reader.
|
||||||
std::string transmit(std::string in) {
|
std::string transmit(std::string in) {
|
||||||
unsigned long len(1024); // arbitrary
|
DWORD len(1024); // arbitrary
|
||||||
unsigned char buff[len];
|
unsigned char buff[len];
|
||||||
SCARD_IO_REQUEST rPci;
|
SCARD_IO_REQUEST rPci;
|
||||||
check(SCardTransmit(_id, pci(),
|
check(SCardTransmit(_id, pci(),
|
||||||
@@ -217,7 +243,7 @@ namespace pcsc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! @throw not_implemented if _protocol is unknown. */
|
/*! @throw not_implemented if _protocol is unknown. */
|
||||||
SCARD_IO_REQUEST* pci() {
|
const SCARD_IO_REQUEST* pci() {
|
||||||
switch(_protocol) {
|
switch(_protocol) {
|
||||||
case SCARD_PROTOCOL_T0: return SCARD_PCI_T0;
|
case SCARD_PROTOCOL_T0: return SCARD_PCI_T0;
|
||||||
case SCARD_PROTOCOL_T1: return SCARD_PCI_T1;
|
case SCARD_PROTOCOL_T1: return SCARD_PCI_T1;
|
||||||
@@ -240,7 +266,7 @@ namespace pcsc {
|
|||||||
//! Establishes a connection to the given named cardreader
|
//! Establishes a connection to the given named cardreader
|
||||||
Reader(const std::string& nm, Connection& c):
|
Reader(const std::string& nm, Connection& c):
|
||||||
name(nm), _connection(c) {
|
name(nm), _connection(c) {
|
||||||
check(SCardConnect(_connection._id, name.c_str(),
|
check(SCardConnect(_connection._id, strconv(name).c_str(),
|
||||||
SCARD_SHARE_SHARED,
|
SCARD_SHARE_SHARED,
|
||||||
SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1,
|
SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1,
|
||||||
&_id, &_protocol));
|
&_id, &_protocol));
|
||||||
@@ -256,9 +282,9 @@ namespace pcsc {
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
Connection& _connection;
|
Connection& _connection;
|
||||||
long _id;
|
SCARDHANDLE _id;
|
||||||
long _state;
|
long _state;
|
||||||
unsigned long _protocol;
|
DWORD _protocol;
|
||||||
|
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------Reader
|
//------------------------------------------------------------------Reader
|
||||||
@@ -319,14 +345,15 @@ namespace pcsc {
|
|||||||
Strings scan(const Strings& groups = Strings()) {
|
Strings scan(const Strings& groups = Strings()) {
|
||||||
Strings res;
|
Strings res;
|
||||||
std::string grp(join(groups));
|
std::string grp(join(groups));
|
||||||
unsigned long num(0);
|
DWORD num(0);
|
||||||
if (!check(SCardListReaders(_id, grp.size()?grp.data():0, 0, &num)))
|
if (!check(SCardListReaders(_id, grp.size()?strconv(grp).data():0, 0,
|
||||||
|
&num)))
|
||||||
return res;
|
return res;
|
||||||
std::auto_ptr<char> nm(new char[num]);
|
std::auto_ptr<char_t> nm(new char_t[num]);
|
||||||
if (!check(SCardListReaders(_id, grp.size()?grp.data():0,
|
if (!check(SCardListReaders(_id, grp.size()?strconv(grp).data():0,
|
||||||
nm.get(), &num)))
|
nm.get(), &num)))
|
||||||
return res;
|
return res;
|
||||||
return res = split(std::string(nm.get(), num-1));
|
return res = split(strconv(string(nm.get(), num-1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Get a reader, open a connection if not already open.
|
//! Get a reader, open a connection if not already open.
|
||||||
@@ -352,7 +379,13 @@ namespace pcsc {
|
|||||||
|
|
||||||
//! Get the describing text of the last error
|
//! Get the describing text of the last error
|
||||||
std::string error() const {
|
std::string error() const {
|
||||||
|
#ifdef WIN32
|
||||||
|
std::stringstream ss;
|
||||||
|
ss<<"PCSC state: "<<_state;
|
||||||
|
return ss.str();
|
||||||
|
#else
|
||||||
return pcsc_stringify_error(_state);
|
return pcsc_stringify_error(_state);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
//................................................................methods
|
//................................................................methods
|
||||||
@@ -396,7 +429,7 @@ namespace pcsc {
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
bool _exc;
|
bool _exc;
|
||||||
long _id;
|
SCARDCONTEXT _id;
|
||||||
long _state;
|
long _state;
|
||||||
std::map<std::string, boost::shared_ptr<Reader> > _reader;
|
std::map<std::string, boost::shared_ptr<Reader> > _reader;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user