Skip to content

Commit

Permalink
merge write-out into nam20485 and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
nam20485 committed May 5, 2024
2 parents c04b952 + 96498af commit 920c026
Show file tree
Hide file tree
Showing 66 changed files with 1,587 additions and 366 deletions.
14 changes: 7 additions & 7 deletions OdbDesignLib/App/BasicRequestAuthentication.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "BasicRequestAuthentication.h"
#include <string>
#include "macros.h"
#include <cstdlib>

using namespace Utils;

Expand All @@ -17,21 +18,20 @@ namespace Odb::Lib::App
if (resp.code != crow::status::OK)
{
const auto& authHeader = req.get_header_value(AUTHORIZATION_HEADER_NAME);
if (authHeader.empty()) return crow::response(401, "Unauthorized");
if (authHeader.empty()) return crow::response(crow::status::UNAUTHORIZED, "Unauthorized");

auto authValue = authHeader.substr(6);
if (authValue.empty()) return crow::response(401, "Unauthorized");
if (authValue.empty()) return crow::response(crow::status::UNAUTHORIZED, "Unauthorized");

auto authValueDecoded = crow::utility::base64decode(authValue, authValue.size());
if (authValueDecoded.empty()) return crow::response(401, "Unauthorized");
if (authValueDecoded.empty()) return crow::response(crow::status::UNAUTHORIZED, "Unauthorized");

auto seperatorPos = authValueDecoded.find(':');
if (seperatorPos == std::string::npos) return crow::response(401, "Unauthorized");
if (seperatorPos == std::string::npos) return crow::response(crow::status::UNAUTHORIZED, "Unauthorized");

auto username = authValueDecoded.substr(0, seperatorPos);
auto password = authValueDecoded.substr(seperatorPos + 1);

//if (! VerifyCredentials(username, password)) return crow::response(403, "Invalid username or password");
resp = VerifyCredentials(username, password);
}
return resp;
Expand All @@ -58,10 +58,10 @@ namespace Odb::Lib::App
if (username != validUsername ||
password != validPassword)
{
return crow::response(403, "Invalid username or password");
return crow::response(crow::status::FORBIDDEN, "Invalid username or password");
}

// 200 Authorized!
return crow::response(200, "Authorized");
return crow::response(crow::status::OK, "Authorized");
}
}
20 changes: 16 additions & 4 deletions OdbDesignLib/App/OdbAppBase.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "OdbServerAppBase.h"
#include "Logger.h"
#include <filesystem>

using namespace Utils;
using namespace std::filesystem;

namespace Odb::Lib::App
{
Expand Down Expand Up @@ -46,17 +48,27 @@ namespace Odb::Lib::App
try
{
auto pFileArchive =
designs().GetDesign(args().loadDesign());
//designs().GetFileArchive(args().loadDesign());
//designs().GetDesign(args().loadDesign());
designs().GetFileArchive(args().loadDesign());
if (pFileArchive == nullptr)
{
logerror("Failed to load design specified in arguments \"" + args().loadDesign() + "\"");
return Utils::ExitCode::FailedInitLoadDesign;
}
else
{
//std::string filename =
pFileArchive->SaveFileModel(".", "notused");
}
}
catch (filesystem_error& fe)
{
logexception(fe);
logerror("filesystem_error: \"" + args().loadDesign() + "\" " + fe.what());
}
catch (std::exception&)
catch (std::exception& e)
{
//logexception(e);
logexception(e);
logerror("Failed to load design specified in arguments \"" + args().loadDesign() + "\"");
return Utils::ExitCode::FailedInitLoadDesign;
}
Expand Down
6 changes: 3 additions & 3 deletions OdbDesignLib/App/RequestAuthenticationBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ namespace Odb::Lib::App
if (IsDebug() && IsLocal())
{
// 200 Authorized!
return crow::response(200, "Authorized");
return crow::response(crow::status::OK, "Authorized");
}
else if (m_disableAuthentication)
{
// 200 Authorized!
return crow::response(200, "Authorized");
return crow::response(crow::status::OK, "Authorized");
}
else
{
return crow::response(401, "Unauthorized");
return crow::response(crow::status::UNAUTHORIZED, "Unauthorized");
}
}
}
2 changes: 1 addition & 1 deletion OdbDesignLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ add_library(OdbDesign SHARED
"ProtoBuf/via.pb.h" "ProtoBuf/via.pb.cc"
"ProtoBuf/package.pb.h" "ProtoBuf/package.pb.cc"
"FileModel/parse_error.h" "FileModel/parse_info.h" "FileModel/parse_info.cpp" "FileModel/parse_error.cpp" "FileModel/invalid_odb_error.h" "FileModel/invalid_odb_error.cpp" "ProtoBuf/common.pb.h" "ProtoBuf/common.pb.cc" "ProtoBuf/componentsfile.pb.h" "ProtoBuf/componentsfile.pb.cc" "FileModel/Design/PropertyRecord.h" "FileModel/Design/PropertyRecord.cpp" "FileModel/Design/FeaturesFile.h" "FileModel/Design/FeaturesFile.cpp" "FileModel/Design/ContourPolygon.h" "FileModel/Design/ContourPolygon.cpp" "FileModel/Design/SymbolName.h" "FileModel/Design/SymbolName.cpp" "FileModel/Design/SymbolsDirectory.h" "FileModel/Design/SymbolsDirectory.cpp" "FileModel/Design/StepHdrFile.h" "FileModel/Design/StepHdrFile.cpp" "FileModel/Design/AttributeLookupTable.h" "FileModel/Design/AttributeLookupTable.cpp"
"App/RequestAuthenticationBase.h" "App/RequestAuthenticationBase.cpp" "App/BasicRequestAuthentication.h" "App/BasicRequestAuthentication.cpp")
"App/RequestAuthenticationBase.h" "App/RequestAuthenticationBase.cpp" "App/BasicRequestAuthentication.h" "App/BasicRequestAuthentication.cpp" "FileModel/IStreamSaveable.h")

# disable warning C4250: inheritance by dominance
target_compile_options(OdbDesign PUBLIC
Expand Down
24 changes: 16 additions & 8 deletions OdbDesignLib/FileModel/Design/AttrListFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ namespace Odb::Lib::FileModel::Design

loginfo("checking for extraction...");

std::filesystem::path featuresFilePath;
for (const std::string featuresFilename : ATTRLIST_FILENAMES)
std::filesystem::path attrListFilePath;
for (const std::string attrListFilename : ATTRLIST_FILENAMES)
{
loginfo("trying attrlist file: [" + featuresFilename + "]...");
loginfo("trying attrlist file: [" + attrListFilename + "]...");

featuresFilePath = Utils::ArchiveExtractor::getUncompressedFilePath(m_directory, featuresFilename);
if (exists(featuresFilePath) && is_regular_file(featuresFilePath))
attrListFilePath = Utils::ArchiveExtractor::getUncompressedFilePath(m_directory, attrListFilename);
if (exists(attrListFilePath) && is_regular_file(attrListFilePath))
{
loginfo("found attrlist file: [" + featuresFilePath.string() + "]");
loginfo("found attrlist file: [" + attrListFilePath.string() + "]");
break;
}
}

m_path = featuresFilePath;
m_path = attrListFilePath;

loginfo("any extraction complete, parsing data...");

Expand Down Expand Up @@ -203,6 +203,14 @@ namespace Odb::Lib::FileModel::Design
return true;
}


bool AttrListFile::Save(std::ostream& os)
{
os << Constants::UNITS_TOKEN << " = " << m_units << std::endl;
for (const auto& kvAttribute : m_attributesByName)
{
os << kvAttribute.first << " = " << kvAttribute.second << std::endl;
}

return true;
}
} // namespace Odb::Lib::FileModel::Design
6 changes: 4 additions & 2 deletions OdbDesignLib/FileModel/Design/AttrListFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#include "../../IProtoBuffable.h"
#include "../../ProtoBuf/attrlistfile.pb.h"
#include "../../odbdesign_export.h"
#include "../IStreamSaveable.h"

namespace Odb::Lib::FileModel::Design
{
class ODBDESIGN_EXPORT AttrListFile : public IProtoBuffable<Odb::Lib::Protobuf::AttrListFile>
class ODBDESIGN_EXPORT AttrListFile : public IProtoBuffable<Odb::Lib::Protobuf::AttrListFile>, public IStreamSaveable
{
public:
AttrListFile();
Expand All @@ -24,6 +25,8 @@ namespace Odb::Lib::FileModel::Design
const AttributeMap& GetAttributes() const;

bool Parse(std::filesystem::path directory);
// Inherited via IStreamSaveable
bool Save(std::ostream& os) override;

// Inherited via IProtoBuffable
std::unique_ptr<Odb::Lib::Protobuf::AttrListFile> to_protobuf() const override;
Expand All @@ -40,7 +43,6 @@ namespace Odb::Lib::FileModel::Design
inline static const auto ATTRLIST_FILENAMES = { "attrlist" };
inline static const char* OPTIONAL_ATTRIBUTES[] = { "" };
};

}

#endif //ODBDESIGN_ATTRLISTFILE_H
11 changes: 5 additions & 6 deletions OdbDesignLib/FileModel/Design/ComponentsFile.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
#include "ComponentsFile.h"
#include "ComponentsFile.h"
#include "ComponentsFile.h"
#include "ComponentsFile.h"
#include "ComponentsFile.h"
#include "ComponentsFile.h"
#include "ComponentsFile.h"
#include <fstream>
#include <sstream>
#include <filesystem>
Expand Down Expand Up @@ -155,6 +149,11 @@ namespace Odb::Lib::FileModel::Design
}
}

bool ComponentsFile::Save(std::ostream& os)
{
return true;
}

std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord> ComponentsFile::BomDescriptionRecord::to_protobuf() const
{
std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord> pBomDescriptionRecordMessage(new Odb::Lib::Protobuf::ComponentsFile::BomDescriptionRecord);
Expand Down
18 changes: 11 additions & 7 deletions OdbDesignLib/FileModel/Design/ComponentsFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
#include "PropertyRecord.h"
#include "../../ProtoBuf/componentsfile.pb.h"
#include "AttributeLookupTable.h"
#include "../IStreamSaveable.h"


namespace Odb::Lib::FileModel::Design
{
class ODBDESIGN_EXPORT ComponentsFile : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile>
class ODBDESIGN_EXPORT ComponentsFile : public IProtoBuffable<Odb::Lib::Protobuf::ComponentsFile>, public IStreamSaveable
{
public:
ComponentsFile();
~ComponentsFile();

bool Parse(std::filesystem::path directory);
// Inherited via IStreamSaveable
bool Save(std::ostream& os) override;

std::string GetUnits() const;
BoardSide GetSide() const;
Expand Down Expand Up @@ -123,7 +126,7 @@ namespace Odb::Lib::FileModel::Design

constexpr inline static const char* TOP_COMPONENTS_LAYER_NAME = "comp_+_top";
constexpr inline static const char* BOTTOM_COMPONENTS_LAYER_NAME = "comp_+_bot";

// Inherited via IProtoBuffable
std::unique_ptr<Odb::Lib::Protobuf::ComponentsFile> to_protobuf() const override;
void from_protobuf(const Odb::Lib::Protobuf::ComponentsFile& message) override;
Expand All @@ -148,9 +151,9 @@ namespace Odb::Lib::FileModel::Design
const bool m_allowToepintNetNumbersOfNegative1 = true;

constexpr inline static const char* COMPONENTS_FILENAMES[] =
{
"components",
"components2",
{
"components",
"components2",
"components3"
};

Expand All @@ -168,6 +171,7 @@ namespace Odb::Lib::FileModel::Design
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VPL_VND = "VPL_VND";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VPL_MPN = "VPL_MPN";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_VND = "VND";
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_MPN = "MPN";
};
constexpr inline static const char* BOM_DESCR_RECORD_TOKEN_MPN = "MPN";

};
}
7 changes: 6 additions & 1 deletion OdbDesignLib/FileModel/Design/EdaDataFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,12 @@ namespace Odb::Lib::FileModel::Design
pFeatureGroupRecord->from_protobuf(featureGroupRecordMessage);
m_featureGroupRecords.push_back(pFeatureGroupRecord);
}
}
}

bool EdaDataFile::Save(std::ostream& os)
{
return true;
}

bool EdaDataFile::Parse(std::filesystem::path path)
{
Expand Down
7 changes: 5 additions & 2 deletions OdbDesignLib/FileModel/Design/EdaDataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
#include "PropertyRecord.h"
#include "ContourPolygon.h"
#include "AttributeLookupTable.h"
#include "../IStreamSaveable.h"


namespace Odb::Lib::FileModel::Design
{
class ODBDESIGN_EXPORT EdaDataFile : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile>
class ODBDESIGN_EXPORT EdaDataFile : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile>, public IStreamSaveable
{
public:
EdaDataFile(bool logAllLineParsing = false);
Expand All @@ -27,7 +28,9 @@ namespace Odb::Lib::FileModel::Design
const std::string& GetUnits() const;
const std::string& GetSource() const;

bool Parse(std::filesystem::path path);
bool Parse(std::filesystem::path path);
// Inherited via IStreamSaveable
bool Save(std::ostream& os) override;

struct ODBDESIGN_EXPORT FeatureIdRecord : public IProtoBuffable<Odb::Lib::Protobuf::EdaDataFile::FeatureIdRecord>
{
Expand Down
6 changes: 5 additions & 1 deletion OdbDesignLib/FileModel/Design/FeaturesFile.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "FeaturesFile.h"
#include "FeaturesFile.h"
#include "ArchiveExtractor.h"
#include <fstream>
#include "Logger.h"
Expand Down Expand Up @@ -858,6 +857,11 @@ namespace Odb::Lib::FileModel::Design
}
}

bool FeaturesFile::Save(std::ostream& os)
{
return true;
}

FeaturesFile::FeatureRecord::~FeatureRecord()
{
m_contourPolygons.clear();
Expand Down
5 changes: 4 additions & 1 deletion OdbDesignLib/FileModel/Design/FeaturesFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
#include "../../ProtoBuf/featuresfile.pb.h"
#include "SymbolName.h"
#include "AttributeLookupTable.h"
#include "../IStreamSaveable.h"


namespace Odb::Lib::FileModel::Design
{
class FeaturesFile : public IProtoBuffable<Odb::Lib::Protobuf::FeaturesFile>
class FeaturesFile : public IProtoBuffable<Odb::Lib::Protobuf::FeaturesFile>, public IStreamSaveable
{
public:
FeaturesFile();
Expand Down Expand Up @@ -86,6 +87,8 @@ namespace Odb::Lib::FileModel::Design
};

bool Parse(std::filesystem::path directory, const std::string& alternateFilename = "");
// Inherited via IStreamSaveable
bool Save(std::ostream& os) override;

std::string GetUnits() const;
std::filesystem::path GetPath();
Expand Down
Loading

0 comments on commit 920c026

Please sign in to comment.