Skip to content
Merged
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
57 changes: 20 additions & 37 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: none
User: andreas
CheckOptions:
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: modernize-replace-auto-ptr.IncludeStyle
value: llvm
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
...

# High-signal static analysis. The bug-finding groups are enabled wholesale;
# the negative entries switch off checks that conflict with deliberate project
# conventions (#pragma once) or that are pure style churn / very high false
# positive rate. Everything left enabled is expected to stay at zero findings,
# which WarningsAsErrors enforces.
Checks: >
-*,
bugprone-*,
clang-analyzer-*,
performance-*,
portability-*,
-bugprone-easily-swappable-parameters,
-bugprone-narrowing-conversions,
-performance-enum-size,
-portability-avoid-pragma-once,
# clang-analyzer-* stays enabled but advisory: its only findings are inside
# third-party -isystem headers (cryptopp/httplib/csv), which we cannot patch.
WarningsAsErrors: '*,-clang-analyzer-*'
HeaderFilterRegex: '(^|/)src/odr/'
FormatStyle: file
36 changes: 21 additions & 15 deletions cli/src/back_translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,37 @@

#include <odr/internal/util/file_util.hpp>

#include <iostream>
#include <string>

using namespace odr;

int main(int, char **argv) {
const std::shared_ptr logger =
Logger::create_stdio("odr-back-translate", LogLevel::verbose);
try {
const std::shared_ptr logger =
Logger::create_stdio("odr-back-translate", LogLevel::verbose);

const std::string input{argv[1]};
const std::string diff_path{argv[2]};
const std::string output{argv[3]};
const std::string input{argv[1]};
const std::string diff_path{argv[2]};
const std::string output{argv[3]};

const DocumentFile document_file{input};
const DocumentFile document_file{input};

if (document_file.password_encrypted()) {
ODR_FATAL(*logger, "encrypted documents are not supported");
return 1;
}
if (document_file.password_encrypted()) {
ODR_FATAL(*logger, "encrypted documents are not supported");
return 1;
}

const Document document = document_file.document();
const Document document = document_file.document();

const std::string diff = internal::util::file::read(diff_path);
html::edit(document, diff.c_str());
const std::string diff = internal::util::file::read(diff_path);
html::edit(document, diff.c_str());

document.save(output);
document.save(output);

return 0;
return 0;
} catch (const std::exception &e) {
std::cerr << "error: " << e.what() << '\n';
return 1;
}
}
53 changes: 29 additions & 24 deletions cli/src/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,39 @@
using namespace odr;

int main(const int argc, char **argv) {
const std::shared_ptr logger =
Logger::create_stdio("odr-meta", LogLevel::verbose);
try {
const std::shared_ptr logger =
Logger::create_stdio("odr-meta", LogLevel::verbose);

const std::string input{argv[1]};
const std::string input{argv[1]};

std::optional<std::string> password;
if (argc >= 3) {
password = argv[2];
}

DocumentFile document_file{input};
std::optional<std::string> password;
if (argc >= 3) {
password = argv[2];
}

if (document_file.password_encrypted() && !password) {
ODR_FATAL(*logger, "document encrypted but no password given");
return 2;
}
if (document_file.password_encrypted()) {
try {
document_file = document_file.decrypt(*password);
} catch (const WrongPasswordError &) {
ODR_FATAL(*logger, "wrong password");
return 1;
DocumentFile document_file{input};

if (document_file.password_encrypted()) {
if (!password) {
ODR_FATAL(*logger, "document encrypted but no password given");
return 2;
}
try {
document_file = document_file.decrypt(*password);
} catch (const WrongPasswordError &) {
ODR_FATAL(*logger, "wrong password");
return 1;
}
}
}

const auto json =
internal::util::meta::meta_to_json(document_file.file_meta());
std::cout << json.dump(4) << std::endl;
const auto json =
internal::util::meta::meta_to_json(document_file.file_meta());
std::cout << json.dump(4) << '\n';

return 0;
return 0;
} catch (const std::exception &e) {
std::cerr << "error: " << e.what() << '\n';
return 1;
}
}
122 changes: 63 additions & 59 deletions cli/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,87 @@
#include <odr/html.hpp>
#include <odr/http_server.hpp>

#include <iostream>
#include <string>

using namespace odr;

int main(const int argc, char **argv) {
const std::shared_ptr logger =
Logger::create_stdio("odr-server", LogLevel::verbose);
try {
const std::shared_ptr logger =
Logger::create_stdio("odr-server", LogLevel::verbose);

std::string input{argv[1]};
std::string input{argv[1]};

std::optional<std::string> password;
if (argc >= 3) {
password = argv[2];
}
std::optional<std::string> password;
if (argc >= 3) {
password = argv[2];
}

DecodePreference decode_preference;
decode_preference.engine_priority = {
DecoderEngine::poppler, DecoderEngine::wvware, DecoderEngine::odr};
decode_preference.as_file_type = FileType::zip;
DecodePreference decode_preference;
decode_preference.engine_priority = {
DecoderEngine::poppler, DecoderEngine::wvware, DecoderEngine::odr};
decode_preference.as_file_type = FileType::zip;

DecodedFile decoded_file{input, decode_preference, *logger};
DecodedFile decoded_file{input, decode_preference, *logger};

if (decoded_file.password_encrypted() && !password) {
ODR_FATAL(*logger, "document encrypted but no password given");
return 2;
}
if (decoded_file.password_encrypted()) {
try {
decoded_file = decoded_file.decrypt(*password);
} catch (const WrongPasswordError &) {
ODR_FATAL(*logger, "wrong password");
return 1;
if (decoded_file.password_encrypted()) {
if (!password) {
ODR_FATAL(*logger, "document encrypted but no password given");
return 2;
}
try {
decoded_file = decoded_file.decrypt(*password);
} catch (const WrongPasswordError &) {
ODR_FATAL(*logger, "wrong password");
return 1;
}
}
}

HttpServer::Config server_config;
HttpServer server(server_config);
HttpServer::Config server_config;
HttpServer server(server_config);

HtmlConfig html_config;
html_config.embed_images = false;
html_config.embed_shipped_resources = true;
html_config.relative_resource_paths = false;
html_config.text_document_margin = true;
html_config.editable = true;
HtmlConfig html_config;
html_config.embed_images = false;
html_config.embed_shipped_resources = true;
html_config.relative_resource_paths = false;
html_config.text_document_margin = true;
html_config.editable = true;

{
const std::string prefix = "file";
const HtmlViews views =
server.serve_file(decoded_file, prefix, html_config);
ODR_INFO(*logger, "hosted decoded file with id: " << prefix);
for (const auto &view : views) {
ODR_INFO(*logger,
"http://localhost:8080/file/" << prefix << "/" << view.path());
{
const std::string prefix = "file";
const HtmlViews views =
server.serve_file(decoded_file, prefix, html_config);
ODR_INFO(*logger, "hosted decoded file with id: " << prefix);
for (const auto &view : views) {
ODR_INFO(*logger,
"http://localhost:8080/file/" << prefix << "/" << view.path());
}
}
}

if (decoded_file.is_document_file() || decoded_file.is_archive_file()) {
std::optional<Filesystem> filesystem;
if (decoded_file.is_document_file()) {
filesystem = decoded_file.as_document_file().document().as_filesystem();
} else if (decoded_file.is_archive_file()) {
filesystem = decoded_file.as_archive_file().archive().as_filesystem();
}
if (decoded_file.is_document_file() || decoded_file.is_archive_file()) {
const Filesystem filesystem =
decoded_file.is_document_file()
? decoded_file.as_document_file().document().as_filesystem()
: decoded_file.as_archive_file().archive().as_filesystem();

const std::string prefix = "filesystem";
const HtmlService filesystem_service = html::translate(
filesystem.value(), server_config.cache_path + "/" + prefix,
html_config, logger);
server.connect_service(filesystem_service, prefix);
ODR_INFO(*logger, "hosted filesystem with id: " << prefix);
for (const auto &view : filesystem_service.list_views()) {
ODR_INFO(*logger,
"http://localhost:8080/file/" << prefix << "/" << view.path());
const std::string prefix = "filesystem";
const HtmlService filesystem_service =
html::translate(filesystem, server_config.cache_path + "/" + prefix,
html_config, logger);
server.connect_service(filesystem_service, prefix);
ODR_INFO(*logger, "hosted filesystem with id: " << prefix);
for (const auto &view : filesystem_service.list_views()) {
ODR_INFO(*logger,
"http://localhost:8080/file/" << prefix << "/" << view.path());
}
}
}

server.listen("localhost", 8080);
server.listen("localhost", 8080);

return 0;
return 0;
} catch (const std::exception &e) {
std::cerr << "error: " << e.what() << '\n';
return 1;
}
}
Loading
Loading