LEFT | RIGHT |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
1 #include <cstdio> | 18 #include <cstdio> |
2 #include <cstdlib> | 19 #include <cstdlib> |
3 | 20 |
4 #include "Subscription.h" | 21 #include "Subscription.h" |
5 #include "DownloadableSubscription.h" | 22 #include "DownloadableSubscription.h" |
6 #include "UserDefinedSubscription.h" | 23 #include "UserDefinedSubscription.h" |
7 #include "../StringMap.h" | 24 #include "../StringMap.h" |
8 | 25 |
9 namespace | 26 namespace |
10 { | 27 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 { | 60 { |
44 // TODO | 61 // TODO |
45 return OwnedString(); | 62 return OwnedString(); |
46 } | 63 } |
47 | 64 |
48 Subscription* Subscription::FromID(const String& id) | 65 Subscription* Subscription::FromID(const String& id) |
49 { | 66 { |
50 if (id.empty()) | 67 if (id.empty()) |
51 { | 68 { |
52 // Generate a new random ID | 69 // Generate a new random ID |
53 unsigned seed = knownSubscriptions.length(); | 70 unsigned int seed = knownSubscriptions.size(); |
54 OwnedString randomID(u"~user~000000"_str); | 71 OwnedString randomID(u"~user~000000"_str); |
55 do | 72 do |
56 { | 73 { |
57 int number = rand_r(&seed); | 74 int number = rand_r(&seed); |
58 for (int i = randomID.length() - 6; i < randomID.length(); i++) | 75 for (int i = randomID.length() - 6; i < randomID.length(); i++) |
59 { | 76 { |
60 randomID[i] = '0' + (number % 10); | 77 randomID[i] = '0' + (number % 10); |
61 number /= 10; | 78 number /= 10; |
62 } | 79 } |
63 } while (knownSubscriptions.find(randomID)); | 80 } while (knownSubscriptions.find(randomID)); |
(...skipping 15 matching lines...) Expand all Loading... |
79 | 96 |
80 // 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 |
81 // subscription->mID. This works because both are equal at this point. | 98 // subscription->mID. This works because both are equal at this point. |
82 // However, id refers to a temporary buffer which will go away. | 99 // However, id refers to a temporary buffer which will go away. |
83 enter_context("Adding to known subscriptions"); | 100 enter_context("Adding to known subscriptions"); |
84 knownSubscription.assign(subscription->mID, subscription.get()); | 101 knownSubscription.assign(subscription->mID, subscription.get()); |
85 exit_context(); | 102 exit_context(); |
86 | 103 |
87 return subscription.release(); | 104 return subscription.release(); |
88 } | 105 } |
LEFT | RIGHT |