| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 2  * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| 3  * Copyright (C) 2006-present eyeo GmbH | 3  * Copyright (C) 2006-present eyeo GmbH | 
| 4  * | 4  * | 
| 5  * Adblock Plus is free software: you can redistribute it and/or modify | 5  * Adblock Plus is free software: you can redistribute it and/or modify | 
| 6  * it under the terms of the GNU General Public License version 3 as | 6  * it under the terms of the GNU General Public License version 3 as | 
| 7  * published by the Free Software Foundation. | 7  * published by the Free Software Foundation. | 
| 8  * | 8  * | 
| 9  * Adblock Plus is distributed in the hope that it will be useful, | 9  * Adblock Plus is distributed in the hope that it will be useful, | 
| 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 23 | 23 | 
| 24 const {Downloader, Downloadable, | 24 const {Downloader, Downloadable, | 
| 25        MILLIS_IN_SECOND, MILLIS_IN_MINUTE, | 25        MILLIS_IN_SECOND, MILLIS_IN_MINUTE, | 
| 26        MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("./downloader"); | 26        MILLIS_IN_HOUR, MILLIS_IN_DAY} = require("./downloader"); | 
| 27 const {Filter} = require("./filterClasses"); | 27 const {Filter} = require("./filterClasses"); | 
| 28 const {FilterStorage} = require("./filterStorage"); | 28 const {FilterStorage} = require("./filterStorage"); | 
| 29 const {FilterNotifier} = require("./filterNotifier"); | 29 const {FilterNotifier} = require("./filterNotifier"); | 
| 30 const {Prefs} = require("prefs"); | 30 const {Prefs} = require("prefs"); | 
| 31 const {Subscription, | 31 const {Subscription, | 
| 32        DownloadableSubscription} = require("./subscriptionClasses"); | 32        DownloadableSubscription} = require("./subscriptionClasses"); | 
| 33 const {Utils} = require("utils"); |  | 
| 34 | 33 | 
| 35 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; | 34 const INITIAL_DELAY = 1 * MILLIS_IN_MINUTE; | 
| 36 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; | 35 const CHECK_INTERVAL = 1 * MILLIS_IN_HOUR; | 
| 37 const DEFAULT_EXPIRATION_INTERVAL = 5 * MILLIS_IN_DAY; | 36 const DEFAULT_EXPIRATION_INTERVAL = 5 * MILLIS_IN_DAY; | 
| 38 | 37 | 
| 39 /** | 38 /** | 
| 40  * The object providing actual downloading functionality. | 39  * The object providing actual downloading functionality. | 
| 41  * @type {Downloader} | 40  * @type {Downloader} | 
| 42  */ | 41  */ | 
| 43 let downloader = null; | 42 let downloader = null; | 
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 147 | 146 | 
| 148   _onDownloadSuccess(downloadable, responseText, errorCallback, | 147   _onDownloadSuccess(downloadable, responseText, errorCallback, | 
| 149                      redirectCallback) | 148                      redirectCallback) | 
| 150   { | 149   { | 
| 151     let lines = responseText.split(/[\r\n]+/); | 150     let lines = responseText.split(/[\r\n]+/); | 
| 152     let headerMatch = /\[Adblock(?:\s*Plus\s*([\d.]+)?)?\]/i.exec(lines[0]); | 151     let headerMatch = /\[Adblock(?:\s*Plus\s*([\d.]+)?)?\]/i.exec(lines[0]); | 
| 153     if (!headerMatch) | 152     if (!headerMatch) | 
| 154       return errorCallback("synchronize_invalid_data"); | 153       return errorCallback("synchronize_invalid_data"); | 
| 155     let minVersion = headerMatch[1]; | 154     let minVersion = headerMatch[1]; | 
| 156 | 155 | 
| 157     // Don't remove parameter comments immediately but add them to a list first, |  | 
| 158     // they need to be considered in the checksum calculation. |  | 
| 159     let remove = []; |  | 
| 160     let params = { | 156     let params = { | 
| 161       redirect: null, | 157       redirect: null, | 
| 162       homepage: null, | 158       homepage: null, | 
| 163       title: null, | 159       title: null, | 
| 164       version: null, | 160       version: null, | 
| 165       expires: null | 161       expires: null | 
| 166     }; | 162     }; | 
| 167     for (let i = 0; i < lines.length; i++) | 163     for (let i = 0; i < lines.length; i++) | 
| 168     { | 164     { | 
| 169       let match = /^\s*!\s*(\w+)\s*:\s*(.*)/.exec(lines[i]); | 165       let match = /^\s*!\s*(\w+)\s*:\s*(.*)/.exec(lines[i]); | 
| 170       if (match) | 166       if (match) | 
| 171       { | 167       { | 
| 172         let keyword = match[1].toLowerCase(); | 168         let keyword = match[1].toLowerCase(); | 
| 173         let value = match[2]; | 169         let value = match[2]; | 
| 174         if (keyword in params) | 170         if (keyword in params) | 
| 175         { | 171         { | 
| 176           params[keyword] = value; | 172           params[keyword] = value; | 
| 177           remove.push(i); |  | 
| 178         } |  | 
| 179         else if (keyword == "checksum") |  | 
| 180         { |  | 
| 181           lines.splice(i--, 1); | 173           lines.splice(i--, 1); | 
| 182           let checksum = Utils.generateChecksum(lines); |  | 
| 183           if (checksum && checksum != value.replace(/=+$/, "")) |  | 
| 184             return errorCallback("synchronize_checksum_mismatch"); |  | 
| 185         } | 174         } | 
| 186       } | 175       } | 
| 187     } | 176     } | 
| 188 | 177 | 
| 189     if (params.redirect) | 178     if (params.redirect) | 
| 190       return redirectCallback(params.redirect); | 179       return redirectCallback(params.redirect); | 
| 191 | 180 | 
| 192     // Handle redirects | 181     // Handle redirects | 
| 193     let subscription = Subscription.fromURL(downloadable.redirectURL || | 182     let subscription = Subscription.fromURL(downloadable.redirectURL || | 
| 194                                             downloadable.url); | 183                                             downloadable.url); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 211     } | 200     } | 
| 212 | 201 | 
| 213     // The download actually succeeded | 202     // The download actually succeeded | 
| 214     subscription.lastSuccess = subscription.lastDownload = Math.round( | 203     subscription.lastSuccess = subscription.lastDownload = Math.round( | 
| 215       Date.now() / MILLIS_IN_SECOND | 204       Date.now() / MILLIS_IN_SECOND | 
| 216     ); | 205     ); | 
| 217     subscription.downloadStatus = "synchronize_ok"; | 206     subscription.downloadStatus = "synchronize_ok"; | 
| 218     subscription.downloadCount = downloadable.downloadCount; | 207     subscription.downloadCount = downloadable.downloadCount; | 
| 219     subscription.errors = 0; | 208     subscription.errors = 0; | 
| 220 | 209 | 
| 221     // Remove lines containing parameters |  | 
| 222     for (let i = remove.length - 1; i >= 0; i--) |  | 
| 223       lines.splice(remove[i], 1); |  | 
| 224 |  | 
| 225     // Process parameters | 210     // Process parameters | 
| 226     if (params.homepage) | 211     if (params.homepage) | 
| 227     { | 212     { | 
| 228       let url; | 213       let url; | 
| 229       try | 214       try | 
| 230       { | 215       { | 
| 231         url = new URL(params.homepage); | 216         url = new URL(params.homepage); | 
| 232       } | 217       } | 
| 233       catch (e) | 218       catch (e) | 
| 234       { | 219       { | 
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 348               subscription.filters.map(f => f.text).join("\n"); | 333               subscription.filters.map(f => f.text).join("\n"); | 
| 349             redirectCallback("data:text/plain," + encodeURIComponent(data)); | 334             redirectCallback("data:text/plain," + encodeURIComponent(data)); | 
| 350           } | 335           } | 
| 351         }, false); | 336         }, false); | 
| 352         request.send(null); | 337         request.send(null); | 
| 353       } | 338       } | 
| 354     } | 339     } | 
| 355   } | 340   } | 
| 356 }; | 341 }; | 
| 357 Synchronizer.init(); | 342 Synchronizer.init(); | 
| OLD | NEW | 
|---|