Merge lp:~mandel/ubuntu-download-manager/remove-username-password-update into lp:ubuntu-download-manager

Proposed by Manuel de la Peña
Status: Superseded
Proposed branch: lp:~mandel/ubuntu-download-manager/remove-username-password-update
Merge into: lp:ubuntu-download-manager
Prerequisite: lp:~mandel/ubuntu-download-manager/upload-go-bindings
Diff against target: 1835 lines (+11/-1702)
13 files modified
bindings/golang/common.go (+0/-78)
bindings/golang/common_test.go (+0/-83)
bindings/golang/downloader.go (+0/-600)
bindings/golang/downloader_test.go (+0/-306)
bindings/golang/uploader.go (+0/-396)
bindings/golang/uploader_test.go (+0/-215)
docs/com.canonical.applications.upload_manager.xml (+0/-2)
src/uploads/priv/ubuntu/uploads/factory.cpp (+2/-4)
src/uploads/priv/ubuntu/uploads/factory.h (+1/-3)
src/uploads/priv/ubuntu/uploads/manager.cpp (+4/-7)
src/uploads/priv/ubuntu/uploads/manager.h (+1/-3)
src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp (+2/-2)
src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h (+1/-3)
To merge this branch: bzr merge lp:~mandel/ubuntu-download-manager/remove-username-password-update
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu One hackers Pending
Review via email: mp+217258@code.launchpad.net

This proposal has been superseded by a proposal from 2014-05-21.

Commit message

Remove the username and password from mms uploads.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
262. By Manuel de la Peña

Merged upload-go-bindings into remove-username-password-update.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
263. By Manuel de la Peña

Merged upload-go-bindings into remove-username-password-update.

264. By Manuel de la Peña

Merged upload-go-bindings into remove-username-password-update.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
265. By Manuel de la Peña

Merged upload-go-bindings into remove-username-password-update.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
266. By Manuel de la Peña

Merged upload-go-bindings into remove-username-password-update.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
267. By Manuel de la Peña

Fix merge issues due to the removal of go.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed directory 'bindings'
=== removed directory 'bindings/golang'
=== removed file 'bindings/golang/common.go'
--- bindings/golang/common.go 2014-05-13 08:50:46 +0000
+++ bindings/golang/common.go 1970-01-01 00:00:00 +0000
@@ -1,78 +0,0 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Manuel de la Pena: manuel.delapena@canonical.com
6 *
7 * This file is part of ubuntu-download-manager.
8 *
9 * ubuntu-download-manager 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 * ubuntu-download-manager 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
22// Package udm provides a go interface to work with the ubuntu download manager
23package udm
24
25import (
26 "launchpad.net/go-dbus/v1"
27)
28
29// Progress provides how much progress has been performed in a download that was
30// already started.
31type Progress struct {
32 Received uint64
33 Total uint64
34}
35
36// internal interface used to simplify testing
37type watch interface {
38 Cancel() error
39 Chanel() chan *dbus.Message
40}
41
42// small wrapper used to simplify testing by using the watch interface
43type watchWrapper struct {
44 watch *dbus.SignalWatch
45}
46
47func newWatchWrapper(sw *dbus.SignalWatch) *watchWrapper {
48 w := watchWrapper{}
49 return &w
50}
51
52func (w *watchWrapper) Cancel() error {
53 return w.watch.Cancel()
54}
55
56func (w *watchWrapper) Chanel() chan *dbus.Message {
57 return w.watch.C
58}
59
60// interface added to simplify testing
61type proxy interface {
62 Call(iface, method string, args ...interface{}) (*dbus.Message, error)
63}
64
65var readArgs = func(msg *dbus.Message, args ...interface{}) error {
66 return msg.Args(args)
67}
68
69func connectToSignal(conn *dbus.Connection, path dbus.ObjectPath, signal string) (watch, error) {
70 sw, err := conn.WatchSignal(&dbus.MatchRule{
71 Type: dbus.TypeSignal,
72 Sender: DOWNLOAD_SERVICE,
73 Interface: DOWNLOAD_INTERFACE,
74 Member: signal,
75 Path: path})
76 w := newWatchWrapper(sw)
77 return w, err
78}
790
=== removed file 'bindings/golang/common_test.go'
--- bindings/golang/common_test.go 2014-05-13 08:50:46 +0000
+++ bindings/golang/common_test.go 1970-01-01 00:00:00 +0000
@@ -1,83 +0,0 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Manuel de la Pena: manuel.delapena@canonical.com
6 *
7 * This file is part of ubuntu-download-manager.
8 *
9 * ubuntu-download-manager 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 * ubuntu-download-manager 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 udm
23
24import (
25 . "gopkg.in/check.v1"
26 "launchpad.net/go-dbus/v1"
27 "testing"
28)
29
30func Test(t *testing.T) { TestingT(t) }
31
32type fakeProxy struct {
33 Interface string
34 MethodName string
35 Args []interface{}
36 Err error
37 Result *dbus.Message
38}
39
40func (f *fakeProxy) Call(iface, method string, args ...interface{}) (*dbus.Message, error) {
41 // store the called method and return Result
42 f.Interface = iface
43 f.MethodName = method
44 f.Args = args
45 if f.Err == nil {
46 return f.Result, nil
47 }
48 return nil, f.Err
49}
50
51type FakeWatch struct {
52 Canceled bool
53 Ch chan *dbus.Message
54}
55
56func newFakeWatch() *FakeWatch {
57 ch := make(chan *dbus.Message)
58 fw := FakeWatch{false, ch}
59 return &fw
60}
61
62func (w *FakeWatch) Cancel() error {
63 w.Canceled = true
64 return nil
65}
66
67func (w *FakeWatch) Chanel() chan *dbus.Message {
68 return w.Ch
69}
70
71// returns a new error that can be used in the tests
72func newDBusError() *dbus.Message {
73 msg := dbus.NewMethodCallMessage("com.destination", "/path", "com.interface", "method")
74 msg.Type = dbus.TypeError
75 msg.ErrorName = "com.testing.udm"
76 return msg
77}
78
79func newDBusReturn() *dbus.Message {
80 msg := dbus.NewMethodCallMessage("com.destination", "/path", "com.interface", "method")
81 msg.Type = dbus.TypeMethodReturn
82 return msg
83}
840
=== removed file 'bindings/golang/downloader.go'
--- bindings/golang/downloader.go 2014-05-13 08:50:46 +0000
+++ bindings/golang/downloader.go 1970-01-01 00:00:00 +0000
@@ -1,600 +0,0 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Manuel de la Pena: manuel.delapena@canonical.com
6 *
7 * This file is part of ubuntu-download-manager.
8 *
9 * ubuntu-download-manager 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 * ubuntu-download-manager 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
22// Package udm provides a go interface to work with the ubuntu download manager
23package udm
24
25import (
26 "errors"
27 "fmt"
28 "launchpad.net/go-dbus/v1"
29 "runtime"
30)
31
32const (
33 DOWNLOAD_SERVICE = "com.canonical.applications.Downloader"
34 DOWNLOAD_INTERFACE = "com.canonical.applications.Download"
35 DOWNLOAD_MANAGER_INTERFACE = "com.canonical.applications.DownloadManager"
36)
37
38type hashType string
39
40const (
41 MD5 hashType = "md5"
42 SHA1 hashType = "sha1"
43 SHA224 hashType = "sha224"
44 SHA256 hashType = "sha256"
45 SHA384 hashType = "sha384"
46 SHA512 hashType = "sha512"
47)
48
49const (
50 LOCAL_PATH = "local-path"
51 OBJECT_PATH = "objectpath"
52 POST_DOWNLOAD_COMMAND = "post-download-command"
53)
54
55// Download is the common interface of a download. It provides all the required
56// methods to interact with a download created by udm.
57type Download interface {
58 TotalSize() (uint64, error)
59 Progress() (uint64, error)
60 Metadata() (map[string]string, error)
61 SetThrottle(uint64) error
62 Throttle() (uint64, error)
63 AllowMobileDownload(bool) error
64 SetDestinationDir(string) error
65 IsMobileDownload() (bool, error)
66 Start() error
67 Pause() error
68 Resume() error
69 Cancel() error
70 Started() chan bool
71 Paused() chan bool
72 DownloadProgress() chan Progress
73 Resumed() chan bool
74 Canceled() chan bool
75 Finished() chan string
76 Error() chan error
77}
78
79// FileDownload represents a single file being downloaded by udm.
80type FileDownload struct {
81 conn *dbus.Connection
82 proxy proxy
83 path dbus.ObjectPath
84 started chan bool
85 started_w watch
86 paused chan bool
87 paused_w watch
88 resumed chan bool
89 resumed_w watch
90 canceled chan bool
91 canceled_w watch
92 finished chan string
93 finished_w watch
94 errors chan error
95 error_w watch
96 progress chan Progress
97 progress_w watch
98}
99
100func (down *FileDownload) free() {
101 // cancel all watches so that goroutines are done and close the
102 // channels
103 down.started_w.Cancel()
104 down.paused_w.Cancel()
105 down.resumed_w.Cancel()
106 down.canceled_w.Cancel()
107 down.finished_w.Cancel()
108 down.error_w.Cancel()
109 down.progress_w.Cancel()
110}
111
112func cleanDownloadData(down *FileDownload) {
113 down.free()
114}
115
116func newFileDownload(conn *dbus.Connection, path dbus.ObjectPath) (*FileDownload, error) {
117 proxy := conn.Object(DOWNLOAD_SERVICE, path)
118 started_ch := make(chan bool)
119 started_w, err := connectToSignal(conn, path, "started")
120 if err != nil {
121 return nil, err
122 }
123
124 paused_ch := make(chan bool)
125 paused_w, err := connectToSignal(conn, path, "paused")
126 if err != nil {
127 return nil, err
128 }
129
130 resumed_ch := make(chan bool)
131 resumed_w, err := connectToSignal(conn, path, "resumed")
132 if err != nil {
133 return nil, err
134 }
135
136 canceled_ch := make(chan bool)
137 canceled_w, err := connectToSignal(conn, path, "canceled")
138 if err != nil {
139 return nil, err
140 }
141
142 finished_ch := make(chan string)
143 finished_w, err := connectToSignal(conn, path, "finished")
144 if err != nil {
145 return nil, err
146 }
147
148 errors_ch := make(chan error)
149 errors_w, err := connectToSignal(conn, path, "error")
150 if err != nil {
151 return nil, err
152 }
153
154 progress_ch := make(chan Progress)
155 progress_w, err := connectToSignal(conn, path, "progress")
156 if err != nil {
157 return nil, err
158 }
159
160 d := FileDownload{conn, proxy, path, started_ch, started_w, paused_ch, paused_w, resumed_ch, resumed_w, canceled_ch, canceled_w, finished_ch, finished_w, errors_ch, errors_w, progress_ch, progress_w}
161
162 // connect to the diff signals so that we have nice channels that do
163 // not expose dbus watchers
164 d.connectToStarted()
165 d.connectToPaused()
166 d.connectToResumed()
167 d.connectToCanceled()
168 d.connectToFinished()
169 d.connectToError()
170 d.connectToProgress()
171 runtime.SetFinalizer(&d, cleanDownloadData)
172 return &d, nil
173}
174
175// TotalSize returns the total size of the file being downloaded.
176func (down *FileDownload) TotalSize() (size uint64, err error) {
177 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "totalSize")
178 if err != nil {
179 return 0, err
180 }
181
182 if reply.Type == dbus.TypeError {
183 return 0, fmt.Errorf("DBus Error: %", reply.ErrorName)
184 }
185
186 if err = readArgs(reply, &size); err != nil {
187 return 0, err
188 }
189 return size, nil
190}
191
192// Process returns the process so far in downloading the file.
193func (down *FileDownload) Progress() (progress uint64, err error) {
194 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "progress")
195 if err != nil {
196 return 0, err
197 }
198
199 if reply.Type == dbus.TypeError {
200 return 0, fmt.Errorf("DBus Error: %", reply.ErrorName)
201 }
202
203 if err = readArgs(reply, &progress); err != nil {
204 return 0, err
205 }
206 return progress, nil
207}
208
209// Metadata returns the metadata that was provided at creating time to the download.
210func (down *FileDownload) Metadata() (metadata map[string]string, err error) {
211 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "metadata")
212 if err != nil {
213 return nil, err
214 }
215
216 if reply.Type == dbus.TypeError {
217 return nil, fmt.Errorf("DBus Error: %", reply.ErrorName)
218 }
219
220 if err = readArgs(reply, &metadata); err != nil {
221 return nil, err
222 }
223 return metadata, nil
224}
225
226// SetThrottle sets the network throttle to be used in the download.
227func (down *FileDownload) SetThrottle(throttle uint64) (err error) {
228 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setThrottle", throttle)
229 if err != nil {
230 return err
231 }
232
233 if reply.Type == dbus.TypeError {
234 return fmt.Errorf("DBus Error: %", reply.ErrorName)
235 }
236
237 return nil
238}
239
240// Throttle returns the network throttle that is currently used in the download.
241func (down *FileDownload) Throttle() (throttle uint64, err error) {
242 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "throttle")
243 if err != nil {
244 return 0, err
245 }
246
247 if reply.Type == dbus.TypeError {
248 return 0, fmt.Errorf("DBus Error: %", reply.ErrorName)
249 }
250
251 if err = readArgs(reply, &throttle); err != nil {
252 return 0, err
253 }
254 return throttle, nil
255}
256
257// AllowMobileDownload returns if the download is allow to use the mobile connect
258// connection.
259func (down *FileDownload) AllowMobileDownload(allowed bool) (err error) {
260 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "allowGSMDownload", allowed)
261 if err != nil {
262 return err
263 }
264
265 if reply.Type == dbus.TypeError {
266 return fmt.Errorf("DBus Error: %", reply.ErrorName)
267 }
268
269 return nil
270}
271
272// SetDestinationDir permits unconfined applications to set the destination
273// directory of the download. This method must be called BEFORE the download
274// is started else an error will be returned.
275func (down *FileDownload) SetDestinationDir(path string) (err error) {
276 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "setDestinationDir", path)
277 if err != nil {
278 return err
279 }
280
281 if reply.Type == dbus.TypeError {
282 return fmt.Errorf("DBus Error: %", reply.ErrorName)
283 }
284
285 return nil
286}
287
288// IsMobileDownload returns if the download will be performed over the mobile data.
289func (down *FileDownload) IsMobileDownload() (allowed bool, err error) {
290 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "isGSMDownloadAllowed", allowed)
291 if err != nil {
292 return false, err
293 }
294
295 if reply.Type == dbus.TypeError {
296 return false, fmt.Errorf("DBus Error: %", reply.ErrorName)
297 }
298
299 if err = readArgs(reply, &allowed); err != nil {
300 return false, err
301 }
302 return allowed, nil
303}
304
305// Start tells udm that the download is ready to be peformed and that the client is
306// ready to recieve signals. The following is a common pattern to be used when
307// creating downloads in udm.
308//
309// man, err := udm.NewDownloadManager()
310// if err != nil {
311// }
312//
313// // variables used to create the download
314//
315// url := "http://www.python.org/ftp/python/3.3.3/Python-3.3.3.tar.xz"
316// hash := "8af44d33ea3a1528fc56b3a362924500"
317// hashAlgo := MD5
318// var metadata map[string]interface{}
319// var headers map[string]string
320//
321// // create the download BUT do not start downloading just yet
322// down, err := man.CreateDownload(url, hash, hashAlgo, metadata, headers)
323//
324// // connect routines to the download channels so that we can get the
325// // information of the download the channel will not get any data until the
326// // Start is called.
327//
328// started_signal := down.Started()
329// go func() {
330// <-started_signal
331// fmt.Println("Download started")
332// }()
333// progress_signal := down.DownloadProgress()
334// go func() {
335// for progress := range p {
336// fmt.Printf("Recieved %d out of %d\n", progress.Received, progress.Total)
337// }
338// }()
339//
340// finished_signal := down.Finished()
341//
342// // start download
343// down.Start()
344//
345// // block until we are finished downloading
346// <- finished_signal
347func (down *FileDownload) Start() (err error) {
348 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "start")
349 if err != nil {
350 return err
351 }
352
353 if reply.Type == dbus.TypeError {
354 return fmt.Errorf("DBus Error: %", reply.ErrorName)
355 }
356
357 return nil
358}
359
360// Pause pauses a download that was started and if not nothing is done.
361func (down *FileDownload) Pause() (err error) {
362 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "pause")
363 if err != nil {
364 return err
365 }
366
367 if reply.Type == dbus.TypeError {
368 return fmt.Errorf("DBus Error: %", reply.ErrorName)
369 }
370
371 return nil
372}
373
374// Resumes a download that was paused or does nothing otherwise.
375func (down *FileDownload) Resume() (err error) {
376 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "resume")
377 if err != nil {
378 return err
379 }
380
381 if reply.Type == dbus.TypeError {
382 return fmt.Errorf("DBus Error: %", reply.ErrorName)
383 }
384
385 return nil
386}
387
388// Cancel cancels a download that was in process and deletes any local files
389// that were created.
390func (down *FileDownload) Cancel() (err error) {
391 reply, err := down.proxy.Call(DOWNLOAD_INTERFACE, "cancel")
392 if err != nil {
393 return err
394 }
395
396 if reply.Type == dbus.TypeError {
397 return fmt.Errorf("DBus Error: %", reply.ErrorName)
398 }
399
400 return nil
401}
402
403func (down *FileDownload) connectToStarted() {
404 go func() {
405 for msg := range down.started_w.Chanel() {
406 var started bool
407 readArgs(msg, &started)
408 down.started <- started
409 }
410 close(down.started)
411 }()
412}
413
414// Started returns a channel that will be used to communicate the started signals.
415func (down *FileDownload) Started() chan bool {
416 return down.started
417}
418
419func (down *FileDownload) connectToPaused() {
420 go func() {
421 for msg := range down.paused_w.Chanel() {
422 var paused bool
423 readArgs(msg, &paused)
424 down.paused <- paused
425 }
426 close(down.paused)
427 }()
428}
429
430// Paused returns a channel that will be used to communicate the paused signals.
431func (down *FileDownload) Paused() chan bool {
432 return down.paused
433}
434
435func (down *FileDownload) connectToProgress() {
436 go func() {
437 for msg := range down.progress_w.Chanel() {
438 var received uint64
439 var total uint64
440 readArgs(msg, &received, &total)
441 down.progress <- Progress{received, total}
442 }
443 close(down.progress)
444 }()
445}
446
447// DownloadProgress returns a channel that will be used to communicate the progress
448// signals.
449func (down *FileDownload) DownloadProgress() chan Progress {
450 return down.progress
451}
452
453func (down *FileDownload) connectToResumed() {
454 go func() {
455 for msg := range down.resumed_w.Chanel() {
456 var resumed bool
457 readArgs(msg, &resumed)
458 down.resumed <- resumed
459 }
460 close(down.resumed)
461 }()
462}
463
464// Resumed returns a channel that will be used to communicate the paused signals.
465func (down *FileDownload) Resumed() chan bool {
466 return down.resumed
467}
468
469func (down *FileDownload) connectToCanceled() {
470 go func() {
471 for msg := range down.canceled_w.Chanel() {
472 var canceled bool
473 readArgs(msg, &canceled)
474 down.canceled <- canceled
475 }
476 close(down.canceled)
477 }()
478}
479
480// Canceled returns a channel that will be used to communicate the canceled signals.
481func (down *FileDownload) Canceled() chan bool {
482 return down.canceled
483}
484
485func (down *FileDownload) connectToFinished() {
486 go func() {
487 for msg := range down.finished_w.Chanel() {
488 var path string
489 readArgs(msg, &path)
490 down.finished <- path
491 }
492 close(down.finished)
493 }()
494}
495
496// Finished returns a channel that will ne used to communicate the finished signals.
497func (down *FileDownload) Finished() chan string {
498 return down.finished
499}
500
501func (down *FileDownload) connectToError() {
502 go func() {
503 for msg := range down.error_w.Chanel() {
504 var reason string
505 readArgs(msg, &reason)
506 down.errors <- errors.New(reason)
507 }
508 close(down.errors)
509 }()
510}
511
512// Error returns the channel that will be used to communicate the error signals.
513func (down *FileDownload) Error() chan error {
514 return down.errors
515}
516
517type DownloadManager struct {
518 conn *dbus.Connection
519 proxy *dbus.ObjectProxy
520}
521
522// NewDownloadManager creates a new manager that can be used to create download in the
523// udm daemon.
524func NewDownloadManager() (*DownloadManager, error) {
525 conn, err := dbus.Connect(dbus.SessionBus)
526 if err != nil {
527 return nil, err
528 }
529
530 if err != nil {
531 return nil, err
532 }
533
534 proxy := conn.Object(DOWNLOAD_SERVICE, "/")
535 d := DownloadManager{conn, proxy}
536 return &d, nil
537}
538
539// CreateDownload creates a new download in the udm daemon that can be used to get
540// a remote resource. Udm allows to pass a hash signature and method that will be
541// check once the download has been complited.
542//
543// The download hash can be one of the the following constants:
544//
545// MD5
546// SHA1
547// SHA224
548// SHA256
549// SHA384
550// SHA512
551//
552// The metadata attribute can be used to pass extra information to the udm daemon
553// that will just be considered if the caller is not a apparmor confined application.
554//
555// LOCAL_PATH => allows to provide the local path for the download.
556// OBJECT_PATH => allows to provide the object path to be used in the dbus daemon.
557// POST_DOWNLOAD_COMMAND => allows to provide a command that will be executed on the
558// download
559//
560// The headers attribute allows to provide extra headers to be used in the request used
561// to perform the download.
562func (man *DownloadManager) CreateDownload(url string, hash string, algo hashType, metadata map[string]interface{}, headers map[string]string) (down Download, err error) {
563 var t map[string]*dbus.Variant
564 for key, value := range metadata {
565 t[key] = &dbus.Variant{Value: value}
566 }
567 s := struct {
568 U string
569 H string
570 A string
571 M map[string]*dbus.Variant
572 HD map[string]string
573 }{url, hash, string(algo), t, headers}
574 var path dbus.ObjectPath
575 reply, err := man.proxy.Call(DOWNLOAD_MANAGER_INTERFACE, "createDownload", s)
576 if err != nil || reply.Type == dbus.TypeError {
577 return nil, err
578 }
579 if err = readArgs(reply, &path); err != nil {
580 return nil, err
581 }
582 down, err = newFileDownload(man.conn, path)
583 return down, err
584}
585
586// CreateMmsDownload creates an mms download that will be performed right away. An
587// mms download only uses mobile that and an apn proxy to download a multime media
588// message.
589func (man *DownloadManager) CreateMmsDownload(url string, hostname string, port int32) (down Download, err error) {
590 var path dbus.ObjectPath
591 reply, err := man.proxy.Call(DOWNLOAD_MANAGER_INTERFACE, "createMmsDownload", url, hostname, port)
592 if err != nil || reply.Type == dbus.TypeError {
593 return nil, err
594 }
595 if err = readArgs(reply, &path); err != nil {
596 return nil, err
597 }
598 down, err = newFileDownload(man.conn, path)
599 return down, err
600}
6010
=== removed file 'bindings/golang/downloader_test.go'
--- bindings/golang/downloader_test.go 2014-05-13 08:50:46 +0000
+++ bindings/golang/downloader_test.go 1970-01-01 00:00:00 +0000
@@ -1,306 +0,0 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Manuel de la Pena: manuel.delapena@canonical.com
6 *
7 * This file is part of ubuntu-download-manager.
8 *
9 * ubuntu-download-manager 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 * ubuntu-download-manager 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 udm
23
24import (
25 "errors"
26 . "gopkg.in/check.v1"
27 "launchpad.net/go-dbus/v1"
28 "reflect"
29)
30
31type DownloadSuite struct {
32 proxy *fakeProxy
33 download *FileDownload
34 msg_args []interface{}
35 msg_args_err error
36 started_ch chan bool
37 started_w watch
38 paused_ch chan bool
39 paused_w watch
40 resumed_ch chan bool
41 resumed_w watch
42 canceled_ch chan bool
43 canceled_w watch
44 finished_ch chan string
45 finished_w watch
46 errors_ch chan error
47 errors_w watch
48 progress_ch chan Progress
49 progress_w watch
50}
51
52var _ = Suite(&DownloadSuite{})
53
54func (s *DownloadSuite) SetUpTest(c *C) {
55 s.proxy = &fakeProxy{}
56 s.started_ch = make(chan bool)
57 s.started_w = newFakeWatch()
58 s.paused_ch = make(chan bool)
59 s.paused_w = newFakeWatch()
60 s.resumed_ch = make(chan bool)
61 s.resumed_w = newFakeWatch()
62 s.canceled_ch = make(chan bool)
63 s.canceled_w = newFakeWatch()
64 s.finished_ch = make(chan string)
65 s.finished_w = newFakeWatch()
66 s.errors_ch = make(chan error)
67 s.errors_w = newFakeWatch()
68 s.progress_ch = make(chan Progress)
69 s.progress_w = newFakeWatch()
70 s.download = &FileDownload{nil, s.proxy, "", s.started_ch, s.started_w, s.paused_ch, s.paused_w, s.resumed_ch, s.resumed_w, s.canceled_ch, s.canceled_w, s.finished_ch, s.finished_w, s.errors_ch, s.errors_w, s.progress_ch, s.progress_w}
71
72 readArgs = func(msg *dbus.Message, args ...interface{}) error {
73 for i, arg := range args {
74 v := reflect.ValueOf(arg)
75 e := v.Elem()
76 switch s.msg_args[i].(type) {
77 default:
78 return errors.New("unexpected type")
79 case bool:
80 e.SetBool(s.msg_args[i].(bool))
81 case uint64:
82 e.SetUint(s.msg_args[i].(uint64))
83 }
84 }
85 return s.msg_args_err
86 }
87}
88
89func (s *DownloadSuite) TestTotalSizeError(c *C) {
90 s.proxy.Result = newDBusError()
91 size, err := s.download.TotalSize()
92 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
93 c.Assert(s.proxy.MethodName, Equals, "totalSize")
94 c.Assert(size, Equals, uint64(0))
95 c.Assert(err, NotNil)
96}
97
98func (s *DownloadSuite) TestTotalSize(c *C) {
99 expected_size := uint64(98)
100 s.proxy.Result = newDBusReturn()
101 s.msg_args = make([]interface{}, 1)
102 s.msg_args[0] = expected_size
103 s.msg_args_err = nil
104 size, err := s.download.TotalSize()
105 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
106 c.Assert(s.proxy.MethodName, Equals, "totalSize")
107 c.Assert(err, IsNil)
108 c.Assert(size, Equals, expected_size)
109}
110
111func (s *DownloadSuite) TestProgressError(c *C) {
112 s.proxy.Result = newDBusError()
113 progress, err := s.download.Progress()
114 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
115 c.Assert(s.proxy.MethodName, Equals, "progress")
116 c.Assert(progress, Equals, uint64(0))
117 c.Assert(err, NotNil)
118}
119
120func (s *DownloadSuite) TestProgress(c *C) {
121 expected_progress := uint64(98)
122 s.proxy.Result = newDBusReturn()
123 s.msg_args = make([]interface{}, 1)
124 s.msg_args[0] = expected_progress
125 s.msg_args_err = nil
126 progress, err := s.download.Progress()
127 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
128 c.Assert(s.proxy.MethodName, Equals, "progress")
129 c.Assert(err, IsNil)
130 c.Assert(progress, Equals, expected_progress)
131}
132
133func (s *DownloadSuite) TestMetadataError(c *C) {
134 s.proxy.Result = newDBusError()
135 metadata, err := s.download.Metadata()
136 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
137 c.Assert(s.proxy.MethodName, Equals, "metadata")
138 c.Assert(metadata, IsNil)
139 c.Assert(err, NotNil)
140}
141
142func (s *DownloadSuite) TestSetThrotthleError(c *C) {
143 throttle := uint64(9)
144 s.proxy.Result = newDBusError()
145 err := s.download.SetThrottle(throttle)
146 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
147 c.Assert(s.proxy.MethodName, Equals, "setThrottle")
148 c.Assert(err, NotNil)
149 c.Assert(s.proxy.Args[0], Equals, throttle)
150}
151
152func (s *DownloadSuite) TestSetThrottle(c *C) {
153 s.proxy.Result = newDBusReturn()
154 err := s.download.SetThrottle(uint64(9))
155 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
156 c.Assert(s.proxy.MethodName, Equals, "setThrottle")
157 c.Assert(err, IsNil)
158}
159
160func (s *DownloadSuite) TestThrottleError(c *C) {
161 s.proxy.Result = newDBusError()
162 size, err := s.download.Throttle()
163 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
164 c.Assert(s.proxy.MethodName, Equals, "throttle")
165 c.Assert(size, Equals, uint64(0))
166 c.Assert(err, NotNil)
167}
168
169func (s *DownloadSuite) TestThrottle(c *C) {
170 expected_throttle := uint64(98)
171 s.proxy.Result = newDBusReturn()
172 s.msg_args = make([]interface{}, 1)
173 s.msg_args[0] = expected_throttle
174 s.msg_args_err = nil
175 throttle, err := s.download.Throttle()
176 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
177 c.Assert(s.proxy.MethodName, Equals, "throttle")
178 c.Assert(err, IsNil)
179 c.Assert(throttle, Equals, expected_throttle)
180}
181
182func (s *DownloadSuite) TestAllowMobileDownloadError(c *C) {
183 s.proxy.Result = newDBusError()
184 err := s.download.AllowMobileDownload(true)
185 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
186 c.Assert(s.proxy.MethodName, Equals, "allowGSMDownload")
187 c.Assert(err, NotNil)
188}
189
190func (s *DownloadSuite) TestAllowMobileDownload(c *C) {
191 expected_allowed := true
192 s.proxy.Result = newDBusReturn()
193 err := s.download.AllowMobileDownload(expected_allowed)
194 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
195 c.Assert(s.proxy.MethodName, Equals, "allowGSMDownload")
196 c.Assert(err, IsNil)
197 c.Assert(s.proxy.Args[0], Equals, expected_allowed)
198}
199
200func (s *DownloadSuite) TestSetDestinationDirError(c *C) {
201 s.proxy.Result = newDBusError()
202 err := s.download.SetDestinationDir("/new/path")
203 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
204 c.Assert(s.proxy.MethodName, Equals, "setDestinationDir")
205 c.Assert(err, NotNil)
206}
207
208func (s *DownloadSuite) TestSetDestinationDir(c *C) {
209 expected_dir := "/path/to/use"
210 s.proxy.Result = newDBusReturn()
211 err := s.download.SetDestinationDir(expected_dir)
212 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
213 c.Assert(s.proxy.MethodName, Equals, "setDestinationDir")
214 c.Assert(err, IsNil)
215 c.Assert(s.proxy.Args[0], Equals, expected_dir)
216}
217
218func (s *DownloadSuite) TestIsMobileDownloadError(c *C) {
219 s.proxy.Result = newDBusError()
220 allowed, err := s.download.IsMobileDownload()
221 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
222 c.Assert(s.proxy.MethodName, Equals, "isGSMDownloadAllowed")
223 c.Assert(allowed, Equals, false)
224 c.Assert(err, NotNil)
225}
226
227func (s *DownloadSuite) TestIsMobileDownload(c *C) {
228 expected_allowed := true
229 s.proxy.Result = newDBusReturn()
230 s.msg_args = make([]interface{}, 1)
231 s.msg_args[0] = expected_allowed
232 s.msg_args_err = nil
233 allowed, err := s.download.IsMobileDownload()
234 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
235 c.Assert(s.proxy.MethodName, Equals, "isGSMDownloadAllowed")
236 c.Assert(err, IsNil)
237 c.Assert(allowed, Equals, expected_allowed)
238}
239
240func (s *DownloadSuite) TestStartDBusError(c *C) {
241 s.proxy.Result = newDBusError()
242 err := s.download.Start()
243 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
244 c.Assert(s.proxy.MethodName, Equals, "start")
245 c.Assert(err, NotNil)
246}
247
248func (s *DownloadSuite) TestStartError(c *C) {
249 s.proxy.Result = newDBusReturn()
250 s.proxy.Err = errors.New("Fake error")
251 err := s.download.Start()
252 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
253 c.Assert(s.proxy.MethodName, Equals, "start")
254 c.Assert(err, NotNil)
255}
256
257func (s *DownloadSuite) TestPauseDBusError(c *C) {
258 s.proxy.Result = newDBusError()
259 err := s.download.Pause()
260 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
261 c.Assert(s.proxy.MethodName, Equals, "pause")
262 c.Assert(err, NotNil)
263}
264
265func (s *DownloadSuite) TestPauseError(c *C) {
266 s.proxy.Result = newDBusReturn()
267 s.proxy.Err = errors.New("Fake error")
268 err := s.download.Pause()
269 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
270 c.Assert(s.proxy.MethodName, Equals, "pause")
271 c.Assert(err, NotNil)
272}
273
274func (s *DownloadSuite) TestResumeDBusError(c *C) {
275 s.proxy.Result = newDBusError()
276 err := s.download.Resume()
277 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
278 c.Assert(s.proxy.MethodName, Equals, "resume")
279 c.Assert(err, NotNil)
280}
281
282func (s *DownloadSuite) TestResumeError(c *C) {
283 s.proxy.Result = newDBusReturn()
284 s.proxy.Err = errors.New("Fake error")
285 err := s.download.Resume()
286 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
287 c.Assert(s.proxy.MethodName, Equals, "resume")
288 c.Assert(err, NotNil)
289}
290
291func (s *DownloadSuite) TestCancelDBusError(c *C) {
292 s.proxy.Result = newDBusError()
293 err := s.download.Cancel()
294 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
295 c.Assert(s.proxy.MethodName, Equals, "cancel")
296 c.Assert(err, NotNil)
297}
298
299func (s *DownloadSuite) TestCancelError(c *C) {
300 s.proxy.Result = newDBusReturn()
301 s.proxy.Err = errors.New("Fake error")
302 err := s.download.Cancel()
303 c.Assert(s.proxy.Interface, Equals, DOWNLOAD_INTERFACE)
304 c.Assert(s.proxy.MethodName, Equals, "cancel")
305 c.Assert(err, NotNil)
306}
3070
=== removed file 'bindings/golang/uploader.go'
--- bindings/golang/uploader.go 2014-05-13 08:50:46 +0000
+++ bindings/golang/uploader.go 1970-01-01 00:00:00 +0000
@@ -1,396 +0,0 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Manuel de la Pena: manuel.delapena@canonical.com
6 *
7 * This file is part of ubuntu-download-manager.
8 *
9 * ubuntu-download-manager 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 * ubuntu-download-manager 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
22// Package udm provides a go interface to work with the ubuntu download manager
23package udm
24
25import (
26 "errors"
27 "fmt"
28 "launchpad.net/go-dbus/v1"
29 "runtime"
30)
31
32const (
33 UPLOAD_SERVICE = "com.canonical.applications.Uploader"
34 UPLOAD_INTERFACE = "com.canonical.applications.Upload"
35 UPLOAD_MANAGER_INTERFACE = "com.canonical.applications.UploadManager"
36)
37
38// Upload is the common interface of an upload. It provides all the required
39// methods to interact with an upload created by udm.
40type Upload interface {
41 Progress() (uint64, error)
42 Metadata() (map[string]string, error)
43 SetThrottle(uint64) error
44 Throttle() (uint64, error)
45 AllowMobileUpload(bool) error
46 IsMobileUpload() (bool, error)
47 Start() error
48 Cancel() error
49 Started() chan bool
50 UploadProgress() chan Progress
51 Canceled() chan bool
52 Finished() chan string
53 Error() chan error
54}
55
56// FileUpload represents a single file being uploaded by udm.
57type FileUpload struct {
58 conn *dbus.Connection
59 proxy proxy
60 path dbus.ObjectPath
61 started chan bool
62 started_w watch
63 canceled chan bool
64 canceled_w watch
65 finished chan string
66 finished_w watch
67 errors chan error
68 error_w watch
69 progress chan Progress
70 progress_w watch
71}
72
73func (upload *FileUpload) free() {
74 // cancel all watches so that goroutines are done and close the
75 // channels
76 upload.started_w.Cancel()
77 upload.canceled_w.Cancel()
78 upload.finished_w.Cancel()
79 upload.error_w.Cancel()
80 upload.progress_w.Cancel()
81}
82
83func cleanUploadData(upload *FileUpload) {
84 upload.free()
85}
86
87func newFileUpload(conn *dbus.Connection, path dbus.ObjectPath) (*FileUpload, error) {
88 proxy := conn.Object(DOWNLOAD_SERVICE, path)
89 started_ch := make(chan bool)
90 started_w, err := connectToSignal(conn, path, "started")
91 if err != nil {
92 return nil, err
93 }
94
95 canceled_ch := make(chan bool)
96 canceled_w, err := connectToSignal(conn, path, "canceled")
97 if err != nil {
98 return nil, err
99 }
100
101 finished_ch := make(chan string)
102 finished_w, err := connectToSignal(conn, path, "finished")
103 if err != nil {
104 return nil, err
105 }
106
107 errors_ch := make(chan error)
108 errors_w, err := connectToSignal(conn, path, "error")
109 if err != nil {
110 return nil, err
111 }
112
113 progress_ch := make(chan Progress)
114 progress_w, err := connectToSignal(conn, path, "progress")
115 if err != nil {
116 return nil, err
117 }
118
119 u := FileUpload{conn, proxy, path, started_ch, started_w, canceled_ch, canceled_w, finished_ch, finished_w, errors_ch, errors_w, progress_ch, progress_w}
120
121 // connect to the diff signals so that we have nice channels that do
122 // not expose dbus watchers
123 u.connectToStarted()
124 u.connectToCanceled()
125 u.connectToFinished()
126 u.connectToError()
127 u.connectToProgress()
128 runtime.SetFinalizer(&u, cleanDownloadData)
129 return &u, nil
130}
131
132// Process returns the process so far in uploading the file.
133func (upload *FileUpload) Progress() (progress uint64, err error) {
134 reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "progress")
135 if err != nil {
136 return 0, err
137 }
138
139 if reply.Type == dbus.TypeError {
140 return 0, fmt.Errorf("DBus Error: %", reply.ErrorName)
141 }
142
143 if err = readArgs(reply, &progress); err != nil {
144 return 0, err
145 }
146 return progress, nil
147}
148
149// Metadata returns the metadata that was provided at creating time to the upload.
150func (upload *FileUpload) Metadata() (metadata map[string]string, err error) {
151 reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "metadata")
152 if err != nil {
153 return nil, err
154 }
155
156 if reply.Type == dbus.TypeError {
157 return nil, fmt.Errorf("DBus Error: %", reply.ErrorName)
158 }
159
160 if err = readArgs(reply, &metadata); err != nil {
161 return nil, err
162 }
163 return metadata, nil
164}
165
166// SetThrottle sets the network throttle to be used in the upload.
167func (upload *FileUpload) SetThrottle(throttle uint64) (err error) {
168 reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "setThrottle", throttle)
169 if err != nil {
170 return err
171 }
172
173 if reply.Type == dbus.TypeError {
174 return fmt.Errorf("DBus Error: %", reply.ErrorName)
175 }
176
177 return nil
178}
179
180// Throttle returns the network throttle that is currently used in the upload.
181func (upload *FileUpload) Throttle() (throttle uint64, err error) {
182 reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "throttle")
183 if err != nil {
184 return 0, err
185 }
186
187 if reply.Type == dbus.TypeError {
188 return 0, fmt.Errorf("DBus Error: %", reply.ErrorName)
189 }
190
191 if err = readArgs(reply, &throttle); err != nil {
192 return 0, err
193 }
194 return throttle, nil
195}
196
197// AllowMobileUpload returns if the download is allow to use the mobile connect
198// connection.
199func (upload *FileUpload) AllowMobileUpload(allowed bool) (err error) {
200 reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "allowMobileUpload", allowed)
201 if err != nil {
202 return err
203 }
204
205 if reply.Type == dbus.TypeError {
206 return fmt.Errorf("DBus Error: %", reply.ErrorName)
207 }
208
209 return nil
210}
211
212// IsMobileUpload returns if the download will be performed over the mobile data.
213func (upload *FileUpload) IsMobileUpload() (allowed bool, err error) {
214 reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "isMobileUploadAllowed", allowed)
215 if err != nil {
216 return false, err
217 }
218
219 if reply.Type == dbus.TypeError {
220 return false, fmt.Errorf("DBus Error: %", reply.ErrorName)
221 }
222
223 if err = readArgs(reply, &allowed); err != nil {
224 return false, err
225 }
226 return allowed, nil
227}
228
229func (upload *FileUpload) Start() (err error) {
230 reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "start")
231 if err != nil {
232 return err
233 }
234
235 if reply.Type == dbus.TypeError {
236 return fmt.Errorf("DBus Error: %", reply.ErrorName)
237 }
238
239 return nil
240}
241
242// Cancel cancels an upload that was in process and deletes any local files
243// that were created.
244func (upload *FileUpload) Cancel() (err error) {
245 reply, err := upload.proxy.Call(UPLOAD_INTERFACE, "cancel")
246 if err != nil {
247 return err
248 }
249
250 if reply.Type == dbus.TypeError {
251 return fmt.Errorf("DBus Error: %", reply.ErrorName)
252 }
253
254 return nil
255}
256
257func (upload *FileUpload) connectToStarted() {
258
259 go func() {
260 for msg := range upload.started_w.Chanel() {
261 var started bool
262 readArgs(msg, &started)
263 upload.started <- started
264 }
265 close(upload.started)
266 }()
267}
268
269// Started returns a channel that will be used to communicate the started signals.
270func (upload *FileUpload) Started() chan bool {
271 return upload.started
272}
273
274func (upload *FileUpload) connectToCanceled() {
275 go func() {
276 for msg := range upload.canceled_w.Chanel() {
277 var canceled bool
278 readArgs(msg, &canceled)
279 upload.canceled <- canceled
280 }
281 close(upload.canceled)
282 }()
283}
284
285// Canceled returns a channel that will be used to communicate the canceled signals.
286func (upload *FileUpload) Canceled() chan bool {
287 return upload.canceled
288}
289
290func (upload *FileUpload) connectToFinished() {
291 go func() {
292 for msg := range upload.finished_w.Chanel() {
293 var path string
294 readArgs(msg, &path)
295 upload.finished <- path
296 }
297 close(upload.finished)
298 }()
299}
300
301// Finished returns a channel that will ne used to communicate the finished signals.
302func (upload *FileUpload) Finished() chan string {
303 return upload.finished
304}
305
306func (upload *FileUpload) connectToError() {
307 go func() {
308 for msg := range upload.error_w.Chanel() {
309 var reason string
310 readArgs(msg, &reason)
311 upload.errors <- errors.New(reason)
312 }
313 close(upload.errors)
314 }()
315}
316
317// Error returns the channel that will be used to communicate the error signals.
318func (upload *FileUpload) Error() chan error {
319 return upload.errors
320}
321
322func (upload *FileUpload) connectToProgress() {
323 go func() {
324 for msg := range upload.progress_w.Chanel() {
325 var received uint64
326 var total uint64
327 readArgs(msg, &received, &total)
328 upload.progress <- Progress{received, total}
329 }
330 close(upload.progress)
331 }()
332}
333
334// UploadProgress returns a channel that will be used to communicate the progress
335// signals.
336func (upload *FileUpload) UploadProgress() chan Progress {
337 return upload.progress
338}
339
340type UploadManager struct {
341 conn *dbus.Connection
342 proxy *dbus.ObjectProxy
343}
344
345// NewUploadManager creates a new manager that can be used to create download in the
346// udm daemon.
347func NewUploadManager() (*UploadManager, error) {
348 conn, err := dbus.Connect(dbus.SessionBus)
349 if err != nil {
350 return nil, err
351 }
352
353 if err != nil {
354 return nil, err
355 }
356
357 proxy := conn.Object(UPLOAD_SERVICE, "/")
358 d := UploadManager{conn, proxy}
359 return &d, nil
360}
361
362func (man *UploadManager) CreateUpload(url string, file string, metadata map[string]interface{}, headers map[string]string) (upload Upload, err error) {
363 var t map[string]*dbus.Variant
364 for key, value := range metadata {
365 t[key] = &dbus.Variant{Value: value}
366 }
367 s := struct {
368 U string
369 F string
370 M map[string]*dbus.Variant
371 HD map[string]string
372 }{url, file, t, headers}
373 var path dbus.ObjectPath
374 reply, err := man.proxy.Call(UPLOAD_MANAGER_INTERFACE, "createUpload", s)
375 if err != nil || reply.Type == dbus.TypeError {
376 return nil, err
377 }
378 if err = readArgs(reply, &path); err != nil {
379 return nil, err
380 }
381 upload, err = newFileUpload(man.conn, path)
382 return upload, err
383}
384
385func (man *UploadManager) CreateMmsUpload(url string, file string, hostname string, port int32) (upload Upload, err error) {
386 var path dbus.ObjectPath
387 reply, err := man.proxy.Call(UPLOAD_MANAGER_INTERFACE, "createMmsUpload", url, file, hostname, port)
388 if err != nil || reply.Type == dbus.TypeError {
389 return nil, err
390 }
391 if err = readArgs(reply, &path); err != nil {
392 return nil, err
393 }
394 upload, err = newFileUpload(man.conn, path)
395 return upload, err
396}
3970
=== removed file 'bindings/golang/uploader_test.go'
--- bindings/golang/uploader_test.go 2014-05-13 08:50:46 +0000
+++ bindings/golang/uploader_test.go 1970-01-01 00:00:00 +0000
@@ -1,215 +0,0 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * Authors:
5 * Manuel de la Pena: manuel.delapena@canonical.com
6 *
7 * This file is part of ubuntu-download-manager.
8 *
9 * ubuntu-download-manager 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 * ubuntu-download-manager 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 udm
23
24import (
25 "errors"
26 . "gopkg.in/check.v1"
27 "launchpad.net/go-dbus/v1"
28 "reflect"
29)
30
31type UploadSuite struct {
32 proxy *fakeProxy
33 upload *FileUpload
34 msg_args []interface{}
35 msg_args_err error
36 started_ch chan bool
37 started_w watch
38 canceled_ch chan bool
39 canceled_w watch
40 finished_ch chan string
41 finished_w watch
42 errors_ch chan error
43 errors_w watch
44 progress_ch chan Progress
45 progress_w watch
46}
47
48var _ = Suite(&UploadSuite{})
49
50func (s *UploadSuite) SetUpTest(c *C) {
51 s.proxy = &fakeProxy{}
52 s.started_ch = make(chan bool)
53 s.started_w = newFakeWatch()
54 s.canceled_ch = make(chan bool)
55 s.canceled_w = newFakeWatch()
56 s.finished_ch = make(chan string)
57 s.finished_w = newFakeWatch()
58 s.errors_ch = make(chan error)
59 s.errors_w = newFakeWatch()
60 s.progress_ch = make(chan Progress)
61 s.progress_w = newFakeWatch()
62 s.upload = &FileUpload{nil, s.proxy, "", s.started_ch, s.started_w, s.canceled_ch, s.canceled_w, s.finished_ch, s.finished_w, s.errors_ch, s.errors_w, s.progress_ch, s.progress_w}
63
64 readArgs = func(msg *dbus.Message, args ...interface{}) error {
65 for i, arg := range args {
66 v := reflect.ValueOf(arg)
67 e := v.Elem()
68 switch s.msg_args[i].(type) {
69 default:
70 return errors.New("unexpected type")
71 case bool:
72 e.SetBool(s.msg_args[i].(bool))
73 case uint64:
74 e.SetUint(s.msg_args[i].(uint64))
75 }
76 }
77 return s.msg_args_err
78 }
79}
80
81func (s *UploadSuite) TestProgressError(c *C) {
82 s.proxy.Result = newDBusError()
83 progress, err := s.upload.Progress()
84 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
85 c.Assert(s.proxy.MethodName, Equals, "progress")
86 c.Assert(progress, Equals, uint64(0))
87 c.Assert(err, NotNil)
88}
89
90func (s *UploadSuite) TestProgress(c *C) {
91 expected_progress := uint64(98)
92 s.proxy.Result = newDBusReturn()
93 s.msg_args = make([]interface{}, 1)
94 s.msg_args[0] = expected_progress
95 s.msg_args_err = nil
96 progress, err := s.upload.Progress()
97 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
98 c.Assert(s.proxy.MethodName, Equals, "progress")
99 c.Assert(err, IsNil)
100 c.Assert(progress, Equals, expected_progress)
101}
102
103func (s *UploadSuite) TestMetadataError(c *C) {
104 s.proxy.Result = newDBusError()
105 metadata, err := s.upload.Metadata()
106 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
107 c.Assert(s.proxy.MethodName, Equals, "metadata")
108 c.Assert(metadata, IsNil)
109 c.Assert(err, NotNil)
110}
111
112func (s *UploadSuite) TestSetThrotthleError(c *C) {
113 throttle := uint64(9)
114 s.proxy.Result = newDBusError()
115 err := s.upload.SetThrottle(throttle)
116 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
117 c.Assert(s.proxy.MethodName, Equals, "setThrottle")
118 c.Assert(err, NotNil)
119 c.Assert(s.proxy.Args[0], Equals, throttle)
120}
121
122func (s *UploadSuite) TestSetThrottle(c *C) {
123 s.proxy.Result = newDBusReturn()
124 err := s.upload.SetThrottle(uint64(9))
125 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
126 c.Assert(s.proxy.MethodName, Equals, "setThrottle")
127 c.Assert(err, IsNil)
128}
129
130func (s *UploadSuite) TestThrottle(c *C) {
131 expected_throttle := uint64(98)
132 s.proxy.Result = newDBusReturn()
133 s.msg_args = make([]interface{}, 1)
134 s.msg_args[0] = expected_throttle
135 s.msg_args_err = nil
136 throttle, err := s.upload.Throttle()
137 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
138 c.Assert(s.proxy.MethodName, Equals, "throttle")
139 c.Assert(err, IsNil)
140 c.Assert(throttle, Equals, expected_throttle)
141}
142
143func (s *UploadSuite) TestAllowMobileUploadError(c *C) {
144 s.proxy.Result = newDBusError()
145 err := s.upload.AllowMobileUpload(true)
146 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
147 c.Assert(s.proxy.MethodName, Equals, "allowMobileUpload")
148 c.Assert(err, NotNil)
149}
150
151func (s *UploadSuite) TestAllowMobileUpload(c *C) {
152 expected_allowed := true
153 s.proxy.Result = newDBusReturn()
154 err := s.upload.AllowMobileUpload(expected_allowed)
155 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
156 c.Assert(s.proxy.MethodName, Equals, "allowMobileUpload")
157 c.Assert(err, IsNil)
158 c.Assert(s.proxy.Args[0], Equals, expected_allowed)
159}
160
161func (s *UploadSuite) TestIsMobileUploadError(c *C) {
162 s.proxy.Result = newDBusError()
163 allowed, err := s.upload.IsMobileUpload()
164 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
165 c.Assert(s.proxy.MethodName, Equals, "isMobileUploadAllowed")
166 c.Assert(allowed, Equals, false)
167 c.Assert(err, NotNil)
168}
169
170func (s *UploadSuite) TestIsMobileUpload(c *C) {
171 expected_allowed := true
172 s.proxy.Result = newDBusReturn()
173 s.msg_args = make([]interface{}, 1)
174 s.msg_args[0] = expected_allowed
175 s.msg_args_err = nil
176 allowed, err := s.upload.IsMobileUpload()
177 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
178 c.Assert(s.proxy.MethodName, Equals, "isMobileUploadAllowed")
179 c.Assert(err, IsNil)
180 c.Assert(allowed, Equals, expected_allowed)
181}
182
183func (s *UploadSuite) TestStartDBusError(c *C) {
184 s.proxy.Result = newDBusError()
185 err := s.upload.Start()
186 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
187 c.Assert(s.proxy.MethodName, Equals, "start")
188 c.Assert(err, NotNil)
189}
190
191func (s *UploadSuite) TestStartError(c *C) {
192 s.proxy.Result = newDBusReturn()
193 s.proxy.Err = errors.New("Fake error")
194 err := s.upload.Start()
195 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
196 c.Assert(s.proxy.MethodName, Equals, "start")
197 c.Assert(err, NotNil)
198}
199
200func (s *UploadSuite) TestCancelDBusError(c *C) {
201 s.proxy.Result = newDBusError()
202 err := s.upload.Cancel()
203 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
204 c.Assert(s.proxy.MethodName, Equals, "cancel")
205 c.Assert(err, NotNil)
206}
207
208func (s *UploadSuite) TestCancelError(c *C) {
209 s.proxy.Result = newDBusReturn()
210 s.proxy.Err = errors.New("Fake error")
211 err := s.upload.Cancel()
212 c.Assert(s.proxy.Interface, Equals, UPLOAD_INTERFACE)
213 c.Assert(s.proxy.MethodName, Equals, "cancel")
214 c.Assert(err, NotNil)
215}
2160
=== modified file 'docs/com.canonical.applications.upload_manager.xml'
--- docs/com.canonical.applications.upload_manager.xml 2014-02-21 11:56:12 +0000
+++ docs/com.canonical.applications.upload_manager.xml 2014-05-13 08:50:47 +0000
@@ -11,8 +11,6 @@
11 <arg name="file" type="s" direction="in" />11 <arg name="file" type="s" direction="in" />
12 <arg name="hostname" type="s" direction="in" />12 <arg name="hostname" type="s" direction="in" />
13 <arg name="port" type="i" direction="in" />13 <arg name="port" type="i" direction="in" />
14 <arg name="username" type="s" direction="in" />
15 <arg name="password" type="s" direction="in" />
16 <arg name="uploadPath" type="o" direction="out" />14 <arg name="uploadPath" type="o" direction="out" />
17 </method>15 </method>
1816
1917
=== modified file 'src/uploads/priv/ubuntu/uploads/factory.cpp'
--- src/uploads/priv/ubuntu/uploads/factory.cpp 2014-05-13 08:50:46 +0000
+++ src/uploads/priv/ubuntu/uploads/factory.cpp 2014-05-13 08:50:47 +0000
@@ -89,11 +89,9 @@
89 const QUrl& url,89 const QUrl& url,
90 const QString& filePath,90 const QString& filePath,
91 const QString& hostname,91 const QString& hostname,
92 int port,92 int port) {
93 const QString& username,
94 const QString& password) {
95 QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostname,93 QNetworkProxy proxy(QNetworkProxy::HttpProxy, hostname,
96 port, username, password);94 port);
97 QVariantMap metadata;95 QVariantMap metadata;
98 QMap<QString, QString> headers;96 QMap<QString, QString> headers;
99 QScopedPointer<SecurityDetails> details(97 QScopedPointer<SecurityDetails> details(
10098
=== modified file 'src/uploads/priv/ubuntu/uploads/factory.h'
--- src/uploads/priv/ubuntu/uploads/factory.h 2014-03-26 10:00:28 +0000
+++ src/uploads/priv/ubuntu/uploads/factory.h 2014-05-13 08:50:47 +0000
@@ -51,9 +51,7 @@
51 const QUrl& url,51 const QUrl& url,
52 const QString& filePath,52 const QString& filePath,
53 const QString& hostname,53 const QString& hostname,
54 int port,54 int port);
55 const QString& username,
56 const QString& password);
5755
58 // mainly for testing purposes56 // mainly for testing purposes
59 virtual QList<QSslCertificate> acceptedCertificates();57 virtual QList<QSslCertificate> acceptedCertificates();
6058
=== modified file 'src/uploads/priv/ubuntu/uploads/manager.cpp'
--- src/uploads/priv/ubuntu/uploads/manager.cpp 2014-03-04 13:17:09 +0000
+++ src/uploads/priv/ubuntu/uploads/manager.cpp 2014-05-13 08:50:47 +0000
@@ -128,16 +128,13 @@
128UploadManager::createMmsUpload(const QString& url,128UploadManager::createMmsUpload(const QString& url,
129 const QString& file,129 const QString& file,
130 const QString& hostname,130 const QString& hostname,
131 int port,131 int port) {
132 const QString& username,
133 const QString& password) {
134 LOG(INFO) << "Create MMS upload == {url:" << url << " filePath: "132 LOG(INFO) << "Create MMS upload == {url:" << url << " filePath: "
135 << file << " hostname:" << hostname << " port:"133 << file << " hostname:" << hostname << " port:" << port << "}";
136 << port << " username:" << username << " pwd: " << password << "}";
137 UploadCreationFunc createUploadFunc =134 UploadCreationFunc createUploadFunc =
138 [this, url, file, hostname, port, username, password](QString owner) {135 [this, url, file, hostname, port](QString owner) {
139 auto upload = _factory->createMmsUpload(owner, url, file, hostname,136 auto upload = _factory->createMmsUpload(owner, url, file, hostname,
140 port, username, password);137 port);
141 return upload;138 return upload;
142 };139 };
143 return createUpload(createUploadFunc);140 return createUpload(createUploadFunc);
144141
=== modified file 'src/uploads/priv/ubuntu/uploads/manager.h'
--- src/uploads/priv/ubuntu/uploads/manager.h 2014-03-03 23:28:01 +0000
+++ src/uploads/priv/ubuntu/uploads/manager.h 2014-05-13 08:50:47 +0000
@@ -64,9 +64,7 @@
64 QDBusObjectPath createMmsUpload(const QString& url,64 QDBusObjectPath createMmsUpload(const QString& url,
65 const QString& file,65 const QString& file,
66 const QString& hostname,66 const QString& hostname,
67 int port,67 int port);
68 const QString& username,
69 const QString& password);
70 QDBusObjectPath createUpload(const QString& url,68 QDBusObjectPath createUpload(const QString& url,
71 const QString& filePath,69 const QString& filePath,
72 const QVariantMap& metadata,70 const QVariantMap& metadata,
7371
=== modified file 'src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp'
--- src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp 2014-02-26 19:54:31 +0000
+++ src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.cpp 2014-05-13 08:50:47 +0000
@@ -44,11 +44,11 @@
44 QMetaObject::invokeMethod(parent(), "allowMobileUpload", Q_ARG(bool, allowed));44 QMetaObject::invokeMethod(parent(), "allowMobileUpload", Q_ARG(bool, allowed));
45}45}
4646
47QDBusObjectPath UploadManagerAdaptor::createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port, const QString &username, const QString &password)47QDBusObjectPath UploadManagerAdaptor::createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port)
48{48{
49 // handle method call com.canonical.applications.UploadManager.createMmsUpload49 // handle method call com.canonical.applications.UploadManager.createMmsUpload
50 QDBusObjectPath uploadPath;50 QDBusObjectPath uploadPath;
51 QMetaObject::invokeMethod(parent(), "createMmsUpload", Q_RETURN_ARG(QDBusObjectPath, uploadPath), Q_ARG(QString, url), Q_ARG(QString, file), Q_ARG(QString, hostname), Q_ARG(int, port), Q_ARG(QString, username), Q_ARG(QString, password));51 QMetaObject::invokeMethod(parent(), "createMmsUpload", Q_RETURN_ARG(QDBusObjectPath, uploadPath), Q_ARG(QString, url), Q_ARG(QString, file), Q_ARG(QString, hostname), Q_ARG(int, port));
52 return uploadPath;52 return uploadPath;
53}53}
5454
5555
=== modified file 'src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h'
--- src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h 2014-02-26 19:54:31 +0000
+++ src/uploads/priv/ubuntu/uploads/upload_manager_adaptor.h 2014-05-13 08:50:47 +0000
@@ -50,8 +50,6 @@
50" <arg direction=\"in\" type=\"s\" name=\"file\"/>\n"50" <arg direction=\"in\" type=\"s\" name=\"file\"/>\n"
51" <arg direction=\"in\" type=\"s\" name=\"hostname\"/>\n"51" <arg direction=\"in\" type=\"s\" name=\"hostname\"/>\n"
52" <arg direction=\"in\" type=\"i\" name=\"port\"/>\n"52" <arg direction=\"in\" type=\"i\" name=\"port\"/>\n"
53" <arg direction=\"in\" type=\"s\" name=\"username\"/>\n"
54" <arg direction=\"in\" type=\"s\" name=\"password\"/>\n"
55" <arg direction=\"out\" type=\"o\" name=\"uploadPath\"/>\n"53" <arg direction=\"out\" type=\"o\" name=\"uploadPath\"/>\n"
56" </method>\n"54" </method>\n"
57" <method name=\"getAllUploads\">\n"55" <method name=\"getAllUploads\">\n"
@@ -87,7 +85,7 @@
87public: // PROPERTIES85public: // PROPERTIES
88public Q_SLOTS: // METHODS86public Q_SLOTS: // METHODS
89 void allowMobileUpload(bool allowed);87 void allowMobileUpload(bool allowed);
90 QDBusObjectPath createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port, const QString &username, const QString &password);88 QDBusObjectPath createMmsUpload(const QString &url, const QString &file, const QString &hostname, int port);
91 QDBusObjectPath createUpload(UploadStruct upload);89 QDBusObjectPath createUpload(UploadStruct upload);
92 qulonglong defaultThrottle();90 qulonglong defaultThrottle();
93 void exit();91 void exit();

Subscribers

People subscribed via source and target branches