0001 // 0002 // Based on NSLinux (https://github.com/johnno1962/NSLinux) by johnno1962. 0003 // 0004 0005 /** 0006 Copyright (c) 2014, Damian KoĊakowski 0007 All rights reserved. 0008 0009 Redistribution and use in source and binary forms, with or without 0010 modification, are permitted provided that the following conditions are met: 0011 0012 * Redistributions of source code must retain the above copyright notice, this 0013 list of conditions and the following disclaimer. 0014 0015 * Redistributions in binary form must reproduce the above copyright notice, 0016 this list of conditions and the following disclaimer in the documentation 0017 and/or other materials provided with the distribution. 0018 0019 * Neither the name of the {organization} nor the names of its 0020 contributors may be used to endorse or promote products derived from 0021 this software without specific prior written permission. 0022 0023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 0026 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 0027 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 0028 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 0029 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 0030 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 0031 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0032 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0033 */ 0034 0035 import Foundation 0036 0037 extension String { 0038 0039 func split(separator: Character) -> [String] { 0040 return self.characters.split { $0 == separator }.map(String.init) 0041 } 0042 0043 func split
Application.swift:99 let workDirString = argument.split("=")[1]Application.swift:103 let portString = argument.split("=")[1]Request.swift:88 let cookieTokens = string.split(";")Request.swift:90 let cookieArray = cookie.split("=")Request.swift:93 let key = cookieArray[0].split(" ").joinWithSeparator("")Request.swift:110 var urlParts = string.split("?")Request.swift:126 for pair in string.split("&") {RequestData+Target.swift:91 for pair in string.split("&") {RequestFormExtension.swift:38 let contentTypeHeaderTokens = contentTypeHeader.split(";").map { $0.trim() }RequestFormExtension.swift:42 return String.fromUInt8(body).split("&").map { (param: String) -> (String, String) inRequestFormExtension.swift:43 let tokens = param.split("=")RequestFormExtension.swift:70 let headerValueParams = header.value.split(";").map { $0.trim() }RequestFormExtension.swift:86 let contentTypeHeaderTokens = contentTypeHeader.split(";").map { $0.trim() }RequestFormExtension.swift:92 let tokens = $0.split("=")RequestFormExtension.swift:122 let tokens = line.split(":")SocketParser.swift:23 let requestLineWords = string.split(" ")(maxSplit: Int = Int.max, separator: Character) -> [String] { 0044 return self.characters.split(maxSplit) { $0 == separator }.map(String.init) 0045 } 0046 0047 func replace
Request.swift:62 self.path = path.split(separator: "?")[0]Request.swift:127 let tokens = pair.split(1, separator: "=")RequestData+Target.swift:92 let tokens = pair.split(1, separator: "=")RequestFormExtension.swift:72 let parameterTokens = token.split(1, separator: "=")SocketParser.swift:91 let headerTokens = headerLine.split(1, separator: ":")(old: Character, new: Character) -> String { 0048 var buffer = [Character]() 0049 self.characters.forEach { buffer.append($0 == old ? new : $0) } 0050 return String(buffer) 0051 } 0052 0053 func unquote
RequestFormExtension.swift:45 return (name.replace("+", new: " ").removePercentEncoding(),RequestFormExtension.swift:46 value.replace("+", new: " ").removePercentEncoding())() -> String { 0054 var scalars = self.unicodeScalars; 0055 if scalars.first == "\"" && scalars.last == "\"" && scalars.count >= 2 { 0056 scalars.removeFirst(); 0057 scalars.removeLast(); 0058 return String(scalars) 0059 } 0060 return self 0061 } 0062 0063 func trim
RequestFormExtension.swift:58 return valueFor("content-disposition", parameterName: "name")?.unquote()RequestFormExtension.swift:62 return valueFor("content-disposition", parameterName: "filename")?.unquote()() -> String { 0064 var scalars = self.unicodeScalars 0065 while let _ = unicodeScalarToUInt32Whitespace(scalars.first) { scalars.removeFirst() } 0066 while let _ = unicodeScalarToUInt32Whitespace(scalars.last) { scalars.removeLast() } 0067 return String(scalars) 0068 } 0069 0070 static func fromUInt8
Request.swift:55 return "keep-alive" == value.trim()RequestFormExtension.swift:38 let contentTypeHeaderTokens = contentTypeHeader.split(";").map { $0.trim() }RequestFormExtension.swift:70 let headerValueParams = header.value.split(";").map { $0.trim() }RequestFormExtension.swift:86 let contentTypeHeaderTokens = contentTypeHeader.split(";").map { $0.trim() }RequestFormExtension.swift:124 headers[name.lowercaseString] = value.trim()SocketParser.swift:93 requestHeaders[name.lowercaseString] = value.trim()(array: [UInt8]) -> String { 0071 #if os(Linux) 0072 return String(data: NSData(bytes: array, length: array.count), encoding: NSUTF8StringEncoding) ?? "" 0073 #else 0074 if let s = String(data: NSData(bytes: array, length: array.count), encoding: NSUTF8StringEncoding) { 0075 return s 0076 } 0077 return "" 0078 #endif 0079 } 0080 0081 func removePercentEncoding
RequestFormExtension.swift:42 return String.fromUInt8(body).split("&").map { (param: String) -> (String, String) inStringExtensions.swift:93 output.appendContentsOf(String.fromUInt8(bytesBuffer))StringExtensions.swift:101 output.appendContentsOf(String.fromUInt8(bytesBuffer))StringExtensions.swift:108 output.appendContentsOf(String.fromUInt8(bytesBuffer))View.swift:35 let template = String.fromUInt8(self.bytes)() -> String { 0082 var scalars = self.unicodeScalars 0083 var output = "" 0084 var bytesBuffer = [UInt8]() 0085 while let scalar = scalars.popFirst() { 0086 if scalar == "%" { 0087 let first = scalars.popFirst() 0088 let secon = scalars.popFirst() 0089 if let first = unicodeScalarToUInt32Hex(first), secon = unicodeScalarToUInt32Hex(secon) { 0090 bytesBuffer.append(first*16+secon) 0091 } else { 0092 if !bytesBuffer.isEmpty { 0093 output.appendContentsOf(String.fromUInt8(bytesBuffer)) 0094 bytesBuffer.removeAll() 0095 } 0096 if let first = first { output.append(Character(first)) } 0097 if let secon = secon { output.append(Character(secon)) } 0098 } 0099 } else { 0100 if !bytesBuffer.isEmpty { 0101 output.appendContentsOf(String.fromUInt8(bytesBuffer)) 0102 bytesBuffer.removeAll() 0103 } 0104 output.append(Character(scalar)) 0105 } 0106 } 0107 if !bytesBuffer.isEmpty { 0108 output.appendContentsOf(String.fromUInt8(bytesBuffer)) 0109 bytesBuffer.removeAll() 0110 } 0111 return output 0112 } 0113 0114 private func unicodeScalarToUInt32Whitespace
Request.swift:130 data[name.removePercentEncoding()] = value.removePercentEncoding()Request.swift:130 data[name.removePercentEncoding()] = value.removePercentEncoding()RequestData+Target.swift:95 data[name.removePercentEncoding()] = value.removePercentEncoding()RequestData+Target.swift:95 data[name.removePercentEncoding()] = value.removePercentEncoding()RequestFormExtension.swift:45 return (name.replace("+", new: " ").removePercentEncoding(),RequestFormExtension.swift:46 value.replace("+", new: " ").removePercentEncoding())(x: UnicodeScalar?) -> UInt8? { 0115 if let x = x { 0116 if x.value >= 9 && x.value <= 13 { 0117 return UInt8(x.value) 0118 } 0119 if x.value == 32 { 0120 return UInt8(x.value) 0121 } 0122 } 0123 return nil 0124 } 0125 0126 private func unicodeScalarToUInt32Hex
StringExtensions.swift:65 while let _ = unicodeScalarToUInt32Whitespace(scalars.first) { scalars.removeFirst() }StringExtensions.swift:66 while let _ = unicodeScalarToUInt32Whitespace(scalars.last) { scalars.removeLast() }(x: UnicodeScalar?) -> UInt8? { 0127 if let x = x { 0128 if x.value >= 48 && x.value <= 57 { 0129 return UInt8(x.value) - 48 0130 } 0131 if x.value >= 97 && x.value <= 102 { 0132 return UInt8(x.value) - 87 0133 } 0134 if x.value >= 65 && x.value <= 70 { 0135 return UInt8(x.value) - 55 0136 } 0137 } 0138 return nil 0139 } 0140 } 0141
StringExtensions.swift:89 if let first = unicodeScalarToUInt32Hex(first), secon = unicodeScalarToUInt32Hex(secon) {StringExtensions.swift:89 if let first = unicodeScalarToUInt32Hex(first), secon = unicodeScalarToUInt32Hex(secon) {