Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
3.8 KiB

  1. // CSpec.cpp -- Card Specification
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1998. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include <scuOsExc.h>
  8. #include "cspec.h"
  9. using namespace std;
  10. bool
  11. CSpec::ValidName(string const &rsName) const
  12. {
  13. return (rsName.find(BreakToken()) == string::npos);
  14. }
  15. // Parse specification (possibly a Fully Qualified Card [container]
  16. // Name) into the respective tokens. A FQCN takes the form
  17. // "[\\.\<readerName>[\{<cardId>|}]]|[{\}<cardId>]". The preceding
  18. // backslash-backslash-period-backslash is used in Win32 to identify a
  19. // specific device name. It is used to identify that everything from
  20. // there to the next backslash or end-of-string indicates the exact
  21. // reader in which the card in question is to be found. Anything
  22. // following that last backslash occurrence indicates the actual card
  23. // Id and container name, with an empty string implying the default
  24. // for the card in the specified reader.
  25. CSpec::CSpec(string const &rsSpec)
  26. {
  27. string sRHSpec;
  28. if (0 == rsSpec.find(DeviceIdToken()))
  29. {
  30. sRHSpec = rsSpec.substr(DeviceIdToken().length());
  31. // Find the reader
  32. string::size_type const stEndOfName(sRHSpec.find(BreakToken()));
  33. if (0 == stEndOfName)
  34. throw scu::OsException(NTE_BAD_KEYSET_PARAM);
  35. if (string::npos != stEndOfName)
  36. {
  37. string const sReader(sRHSpec.substr(0, stEndOfName));
  38. if (ValidName(sReader))
  39. m_sReader = sReader;
  40. else
  41. throw scu::OsException(NTE_BAD_KEYSET_PARAM);
  42. sRHSpec = sRHSpec.substr(stEndOfName + 1);
  43. }
  44. else
  45. {
  46. m_sReader = sRHSpec;
  47. sRHSpec.erase();
  48. }
  49. }
  50. else
  51. sRHSpec = rsSpec;
  52. // Check for well-formed card id
  53. if (ValidName(sRHSpec))
  54. m_sCardId = sRHSpec;
  55. else
  56. throw scu::OsException(NTE_BAD_KEYSET_PARAM);
  57. RefreshSpec();
  58. }
  59. CSpec::CSpec(string const &rsReader,
  60. string const &rsCardId)
  61. {
  62. if (!ValidName(rsReader) || !ValidName(rsCardId))
  63. throw scu::OsException(NTE_BAD_KEYSET_PARAM);
  64. m_sReader = rsReader;
  65. m_sCardId = rsCardId;
  66. RefreshSpec();
  67. }
  68. CSpec::CSpec(CSpec const &rhs)
  69. : m_sReader(rhs.m_sReader),
  70. m_sCardId(rhs.m_sCardId),
  71. m_sSpec(rhs.m_sSpec)
  72. {
  73. }
  74. void
  75. CSpec::Empty(void)
  76. {
  77. m_sReader.erase();
  78. m_sCardId.erase();
  79. m_sSpec.erase();
  80. }
  81. void
  82. CSpec::EmptyCardId(void)
  83. {
  84. m_sCardId.erase();
  85. RefreshSpec();
  86. }
  87. void
  88. CSpec::EmptyReader(void)
  89. {
  90. m_sReader.erase();
  91. RefreshSpec();
  92. }
  93. bool
  94. CSpec::Equiv(string const &rsSpec,
  95. string const &rsName)
  96. {
  97. return rsSpec.empty() || (rsSpec == rsName);
  98. }
  99. bool
  100. CSpec::Equiv(CSpec const &rhs) const
  101. {
  102. return Equiv(m_sReader, rhs.m_sReader) &&
  103. Equiv(m_sCardId, rhs.m_sCardId);
  104. }
  105. void
  106. CSpec::RefreshSpec(void)
  107. {
  108. if (m_sReader.empty())
  109. m_sSpec = m_sCardId;
  110. else
  111. {
  112. m_sSpec = DeviceIdToken();
  113. m_sSpec += m_sReader;
  114. m_sSpec += BreakToken();
  115. m_sSpec += m_sCardId;
  116. }
  117. }
  118. void
  119. CSpec::SetCardId(string const &rsCardId)
  120. {
  121. m_sCardId = rsCardId;
  122. RefreshSpec();
  123. }
  124. void
  125. CSpec::SetReader(string const &rsReader)
  126. {
  127. m_sReader = rsReader;
  128. RefreshSpec();
  129. }
  130. CSpec &
  131. CSpec::operator=(CSpec const &rhs)
  132. {
  133. if (this == &rhs)
  134. return *this;
  135. m_sReader = rhs.m_sReader;
  136. m_sCardId = rhs.m_sCardId;
  137. RefreshSpec();
  138. return *this;
  139. }