WebSocketReader.smali 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. .class final Lokhttp3/internal/ws/WebSocketReader;
  2. .super Ljava/lang/Object;
  3. .source ""
  4. # annotations
  5. .annotation system Ldalvik/annotation/MemberClasses;
  6. value = {
  7. Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  8. }
  9. .end annotation
  10. # instance fields
  11. .field closed:Z
  12. .field frameBytesRead:J
  13. .field final frameCallback:Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  14. .field frameLength:J
  15. .field final isClient:Z
  16. .field isControlFrame:Z
  17. .field isFinalFrame:Z
  18. .field isMasked:Z
  19. .field final maskBuffer:[B
  20. .field final maskKey:[B
  21. .field opcode:I
  22. .field final source:Lokio/BufferedSource;
  23. # direct methods
  24. .method constructor <init>(ZLokio/BufferedSource;Lokhttp3/internal/ws/WebSocketReader$FrameCallback;)V
  25. .locals 1
  26. invoke-direct {p0}, Ljava/lang/Object;-><init>()V
  27. const/4 v0, 0x4
  28. new-array v0, v0, [B
  29. iput-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->maskKey:[B
  30. const/16 v0, 0x2000
  31. new-array v0, v0, [B
  32. iput-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  33. if-eqz p2, :cond_1
  34. if-eqz p3, :cond_0
  35. iput-boolean p1, p0, Lokhttp3/internal/ws/WebSocketReader;->isClient:Z
  36. iput-object p2, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  37. iput-object p3, p0, Lokhttp3/internal/ws/WebSocketReader;->frameCallback:Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  38. return-void
  39. :cond_0
  40. new-instance p1, Ljava/lang/NullPointerException;
  41. const-string p2, "frameCallback == null"
  42. invoke-direct {p1, p2}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
  43. throw p1
  44. :cond_1
  45. new-instance p1, Ljava/lang/NullPointerException;
  46. const-string p2, "source == null"
  47. invoke-direct {p1, p2}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V
  48. throw p1
  49. .end method
  50. .method private readControlFrame()V
  51. .locals 11
  52. .annotation system Ldalvik/annotation/Throws;
  53. value = {
  54. Ljava/io/IOException;
  55. }
  56. .end annotation
  57. new-instance v0, Lokio/Buffer;
  58. invoke-direct {v0}, Lokio/Buffer;-><init>()V
  59. iget-wide v1, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  60. iget-wide v3, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  61. cmp-long v5, v1, v3
  62. if-gez v5, :cond_2
  63. iget-boolean v1, p0, Lokhttp3/internal/ws/WebSocketReader;->isClient:Z
  64. if-eqz v1, :cond_0
  65. iget-object v1, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  66. invoke-interface {v1, v0, v3, v4}, Lokio/BufferedSource;->readFully(Lokio/Buffer;J)V
  67. goto :goto_1
  68. :cond_0
  69. :goto_0
  70. iget-wide v1, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  71. iget-wide v3, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  72. cmp-long v5, v1, v3
  73. if-gez v5, :cond_2
  74. sub-long/2addr v3, v1
  75. iget-object v1, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  76. array-length v1, v1
  77. int-to-long v1, v1
  78. invoke-static {v3, v4, v1, v2}, Ljava/lang/Math;->min(JJ)J
  79. move-result-wide v1
  80. long-to-int v2, v1
  81. iget-object v1, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  82. iget-object v3, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  83. const/4 v4, 0x0
  84. invoke-interface {v1, v3, v4, v2}, Lokio/BufferedSource;->read([BII)I
  85. move-result v1
  86. const/4 v2, -0x1
  87. if-eq v1, v2, :cond_1
  88. iget-object v5, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  89. int-to-long v2, v1
  90. iget-object v8, p0, Lokhttp3/internal/ws/WebSocketReader;->maskKey:[B
  91. iget-wide v9, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  92. move-wide v6, v2
  93. invoke-static/range {v5 .. v10}, Lokhttp3/internal/ws/WebSocketProtocol;->toggleMask([BJ[BJ)V
  94. iget-object v5, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  95. invoke-virtual {v0, v5, v4, v1}, Lokio/Buffer;->write([BII)Lokio/Buffer;
  96. iget-wide v4, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  97. add-long/2addr v4, v2
  98. iput-wide v4, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  99. goto :goto_0
  100. :cond_1
  101. new-instance v0, Ljava/io/EOFException;
  102. invoke-direct {v0}, Ljava/io/EOFException;-><init>()V
  103. throw v0
  104. :cond_2
  105. :goto_1
  106. iget v1, p0, Lokhttp3/internal/ws/WebSocketReader;->opcode:I
  107. packed-switch v1, :pswitch_data_0
  108. new-instance v0, Ljava/net/ProtocolException;
  109. new-instance v1, Ljava/lang/StringBuilder;
  110. invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
  111. const-string v2, "Unknown control opcode: "
  112. invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  113. iget v2, p0, Lokhttp3/internal/ws/WebSocketReader;->opcode:I
  114. invoke-static {v2}, Ljava/lang/Integer;->toHexString(I)Ljava/lang/String;
  115. move-result-object v2
  116. invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  117. invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  118. move-result-object v1
  119. invoke-direct {v0, v1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  120. throw v0
  121. :pswitch_0
  122. iget-object v1, p0, Lokhttp3/internal/ws/WebSocketReader;->frameCallback:Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  123. invoke-virtual {v0}, Lokio/Buffer;->readByteString()Lokio/ByteString;
  124. move-result-object v0
  125. invoke-interface {v1, v0}, Lokhttp3/internal/ws/WebSocketReader$FrameCallback;->onReadPong(Lokio/ByteString;)V
  126. goto :goto_3
  127. :pswitch_1
  128. iget-object v1, p0, Lokhttp3/internal/ws/WebSocketReader;->frameCallback:Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  129. invoke-virtual {v0}, Lokio/Buffer;->readByteString()Lokio/ByteString;
  130. move-result-object v0
  131. invoke-interface {v1, v0}, Lokhttp3/internal/ws/WebSocketReader$FrameCallback;->onReadPing(Lokio/ByteString;)V
  132. goto :goto_3
  133. :pswitch_2
  134. const/16 v1, 0x3ed
  135. invoke-virtual {v0}, Lokio/Buffer;->size()J
  136. move-result-wide v2
  137. const-wide/16 v4, 0x1
  138. cmp-long v6, v2, v4
  139. if-eqz v6, :cond_5
  140. const-wide/16 v4, 0x0
  141. cmp-long v6, v2, v4
  142. if-eqz v6, :cond_4
  143. invoke-virtual {v0}, Lokio/Buffer;->readShort()S
  144. move-result v1
  145. invoke-virtual {v0}, Lokio/Buffer;->readUtf8()Ljava/lang/String;
  146. move-result-object v0
  147. invoke-static {v1}, Lokhttp3/internal/ws/WebSocketProtocol;->closeCodeExceptionMessage(I)Ljava/lang/String;
  148. move-result-object v2
  149. if-nez v2, :cond_3
  150. goto :goto_2
  151. :cond_3
  152. new-instance v0, Ljava/net/ProtocolException;
  153. invoke-direct {v0, v2}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  154. throw v0
  155. :cond_4
  156. const-string v0, ""
  157. :goto_2
  158. iget-object v2, p0, Lokhttp3/internal/ws/WebSocketReader;->frameCallback:Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  159. invoke-interface {v2, v1, v0}, Lokhttp3/internal/ws/WebSocketReader$FrameCallback;->onReadClose(ILjava/lang/String;)V
  160. const/4 v0, 0x1
  161. iput-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->closed:Z
  162. :goto_3
  163. return-void
  164. :cond_5
  165. new-instance v0, Ljava/net/ProtocolException;
  166. const-string v1, "Malformed close payload length of 1."
  167. invoke-direct {v0, v1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  168. goto :goto_5
  169. :goto_4
  170. throw v0
  171. :goto_5
  172. goto :goto_4
  173. nop
  174. :pswitch_data_0
  175. .packed-switch 0x8
  176. :pswitch_2
  177. :pswitch_1
  178. :pswitch_0
  179. .end packed-switch
  180. .end method
  181. .method private readHeader()V
  182. .locals 7
  183. .annotation system Ldalvik/annotation/Throws;
  184. value = {
  185. Ljava/io/IOException;
  186. }
  187. .end annotation
  188. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->closed:Z
  189. if-nez v0, :cond_11
  190. iget-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  191. invoke-interface {v0}, Lokio/Source;->timeout()Lokio/Timeout;
  192. move-result-object v0
  193. invoke-virtual {v0}, Lokio/Timeout;->timeoutNanos()J
  194. move-result-wide v0
  195. iget-object v2, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  196. invoke-interface {v2}, Lokio/Source;->timeout()Lokio/Timeout;
  197. move-result-object v2
  198. invoke-virtual {v2}, Lokio/Timeout;->clearTimeout()Lokio/Timeout;
  199. :try_start_0
  200. iget-object v2, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  201. invoke-interface {v2}, Lokio/BufferedSource;->readByte()B
  202. move-result v2
  203. :try_end_0
  204. .catchall {:try_start_0 .. :try_end_0} :catchall_0
  205. and-int/lit16 v2, v2, 0xff
  206. iget-object v3, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  207. invoke-interface {v3}, Lokio/Source;->timeout()Lokio/Timeout;
  208. move-result-object v3
  209. sget-object v4, Ljava/util/concurrent/TimeUnit;->NANOSECONDS:Ljava/util/concurrent/TimeUnit;
  210. invoke-virtual {v3, v0, v1, v4}, Lokio/Timeout;->timeout(JLjava/util/concurrent/TimeUnit;)Lokio/Timeout;
  211. and-int/lit8 v0, v2, 0xf
  212. iput v0, p0, Lokhttp3/internal/ws/WebSocketReader;->opcode:I
  213. and-int/lit16 v0, v2, 0x80
  214. const/4 v1, 0x1
  215. const/4 v3, 0x0
  216. if-eqz v0, :cond_0
  217. const/4 v0, 0x1
  218. goto :goto_0
  219. :cond_0
  220. const/4 v0, 0x0
  221. :goto_0
  222. iput-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isFinalFrame:Z
  223. and-int/lit8 v0, v2, 0x8
  224. if-eqz v0, :cond_1
  225. const/4 v0, 0x1
  226. goto :goto_1
  227. :cond_1
  228. const/4 v0, 0x0
  229. :goto_1
  230. iput-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isControlFrame:Z
  231. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isControlFrame:Z
  232. if-eqz v0, :cond_3
  233. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isFinalFrame:Z
  234. if-eqz v0, :cond_2
  235. goto :goto_2
  236. :cond_2
  237. new-instance v0, Ljava/net/ProtocolException;
  238. const-string v1, "Control frames must be final."
  239. invoke-direct {v0, v1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  240. throw v0
  241. :cond_3
  242. :goto_2
  243. and-int/lit8 v0, v2, 0x40
  244. if-eqz v0, :cond_4
  245. const/4 v0, 0x1
  246. goto :goto_3
  247. :cond_4
  248. const/4 v0, 0x0
  249. :goto_3
  250. and-int/lit8 v4, v2, 0x20
  251. if-eqz v4, :cond_5
  252. const/4 v4, 0x1
  253. goto :goto_4
  254. :cond_5
  255. const/4 v4, 0x0
  256. :goto_4
  257. and-int/lit8 v2, v2, 0x10
  258. if-eqz v2, :cond_6
  259. const/4 v2, 0x1
  260. goto :goto_5
  261. :cond_6
  262. const/4 v2, 0x0
  263. :goto_5
  264. if-nez v0, :cond_10
  265. if-nez v4, :cond_10
  266. if-nez v2, :cond_10
  267. iget-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  268. invoke-interface {v0}, Lokio/BufferedSource;->readByte()B
  269. move-result v0
  270. and-int/lit16 v0, v0, 0xff
  271. and-int/lit16 v2, v0, 0x80
  272. if-eqz v2, :cond_7
  273. goto :goto_6
  274. :cond_7
  275. const/4 v1, 0x0
  276. :goto_6
  277. iput-boolean v1, p0, Lokhttp3/internal/ws/WebSocketReader;->isMasked:Z
  278. iget-boolean v1, p0, Lokhttp3/internal/ws/WebSocketReader;->isMasked:Z
  279. iget-boolean v2, p0, Lokhttp3/internal/ws/WebSocketReader;->isClient:Z
  280. if-ne v1, v2, :cond_9
  281. new-instance v0, Ljava/net/ProtocolException;
  282. if-eqz v2, :cond_8
  283. const-string v1, "Server-sent frames must not be masked."
  284. goto :goto_7
  285. :cond_8
  286. const-string v1, "Client-sent frames must be masked."
  287. :goto_7
  288. invoke-direct {v0, v1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  289. throw v0
  290. :cond_9
  291. and-int/lit8 v0, v0, 0x7f
  292. int-to-long v0, v0
  293. iput-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  294. iget-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  295. const-wide/16 v2, 0x7e
  296. const-wide/16 v4, 0x0
  297. cmp-long v6, v0, v2
  298. if-nez v6, :cond_a
  299. iget-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  300. invoke-interface {v0}, Lokio/BufferedSource;->readShort()S
  301. move-result v0
  302. int-to-long v0, v0
  303. const-wide/32 v2, 0xffff
  304. and-long/2addr v0, v2
  305. iput-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  306. goto :goto_8
  307. :cond_a
  308. const-wide/16 v2, 0x7f
  309. cmp-long v6, v0, v2
  310. if-nez v6, :cond_c
  311. iget-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  312. invoke-interface {v0}, Lokio/BufferedSource;->readLong()J
  313. move-result-wide v0
  314. iput-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  315. iget-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  316. cmp-long v2, v0, v4
  317. if-ltz v2, :cond_b
  318. goto :goto_8
  319. :cond_b
  320. new-instance v0, Ljava/net/ProtocolException;
  321. new-instance v1, Ljava/lang/StringBuilder;
  322. invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
  323. const-string v2, "Frame length 0x"
  324. invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  325. iget-wide v2, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  326. invoke-static {v2, v3}, Ljava/lang/Long;->toHexString(J)Ljava/lang/String;
  327. move-result-object v2
  328. invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  329. const-string v2, " > 0x7FFFFFFFFFFFFFFF"
  330. invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  331. invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  332. move-result-object v1
  333. invoke-direct {v0, v1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  334. throw v0
  335. :cond_c
  336. :goto_8
  337. iput-wide v4, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  338. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isControlFrame:Z
  339. if-eqz v0, :cond_e
  340. iget-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  341. const-wide/16 v2, 0x7d
  342. cmp-long v4, v0, v2
  343. if-gtz v4, :cond_d
  344. goto :goto_9
  345. :cond_d
  346. new-instance v0, Ljava/net/ProtocolException;
  347. const-string v1, "Control frame must be less than 125B."
  348. invoke-direct {v0, v1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  349. throw v0
  350. :cond_e
  351. :goto_9
  352. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isMasked:Z
  353. if-eqz v0, :cond_f
  354. iget-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  355. iget-object v1, p0, Lokhttp3/internal/ws/WebSocketReader;->maskKey:[B
  356. invoke-interface {v0, v1}, Lokio/BufferedSource;->readFully([B)V
  357. :cond_f
  358. return-void
  359. :cond_10
  360. new-instance v0, Ljava/net/ProtocolException;
  361. const-string v1, "Reserved flags are unsupported."
  362. invoke-direct {v0, v1}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  363. throw v0
  364. :catchall_0
  365. move-exception v2
  366. iget-object v3, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  367. invoke-interface {v3}, Lokio/Source;->timeout()Lokio/Timeout;
  368. move-result-object v3
  369. sget-object v4, Ljava/util/concurrent/TimeUnit;->NANOSECONDS:Ljava/util/concurrent/TimeUnit;
  370. invoke-virtual {v3, v0, v1, v4}, Lokio/Timeout;->timeout(JLjava/util/concurrent/TimeUnit;)Lokio/Timeout;
  371. throw v2
  372. :cond_11
  373. new-instance v0, Ljava/io/IOException;
  374. const-string v1, "closed"
  375. invoke-direct {v0, v1}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
  376. throw v0
  377. .end method
  378. .method private readMessage(Lokio/Buffer;)V
  379. .locals 11
  380. .annotation system Ldalvik/annotation/Throws;
  381. value = {
  382. Ljava/io/IOException;
  383. }
  384. .end annotation
  385. :goto_0
  386. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->closed:Z
  387. if-nez v0, :cond_6
  388. iget-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  389. iget-wide v2, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  390. cmp-long v4, v0, v2
  391. if-nez v4, :cond_2
  392. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isFinalFrame:Z
  393. if-eqz v0, :cond_0
  394. return-void
  395. :cond_0
  396. invoke-virtual {p0}, Lokhttp3/internal/ws/WebSocketReader;->readUntilNonControlFrame()V
  397. iget v0, p0, Lokhttp3/internal/ws/WebSocketReader;->opcode:I
  398. if-nez v0, :cond_1
  399. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isFinalFrame:Z
  400. if-eqz v0, :cond_2
  401. iget-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  402. const-wide/16 v2, 0x0
  403. cmp-long v4, v0, v2
  404. if-nez v4, :cond_2
  405. return-void
  406. :cond_1
  407. new-instance p1, Ljava/net/ProtocolException;
  408. new-instance v0, Ljava/lang/StringBuilder;
  409. invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
  410. const-string v1, "Expected continuation opcode. Got: "
  411. invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  412. iget v1, p0, Lokhttp3/internal/ws/WebSocketReader;->opcode:I
  413. invoke-static {v1}, Ljava/lang/Integer;->toHexString(I)Ljava/lang/String;
  414. move-result-object v1
  415. invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  416. invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  417. move-result-object v0
  418. invoke-direct {p1, v0}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  419. throw p1
  420. :cond_2
  421. iget-wide v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameLength:J
  422. iget-wide v2, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  423. sub-long/2addr v0, v2
  424. iget-boolean v2, p0, Lokhttp3/internal/ws/WebSocketReader;->isMasked:Z
  425. const-wide/16 v3, -0x1
  426. if-eqz v2, :cond_4
  427. iget-object v2, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  428. array-length v2, v2
  429. int-to-long v5, v2
  430. invoke-static {v0, v1, v5, v6}, Ljava/lang/Math;->min(JJ)J
  431. move-result-wide v0
  432. iget-object v2, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  433. iget-object v5, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  434. long-to-int v1, v0
  435. const/4 v0, 0x0
  436. invoke-interface {v2, v5, v0, v1}, Lokio/BufferedSource;->read([BII)I
  437. move-result v1
  438. int-to-long v1, v1
  439. cmp-long v5, v1, v3
  440. if-eqz v5, :cond_3
  441. iget-object v5, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  442. iget-object v8, p0, Lokhttp3/internal/ws/WebSocketReader;->maskKey:[B
  443. iget-wide v9, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  444. move-wide v6, v1
  445. invoke-static/range {v5 .. v10}, Lokhttp3/internal/ws/WebSocketProtocol;->toggleMask([BJ[BJ)V
  446. iget-object v3, p0, Lokhttp3/internal/ws/WebSocketReader;->maskBuffer:[B
  447. long-to-int v4, v1
  448. invoke-virtual {p1, v3, v0, v4}, Lokio/Buffer;->write([BII)Lokio/Buffer;
  449. goto :goto_1
  450. :cond_3
  451. new-instance p1, Ljava/io/EOFException;
  452. invoke-direct {p1}, Ljava/io/EOFException;-><init>()V
  453. throw p1
  454. :cond_4
  455. iget-object v2, p0, Lokhttp3/internal/ws/WebSocketReader;->source:Lokio/BufferedSource;
  456. invoke-interface {v2, p1, v0, v1}, Lokio/Source;->read(Lokio/Buffer;J)J
  457. move-result-wide v1
  458. cmp-long v0, v1, v3
  459. if-eqz v0, :cond_5
  460. :goto_1
  461. iget-wide v3, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  462. add-long/2addr v3, v1
  463. iput-wide v3, p0, Lokhttp3/internal/ws/WebSocketReader;->frameBytesRead:J
  464. goto/16 :goto_0
  465. :cond_5
  466. new-instance p1, Ljava/io/EOFException;
  467. invoke-direct {p1}, Ljava/io/EOFException;-><init>()V
  468. throw p1
  469. :cond_6
  470. new-instance p1, Ljava/io/IOException;
  471. const-string v0, "closed"
  472. invoke-direct {p1, v0}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V
  473. goto :goto_3
  474. :goto_2
  475. throw p1
  476. :goto_3
  477. goto :goto_2
  478. .end method
  479. .method private readMessageFrame()V
  480. .locals 4
  481. .annotation system Ldalvik/annotation/Throws;
  482. value = {
  483. Ljava/io/IOException;
  484. }
  485. .end annotation
  486. iget v0, p0, Lokhttp3/internal/ws/WebSocketReader;->opcode:I
  487. const/4 v1, 0x1
  488. if-eq v0, v1, :cond_1
  489. const/4 v2, 0x2
  490. if-ne v0, v2, :cond_0
  491. goto :goto_0
  492. :cond_0
  493. new-instance v1, Ljava/net/ProtocolException;
  494. new-instance v2, Ljava/lang/StringBuilder;
  495. invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V
  496. const-string v3, "Unknown opcode: "
  497. invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  498. invoke-static {v0}, Ljava/lang/Integer;->toHexString(I)Ljava/lang/String;
  499. move-result-object v0
  500. invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  501. invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  502. move-result-object v0
  503. invoke-direct {v1, v0}, Ljava/net/ProtocolException;-><init>(Ljava/lang/String;)V
  504. throw v1
  505. :cond_1
  506. :goto_0
  507. new-instance v2, Lokio/Buffer;
  508. invoke-direct {v2}, Lokio/Buffer;-><init>()V
  509. invoke-direct {p0, v2}, Lokhttp3/internal/ws/WebSocketReader;->readMessage(Lokio/Buffer;)V
  510. if-ne v0, v1, :cond_2
  511. iget-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameCallback:Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  512. invoke-virtual {v2}, Lokio/Buffer;->readUtf8()Ljava/lang/String;
  513. move-result-object v1
  514. invoke-interface {v0, v1}, Lokhttp3/internal/ws/WebSocketReader$FrameCallback;->onReadMessage(Ljava/lang/String;)V
  515. goto :goto_1
  516. :cond_2
  517. iget-object v0, p0, Lokhttp3/internal/ws/WebSocketReader;->frameCallback:Lokhttp3/internal/ws/WebSocketReader$FrameCallback;
  518. invoke-virtual {v2}, Lokio/Buffer;->readByteString()Lokio/ByteString;
  519. move-result-object v1
  520. invoke-interface {v0, v1}, Lokhttp3/internal/ws/WebSocketReader$FrameCallback;->onReadMessage(Lokio/ByteString;)V
  521. :goto_1
  522. return-void
  523. .end method
  524. # virtual methods
  525. .method processNextFrame()V
  526. .locals 1
  527. .annotation system Ldalvik/annotation/Throws;
  528. value = {
  529. Ljava/io/IOException;
  530. }
  531. .end annotation
  532. invoke-direct {p0}, Lokhttp3/internal/ws/WebSocketReader;->readHeader()V
  533. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isControlFrame:Z
  534. if-eqz v0, :cond_0
  535. invoke-direct {p0}, Lokhttp3/internal/ws/WebSocketReader;->readControlFrame()V
  536. goto :goto_0
  537. :cond_0
  538. invoke-direct {p0}, Lokhttp3/internal/ws/WebSocketReader;->readMessageFrame()V
  539. :goto_0
  540. return-void
  541. .end method
  542. .method readUntilNonControlFrame()V
  543. .locals 1
  544. .annotation system Ldalvik/annotation/Throws;
  545. value = {
  546. Ljava/io/IOException;
  547. }
  548. .end annotation
  549. :goto_0
  550. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->closed:Z
  551. if-nez v0, :cond_1
  552. invoke-direct {p0}, Lokhttp3/internal/ws/WebSocketReader;->readHeader()V
  553. iget-boolean v0, p0, Lokhttp3/internal/ws/WebSocketReader;->isControlFrame:Z
  554. if-nez v0, :cond_0
  555. goto :goto_1
  556. :cond_0
  557. invoke-direct {p0}, Lokhttp3/internal/ws/WebSocketReader;->readControlFrame()V
  558. goto :goto_0
  559. :cond_1
  560. :goto_1
  561. return-void
  562. .end method