Merge lp:~alfonsosanchezbeato/nuntium/fix-decode-crash into lp:nuntium/packaging
- fix-decode-crash
- Merge into packaging
Proposed by
Alfonso Sanchez-Beato
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Manuel de la Peña | ||||||||
Approved revision: | 99 | ||||||||
Merged at revision: | 99 | ||||||||
Proposed branch: | lp:~alfonsosanchezbeato/nuntium/fix-decode-crash | ||||||||
Merge into: | lp:nuntium/packaging | ||||||||
Diff against target: |
430 lines (+156/-63) 6 files modified
cmd/nuntium/mediator.go (+31/-23) debian/changelog (+9/-0) mms/decoder.go (+72/-37) mms/mms.go (+1/-0) ofono/modem.go (+19/-3) ofono/push_decode_test.go (+24/-0) |
||||||||
To merge this branch: | bzr merge lp:~alfonsosanchezbeato/nuntium/fix-decode-crash | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Manuel de la Peña (community) | Approve | ||
Review via email: mp+261847@code.launchpad.net |
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cmd/nuntium/mediator.go' | |||
2 | --- cmd/nuntium/mediator.go 2014-11-06 05:20:46 +0000 | |||
3 | +++ cmd/nuntium/mediator.go 2015-06-12 13:14:10 +0000 | |||
4 | @@ -38,9 +38,7 @@ | |||
5 | 38 | modem *ofono.Modem | 38 | modem *ofono.Modem |
6 | 39 | telepathyService *telepathy.MMSService | 39 | telepathyService *telepathy.MMSService |
7 | 40 | NewMNotificationInd chan *mms.MNotificationInd | 40 | NewMNotificationInd chan *mms.MNotificationInd |
8 | 41 | NewMNotifyRespInd chan *mms.MNotifyRespInd | ||
9 | 42 | NewMSendReq chan *mms.MSendReq | 41 | NewMSendReq chan *mms.MSendReq |
10 | 43 | NewMNotifyRespIndFile chan string | ||
11 | 44 | NewMSendReqFile chan struct{ filePath, uuid string } | 42 | NewMSendReqFile chan struct{ filePath, uuid string } |
12 | 45 | outMessage chan *telepathy.OutgoingMessage | 43 | outMessage chan *telepathy.OutgoingMessage |
13 | 46 | terminate chan bool | 44 | terminate chan bool |
14 | @@ -58,8 +56,6 @@ | |||
15 | 58 | func NewMediator(modem *ofono.Modem) *Mediator { | 56 | func NewMediator(modem *ofono.Modem) *Mediator { |
16 | 59 | mediator := &Mediator{modem: modem} | 57 | mediator := &Mediator{modem: modem} |
17 | 60 | mediator.NewMNotificationInd = make(chan *mms.MNotificationInd) | 58 | mediator.NewMNotificationInd = make(chan *mms.MNotificationInd) |
18 | 61 | mediator.NewMNotifyRespInd = make(chan *mms.MNotifyRespInd) | ||
19 | 62 | mediator.NewMNotifyRespIndFile = make(chan string) | ||
20 | 63 | mediator.NewMSendReq = make(chan *mms.MSendReq) | 59 | mediator.NewMSendReq = make(chan *mms.MSendReq) |
21 | 64 | mediator.NewMSendReqFile = make(chan struct{ filePath, uuid string }) | 60 | mediator.NewMSendReqFile = make(chan struct{ filePath, uuid string }) |
22 | 65 | mediator.outMessage = make(chan *telepathy.OutgoingMessage) | 61 | mediator.outMessage = make(chan *telepathy.OutgoingMessage) |
23 | @@ -87,10 +83,6 @@ | |||
24 | 87 | } else { | 83 | } else { |
25 | 88 | go mediator.getMRetrieveConf(mNotificationInd) | 84 | go mediator.getMRetrieveConf(mNotificationInd) |
26 | 89 | } | 85 | } |
27 | 90 | case mNotifyRespInd := <-mediator.NewMNotifyRespInd: | ||
28 | 91 | go mediator.handleMNotifyRespInd(mNotifyRespInd) | ||
29 | 92 | case mNotifyRespIndFilePath := <-mediator.NewMNotifyRespIndFile: | ||
30 | 93 | go mediator.sendMNotifyRespInd(mNotifyRespIndFilePath) | ||
31 | 94 | case msg := <-mediator.outMessage: | 86 | case msg := <-mediator.outMessage: |
32 | 95 | go mediator.handleOutgoingMessage(msg) | 87 | go mediator.handleOutgoingMessage(msg) |
33 | 96 | case mSendReq := <-mediator.NewMSendReq: | 88 | case mSendReq := <-mediator.NewMSendReq: |
34 | @@ -126,8 +118,6 @@ | |||
35 | 126 | close(mediator.NewMNotificationInd) | 118 | close(mediator.NewMNotificationInd) |
36 | 127 | close(mediator.NewMRetrieveConf) | 119 | close(mediator.NewMRetrieveConf) |
37 | 128 | close(mediator.NewMRetrieveConfFile) | 120 | close(mediator.NewMRetrieveConfFile) |
38 | 129 | close(mediator.NewMNotifyRespInd) | ||
39 | 130 | close(mediator.NewMNotifyRespIndFile) | ||
40 | 131 | close(mediator.NewMSendReq) | 121 | close(mediator.NewMSendReq) |
41 | 132 | close(mediator.NewMSendReqFile) | 122 | close(mediator.NewMSendReqFile) |
42 | 133 | */ | 123 | */ |
43 | @@ -163,12 +153,14 @@ | |||
44 | 163 | defer mediator.contextLock.Unlock() | 153 | defer mediator.contextLock.Unlock() |
45 | 164 | 154 | ||
46 | 165 | var proxy ofono.ProxyInfo | 155 | var proxy ofono.ProxyInfo |
47 | 156 | var mmsContext ofono.OfonoContext | ||
48 | 166 | 157 | ||
49 | 167 | if mNotificationInd.IsLocal() { | 158 | if mNotificationInd.IsLocal() { |
50 | 168 | log.Print("This is a local test, skipping context activation and proxy settings") | 159 | log.Print("This is a local test, skipping context activation and proxy settings") |
51 | 169 | } else { | 160 | } else { |
52 | 161 | var err error | ||
53 | 170 | preferredContext, _ := mediator.telepathyService.GetPreferredContext() | 162 | preferredContext, _ := mediator.telepathyService.GetPreferredContext() |
55 | 171 | mmsContext, err := mediator.modem.ActivateMMSContext(preferredContext) | 163 | mmsContext, err = mediator.modem.ActivateMMSContext(preferredContext) |
56 | 172 | if err != nil { | 164 | if err != nil { |
57 | 173 | log.Print("Cannot activate ofono context: ", err) | 165 | log.Print("Cannot activate ofono context: ", err) |
58 | 174 | return | 166 | return |
59 | @@ -210,7 +202,12 @@ | |||
60 | 210 | } | 202 | } |
61 | 211 | 203 | ||
62 | 212 | if !mNotificationInd.IsLocal() { | 204 | if !mNotificationInd.IsLocal() { |
64 | 213 | mediator.NewMNotifyRespInd <- mNotifyRespInd | 205 | // TODO deferred case |
65 | 206 | filePath := mediator.handleMNotifyRespInd(mNotifyRespInd) | ||
66 | 207 | if filePath == "" { | ||
67 | 208 | return | ||
68 | 209 | } | ||
69 | 210 | mediator.sendMNotifyRespInd(filePath, &mmsContext) | ||
70 | 214 | } else { | 211 | } else { |
71 | 215 | log.Print("This is a local test, skipping m-notifyresp.ind") | 212 | log.Print("This is a local test, skipping m-notifyresp.ind") |
72 | 216 | } | 213 | } |
73 | @@ -246,36 +243,47 @@ | |||
74 | 246 | return mRetrieveConf, nil | 243 | return mRetrieveConf, nil |
75 | 247 | } | 244 | } |
76 | 248 | 245 | ||
78 | 249 | func (mediator *Mediator) handleMNotifyRespInd(mNotifyRespInd *mms.MNotifyRespInd) { | 246 | func (mediator *Mediator) handleMNotifyRespInd(mNotifyRespInd *mms.MNotifyRespInd) string { |
79 | 250 | f, err := storage.CreateResponseFile(mNotifyRespInd.UUID) | 247 | f, err := storage.CreateResponseFile(mNotifyRespInd.UUID) |
80 | 251 | if err != nil { | 248 | if err != nil { |
81 | 252 | log.Print("Unable to create m-notifyresp.ind file for ", mNotifyRespInd.UUID) | 249 | log.Print("Unable to create m-notifyresp.ind file for ", mNotifyRespInd.UUID) |
83 | 253 | return | 250 | return "" |
84 | 254 | } | 251 | } |
85 | 255 | enc := mms.NewEncoder(f) | 252 | enc := mms.NewEncoder(f) |
86 | 256 | if err := enc.Encode(mNotifyRespInd); err != nil { | 253 | if err := enc.Encode(mNotifyRespInd); err != nil { |
87 | 257 | log.Print("Unable to encode m-notifyresp.ind for ", mNotifyRespInd.UUID) | 254 | log.Print("Unable to encode m-notifyresp.ind for ", mNotifyRespInd.UUID) |
88 | 258 | f.Close() | 255 | f.Close() |
90 | 259 | return | 256 | return "" |
91 | 260 | } | 257 | } |
92 | 261 | filePath := f.Name() | 258 | filePath := f.Name() |
93 | 262 | if err := f.Sync(); err != nil { | 259 | if err := f.Sync(); err != nil { |
94 | 263 | log.Print("Error while syncing", f.Name(), ": ", err) | 260 | log.Print("Error while syncing", f.Name(), ": ", err) |
96 | 264 | return | 261 | return "" |
97 | 265 | } | 262 | } |
98 | 266 | if err := f.Close(); err != nil { | 263 | if err := f.Close(); err != nil { |
99 | 267 | log.Print("Error while closing", f.Name(), ": ", err) | 264 | log.Print("Error while closing", f.Name(), ": ", err) |
101 | 268 | return | 265 | return "" |
102 | 269 | } | 266 | } |
103 | 270 | log.Printf("Created %s to handle m-notifyresp.ind for %s", filePath, mNotifyRespInd.UUID) | 267 | log.Printf("Created %s to handle m-notifyresp.ind for %s", filePath, mNotifyRespInd.UUID) |
105 | 271 | mediator.NewMNotifyRespIndFile <- filePath | 268 | return filePath |
106 | 272 | } | 269 | } |
107 | 273 | 270 | ||
113 | 274 | func (mediator *Mediator) sendMNotifyRespInd(mNotifyRespIndFile string) { | 271 | func (mediator *Mediator) sendMNotifyRespInd(filePath string, mmsContext *ofono.OfonoContext) { |
114 | 275 | defer os.Remove(mNotifyRespIndFile) | 272 | defer os.Remove(filePath) |
115 | 276 | 273 | ||
116 | 277 | if _, err := mediator.uploadFile(mNotifyRespIndFile); err != nil { | 274 | proxy, err := mmsContext.GetProxy() |
117 | 278 | log.Printf("Cannot upload m-notifyresp.ind encoded file %s to message center: %s", mNotifyRespIndFile, err) | 275 | if err != nil { |
118 | 276 | log.Println("Cannot retrieve MMS proxy setting", err) | ||
119 | 277 | return | ||
120 | 278 | } | ||
121 | 279 | msc, err := mmsContext.GetMessageCenter() | ||
122 | 280 | if err != nil { | ||
123 | 281 | log.Println("Cannot retrieve MMSC setting", err) | ||
124 | 282 | return | ||
125 | 283 | } | ||
126 | 284 | |||
127 | 285 | if _, err := mms.Upload(filePath, msc, proxy.Host, int32(proxy.Port)); err != nil { | ||
128 | 286 | log.Printf("Cannot upload m-notifyresp.ind encoded file %s to message center: %s", filePath, err) | ||
129 | 279 | } | 287 | } |
130 | 280 | } | 288 | } |
131 | 281 | 289 | ||
132 | 282 | 290 | ||
133 | === modified file 'debian/changelog' | |||
134 | --- debian/changelog 2015-06-04 12:49:28 +0000 | |||
135 | +++ debian/changelog 2015-06-12 13:14:10 +0000 | |||
136 | @@ -1,3 +1,12 @@ | |||
137 | 1 | nuntium (1.4+15.10.20150612-0ubuntu1) UNRELEASED; urgency=medium | ||
138 | 2 | |||
139 | 3 | * Fix LP: #1461107 and make PDU decoding more robust | ||
140 | 4 | * Fix LP: #1460012 (context opened twice on rx) | ||
141 | 5 | * Wait between retries when opening an IP context | ||
142 | 6 | * Set ofono's Preferred property when a context is known to work | ||
143 | 7 | |||
144 | 8 | -- Alfonso Sanchez-Beato (email Canonical) <alfonso.sanchez-beato@canonical.com> Fri, 12 Jun 2015 14:38:53 +0200 | ||
145 | 9 | |||
146 | 1 | nuntium (1.4+15.10.20150604-0ubuntu1) wily; urgency=medium | 10 | nuntium (1.4+15.10.20150604-0ubuntu1) wily; urgency=medium |
147 | 2 | 11 | ||
148 | 3 | [ Alfonso Sanchez-Beato (email Canonical) ] | 12 | [ Alfonso Sanchez-Beato (email Canonical) ] |
149 | 4 | 13 | ||
150 | === modified file 'mms/decoder.go' | |||
151 | --- mms/decoder.go 2015-06-01 06:38:12 +0000 | |||
152 | +++ mms/decoder.go 2015-06-12 13:14:10 +0000 | |||
153 | @@ -23,6 +23,7 @@ | |||
154 | 23 | 23 | ||
155 | 24 | import ( | 24 | import ( |
156 | 25 | "fmt" | 25 | "fmt" |
157 | 26 | "log" | ||
158 | 26 | "reflect" | 27 | "reflect" |
159 | 27 | ) | 28 | ) |
160 | 28 | 29 | ||
161 | @@ -36,6 +37,24 @@ | |||
162 | 36 | log string | 37 | log string |
163 | 37 | } | 38 | } |
164 | 38 | 39 | ||
165 | 40 | func (dec *MMSDecoder) setPduField(pdu *reflect.Value, name string, v interface{}, | ||
166 | 41 | setter func(*reflect.Value, interface{})) { | ||
167 | 42 | |||
168 | 43 | if name != "" { | ||
169 | 44 | field := pdu.FieldByName(name) | ||
170 | 45 | if field.IsValid() { | ||
171 | 46 | setter(&field, v) | ||
172 | 47 | dec.log = dec.log + fmt.Sprintf("Setting %s to %s\n", name, v) | ||
173 | 48 | } else { | ||
174 | 49 | log.Println("Field", name, "not in decoding structure") | ||
175 | 50 | } | ||
176 | 51 | } | ||
177 | 52 | } | ||
178 | 53 | |||
179 | 54 | func setterString(field *reflect.Value, v interface{}) { field.SetString(v.(string)) } | ||
180 | 55 | func setterUint64(field *reflect.Value, v interface{}) { field.SetUint(v.(uint64)) } | ||
181 | 56 | func setterSlice(field *reflect.Value, v interface{}) { field.SetBytes(v.([]byte)) } | ||
182 | 57 | |||
183 | 39 | func (dec *MMSDecoder) ReadEncodedString(reflectedPdu *reflect.Value, hdr string) (string, error) { | 58 | func (dec *MMSDecoder) ReadEncodedString(reflectedPdu *reflect.Value, hdr string) (string, error) { |
184 | 40 | var length uint64 | 59 | var length uint64 |
185 | 41 | var err error | 60 | var err error |
186 | @@ -192,10 +211,8 @@ | |||
187 | 192 | return "", fmt.Errorf("reached end of data while trying to read string: %s", dec.Data[begin:]) | 211 | return "", fmt.Errorf("reached end of data while trying to read string: %s", dec.Data[begin:]) |
188 | 193 | } | 212 | } |
189 | 194 | v := string(dec.Data[begin:dec.Offset]) | 213 | v := string(dec.Data[begin:dec.Offset]) |
194 | 195 | if hdr != "" { | 214 | dec.setPduField(reflectedPdu, hdr, v, setterString) |
195 | 196 | reflectedPdu.FieldByName(hdr).SetString(v) | 215 | |
192 | 197 | dec.log = dec.log + fmt.Sprintf("Setting %s to %s\n", hdr, v) | ||
193 | 198 | } | ||
196 | 199 | return v, nil | 216 | return v, nil |
197 | 200 | } | 217 | } |
198 | 201 | 218 | ||
199 | @@ -208,39 +225,24 @@ | |||
200 | 208 | } | 225 | } |
201 | 209 | */ | 226 | */ |
202 | 210 | v := dec.Data[dec.Offset] & 0x7F | 227 | v := dec.Data[dec.Offset] & 0x7F |
207 | 211 | if hdr != "" { | 228 | dec.setPduField(reflectedPdu, hdr, uint64(v), setterUint64) |
208 | 212 | reflectedPdu.FieldByName(hdr).SetUint(uint64(v)) | 229 | |
205 | 213 | dec.log = dec.log + fmt.Sprintf("Setting %s to %#x == %d\n", hdr, v, v) | ||
206 | 214 | } | ||
209 | 215 | return v, nil | 230 | return v, nil |
210 | 216 | } | 231 | } |
211 | 217 | 232 | ||
212 | 218 | func (dec *MMSDecoder) ReadByte(reflectedPdu *reflect.Value, hdr string) (byte, error) { | 233 | func (dec *MMSDecoder) ReadByte(reflectedPdu *reflect.Value, hdr string) (byte, error) { |
213 | 219 | dec.Offset++ | 234 | dec.Offset++ |
214 | 220 | v := dec.Data[dec.Offset] | 235 | v := dec.Data[dec.Offset] |
221 | 221 | if hdr != "" { | 236 | dec.setPduField(reflectedPdu, hdr, uint64(v), setterUint64) |
216 | 222 | reflectedPdu.FieldByName(hdr).SetUint(uint64(v)) | ||
217 | 223 | dec.log = dec.log + fmt.Sprintf("Setting %s to %#x == %d\n", hdr, v, v) | ||
218 | 224 | } | ||
219 | 225 | return v, nil | ||
220 | 226 | } | ||
222 | 227 | 237 | ||
223 | 228 | func (dec *MMSDecoder) ReadBytes(reflectedPdu *reflect.Value, hdr string) ([]byte, error) { | ||
224 | 229 | dec.Offset++ | ||
225 | 230 | v := []byte(dec.Data[dec.Offset:]) | ||
226 | 231 | if hdr != "" { | ||
227 | 232 | reflectedPdu.FieldByName(hdr).SetBytes(v) | ||
228 | 233 | dec.log = dec.log + fmt.Sprintf("Setting %s to %#x == %d\n", hdr, v, v) | ||
229 | 234 | } | ||
230 | 235 | return v, nil | 238 | return v, nil |
231 | 236 | } | 239 | } |
232 | 237 | 240 | ||
233 | 238 | func (dec *MMSDecoder) ReadBoundedBytes(reflectedPdu *reflect.Value, hdr string, end int) ([]byte, error) { | 241 | func (dec *MMSDecoder) ReadBoundedBytes(reflectedPdu *reflect.Value, hdr string, end int) ([]byte, error) { |
234 | 239 | v := []byte(dec.Data[dec.Offset:end]) | 242 | v := []byte(dec.Data[dec.Offset:end]) |
238 | 240 | if hdr != "" { | 243 | dec.setPduField(reflectedPdu, hdr, v, setterSlice) |
236 | 241 | reflectedPdu.FieldByName(hdr).SetBytes(v) | ||
237 | 242 | } | ||
239 | 243 | dec.Offset = end - 1 | 244 | dec.Offset = end - 1 |
240 | 245 | |||
241 | 244 | return v, nil | 246 | return v, nil |
242 | 245 | } | 247 | } |
243 | 246 | 248 | ||
244 | @@ -257,10 +259,8 @@ | |||
245 | 257 | 259 | ||
246 | 258 | value = value << 7 | 260 | value = value << 7 |
247 | 259 | value |= uint64(dec.Data[dec.Offset] & 0x7F) | 261 | value |= uint64(dec.Data[dec.Offset] & 0x7F) |
252 | 260 | if hdr != "" { | 262 | dec.setPduField(reflectedPdu, hdr, value, setterUint64) |
253 | 261 | reflectedPdu.FieldByName(hdr).SetUint(value) | 263 | |
250 | 262 | dec.log = dec.log + fmt.Sprintf("Setting %s to %d\n", hdr, value) | ||
251 | 263 | } | ||
254 | 264 | return value, nil | 264 | return value, nil |
255 | 265 | } | 265 | } |
256 | 266 | 266 | ||
257 | @@ -276,10 +276,8 @@ | |||
258 | 276 | default: | 276 | default: |
259 | 277 | v, err = dec.ReadLongInteger(nil, "") | 277 | v, err = dec.ReadLongInteger(nil, "") |
260 | 278 | } | 278 | } |
265 | 279 | if hdr != "" { | 279 | dec.setPduField(reflectedPdu, hdr, v, setterUint64) |
266 | 280 | reflectedPdu.FieldByName(hdr).SetUint(v) | 280 | |
263 | 281 | dec.log = dec.log + fmt.Sprintf("Setting %s to %d\n", hdr, v) | ||
264 | 282 | } | ||
267 | 283 | return v, err | 281 | return v, err |
268 | 284 | } | 282 | } |
269 | 285 | 283 | ||
270 | @@ -297,10 +295,8 @@ | |||
271 | 297 | v |= uint64(dec.Data[dec.Offset]) | 295 | v |= uint64(dec.Data[dec.Offset]) |
272 | 298 | } | 296 | } |
273 | 299 | dec.Offset-- | 297 | dec.Offset-- |
278 | 300 | if hdr != "" { | 298 | dec.setPduField(reflectedPdu, hdr, v, setterUint64) |
279 | 301 | reflectedPdu.FieldByName(hdr).SetUint(uint64(v)) | 299 | |
276 | 302 | dec.log = dec.log + fmt.Sprintf("Setting %s to %d\n", hdr, v) | ||
277 | 303 | } | ||
280 | 304 | return v, nil | 300 | return v, nil |
281 | 305 | } | 301 | } |
282 | 306 | 302 | ||
283 | @@ -327,6 +323,44 @@ | |||
284 | 327 | } | 323 | } |
285 | 328 | } | 324 | } |
286 | 329 | 325 | ||
287 | 326 | func (dec *MMSDecoder) skipFieldValue() error { | ||
288 | 327 | switch { | ||
289 | 328 | case dec.Data[dec.Offset+1] < LENGTH_QUOTE: | ||
290 | 329 | l, err := dec.ReadByte(nil, "") | ||
291 | 330 | if err != nil { | ||
292 | 331 | return err | ||
293 | 332 | } | ||
294 | 333 | length := int(l) | ||
295 | 334 | if dec.Offset+length >= len(dec.Data) { | ||
296 | 335 | return fmt.Errorf("Bad field value length") | ||
297 | 336 | } | ||
298 | 337 | dec.Offset += length | ||
299 | 338 | return nil | ||
300 | 339 | case dec.Data[dec.Offset+1] == LENGTH_QUOTE: | ||
301 | 340 | dec.Offset++ | ||
302 | 341 | // TODO These tests should be done in basic read functions | ||
303 | 342 | if dec.Offset+1 >= len(dec.Data) { | ||
304 | 343 | return fmt.Errorf("Bad uintvar") | ||
305 | 344 | } | ||
306 | 345 | l, err := dec.ReadUintVar(nil, "") | ||
307 | 346 | if err != nil { | ||
308 | 347 | return err | ||
309 | 348 | } | ||
310 | 349 | length := int(l) | ||
311 | 350 | if dec.Offset+length >= len(dec.Data) { | ||
312 | 351 | return fmt.Errorf("Bad field value length") | ||
313 | 352 | } | ||
314 | 353 | dec.Offset += length | ||
315 | 354 | return nil | ||
316 | 355 | case dec.Data[dec.Offset+1] <= TEXT_MAX: | ||
317 | 356 | _, err := dec.ReadString(nil, "") | ||
318 | 357 | return err | ||
319 | 358 | } | ||
320 | 359 | // case dec.Data[dec.Offset + 1] > TEXT_MAX | ||
321 | 360 | _, err := dec.ReadShortInteger(nil, "") | ||
322 | 361 | return err | ||
323 | 362 | } | ||
324 | 363 | |||
325 | 330 | func (dec *MMSDecoder) Decode(pdu MMSReader) (err error) { | 364 | func (dec *MMSDecoder) Decode(pdu MMSReader) (err error) { |
326 | 331 | reflectedPdu := reflect.ValueOf(pdu).Elem() | 365 | reflectedPdu := reflect.ValueOf(pdu).Elem() |
327 | 332 | moreHdrToRead := true | 366 | moreHdrToRead := true |
328 | @@ -444,7 +478,8 @@ | |||
329 | 444 | case DATE: | 478 | case DATE: |
330 | 445 | _, err = dec.ReadLongInteger(&reflectedPdu, "Date") | 479 | _, err = dec.ReadLongInteger(&reflectedPdu, "Date") |
331 | 446 | default: | 480 | default: |
333 | 447 | return fmt.Errorf("Unhandled byte: %#0x\tdec: %d\tdec.Offset: %d ... decoded so far: %s", param, param, dec.Offset) | 481 | log.Printf("Skipping unrecognized header 0x%02x", param) |
334 | 482 | err = dec.skipFieldValue() | ||
335 | 448 | } | 483 | } |
336 | 449 | if err != nil { | 484 | if err != nil { |
337 | 450 | return err | 485 | return err |
338 | 451 | 486 | ||
339 | === modified file 'mms/mms.go' | |||
340 | --- mms/mms.go 2015-01-15 15:45:48 +0000 | |||
341 | +++ mms/mms.go 2015-06-12 13:14:10 +0000 | |||
342 | @@ -224,6 +224,7 @@ | |||
343 | 224 | UUID string | 224 | UUID string |
344 | 225 | Type, Version, Class, DeliveryReport byte | 225 | Type, Version, Class, DeliveryReport byte |
345 | 226 | ReplyCharging, ReplyChargingDeadline byte | 226 | ReplyCharging, ReplyChargingDeadline byte |
346 | 227 | Priority byte | ||
347 | 227 | ReplyChargingId string | 228 | ReplyChargingId string |
348 | 228 | TransactionId, ContentLocation string | 229 | TransactionId, ContentLocation string |
349 | 229 | From, Subject string | 230 | From, Subject string |
350 | 230 | 231 | ||
351 | === modified file 'ofono/modem.go' | |||
352 | --- ofono/modem.go 2015-05-20 12:32:08 +0000 | |||
353 | +++ ofono/modem.go 2015-06-12 13:14:10 +0000 | |||
354 | @@ -40,9 +40,10 @@ | |||
355 | 40 | ) | 40 | ) |
356 | 41 | 41 | ||
357 | 42 | const ( | 42 | const ( |
360 | 43 | ofonoAttachInProgressError = "org.ofono.AttachInProgress" | 43 | ofonoAttachInProgressError = "org.ofono.Error.AttachInProgress" |
361 | 44 | ofonoInProgressError = "org.ofono.InProgress" | 44 | ofonoInProgressError = "org.ofono.Error.InProgress" |
362 | 45 | ofonoNotAttachedError = "org.ofono.Error.NotAttached" | 45 | ofonoNotAttachedError = "org.ofono.Error.NotAttached" |
363 | 46 | ofonoFailedError = "org.ofono.Error.Failed" | ||
364 | 46 | ) | 47 | ) |
365 | 47 | 48 | ||
366 | 48 | type OfonoContext struct { | 49 | type OfonoContext struct { |
367 | @@ -269,8 +270,16 @@ | |||
368 | 269 | } | 270 | } |
369 | 270 | 271 | ||
370 | 271 | func activationErrorNeedsWait(err error) bool { | 272 | func activationErrorNeedsWait(err error) bool { |
371 | 273 | // ofonoFailedError might be due to network issues or to wrong APN configuration. | ||
372 | 274 | // Retrying would not make sense for the latter, but we cannot distinguish | ||
373 | 275 | // and any possible delay retrying might cause would happen only the first time | ||
374 | 276 | // (provided we end up finding the right APN on the list so we save it as | ||
375 | 277 | // preferred). | ||
376 | 272 | if dbusErr, ok := err.(*dbus.Error); ok { | 278 | if dbusErr, ok := err.(*dbus.Error); ok { |
378 | 273 | return dbusErr.Name == ofonoInProgressError || dbusErr.Name == ofonoAttachInProgressError || dbusErr.Name == ofonoNotAttachedError | 279 | return dbusErr.Name == ofonoInProgressError || |
379 | 280 | dbusErr.Name == ofonoAttachInProgressError || | ||
380 | 281 | dbusErr.Name == ofonoNotAttachedError || | ||
381 | 282 | dbusErr.Name == ofonoFailedError | ||
382 | 274 | } | 283 | } |
383 | 275 | return false | 284 | return false |
384 | 276 | } | 285 | } |
385 | @@ -286,6 +295,13 @@ | |||
386 | 286 | time.Sleep(2 * time.Second) | 295 | time.Sleep(2 * time.Second) |
387 | 287 | } | 296 | } |
388 | 288 | } else { | 297 | } else { |
389 | 298 | // If it works we set it as preferred in ofono, provided it is not | ||
390 | 299 | // a combined context. | ||
391 | 300 | // TODO get rid of nuntium's internal preferred setting | ||
392 | 301 | if !context.isPreferred() && context.isTypeMMS() { | ||
393 | 302 | obj.Call(CONNECTION_CONTEXT_INTERFACE, "SetProperty", | ||
394 | 303 | "Preferred", dbus.Variant{true}) | ||
395 | 304 | } | ||
396 | 289 | return nil | 305 | return nil |
397 | 290 | } | 306 | } |
398 | 291 | } | 307 | } |
399 | 292 | 308 | ||
400 | === modified file 'ofono/push_decode_test.go' | |||
401 | --- ofono/push_decode_test.go 2015-05-20 12:32:08 +0000 | |||
402 | +++ ofono/push_decode_test.go 2015-06-12 13:14:10 +0000 | |||
403 | @@ -199,3 +199,27 @@ | |||
404 | 199 | c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE) | 199 | c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE) |
405 | 200 | c.Check(len(s.pdu.Data), Equals, 183) | 200 | c.Check(len(s.pdu.Data), Equals, 183) |
406 | 201 | } | 201 | } |
407 | 202 | |||
408 | 203 | func (s *PushDecodeTestSuite) TestDecodePlayPoland(c *C) { | ||
409 | 204 | inputBytes := []byte{ | ||
410 | 205 | 0x2e, 0x06, 0x22, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, | ||
411 | 206 | 0x6f, 0x6e, 0x2f, 0x76, 0x6e, 0x64, 0x2e, 0x77, 0x61, 0x70, 0x2e, 0x6d, | ||
412 | 207 | 0x6d, 0x73, 0x2d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x00, 0xaf, | ||
413 | 208 | 0x84, 0x8c, 0x82, 0x98, 0x31, 0x34, 0x34, 0x32, 0x34, 0x30, 0x31, 0x33, | ||
414 | 209 | 0x31, 0x38, 0x40, 0x6d, 0x6d, 0x73, 0x32, 0x00, 0x8d, 0x92, 0x89, 0x18, | ||
415 | 210 | 0x80, 0x2b, 0x34, 0x38, 0x38, 0x38, 0x32, 0x30, 0x34, 0x30, 0x32, 0x32, | ||
416 | 211 | 0x35, 0x2f, 0x54, 0x59, 0x50, 0x45, 0x3d, 0x50, 0x4c, 0x4d, 0x4e, 0x00, | ||
417 | 212 | 0x8f, 0x81, 0x86, 0x80, 0x8a, 0x80, 0x8e, 0x03, 0x03, 0xad, 0x21, 0x88, | ||
418 | 213 | 0x05, 0x81, 0x03, 0x03, 0xf4, 0x80, 0x83, 0x68, 0x74, 0x74, 0x70, 0x3a, | ||
419 | 214 | 0x2f, 0x2f, 0x6d, 0x6d, 0x73, 0x63, 0x2e, 0x70, 0x6c, 0x61, 0x79, 0x2e, | ||
420 | 215 | 0x70, 0x6c, 0x2f, 0x3f, 0x69, 0x64, 0x3d, 0x31, 0x34, 0x34, 0x32, 0x34, | ||
421 | 216 | 0x30, 0x31, 0x33, 0x31, 0x38, 0x42, 0x00, | ||
422 | 217 | } | ||
423 | 218 | dec := NewDecoder(inputBytes) | ||
424 | 219 | c.Assert(dec.Decode(s.pdu), IsNil) | ||
425 | 220 | |||
426 | 221 | c.Check(int(s.pdu.HeaderLength), Equals, 34) | ||
427 | 222 | c.Check(int(s.pdu.ApplicationId), Equals, mms.PUSH_APPLICATION_ID) | ||
428 | 223 | c.Check(s.pdu.ContentType, Equals, mms.VND_WAP_MMS_MESSAGE) | ||
429 | 224 | c.Check(len(s.pdu.Data), Equals, 102) | ||
430 | 225 | } |
Review was already done in github, looks good.