mkiiskila closed pull request #66: newtmgr; allow payload in CoAP DELETE
URL: https://github.com/apache/mynewt-newtmgr/pull/66
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/newtmgr/cli/res.go b/newtmgr/cli/res.go
index af9cef0..d9c4f2a 100644
--- a/newtmgr/cli/res.go
+++ b/newtmgr/cli/res.go
@@ -249,10 +249,22 @@ func resDeleteCmd(cmd *cobra.Command, args []string) {
 
        path := args[1]
 
+       var m map[string]interface{}
+       m, err = extractResKv(args[2:])
+       if err != nil {
+               nmUsage(cmd, err)
+       }
+
+       b, err := nmxutil.EncodeCborMap(m)
+       if err != nil {
+               nmUsage(nil, util.ChildNewtError(err))
+       }
+
        c := xact.NewDeleteResCmd()
        c.SetTxOptions(nmutil.TxOptions())
        c.Path = path
        c.Typ = rt
+       c.Value = b
 
        res, err := c.Run(s)
        if err != nil {
diff --git a/nmxact/nmcoap/nmcoap.go b/nmxact/nmcoap/nmcoap.go
index 117f64d..4e5386c 100644
--- a/nmxact/nmcoap/nmcoap.go
+++ b/nmxact/nmcoap/nmcoap.go
@@ -132,15 +132,18 @@ func CreatePost(isTcp bool, resUri string, token []byte,
        return m, nil
 }
 
-func CreateDelete(isTcp bool, resUri string, token []byte) (coap.Message, 
error) {
+func CreateDelete(isTcp bool, resUri string, token []byte,
+       val []byte) (coap.Message, error) {
+
        if err := validateToken(token); err != nil {
                return nil, err
        }
 
        p := coap.MessageParams{
-               Type:  coap.Confirmable,
-               Code:  coap.DELETE,
-               Token: token,
+               Type:    coap.Confirmable,
+               Code:    coap.DELETE,
+               Token:   token,
+               Payload: val,
        }
 
        m := buildMessage(isTcp, p)
diff --git a/nmxact/sesn/sesn_util.go b/nmxact/sesn/sesn_util.go
index 4bf51dd..d554682 100644
--- a/nmxact/sesn/sesn_util.go
+++ b/nmxact/sesn/sesn_util.go
@@ -102,9 +102,11 @@ func postResourceOnce(s Sesn, resType ResourceType,
 }
 
 func deleteResourceOnce(s Sesn, resType ResourceType,
-       uri string, opt TxOptions) (coap.COAPCode, []byte, error) {
+       uri string, value []byte,
+       opt TxOptions) (coap.COAPCode, []byte, error) {
 
-       req, err := nmcoap.CreateDelete(s.CoapIsTcp(), uri, nmxutil.NextToken())
+       req, err := nmcoap.CreateDelete(s.CoapIsTcp(), uri, nmxutil.NextToken(),
+               value)
        if err != nil {
                return 0, nil, err
        }
@@ -178,10 +180,10 @@ func PostResource(s Sesn, resType ResourceType, uri 
string,
 }
 
 func DeleteResource(s Sesn, resType ResourceType, uri string,
-       o TxOptions) (coap.COAPCode, []byte, error) {
+       value []byte, o TxOptions) (coap.COAPCode, []byte, error) {
 
        return txCoap(func() (coap.COAPCode, []byte, error) {
-               return deleteResourceOnce(s, resType, uri, o)
+               return deleteResourceOnce(s, resType, uri, value, o)
        }, o.Tries)
 }
 
diff --git a/nmxact/xact/res.go b/nmxact/xact/res.go
index 7285b68..dc4819f 100644
--- a/nmxact/xact/res.go
+++ b/nmxact/xact/res.go
@@ -179,6 +179,7 @@ type DeleteResCmd struct {
        CmdBase
        Path string
        Typ  sesn.ResourceType
+       Value []byte
 }
 
 func NewDeleteResCmd() *DeleteResCmd {
@@ -205,7 +206,7 @@ func (r *DeleteResResult) Status() int {
 }
 
 func (c *DeleteResCmd) Run(s sesn.Sesn) (Result, error) {
-       status, val, err := sesn.DeleteResource(s, c.Typ, c.Path, c.TxOptions())
+       status, val, err := sesn.DeleteResource(s, c.Typ, c.Path, c.Value, 
c.TxOptions())
        if err != nil {
                return nil, err
        }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to