| 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 10 matching lines...) Expand all  Loading... | 
| 21  * @fileOverview FilterStorage class responsible for managing user's | 21  * @fileOverview FilterStorage class responsible for managing user's | 
| 22  *               subscriptions and filters. | 22  *               subscriptions and filters. | 
| 23  */ | 23  */ | 
| 24 | 24 | 
| 25 const {IO} = require("io"); | 25 const {IO} = require("io"); | 
| 26 const {Prefs} = require("prefs"); | 26 const {Prefs} = require("prefs"); | 
| 27 const {Filter, ActiveFilter} = require("./filterClasses"); | 27 const {Filter, ActiveFilter} = require("./filterClasses"); | 
| 28 const {Subscription, SpecialSubscription, | 28 const {Subscription, SpecialSubscription, | 
| 29        ExternalSubscription} = require("./subscriptionClasses"); | 29        ExternalSubscription} = require("./subscriptionClasses"); | 
| 30 const {FilterNotifier} = require("./filterNotifier"); | 30 const {FilterNotifier} = require("./filterNotifier"); | 
|  | 31 const {INIParser} = require("./iniParser"); | 
| 31 | 32 | 
| 32 /** | 33 /** | 
| 33  * Version number of the filter storage file format. | 34  * Version number of the filter storage file format. | 
| 34  * @type {number} | 35  * @type {number} | 
| 35  */ | 36  */ | 
| 36 let formatVersion = 5; | 37 let formatVersion = 5; | 
| 37 | 38 | 
| 38 /** | 39 /** | 
| 39  * This class reads user's filters from disk, manages them in memory | 40  * This class reads user's filters from disk, manages them in memory | 
| 40  * and writes them back. | 41  * and writes them back. | 
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 673  * @param {Subscription} subscription filter subscription to be removed | 674  * @param {Subscription} subscription filter subscription to be removed | 
| 674  */ | 675  */ | 
| 675 function removeSubscriptionFilters(subscription) | 676 function removeSubscriptionFilters(subscription) | 
| 676 { | 677 { | 
| 677   if (!FilterStorage.knownSubscriptions.has(subscription.url)) | 678   if (!FilterStorage.knownSubscriptions.has(subscription.url)) | 
| 678     return; | 679     return; | 
| 679 | 680 | 
| 680   for (let filter of subscription.filters) | 681   for (let filter of subscription.filters) | 
| 681     filter.subscriptions.delete(subscription); | 682     filter.subscriptions.delete(subscription); | 
| 682 } | 683 } | 
| 683 |  | 
| 684 /** |  | 
| 685  * Listener returned by FilterStorage.importData(), parses filter data. |  | 
| 686  * @constructor |  | 
| 687  */ |  | 
| 688 function INIParser() |  | 
| 689 { |  | 
| 690   this.fileProperties = this.curObj = {}; |  | 
| 691   this.subscriptions = []; |  | 
| 692   this.knownFilters = new Map(); |  | 
| 693   this.knownSubscriptions = new Map(); |  | 
| 694 } |  | 
| 695 INIParser.prototype = |  | 
| 696 { |  | 
| 697   linesProcessed: 0, |  | 
| 698   subscriptions: null, |  | 
| 699   knownFilters: null, |  | 
| 700   knownSubscriptions: null, |  | 
| 701   wantObj: true, |  | 
| 702   fileProperties: null, |  | 
| 703   curObj: null, |  | 
| 704   curSection: null, |  | 
| 705 |  | 
| 706   process(val) |  | 
| 707   { |  | 
| 708     let origKnownFilters = Filter.knownFilters; |  | 
| 709     Filter.knownFilters = this.knownFilters; |  | 
| 710     let origKnownSubscriptions = Subscription.knownSubscriptions; |  | 
| 711     Subscription.knownSubscriptions = this.knownSubscriptions; |  | 
| 712     let match; |  | 
| 713     try |  | 
| 714     { |  | 
| 715       if (this.wantObj === true && (match = /^(\w+)=(.*)$/.exec(val))) |  | 
| 716         this.curObj[match[1]] = match[2]; |  | 
| 717       else if (val === null || (match = /^\s*\[(.+)\]\s*$/.exec(val))) |  | 
| 718       { |  | 
| 719         if (this.curObj) |  | 
| 720         { |  | 
| 721           // Process current object before going to next section |  | 
| 722           switch (this.curSection) |  | 
| 723           { |  | 
| 724             case "filter": |  | 
| 725               if ("text" in this.curObj) |  | 
| 726                 Filter.fromObject(this.curObj); |  | 
| 727               break; |  | 
| 728             case "subscription": { |  | 
| 729               let subscription = Subscription.fromObject(this.curObj); |  | 
| 730               if (subscription) |  | 
| 731                 this.subscriptions.push(subscription); |  | 
| 732               break; |  | 
| 733             } |  | 
| 734             case "subscription filters": |  | 
| 735               if (this.subscriptions.length) |  | 
| 736               { |  | 
| 737                 let subscription = this.subscriptions[ |  | 
| 738                   this.subscriptions.length - 1 |  | 
| 739                 ]; |  | 
| 740                 for (let text of this.curObj) |  | 
| 741                 { |  | 
| 742                   let filter = Filter.fromText(text); |  | 
| 743                   subscription.filters.push(filter); |  | 
| 744                   filter.subscriptions.add(subscription); |  | 
| 745                 } |  | 
| 746               } |  | 
| 747               break; |  | 
| 748           } |  | 
| 749         } |  | 
| 750 |  | 
| 751         if (val === null) |  | 
| 752           return; |  | 
| 753 |  | 
| 754         this.curSection = match[1].toLowerCase(); |  | 
| 755         switch (this.curSection) |  | 
| 756         { |  | 
| 757           case "filter": |  | 
| 758           case "subscription": |  | 
| 759             this.wantObj = true; |  | 
| 760             this.curObj = {}; |  | 
| 761             break; |  | 
| 762           case "subscription filters": |  | 
| 763             this.wantObj = false; |  | 
| 764             this.curObj = []; |  | 
| 765             break; |  | 
| 766           default: |  | 
| 767             this.wantObj = null; |  | 
| 768             this.curObj = null; |  | 
| 769         } |  | 
| 770       } |  | 
| 771       else if (this.wantObj === false && val) |  | 
| 772         this.curObj.push(val.replace(/\\\[/g, "[")); |  | 
| 773     } |  | 
| 774     finally |  | 
| 775     { |  | 
| 776       Filter.knownFilters = origKnownFilters; |  | 
| 777       Subscription.knownSubscriptions = origKnownSubscriptions; |  | 
| 778     } |  | 
| 779   } |  | 
| 780 }; |  | 
| OLD | NEW | 
|---|