Last active
April 24, 2018 16:13
-
-
Save dpward/371c27079513adfc905d8035449a81b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/libopensc/reader-cryptotokenkit.m b/src/libopensc/reader-cryptotokenkit.m | |
index cf07746..29dd2fb 100644 | |
--- a/src/libopensc/reader-cryptotokenkit.m | |
+++ b/src/libopensc/reader-cryptotokenkit.m | |
@@ -545,6 +545,7 @@ static int cryptotokenkit_detect_readers(sc_context_t *ctx) | |
size_t i; | |
int r; | |
TKSmartCardSlotManager *mngr = [TKSmartCardSlotManager defaultManager]; | |
+ NSMutableArray *slotNames; | |
LOG_FUNC_CALLED(ctx); | |
@@ -554,38 +555,31 @@ static int cryptotokenkit_detect_readers(sc_context_t *ctx) | |
goto err; | |
} | |
- /* temporarily mark all readers as removed */ | |
- for (i=0; i < sc_ctx_get_reader_count(ctx); i++) { | |
- sc_reader_t *reader = sc_ctx_get_reader(ctx, i); | |
- reader->flags |= SC_READER_REMOVED; | |
- } | |
- | |
sc_log(ctx, "Probing CryptoTokenKit readers"); | |
- for (NSString *slotName in [mngr slotNames]) { | |
- sc_reader_t *old_reader; | |
- int found = 0; | |
- const char *reader_name = [slotName UTF8String]; | |
- dispatch_semaphore_t sema = dispatch_semaphore_create(0); | |
+ slotNames = [[mngr slotNames] mutableCopy]; | |
- for (i=0; i < sc_ctx_get_reader_count(ctx) && !found; i++) { | |
- old_reader = sc_ctx_get_reader(ctx, i); | |
- if (old_reader == NULL) { | |
- r = SC_ERROR_INTERNAL; | |
- goto err; | |
- } | |
- if (!strcmp(old_reader->name, reader_name)) { | |
- found = 1; | |
- } | |
- } | |
+ for (i=0; i < sc_ctx_get_reader_count(ctx); i++) { | |
+ NSString *slotName; | |
+ NSUInteger index; | |
- /* Reader already available, skip */ | |
- if (found) { | |
- old_reader->flags &= ~SC_READER_REMOVED; | |
- continue; | |
+ sc_reader_t *reader = sc_ctx_get_reader(ctx, i); | |
+ if (reader == NULL) { | |
+ r = SC_ERROR_INTERNAL; | |
+ goto err; | |
} | |
- sc_log(ctx, "Found new CryptoTokenKit reader '%s'", reader_name); | |
+ slotName = [[NSString alloc] initWithUTF8String:reader->name]; | |
+ index = [slotNames indexOfObject:slotName]; | |
+ if (index == NSNotFound) | |
+ reader->flags |= SC_READER_REMOVED; | |
+ else | |
+ [slotNames removeObjectAtIndex:index]; | |
+ } | |
+ | |
+ for (NSString *slotName in slotNames) { | |
+ dispatch_semaphore_t sema = dispatch_semaphore_create(0); | |
+ sc_log(ctx, "Found new CryptoTokenKit reader '%s'", [slotName UTF8String]); | |
[mngr getSlotWithName:slotName reply:^(TKSmartCardSlot *slot) { | |
cryptotokenkit_use_reader(ctx, slot, NULL); | |
dispatch_semaphore_signal(sema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment