summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-08-17 13:35:13 +0200
committerAndrej Mihajlov <and@mullvad.net>2020-08-18 17:18:20 +0200
commitec96a7e65a252533ed3634995dfcc64887ec3112 (patch)
tree550ac9a1093b5d91b4b8ddaea596082819428dc9
parent94cd0e081ceb793adc7c23f69683536650548f2a (diff)
downloadmullvadvpn-ec96a7e65a252533ed3634995dfcc64887ec3112.tar.xz
mullvadvpn-ec96a7e65a252533ed3634995dfcc64887ec3112.zip
Conditionally compile classes used in DEBUG only
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj8
-rw-r--r--ios/MullvadVPN/Logging/LogStreamer.swift4
-rw-r--r--ios/MullvadVPN/Logging/StringStreamIterator.swift58
-rw-r--r--ios/MullvadVPN/Logging/TextFileStream.swift47
4 files changed, 71 insertions, 46 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 43c8b30ed0..4161ef6378 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -155,6 +155,7 @@
58BFA5CD22A7CE1F00A6173D /* ApplicationConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BFA5CB22A7CE1F00A6173D /* ApplicationConfiguration.swift */; };
58C3A4B222456F1B00340BDB /* AccountInputGroupView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C3A4B122456F1A00340BDB /* AccountInputGroupView.swift */; };
58C3B06724EA768100C0348E /* LogStreamerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C3B06624EA768100C0348E /* LogStreamerViewController.swift */; };
+ 58C3B06924EAA25000C0348E /* StringStreamIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C3B06824EAA25000C0348E /* StringStreamIterator.swift */; };
58C6B34F22BB7AC0003C19AD /* IPAddressRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C6B34E22BB7AC0003C19AD /* IPAddressRange.swift */; };
58C6B35122BB7CFD003C19AD /* IPAddressRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C6B34E22BB7AC0003C19AD /* IPAddressRange.swift */; };
58C6B35422BB87C4003C19AD /* WireguardPrivateKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C6B35322BB87C4003C19AD /* WireguardPrivateKey.swift */; };
@@ -341,6 +342,7 @@
58BFA5CB22A7CE1F00A6173D /* ApplicationConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationConfiguration.swift; sourceTree = "<group>"; };
58C3A4B122456F1A00340BDB /* AccountInputGroupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountInputGroupView.swift; sourceTree = "<group>"; };
58C3B06624EA768100C0348E /* LogStreamerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogStreamerViewController.swift; sourceTree = "<group>"; };
+ 58C3B06824EAA25000C0348E /* StringStreamIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringStreamIterator.swift; sourceTree = "<group>"; };
58C6B34E22BB7AC0003C19AD /* IPAddressRange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPAddressRange.swift; sourceTree = "<group>"; };
58C6B35322BB87C4003C19AD /* WireguardPrivateKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WireguardPrivateKey.swift; sourceTree = "<group>"; };
58C6B35D22BBBFE3003C19AD /* Data+HexCoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+HexCoding.swift"; sourceTree = "<group>"; };
@@ -468,11 +470,12 @@
children = (
581503A224D6F1EC00C9C50E /* ChainedError+Logger.swift */,
5815039624D6ECAE00C9C50E /* CustomFormatLogHandler.swift */,
- 5815039C24D6ECE600C9C50E /* TextFileOutputStream.swift */,
581503A524D6F4AE00C9C50E /* Logging.swift */,
5815039324D6EB7200C9C50E /* LogRotation.swift */,
- 58141EC824DAC0ED0013F79C /* TextFileStream.swift */,
585FE2F024E1365400439C50 /* LogStreamer.swift */,
+ 58C3B06824EAA25000C0348E /* StringStreamIterator.swift */,
+ 5815039C24D6ECE600C9C50E /* TextFileOutputStream.swift */,
+ 58141EC824DAC0ED0013F79C /* TextFileStream.swift */,
);
path = Logging;
sourceTree = "<group>";
@@ -1020,6 +1023,7 @@
58C6B35E22BBBFE3003C19AD /* Data+HexCoding.swift in Sources */,
5857F24324C8662600CF6F47 /* SelectLocationHeaderView.swift in Sources */,
58AEEF652344A36000C9BBD5 /* KeychainError.swift in Sources */,
+ 58C3B06924EAA25000C0348E /* StringStreamIterator.swift in Sources */,
580EE22824B3289300F9D8A1 /* AssociatedValue.swift in Sources */,
581503A624D6F4AE00C9C50E /* Logging.swift in Sources */,
58CCA01222424D11004F3011 /* SettingsViewController.swift in Sources */,
diff --git a/ios/MullvadVPN/Logging/LogStreamer.swift b/ios/MullvadVPN/Logging/LogStreamer.swift
index 5c5e34ea40..aba7fec4d8 100644
--- a/ios/MullvadVPN/Logging/LogStreamer.swift
+++ b/ios/MullvadVPN/Logging/LogStreamer.swift
@@ -6,6 +6,8 @@
// Copyright © 2020 Mullvad VPN AB. All rights reserved.
//
+#if DEBUG
+
import Foundation
private let kLogPollIntervalSeconds = 2
@@ -82,3 +84,5 @@ class LogStreamer<Codec> where Codec: UnicodeCodec {
}
}
}
+
+#endif
diff --git a/ios/MullvadVPN/Logging/StringStreamIterator.swift b/ios/MullvadVPN/Logging/StringStreamIterator.swift
new file mode 100644
index 0000000000..c13b921c33
--- /dev/null
+++ b/ios/MullvadVPN/Logging/StringStreamIterator.swift
@@ -0,0 +1,58 @@
+//
+// StringStreamIterator.swift
+// MullvadVPN
+//
+// Created by pronebird on 17/08/2020.
+// Copyright © 2020 Mullvad VPN AB. All rights reserved.
+//
+
+#if DEBUG
+
+import Foundation
+
+class StringStreamIterator<Codec>: IteratorProtocol where Codec: UnicodeCodec {
+ let separator: Character
+
+ private var string = ""
+ private var data = [Codec.CodeUnit]()
+ private var parser = Codec.ForwardParser()
+
+ init(separator: Character) {
+ self.separator = separator
+ }
+
+ func append<S>(bytes: S) where S: Sequence, S.Element == Codec.CodeUnit {
+ data.append(contentsOf: bytes)
+ }
+
+ func next() -> String? {
+ var dataIterator = data.makeIterator()
+ var bytesRead = 0
+
+ defer {
+ if bytesRead > 0 {
+ data.removeSubrange(..<bytesRead)
+ }
+ }
+
+ while case .valid(let encodedScalar) = parser.parseScalar(from: &dataIterator) {
+ let unicodeScalar = Codec.decode(encodedScalar)
+ let character = Character(unicodeScalar)
+
+ bytesRead += encodedScalar.count
+
+ if character == separator {
+ let returnString = string
+ string = ""
+
+ return returnString
+ } else {
+ string.append(character)
+ }
+ }
+
+ return nil
+ }
+}
+
+#endif
diff --git a/ios/MullvadVPN/Logging/TextFileStream.swift b/ios/MullvadVPN/Logging/TextFileStream.swift
index f37ae0b522..a6a260aedd 100644
--- a/ios/MullvadVPN/Logging/TextFileStream.swift
+++ b/ios/MullvadVPN/Logging/TextFileStream.swift
@@ -6,6 +6,8 @@
// Copyright © 2020 Mullvad VPN AB. All rights reserved.
//
+#if DEBUG
+
import Foundation
import Darwin
@@ -71,47 +73,4 @@ class TextFileStream<Codec> where Codec: UnicodeCodec {
}
-class StringStreamIterator<Codec>: IteratorProtocol where Codec: UnicodeCodec {
- let separator: Character
-
- private var string = ""
- private var data = [Codec.CodeUnit]()
- private var parser = Codec.ForwardParser()
-
- init(separator: Character) {
- self.separator = separator
- }
-
- func append<S>(bytes: S) where S: Sequence, S.Element == Codec.CodeUnit {
- data.append(contentsOf: bytes)
- }
-
- func next() -> String? {
- var dataIterator = data.makeIterator()
- var bytesRead = 0
-
- defer {
- if bytesRead > 0 {
- data.removeSubrange(..<bytesRead)
- }
- }
-
- while case .valid(let encodedScalar) = parser.parseScalar(from: &dataIterator) {
- let unicodeScalar = Codec.decode(encodedScalar)
- let character = Character(unicodeScalar)
-
- bytesRead += encodedScalar.count
-
- if character == separator {
- let returnString = string
- string = ""
-
- return returnString
- } else {
- string.append(character)
- }
- }
-
- return nil
- }
-}
+#endif