Update vendor (whatsapp)

pull/1773/head
Wim 2 years ago
parent 1b9877fda4
commit aefa70891c

@ -45,7 +45,7 @@ require (
github.com/writeas/go-strip-markdown v2.0.1+incompatible
github.com/yaegashi/msgraph.go v0.1.4
github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134
go.mau.fi/whatsmeow v0.0.0-20220128124639-e64fb976bf15
go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52
golang.org/x/image v0.0.0-20220302094943-723b81ca9867
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
golang.org/x/text v0.3.7
@ -53,7 +53,7 @@ require (
google.golang.org/protobuf v1.27.1
gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376
layeh.com/gumble v0.0.0-20200818122324-146f9205029b
modernc.org/sqlite v1.14.5
modernc.org/sqlite v1.14.8
)
require (
@ -124,11 +124,11 @@ require (
github.com/wiggin77/cfg v1.0.2 // indirect
github.com/wiggin77/merror v1.0.3 // indirect
github.com/wiggin77/srslog v1.0.1 // indirect
go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910 // indirect
go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
@ -143,8 +143,8 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
lukechampine.com/uint128 v1.1.1 // indirect
modernc.org/cc/v3 v3.35.22 // indirect
modernc.org/ccgo/v3 v3.15.1 // indirect
modernc.org/libc v1.14.1 // indirect
modernc.org/ccgo/v3 v3.15.14 // indirect
modernc.org/libc v1.14.6 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.0.5 // indirect
modernc.org/opt v0.1.1 // indirect

@ -10,7 +10,6 @@ github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/Philipp15b/go-steam v1.0.1-0.20200727090957-6ae9b3c0a560 h1:ItnC9PEEMESzTbFayxrhKBbuFQOXDBI8yy7NudTcEWs=
github.com/Philipp15b/go-steam v1.0.1-0.20200727090957-6ae9b3c0a560/go.mod h1:o38AwUFFS4gzbjSoyIgrZ1h9UeDrKwcci1Pj6baifvI=
github.com/Rhymen/go-whatsapp v0.1.2-0.20211102134409-31a2e740845c/go.mod h1:DNSFRLFDFIqm2+0aJzSOVfn25020vldM4SRqz6YtLgI=
github.com/SevereCloud/vksdk/v2 v2.13.1 h1:D11NaP275mW01v2hRF0ycDHdJaIyZEvasZV4MSkg5Sk=
github.com/SevereCloud/vksdk/v2 v2.13.1/go.mod h1:UyOgSj/CYt2dByu3Fyf/y1yT1NoahVi4zECvvrbtPU4=
github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0=
@ -227,18 +226,18 @@ github.com/yaegashi/msgraph.go v0.1.4 h1:leDXSczAbwBpYFSmmZrdByTiPoUw8dbTfNMetAj
github.com/yaegashi/msgraph.go v0.1.4/go.mod h1:vgeYhHa5skJt/3lTyjGXThTZhwbhRnGo6uUxzoJIGME=
github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134 h1:itYC8Ycx8aVBN7a8q1Yr187W5WmQthvYU13+f4rOWkU=
github.com/zfjagann/golang-ring v0.0.0-20210116075443-7c86fdb43134/go.mod h1:0MsIttMJIF/8Y7x0XjonJP7K99t3sR6bjj4m5S4JmqU=
go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910 h1:9FFhG0OmkuMau5UEaTgiUQ+7cSbtbOQ7hiWKdN8OI3I=
go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910/go.mod h1:AufGrvVh+00Nc07Jm4hTquh7yleZyn20tKJI2wCPAKg=
go.mau.fi/whatsmeow v0.0.0-20220128124639-e64fb976bf15 h1:BmdZu7K6IHsb+sPxvzkEjAINKxTMNeSiJRe1cvfesIY=
go.mau.fi/whatsmeow v0.0.0-20220128124639-e64fb976bf15/go.mod h1:8jUjOAi3xtGubxcZgG8uSHpAdyQXBRbWAfxkctX/4y4=
go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7 h1:L09XYQRGJwC6KbJumz3cD/6JTUAPNZHfnu8hroqm1KE=
go.mau.fi/libsignal v0.0.0-20220308120827-0d87a03fd7c7/go.mod h1:LjEYzdnRUcRArJJUUHQUfMU1A+WzEM73qBTirXluuaY=
go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52 h1:CVJ4dVzluwsUFI8zBLQBlrtYHuMcEYM6oLeAbplCrI4=
go.mau.fi/whatsmeow v0.0.0-20220312175208-0c4681a6ff52/go.mod h1:nH4IwHZf+Ks61nM5p71jZqLXiT0NpG+0uR/WqzCqHH8=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 h1:/pEO3GD/ABYAjuakUS6xSEmmlyVS4kxBNkeA9tLJiTI=
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70 h1:syTAU9FwmvzEoIYMqcPHOcVm4H3U5u90WsvuYgwpETU=
golang.org/x/crypto v0.0.0-20220307211146-efcb8507fb70/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/image v0.0.0-20220302094943-723b81ca9867 h1:TcHcE0vrmgzNH1v3ppjcMGbhG5+9fMuvOmUYwNEF4q4=
golang.org/x/image v0.0.0-20220302094943-723b81ca9867/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
@ -281,18 +280,18 @@ lukechampine.com/uint128 v1.1.1 h1:pnxCASz787iMf+02ssImqk6OLt+Z5QHMoZyUXR4z6JU=
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/cc/v3 v3.35.22 h1:BzShpwCAP7TWzFppM4k2t03RhXhgYqaibROWkrWq7lE=
modernc.org/cc/v3 v3.35.22/go.mod h1:iPJg1pkwXqAV16SNgFBVYmggfMg6xhs+2oiO0vclK3g=
modernc.org/ccgo/v3 v3.15.1 h1:bagyhO7uFlYWedkh6mfIYf8LZGYnVGPYh2FqXisaOV4=
modernc.org/ccgo/v3 v3.15.1/go.mod h1:md59wBwDT2LznX/OTCPoVS6KIsdRgY8xqQwBV+hkTH0=
modernc.org/libc v1.14.1 h1:rwx9uVJU/fEmsmV5ECGRwdAiXgUm6k6tsFA+L8kQb6E=
modernc.org/libc v1.14.1/go.mod h1:npFeGWjmZTjFeWALQLrvklVmAxv4m80jnG3+xI8FdJk=
modernc.org/ccgo/v3 v3.15.14 h1:/Pcjoc5mPznDMH3CErDeX4mHLAAQyR5lzr3s2FpqDY0=
modernc.org/ccgo/v3 v3.15.14/go.mod h1:144Sz2iBCKogb9OKwsu7hQEub3EVgOlyI8wMUPGKUXQ=
modernc.org/libc v1.14.6 h1:SSiZiE5199iYsGM9gtkDj90xqcXVwubWG8CtoYE+Mnk=
modernc.org/libc v1.14.6/go.mod h1:2PJHINagVxO4QW/5OQdRrvMYo+bm5ClpUFfyXCYl9ak=
modernc.org/mathutil v1.4.1 h1:ij3fYGe8zBF4Vu+g0oT7mB06r8sqGWKuJu1yXeR4by8=
modernc.org/mathutil v1.4.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.0.5 h1:XRch8trV7GgvTec2i7jc33YlUI0RKVDBvZ5eZ5m8y14=
modernc.org/memory v1.0.5/go.mod h1:B7OYswTRnfGg+4tDH1t1OeUNnsy2viGTdME4tzd+IjM=
modernc.org/opt v0.1.1 h1:/0RX92k9vwVeDXj+Xn23DKp2VJubL7k8qNffND6qn3A=
modernc.org/opt v0.1.1/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0=
modernc.org/sqlite v1.14.5 h1:bYrrjwH9Y7QUGk1MbchZDhRfmpGuEAs/D45sVjNbfvs=
modernc.org/sqlite v1.14.5/go.mod h1:YyX5Rx0WbXokitdWl2GJIDy4BrPxBP0PwwhpXOHCDLE=
modernc.org/sqlite v1.14.8 h1:2OOqfZAyU4x4qusilvHoRXXqsAgaZobi1o+mjQ5MUpw=
modernc.org/sqlite v1.14.8/go.mod h1:TFmXjym+/jR31fxc2B5eHnKMuJJGY7i1L/T5A0jzVww=
modernc.org/strutil v1.1.1 h1:xv+J1BXY3Opl2ALrBwyfEikFAj8pmqcpnfmuwUwcozs=
modernc.org/strutil v1.1.1/go.mod h1:DE+MQQ/hjKBZS2zNInV5hhcipt5rLPWkmpbGeW5mmdw=
modernc.org/token v1.0.0 h1:a0jaWiNMDhDUtqOj09wvjWWAqd3q7WpBulmL9H2egsk=

@ -1,21 +1,13 @@
# whatsmeow
[![godocs.io](https://godocs.io/go.mau.fi/whatsmeow?status.svg)](https://godocs.io/go.mau.fi/whatsmeow)
[![Go Reference](https://pkg.go.dev/badge/go.mau.fi/whatsmeow.svg)](https://pkg.go.dev/go.mau.fi/whatsmeow)
whatsmeow is a Go library for the WhatsApp web multidevice API.
This was initially forked from [go-whatsapp] (MIT license), but large parts of
the code have been rewritten for multidevice support. Parts of the code are
ported from [WhatsappWeb4j] and [Baileys] (also MIT license).
[go-whatsapp]: https://github.com/Rhymen/go-whatsapp
[WhatsappWeb4j]: https://github.com/Auties00/WhatsappWeb4j
[Baileys]: https://github.com/adiwajshing/Baileys
## Discussion
Matrix room: [#whatsmeow:maunium.net](https://matrix.to/#/#whatsmeow:maunium.net)
## Usage
The [godoc](https://godocs.io/go.mau.fi/whatsmeow) includes docs for all methods and event types.
The [godoc](https://pkg.go.dev/go.mau.fi/whatsmeow) includes docs for all methods and event types.
There's also a [simple example](https://godocs.io/go.mau.fi/whatsmeow#example-package) at the top.
Also see [mdtest](./mdtest) for a CLI tool you can easily try out whatsmeow with.

@ -1,4 +1,4 @@
// Copyright (c) 2021 Tulir Asokan
// Copyright (c) 2022 Tulir Asokan
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@ -13,6 +13,7 @@ import (
"go.mau.fi/whatsmeow/appstate"
waBinary "go.mau.fi/whatsmeow/binary"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/store"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/types/events"
)
@ -54,7 +55,18 @@ func (cli *Client) FetchAppState(name appstate.WAPatchName, fullSync, onlyIfNotS
if err != nil {
return fmt.Errorf("failed to decode app state %s patches: %w", name, err)
}
wasFullSync := state.Version == 0 && patches.Snapshot != nil
state = newState
if name == appstate.WAPatchCriticalUnblockLow && wasFullSync && !cli.EmitAppStateEventsOnFullSync {
var contacts []store.ContactEntry
mutations, contacts = cli.filterContacts(mutations)
cli.Log.Debugf("Mass inserting app state snapshot with %d contacts into the store", len(contacts))
err = cli.Store.Contacts.PutAllContactNames(contacts)
if err != nil {
// This is a fairly serious failure, so just abort the whole thing
return fmt.Errorf("failed to update contact store with data from snapshot: %v", err)
}
}
for _, mutation := range mutations {
cli.dispatchAppState(mutation, !fullSync || cli.EmitAppStateEventsOnFullSync)
}
@ -68,6 +80,25 @@ func (cli *Client) FetchAppState(name appstate.WAPatchName, fullSync, onlyIfNotS
return nil
}
func (cli *Client) filterContacts(mutations []appstate.Mutation) ([]appstate.Mutation, []store.ContactEntry) {
filteredMutations := mutations[:0]
contacts := make([]store.ContactEntry, 0, len(mutations))
for _, mutation := range mutations {
if mutation.Index[0] == "contact" && len(mutation.Index) > 1 {
jid, _ := types.ParseJID(mutation.Index[1])
act := mutation.Action.GetContactAction()
contacts = append(contacts, store.ContactEntry{
JID: jid,
FirstName: act.GetFirstName(),
FullName: act.GetFullName(),
})
} else {
filteredMutations = append(filteredMutations, mutation)
}
}
return filteredMutations, contacts
}
func (cli *Client) dispatchAppState(mutation appstate.Mutation, dispatchEvts bool) {
if mutation.Operation != waProto.SyncdMutation_SET {
return
@ -144,6 +175,12 @@ func (cli *Client) dispatchAppState(mutation appstate.Mutation, dispatchEvts boo
evt.SenderJID, _ = types.ParseJID(mutation.Index[4])
}
eventToDispatch = &evt
case "markChatAsRead":
eventToDispatch = &events.MarkChatAsRead{
JID: jid,
Timestamp: ts,
Action: mutation.Action.GetMarkChatAsReadAction(),
}
case "setting_pushName":
eventToDispatch = &events.PushNameSetting{Timestamp: ts, Action: mutation.Action.GetPushNameSetting()}
cli.Store.PushName = mutation.Action.GetPushNameSetting().GetName()

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -15,6 +15,10 @@ var (
}
)
// DictVersion is the version number of the token lists above.
// It's sent when connecting to the websocket so the server knows which tokens are supported.
const DictVersion = 2
type doubleByteTokenIndex struct {
dictionary byte
index byte

@ -13,6 +13,8 @@ import (
"encoding/hex"
"errors"
"fmt"
"net/http"
"net/url"
"runtime/debug"
"sync"
"sync/atomic"
@ -56,6 +58,8 @@ type Client struct {
LastSuccessfulConnect time.Time
AutoReconnectErrors int
sendActiveReceipts uint32
// EmitAppStateEventsOnFullSync can be set to true if you want to get app state events emitted
// even when re-syncing the whole state.
EmitAppStateEventsOnFullSync bool
@ -100,6 +104,9 @@ type Client struct {
uniqueID string
idCounter uint32
proxy socket.Proxy
http *http.Client
}
// Size of buffer for the channel that all incoming XML nodes go through.
@ -128,6 +135,10 @@ func NewClient(deviceStore *store.Device, log waLog.Logger) *Client {
randomBytes := make([]byte, 2)
_, _ = rand.Read(randomBytes)
cli := &Client{
http: &http.Client{
Transport: (http.DefaultTransport.(*http.Transport)).Clone(),
},
proxy: http.ProxyFromEnvironment,
Store: deviceStore,
Log: log,
recvLog: log.Sub("Recv"),
@ -159,10 +170,46 @@ func NewClient(deviceStore *store.Device, log waLog.Logger) *Client {
"stream:error": cli.handleStreamError,
"iq": cli.handleIQ,
"ib": cli.handleIB,
// Apparently there's also an <error> node which can have a code=479 and means "Invalid stanza sent (smax-invalid)"
}
return cli
}
// SetProxyAddress is a helper method that parses a URL string and calls SetProxy.
//
// Returns an error if url.Parse fails to parse the given address.
func (cli *Client) SetProxyAddress(addr string) error {
parsed, err := url.Parse(addr)
if err != nil {
return err
}
cli.SetProxy(http.ProxyURL(parsed))
return nil
}
// SetProxy sets the proxy to use for WhatsApp web websocket connections and media uploads/downloads.
//
// Must be called before Connect() to take effect in the websocket connection.
// If you want to change the proxy after connecting, you must call Disconnect() and then Connect() again manually.
//
// By default, the client will find the proxy from the https_proxy environment variable like Go's net/http does.
//
// To disable reading proxy info from environment variables, explicitly set the proxy to nil:
// cli.SetProxy(nil)
//
// To use a different proxy for the websocket and media, pass a function that checks the request path or headers:
// cli.SetProxy(func(r *http.Request) (*url.URL, error) {
// if r.URL.Host == "web.whatsapp.com" && r.URL.Path == "/ws/chat" {
// return websocketProxyURL, nil
// } else {
// return mediaProxyURL, nil
// }
// })
func (cli *Client) SetProxy(proxy socket.Proxy) {
cli.proxy = proxy
cli.http.Transport.(*http.Transport).Proxy = proxy
}
// Connect connects the client to the WhatsApp web websocket. After connection, it will either
// authenticate if there's data in the device store, or emit a QREvent to set up a new link.
func (cli *Client) Connect() error {
@ -177,7 +224,7 @@ func (cli *Client) Connect() error {
}
cli.resetExpectedDisconnect()
fs := socket.NewFrameSocket(cli.Log.Sub("Socket"), socket.WAConnHeader)
fs := socket.NewFrameSocket(cli.Log.Sub("Socket"), socket.WAConnHeader, cli.proxy)
if err := fs.Connect(); err != nil {
fs.Close(0)
return err
@ -313,29 +360,29 @@ func (cli *Client) Logout() error {
//
// All registered event handlers will receive all events. You should use a type switch statement to
// filter the events you want:
// func myEventHandler(evt interface{}) {
// switch v := evt.(type) {
// case *events.Message:
// fmt.Println("Received a message!")
// case *events.Receipt:
// fmt.Println("Received a receipt!")
// }
// }
// func myEventHandler(evt interface{}) {
// switch v := evt.(type) {
// case *events.Message:
// fmt.Println("Received a message!")
// case *events.Receipt:
// fmt.Println("Received a receipt!")
// }
// }
//
// If you want to access the Client instance inside the event handler, the recommended way is to
// wrap the whole handler in another struct:
// type MyClient struct {
// WAClient *whatsmeow.Client
// eventHandlerID uint32
// }
// type MyClient struct {
// WAClient *whatsmeow.Client
// eventHandlerID uint32
// }
//
// func (mycli *MyClient) register() {
// mycli.eventHandlerID = mycli.WAClient.AddEventHandler(mycli.myEventHandler)
// }
// func (mycli *MyClient) register() {
// mycli.eventHandlerID = mycli.WAClient.AddEventHandler(mycli.myEventHandler)
// }
//
// func (mycli *MyClient) myEventHandler(evt interface{}) {
// // Handle event and access mycli.WAClient
// }
// func (mycli *MyClient) myEventHandler(evt interface{}) {
// // Handle event and access mycli.WAClient
// }
func (cli *Client) AddEventHandler(handler EventHandler) uint32 {
nextID := atomic.AddUint32(&nextHandlerID, 1)
cli.eventHandlersLock.Lock()
@ -350,11 +397,11 @@ func (cli *Client) AddEventHandler(handler EventHandler) uint32 {
// N.B. Do not run this directly from an event handler. That would cause a deadlock because the
// event dispatcher holds a read lock on the event handler list, and this method wants a write lock
// on the same list. Instead run it in a goroutine:
// func (mycli *MyClient) myEventHandler(evt interface{}) {
// if noLongerWantEvents {
// go mycli.WAClient.RemoveEventHandler(mycli.eventHandlerID)
// }
// }
// func (mycli *MyClient) myEventHandler(evt interface{}) {
// if noLongerWantEvents {
// go mycli.WAClient.RemoveEventHandler(mycli.eventHandlerID)
// }
// }
func (cli *Client) RemoveEventHandler(id uint32) bool {
cli.eventHandlersLock.Lock()
defer cli.eventHandlersLock.Unlock()

@ -33,7 +33,7 @@ func (cli *Client) handleStreamError(node *waBinary.Node) {
case code == "401" && conflictType == "device_removed":
cli.expectDisconnect()
cli.Log.Infof("Got device removed stream error, sending LoggedOut event and deleting session")
go cli.dispatchEvent(&events.LoggedOut{OnConnect: false})
go cli.dispatchEvent(&events.LoggedOut{OnConnect: false, Reason: events.ConnectFailureLoggedOut})
err := cli.Store.Delete()
if err != nil {
cli.Log.Warnf("Failed to delete store after device_removed error: %v", err)
@ -77,17 +77,30 @@ func (cli *Client) handleIB(node *waBinary.Node) {
func (cli *Client) handleConnectFailure(node *waBinary.Node) {
ag := node.AttrGetter()
reason := ag.String("reason")
if reason == "401" {
cli.expectDisconnect()
cli.Log.Infof("Got 401 connect failure, sending LoggedOut event and deleting session")
go cli.dispatchEvent(&events.LoggedOut{OnConnect: true})
reason := events.ConnectFailureReason(ag.Int("reason"))
cli.expectDisconnect()
if reason.IsLoggedOut() {
cli.Log.Infof("Got %s connect failure, sending LoggedOut event and deleting session", reason)
go cli.dispatchEvent(&events.LoggedOut{OnConnect: true, Reason: reason})
err := cli.Store.Delete()
if err != nil {
cli.Log.Warnf("Failed to delete store after 401 failure: %v", err)
cli.Log.Warnf("Failed to delete store after %d failure: %v", int(reason), err)
}
} else if reason == events.ConnectFailureTempBanned {
cli.Log.Warnf("Temporary ban connect failure: %s", node.XMLString())
expiryTimeUnix := ag.Int64("expire")
var expiryTime time.Time
if expiryTimeUnix > 0 {
expiryTime = time.Unix(expiryTimeUnix, 0)
}
go cli.dispatchEvent(&events.TemporaryBan{
Code: events.TempBanReason(ag.Int("code")),
Expire: expiryTime,
})
} else if reason == events.ConnectFailureClientOutdated {
cli.Log.Errorf("Client outdated (405) connect failure")
go cli.dispatchEvent(&events.ClientOutdated{})
} else {
cli.expectDisconnect()
cli.Log.Warnf("Unknown connect failure: %s", node.XMLString())
go cli.dispatchEvent(&events.ConnectFailure{Reason: reason, Raw: node})
}

@ -18,6 +18,7 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/socket"
"go.mau.fi/whatsmeow/util/cbcutil"
"go.mau.fi/whatsmeow/util/hkdfutil"
)
@ -34,9 +35,14 @@ const (
MediaDocument MediaType = "WhatsApp Document Keys"
MediaHistory MediaType = "WhatsApp History Keys"
MediaAppState MediaType = "WhatsApp App State Keys"
MediaLinkThumbnail MediaType = "WhatsApp Link Thumbnail Keys"
)
// DownloadableMessage represents a protobuf message that contains attachment info.
//
// All of the downloadable messages inside a Message struct implement this interface
// (ImageMessage, VideoMessage, AudioMessage, DocumentMessage, StickerMessage).
type DownloadableMessage interface {
proto.Message
GetDirectPath() string
@ -45,15 +51,27 @@ type DownloadableMessage interface {
GetFileEncSha256() []byte
}
// DownloadableThumbnail represents a protobuf message that contains a thumbnail attachment.
//
// This is primarily meant for link preview thumbnails in ExtendedTextMessage.
type DownloadableThumbnail interface {
proto.Message
GetThumbnailDirectPath() string
GetThumbnailSha256() []byte
GetThumbnailEncSha256() []byte
GetMediaKey() []byte
}
// All the message types that are intended to be downloadable
var (
_ DownloadableMessage = (*waProto.ImageMessage)(nil)
_ DownloadableMessage = (*waProto.AudioMessage)(nil)
_ DownloadableMessage = (*waProto.VideoMessage)(nil)
_ DownloadableMessage = (*waProto.DocumentMessage)(nil)
_ DownloadableMessage = (*waProto.StickerMessage)(nil)
_ DownloadableMessage = (*waProto.HistorySyncNotification)(nil)
_ DownloadableMessage = (*waProto.ExternalBlobReference)(nil)
_ DownloadableMessage = (*waProto.ImageMessage)(nil)
_ DownloadableMessage = (*waProto.AudioMessage)(nil)
_ DownloadableMessage = (*waProto.VideoMessage)(nil)
_ DownloadableMessage = (*waProto.DocumentMessage)(nil)
_ DownloadableMessage = (*waProto.StickerMessage)(nil)
_ DownloadableMessage = (*waProto.HistorySyncNotification)(nil)
_ DownloadableMessage = (*waProto.ExternalBlobReference)(nil)
_ DownloadableThumbnail = (*waProto.ExtendedTextMessage)(nil)
)
type downloadableMessageWithLength interface {
@ -82,6 +100,10 @@ var classToMediaType = map[protoreflect.Name]MediaType{
"ExternalBlobReference": MediaAppState,
}
var classToThumbnailMediaType = map[protoreflect.Name]MediaType{
"ExtendedTextMessage": MediaLinkThumbnail,
}
var mediaTypeToMMSType = map[MediaType]string{
MediaImage: "image",
MediaAudio: "audio",
@ -89,17 +111,29 @@ var mediaTypeToMMSType = map[MediaType]string{
MediaDocument: "document",
MediaHistory: "md-msg-hist",
MediaAppState: "md-app-state",
MediaLinkThumbnail: "thumbnail-link",
}
// DownloadAny loops through the downloadable parts of the given message and downloads the first non-nil item.
func (cli *Client) DownloadAny(msg *waProto.Message) (data []byte, err error) {
downloadables := []DownloadableMessage{msg.GetImageMessage(), msg.GetAudioMessage(), msg.GetVideoMessage(), msg.GetDocumentMessage(), msg.GetStickerMessage()}
for _, downloadable := range downloadables {
if downloadable != nil {
return cli.Download(downloadable)
}
if msg == nil {
return nil, ErrNothingDownloadableFound
}
switch {
case msg.ImageMessage != nil:
return cli.Download(msg.ImageMessage)
case msg.VideoMessage != nil:
return cli.Download(msg.VideoMessage)
case msg.AudioMessage != nil:
return cli.Download(msg.AudioMessage)
case msg.DocumentMessage != nil:
return cli.Download(msg.DocumentMessage)
case msg.StickerMessage != nil:
return cli.Download(msg.StickerMessage)
default:
return nil, ErrNothingDownloadableFound
}
return nil, ErrNothingDownloadableFound
}
func getSize(msg DownloadableMessage) int {
@ -113,30 +147,63 @@ func getSize(msg DownloadableMessage) int {
}
}
// DownloadThumbnail downloads a thumbnail from a message.
//
// This is primarily intended for downloading link preview thumbnails, which are in ExtendedTextMessage:
// var msg *waProto.Message
// ...
// thumbnailImageBytes, err := cli.DownloadThumbnail(msg.GetExtendedTextMessage())
func (cli *Client) DownloadThumbnail(msg DownloadableThumbnail) ([]byte, error) {
mediaType, ok := classToThumbnailMediaType[msg.ProtoReflect().Descriptor().Name()]
if !ok {
return nil, fmt.Errorf("%w '%s'", ErrUnknownMediaType, string(msg.ProtoReflect().Descriptor().Name()))
} else if len(msg.GetThumbnailDirectPath()) > 0 {
return cli.DownloadMediaWithPath(msg.GetThumbnailDirectPath(), msg.GetThumbnailEncSha256(), msg.GetThumbnailSha256(), msg.GetMediaKey(), -1, mediaType, mediaTypeToMMSType[mediaType])
} else {
return nil, ErrNoURLPresent
}
}
// GetMediaType returns the MediaType value corresponding to the given protobuf message.
func GetMediaType(msg DownloadableMessage) MediaType {
return classToMediaType[msg.ProtoReflect().Descriptor().Name()]
}
// Download downloads the attachment from the given protobuf message.
func (cli *Client) Download(msg DownloadableMessage) (data []byte, err error) {
//
// The attachment is a specific part of a Message protobuf struct, not the message itself, e.g.
// var msg *waProto.Message
// ...
// imageData, err := cli.Download(msg.GetImageMessage())
//
// You can also use DownloadAny to download the first non-nil sub-message.
func (cli *Client) Download(msg DownloadableMessage) ([]byte, error) {
mediaType, ok := classToMediaType[msg.ProtoReflect().Descriptor().Name()]
if !ok {
return nil, fmt.Errorf("%w '%s'", ErrUnknownMediaType, string(msg.ProtoReflect().Descriptor().Name()))
}
urlable, ok := msg.(downloadableMessageWithURL)
if ok && len(urlable.GetUrl()) > 0 {
return downloadAndDecrypt(urlable.GetUrl(), msg.GetMediaKey(), mediaType, getSize(msg), msg.GetFileEncSha256(), msg.GetFileSha256())
return cli.downloadAndDecrypt(urlable.GetUrl(), msg.GetMediaKey(), mediaType, getSize(msg), msg.GetFileEncSha256(), msg.GetFileSha256())
} else if len(msg.GetDirectPath()) > 0 {
return cli.downloadMediaWithPath(msg.GetDirectPath(), msg.GetFileEncSha256(), msg.GetFileSha256(), msg.GetMediaKey(), getSize(msg), mediaType, mediaTypeToMMSType[mediaType])
return cli.DownloadMediaWithPath(msg.GetDirectPath(), msg.GetFileEncSha256(), msg.GetFileSha256(), msg.GetMediaKey(), getSize(msg), mediaType, mediaTypeToMMSType[mediaType])
} else {
return nil, ErrNoURLPresent
}
}
func (cli *Client) downloadMediaWithPath(directPath string, encFileHash, fileHash, mediaKey []byte, fileLength int, mediaType MediaType, mmsType string) (data []byte, err error) {
// DownloadMediaWithPath downloads an attachment by manually specifying the path and encryption details.
func (cli *Client) DownloadMediaWithPath(directPath string, encFileHash, fileHash, mediaKey []byte, fileLength int, mediaType MediaType, mmsType string) (data []byte, err error) {
err = cli.refreshMediaConn(false)
if err != nil {
return nil, fmt.Errorf("failed to refresh media connections: %w", err)
}
if len(mmsType) == 0 {
mmsType = mediaTypeToMMSType[mediaType]
}
for i, host := range cli.mediaConn.Hosts {
mediaURL := fmt.Sprintf("https://%s%s&hash=%s&mms-type=%s&__wa-mms=", host.Hostname, directPath, base64.URLEncoding.EncodeToString(encFileHash), mmsType)
data, err = downloadAndDecrypt(mediaURL, mediaKey, mediaType, fileLength, encFileHash, fileHash)
data, err = cli.downloadAndDecrypt(mediaURL, mediaKey, mediaType, fileLength, encFileHash, fileHash)
// TODO there are probably some errors that shouldn't retry
if err != nil {
if i >= len(cli.mediaConn.Hosts)-1 {
@ -148,10 +215,10 @@ func (cli *Client) downloadMediaWithPath(directPath string, encFileHash, fileHas
return
}
func downloadAndDecrypt(url string, mediaKey []byte, appInfo MediaType, fileLength int, fileEncSha256, fileSha256 []byte) (data []byte, err error) {
func (cli *Client) downloadAndDecrypt(url string, mediaKey []byte, appInfo MediaType, fileLength int, fileEncSha256, fileSha256 []byte) (data []byte, err error) {
iv, cipherKey, macKey, _ := getMediaKeys(mediaKey, appInfo)
var ciphertext, mac []byte
if ciphertext, mac, err = downloadEncryptedMedia(url, fileEncSha256); err != nil {
if ciphertext, mac, err = cli.downloadEncryptedMedia(url, fileEncSha256); err != nil {
} else if err = validateMedia(iv, ciphertext, macKey, mac); err != nil {
@ -170,9 +237,17 @@ func getMediaKeys(mediaKey []byte, appInfo MediaType) (iv, cipherKey, macKey, re
return mediaKeyExpanded[:16], mediaKeyExpanded[16:48], mediaKeyExpanded[48:80], mediaKeyExpanded[80:]
}
func downloadEncryptedMedia(url string, checksum []byte) (file, mac []byte, err error) {
func (cli *Client) downloadEncryptedMedia(url string, checksum []byte) (file, mac []byte, err error) {
var req *http.Request
req, err = http.NewRequest(http.MethodGet, url, nil)
if err != nil {
err = fmt.Errorf("failed to prepare request: %w", err)
return
}
req.Header.Set("Origin", socket.Origin)
req.Header.Set("Referer", socket.Origin+"/")
var resp *http.Response
resp, err = http.Get(url)
resp, err = cli.http.Do(req)
if err != nil {
return
}

@ -45,6 +45,8 @@ var (
ErrInviteLinkRevoked = errors.New("that group invite link has been revoked")
// ErrBusinessMessageLinkNotFound is returned by ResolveBusinessMessageLink if the link doesn't exist or has been revoked.
ErrBusinessMessageLinkNotFound = errors.New("that business message link does not exist or has been revoked")
// ErrInvalidImageFormat is returned by SetGroupPhoto if the given photo is not in the correct format.
ErrInvalidImageFormat = errors.New("the given data is not a valid image")
)
// Some errors that Client.SendMessage can return

@ -106,6 +106,40 @@ func (cli *Client) UpdateGroupParticipants(jid types.JID, participantChanges map
return resp, nil
}
// SetGroupPhoto updates the group picture/icon of the given group on WhatsApp.
// The avatar should be a JPEG photo, other formats may be rejected with ErrInvalidImageFormat.
// The bytes can be nil to remove the photo. Returns the new picture ID.
func (cli *Client) SetGroupPhoto(jid types.JID, avatar []byte) (string, error) {
var content interface{}
if avatar != nil {
content = []waBinary.Node{{
Tag: "picture",
Attrs: waBinary.Attrs{"type": "image"},
Content: avatar,
}}
}
resp, err := cli.sendIQ(infoQuery{
Namespace: "w:profile:picture",
Type: iqSet,
To: types.ServerJID,
Target: jid,
Content: content,
})
if errors.Is(err, ErrIQNotAcceptable) {
return "", wrapIQError(ErrInvalidImageFormat, err)
} else if err != nil {
return "", err
}
if avatar == nil {
return "remove", nil
}
pictureID, ok := resp.GetChildByTag("picture").Attrs["id"].(string)
if !ok {
return "", fmt.Errorf("didn't find picture ID in response")
}
return pictureID, nil
}
// SetGroupName updates the name (subject) of the given group on WhatsApp.
func (cli *Client) SetGroupName(jid types.JID, name string) error {
_, err := cli.sendGroupIQ(iqSet, jid, waBinary.Node{
@ -385,7 +419,8 @@ func (cli *Client) parseGroupNode(groupNode *waBinary.Node) (*types.GroupInfo, e
case "description":
body, bodyOK := child.GetOptionalChildByTag("body")
if bodyOK {
group.Topic, _ = body.Content.(string)
topicBytes, _ := body.Content.([]byte)
group.Topic = string(topicBytes)
group.TopicID = childAG.String("id")
group.TopicSetBy = childAG.OptionalJIDOrEmpty("participant")
group.TopicSetAt = time.Unix(childAG.Int64("t"), 0)

@ -0,0 +1,163 @@
// Copyright (c) 2022 Tulir Asokan
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package whatsmeow
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"fmt"
"time"
"google.golang.org/protobuf/proto"
waBinary "go.mau.fi/whatsmeow/binary"
waProto "go.mau.fi/whatsmeow/binary/proto"
"go.mau.fi/whatsmeow/types"
"go.mau.fi/whatsmeow/types/events"
"go.mau.fi/whatsmeow/util/hkdfutil"
)
func getMediaRetryKey(mediaKey []byte) (cipherKey []byte) {
return hkdfutil.SHA256(mediaKey, nil, []byte("WhatsApp Media Retry Notification"), 32)
}
func prepareMediaRetryGCM(mediaKey []byte) (cipher.AEAD, error) {
block, err := aes.NewCipher(getMediaRetryKey(mediaKey))
if err != nil {
return nil, fmt.Errorf("failed to initialize AES cipher: %w", err)
}
gcm, err := cipher.NewGCM(block)
if err != nil {
return nil, fmt.Errorf("failed to initialize GCM: %w", err)
}
return gcm, nil
}
func encryptMediaRetryReceipt(messageID types.MessageID, mediaKey []byte) (ciphertext, iv []byte, err error) {
receipt := &waProto.ServerErrorReceipt{
StanzaId: proto.String(messageID),
}
var plaintext []byte
plaintext, err = proto.Marshal(receipt)
if err != nil {
err = fmt.Errorf("failed to marshal payload: %w", err)
return
}
var gcm cipher.AEAD
gcm, err = prepareMediaRetryGCM(mediaKey)
if err != nil {
return
}
iv = make([]byte, 12)
_, err = rand.Read(iv)
if err != nil {
panic(err)
}
ciphertext = gcm.Seal(plaintext[:0], iv, plaintext, []byte(messageID))
return
}
// SendMediaRetryReceipt sends a request to the phone to re-upload the media in a message.
//
// The response will come as an *events.MediaRetry. The response will then have to be decrypted
// using DecryptMediaRetryNotification and the same media key passed here.
func (cli *Client) SendMediaRetryReceipt(message *types.MessageInfo, mediaKey []byte) error {
ciphertext, iv, err := encryptMediaRetryReceipt(message.ID, mediaKey)
if err != nil {
return fmt.Errorf("failed to prepare encrypted retry receipt: %w", err)
}
rmrAttrs := waBinary.Attrs{
"jid": message.Chat,
"from_me": message.IsFromMe,
}
if message.IsGroup {
rmrAttrs["participant"] = message.Sender
}
encryptedRequest := []waBinary.Node{
{Tag: "enc_p", Content: ciphertext},
{Tag: "enc_iv", Content: iv},
}
err = cli.sendNode(waBinary.Node{
Tag: "receipt",
Attrs: waBinary.Attrs{
"id": message.ID,
"to": cli.Store.ID.ToNonAD(),
"type": "server-error",
},
Content: []waBinary.Node{
{Tag: "encrypt", Content: encryptedRequest},
{Tag: "rmr", Attrs: rmrAttrs},
},
})
if err != nil {
return err
}
return nil
}
// DecryptMediaRetryNotification decrypts a media retry notification using the media key.
func DecryptMediaRetryNotification(evt *events.MediaRetry, mediaKey []byte) (*waProto.MediaRetryNotification, error) {
gcm, err := prepareMediaRetryGCM(mediaKey)
if err != nil {
return nil, err
}
plaintext, err := gcm.Open(nil, evt.IV, evt.Ciphertext, []byte(evt.MessageID))
if err != nil {
return nil, fmt.Errorf("failed to decrypt notification: %w", err)
}
var notif waProto.MediaRetryNotification
err = proto.Unmarshal(plaintext, &notif)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal notification (invalid encryption key?): %w", err)
}
return &notif, nil
}
func parseMediaRetryNotification(node *waBinary.Node) (*events.MediaRetry, error) {
ag := node.AttrGetter()
var evt events.MediaRetry
evt.Timestamp = time.Unix(ag.Int64("t"), 0)
evt.MessageID = types.MessageID(ag.String("id"))
if !ag.OK() {
return nil, ag.Error()
}
rmr, ok := node.GetOptionalChildByTag("rmr")
if !ok {
return nil, &ElementMissingError{Tag: "rmr", In: "retry notification"}
}
rmrAG := rmr.AttrGetter()
evt.ChatID = rmrAG.JID("jid")
evt.FromMe = rmrAG.Bool("from_me")
evt.SenderID = rmrAG.OptionalJIDOrEmpty("participant")
if !rmrAG.OK() {
return nil, fmt.Errorf("missing attributes in <rmr> tag: %w", rmrAG.Error())
}
evt.Ciphertext, ok = node.GetChildByTag("encrypt", "enc_p").Content.([]byte)
if !ok {
return nil, &ElementMissingError{Tag: "enc_p", In: fmt.Sprintf("retry notification %s", evt.MessageID)}
}
evt.IV, ok = node.GetChildByTag("encrypt", "enc_iv").Content.([]byte)
if !ok {
return nil, &ElementMissingError{Tag: "enc_iv", In: fmt.Sprintf("retry notification %s", evt.MessageID)}
}
return &evt, nil
}
func (cli *Client) handleMediaRetryNotification(node *waBinary.Node) {
// TODO handle errors (e.g. <error code="2"/>)
evt, err := parseMediaRetryNotification(node)
if err != nil {
cli.Log.Warnf("Failed to parse media retry notification: %v", err)
return
}
cli.dispatchEvent(evt)
}

@ -283,6 +283,7 @@ func (cli *Client) handleHistorySyncNotification(notif *waProto.HistorySyncNotif
}
func (cli *Client) handleAppStateSyncKeyShare(keys *waProto.AppStateSyncKeyShare) {
cli.Log.Debugf("Got %d new app state keys", len(keys.GetKeys()))
for _, key := range keys.GetKeys() {
marshaledFingerprint, err := proto.Marshal(key.GetKeyData().GetFingerprint())
if err != nil {
@ -365,7 +366,7 @@ func (cli *Client) handleDecryptedMessage(info *types.MessageInfo, msg *waProto.
}
func (cli *Client) sendProtocolMessageReceipt(id, msgType string) {
if len(id) == 0 {
if len(id) == 0 || cli.Store.ID == nil {
return
}
err := cli.sendNode(waBinary.Node{

@ -199,6 +199,9 @@ func (cli *Client) handleNotification(node *waBinary.Node) {
}
case "picture":
go cli.handlePictureNotification(node)
case "mediaretry":
go cli.handleMediaRetryNotification(node)
// Other types: business, disappearing_mode, server, status, pay, psa, privacy_token
default:
cli.Log.Debugf("Unhandled notification with type %s", notifType)
}

@ -7,6 +7,7 @@
package whatsmeow
import (
"sync/atomic"
"time"
waBinary "go.mau.fi/whatsmeow/binary"
@ -23,12 +24,14 @@ func (cli *Client) handleChatState(node *waBinary.Node) {
} else {
child := node.GetChildren()[0]
presence := types.ChatPresence(child.Tag)
if presence != types.ChatPresenceComposing && presence != types.ChatPresenceRecording && presence != types.ChatPresencePaused {
if presence != types.ChatPresenceComposing && presence != types.ChatPresencePaused {
cli.Log.Warnf("Unrecognized chat presence state %s", child.Tag)
}
media := types.ChatPresenceMedia(child.AttrGetter().OptionalString("media"))
cli.dispatchEvent(&events.ChatPresence{
MessageSource: source,
State: presence,
Media: media,
})
}
}
@ -62,6 +65,11 @@ func (cli *Client) SendPresence(state types.Presence) error {
if len(cli.Store.PushName) == 0 {
return ErrNoPushName
}
if state == types.PresenceAvailable {
atomic.CompareAndSwapUint32(&cli.sendActiveReceipts, 0, 1)
} else {
atomic.CompareAndSwapUint32(&cli.sendActiveReceipts, 1, 0)
}
return cli.sendNode(waBinary.Node{
Tag: "presence",
Attrs: waBinary.Attrs{
@ -89,13 +97,21 @@ func (cli *Client) SubscribePresence(jid types.JID) error {
}
// SendChatPresence updates the user's typing status in a specific chat.
func (cli *Client) SendChatPresence(state types.ChatPresence, jid types.JID) error {
//
// The media parameter can be set to indicate the user is recording media (like a voice message) rather than typing a text message.
func (cli *Client) SendChatPresence(jid types.JID, state types.ChatPresence, media types.ChatPresenceMedia) error {
content := []waBinary.Node{{Tag: string(state)}}
if state == types.ChatPresenceComposing && len(media) > 0 {
content[0].Attrs = waBinary.Attrs{
"media": string(media),
}
}
return cli.sendNode(waBinary.Node{
Tag: "chatstate",
Attrs: waBinary.Attrs{
"from": *cli.Store.ID,
"to": jid,
},
Content: []waBinary.Node{{Tag: string(state)}},
Content: content,
})
}

@ -1,4 +1,4 @@
// Copyright (c) 2021 Tulir Asokan
// Copyright (c) 2022 Tulir Asokan
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@ -36,6 +36,8 @@ var (
// QRChannelErrUnexpectedEvent is emitted from GetQRChannel if an unexpected connection event is received,
// as that likely means that the pairing has already happened before the channel was set up.
QRChannelErrUnexpectedEvent = QRChannelItem{Event: "err-unexpected-state"}
// QRChannelClientOutdated is emitted from GetQRChannel if events.ClientOutdated is received.
QRChannelClientOutdated = QRChannelItem{Event: "err-client-outdated"}
// QRChannelScannedWithoutMultidevice is emitted from GetQRChannel if events.QRScannedWithoutMultidevice is received.
QRChannelScannedWithoutMultidevice = QRChannelItem{Event: "err-scanned-without-multidevice"}
)
@ -117,6 +119,8 @@ func (qrc *qrChannel) handleEvent(rawEvt interface{}) {
qrc.log.Debugf("QR code scanned without multidevice enabled")
qrc.output <- QRChannelScannedWithoutMultidevice
return
case *events.ClientOutdated:
outputType = QRChannelClientOutdated
case *events.PairSuccess:
outputType = QRChannelSuccess
case *events.PairError:
@ -126,7 +130,7 @@ func (qrc *qrChannel) handleEvent(rawEvt interface{}) {
}
case *events.Disconnected:
outputType = QRChannelTimeout
case *events.Connected, *events.ConnectFailure, *events.LoggedOut:
case *events.Connected, *events.ConnectFailure, *events.LoggedOut, *events.TemporaryBan:
outputType = QRChannelErrUnexpectedEvent
default:
return

@ -8,6 +8,7 @@ package whatsmeow
import (
"fmt"
"sync/atomic"
"time"
waBinary "go.mau.fi/whatsmeow/binary"
@ -123,13 +124,35 @@ func (cli *Client) MarkRead(ids []types.MessageID, timestamp time.Time, chat, se
return cli.sendNode(node)
}
// SetForceActiveDeliveryReceipts will force the client to send normal delivery
// receipts (which will show up as the two gray ticks on WhatsApp), even if the
// client isn't marked as online.
//
// By default, clients that haven't been marked as online will send delivery
// receipts with type="inactive", which is transmitted to the sender, but not
// rendered in the official WhatsApp apps. This is consistent with how WhatsApp
// web works when it's not in the foreground.
//
// To mark the client as online, use
// cli.SendPresence(types.PresenceAvailable)
//
// Note that if you turn this off (i.e. call SetForceActiveDeliveryReceipts(false)),
// receipts will act like the client is offline until SendPresence is called again.
func (cli *Client) SetForceActiveDeliveryReceipts(active bool) {
if active {
atomic.StoreUint32(&cli.sendActiveReceipts, 2)
} else {
atomic.StoreUint32(&cli.sendActiveReceipts, 0)
}
}
func (cli *Client) sendMessageReceipt(info *types.MessageInfo) {
attrs := waBinary.Attrs{
"id": info.ID,
}
if info.IsFromMe {
attrs["type"] = "sender"
} else {
} else if atomic.LoadUint32(&cli.sendActiveReceipts) == 0 {
attrs["type"] = "inactive"
}
attrs["to"] = info.Chat
@ -137,6 +160,9 @@ func (cli *Client) sendMessageReceipt(info *types.MessageInfo) {
attrs["participant"] = info.Sender
} else if info.IsFromMe {
attrs["recipient"] = info.Sender
} else {
// Override the to attribute with the JID version with a device number
attrs["to"] = info.Sender
}
err := cli.sendNode(waBinary.Node{
Tag: "receipt",

@ -78,6 +78,7 @@ type infoQuery struct {
Namespace string
Type infoQueryType
To types.JID
Target types.JID
ID string
Content interface{}
@ -98,6 +99,9 @@ func (cli *Client) sendIQAsync(query infoQuery) (<-chan *waBinary.Node, error) {
if !query.To.IsEmpty() {
attrs["to"] = query.To
}
if !query.Target.IsEmpty() {
attrs["target"] = query.Target
}
err := cli.sendNode(waBinary.Node{
Tag: "iq",
Attrs: attrs,
@ -116,7 +120,7 @@ func (cli *Client) sendIQ(query infoQuery) (*waBinary.Node, error) {
return nil, err
}
if query.Timeout == 0 {
query.Timeout = 1 * time.Minute
query.Timeout = 75 * time.Second
}
if query.Context == nil {
query.Context = context.Background()

@ -30,6 +30,9 @@ import (
)
// GenerateMessageID generates a random string that can be used as a message ID on WhatsApp.
//
// msgID := whatsmeow.GenerateMessageID()
// cli.SendMessage(targetJID, msgID, &waProto.Message{...})
func GenerateMessageID() types.MessageID {
id := make([]byte, 16)
_, err := rand.Read(id)
@ -46,6 +49,20 @@ func GenerateMessageID() types.MessageID {
//
// This method will wait for the server to acknowledge the message before returning.
// The return value is the timestamp of the message from the server.
//
// The message itself can contain anything you want (within the protobuf schema).
// e.g. for a simple text message, use the Conversation field:
// cli.SendMessage(targetJID, "", &waProto.Message{
// Conversation: proto.String("Hello, World!"),
// })
//
// Things like replies, mentioning users and the "forwarded" flag are stored in ContextInfo,
// which can be put in ExtendedTextMessage and any of the media message types.
//
// For uploading and sending media/attachments, see the Upload method.
//
// For other message types, you'll have to figure it out yourself. Looking at the protobuf schema
// in binary/proto/def.proto may be useful to find out all the allowed fields.
func (cli *Client) SendMessage(to types.JID, id types.MessageID, message *waProto.Message) (time.Time, error) {
if to.AD {
return time.Time{}, ErrRecipientADJID
@ -210,7 +227,7 @@ func (cli *Client) prepareMessageNode(to types.JID, id types.MessageID, message
Content: participantNodes,
}},
}
if message.ProtocolMessage != nil && message.GetProtocolMessage().GetType() == waProto.ProtocolMessage_REVOKE {
if message.ProtocolMessage != nil && message.GetProtocolMessage().GetType() == waProto.ProtocolMessage_REVOKE && message.GetProtocolMessage().GetKey() != nil {
node.Attrs["edit"] = "7"
}
if includeIdentity {

@ -10,7 +10,11 @@
// The Client struct in the top-level whatsmeow package handles everything.
package socket
import "errors"
import (
"errors"
"go.mau.fi/whatsmeow/binary/token"
)
const (
// Origin is the Origin header for all WhatsApp websocket connections
@ -22,11 +26,10 @@ const (
const (
NoiseStartPattern = "Noise_XX_25519_AESGCM_SHA256\x00\x00\x00\x00"
WADictVersion = 2
WAMagicValue = 5
WAMagicValue = 5
)
var WAConnHeader = []byte{'W', 'A', WAMagicValue, WADictVersion}
var WAConnHeader = []byte{'W', 'A', WAMagicValue, token.DictVersion}
const (
FrameMaxSize = 2 << 23

@ -11,6 +11,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"sync"
"time"
@ -19,6 +20,8 @@ import (
waLog "go.mau.fi/whatsmeow/util/log"
)
type Proxy = func(*http.Request) (*url.URL, error)
type FrameSocket struct {
conn *websocket.Conn
ctx context.Context
@ -31,6 +34,7 @@ type FrameSocket struct {
WriteTimeout time.Duration
Header []byte
Proxy Proxy
incomingLength int
receivedLength int
@ -38,12 +42,14 @@ type FrameSocket struct {
partialHeader []byte
}
func NewFrameSocket(log waLog.Logger, header []byte) *FrameSocket {
func NewFrameSocket(log waLog.Logger, header []byte, proxy Proxy) *FrameSocket {
return &FrameSocket{
conn: nil,
log: log,
Header: header,
Frames: make(chan []byte),
Proxy: proxy,
}
}
@ -92,7 +98,9 @@ func (fs *FrameSocket) Connect() error {
return ErrSocketAlreadyOpen
}
ctx, cancel := context.WithCancel(context.Background())
dialer := websocket.Dialer{}
dialer := websocket.Dialer{
Proxy: fs.Proxy,
}
headers := http.Header{"Origin": []string{Origin}}
fs.log.Debugf("Dialing %s", URL)

@ -20,36 +20,98 @@ import (
waProto "go.mau.fi/whatsmeow/binary/proto"
)
// WAVersionContainer is a container for a WhatsApp web version number.
type WAVersionContainer [3]uint32
// ParseVersion parses a version string (three dot-separated numbers) into a WAVersionContainer.
func ParseVersion(version string) (parsed WAVersionContainer, err error) {
var part1, part2, part3 int
if parts := strings.Split(version, "."); len(parts) != 3 {
err = fmt.Errorf("'%s' doesn't contain three dot-separated parts", version)
} else if part1, err = strconv.Atoi(parts[0]); err != nil {
err = fmt.Errorf("first part of '%s' is not a number: %w", version, err)
} else if part2, err = strconv.Atoi(parts[1]); err != nil {
err = fmt.Errorf("second part of '%s' is not a number: %w", version, err)
} else if part3, err = strconv.Atoi(parts[2]); err != nil {
err = fmt.Errorf("third part of '%s' is not a number: %w", version, err)
} else {
parsed = WAVersionContainer{uint32(part1), uint32(part2), uint32(part3)}
}
return
}
func (vc WAVersionContainer) LessThan(other WAVersionContainer) bool {
return vc[0] < other[0] ||
(vc[0] == other[0] && vc[1] < other[1]) ||
(vc[0] == other[0] && vc[1] == other[1] && vc[2] < other[2])
}
// IsZero returns true if the version is zero.
func (vc WAVersionContainer) IsZero() bool {
return vc == [3]uint32{0, 0, 0}
}
// String returns the version number as a dot-separated string.
func (vc WAVersionContainer) String() string {
parts := make([]string, len(vc))
for i, part := range vc {
parts[i] = strconv.Itoa(int(part))
}
return strings.Join(parts, ".")
}
// Hash returns the md5 hash of the String representation of this version.
func (vc WAVersionContainer) Hash() [16]byte {
return md5.Sum([]byte(vc.String()))
}
func (vc WAVersionContainer) ProtoAppVersion() *waProto.AppVersion {
return &waProto.AppVersion{
Primary: &vc[0],
Secondary: &vc[1],
Tertiary: &vc[2],
}
}
// waVersion is the WhatsApp web client version
var waVersion = []uint32{2, 2202, 9}
var waVersion = WAVersionContainer{2, 2208, 7}
// waVersionHash is the md5 hash of a dot-separated waVersion
var waVersionHash [16]byte
func init() {
waVersionParts := make([]string, len(waVersion))
for i, part := range waVersion {
waVersionParts[i] = strconv.Itoa(int(part))
waVersionHash = waVersion.Hash()
}
// GetWAVersion gets the current WhatsApp web client version.
func GetWAVersion() WAVersionContainer {
return waVersion
}
// SetWAVersion sets the current WhatsApp web client version.
//
// In general, you should keep the library up-to-date instead of using this,
// as there may be code changes that are necessary too (like protobuf schema changes).
func SetWAVersion(version WAVersionContainer) {
if version.IsZero() {
return
}
waVersionString := strings.Join(waVersionParts, ".")
waVersionHash = md5.Sum([]byte(waVersionString))
waVersion = version
waVersionHash = version.Hash()
}
var BaseClientPayload = &waProto.ClientPayload{
UserAgent: &waProto.UserAgent{
Platform: waProto.UserAgent_WEB.Enum(),
ReleaseChannel: waProto.UserAgent_RELEASE.Enum(),
AppVersion: &waProto.AppVersion{
Primary: &waVersion[0],
Secondary: &waVersion[1],
Tertiary: &waVersion[2],
},
Mcc: proto.String("000"),
Mnc: proto.String("000"),
OsVersion: proto.String("0.1.0"),
Manufacturer: proto.String(""),
Device: proto.String("Desktop"),
OsBuildNumber: proto.String("0.1.0"),
AppVersion: waVersion.ProtoAppVersion(),
Mcc: proto.String("000"),
Mnc: proto.String("000"),
OsVersion: proto.String("0.1.0"),
Manufacturer: proto.String(""),
Device: proto.String("Desktop"),
OsBuildNumber: proto.String("0.1.0"),
LocaleLanguageIso6391: proto.String("en"),
LocaleCountryIso31661Alpha2: proto.String("en"),
},

@ -1,4 +1,4 @@
// Copyright (c) 2021 Tulir Asokan
// Copyright (c) 2022 Tulir Asokan
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@ -349,15 +349,15 @@ func (s *SQLStore) putAppStateMutationMACs(tx execable, name string, version uin
values[0] = s.JID
values[1] = name
values[2] = version
placeholderSyntax := "($1, $2, $3, $%d, $%d)"
if s.dialect == "sqlite3" {
placeholderSyntax = "(?1, ?2, ?3, ?%d, ?%d)"
}
for i, mutation := range mutations {
baseIndex := 3 + i*2
values[baseIndex] = mutation.IndexMAC
values[baseIndex+1] = mutation.ValueMAC
if s.dialect == "sqlite3" {
queryParts[i] = fmt.Sprintf("(?1, ?2, ?3, ?%d, ?%d)", baseIndex+1, baseIndex+2)
} else {
queryParts[i] = fmt.Sprintf("($1, $2, $3, $%d, $%d)", baseIndex+1, baseIndex+2)
}
queryParts[i] = fmt.Sprintf(placeholderSyntax, baseIndex+1, baseIndex+2)
}
_, err := tx.Exec(putAppStateMutationMACsQuery+strings.Join(queryParts, ","), values...)
return err
@ -426,7 +426,12 @@ func (s *SQLStore) GetAppStateMutationMAC(name string, indexMAC []byte) (valueMA
const (
putContactNameQuery = `
INSERT INTO whatsmeow_contacts (our_jid, their_jid, first_name, full_name) VALUES ($1, $2, $3, $4)
ON CONFLICT (our_jid, their_jid) DO UPDATE SET first_name=$3, full_name=$4
ON CONFLICT (our_jid, their_jid) DO UPDATE SET first_name=excluded.first_name, full_name=excluded.full_name
`
putManyContactNamesQuery = `
INSERT INTO whatsmeow_contacts (our_jid, their_jid, first_name, full_name)
VALUES %s
ON CONFLICT (our_jid, their_jid) DO UPDATE SET first_name=excluded.first_name, full_name=excluded.full_name
`
putPushNameQuery = `
INSERT INTO whatsmeow_contacts (our_jid, their_jid, push_name) VALUES ($1, $2, $3)
@ -504,6 +509,77 @@ func (s *SQLStore) PutContactName(user types.JID, firstName, fullName string) er
return nil
}
const contactBatchSize = 300
func (s *SQLStore) putContactNamesBatch(tx execable, contacts []store.ContactEntry) error {
values := make([]interface{}, 1, 1+len(contacts)*3)
queryParts := make([]string, 0, len(contacts))
values[0] = s.JID
placeholderSyntax := "($1, $%d, $%d, $%d)"
if s.dialect == "sqlite3" {
placeholderSyntax = "(?1, ?%d, ?%d, ?%d)"
}
i := 0
handledContacts := make(map[types.JID]struct{}, len(contacts))
for _, contact := range contacts {
if contact.JID.IsEmpty() {
s.log.Warnf("Empty contact info in mass insert: %+v", contact)
continue
}
// The whole query will break if there are duplicates, so make sure there aren't any duplicates
_, alreadyHandled := handledContacts[contact.JID]
if alreadyHandled {
s.log.Warnf("Duplicate contact info for %s in mass insert", contact.JID)
continue
}
handledContacts[contact.JID] = struct{}{}
baseIndex := i*3 + 1
values = append(values, contact.JID.String(), contact.FirstName, contact.FullName)
queryParts = append(queryParts, fmt.Sprintf(placeholderSyntax, baseIndex+1, baseIndex+2, baseIndex+3))
i++
}
_, err := tx.Exec(fmt.Sprintf(putManyContactNamesQuery, strings.Join(queryParts, ",")), values...)
return err
}
func (s *SQLStore) PutAllContactNames(contacts []store.ContactEntry) error {
if len(contacts) > contactBatchSize {
tx, err := s.db.Begin()
if err != nil {
return fmt.Errorf("failed to start transaction: %w", err)
}
for i := 0; i < len(contacts); i += contactBatchSize {
var contactSlice []store.ContactEntry
if len(contacts) > i+contactBatchSize {
contactSlice = contacts[i : i+contactBatchSize]
} else {
contactSlice = contacts[i:]
}
err = s.putContactNamesBatch(tx, contactSlice)
if err != nil {
_ = tx.Rollback()
return err
}
}
err = tx.Commit()
if err != nil {
return fmt.Errorf("failed to commit transaction: %w", err)
}
} else if len(contacts) > 0 {
err := s.putContactNamesBatch(s.db, contacts)
if err != nil {
return err
}
} else {
return nil
}
s.contactCacheLock.Lock()
// Just clear the cache, fetching pushnames and business names would be too much effort
s.contactCache = make(map[types.JID]*types.ContactInfo)
s.contactCacheLock.Unlock()
return nil
}
func (s *SQLStore) getContact(user types.JID) (*types.ContactInfo, error) {
cached, ok := s.contactCache[user]
if ok {

@ -1,4 +1,4 @@
// Copyright (c) 2021 Tulir Asokan
// Copyright (c) 2022 Tulir Asokan
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@ -71,10 +71,17 @@ type AppStateStore interface {
GetAppStateMutationMAC(name string, indexMAC []byte) (valueMAC []byte, err error)
}
type ContactEntry struct {
JID types.JID
FirstName string
FullName string
}
type ContactStore interface {
PutPushName(user types.JID, pushName string) (bool, string, error)
PutBusinessName(user types.JID, businessName string) error
PutContactName(user types.JID, fullName, firstName string) error
PutAllContactNames(contacts []ContactEntry) error
GetContact(user types.JID) (types.ContactInfo, error)
GetAllContacts() (map[types.JID]types.ContactInfo, error)
}

@ -76,6 +76,14 @@ type Archive struct {
Action *waProto.ArchiveChatAction // The current archival status of the chat.
}
// MarkChatAsRead is emitted when a whole chat is marked as read or unread from another device.
type MarkChatAsRead struct {
JID types.JID // The chat which was marked as read or unread.
Timestamp time.Time // The time when the marking happened.
Action *waProto.MarkChatAsReadAction // Whether the chat was marked as read or unread, and info about the most recent messages.
}
// PushNameSetting is emitted when the user's push name is changed from another device.
type PushNameSetting struct {
Timestamp time.Time // The time when the push name was changed.

@ -62,6 +62,8 @@ type LoggedOut struct {
// OnConnect is true if the event was triggered by a connect failure message.
// If it's false, the event was triggered by a stream:error message.
OnConnect bool
// If OnConnect is true, then this field contains the reason code.
Reason ConnectFailureReason
}
// StreamReplaced is emitted when the client is disconnected by another client connecting with the same keys.
@ -70,14 +72,96 @@ type LoggedOut struct {
// or otherwise try to connect twice with the same session.
type StreamReplaced struct{}
// TempBanReason is an error code included in temp ban error events.
type TempBanReason int
const (
TempBanBlockedByUsers TempBanReason = 101
TempBanSentToTooManyPeople TempBanReason = 102
TempBanCreatedTooManyGroups TempBanReason = 103
TempBanSentTooManySameMessage TempBanReason = 104
TempBanBroadcastList TempBanReason = 106
)
var tempBanReasonMessage = map[TempBanReason]string{
TempBanBlockedByUsers: "too many people blocked you",
TempBanSentToTooManyPeople: "you sent too many messages to people who don't have you in their address books",
TempBanCreatedTooManyGroups: "you created too many groups with people who don't have you in their address books",
TempBanSentTooManySameMessage: "you sent the same message to too many people",
TempBanBroadcastList: "you sent too many messages to a broadcast list",
}
// String returns the reason code and a human-readable description of the ban reason.
func (tbr TempBanReason) String() string {
msg, ok := tempBanReasonMessage[tbr]
if !ok {
msg = "you may have violated the terms of service (unknown error)"
}
return fmt.Sprintf("%d: %s", int(tbr), msg)
}
// TemporaryBan is emitted when there's a connection failure with the ConnectFailureTempBanned reason code.
type TemporaryBan struct {
Code TempBanReason
Expire time.Time
}
func (tb *TemporaryBan) String() string {
if tb.Expire.IsZero() {
return fmt.Sprintf("You've been temporarily banned: %v", tb.Code)
}
return fmt.Sprintf("You've been temporarily banned: %v. The ban expires at %v", tb.Code, tb.Expire)
}
// ConnectFailureReason is an error code included in connection failure events.
type ConnectFailureReason int
const (
ConnectFailureLoggedOut ConnectFailureReason = 401
ConnectFailureTempBanned ConnectFailureReason = 402
ConnectFailureBanned ConnectFailureReason = 403
ConnectFailureUnknownLogout ConnectFailureReason = 406
ConnectFailureClientOutdated ConnectFailureReason = 405
ConnectFailureBadUserAgent ConnectFailureReason = 409
// 400, 500 and 501 are also existing codes, but the meaning is unknown
)
var connectFailureReasonMessage = map[ConnectFailureReason]string{
ConnectFailureLoggedOut: "logged out from another device",
ConnectFailureTempBanned: "account temporarily banned",
ConnectFailureBanned: "account banned from WhatsApp",
ConnectFailureUnknownLogout: "logged out for unknown reason",
ConnectFailureClientOutdated: "client is out of date",
ConnectFailureBadUserAgent: "client user agent was rejected",
}
// IsLoggedOut returns true if the client should delete session data due to this connect failure.
func (cfr ConnectFailureReason) IsLoggedOut() bool {
return cfr == ConnectFailureLoggedOut || cfr == ConnectFailureBanned || cfr == ConnectFailureUnknownLogout
}
// String returns the reason code and a short human-readable description of the error.
func (cfr ConnectFailureReason) String() string {
msg, ok := connectFailureReasonMessage[cfr]
if !ok {
msg = "unknown error"
}
return fmt.Sprintf("%d: %s", int(cfr), msg)
}
// ConnectFailure is emitted when the WhatsApp server sends a <failure> node with an unknown reason.
//
// Known reasons are handled internally and emitted as different events (e.g. LoggedOut).
// Known reasons are handled internally and emitted as different events (e.g. LoggedOut and TemporaryBan).
type ConnectFailure struct {
Reason string
Reason ConnectFailureReason
Raw *waBinary.Node
}
// ClientOutdated is emitted when the WhatsApp server rejects the connection with the ConnectFailureClientOutdated code.
type ClientOutdated struct{}
// StreamError is emitted when the WhatsApp server sends a <stream:error> node with an unknown code.
//
// Known codes are handled internally and emitted as different events (e.g. LoggedOut).
@ -165,7 +249,8 @@ type Receipt struct {
// client.SendPresence(types.PresenceAvailable)
type ChatPresence struct {
types.MessageSource
State types.ChatPresence
State types.ChatPresence // The current state, either composing or paused
Media types.ChatPresenceMedia // When composing, the type of message
}
// Presence is emitted when a presence update is received.
@ -261,3 +346,16 @@ type OfflineSyncPreview struct {
type OfflineSyncCompleted struct {
Count int
}
// MediaRetry is emitted when the phone sends a response to a media retry request.
type MediaRetry struct {
Ciphertext []byte
IV []byte
Timestamp time.Time // The time of the response.
MessageID types.MessageID // The ID of the message.
ChatID types.JID // The chat ID where the message was sent.
SenderID types.JID // The user who sent the message. Only present in groups.
FromMe bool // Whether the message was sent by the current user or someone else.
}

@ -155,6 +155,21 @@ func (jid JID) String() string {
}
}
// MarshalText implements encoding.TextMarshaler for JID
func (jid JID) MarshalText() ([]byte, error) {
return []byte(jid.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaler for JID
func (jid *JID) UnmarshalText(val []byte) error {
out, err := ParseJID(string(val))
if err != nil {
return err
}
*jid = out
return nil
}
// IsEmpty returns true if the JID has no server (which is required for all JIDs).
func (jid JID) IsEmpty() bool {
return len(jid.Server) == 0

@ -17,6 +17,12 @@ type ChatPresence string
const (
ChatPresenceComposing ChatPresence = "composing"
ChatPresenceRecording ChatPresence = "recording"
ChatPresencePaused ChatPresence = "paused"
)
type ChatPresenceMedia string
const (
ChatPresenceMediaText ChatPresenceMedia = ""
ChatPresenceMediaAudio ChatPresenceMedia = "audio"
)

@ -0,0 +1,81 @@
// Copyright (c) 2022 Tulir Asokan
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package whatsmeow
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"go.mau.fi/whatsmeow/socket"
"go.mau.fi/whatsmeow/store"
)
// CheckUpdateResponse is the data returned by CheckUpdate.
type CheckUpdateResponse struct {
IsBroken bool
IsBelowSoft bool
IsBelowHard bool
CurrentVersion string
ParsedVersion store.WAVersionContainer `json:"-"`
}
// CheckUpdateURL is the base URL to check for WhatsApp web updates.
const CheckUpdateURL = "https://web.whatsapp.com/check-update"
// CheckUpdate asks the WhatsApp servers if there is an update available
// (using the HTTP client and proxy settings of this whatsmeow Client instance).
func (cli *Client) CheckUpdate() (respData CheckUpdateResponse, err error) {
return CheckUpdate(http.DefaultClient)
}
// CheckUpdate asks the WhatsApp servers if there is an update available.
func CheckUpdate(httpClient *http.Client) (respData CheckUpdateResponse, err error) {
var reqURL *url.URL
reqURL, err = url.Parse(CheckUpdateURL)
if err != nil {
err = fmt.Errorf("failed to parse check update URL: %w", err)
return
}
q := reqURL.Query()
q.Set("version", store.GetWAVersion().String())
q.Set("platform", "web")
reqURL.RawQuery = q.Encode()
var req *http.Request
req, err = http.NewRequest(http.MethodGet, reqURL.String(), nil)
if err != nil {
err = fmt.Errorf("failed to prepare request: %w", err)
return
}
req.Header.Set("Origin", socket.Origin)
req.Header.Set("Referer", socket.Origin+"/")
var resp *http.Response
resp, err = httpClient.Do(req)
if err != nil {
err = fmt.Errorf("failed to send request: %w", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
body, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("unexpected response with status %d: %s", resp.StatusCode, body)
return
}
err = json.NewDecoder(resp.Body).Decode(&respData)
if err != nil {
err = fmt.Errorf("failed to decode response body (status %d): %w", resp.StatusCode, err)
return
}
respData.ParsedVersion, err = store.ParseVersion(respData.CurrentVersion)
if err != nil {
err = fmt.Errorf("failed to parse version string: %w", err)
}
return
}

@ -24,16 +24,41 @@ import (
// UploadResponse contains the data from the attachment upload, which can be put into a message to send the attachment.
type UploadResponse struct {
URL string
DirectPath string
URL string `json:"url"`
DirectPath string `json:"direct_path"`
MediaKey []byte
FileEncSHA256 []byte
FileSHA256 []byte
FileLength uint64
MediaKey []byte `json:"-"`
FileEncSHA256 []byte `json:"-"`
FileSHA256 []byte `json:"-"`
FileLength uint64 `json:"-"`
}
// Upload uploads the given attachment to WhatsApp servers.
//
// You should copy the fields in the response to the corresponding fields in a protobuf message.
//
// For example, to send an image:
// resp, err := cli.Upload(context.Background(), yourImageBytes, whatsmeow.MediaImage)
// // handle error
//
// imageMsg := &waProto.ImageMessage{
// Caption: proto.String("Hello, world!"),
// Mimetype: proto.String("image/png"), // replace this with the actual mime type
// // you can also optionally add other fields like ContextInfo and JpegThumbnail here
//
// Url: &resp.URL,
// DirectPath: &uploaded.DirectPath,
// MediaKey: resp.MediaKey,
// FileEncSha256: resp.FileEncSHA256,
// FileSha256: resp.FileSha256,
// FileLength: &resp.FileLength,
// }
// _, err = cli.SendMessage(targetJID, "", &waProto.Message{
// ImageMessage: imageMsg,
// })
// // handle error again
//
// The same applies to the other message types like DocumentMessage, just replace the struct type and Message field name.
func (cli *Client) Upload(ctx context.Context, plaintext []byte, appInfo MediaType) (resp UploadResponse, err error) {
resp.FileLength = uint64(len(plaintext))
resp.MediaKey = make([]byte, 32)
@ -92,7 +117,7 @@ func (cli *Client) Upload(ctx context.Context, plaintext []byte, appInfo MediaTy
req.Header.Set("Referer", socket.Origin+"/")
var httpResp *http.Response
httpResp, err = http.DefaultClient.Do(req)
httpResp, err = cli.http.Do(req)
if err != nil {
err = fmt.Errorf("failed to execute request: %w", err)
} else if httpResp.StatusCode != http.StatusOK {

@ -3,17 +3,20 @@
// license that can be found in the LICENSE file.
// Package acme provides an implementation of the
// Automatic Certificate Management Environment (ACME) spec.
// The initial implementation was based on ACME draft-02 and
// is now being extended to comply with RFC 8555.
// See https://tools.ietf.org/html/draft-ietf-acme-acme-02
// and https://tools.ietf.org/html/rfc8555 for details.
// Automatic Certificate Management Environment (ACME) spec,
// most famously used by Let's Encrypt.
//
// The initial implementation of this package was based on an early version
// of the spec. The current implementation supports only the modern
// RFC 8555 but some of the old API surface remains for compatibility.
// While code using the old API will still compile, it will return an error.
// Note the deprecation comments to update your code.
//
// See https://tools.ietf.org/html/rfc8555 for the spec.
//
// Most common scenarios will want to use autocert subdirectory instead,
// which provides automatic access to certificates from Let's Encrypt
// and any other ACME-based CA.
//
// This package is a work in progress and makes no API stability promises.
package acme
import (
@ -33,8 +36,6 @@ import (
"encoding/pem"
"errors"
"fmt"
"io"
"io/ioutil"
"math/big"
"net/http"
"strings"
@ -72,6 +73,7 @@ const (
)
// Client is an ACME client.
//
// The only required field is Key. An example of creating a client with a new key
// is as follows:
//
@ -125,7 +127,9 @@ type Client struct {
cacheMu sync.Mutex
dir *Directory // cached result of Client's Discover method
kid keyID // cached Account.URI obtained from registerRFC or getAccountRFC
// KID is the key identifier provided by the CA. If not provided it will be
// retrieved from the CA by making a call to the registration endpoint.
KID KeyID
noncesMu sync.Mutex
nonces map[string]struct{} // nonces collected from previous responses
@ -140,23 +144,22 @@ type Client struct {
//
// When in pre-RFC mode or when c.getRegRFC responds with an error, accountKID
// returns noKeyID.
func (c *Client) accountKID(ctx context.Context) keyID {
func (c *Client) accountKID(ctx context.Context) KeyID {
c.cacheMu.Lock()
defer c.cacheMu.Unlock()
if !c.dir.rfcCompliant() {
return noKeyID
}
if c.kid != noKeyID {
return c.kid
if c.KID != noKeyID {
return c.KID
}
a, err := c.getRegRFC(ctx)
if err != nil {
return noKeyID
}
c.kid = keyID(a.URI)
return c.kid
c.KID = KeyID(a.URI)
return c.KID
}
var errPreRFC = errors.New("acme: server does not support the RFC 8555 version of ACME")
// Discover performs ACME server discovery using c.DirectoryURL.
//
// It caches successful result. So, subsequent calls will not result in
@ -177,53 +180,36 @@ func (c *Client) Discover(ctx context.Context) (Directory, error) {
c.addNonce(res.Header)
var v struct {
Reg string `json:"new-reg"`
RegRFC string `json:"newAccount"`
Authz string `json:"new-authz"`
AuthzRFC string `json:"newAuthz"`
OrderRFC string `json:"newOrder"`
Cert string `json:"new-cert"`
Revoke string `json:"revoke-cert"`
RevokeRFC string `json:"revokeCert"`
NonceRFC string `json:"newNonce"`
KeyChangeRFC string `json:"keyChange"`
Meta struct {
Terms string `json:"terms-of-service"`
TermsRFC string `json:"termsOfService"`
WebsiteRFC string `json:"website"`
CAA []string `json:"caa-identities"`
CAARFC []string `json:"caaIdentities"`
ExternalAcctRFC bool `json:"externalAccountRequired"`
Reg string `json:"newAccount"`
Authz string `json:"newAuthz"`
Order string `json:"newOrder"`
Revoke string `json:"revokeCert"`
Nonce string `json:"newNonce"`
KeyChange string `json:"keyChange"`
Meta struct {
Terms string `json:"termsOfService"`
Website string `json:"website"`
CAA []string `json:"caaIdentities"`
ExternalAcct bool `json:"externalAccountRequired"`
}
}
if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
return Directory{}, err
}
if v.OrderRFC == "" {
// Non-RFC compliant ACME CA.
c.dir = &Directory{
RegURL: v.Reg,
AuthzURL: v.Authz,
CertURL: v.Cert,
RevokeURL: v.Revoke,
Terms: v.Meta.Terms,
Website: v.Meta.WebsiteRFC,
CAA: v.Meta.CAA,
}
return *c.dir, nil
if v.Order == "" {
return Directory{}, errPreRFC
}
// RFC compliant ACME CA.
c.dir = &Directory{
RegURL: v.RegRFC,
AuthzURL: v.AuthzRFC,
OrderURL: v.OrderRFC,
RevokeURL: v.RevokeRFC,
NonceURL: v.NonceRFC,
KeyChangeURL: v.KeyChangeRFC,
Terms: v.Meta.TermsRFC,
Website: v.Meta.WebsiteRFC,
CAA: v.Meta.CAARFC,
ExternalAccountRequired: v.Meta.ExternalAcctRFC,
RegURL: v.Reg,
AuthzURL: v.Authz,
OrderURL: v.Order,
RevokeURL: v.Revoke,
NonceURL: v.Nonce,
KeyChangeURL: v.KeyChange,
Terms: v.Meta.Terms,
Website: v.Meta.Website,
CAA: v.Meta.CAA,
ExternalAccountRequired: v.Meta.ExternalAcct,
}
return *c.dir, nil
}
@ -235,55 +221,11 @@ func (c *Client) directoryURL() string {
return LetsEncryptURL
}
// CreateCert requests a new certificate using the Certificate Signing Request csr encoded in DER format.
// It is incompatible with RFC 8555. Callers should use CreateOrderCert when interfacing
// with an RFC-compliant CA.
// CreateCert was part of the old version of ACME. It is incompatible with RFC 8555.
//
// The exp argument indicates the desired certificate validity duration. CA may issue a certificate
// with a different duration.
// If the bundle argument is true, the returned value will also contain the CA (issuer) certificate chain.
//
// In the case where CA server does not provide the issued certificate in the response,
// CreateCert will poll certURL using c.FetchCert, which will result in additional round-trips.
// In such a scenario, the caller can cancel the polling with ctx.
//
// CreateCert returns an error if the CA's response or chain was unreasonably large.
// Callers are encouraged to parse the returned value to ensure the certificate is valid and has the expected features.
// Deprecated: this was for the pre-RFC 8555 version of ACME. Callers should use CreateOrderCert.
func (c *Client) CreateCert(ctx context.Context, csr []byte, exp time.Duration, bundle bool) (der [][]byte, certURL string, err error) {
if _, err := c.Discover(ctx); err != nil {
return nil, "", err
}
req := struct {
Resource string `json:"resource"`
CSR string `json:"csr"`
NotBefore string `json:"notBefore,omitempty"`
NotAfter string `json:"notAfter,omitempty"`
}{
Resource: "new-cert",
CSR: base64.RawURLEncoding.EncodeToString(csr),
}
now := timeNow()
req.NotBefore = now.Format(time.RFC3339)
if exp > 0 {
req.NotAfter = now.Add(exp).Format(time.RFC3339)
}
res, err := c.post(ctx, nil, c.dir.CertURL, req, wantStatus(http.StatusCreated))
if err != nil {
return nil, "", err
}
defer res.Body.Close()
curl := res.Header.Get("Location") // cert permanent URL
if res.ContentLength == 0 {
// no cert in the body; poll until we get it
cert, err := c.FetchCert(ctx, curl, bundle)
return cert, curl, err
}
// slurp issued cert and CA chain, if requested
cert, err := c.responseCert(ctx, res, bundle)
return cert, curl, err
return nil, "", errPreRFC
}
// FetchCert retrieves already issued certificate from the given url, in DER format.
@ -297,20 +239,10 @@ func (c *Client) CreateCert(ctx context.Context, csr []byte, exp time.Duration,
// Callers are encouraged to parse the returned value to ensure the certificate is valid
// and has expected features.
func (c *Client) FetchCert(ctx context.Context, url string, bundle bool) ([][]byte, error) {
dir, err := c.Discover(ctx)
if err != nil {
return nil, err
}
if dir.rfcCompliant() {
return c.fetchCertRFC(ctx, url, bundle)
}
// Legacy non-authenticated GET request.
res, err := c.get(ctx, url, wantStatus(http.StatusOK))
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return nil, err
}
return c.responseCert(ctx, res, bundle)
return c.fetchCertRFC(ctx, url, bundle)
}
// RevokeCert revokes a previously issued certificate cert, provided in DER format.
@ -320,30 +252,10 @@ func (c *Client) FetchCert(ctx context.Context, url string, bundle bool) ([][]by
// For instance, the key pair of the certificate may be authorized.
// If the key is nil, c.Key is used instead.
func (c *Client) RevokeCert(ctx context.Context, key crypto.Signer, cert []byte, reason CRLReasonCode) error {
dir, err := c.Discover(ctx)
if err != nil {
return err
}
if dir.rfcCompliant() {
return c.revokeCertRFC(ctx, key, cert, reason)
}
// Legacy CA.
body := &struct {
Resource string `json:"resource"`
Cert string `json:"certificate"`
Reason int `json:"reason"`
}{
Resource: "revoke-cert",
Cert: base64.RawURLEncoding.EncodeToString(cert),
Reason: int(reason),
}
res, err := c.post(ctx, key, dir.RevokeURL, body, wantStatus(http.StatusOK))
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return err
}
defer res.Body.Close()
return nil
return c.revokeCertRFC(ctx, key, cert, reason)
}
// AcceptTOS always returns true to indicate the acceptance of a CA's Terms of Service
@ -366,75 +278,33 @@ func (c *Client) Register(ctx context.Context, acct *Account, prompt func(tosURL
if c.Key == nil {
return nil, errors.New("acme: client.Key must be set to Register")
}
dir, err := c.Discover(ctx)
if err != nil {
return nil, err
}
if dir.rfcCompliant() {
return c.registerRFC(ctx, acct, prompt)
}
// Legacy ACME draft registration flow.
a, err := c.doReg(ctx, dir.RegURL, "new-reg", acct)
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return nil, err
}
var accept bool
if a.CurrentTerms != "" && a.CurrentTerms != a.AgreedTerms {
accept = prompt(a.CurrentTerms)
}
if accept {
a.AgreedTerms = a.CurrentTerms
a, err = c.UpdateReg(ctx, a)
}
return a, err
return c.registerRFC(ctx, acct, prompt)
}
// GetReg retrieves an existing account associated with c.Key.
//
// The url argument is an Account URI used with pre-RFC 8555 CAs.
// It is ignored when interfacing with an RFC-compliant CA.
// The url argument is a legacy artifact of the pre-RFC 8555 API
// and is ignored.
func (c *Client) GetReg(ctx context.Context, url string) (*Account, error) {
dir, err := c.Discover(ctx)
if err != nil {
return nil, err
}
if dir.rfcCompliant() {
return c.getRegRFC(ctx)
}
// Legacy CA.
a, err := c.doReg(ctx, url, "reg", nil)
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return nil, err
}
a.URI = url
return a, nil
return c.getRegRFC(ctx)
}
// UpdateReg updates an existing registration.
// It returns an updated account copy. The provided account is not modified.
//
// When interfacing with RFC-compliant CAs, a.URI is ignored and the account URL
// associated with c.Key is used instead.
// The account's URI is ignored and the account URL associated with
// c.Key is used instead.
func (c *Client) UpdateReg(ctx context.Context, acct *Account) (*Account, error) {
dir, err := c.Discover(ctx)
if err != nil {
return nil, err
}
if dir.rfcCompliant() {
return c.updateRegRFC(ctx, acct)
}
// Legacy CA.
uri := acct.URI
a, err := c.doReg(ctx, uri, "reg", acct)
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return nil, err
}
a.URI = uri
return a, nil
return c.updateRegRFC(ctx, acct)
}
// Authorize performs the initial step in the pre-authorization flow,
@ -503,17 +373,11 @@ func (c *Client) authorize(ctx context.Context, typ, val string) (*Authorization
// If a caller needs to poll an authorization until its status is final,
// see the WaitAuthorization method.
func (c *Client) GetAuthorization(ctx context.Context, url string) (*Authorization, error) {
dir, err := c.Discover(ctx)
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return nil, err
}
var res *http.Response
if dir.rfcCompliant() {
res, err = c.postAsGet(ctx, url, wantStatus(http.StatusOK))
} else {
res, err = c.get(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
}
res, err := c.postAsGet(ctx, url, wantStatus(http.StatusOK))
if err != nil {
return nil, err
}
@ -535,7 +399,6 @@ func (c *Client) GetAuthorization(ctx context.Context, url string) (*Authorizati
//
// It does not revoke existing certificates.
func (c *Client) RevokeAuthorization(ctx context.Context, url string) error {
// Required for c.accountKID() when in RFC mode.
if _, err := c.Discover(ctx); err != nil {
return err
}
@ -565,18 +428,11 @@ func (c *Client) RevokeAuthorization(ctx context.Context, url string) error {
// In all other cases WaitAuthorization returns an error.
// If the Status is StatusInvalid, the returned error is of type *AuthorizationError.
func (c *Client) WaitAuthorization(ctx context.Context, url string) (*Authorization, error) {
// Required for c.accountKID() when in RFC mode.
dir, err := c.Discover(ctx)
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return nil, err
}
getfn := c.postAsGet
if !dir.rfcCompliant() {
getfn = c.get
}
for {
res, err := getfn(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
res, err := c.postAsGet(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
if err != nil {
return nil, err
}
@ -619,17 +475,11 @@ func (c *Client) WaitAuthorization(ctx context.Context, url string) (*Authorizat
//
// A client typically polls a challenge status using this method.
func (c *Client) GetChallenge(ctx context.Context, url string) (*Challenge, error) {
// Required for c.accountKID() when in RFC mode.
dir, err := c.Discover(ctx)
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return nil, err
}
getfn := c.postAsGet
if !dir.rfcCompliant() {
getfn = c.get
}
res, err := getfn(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
res, err := c.postAsGet(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
if err != nil {
return nil, err
}
@ -647,29 +497,11 @@ func (c *Client) GetChallenge(ctx context.Context, url string) (*Challenge, erro
//
// The server will then perform the validation asynchronously.
func (c *Client) Accept(ctx context.Context, chal *Challenge) (*Challenge, error) {
// Required for c.accountKID() when in RFC mode.
dir, err := c.Discover(ctx)
if err != nil {
if _, err := c.Discover(ctx); err != nil {
return nil, err
}
var req interface{} = json.RawMessage("{}") // RFC-compliant CA
if !dir.rfcCompliant() {
auth, err := keyAuth(c.Key.Public(), chal.Token)
if err != nil {
return nil, err
}
req = struct {
Resource string `json:"resource"`
Type string `json:"type"`
Auth string `json:"keyAuthorization"`
}{
Resource: "challenge",
Type: chal.Type,
Auth: auth,
}
}
res, err := c.post(ctx, nil, chal.URI, req, wantStatus(
res, err := c.post(ctx, nil, chal.URI, json.RawMessage("{}"), wantStatus(
http.StatusOK, // according to the spec
http.StatusAccepted, // Let's Encrypt: see https://goo.gl/WsJ7VT (acme-divergences.md)
))
@ -720,7 +552,7 @@ func (c *Client) HTTP01ChallengePath(token string) string {
// TLSSNI01ChallengeCert creates a certificate for TLS-SNI-01 challenge response.
//
// Deprecated: This challenge type is unused in both draft-02 and RFC versions of ACME spec.
// Deprecated: This challenge type is unused in both draft-02 and RFC versions of the ACME spec.
func (c *Client) TLSSNI01ChallengeCert(token string, opt ...CertOption) (cert tls.Certificate, name string, err error) {
ka, err := keyAuth(c.Key.Public(), token)
if err != nil {
@ -738,7 +570,7 @@ func (c *Client) TLSSNI01ChallengeCert(token string, opt ...CertOption) (cert tl
// TLSSNI02ChallengeCert creates a certificate for TLS-SNI-02 challenge response.
//
// Deprecated: This challenge type is unused in both draft-02 and RFC versions of ACME spec.
// Deprecated: This challenge type is unused in both draft-02 and RFC versions of the ACME spec.
func (c *Client) TLSSNI02ChallengeCert(token string, opt ...CertOption) (cert tls.Certificate, name string, err error) {
b := sha256.Sum256([]byte(token))
h := hex.EncodeToString(b[:])
@ -805,63 +637,6 @@ func (c *Client) TLSALPN01ChallengeCert(token, domain string, opt ...CertOption)
return tlsChallengeCert([]string{domain}, newOpt)
}
// doReg sends all types of registration requests the old way (pre-RFC world).
// The type of request is identified by typ argument, which is a "resource"
// in the ACME spec terms.
//
// A non-nil acct argument indicates whether the intention is to mutate data
// of the Account. Only Contact and Agreement of its fields are used
// in such cases.
func (c *Client) doReg(ctx context.Context, url string, typ string, acct *Account) (*Account, error) {
req := struct {
Resource string `json:"resource"`
Contact []string `json:"contact,omitempty"`
Agreement string `json:"agreement,omitempty"`
}{
Resource: typ,
}
if acct != nil {
req.Contact = acct.Contact
req.Agreement = acct.AgreedTerms
}
res, err := c.post(ctx, nil, url, req, wantStatus(
http.StatusOK, // updates and deletes
http.StatusCreated, // new account creation
http.StatusAccepted, // Let's Encrypt divergent implementation
))
if err != nil {
return nil, err
}
defer res.Body.Close()
var v struct {
Contact []string
Agreement string
Authorizations string
Certificates string
}
if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
return nil, fmt.Errorf("acme: invalid response: %v", err)
}
var tos string
if v := linkHeader(res.Header, "terms-of-service"); len(v) > 0 {
tos = v[0]
}
var authz string
if v := linkHeader(res.Header, "next"); len(v) > 0 {
authz = v[0]
}
return &Account{
URI: res.Header.Get("Location"),
Contact: v.Contact,
AgreedTerms: v.Agreement,
CurrentTerms: tos,
Authz: authz,
Authorizations: v.Authorizations,
Certificates: v.Certificates,
}, nil
}
// popNonce returns a nonce value previously stored with c.addNonce
// or fetches a fresh one from c.dir.NonceURL.
// If NonceURL is empty, it first tries c.directoryURL() and, failing that,
@ -936,78 +711,6 @@ func nonceFromHeader(h http.Header) string {
return h.Get("Replay-Nonce")
}
func (c *Client) responseCert(ctx context.Context, res *http.Response, bundle bool) ([][]byte, error) {
b, err := ioutil.ReadAll(io.LimitReader(res.Body, maxCertSize+1))
if err != nil {
return nil, fmt.Errorf("acme: response stream: %v", err)
}
if len(b) > maxCertSize {
return nil, errors.New("acme: certificate is too big")
}
cert := [][]byte{b}
if !bundle {
return cert, nil
}
// Append CA chain cert(s).
// At least one is required according to the spec:
// https://tools.ietf.org/html/draft-ietf-acme-acme-03#section-6.3.1
up := linkHeader(res.Header, "up")
if len(up) == 0 {
return nil, errors.New("acme: rel=up link not found")
}
if len(up) > maxChainLen {
return nil, errors.New("acme: rel=up link is too large")
}
for _, url := range up {
cc, err := c.chainCert(ctx, url, 0)
if err != nil {
return nil, err
}
cert = append(cert, cc...)
}
return cert, nil
}
// chainCert fetches CA certificate chain recursively by following "up" links.
// Each recursive call increments the depth by 1, resulting in an error
// if the recursion level reaches maxChainLen.
//
// First chainCert call starts with depth of 0.
func (c *Client) chainCert(ctx context.Context, url string, depth int) ([][]byte, error) {
if depth >= maxChainLen {
return nil, errors.New("acme: certificate chain is too deep")
}
res, err := c.get(ctx, url, wantStatus(http.StatusOK))
if err != nil {
return nil, err
}
defer res.Body.Close()
b, err := ioutil.ReadAll(io.LimitReader(res.Body, maxCertSize+1))
if err != nil {
return nil, err
}
if len(b) > maxCertSize {
return nil, errors.New("acme: certificate is too big")
}
chain := [][]byte{b}
uplink := linkHeader(res.Header, "up")
if len(uplink) > maxChainLen {
return nil, errors.New("acme: certificate chain is too large")
}
for _, up := range uplink {
cc, err := c.chainCert(ctx, up, depth+1)
if err != nil {
return nil, err
}
chain = append(chain, cc...)
}
return chain, nil
}
// linkHeader returns URI-Reference values of all Link headers
// with relation-type rel.
// See https://tools.ietf.org/html/rfc5988#section-5 for details.
@ -1098,5 +801,5 @@ func encodePEM(typ string, b []byte) []byte {
return pem.EncodeToMemory(pb)
}
// timeNow is useful for testing for fixed current time.
// timeNow is time.Now, except in tests which can mess with it.
var timeNow = time.Now

@ -47,6 +47,8 @@ var createCertRetryAfter = time.Minute
// pseudoRand is safe for concurrent use.
var pseudoRand *lockedMathRand
var errPreRFC = errors.New("autocert: ACME server doesn't support RFC 8555")
func init() {
src := mathrand.NewSource(time.Now().UnixNano())
pseudoRand = &lockedMathRand{rnd: mathrand.New(src)}
@ -456,7 +458,7 @@ func (m *Manager) cert(ctx context.Context, ck certKey) (*tls.Certificate, error
leaf: cert.Leaf,
}
m.state[ck] = s
go m.renew(ck, s.key, s.leaf.NotAfter)
go m.startRenew(ck, s.key, s.leaf.NotAfter)
return cert, nil
}
@ -582,8 +584,9 @@ func (m *Manager) createCert(ctx context.Context, ck certKey) (*tls.Certificate,
if err != nil {
// Remove the failed state after some time,
// making the manager call createCert again on the following TLS hello.
didRemove := testDidRemoveState // The lifetime of this timer is untracked, so copy mutable local state to avoid races.
time.AfterFunc(createCertRetryAfter, func() {
defer testDidRemoveState(ck)
defer didRemove(ck)
m.stateMu.Lock()
defer m.stateMu.Unlock()
// Verify the state hasn't changed and it's still invalid
@ -601,7 +604,7 @@ func (m *Manager) createCert(ctx context.Context, ck certKey) (*tls.Certificate,
}
state.cert = der
state.leaf = leaf
go m.renew(ck, state.key, state.leaf.NotAfter)
go m.startRenew(ck, state.key, state.leaf.NotAfter)
return state.tlscert()
}
@ -658,99 +661,24 @@ func (m *Manager) authorizedCert(ctx context.Context, key crypto.Signer, ck cert
if err != nil {
return nil, nil, err
}
if dir.OrderURL == "" {
return nil, nil, errPreRFC
}
var chain [][]byte
switch {
// Pre-RFC legacy CA.
case dir.OrderURL == "":
if err := m.verify(ctx, client, ck.domain); err != nil {
return nil, nil, err
}
der, _, err := client.CreateCert(ctx, csr, 0, true)
if err != nil {
return nil, nil, err
}
chain = der
// RFC 8555 compliant CA.
default:
o, err := m.verifyRFC(ctx, client, ck.domain)
if err != nil {
return nil, nil, err
}
der, _, err := client.CreateOrderCert(ctx, o.FinalizeURL, csr, true)
if err != nil {
return nil, nil, err
}
chain = der
o, err := m.verifyRFC(ctx, client, ck.domain)
if err != nil {
return nil, nil, err
}
leaf, err = validCert(ck, chain, key, m.now())
chain, _, err := client.CreateOrderCert(ctx, o.FinalizeURL, csr, true)
if err != nil {
return nil, nil, err
}
return chain, leaf, nil
}
// verify runs the identifier (domain) pre-authorization flow for legacy CAs
// using each applicable ACME challenge type.
func (m *Manager) verify(ctx context.Context, client *acme.Client, domain string) error {
// Remove all hanging authorizations to reduce rate limit quotas
// after we're done.
var authzURLs []string
defer func() {
go m.deactivatePendingAuthz(authzURLs)
}()
// errs accumulates challenge failure errors, printed if all fail
errs := make(map[*acme.Challenge]error)
challengeTypes := m.supportedChallengeTypes()
var nextTyp int // challengeType index of the next challenge type to try
for {
// Start domain authorization and get the challenge.
authz, err := client.Authorize(ctx, domain)
if err != nil {
return err
}
authzURLs = append(authzURLs, authz.URI)
// No point in accepting challenges if the authorization status
// is in a final state.
switch authz.Status {
case acme.StatusValid:
return nil // already authorized
case acme.StatusInvalid:
return fmt.Errorf("acme/autocert: invalid authorization %q", authz.URI)
}
// Pick the next preferred challenge.
var chal *acme.Challenge
for chal == nil && nextTyp < len(challengeTypes) {
chal = pickChallenge(challengeTypes[nextTyp], authz.Challenges)
nextTyp++
}
if chal == nil {
errorMsg := fmt.Sprintf("acme/autocert: unable to authorize %q", domain)
for chal, err := range errs {
errorMsg += fmt.Sprintf("; challenge %q failed with error: %v", chal.Type, err)
}
return errors.New(errorMsg)
}
cleanup, err := m.fulfill(ctx, client, chal, domain)
if err != nil {
errs[chal] = err
continue
}
defer cleanup()
if _, err := client.Accept(ctx, chal); err != nil {
errs[chal] = err
continue
}
// A challenge is fulfilled and accepted: wait for the CA to validate.
if _, err := client.WaitAuthorization(ctx, authz.URI); err != nil {
errs[chal] = err
continue
}
return nil
leaf, err = validCert(ck, chain, key, m.now())
if err != nil {
return nil, nil, err
}
return chain, leaf, nil
}
// verifyRFC runs the identifier (domain) order-based authorization flow for RFC compliant CAs
@ -966,7 +894,7 @@ func httpTokenCacheKey(tokenPath string) string {
return path.Base(tokenPath) + "+http-01"
}
// renew starts a cert renewal timer loop, one per domain.
// startRenew starts a cert renewal timer loop, one per domain.
//
// The loop is scheduled in two cases:
// - a cert was fetched from cache for the first time (wasn't in m.state)
@ -974,7 +902,7 @@ func httpTokenCacheKey(tokenPath string) string {
//
// The key argument is a certificate private key.
// The exp argument is the cert expiration time (NotAfter).
func (m *Manager) renew(ck certKey, key crypto.Signer, exp time.Time) {
func (m *Manager) startRenew(ck certKey, key crypto.Signer, exp time.Time) {
m.renewalMu.Lock()
defer m.renewalMu.Unlock()
if m.renewal[ck] != nil {
@ -1200,6 +1128,10 @@ func validCert(ck certKey, der [][]byte, key crypto.Signer, now time.Time) (leaf
if err := leaf.VerifyHostname(ck.domain); err != nil {
return nil, err
}
// renew certificates revoked by Let's Encrypt in January 2022
if isRevokedLetsEncrypt(leaf) {
return nil, errors.New("acme/autocert: certificate was probably revoked by Let's Encrypt")
}
// ensure the leaf corresponds to the private key and matches the certKey type
switch pub := leaf.PublicKey.(type) {
case *rsa.PublicKey:
@ -1230,6 +1162,18 @@ func validCert(ck certKey, der [][]byte, key crypto.Signer, now time.Time) (leaf
return leaf, nil
}
// https://community.letsencrypt.org/t/2022-01-25-issue-with-tls-alpn-01-validation-method/170450
var letsEncryptFixDeployTime = time.Date(2022, time.January, 26, 00, 48, 0, 0, time.UTC)
// isRevokedLetsEncrypt returns whether the certificate is likely to be part of
// a batch of certificates revoked by Let's Encrypt in January 2022. This check
// can be safely removed from May 2022.
func isRevokedLetsEncrypt(cert *x509.Certificate) bool {
O := cert.Issuer.Organization
return len(O) == 1 && O[0] == "Let's Encrypt" &&
cert.NotBefore.Before(letsEncryptFixDeployTime)
}
type lockedMathRand struct {
sync.Mutex
rnd *mathrand.Rand

@ -21,8 +21,9 @@ type domainRenewal struct {
ck certKey
key crypto.Signer
timerMu sync.Mutex
timer *time.Timer
timerMu sync.Mutex
timer *time.Timer
timerClose chan struct{} // if non-nil, renew closes this channel (and nils out the timer fields) instead of running
}
// start starts a cert renewal timer at the time
@ -38,16 +39,28 @@ func (dr *domainRenewal) start(exp time.Time) {
dr.timer = time.AfterFunc(dr.next(exp), dr.renew)
}
// stop stops the cert renewal timer.
// If the timer is already stopped, calling stop is a noop.
// stop stops the cert renewal timer and waits for any in-flight calls to renew
// to complete. If the timer is already stopped, calling stop is a noop.
func (dr *domainRenewal) stop() {
dr.timerMu.Lock()
defer dr.timerMu.Unlock()
if dr.timer == nil {
return
for {
if dr.timer == nil {
return
}
if dr.timer.Stop() {
dr.timer = nil
return
} else {
// dr.timer fired, and we acquired dr.timerMu before the renew callback did.
// (We know this because otherwise the renew callback would have reset dr.timer!)
timerClose := make(chan struct{})
dr.timerClose = timerClose
dr.timerMu.Unlock()
<-timerClose
dr.timerMu.Lock()
}
}
dr.timer.Stop()
dr.timer = nil
}
// renew is called periodically by a timer.
@ -55,7 +68,9 @@ func (dr *domainRenewal) stop() {
func (dr *domainRenewal) renew() {
dr.timerMu.Lock()
defer dr.timerMu.Unlock()
if dr.timer == nil {
if dr.timerClose != nil {
close(dr.timerClose)
dr.timer, dr.timerClose = nil, nil
return
}
@ -67,8 +82,8 @@ func (dr *domainRenewal) renew() {
next = renewJitter / 2
next += time.Duration(pseudoRand.int63n(int64(next)))
}
dr.timer = time.AfterFunc(next, dr.renew)
testDidRenewLoop(next, err)
dr.timer = time.AfterFunc(next, dr.renew)
}
// updateState locks and replaces the relevant Manager.state item with the given

@ -20,12 +20,12 @@ import (
"math/big"
)
// keyID is the account identity provided by a CA during registration.
type keyID string
// KeyID is the account key identity provided by a CA during registration.
type KeyID string
// noKeyID indicates that jwsEncodeJSON should compute and use JWK instead of a KID.
// See jwsEncodeJSON for details.
const noKeyID = keyID("")
const noKeyID = KeyID("")
// noPayload indicates jwsEncodeJSON will encode zero-length octet string
// in a JWS request. This is called POST-as-GET in RFC 8555 and is used to make
@ -43,14 +43,17 @@ type jsonWebSignature struct {
// jwsEncodeJSON signs claimset using provided key and a nonce.
// The result is serialized in JSON format containing either kid or jwk
// fields based on the provided keyID value.
// fields based on the provided KeyID value.
//
// If kid is non-empty, its quoted value is inserted in the protected head
// as "kid" field value. Otherwise, JWK is computed using jwkEncode and inserted
// as "jwk" field value. The "jwk" and "kid" fields are mutually exclusive.
//
// See https://tools.ietf.org/html/rfc7515#section-7.
func jwsEncodeJSON(claimset interface{}, key crypto.Signer, kid keyID, nonce, url string) ([]byte, error) {
func jwsEncodeJSON(claimset interface{}, key crypto.Signer, kid KeyID, nonce, url string) ([]byte, error) {
if key == nil {
return nil, errors.New("nil key")
}
alg, sha := jwsHasher(key.Public())
if alg == "" || !sha.Available() {
return nil, ErrUnsupportedKey

@ -78,7 +78,7 @@ func (c *Client) registerRFC(ctx context.Context, acct *Account, prompt func(tos
}
// Cache Account URL even if we return an error to the caller.
// It is by all means a valid and usable "kid" value for future requests.
c.kid = keyID(a.URI)
c.KID = KeyID(a.URI)
if res.StatusCode == http.StatusOK {
return nil, ErrAccountAlreadyExists
}

@ -305,14 +305,6 @@ type Directory struct {
ExternalAccountRequired bool
}
// rfcCompliant reports whether the ACME server implements RFC 8555.
// Note that some servers may have incomplete RFC implementation
// even if the returned value is true.
// If rfcCompliant reports false, the server most likely implements draft-02.
func (d *Directory) rfcCompliant() bool {
return d.OrderURL != ""
}
// Order represents a client's request for a certificate.
// It tracks the request flow progress through to issuance.
type Order struct {

@ -1,13 +1,7 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// In Go 1.13, the ed25519 package was promoted to the standard library as
// crypto/ed25519, and this package became a wrapper for the standard library one.
//
//go:build !go1.13
// +build !go1.13
// Package ed25519 implements the Ed25519 signature algorithm. See
// https://ed25519.cr.yp.to/.
//
@ -16,21 +10,15 @@
// representation includes a public key suffix to make multiple signing
// operations with the same key more efficient. This package refers to the RFC
// 8032 private key as the “seed”.
//
// Beginning with Go 1.13, the functionality of this package was moved to the
// standard library as crypto/ed25519. This package only acts as a compatibility
// wrapper.
package ed25519
// This code is a port of the public domain, “ref10” implementation of ed25519
// from SUPERCOP.
import (
"bytes"
"crypto"
cryptorand "crypto/rand"
"crypto/sha512"
"errors"
"crypto/ed25519"
"io"
"strconv"
"golang.org/x/crypto/ed25519/internal/edwards25519"
)
const (
@ -45,57 +33,21 @@ const (
)
// PublicKey is the type of Ed25519 public keys.
type PublicKey []byte
//
// This type is an alias for crypto/ed25519's PublicKey type.
// See the crypto/ed25519 package for the methods on this type.
type PublicKey = ed25519.PublicKey
// PrivateKey is the type of Ed25519 private keys. It implements crypto.Signer.
type PrivateKey []byte
// Public returns the PublicKey corresponding to priv.
func (priv PrivateKey) Public() crypto.PublicKey {
publicKey := make([]byte, PublicKeySize)
copy(publicKey, priv[32:])
return PublicKey(publicKey)
}
// Seed returns the private key seed corresponding to priv. It is provided for
// interoperability with RFC 8032. RFC 8032's private keys correspond to seeds
// in this package.
func (priv PrivateKey) Seed() []byte {
seed := make([]byte, SeedSize)
copy(seed, priv[:32])
return seed
}
// Sign signs the given message with priv.
// Ed25519 performs two passes over messages to be signed and therefore cannot
// handle pre-hashed messages. Thus opts.HashFunc() must return zero to
// indicate the message hasn't been hashed. This can be achieved by passing
// crypto.Hash(0) as the value for opts.
func (priv PrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) (signature []byte, err error) {
if opts.HashFunc() != crypto.Hash(0) {
return nil, errors.New("ed25519: cannot sign hashed message")
}
return Sign(priv, message), nil
}
//
// This type is an alias for crypto/ed25519's PrivateKey type.
// See the crypto/ed25519 package for the methods on this type.
type PrivateKey = ed25519.PrivateKey
// GenerateKey generates a public/private key pair using entropy from rand.
// If rand is nil, crypto/rand.Reader will be used.
func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) {
if rand == nil {
rand = cryptorand.Reader
}
seed := make([]byte, SeedSize)
if _, err := io.ReadFull(rand, seed); err != nil {
return nil, nil, err
}
privateKey := NewKeyFromSeed(seed)
publicKey := make([]byte, PublicKeySize)
copy(publicKey, privateKey[32:])
return publicKey, privateKey, nil
return ed25519.GenerateKey(rand)
}
// NewKeyFromSeed calculates a private key from a seed. It will panic if
@ -103,121 +55,17 @@ func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) {
// with RFC 8032. RFC 8032's private keys correspond to seeds in this
// package.
func NewKeyFromSeed(seed []byte) PrivateKey {
if l := len(seed); l != SeedSize {
panic("ed25519: bad seed length: " + strconv.Itoa(l))
}
digest := sha512.Sum512(seed)
digest[0] &= 248
digest[31] &= 127
digest[31] |= 64
var A edwards25519.ExtendedGroupElement
var hBytes [32]byte
copy(hBytes[:], digest[:])
edwards25519.GeScalarMultBase(&A, &hBytes)
var publicKeyBytes [32]byte
A.ToBytes(&publicKeyBytes)
privateKey := make([]byte, PrivateKeySize)
copy(privateKey, seed)
copy(privateKey[32:], publicKeyBytes[:])
return privateKey
return ed25519.NewKeyFromSeed(seed)
}
// Sign signs the message with privateKey and returns a signature. It will
// panic if len(privateKey) is not PrivateKeySize.
func Sign(privateKey PrivateKey, message []byte) []byte {
if l := len(privateKey); l != PrivateKeySize {
panic("ed25519: bad private key length: " + strconv.Itoa(l))
}
h := sha512.New()
h.Write(privateKey[:32])
var digest1, messageDigest, hramDigest [64]byte
var expandedSecretKey [32]byte
h.Sum(digest1[:0])
copy(expandedSecretKey[:], digest1[:])
expandedSecretKey[0] &= 248
expandedSecretKey[31] &= 63
expandedSecretKey[31] |= 64
h.Reset()
h.Write(digest1[32:])
h.Write(message)
h.Sum(messageDigest[:0])
var messageDigestReduced [32]byte
edwards25519.ScReduce(&messageDigestReduced, &messageDigest)
var R edwards25519.ExtendedGroupElement
edwards25519.GeScalarMultBase(&R, &messageDigestReduced)
var encodedR [32]byte
R.ToBytes(&encodedR)
h.Reset()
h.Write(encodedR[:])
h.Write(privateKey[32:])
h.Write(message)
h.Sum(hramDigest[:0])
var hramDigestReduced [32]byte
edwards25519.ScReduce(&hramDigestReduced, &hramDigest)
var s [32]byte
edwards25519.ScMulAdd(&s, &hramDigestReduced, &expandedSecretKey, &messageDigestReduced)
signature := make([]byte, SignatureSize)
copy(signature[:], encodedR[:])
copy(signature[32:], s[:])
return signature
return ed25519.Sign(privateKey, message)
}
// Verify reports whether sig is a valid signature of message by publicKey. It
// will panic if len(publicKey) is not PublicKeySize.
func Verify(publicKey PublicKey, message, sig []byte) bool {
if l := len(publicKey); l != PublicKeySize {
panic("ed25519: bad public key length: " + strconv.Itoa(l))
}
if len(sig) != SignatureSize || sig[63]&224 != 0 {
return false
}
var A edwards25519.ExtendedGroupElement
var publicKeyBytes [32]byte
copy(publicKeyBytes[:], publicKey)
if !A.FromBytes(&publicKeyBytes) {
return false
}
edwards25519.FeNeg(&A.X, &A.X)
edwards25519.FeNeg(&A.T, &A.T)
h := sha512.New()
h.Write(sig[:32])
h.Write(publicKey[:])
h.Write(message)
var digest [64]byte
h.Sum(digest[:0])
var hReduced [32]byte
edwards25519.ScReduce(&hReduced, &digest)
var R edwards25519.ProjectiveGroupElement
var s [32]byte
copy(s[:], sig[32:])
// https://tools.ietf.org/html/rfc8032#section-5.1.7 requires that s be in
// the range [0, order) in order to prevent signature malleability.
if !edwards25519.ScMinimal(&s) {
return false
}
edwards25519.GeDoubleScalarMultVartime(&R, &hReduced, &A, &s)
var checkR [32]byte
R.ToBytes(&checkR)
return bytes.Equal(sig[:32], checkR[:])
return ed25519.Verify(publicKey, message, sig)
}

@ -1,74 +0,0 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.13
// +build go1.13
// Package ed25519 implements the Ed25519 signature algorithm. See
// https://ed25519.cr.yp.to/.
//
// These functions are also compatible with the “Ed25519” function defined in
// RFC 8032. However, unlike RFC 8032's formulation, this package's private key
// representation includes a public key suffix to make multiple signing
// operations with the same key more efficient. This package refers to the RFC
// 8032 private key as the “seed”.
//
// Beginning with Go 1.13, the functionality of this package was moved to the
// standard library as crypto/ed25519. This package only acts as a compatibility
// wrapper.
package ed25519
import (
"crypto/ed25519"
"io"
)
const (
// PublicKeySize is the size, in bytes, of public keys as used in this package.
PublicKeySize = 32
// PrivateKeySize is the size, in bytes, of private keys as used in this package.
PrivateKeySize = 64
// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
SignatureSize = 64
// SeedSize is the size, in bytes, of private key seeds. These are the private key representations used by RFC 8032.
SeedSize = 32
)
// PublicKey is the type of Ed25519 public keys.
//
// This type is an alias for crypto/ed25519's PublicKey type.
// See the crypto/ed25519 package for the methods on this type.
type PublicKey = ed25519.PublicKey
// PrivateKey is the type of Ed25519 private keys. It implements crypto.Signer.
//
// This type is an alias for crypto/ed25519's PrivateKey type.
// See the crypto/ed25519 package for the methods on this type.
type PrivateKey = ed25519.PrivateKey
// GenerateKey generates a public/private key pair using entropy from rand.
// If rand is nil, crypto/rand.Reader will be used.
func GenerateKey(rand io.Reader) (PublicKey, PrivateKey, error) {
return ed25519.GenerateKey(rand)
}
// NewKeyFromSeed calculates a private key from a seed. It will panic if
// len(seed) is not SeedSize. This function is provided for interoperability
// with RFC 8032. RFC 8032's private keys correspond to seeds in this
// package.
func NewKeyFromSeed(seed []byte) PrivateKey {
return ed25519.NewKeyFromSeed(seed)
}
// Sign signs the message with privateKey and returns a signature. It will
// panic if len(privateKey) is not PrivateKeySize.
func Sign(privateKey PrivateKey, message []byte) []byte {
return ed25519.Sign(privateKey, message)
}
// Verify reports whether sig is a valid signature of message by publicKey. It
// will panic if len(publicKey) is not PublicKeySize.
func Verify(publicKey PublicKey, message, sig []byte) bool {
return ed25519.Verify(publicKey, message, sig)
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -394,6 +394,10 @@ func (c *gcmCipher) readCipherPacket(seqNum uint32, r io.Reader) ([]byte, error)
}
c.incIV()
if len(plain) == 0 {
return nil, errors.New("ssh: empty packet")
}
padding := plain[0]
if padding < 4 {
// padding is a byte, so it automatically satisfies
@ -710,6 +714,10 @@ func (c *chacha20Poly1305Cipher) readCipherPacket(seqNum uint32, r io.Reader) ([
plain := c.buf[4:contentEnd]
s.XORKeyStream(plain, plain)
if len(plain) == 0 {
return nil, errors.New("ssh: empty packet")
}
padding := plain[0]
if padding < 4 {
// padding is a byte, so it automatically satisfies

@ -633,6 +633,30 @@ userAuthLoop:
}
authFailures++
if config.MaxAuthTries > 0 && authFailures >= config.MaxAuthTries {
// If we have hit the max attempts, don't bother sending the
// final SSH_MSG_USERAUTH_FAILURE message, since there are
// no more authentication methods which can be attempted,
// and this message may cause the client to re-attempt
// authentication while we send the disconnect message.
// Continue, and trigger the disconnect at the start of
// the loop.
//
// The SSH specification is somewhat confusing about this,
// RFC 4252 Section 5.1 requires each authentication failure
// be responded to with a respective SSH_MSG_USERAUTH_FAILURE
// message, but Section 4 says the server should disconnect
// after some number of attempts, but it isn't explicit which
// message should take precedence (i.e. should there be a failure
// message than a disconnect message, or if we are going to
// disconnect, should we only send that message.)
//
// Either way, OpenSSH disconnects immediately after the last
// failed authnetication attempt, and given they are typically
// considered the golden implementation it seems reasonable
// to match that behavior.
continue
}
var failureMsg userAuthFailureMsg
if config.PasswordCallback != nil {

@ -904,10 +904,10 @@ func (t *Task) Main() (err error) {
}
abi, err := cc.NewABI(t.goos, t.goarch)
abi.Types[cc.LongDouble] = abi.Types[cc.Double]
if err != nil {
return err
}
abi.Types[cc.LongDouble] = abi.Types[cc.Double]
var re *regexp.Regexp
if t.ignoredIncludes != "" {
@ -1474,7 +1474,7 @@ func (t *Task) createCompileDB(command []string) (rerr error) {
var parser func(s string) ([]string, error)
out:
switch t.goos {
case "darwin", "freebsd", "netbsd", "openbsd":
case "darwin", "freebsd", "netbsd":
switch command[0] {
case "make", "gmake":
// ok
@ -1490,6 +1490,22 @@ out:
command = append([]string{sh, "-c"}, join(" ", command[0], "SHELL='sh -x'", command[1:]))
cmd = exec.Command(command[0], command[1:]...)
parser = makeXParser
case "openbsd":
switch command[0] {
case "make", "gmake":
// ok
default:
return fmt.Errorf("usupported build command: %s", command[0])
}
sh, err := exec.LookPath("sh")
if err != nil {
return err
}
command = append([]string{sh, "-c"}, join(" ", command[0], "SHELL='sh -x'", command[1:]))
cmd = exec.Command(command[0], command[1:]...)
parser = makeXParser2
case "windows":
if command[0] != "make" {
return fmt.Errorf("usupported build command: %s", command[0])
@ -1580,7 +1596,7 @@ func isCreateArchive(s string) bool {
b := []byte(s)
sort.Slice(b, func(i, j int) bool { return b[i] < b[j] })
switch string(b) {
case "cq", "cr", "crs", "cru":
case "cq", "cr", "crs", "cru", "r":
return true
}
return false
@ -1615,7 +1631,48 @@ func makeXParser(s string) (r []string, err error) {
}
s = s[1:]
if dmesgs {
dmesg("%v: source line `%s`, caller %v:", origin(1), s, origin(2))
}
r, err = shellquote.Split(s)
if dmesgs {
dmesg("%v: shellquote.Split -> %v %[2]q, %v", origin(1), r, err)
}
if err != nil {
if strings.Contains(err.Error(), "Unterminated single-quoted string") {
return nil, nil // ignore
}
}
if len(r) != 0 && filepath.Base(r[0]) == "libtool" {
r[0] = "libtool"
}
return r, err
}
func makeXParser2(s string) (r []string, err error) {
s = strings.TrimSpace(s)
switch {
case strings.HasPrefix(s, "libtool: link: ar "):
s = s[len("libtool: link:"):]
case strings.HasPrefix(s, "libtool: compile: "):
s = s[len("libtool: compile:"):]
for strings.HasPrefix(s, " ") {
s = s[1:]
}
default:
var n int
if n, s = hasPlusPrefix(s); n != 0 {
return nil, nil
}
}
if dmesgs {
dmesg("%v: source line `%s`, caller %v:", origin(1), s, origin(2))
}
r, err = shellquote.Split(s)
if dmesgs {
dmesg("%v: shellquote.Split -> %v %[2]q, %v", origin(1), r, err)
}
if err != nil {
if strings.Contains(err.Error(), "Unterminated single-quoted string") {
return nil, nil // ignore
@ -1809,26 +1866,29 @@ func (it *cdbItem) sources(cc, ar string) (r []string) {
}
type cdbMakeWriter struct {
b bytes.Buffer
cc string
ar string
arBase string
b bytes.Buffer
cc string
dir string
err error
it cdbItem
parser func(s string) ([]string, error)
prefix string
sc *bufio.Scanner
t *Task
w *cdbWriter
}
func (t *Task) newCdbMakeWriter(w *cdbWriter, dir string, parser func(s string) ([]string, error)) *cdbMakeWriter {
const sz = 1 << 16
r := &cdbMakeWriter{
cc: t.ccLookPath,
ar: t.arLookPath,
arBase: filepath.Base(t.arLookPath),
cc: t.ccLookPath,
dir: dir,
parser: parser,
t: t,
w: w,
}
r.sc = bufio.NewScanner(&r.b)
@ -1849,7 +1909,15 @@ func (w *cdbMakeWriter) Write(b []byte) (int, error) {
panic(todo("internal error"))
}
s := strings.TrimSpace(w.sc.Text())
s := w.sc.Text()
if strings.HasSuffix(s, "\\") {
w.prefix += s[:len(s)-1]
continue
}
s = w.prefix + s
w.prefix = ""
s = strings.TrimSpace(s)
if edx := strings.Index(s, "Entering directory"); edx >= 0 {
s = s[edx+len("Entering directory"):]
s = strings.TrimSpace(s)
@ -1882,7 +1950,13 @@ func (w *cdbMakeWriter) Write(b []byte) (int, error) {
continue
}
if dmesgs {
dmesg("%v: source line `%s`", origin(1), s)
}
args, err := w.parser(s)
if dmesgs {
dmesg("%v: parser -> %v %[2]q, %v", origin(1), args, err)
}
if err != nil {
w.fail(err)
continue
@ -1899,16 +1973,25 @@ func (w *cdbMakeWriter) Write(b []byte) (int, error) {
err = nil
switch args[0] {
case w.cc:
if w.t.verboseCompiledb {
fmt.Printf("source line: %q\n", s)
}
fmt.Printf("CCGO CC: %q\n", args)
err = w.handleGCC(args)
case w.ar:
fallthrough
case w.arBase:
if isCreateArchive(args[1]) {
if w.t.verboseCompiledb {
fmt.Printf("source line: %q\n", s)
}
fmt.Printf("CCGO AR: %q\n", args)
err = w.handleAR(args)
}
case "libtool":
if w.t.verboseCompiledb {
fmt.Printf("source line: %q\n", s)
}
fmt.Printf("CCGO LIBTOOL: %q\n", args)
err = w.handleLibtool(args)
}

@ -32,7 +32,8 @@ func dmesg(s string, args ...interface{}) {
if s == "" {
s = strings.Repeat("%v ", len(args))
}
s = fmt.Sprintf(pid+s, args...)
s = fmt.Sprintf(s, args...)
s = pid + s
switch {
case len(s) != 0 && s[len(s)-1] == '\n':
fmt.Fprint(logf, s)

@ -3117,6 +3117,9 @@ func (p *project) declaratorDecay(n cc.Node, f *function, d *cc.Declarator, t cc
return
}
if !local.isPinned {
p.err(n, "%v: %v: missed pinning", n.Position(), d.Position(), d.Name())
}
p.w("(%s%s)/* &%s[0] */", f.bpName, nonZeroUintptr(local.off), local.name)
return
}
@ -8135,6 +8138,11 @@ func (p *project) castExpressionValue(f *function, n *cc.CastExpression, t cc.Ty
case cc.CastExpressionUnary: // UnaryExpression
p.unaryExpression(f, n.UnaryExpression, t, mode, flags)
case cc.CastExpressionCast: // '(' TypeName ')' CastExpression
if f != nil && p.pass1 && n.TypeName.Type().IsIntegerType() && n.CastExpression.Operand.Type().Kind() == cc.Array {
if d := n.CastExpression.Declarator(); d != nil {
f.pin(n, d)
}
}
switch k := p.opKind(f, n.CastExpression, n.CastExpression.Operand.Type()); k {
case opNormal, opBitfield:
p.castExpressionValueNormal(f, n, t, mode, flags)
@ -12561,7 +12569,7 @@ func (p *project) iterationStatement(f *function, n *cc.IterationStatement) {
break
}
v := "ok"
v := "__ccgo"
if !p.pass1 {
v = f.scope.take(cc.String(v))
}

1
vendor/modernc.org/libc/AUTHORS generated vendored

@ -13,4 +13,5 @@ Dan Peterson <danp@danp.net>
Jan Mercl <0xjnml@gmail.com>
Jason DeBettencourt <jasond17@gmail.com>
Koichi Shiraishi <zchee.io@gmail.com>
Marius Orcsik <marius@federated.id>
Steffen Butzer <steffen(dot)butzer@outlook.com>

@ -12,4 +12,5 @@ Jaap Aarts <jaap.aarts1@gmail.com>
Jan Mercl <0xjnml@gmail.com>
Jason DeBettencourt <jasond17@gmail.com>
Koichi Shiraishi <zchee.io@gmail.com>
Marius Orcsik <marius@federated.id>
Steffen Butzer <steffen(dot)butzer@outlook.com>

@ -153,6 +153,7 @@ var CAPI = map[string]struct{}{
"atoi": {},
"atol": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},

@ -82,6 +82,7 @@ var CAPI = map[string]struct{}{
"__ccgo_sqlite3_log": {},
"__cmsg_nxthdr": {},
"__ctype_get_mb_cur_max": {},
"__darwin_check_fd_set_overflow": {},
"__darwin_fd_clr": {},
"__darwin_fd_isset": {},
"__darwin_fd_set": {},
@ -152,6 +153,7 @@ var CAPI = map[string]struct{}{
"atoi": {},
"atol": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},

@ -39,6 +39,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -47,6 +49,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -90,11 +93,16 @@ var CAPI = map[string]struct{}{
"__isalnum_l": {},
"__isalpha_l": {},
"__isdigit_l": {},
"__islower_l": {},
"__isnan": {},
"__isnanf": {},
"__isnanl": {},
"__isoc99_sscanf": {},
"__isprint_l": {},
"__isspace_l": {},
"__isthreaded": {},
"__isupper_l": {},
"__isxdigit_l": {},
"__lookup_ipliteral": {},
"__lookup_name": {},
"__lookup_serv": {},
@ -139,6 +147,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},
@ -266,9 +275,14 @@ var CAPI = map[string]struct{}{
"isascii": {},
"isatty": {},
"isdigit": {},
"islower": {},
"isnan": {},
"isnanf": {},
"isnanl": {},
"isprint": {},
"isspace": {},
"isupper": {},
"isxdigit": {},
"kill": {},
"ldexp": {},
"link": {},

@ -34,6 +34,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -42,6 +44,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -136,6 +139,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},
@ -258,6 +262,7 @@ var CAPI = map[string]struct{}{
"inet_ntoa": {},
"inet_ntop": {},
"inet_pton": {},
"initstate": {},
"initstate_r": {},
"ioctl": {},
"isalnum": {},
@ -405,6 +410,7 @@ var CAPI = map[string]struct{}{
"setrlimit64": {},
"setsid": {},
"setsockopt": {},
"setstate": {},
"setvbuf": {},
"shmat": {},
"shmctl": {},

@ -34,6 +34,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -42,6 +44,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -136,6 +139,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},
@ -258,6 +262,7 @@ var CAPI = map[string]struct{}{
"inet_ntoa": {},
"inet_ntop": {},
"inet_pton": {},
"initstate": {},
"initstate_r": {},
"ioctl": {},
"isalnum": {},
@ -407,6 +412,7 @@ var CAPI = map[string]struct{}{
"setrlimit64": {},
"setsid": {},
"setsockopt": {},
"setstate": {},
"setvbuf": {},
"shmat": {},
"shmctl": {},

@ -34,6 +34,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -42,6 +44,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -136,6 +139,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},
@ -258,6 +262,7 @@ var CAPI = map[string]struct{}{
"inet_ntoa": {},
"inet_ntop": {},
"inet_pton": {},
"initstate": {},
"initstate_r": {},
"ioctl": {},
"isalnum": {},
@ -405,6 +410,7 @@ var CAPI = map[string]struct{}{
"setrlimit64": {},
"setsid": {},
"setsockopt": {},
"setstate": {},
"setvbuf": {},
"shmat": {},
"shmctl": {},

@ -34,6 +34,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -42,6 +44,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -136,6 +139,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},
@ -258,6 +262,7 @@ var CAPI = map[string]struct{}{
"inet_ntoa": {},
"inet_ntop": {},
"inet_pton": {},
"initstate": {},
"initstate_r": {},
"ioctl": {},
"isalnum": {},
@ -405,6 +410,7 @@ var CAPI = map[string]struct{}{
"setrlimit64": {},
"setsid": {},
"setsockopt": {},
"setstate": {},
"setvbuf": {},
"shmat": {},
"shmctl": {},

@ -34,6 +34,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -42,6 +44,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -136,6 +139,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},
@ -258,6 +262,7 @@ var CAPI = map[string]struct{}{
"inet_ntoa": {},
"inet_ntop": {},
"inet_pton": {},
"initstate": {},
"initstate_r": {},
"ioctl": {},
"isalnum": {},
@ -405,6 +410,7 @@ var CAPI = map[string]struct{}{
"setrlimit64": {},
"setsid": {},
"setsockopt": {},
"setstate": {},
"setvbuf": {},
"shmat": {},
"shmctl": {},

@ -39,6 +39,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -47,6 +49,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -110,7 +113,6 @@ var CAPI = map[string]struct{}{
"__swbuf": {},
"__sync_add_and_fetch_uint32": {},
"__sync_sub_and_fetch_uint32": {},
"__sync_synchronize": {},
"__syscall1": {},
"__syscall3": {},
"__syscall4": {},
@ -145,6 +147,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},
@ -264,6 +267,8 @@ var CAPI = map[string]struct{}{
"inet_ntoa": {},
"inet_ntop": {},
"inet_pton": {},
"initstate": {},
"initstate_r": {},
"ioctl": {},
"isalnum": {},
"isalpha": {},
@ -299,6 +304,7 @@ var CAPI = map[string]struct{}{
"mkdir": {},
"mkfifo": {},
"mknod": {},
"mkostemp": {},
"mkstemp": {},
"mkstemp64": {},
"mkstemps": {},
@ -362,6 +368,7 @@ var CAPI = map[string]struct{}{
"raise": {},
"rand": {},
"random": {},
"random_r": {},
"read": {},
"readdir": {},
"readdir64": {},
@ -395,6 +402,7 @@ var CAPI = map[string]struct{}{
"setrlimit64": {},
"setsid": {},
"setsockopt": {},
"setstate": {},
"setvbuf": {},
"shmat": {},
"shmctl": {},
@ -425,6 +433,7 @@ var CAPI = map[string]struct{}{
"strcspn": {},
"strdup": {},
"strerror": {},
"strerror_r": {},
"strlen": {},
"strncmp": {},
"strncpy": {},
@ -464,6 +473,9 @@ var CAPI = map[string]struct{}{
"usleep": {},
"utime": {},
"utimes": {},
"uuid_generate_random": {},
"uuid_parse": {},
"uuid_unparse": {},
"vasprintf": {},
"vfprintf": {},
"vprintf": {},

@ -96,6 +96,7 @@ var CAPI = map[string]struct{}{
"__isalnum_l": {},
"__isalpha_l": {},
"__isdigit_l": {},
"__islower_l": {},
"__isnan": {},
"__isnanf": {},
"__isnanl": {},
@ -103,6 +104,8 @@ var CAPI = map[string]struct{}{
"__isprint_l": {},
"__isspace_l": {},
"__isthreaded": {},
"__isupper_l": {},
"__isxdigit_l": {},
"__lookup_ipliteral": {},
"__lookup_name": {},
"__lookup_serv": {},
@ -151,6 +154,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},
@ -279,11 +283,14 @@ var CAPI = map[string]struct{}{
"isascii": {},
"isatty": {},
"isdigit": {},
"islower": {},
"isnan": {},
"isnanf": {},
"isnanl": {},
"isprint": {},
"isspace": {},
"isupper": {},
"isxdigit": {},
"kill": {},
"ldexp": {},
"link": {},

@ -284,6 +284,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -292,6 +294,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -440,6 +443,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},

@ -282,6 +282,8 @@ var CAPI = map[string]struct{}{
"__builtin_exit": {},
"__builtin_expect": {},
"__builtin_fabs": {},
"__builtin_fabsf": {},
"__builtin_fabsl": {},
"__builtin_free": {},
"__builtin_getentropy": {},
"__builtin_huge_val": {},
@ -290,6 +292,7 @@ var CAPI = map[string]struct{}{
"__builtin_inff": {},
"__builtin_infl": {},
"__builtin_isnan": {},
"__builtin_isunordered": {},
"__builtin_malloc": {},
"__builtin_memcmp": {},
"__builtin_memcpy": {},
@ -436,6 +439,7 @@ var CAPI = map[string]struct{}{
"backtrace": {},
"backtrace_symbols_fd": {},
"bind": {},
"bsearch": {},
"bzero": {},
"calloc": {},
"ceil": {},

@ -2,4 +2,6 @@
package errno
var CAPI = map[string]struct{}{}
var CAPI = map[string]struct{}{
"__darwin_check_fd_set_overflow": {},
}

@ -1,4 +1,4 @@
// Code generated by 'ccgo errno/gen.c -crt-import-path -export-defines -export-enums -export-externs X -export-fields F -export-structs -export-typedefs -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o errno/errno_windows_386.go -pkgname errno', DO NOT EDIT.
// Code generated by 'ccgo errno\gen.c -crt-import-path -export-defines -export-enums -export-externs X -export-fields F -export-structs -export-typedefs -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o errno\errno_windows_386.go -pkgname errno', DO NOT EDIT.
package errno

@ -314,6 +314,13 @@ var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __unused denotes variables and functions that may not be used, preventing
// the compiler from warning about it if not used.

@ -156,6 +156,8 @@ type X__uint128_t = struct {
type X__builtin_va_list = uintptr /* <builtin>:46:14 */
type X__float128 = float64 /* <builtin>:47:21 */
var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
//
// @APPLE_LICENSE_HEADER_START@
@ -314,6 +316,13 @@ type X__float128 = float64 /* <builtin>:47:21 */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __pure2 can be used for functions that are only a function of their scalar
// arguments (meaning they can't dereference pointers).
//

@ -1,4 +1,4 @@
// Code generated by 'ccgo errno/gen.c -crt-import-path "" -export-defines "" -export-enums "" -export-externs X -export-fields F -export-structs "" -export-typedefs "" -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o errno/errno_windows_386.go -pkgname errno', DO NOT EDIT.
// Code generated by 'ccgo errno\gen.c -crt-import-path "" -export-defines "" -export-enums "" -export-externs X -export-fields F -export-structs "" -export-typedefs "" -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o errno\errno_windows_386.go -pkgname errno', DO NOT EDIT.
package errno
@ -112,7 +112,9 @@ const (
EWOULDBLOCK = 140
EXDEV = 18
MINGW_DDK_H = 0
MINGW_DDRAW_VERSION = 7
MINGW_HAS_DDK_H = 1
MINGW_HAS_DDRAW_H = 1
MINGW_HAS_SECURE_API = 1
MINGW_SDK_INIT = 0
STRUNCATE = 80
@ -136,12 +138,9 @@ const (
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES = 0
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT = 0
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY = 0
X_CRT_USE_WINAPI_FAMILY_DESKTOP_APP = 0
X_DLL = 0
X_ERRCODE_DEFINED = 0
X_FILE_OFFSET_BITS = 64
X_ILP32 = 1
X_INC_CORECRT = 0
X_INC_CRTDEFS = 0
X_INC_CRTDEFS_MACRO = 0
X_INC_ERRNO = 0
@ -156,6 +155,7 @@ const (
X_PGLOBAL = 0
X_PTRDIFF_T_ = 0
X_PTRDIFF_T_DEFINED = 0
X_REENTRANT = 1
X_RSIZE_T_DEFINED = 0
X_SECURECRT_ERRCODE_VALUES_DEFINED = 0
X_SECURECRT_FILL_BUFFER_PATTERN = 0xFD
@ -210,11 +210,6 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// *
// This file has no copyright assigned and is placed in the Public Domain.
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// This macro holds an monotonic increasing value, which indicates
// a specific fix/patch is present on trunk. This value isn't related to
// minor/major version-macros. It is increased on demand, if a big
@ -235,12 +230,6 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// MinGW-w64 has some additional C99 printf/scanf feature support.
// So we add some helper macros to ease recognition of them.
// If _FORTIFY_SOURCE is enabled, some inline functions may use
// __builtin_va_arg_pack(). GCC may report an error if the address
// of such a function is used. Set _FORTIFY_VA_ARG=0 in this case.
// Enable workaround for ABI incompatibility on affected platforms
// *
// This file has no copyright assigned and is placed in the Public Domain.
// This file is part of the mingw-w64 runtime package.
@ -281,28 +270,26 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// for backward compatibility
type X__gnuc_va_list = X__builtin_va_list /* vadefs.h:24:29 */
type Ssize_t = int32 /* corecrt.h:52:13 */
type Ssize_t = int32 /* crtdefs.h:47:13 */
type Rsize_t = Size_t /* corecrt.h:57:16 */
type Rsize_t = Size_t /* crtdefs.h:52:16 */
type Intptr_t = int32 /* corecrt.h:69:13 */
type Intptr_t = int32 /* crtdefs.h:64:13 */
type Uintptr_t = uint32 /* corecrt.h:82:22 */
type Uintptr_t = uint32 /* crtdefs.h:77:22 */
type Wint_t = uint16 /* corecrt.h:111:24 */
type Wctype_t = uint16 /* corecrt.h:112:24 */
type Wint_t = uint16 /* crtdefs.h:106:24 */
type Wctype_t = uint16 /* crtdefs.h:107:24 */
type Errno_t = int32 /* corecrt.h:118:13 */
type Errno_t = int32 /* crtdefs.h:113:13 */
type X__time32_t = int32 /* corecrt.h:123:14 */
type X__time32_t = int32 /* crtdefs.h:118:14 */
type X__time64_t = int64 /* corecrt.h:128:35 */
type X__time64_t = int64 /* crtdefs.h:123:35 */
type Time_t = X__time32_t /* corecrt.h:141:20 */
type Time_t = X__time32_t /* crtdefs.h:136:20 */
type Threadlocaleinfostruct = struct {
Frefcount int32
@ -328,29 +315,29 @@ type Threadlocaleinfostruct = struct {
Fpclmap uintptr
Fpcumap uintptr
Flc_time_curr uintptr
} /* corecrt.h:435:1 */
} /* crtdefs.h:422:1 */
type Pthreadlocinfo = uintptr /* corecrt.h:437:39 */
type Pthreadmbcinfo = uintptr /* corecrt.h:438:36 */
type Pthreadlocinfo = uintptr /* crtdefs.h:424:39 */
type Pthreadmbcinfo = uintptr /* crtdefs.h:425:36 */
type Localeinfo_struct = struct {
Flocinfo Pthreadlocinfo
Fmbcinfo Pthreadmbcinfo
} /* corecrt.h:441:9 */
} /* crtdefs.h:428:9 */
type X_locale_tstruct = Localeinfo_struct /* corecrt.h:444:3 */
type X_locale_t = uintptr /* corecrt.h:444:19 */
type X_locale_tstruct = Localeinfo_struct /* crtdefs.h:431:3 */
type X_locale_t = uintptr /* crtdefs.h:431:19 */
type TagLC_ID = struct {
FwLanguage uint16
FwCountry uint16
FwCodePage uint16
} /* corecrt.h:435:1 */
} /* crtdefs.h:422:1 */
type LC_ID = TagLC_ID /* corecrt.h:452:3 */
type LPLC_ID = uintptr /* corecrt.h:452:9 */
type LC_ID = TagLC_ID /* crtdefs.h:439:3 */
type LPLC_ID = uintptr /* crtdefs.h:439:9 */
type Threadlocinfo = Threadlocaleinfostruct /* corecrt.h:487:3 */
type Threadlocinfo = Threadlocaleinfostruct /* crtdefs.h:468:3 */
// Posix thread extensions.

@ -2,4 +2,6 @@
package fcntl
var CAPI = map[string]struct{}{}
var CAPI = map[string]struct{}{
"__darwin_check_fd_set_overflow": {},
}

@ -1,4 +1,4 @@
// Code generated by 'ccgo fcntl/gen.c -crt-import-path -export-defines -export-enums -export-externs X -export-fields F -export-structs -export-typedefs -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o fcntl/fcntl_windows_386.go -pkgname fcntl', DO NOT EDIT.
// Code generated by 'ccgo fcntl\gen.c -crt-import-path -export-defines -export-enums -export-externs X -export-fields F -export-structs -export-typedefs -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o fcntl\fcntl_windows_386.go -pkgname fcntl', DO NOT EDIT.
package fcntl

@ -409,6 +409,13 @@ var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __unused denotes variables and functions that may not be used, preventing
// the compiler from warning about it if not used.

@ -262,6 +262,8 @@ type X__uint128_t = struct {
type X__builtin_va_list = uintptr /* <builtin>:46:14 */
type X__float128 = float64 /* <builtin>:47:21 */
var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
//
// @APPLE_LICENSE_HEADER_START@
@ -450,6 +452,13 @@ type X__float128 = float64 /* <builtin>:47:21 */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __pure2 can be used for functions that are only a function of their scalar
// arguments (meaning they can't dereference pointers).
//

@ -1,4 +1,4 @@
// Code generated by 'ccgo fcntl/gen.c -crt-import-path "" -export-defines "" -export-enums "" -export-externs X -export-fields F -export-structs "" -export-typedefs "" -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o fcntl/fcntl_windows_386.go -pkgname fcntl', DO NOT EDIT.
// Code generated by 'ccgo fcntl\gen.c -crt-import-path "" -export-defines "" -export-enums "" -export-externs X -export-fields F -export-structs "" -export-typedefs "" -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o fcntl\fcntl_windows_386.go -pkgname fcntl', DO NOT EDIT.
package fcntl
@ -33,7 +33,9 @@ const (
DUMMYUNIONNAME9 = 0
F_OK = 0
MINGW_DDK_H = 0
MINGW_DDRAW_VERSION = 7
MINGW_HAS_DDK_H = 1
MINGW_HAS_DDRAW_H = 1
MINGW_HAS_SECURE_API = 1
MINGW_SDK_INIT = 0
O_ACCMODE = 3
@ -81,7 +83,6 @@ const (
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES = 0
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT = 0
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY = 0
X_CRT_USE_WINAPI_FAMILY_DESKTOP_APP = 0
X_DLL = 0
X_ERRCODE_DEFINED = 0
X_FILE_OFFSET_BITS = 64
@ -89,8 +90,6 @@ const (
X_FILE_OFFSET_BITS_SET_OFFT = 0
X_FINDDATA_T_DEFINED = 0
X_FSIZE_T_DEFINED = 0
X_ILP32 = 1
X_INC_CORECRT = 0
X_INC_CRTDEFS = 0
X_INC_CRTDEFS_MACRO = 0
X_INC_FCNTL = 0
@ -132,6 +131,7 @@ const (
X_PGLOBAL = 0
X_PTRDIFF_T_ = 0
X_PTRDIFF_T_DEFINED = 0
X_REENTRANT = 1
X_RSIZE_T_DEFINED = 0
X_SECURECRT_FILL_BUFFER_PATTERN = 0xFD
X_SIZE_T_DEFINED = 0
@ -189,11 +189,6 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// *
// This file has no copyright assigned and is placed in the Public Domain.
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// This macro holds an monotonic increasing value, which indicates
// a specific fix/patch is present on trunk. This value isn't related to
// minor/major version-macros. It is increased on demand, if a big
@ -214,12 +209,6 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// MinGW-w64 has some additional C99 printf/scanf feature support.
// So we add some helper macros to ease recognition of them.
// If _FORTIFY_SOURCE is enabled, some inline functions may use
// __builtin_va_arg_pack(). GCC may report an error if the address
// of such a function is used. Set _FORTIFY_VA_ARG=0 in this case.
// Enable workaround for ABI incompatibility on affected platforms
// *
// This file has no copyright assigned and is placed in the Public Domain.
// This file is part of the mingw-w64 runtime package.
@ -260,28 +249,26 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// for backward compatibility
type X__gnuc_va_list = X__builtin_va_list /* vadefs.h:24:29 */
type Ssize_t = int32 /* corecrt.h:52:13 */
type Ssize_t = int32 /* crtdefs.h:47:13 */
type Rsize_t = Size_t /* corecrt.h:57:16 */
type Rsize_t = Size_t /* crtdefs.h:52:16 */
type Intptr_t = int32 /* corecrt.h:69:13 */
type Intptr_t = int32 /* crtdefs.h:64:13 */
type Uintptr_t = uint32 /* corecrt.h:82:22 */
type Uintptr_t = uint32 /* crtdefs.h:77:22 */
type Wint_t = uint16 /* corecrt.h:111:24 */
type Wctype_t = uint16 /* corecrt.h:112:24 */
type Wint_t = uint16 /* crtdefs.h:106:24 */
type Wctype_t = uint16 /* crtdefs.h:107:24 */
type Errno_t = int32 /* corecrt.h:118:13 */
type Errno_t = int32 /* crtdefs.h:113:13 */
type X__time32_t = int32 /* corecrt.h:123:14 */
type X__time32_t = int32 /* crtdefs.h:118:14 */
type X__time64_t = int64 /* corecrt.h:128:35 */
type X__time64_t = int64 /* crtdefs.h:123:35 */
type Time_t = X__time32_t /* corecrt.h:141:20 */
type Time_t = X__time32_t /* crtdefs.h:136:20 */
type Threadlocaleinfostruct = struct {
Frefcount int32
@ -307,29 +294,29 @@ type Threadlocaleinfostruct = struct {
Fpclmap uintptr
Fpcumap uintptr
Flc_time_curr uintptr
} /* corecrt.h:435:1 */
} /* crtdefs.h:422:1 */
type Pthreadlocinfo = uintptr /* corecrt.h:437:39 */
type Pthreadmbcinfo = uintptr /* corecrt.h:438:36 */
type Pthreadlocinfo = uintptr /* crtdefs.h:424:39 */
type Pthreadmbcinfo = uintptr /* crtdefs.h:425:36 */
type Localeinfo_struct = struct {
Flocinfo Pthreadlocinfo
Fmbcinfo Pthreadmbcinfo
} /* corecrt.h:441:9 */
} /* crtdefs.h:428:9 */
type X_locale_tstruct = Localeinfo_struct /* corecrt.h:444:3 */
type X_locale_t = uintptr /* corecrt.h:444:19 */
type X_locale_tstruct = Localeinfo_struct /* crtdefs.h:431:3 */
type X_locale_t = uintptr /* crtdefs.h:431:19 */
type TagLC_ID = struct {
FwLanguage uint16
FwCountry uint16
FwCodePage uint16
} /* corecrt.h:435:1 */
} /* crtdefs.h:422:1 */
type LC_ID = TagLC_ID /* corecrt.h:452:3 */
type LPLC_ID = uintptr /* corecrt.h:452:9 */
type LC_ID = TagLC_ID /* crtdefs.h:439:3 */
type LPLC_ID = uintptr /* crtdefs.h:439:9 */
type Threadlocinfo = Threadlocaleinfostruct /* corecrt.h:487:3 */
type Threadlocinfo = Threadlocaleinfostruct /* crtdefs.h:468:3 */
type X_fsize_t = uint32 /* io.h:29:25 */
type X_finddata32_t = struct {

@ -3,5 +3,9 @@
package fts
var CAPI = map[string]struct{}{
"__darwin_check_fd_set": {},
"__darwin_check_fd_set_overflow": {},
"__darwin_fd_clr": {},
"__darwin_fd_isset": {},
"__darwin_fd_set": {},
}

@ -2,4 +2,10 @@
package fts
var CAPI = map[string]struct{}{}
var CAPI = map[string]struct{}{
"__darwin_check_fd_set": {},
"__darwin_check_fd_set_overflow": {},
"__darwin_fd_clr": {},
"__darwin_fd_isset": {},
"__darwin_fd_set": {},
}

@ -27,6 +27,7 @@ const (
EF_NO_XATTRS = 0x00000002
FD_SETSIZE = 1024
FTS_AGAIN = 1
FTS_BLOCK_COMPAR = 0x80000000
FTS_COMFOLLOW = 0x001
FTS_COMFOLLOWDIR = 0x400
FTS_D = 1
@ -379,6 +380,13 @@ var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __unused denotes variables and functions that may not be used, preventing
// the compiler from warning about it if not used.
@ -2946,15 +2954,6 @@ type Errno_t = int32 /* _errno_t.h:30:32 */
// __IPHONE_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable
// DO NOT EDIT THIS FILE.
//
// It has been auto-edited by fixincludes from:
//
// "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/AvailabilityInternal.h"
//
// This had to be done to correct non-standard usages in the
// original, manufacturer supplied header file.
// Copyright (c) 2007-2016 by Apple Inc.. All rights reserved.
//
// @APPLE_LICENSE_HEADER_START@
@ -3225,15 +3224,6 @@ type Fd_set1 = struct{ Ffds_bits [32]X__int32_t } /* _fd_def.h:50:9 */
// __IPHONE_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable
// DO NOT EDIT THIS FILE.
//
// It has been auto-edited by fixincludes from:
//
// "/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/AvailabilityInternal.h"
//
// This had to be done to correct non-standard usages in the
// original, manufacturer supplied header file.
// Copyright (c) 2007-2016 by Apple Inc.. All rights reserved.
//
// @APPLE_LICENSE_HEADER_START@
@ -5132,7 +5122,7 @@ type FTS = struct {
Ffts_pathlen int32
Ffts_nitems int32
F__ccgo_pad2 [4]byte
Ffts_compar uintptr
F__56 struct{ Ffts_compar uintptr }
Ffts_options int32
F__ccgo_pad3 [4]byte
} /* fts.h:111:3 */

File diff suppressed because it is too large Load Diff

@ -2,4 +2,6 @@
package grp
var CAPI = map[string]struct{}{}
var CAPI = map[string]struct{}{
"__darwin_check_fd_set_overflow": {},
}

@ -219,6 +219,13 @@ var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __unused denotes variables and functions that may not be used, preventing
// the compiler from warning about it if not used.

@ -58,6 +58,8 @@ type X__uint128_t = struct {
type X__builtin_va_list = uintptr /* <builtin>:46:14 */
type X__float128 = float64 /* <builtin>:47:21 */
var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// -
// Copyright (c) 1989, 1993
// The Regents of the University of California. All rights reserved.
@ -219,6 +221,13 @@ type X__float128 = float64 /* <builtin>:47:21 */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __pure2 can be used for functions that are only a function of their scalar
// arguments (meaning they can't dereference pointers).
//

@ -713,7 +713,10 @@ func init() {
num, err := strconv.ParseInt(fields[1], 10, 32)
if err != nil {
panic(err)
// If we find lines that don't match the expected format we skip over them.
// The expected format is <protocol> <number> <aliases> ...
// As we're using strings.Fields for splitting the line, failures can happen if the protocol field contains white spaces.
continue
}
protoent := &Protoent{

@ -2,4 +2,6 @@
package langinfo
var CAPI = map[string]struct{}{}
var CAPI = map[string]struct{}{
"__darwin_check_fd_set_overflow": {},
}

@ -259,6 +259,13 @@ var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __unused denotes variables and functions that may not be used, preventing
// the compiler from warning about it if not used.

@ -111,6 +111,8 @@ type X__uint128_t = struct {
type X__builtin_va_list = uintptr /* <builtin>:46:14 */
type X__float128 = float64 /* <builtin>:47:21 */
var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// -
// Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
// All rights reserved.
@ -259,6 +261,13 @@ type X__float128 = float64 /* <builtin>:47:21 */
// in between its arguments. __CONCAT can also concatenate double-quoted
// strings produced by the __STRING macro, but this only works with ANSI C.
// In non-ANSI C environments, new programs will want ANSI-only C keywords
// deleted from the program and old programs will want them left alone.
// When using a compiler other than gcc, programs using the ANSI C keywords
// const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
// When using "gcc -traditional", we assume that this is the intent; if
// __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
// __pure2 can be used for functions that are only a function of their scalar
// arguments (meaning they can't dereference pointers).
//

4
vendor/modernc.org/libc/libc.go generated vendored

@ -161,6 +161,10 @@ func X_exit(_ *TLS, status int32) {
}
func SetEnviron(t *TLS, env []string) {
if environInitialized {
return
}
environInitialized = true
p := Xcalloc(t, 1, types.Size_t((len(env)+1)*(int(uintptrSize))))
if p == 0 {

@ -1481,7 +1481,7 @@ func X__xuname(t *TLS, namesize int32, namebuf uintptr) int32 {
}
// int chflags(const char *path, u_int flags);
func Xchflags(t *TLS, path uintptr, flags uint64) int32 {
func Xchflags(t *TLS, path uintptr, flags uint32) int32 {
if err := unix.Chflags(GoString(path), int(flags)); err != nil {
if dmesgs {
dmesg("%v: %v FAIL", origin(1), err)
@ -1605,3 +1605,29 @@ func X__assert2(t *TLS, file uintptr, line int32, fn, expr uintptr) {
func Xgetpagesize(t *TLS) int32 {
return int32(unix.Getpagesize())
}
const PTHREAD_MUTEX_DEFAULT = 0
// The pthread_mutex_init() function shall initialize the mutex referenced by
// mutex with attributes specified by attr. If attr is NULL, the default mutex
// attributes are used; the effect shall be the same as passing the address of
// a default mutex attributes object. Upon successful initialization, the state
// of the mutex becomes initialized and unlocked.
//
// If successful, the pthread_mutex_destroy() and pthread_mutex_init()
// functions shall return zero; otherwise, an error number shall be returned to
// indicate the error.
//
// int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
func Xpthread_mutex_init(t *TLS, pMutex, pAttr uintptr) int32 {
typ := PTHREAD_MUTEX_DEFAULT
if pAttr != 0 {
typ = int(X__ccgo_pthreadMutexattrGettype(t, pAttr))
}
mutexesMu.Lock()
defer mutexesMu.Unlock()
mutexes[pMutex] = newMutex(typ)
return 0
}

@ -380,7 +380,7 @@ func Xalarm(t *TLS, seconds uint32) uint32 {
}
// int getnameinfo(const struct sockaddr * restrict sa, socklen_t salen, char * restrict host, socklen_t hostlen, char * restrict serv, socklen_t servlen, int flags);
func Xgetnameinfo(tls *TLS, sa1 uintptr, sl socklen_t, node uintptr, nodelen socklen_t, serv uintptr, servlen socklen_t, flags int32) int32 { /* getnameinfo.c:125:5: */
func Xgetnameinfo(tls *TLS, sa1 uintptr, sl socklen_t, node uintptr, nodelen size_t, serv uintptr, servlen size_t, flags int32) int32 { /* getnameinfo.c:125:5: */
panic(todo(""))
//TODO bp := tls.Alloc(347)
//TODO defer tls.Free(347)

@ -2,4 +2,6 @@
package limits
var CAPI = map[string]struct{}{}
var CAPI = map[string]struct{}{
"__darwin_check_fd_set_overflow": {},
}

@ -1,4 +1,4 @@
// Code generated by 'ccgo limits/gen.c -crt-import-path -export-defines -export-enums -export-externs X -export-fields F -export-structs -export-typedefs -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o limits/limits_windows_386.go -pkgname limits', DO NOT EDIT.
// Code generated by 'ccgo limits\gen.c -crt-import-path -export-defines -export-enums -export-externs X -export-fields F -export-structs -export-typedefs -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o limits\limits_windows_386.go -pkgname limits', DO NOT EDIT.
package limits

@ -1,4 +1,4 @@
// Code generated by 'ccgo limits/gen.c -crt-import-path "" -export-defines "" -export-enums "" -export-externs X -export-fields F -export-structs "" -export-typedefs "" -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o limits/limits_windows_386.go -pkgname limits', DO NOT EDIT.
// Code generated by 'ccgo limits\gen.c -crt-import-path "" -export-defines "" -export-enums "" -export-externs X -export-fields F -export-structs "" -export-typedefs "" -header -hide _OSSwapInt16,_OSSwapInt32,_OSSwapInt64 -o limits\limits_windows_386.go -pkgname limits', DO NOT EDIT.
package limits
@ -44,7 +44,9 @@ const (
LONG_MIN = -2147483648
MB_LEN_MAX = 5
MINGW_DDK_H = 0
MINGW_DDRAW_VERSION = 7
MINGW_HAS_DDK_H = 1
MINGW_HAS_DDRAW_H = 1
MINGW_HAS_SECURE_API = 1
MINGW_SDK_INIT = 0
PATH_MAX = 260
@ -79,7 +81,6 @@ const (
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES = 0
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT = 0
X_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_MEMORY = 0
X_CRT_USE_WINAPI_FAMILY_DESKTOP_APP = 0
X_DLL = 0
X_ERRCODE_DEFINED = 0
X_FILE_OFFSET_BITS = 64
@ -92,8 +93,6 @@ const (
X_I64_MIN = -9223372036854775808
X_I8_MAX = 127
X_I8_MIN = -128
X_ILP32 = 1
X_INC_CORECRT = 0
X_INC_CRTDEFS = 0
X_INC_CRTDEFS_MACRO = 0
X_INC_LIMITS = 0
@ -109,6 +108,7 @@ const (
X_PGLOBAL = 0
X_PTRDIFF_T_ = 0
X_PTRDIFF_T_DEFINED = 0
X_REENTRANT = 1
X_RSIZE_T_DEFINED = 0
X_SECURECRT_FILL_BUFFER_PATTERN = 0xFD
X_SIZE_T_DEFINED = 0
@ -146,7 +146,7 @@ type X__float128 = float64 /* <builtin>:47:21 */
type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// Copyright (C) 1992-2020 Free Software Foundation, Inc.
// Copyright (C) 1992-2018 Free Software Foundation, Inc.
//
// This file is part of GCC.
//
@ -200,11 +200,6 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// *
// This file has no copyright assigned and is placed in the Public Domain.
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// This macro holds an monotonic increasing value, which indicates
// a specific fix/patch is present on trunk. This value isn't related to
// minor/major version-macros. It is increased on demand, if a big
@ -225,12 +220,6 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// MinGW-w64 has some additional C99 printf/scanf feature support.
// So we add some helper macros to ease recognition of them.
// If _FORTIFY_SOURCE is enabled, some inline functions may use
// __builtin_va_arg_pack(). GCC may report an error if the address
// of such a function is used. Set _FORTIFY_VA_ARG=0 in this case.
// Enable workaround for ABI incompatibility on affected platforms
// *
// This file has no copyright assigned and is placed in the Public Domain.
// This file is part of the mingw-w64 runtime package.
@ -271,28 +260,26 @@ type Va_list = X__builtin_va_list /* <builtin>:50:27 */
// This file is part of the mingw-w64 runtime package.
// No warranty is given; refer to the file DISCLAIMER.PD within this package.
// for backward compatibility
type X__gnuc_va_list = X__builtin_va_list /* vadefs.h:24:29 */
type Ssize_t = int32 /* corecrt.h:52:13 */
type Ssize_t = int32 /* crtdefs.h:47:13 */
type Rsize_t = Size_t /* corecrt.h:57:16 */
type Rsize_t = Size_t /* crtdefs.h:52:16 */
type Intptr_t = int32 /* corecrt.h:69:13 */
type Intptr_t = int32 /* crtdefs.h:64:13 */
type Uintptr_t = uint32 /* corecrt.h:82:22 */
type Uintptr_t = uint32 /* crtdefs.h:77:22 */
type Wint_t = uint16 /* corecrt.h:111:24 */
type Wctype_t = uint16 /* corecrt.h:112:24 */
type Wint_t = uint16 /* crtdefs.h:106:24 */
type Wctype_t = uint16 /* crtdefs.h:107:24 */
type Errno_t = int32 /* corecrt.h:118:13 */
type Errno_t = int32 /* crtdefs.h:113:13 */
type X__time32_t = int32 /* corecrt.h:123:14 */
type X__time32_t = int32 /* crtdefs.h:118:14 */
type X__time64_t = int64 /* corecrt.h:128:35 */
type X__time64_t = int64 /* crtdefs.h:123:35 */
type Time_t = X__time32_t /* corecrt.h:141:20 */
type Time_t = X__time32_t /* crtdefs.h:136:20 */
type Threadlocaleinfostruct = struct {
Frefcount int32
@ -318,29 +305,29 @@ type Threadlocaleinfostruct = struct {
Fpclmap uintptr
Fpcumap uintptr
Flc_time_curr uintptr
} /* corecrt.h:435:1 */
} /* crtdefs.h:422:1 */
type Pthreadlocinfo = uintptr /* corecrt.h:437:39 */
type Pthreadmbcinfo = uintptr /* corecrt.h:438:36 */
type Pthreadlocinfo = uintptr /* crtdefs.h:424:39 */
type Pthreadmbcinfo = uintptr /* crtdefs.h:425:36 */
type Localeinfo_struct = struct {
Flocinfo Pthreadlocinfo
Fmbcinfo Pthreadmbcinfo
} /* corecrt.h:441:9 */
} /* crtdefs.h:428:9 */
type X_locale_tstruct = Localeinfo_struct /* corecrt.h:444:3 */
type X_locale_t = uintptr /* corecrt.h:444:19 */
type X_locale_tstruct = Localeinfo_struct /* crtdefs.h:431:3 */
type X_locale_t = uintptr /* crtdefs.h:431:19 */
type TagLC_ID = struct {
FwLanguage uint16
FwCountry uint16
FwCodePage uint16
} /* corecrt.h:435:1 */
} /* crtdefs.h:422:1 */
type LC_ID = TagLC_ID /* corecrt.h:452:3 */
type LPLC_ID = uintptr /* corecrt.h:452:9 */
type LC_ID = TagLC_ID /* crtdefs.h:439:3 */
type LPLC_ID = uintptr /* crtdefs.h:439:9 */
type Threadlocinfo = Threadlocaleinfostruct /* corecrt.h:487:3 */
type Threadlocinfo = Threadlocaleinfostruct /* crtdefs.h:468:3 */
// File system limits
//
@ -350,7 +337,7 @@ type Threadlocinfo = Threadlocaleinfostruct /* corecrt.h:487:3 */
// are semantically identical, with a limit of 259 characters for the
// path name, plus one for a terminating NUL, for a total of 260.
// Copyright (C) 1991-2020 Free Software Foundation, Inc.
// Copyright (C) 1991-2018 Free Software Foundation, Inc.
//
// This file is part of GCC.
//

@ -1,4 +1,4 @@
// Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -hide isascii,isspace,tolower,toupper -nostdinc -nostdlib -o ../musl_darwin_amd64.go -pkgname libc -static-locals-prefix _s -Iarch/x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c ../darwin/table.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strchrnul.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c', DO NOT EDIT.
// Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -hide isascii,isspace,tolower,toupper -nostdinc -nostdlib -o ../musl_darwin_amd64.go -pkgname libc -static-locals-prefix _s -Iarch/x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c ../darwin/table.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strchrnul.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c', DO NOT EDIT.
package libc
@ -4415,6 +4415,26 @@ func X__uflow(tls *TLS, f uintptr) int32 { /* __uflow.c:6:5: */
return -1
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > uint64(0) {
try = base + uintptr(width*(nel/uint64(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / uint64(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/uint64(2) + uint64(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(232)
defer tls.Free(232)

@ -1,4 +1,4 @@
// Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -hide isascii,isspace,tolower,toupper -nostdinc -nostdlib -o ../musl_darwin_arm64.go -pkgname libc -static-locals-prefix _s -Iarch/aarch64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c ../darwin/table.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strchrnul.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c', DO NOT EDIT.
// Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -hide isascii,isspace,tolower,toupper -nostdinc -nostdlib -o ../musl_darwin_arm64.go -pkgname libc -static-locals-prefix _s -Iarch/aarch64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c ../darwin/table.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strchrnul.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c', DO NOT EDIT.
package libc
@ -357,6 +357,8 @@ type size_t = uint64 /* <builtin>:9:23 */
type wchar_t = int32 /* <builtin>:15:24 */
var X__darwin_check_fd_set_overflow uintptr /* <builtin>:146:5: */
// pthread opaque structures
type __darwin_pthread_handler_rec = struct {
@ -4413,6 +4415,26 @@ func X__uflow(tls *TLS, f uintptr) int32 { /* __uflow.c:6:5: */
return -1
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > uint64(0) {
try = base + uintptr(width*(nel/uint64(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / uint64(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/uint64(2) + uint64(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(232)
defer tls.Free(232)

@ -1,4 +1,4 @@
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6,getnameinfo,gethostbyaddr_r, -nostdinc -nostdlib -o ../musl_freebsd_amd64.go -pkgname libc -static-locals-prefix _s -Iarch/x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c ../freebsd/table.cpp.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strnlen.c src/string/strspn.c', DO NOT EDIT.
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6,getnameinfo,gethostbyaddr_r, -nostdinc -nostdlib -o ../musl_freebsd_amd64.go -pkgname libc -static-locals-prefix _s -Iarch/x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c ../freebsd/table.cpp.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isspace.c src/ctype/isupper.c src/ctype/isxdigit.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strnlen.c src/string/strspn.c', DO NOT EDIT.
package libc
@ -3356,6 +3356,51 @@ func X__isdigit_l(tls *TLS, c int32, l locale_t) int32 { /* isdigit.c:9:5: */
return Xisdigit(tls, c)
}
func Xislower(tls *TLS, c int32) int32 { /* islower.c:4:5: */
return Bool32(uint32(c)-uint32('a') < uint32(26))
}
func X__islower_l(tls *TLS, c int32, l locale_t) int32 { /* islower.c:9:5: */
return Xislower(tls, c)
}
func Xisprint(tls *TLS, c int32) int32 { /* isprint.c:4:5: */
return Bool32(uint32(c)-uint32(0x20) < uint32(0x5f))
}
func X__isprint_l(tls *TLS, c int32, l locale_t) int32 { /* isprint.c:9:5: */
return Xisprint(tls, c)
}
func Xisspace(tls *TLS, c int32) int32 { /* isspace.c:4:5: */
return Bool32(c == ' ' || uint32(c)-uint32('\t') < uint32(5))
}
func X__isspace_l(tls *TLS, c int32, l locale_t) int32 { /* isspace.c:9:5: */
return Xisspace(tls, c)
}
func Xisupper(tls *TLS, c int32) int32 { /* isupper.c:4:5: */
return Bool32(uint32(c)-uint32('A') < uint32(26))
}
func X__isupper_l(tls *TLS, c int32, l locale_t) int32 { /* isupper.c:9:5: */
return Xisupper(tls, c)
}
func Xisxdigit(tls *TLS, c int32) int32 { /* isxdigit.c:3:5: */
return Bool32(func() int32 {
if 0 != 0 {
return Xisdigit(tls, c)
}
return Bool32(uint32(c)-uint32('0') < uint32(10))
}() != 0 || uint32(c)|uint32(32)-uint32('a') < uint32(6))
}
func X__isxdigit_l(tls *TLS, c int32, l locale_t) int32 { /* isxdigit.c:8:5: */
return Xisxdigit(tls, c)
}
type uintptr_t = uint64 /* alltypes.h:55:24 */
type intptr_t = int64 /* alltypes.h:70:15 */
@ -6667,6 +6712,26 @@ func X__uflow(tls *TLS, f uintptr) int32 { /* __uflow.c:6:5: */
return -1
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > uint64(0) {
try = base + uintptr(width*(nel/uint64(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / uint64(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/uint64(2) + uint64(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(232)
defer tls.Free(232)

@ -1,4 +1,4 @@
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_386.go -pkgname libc -static-locals-prefix _s -Iarch/i386 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_386.go -pkgname libc -static-locals-prefix _s -Iarch/i386 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
package libc
@ -6452,6 +6452,26 @@ func Xvsscanf(tls *TLS, s uintptr, fmt uintptr, ap va_list) int32 { /* vsscanf.c
return Xvfscanf(tls, bp, fmt, ap)
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > size_t(0) {
try = base + uintptr(width*(nel/size_t(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / size_t(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/size_t(2) + size_t(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(136)
defer tls.Free(136)

@ -1,4 +1,4 @@
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_amd64.go -pkgname libc -static-locals-prefix _s -Iarch/x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_amd64.go -pkgname libc -static-locals-prefix _s -Iarch/x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
package libc
@ -6507,6 +6507,26 @@ func Xvsscanf(tls *TLS, s uintptr, fmt uintptr, ap va_list) int32 { /* vsscanf.c
return Xvfscanf(tls, bp, fmt, ap)
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > uint64(0) {
try = base + uintptr(width*(nel/uint64(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / uint64(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/uint64(2) + uint64(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(232)
defer tls.Free(232)

@ -1,4 +1,4 @@
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_arm.go -pkgname libc -static-locals-prefix _s -Iarch/arm -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_arm.go -pkgname libc -static-locals-prefix _s -Iarch/arm -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
package libc
@ -6485,6 +6485,26 @@ func Xvsscanf(tls *TLS, s uintptr, fmt uintptr, ap va_list) int32 { /* vsscanf.c
return Xvfscanf(tls, bp, fmt, ap)
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > size_t(0) {
try = base + uintptr(width*(nel/size_t(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / size_t(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/size_t(2) + size_t(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(144)
defer tls.Free(144)

@ -1,4 +1,4 @@
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_arm64.go -pkgname libc -static-locals-prefix _s -Iarch/aarch64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_arm64.go -pkgname libc -static-locals-prefix _s -Iarch/aarch64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
package libc
@ -6595,6 +6595,26 @@ func Xvsscanf(tls *TLS, s uintptr, fmt uintptr, ap va_list) int32 { /* vsscanf.c
return Xvfscanf(tls, bp, fmt, ap)
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > uint64(0) {
try = base + uintptr(width*(nel/uint64(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / uint64(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/uint64(2) + uint64(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(232)
defer tls.Free(232)

@ -1,4 +1,4 @@
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_s390x.go -pkgname libc -static-locals-prefix _s -Iarch/s390x -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_s390x.go -pkgname libc -static-locals-prefix _s -Iarch/s390x -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/__ctype_b_loc.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/locale/localeconv.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT.
package libc
@ -6535,6 +6535,26 @@ func Xvsscanf(tls *TLS, s uintptr, fmt uintptr, ap va_list) int32 { /* vsscanf.c
return Xvfscanf(tls, bp, fmt, ap)
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > uint64(0) {
try = base + uintptr(width*(nel/uint64(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / uint64(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/uint64(2) + uint64(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(232)
defer tls.Free(232)

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6,getnameinfo,gethostbyaddr_r, -nostdinc -nostdlib -o ../musl_openbsd_amd64.go -pkgname libc -static-locals-prefix _s -Iarch/x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c ../freebsd/table.cpp.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/isprint.c src/ctype/isspace.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strnlen.c src/string/strspn.c', DO NOT EDIT.
// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6,getnameinfo,gethostbyaddr_r, -nostdinc -nostdlib -o ../musl_openbsd_amd64.go -pkgname libc -static-locals-prefix _s -Iarch/x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c ../freebsd/table.cpp.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isspace.c src/ctype/isupper.c src/ctype/isxdigit.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/rint.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/bsearch.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strnlen.c src/string/strspn.c', DO NOT EDIT.
package libc
@ -3356,6 +3356,14 @@ func X__isdigit_l(tls *TLS, c int32, l locale_t) int32 { /* isdigit.c:9:5: */
return Xisdigit(tls, c)
}
func Xislower(tls *TLS, c int32) int32 { /* islower.c:4:5: */
return Bool32(uint32(c)-uint32('a') < uint32(26))
}
func X__islower_l(tls *TLS, c int32, l locale_t) int32 { /* islower.c:9:5: */
return Xislower(tls, c)
}
func Xisprint(tls *TLS, c int32) int32 { /* isprint.c:4:5: */
return Bool32(uint32(c)-uint32(0x20) < uint32(0x5f))
}
@ -3372,6 +3380,27 @@ func X__isspace_l(tls *TLS, c int32, l locale_t) int32 { /* isspace.c:9:5: */
return Xisspace(tls, c)
}
func Xisupper(tls *TLS, c int32) int32 { /* isupper.c:4:5: */
return Bool32(uint32(c)-uint32('A') < uint32(26))
}
func X__isupper_l(tls *TLS, c int32, l locale_t) int32 { /* isupper.c:9:5: */
return Xisupper(tls, c)
}
func Xisxdigit(tls *TLS, c int32) int32 { /* isxdigit.c:3:5: */
return Bool32(func() int32 {
if 0 != 0 {
return Xisdigit(tls, c)
}
return Bool32(uint32(c)-uint32('0') < uint32(10))
}() != 0 || uint32(c)|uint32(32)-uint32('a') < uint32(6))
}
func X__isxdigit_l(tls *TLS, c int32, l locale_t) int32 { /* isxdigit.c:8:5: */
return Xisxdigit(tls, c)
}
type uintptr_t = uint64 /* alltypes.h:55:24 */
type intptr_t = int64 /* alltypes.h:70:15 */
@ -6683,6 +6712,26 @@ func X__uflow(tls *TLS, f uintptr) int32 { /* __uflow.c:6:5: */
return -1
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > uint64(0) {
try = base + uintptr(width*(nel/uint64(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / uint64(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/uint64(2) + uint64(1))
} else {
return try
}
}
return uintptr(0)
}
func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */
bp := tls.Alloc(232)
defer tls.Free(232)

@ -1,4 +1,4 @@
// Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_windows_386.go -pkgname libc -static-locals-prefix _s -Iarch/i386 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isspace.c src/ctype/isxdigit.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/multibyte/wcrtomb.c src/multibyte/wcsrtombs.c src/multibyte/wcstombs.c src/string/strchrnul.c src/string/strdup.c', DO NOT EDIT.
// Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_windows_386.go -pkgname libc -static-locals-prefix _s -Iarch\i386 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isspace.c src/ctype/isxdigit.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/multibyte/wcrtomb.c src/multibyte/wcsrtombs.c src/multibyte/wcstombs.c src/stdlib/bsearch.c src/string/strchrnul.c src/string/strdup.c', DO NOT EDIT.
package libc
@ -863,32 +863,32 @@ type mode_t = uint32 /* alltypes.h:175:18 */
type syscall_arg_t = int32 /* syscall.h:22:14 */
func a_cas(tls *TLS, p uintptr, t int32, s int32) int32 { /* atomic_arch.h:2:19: */
panic(`arch/i386/atomic_arch.h:4:2: assembler statements not supported`)
panic(`arch\i386\atomic_arch.h:4:2: assembler statements not supported`)
return t
}
func a_and(tls *TLS, p uintptr, v int32) { /* atomic_arch.h:29:20: */
panic(`arch/i386/atomic_arch.h:31:2: assembler statements not supported`)
panic(`arch\i386\atomic_arch.h:31:2: assembler statements not supported`)
}
func a_or(tls *TLS, p uintptr, v int32) { /* atomic_arch.h:37:20: */
panic(`arch/i386/atomic_arch.h:39:2: assembler statements not supported`)
panic(`arch\i386\atomic_arch.h:39:2: assembler statements not supported`)
}
func a_ctz_64(tls *TLS, x uint64_t) int32 { /* atomic_arch.h:87:19: */
var r int32
panic(`arch/i386/atomic_arch.h:90:2: assembler statements not supported`)
panic(`arch\i386\atomic_arch.h:90:2: assembler statements not supported`)
return r
}
func a_ctz_32(tls *TLS, x uint32_t) int32 { /* atomic_arch.h:96:19: */
var r int32
panic(`arch/i386/atomic_arch.h:99:2: assembler statements not supported`)
panic(`arch\i386\atomic_arch.h:99:2: assembler statements not supported`)
return r
}
func a_clz_32(tls *TLS, x uint32_t) int32 { /* atomic_arch.h:104:19: */
panic(`arch/i386/atomic_arch.h:106:2: assembler statements not supported`)
panic(`arch\i386\atomic_arch.h:106:2: assembler statements not supported`)
return int32(x)
}
@ -917,7 +917,7 @@ type __timer = struct {
func __pthread_self(tls *TLS) uintptr { /* pthread_arch.h:1:30: */
var self uintptr
panic(`arch/i386/pthread_arch.h:4:2: assembler statements not supported`)
panic(`arch\i386\pthread_arch.h:4:2: assembler statements not supported`)
return self
}
@ -1039,6 +1039,26 @@ func Xwcstombs(tls *TLS, s uintptr, ws uintptr, n size_t) size_t { /* wcstombs.c
return Xwcsrtombs(tls, s, bp, n, uintptr(0))
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > size_t(0) {
try = base + uintptr(width*(nel/size_t(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / size_t(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/size_t(2) + size_t(1))
} else {
return try
}
}
return uintptr(0)
}
// Support signed or unsigned plain-char
// Implementation choices...

@ -1,4 +1,4 @@
// Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_windows_amd64.go -pkgname libc -static-locals-prefix _s -Iarch\x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isspace.c src/ctype/isxdigit.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/multibyte/wcrtomb.c src/multibyte/wcsrtombs.c src/multibyte/wcstombs.c src/string/strchrnul.c src/string/strdup.c', DO NOT EDIT.
// Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_windows_amd64.go -pkgname libc -static-locals-prefix _s -Iarch\x86_64 -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isspace.c src/ctype/isxdigit.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/multibyte/wcrtomb.c src/multibyte/wcsrtombs.c src/multibyte/wcstombs.c src/stdlib/bsearch.c src/string/strchrnul.c src/string/strdup.c', DO NOT EDIT.
package libc
@ -1062,6 +1062,26 @@ func Xwcstombs(tls *TLS, s uintptr, ws uintptr, n size_t) size_t { /* wcstombs.c
return Xwcsrtombs(tls, s, bp, n, uintptr(0))
}
func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
var try uintptr
var sign int32
for nel > uint64(0) {
try = base + uintptr(width*(nel/uint64(2)))
sign = (*struct {
f func(*TLS, uintptr, uintptr) int32
})(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
if sign < 0 {
nel = nel / uint64(2)
} else if sign > 0 {
base = try + uintptr(width)
nel = nel - (nel/uint64(2) + uint64(1))
} else {
return try
}
}
return uintptr(0)
}
// Support signed or unsigned plain-char
// Implementation choices...

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save