summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Rhymen
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/Rhymen')
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/errors.go32
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/media.go33
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/read.go11
3 files changed, 34 insertions, 42 deletions
diff --git a/vendor/github.com/Rhymen/go-whatsapp/errors.go b/vendor/github.com/Rhymen/go-whatsapp/errors.go
index 022f977a..2f58a771 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/errors.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/errors.go
@@ -7,23 +7,21 @@ import (
)
var (
- ErrAlreadyConnected = errors.New("already connected")
- ErrAlreadyLoggedIn = errors.New("already logged in")
- ErrInvalidSession = errors.New("invalid session")
- ErrLoginInProgress = errors.New("login or restore already running")
- ErrNotConnected = errors.New("not connected")
- ErrInvalidWsData = errors.New("received invalid data")
- ErrInvalidWsState = errors.New("can't handle binary data when not logged in")
- ErrConnectionTimeout = errors.New("connection timed out")
- ErrMissingMessageTag = errors.New("no messageTag specified or to short")
- ErrInvalidHmac = errors.New("invalid hmac")
- ErrInvalidServerResponse = errors.New("invalid response received from server")
- ErrServerRespondedWith404 = errors.New("server responded with status 404")
- ErrMediaDownloadFailedWith404 = errors.New("download failed with status code 404")
- ErrMediaDownloadFailedWith410 = errors.New("download failed with status code 410")
- ErrInvalidWebsocket = errors.New("invalid websocket")
- ErrMessageTypeNotImplemented = errors.New("message type not implemented")
- ErrOptionsNotProvided = errors.New("new conn options not provided")
+ ErrAlreadyConnected = errors.New("already connected")
+ ErrAlreadyLoggedIn = errors.New("already logged in")
+ ErrInvalidSession = errors.New("invalid session")
+ ErrLoginInProgress = errors.New("login or restore already running")
+ ErrNotConnected = errors.New("not connected")
+ ErrInvalidWsData = errors.New("received invalid data")
+ ErrInvalidWsState = errors.New("can't handle binary data when not logged in")
+ ErrConnectionTimeout = errors.New("connection timed out")
+ ErrMissingMessageTag = errors.New("no messageTag specified or to short")
+ ErrInvalidHmac = errors.New("invalid hmac")
+ ErrInvalidServerResponse = errors.New("invalid response received from server")
+ ErrServerRespondedWith404 = errors.New("server responded with status 404")
+ ErrInvalidWebsocket = errors.New("invalid websocket")
+ ErrMessageTypeNotImplemented = errors.New("message type not implemented")
+ ErrOptionsNotProvided = errors.New("new conn options not provided")
)
type ErrConnectionFailed struct {
diff --git a/vendor/github.com/Rhymen/go-whatsapp/media.go b/vendor/github.com/Rhymen/go-whatsapp/media.go
index 0fcacd2e..f72e7922 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/media.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/media.go
@@ -10,6 +10,7 @@ import (
"fmt"
"io"
"io/ioutil"
+ "net"
"net/http"
"net/url"
"time"
@@ -71,16 +72,10 @@ func downloadMedia(url string) (file []byte, mac []byte, err error) {
if err != nil {
return nil, nil, err
}
- if resp.StatusCode != 200 {
- if resp.StatusCode == 404 {
- return nil, nil, ErrMediaDownloadFailedWith404
- }
- if resp.StatusCode == 410 {
- return nil, nil, ErrMediaDownloadFailedWith410
- }
+ defer resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
return nil, nil, fmt.Errorf("download failed with status code %d", resp.StatusCode)
}
- defer resp.Body.Close()
if resp.ContentLength <= 10 {
return nil, nil, fmt.Errorf("file to short")
}
@@ -101,8 +96,8 @@ type MediaConn struct {
Hosts []struct {
Hostname string `json:"hostname"`
IPs []struct {
- IP4 string `json:"ip4"`
- IP6 string `json:"ip6"`
+ IP4 net.IP `json:"ip4"`
+ IP6 net.IP `json:"ip6"`
} `json:"ips"`
} `json:"hosts"`
} `json:"media_conn"`
@@ -125,21 +120,17 @@ func (wac *Conn) queryMediaConn() (hostname, auth string, ttl int, err error) {
return "", "", 0, fmt.Errorf("query media conn timed out")
}
- if resp.Status != 200 {
+ if resp.Status != http.StatusOK {
return "", "", 0, fmt.Errorf("query media conn responded with %d", resp.Status)
}
- var host string
for _, h := range resp.MediaConn.Hosts {
if h.Hostname != "" {
- host = h.Hostname
- break
+ return h.Hostname, resp.MediaConn.Auth, resp.MediaConn.TTL, nil
}
}
- if host == "" {
- return "", "", 0, fmt.Errorf("query media conn responded with no host")
- }
- return host, resp.MediaConn.Auth, resp.MediaConn.TTL, nil
+
+ return "", "", 0, fmt.Errorf("query media conn responded with no host")
}
var mediaTypeMap = map[MediaType]string{
@@ -202,7 +193,7 @@ func (wac *Conn) Upload(reader io.Reader, appInfo MediaType) (downloadURL string
body := bytes.NewReader(append(enc, mac...))
- req, err := http.NewRequest("POST", uploadURL.String(), body)
+ req, err := http.NewRequest(http.MethodPost, uploadURL.String(), body)
if err != nil {
return "", nil, nil, nil, 0, err
}
@@ -222,7 +213,9 @@ func (wac *Conn) Upload(reader io.Reader, appInfo MediaType) (downloadURL string
}
var jsonRes map[string]string
- json.NewDecoder(res.Body).Decode(&jsonRes)
+ if err := json.NewDecoder(res.Body).Decode(&jsonRes); err != nil {
+ return "", nil, nil, nil, 0, err
+ }
return jsonRes["url"], mediaKey, fileEncSha256, fileSha256, fileLength, nil
}
diff --git a/vendor/github.com/Rhymen/go-whatsapp/read.go b/vendor/github.com/Rhymen/go-whatsapp/read.go
index 81e16619..1621c0f5 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/read.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/read.go
@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"io/ioutil"
+ "net/http"
"strings"
"github.com/Rhymen/go-whatsapp/binary"
@@ -111,16 +112,16 @@ func (wac *Conn) decryptBinaryMessage(msg []byte) (*binary.Node, error) {
var response struct {
Status int `json:"status"`
}
- err := json.Unmarshal(msg, &response)
- if err == nil {
- if response.Status == 404 {
+
+ if err := json.Unmarshal(msg, &response); err == nil {
+ if response.Status == http.StatusNotFound {
return nil, ErrServerRespondedWith404
}
return nil, errors.New(fmt.Sprintf("server responded with %d", response.Status))
- } else {
- return nil, ErrInvalidServerResponse
}
+ return nil, ErrInvalidServerResponse
+
}
h2.Write([]byte(msg[32:]))
if !hmac.Equal(h2.Sum(nil), msg[:32]) {