Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 { | 60 { |
61 // TODO | 61 // TODO |
62 return OwnedString(); | 62 return OwnedString(); |
63 } | 63 } |
64 | 64 |
65 Subscription* Subscription::FromID(const String& id) | 65 Subscription* Subscription::FromID(const String& id) |
66 { | 66 { |
67 if (id.empty()) | 67 if (id.empty()) |
68 { | 68 { |
69 // Generate a new random ID | 69 // Generate a new random ID |
70 unsigned seed = knownSubscriptions.size(); | 70 unsigned int seed = knownSubscriptions.size(); |
sergei
2017/04/12 12:04:33
it would be better to put "unsigned int" (int is a
Wladimir Palant
2017/04/13 13:04:41
Done.
| |
71 OwnedString randomID(u"~user~000000"_str); | 71 OwnedString randomID(u"~user~000000"_str); |
72 do | 72 do |
73 { | 73 { |
74 int number = rand_r(&seed); | 74 int number = rand_r(&seed); |
75 for (int i = randomID.length() - 6; i < randomID.length(); i++) | 75 for (int i = randomID.length() - 6; i < randomID.length(); i++) |
76 { | 76 { |
77 randomID[i] = '0' + (number % 10); | 77 randomID[i] = '0' + (number % 10); |
78 number /= 10; | 78 number /= 10; |
79 } | 79 } |
80 } while (knownSubscriptions.find(randomID)); | 80 } while (knownSubscriptions.find(randomID)); |
81 return FromID(randomID); | 81 return FromID(randomID); |
82 } | 82 } |
83 | 83 |
84 auto knownSubscription = knownSubscriptions.find(id); | 84 auto knownSubscription = knownSubscriptions.find(id); |
85 if (knownSubscription) | 85 if (knownSubscription) |
86 { | 86 { |
87 knownSubscription->second->AddRef(); | 87 knownSubscription->second->AddRef(); |
88 return knownSubscription->second; | 88 return knownSubscription->second; |
89 } | 89 } |
90 | 90 |
91 SubscriptionPtr subscription; | 91 SubscriptionPtr subscription; |
92 if (!id.empty() && id[0] == '~') | 92 if (!id.empty() && id[0] == '~') |
sergei
2017/04/12 12:04:33
id cannot be empty here, though maybe it's still g
Wladimir Palant
2017/04/13 13:04:41
No, it cannot - with the current logic. I just ver
| |
93 subscription = new UserDefinedSubscription(id); | 93 subscription = new UserDefinedSubscription(id); |
94 else | 94 else |
95 subscription = new DownloadableSubscription(id); | 95 subscription = new DownloadableSubscription(id); |
96 | 96 |
97 // This is a hack: we looked up the entry using id but create it using | 97 // This is a hack: we looked up the entry using id but create it using |
98 // subscription->mID. This works because both are equal at this point. | 98 // subscription->mID. This works because both are equal at this point. |
99 // However, id refers to a temporary buffer which will go away. | 99 // However, id refers to a temporary buffer which will go away. |
100 enter_context("Adding to known subscriptions"); | 100 enter_context("Adding to known subscriptions"); |
101 knownSubscription.assign(subscription->mID, subscription.get()); | 101 knownSubscription.assign(subscription->mID, subscription.get()); |
102 exit_context(); | 102 exit_context(); |
103 | 103 |
104 return subscription.release(); | 104 return subscription.release(); |
105 } | 105 } |
LEFT | RIGHT |