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
1=== modified file 'debian/rules'
2--- debian/rules 2014-05-08 10:19:46 +0000
3+++ debian/rules 2014-06-21 19:40:20 +0000
4@@ -4,12 +4,20 @@
5 export DH_OPTIONS
6 export DH_GOPKG := launchpad.net/nuntium
7
8+DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
9+
10 %:
11 dh $@ \
12 --buildsystem=golang \
13 --with=golang \
14 --fail-missing
15
16+override_dh_auto_test:
17+# The test runners panic when running on powerpc64.
18+ifneq ($(DEB_HOST_ARCH),powerpc)
19+ dh_auto_test
20+endif
21+
22 override_dh_auto_install:
23 dh_auto_install -O--buildsystem=golang
24 mv ${CURDIR}/debian/tmp/usr/bin/decode-cli \
25
26=== modified file 'mms/contenttype.go'
27--- mms/contenttype.go 2014-05-29 12:41:27 +0000
28+++ mms/contenttype.go 2014-06-21 19:40:20 +0000
29@@ -135,9 +135,9 @@
30 }
31 // These call the same function
32 if next := dec.Data[dec.Offset+1]; next&SHORT_FILTER != 0 {
33- return dec.ReadMediaType(ctMember)
34+ return dec.ReadMediaType(ctMember, "MediaType")
35 } else if next >= TEXT_MIN && next <= TEXT_MAX {
36- return dec.ReadMediaType(ctMember)
37+ return dec.ReadMediaType(ctMember, "MediaType")
38 }
39
40 var err error
41@@ -148,7 +148,7 @@
42 fmt.Println("Content Type Length:", length)
43 endOffset := int(length) + dec.Offset
44
45- if err := dec.ReadMediaType(ctMember); err != nil {
46+ if err := dec.ReadMediaType(ctMember, "MediaType"); err != nil {
47 return err
48 }
49
50
51=== modified file 'mms/decoder.go'
52--- mms/decoder.go 2014-05-09 18:30:00 +0000
53+++ mms/decoder.go 2014-06-21 19:40:20 +0000
54@@ -117,23 +117,21 @@
55
56 }
57
58-func (dec *MMSDecoder) ReadMediaType(reflectedPdu *reflect.Value) (err error) {
59+func (dec *MMSDecoder) ReadMediaType(reflectedPdu *reflect.Value, hdr string) (err error) {
60 var mediaType string
61 origOffset := dec.Offset
62-
63- if mt, err := dec.ReadInteger(nil, ""); err == nil && len(CONTENT_TYPES) > int(mt) {
64+ if dec.Data[dec.Offset+1] >= TEXT_MIN && dec.Data[dec.Offset+1] <= TEXT_MAX {
65+ if mediaType, err = dec.ReadString(nil, ""); err != nil {
66+ return err
67+ }
68+ } else if mt, err := dec.ReadInteger(nil, ""); err == nil && len(CONTENT_TYPES) > int(mt) {
69 mediaType = CONTENT_TYPES[mt]
70 } else {
71- err = nil
72- dec.Offset = origOffset
73- mediaType, err = dec.ReadString(nil, "")
74- if err != nil {
75- return err
76- }
77+ return fmt.Errorf("cannot decode media type for field beginning with %#x@%d", dec.Data[origOffset], origOffset)
78 }
79
80- reflectedPdu.FieldByName("MediaType").SetString(mediaType)
81- fmt.Println("Media Type:", mediaType)
82+ reflectedPdu.FieldByName(hdr).SetString(mediaType)
83+ fmt.Print(hdr, ": ", mediaType, "\n")
84 return nil
85 }
86
87
88=== modified file 'mms/mms.go'
89--- mms/mms.go 2014-05-07 13:22:18 +0000
90+++ mms/mms.go 2014-06-21 19:40:20 +0000
91@@ -26,7 +26,7 @@
92 "os"
93 )
94
95-// MMS Field names from OMA-WAP-MMS section 7.3
96+// MMS Field names from OMA-WAP-MMS section 7.3 Table 12
97 const (
98 BCC = 0x01
99 CC = 0x02
100@@ -63,6 +63,12 @@
101 X_MMS_PREVIOUSLY_SENT_DATE = 0x21
102 )
103
104+// MMS Content Type Assignments OMA-WAP-MMS section 7.3 Table 13
105+const (
106+ PUSH_APPLICATION_ID = 4
107+ VND_WAP_MMS_MESSAGE = "application/vnd.wap.mms-message"
108+)
109+
110 const (
111 TYPE_SEND_REQ = 0x80
112 TYPE_SEND_CONF = 0x81
113
114=== modified file 'ofono/push.go'
115--- ofono/push.go 2014-04-24 21:33:38 +0000
116+++ ofono/push.go 2014-06-21 19:40:20 +0000
117@@ -66,11 +66,12 @@
118 if _, err = dec.ReadUintVar(&rValue, "HeaderLength"); err != nil {
119 return err
120 }
121- if _, err = dec.ReadString(&rValue, "ContentType"); err != nil {
122+ if err = dec.ReadMediaType(&rValue, "ContentType"); err != nil {
123 return err
124 }
125 dec.Offset++
126- if err = dec.decodeHeaders(pdu, int(pdu.HeaderLength)-(len(pdu.ContentType)+1)); err != nil {
127+ remainHeaders := int(pdu.HeaderLength) - dec.Offset + 3
128+ if err = dec.decodeHeaders(pdu, remainHeaders); err != nil {
129 return err
130 }
131 pdu.Data = dec.Data[(pdu.HeaderLength + 3):]
132
133=== added file 'ofono/push_decode_test.go'
134--- ofono/push_decode_test.go 1970-01-01 00:00:00 +0000
135+++ ofono/push_decode_test.go 2014-06-21 19:40:20 +0000
136@@ -0,0 +1,146 @@
137+/*
138+ * Copyright 2014 Canonical Ltd.
139+ *
140+ * Authors:
141+ * Sergio Schvezov: sergio.schvezov@canonical.com
142+ *
143+ * This file is part of mms.
144+ *
145+ * mms is free software; you can redistribute it and/or modify
146+ * it under the terms of the GNU General Public License as published by
147+ * the Free Software Foundation; version 3.
148+ *
149+ * mms is distributed in the hope that it will be useful,
150+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
151+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152+ * GNU General Public License for more details.
153+ *
154+ * You should have received a copy of the GNU General Public License
155+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
156+ */
157+
158+package ofono
159+
160+import (
161+ "errors"
162+ "testing"
163+ . "launchpad.net/gocheck"
164+ "launchpad.net/nuntium/mms"
165+)
166+
167+type PushDecodeTestSuite struct {
168+ pdu *PushPDU
169+}
170+
171+var _ = Suite(&PushDecodeTestSuite{})
172+
173+func Test(t *testing.T) { TestingT(t) }
174+
175+func (s *PushDecodeTestSuite) SetUpTest(c *C) {
176+ s.pdu = new(PushPDU)
177+}
178+
179+func (s *PushDecodeTestSuite) TestDecodeVodaphoneSpain(c *C) {
180+ inputBytes := []byte{
181+ 0x00, 0x06, 0x26, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
182+ 0x6e, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x77, 0x61, 0x70, 0x2e, 0x6d, 0x6d, 0x73,
183+ 0x2d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00, 0xaf, 0x84, 0xb4, 0x81,
184+ 0x8d, 0xdf, 0x8c, 0x82, 0x98, 0x4e, 0x4f, 0x4b, 0x35, 0x43, 0x64, 0x7a, 0x30,
185+ 0x38, 0x42, 0x41, 0x73, 0x77, 0x61, 0x62, 0x77, 0x55, 0x48, 0x00, 0x8d, 0x90,
186+ 0x89, 0x18, 0x80, 0x2b, 0x33, 0x34, 0x36, 0x30, 0x30, 0x39, 0x34, 0x34, 0x34,
187+ 0x36, 0x33, 0x2f, 0x54, 0x59, 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e, 0x00,
188+ 0x8a, 0x80, 0x8e, 0x02, 0x74, 0x00, 0x88, 0x05, 0x81, 0x03, 0x02, 0xa3, 0x00,
189+ 0x83, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6d, 0x6d, 0x31, 0x66, 0x65,
190+ 0x31, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x6c, 0x65, 0x74, 0x73, 0x2f, 0x4e, 0x4f,
191+ 0x4b, 0x35, 0x43, 0x64, 0x7a, 0x30, 0x38, 0x42, 0x41, 0x73, 0x77, 0x61, 0x62,
192+ 0x77, 0x55, 0x48, 0x00,
193+ }
194+ dec := NewDecoder(inputBytes)
195+ c.Assert(dec.Decode(s.pdu), IsNil)
196+
197+ c.Check(int(s.pdu.HeaderLength), Equals, 38)
198+ c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID)
199+ c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE)
200+ c.Check(len(s.pdu.Data), Equals, 106)
201+}
202+
203+func (s *PushDecodeTestSuite) TestDecodeTelecomPersonal(c *C) {
204+ inputBytes := []byte{
205+ 0x01, 0x06, 0x26, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
206+ 0x6e, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x77, 0x61, 0x70, 0x2e, 0x6d, 0x6d, 0x73,
207+ 0x2d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00, 0xaf, 0x84, 0xb4, 0x86,
208+ 0xc3, 0x95, 0x8c, 0x82, 0x98, 0x6d, 0x30, 0x34, 0x42, 0x4b, 0x6b, 0x73, 0x69,
209+ 0x6d, 0x30, 0x35, 0x40, 0x6d, 0x6d, 0x73, 0x2e, 0x70, 0x65, 0x72, 0x73, 0x6f,
210+ 0x6e, 0x61, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x72, 0x00, 0x8d, 0x90,
211+ 0x89, 0x19, 0x80, 0x2b, 0x35, 0x34, 0x33, 0x35, 0x31, 0x35, 0x39, 0x32, 0x34,
212+ 0x39, 0x30, 0x36, 0x2f, 0x54, 0x59, 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e,
213+ 0x00, 0x8a, 0x80, 0x8e, 0x02, 0x74, 0x00, 0x88, 0x05, 0x81, 0x03, 0x02, 0xa2,
214+ 0xff, 0x83, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x37, 0x32, 0x2e,
215+ 0x32, 0x35, 0x2e, 0x37, 0x2e, 0x31, 0x33, 0x31, 0x2f, 0x3f, 0x6d, 0x65, 0x73,
216+ 0x73, 0x61, 0x67, 0x65, 0x2d, 0x69, 0x64, 0x3d, 0x6d, 0x30, 0x34, 0x42, 0x4b,
217+ 0x68, 0x34, 0x33, 0x65, 0x30, 0x33, 0x00,
218+ }
219+ dec := NewDecoder(inputBytes)
220+ c.Assert(dec.Decode(s.pdu), IsNil)
221+
222+ c.Check(int(s.pdu.HeaderLength), Equals, 38)
223+ c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID)
224+ c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE)
225+ c.Check(len(s.pdu.Data), Equals, 122)
226+}
227+
228+func (s *PushDecodeTestSuite) TestDecodeATTUSA(c *C) {
229+ inputBytes := []byte{
230+ 0x01, 0x06, 0x27, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
231+ 0x6e, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x77, 0x61, 0x70, 0x2e, 0x6d, 0x6d, 0x73,
232+ 0x2d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00, 0xaf, 0x84, 0x8d, 0x01,
233+ 0x82, 0xb4, 0x84, 0x8c, 0x82, 0x98, 0x44, 0x32, 0x30, 0x34, 0x30, 0x37, 0x31,
234+ 0x36, 0x35, 0x36, 0x32, 0x34, 0x36, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30,
235+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x8d, 0x90, 0x89, 0x18, 0x80,
236+ 0x2b, 0x31, 0x37, 0x37, 0x34, 0x32, 0x37, 0x30, 0x30, 0x36, 0x35, 0x39, 0x2f,
237+ 0x54, 0x59, 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e, 0x00, 0x96, 0x02, 0xea,
238+ 0x00, 0x8a, 0x80, 0x8e, 0x02, 0x80, 0x00, 0x88, 0x05, 0x81, 0x03, 0x05, 0x46,
239+ 0x00, 0x83, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x36, 0x36, 0x2e,
240+ 0x32, 0x31, 0x36, 0x2e, 0x31, 0x36, 0x36, 0x2e, 0x36, 0x37, 0x3a, 0x38, 0x30,
241+ 0x30, 0x34, 0x2f, 0x30, 0x34, 0x30, 0x37, 0x31, 0x36, 0x35, 0x36, 0x32, 0x34,
242+ 0x36, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
243+ 0x30, 0x30, 0x00,
244+ }
245+ dec := NewDecoder(inputBytes)
246+ c.Assert(dec.Decode(s.pdu), IsNil)
247+
248+ c.Check(int(s.pdu.HeaderLength), Equals, 39)
249+ c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID)
250+ c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE)
251+ c.Check(len(s.pdu.Data), Equals, 130)
252+}
253+
254+func (s *PushDecodeTestSuite) TestDecodeSoneraFinland(c *C) {
255+ inputBytes := []byte{
256+ 0x00, 0x06, 0x07, 0xbe, 0xaf, 0x84, 0x8d, 0xf2, 0xb4, 0x81, 0x8c, 0x82, 0x98,
257+ 0x41, 0x42, 0x73, 0x54, 0x4c, 0x4e, 0x41, 0x4c, 0x41, 0x6d, 0x6d, 0x4e, 0x33,
258+ 0x77, 0x72, 0x38, 0x32, 0x00, 0x8d, 0x92, 0x89, 0x19, 0x80, 0x2b, 0x33, 0x35,
259+ 0x38, 0x34, 0x30, 0x37, 0x36, 0x39, 0x34, 0x34, 0x38, 0x34, 0x2f, 0x54, 0x59,
260+ 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e, 0x00, 0x86, 0x81, 0x8a, 0x80, 0x8e,
261+ 0x03, 0x03, 0x15, 0x85, 0x88, 0x05, 0x81, 0x03, 0x03, 0xf4, 0x7f, 0x83, 0x68,
262+ 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6d, 0x6d, 0x73, 0x63, 0x36, 0x31, 0x3a,
263+ 0x31, 0x30, 0x30, 0x32, 0x31, 0x2f, 0x6d, 0x6d, 0x73, 0x63, 0x2f, 0x36, 0x5f,
264+ 0x31, 0x3f, 0x41, 0x42, 0x73, 0x54, 0x4c, 0x4e, 0x41, 0x4c, 0x41, 0x6d, 0x6d,
265+ 0x4e, 0x33, 0x77, 0x72, 0x38, 0x32, 0x00,
266+ }
267+ dec := NewDecoder(inputBytes)
268+ c.Assert(dec.Decode(s.pdu), IsNil)
269+
270+ c.Check(int(s.pdu.HeaderLength), Equals, 7)
271+ c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID)
272+ c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE)
273+ c.Check(len(s.pdu.Data), Equals, 114)
274+}
275+
276+func (s *PushDecodeTestSuite) TestDecodeNonPushPDU(c *C) {
277+ inputBytes := []byte{
278+ 0x00, 0x07, 0x07, 0xbe, 0xaf, 0x84, 0x8d, 0xf2, 0xb4, 0x81, 0x8c,
279+ }
280+ dec := NewDecoder(inputBytes)
281+ c.Assert(dec.Decode(s.pdu), DeepEquals, errors.New("7 != 6 is not a push PDU"))
282+}
283
284=== modified file 'ofono/pushagent.go'
285--- ofono/pushagent.go 2014-05-12 13:47:34 +0000
286+++ ofono/pushagent.go 2014-06-21 19:40:20 +0000
287@@ -28,6 +28,7 @@
288 "sync"
289
290 "launchpad.net/go-dbus/v1"
291+ "launchpad.net/nuntium/mms"
292 )
293
294 /*
295@@ -142,7 +143,7 @@
296 return dbus.NewErrorMessage(msg, "org.freedesktop.DBus.Error", "DecodeError")
297 }
298 // TODO later switch on ApplicationId and ContentType to different channels
299- if pdu.ApplicationId == 0x04 && pdu.ContentType == "application/vnd.wap.mms-message" {
300+ if pdu.ApplicationId == mms.PUSH_APPLICATION_ID && pdu.ContentType == mms.VND_WAP_MMS_MESSAGE {
301 agent.Push <- pdu
302 } else {
303 log.Print("Unhandled push pdu", pdu)

Subscribers

People subscribed via source and target branches