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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/subscription/DownloadableSubscription.h ('k') | compiled/subscription/Subscription.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/subscription/DownloadableSubscription.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/subscription/DownloadableSubscription.cpp
@@ -0,0 +1,110 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2017 eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "DownloadableSubscription.h"
+
+DownloadableSubscription::DownloadableSubscription(const String& id)
+ : Subscription(Type::DOWNLOADABLE, id), mFixedTitle(false), mLastCheck(0),
+ mHardExpiration(0), mSoftExpiration(0), mLastDownload(0), mLastSuccess(0),
+ mErrorCount(0), mDataRevision(0), mDownloadCount(0)
+{
+ SetTitle(id);
+}
+
+OwnedString DownloadableSubscription::Serialize() const
+{
+ OwnedString result(Subscription::Serialize());
+ const std::size_t BUFFER_SIZE = 32;
+ char buffer[BUFFER_SIZE];
+ if (mFixedTitle)
+ result.append(u"fixedTitle=true\n"_str);
+ if (!mHomepage.empty())
+ {
+ result.append(u"homepage="_str);
+ result.append(mHomepage);
+ result.append(u'\n');
+ }
+ if (mLastCheck)
+ {
+ result.append(u"lastCheck="_str);
+ int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mLastCheck);
+ result.append(buffer, len);
+ result.append(u'\n');
+ }
+ if (mHardExpiration)
+ {
+ result.append(u"expires="_str);
+ int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mHardExpiration);
+ result.append(buffer, len);
+ result.append(u'\n');
+ }
+ if (mSoftExpiration)
+ {
+ result.append(u"softExpiration="_str);
+ int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mSoftExpiration);
+ result.append(buffer, len);
+ result.append(u'\n');
+ }
+ if (mLastDownload)
+ {
+ result.append(u"lastDownload="_str);
+ int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mLastDownload);
+ result.append(buffer, len);
+ result.append(u'\n');
+ }
+ if (!mDownloadStatus.empty())
+ {
+ result.append(u"downloadStatus="_str);
+ result.append(mDownloadStatus);
+ result.append(u'\n');
+ }
+ if (mLastSuccess)
+ {
+ result.append(u"lastSuccess="_str);
+ int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mLastSuccess);
+ result.append(buffer, len);
+ result.append(u'\n');
+ }
+ if (mErrorCount)
+ {
+ result.append(u"errors="_str);
+ int len = snprintf(buffer, BUFFER_SIZE, "%i", mErrorCount);
+ result.append(buffer, len);
+ result.append(u'\n');
+ }
+ if (mDataRevision)
+ {
+ result.append(u"version="_str);
+ int len = snprintf(buffer, BUFFER_SIZE, "%.0f", mDataRevision);
+ result.append(buffer, len);
+ result.append(u'\n');
+ }
+ if (!mRequiredVersion.empty())
+ {
+ result.append(u"requiredVersion="_str);
+ result.append(mRequiredVersion);
+ result.append(u'\n');
+ }
+ if (mDownloadCount)
+ {
+ result.append(u"downloadCount="_str);
+ int len = snprintf(buffer, BUFFER_SIZE, "%i", mDownloadCount);
+ result.append(buffer, len);
+ result.append(u'\n');
+ }
+ return result;
+}
« 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