diff --git a/services/sync/modules/dav.js b/services/sync/modules/dav.js index ceb2f2860fe..bec181c789c 100644 --- a/services/sync/modules/dav.js +++ b/services/sync/modules/dav.js @@ -253,6 +253,14 @@ DAVCollection.prototype = { return this._makeRequest.async(this, onComplete, "POST", path, this._defaultHeaders, data); }, + + formPost: function DC_formPOST(path, data, onComplete) { + let headers = {'Content-type': 'application/x-www-form-urlencoded'}; + headers.__proto__ = this._defaultHeaders; + + return this._makeRequest.async(this, onComplete, "POST", path, + headers, data); + }, PUT: function DC_PUT(path, data, onComplete) { return this._makeRequest.async(this, onComplete, "PUT", path, diff --git a/services/sync/modules/engines/bookmarks.js b/services/sync/modules/engines/bookmarks.js index 623de6d9d0a..a9733873b2f 100644 --- a/services/sync/modules/engines/bookmarks.js +++ b/services/sync/modules/engines/bookmarks.js @@ -20,6 +20,7 @@ * Contributor(s): * Dan Mills * Jono DiCarlo + * Anant Narayanan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -290,6 +291,34 @@ BookmarksSharingManager.prototype = { self.done( true ); }, + /* FIXME! Gets all shares, not just the new ones. Doesn't impact + functionality because _incomingShareOffer does not create + duplicates, but annoys the user by showing notification of ALL + shares on EVERY sync :( + */ + getNewShares: function BmkSharing_getNewShares(onComplete) { + this._getNewShares.async(this, onComplete); + }, + _getNewShares: function BmkSharing__getNewShares() { + let self = yield; + + let sharingApi = new Sharing.Api( DAV ); + let result = yield sharingApi.getShares(self.cb); + + this._log.info("Got Shares: " + result); + let shares = result.split(','); + if (shares.length > 1) { + this._log.info('Found shares'); + for (var i = 0; i < shares.length - 1; i++) { + let share = shares[i].split(':'); + let name = share[0]; + let user = share[1]; + let path = share[2]; + this._incomingShareOffer(user, '/user/' + user + '/' + path, name); + } + } + }, + updateAllIncomingShares: function BmkSharing_updateAllIncoming(onComplete) { this._updateAllIncomingShares.async(this, onComplete); }, @@ -436,8 +465,9 @@ BookmarksSharingManager.prototype = { // Call Atul's js api for setting htaccess: let sharingApi = new Sharing.Api( DAV ); let result = yield sharingApi.shareWithUsers( serverPath, - [username], + [username], folderName, self.cb ); + this._log.info(result.errorText); // return the server path: self.done( serverPath ); }, @@ -725,6 +755,7 @@ BookmarksEngine.prototype = { /* After syncing the regular bookmark folder contents, * also update both the incoming and outgoing shared folders. */ let self = yield; + let ret = yield this._sharing.getNewShares(self.cb); this.__proto__.__proto__._sync.async(this, self.cb ); yield; this._sharing.updateAllOutgoingShares(self.cb); diff --git a/services/sync/modules/sharing.js b/services/sync/modules/sharing.js index 794febc5d8c..787deff99a6 100644 --- a/services/sync/modules/sharing.js +++ b/services/sync/modules/sharing.js @@ -19,6 +19,7 @@ * * Contributor(s): * Atul Varma + * Anant Narayanan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -50,14 +51,29 @@ function Api(dav) { } Api.prototype = { - shareWithUsers: function Api_shareWithUsers(path, users, onComplete) { - this._shareGenerator.async(this, + shareWithUsers: function Api_shareWithUsers(path, users, folder, onComplete) { + return this._shareGenerator.async(this, onComplete, path, - users); + users, folder); }, - _shareGenerator: function Api__shareGenerator(path, users) { + getShares: function Api_getShares(onComplete) { + return this._getShareGenerator.async(this, onComplete); + }, + + _getShareGenerator: function Api__getShareGenerator() { + let self = yield; + let id = ID.get(this._dav.identity); + + this._dav.formPost("/api/share/get.php", ("uid=" + escape(id.username) + + "&password=" + escape(id.password)), + self.cb); + let xhr = yield; + self.done(xhr.responseText); + }, + + _shareGenerator: function Api__shareGenerator(path, users, folder) { let self = yield; let id = ID.get(this._dav.identity); @@ -67,10 +83,11 @@ Api.prototype = { let jsonSvc = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); let json = jsonSvc.encode(cmd); - this._dav.POST("/api/share/", + this._dav.formPost("/api/share/", ("cmd=" + escape(json) + "&uid=" + escape(id.username) + - "&password=" + escape(id.password)), + "&password=" + escape(id.password) + + "&name=" + escape(folder)), self.cb); let xhr = yield;