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
@@ -1,473 +0,0 @@
1
- // Code generated by golang.org/x/tools/cmd/bundle. DO NOT EDIT.
2
- //go:generate bundle -o x_net_proxy.go golang.org/x/net/proxy
3
-
4
- // Package proxy provides support for a variety of protocols to proxy network
5
- // data.
6
- //
7
-
8
- package websocket
9
-
10
- import (
11
- "errors"
12
- "io"
13
- "net"
14
- "net/url"
15
- "os"
16
- "strconv"
17
- "strings"
18
- "sync"
19
- )
20
-
21
- type proxy_direct struct{}
22
-
23
- // Direct is a direct proxy: one that makes network connections directly.
24
- var proxy_Direct = proxy_direct{}
25
-
26
- func (proxy_direct) Dial(network, addr string) (net.Conn, error) {
27
- return net.Dial(network, addr)
28
- }
29
-
30
- // A PerHost directs connections to a default Dialer unless the host name
31
- // requested matches one of a number of exceptions.
32
- type proxy_PerHost struct {
33
- def, bypass proxy_Dialer
34
-
35
- bypassNetworks []*net.IPNet
36
- bypassIPs []net.IP
37
- bypassZones []string
38
- bypassHosts []string
39
- }
40
-
41
- // NewPerHost returns a PerHost Dialer that directs connections to either
42
- // defaultDialer or bypass, depending on whether the connection matches one of
43
- // the configured rules.
44
- func proxy_NewPerHost(defaultDialer, bypass proxy_Dialer) *proxy_PerHost {
45
- return &proxy_PerHost{
46
- def: defaultDialer,
47
- bypass: bypass,
48
- }
49
- }
50
-
51
- // Dial connects to the address addr on the given network through either
52
- // defaultDialer or bypass.
53
- func (p *proxy_PerHost) Dial(network, addr string) (c net.Conn, err error) {
54
- host, _, err := net.SplitHostPort(addr)
55
- if err != nil {
56
- return nil, err
57
- }
58
-
59
- return p.dialerForRequest(host).Dial(network, addr)
60
- }
61
-
62
- func (p *proxy_PerHost) dialerForRequest(host string) proxy_Dialer {
63
- if ip := net.ParseIP(host); ip != nil {
64
- for _, net := range p.bypassNetworks {
65
- if net.Contains(ip) {
66
- return p.bypass
67
- }
68
- }
69
- for _, bypassIP := range p.bypassIPs {
70
- if bypassIP.Equal(ip) {
71
- return p.bypass
72
- }
73
- }
74
- return p.def
75
- }
76
-
77
- for _, zone := range p.bypassZones {
78
- if strings.HasSuffix(host, zone) {
79
- return p.bypass
80
- }
81
- if host == zone[1:] {
82
- // For a zone ".example.com", we match "example.com"
83
- // too.
84
- return p.bypass
85
- }
86
- }
87
- for _, bypassHost := range p.bypassHosts {
88
- if bypassHost == host {
89
- return p.bypass
90
- }
91
- }
92
- return p.def
93
- }
94
-
95
- // AddFromString parses a string that contains comma-separated values
96
- // specifying hosts that should use the bypass proxy. Each value is either an
97
- // IP address, a CIDR range, a zone (*.example.com) or a host name
98
- // (localhost). A best effort is made to parse the string and errors are
99
- // ignored.
100
- func (p *proxy_PerHost) AddFromString(s string) {
101
- hosts := strings.Split(s, ",")
102
- for _, host := range hosts {
103
- host = strings.TrimSpace(host)
104
- if len(host) == 0 {
105
- continue
106
- }
107
- if strings.Contains(host, "/") {
108
- // We assume that it's a CIDR address like 127.0.0.0/8
109
- if _, net, err := net.ParseCIDR(host); err == nil {
110
- p.AddNetwork(net)
111
- }
112
- continue
113
- }
114
- if ip := net.ParseIP(host); ip != nil {
115
- p.AddIP(ip)
116
- continue
117
- }
118
- if strings.HasPrefix(host, "*.") {
119
- p.AddZone(host[1:])
120
- continue
121
- }
122
- p.AddHost(host)
123
- }
124
- }
125
-
126
- // AddIP specifies an IP address that will use the bypass proxy. Note that
127
- // this will only take effect if a literal IP address is dialed. A connection
128
- // to a named host will never match an IP.
129
- func (p *proxy_PerHost) AddIP(ip net.IP) {
130
- p.bypassIPs = append(p.bypassIPs, ip)
131
- }
132
-
133
- // AddNetwork specifies an IP range that will use the bypass proxy. Note that
134
- // this will only take effect if a literal IP address is dialed. A connection
135
- // to a named host will never match.
136
- func (p *proxy_PerHost) AddNetwork(net *net.IPNet) {
137
- p.bypassNetworks = append(p.bypassNetworks, net)
138
- }
139
-
140
- // AddZone specifies a DNS suffix that will use the bypass proxy. A zone of
141
- // "example.com" matches "example.com" and all of its subdomains.
142
- func (p *proxy_PerHost) AddZone(zone string) {
143
- if strings.HasSuffix(zone, ".") {
144
- zone = zone[:len(zone)-1]
145
- }
146
- if !strings.HasPrefix(zone, ".") {
147
- zone = "." + zone
148
- }
149
- p.bypassZones = append(p.bypassZones, zone)
150
- }
151
-
152
- // AddHost specifies a host name that will use the bypass proxy.
153
- func (p *proxy_PerHost) AddHost(host string) {
154
- if strings.HasSuffix(host, ".") {
155
- host = host[:len(host)-1]
156
- }
157
- p.bypassHosts = append(p.bypassHosts, host)
158
- }
159
-
160
- // A Dialer is a means to establish a connection.
161
- type proxy_Dialer interface {
162
- // Dial connects to the given address via the proxy.
163
- Dial(network, addr string) (c net.Conn, err error)
164
- }
165
-
166
- // Auth contains authentication parameters that specific Dialers may require.
167
- type proxy_Auth struct {
168
- User, Password string
169
- }
170
-
171
- // FromEnvironment returns the dialer specified by the proxy related variables in
172
- // the environment.
173
- func proxy_FromEnvironment() proxy_Dialer {
174
- allProxy := proxy_allProxyEnv.Get()
175
- if len(allProxy) == 0 {
176
- return proxy_Direct
177
- }
178
-
179
- proxyURL, err := url.Parse(allProxy)
180
- if err != nil {
181
- return proxy_Direct
182
- }
183
- proxy, err := proxy_FromURL(proxyURL, proxy_Direct)
184
- if err != nil {
185
- return proxy_Direct
186
- }
187
-
188
- noProxy := proxy_noProxyEnv.Get()
189
- if len(noProxy) == 0 {
190
- return proxy
191
- }
192
-
193
- perHost := proxy_NewPerHost(proxy, proxy_Direct)
194
- perHost.AddFromString(noProxy)
195
- return perHost
196
- }
197
-
198
- // proxySchemes is a map from URL schemes to a function that creates a Dialer
199
- // from a URL with such a scheme.
200
- var proxy_proxySchemes map[string]func(*url.URL, proxy_Dialer) (proxy_Dialer, error)
201
-
202
- // RegisterDialerType takes a URL scheme and a function to generate Dialers from
203
- // a URL with that scheme and a forwarding Dialer. Registered schemes are used
204
- // by FromURL.
205
- func proxy_RegisterDialerType(scheme string, f func(*url.URL, proxy_Dialer) (proxy_Dialer, error)) {
206
- if proxy_proxySchemes == nil {
207
- proxy_proxySchemes = make(map[string]func(*url.URL, proxy_Dialer) (proxy_Dialer, error))
208
- }
209
- proxy_proxySchemes[scheme] = f
210
- }
211
-
212
- // FromURL returns a Dialer given a URL specification and an underlying
213
- // Dialer for it to make network requests.
214
- func proxy_FromURL(u *url.URL, forward proxy_Dialer) (proxy_Dialer, error) {
215
- var auth *proxy_Auth
216
- if u.User != nil {
217
- auth = new(proxy_Auth)
218
- auth.User = u.User.Username()
219
- if p, ok := u.User.Password(); ok {
220
- auth.Password = p
221
- }
222
- }
223
-
224
- switch u.Scheme {
225
- case "socks5":
226
- return proxy_SOCKS5("tcp", u.Host, auth, forward)
227
- }
228
-
229
- // If the scheme doesn't match any of the built-in schemes, see if it
230
- // was registered by another package.
231
- if proxy_proxySchemes != nil {
232
- if f, ok := proxy_proxySchemes[u.Scheme]; ok {
233
- return f(u, forward)
234
- }
235
- }
236
-
237
- return nil, errors.New("proxy: unknown scheme: " + u.Scheme)
238
- }
239
-
240
- var (
241
- proxy_allProxyEnv = &proxy_envOnce{
242
- names: []string{"ALL_PROXY", "all_proxy"},
243
- }
244
- proxy_noProxyEnv = &proxy_envOnce{
245
- names: []string{"NO_PROXY", "no_proxy"},
246
- }
247
- )
248
-
249
- // envOnce looks up an environment variable (optionally by multiple
250
- // names) once. It mitigates expensive lookups on some platforms
251
- // (e.g. Windows).
252
- // (Borrowed from net/http/transport.go)
253
- type proxy_envOnce struct {
254
- names []string
255
- once sync.Once
256
- val string
257
- }
258
-
259
- func (e *proxy_envOnce) Get() string {
260
- e.once.Do(e.init)
261
- return e.val
262
- }
263
-
264
- func (e *proxy_envOnce) init() {
265
- for _, n := range e.names {
266
- e.val = os.Getenv(n)
267
- if e.val != "" {
268
- return
269
- }
270
- }
271
- }
272
-
273
- // SOCKS5 returns a Dialer that makes SOCKSv5 connections to the given address
274
- // with an optional username and password. See RFC 1928 and RFC 1929.
275
- func proxy_SOCKS5(network, addr string, auth *proxy_Auth, forward proxy_Dialer) (proxy_Dialer, error) {
276
- s := &proxy_socks5{
277
- network: network,
278
- addr: addr,
279
- forward: forward,
280
- }
281
- if auth != nil {
282
- s.user = auth.User
283
- s.password = auth.Password
284
- }
285
-
286
- return s, nil
287
- }
288
-
289
- type proxy_socks5 struct {
290
- user, password string
291
- network, addr string
292
- forward proxy_Dialer
293
- }
294
-
295
- const proxy_socks5Version = 5
296
-
297
- const (
298
- proxy_socks5AuthNone = 0
299
- proxy_socks5AuthPassword = 2
300
- )
301
-
302
- const proxy_socks5Connect = 1
303
-
304
- const (
305
- proxy_socks5IP4 = 1
306
- proxy_socks5Domain = 3
307
- proxy_socks5IP6 = 4
308
- )
309
-
310
- var proxy_socks5Errors = []string{
311
- "",
312
- "general failure",
313
- "connection forbidden",
314
- "network unreachable",
315
- "host unreachable",
316
- "connection refused",
317
- "TTL expired",
318
- "command not supported",
319
- "address type not supported",
320
- }
321
-
322
- // Dial connects to the address addr on the given network via the SOCKS5 proxy.
323
- func (s *proxy_socks5) Dial(network, addr string) (net.Conn, error) {
324
- switch network {
325
- case "tcp", "tcp6", "tcp4":
326
- default:
327
- return nil, errors.New("proxy: no support for SOCKS5 proxy connections of type " + network)
328
- }
329
-
330
- conn, err := s.forward.Dial(s.network, s.addr)
331
- if err != nil {
332
- return nil, err
333
- }
334
- if err := s.connect(conn, addr); err != nil {
335
- conn.Close()
336
- return nil, err
337
- }
338
- return conn, nil
339
- }
340
-
341
- // connect takes an existing connection to a socks5 proxy server,
342
- // and commands the server to extend that connection to target,
343
- // which must be a canonical address with a host and port.
344
- func (s *proxy_socks5) connect(conn net.Conn, target string) error {
345
- host, portStr, err := net.SplitHostPort(target)
346
- if err != nil {
347
- return err
348
- }
349
-
350
- port, err := strconv.Atoi(portStr)
351
- if err != nil {
352
- return errors.New("proxy: failed to parse port number: " + portStr)
353
- }
354
- if port < 1 || port > 0xffff {
355
- return errors.New("proxy: port number out of range: " + portStr)
356
- }
357
-
358
- // the size here is just an estimate
359
- buf := make([]byte, 0, 6+len(host))
360
-
361
- buf = append(buf, proxy_socks5Version)
362
- if len(s.user) > 0 && len(s.user) < 256 && len(s.password) < 256 {
363
- buf = append(buf, 2 /* num auth methods */, proxy_socks5AuthNone, proxy_socks5AuthPassword)
364
- } else {
365
- buf = append(buf, 1 /* num auth methods */, proxy_socks5AuthNone)
366
- }
367
-
368
- if _, err := conn.Write(buf); err != nil {
369
- return errors.New("proxy: failed to write greeting to SOCKS5 proxy at " + s.addr + ": " + err.Error())
370
- }
371
-
372
- if _, err := io.ReadFull(conn, buf[:2]); err != nil {
373
- return errors.New("proxy: failed to read greeting from SOCKS5 proxy at " + s.addr + ": " + err.Error())
374
- }
375
- if buf[0] != 5 {
376
- return errors.New("proxy: SOCKS5 proxy at " + s.addr + " has unexpected version " + strconv.Itoa(int(buf[0])))
377
- }
378
- if buf[1] == 0xff {
379
- return errors.New("proxy: SOCKS5 proxy at " + s.addr + " requires authentication")
380
- }
381
-
382
- // See RFC 1929
383
- if buf[1] == proxy_socks5AuthPassword {
384
- buf = buf[:0]
385
- buf = append(buf, 1 /* password protocol version */)
386
- buf = append(buf, uint8(len(s.user)))
387
- buf = append(buf, s.user...)
388
- buf = append(buf, uint8(len(s.password)))
389
- buf = append(buf, s.password...)
390
-
391
- if _, err := conn.Write(buf); err != nil {
392
- return errors.New("proxy: failed to write authentication request to SOCKS5 proxy at " + s.addr + ": " + err.Error())
393
- }
394
-
395
- if _, err := io.ReadFull(conn, buf[:2]); err != nil {
396
- return errors.New("proxy: failed to read authentication reply from SOCKS5 proxy at " + s.addr + ": " + err.Error())
397
- }
398
-
399
- if buf[1] != 0 {
400
- return errors.New("proxy: SOCKS5 proxy at " + s.addr + " rejected username/password")
401
- }
402
- }
403
-
404
- buf = buf[:0]
405
- buf = append(buf, proxy_socks5Version, proxy_socks5Connect, 0 /* reserved */)
406
-
407
- if ip := net.ParseIP(host); ip != nil {
408
- if ip4 := ip.To4(); ip4 != nil {
409
- buf = append(buf, proxy_socks5IP4)
410
- ip = ip4
411
- } else {
412
- buf = append(buf, proxy_socks5IP6)
413
- }
414
- buf = append(buf, ip...)
415
- } else {
416
- if len(host) > 255 {
417
- return errors.New("proxy: destination host name too long: " + host)
418
- }
419
- buf = append(buf, proxy_socks5Domain)
420
- buf = append(buf, byte(len(host)))
421
- buf = append(buf, host...)
422
- }
423
- buf = append(buf, byte(port>>8), byte(port))
424
-
425
- if _, err := conn.Write(buf); err != nil {
426
- return errors.New("proxy: failed to write connect request to SOCKS5 proxy at " + s.addr + ": " + err.Error())
427
- }
428
-
429
- if _, err := io.ReadFull(conn, buf[:4]); err != nil {
430
- return errors.New("proxy: failed to read connect reply from SOCKS5 proxy at " + s.addr + ": " + err.Error())
431
- }
432
-
433
- failure := "unknown error"
434
- if int(buf[1]) < len(proxy_socks5Errors) {
435
- failure = proxy_socks5Errors[buf[1]]
436
- }
437
-
438
- if len(failure) > 0 {
439
- return errors.New("proxy: SOCKS5 proxy at " + s.addr + " failed to connect: " + failure)
440
- }
441
-
442
- bytesToDiscard := 0
443
- switch buf[3] {
444
- case proxy_socks5IP4:
445
- bytesToDiscard = net.IPv4len
446
- case proxy_socks5IP6:
447
- bytesToDiscard = net.IPv6len
448
- case proxy_socks5Domain:
449
- _, err := io.ReadFull(conn, buf[:1])
450
- if err != nil {
451
- return errors.New("proxy: failed to read domain length from SOCKS5 proxy at " + s.addr + ": " + err.Error())
452
- }
453
- bytesToDiscard = int(buf[0])
454
- default:
455
- return errors.New("proxy: got unknown address type " + strconv.Itoa(int(buf[3])) + " from SOCKS5 proxy at " + s.addr)
456
- }
457
-
458
- if cap(buf) < bytesToDiscard {
459
- buf = make([]byte, bytesToDiscard)
460
- } else {
461
- buf = buf[:bytesToDiscard]
462
- }
463
- if _, err := io.ReadFull(conn, buf); err != nil {
464
- return errors.New("proxy: failed to read address from SOCKS5 proxy at " + s.addr + ": " + err.Error())
465
- }
466
-
467
- // Also need to discard the port number
468
- if _, err := io.ReadFull(conn, buf[:2]); err != nil {
469
- return errors.New("proxy: failed to read port from SOCKS5 proxy at " + s.addr + ": " + err.Error())
470
- }
471
-
472
- return nil
473
- }