diff options
-rw-r--r-- | SwifTools/MacOSXChecker.mm | 6 | ||||
-rw-r--r-- | Swiften/TLS/SecureTransport/SecureTransportCertificate.mm | 9 |
2 files changed, 9 insertions, 6 deletions
diff --git a/SwifTools/MacOSXChecker.mm b/SwifTools/MacOSXChecker.mm index aefe3e7..afaa87c 100644 --- a/SwifTools/MacOSXChecker.mm +++ b/SwifTools/MacOSXChecker.mm @@ -1,79 +1,81 @@ /* * Copyright (c) 2013 Tobias Markmann * Licensed under the Simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* - * Copyright (c) 2015-2016 Isode Limited. + * Copyright (c) 2015-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <SwifTools/MacOSXChecker.h> #include <algorithm> #include <cassert> #include <boost/algorithm/string.hpp> #include <AppKit/AppKit.h> +#include <SwifTools/Cocoa/CocoaUtil.h> + namespace Swift { MacOSXChecker::MacOSXChecker() { NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker]; [spellChecker setAutomaticallyIdentifiesLanguages:YES]; } MacOSXChecker::~MacOSXChecker() { } bool MacOSXChecker::isCorrect(const std::string& /*word*/) { // No content since it doesn't seem to be used anywhere. return false; } bool MacOSXChecker::isAutomaticallyDetectingLanguage() { return true; } void MacOSXChecker::setActiveLanguage(const std::string& /*language*/) { assert(false); } std::string MacOSXChecker::activeLanguage() const { assert(false); } std::vector<std::string> MacOSXChecker::supportedLanguages() const { assert(false); } void MacOSXChecker::getSuggestions(const std::string& word, std::vector<std::string>& list) { NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker]; NSString* wordString = [[NSString alloc] initWithUTF8String: word.c_str()]; NSArray* suggestions = [spellChecker guessesForWordRange:NSMakeRange(0, [wordString length]) inString:wordString language:nil inSpellDocumentWithTag:0]; for(unsigned int i = 0; i < [suggestions count]; ++i) { - list.push_back(std::string([[suggestions objectAtIndex:i] UTF8String])); + list.push_back(ns2StdString([suggestions objectAtIndex:i])); } [wordString release]; } void MacOSXChecker::checkFragment(const std::string& fragment, PositionPairList& misspelledPositions) { NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker]; size_t nextLocation = 0; NSRange range; NSString *fragmentString = [[NSString alloc] initWithUTF8String: fragment.c_str()]; do { range = [spellChecker checkSpellingOfString:fragmentString startingAt:static_cast<long>(nextLocation)]; if (range.location != NSNotFound) { if (range.location < nextLocation) break; misspelledPositions.push_back(PositionPair(range.location, range.location + range.length)); nextLocation = range.location + range.length + 1; } } while (range.location != NSNotFound); [fragmentString release]; } } diff --git a/Swiften/TLS/SecureTransport/SecureTransportCertificate.mm b/Swiften/TLS/SecureTransport/SecureTransportCertificate.mm index db0af89..fffb3ed 100644 --- a/Swiften/TLS/SecureTransport/SecureTransportCertificate.mm +++ b/Swiften/TLS/SecureTransport/SecureTransportCertificate.mm @@ -1,32 +1,32 @@ /* - * Copyright (c) 2015-2016 Isode Limited. + * Copyright (c) 2015-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/TLS/SecureTransport/SecureTransportCertificate.h> #include <boost/numeric/conversion/cast.hpp> #include <Cocoa/Cocoa.h> #include <Security/Security.h> #include <Swiften/Base/Log.h> namespace { template <typename T, typename S> T bridge_cast(S source) { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wold-style-cast" return (__bridge T)(source); #pragma clang diagnostic pop } } namespace { inline std::string ns2StdString(NSString* _Nullable nsString); inline std::string ns2StdString(NSString* _Nullable nsString) { std::string stdString; @@ -66,67 +66,68 @@ void SecureTransportCertificate::parse() { assert(certificateHandle_); CFErrorRef error = nullptr; // The SecCertificateCopyValues function is not part of the iOS Secure Transport API. CFDictionaryRef valueDict = SecCertificateCopyValues(certificateHandle_.get(), nullptr, &error); if (valueDict) { // Handle subject. CFStringRef subject = SecCertificateCopySubjectSummary(certificateHandle_.get()); if (subject) { NSString* subjectStr = bridge_cast<NSString*>(subject); subjectName_ = ns2StdString(subjectStr); CFRelease(subject); } // Handle a single Common Name. CFStringRef commonName = nullptr; OSStatus error = SecCertificateCopyCommonName(certificateHandle_.get(), &commonName); if (!error && commonName) { NSString* commonNameStr = bridge_cast<NSString*>(commonName); commonNames_.push_back(ns2StdString(commonNameStr)); } if (commonName) { CFRelease(commonName); } // Handle Subject Alternative Names NSDictionary* certDict = bridge_cast<NSDictionary*>(valueDict); NSDictionary* subjectAltNamesDict = certDict[@"2.5.29.17"][@"value"]; for (NSDictionary* entry in subjectAltNamesDict) { - if ([entry[@"label"] isEqualToString:static_cast<NSString * _Nonnull>([NSString stringWithUTF8String:ID_ON_XMPPADDR_OID])]) { + NSString* label = entry[@"label"]; + if ([label isEqualToString:static_cast<NSString * _Nonnull>([NSString stringWithUTF8String:ID_ON_XMPPADDR_OID])]) { xmppAddresses_.push_back(ns2StdString(entry[@"value"])); } - else if ([entry[@"label"] isEqualToString:static_cast<NSString * _Nonnull>([NSString stringWithUTF8String:ID_ON_DNSSRV_OID])]) { + else if ([label isEqualToString:static_cast<NSString * _Nonnull>([NSString stringWithUTF8String:ID_ON_DNSSRV_OID])]) { srvNames_.push_back(ns2StdString(entry[@"value"])); } - else if ([entry[@"label"] isEqualToString:@"DNS Name"]) { + else if ([label isEqualToString:@"DNS Name"]) { dnsNames_.push_back(ns2StdString(entry[@"value"])); } } CFRelease(valueDict); } if (error) { CFRelease(error); } } std::string SecureTransportCertificate::getSubjectName() const { return subjectName_; } std::vector<std::string> SecureTransportCertificate::getCommonNames() const { return commonNames_; } std::vector<std::string> SecureTransportCertificate::getSRVNames() const { return srvNames_; } std::vector<std::string> SecureTransportCertificate::getDNSNames() const { return dnsNames_; } std::vector<std::string> SecureTransportCertificate::getXMPPAddresses() const { return xmppAddresses_; } |