Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BasedOnStyle: Google
ColumnLimit: 100

IncludeCategories:
- Regex: '^".*\.h"'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<ext/.*\.h>'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 4
SortPriority: 0
CaseSensitive: false

AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
BinPackArguments: false
BinPackParameters: false
7 changes: 3 additions & 4 deletions src/zm_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "zm_line.h"
#include "zm_vector2.h"

#include <cmath>
#include <vector>

Expand Down Expand Up @@ -49,9 +50,7 @@ class Box {
}

// Get vertices of the box in a counter-clockwise order
std::vector<Vector2> Vertices() const {
return {lo_, {hi_.x_, lo_.y_}, hi_, {lo_.x_, hi_.y_}};
}
std::vector<Vector2> Vertices() const { return {lo_, {hi_.x_, lo_.y_}, hi_, {lo_.x_, hi_.y_}}; }

// Get edges of the box in a counter-clockwise order
std::vector<LineSegment> Edges() const {
Expand All @@ -77,4 +76,4 @@ class Box {
Vector2 size_;
};

#endif // ZM_BOX_H
#endif // ZM_BOX_H
17 changes: 9 additions & 8 deletions src/zm_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "zm_crypto_gnutls.h"
#include "zm_crypto_openssl.h"
#include "zm_define.h"

#include <string>

bool verifyPassword(const char *username, const char *input_password, const char *db_password_hash);
Expand All @@ -37,21 +38,21 @@ namespace crypto {
namespace impl {

#if defined(HAVE_LIBGNUTLS)
template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
using Hash = gnutls::GenericHashImpl<Algorithm>;
#elif defined(HAVE_LIBOPENSSL)
template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
using Hash = openssl::GenericHashImpl<Algorithm>;
#endif
}
}
}
} // namespace impl
} // namespace crypto
} // namespace zm

namespace zm {
namespace crypto {
using MD5 = impl::Hash<impl::HashAlgorithms::kMD5>;
using SHA1 = impl::Hash<impl::HashAlgorithms::kSHA1>;
}
}
} // namespace crypto
} // namespace zm

#endif // ZM_CRYPT_H
#endif // ZM_CRYPT_H
38 changes: 17 additions & 21 deletions src/zm_crypto_generics.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,30 @@

#include "zm_define.h"
#include "zm_utils.h"

#include <array>
#include <cstring>

namespace zm {
namespace crypto {
namespace impl {

enum class HashAlgorithms {
kMD5,
kSHA1
};
enum class HashAlgorithms { kMD5, kSHA1 };

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
struct HashAlgorithm;

template<>
template <>
struct HashAlgorithm<HashAlgorithms::kMD5> {
static constexpr size_t digest_length = 16;
};

template<>
template <>
struct HashAlgorithm<HashAlgorithms::kSHA1> {
static constexpr size_t digest_length = 20;
};

template<typename Impl, HashAlgorithms Algorithm>
template <typename Impl, HashAlgorithms Algorithm>
class GenericHash {
public:
static constexpr size_t DIGEST_LENGTH = HashAlgorithm<Algorithm>::digest_length;
Expand All @@ -58,8 +56,8 @@ class GenericHash {
return hash.GetDigest();
}

template<typename... Ts>
static Digest GetDigestOf(Ts &&... pack) {
template <typename... Ts>
static Digest GetDigestOf(Ts &&...pack) {
Impl hash;
UpdateData(hash, std::forward<Ts>(pack)...);
hash.Finalize();
Expand All @@ -75,34 +73,32 @@ class GenericHash {
void UpdateData(const char *str) {
UpdateData(reinterpret_cast<const uint8 *>(str), strlen(str));
}
template<typename Container>
template <typename Container>
void UpdateData(Container const &c) {
UpdateData(zm::data(c), zm::size(c));
}

void Finalize() {
static_cast<Impl &>(*this).DoFinalize();
}
void Finalize() { static_cast<Impl &>(*this).DoFinalize(); }

const Digest &GetDigest() const { return digest_; }

protected:
Digest digest_ = {};

private:
template<typename T>
template <typename T>
static void UpdateData(Impl &hash, T const &data) {
hash.UpdateData(data);
}

template<typename T, typename... TRest>
static void UpdateData(Impl &hash, T const &data, TRest &&... rest) {
template <typename T, typename... TRest>
static void UpdateData(Impl &hash, T const &data, TRest &&...rest) {
hash.UpdateData(data);
UpdateData(hash, std::forward<TRest>(rest)...);
}
};
}
}
}
} // namespace impl
} // namespace crypto
} // namespace zm

#endif //ZONEMINDER_SRC_ZM_CRYPTO_GENERICS_H_
#endif // ZONEMINDER_SRC_ZM_CRYPTO_GENERICS_H_
25 changes: 12 additions & 13 deletions src/zm_crypto_gnutls.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,28 @@

#include "zm_crypto_generics.h"
#include "zm_utils.h"

#include <gnutls/crypto.h>

namespace zm {
namespace crypto {
namespace impl {
namespace gnutls {

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
struct HashAlgorithmMapper;

template<>
template <>
struct HashAlgorithmMapper<HashAlgorithms::kMD5> {
static constexpr gnutls_digest_algorithm_t algorithm = GNUTLS_DIG_MD5;
};

template<>
template <>
struct HashAlgorithmMapper<HashAlgorithms::kSHA1> {
static constexpr gnutls_digest_algorithm_t algorithm = GNUTLS_DIG_SHA1;
};

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
class GenericHashImpl : public GenericHash<GenericHashImpl<Algorithm>, Algorithm> {
public:
GenericHashImpl() {
Expand All @@ -55,21 +56,19 @@ class GenericHashImpl : public GenericHash<GenericHashImpl<Algorithm>, Algorithm
ASSERT(res == 0);
}

void DoFinalize() {
gnutls_hash_deinit(handle_, digest_.data());
}
void DoFinalize() { gnutls_hash_deinit(handle_, digest_.data()); }

private:
gnutls_hash_hd_t handle_ = {};

using Base = GenericHash<GenericHashImpl<Algorithm>, Algorithm>;
using Base::digest_;
};
}
}
}
}
} // namespace gnutls
} // namespace impl
} // namespace crypto
} // namespace zm

#endif // HAVE_LIBGNUTLS
#endif // HAVE_LIBGNUTLS

#endif // ZONEMINDER_SRC_ZM_CRYPTO_GNUTLS_H_
#endif // ZONEMINDER_SRC_ZM_CRYPTO_GNUTLS_H_
21 changes: 11 additions & 10 deletions src/zm_crypto_openssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "zm_crypto_generics.h"
#include "zm_utils.h"

#include <openssl/evp.h>

namespace zm {
Expand All @@ -31,10 +32,10 @@ namespace openssl {

typedef EVP_MD const *(*HashCreator)();

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
struct HashAlgorithmMapper;

template<>
template <>
struct HashAlgorithmMapper<HashAlgorithms::kMD5> {
// TODO: Remove conditional once Jessie and CentOS 7 are deprecated
// This is needed since GCC 4.8 is faulty (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60199)
Expand All @@ -48,7 +49,7 @@ struct HashAlgorithmMapper<HashAlgorithms::kMD5> {
#endif
};

template<>
template <>
struct HashAlgorithmMapper<HashAlgorithms::kSHA1> {
// TODO: Remove conditional once Jessie and CentOS 7 are deprecated
// This is needed since GCC 4.8 is faulty (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60199)
Expand All @@ -62,7 +63,7 @@ struct HashAlgorithmMapper<HashAlgorithms::kSHA1> {
#endif
};

template<HashAlgorithms Algorithm>
template <HashAlgorithms Algorithm>
class GenericHashImpl : public GenericHash<GenericHashImpl<Algorithm>, Algorithm> {
public:
GenericHashImpl() {
Expand Down Expand Up @@ -98,11 +99,11 @@ class GenericHashImpl : public GenericHash<GenericHashImpl<Algorithm>, Algorithm
using Base = GenericHash<GenericHashImpl<Algorithm>, Algorithm>;
using Base::digest_;
};
}
}
}
}
} // namespace openssl
} // namespace impl
} // namespace crypto
} // namespace zm

#endif // HAVE_LIBOPENSSL
#endif // HAVE_LIBOPENSSL

#endif // ZONEMINDER_SRC_ZM_CRYPTO_OPENSSL_H_
#endif // ZONEMINDER_SRC_ZM_CRYPTO_OPENSSL_H_
6 changes: 4 additions & 2 deletions src/zm_decoder_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ void DecoderThread::Run() {
while (!(terminate_ or zm_terminate)) {
if (!monitor_->Decode()) {
if (!(terminate_ or zm_terminate)) {
// We only sleep when Decode returns false because it is an error condition and we will spin like mad if it persists.
Microseconds sleep_for = monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE);
// We only sleep when Decode returns false because it is an error condition and we will spin
// like mad if it persists.
Microseconds sleep_for =
monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE);
Debug(2, "Sleeping for %" PRId64 "us", int64(sleep_for.count()));
std::this_thread::sleep_for(sleep_for);
}
Expand Down
11 changes: 6 additions & 5 deletions src/zm_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
*/

#ifndef ZONEMINDER_SRC_ZM_DEFINE_H_
#define ZONEMINDER_SRC_ZM_DEFINE_H_

// These macros have not been adopted by the C++11 standard.
// However glibc 2.17 (CentOS 7) still depends on them to provide the macros which are guarded by these defines.
// However glibc 2.17 (CentOS 7) still depends on them to provide the macros which are guarded by
// these defines.
#if !defined(__STDC_FORMAT_MACROS)
# define __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#if !defined(__STDC_CONSTANT_MACROS)
# define __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif

#include <cinttypes>
Expand All @@ -50,4 +51,4 @@ typedef std::uint8_t uint8;
#endif
#endif

#endif // ZONEMINDER_SRC_ZM_DEFINE_H_
#endif // ZONEMINDER_SRC_ZM_DEFINE_H_
Loading