motion-yapper 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (296) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.travis.yml +2 -0
  4. data/Gemfile +1 -0
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/lib/motion-yapper.rb +1 -0
  8. data/lib/yapper.rb +3 -5
  9. data/lib/yapper/config.rb +2 -0
  10. data/lib/yapper/db.rb +105 -40
  11. data/lib/yapper/document.rb +7 -4
  12. data/lib/yapper/document/callbacks.rb +0 -7
  13. data/lib/yapper/document/{persistance.rb → persistence.rb} +27 -21
  14. data/lib/yapper/document/relation.rb +29 -22
  15. data/lib/yapper/document/selection.rb +122 -54
  16. data/lib/yapper/extensions.rb +12 -24
  17. data/lib/yapper/settings.rb +43 -0
  18. data/lib/yapper/timestamps.rb +2 -0
  19. data/lib/yapper/version.rb +1 -1
  20. data/{yapper.gemspec → motion-yapper.gemspec} +0 -0
  21. data/spec/integration/{where_spec.rb → criteria_spec.rb} +78 -10
  22. data/spec/integration/db_spec.rb +70 -0
  23. data/spec/integration/defaults_spec.rb +37 -0
  24. data/spec/integration/extensions_spec.rb +14 -0
  25. data/spec/integration/{persistance_spec.rb → persistence_spec.rb} +0 -0
  26. data/spec/integration/relation_spec.rb +4 -4
  27. data/vendor/Podfile.lock +9 -11
  28. data/vendor/Pods/.build/libPods-CocoaLumberjack.a +0 -0
  29. data/vendor/Pods/.build/libPods-NSData+MD5Digest.a +0 -0
  30. data/vendor/Pods/.build/libPods-YapDatabase.a +0 -0
  31. data/vendor/Pods/.build/libPods.a +0 -0
  32. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +4 -4
  33. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +14 -14
  34. data/vendor/Pods/{CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.h → BuildHeaders/CocoaLumberjack/DDContextFilterLogFormatter.h} +6 -8
  35. data/vendor/Pods/BuildHeaders/CocoaLumberjack/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  36. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +67 -32
  37. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog+LOGV.h +99 -0
  38. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +98 -65
  39. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDMultiFormatter.h +30 -0
  40. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +39 -25
  41. data/vendor/Pods/BuildHeaders/YapDatabase/NSDictionary+YapDatabase.h +8 -0
  42. data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +1 -0
  43. data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +3 -0
  44. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +4 -4
  45. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +21 -19
  46. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +1 -1
  47. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +35 -31
  48. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +8 -35
  49. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +0 -2
  50. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +17 -17
  51. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTypes.h +32 -0
  52. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +8 -0
  53. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +43 -21
  54. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationship.h +35 -0
  55. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipConnection.h +29 -0
  56. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipEdge.h +163 -0
  57. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipEdgePrivate.h +79 -0
  58. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipNode.h +99 -0
  59. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipOptions.h +59 -0
  60. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipPrivate.h +125 -0
  61. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseRelationshipTransaction.h +384 -0
  62. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +49 -0
  63. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +10 -0
  64. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetupPrivate.h +18 -0
  65. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +131 -21
  66. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +48 -107
  67. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +2 -2
  68. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +1 -0
  69. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +17 -0
  70. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +10 -3
  71. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +18 -1
  72. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +75 -24
  73. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTypes.h +99 -0
  74. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +4 -4
  75. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +51 -50
  76. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +14 -14
  77. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +546 -546
  78. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +67 -32
  79. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1093 -907
  80. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog+LOGV.h +99 -0
  81. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +98 -65
  82. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +873 -748
  83. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +39 -25
  84. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +1284 -1243
  85. data/vendor/Pods/{BuildHeaders/CocoaLumberjack/ContextFilterLogFormatter.h → CocoaLumberjack/Lumberjack/Extensions/DDContextFilterLogFormatter.h} +6 -8
  86. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/{ContextFilterLogFormatter.m → DDContextFilterLogFormatter.m} +70 -70
  87. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  88. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDDispatchQueueLogFormatter.m +253 -0
  89. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDMultiFormatter.h +30 -0
  90. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DDMultiFormatter.m +127 -0
  91. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +1 -1
  92. data/vendor/Pods/CocoaLumberjack/README.markdown +52 -15
  93. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +4 -4
  94. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +14 -14
  95. data/vendor/Pods/Headers/CocoaLumberjack/{ContextFilterLogFormatter.h → DDContextFilterLogFormatter.h} +6 -8
  96. data/vendor/Pods/Headers/CocoaLumberjack/{DispatchQueueLogFormatter.h → DDDispatchQueueLogFormatter.h} +18 -6
  97. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +67 -32
  98. data/vendor/Pods/Headers/CocoaLumberjack/DDLog+LOGV.h +99 -0
  99. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +98 -65
  100. data/vendor/Pods/Headers/CocoaLumberjack/DDMultiFormatter.h +30 -0
  101. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +39 -25
  102. data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +3 -0
  103. data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +4 -4
  104. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +21 -19
  105. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +8 -35
  106. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +17 -17
  107. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTypes.h +32 -0
  108. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationship.h +35 -0
  109. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipConnection.h +29 -0
  110. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipEdge.h +163 -0
  111. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipNode.h +99 -0
  112. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipOptions.h +59 -0
  113. data/vendor/Pods/Headers/YapDatabase/YapDatabaseRelationshipTransaction.h +384 -0
  114. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +49 -0
  115. data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +131 -21
  116. data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +48 -107
  117. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +2 -2
  118. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +1 -0
  119. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +17 -0
  120. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +10 -3
  121. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +75 -24
  122. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTypes.h +99 -0
  123. data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +2 -0
  124. data/vendor/Pods/Headers/____Pods-environment.h +15 -15
  125. data/vendor/Pods/Manifest.lock +9 -11
  126. data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +1 -1
  127. data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +2 -0
  128. data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +1 -1
  129. data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +1 -1
  130. data/vendor/Pods/{Pods-Acknowledgements.markdown → Pods-acknowledgements.markdown} +0 -37
  131. data/vendor/Pods/{Pods-Acknowledgements.plist → Pods-acknowledgements.plist} +0 -45
  132. data/vendor/Pods/Pods-environment.h +15 -15
  133. data/vendor/Pods/Pods.xcconfig +3 -3
  134. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +2426 -3155
  135. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-CocoaLumberjack.xcscheme +59 -0
  136. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-NSData+MD5Digest.xcscheme +59 -0
  137. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods-YapDatabase.xcscheme +59 -0
  138. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/Pods.xcscheme +59 -0
  139. data/vendor/Pods/Pods.xcodeproj/xcuserdata/kareemk.xcuserdatad/xcschemes/xcschememanagement.plist +31 -0
  140. data/vendor/Pods/YapDatabase/README.md +3 -1
  141. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +0 -2
  142. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +8 -35
  143. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +25 -41
  144. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +17 -17
  145. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +403 -134
  146. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTypes.h +32 -0
  147. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +8 -0
  148. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +8 -8
  149. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +113 -62
  150. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +35 -31
  151. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +25 -0
  152. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +1 -1
  153. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +25 -1
  154. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/Internal/YapDatabaseRelationshipEdgePrivate.h +79 -0
  155. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/Internal/YapDatabaseRelationshipPrivate.h +125 -0
  156. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationship.h +35 -0
  157. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationship.m +129 -0
  158. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipConnection.h +29 -0
  159. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipConnection.m +802 -0
  160. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipEdge.h +163 -0
  161. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipEdge.m +408 -0
  162. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipNode.h +99 -0
  163. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipOptions.h +59 -0
  164. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipOptions.m +29 -0
  165. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipTransaction.h +384 -0
  166. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Relationships/YapDatabaseRelationshipTransaction.m +5254 -0
  167. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +10 -0
  168. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexSetupPrivate.h +18 -0
  169. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +49 -0
  170. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +12 -0
  171. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +9 -8
  172. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +62 -1
  173. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +148 -45
  174. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +18 -1
  175. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +2 -2
  176. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +15 -9
  177. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +17 -0
  178. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +211 -64
  179. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +48 -107
  180. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +10 -7
  181. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +1 -0
  182. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +13 -22
  183. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +10 -3
  184. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +75 -24
  185. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +725 -244
  186. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTypes.h +99 -0
  187. data/vendor/Pods/YapDatabase/YapDatabase/Internal/NSDictionary+YapDatabase.h +8 -0
  188. data/vendor/Pods/YapDatabase/YapDatabase/Internal/NSDictionary+YapDatabase.m +19 -0
  189. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +1 -0
  190. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +12 -0
  191. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +1 -1
  192. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +3 -3
  193. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +43 -21
  194. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +4 -0
  195. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +3 -0
  196. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +5 -0
  197. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +4 -4
  198. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +84 -93
  199. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +21 -19
  200. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +381 -209
  201. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +131 -21
  202. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +587 -267
  203. data/vendor/Pods/{Pods.bridgesupport → build-iPhoneSimulator/Pods.bridgesupport} +633 -2557
  204. data/vendor/Pods/build-iPhoneSimulator/libPods.a +0 -0
  205. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +2 -1
  206. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +2 -1
  207. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +4 -2
  208. metadata +80 -108
  209. data/Gemfile.lock +0 -63
  210. data/lib/yapper/attachment.rb +0 -48
  211. data/lib/yapper/document/attachment.rb +0 -26
  212. data/lib/yapper/sync.rb +0 -134
  213. data/lib/yapper/sync/data.rb +0 -12
  214. data/lib/yapper/sync/event.rb +0 -194
  215. data/lib/yapper/sync/queue.rb +0 -164
  216. data/spec/integration/all_spec.rb +0 -40
  217. data/spec/integration/sync_spec.rb +0 -42
  218. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +0 -641
  219. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +0 -1396
  220. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +0 -133
  221. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +0 -327
  222. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +0 -113
  223. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +0 -321
  224. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +0 -71
  225. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +0 -150
  226. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  227. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +0 -157
  228. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +0 -43
  229. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  230. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +0 -143
  231. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +0 -370
  232. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +0 -848
  233. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +0 -89
  234. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +0 -167
  235. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +0 -78
  236. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +0 -191
  237. data/vendor/Pods/AFNetworking/LICENSE +0 -19
  238. data/vendor/Pods/AFNetworking/README.md +0 -208
  239. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +0 -641
  240. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +0 -133
  241. data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +0 -113
  242. data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +0 -71
  243. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  244. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +0 -43
  245. data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  246. data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +0 -370
  247. data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +0 -89
  248. data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +0 -78
  249. data/vendor/Pods/BuildHeaders/Reachability/Reachability.h +0 -109
  250. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.m +0 -251
  251. data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +0 -641
  252. data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +0 -133
  253. data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +0 -113
  254. data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +0 -71
  255. data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +0 -75
  256. data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +0 -43
  257. data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +0 -68
  258. data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +0 -370
  259. data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +0 -89
  260. data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +0 -78
  261. data/vendor/Pods/Headers/Reachability/Reachability.h +0 -109
  262. data/vendor/Pods/Headers/YapDatabase/YapCache.h +0 -90
  263. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnectionState.h +0 -29
  264. data/vendor/Pods/Headers/YapDatabase/YapDatabaseDefaults.h +0 -37
  265. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionPrivate.h +0 -440
  266. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewPrivate.h +0 -19
  267. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchPrivate.h +0 -69
  268. data/vendor/Pods/Headers/YapDatabase/YapDatabaseLogging.h +0 -158
  269. data/vendor/Pods/Headers/YapDatabase/YapDatabaseManager.h +0 -17
  270. data/vendor/Pods/Headers/YapDatabase/YapDatabasePrivate.h +0 -424
  271. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +0 -73
  272. data/vendor/Pods/Headers/YapDatabase/YapDatabaseStatement.h +0 -13
  273. data/vendor/Pods/Headers/YapDatabase/YapDatabaseString.h +0 -121
  274. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChangePrivate.h +0 -94
  275. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappingsPrivate.h +0 -72
  276. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPage.h +0 -36
  277. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPageMetadata.h +0 -27
  278. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPrivate.h +0 -153
  279. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +0 -17
  280. data/vendor/Pods/Headers/YapDatabase/YapMemoryTable.h +0 -74
  281. data/vendor/Pods/Headers/YapDatabase/YapNull.h +0 -17
  282. data/vendor/Pods/Headers/YapDatabase/YapTouch.h +0 -15
  283. data/vendor/Pods/Headers/____Pods-AFNetworking-prefix.h +0 -17
  284. data/vendor/Pods/Headers/____Pods-Reachability-prefix.h +0 -5
  285. data/vendor/Pods/Pods-AFNetworking-Private.xcconfig +0 -5
  286. data/vendor/Pods/Pods-AFNetworking-dummy.m +0 -5
  287. data/vendor/Pods/Pods-AFNetworking-prefix.pch +0 -17
  288. data/vendor/Pods/Pods-AFNetworking.xcconfig +0 -1
  289. data/vendor/Pods/Pods-Reachability-Private.xcconfig +0 -5
  290. data/vendor/Pods/Pods-Reachability-dummy.m +0 -5
  291. data/vendor/Pods/Pods-Reachability-prefix.pch +0 -5
  292. data/vendor/Pods/Pods-Reachability.xcconfig +0 -1
  293. data/vendor/Pods/Reachability/LICENCE.txt +0 -24
  294. data/vendor/Pods/Reachability/README.md +0 -65
  295. data/vendor/Pods/Reachability/Reachability.h +0 -109
  296. data/vendor/Pods/Reachability/Reachability.m +0 -527
@@ -1,1396 +0,0 @@
1
- // AFHTTPClient.m
2
- //
3
- // Copyright (c) 2011 Gowalla (http://gowalla.com/)
4
- //
5
- // Permission is hereby granted, free of charge, to any person obtaining a copy
6
- // of this software and associated documentation files (the "Software"), to deal
7
- // in the Software without restriction, including without limitation the rights
8
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- // copies of the Software, and to permit persons to whom the Software is
10
- // furnished to do so, subject to the following conditions:
11
- //
12
- // The above copyright notice and this permission notice shall be included in
13
- // all copies or substantial portions of the Software.
14
- //
15
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- // THE SOFTWARE.
22
-
23
- #import <Foundation/Foundation.h>
24
-
25
- #import "AFHTTPClient.h"
26
- #import "AFHTTPRequestOperation.h"
27
-
28
- #import <Availability.h>
29
-
30
- #ifdef _SYSTEMCONFIGURATION_H
31
- #import <netinet/in.h>
32
- #import <netinet6/in6.h>
33
- #import <arpa/inet.h>
34
- #import <ifaddrs.h>
35
- #import <netdb.h>
36
- #endif
37
-
38
- #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
39
- #import <UIKit/UIKit.h>
40
- #endif
41
-
42
- #ifdef _SYSTEMCONFIGURATION_H
43
- NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
44
- NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";
45
-
46
- typedef SCNetworkReachabilityRef AFNetworkReachabilityRef;
47
- typedef void (^AFNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status);
48
- #else
49
- typedef id AFNetworkReachabilityRef;
50
- #endif
51
-
52
- typedef void (^AFCompletionBlock)(void);
53
-
54
- static NSString * AFBase64EncodedStringFromString(NSString *string) {
55
- NSData *data = [NSData dataWithBytes:[string UTF8String] length:[string lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
56
- NSUInteger length = [data length];
57
- NSMutableData *mutableData = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
58
-
59
- uint8_t *input = (uint8_t *)[data bytes];
60
- uint8_t *output = (uint8_t *)[mutableData mutableBytes];
61
-
62
- for (NSUInteger i = 0; i < length; i += 3) {
63
- NSUInteger value = 0;
64
- for (NSUInteger j = i; j < (i + 3); j++) {
65
- value <<= 8;
66
- if (j < length) {
67
- value |= (0xFF & input[j]);
68
- }
69
- }
70
-
71
- static uint8_t const kAFBase64EncodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
72
-
73
- NSUInteger idx = (i / 3) * 4;
74
- output[idx + 0] = kAFBase64EncodingTable[(value >> 18) & 0x3F];
75
- output[idx + 1] = kAFBase64EncodingTable[(value >> 12) & 0x3F];
76
- output[idx + 2] = (i + 1) < length ? kAFBase64EncodingTable[(value >> 6) & 0x3F] : '=';
77
- output[idx + 3] = (i + 2) < length ? kAFBase64EncodingTable[(value >> 0) & 0x3F] : '=';
78
- }
79
-
80
- return [[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding];
81
- }
82
-
83
- static NSString * const kAFCharactersToBeEscapedInQueryString = @":/?&=;+!@#$()',*";
84
-
85
- static NSString * AFPercentEscapedQueryStringKeyFromStringWithEncoding(NSString *string, NSStringEncoding encoding) {
86
- static NSString * const kAFCharactersToLeaveUnescapedInQueryStringPairKey = @"[].";
87
-
88
- return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, (__bridge CFStringRef)kAFCharactersToLeaveUnescapedInQueryStringPairKey, (__bridge CFStringRef)kAFCharactersToBeEscapedInQueryString, CFStringConvertNSStringEncodingToEncoding(encoding));
89
- }
90
-
91
- static NSString * AFPercentEscapedQueryStringValueFromStringWithEncoding(NSString *string, NSStringEncoding encoding) {
92
- return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, (__bridge CFStringRef)kAFCharactersToBeEscapedInQueryString, CFStringConvertNSStringEncodingToEncoding(encoding));
93
- }
94
-
95
- #pragma mark -
96
-
97
- @interface AFQueryStringPair : NSObject
98
- @property (readwrite, nonatomic, strong) id field;
99
- @property (readwrite, nonatomic, strong) id value;
100
-
101
- - (id)initWithField:(id)field value:(id)value;
102
-
103
- - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding;
104
- @end
105
-
106
- @implementation AFQueryStringPair
107
- @synthesize field = _field;
108
- @synthesize value = _value;
109
-
110
- - (id)initWithField:(id)field value:(id)value {
111
- self = [super init];
112
- if (!self) {
113
- return nil;
114
- }
115
-
116
- self.field = field;
117
- self.value = value;
118
-
119
- return self;
120
- }
121
-
122
- - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding {
123
- if (!self.value || [self.value isEqual:[NSNull null]]) {
124
- return AFPercentEscapedQueryStringKeyFromStringWithEncoding([self.field description], stringEncoding);
125
- } else {
126
- return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedQueryStringKeyFromStringWithEncoding([self.field description], stringEncoding), AFPercentEscapedQueryStringValueFromStringWithEncoding([self.value description], stringEncoding)];
127
- }
128
- }
129
-
130
- @end
131
-
132
- #pragma mark -
133
-
134
- extern NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary);
135
- extern NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value);
136
-
137
- NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *parameters, NSStringEncoding stringEncoding) {
138
- NSMutableArray *mutablePairs = [NSMutableArray array];
139
- for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) {
140
- [mutablePairs addObject:[pair URLEncodedStringValueWithEncoding:stringEncoding]];
141
- }
142
-
143
- return [mutablePairs componentsJoinedByString:@"&"];
144
- }
145
-
146
- NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary) {
147
- return AFQueryStringPairsFromKeyAndValue(nil, dictionary);
148
- }
149
-
150
- NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) {
151
- NSMutableArray *mutableQueryStringComponents = [NSMutableArray array];
152
-
153
- if ([value isKindOfClass:[NSDictionary class]]) {
154
- NSDictionary *dictionary = value;
155
- // Sort dictionary keys to ensure consistent ordering in query string, which is important when deserializing potentially ambiguous sequences, such as an array of dictionaries
156
- NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES selector:@selector(caseInsensitiveCompare:)];
157
- for (id nestedKey in [dictionary.allKeys sortedArrayUsingDescriptors:@[ sortDescriptor ]]) {
158
- id nestedValue = [dictionary objectForKey:nestedKey];
159
- if (nestedValue) {
160
- [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
161
- }
162
- }
163
- } else if ([value isKindOfClass:[NSArray class]]) {
164
- NSArray *array = value;
165
- for (id nestedValue in array) {
166
- [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)];
167
- }
168
- } else if ([value isKindOfClass:[NSSet class]]) {
169
- NSSet *set = value;
170
- for (id obj in set) {
171
- [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue(key, obj)];
172
- }
173
- } else {
174
- [mutableQueryStringComponents addObject:[[AFQueryStringPair alloc] initWithField:key value:value]];
175
- }
176
-
177
- return mutableQueryStringComponents;
178
- }
179
-
180
- @interface AFStreamingMultipartFormData : NSObject <AFMultipartFormData>
181
- - (id)initWithURLRequest:(NSMutableURLRequest *)urlRequest
182
- stringEncoding:(NSStringEncoding)encoding;
183
-
184
- - (NSMutableURLRequest *)requestByFinalizingMultipartFormData;
185
- @end
186
-
187
- #pragma mark -
188
-
189
- @interface AFHTTPClient ()
190
- @property (readwrite, nonatomic, strong) NSURL *baseURL;
191
- @property (readwrite, nonatomic, strong) NSMutableArray *registeredHTTPOperationClassNames;
192
- @property (readwrite, nonatomic, strong) NSMutableDictionary *defaultHeaders;
193
- @property (readwrite, nonatomic, strong) NSURLCredential *defaultCredential;
194
- @property (readwrite, nonatomic, strong) NSOperationQueue *operationQueue;
195
- #ifdef _SYSTEMCONFIGURATION_H
196
- @property (readwrite, nonatomic, assign) AFNetworkReachabilityRef networkReachability;
197
- @property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
198
- @property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
199
- #endif
200
-
201
- #ifdef _SYSTEMCONFIGURATION_H
202
- - (void)startMonitoringNetworkReachability;
203
- - (void)stopMonitoringNetworkReachability;
204
- #endif
205
- @end
206
-
207
- @implementation AFHTTPClient
208
- @synthesize baseURL = _baseURL;
209
- @synthesize stringEncoding = _stringEncoding;
210
- @synthesize parameterEncoding = _parameterEncoding;
211
- @synthesize registeredHTTPOperationClassNames = _registeredHTTPOperationClassNames;
212
- @synthesize defaultHeaders = _defaultHeaders;
213
- @synthesize defaultCredential = _defaultCredential;
214
- @synthesize operationQueue = _operationQueue;
215
- #ifdef _SYSTEMCONFIGURATION_H
216
- @synthesize networkReachability = _networkReachability;
217
- @synthesize networkReachabilityStatus = _networkReachabilityStatus;
218
- @synthesize networkReachabilityStatusBlock = _networkReachabilityStatusBlock;
219
- #endif
220
- @synthesize defaultSSLPinningMode = _defaultSSLPinningMode;
221
- @synthesize allowsInvalidSSLCertificate = _allowsInvalidSSLCertificate;
222
-
223
- + (instancetype)clientWithBaseURL:(NSURL *)url {
224
- return [[self alloc] initWithBaseURL:url];
225
- }
226
-
227
- - (id)init {
228
- @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"%@ Failed to call designated initializer. Invoke `initWithBaseURL:` instead.", NSStringFromClass([self class])] userInfo:nil];
229
- }
230
-
231
- - (id)initWithBaseURL:(NSURL *)url {
232
- NSParameterAssert(url);
233
-
234
- self = [super init];
235
- if (!self) {
236
- return nil;
237
- }
238
-
239
- // Ensure terminal slash for baseURL path, so that NSURL +URLWithString:relativeToURL: works as expected
240
- if ([[url path] length] > 0 && ![[url absoluteString] hasSuffix:@"/"]) {
241
- url = [url URLByAppendingPathComponent:@""];
242
- }
243
-
244
- self.baseURL = url;
245
-
246
- self.stringEncoding = NSUTF8StringEncoding;
247
- self.parameterEncoding = AFFormURLParameterEncoding;
248
-
249
- self.registeredHTTPOperationClassNames = [NSMutableArray array];
250
-
251
- self.defaultHeaders = [NSMutableDictionary dictionary];
252
-
253
- // Accept-Language HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
254
- NSMutableArray *acceptLanguagesComponents = [NSMutableArray array];
255
- [[NSLocale preferredLanguages] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
256
- float q = 1.0f - (idx * 0.1f);
257
- [acceptLanguagesComponents addObject:[NSString stringWithFormat:@"%@;q=%0.1g", obj, q]];
258
- *stop = q <= 0.5f;
259
- }];
260
- [self setDefaultHeader:@"Accept-Language" value:[acceptLanguagesComponents componentsJoinedByString:@", "]];
261
-
262
- NSString *userAgent = nil;
263
- #pragma clang diagnostic push
264
- #pragma clang diagnostic ignored "-Wgnu"
265
- #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
266
- // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
267
- userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], (__bridge id)CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)];
268
- #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
269
- userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]];
270
- #endif
271
- #pragma clang diagnostic pop
272
- if (userAgent) {
273
- if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) {
274
- NSMutableString *mutableUserAgent = [userAgent mutableCopy];
275
- CFStringTransform((__bridge CFMutableStringRef)(mutableUserAgent), NULL, kCFStringTransformToLatin, false);
276
- userAgent = mutableUserAgent;
277
- }
278
- [self setDefaultHeader:@"User-Agent" value:userAgent];
279
- }
280
-
281
- #ifdef _SYSTEMCONFIGURATION_H
282
- self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
283
- [self startMonitoringNetworkReachability];
284
- #endif
285
-
286
- self.operationQueue = [[NSOperationQueue alloc] init];
287
- [self.operationQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];
288
-
289
- // #ifdef included for backwards-compatibility
290
- #ifdef _AFNETWORKING_ALLOW_INVALID_SSL_CERTIFICATES_
291
- self.allowsInvalidSSLCertificate = YES;
292
- #endif
293
-
294
- return self;
295
- }
296
-
297
- - (void)dealloc {
298
- #ifdef _SYSTEMCONFIGURATION_H
299
- [self stopMonitoringNetworkReachability];
300
- #endif
301
- }
302
-
303
- - (NSString *)description {
304
- return [NSString stringWithFormat:@"<%@: %p, baseURL: %@, defaultHeaders: %@, registeredOperationClasses: %@, operationQueue: %@>", NSStringFromClass([self class]), self, [self.baseURL absoluteString], self.defaultHeaders, self.registeredHTTPOperationClassNames, self.operationQueue];
305
- }
306
-
307
- #pragma mark -
308
-
309
- #ifdef _SYSTEMCONFIGURATION_H
310
- static BOOL AFURLHostIsIPAddress(NSURL *url) {
311
- struct sockaddr_in sa_in;
312
- struct sockaddr_in6 sa_in6;
313
-
314
- return [url host] && (inet_pton(AF_INET, [[url host] UTF8String], &sa_in) == 1 || inet_pton(AF_INET6, [[url host] UTF8String], &sa_in6) == 1);
315
- }
316
-
317
- static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetworkReachabilityFlags flags) {
318
- BOOL isReachable = ((flags & kSCNetworkReachabilityFlagsReachable) != 0);
319
- BOOL needsConnection = ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0);
320
- BOOL canConnectionAutomatically = (((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || ((flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0));
321
- BOOL canConnectWithoutUserInteraction = (canConnectionAutomatically && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0);
322
- BOOL isNetworkReachable = (isReachable && (!needsConnection || canConnectWithoutUserInteraction));
323
-
324
- AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
325
- if (isNetworkReachable == NO) {
326
- status = AFNetworkReachabilityStatusNotReachable;
327
- }
328
- #if TARGET_OS_IPHONE
329
- else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
330
- status = AFNetworkReachabilityStatusReachableViaWWAN;
331
- }
332
- #endif
333
- else {
334
- status = AFNetworkReachabilityStatusReachableViaWiFi;
335
- }
336
-
337
- return status;
338
- }
339
-
340
- static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) {
341
- AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
342
- AFNetworkReachabilityStatusBlock block = (__bridge AFNetworkReachabilityStatusBlock)info;
343
- if (block) {
344
- block(status);
345
- }
346
-
347
- dispatch_async(dispatch_get_main_queue(), ^{
348
- NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
349
- [notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:status] forKey:AFNetworkingReachabilityNotificationStatusItem]];
350
- });
351
- }
352
-
353
- static const void * AFNetworkReachabilityRetainCallback(const void *info) {
354
- return Block_copy(info);
355
- }
356
-
357
- static void AFNetworkReachabilityReleaseCallback(const void *info) {
358
- if (info) {
359
- Block_release(info);
360
- }
361
- }
362
-
363
- - (void)startMonitoringNetworkReachability {
364
- [self stopMonitoringNetworkReachability];
365
-
366
- if (!self.baseURL) {
367
- return;
368
- }
369
-
370
- self.networkReachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [[self.baseURL host] UTF8String]);
371
-
372
- if (!self.networkReachability) {
373
- return;
374
- }
375
-
376
- __weak __typeof(&*self)weakSelf = self;
377
- AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) {
378
- __strong __typeof(&*weakSelf)strongSelf = weakSelf;
379
- if (!strongSelf) {
380
- return;
381
- }
382
-
383
- strongSelf.networkReachabilityStatus = status;
384
- if (strongSelf.networkReachabilityStatusBlock) {
385
- strongSelf.networkReachabilityStatusBlock(status);
386
- }
387
- };
388
-
389
- SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
390
- SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
391
-
392
- /* Network reachability monitoring does not establish a baseline for IP addresses as it does for hostnames, so if the base URL host is an IP address, the initial reachability callback is manually triggered.
393
- */
394
- if (AFURLHostIsIPAddress(self.baseURL)) {
395
- SCNetworkReachabilityFlags flags;
396
- SCNetworkReachabilityGetFlags(self.networkReachability, &flags);
397
- dispatch_async(dispatch_get_main_queue(), ^{
398
- AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
399
- callback(status);
400
- });
401
- }
402
-
403
- SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
404
- }
405
-
406
- - (void)stopMonitoringNetworkReachability {
407
- if (self.networkReachability) {
408
- SCNetworkReachabilityUnscheduleFromRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
409
-
410
- CFRelease(_networkReachability);
411
- _networkReachability = NULL;
412
- }
413
- }
414
-
415
- - (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block {
416
- self.networkReachabilityStatusBlock = block;
417
- }
418
- #endif
419
-
420
- #pragma mark -
421
-
422
- - (BOOL)registerHTTPOperationClass:(Class)operationClass {
423
- if (![operationClass isSubclassOfClass:[AFHTTPRequestOperation class]]) {
424
- return NO;
425
- }
426
-
427
- NSString *className = NSStringFromClass(operationClass);
428
- [self.registeredHTTPOperationClassNames removeObject:className];
429
- [self.registeredHTTPOperationClassNames insertObject:className atIndex:0];
430
-
431
- return YES;
432
- }
433
-
434
- - (void)unregisterHTTPOperationClass:(Class)operationClass {
435
- NSString *className = NSStringFromClass(operationClass);
436
- [self.registeredHTTPOperationClassNames removeObject:className];
437
- }
438
-
439
- #pragma mark -
440
-
441
- - (NSString *)defaultValueForHeader:(NSString *)header {
442
- return [self.defaultHeaders valueForKey:header];
443
- }
444
-
445
- - (void)setDefaultHeader:(NSString *)header value:(NSString *)value {
446
- [self.defaultHeaders setValue:value forKey:header];
447
- }
448
-
449
- - (void)setAuthorizationHeaderWithUsername:(NSString *)username password:(NSString *)password {
450
- NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", username, password];
451
- [self setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"Basic %@", AFBase64EncodedStringFromString(basicAuthCredentials)]];
452
- }
453
-
454
- - (void)setAuthorizationHeaderWithToken:(NSString *)token {
455
- [self setDefaultHeader:@"Authorization" value:[NSString stringWithFormat:@"Token token=\"%@\"", token]];
456
- }
457
-
458
- - (void)clearAuthorizationHeader {
459
- [self.defaultHeaders removeObjectForKey:@"Authorization"];
460
- }
461
-
462
- #pragma mark -
463
-
464
- - (NSMutableURLRequest *)requestWithMethod:(NSString *)method
465
- path:(NSString *)path
466
- parameters:(NSDictionary *)parameters
467
- {
468
- NSParameterAssert(method);
469
-
470
- if (!path) {
471
- path = @"";
472
- }
473
-
474
- NSURL *url = [NSURL URLWithString:path relativeToURL:self.baseURL];
475
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
476
- [request setHTTPMethod:method];
477
- [request setAllHTTPHeaderFields:self.defaultHeaders];
478
-
479
- if (parameters) {
480
- if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"] || [method isEqualToString:@"DELETE"]) {
481
- url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:[path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding)]];
482
- [request setURL:url];
483
- } else {
484
- NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding));
485
- NSError *error = nil;
486
-
487
- switch (self.parameterEncoding) {
488
- case AFFormURLParameterEncoding:;
489
- [request setValue:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset] forHTTPHeaderField:@"Content-Type"];
490
- [request setHTTPBody:[AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding) dataUsingEncoding:self.stringEncoding]];
491
- break;
492
- case AFJSONParameterEncoding:;
493
- [request setValue:[NSString stringWithFormat:@"application/json; charset=%@", charset] forHTTPHeaderField:@"Content-Type"];
494
- [request setHTTPBody:[NSJSONSerialization dataWithJSONObject:parameters options:(NSJSONWritingOptions)0 error:&error]];
495
- break;
496
- case AFPropertyListParameterEncoding:;
497
- [request setValue:[NSString stringWithFormat:@"application/x-plist; charset=%@", charset] forHTTPHeaderField:@"Content-Type"];
498
- [request setHTTPBody:[NSPropertyListSerialization dataWithPropertyList:parameters format:NSPropertyListXMLFormat_v1_0 options:0 error:&error]];
499
- break;
500
- }
501
-
502
- if (error) {
503
- NSLog(@"%@ %@: %@", [self class], NSStringFromSelector(_cmd), error);
504
- }
505
- }
506
- }
507
-
508
- return request;
509
- }
510
-
511
- - (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
512
- path:(NSString *)path
513
- parameters:(NSDictionary *)parameters
514
- constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block
515
- {
516
- NSParameterAssert(method);
517
- NSParameterAssert(![method isEqualToString:@"GET"] && ![method isEqualToString:@"HEAD"]);
518
-
519
- NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil];
520
-
521
- __block AFStreamingMultipartFormData *formData = [[AFStreamingMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding];
522
-
523
- if (parameters) {
524
- for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) {
525
- NSData *data = nil;
526
- if ([pair.value isKindOfClass:[NSData class]]) {
527
- data = pair.value;
528
- } else if ([pair.value isEqual:[NSNull null]]) {
529
- data = [NSData data];
530
- } else {
531
- data = [[pair.value description] dataUsingEncoding:self.stringEncoding];
532
- }
533
-
534
- if (data) {
535
- [formData appendPartWithFormData:data name:[pair.field description]];
536
- }
537
- }
538
- }
539
-
540
- if (block) {
541
- block(formData);
542
- }
543
-
544
- return [formData requestByFinalizingMultipartFormData];
545
- }
546
-
547
- - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest
548
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
549
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
550
- {
551
- AFHTTPRequestOperation *operation = nil;
552
-
553
- for (NSString *className in self.registeredHTTPOperationClassNames) {
554
- Class operationClass = NSClassFromString(className);
555
- if (operationClass && [operationClass canProcessRequest:urlRequest]) {
556
- operation = [(AFHTTPRequestOperation *)[operationClass alloc] initWithRequest:urlRequest];
557
- break;
558
- }
559
- }
560
-
561
- if (!operation) {
562
- operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
563
- }
564
-
565
- [operation setCompletionBlockWithSuccess:success failure:failure];
566
-
567
- operation.credential = self.defaultCredential;
568
- operation.SSLPinningMode = self.defaultSSLPinningMode;
569
- operation.allowsInvalidSSLCertificate = self.allowsInvalidSSLCertificate;
570
-
571
- return operation;
572
- }
573
-
574
- #pragma mark -
575
-
576
- - (void)enqueueHTTPRequestOperation:(AFHTTPRequestOperation *)operation {
577
- [self.operationQueue addOperation:operation];
578
- }
579
-
580
- - (void)cancelAllHTTPOperationsWithMethod:(NSString *)method
581
- path:(NSString *)path
582
- {
583
- #pragma clang diagnostic push
584
- #pragma clang diagnostic ignored "-Wgnu"
585
- NSString *pathToBeMatched = [[[self requestWithMethod:(method ?: @"GET") path:path parameters:nil] URL] path];
586
- #pragma clang diagnostic pop
587
-
588
- for (NSOperation *operation in [self.operationQueue operations]) {
589
- if (![operation isKindOfClass:[AFHTTPRequestOperation class]]) {
590
- continue;
591
- }
592
-
593
- BOOL hasMatchingMethod = !method || [method isEqualToString:[[(AFHTTPRequestOperation *)operation request] HTTPMethod]];
594
- BOOL hasMatchingPath = [[[[(AFHTTPRequestOperation *)operation request] URL] path] isEqual:pathToBeMatched];
595
-
596
- if (hasMatchingMethod && hasMatchingPath) {
597
- [operation cancel];
598
- }
599
- }
600
- }
601
-
602
- - (void)enqueueBatchOfHTTPRequestOperationsWithRequests:(NSArray *)urlRequests
603
- progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock
604
- completionBlock:(void (^)(NSArray *operations))completionBlock
605
- {
606
- NSMutableArray *mutableOperations = [NSMutableArray array];
607
- for (NSURLRequest *request in urlRequests) {
608
- AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:nil failure:nil];
609
- [mutableOperations addObject:operation];
610
- }
611
-
612
- [self enqueueBatchOfHTTPRequestOperations:mutableOperations progressBlock:progressBlock completionBlock:completionBlock];
613
- }
614
-
615
- - (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations
616
- progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock
617
- completionBlock:(void (^)(NSArray *operations))completionBlock
618
- {
619
- __block dispatch_group_t dispatchGroup = dispatch_group_create();
620
- NSBlockOperation *batchedOperation = [NSBlockOperation blockOperationWithBlock:^{
621
- dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^{
622
- if (completionBlock) {
623
- completionBlock(operations);
624
- }
625
- });
626
- #if !OS_OBJECT_USE_OBJC
627
- dispatch_release(dispatchGroup);
628
- #endif
629
- }];
630
-
631
- for (AFHTTPRequestOperation *operation in operations) {
632
- AFCompletionBlock originalCompletionBlock = [operation.completionBlock copy];
633
- __weak __typeof(&*operation)weakOperation = operation;
634
- operation.completionBlock = ^{
635
- __strong __typeof(&*weakOperation)strongOperation = weakOperation;
636
- #pragma clang diagnostic push
637
- #pragma clang diagnostic ignored "-Wgnu"
638
- dispatch_queue_t queue = strongOperation.successCallbackQueue ?: dispatch_get_main_queue();
639
- #pragma clang diagnostic pop
640
- dispatch_group_async(dispatchGroup, queue, ^{
641
- if (originalCompletionBlock) {
642
- originalCompletionBlock();
643
- }
644
-
645
- NSUInteger numberOfFinishedOperations = [[operations indexesOfObjectsPassingTest:^BOOL(id op, NSUInteger __unused idx, BOOL __unused *stop) {
646
- return [op isFinished];
647
- }] count];
648
-
649
- if (progressBlock) {
650
- progressBlock(numberOfFinishedOperations, [operations count]);
651
- }
652
-
653
- dispatch_group_leave(dispatchGroup);
654
- });
655
- };
656
-
657
- dispatch_group_enter(dispatchGroup);
658
- [batchedOperation addDependency:operation];
659
- }
660
- [self.operationQueue addOperations:operations waitUntilFinished:NO];
661
- [self.operationQueue addOperation:batchedOperation];
662
- }
663
-
664
- #pragma mark -
665
-
666
- - (void)getPath:(NSString *)path
667
- parameters:(NSDictionary *)parameters
668
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
669
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
670
- {
671
- NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:parameters];
672
- AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
673
- [self enqueueHTTPRequestOperation:operation];
674
- }
675
-
676
- - (void)postPath:(NSString *)path
677
- parameters:(NSDictionary *)parameters
678
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
679
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
680
- {
681
- NSURLRequest *request = [self requestWithMethod:@"POST" path:path parameters:parameters];
682
- AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
683
- [self enqueueHTTPRequestOperation:operation];
684
- }
685
-
686
- - (void)putPath:(NSString *)path
687
- parameters:(NSDictionary *)parameters
688
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
689
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
690
- {
691
- NSURLRequest *request = [self requestWithMethod:@"PUT" path:path parameters:parameters];
692
- AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
693
- [self enqueueHTTPRequestOperation:operation];
694
- }
695
-
696
- - (void)deletePath:(NSString *)path
697
- parameters:(NSDictionary *)parameters
698
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
699
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
700
- {
701
- NSURLRequest *request = [self requestWithMethod:@"DELETE" path:path parameters:parameters];
702
- AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
703
- [self enqueueHTTPRequestOperation:operation];
704
- }
705
-
706
- - (void)patchPath:(NSString *)path
707
- parameters:(NSDictionary *)parameters
708
- success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
709
- failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
710
- {
711
- NSURLRequest *request = [self requestWithMethod:@"PATCH" path:path parameters:parameters];
712
- AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
713
- [self enqueueHTTPRequestOperation:operation];
714
- }
715
-
716
- #pragma mark - NSCoding
717
-
718
- - (id)initWithCoder:(NSCoder *)aDecoder {
719
- NSURL *baseURL = [aDecoder decodeObjectForKey:@"baseURL"];
720
-
721
- self = [self initWithBaseURL:baseURL];
722
- if (!self) {
723
- return nil;
724
- }
725
-
726
- self.stringEncoding = [aDecoder decodeIntegerForKey:@"stringEncoding"];
727
- self.parameterEncoding = (AFHTTPClientParameterEncoding) [aDecoder decodeIntegerForKey:@"parameterEncoding"];
728
- self.registeredHTTPOperationClassNames = [aDecoder decodeObjectForKey:@"registeredHTTPOperationClassNames"];
729
- self.defaultHeaders = [aDecoder decodeObjectForKey:@"defaultHeaders"];
730
-
731
- return self;
732
- }
733
-
734
- - (void)encodeWithCoder:(NSCoder *)aCoder {
735
- [aCoder encodeObject:self.baseURL forKey:@"baseURL"];
736
- [aCoder encodeInteger:(NSInteger)self.stringEncoding forKey:@"stringEncoding"];
737
- [aCoder encodeInteger:self.parameterEncoding forKey:@"parameterEncoding"];
738
- [aCoder encodeObject:self.registeredHTTPOperationClassNames forKey:@"registeredHTTPOperationClassNames"];
739
- [aCoder encodeObject:self.defaultHeaders forKey:@"defaultHeaders"];
740
- }
741
-
742
- #pragma mark - NSCopying
743
-
744
- - (id)copyWithZone:(NSZone *)zone {
745
- AFHTTPClient *HTTPClient = [[[self class] allocWithZone:zone] initWithBaseURL:self.baseURL];
746
-
747
- HTTPClient.stringEncoding = self.stringEncoding;
748
- HTTPClient.parameterEncoding = self.parameterEncoding;
749
- HTTPClient.registeredHTTPOperationClassNames = [self.registeredHTTPOperationClassNames mutableCopyWithZone:zone];
750
- HTTPClient.defaultHeaders = [self.defaultHeaders mutableCopyWithZone:zone];
751
- #ifdef _SYSTEMCONFIGURATION_H
752
- HTTPClient.networkReachabilityStatusBlock = self.networkReachabilityStatusBlock;
753
- #endif
754
- return HTTPClient;
755
- }
756
-
757
- @end
758
-
759
- #pragma mark -
760
-
761
- static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY";
762
-
763
- static NSString * const kAFMultipartFormCRLF = @"\r\n";
764
-
765
- static NSInteger const kAFStreamToStreamBufferSize = 1024 * 1024; //1 meg default
766
-
767
- static inline NSString * AFMultipartFormInitialBoundary() {
768
- return [NSString stringWithFormat:@"--%@%@", kAFMultipartFormBoundary, kAFMultipartFormCRLF];
769
- }
770
-
771
- static inline NSString * AFMultipartFormEncapsulationBoundary() {
772
- return [NSString stringWithFormat:@"%@--%@%@", kAFMultipartFormCRLF, kAFMultipartFormBoundary, kAFMultipartFormCRLF];
773
- }
774
-
775
- static inline NSString * AFMultipartFormFinalBoundary() {
776
- return [NSString stringWithFormat:@"%@--%@--%@", kAFMultipartFormCRLF, kAFMultipartFormBoundary, kAFMultipartFormCRLF];
777
- }
778
-
779
- static inline NSString * AFContentTypeForPathExtension(NSString *extension) {
780
- #ifdef __UTTYPE__
781
- NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL);
782
- NSString *contentType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType);
783
- if (!contentType) {
784
- return @"application/octet-stream";
785
- } else {
786
- return contentType;
787
- }
788
- #else
789
- return @"application/octet-stream";
790
- #endif
791
- }
792
-
793
- NSUInteger const kAFUploadStream3GSuggestedPacketSize = 1024 * 16;
794
- NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
795
-
796
- @interface AFHTTPBodyPart : NSObject
797
- @property (nonatomic, assign) NSStringEncoding stringEncoding;
798
- @property (nonatomic, strong) NSDictionary *headers;
799
- @property (nonatomic, strong) id body;
800
- @property (nonatomic, assign) unsigned long long bodyContentLength;
801
- @property (nonatomic, strong) NSInputStream *inputStream;
802
-
803
- @property (nonatomic, assign) BOOL hasInitialBoundary;
804
- @property (nonatomic, assign) BOOL hasFinalBoundary;
805
-
806
- @property (nonatomic, readonly, getter = hasBytesAvailable) BOOL bytesAvailable;
807
- @property (nonatomic, readonly) unsigned long long contentLength;
808
-
809
- - (NSInteger)read:(uint8_t *)buffer
810
- maxLength:(NSUInteger)length;
811
- @end
812
-
813
- @interface AFMultipartBodyStream : NSInputStream <NSStreamDelegate>
814
- @property (nonatomic, assign) NSUInteger numberOfBytesInPacket;
815
- @property (nonatomic, assign) NSTimeInterval delay;
816
- @property (nonatomic, strong) NSInputStream *inputStream;
817
- @property (nonatomic, readonly) unsigned long long contentLength;
818
- @property (nonatomic, readonly, getter = isEmpty) BOOL empty;
819
-
820
- - (id)initWithStringEncoding:(NSStringEncoding)encoding;
821
- - (void)setInitialAndFinalBoundaries;
822
- - (void)appendHTTPBodyPart:(AFHTTPBodyPart *)bodyPart;
823
- @end
824
-
825
- #pragma mark -
826
-
827
- @interface AFStreamingMultipartFormData ()
828
- @property (readwrite, nonatomic, copy) NSMutableURLRequest *request;
829
- @property (readwrite, nonatomic, strong) AFMultipartBodyStream *bodyStream;
830
- @property (readwrite, nonatomic, assign) NSStringEncoding stringEncoding;
831
- @end
832
-
833
- @implementation AFStreamingMultipartFormData
834
- @synthesize request = _request;
835
- @synthesize bodyStream = _bodyStream;
836
- @synthesize stringEncoding = _stringEncoding;
837
-
838
- - (id)initWithURLRequest:(NSMutableURLRequest *)urlRequest
839
- stringEncoding:(NSStringEncoding)encoding
840
- {
841
- self = [super init];
842
- if (!self) {
843
- return nil;
844
- }
845
-
846
- self.request = urlRequest;
847
- self.stringEncoding = encoding;
848
- self.bodyStream = [[AFMultipartBodyStream alloc] initWithStringEncoding:encoding];
849
-
850
- return self;
851
- }
852
-
853
- - (BOOL)appendPartWithFileURL:(NSURL *)fileURL
854
- name:(NSString *)name
855
- error:(NSError * __autoreleasing *)error
856
- {
857
- NSParameterAssert(fileURL);
858
- NSParameterAssert(name);
859
-
860
- NSString *fileName = [fileURL lastPathComponent];
861
- NSString *mimeType = AFContentTypeForPathExtension([fileURL pathExtension]);
862
-
863
- return [self appendPartWithFileURL:fileURL name:name fileName:fileName mimeType:mimeType error:error];
864
- }
865
-
866
- - (BOOL)appendPartWithFileURL:(NSURL *)fileURL
867
- name:(NSString *)name
868
- fileName:(NSString *)fileName
869
- mimeType:(NSString *)mimeType
870
- error:(NSError * __autoreleasing *)error
871
- {
872
- NSParameterAssert(fileURL);
873
- NSParameterAssert(name);
874
- NSParameterAssert(fileName);
875
- NSParameterAssert(mimeType);
876
-
877
- if (![fileURL isFileURL]) {
878
- NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedStringFromTable(@"Expected URL to be a file URL", @"AFNetworking", nil) forKey:NSLocalizedFailureReasonErrorKey];
879
- if (error != NULL) {
880
- *error = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo];
881
- }
882
-
883
- return NO;
884
- } else if ([fileURL checkResourceIsReachableAndReturnError:error] == NO) {
885
- NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedStringFromTable(@"File URL not reachable.", @"AFNetworking", nil) forKey:NSLocalizedFailureReasonErrorKey];
886
- if (error != NULL) {
887
- *error = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo];
888
- }
889
-
890
- return NO;
891
- }
892
-
893
- NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
894
- [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
895
- [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
896
-
897
- AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
898
- bodyPart.stringEncoding = self.stringEncoding;
899
- bodyPart.headers = mutableHeaders;
900
- bodyPart.body = fileURL;
901
-
902
- NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:[fileURL path] error:nil];
903
- bodyPart.bodyContentLength = [[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue];
904
-
905
- [self.bodyStream appendHTTPBodyPart:bodyPart];
906
-
907
- return YES;
908
- }
909
-
910
-
911
- - (void)appendPartWithInputStream:(NSInputStream *)inputStream
912
- name:(NSString *)name
913
- fileName:(NSString *)fileName
914
- length:(unsigned long long)length
915
- mimeType:(NSString *)mimeType
916
- {
917
- NSParameterAssert(name);
918
- NSParameterAssert(fileName);
919
- NSParameterAssert(mimeType);
920
-
921
- NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
922
- [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
923
- [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
924
-
925
-
926
- AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
927
- bodyPart.stringEncoding = self.stringEncoding;
928
- bodyPart.headers = mutableHeaders;
929
- bodyPart.body = inputStream;
930
-
931
- bodyPart.bodyContentLength = length;
932
-
933
- [self.bodyStream appendHTTPBodyPart:bodyPart];
934
- }
935
-
936
- - (void)appendPartWithFileData:(NSData *)data
937
- name:(NSString *)name
938
- fileName:(NSString *)fileName
939
- mimeType:(NSString *)mimeType
940
- {
941
- NSParameterAssert(name);
942
- NSParameterAssert(fileName);
943
- NSParameterAssert(mimeType);
944
-
945
- NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
946
- [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"];
947
- [mutableHeaders setValue:mimeType forKey:@"Content-Type"];
948
-
949
- [self appendPartWithHeaders:mutableHeaders body:data];
950
- }
951
-
952
- - (void)appendPartWithFormData:(NSData *)data
953
- name:(NSString *)name
954
- {
955
- NSParameterAssert(name);
956
-
957
- NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
958
- [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"];
959
-
960
- [self appendPartWithHeaders:mutableHeaders body:data];
961
- }
962
-
963
- - (void)appendPartWithHeaders:(NSDictionary *)headers
964
- body:(NSData *)body
965
- {
966
- NSParameterAssert(body);
967
-
968
- AFHTTPBodyPart *bodyPart = [[AFHTTPBodyPart alloc] init];
969
- bodyPart.stringEncoding = self.stringEncoding;
970
- bodyPart.headers = headers;
971
- bodyPart.bodyContentLength = [body length];
972
- bodyPart.body = body;
973
-
974
- [self.bodyStream appendHTTPBodyPart:bodyPart];
975
- }
976
-
977
- - (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes
978
- delay:(NSTimeInterval)delay
979
- {
980
- self.bodyStream.numberOfBytesInPacket = numberOfBytes;
981
- self.bodyStream.delay = delay;
982
- }
983
-
984
- - (NSMutableURLRequest *)requestByFinalizingMultipartFormData {
985
- if ([self.bodyStream isEmpty]) {
986
- return self.request;
987
- }
988
-
989
- // Reset the initial and final boundaries to ensure correct Content-Length
990
- [self.bodyStream setInitialAndFinalBoundaries];
991
-
992
- [self.request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", kAFMultipartFormBoundary] forHTTPHeaderField:@"Content-Type"];
993
- [self.request setValue:[NSString stringWithFormat:@"%llu", [self.bodyStream contentLength]] forHTTPHeaderField:@"Content-Length"];
994
- [self.request setHTTPBodyStream:self.bodyStream];
995
-
996
- return self.request;
997
- }
998
-
999
- @end
1000
-
1001
- #pragma mark -
1002
-
1003
- @interface AFMultipartBodyStream () <NSCopying>
1004
- @property (nonatomic, assign) NSStreamStatus streamStatus;
1005
- @property (nonatomic, strong) NSError *streamError;
1006
- @property (nonatomic, assign) NSStringEncoding stringEncoding;
1007
- @property (nonatomic, strong) NSMutableArray *HTTPBodyParts;
1008
- @property (nonatomic, strong) NSEnumerator *HTTPBodyPartEnumerator;
1009
- @property (nonatomic, strong) AFHTTPBodyPart *currentHTTPBodyPart;
1010
- @property (nonatomic, strong) NSOutputStream *outputStream;
1011
- @property (nonatomic, strong) NSMutableData *buffer;
1012
- @end
1013
-
1014
- @implementation AFMultipartBodyStream
1015
- @synthesize streamStatus = _streamStatus;
1016
- @synthesize streamError = _streamError;
1017
- @synthesize stringEncoding = _stringEncoding;
1018
- @synthesize HTTPBodyParts = _HTTPBodyParts;
1019
- @synthesize HTTPBodyPartEnumerator = _HTTPBodyPartEnumerator;
1020
- @synthesize currentHTTPBodyPart = _currentHTTPBodyPart;
1021
- @synthesize inputStream = _inputStream;
1022
- @synthesize outputStream = _outputStream;
1023
- @synthesize buffer = _buffer;
1024
- @synthesize numberOfBytesInPacket = _numberOfBytesInPacket;
1025
- @synthesize delay = _delay;
1026
-
1027
- - (id)initWithStringEncoding:(NSStringEncoding)encoding {
1028
- self = [super init];
1029
- if (!self) {
1030
- return nil;
1031
- }
1032
-
1033
- self.stringEncoding = encoding;
1034
- self.HTTPBodyParts = [NSMutableArray array];
1035
- self.numberOfBytesInPacket = NSIntegerMax;
1036
-
1037
- return self;
1038
- }
1039
-
1040
- - (void)setInitialAndFinalBoundaries {
1041
- if ([self.HTTPBodyParts count] > 0) {
1042
- for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
1043
- bodyPart.hasInitialBoundary = NO;
1044
- bodyPart.hasFinalBoundary = NO;
1045
- }
1046
-
1047
- [[self.HTTPBodyParts objectAtIndex:0] setHasInitialBoundary:YES];
1048
- [[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
1049
- }
1050
- }
1051
-
1052
- - (void)appendHTTPBodyPart:(AFHTTPBodyPart *)bodyPart {
1053
- [self.HTTPBodyParts addObject:bodyPart];
1054
- }
1055
-
1056
- - (BOOL)isEmpty {
1057
- return [self.HTTPBodyParts count] == 0;
1058
- }
1059
-
1060
- #pragma mark - NSInputStream
1061
-
1062
- - (NSInteger)read:(uint8_t *)buffer
1063
- maxLength:(NSUInteger)length
1064
- {
1065
- if ([self streamStatus] == NSStreamStatusClosed) {
1066
- return 0;
1067
- }
1068
-
1069
- NSInteger totalNumberOfBytesRead = 0;
1070
-
1071
- while ((NSUInteger)totalNumberOfBytesRead < MIN(length, self.numberOfBytesInPacket)) {
1072
- if (!self.currentHTTPBodyPart || ![self.currentHTTPBodyPart hasBytesAvailable]) {
1073
- if (!(self.currentHTTPBodyPart = [self.HTTPBodyPartEnumerator nextObject])) {
1074
- break;
1075
- }
1076
- } else {
1077
- NSUInteger maxLength = length - (NSUInteger)totalNumberOfBytesRead;
1078
- NSInteger numberOfBytesRead = [self.currentHTTPBodyPart read:&buffer[totalNumberOfBytesRead] maxLength:maxLength];
1079
- if (numberOfBytesRead == -1) {
1080
- self.streamError = self.currentHTTPBodyPart.inputStream.streamError;
1081
- break;
1082
- } else {
1083
- totalNumberOfBytesRead += numberOfBytesRead;
1084
-
1085
- if (self.delay > 0.0f) {
1086
- [NSThread sleepForTimeInterval:self.delay];
1087
- }
1088
- }
1089
- }
1090
- }
1091
-
1092
- return totalNumberOfBytesRead;
1093
- }
1094
-
1095
- - (BOOL)getBuffer:(__unused uint8_t **)buffer
1096
- length:(__unused NSUInteger *)len
1097
- {
1098
- return NO;
1099
- }
1100
-
1101
- - (BOOL)hasBytesAvailable {
1102
- return [self streamStatus] == NSStreamStatusOpen;
1103
- }
1104
-
1105
- #pragma mark - NSStream
1106
-
1107
- - (void)open {
1108
- if (self.streamStatus == NSStreamStatusOpen) {
1109
- return;
1110
- }
1111
-
1112
- self.streamStatus = NSStreamStatusOpen;
1113
-
1114
- [self setInitialAndFinalBoundaries];
1115
- self.HTTPBodyPartEnumerator = [self.HTTPBodyParts objectEnumerator];
1116
- }
1117
-
1118
- - (void)close {
1119
- self.streamStatus = NSStreamStatusClosed;
1120
- }
1121
-
1122
- - (id)propertyForKey:(__unused NSString *)key {
1123
- return nil;
1124
- }
1125
-
1126
- - (BOOL)setProperty:(__unused id)property
1127
- forKey:(__unused NSString *)key
1128
- {
1129
- return NO;
1130
- }
1131
-
1132
- - (void)scheduleInRunLoop:(__unused NSRunLoop *)aRunLoop
1133
- forMode:(__unused NSString *)mode
1134
- {}
1135
-
1136
- - (void)removeFromRunLoop:(__unused NSRunLoop *)aRunLoop
1137
- forMode:(__unused NSString *)mode
1138
- {}
1139
-
1140
- - (unsigned long long)contentLength {
1141
- unsigned long long length = 0;
1142
- for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
1143
- length += [bodyPart contentLength];
1144
- }
1145
-
1146
- return length;
1147
- }
1148
-
1149
- #pragma mark - Undocumented CFReadStream Bridged Methods
1150
-
1151
- - (void)_scheduleInCFRunLoop:(__unused CFRunLoopRef)aRunLoop
1152
- forMode:(__unused CFStringRef)aMode
1153
- {}
1154
-
1155
- - (void)_unscheduleFromCFRunLoop:(__unused CFRunLoopRef)aRunLoop
1156
- forMode:(__unused CFStringRef)aMode
1157
- {}
1158
-
1159
- - (BOOL)_setCFClientFlags:(__unused CFOptionFlags)inFlags
1160
- callback:(__unused CFReadStreamClientCallBack)inCallback
1161
- context:(__unused CFStreamClientContext *)inContext {
1162
- return NO;
1163
- }
1164
-
1165
- #pragma mark - NSCopying
1166
-
1167
- -(id)copyWithZone:(NSZone *)zone {
1168
- AFMultipartBodyStream *bodyStreamCopy = [[[self class] allocWithZone:zone] initWithStringEncoding:self.stringEncoding];
1169
-
1170
- for (AFHTTPBodyPart *bodyPart in self.HTTPBodyParts) {
1171
- [bodyStreamCopy appendHTTPBodyPart:[bodyPart copy]];
1172
- }
1173
-
1174
- [bodyStreamCopy setInitialAndFinalBoundaries];
1175
-
1176
- return bodyStreamCopy;
1177
- }
1178
-
1179
- @end
1180
-
1181
- #pragma mark -
1182
-
1183
- typedef enum {
1184
- AFEncapsulationBoundaryPhase = 1,
1185
- AFHeaderPhase = 2,
1186
- AFBodyPhase = 3,
1187
- AFFinalBoundaryPhase = 4,
1188
- } AFHTTPBodyPartReadPhase;
1189
-
1190
- @interface AFHTTPBodyPart () <NSCopying> {
1191
- AFHTTPBodyPartReadPhase _phase;
1192
- NSInputStream *_inputStream;
1193
- unsigned long long _phaseReadOffset;
1194
- }
1195
-
1196
- - (BOOL)transitionToNextPhase;
1197
- - (NSInteger)readData:(NSData *)data
1198
- intoBuffer:(uint8_t *)buffer
1199
- maxLength:(NSUInteger)length;
1200
- @end
1201
-
1202
- @implementation AFHTTPBodyPart
1203
- @synthesize stringEncoding = _stringEncoding;
1204
- @synthesize headers = _headers;
1205
- @synthesize body = _body;
1206
- @synthesize bodyContentLength = _bodyContentLength;
1207
- @synthesize inputStream = _inputStream;
1208
- @synthesize hasInitialBoundary = _hasInitialBoundary;
1209
- @synthesize hasFinalBoundary = _hasFinalBoundary;
1210
-
1211
- - (id)init {
1212
- self = [super init];
1213
- if (!self) {
1214
- return nil;
1215
- }
1216
-
1217
- [self transitionToNextPhase];
1218
-
1219
- return self;
1220
- }
1221
-
1222
- - (void)dealloc {
1223
- if (_inputStream) {
1224
- [_inputStream close];
1225
- _inputStream = nil;
1226
- }
1227
- }
1228
-
1229
- - (NSInputStream *)inputStream {
1230
- if (!_inputStream) {
1231
- if ([self.body isKindOfClass:[NSData class]]) {
1232
- _inputStream = [NSInputStream inputStreamWithData:self.body];
1233
- } else if ([self.body isKindOfClass:[NSURL class]]) {
1234
- _inputStream = [NSInputStream inputStreamWithURL:self.body];
1235
- } else if ([self.body isKindOfClass:[NSInputStream class]]) {
1236
- _inputStream = self.body;
1237
- }
1238
- }
1239
-
1240
- return _inputStream;
1241
- }
1242
-
1243
- - (NSString *)stringForHeaders {
1244
- NSMutableString *headerString = [NSMutableString string];
1245
- for (NSString *field in [self.headers allKeys]) {
1246
- [headerString appendString:[NSString stringWithFormat:@"%@: %@%@", field, [self.headers valueForKey:field], kAFMultipartFormCRLF]];
1247
- }
1248
- [headerString appendString:kAFMultipartFormCRLF];
1249
-
1250
- return [NSString stringWithString:headerString];
1251
- }
1252
-
1253
- - (unsigned long long)contentLength {
1254
- unsigned long long length = 0;
1255
-
1256
- NSData *encapsulationBoundaryData = [([self hasInitialBoundary] ? AFMultipartFormInitialBoundary() : AFMultipartFormEncapsulationBoundary()) dataUsingEncoding:self.stringEncoding];
1257
- length += [encapsulationBoundaryData length];
1258
-
1259
- NSData *headersData = [[self stringForHeaders] dataUsingEncoding:self.stringEncoding];
1260
- length += [headersData length];
1261
-
1262
- length += _bodyContentLength;
1263
-
1264
- NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding] : [NSData data]);
1265
- length += [closingBoundaryData length];
1266
-
1267
- return length;
1268
- }
1269
-
1270
- - (BOOL)hasBytesAvailable {
1271
- // Allows `read:maxLength:` to be called again if `AFMultipartFormFinalBoundary` doesn't fit into the available buffer
1272
- if (_phase == AFFinalBoundaryPhase) {
1273
- return YES;
1274
- }
1275
-
1276
- #pragma clang diagnostic push
1277
- #pragma clang diagnostic ignored "-Wcovered-switch-default"
1278
- switch (self.inputStream.streamStatus) {
1279
- case NSStreamStatusNotOpen:
1280
- case NSStreamStatusOpening:
1281
- case NSStreamStatusOpen:
1282
- case NSStreamStatusReading:
1283
- case NSStreamStatusWriting:
1284
- return YES;
1285
- case NSStreamStatusAtEnd:
1286
- case NSStreamStatusClosed:
1287
- case NSStreamStatusError:
1288
- default:
1289
- return NO;
1290
- }
1291
- #pragma clang diagnostic pop
1292
- }
1293
-
1294
- - (NSInteger)read:(uint8_t *)buffer
1295
- maxLength:(NSUInteger)length
1296
- {
1297
- NSUInteger totalNumberOfBytesRead = 0;
1298
-
1299
- if (_phase == AFEncapsulationBoundaryPhase) {
1300
- NSData *encapsulationBoundaryData = [([self hasInitialBoundary] ? AFMultipartFormInitialBoundary() : AFMultipartFormEncapsulationBoundary()) dataUsingEncoding:self.stringEncoding];
1301
- totalNumberOfBytesRead += [self readData:encapsulationBoundaryData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
1302
- }
1303
-
1304
- if (_phase == AFHeaderPhase) {
1305
- NSData *headersData = [[self stringForHeaders] dataUsingEncoding:self.stringEncoding];
1306
- totalNumberOfBytesRead += [self readData:headersData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
1307
- }
1308
-
1309
- if (_phase == AFBodyPhase) {
1310
- NSInteger numberOfBytesRead = 0;
1311
-
1312
- numberOfBytesRead = [self.inputStream read:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
1313
- if (numberOfBytesRead == -1) {
1314
- return -1;
1315
- } else {
1316
- totalNumberOfBytesRead += numberOfBytesRead;
1317
-
1318
- if ([self.inputStream streamStatus] >= NSStreamStatusAtEnd) {
1319
- [self transitionToNextPhase];
1320
- }
1321
- }
1322
- }
1323
-
1324
- if (_phase == AFFinalBoundaryPhase) {
1325
- NSData *closingBoundaryData = ([self hasFinalBoundary] ? [AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding] : [NSData data]);
1326
- totalNumberOfBytesRead += [self readData:closingBoundaryData intoBuffer:&buffer[totalNumberOfBytesRead] maxLength:(length - (NSUInteger)totalNumberOfBytesRead)];
1327
- }
1328
-
1329
- return totalNumberOfBytesRead;
1330
- }
1331
-
1332
- - (NSInteger)readData:(NSData *)data
1333
- intoBuffer:(uint8_t *)buffer
1334
- maxLength:(NSUInteger)length
1335
- {
1336
- #pragma clang diagnostic push
1337
- #pragma clang diagnostic ignored "-Wgnu"
1338
- NSRange range = NSMakeRange((NSUInteger)_phaseReadOffset, MIN([data length] - ((NSUInteger)_phaseReadOffset), length));
1339
- [data getBytes:buffer range:range];
1340
- #pragma clang diagnostic pop
1341
-
1342
- _phaseReadOffset += range.length;
1343
-
1344
- if (((NSUInteger)_phaseReadOffset) >= [data length]) {
1345
- [self transitionToNextPhase];
1346
- }
1347
-
1348
- return (NSInteger)range.length;
1349
- }
1350
-
1351
- - (BOOL)transitionToNextPhase {
1352
- if (![[NSThread currentThread] isMainThread]) {
1353
- [self performSelectorOnMainThread:@selector(transitionToNextPhase) withObject:nil waitUntilDone:YES];
1354
- return YES;
1355
- }
1356
-
1357
- #pragma clang diagnostic push
1358
- #pragma clang diagnostic ignored "-Wcovered-switch-default"
1359
- switch (_phase) {
1360
- case AFEncapsulationBoundaryPhase:
1361
- _phase = AFHeaderPhase;
1362
- break;
1363
- case AFHeaderPhase:
1364
- [self.inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
1365
- [self.inputStream open];
1366
- _phase = AFBodyPhase;
1367
- break;
1368
- case AFBodyPhase:
1369
- [self.inputStream close];
1370
- _phase = AFFinalBoundaryPhase;
1371
- break;
1372
- case AFFinalBoundaryPhase:
1373
- default:
1374
- _phase = AFEncapsulationBoundaryPhase;
1375
- break;
1376
- }
1377
- _phaseReadOffset = 0;
1378
- #pragma clang diagnostic pop
1379
-
1380
- return YES;
1381
- }
1382
-
1383
- #pragma mark - NSCopying
1384
-
1385
- - (id)copyWithZone:(NSZone *)zone {
1386
- AFHTTPBodyPart *bodyPart = [[[self class] allocWithZone:zone] init];
1387
-
1388
- bodyPart.stringEncoding = self.stringEncoding;
1389
- bodyPart.headers = self.headers;
1390
- bodyPart.bodyContentLength = self.bodyContentLength;
1391
- bodyPart.body = self.body;
1392
-
1393
- return bodyPart;
1394
- }
1395
-
1396
- @end