Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: compiled/subscription/DownloadableSubscription.cpp

Issue 29384812: Issue 4127 - [emscripten] Convert subscription classes to C++ - Part 1 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Safe buffer manipulation Created April 4, 2017, 2:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/subscription/DownloadableSubscription.h ('k') | compiled/subscription/Subscription.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
18 #include "DownloadableSubscription.h"
19
20 DownloadableSubscription::DownloadableSubscription(const String& id)
21 : Subscription(Type::DOWNLOADABLE, id), mFixedTitle(false), mLastCheck(0),
22 mHardExpiration(0), mSoftExpiration(0), mLastDownload(0), mLastSuccess(0),
23 mErrorCount(0), mDataRevision(0), mDownloadCount(0)
24 {
25 SetTitle(id);
26 }
27
28 OwnedString DownloadableSubscription::Serialize() const
29 {
30 OwnedString result(Subscription::Serialize());
31 const std::size_t BUFFER_SIZE = 32;
32 char buffer[BUFFER_SIZE];
33 if (mFixedTitle)
34 result.append(u"fixedTitle=true\n"_str);
35 if (!mHomepage.empty())
36 {
37 result.append(u"homepage="_str);
38 result.append(mHomepage);
39 result.append(u'\n');
40 }
41 if (mLastCheck)
42 {
43 result.append(u"lastCheck="_str);
44 int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mLastCheck);
45 result.append(buffer, len);
46 result.append(u'\n');
47 }
48 if (mHardExpiration)
49 {
50 result.append(u"expires="_str);
51 int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mHardExpiration);
52 result.append(buffer, len);
53 result.append(u'\n');
54 }
55 if (mSoftExpiration)
56 {
57 result.append(u"softExpiration="_str);
58 int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mSoftExpiration);
59 result.append(buffer, len);
60 result.append(u'\n');
61 }
62 if (mLastDownload)
63 {
64 result.append(u"lastDownload="_str);
65 int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mLastDownload);
66 result.append(buffer, len);
67 result.append(u'\n');
68 }
69 if (!mDownloadStatus.empty())
70 {
71 result.append(u"downloadStatus="_str);
72 result.append(mDownloadStatus);
73 result.append(u'\n');
74 }
75 if (mLastSuccess)
76 {
77 result.append(u"lastSuccess="_str);
78 int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mLastSuccess);
79 result.append(buffer, len);
80 result.append(u'\n');
81 }
82 if (mErrorCount)
83 {
84 result.append(u"errors="_str);
85 int len = snprintf(buffer, BUFFER_SIZE, "%i", mErrorCount);
86 result.append(buffer, len);
87 result.append(u'\n');
88 }
89 if (mDataRevision)
90 {
91 result.append(u"version="_str);
92 int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mDataRevision);
93 result.append(buffer, len);
94 result.append(u'\n');
95 }
96 if (!mRequiredVersion.empty())
97 {
98 result.append(u"requiredVersion="_str);
99 result.append(mRequiredVersion);
100 result.append(u'\n');
101 }
102 if (mDownloadCount)
103 {
104 result.append(u"downloadCount="_str);
105 int len = snprintf(buffer, BUFFER_SIZE, "%i", mDownloadCount);
106 result.append(buffer, len);
107 result.append(u'\n');
108 }
109 return result;
110 }
OLDNEW
« no previous file with comments | « compiled/subscription/DownloadableSubscription.h ('k') | compiled/subscription/Subscription.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld