From aeaddd954bb6570f2d50e34c597e8fbd672c3845 Mon Sep 17 00:00:00 2001 From: Romain Hunault Date: Mon, 23 Mar 2020 16:39:28 +0000 Subject: [PATCH] Ecloud support --- .gitlab-ci.yml | 2 +- sms.go | 7 ++++++ smsbuffer.go | 11 +++++++-- smshttpclient.go | 55 ++++++++++++++++++++++++++++++++++++--------- smshttpresponses.go | 36 ++++++++++++++++++++++++++++- 5 files changed, 96 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c6d3955..527c88f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,11 +19,11 @@ build: - unzip /tmp/sdk-tools-linux.zip -d .android > /dev/null - unzip /tmp/android-ndk-linux.zip -d .android/ndk > /dev/null - export ANDROID_HOME=$PWD/.android + - export ANDROID_NDK_HOME=$PWD/.android/ndk/android-ndk-${ANDROID_NDK_VERSION} - export PATH=$PATH:$PWD/.android/platform-tools/:$GOPATH/bin - echo y | .android/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" # Gomobile part - go get -u golang.org/x/mobile/cmd/gomobile - - $GOPATH/bin/gomobile init -ndk .android/ndk/android-ndk-${ANDROID_NDK_VERSION} - mkdir -p $GOPATH/src/gitlab.com/nerzhul - ln -s $(pwd) $GOPATH/src/gitlab.com/nerzhul/ncsmsgo script: diff --git a/sms.go b/sms.go index 0174faa..ad20f4d 100644 --- a/sms.go +++ b/sms.go @@ -2,11 +2,18 @@ package ncsmsgo type Sms struct { ID int `json:"_id"` + NCID int `json:"nc_id"` Mailbox int `json:"mbox"` Type int `json:"type"` Date int64 `json:"date"` Body string `json:"body"` Address string `json:"address"` + CardNumber string `json:"card_number"` + CardSlot int `json:"card_slot"` + IccID string `json:"icc_id"` + DeviceName string `json:"device_name"` + CarrierName string `json:"carrier_name"` + Sent int `json:"sent"` Read string `json:"read"` Seen string `json:"seen"` } diff --git a/smsbuffer.go b/smsbuffer.go index 7926c1e..194165e 100644 --- a/smsbuffer.go +++ b/smsbuffer.go @@ -27,15 +27,22 @@ func (b *SmsBuffer) AsRawJSONString() string { return string(bspq) } -func (b *SmsBuffer) Push(ID int, mailboxID int, t int, date int64, address string, body string, read string, +func (b *SmsBuffer) Push(ID int, NCID int, mailboxID int, t int, date int64, address string, card_number string, card_slot int, icc_id string, device_name string, carrier_name string, body string, sent int, read string, seen string) { b.spq.SmsData = append(b.spq.SmsData, Sms{ ID: ID, + NCID: NCID, Mailbox: mailboxID, Type: t, Date: date, Address: address, + CardNumber: card_number, + CardSlot: card_slot, + IccID: icc_id, + DeviceName: device_name, + CarrierName: carrier_name, Body: body, + Sent: sent, Read: read, Seen: seen, }) @@ -49,4 +56,4 @@ func (b *SmsBuffer) Push(ID int, mailboxID int, t int, date int64, address strin func (b *SmsBuffer) GetLastMessageDate() int64 { return b.lastMessageDate -} \ No newline at end of file +} diff --git a/smshttpclient.go b/smshttpclient.go index d24988a..2ec7da0 100644 --- a/smshttpclient.go +++ b/smshttpclient.go @@ -13,16 +13,19 @@ import ( const ( // APIv1 - rcallGetVersion = "/index.php/apps/ocsms/get/apiversion?format=json" - rcallGetAllSmsIds = "/index.php/apps/ocsms/get/smsidlist?format=json" - rcallGetLastMsgTimestamp = "/index.php/apps/ocsms/get/lastmsgtime?format=json" - rcallPushRoute = "/index.php/apps/ocsms/push?format=json" + rcallGetVersion = "/index.php/apps/esms/get/apiversion?format=json" + rcallGetAllSmsIds = "/index.php/apps/esms/get/smsidlist?format=json" + rcallGetLastMsgTimestamp = "/index.php/apps/esms/get/lastmsgtime?format=json" + rcallPushRoute = "/index.php/apps/esms/push?format=json" // APIv2 - rcallV2GetPhoneList = "/index.php/apps/ocsms/api/v2/phones/list?format=json"; - rcallV2GetMessages = "/index.php/apps/ocsms/api/v2/messages/[START]/[LIMIT]?format=json"; - rcallV2GetMessagesPhone = "/index.php/apps/ocsms/api/v2/messages/[PHONENUMBER]/[START]/[LIMIT]?format=json"; - rcallV2GetMessagesSendQueue = "/index.php/apps/ocsms/api/v2/messages/sendqueue?format=json"; + rcallV2GetPhoneList = "/index.php/apps/esms/api/v2/phones/list?format=json"; + rcallV2GetMessages = "/index.php/apps/esms/api/v2/messages/[START]/[LIMIT]?format=json"; + rcallV2GetMessagesPhone = "/index.php/apps/esms/api/v2/messages/[PHONENUMBER]/[START]/[LIMIT]?format=json"; + rcallV2GetMessagesSendQueue = "/index.php/apps/esms/api/v2/messages/sendqueue?format=json"; + + // APIv4 + rcallV4DeleteMessages = "/index.php/apps/esms/api/v4/messages/delete_message?format=json&date=[DATE]&phoneNumber=[PHONENUMBER]"; ) type SmsHTTPClient struct { @@ -40,13 +43,15 @@ func (s *SmsHTTPClient) Init(url string, appVersion string, userName string, pas s.userAgent = "nextcloud-phonesync-go (" + appVersion + ")" s.userName = userName s.password = password - tr := &http.Transport{} if insecure { tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} } - s.client = &http.Client{Transport: tr} + s.client = &http.Client{Transport: tr, CheckRedirect: func(req *http.Request, via []*http.Request) error { + req.SetBasicAuth(userName, password) + return nil + }} } func (s *SmsHTTPClient) GetLastHTTPStatus() int { @@ -234,4 +239,32 @@ func (s *SmsHTTPClient) DoGetMessagesCall(start int64, limit int) *SmsMessagesRe smsResp.transformResponse() return smsResp -} \ No newline at end of file +} + +func (s *SmsHTTPClient) DoDeleteMessageCall(address string, date int64) *SmsDeleteResponse { + fixedEndpoint := strings.Replace( + strings.Replace(rcallV4DeleteMessages, "[DATE]", strconv.FormatInt(date, 10), -1), + "[PHONENUMBER]", address, -1) + + resp := s.performHTTPRequest("DELETE", s.instanceURL + fixedEndpoint, nil) + if resp == nil { + log.Println("DoDeleteMessageCall: unable to performHTTPRequest") + return nil + } + + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + log.Printf("DoDeleteMessageCall: status code %d != 200\n", resp.StatusCode) + return nil + } + + smsResp := &SmsDeleteResponse{} + if err := json.NewDecoder(resp.Body).Decode(&smsResp.Body); err != nil { + s.lastError = err.Error() + log.Printf("DoDeleteMessageCall: Unable to decode JSON response from server. Error was: %s\n", err) + return nil + } + + return smsResp +} diff --git a/smshttpresponses.go b/smshttpresponses.go index f82d476..6d93b60 100644 --- a/smshttpresponses.go +++ b/smshttpresponses.go @@ -75,9 +75,17 @@ type SmsIDListResponse struct { } type SmsMessage struct { + Id int `json:"id"` + NcId int `json:"nc_id"` Address string `json:"address"` Mailbox int `json:"mailbox"` Message string `json:"msg"` + Sent int `json:"sent"` + CardNumber string `json:"card_number"` + CardSlot int `json:"card_slot"` + IccId string `json:"icc_id"` + DeviceName string `json:"device_name"` + CarrierName string `json:"carrier_name"` Type int `json:"type"` Date int64 `json:"omit"`// This attribute is only used on transformation } @@ -125,4 +133,30 @@ func (smr *SmsMessagesResponse) GetNextMessage() *SmsMessage { res := &smr.messages[smr.cursor] smr.cursor++ return res -} \ No newline at end of file +} + + +// SmsDeleteResponse delete response +// swagger:response SmsDeleteResponse +type SmsDeleteResponse struct { + // in: body + Body struct { + // Status + // required: true + Status bool `json:"status"` + + // Message + // required: true + Message string `json:"msg"` + } +} + +// Return response status +func (spr *SmsDeleteResponse) GetStatus() bool { + return spr.Body.Status +} + +// Returns response message +func (spr *SmsDeleteResponse) GetMessage() string { + return spr.Body.Message +} -- GitLab