X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/fdee6fdb88e79929c952fea956fa57e5780804cf..46b0747592074017ff0ea4b33d4a7194235886e5:/projects/stargazer/plugins/other/smux/types.cpp diff --git a/projects/stargazer/plugins/other/smux/types.cpp b/projects/stargazer/plugins/other/smux/types.cpp deleted file mode 100644 index ac1d0253..00000000 --- a/projects/stargazer/plugins/other/smux/types.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include - -#include "types.h" - -bool StringToArcs(const char * str, size_t length, std::vector & arcs) -{ -unsigned a[1024]; -if (length == 0) - return false; -const char * left = str; -if (*left == '.') - ++left; -size_t arcPos = 0; -while ((left - str) < length) - { - char * pos = NULL; - unsigned arc = strtoul(left, &pos, 10); - if (pos == left) - return false; - a[arcPos++] = arc; - if (arcPos >= 1024) - return false; - left = pos + 1; - } - -std::vector newArcs(a, a + arcPos); -arcs.swap(newArcs); -return true; -} - -OID::OID(const std::string & str) -{ -if (!StringToArcs(str.c_str(), str.length(), arcs)) - throw std::runtime_error("Invalid oid"); -} - -OID::OID(const char * str, size_t length) -{ -if (!StringToArcs(str, length, arcs)) - throw std::runtime_error("Invalid oid"); -} - -OID::OID(const std::vector & a) - : arcs(a) -{ -} - -OID::OID(const unsigned * a, size_t length) -{ -std::vector newArcs(a, a + length); -arcs.swap(newArcs); -} - -OID::OID(OBJECT_IDENTIFIER_t * oid) -{ -unsigned a[1024]; -int count = OBJECT_IDENTIFIER_get_arcs(oid, a, sizeof(a[0]), 1024); - -if (count > 1024) - throw std::runtime_error("OID is too long"); - -std::vector newArcs(a, a + count); -arcs.swap(newArcs); -} - -OID::OID(const OID & rvalue) - : arcs(rvalue.arcs) -{ -} - -OID::~OID() -{ -} - -std::string OID::ToString() const -{ -std::stringstream stream; -for (size_t i = 0; i < arcs.size(); ++i) - stream << "." << arcs[i]; -return stream.str(); -} - -void OID::ToOID(OBJECT_IDENTIFIER_t * oid) const -{ -OBJECT_IDENTIFIER_set_arcs(oid, &arcs.front(), sizeof(unsigned), arcs.size()); -} - -OID & OID::operator=(const OID & rvalue) -{ -arcs = rvalue.arcs; -return *this; -} - -bool OID::operator==(const OID & rvalue) const -{ -if (arcs.size() != rvalue.arcs.size()) - return false; -for (size_t i = 0; i < arcs.size(); ++i) - if (arcs[i] != rvalue.arcs[i]) - return false; -return true; -} - -bool OID::operator<(const OID & rvalue) const -{ -for (size_t i = 0; i < std::min(arcs.size(), rvalue.arcs.size()); ++i) - if (arcs[i] > rvalue.arcs[i]) - return false; -if (rvalue.arcs.size() < arcs.size()) - return false; -return true; -} - -std::ostream & OID::operator<<(std::ostream & stream) const -{ -for (size_t i = 0; i < arcs.size(); ++i) - stream << "." << arcs[i]; -return stream; -}