| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include <cstdio> | 18 #include <cstdio> |
| 19 #include <cstdlib> | 19 #include <cstdlib> |
| 20 #include <random> |
| 20 | 21 |
| 21 #include "Subscription.h" | 22 #include "Subscription.h" |
| 22 #include "DownloadableSubscription.h" | 23 #include "DownloadableSubscription.h" |
| 23 #include "UserDefinedSubscription.h" | 24 #include "UserDefinedSubscription.h" |
| 24 #include "../StringMap.h" | 25 #include "../StringMap.h" |
| 25 | 26 |
| 26 ABP_NS_USING | 27 ABP_NS_USING |
| 27 | 28 |
| 28 namespace | 29 namespace |
| 29 { | 30 { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 result.append(u'\n'); | 89 result.append(u'\n'); |
| 89 } | 90 } |
| 90 return result; | 91 return result; |
| 91 } | 92 } |
| 92 | 93 |
| 93 Subscription* Subscription::FromID(const String& id) | 94 Subscription* Subscription::FromID(const String& id) |
| 94 { | 95 { |
| 95 if (id.empty()) | 96 if (id.empty()) |
| 96 { | 97 { |
| 97 // Generate a new random ID | 98 // Generate a new random ID |
| 98 unsigned int seed = knownSubscriptions.size(); | 99 std::mt19937 gen(knownSubscriptions.size()); |
| 99 OwnedString randomID(u"~user~000000"_str); | 100 OwnedString randomID(u"~user~000000"_str); |
| 100 do | 101 do |
| 101 { | 102 { |
| 102 int number = rand_r(&seed); | 103 int number = gen(); |
| 103 for (int i = randomID.length() - 6; i < randomID.length(); i++) | 104 for (int i = randomID.length() - 6; i < randomID.length(); i++) |
| 104 { | 105 { |
| 105 randomID[i] = '0' + (number % 10); | 106 randomID[i] = '0' + (number % 10); |
| 106 number /= 10; | 107 number /= 10; |
| 107 } | 108 } |
| 108 } while (knownSubscriptions.find(randomID)); | 109 } while (knownSubscriptions.find(randomID)); |
| 109 return FromID(randomID); | 110 return FromID(randomID); |
| 110 } | 111 } |
| 111 | 112 |
| 112 auto knownSubscription = knownSubscriptions.find(id); | 113 auto knownSubscription = knownSubscriptions.find(id); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 124 | 125 |
| 125 // This is a hack: we looked up the entry using id but create it using | 126 // This is a hack: we looked up the entry using id but create it using |
| 126 // subscription->mID. This works because both are equal at this point. | 127 // subscription->mID. This works because both are equal at this point. |
| 127 // However, id refers to a temporary buffer which will go away. | 128 // However, id refers to a temporary buffer which will go away. |
| 128 enter_context("Adding to known subscriptions"); | 129 enter_context("Adding to known subscriptions"); |
| 129 knownSubscription.assign(subscription->mID, subscription.get()); | 130 knownSubscription.assign(subscription->mID, subscription.get()); |
| 130 exit_context(); | 131 exit_context(); |
| 131 | 132 |
| 132 return subscription.release(); | 133 return subscription.release(); |
| 133 } | 134 } |
| OLD | NEW |