diff options
Diffstat (limited to 'libcommon')
| -rw-r--r-- | libcommon/Makefile | 39 | ||||
| -rw-r--r-- | libcommon/file.cpp | 46 | ||||
| -rw-r--r-- | libcommon/file.h | 15 | ||||
| -rw-r--r-- | libcommon/mime.cpp | 41 | ||||
| -rw-r--r-- | libcommon/mime.h | 5 | ||||
| -rw-r--r-- | libcommon/stringutil.cpp | 66 | ||||
| -rw-r--r-- | libcommon/stringutil.h | 10 | ||||
| -rw-r--r-- | libcommon/tempfile.cpp | 42 | ||||
| -rw-r--r-- | libcommon/tempfile.h | 17 | ||||
| -rw-r--r-- | libcommon/url.cpp | 32 | ||||
| -rw-r--r-- | libcommon/url.h | 6 | 
11 files changed, 0 insertions, 319 deletions
| diff --git a/libcommon/Makefile b/libcommon/Makefile deleted file mode 100644 index ddff9fc..0000000 --- a/libcommon/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# Static library to be included both in main program an in plugins (.so) - -include ../common.mk - -PROJECTNAME=libcommon - -CXXFLAGS+= -fvisibility=hidden -fPIC - -PROGSRC=\ -    file.cpp \ -    mime.cpp \ -    stringutil.cpp \ -    tempfile.cpp \ -    url.cpp - -SRC=$(PROGSRC) - -all: $(PROJECTNAME).a - -$(PROJECTNAME).a: $(SRC:.cpp=.o) -	ar rcs $@ $^ - -%.d: %.cpp -	$(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< - -%.o: %.cpp %.d -	$(CXX) $(CXXFLAGS) -c $< -o $@ - -# dependencies - -ADD_DEP=Makefile - -# misc --------------------------------------------------- -clean: -	-rm -f *.o *.a *.d - -.PHONY: clean all install - --include $(wildcard $(SRC:.cpp=.d)) diff --git a/libcommon/file.cpp b/libcommon/file.cpp deleted file mode 100644 index 47ab8be..0000000 --- a/libcommon/file.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "file.h" - -#include <fstream> - -namespace fs = std::filesystem; - -using namespace std::string_literals; - -std::string File::getFile(const fs::path& filename) -{ - std::ifstream file(filename.string(), std::ios::in | std::ios::binary | std::ios::ate); - - if (file.is_open()) { -  std::ifstream::pos_type fileSize = file.tellg(); -  file.seekg(0, std::ios::beg); - -  std::string bytes(fileSize, ' '); -  file.read(reinterpret_cast<char*>(bytes.data()), fileSize); - -  return bytes; - - } else { -  throw std::runtime_error("Opening "s + filename.string() + " for reading"); - } -} - -void File::setFile(const fs::path& filename, const std::string& s) -{ - File::setFile(filename, s.data(), s.size()); -} - -void File::setFile(const fs::path& filename, const char* data, size_t size) -{ - std::ofstream file(filename.string(), std::ios::out | std::ios::binary); - if (file.is_open()) { -  file.write(data, size); - } else { -  throw std::runtime_error("Opening "s + filename.string() + " for writing"); - } -} - -void File::setFile(const fs::path& filename, const std::vector<uint8_t>& data) -{ - File::setFile(filename, reinterpret_cast<const char*>(data.data()), data.size()); -} - diff --git a/libcommon/file.h b/libcommon/file.h deleted file mode 100644 index e7e4cf6..0000000 --- a/libcommon/file.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include <cstdint> -#include <filesystem> -#include <string> -#include <vector> - -namespace File { - -std::string getFile(const std::filesystem::path& filename); -void setFile(const std::filesystem::path& filename, const std::string& s); -void setFile(const std::filesystem::path& filename, const char* data, size_t size); -void setFile(const std::filesystem::path& filename, const std::vector<uint8_t>& data); - -} diff --git a/libcommon/mime.cpp b/libcommon/mime.cpp deleted file mode 100644 index f64d046..0000000 --- a/libcommon/mime.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "mime.h" - -#include <boost/algorithm/string/predicate.hpp> -#include <boost/beast/http.hpp> - -namespace beast = boost::beast;  - -// Return a reasonable mime type based on the extension of a file. -std::string mime_type(const std::string& path) -{ -    auto const ext = [&path] -    { -        auto const pos = path.rfind("."); -        if (pos == std::string::npos) -            return std::string{}; -        return path.substr(pos); -    }(); -    if(boost::algorithm::istarts_with(ext, ".htm"))  return "text/html"; -    if(boost::algorithm::istarts_with(ext, ".html")) return "text/html"; -    if(boost::algorithm::istarts_with(ext, ".php"))  return "text/html"; -    if(boost::algorithm::istarts_with(ext, ".css"))  return "text/css"; -    if(boost::algorithm::istarts_with(ext, ".txt"))  return "text/plain"; -    if(boost::algorithm::istarts_with(ext, ".js"))   return "application/javascript"; -    if(boost::algorithm::istarts_with(ext, ".json")) return "application/json"; -    if(boost::algorithm::istarts_with(ext, ".xml"))  return "application/xml"; -    if(boost::algorithm::istarts_with(ext, ".swf"))  return "application/x-shockwave-flash"; -    if(boost::algorithm::istarts_with(ext, ".flv"))  return "video/x-flv"; -    if(boost::algorithm::istarts_with(ext, ".png"))  return "image/png"; -    if(boost::algorithm::istarts_with(ext, ".jpe"))  return "image/jpeg"; -    if(boost::algorithm::istarts_with(ext, ".jpeg")) return "image/jpeg"; -    if(boost::algorithm::istarts_with(ext, ".jpg"))  return "image/jpeg"; -    if(boost::algorithm::istarts_with(ext, ".gif"))  return "image/gif"; -    if(boost::algorithm::istarts_with(ext, ".bmp"))  return "image/bmp"; -    if(boost::algorithm::istarts_with(ext, ".ico"))  return "image/vnd.microsoft.icon"; -    if(boost::algorithm::istarts_with(ext, ".tiff")) return "image/tiff"; -    if(boost::algorithm::istarts_with(ext, ".tif"))  return "image/tiff"; -    if(boost::algorithm::istarts_with(ext, ".svg"))  return "image/svg+xml"; -    if(boost::algorithm::istarts_with(ext, ".svgz")) return "image/svg+xml"; -    return "application/text"; -} - diff --git a/libcommon/mime.h b/libcommon/mime.h deleted file mode 100644 index c05eb45..0000000 --- a/libcommon/mime.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include <string> - -std::string mime_type(const std::string& path); diff --git a/libcommon/stringutil.cpp b/libcommon/stringutil.cpp deleted file mode 100644 index f87fa00..0000000 --- a/libcommon/stringutil.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "stringutil.h" - -#include <boost/algorithm/string/predicate.hpp> -#include <boost/algorithm/string/case_conv.hpp> - -#include <cstdarg> - -std::string strfmt(const char* fmt, ...) -{ - va_list args; - - va_start(args, fmt); - int size = std::vsnprintf(nullptr, 0, fmt, args); - va_end(args); - - std::string result(size, ' '); - - va_start(args, fmt); - std::vsnprintf(result.data(), size + 1, fmt, args); - va_end(args); - - return result; -} - -std::vector<std::string> split(std::string value, const std::string separators) -{ - std::vector<std::string> result; - - size_t pos0 = 0; - size_t pos1 = 0; - while (pos0 < value.size()) { -  pos1 = value.find_first_of(separators, pos0); -  if (pos1 == std::string::npos) -   pos1 = value.size(); -  std::string part = value.substr(pos0, pos1 - pos0); -  //std::cout << "DEBUG: " << part << std::endl << std::flush; -  if (part != "") -   result.push_back(part); -  pos0 = value.find_first_not_of(separators, pos1); -  if (pos0 == std::string::npos) -   pos0 = value.size(); - } - - return result; -} - -std::string join(std::vector<std::string> vs, std::string separator) -{ -  std::string s; -  for (const auto& line : vs) { -   if (s.size() > 0) -    s += separator; -   s += line; -  } - -  return s; -} - -bool startsWithAnyOfLower(const std::string &s, const std::vector<std::string> &list) { - for (const std::string& element : list) { -  if (boost::algorithm::starts_with(boost::algorithm::to_lower_copy(s), boost::algorithm::to_lower_copy(element))) -   return true; - } - return false; -} - diff --git a/libcommon/stringutil.h b/libcommon/stringutil.h deleted file mode 100644 index 5110e2e..0000000 --- a/libcommon/stringutil.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include <string> -#include <vector> - -std::string strfmt(const char* fmt, ...); - -std::vector<std::string> split(std::string value, const std::string separators = "\r\n "); -std::string join(std::vector<std::string> vs, std::string separator = "\n"); -bool startsWithAnyOfLower(const std::string &s, const std::vector<std::string> &list); diff --git a/libcommon/tempfile.cpp b/libcommon/tempfile.cpp deleted file mode 100644 index f425db2..0000000 --- a/libcommon/tempfile.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "tempfile.h" - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <iostream> - -namespace fs = std::filesystem; -using namespace std::string_literals; - -fs::path Tempfile::GetPath() const -{ - return m_path; -} - -Tempfile::Tempfile(const std::filesystem::path& extension) -{ - try { -  fs::path path { fs::temp_directory_path() / "tempfileXXXXXX"}; -  if (!extension.empty()) -   path += extension; - -  fs::path::string_type name{path.native()}; -  int fd = mkstemps(name.data(), extension.native().size()); -  if (fd == -1) -   std::runtime_error("mkstemps: "s + strerror(errno)); -  close(fd); -  m_path = std::string{name}; - } catch (const std::exception& ex) { -  throw std::runtime_error("Tempfile error: "s + ex.what()); - } -} - -Tempfile::~Tempfile() -{ - try { -  fs::remove_all(m_path); - } catch (const std::exception& ex) { -  std::cerr << "Warning: Couldn't remove temporary file " << m_path << std::endl; - } -} diff --git a/libcommon/tempfile.h b/libcommon/tempfile.h deleted file mode 100644 index b9839a7..0000000 --- a/libcommon/tempfile.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include <filesystem> - -class Tempfile -{ - std::filesystem::path m_path; - - public: -  std::filesystem::path GetPath() const; - -  // extension: e.g. ".zip" -  Tempfile(const std::filesystem::path& extension = std::filesystem::path{}); -  ~Tempfile(); - }; - - diff --git a/libcommon/url.cpp b/libcommon/url.cpp deleted file mode 100644 index 5baf603..0000000 --- a/libcommon/url.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "url.h" - -std::string urlDecode(std::string s) -{ - std::string result; - - size_t pos = 0; - while (pos < s.size()) { -  char c {s[pos]}; -  if (c == '+') { -   result += ' '; -  } else if (c == '%' && pos + 2 < s.size()) { -   try { -    int i = stoi(s.substr(pos + 1, 2), 0, 16); -    if (i < 0 || i > 255) -     return result; - -    result += static_cast<char>(i); -   } catch (...) { -    return result; -   } - -   pos += 2; -  } else { -   result += c; -  } -  pos++; - } - - return result; -} - diff --git a/libcommon/url.h b/libcommon/url.h deleted file mode 100644 index bd60616..0000000 --- a/libcommon/url.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include <string> - -std::string urlDecode(std::string s); - | 
