SET(LIB_CYNARA_STORAGE_SOURCES
${CYNARA_LIB_CYNARA_STORAGE_PATH}/BucketDeserializer.cpp
+ ${CYNARA_LIB_CYNARA_STORAGE_PATH}/ChecksumStream.cpp
${CYNARA_LIB_CYNARA_STORAGE_PATH}/ChecksumValidator.cpp
${CYNARA_LIB_CYNARA_STORAGE_PATH}/InMemoryStorageBackend.cpp
${CYNARA_LIB_CYNARA_STORAGE_PATH}/Integrity.cpp
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file src/storage/ChecksumStream.cpp
+ * @author Pawel Wieczorek <p.wieczorek2@samsung.com>
+ * @version 1.0
+ * @brief This file contains ChecksumStream implementation.
+ */
+
+#include <exception>
+#include <unistd.h>
+
+#include <config/PathConfig.h>
+
+#include <storage/ChecksumValidator.h>
+
+#include "ChecksumStream.h"
+
+namespace Cynara {
+
+const char ChecksumStream::m_fieldSeparator(PathConfig::StoragePath::fieldSeparator);
+const char ChecksumStream::m_recordSeparator(PathConfig::StoragePath::recordSeparator);
+
+ChecksumStream::~ChecksumStream() {
+ if (!std::uncaught_exception()) {
+ save();
+ }
+}
+
+ChecksumStream& ChecksumStream::operator<<(std::ostream& (*manip)(std::ostream&)) {
+ m_bufStream << manip;
+ m_outStream << manip;
+ return *this;
+}
+
+void ChecksumStream::open(const std::string &filename, std::ios_base::openmode mode) {
+ m_outStream.open(filename, mode);
+}
+
+bool ChecksumStream::is_open(void) const {
+ return m_outStream.is_open();
+}
+
+std::ios_base::fmtflags ChecksumStream::flags(void) const {
+ return m_outStream.flags();
+}
+
+std::ios_base::fmtflags ChecksumStream::flags(std::ios_base::fmtflags flags) {
+ return m_outStream.flags(flags);
+}
+
+void ChecksumStream::save() {
+ m_outStream.close();
+ *m_chsStream << m_filename << m_fieldSeparator << ChecksumValidator::generate(m_bufStream.str())
+ << m_recordSeparator;
+}
+
+} // namespace Cynara
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file src/storage/ChecksumStream.h
+ * @author Pawel Wieczorek <p.wieczorek2@samsung.com>
+ * @version 1.0
+ * @brief This file contains ChecksumStream header.
+ */
+
+#ifndef SRC_STORAGE_CHECKSUMSTREAM_H_
+#define SRC_STORAGE_CHECKSUMSTREAM_H_
+
+#include <fstream>
+#include <iostream>
+#include <memory>
+#include <sstream>
+#include <string>
+
+namespace Cynara {
+
+class ChecksumStream {
+public:
+ ChecksumStream(const std::string &filename, const std::shared_ptr<std::ofstream> &stream)
+ : m_chsStream(stream), m_filename(filename) {
+ }
+ ~ChecksumStream();
+
+ template<typename Type>
+ ChecksumStream& operator<<(const Type &item);
+ ChecksumStream& operator<<(std::ostream& (*manip)(std::ostream&));
+
+ void open(const std::string &filename, std::ios_base::openmode mode);
+ bool is_open(void) const;
+ std::ios_base::fmtflags flags(void) const;
+ std::ios_base::fmtflags flags(std::ios_base::fmtflags flags);
+
+private:
+ void save(void);
+
+ std::shared_ptr<std::ofstream> m_chsStream;
+ std::ofstream m_outStream;
+ std::stringstream m_bufStream;
+ const std::string m_filename;
+ static const char m_fieldSeparator;
+ static const char m_recordSeparator;
+};
+
+template<typename Type>
+ChecksumStream& ChecksumStream::operator<<(const Type& item) {
+ m_bufStream << item;
+ m_outStream << item;
+ return *this;
+}
+
+} // namespace Cynara
+
+#endif // SRC_STORAGE_CHECKSUMSTREAM_H_
${CYNARA_SRC}/helpers/creds-commons/creds-commons.cpp
${CYNARA_SRC}/service/main/CmdlineParser.cpp
${CYNARA_SRC}/storage/BucketDeserializer.cpp
+ ${CYNARA_SRC}/storage/ChecksumStream.cpp
${CYNARA_SRC}/storage/ChecksumValidator.cpp
${CYNARA_SRC}/storage/InMemoryStorageBackend.cpp
${CYNARA_SRC}/storage/Integrity.cpp