slidge-whatsapp 0.3.7__cp312-cp312-manylinux_2_41_aarch64.whl → 0.3.8__cp312-cp312-manylinux_2_41_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. slidge_whatsapp/config.py +7 -2
  2. slidge_whatsapp/contact.py +3 -2
  3. slidge_whatsapp/event.go +14 -9
  4. slidge_whatsapp/gateway.go +7 -1
  5. slidge_whatsapp/generated/_whatsapp.cpython-312-aarch64-linux-gnu.h +182 -178
  6. slidge_whatsapp/generated/_whatsapp.cpython-312-aarch64-linux-gnu.so +0 -0
  7. slidge_whatsapp/generated/build.py +146 -142
  8. slidge_whatsapp/generated/whatsapp.c +1456 -1376
  9. slidge_whatsapp/generated/whatsapp.go +1069 -1045
  10. slidge_whatsapp/generated/whatsapp.py +1324 -1298
  11. slidge_whatsapp/generated/whatsapp_go.h +182 -178
  12. slidge_whatsapp/go.mod +6 -6
  13. slidge_whatsapp/go.sum +12 -12
  14. slidge_whatsapp/group.py +25 -0
  15. slidge_whatsapp/session.go +69 -67
  16. slidge_whatsapp/session.py +11 -1
  17. slidge_whatsapp/vendor/github.com/coder/websocket/LICENSE.txt +13 -0
  18. slidge_whatsapp/vendor/github.com/coder/websocket/Makefile +18 -0
  19. slidge_whatsapp/vendor/github.com/coder/websocket/README.md +162 -0
  20. slidge_whatsapp/vendor/github.com/coder/websocket/accept.go +378 -0
  21. slidge_whatsapp/vendor/github.com/coder/websocket/close.go +335 -0
  22. slidge_whatsapp/vendor/github.com/coder/websocket/compress.go +234 -0
  23. slidge_whatsapp/vendor/github.com/coder/websocket/conn.go +306 -0
  24. slidge_whatsapp/vendor/github.com/coder/websocket/dial.go +347 -0
  25. slidge_whatsapp/vendor/github.com/coder/websocket/doc.go +33 -0
  26. slidge_whatsapp/vendor/github.com/coder/websocket/errors.go +8 -0
  27. slidge_whatsapp/vendor/github.com/coder/websocket/frame.go +173 -0
  28. slidge_whatsapp/vendor/github.com/coder/websocket/hijack.go +33 -0
  29. slidge_whatsapp/vendor/github.com/coder/websocket/internal/bpool/bpool.go +25 -0
  30. slidge_whatsapp/vendor/github.com/coder/websocket/internal/errd/wrap.go +14 -0
  31. slidge_whatsapp/vendor/github.com/coder/websocket/internal/util/util.go +15 -0
  32. slidge_whatsapp/vendor/github.com/coder/websocket/internal/wsjs/wsjs_js.go +169 -0
  33. slidge_whatsapp/vendor/github.com/coder/websocket/mask.go +128 -0
  34. slidge_whatsapp/vendor/github.com/coder/websocket/mask_amd64.s +127 -0
  35. slidge_whatsapp/vendor/github.com/coder/websocket/mask_arm64.s +72 -0
  36. slidge_whatsapp/vendor/github.com/coder/websocket/mask_asm.go +26 -0
  37. slidge_whatsapp/vendor/github.com/coder/websocket/mask_go.go +7 -0
  38. slidge_whatsapp/vendor/github.com/coder/websocket/netconn.go +233 -0
  39. slidge_whatsapp/vendor/github.com/coder/websocket/netconn_js.go +11 -0
  40. slidge_whatsapp/vendor/github.com/coder/websocket/netconn_notjs.go +19 -0
  41. slidge_whatsapp/vendor/github.com/coder/websocket/read.go +540 -0
  42. slidge_whatsapp/vendor/github.com/coder/websocket/stringer.go +91 -0
  43. slidge_whatsapp/vendor/github.com/coder/websocket/write.go +384 -0
  44. slidge_whatsapp/vendor/github.com/coder/websocket/ws_js.go +598 -0
  45. slidge_whatsapp/vendor/github.com/ebitengine/purego/func.go +1 -1
  46. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_amd64.go +1 -1
  47. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_arm64.go +3 -1
  48. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_loong64.go +1 -1
  49. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/directive.go +3 -0
  50. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/selection.go +3 -0
  51. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/value.go +4 -3
  52. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/encode.go +3 -0
  53. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate.go +18 -4
  54. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/broadcast.go +3 -3
  55. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/call.go +6 -4
  56. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/client.go +90 -80
  57. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/connectionevents.go +14 -11
  58. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/download.go +4 -1
  59. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/group.go +47 -48
  60. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/handshake.go +3 -2
  61. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/internals.go +79 -75
  62. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/keepalive.go +8 -6
  63. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/mediaconn.go +1 -2
  64. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/mediaretry.go +2 -2
  65. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/message.go +42 -40
  66. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/newsletter.go +35 -32
  67. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/notification.go +2 -3
  68. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair-code.go +2 -4
  69. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair.go +19 -19
  70. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/prekeys.go +9 -8
  71. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/presence.go +9 -9
  72. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/privacysettings.go +4 -5
  73. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloAddMessage/InstamadilloAddMessage.pb.go +1 -1
  74. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeActionLog/InstamadilloCoreTypeActionLog.pb.go +1 -1
  75. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeAdminMessage/InstamadilloCoreTypeAdminMessage.pb.go +1 -1
  76. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeCollection/InstamadilloCoreTypeCollection.pb.go +1 -1
  77. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeLink/InstamadilloCoreTypeLink.pb.go +1 -1
  78. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeMedia/InstamadilloCoreTypeMedia.pb.go +1 -1
  79. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeText/InstamadilloCoreTypeText.pb.go +1 -1
  80. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloDeleteMessage/InstamadilloDeleteMessage.pb.go +1 -1
  81. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloSupplementMessage/InstamadilloSupplementMessage.pb.go +1 -1
  82. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloTransportPayload/InstamadilloTransportPayload.pb.go +1 -1
  83. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloXmaContentRef/InstamadilloXmaContentRef.pb.go +1 -1
  84. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAICommon/WAAICommon.pb.go +1145 -335
  85. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAICommon/WAAICommon.proto +78 -0
  86. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAdv/WAAdv.pb.go +1 -1
  87. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloApplication/WAArmadilloApplication.pb.go +1 -1
  88. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloXMA/WAArmadilloXMA.pb.go +1 -1
  89. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCert/WACert.pb.go +1 -1
  90. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waChatLockSettings/WAProtobufsChatLockSettings.pb.go +1 -1
  91. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCommon/WACommon.pb.go +1 -1
  92. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.pb.go +22 -4
  93. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.proto +2 -0
  94. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waConsumerApplication/WAConsumerApplication.pb.go +1 -1
  95. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.pb.go +104 -30
  96. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.proto +7 -0
  97. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.pb.go +1037 -963
  98. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.proto +15 -8
  99. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.pb.go +1 -1
  100. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waLidMigrationSyncPayload/WAWebProtobufLidMigrationSyncPayload.pb.go +1 -1
  101. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMediaTransport/WAMediaTransport.pb.go +1 -1
  102. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMmsRetry/WAMmsRetry.pb.go +1 -1
  103. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgApplication/WAMsgApplication.pb.go +1 -1
  104. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgTransport/WAMsgTransport.pb.go +1 -1
  105. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMultiDevice/WAMultiDevice.pb.go +1 -1
  106. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waServerSync/WAServerSync.pb.go +1 -1
  107. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.pb.go +40 -35
  108. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.proto +1 -0
  109. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.pb.go +921 -653
  110. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.proto +44 -15
  111. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waUserPassword/WAProtobufsUserPassword.pb.go +1 -1
  112. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waVnameCert/WAWebProtobufsVnameCert.pb.go +1 -1
  113. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.pb.go +9 -5
  114. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.proto +1 -0
  115. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.pb.go +193 -115
  116. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.proto +9 -0
  117. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/push.go +2 -4
  118. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/receipt.go +12 -12
  119. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/request.go +25 -19
  120. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/retry.go +2 -2
  121. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/send.go +43 -27
  122. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/sendfb.go +4 -4
  123. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/constants.go +1 -1
  124. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/framesocket.go +43 -56
  125. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/noisehandshake.go +9 -3
  126. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/noisesocket.go +36 -22
  127. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/clientpayload.go +24 -4
  128. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/store.go +12 -0
  129. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/events/appstate.go +2 -1
  130. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/upload.go +1 -1
  131. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/user.go +79 -40
  132. slidge_whatsapp/vendor/golang.org/x/sys/unix/mkerrors.sh +2 -0
  133. slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_linux.go +6 -0
  134. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux.go +359 -0
  135. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_linux.go +10 -0
  136. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux.go +31 -0
  137. slidge_whatsapp/vendor/golang.org/x/sys/windows/syscall_windows.go +15 -0
  138. slidge_whatsapp/vendor/golang.org/x/sys/windows/types_windows.go +76 -0
  139. slidge_whatsapp/vendor/golang.org/x/sys/windows/zsyscall_windows.go +37 -0
  140. slidge_whatsapp/vendor/modules.txt +12 -8
  141. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/METADATA +1 -1
  142. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/RECORD +145 -136
  143. slidge_whatsapp/vendor/github.com/gorilla/websocket/.gitignore +0 -25
  144. slidge_whatsapp/vendor/github.com/gorilla/websocket/AUTHORS +0 -9
  145. slidge_whatsapp/vendor/github.com/gorilla/websocket/LICENSE +0 -22
  146. slidge_whatsapp/vendor/github.com/gorilla/websocket/README.md +0 -33
  147. slidge_whatsapp/vendor/github.com/gorilla/websocket/client.go +0 -434
  148. slidge_whatsapp/vendor/github.com/gorilla/websocket/compression.go +0 -148
  149. slidge_whatsapp/vendor/github.com/gorilla/websocket/conn.go +0 -1238
  150. slidge_whatsapp/vendor/github.com/gorilla/websocket/doc.go +0 -227
  151. slidge_whatsapp/vendor/github.com/gorilla/websocket/join.go +0 -42
  152. slidge_whatsapp/vendor/github.com/gorilla/websocket/json.go +0 -60
  153. slidge_whatsapp/vendor/github.com/gorilla/websocket/mask.go +0 -55
  154. slidge_whatsapp/vendor/github.com/gorilla/websocket/mask_safe.go +0 -16
  155. slidge_whatsapp/vendor/github.com/gorilla/websocket/prepared.go +0 -102
  156. slidge_whatsapp/vendor/github.com/gorilla/websocket/proxy.go +0 -77
  157. slidge_whatsapp/vendor/github.com/gorilla/websocket/server.go +0 -365
  158. slidge_whatsapp/vendor/github.com/gorilla/websocket/tls_handshake.go +0 -21
  159. slidge_whatsapp/vendor/github.com/gorilla/websocket/tls_handshake_116.go +0 -21
  160. slidge_whatsapp/vendor/github.com/gorilla/websocket/util.go +0 -298
  161. slidge_whatsapp/vendor/github.com/gorilla/websocket/x_net_proxy.go +0 -473
  162. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/WHEEL +0 -0
  163. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/entry_points.txt +0 -0
  164. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,173 @@
1
+ //go:build !js
2
+
3
+ package websocket
4
+
5
+ import (
6
+ "bufio"
7
+ "encoding/binary"
8
+ "fmt"
9
+ "io"
10
+ "math"
11
+
12
+ "github.com/coder/websocket/internal/errd"
13
+ )
14
+
15
+ // opcode represents a WebSocket opcode.
16
+ type opcode int
17
+
18
+ // https://tools.ietf.org/html/rfc6455#section-11.8.
19
+ const (
20
+ opContinuation opcode = iota
21
+ opText
22
+ opBinary
23
+ // 3 - 7 are reserved for further non-control frames.
24
+ _
25
+ _
26
+ _
27
+ _
28
+ _
29
+ opClose
30
+ opPing
31
+ opPong
32
+ // 11-16 are reserved for further control frames.
33
+ )
34
+
35
+ // header represents a WebSocket frame header.
36
+ // See https://tools.ietf.org/html/rfc6455#section-5.2.
37
+ type header struct {
38
+ fin bool
39
+ rsv1 bool
40
+ rsv2 bool
41
+ rsv3 bool
42
+ opcode opcode
43
+
44
+ payloadLength int64
45
+
46
+ masked bool
47
+ maskKey uint32
48
+ }
49
+
50
+ // readFrameHeader reads a header from the reader.
51
+ // See https://tools.ietf.org/html/rfc6455#section-5.2.
52
+ func readFrameHeader(r *bufio.Reader, readBuf []byte) (h header, err error) {
53
+ defer errd.Wrap(&err, "failed to read frame header")
54
+
55
+ b, err := r.ReadByte()
56
+ if err != nil {
57
+ return header{}, err
58
+ }
59
+
60
+ h.fin = b&(1<<7) != 0
61
+ h.rsv1 = b&(1<<6) != 0
62
+ h.rsv2 = b&(1<<5) != 0
63
+ h.rsv3 = b&(1<<4) != 0
64
+
65
+ h.opcode = opcode(b & 0xf)
66
+
67
+ b, err = r.ReadByte()
68
+ if err != nil {
69
+ return header{}, err
70
+ }
71
+
72
+ h.masked = b&(1<<7) != 0
73
+
74
+ payloadLength := b &^ (1 << 7)
75
+ switch {
76
+ case payloadLength < 126:
77
+ h.payloadLength = int64(payloadLength)
78
+ case payloadLength == 126:
79
+ _, err = io.ReadFull(r, readBuf[:2])
80
+ h.payloadLength = int64(binary.BigEndian.Uint16(readBuf))
81
+ case payloadLength == 127:
82
+ _, err = io.ReadFull(r, readBuf)
83
+ h.payloadLength = int64(binary.BigEndian.Uint64(readBuf))
84
+ }
85
+ if err != nil {
86
+ return header{}, err
87
+ }
88
+
89
+ if h.payloadLength < 0 {
90
+ return header{}, fmt.Errorf("received negative payload length: %v", h.payloadLength)
91
+ }
92
+
93
+ if h.masked {
94
+ _, err = io.ReadFull(r, readBuf[:4])
95
+ if err != nil {
96
+ return header{}, err
97
+ }
98
+ h.maskKey = binary.LittleEndian.Uint32(readBuf)
99
+ }
100
+
101
+ return h, nil
102
+ }
103
+
104
+ // maxControlPayload is the maximum length of a control frame payload.
105
+ // See https://tools.ietf.org/html/rfc6455#section-5.5.
106
+ const maxControlPayload = 125
107
+
108
+ // writeFrameHeader writes the bytes of the header to w.
109
+ // See https://tools.ietf.org/html/rfc6455#section-5.2
110
+ func writeFrameHeader(h header, w *bufio.Writer, buf []byte) (err error) {
111
+ defer errd.Wrap(&err, "failed to write frame header")
112
+
113
+ var b byte
114
+ if h.fin {
115
+ b |= 1 << 7
116
+ }
117
+ if h.rsv1 {
118
+ b |= 1 << 6
119
+ }
120
+ if h.rsv2 {
121
+ b |= 1 << 5
122
+ }
123
+ if h.rsv3 {
124
+ b |= 1 << 4
125
+ }
126
+
127
+ b |= byte(h.opcode)
128
+
129
+ err = w.WriteByte(b)
130
+ if err != nil {
131
+ return err
132
+ }
133
+
134
+ lengthByte := byte(0)
135
+ if h.masked {
136
+ lengthByte |= 1 << 7
137
+ }
138
+
139
+ switch {
140
+ case h.payloadLength > math.MaxUint16:
141
+ lengthByte |= 127
142
+ case h.payloadLength > 125:
143
+ lengthByte |= 126
144
+ case h.payloadLength >= 0:
145
+ lengthByte |= byte(h.payloadLength)
146
+ }
147
+ err = w.WriteByte(lengthByte)
148
+ if err != nil {
149
+ return err
150
+ }
151
+
152
+ switch {
153
+ case h.payloadLength > math.MaxUint16:
154
+ binary.BigEndian.PutUint64(buf, uint64(h.payloadLength))
155
+ _, err = w.Write(buf)
156
+ case h.payloadLength > 125:
157
+ binary.BigEndian.PutUint16(buf, uint16(h.payloadLength))
158
+ _, err = w.Write(buf[:2])
159
+ }
160
+ if err != nil {
161
+ return err
162
+ }
163
+
164
+ if h.masked {
165
+ binary.LittleEndian.PutUint32(buf, h.maskKey)
166
+ _, err = w.Write(buf[:4])
167
+ if err != nil {
168
+ return err
169
+ }
170
+ }
171
+
172
+ return nil
173
+ }
@@ -0,0 +1,33 @@
1
+ //go:build !js
2
+
3
+ package websocket
4
+
5
+ import (
6
+ "net/http"
7
+ )
8
+
9
+ type rwUnwrapper interface {
10
+ Unwrap() http.ResponseWriter
11
+ }
12
+
13
+ // hijacker returns the Hijacker interface of the http.ResponseWriter.
14
+ // It follows the Unwrap method of the http.ResponseWriter if available,
15
+ // matching the behavior of http.ResponseController. If the Hijacker
16
+ // interface is not found, it returns false.
17
+ //
18
+ // Since the http.ResponseController is not available in Go 1.19, and
19
+ // does not support checking the presence of the Hijacker interface,
20
+ // this function is used to provide a consistent way to check for the
21
+ // Hijacker interface across Go versions.
22
+ func hijacker(rw http.ResponseWriter) (http.Hijacker, bool) {
23
+ for {
24
+ switch t := rw.(type) {
25
+ case http.Hijacker:
26
+ return t, true
27
+ case rwUnwrapper:
28
+ rw = t.Unwrap()
29
+ default:
30
+ return nil, false
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,25 @@
1
+ package bpool
2
+
3
+ import (
4
+ "bytes"
5
+ "sync"
6
+ )
7
+
8
+ var bpool = sync.Pool{
9
+ New: func() any {
10
+ return &bytes.Buffer{}
11
+ },
12
+ }
13
+
14
+ // Get returns a buffer from the pool or creates a new one if
15
+ // the pool is empty.
16
+ func Get() *bytes.Buffer {
17
+ b := bpool.Get()
18
+ return b.(*bytes.Buffer)
19
+ }
20
+
21
+ // Put returns a buffer into the pool.
22
+ func Put(b *bytes.Buffer) {
23
+ b.Reset()
24
+ bpool.Put(b)
25
+ }
@@ -0,0 +1,14 @@
1
+ package errd
2
+
3
+ import (
4
+ "fmt"
5
+ )
6
+
7
+ // Wrap wraps err with fmt.Errorf if err is non nil.
8
+ // Intended for use with defer and a named error return.
9
+ // Inspired by https://github.com/golang/go/issues/32676.
10
+ func Wrap(err *error, f string, v ...any) {
11
+ if *err != nil {
12
+ *err = fmt.Errorf(f+": %w", append(v, *err)...)
13
+ }
14
+ }
@@ -0,0 +1,15 @@
1
+ package util
2
+
3
+ // WriterFunc is used to implement one off io.Writers.
4
+ type WriterFunc func(p []byte) (int, error)
5
+
6
+ func (f WriterFunc) Write(p []byte) (int, error) {
7
+ return f(p)
8
+ }
9
+
10
+ // ReaderFunc is used to implement one off io.Readers.
11
+ type ReaderFunc func(p []byte) (int, error)
12
+
13
+ func (f ReaderFunc) Read(p []byte) (int, error) {
14
+ return f(p)
15
+ }
@@ -0,0 +1,169 @@
1
+ //go:build js
2
+ // +build js
3
+
4
+ // Package wsjs implements typed access to the browser javascript WebSocket API.
5
+ //
6
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
7
+ package wsjs
8
+
9
+ import (
10
+ "syscall/js"
11
+ )
12
+
13
+ func handleJSError(err *error, onErr func()) {
14
+ r := recover()
15
+
16
+ if jsErr, ok := r.(js.Error); ok {
17
+ *err = jsErr
18
+
19
+ if onErr != nil {
20
+ onErr()
21
+ }
22
+ return
23
+ }
24
+
25
+ if r != nil {
26
+ panic(r)
27
+ }
28
+ }
29
+
30
+ // New is a wrapper around the javascript WebSocket constructor.
31
+ func New(url string, protocols []string) (c WebSocket, err error) {
32
+ defer handleJSError(&err, func() {
33
+ c = WebSocket{}
34
+ })
35
+
36
+ jsProtocols := make([]any, len(protocols))
37
+ for i, p := range protocols {
38
+ jsProtocols[i] = p
39
+ }
40
+
41
+ c = WebSocket{
42
+ v: js.Global().Get("WebSocket").New(url, jsProtocols),
43
+ }
44
+
45
+ c.setBinaryType("arraybuffer")
46
+
47
+ return c, nil
48
+ }
49
+
50
+ // WebSocket is a wrapper around a javascript WebSocket object.
51
+ type WebSocket struct {
52
+ v js.Value
53
+ }
54
+
55
+ func (c WebSocket) setBinaryType(typ string) {
56
+ c.v.Set("binaryType", string(typ))
57
+ }
58
+
59
+ func (c WebSocket) addEventListener(eventType string, fn func(e js.Value)) func() {
60
+ f := js.FuncOf(func(this js.Value, args []js.Value) any {
61
+ fn(args[0])
62
+ return nil
63
+ })
64
+ c.v.Call("addEventListener", eventType, f)
65
+
66
+ return func() {
67
+ c.v.Call("removeEventListener", eventType, f)
68
+ f.Release()
69
+ }
70
+ }
71
+
72
+ // CloseEvent is the type passed to a WebSocket close handler.
73
+ type CloseEvent struct {
74
+ Code uint16
75
+ Reason string
76
+ WasClean bool
77
+ }
78
+
79
+ // OnClose registers a function to be called when the WebSocket is closed.
80
+ func (c WebSocket) OnClose(fn func(CloseEvent)) (remove func()) {
81
+ return c.addEventListener("close", func(e js.Value) {
82
+ ce := CloseEvent{
83
+ Code: uint16(e.Get("code").Int()),
84
+ Reason: e.Get("reason").String(),
85
+ WasClean: e.Get("wasClean").Bool(),
86
+ }
87
+ fn(ce)
88
+ })
89
+ }
90
+
91
+ // OnError registers a function to be called when there is an error
92
+ // with the WebSocket.
93
+ func (c WebSocket) OnError(fn func(e js.Value)) (remove func()) {
94
+ return c.addEventListener("error", fn)
95
+ }
96
+
97
+ // MessageEvent is the type passed to a message handler.
98
+ type MessageEvent struct {
99
+ // string or []byte.
100
+ Data any
101
+
102
+ // There are more fields to the interface but we don't use them.
103
+ // See https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
104
+ }
105
+
106
+ // OnMessage registers a function to be called when the WebSocket receives a message.
107
+ func (c WebSocket) OnMessage(fn func(m MessageEvent)) (remove func()) {
108
+ return c.addEventListener("message", func(e js.Value) {
109
+ var data any
110
+
111
+ arrayBuffer := e.Get("data")
112
+ if arrayBuffer.Type() == js.TypeString {
113
+ data = arrayBuffer.String()
114
+ } else {
115
+ data = extractArrayBuffer(arrayBuffer)
116
+ }
117
+
118
+ me := MessageEvent{
119
+ Data: data,
120
+ }
121
+ fn(me)
122
+ })
123
+ }
124
+
125
+ // Subprotocol returns the WebSocket subprotocol in use.
126
+ func (c WebSocket) Subprotocol() string {
127
+ return c.v.Get("protocol").String()
128
+ }
129
+
130
+ // OnOpen registers a function to be called when the WebSocket is opened.
131
+ func (c WebSocket) OnOpen(fn func(e js.Value)) (remove func()) {
132
+ return c.addEventListener("open", fn)
133
+ }
134
+
135
+ // Close closes the WebSocket with the given code and reason.
136
+ func (c WebSocket) Close(code int, reason string) (err error) {
137
+ defer handleJSError(&err, nil)
138
+ c.v.Call("close", code, reason)
139
+ return err
140
+ }
141
+
142
+ // SendText sends the given string as a text message
143
+ // on the WebSocket.
144
+ func (c WebSocket) SendText(v string) (err error) {
145
+ defer handleJSError(&err, nil)
146
+ c.v.Call("send", v)
147
+ return err
148
+ }
149
+
150
+ // SendBytes sends the given message as a binary message
151
+ // on the WebSocket.
152
+ func (c WebSocket) SendBytes(v []byte) (err error) {
153
+ defer handleJSError(&err, nil)
154
+ c.v.Call("send", uint8Array(v))
155
+ return err
156
+ }
157
+
158
+ func extractArrayBuffer(arrayBuffer js.Value) []byte {
159
+ uint8Array := js.Global().Get("Uint8Array").New(arrayBuffer)
160
+ dst := make([]byte, uint8Array.Length())
161
+ js.CopyBytesToGo(dst, uint8Array)
162
+ return dst
163
+ }
164
+
165
+ func uint8Array(src []byte) js.Value {
166
+ uint8Array := js.Global().Get("Uint8Array").New(len(src))
167
+ js.CopyBytesToJS(uint8Array, src)
168
+ return uint8Array
169
+ }
@@ -0,0 +1,128 @@
1
+ package websocket
2
+
3
+ import (
4
+ "encoding/binary"
5
+ "math/bits"
6
+ )
7
+
8
+ // maskGo applies the WebSocket masking algorithm to p
9
+ // with the given key.
10
+ // See https://tools.ietf.org/html/rfc6455#section-5.3
11
+ //
12
+ // The returned value is the correctly rotated key to
13
+ // to continue to mask/unmask the message.
14
+ //
15
+ // It is optimized for LittleEndian and expects the key
16
+ // to be in little endian.
17
+ //
18
+ // See https://github.com/golang/go/issues/31586
19
+ func maskGo(b []byte, key uint32) uint32 {
20
+ if len(b) >= 8 {
21
+ key64 := uint64(key)<<32 | uint64(key)
22
+
23
+ // At some point in the future we can clean these unrolled loops up.
24
+ // See https://github.com/golang/go/issues/31586#issuecomment-487436401
25
+
26
+ // Then we xor until b is less than 128 bytes.
27
+ for len(b) >= 128 {
28
+ v := binary.LittleEndian.Uint64(b)
29
+ binary.LittleEndian.PutUint64(b, v^key64)
30
+ v = binary.LittleEndian.Uint64(b[8:16])
31
+ binary.LittleEndian.PutUint64(b[8:16], v^key64)
32
+ v = binary.LittleEndian.Uint64(b[16:24])
33
+ binary.LittleEndian.PutUint64(b[16:24], v^key64)
34
+ v = binary.LittleEndian.Uint64(b[24:32])
35
+ binary.LittleEndian.PutUint64(b[24:32], v^key64)
36
+ v = binary.LittleEndian.Uint64(b[32:40])
37
+ binary.LittleEndian.PutUint64(b[32:40], v^key64)
38
+ v = binary.LittleEndian.Uint64(b[40:48])
39
+ binary.LittleEndian.PutUint64(b[40:48], v^key64)
40
+ v = binary.LittleEndian.Uint64(b[48:56])
41
+ binary.LittleEndian.PutUint64(b[48:56], v^key64)
42
+ v = binary.LittleEndian.Uint64(b[56:64])
43
+ binary.LittleEndian.PutUint64(b[56:64], v^key64)
44
+ v = binary.LittleEndian.Uint64(b[64:72])
45
+ binary.LittleEndian.PutUint64(b[64:72], v^key64)
46
+ v = binary.LittleEndian.Uint64(b[72:80])
47
+ binary.LittleEndian.PutUint64(b[72:80], v^key64)
48
+ v = binary.LittleEndian.Uint64(b[80:88])
49
+ binary.LittleEndian.PutUint64(b[80:88], v^key64)
50
+ v = binary.LittleEndian.Uint64(b[88:96])
51
+ binary.LittleEndian.PutUint64(b[88:96], v^key64)
52
+ v = binary.LittleEndian.Uint64(b[96:104])
53
+ binary.LittleEndian.PutUint64(b[96:104], v^key64)
54
+ v = binary.LittleEndian.Uint64(b[104:112])
55
+ binary.LittleEndian.PutUint64(b[104:112], v^key64)
56
+ v = binary.LittleEndian.Uint64(b[112:120])
57
+ binary.LittleEndian.PutUint64(b[112:120], v^key64)
58
+ v = binary.LittleEndian.Uint64(b[120:128])
59
+ binary.LittleEndian.PutUint64(b[120:128], v^key64)
60
+ b = b[128:]
61
+ }
62
+
63
+ // Then we xor until b is less than 64 bytes.
64
+ for len(b) >= 64 {
65
+ v := binary.LittleEndian.Uint64(b)
66
+ binary.LittleEndian.PutUint64(b, v^key64)
67
+ v = binary.LittleEndian.Uint64(b[8:16])
68
+ binary.LittleEndian.PutUint64(b[8:16], v^key64)
69
+ v = binary.LittleEndian.Uint64(b[16:24])
70
+ binary.LittleEndian.PutUint64(b[16:24], v^key64)
71
+ v = binary.LittleEndian.Uint64(b[24:32])
72
+ binary.LittleEndian.PutUint64(b[24:32], v^key64)
73
+ v = binary.LittleEndian.Uint64(b[32:40])
74
+ binary.LittleEndian.PutUint64(b[32:40], v^key64)
75
+ v = binary.LittleEndian.Uint64(b[40:48])
76
+ binary.LittleEndian.PutUint64(b[40:48], v^key64)
77
+ v = binary.LittleEndian.Uint64(b[48:56])
78
+ binary.LittleEndian.PutUint64(b[48:56], v^key64)
79
+ v = binary.LittleEndian.Uint64(b[56:64])
80
+ binary.LittleEndian.PutUint64(b[56:64], v^key64)
81
+ b = b[64:]
82
+ }
83
+
84
+ // Then we xor until b is less than 32 bytes.
85
+ for len(b) >= 32 {
86
+ v := binary.LittleEndian.Uint64(b)
87
+ binary.LittleEndian.PutUint64(b, v^key64)
88
+ v = binary.LittleEndian.Uint64(b[8:16])
89
+ binary.LittleEndian.PutUint64(b[8:16], v^key64)
90
+ v = binary.LittleEndian.Uint64(b[16:24])
91
+ binary.LittleEndian.PutUint64(b[16:24], v^key64)
92
+ v = binary.LittleEndian.Uint64(b[24:32])
93
+ binary.LittleEndian.PutUint64(b[24:32], v^key64)
94
+ b = b[32:]
95
+ }
96
+
97
+ // Then we xor until b is less than 16 bytes.
98
+ for len(b) >= 16 {
99
+ v := binary.LittleEndian.Uint64(b)
100
+ binary.LittleEndian.PutUint64(b, v^key64)
101
+ v = binary.LittleEndian.Uint64(b[8:16])
102
+ binary.LittleEndian.PutUint64(b[8:16], v^key64)
103
+ b = b[16:]
104
+ }
105
+
106
+ // Then we xor until b is less than 8 bytes.
107
+ for len(b) >= 8 {
108
+ v := binary.LittleEndian.Uint64(b)
109
+ binary.LittleEndian.PutUint64(b, v^key64)
110
+ b = b[8:]
111
+ }
112
+ }
113
+
114
+ // Then we xor until b is less than 4 bytes.
115
+ for len(b) >= 4 {
116
+ v := binary.LittleEndian.Uint32(b)
117
+ binary.LittleEndian.PutUint32(b, v^key)
118
+ b = b[4:]
119
+ }
120
+
121
+ // xor remaining bytes.
122
+ for i := range b {
123
+ b[i] ^= byte(key)
124
+ key = bits.RotateLeft32(key, -8)
125
+ }
126
+
127
+ return key
128
+ }
@@ -0,0 +1,127 @@
1
+ #include "textflag.h"
2
+
3
+ // func maskAsm(b *byte, len int, key uint32)
4
+ TEXT ·maskAsm(SB), NOSPLIT, $0-28
5
+ // AX = b
6
+ // CX = len (left length)
7
+ // SI = key (uint32)
8
+ // DI = uint64(SI) | uint64(SI)<<32
9
+ MOVQ b+0(FP), AX
10
+ MOVQ len+8(FP), CX
11
+ MOVL key+16(FP), SI
12
+
13
+ // calculate the DI
14
+ // DI = SI<<32 | SI
15
+ MOVL SI, DI
16
+ MOVQ DI, DX
17
+ SHLQ $32, DI
18
+ ORQ DX, DI
19
+
20
+ CMPQ CX, $15
21
+ JLE less_than_16
22
+ CMPQ CX, $63
23
+ JLE less_than_64
24
+ CMPQ CX, $128
25
+ JLE sse
26
+ TESTQ $31, AX
27
+ JNZ unaligned
28
+
29
+ unaligned_loop_1byte:
30
+ XORB SI, (AX)
31
+ INCQ AX
32
+ DECQ CX
33
+ ROLL $24, SI
34
+ TESTQ $7, AX
35
+ JNZ unaligned_loop_1byte
36
+
37
+ // calculate DI again since SI was modified
38
+ // DI = SI<<32 | SI
39
+ MOVL SI, DI
40
+ MOVQ DI, DX
41
+ SHLQ $32, DI
42
+ ORQ DX, DI
43
+
44
+ TESTQ $31, AX
45
+ JZ sse
46
+
47
+ unaligned:
48
+ TESTQ $7, AX // AND $7 & len, if not zero jump to loop_1b.
49
+ JNZ unaligned_loop_1byte
50
+
51
+ unaligned_loop:
52
+ // we don't need to check the CX since we know it's above 128
53
+ XORQ DI, (AX)
54
+ ADDQ $8, AX
55
+ SUBQ $8, CX
56
+ TESTQ $31, AX
57
+ JNZ unaligned_loop
58
+ JMP sse
59
+
60
+ sse:
61
+ CMPQ CX, $0x40
62
+ JL less_than_64
63
+ MOVQ DI, X0
64
+ PUNPCKLQDQ X0, X0
65
+
66
+ sse_loop:
67
+ MOVOU 0*16(AX), X1
68
+ MOVOU 1*16(AX), X2
69
+ MOVOU 2*16(AX), X3
70
+ MOVOU 3*16(AX), X4
71
+ PXOR X0, X1
72
+ PXOR X0, X2
73
+ PXOR X0, X3
74
+ PXOR X0, X4
75
+ MOVOU X1, 0*16(AX)
76
+ MOVOU X2, 1*16(AX)
77
+ MOVOU X3, 2*16(AX)
78
+ MOVOU X4, 3*16(AX)
79
+ ADDQ $0x40, AX
80
+ SUBQ $0x40, CX
81
+ CMPQ CX, $0x40
82
+ JAE sse_loop
83
+
84
+ less_than_64:
85
+ TESTQ $32, CX
86
+ JZ less_than_32
87
+ XORQ DI, (AX)
88
+ XORQ DI, 8(AX)
89
+ XORQ DI, 16(AX)
90
+ XORQ DI, 24(AX)
91
+ ADDQ $32, AX
92
+
93
+ less_than_32:
94
+ TESTQ $16, CX
95
+ JZ less_than_16
96
+ XORQ DI, (AX)
97
+ XORQ DI, 8(AX)
98
+ ADDQ $16, AX
99
+
100
+ less_than_16:
101
+ TESTQ $8, CX
102
+ JZ less_than_8
103
+ XORQ DI, (AX)
104
+ ADDQ $8, AX
105
+
106
+ less_than_8:
107
+ TESTQ $4, CX
108
+ JZ less_than_4
109
+ XORL SI, (AX)
110
+ ADDQ $4, AX
111
+
112
+ less_than_4:
113
+ TESTQ $2, CX
114
+ JZ less_than_2
115
+ XORW SI, (AX)
116
+ ROLL $16, SI
117
+ ADDQ $2, AX
118
+
119
+ less_than_2:
120
+ TESTQ $1, CX
121
+ JZ done
122
+ XORB SI, (AX)
123
+ ROLL $24, SI
124
+
125
+ done:
126
+ MOVL SI, ret+24(FP)
127
+ RET