Merge lp:~sergiusens/nuntium/1330917 into lp:nuntium

Proposed by Sergio Schvezov
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 45
Merged at revision: 43
Proposed branch: lp:~sergiusens/nuntium/1330917
Merge into: lp:nuntium
Diff against target: 303 lines (+178/-18)
7 files modified
debian/rules (+8/-0)
mms/contenttype.go (+3/-3)
mms/decoder.go (+9/-11)
mms/mms.go (+7/-1)
ofono/push.go (+3/-2)
ofono/push_decode_test.go (+146/-0)
ofono/pushagent.go (+2/-1)
To merge this branch: bzr merge lp:~sergiusens/nuntium/1330917
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
Review via email: mp+223640@code.launchpad.net

Commit message

Decoding well known media types in the push notification.

To post a comment you must log in.
Revision history for this message
Martti Piirainen (piiramar) wrote :

Tested the fix in mako - works fine now.

Setting HeaderLength to 7
ContentType: application/vnd.wap.mms-message
Setting ApplicationId to 4
Setting TransactionId to A2iBdUt4k7QDnp1Xk
Setting Version to 0x12 == 18
Setting From to +358407694484/TYPE=PLMN
Setting DeliveryReport to 0x81 == 129
Setting Class to 0x80 == 128
Setting Size to 296192
Expiry token: 81
Message Expiry 197620, 7f
Setting ContentLocation to http://mmsc51:10021/mmsc/5_1?A2iBdUt4k7QDnp1Xk
2014/06/19 04:03:59 Context type: internet MessageCenter: MessageProxy: Active
: true
2014/06/19 04:03:59 Context type: mms MessageCenter: http://mms.sonera.fi:8002 M
essageProxy: 195.156.25.33:80 Active: false
2014/06/19 04:04:10 Starting download

lp:~sergiusens/nuntium/1330917 updated
44. By Sergio Schvezov

Fixing introduced errors while decoding media type

45. By Sergio Schvezov

Fixing typos

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Looks good.

review: Approve
lp:~sergiusens/nuntium/1330917 updated
46. By Sergio Schvezov

Fix test to not decode twice

47. By Sergio Schvezov

Not running tests on powerpc, the runners panic

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/rules'
--- debian/rules 2014-05-08 10:19:46 +0000
+++ debian/rules 2014-06-21 19:40:20 +0000
@@ -4,12 +4,20 @@
4export DH_OPTIONS4export DH_OPTIONS
5export DH_GOPKG := launchpad.net/nuntium5export DH_GOPKG := launchpad.net/nuntium
66
7DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
8
7%:9%:
8 dh $@ \10 dh $@ \
9 --buildsystem=golang \11 --buildsystem=golang \
10 --with=golang \12 --with=golang \
11 --fail-missing13 --fail-missing
1214
15override_dh_auto_test:
16# The test runners panic when running on powerpc64.
17ifneq ($(DEB_HOST_ARCH),powerpc)
18 dh_auto_test
19endif
20
13override_dh_auto_install:21override_dh_auto_install:
14 dh_auto_install -O--buildsystem=golang22 dh_auto_install -O--buildsystem=golang
15 mv ${CURDIR}/debian/tmp/usr/bin/decode-cli \23 mv ${CURDIR}/debian/tmp/usr/bin/decode-cli \
1624
=== modified file 'mms/contenttype.go'
--- mms/contenttype.go 2014-05-29 12:41:27 +0000
+++ mms/contenttype.go 2014-06-21 19:40:20 +0000
@@ -135,9 +135,9 @@
135 }135 }
136 // These call the same function136 // These call the same function
137 if next := dec.Data[dec.Offset+1]; next&SHORT_FILTER != 0 {137 if next := dec.Data[dec.Offset+1]; next&SHORT_FILTER != 0 {
138 return dec.ReadMediaType(ctMember)138 return dec.ReadMediaType(ctMember, "MediaType")
139 } else if next >= TEXT_MIN && next <= TEXT_MAX {139 } else if next >= TEXT_MIN && next <= TEXT_MAX {
140 return dec.ReadMediaType(ctMember)140 return dec.ReadMediaType(ctMember, "MediaType")
141 }141 }
142142
143 var err error143 var err error
@@ -148,7 +148,7 @@
148 fmt.Println("Content Type Length:", length)148 fmt.Println("Content Type Length:", length)
149 endOffset := int(length) + dec.Offset149 endOffset := int(length) + dec.Offset
150150
151 if err := dec.ReadMediaType(ctMember); err != nil {151 if err := dec.ReadMediaType(ctMember, "MediaType"); err != nil {
152 return err152 return err
153 }153 }
154154
155155
=== modified file 'mms/decoder.go'
--- mms/decoder.go 2014-05-09 18:30:00 +0000
+++ mms/decoder.go 2014-06-21 19:40:20 +0000
@@ -117,23 +117,21 @@
117117
118}118}
119119
120func (dec *MMSDecoder) ReadMediaType(reflectedPdu *reflect.Value) (err error) {120func (dec *MMSDecoder) ReadMediaType(reflectedPdu *reflect.Value, hdr string) (err error) {
121 var mediaType string121 var mediaType string
122 origOffset := dec.Offset122 origOffset := dec.Offset
123123 if dec.Data[dec.Offset+1] >= TEXT_MIN && dec.Data[dec.Offset+1] <= TEXT_MAX {
124 if mt, err := dec.ReadInteger(nil, ""); err == nil && len(CONTENT_TYPES) > int(mt) {124 if mediaType, err = dec.ReadString(nil, ""); err != nil {
125 return err
126 }
127 } else if mt, err := dec.ReadInteger(nil, ""); err == nil && len(CONTENT_TYPES) > int(mt) {
125 mediaType = CONTENT_TYPES[mt]128 mediaType = CONTENT_TYPES[mt]
126 } else {129 } else {
127 err = nil130 return fmt.Errorf("cannot decode media type for field beginning with %#x@%d", dec.Data[origOffset], origOffset)
128 dec.Offset = origOffset
129 mediaType, err = dec.ReadString(nil, "")
130 if err != nil {
131 return err
132 }
133 }131 }
134132
135 reflectedPdu.FieldByName("MediaType").SetString(mediaType)133 reflectedPdu.FieldByName(hdr).SetString(mediaType)
136 fmt.Println("Media Type:", mediaType)134 fmt.Print(hdr, ": ", mediaType, "\n")
137 return nil135 return nil
138}136}
139137
140138
=== modified file 'mms/mms.go'
--- mms/mms.go 2014-05-07 13:22:18 +0000
+++ mms/mms.go 2014-06-21 19:40:20 +0000
@@ -26,7 +26,7 @@
26 "os"26 "os"
27)27)
2828
29// MMS Field names from OMA-WAP-MMS section 7.329// MMS Field names from OMA-WAP-MMS section 7.3 Table 12
30const (30const (
31 BCC = 0x0131 BCC = 0x01
32 CC = 0x0232 CC = 0x02
@@ -63,6 +63,12 @@
63 X_MMS_PREVIOUSLY_SENT_DATE = 0x2163 X_MMS_PREVIOUSLY_SENT_DATE = 0x21
64)64)
6565
66// MMS Content Type Assignments OMA-WAP-MMS section 7.3 Table 13
67const (
68 PUSH_APPLICATION_ID = 4
69 VND_WAP_MMS_MESSAGE = "application/vnd.wap.mms-message"
70)
71
66const (72const (
67 TYPE_SEND_REQ = 0x8073 TYPE_SEND_REQ = 0x80
68 TYPE_SEND_CONF = 0x8174 TYPE_SEND_CONF = 0x81
6975
=== modified file 'ofono/push.go'
--- ofono/push.go 2014-04-24 21:33:38 +0000
+++ ofono/push.go 2014-06-21 19:40:20 +0000
@@ -66,11 +66,12 @@
66 if _, err = dec.ReadUintVar(&rValue, "HeaderLength"); err != nil {66 if _, err = dec.ReadUintVar(&rValue, "HeaderLength"); err != nil {
67 return err67 return err
68 }68 }
69 if _, err = dec.ReadString(&rValue, "ContentType"); err != nil {69 if err = dec.ReadMediaType(&rValue, "ContentType"); err != nil {
70 return err70 return err
71 }71 }
72 dec.Offset++72 dec.Offset++
73 if err = dec.decodeHeaders(pdu, int(pdu.HeaderLength)-(len(pdu.ContentType)+1)); err != nil {73 remainHeaders := int(pdu.HeaderLength) - dec.Offset + 3
74 if err = dec.decodeHeaders(pdu, remainHeaders); err != nil {
74 return err75 return err
75 }76 }
76 pdu.Data = dec.Data[(pdu.HeaderLength + 3):]77 pdu.Data = dec.Data[(pdu.HeaderLength + 3):]
7778
=== added file 'ofono/push_decode_test.go'
--- ofono/push_decode_test.go 1970-01-01 00:00:00 +0000
+++ ofono/push_decode_test.go 2014-06-21 19:40:20 +0000
@@ -0,0 +1,146 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Sergio Schvezov: sergio.schvezov@canonical.com
6 *
7 * This file is part of mms.
8 *
9 * mms is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 3.
12 *
13 * mms is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22package ofono
23
24import (
25 "errors"
26 "testing"
27 . "launchpad.net/gocheck"
28 "launchpad.net/nuntium/mms"
29)
30
31type PushDecodeTestSuite struct {
32 pdu *PushPDU
33}
34
35var _ = Suite(&PushDecodeTestSuite{})
36
37func Test(t *testing.T) { TestingT(t) }
38
39func (s *PushDecodeTestSuite) SetUpTest(c *C) {
40 s.pdu = new(PushPDU)
41}
42
43func (s *PushDecodeTestSuite) TestDecodeVodaphoneSpain(c *C) {
44 inputBytes := []byte{
45 0x00, 0x06, 0x26, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
46 0x6e, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x77, 0x61, 0x70, 0x2e, 0x6d, 0x6d, 0x73,
47 0x2d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00, 0xaf, 0x84, 0xb4, 0x81,
48 0x8d, 0xdf, 0x8c, 0x82, 0x98, 0x4e, 0x4f, 0x4b, 0x35, 0x43, 0x64, 0x7a, 0x30,
49 0x38, 0x42, 0x41, 0x73, 0x77, 0x61, 0x62, 0x77, 0x55, 0x48, 0x00, 0x8d, 0x90,
50 0x89, 0x18, 0x80, 0x2b, 0x33, 0x34, 0x36, 0x30, 0x30, 0x39, 0x34, 0x34, 0x34,
51 0x36, 0x33, 0x2f, 0x54, 0x59, 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e, 0x00,
52 0x8a, 0x80, 0x8e, 0x02, 0x74, 0x00, 0x88, 0x05, 0x81, 0x03, 0x02, 0xa3, 0x00,
53 0x83, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6d, 0x6d, 0x31, 0x66, 0x65,
54 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x6c, 0x65, 0x74, 0x73, 0x2f, 0x4e, 0x4f,
55 0x4b, 0x35, 0x43, 0x64, 0x7a, 0x30, 0x38, 0x42, 0x41, 0x73, 0x77, 0x61, 0x62,
56 0x77, 0x55, 0x48, 0x00,
57 }
58 dec := NewDecoder(inputBytes)
59 c.Assert(dec.Decode(s.pdu), IsNil)
60
61 c.Check(int(s.pdu.HeaderLength), Equals, 38)
62 c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID)
63 c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE)
64 c.Check(len(s.pdu.Data), Equals, 106)
65}
66
67func (s *PushDecodeTestSuite) TestDecodeTelecomPersonal(c *C) {
68 inputBytes := []byte{
69 0x01, 0x06, 0x26, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
70 0x6e, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x77, 0x61, 0x70, 0x2e, 0x6d, 0x6d, 0x73,
71 0x2d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00, 0xaf, 0x84, 0xb4, 0x86,
72 0xc3, 0x95, 0x8c, 0x82, 0x98, 0x6d, 0x30, 0x34, 0x42, 0x4b, 0x6b, 0x73, 0x69,
73 0x6d, 0x30, 0x35, 0x40, 0x6d, 0x6d, 0x73, 0x2e, 0x70, 0x65, 0x72, 0x73, 0x6f,
74 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72, 0x00, 0x8d, 0x90,
75 0x89, 0x19, 0x80, 0x2b, 0x35, 0x34, 0x33, 0x35, 0x31, 0x35, 0x39, 0x32, 0x34,
76 0x39, 0x30, 0x36, 0x2f, 0x54, 0x59, 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e,
77 0x00, 0x8a, 0x80, 0x8e, 0x02, 0x74, 0x00, 0x88, 0x05, 0x81, 0x03, 0x02, 0xa2,
78 0xff, 0x83, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x37, 0x32, 0x2e,
79 0x32, 0x35, 0x2e, 0x37, 0x2e, 0x31, 0x33, 0x31, 0x2f, 0x3f, 0x6d, 0x65, 0x73,
80 0x73, 0x61, 0x67, 0x65, 0x2d, 0x69, 0x64, 0x3d, 0x6d, 0x30, 0x34, 0x42, 0x4b,
81 0x68, 0x34, 0x33, 0x65, 0x30, 0x33, 0x00,
82 }
83 dec := NewDecoder(inputBytes)
84 c.Assert(dec.Decode(s.pdu), IsNil)
85
86 c.Check(int(s.pdu.HeaderLength), Equals, 38)
87 c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID)
88 c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE)
89 c.Check(len(s.pdu.Data), Equals, 122)
90}
91
92func (s *PushDecodeTestSuite) TestDecodeATTUSA(c *C) {
93 inputBytes := []byte{
94 0x01, 0x06, 0x27, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
95 0x6e, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x77, 0x61, 0x70, 0x2e, 0x6d, 0x6d, 0x73,
96 0x2d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00, 0xaf, 0x84, 0x8d, 0x01,
97 0x82, 0xb4, 0x84, 0x8c, 0x82, 0x98, 0x44, 0x32, 0x30, 0x34, 0x30, 0x37, 0x31,
98 0x36, 0x35, 0x36, 0x32, 0x34, 0x36, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
99 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x8d, 0x90, 0x89, 0x18, 0x80,
100 0x2b, 0x31, 0x37, 0x37, 0x34, 0x32, 0x37, 0x30, 0x30, 0x36, 0x35, 0x39, 0x2f,
101 0x54, 0x59, 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e, 0x00, 0x96, 0x02, 0xea,
102 0x00, 0x8a, 0x80, 0x8e, 0x02, 0x80, 0x00, 0x88, 0x05, 0x81, 0x03, 0x05, 0x46,
103 0x00, 0x83, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x36, 0x36, 0x2e,
104 0x32, 0x31, 0x36, 0x2e, 0x31, 0x36, 0x36, 0x2e, 0x36, 0x37, 0x3a, 0x38, 0x30,
105 0x30, 0x34, 0x2f, 0x30, 0x34, 0x30, 0x37, 0x31, 0x36, 0x35, 0x36, 0x32, 0x34,
106 0x36, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
107 0x30, 0x30, 0x00,
108 }
109 dec := NewDecoder(inputBytes)
110 c.Assert(dec.Decode(s.pdu), IsNil)
111
112 c.Check(int(s.pdu.HeaderLength), Equals, 39)
113 c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID)
114 c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE)
115 c.Check(len(s.pdu.Data), Equals, 130)
116}
117
118func (s *PushDecodeTestSuite) TestDecodeSoneraFinland(c *C) {
119 inputBytes := []byte{
120 0x00, 0x06, 0x07, 0xbe, 0xaf, 0x84, 0x8d, 0xf2, 0xb4, 0x81, 0x8c, 0x82, 0x98,
121 0x41, 0x42, 0x73, 0x54, 0x4c, 0x4e, 0x41, 0x4c, 0x41, 0x6d, 0x6d, 0x4e, 0x33,
122 0x77, 0x72, 0x38, 0x32, 0x00, 0x8d, 0x92, 0x89, 0x19, 0x80, 0x2b, 0x33, 0x35,
123 0x38, 0x34, 0x30, 0x37, 0x36, 0x39, 0x34, 0x34, 0x38, 0x34, 0x2f, 0x54, 0x59,
124 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e, 0x00, 0x86, 0x81, 0x8a, 0x80, 0x8e,
125 0x03, 0x03, 0x15, 0x85, 0x88, 0x05, 0x81, 0x03, 0x03, 0xf4, 0x7f, 0x83, 0x68,
126 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6d, 0x6d, 0x73, 0x63, 0x36, 0x31, 0x3a,
127 0x31, 0x30, 0x30, 0x32, 0x31, 0x2f, 0x6d, 0x6d, 0x73, 0x63, 0x2f, 0x36, 0x5f,
128 0x31, 0x3f, 0x41, 0x42, 0x73, 0x54, 0x4c, 0x4e, 0x41, 0x4c, 0x41, 0x6d, 0x6d,
129 0x4e, 0x33, 0x77, 0x72, 0x38, 0x32, 0x00,
130 }
131 dec := NewDecoder(inputBytes)
132 c.Assert(dec.Decode(s.pdu), IsNil)
133
134 c.Check(int(s.pdu.HeaderLength), Equals, 7)
135 c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID)
136 c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE)
137 c.Check(len(s.pdu.Data), Equals, 114)
138}
139
140func (s *PushDecodeTestSuite) TestDecodeNonPushPDU(c *C) {
141 inputBytes := []byte{
142 0x00, 0x07, 0x07, 0xbe, 0xaf, 0x84, 0x8d, 0xf2, 0xb4, 0x81, 0x8c,
143 }
144 dec := NewDecoder(inputBytes)
145 c.Assert(dec.Decode(s.pdu), DeepEquals, errors.New("7 != 6 is not a push PDU"))
146}
0147
=== modified file 'ofono/pushagent.go'
--- ofono/pushagent.go 2014-05-12 13:47:34 +0000
+++ ofono/pushagent.go 2014-06-21 19:40:20 +0000
@@ -28,6 +28,7 @@
28 "sync"28 "sync"
2929
30 "launchpad.net/go-dbus/v1"30 "launchpad.net/go-dbus/v1"
31 "launchpad.net/nuntium/mms"
31)32)
3233
33/*34/*
@@ -142,7 +143,7 @@
142 return dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error", "DecodeError")143 return dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error", "DecodeError")
143 }144 }
144 // TODO later switch on ApplicationId and ContentType to different channels145 // TODO later switch on ApplicationId and ContentType to different channels
145 if pdu.ApplicationId == 0x04 && pdu.ContentType == "application/vnd.wap.mms-message" {146 if pdu.ApplicationId == mms.PUSH_APPLICATION_ID && pdu.ContentType == mms.VND_WAP_MMS_MESSAGE {
146 agent.Push <- pdu147 agent.Push <- pdu
147 } else {148 } else {
148 log.Print("Unhandled push pdu", pdu)149 log.Print("Unhandled push pdu", pdu)

Subscribers

People subscribed via source and target branches