Logo Search packages:      
Sourcecode: pcsc-lite version File versions  Download package

LONG SCardCancelTransaction ( SCARDHANDLE  hCard  ) 

Deprecated:
This function is not in Microsoft(R) WinSCard API and is deprecated in pcsc-lite API.

Definition at line 1365 of file winscard_clnt.c.

References rxSharedSegment::data, cancel_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_READERS_CONTEXTS, _psContextMap::psChannelMap, psContextMap, _psChannelMap::readerName, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_F_COMM_ERROR, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SHMClientRead(), and WrapSHMWrite().

{
      LONG rv;
      cancel_struct scCancelStruct;
      sharedSegmentMsg msgStruct;
      int i;
      DWORD dwContextIndex, dwChannelIndex;

      PROFILE_START

      rv = SCardCheckDaemonAvailability();
      if (rv != SCARD_S_SUCCESS)
            return rv;

      /*
       * Make sure this handle has been opened
       */
      rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
      if (rv == -1)
            return SCARD_E_INVALID_HANDLE;

      (void)SYS_MutexLock(psContextMap[dwContextIndex].mMutex);

      /* check the handle is still valid */
      rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
      if (rv == -1)
            /* the handle is now invalid
             * -> another thread may have called SCardReleaseContext
             * -> so the mMutex has been unlocked */
            return SCARD_E_INVALID_HANDLE;

      for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
      {
            char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;

            /* by default r == NULL */
            if (r && strcmp(r, (readerStates[i])->readerName) == 0)
                  break;
      }

      if (i == PCSCLITE_MAX_READERS_CONTEXTS)
      {
            (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
            return SCARD_E_READER_UNAVAILABLE;
      }

      scCancelStruct.hCard = hCard;

      rv = WrapSHMWrite(SCARD_CANCEL_TRANSACTION,
            psContextMap[dwContextIndex].dwClientID,
            sizeof(scCancelStruct),
            PCSCLITE_CLIENT_ATTEMPTS, (void *) &scCancelStruct);

      if (rv == -1)
      {
            (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
            return SCARD_E_NO_SERVICE;
      }

      /*
       * Read a message from the server
       */
      rv = SHMClientRead(&msgStruct, psContextMap[dwContextIndex].dwClientID,
            PCSCLITE_CLIENT_ATTEMPTS);

      memcpy(&scCancelStruct, &msgStruct.data, sizeof(scCancelStruct));

      if (rv == -1)
      {
            (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
            return SCARD_F_COMM_ERROR;
      }

      (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);

      PROFILE_END(scCancelStruct.rv)

      return scCancelStruct.rv;
}


Generated by  Doxygen 1.6.0   Back to index